ieee80211.c 47 KB

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