ieee80211.c 50 KB

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