main.c 53 KB

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