main.c 50 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 "rate.h"
  27. #include "mesh.h"
  28. #include "wep.h"
  29. #include "wme.h"
  30. #include "aes_ccm.h"
  31. #include "led.h"
  32. #include "cfg.h"
  33. #include "debugfs.h"
  34. #include "debugfs_netdev.h"
  35. /*
  36. * For seeing transmitted packets on monitor interfaces
  37. * we have a radiotap header too.
  38. */
  39. struct ieee80211_tx_status_rtap_hdr {
  40. struct ieee80211_radiotap_header hdr;
  41. __le16 tx_flags;
  42. u8 data_retries;
  43. } __attribute__ ((packed));
  44. /* common interface routines */
  45. static int header_parse_80211(const struct sk_buff *skb, unsigned char *haddr)
  46. {
  47. memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
  48. return ETH_ALEN;
  49. }
  50. /* must be called under mdev tx lock */
  51. static void ieee80211_configure_filter(struct ieee80211_local *local)
  52. {
  53. unsigned int changed_flags;
  54. unsigned int new_flags = 0;
  55. if (atomic_read(&local->iff_promiscs))
  56. new_flags |= FIF_PROMISC_IN_BSS;
  57. if (atomic_read(&local->iff_allmultis))
  58. new_flags |= FIF_ALLMULTI;
  59. if (local->monitors)
  60. new_flags |= FIF_BCN_PRBRESP_PROMISC;
  61. if (local->fif_fcsfail)
  62. new_flags |= FIF_FCSFAIL;
  63. if (local->fif_plcpfail)
  64. new_flags |= FIF_PLCPFAIL;
  65. if (local->fif_control)
  66. new_flags |= FIF_CONTROL;
  67. if (local->fif_other_bss)
  68. new_flags |= FIF_OTHER_BSS;
  69. changed_flags = local->filter_flags ^ new_flags;
  70. /* be a bit nasty */
  71. new_flags |= (1<<31);
  72. local->ops->configure_filter(local_to_hw(local),
  73. changed_flags, &new_flags,
  74. local->mdev->mc_count,
  75. local->mdev->mc_list);
  76. WARN_ON(new_flags & (1<<31));
  77. local->filter_flags = new_flags & ~(1<<31);
  78. }
  79. /* master interface */
  80. static int ieee80211_master_open(struct net_device *dev)
  81. {
  82. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  83. struct ieee80211_sub_if_data *sdata;
  84. int res = -EOPNOTSUPP;
  85. /* we hold the RTNL here so can safely walk the list */
  86. list_for_each_entry(sdata, &local->interfaces, list) {
  87. if (netif_running(sdata->dev)) {
  88. res = 0;
  89. break;
  90. }
  91. }
  92. if (res)
  93. return res;
  94. netif_tx_start_all_queues(local->mdev);
  95. return 0;
  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 (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. 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 sta_info *sta;
  150. struct ieee80211_if_init_conf conf;
  151. u32 changed = 0;
  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 && 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. * The remaining checks are only performed for interfaces
  174. * with the same MAC address.
  175. */
  176. if (compare_ether_addr(dev->dev_addr, ndev->dev_addr))
  177. continue;
  178. /*
  179. * check whether it may have the same address
  180. */
  181. if (!identical_mac_addr_allowed(sdata->vif.type,
  182. nsdata->vif.type))
  183. return -ENOTUNIQ;
  184. /*
  185. * can only add VLANs to enabled APs
  186. */
  187. if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN &&
  188. nsdata->vif.type == IEEE80211_IF_TYPE_AP)
  189. sdata->bss = &nsdata->u.ap;
  190. }
  191. }
  192. switch (sdata->vif.type) {
  193. case IEEE80211_IF_TYPE_WDS:
  194. if (!is_valid_ether_addr(sdata->u.wds.remote_addr))
  195. return -ENOLINK;
  196. break;
  197. case IEEE80211_IF_TYPE_VLAN:
  198. if (!sdata->bss)
  199. return -ENOLINK;
  200. list_add(&sdata->u.vlan.list, &sdata->bss->vlans);
  201. break;
  202. case IEEE80211_IF_TYPE_AP:
  203. sdata->bss = &sdata->u.ap;
  204. break;
  205. case IEEE80211_IF_TYPE_MESH_POINT:
  206. /* mesh ifaces must set allmulti to forward mcast traffic */
  207. atomic_inc(&local->iff_allmultis);
  208. break;
  209. case IEEE80211_IF_TYPE_STA:
  210. case IEEE80211_IF_TYPE_MNTR:
  211. case IEEE80211_IF_TYPE_IBSS:
  212. /* no special treatment */
  213. break;
  214. case IEEE80211_IF_TYPE_INVALID:
  215. /* cannot happen */
  216. WARN_ON(1);
  217. break;
  218. }
  219. if (local->open_count == 0) {
  220. res = 0;
  221. if (local->ops->start)
  222. res = local->ops->start(local_to_hw(local));
  223. if (res)
  224. goto err_del_bss;
  225. need_hw_reconfig = 1;
  226. ieee80211_led_radio(local, local->hw.conf.radio_enabled);
  227. }
  228. switch (sdata->vif.type) {
  229. case IEEE80211_IF_TYPE_VLAN:
  230. /* no need to tell driver */
  231. break;
  232. case IEEE80211_IF_TYPE_MNTR:
  233. if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
  234. local->cooked_mntrs++;
  235. break;
  236. }
  237. /* must be before the call to ieee80211_configure_filter */
  238. local->monitors++;
  239. if (local->monitors == 1)
  240. local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
  241. if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
  242. local->fif_fcsfail++;
  243. if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
  244. local->fif_plcpfail++;
  245. if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
  246. local->fif_control++;
  247. if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
  248. local->fif_other_bss++;
  249. netif_addr_lock_bh(local->mdev);
  250. ieee80211_configure_filter(local);
  251. netif_addr_unlock_bh(local->mdev);
  252. break;
  253. case IEEE80211_IF_TYPE_STA:
  254. case IEEE80211_IF_TYPE_IBSS:
  255. sdata->u.sta.flags &= ~IEEE80211_STA_PREV_BSSID_SET;
  256. /* fall through */
  257. default:
  258. conf.vif = &sdata->vif;
  259. conf.type = sdata->vif.type;
  260. conf.mac_addr = dev->dev_addr;
  261. res = local->ops->add_interface(local_to_hw(local), &conf);
  262. if (res)
  263. goto err_stop;
  264. if (ieee80211_vif_is_mesh(&sdata->vif))
  265. ieee80211_start_mesh(sdata->dev);
  266. changed |= ieee80211_reset_erp_info(dev);
  267. ieee80211_bss_info_change_notify(sdata, changed);
  268. ieee80211_enable_keys(sdata);
  269. if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
  270. !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
  271. netif_carrier_off(dev);
  272. else
  273. netif_carrier_on(dev);
  274. }
  275. if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
  276. /* Create STA entry for the WDS peer */
  277. sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
  278. GFP_KERNEL);
  279. if (!sta) {
  280. res = -ENOMEM;
  281. goto err_del_interface;
  282. }
  283. /* no locking required since STA is not live yet */
  284. sta->flags |= WLAN_STA_AUTHORIZED;
  285. res = sta_info_insert(sta);
  286. if (res) {
  287. /* STA has been freed */
  288. goto err_del_interface;
  289. }
  290. }
  291. if (local->open_count == 0) {
  292. res = dev_open(local->mdev);
  293. WARN_ON(res);
  294. if (res)
  295. goto err_del_interface;
  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. /*
  312. * ieee80211_sta_work is disabled while network interface
  313. * is down. Therefore, some configuration changes may not
  314. * yet be effective. Trigger execution of ieee80211_sta_work
  315. * to fix this.
  316. */
  317. if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
  318. sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
  319. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  320. queue_work(local->hw.workqueue, &ifsta->work);
  321. }
  322. netif_tx_start_all_queues(dev);
  323. return 0;
  324. err_del_interface:
  325. local->ops->remove_interface(local_to_hw(local), &conf);
  326. err_stop:
  327. if (!local->open_count && local->ops->stop)
  328. local->ops->stop(local_to_hw(local));
  329. err_del_bss:
  330. sdata->bss = NULL;
  331. if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
  332. list_del(&sdata->u.vlan.list);
  333. return res;
  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_tx_stop_all_queues(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. /* no need to tell driver */
  402. break;
  403. case IEEE80211_IF_TYPE_MNTR:
  404. if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
  405. local->cooked_mntrs--;
  406. break;
  407. }
  408. local->monitors--;
  409. if (local->monitors == 0)
  410. local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
  411. if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
  412. local->fif_fcsfail--;
  413. if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
  414. local->fif_plcpfail--;
  415. if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
  416. local->fif_control--;
  417. if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
  418. local->fif_other_bss--;
  419. netif_addr_lock_bh(local->mdev);
  420. ieee80211_configure_filter(local);
  421. netif_addr_unlock_bh(local->mdev);
  422. break;
  423. case IEEE80211_IF_TYPE_MESH_POINT:
  424. /* allmulti is always set on mesh ifaces */
  425. atomic_dec(&local->iff_allmultis);
  426. /* fall through */
  427. case IEEE80211_IF_TYPE_STA:
  428. case IEEE80211_IF_TYPE_IBSS:
  429. sdata->u.sta.state = IEEE80211_DISABLED;
  430. memset(sdata->u.sta.bssid, 0, ETH_ALEN);
  431. del_timer_sync(&sdata->u.sta.timer);
  432. /*
  433. * When we get here, the interface is marked down.
  434. * Call synchronize_rcu() to wait for the RX path
  435. * should it be using the interface and enqueuing
  436. * frames at this very time on another CPU.
  437. */
  438. synchronize_rcu();
  439. skb_queue_purge(&sdata->u.sta.skb_queue);
  440. if (local->scan_dev == sdata->dev) {
  441. if (!local->ops->hw_scan) {
  442. local->sta_sw_scanning = 0;
  443. cancel_delayed_work(&local->scan_work);
  444. } else
  445. local->sta_hw_scanning = 0;
  446. }
  447. sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
  448. kfree(sdata->u.sta.extra_ie);
  449. sdata->u.sta.extra_ie = NULL;
  450. sdata->u.sta.extra_ie_len = 0;
  451. /* fall through */
  452. default:
  453. conf.vif = &sdata->vif;
  454. conf.type = sdata->vif.type;
  455. conf.mac_addr = dev->dev_addr;
  456. /* disable all keys for as long as this netdev is down */
  457. ieee80211_disable_keys(sdata);
  458. local->ops->remove_interface(local_to_hw(local), &conf);
  459. }
  460. sdata->bss = NULL;
  461. if (local->open_count == 0) {
  462. if (netif_running(local->mdev))
  463. dev_close(local->mdev);
  464. if (local->ops->stop)
  465. local->ops->stop(local_to_hw(local));
  466. ieee80211_led_radio(local, 0);
  467. flush_workqueue(local->hw.workqueue);
  468. tasklet_disable(&local->tx_pending_tasklet);
  469. tasklet_disable(&local->tasklet);
  470. }
  471. return 0;
  472. }
  473. int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
  474. {
  475. struct ieee80211_local *local = hw_to_local(hw);
  476. struct sta_info *sta;
  477. struct ieee80211_sub_if_data *sdata;
  478. u16 start_seq_num = 0;
  479. u8 *state;
  480. int ret;
  481. DECLARE_MAC_BUF(mac);
  482. if (tid >= STA_TID_NUM)
  483. return -EINVAL;
  484. #ifdef CONFIG_MAC80211_HT_DEBUG
  485. printk(KERN_DEBUG "Open BA session requested for %s tid %u\n",
  486. print_mac(mac, ra), tid);
  487. #endif /* CONFIG_MAC80211_HT_DEBUG */
  488. rcu_read_lock();
  489. sta = sta_info_get(local, ra);
  490. if (!sta) {
  491. #ifdef CONFIG_MAC80211_HT_DEBUG
  492. printk(KERN_DEBUG "Could not find the station\n");
  493. #endif
  494. ret = -ENOENT;
  495. goto exit;
  496. }
  497. spin_lock_bh(&sta->lock);
  498. /* we have tried too many times, receiver does not want A-MPDU */
  499. if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) {
  500. ret = -EBUSY;
  501. goto err_unlock_sta;
  502. }
  503. state = &sta->ampdu_mlme.tid_state_tx[tid];
  504. /* check if the TID is not in aggregation flow already */
  505. if (*state != HT_AGG_STATE_IDLE) {
  506. #ifdef CONFIG_MAC80211_HT_DEBUG
  507. printk(KERN_DEBUG "BA request denied - session is not "
  508. "idle on tid %u\n", tid);
  509. #endif /* CONFIG_MAC80211_HT_DEBUG */
  510. ret = -EAGAIN;
  511. goto err_unlock_sta;
  512. }
  513. /* prepare A-MPDU MLME for Tx aggregation */
  514. sta->ampdu_mlme.tid_tx[tid] =
  515. kmalloc(sizeof(struct tid_ampdu_tx), GFP_ATOMIC);
  516. if (!sta->ampdu_mlme.tid_tx[tid]) {
  517. #ifdef CONFIG_MAC80211_HT_DEBUG
  518. if (net_ratelimit())
  519. printk(KERN_ERR "allocate tx mlme to tid %d failed\n",
  520. tid);
  521. #endif
  522. ret = -ENOMEM;
  523. goto err_unlock_sta;
  524. }
  525. /* Tx timer */
  526. sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.function =
  527. sta_addba_resp_timer_expired;
  528. sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.data =
  529. (unsigned long)&sta->timer_to_tid[tid];
  530. init_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
  531. /* create a new queue for this aggregation */
  532. ret = ieee80211_ht_agg_queue_add(local, sta, tid);
  533. /* case no queue is available to aggregation
  534. * don't switch to aggregation */
  535. if (ret) {
  536. #ifdef CONFIG_MAC80211_HT_DEBUG
  537. printk(KERN_DEBUG "BA request denied - queue unavailable for"
  538. " tid %d\n", tid);
  539. #endif /* CONFIG_MAC80211_HT_DEBUG */
  540. goto err_unlock_queue;
  541. }
  542. sdata = sta->sdata;
  543. /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
  544. * call back right away, it must see that the flow has begun */
  545. *state |= HT_ADDBA_REQUESTED_MSK;
  546. if (local->ops->ampdu_action)
  547. ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START,
  548. ra, tid, &start_seq_num);
  549. if (ret) {
  550. /* No need to requeue the packets in the agg queue, since we
  551. * held the tx lock: no packet could be enqueued to the newly
  552. * allocated queue */
  553. ieee80211_ht_agg_queue_remove(local, sta, tid, 0);
  554. #ifdef CONFIG_MAC80211_HT_DEBUG
  555. printk(KERN_DEBUG "BA request denied - HW unavailable for"
  556. " tid %d\n", tid);
  557. #endif /* CONFIG_MAC80211_HT_DEBUG */
  558. *state = HT_AGG_STATE_IDLE;
  559. goto err_unlock_queue;
  560. }
  561. /* Will put all the packets in the new SW queue */
  562. ieee80211_requeue(local, ieee802_1d_to_ac[tid]);
  563. spin_unlock_bh(&sta->lock);
  564. /* send an addBA request */
  565. sta->ampdu_mlme.dialog_token_allocator++;
  566. sta->ampdu_mlme.tid_tx[tid]->dialog_token =
  567. sta->ampdu_mlme.dialog_token_allocator;
  568. sta->ampdu_mlme.tid_tx[tid]->ssn = start_seq_num;
  569. ieee80211_send_addba_request(sta->sdata->dev, ra, tid,
  570. sta->ampdu_mlme.tid_tx[tid]->dialog_token,
  571. sta->ampdu_mlme.tid_tx[tid]->ssn,
  572. 0x40, 5000);
  573. /* activate the timer for the recipient's addBA response */
  574. sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.expires =
  575. jiffies + ADDBA_RESP_INTERVAL;
  576. add_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
  577. #ifdef CONFIG_MAC80211_HT_DEBUG
  578. printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
  579. #endif
  580. goto exit;
  581. err_unlock_queue:
  582. kfree(sta->ampdu_mlme.tid_tx[tid]);
  583. sta->ampdu_mlme.tid_tx[tid] = NULL;
  584. ret = -EBUSY;
  585. err_unlock_sta:
  586. spin_unlock_bh(&sta->lock);
  587. exit:
  588. rcu_read_unlock();
  589. return ret;
  590. }
  591. EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
  592. int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
  593. u8 *ra, u16 tid,
  594. enum ieee80211_back_parties initiator)
  595. {
  596. struct ieee80211_local *local = hw_to_local(hw);
  597. struct sta_info *sta;
  598. u8 *state;
  599. int ret = 0;
  600. DECLARE_MAC_BUF(mac);
  601. if (tid >= STA_TID_NUM)
  602. return -EINVAL;
  603. rcu_read_lock();
  604. sta = sta_info_get(local, ra);
  605. if (!sta) {
  606. rcu_read_unlock();
  607. return -ENOENT;
  608. }
  609. /* check if the TID is in aggregation */
  610. state = &sta->ampdu_mlme.tid_state_tx[tid];
  611. spin_lock_bh(&sta->lock);
  612. if (*state != HT_AGG_STATE_OPERATIONAL) {
  613. ret = -ENOENT;
  614. goto stop_BA_exit;
  615. }
  616. #ifdef CONFIG_MAC80211_HT_DEBUG
  617. printk(KERN_DEBUG "Tx BA session stop requested for %s tid %u\n",
  618. print_mac(mac, ra), tid);
  619. #endif /* CONFIG_MAC80211_HT_DEBUG */
  620. ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]);
  621. *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
  622. (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
  623. if (local->ops->ampdu_action)
  624. ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP,
  625. ra, tid, NULL);
  626. /* case HW denied going back to legacy */
  627. if (ret) {
  628. WARN_ON(ret != -EBUSY);
  629. *state = HT_AGG_STATE_OPERATIONAL;
  630. ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
  631. goto stop_BA_exit;
  632. }
  633. stop_BA_exit:
  634. spin_unlock_bh(&sta->lock);
  635. rcu_read_unlock();
  636. return ret;
  637. }
  638. EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
  639. void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
  640. {
  641. struct ieee80211_local *local = hw_to_local(hw);
  642. struct sta_info *sta;
  643. u8 *state;
  644. DECLARE_MAC_BUF(mac);
  645. if (tid >= STA_TID_NUM) {
  646. #ifdef CONFIG_MAC80211_HT_DEBUG
  647. printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
  648. tid, STA_TID_NUM);
  649. #endif
  650. return;
  651. }
  652. rcu_read_lock();
  653. sta = sta_info_get(local, ra);
  654. if (!sta) {
  655. rcu_read_unlock();
  656. #ifdef CONFIG_MAC80211_HT_DEBUG
  657. printk(KERN_DEBUG "Could not find station: %s\n",
  658. print_mac(mac, ra));
  659. #endif
  660. return;
  661. }
  662. state = &sta->ampdu_mlme.tid_state_tx[tid];
  663. spin_lock_bh(&sta->lock);
  664. if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
  665. #ifdef CONFIG_MAC80211_HT_DEBUG
  666. printk(KERN_DEBUG "addBA was not requested yet, state is %d\n",
  667. *state);
  668. #endif
  669. spin_unlock_bh(&sta->lock);
  670. rcu_read_unlock();
  671. return;
  672. }
  673. WARN_ON_ONCE(*state & HT_ADDBA_DRV_READY_MSK);
  674. *state |= HT_ADDBA_DRV_READY_MSK;
  675. if (*state == HT_AGG_STATE_OPERATIONAL) {
  676. #ifdef CONFIG_MAC80211_HT_DEBUG
  677. printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid);
  678. #endif
  679. ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
  680. }
  681. spin_unlock_bh(&sta->lock);
  682. rcu_read_unlock();
  683. }
  684. EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
  685. void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
  686. {
  687. struct ieee80211_local *local = hw_to_local(hw);
  688. struct sta_info *sta;
  689. u8 *state;
  690. int agg_queue;
  691. DECLARE_MAC_BUF(mac);
  692. if (tid >= STA_TID_NUM) {
  693. #ifdef CONFIG_MAC80211_HT_DEBUG
  694. printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
  695. tid, STA_TID_NUM);
  696. #endif
  697. return;
  698. }
  699. #ifdef CONFIG_MAC80211_HT_DEBUG
  700. printk(KERN_DEBUG "Stopping Tx BA session for %s tid %d\n",
  701. print_mac(mac, ra), tid);
  702. #endif /* CONFIG_MAC80211_HT_DEBUG */
  703. rcu_read_lock();
  704. sta = sta_info_get(local, ra);
  705. if (!sta) {
  706. #ifdef CONFIG_MAC80211_HT_DEBUG
  707. printk(KERN_DEBUG "Could not find station: %s\n",
  708. print_mac(mac, ra));
  709. #endif
  710. rcu_read_unlock();
  711. return;
  712. }
  713. state = &sta->ampdu_mlme.tid_state_tx[tid];
  714. /* NOTE: no need to use sta->lock in this state check, as
  715. * ieee80211_stop_tx_ba_session will let only one stop call to
  716. * pass through per sta/tid
  717. */
  718. if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) {
  719. #ifdef CONFIG_MAC80211_HT_DEBUG
  720. printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
  721. #endif
  722. rcu_read_unlock();
  723. return;
  724. }
  725. if (*state & HT_AGG_STATE_INITIATOR_MSK)
  726. ieee80211_send_delba(sta->sdata->dev, ra, tid,
  727. WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
  728. agg_queue = sta->tid_to_tx_q[tid];
  729. ieee80211_ht_agg_queue_remove(local, sta, tid, 1);
  730. /* We just requeued the all the frames that were in the
  731. * removed queue, and since we might miss a softirq we do
  732. * netif_schedule_queue. ieee80211_wake_queue is not used
  733. * here as this queue is not necessarily stopped
  734. */
  735. netif_schedule_queue(netdev_get_tx_queue(local->mdev, agg_queue));
  736. spin_lock_bh(&sta->lock);
  737. *state = HT_AGG_STATE_IDLE;
  738. sta->ampdu_mlme.addba_req_num[tid] = 0;
  739. kfree(sta->ampdu_mlme.tid_tx[tid]);
  740. sta->ampdu_mlme.tid_tx[tid] = NULL;
  741. spin_unlock_bh(&sta->lock);
  742. rcu_read_unlock();
  743. }
  744. EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb);
  745. void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
  746. const u8 *ra, u16 tid)
  747. {
  748. struct ieee80211_local *local = hw_to_local(hw);
  749. struct ieee80211_ra_tid *ra_tid;
  750. struct sk_buff *skb = dev_alloc_skb(0);
  751. if (unlikely(!skb)) {
  752. #ifdef CONFIG_MAC80211_HT_DEBUG
  753. if (net_ratelimit())
  754. printk(KERN_WARNING "%s: Not enough memory, "
  755. "dropping start BA session", skb->dev->name);
  756. #endif
  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_ADDBA_MSG;
  763. skb_queue_tail(&local->skb_queue, skb);
  764. tasklet_schedule(&local->tasklet);
  765. }
  766. EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
  767. void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
  768. const u8 *ra, u16 tid)
  769. {
  770. struct ieee80211_local *local = hw_to_local(hw);
  771. struct ieee80211_ra_tid *ra_tid;
  772. struct sk_buff *skb = dev_alloc_skb(0);
  773. if (unlikely(!skb)) {
  774. #ifdef CONFIG_MAC80211_HT_DEBUG
  775. if (net_ratelimit())
  776. printk(KERN_WARNING "%s: Not enough memory, "
  777. "dropping stop BA session", skb->dev->name);
  778. #endif
  779. return;
  780. }
  781. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  782. memcpy(&ra_tid->ra, ra, ETH_ALEN);
  783. ra_tid->tid = tid;
  784. skb->pkt_type = IEEE80211_DELBA_MSG;
  785. skb_queue_tail(&local->skb_queue, skb);
  786. tasklet_schedule(&local->tasklet);
  787. }
  788. EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
  789. static void ieee80211_set_multicast_list(struct net_device *dev)
  790. {
  791. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  792. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  793. int allmulti, promisc, sdata_allmulti, sdata_promisc;
  794. allmulti = !!(dev->flags & IFF_ALLMULTI);
  795. promisc = !!(dev->flags & IFF_PROMISC);
  796. sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
  797. sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC);
  798. if (allmulti != sdata_allmulti) {
  799. if (dev->flags & IFF_ALLMULTI)
  800. atomic_inc(&local->iff_allmultis);
  801. else
  802. atomic_dec(&local->iff_allmultis);
  803. sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
  804. }
  805. if (promisc != sdata_promisc) {
  806. if (dev->flags & IFF_PROMISC)
  807. atomic_inc(&local->iff_promiscs);
  808. else
  809. atomic_dec(&local->iff_promiscs);
  810. sdata->flags ^= IEEE80211_SDATA_PROMISC;
  811. }
  812. dev_mc_sync(local->mdev, dev);
  813. }
  814. static const struct header_ops ieee80211_header_ops = {
  815. .create = eth_header,
  816. .parse = header_parse_80211,
  817. .rebuild = eth_rebuild_header,
  818. .cache = eth_header_cache,
  819. .cache_update = eth_header_cache_update,
  820. };
  821. void ieee80211_if_setup(struct net_device *dev)
  822. {
  823. ether_setup(dev);
  824. dev->hard_start_xmit = ieee80211_subif_start_xmit;
  825. dev->wireless_handlers = &ieee80211_iw_handler_def;
  826. dev->set_multicast_list = ieee80211_set_multicast_list;
  827. dev->change_mtu = ieee80211_change_mtu;
  828. dev->open = ieee80211_open;
  829. dev->stop = ieee80211_stop;
  830. dev->destructor = free_netdev;
  831. }
  832. /* everything else */
  833. int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed)
  834. {
  835. struct ieee80211_local *local = sdata->local;
  836. struct ieee80211_if_conf conf;
  837. if (WARN_ON(!netif_running(sdata->dev)))
  838. return 0;
  839. if (!local->ops->config_interface)
  840. return 0;
  841. memset(&conf, 0, sizeof(conf));
  842. conf.changed = changed;
  843. if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
  844. sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
  845. conf.bssid = sdata->u.sta.bssid;
  846. conf.ssid = sdata->u.sta.ssid;
  847. conf.ssid_len = sdata->u.sta.ssid_len;
  848. } else if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
  849. conf.bssid = sdata->dev->dev_addr;
  850. conf.ssid = sdata->u.ap.ssid;
  851. conf.ssid_len = sdata->u.ap.ssid_len;
  852. } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
  853. u8 zero[ETH_ALEN] = { 0 };
  854. conf.bssid = zero;
  855. conf.ssid = zero;
  856. conf.ssid_len = 0;
  857. } else {
  858. WARN_ON(1);
  859. return -EINVAL;
  860. }
  861. if (WARN_ON(!conf.bssid && (changed & IEEE80211_IFCC_BSSID)))
  862. return -EINVAL;
  863. if (WARN_ON(!conf.ssid && (changed & IEEE80211_IFCC_SSID)))
  864. return -EINVAL;
  865. return local->ops->config_interface(local_to_hw(local),
  866. &sdata->vif, &conf);
  867. }
  868. int ieee80211_hw_config(struct ieee80211_local *local)
  869. {
  870. struct ieee80211_channel *chan;
  871. int ret = 0;
  872. if (local->sta_sw_scanning)
  873. chan = local->scan_channel;
  874. else
  875. chan = local->oper_channel;
  876. local->hw.conf.channel = chan;
  877. if (!local->hw.conf.power_level)
  878. local->hw.conf.power_level = chan->max_power;
  879. else
  880. local->hw.conf.power_level = min(chan->max_power,
  881. local->hw.conf.power_level);
  882. local->hw.conf.max_antenna_gain = chan->max_antenna_gain;
  883. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  884. printk(KERN_DEBUG "%s: HW CONFIG: freq=%d\n",
  885. wiphy_name(local->hw.wiphy), chan->center_freq);
  886. #endif
  887. if (local->open_count)
  888. ret = local->ops->config(local_to_hw(local), &local->hw.conf);
  889. return ret;
  890. }
  891. /**
  892. * ieee80211_handle_ht should be used only after legacy configuration
  893. * has been determined namely band, as ht configuration depends upon
  894. * the hardware's HT abilities for a _specific_ band.
  895. */
  896. u32 ieee80211_handle_ht(struct ieee80211_local *local, int enable_ht,
  897. struct ieee80211_ht_info *req_ht_cap,
  898. struct ieee80211_ht_bss_info *req_bss_cap)
  899. {
  900. struct ieee80211_conf *conf = &local->hw.conf;
  901. struct ieee80211_supported_band *sband;
  902. struct ieee80211_ht_info ht_conf;
  903. struct ieee80211_ht_bss_info ht_bss_conf;
  904. u32 changed = 0;
  905. int i;
  906. u8 max_tx_streams = IEEE80211_HT_CAP_MAX_STREAMS;
  907. u8 tx_mcs_set_cap;
  908. sband = local->hw.wiphy->bands[conf->channel->band];
  909. memset(&ht_conf, 0, sizeof(struct ieee80211_ht_info));
  910. memset(&ht_bss_conf, 0, sizeof(struct ieee80211_ht_bss_info));
  911. /* HT is not supported */
  912. if (!sband->ht_info.ht_supported) {
  913. conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
  914. goto out;
  915. }
  916. /* disable HT */
  917. if (!enable_ht) {
  918. if (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)
  919. changed |= BSS_CHANGED_HT;
  920. conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
  921. conf->ht_conf.ht_supported = 0;
  922. goto out;
  923. }
  924. if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE))
  925. changed |= BSS_CHANGED_HT;
  926. conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE;
  927. ht_conf.ht_supported = 1;
  928. ht_conf.cap = req_ht_cap->cap & sband->ht_info.cap;
  929. ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS);
  930. ht_conf.cap |= sband->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS;
  931. ht_bss_conf.primary_channel = req_bss_cap->primary_channel;
  932. ht_bss_conf.bss_cap = req_bss_cap->bss_cap;
  933. ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode;
  934. ht_conf.ampdu_factor = req_ht_cap->ampdu_factor;
  935. ht_conf.ampdu_density = req_ht_cap->ampdu_density;
  936. /* Bits 96-100 */
  937. tx_mcs_set_cap = sband->ht_info.supp_mcs_set[12];
  938. /* configure suppoerted Tx MCS according to requested MCS
  939. * (based in most cases on Rx capabilities of peer) and self
  940. * Tx MCS capabilities (as defined by low level driver HW
  941. * Tx capabilities) */
  942. if (!(tx_mcs_set_cap & IEEE80211_HT_CAP_MCS_TX_DEFINED))
  943. goto check_changed;
  944. /* Counting from 0 therfore + 1 */
  945. if (tx_mcs_set_cap & IEEE80211_HT_CAP_MCS_TX_RX_DIFF)
  946. max_tx_streams = ((tx_mcs_set_cap &
  947. IEEE80211_HT_CAP_MCS_TX_STREAMS) >> 2) + 1;
  948. for (i = 0; i < max_tx_streams; i++)
  949. ht_conf.supp_mcs_set[i] =
  950. sband->ht_info.supp_mcs_set[i] &
  951. req_ht_cap->supp_mcs_set[i];
  952. if (tx_mcs_set_cap & IEEE80211_HT_CAP_MCS_TX_UEQM)
  953. for (i = IEEE80211_SUPP_MCS_SET_UEQM;
  954. i < IEEE80211_SUPP_MCS_SET_LEN; i++)
  955. ht_conf.supp_mcs_set[i] =
  956. sband->ht_info.supp_mcs_set[i] &
  957. req_ht_cap->supp_mcs_set[i];
  958. check_changed:
  959. /* if bss configuration changed store the new one */
  960. if (memcmp(&conf->ht_conf, &ht_conf, sizeof(ht_conf)) ||
  961. memcmp(&conf->ht_bss_conf, &ht_bss_conf, sizeof(ht_bss_conf))) {
  962. changed |= BSS_CHANGED_HT;
  963. memcpy(&conf->ht_conf, &ht_conf, sizeof(ht_conf));
  964. memcpy(&conf->ht_bss_conf, &ht_bss_conf, sizeof(ht_bss_conf));
  965. }
  966. out:
  967. return changed;
  968. }
  969. void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
  970. u32 changed)
  971. {
  972. struct ieee80211_local *local = sdata->local;
  973. if (!changed)
  974. return;
  975. if (local->ops->bss_info_changed)
  976. local->ops->bss_info_changed(local_to_hw(local),
  977. &sdata->vif,
  978. &sdata->bss_conf,
  979. changed);
  980. }
  981. u32 ieee80211_reset_erp_info(struct net_device *dev)
  982. {
  983. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  984. sdata->bss_conf.use_cts_prot = 0;
  985. sdata->bss_conf.use_short_preamble = 0;
  986. return BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_ERP_PREAMBLE;
  987. }
  988. void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
  989. struct sk_buff *skb)
  990. {
  991. struct ieee80211_local *local = hw_to_local(hw);
  992. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  993. int tmp;
  994. skb->dev = local->mdev;
  995. skb->pkt_type = IEEE80211_TX_STATUS_MSG;
  996. skb_queue_tail(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS ?
  997. &local->skb_queue : &local->skb_queue_unreliable, skb);
  998. tmp = skb_queue_len(&local->skb_queue) +
  999. skb_queue_len(&local->skb_queue_unreliable);
  1000. while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
  1001. (skb = skb_dequeue(&local->skb_queue_unreliable))) {
  1002. dev_kfree_skb_irq(skb);
  1003. tmp--;
  1004. I802_DEBUG_INC(local->tx_status_drop);
  1005. }
  1006. tasklet_schedule(&local->tasklet);
  1007. }
  1008. EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
  1009. static void ieee80211_tasklet_handler(unsigned long data)
  1010. {
  1011. struct ieee80211_local *local = (struct ieee80211_local *) data;
  1012. struct sk_buff *skb;
  1013. struct ieee80211_rx_status rx_status;
  1014. struct ieee80211_ra_tid *ra_tid;
  1015. while ((skb = skb_dequeue(&local->skb_queue)) ||
  1016. (skb = skb_dequeue(&local->skb_queue_unreliable))) {
  1017. switch (skb->pkt_type) {
  1018. case IEEE80211_RX_MSG:
  1019. /* status is in skb->cb */
  1020. memcpy(&rx_status, skb->cb, sizeof(rx_status));
  1021. /* Clear skb->pkt_type in order to not confuse kernel
  1022. * netstack. */
  1023. skb->pkt_type = 0;
  1024. __ieee80211_rx(local_to_hw(local), skb, &rx_status);
  1025. break;
  1026. case IEEE80211_TX_STATUS_MSG:
  1027. skb->pkt_type = 0;
  1028. ieee80211_tx_status(local_to_hw(local), skb);
  1029. break;
  1030. case IEEE80211_DELBA_MSG:
  1031. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  1032. ieee80211_stop_tx_ba_cb(local_to_hw(local),
  1033. ra_tid->ra, ra_tid->tid);
  1034. dev_kfree_skb(skb);
  1035. break;
  1036. case IEEE80211_ADDBA_MSG:
  1037. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  1038. ieee80211_start_tx_ba_cb(local_to_hw(local),
  1039. ra_tid->ra, ra_tid->tid);
  1040. dev_kfree_skb(skb);
  1041. break ;
  1042. default:
  1043. WARN_ON(1);
  1044. dev_kfree_skb(skb);
  1045. break;
  1046. }
  1047. }
  1048. }
  1049. /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
  1050. * make a prepared TX frame (one that has been given to hw) to look like brand
  1051. * new IEEE 802.11 frame that is ready to go through TX processing again.
  1052. */
  1053. static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
  1054. struct ieee80211_key *key,
  1055. struct sk_buff *skb)
  1056. {
  1057. int hdrlen, iv_len, mic_len;
  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. {
  1100. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  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. * when it wakes up for the next time.
  1106. */
  1107. set_sta_flags(sta, 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 (test_sta_flags(sta, WLAN_STA_PS) &&
  1139. skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) {
  1140. ieee80211_remove_tx_extra(local, sta->key, skb);
  1141. skb_queue_tail(&sta->tx_filtered, skb);
  1142. return;
  1143. }
  1144. if (!test_sta_flags(sta, WLAN_STA_PS) &&
  1145. !(info->flags & IEEE80211_TX_CTL_REQUEUE)) {
  1146. /* Software retry the packet once */
  1147. info->flags |= IEEE80211_TX_CTL_REQUEUE;
  1148. ieee80211_remove_tx_extra(local, sta->key, skb);
  1149. dev_queue_xmit(skb);
  1150. return;
  1151. }
  1152. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1153. if (net_ratelimit())
  1154. printk(KERN_DEBUG "%s: dropped TX filtered frame, "
  1155. "queue_len=%d PS=%d @%lu\n",
  1156. wiphy_name(local->hw.wiphy),
  1157. skb_queue_len(&sta->tx_filtered),
  1158. !!test_sta_flags(sta, WLAN_STA_PS), jiffies);
  1159. #endif
  1160. dev_kfree_skb(skb);
  1161. }
  1162. void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
  1163. {
  1164. struct sk_buff *skb2;
  1165. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1166. struct ieee80211_local *local = hw_to_local(hw);
  1167. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1168. u16 frag, type;
  1169. __le16 fc;
  1170. struct ieee80211_tx_status_rtap_hdr *rthdr;
  1171. struct ieee80211_sub_if_data *sdata;
  1172. struct net_device *prev_dev = NULL;
  1173. struct sta_info *sta;
  1174. rcu_read_lock();
  1175. if (info->status.excessive_retries) {
  1176. sta = sta_info_get(local, hdr->addr1);
  1177. if (sta) {
  1178. if (test_sta_flags(sta, WLAN_STA_PS)) {
  1179. /*
  1180. * The STA is in power save mode, so assume
  1181. * that this TX packet failed because of that.
  1182. */
  1183. ieee80211_handle_filtered_frame(local, sta, skb);
  1184. rcu_read_unlock();
  1185. return;
  1186. }
  1187. }
  1188. }
  1189. fc = hdr->frame_control;
  1190. if ((info->flags & IEEE80211_TX_STAT_AMPDU_NO_BACK) &&
  1191. (ieee80211_is_data_qos(fc))) {
  1192. u16 tid, ssn;
  1193. u8 *qc;
  1194. sta = sta_info_get(local, hdr->addr1);
  1195. if (sta) {
  1196. qc = ieee80211_get_qos_ctl(hdr);
  1197. tid = qc[0] & 0xf;
  1198. ssn = ((le16_to_cpu(hdr->seq_ctrl) + 0x10)
  1199. & IEEE80211_SCTL_SEQ);
  1200. ieee80211_send_bar(sta->sdata->dev, hdr->addr1,
  1201. tid, ssn);
  1202. }
  1203. }
  1204. if (info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
  1205. sta = sta_info_get(local, hdr->addr1);
  1206. if (sta) {
  1207. ieee80211_handle_filtered_frame(local, sta, skb);
  1208. rcu_read_unlock();
  1209. return;
  1210. }
  1211. } else
  1212. rate_control_tx_status(local->mdev, skb);
  1213. rcu_read_unlock();
  1214. ieee80211_led_tx(local, 0);
  1215. /* SNMP counters
  1216. * Fragments are passed to low-level drivers as separate skbs, so these
  1217. * are actually fragments, not frames. Update frame counters only for
  1218. * the first fragment of the frame. */
  1219. frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
  1220. type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
  1221. if (info->flags & IEEE80211_TX_STAT_ACK) {
  1222. if (frag == 0) {
  1223. local->dot11TransmittedFrameCount++;
  1224. if (is_multicast_ether_addr(hdr->addr1))
  1225. local->dot11MulticastTransmittedFrameCount++;
  1226. if (info->status.retry_count > 0)
  1227. local->dot11RetryCount++;
  1228. if (info->status.retry_count > 1)
  1229. local->dot11MultipleRetryCount++;
  1230. }
  1231. /* This counter shall be incremented for an acknowledged MPDU
  1232. * with an individual address in the address 1 field or an MPDU
  1233. * with a multicast address in the address 1 field of type Data
  1234. * or Management. */
  1235. if (!is_multicast_ether_addr(hdr->addr1) ||
  1236. type == IEEE80211_FTYPE_DATA ||
  1237. type == IEEE80211_FTYPE_MGMT)
  1238. local->dot11TransmittedFragmentCount++;
  1239. } else {
  1240. if (frag == 0)
  1241. local->dot11FailedCount++;
  1242. }
  1243. /* this was a transmitted frame, but now we want to reuse it */
  1244. skb_orphan(skb);
  1245. /*
  1246. * This is a bit racy but we can avoid a lot of work
  1247. * with this test...
  1248. */
  1249. if (!local->monitors && !local->cooked_mntrs) {
  1250. dev_kfree_skb(skb);
  1251. return;
  1252. }
  1253. /* send frame to monitor interfaces now */
  1254. if (skb_headroom(skb) < sizeof(*rthdr)) {
  1255. printk(KERN_ERR "ieee80211_tx_status: headroom too small\n");
  1256. dev_kfree_skb(skb);
  1257. return;
  1258. }
  1259. rthdr = (struct ieee80211_tx_status_rtap_hdr *)
  1260. skb_push(skb, sizeof(*rthdr));
  1261. memset(rthdr, 0, sizeof(*rthdr));
  1262. rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
  1263. rthdr->hdr.it_present =
  1264. cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
  1265. (1 << IEEE80211_RADIOTAP_DATA_RETRIES));
  1266. if (!(info->flags & IEEE80211_TX_STAT_ACK) &&
  1267. !is_multicast_ether_addr(hdr->addr1))
  1268. rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
  1269. if ((info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) &&
  1270. (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT))
  1271. rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
  1272. else if (info->flags & IEEE80211_TX_CTL_USE_RTS_CTS)
  1273. rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
  1274. rthdr->data_retries = info->status.retry_count;
  1275. /* XXX: is this sufficient for BPF? */
  1276. skb_set_mac_header(skb, 0);
  1277. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1278. skb->pkt_type = PACKET_OTHERHOST;
  1279. skb->protocol = htons(ETH_P_802_2);
  1280. memset(skb->cb, 0, sizeof(skb->cb));
  1281. rcu_read_lock();
  1282. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  1283. if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) {
  1284. if (!netif_running(sdata->dev))
  1285. continue;
  1286. if (prev_dev) {
  1287. skb2 = skb_clone(skb, GFP_ATOMIC);
  1288. if (skb2) {
  1289. skb2->dev = prev_dev;
  1290. netif_rx(skb2);
  1291. }
  1292. }
  1293. prev_dev = sdata->dev;
  1294. }
  1295. }
  1296. if (prev_dev) {
  1297. skb->dev = prev_dev;
  1298. netif_rx(skb);
  1299. skb = NULL;
  1300. }
  1301. rcu_read_unlock();
  1302. dev_kfree_skb(skb);
  1303. }
  1304. EXPORT_SYMBOL(ieee80211_tx_status);
  1305. struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
  1306. const struct ieee80211_ops *ops)
  1307. {
  1308. struct ieee80211_local *local;
  1309. int priv_size;
  1310. struct wiphy *wiphy;
  1311. /* Ensure 32-byte alignment of our private data and hw private data.
  1312. * We use the wiphy priv data for both our ieee80211_local and for
  1313. * the driver's private data
  1314. *
  1315. * In memory it'll be like this:
  1316. *
  1317. * +-------------------------+
  1318. * | struct wiphy |
  1319. * +-------------------------+
  1320. * | struct ieee80211_local |
  1321. * +-------------------------+
  1322. * | driver's private data |
  1323. * +-------------------------+
  1324. *
  1325. */
  1326. priv_size = ((sizeof(struct ieee80211_local) +
  1327. NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
  1328. priv_data_len;
  1329. wiphy = wiphy_new(&mac80211_config_ops, priv_size);
  1330. if (!wiphy)
  1331. return NULL;
  1332. wiphy->privid = mac80211_wiphy_privid;
  1333. local = wiphy_priv(wiphy);
  1334. local->hw.wiphy = wiphy;
  1335. local->hw.priv = (char *)local +
  1336. ((sizeof(struct ieee80211_local) +
  1337. NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
  1338. BUG_ON(!ops->tx);
  1339. BUG_ON(!ops->start);
  1340. BUG_ON(!ops->stop);
  1341. BUG_ON(!ops->config);
  1342. BUG_ON(!ops->add_interface);
  1343. BUG_ON(!ops->remove_interface);
  1344. BUG_ON(!ops->configure_filter);
  1345. local->ops = ops;
  1346. local->hw.queues = 1; /* default */
  1347. local->bridge_packets = 1;
  1348. local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  1349. local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
  1350. local->short_retry_limit = 7;
  1351. local->long_retry_limit = 4;
  1352. local->hw.conf.radio_enabled = 1;
  1353. INIT_LIST_HEAD(&local->interfaces);
  1354. spin_lock_init(&local->key_lock);
  1355. INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work);
  1356. sta_info_init(local);
  1357. tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
  1358. (unsigned long)local);
  1359. tasklet_disable(&local->tx_pending_tasklet);
  1360. tasklet_init(&local->tasklet,
  1361. ieee80211_tasklet_handler,
  1362. (unsigned long) local);
  1363. tasklet_disable(&local->tasklet);
  1364. skb_queue_head_init(&local->skb_queue);
  1365. skb_queue_head_init(&local->skb_queue_unreliable);
  1366. return local_to_hw(local);
  1367. }
  1368. EXPORT_SYMBOL(ieee80211_alloc_hw);
  1369. int ieee80211_register_hw(struct ieee80211_hw *hw)
  1370. {
  1371. struct ieee80211_local *local = hw_to_local(hw);
  1372. const char *name;
  1373. int result;
  1374. enum ieee80211_band band;
  1375. struct net_device *mdev;
  1376. struct wireless_dev *mwdev;
  1377. /*
  1378. * generic code guarantees at least one band,
  1379. * set this very early because much code assumes
  1380. * that hw.conf.channel is assigned
  1381. */
  1382. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  1383. struct ieee80211_supported_band *sband;
  1384. sband = local->hw.wiphy->bands[band];
  1385. if (sband) {
  1386. /* init channel we're on */
  1387. local->hw.conf.channel =
  1388. local->oper_channel =
  1389. local->scan_channel = &sband->channels[0];
  1390. break;
  1391. }
  1392. }
  1393. result = wiphy_register(local->hw.wiphy);
  1394. if (result < 0)
  1395. return result;
  1396. /*
  1397. * We use the number of queues for feature tests (QoS, HT) internally
  1398. * so restrict them appropriately.
  1399. */
  1400. if (hw->queues > IEEE80211_MAX_QUEUES)
  1401. hw->queues = IEEE80211_MAX_QUEUES;
  1402. if (hw->ampdu_queues > IEEE80211_MAX_AMPDU_QUEUES)
  1403. hw->ampdu_queues = IEEE80211_MAX_AMPDU_QUEUES;
  1404. if (hw->queues < 4)
  1405. hw->ampdu_queues = 0;
  1406. mdev = alloc_netdev_mq(sizeof(struct wireless_dev),
  1407. "wmaster%d", ether_setup,
  1408. ieee80211_num_queues(hw));
  1409. if (!mdev)
  1410. goto fail_mdev_alloc;
  1411. mwdev = netdev_priv(mdev);
  1412. mdev->ieee80211_ptr = mwdev;
  1413. mwdev->wiphy = local->hw.wiphy;
  1414. local->mdev = mdev;
  1415. ieee80211_rx_bss_list_init(local);
  1416. mdev->hard_start_xmit = ieee80211_master_start_xmit;
  1417. mdev->open = ieee80211_master_open;
  1418. mdev->stop = ieee80211_master_stop;
  1419. mdev->type = ARPHRD_IEEE80211;
  1420. mdev->header_ops = &ieee80211_header_ops;
  1421. mdev->set_multicast_list = ieee80211_master_set_multicast_list;
  1422. name = wiphy_dev(local->hw.wiphy)->driver->name;
  1423. local->hw.workqueue = create_freezeable_workqueue(name);
  1424. if (!local->hw.workqueue) {
  1425. result = -ENOMEM;
  1426. goto fail_workqueue;
  1427. }
  1428. /*
  1429. * The hardware needs headroom for sending the frame,
  1430. * and we need some headroom for passing the frame to monitor
  1431. * interfaces, but never both at the same time.
  1432. */
  1433. local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
  1434. sizeof(struct ieee80211_tx_status_rtap_hdr));
  1435. debugfs_hw_add(local);
  1436. if (local->hw.conf.beacon_int < 10)
  1437. local->hw.conf.beacon_int = 100;
  1438. if (local->hw.max_listen_interval == 0)
  1439. local->hw.max_listen_interval = 1;
  1440. local->hw.conf.listen_interval = local->hw.max_listen_interval;
  1441. local->wstats_flags |= local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
  1442. IEEE80211_HW_SIGNAL_DB |
  1443. IEEE80211_HW_SIGNAL_DBM) ?
  1444. IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
  1445. local->wstats_flags |= local->hw.flags & IEEE80211_HW_NOISE_DBM ?
  1446. IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
  1447. if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
  1448. local->wstats_flags |= IW_QUAL_DBM;
  1449. result = sta_info_start(local);
  1450. if (result < 0)
  1451. goto fail_sta_info;
  1452. rtnl_lock();
  1453. result = dev_alloc_name(local->mdev, local->mdev->name);
  1454. if (result < 0)
  1455. goto fail_dev;
  1456. memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
  1457. SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy));
  1458. result = register_netdevice(local->mdev);
  1459. if (result < 0)
  1460. goto fail_dev;
  1461. result = ieee80211_init_rate_ctrl_alg(local,
  1462. hw->rate_control_algorithm);
  1463. if (result < 0) {
  1464. printk(KERN_DEBUG "%s: Failed to initialize rate control "
  1465. "algorithm\n", wiphy_name(local->hw.wiphy));
  1466. goto fail_rate;
  1467. }
  1468. result = ieee80211_wep_init(local);
  1469. if (result < 0) {
  1470. printk(KERN_DEBUG "%s: Failed to initialize wep: %d\n",
  1471. wiphy_name(local->hw.wiphy), result);
  1472. goto fail_wep;
  1473. }
  1474. local->mdev->select_queue = ieee80211_select_queue;
  1475. /* add one default STA interface */
  1476. result = ieee80211_if_add(local, "wlan%d", NULL,
  1477. IEEE80211_IF_TYPE_STA, NULL);
  1478. if (result)
  1479. printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
  1480. wiphy_name(local->hw.wiphy));
  1481. rtnl_unlock();
  1482. ieee80211_led_init(local);
  1483. return 0;
  1484. fail_wep:
  1485. rate_control_deinitialize(local);
  1486. fail_rate:
  1487. unregister_netdevice(local->mdev);
  1488. local->mdev = NULL;
  1489. fail_dev:
  1490. rtnl_unlock();
  1491. sta_info_stop(local);
  1492. fail_sta_info:
  1493. debugfs_hw_del(local);
  1494. destroy_workqueue(local->hw.workqueue);
  1495. fail_workqueue:
  1496. if (local->mdev)
  1497. free_netdev(local->mdev);
  1498. fail_mdev_alloc:
  1499. wiphy_unregister(local->hw.wiphy);
  1500. return result;
  1501. }
  1502. EXPORT_SYMBOL(ieee80211_register_hw);
  1503. void ieee80211_unregister_hw(struct ieee80211_hw *hw)
  1504. {
  1505. struct ieee80211_local *local = hw_to_local(hw);
  1506. tasklet_kill(&local->tx_pending_tasklet);
  1507. tasklet_kill(&local->tasklet);
  1508. rtnl_lock();
  1509. /*
  1510. * At this point, interface list manipulations are fine
  1511. * because the driver cannot be handing us frames any
  1512. * more and the tasklet is killed.
  1513. */
  1514. /* First, we remove all virtual interfaces. */
  1515. ieee80211_remove_interfaces(local);
  1516. /* then, finally, remove the master interface */
  1517. unregister_netdevice(local->mdev);
  1518. rtnl_unlock();
  1519. ieee80211_rx_bss_list_deinit(local);
  1520. ieee80211_clear_tx_pending(local);
  1521. sta_info_stop(local);
  1522. rate_control_deinitialize(local);
  1523. debugfs_hw_del(local);
  1524. if (skb_queue_len(&local->skb_queue)
  1525. || skb_queue_len(&local->skb_queue_unreliable))
  1526. printk(KERN_WARNING "%s: skb_queue not empty\n",
  1527. wiphy_name(local->hw.wiphy));
  1528. skb_queue_purge(&local->skb_queue);
  1529. skb_queue_purge(&local->skb_queue_unreliable);
  1530. destroy_workqueue(local->hw.workqueue);
  1531. wiphy_unregister(local->hw.wiphy);
  1532. ieee80211_wep_free(local);
  1533. ieee80211_led_exit(local);
  1534. free_netdev(local->mdev);
  1535. }
  1536. EXPORT_SYMBOL(ieee80211_unregister_hw);
  1537. void ieee80211_free_hw(struct ieee80211_hw *hw)
  1538. {
  1539. struct ieee80211_local *local = hw_to_local(hw);
  1540. wiphy_free(local->hw.wiphy);
  1541. }
  1542. EXPORT_SYMBOL(ieee80211_free_hw);
  1543. static int __init ieee80211_init(void)
  1544. {
  1545. struct sk_buff *skb;
  1546. int ret;
  1547. BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb));
  1548. BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
  1549. IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
  1550. ret = rc80211_pid_init();
  1551. if (ret)
  1552. return ret;
  1553. ieee80211_debugfs_netdev_init();
  1554. return 0;
  1555. }
  1556. static void __exit ieee80211_exit(void)
  1557. {
  1558. rc80211_pid_exit();
  1559. /*
  1560. * For key todo, it'll be empty by now but the work
  1561. * might still be scheduled.
  1562. */
  1563. flush_scheduled_work();
  1564. if (mesh_allocated)
  1565. ieee80211s_stop();
  1566. ieee80211_debugfs_netdev_exit();
  1567. }
  1568. subsys_initcall(ieee80211_init);
  1569. module_exit(ieee80211_exit);
  1570. MODULE_DESCRIPTION("IEEE 802.11 subsystem");
  1571. MODULE_LICENSE("GPL");