ieee80211.c 51 KB

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