main.c 51 KB

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