main.c 53 KB

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