ieee80211.c 51 KB

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