main.c 50 KB

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