main.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908
  1. /*
  2. * Copyright 2002-2005, Instant802 Networks, Inc.
  3. * Copyright 2005-2006, Devicescape Software, Inc.
  4. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <net/mac80211.h>
  11. #include <net/ieee80211_radiotap.h>
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/netdevice.h>
  15. #include <linux/types.h>
  16. #include <linux/slab.h>
  17. #include <linux/skbuff.h>
  18. #include <linux/etherdevice.h>
  19. #include <linux/if_arp.h>
  20. #include <linux/wireless.h>
  21. #include <linux/rtnetlink.h>
  22. #include <linux/bitmap.h>
  23. #include <net/net_namespace.h>
  24. #include <net/cfg80211.h>
  25. #include "ieee80211_i.h"
  26. #include "rate.h"
  27. #include "mesh.h"
  28. #include "wep.h"
  29. #include "wme.h"
  30. #include "aes_ccm.h"
  31. #include "led.h"
  32. #include "cfg.h"
  33. #include "debugfs.h"
  34. #include "debugfs_netdev.h"
  35. #define SUPP_MCS_SET_LEN 16
  36. /*
  37. * For seeing transmitted packets on monitor interfaces
  38. * we have a radiotap header too.
  39. */
  40. struct ieee80211_tx_status_rtap_hdr {
  41. struct ieee80211_radiotap_header hdr;
  42. __le16 tx_flags;
  43. u8 data_retries;
  44. } __attribute__ ((packed));
  45. /* common interface routines */
  46. static int header_parse_80211(const struct sk_buff *skb, unsigned char *haddr)
  47. {
  48. memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
  49. return ETH_ALEN;
  50. }
  51. /* must be called under mdev tx lock */
  52. static void ieee80211_configure_filter(struct ieee80211_local *local)
  53. {
  54. unsigned int changed_flags;
  55. unsigned int new_flags = 0;
  56. if (atomic_read(&local->iff_promiscs))
  57. new_flags |= FIF_PROMISC_IN_BSS;
  58. if (atomic_read(&local->iff_allmultis))
  59. new_flags |= FIF_ALLMULTI;
  60. if (local->monitors)
  61. new_flags |= FIF_BCN_PRBRESP_PROMISC;
  62. if (local->fif_fcsfail)
  63. new_flags |= FIF_FCSFAIL;
  64. if (local->fif_plcpfail)
  65. new_flags |= FIF_PLCPFAIL;
  66. if (local->fif_control)
  67. new_flags |= FIF_CONTROL;
  68. if (local->fif_other_bss)
  69. new_flags |= FIF_OTHER_BSS;
  70. changed_flags = local->filter_flags ^ new_flags;
  71. /* be a bit nasty */
  72. new_flags |= (1<<31);
  73. local->ops->configure_filter(local_to_hw(local),
  74. changed_flags, &new_flags,
  75. local->mdev->mc_count,
  76. local->mdev->mc_list);
  77. WARN_ON(new_flags & (1<<31));
  78. local->filter_flags = new_flags & ~(1<<31);
  79. }
  80. /* master interface */
  81. static int ieee80211_master_open(struct net_device *dev)
  82. {
  83. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  84. struct ieee80211_sub_if_data *sdata;
  85. int res = -EOPNOTSUPP;
  86. /* we hold the RTNL here so can safely walk the list */
  87. list_for_each_entry(sdata, &local->interfaces, list) {
  88. if (sdata->dev != dev && netif_running(sdata->dev)) {
  89. res = 0;
  90. break;
  91. }
  92. }
  93. return res;
  94. }
  95. static int ieee80211_master_stop(struct net_device *dev)
  96. {
  97. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  98. struct ieee80211_sub_if_data *sdata;
  99. /* we hold the RTNL here so can safely walk the list */
  100. list_for_each_entry(sdata, &local->interfaces, list)
  101. if (sdata->dev != dev && netif_running(sdata->dev))
  102. dev_close(sdata->dev);
  103. return 0;
  104. }
  105. static void ieee80211_master_set_multicast_list(struct net_device *dev)
  106. {
  107. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  108. ieee80211_configure_filter(local);
  109. }
  110. /* regular interfaces */
  111. static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
  112. {
  113. int meshhdrlen;
  114. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  115. meshhdrlen = (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT) ? 5 : 0;
  116. /* FIX: what would be proper limits for MTU?
  117. * This interface uses 802.3 frames. */
  118. if (new_mtu < 256 ||
  119. new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6 - meshhdrlen) {
  120. printk(KERN_WARNING "%s: invalid MTU %d\n",
  121. dev->name, new_mtu);
  122. return -EINVAL;
  123. }
  124. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  125. printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
  126. #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
  127. dev->mtu = new_mtu;
  128. return 0;
  129. }
  130. static inline int identical_mac_addr_allowed(int type1, int type2)
  131. {
  132. return (type1 == IEEE80211_IF_TYPE_MNTR ||
  133. type2 == IEEE80211_IF_TYPE_MNTR ||
  134. (type1 == IEEE80211_IF_TYPE_AP &&
  135. type2 == IEEE80211_IF_TYPE_WDS) ||
  136. (type1 == IEEE80211_IF_TYPE_WDS &&
  137. (type2 == IEEE80211_IF_TYPE_WDS ||
  138. type2 == IEEE80211_IF_TYPE_AP)) ||
  139. (type1 == IEEE80211_IF_TYPE_AP &&
  140. type2 == IEEE80211_IF_TYPE_VLAN) ||
  141. (type1 == IEEE80211_IF_TYPE_VLAN &&
  142. (type2 == IEEE80211_IF_TYPE_AP ||
  143. type2 == IEEE80211_IF_TYPE_VLAN)));
  144. }
  145. static int ieee80211_open(struct net_device *dev)
  146. {
  147. struct ieee80211_sub_if_data *sdata, *nsdata;
  148. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  149. struct ieee80211_if_init_conf conf;
  150. int res;
  151. bool need_hw_reconfig = 0;
  152. struct sta_info *sta;
  153. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  154. /* we hold the RTNL here so can safely walk the list */
  155. list_for_each_entry(nsdata, &local->interfaces, list) {
  156. struct net_device *ndev = nsdata->dev;
  157. if (ndev != dev && ndev != local->mdev && netif_running(ndev)) {
  158. /*
  159. * Allow only a single IBSS interface to be up at any
  160. * time. This is restricted because beacon distribution
  161. * cannot work properly if both are in the same IBSS.
  162. *
  163. * To remove this restriction we'd have to disallow them
  164. * from setting the same SSID on different IBSS interfaces
  165. * belonging to the same hardware. Then, however, we're
  166. * faced with having to adopt two different TSF timers...
  167. */
  168. if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
  169. nsdata->vif.type == IEEE80211_IF_TYPE_IBSS)
  170. return -EBUSY;
  171. /*
  172. * Disallow multiple IBSS/STA mode interfaces.
  173. *
  174. * This is a technical restriction, it is possible although
  175. * most likely not IEEE 802.11 compliant to have multiple
  176. * STAs with just a single hardware (the TSF timer will not
  177. * be adjusted properly.)
  178. *
  179. * However, because mac80211 uses the master device's BSS
  180. * information for each STA/IBSS interface, doing this will
  181. * currently corrupt that BSS information completely, unless,
  182. * a not very useful case, both STAs are associated to the
  183. * same BSS.
  184. *
  185. * To remove this restriction, the BSS information needs to
  186. * be embedded in the STA/IBSS mode sdata instead of using
  187. * the master device's BSS structure.
  188. */
  189. if ((sdata->vif.type == IEEE80211_IF_TYPE_STA ||
  190. sdata->vif.type == IEEE80211_IF_TYPE_IBSS) &&
  191. (nsdata->vif.type == IEEE80211_IF_TYPE_STA ||
  192. nsdata->vif.type == IEEE80211_IF_TYPE_IBSS))
  193. return -EBUSY;
  194. /*
  195. * The remaining checks are only performed for interfaces
  196. * with the same MAC address.
  197. */
  198. if (compare_ether_addr(dev->dev_addr, ndev->dev_addr))
  199. continue;
  200. /*
  201. * check whether it may have the same address
  202. */
  203. if (!identical_mac_addr_allowed(sdata->vif.type,
  204. nsdata->vif.type))
  205. return -ENOTUNIQ;
  206. /*
  207. * can only add VLANs to enabled APs
  208. */
  209. if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN &&
  210. nsdata->vif.type == IEEE80211_IF_TYPE_AP)
  211. sdata->u.vlan.ap = nsdata;
  212. }
  213. }
  214. switch (sdata->vif.type) {
  215. case IEEE80211_IF_TYPE_WDS:
  216. if (!is_valid_ether_addr(sdata->u.wds.remote_addr))
  217. return -ENOLINK;
  218. break;
  219. case IEEE80211_IF_TYPE_VLAN:
  220. if (!sdata->u.vlan.ap)
  221. return -ENOLINK;
  222. break;
  223. case IEEE80211_IF_TYPE_AP:
  224. case IEEE80211_IF_TYPE_STA:
  225. case IEEE80211_IF_TYPE_MNTR:
  226. case IEEE80211_IF_TYPE_IBSS:
  227. case IEEE80211_IF_TYPE_MESH_POINT:
  228. /* no special treatment */
  229. break;
  230. case IEEE80211_IF_TYPE_INVALID:
  231. /* cannot happen */
  232. WARN_ON(1);
  233. break;
  234. }
  235. if (local->open_count == 0) {
  236. res = 0;
  237. if (local->ops->start)
  238. res = local->ops->start(local_to_hw(local));
  239. if (res)
  240. return res;
  241. need_hw_reconfig = 1;
  242. ieee80211_led_radio(local, local->hw.conf.radio_enabled);
  243. }
  244. switch (sdata->vif.type) {
  245. case IEEE80211_IF_TYPE_VLAN:
  246. list_add(&sdata->u.vlan.list, &sdata->u.vlan.ap->u.ap.vlans);
  247. /* no need to tell driver */
  248. break;
  249. case IEEE80211_IF_TYPE_MNTR:
  250. if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
  251. local->cooked_mntrs++;
  252. break;
  253. }
  254. /* must be before the call to ieee80211_configure_filter */
  255. local->monitors++;
  256. if (local->monitors == 1)
  257. local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
  258. if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
  259. local->fif_fcsfail++;
  260. if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
  261. local->fif_plcpfail++;
  262. if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
  263. local->fif_control++;
  264. if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
  265. local->fif_other_bss++;
  266. netif_tx_lock_bh(local->mdev);
  267. ieee80211_configure_filter(local);
  268. netif_tx_unlock_bh(local->mdev);
  269. break;
  270. case IEEE80211_IF_TYPE_STA:
  271. case IEEE80211_IF_TYPE_IBSS:
  272. sdata->u.sta.flags &= ~IEEE80211_STA_PREV_BSSID_SET;
  273. /* fall through */
  274. default:
  275. conf.vif = &sdata->vif;
  276. conf.type = sdata->vif.type;
  277. conf.mac_addr = dev->dev_addr;
  278. res = local->ops->add_interface(local_to_hw(local), &conf);
  279. if (res)
  280. goto err_stop;
  281. ieee80211_if_config(dev);
  282. ieee80211_reset_erp_info(dev);
  283. ieee80211_enable_keys(sdata);
  284. if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
  285. !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
  286. netif_carrier_off(dev);
  287. else
  288. netif_carrier_on(dev);
  289. }
  290. if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
  291. /* Create STA entry for the WDS peer */
  292. sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
  293. GFP_KERNEL);
  294. if (!sta) {
  295. res = -ENOMEM;
  296. goto err_del_interface;
  297. }
  298. /* no locking required since STA is not live yet */
  299. sta->flags |= WLAN_STA_AUTHORIZED;
  300. res = sta_info_insert(sta);
  301. if (res) {
  302. /* STA has been freed */
  303. goto err_del_interface;
  304. }
  305. }
  306. if (local->open_count == 0) {
  307. res = dev_open(local->mdev);
  308. WARN_ON(res);
  309. if (res)
  310. goto err_del_interface;
  311. tasklet_enable(&local->tx_pending_tasklet);
  312. tasklet_enable(&local->tasklet);
  313. }
  314. /*
  315. * set_multicast_list will be invoked by the networking core
  316. * which will check whether any increments here were done in
  317. * error and sync them down to the hardware as filter flags.
  318. */
  319. if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
  320. atomic_inc(&local->iff_allmultis);
  321. if (sdata->flags & IEEE80211_SDATA_PROMISC)
  322. atomic_inc(&local->iff_promiscs);
  323. local->open_count++;
  324. if (need_hw_reconfig)
  325. ieee80211_hw_config(local);
  326. /*
  327. * ieee80211_sta_work is disabled while network interface
  328. * is down. Therefore, some configuration changes may not
  329. * yet be effective. Trigger execution of ieee80211_sta_work
  330. * to fix this.
  331. */
  332. if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
  333. sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
  334. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  335. queue_work(local->hw.workqueue, &ifsta->work);
  336. }
  337. netif_start_queue(dev);
  338. return 0;
  339. err_del_interface:
  340. local->ops->remove_interface(local_to_hw(local), &conf);
  341. err_stop:
  342. if (!local->open_count && local->ops->stop)
  343. local->ops->stop(local_to_hw(local));
  344. return res;
  345. }
  346. static int ieee80211_stop(struct net_device *dev)
  347. {
  348. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  349. struct ieee80211_local *local = sdata->local;
  350. struct ieee80211_if_init_conf conf;
  351. struct sta_info *sta;
  352. /*
  353. * Stop TX on this interface first.
  354. */
  355. netif_stop_queue(dev);
  356. /*
  357. * Now delete all active aggregation sessions.
  358. */
  359. rcu_read_lock();
  360. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  361. if (sta->sdata == sdata)
  362. ieee80211_sta_tear_down_BA_sessions(dev, sta->addr);
  363. }
  364. rcu_read_unlock();
  365. /*
  366. * Remove all stations associated with this interface.
  367. *
  368. * This must be done before calling ops->remove_interface()
  369. * because otherwise we can later invoke ops->sta_notify()
  370. * whenever the STAs are removed, and that invalidates driver
  371. * assumptions about always getting a vif pointer that is valid
  372. * (because if we remove a STA after ops->remove_interface()
  373. * the driver will have removed the vif info already!)
  374. *
  375. * We could relax this and only unlink the stations from the
  376. * hash table and list but keep them on a per-sdata list that
  377. * will be inserted back again when the interface is brought
  378. * up again, but I don't currently see a use case for that,
  379. * except with WDS which gets a STA entry created when it is
  380. * brought up.
  381. */
  382. sta_info_flush(local, sdata);
  383. /*
  384. * Don't count this interface for promisc/allmulti while it
  385. * is down. dev_mc_unsync() will invoke set_multicast_list
  386. * on the master interface which will sync these down to the
  387. * hardware as filter flags.
  388. */
  389. if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
  390. atomic_dec(&local->iff_allmultis);
  391. if (sdata->flags & IEEE80211_SDATA_PROMISC)
  392. atomic_dec(&local->iff_promiscs);
  393. dev_mc_unsync(local->mdev, dev);
  394. /* APs need special treatment */
  395. if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
  396. struct ieee80211_sub_if_data *vlan, *tmp;
  397. struct beacon_data *old_beacon = sdata->u.ap.beacon;
  398. /* remove beacon */
  399. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  400. synchronize_rcu();
  401. kfree(old_beacon);
  402. /* down all dependent devices, that is VLANs */
  403. list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans,
  404. u.vlan.list)
  405. dev_close(vlan->dev);
  406. WARN_ON(!list_empty(&sdata->u.ap.vlans));
  407. }
  408. local->open_count--;
  409. switch (sdata->vif.type) {
  410. case IEEE80211_IF_TYPE_VLAN:
  411. list_del(&sdata->u.vlan.list);
  412. sdata->u.vlan.ap = NULL;
  413. /* no need to tell driver */
  414. break;
  415. case IEEE80211_IF_TYPE_MNTR:
  416. if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
  417. local->cooked_mntrs--;
  418. break;
  419. }
  420. local->monitors--;
  421. if (local->monitors == 0)
  422. local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
  423. if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
  424. local->fif_fcsfail--;
  425. if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
  426. local->fif_plcpfail--;
  427. if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
  428. local->fif_control--;
  429. if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
  430. local->fif_other_bss--;
  431. netif_tx_lock_bh(local->mdev);
  432. ieee80211_configure_filter(local);
  433. netif_tx_unlock_bh(local->mdev);
  434. break;
  435. case IEEE80211_IF_TYPE_MESH_POINT:
  436. case IEEE80211_IF_TYPE_STA:
  437. case IEEE80211_IF_TYPE_IBSS:
  438. sdata->u.sta.state = IEEE80211_DISABLED;
  439. del_timer_sync(&sdata->u.sta.timer);
  440. /*
  441. * When we get here, the interface is marked down.
  442. * Call synchronize_rcu() to wait for the RX path
  443. * should it be using the interface and enqueuing
  444. * frames at this very time on another CPU.
  445. */
  446. synchronize_rcu();
  447. skb_queue_purge(&sdata->u.sta.skb_queue);
  448. if (local->scan_dev == sdata->dev) {
  449. if (!local->ops->hw_scan) {
  450. local->sta_sw_scanning = 0;
  451. cancel_delayed_work(&local->scan_work);
  452. } else
  453. local->sta_hw_scanning = 0;
  454. }
  455. flush_workqueue(local->hw.workqueue);
  456. sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
  457. kfree(sdata->u.sta.extra_ie);
  458. sdata->u.sta.extra_ie = NULL;
  459. sdata->u.sta.extra_ie_len = 0;
  460. /* fall through */
  461. default:
  462. conf.vif = &sdata->vif;
  463. conf.type = sdata->vif.type;
  464. conf.mac_addr = dev->dev_addr;
  465. /* disable all keys for as long as this netdev is down */
  466. ieee80211_disable_keys(sdata);
  467. local->ops->remove_interface(local_to_hw(local), &conf);
  468. }
  469. if (local->open_count == 0) {
  470. if (netif_running(local->mdev))
  471. dev_close(local->mdev);
  472. if (local->ops->stop)
  473. local->ops->stop(local_to_hw(local));
  474. ieee80211_led_radio(local, 0);
  475. tasklet_disable(&local->tx_pending_tasklet);
  476. tasklet_disable(&local->tasklet);
  477. }
  478. return 0;
  479. }
  480. int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
  481. {
  482. struct ieee80211_local *local = hw_to_local(hw);
  483. struct sta_info *sta;
  484. struct ieee80211_sub_if_data *sdata;
  485. u16 start_seq_num = 0;
  486. u8 *state;
  487. int ret;
  488. DECLARE_MAC_BUF(mac);
  489. if (tid >= STA_TID_NUM)
  490. return -EINVAL;
  491. #ifdef CONFIG_MAC80211_HT_DEBUG
  492. printk(KERN_DEBUG "Open BA session requested for %s tid %u\n",
  493. print_mac(mac, ra), tid);
  494. #endif /* CONFIG_MAC80211_HT_DEBUG */
  495. rcu_read_lock();
  496. sta = sta_info_get(local, ra);
  497. if (!sta) {
  498. printk(KERN_DEBUG "Could not find the station\n");
  499. rcu_read_unlock();
  500. return -ENOENT;
  501. }
  502. spin_lock_bh(&sta->lock);
  503. /* we have tried too many times, receiver does not want A-MPDU */
  504. if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) {
  505. ret = -EBUSY;
  506. goto start_ba_exit;
  507. }
  508. state = &sta->ampdu_mlme.tid_state_tx[tid];
  509. /* check if the TID is not in aggregation flow already */
  510. if (*state != HT_AGG_STATE_IDLE) {
  511. #ifdef CONFIG_MAC80211_HT_DEBUG
  512. printk(KERN_DEBUG "BA request denied - session is not "
  513. "idle on tid %u\n", tid);
  514. #endif /* CONFIG_MAC80211_HT_DEBUG */
  515. ret = -EAGAIN;
  516. goto start_ba_exit;
  517. }
  518. /* prepare A-MPDU MLME for Tx aggregation */
  519. sta->ampdu_mlme.tid_tx[tid] =
  520. kmalloc(sizeof(struct tid_ampdu_tx), GFP_ATOMIC);
  521. if (!sta->ampdu_mlme.tid_tx[tid]) {
  522. if (net_ratelimit())
  523. printk(KERN_ERR "allocate tx mlme to tid %d failed\n",
  524. tid);
  525. ret = -ENOMEM;
  526. goto start_ba_exit;
  527. }
  528. /* Tx timer */
  529. sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.function =
  530. sta_addba_resp_timer_expired;
  531. sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.data =
  532. (unsigned long)&sta->timer_to_tid[tid];
  533. init_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
  534. /* ensure that TX flow won't interrupt us
  535. * until the end of the call to requeue function */
  536. spin_lock_bh(&local->mdev->queue_lock);
  537. /* create a new queue for this aggregation */
  538. ret = ieee80211_ht_agg_queue_add(local, sta, tid);
  539. /* case no queue is available to aggregation
  540. * don't switch to aggregation */
  541. if (ret) {
  542. #ifdef CONFIG_MAC80211_HT_DEBUG
  543. printk(KERN_DEBUG "BA request denied - queue unavailable for"
  544. " tid %d\n", tid);
  545. #endif /* CONFIG_MAC80211_HT_DEBUG */
  546. goto start_ba_err;
  547. }
  548. sdata = sta->sdata;
  549. /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
  550. * call back right away, it must see that the flow has begun */
  551. *state |= HT_ADDBA_REQUESTED_MSK;
  552. if (local->ops->ampdu_action)
  553. ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START,
  554. ra, tid, &start_seq_num);
  555. if (ret) {
  556. /* No need to requeue the packets in the agg queue, since we
  557. * held the tx lock: no packet could be enqueued to the newly
  558. * allocated queue */
  559. ieee80211_ht_agg_queue_remove(local, sta, tid, 0);
  560. #ifdef CONFIG_MAC80211_HT_DEBUG
  561. printk(KERN_DEBUG "BA request denied - HW unavailable for"
  562. " tid %d\n", tid);
  563. #endif /* CONFIG_MAC80211_HT_DEBUG */
  564. *state = HT_AGG_STATE_IDLE;
  565. goto start_ba_err;
  566. }
  567. /* Will put all the packets in the new SW queue */
  568. ieee80211_requeue(local, ieee802_1d_to_ac[tid]);
  569. spin_unlock_bh(&local->mdev->queue_lock);
  570. /* send an addBA request */
  571. sta->ampdu_mlme.dialog_token_allocator++;
  572. sta->ampdu_mlme.tid_tx[tid]->dialog_token =
  573. sta->ampdu_mlme.dialog_token_allocator;
  574. sta->ampdu_mlme.tid_tx[tid]->ssn = start_seq_num;
  575. ieee80211_send_addba_request(sta->sdata->dev, ra, tid,
  576. sta->ampdu_mlme.tid_tx[tid]->dialog_token,
  577. sta->ampdu_mlme.tid_tx[tid]->ssn,
  578. 0x40, 5000);
  579. /* activate the timer for the recipient's addBA response */
  580. sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.expires =
  581. jiffies + ADDBA_RESP_INTERVAL;
  582. add_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
  583. printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
  584. goto start_ba_exit;
  585. start_ba_err:
  586. kfree(sta->ampdu_mlme.tid_tx[tid]);
  587. sta->ampdu_mlme.tid_tx[tid] = NULL;
  588. spin_unlock_bh(&local->mdev->queue_lock);
  589. ret = -EBUSY;
  590. start_ba_exit:
  591. spin_unlock_bh(&sta->lock);
  592. rcu_read_unlock();
  593. return ret;
  594. }
  595. EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
  596. int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
  597. u8 *ra, u16 tid,
  598. enum ieee80211_back_parties initiator)
  599. {
  600. struct ieee80211_local *local = hw_to_local(hw);
  601. struct sta_info *sta;
  602. u8 *state;
  603. int ret = 0;
  604. DECLARE_MAC_BUF(mac);
  605. if (tid >= STA_TID_NUM)
  606. return -EINVAL;
  607. rcu_read_lock();
  608. sta = sta_info_get(local, ra);
  609. if (!sta) {
  610. rcu_read_unlock();
  611. return -ENOENT;
  612. }
  613. /* check if the TID is in aggregation */
  614. state = &sta->ampdu_mlme.tid_state_tx[tid];
  615. spin_lock_bh(&sta->lock);
  616. if (*state != HT_AGG_STATE_OPERATIONAL) {
  617. ret = -ENOENT;
  618. goto stop_BA_exit;
  619. }
  620. #ifdef CONFIG_MAC80211_HT_DEBUG
  621. printk(KERN_DEBUG "Tx BA session stop requested for %s tid %u\n",
  622. print_mac(mac, ra), tid);
  623. #endif /* CONFIG_MAC80211_HT_DEBUG */
  624. ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]);
  625. *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
  626. (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
  627. if (local->ops->ampdu_action)
  628. ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP,
  629. ra, tid, NULL);
  630. /* case HW denied going back to legacy */
  631. if (ret) {
  632. WARN_ON(ret != -EBUSY);
  633. *state = HT_AGG_STATE_OPERATIONAL;
  634. ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
  635. goto stop_BA_exit;
  636. }
  637. stop_BA_exit:
  638. spin_unlock_bh(&sta->lock);
  639. rcu_read_unlock();
  640. return ret;
  641. }
  642. EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
  643. void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
  644. {
  645. struct ieee80211_local *local = hw_to_local(hw);
  646. struct sta_info *sta;
  647. u8 *state;
  648. DECLARE_MAC_BUF(mac);
  649. if (tid >= STA_TID_NUM) {
  650. printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
  651. tid, STA_TID_NUM);
  652. return;
  653. }
  654. rcu_read_lock();
  655. sta = sta_info_get(local, ra);
  656. if (!sta) {
  657. rcu_read_unlock();
  658. printk(KERN_DEBUG "Could not find station: %s\n",
  659. print_mac(mac, ra));
  660. return;
  661. }
  662. state = &sta->ampdu_mlme.tid_state_tx[tid];
  663. spin_lock_bh(&sta->lock);
  664. if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
  665. printk(KERN_DEBUG "addBA was not requested yet, state is %d\n",
  666. *state);
  667. spin_unlock_bh(&sta->lock);
  668. rcu_read_unlock();
  669. return;
  670. }
  671. WARN_ON_ONCE(*state & HT_ADDBA_DRV_READY_MSK);
  672. *state |= HT_ADDBA_DRV_READY_MSK;
  673. if (*state == HT_AGG_STATE_OPERATIONAL) {
  674. printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid);
  675. ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
  676. }
  677. spin_unlock_bh(&sta->lock);
  678. rcu_read_unlock();
  679. }
  680. EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
  681. void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
  682. {
  683. struct ieee80211_local *local = hw_to_local(hw);
  684. struct sta_info *sta;
  685. u8 *state;
  686. int agg_queue;
  687. DECLARE_MAC_BUF(mac);
  688. if (tid >= STA_TID_NUM) {
  689. printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
  690. tid, STA_TID_NUM);
  691. return;
  692. }
  693. #ifdef CONFIG_MAC80211_HT_DEBUG
  694. printk(KERN_DEBUG "Stopping Tx BA session for %s tid %d\n",
  695. print_mac(mac, ra), tid);
  696. #endif /* CONFIG_MAC80211_HT_DEBUG */
  697. rcu_read_lock();
  698. sta = sta_info_get(local, ra);
  699. if (!sta) {
  700. printk(KERN_DEBUG "Could not find station: %s\n",
  701. print_mac(mac, ra));
  702. rcu_read_unlock();
  703. return;
  704. }
  705. state = &sta->ampdu_mlme.tid_state_tx[tid];
  706. spin_lock_bh(&sta->lock);
  707. if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) {
  708. printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
  709. spin_unlock_bh(&sta->lock);
  710. rcu_read_unlock();
  711. return;
  712. }
  713. if (*state & HT_AGG_STATE_INITIATOR_MSK)
  714. ieee80211_send_delba(sta->sdata->dev, ra, tid,
  715. WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
  716. agg_queue = sta->tid_to_tx_q[tid];
  717. /* avoid ordering issues: we are the only one that can modify
  718. * the content of the qdiscs */
  719. spin_lock_bh(&local->mdev->queue_lock);
  720. /* remove the queue for this aggregation */
  721. ieee80211_ht_agg_queue_remove(local, sta, tid, 1);
  722. spin_unlock_bh(&local->mdev->queue_lock);
  723. /* we just requeued the all the frames that were in the removed
  724. * queue, and since we might miss a softirq we do netif_schedule.
  725. * ieee80211_wake_queue is not used here as this queue is not
  726. * necessarily stopped */
  727. netif_schedule(local->mdev);
  728. *state = HT_AGG_STATE_IDLE;
  729. sta->ampdu_mlme.addba_req_num[tid] = 0;
  730. kfree(sta->ampdu_mlme.tid_tx[tid]);
  731. sta->ampdu_mlme.tid_tx[tid] = NULL;
  732. spin_unlock_bh(&sta->lock);
  733. rcu_read_unlock();
  734. }
  735. EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb);
  736. void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
  737. const u8 *ra, u16 tid)
  738. {
  739. struct ieee80211_local *local = hw_to_local(hw);
  740. struct ieee80211_ra_tid *ra_tid;
  741. struct sk_buff *skb = dev_alloc_skb(0);
  742. if (unlikely(!skb)) {
  743. if (net_ratelimit())
  744. printk(KERN_WARNING "%s: Not enough memory, "
  745. "dropping start BA session", skb->dev->name);
  746. return;
  747. }
  748. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  749. memcpy(&ra_tid->ra, ra, ETH_ALEN);
  750. ra_tid->tid = tid;
  751. skb->pkt_type = IEEE80211_ADDBA_MSG;
  752. skb_queue_tail(&local->skb_queue, skb);
  753. tasklet_schedule(&local->tasklet);
  754. }
  755. EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
  756. void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
  757. const u8 *ra, u16 tid)
  758. {
  759. struct ieee80211_local *local = hw_to_local(hw);
  760. struct ieee80211_ra_tid *ra_tid;
  761. struct sk_buff *skb = dev_alloc_skb(0);
  762. if (unlikely(!skb)) {
  763. if (net_ratelimit())
  764. printk(KERN_WARNING "%s: Not enough memory, "
  765. "dropping stop BA session", skb->dev->name);
  766. return;
  767. }
  768. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  769. memcpy(&ra_tid->ra, ra, ETH_ALEN);
  770. ra_tid->tid = tid;
  771. skb->pkt_type = IEEE80211_DELBA_MSG;
  772. skb_queue_tail(&local->skb_queue, skb);
  773. tasklet_schedule(&local->tasklet);
  774. }
  775. EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
  776. static void ieee80211_set_multicast_list(struct net_device *dev)
  777. {
  778. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  779. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  780. int allmulti, promisc, sdata_allmulti, sdata_promisc;
  781. allmulti = !!(dev->flags & IFF_ALLMULTI);
  782. promisc = !!(dev->flags & IFF_PROMISC);
  783. sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
  784. sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC);
  785. if (allmulti != sdata_allmulti) {
  786. if (dev->flags & IFF_ALLMULTI)
  787. atomic_inc(&local->iff_allmultis);
  788. else
  789. atomic_dec(&local->iff_allmultis);
  790. sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
  791. }
  792. if (promisc != sdata_promisc) {
  793. if (dev->flags & IFF_PROMISC)
  794. atomic_inc(&local->iff_promiscs);
  795. else
  796. atomic_dec(&local->iff_promiscs);
  797. sdata->flags ^= IEEE80211_SDATA_PROMISC;
  798. }
  799. dev_mc_sync(local->mdev, dev);
  800. }
  801. static const struct header_ops ieee80211_header_ops = {
  802. .create = eth_header,
  803. .parse = header_parse_80211,
  804. .rebuild = eth_rebuild_header,
  805. .cache = eth_header_cache,
  806. .cache_update = eth_header_cache_update,
  807. };
  808. /* Must not be called for mdev */
  809. void ieee80211_if_setup(struct net_device *dev)
  810. {
  811. ether_setup(dev);
  812. dev->hard_start_xmit = ieee80211_subif_start_xmit;
  813. dev->wireless_handlers = &ieee80211_iw_handler_def;
  814. dev->set_multicast_list = ieee80211_set_multicast_list;
  815. dev->change_mtu = ieee80211_change_mtu;
  816. dev->open = ieee80211_open;
  817. dev->stop = ieee80211_stop;
  818. dev->destructor = ieee80211_if_free;
  819. }
  820. /* everything else */
  821. static int __ieee80211_if_config(struct net_device *dev,
  822. struct sk_buff *beacon,
  823. struct ieee80211_tx_control *control)
  824. {
  825. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  826. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  827. struct ieee80211_if_conf conf;
  828. if (!local->ops->config_interface || !netif_running(dev))
  829. return 0;
  830. memset(&conf, 0, sizeof(conf));
  831. conf.type = sdata->vif.type;
  832. if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
  833. sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
  834. conf.bssid = sdata->u.sta.bssid;
  835. conf.ssid = sdata->u.sta.ssid;
  836. conf.ssid_len = sdata->u.sta.ssid_len;
  837. } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
  838. conf.beacon = beacon;
  839. conf.beacon_control = control;
  840. ieee80211_start_mesh(dev);
  841. } else if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
  842. conf.ssid = sdata->u.ap.ssid;
  843. conf.ssid_len = sdata->u.ap.ssid_len;
  844. conf.beacon = beacon;
  845. conf.beacon_control = control;
  846. }
  847. return local->ops->config_interface(local_to_hw(local),
  848. &sdata->vif, &conf);
  849. }
  850. int ieee80211_if_config(struct net_device *dev)
  851. {
  852. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  853. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  854. if (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT &&
  855. (local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
  856. return ieee80211_if_config_beacon(dev);
  857. return __ieee80211_if_config(dev, NULL, NULL);
  858. }
  859. int ieee80211_if_config_beacon(struct net_device *dev)
  860. {
  861. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  862. struct ieee80211_tx_control control;
  863. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  864. struct sk_buff *skb;
  865. if (!(local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
  866. return 0;
  867. skb = ieee80211_beacon_get(local_to_hw(local), &sdata->vif,
  868. &control);
  869. if (!skb)
  870. return -ENOMEM;
  871. return __ieee80211_if_config(dev, skb, &control);
  872. }
  873. int ieee80211_hw_config(struct ieee80211_local *local)
  874. {
  875. struct ieee80211_channel *chan;
  876. int ret = 0;
  877. if (local->sta_sw_scanning)
  878. chan = local->scan_channel;
  879. else
  880. chan = local->oper_channel;
  881. local->hw.conf.channel = chan;
  882. if (!local->hw.conf.power_level)
  883. local->hw.conf.power_level = chan->max_power;
  884. else
  885. local->hw.conf.power_level = min(chan->max_power,
  886. local->hw.conf.power_level);
  887. local->hw.conf.max_antenna_gain = chan->max_antenna_gain;
  888. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  889. printk(KERN_DEBUG "%s: HW CONFIG: freq=%d\n",
  890. wiphy_name(local->hw.wiphy), chan->center_freq);
  891. #endif
  892. if (local->open_count)
  893. ret = local->ops->config(local_to_hw(local), &local->hw.conf);
  894. return ret;
  895. }
  896. /**
  897. * ieee80211_handle_ht should be used only after legacy configuration
  898. * has been determined namely band, as ht configuration depends upon
  899. * the hardware's HT abilities for a _specific_ band.
  900. */
  901. u32 ieee80211_handle_ht(struct ieee80211_local *local, int enable_ht,
  902. struct ieee80211_ht_info *req_ht_cap,
  903. struct ieee80211_ht_bss_info *req_bss_cap)
  904. {
  905. struct ieee80211_conf *conf = &local->hw.conf;
  906. struct ieee80211_supported_band *sband;
  907. struct ieee80211_ht_info ht_conf;
  908. struct ieee80211_ht_bss_info ht_bss_conf;
  909. int i;
  910. u32 changed = 0;
  911. sband = local->hw.wiphy->bands[conf->channel->band];
  912. /* HT is not supported */
  913. if (!sband->ht_info.ht_supported) {
  914. conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
  915. return 0;
  916. }
  917. memset(&ht_conf, 0, sizeof(struct ieee80211_ht_info));
  918. memset(&ht_bss_conf, 0, sizeof(struct ieee80211_ht_bss_info));
  919. if (enable_ht) {
  920. if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE))
  921. changed |= BSS_CHANGED_HT;
  922. conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE;
  923. ht_conf.ht_supported = 1;
  924. ht_conf.cap = req_ht_cap->cap & sband->ht_info.cap;
  925. ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS);
  926. ht_conf.cap |= sband->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS;
  927. for (i = 0; i < SUPP_MCS_SET_LEN; i++)
  928. ht_conf.supp_mcs_set[i] =
  929. sband->ht_info.supp_mcs_set[i] &
  930. req_ht_cap->supp_mcs_set[i];
  931. ht_bss_conf.primary_channel = req_bss_cap->primary_channel;
  932. ht_bss_conf.bss_cap = req_bss_cap->bss_cap;
  933. ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode;
  934. ht_conf.ampdu_factor = req_ht_cap->ampdu_factor;
  935. ht_conf.ampdu_density = req_ht_cap->ampdu_density;
  936. /* if bss configuration changed store the new one */
  937. if (memcmp(&conf->ht_conf, &ht_conf, sizeof(ht_conf)) ||
  938. memcmp(&conf->ht_bss_conf, &ht_bss_conf, sizeof(ht_bss_conf))) {
  939. changed |= BSS_CHANGED_HT;
  940. memcpy(&conf->ht_conf, &ht_conf, sizeof(ht_conf));
  941. memcpy(&conf->ht_bss_conf, &ht_bss_conf, sizeof(ht_bss_conf));
  942. }
  943. } else {
  944. if (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)
  945. changed |= BSS_CHANGED_HT;
  946. conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
  947. }
  948. return changed;
  949. }
  950. void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
  951. u32 changed)
  952. {
  953. struct ieee80211_local *local = sdata->local;
  954. if (!changed)
  955. return;
  956. if (local->ops->bss_info_changed)
  957. local->ops->bss_info_changed(local_to_hw(local),
  958. &sdata->vif,
  959. &sdata->bss_conf,
  960. changed);
  961. }
  962. void ieee80211_reset_erp_info(struct net_device *dev)
  963. {
  964. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  965. sdata->bss_conf.use_cts_prot = 0;
  966. sdata->bss_conf.use_short_preamble = 0;
  967. ieee80211_bss_info_change_notify(sdata,
  968. BSS_CHANGED_ERP_CTS_PROT |
  969. BSS_CHANGED_ERP_PREAMBLE);
  970. }
  971. void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
  972. struct sk_buff *skb,
  973. struct ieee80211_tx_status *status)
  974. {
  975. struct ieee80211_local *local = hw_to_local(hw);
  976. struct ieee80211_tx_status *saved;
  977. int tmp;
  978. skb->dev = local->mdev;
  979. saved = kmalloc(sizeof(struct ieee80211_tx_status), GFP_ATOMIC);
  980. if (unlikely(!saved)) {
  981. if (net_ratelimit())
  982. printk(KERN_WARNING "%s: Not enough memory, "
  983. "dropping tx status", skb->dev->name);
  984. /* should be dev_kfree_skb_irq, but due to this function being
  985. * named _irqsafe instead of just _irq we can't be sure that
  986. * people won't call it from non-irq contexts */
  987. dev_kfree_skb_any(skb);
  988. return;
  989. }
  990. memcpy(saved, status, sizeof(struct ieee80211_tx_status));
  991. /* copy pointer to saved status into skb->cb for use by tasklet */
  992. memcpy(skb->cb, &saved, sizeof(saved));
  993. skb->pkt_type = IEEE80211_TX_STATUS_MSG;
  994. skb_queue_tail(status->control.flags & IEEE80211_TXCTL_REQ_TX_STATUS ?
  995. &local->skb_queue : &local->skb_queue_unreliable, skb);
  996. tmp = skb_queue_len(&local->skb_queue) +
  997. skb_queue_len(&local->skb_queue_unreliable);
  998. while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
  999. (skb = skb_dequeue(&local->skb_queue_unreliable))) {
  1000. memcpy(&saved, skb->cb, sizeof(saved));
  1001. kfree(saved);
  1002. dev_kfree_skb_irq(skb);
  1003. tmp--;
  1004. I802_DEBUG_INC(local->tx_status_drop);
  1005. }
  1006. tasklet_schedule(&local->tasklet);
  1007. }
  1008. EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
  1009. static void ieee80211_tasklet_handler(unsigned long data)
  1010. {
  1011. struct ieee80211_local *local = (struct ieee80211_local *) data;
  1012. struct sk_buff *skb;
  1013. struct ieee80211_rx_status rx_status;
  1014. struct ieee80211_tx_status *tx_status;
  1015. struct ieee80211_ra_tid *ra_tid;
  1016. while ((skb = skb_dequeue(&local->skb_queue)) ||
  1017. (skb = skb_dequeue(&local->skb_queue_unreliable))) {
  1018. switch (skb->pkt_type) {
  1019. case IEEE80211_RX_MSG:
  1020. /* status is in skb->cb */
  1021. memcpy(&rx_status, skb->cb, sizeof(rx_status));
  1022. /* Clear skb->pkt_type in order to not confuse kernel
  1023. * netstack. */
  1024. skb->pkt_type = 0;
  1025. __ieee80211_rx(local_to_hw(local), skb, &rx_status);
  1026. break;
  1027. case IEEE80211_TX_STATUS_MSG:
  1028. /* get pointer to saved status out of skb->cb */
  1029. memcpy(&tx_status, skb->cb, sizeof(tx_status));
  1030. skb->pkt_type = 0;
  1031. ieee80211_tx_status(local_to_hw(local),
  1032. skb, tx_status);
  1033. kfree(tx_status);
  1034. break;
  1035. case IEEE80211_DELBA_MSG:
  1036. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  1037. ieee80211_stop_tx_ba_cb(local_to_hw(local),
  1038. ra_tid->ra, ra_tid->tid);
  1039. dev_kfree_skb(skb);
  1040. break;
  1041. case IEEE80211_ADDBA_MSG:
  1042. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  1043. ieee80211_start_tx_ba_cb(local_to_hw(local),
  1044. ra_tid->ra, ra_tid->tid);
  1045. dev_kfree_skb(skb);
  1046. break ;
  1047. default: /* should never get here! */
  1048. printk(KERN_ERR "%s: Unknown message type (%d)\n",
  1049. wiphy_name(local->hw.wiphy), skb->pkt_type);
  1050. dev_kfree_skb(skb);
  1051. break;
  1052. }
  1053. }
  1054. }
  1055. /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
  1056. * make a prepared TX frame (one that has been given to hw) to look like brand
  1057. * new IEEE 802.11 frame that is ready to go through TX processing again.
  1058. * Also, tx_packet_data in cb is restored from tx_control. */
  1059. static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
  1060. struct ieee80211_key *key,
  1061. struct sk_buff *skb,
  1062. struct ieee80211_tx_control *control)
  1063. {
  1064. int hdrlen, iv_len, mic_len;
  1065. struct ieee80211_tx_packet_data *pkt_data;
  1066. pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
  1067. pkt_data->ifindex = vif_to_sdata(control->vif)->dev->ifindex;
  1068. pkt_data->flags = 0;
  1069. if (control->flags & IEEE80211_TXCTL_REQ_TX_STATUS)
  1070. pkt_data->flags |= IEEE80211_TXPD_REQ_TX_STATUS;
  1071. if (control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)
  1072. pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT;
  1073. if (control->flags & IEEE80211_TXCTL_REQUEUE)
  1074. pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
  1075. if (control->flags & IEEE80211_TXCTL_EAPOL_FRAME)
  1076. pkt_data->flags |= IEEE80211_TXPD_EAPOL_FRAME;
  1077. pkt_data->queue = control->queue;
  1078. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  1079. if (!key)
  1080. goto no_key;
  1081. switch (key->conf.alg) {
  1082. case ALG_WEP:
  1083. iv_len = WEP_IV_LEN;
  1084. mic_len = WEP_ICV_LEN;
  1085. break;
  1086. case ALG_TKIP:
  1087. iv_len = TKIP_IV_LEN;
  1088. mic_len = TKIP_ICV_LEN;
  1089. break;
  1090. case ALG_CCMP:
  1091. iv_len = CCMP_HDR_LEN;
  1092. mic_len = CCMP_MIC_LEN;
  1093. break;
  1094. default:
  1095. goto no_key;
  1096. }
  1097. if (skb->len >= mic_len &&
  1098. !(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
  1099. skb_trim(skb, skb->len - mic_len);
  1100. if (skb->len >= iv_len && skb->len > hdrlen) {
  1101. memmove(skb->data + iv_len, skb->data, hdrlen);
  1102. skb_pull(skb, iv_len);
  1103. }
  1104. no_key:
  1105. {
  1106. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1107. u16 fc = le16_to_cpu(hdr->frame_control);
  1108. if ((fc & 0x8C) == 0x88) /* QoS Control Field */ {
  1109. fc &= ~IEEE80211_STYPE_QOS_DATA;
  1110. hdr->frame_control = cpu_to_le16(fc);
  1111. memmove(skb->data + 2, skb->data, hdrlen - 2);
  1112. skb_pull(skb, 2);
  1113. }
  1114. }
  1115. }
  1116. static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
  1117. struct sta_info *sta,
  1118. struct sk_buff *skb,
  1119. struct ieee80211_tx_status *status)
  1120. {
  1121. sta->tx_filtered_count++;
  1122. /*
  1123. * Clear the TX filter mask for this STA when sending the next
  1124. * packet. If the STA went to power save mode, this will happen
  1125. * happen when it wakes up for the next time.
  1126. */
  1127. set_sta_flags(sta, WLAN_STA_CLEAR_PS_FILT);
  1128. /*
  1129. * This code races in the following way:
  1130. *
  1131. * (1) STA sends frame indicating it will go to sleep and does so
  1132. * (2) hardware/firmware adds STA to filter list, passes frame up
  1133. * (3) hardware/firmware processes TX fifo and suppresses a frame
  1134. * (4) we get TX status before having processed the frame and
  1135. * knowing that the STA has gone to sleep.
  1136. *
  1137. * This is actually quite unlikely even when both those events are
  1138. * processed from interrupts coming in quickly after one another or
  1139. * even at the same time because we queue both TX status events and
  1140. * RX frames to be processed by a tasklet and process them in the
  1141. * same order that they were received or TX status last. Hence, there
  1142. * is no race as long as the frame RX is processed before the next TX
  1143. * status, which drivers can ensure, see below.
  1144. *
  1145. * Note that this can only happen if the hardware or firmware can
  1146. * actually add STAs to the filter list, if this is done by the
  1147. * driver in response to set_tim() (which will only reduce the race
  1148. * this whole filtering tries to solve, not completely solve it)
  1149. * this situation cannot happen.
  1150. *
  1151. * To completely solve this race drivers need to make sure that they
  1152. * (a) don't mix the irq-safe/not irq-safe TX status/RX processing
  1153. * functions and
  1154. * (b) always process RX events before TX status events if ordering
  1155. * can be unknown, for example with different interrupt status
  1156. * bits.
  1157. */
  1158. if (test_sta_flags(sta, WLAN_STA_PS) &&
  1159. skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) {
  1160. ieee80211_remove_tx_extra(local, sta->key, skb,
  1161. &status->control);
  1162. skb_queue_tail(&sta->tx_filtered, skb);
  1163. return;
  1164. }
  1165. if (!test_sta_flags(sta, WLAN_STA_PS) &&
  1166. !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) {
  1167. /* Software retry the packet once */
  1168. status->control.flags |= IEEE80211_TXCTL_REQUEUE;
  1169. ieee80211_remove_tx_extra(local, sta->key, skb,
  1170. &status->control);
  1171. dev_queue_xmit(skb);
  1172. return;
  1173. }
  1174. if (net_ratelimit())
  1175. printk(KERN_DEBUG "%s: dropped TX filtered frame, "
  1176. "queue_len=%d PS=%d @%lu\n",
  1177. wiphy_name(local->hw.wiphy),
  1178. skb_queue_len(&sta->tx_filtered),
  1179. !!test_sta_flags(sta, WLAN_STA_PS), jiffies);
  1180. dev_kfree_skb(skb);
  1181. }
  1182. void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
  1183. struct ieee80211_tx_status *status)
  1184. {
  1185. struct sk_buff *skb2;
  1186. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1187. struct ieee80211_local *local = hw_to_local(hw);
  1188. u16 frag, type;
  1189. struct ieee80211_tx_status_rtap_hdr *rthdr;
  1190. struct ieee80211_sub_if_data *sdata;
  1191. struct net_device *prev_dev = NULL;
  1192. if (!status) {
  1193. printk(KERN_ERR
  1194. "%s: ieee80211_tx_status called with NULL status\n",
  1195. wiphy_name(local->hw.wiphy));
  1196. dev_kfree_skb(skb);
  1197. return;
  1198. }
  1199. rcu_read_lock();
  1200. if (status->excessive_retries) {
  1201. struct sta_info *sta;
  1202. sta = sta_info_get(local, hdr->addr1);
  1203. if (sta) {
  1204. if (test_sta_flags(sta, WLAN_STA_PS)) {
  1205. /*
  1206. * The STA is in power save mode, so assume
  1207. * that this TX packet failed because of that.
  1208. */
  1209. status->excessive_retries = 0;
  1210. status->flags |= IEEE80211_TX_STATUS_TX_FILTERED;
  1211. ieee80211_handle_filtered_frame(local, sta,
  1212. skb, status);
  1213. rcu_read_unlock();
  1214. return;
  1215. }
  1216. }
  1217. }
  1218. if (status->flags & IEEE80211_TX_STATUS_TX_FILTERED) {
  1219. struct sta_info *sta;
  1220. sta = sta_info_get(local, hdr->addr1);
  1221. if (sta) {
  1222. ieee80211_handle_filtered_frame(local, sta, skb,
  1223. status);
  1224. rcu_read_unlock();
  1225. return;
  1226. }
  1227. } else
  1228. rate_control_tx_status(local->mdev, skb, status);
  1229. rcu_read_unlock();
  1230. ieee80211_led_tx(local, 0);
  1231. /* SNMP counters
  1232. * Fragments are passed to low-level drivers as separate skbs, so these
  1233. * are actually fragments, not frames. Update frame counters only for
  1234. * the first fragment of the frame. */
  1235. frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
  1236. type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
  1237. if (status->flags & IEEE80211_TX_STATUS_ACK) {
  1238. if (frag == 0) {
  1239. local->dot11TransmittedFrameCount++;
  1240. if (is_multicast_ether_addr(hdr->addr1))
  1241. local->dot11MulticastTransmittedFrameCount++;
  1242. if (status->retry_count > 0)
  1243. local->dot11RetryCount++;
  1244. if (status->retry_count > 1)
  1245. local->dot11MultipleRetryCount++;
  1246. }
  1247. /* This counter shall be incremented for an acknowledged MPDU
  1248. * with an individual address in the address 1 field or an MPDU
  1249. * with a multicast address in the address 1 field of type Data
  1250. * or Management. */
  1251. if (!is_multicast_ether_addr(hdr->addr1) ||
  1252. type == IEEE80211_FTYPE_DATA ||
  1253. type == IEEE80211_FTYPE_MGMT)
  1254. local->dot11TransmittedFragmentCount++;
  1255. } else {
  1256. if (frag == 0)
  1257. local->dot11FailedCount++;
  1258. }
  1259. /* this was a transmitted frame, but now we want to reuse it */
  1260. skb_orphan(skb);
  1261. /*
  1262. * This is a bit racy but we can avoid a lot of work
  1263. * with this test...
  1264. */
  1265. if (!local->monitors && !local->cooked_mntrs) {
  1266. dev_kfree_skb(skb);
  1267. return;
  1268. }
  1269. /* send frame to monitor interfaces now */
  1270. if (skb_headroom(skb) < sizeof(*rthdr)) {
  1271. printk(KERN_ERR "ieee80211_tx_status: headroom too small\n");
  1272. dev_kfree_skb(skb);
  1273. return;
  1274. }
  1275. rthdr = (struct ieee80211_tx_status_rtap_hdr *)
  1276. skb_push(skb, sizeof(*rthdr));
  1277. memset(rthdr, 0, sizeof(*rthdr));
  1278. rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
  1279. rthdr->hdr.it_present =
  1280. cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
  1281. (1 << IEEE80211_RADIOTAP_DATA_RETRIES));
  1282. if (!(status->flags & IEEE80211_TX_STATUS_ACK) &&
  1283. !is_multicast_ether_addr(hdr->addr1))
  1284. rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
  1285. if ((status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) &&
  1286. (status->control.flags & IEEE80211_TXCTL_USE_CTS_PROTECT))
  1287. rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
  1288. else if (status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS)
  1289. rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
  1290. rthdr->data_retries = status->retry_count;
  1291. /* XXX: is this sufficient for BPF? */
  1292. skb_set_mac_header(skb, 0);
  1293. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1294. skb->pkt_type = PACKET_OTHERHOST;
  1295. skb->protocol = htons(ETH_P_802_2);
  1296. memset(skb->cb, 0, sizeof(skb->cb));
  1297. rcu_read_lock();
  1298. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  1299. if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) {
  1300. if (!netif_running(sdata->dev))
  1301. continue;
  1302. if (prev_dev) {
  1303. skb2 = skb_clone(skb, GFP_ATOMIC);
  1304. if (skb2) {
  1305. skb2->dev = prev_dev;
  1306. netif_rx(skb2);
  1307. }
  1308. }
  1309. prev_dev = sdata->dev;
  1310. }
  1311. }
  1312. if (prev_dev) {
  1313. skb->dev = prev_dev;
  1314. netif_rx(skb);
  1315. skb = NULL;
  1316. }
  1317. rcu_read_unlock();
  1318. dev_kfree_skb(skb);
  1319. }
  1320. EXPORT_SYMBOL(ieee80211_tx_status);
  1321. struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
  1322. const struct ieee80211_ops *ops)
  1323. {
  1324. struct ieee80211_local *local;
  1325. int priv_size;
  1326. struct wiphy *wiphy;
  1327. /* Ensure 32-byte alignment of our private data and hw private data.
  1328. * We use the wiphy priv data for both our ieee80211_local and for
  1329. * the driver's private data
  1330. *
  1331. * In memory it'll be like this:
  1332. *
  1333. * +-------------------------+
  1334. * | struct wiphy |
  1335. * +-------------------------+
  1336. * | struct ieee80211_local |
  1337. * +-------------------------+
  1338. * | driver's private data |
  1339. * +-------------------------+
  1340. *
  1341. */
  1342. priv_size = ((sizeof(struct ieee80211_local) +
  1343. NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
  1344. priv_data_len;
  1345. wiphy = wiphy_new(&mac80211_config_ops, priv_size);
  1346. if (!wiphy)
  1347. return NULL;
  1348. wiphy->privid = mac80211_wiphy_privid;
  1349. local = wiphy_priv(wiphy);
  1350. local->hw.wiphy = wiphy;
  1351. local->hw.priv = (char *)local +
  1352. ((sizeof(struct ieee80211_local) +
  1353. NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
  1354. BUG_ON(!ops->tx);
  1355. BUG_ON(!ops->start);
  1356. BUG_ON(!ops->stop);
  1357. BUG_ON(!ops->config);
  1358. BUG_ON(!ops->add_interface);
  1359. BUG_ON(!ops->remove_interface);
  1360. BUG_ON(!ops->configure_filter);
  1361. local->ops = ops;
  1362. local->hw.queues = 1; /* default */
  1363. local->bridge_packets = 1;
  1364. local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  1365. local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
  1366. local->short_retry_limit = 7;
  1367. local->long_retry_limit = 4;
  1368. local->hw.conf.radio_enabled = 1;
  1369. INIT_LIST_HEAD(&local->interfaces);
  1370. spin_lock_init(&local->key_lock);
  1371. INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work);
  1372. sta_info_init(local);
  1373. tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
  1374. (unsigned long)local);
  1375. tasklet_disable(&local->tx_pending_tasklet);
  1376. tasklet_init(&local->tasklet,
  1377. ieee80211_tasklet_handler,
  1378. (unsigned long) local);
  1379. tasklet_disable(&local->tasklet);
  1380. skb_queue_head_init(&local->skb_queue);
  1381. skb_queue_head_init(&local->skb_queue_unreliable);
  1382. return local_to_hw(local);
  1383. }
  1384. EXPORT_SYMBOL(ieee80211_alloc_hw);
  1385. int ieee80211_register_hw(struct ieee80211_hw *hw)
  1386. {
  1387. struct ieee80211_local *local = hw_to_local(hw);
  1388. const char *name;
  1389. int result;
  1390. enum ieee80211_band band;
  1391. struct net_device *mdev;
  1392. struct ieee80211_sub_if_data *sdata;
  1393. /*
  1394. * generic code guarantees at least one band,
  1395. * set this very early because much code assumes
  1396. * that hw.conf.channel is assigned
  1397. */
  1398. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  1399. struct ieee80211_supported_band *sband;
  1400. sband = local->hw.wiphy->bands[band];
  1401. if (sband) {
  1402. /* init channel we're on */
  1403. local->hw.conf.channel =
  1404. local->oper_channel =
  1405. local->scan_channel = &sband->channels[0];
  1406. break;
  1407. }
  1408. }
  1409. result = wiphy_register(local->hw.wiphy);
  1410. if (result < 0)
  1411. return result;
  1412. /* for now, mdev needs sub_if_data :/ */
  1413. mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
  1414. "wmaster%d", ether_setup);
  1415. if (!mdev)
  1416. goto fail_mdev_alloc;
  1417. sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
  1418. mdev->ieee80211_ptr = &sdata->wdev;
  1419. sdata->wdev.wiphy = local->hw.wiphy;
  1420. local->mdev = mdev;
  1421. ieee80211_rx_bss_list_init(mdev);
  1422. mdev->hard_start_xmit = ieee80211_master_start_xmit;
  1423. mdev->open = ieee80211_master_open;
  1424. mdev->stop = ieee80211_master_stop;
  1425. mdev->type = ARPHRD_IEEE80211;
  1426. mdev->header_ops = &ieee80211_header_ops;
  1427. mdev->set_multicast_list = ieee80211_master_set_multicast_list;
  1428. sdata->vif.type = IEEE80211_IF_TYPE_AP;
  1429. sdata->dev = mdev;
  1430. sdata->local = local;
  1431. sdata->u.ap.force_unicast_rateidx = -1;
  1432. sdata->u.ap.max_ratectrl_rateidx = -1;
  1433. ieee80211_if_sdata_init(sdata);
  1434. /* no RCU needed since we're still during init phase */
  1435. list_add_tail(&sdata->list, &local->interfaces);
  1436. name = wiphy_dev(local->hw.wiphy)->driver->name;
  1437. local->hw.workqueue = create_singlethread_workqueue(name);
  1438. if (!local->hw.workqueue) {
  1439. result = -ENOMEM;
  1440. goto fail_workqueue;
  1441. }
  1442. /*
  1443. * The hardware needs headroom for sending the frame,
  1444. * and we need some headroom for passing the frame to monitor
  1445. * interfaces, but never both at the same time.
  1446. */
  1447. local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
  1448. sizeof(struct ieee80211_tx_status_rtap_hdr));
  1449. debugfs_hw_add(local);
  1450. local->hw.conf.beacon_int = 1000;
  1451. local->wstats_flags |= local->hw.max_rssi ?
  1452. IW_QUAL_LEVEL_UPDATED : IW_QUAL_LEVEL_INVALID;
  1453. local->wstats_flags |= local->hw.max_signal ?
  1454. IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
  1455. local->wstats_flags |= local->hw.max_noise ?
  1456. IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
  1457. if (local->hw.max_rssi < 0 || local->hw.max_noise < 0)
  1458. local->wstats_flags |= IW_QUAL_DBM;
  1459. result = sta_info_start(local);
  1460. if (result < 0)
  1461. goto fail_sta_info;
  1462. rtnl_lock();
  1463. result = dev_alloc_name(local->mdev, local->mdev->name);
  1464. if (result < 0)
  1465. goto fail_dev;
  1466. memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
  1467. SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy));
  1468. result = register_netdevice(local->mdev);
  1469. if (result < 0)
  1470. goto fail_dev;
  1471. ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
  1472. ieee80211_if_set_type(local->mdev, IEEE80211_IF_TYPE_AP);
  1473. result = ieee80211_init_rate_ctrl_alg(local,
  1474. hw->rate_control_algorithm);
  1475. if (result < 0) {
  1476. printk(KERN_DEBUG "%s: Failed to initialize rate control "
  1477. "algorithm\n", wiphy_name(local->hw.wiphy));
  1478. goto fail_rate;
  1479. }
  1480. result = ieee80211_wep_init(local);
  1481. if (result < 0) {
  1482. printk(KERN_DEBUG "%s: Failed to initialize wep\n",
  1483. wiphy_name(local->hw.wiphy));
  1484. goto fail_wep;
  1485. }
  1486. if (hw->queues > IEEE80211_MAX_QUEUES)
  1487. hw->queues = IEEE80211_MAX_QUEUES;
  1488. if (hw->ampdu_queues > IEEE80211_MAX_AMPDU_QUEUES)
  1489. hw->ampdu_queues = IEEE80211_MAX_AMPDU_QUEUES;
  1490. ieee80211_install_qdisc(local->mdev);
  1491. /* add one default STA interface */
  1492. result = ieee80211_if_add(local->mdev, "wlan%d", NULL,
  1493. IEEE80211_IF_TYPE_STA, NULL);
  1494. if (result)
  1495. printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
  1496. wiphy_name(local->hw.wiphy));
  1497. local->reg_state = IEEE80211_DEV_REGISTERED;
  1498. rtnl_unlock();
  1499. ieee80211_led_init(local);
  1500. return 0;
  1501. fail_wep:
  1502. rate_control_deinitialize(local);
  1503. fail_rate:
  1504. ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
  1505. unregister_netdevice(local->mdev);
  1506. fail_dev:
  1507. rtnl_unlock();
  1508. sta_info_stop(local);
  1509. fail_sta_info:
  1510. debugfs_hw_del(local);
  1511. destroy_workqueue(local->hw.workqueue);
  1512. fail_workqueue:
  1513. ieee80211_if_free(local->mdev);
  1514. local->mdev = NULL;
  1515. fail_mdev_alloc:
  1516. wiphy_unregister(local->hw.wiphy);
  1517. return result;
  1518. }
  1519. EXPORT_SYMBOL(ieee80211_register_hw);
  1520. void ieee80211_unregister_hw(struct ieee80211_hw *hw)
  1521. {
  1522. struct ieee80211_local *local = hw_to_local(hw);
  1523. struct ieee80211_sub_if_data *sdata, *tmp;
  1524. tasklet_kill(&local->tx_pending_tasklet);
  1525. tasklet_kill(&local->tasklet);
  1526. rtnl_lock();
  1527. BUG_ON(local->reg_state != IEEE80211_DEV_REGISTERED);
  1528. local->reg_state = IEEE80211_DEV_UNREGISTERED;
  1529. /*
  1530. * At this point, interface list manipulations are fine
  1531. * because the driver cannot be handing us frames any
  1532. * more and the tasklet is killed.
  1533. */
  1534. /*
  1535. * First, we remove all non-master interfaces. Do this because they
  1536. * may have bss pointer dependency on the master, and when we free
  1537. * the master these would be freed as well, breaking our list
  1538. * iteration completely.
  1539. */
  1540. list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
  1541. if (sdata->dev == local->mdev)
  1542. continue;
  1543. list_del(&sdata->list);
  1544. __ieee80211_if_del(local, sdata);
  1545. }
  1546. /* then, finally, remove the master interface */
  1547. __ieee80211_if_del(local, IEEE80211_DEV_TO_SUB_IF(local->mdev));
  1548. rtnl_unlock();
  1549. ieee80211_rx_bss_list_deinit(local->mdev);
  1550. ieee80211_clear_tx_pending(local);
  1551. sta_info_stop(local);
  1552. rate_control_deinitialize(local);
  1553. debugfs_hw_del(local);
  1554. if (skb_queue_len(&local->skb_queue)
  1555. || skb_queue_len(&local->skb_queue_unreliable))
  1556. printk(KERN_WARNING "%s: skb_queue not empty\n",
  1557. wiphy_name(local->hw.wiphy));
  1558. skb_queue_purge(&local->skb_queue);
  1559. skb_queue_purge(&local->skb_queue_unreliable);
  1560. destroy_workqueue(local->hw.workqueue);
  1561. wiphy_unregister(local->hw.wiphy);
  1562. ieee80211_wep_free(local);
  1563. ieee80211_led_exit(local);
  1564. ieee80211_if_free(local->mdev);
  1565. local->mdev = NULL;
  1566. }
  1567. EXPORT_SYMBOL(ieee80211_unregister_hw);
  1568. void ieee80211_free_hw(struct ieee80211_hw *hw)
  1569. {
  1570. struct ieee80211_local *local = hw_to_local(hw);
  1571. wiphy_free(local->hw.wiphy);
  1572. }
  1573. EXPORT_SYMBOL(ieee80211_free_hw);
  1574. static int __init ieee80211_init(void)
  1575. {
  1576. struct sk_buff *skb;
  1577. int ret;
  1578. BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb));
  1579. ret = rc80211_pid_init();
  1580. if (ret)
  1581. goto out;
  1582. ret = ieee80211_wme_register();
  1583. if (ret) {
  1584. printk(KERN_DEBUG "ieee80211_init: failed to "
  1585. "initialize WME (err=%d)\n", ret);
  1586. goto out_cleanup_pid;
  1587. }
  1588. ieee80211_debugfs_netdev_init();
  1589. return 0;
  1590. out_cleanup_pid:
  1591. rc80211_pid_exit();
  1592. out:
  1593. return ret;
  1594. }
  1595. static void __exit ieee80211_exit(void)
  1596. {
  1597. rc80211_pid_exit();
  1598. /*
  1599. * For key todo, it'll be empty by now but the work
  1600. * might still be scheduled.
  1601. */
  1602. flush_scheduled_work();
  1603. if (mesh_allocated)
  1604. ieee80211s_stop();
  1605. ieee80211_wme_unregister();
  1606. ieee80211_debugfs_netdev_exit();
  1607. }
  1608. subsys_initcall(ieee80211_init);
  1609. module_exit(ieee80211_exit);
  1610. MODULE_DESCRIPTION("IEEE 802.11 subsystem");
  1611. MODULE_LICENSE("GPL");