main.c 53 KB

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