main.c 54 KB

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