ieee80211.c 52 KB

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