main.c 51 KB

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