ieee80211.c 51 KB

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