ieee80211.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  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 "ieee80211_rate.h"
  27. #include "wep.h"
  28. #include "wme.h"
  29. #include "aes_ccm.h"
  30. #include "ieee80211_led.h"
  31. #include "cfg.h"
  32. #include "debugfs.h"
  33. #include "debugfs_netdev.h"
  34. /*
  35. * For seeing transmitted packets on monitor interfaces
  36. * we have a radiotap header too.
  37. */
  38. struct ieee80211_tx_status_rtap_hdr {
  39. struct ieee80211_radiotap_header hdr;
  40. __le16 tx_flags;
  41. u8 data_retries;
  42. } __attribute__ ((packed));
  43. /* common interface routines */
  44. static int header_parse_80211(const struct sk_buff *skb, unsigned char *haddr)
  45. {
  46. memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
  47. return ETH_ALEN;
  48. }
  49. /* must be called under mdev tx lock */
  50. static void ieee80211_configure_filter(struct ieee80211_local *local)
  51. {
  52. unsigned int changed_flags;
  53. unsigned int new_flags = 0;
  54. if (atomic_read(&local->iff_promiscs))
  55. new_flags |= FIF_PROMISC_IN_BSS;
  56. if (atomic_read(&local->iff_allmultis))
  57. new_flags |= FIF_ALLMULTI;
  58. if (local->monitors)
  59. new_flags |= FIF_CONTROL |
  60. FIF_OTHER_BSS |
  61. FIF_BCN_PRBRESP_PROMISC;
  62. changed_flags = local->filter_flags ^ new_flags;
  63. /* be a bit nasty */
  64. new_flags |= (1<<31);
  65. local->ops->configure_filter(local_to_hw(local),
  66. changed_flags, &new_flags,
  67. local->mdev->mc_count,
  68. local->mdev->mc_list);
  69. WARN_ON(new_flags & (1<<31));
  70. local->filter_flags = new_flags & ~(1<<31);
  71. }
  72. /* master interface */
  73. static int ieee80211_master_open(struct net_device *dev)
  74. {
  75. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  76. struct ieee80211_sub_if_data *sdata;
  77. int res = -EOPNOTSUPP;
  78. /* we hold the RTNL here so can safely walk the list */
  79. list_for_each_entry(sdata, &local->interfaces, list) {
  80. if (sdata->dev != dev && netif_running(sdata->dev)) {
  81. res = 0;
  82. break;
  83. }
  84. }
  85. return res;
  86. }
  87. static int ieee80211_master_stop(struct net_device *dev)
  88. {
  89. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  90. struct ieee80211_sub_if_data *sdata;
  91. /* we hold the RTNL here so can safely walk the list */
  92. list_for_each_entry(sdata, &local->interfaces, list)
  93. if (sdata->dev != dev && netif_running(sdata->dev))
  94. dev_close(sdata->dev);
  95. return 0;
  96. }
  97. static void ieee80211_master_set_multicast_list(struct net_device *dev)
  98. {
  99. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  100. ieee80211_configure_filter(local);
  101. }
  102. /* regular interfaces */
  103. static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
  104. {
  105. /* FIX: what would be proper limits for MTU?
  106. * This interface uses 802.3 frames. */
  107. if (new_mtu < 256 || new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6) {
  108. printk(KERN_WARNING "%s: invalid MTU %d\n",
  109. dev->name, new_mtu);
  110. return -EINVAL;
  111. }
  112. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  113. printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
  114. #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
  115. dev->mtu = new_mtu;
  116. return 0;
  117. }
  118. static inline int identical_mac_addr_allowed(int type1, int type2)
  119. {
  120. return (type1 == IEEE80211_IF_TYPE_MNTR ||
  121. type2 == IEEE80211_IF_TYPE_MNTR ||
  122. (type1 == IEEE80211_IF_TYPE_AP &&
  123. type2 == IEEE80211_IF_TYPE_WDS) ||
  124. (type1 == IEEE80211_IF_TYPE_WDS &&
  125. (type2 == IEEE80211_IF_TYPE_WDS ||
  126. type2 == IEEE80211_IF_TYPE_AP)) ||
  127. (type1 == IEEE80211_IF_TYPE_AP &&
  128. type2 == IEEE80211_IF_TYPE_VLAN) ||
  129. (type1 == IEEE80211_IF_TYPE_VLAN &&
  130. (type2 == IEEE80211_IF_TYPE_AP ||
  131. type2 == IEEE80211_IF_TYPE_VLAN)));
  132. }
  133. static int ieee80211_open(struct net_device *dev)
  134. {
  135. struct ieee80211_sub_if_data *sdata, *nsdata;
  136. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  137. struct ieee80211_if_init_conf conf;
  138. int res;
  139. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  140. /* we hold the RTNL here so can safely walk the list */
  141. list_for_each_entry(nsdata, &local->interfaces, list) {
  142. struct net_device *ndev = nsdata->dev;
  143. if (ndev != dev && ndev != local->mdev && netif_running(ndev) &&
  144. compare_ether_addr(dev->dev_addr, ndev->dev_addr) == 0) {
  145. /*
  146. * check whether it may have the same address
  147. */
  148. if (!identical_mac_addr_allowed(sdata->type,
  149. nsdata->type))
  150. return -ENOTUNIQ;
  151. /*
  152. * can only add VLANs to enabled APs
  153. */
  154. if (sdata->type == IEEE80211_IF_TYPE_VLAN &&
  155. nsdata->type == IEEE80211_IF_TYPE_AP &&
  156. netif_running(nsdata->dev))
  157. sdata->u.vlan.ap = nsdata;
  158. }
  159. }
  160. switch (sdata->type) {
  161. case IEEE80211_IF_TYPE_WDS:
  162. if (is_zero_ether_addr(sdata->u.wds.remote_addr))
  163. return -ENOLINK;
  164. break;
  165. case IEEE80211_IF_TYPE_VLAN:
  166. if (!sdata->u.vlan.ap)
  167. return -ENOLINK;
  168. break;
  169. case IEEE80211_IF_TYPE_AP:
  170. case IEEE80211_IF_TYPE_STA:
  171. case IEEE80211_IF_TYPE_MNTR:
  172. case IEEE80211_IF_TYPE_IBSS:
  173. /* no special treatment */
  174. break;
  175. case IEEE80211_IF_TYPE_INVALID:
  176. /* cannot happen */
  177. WARN_ON(1);
  178. break;
  179. }
  180. if (local->open_count == 0) {
  181. res = 0;
  182. if (local->ops->start)
  183. res = local->ops->start(local_to_hw(local));
  184. if (res)
  185. return res;
  186. }
  187. switch (sdata->type) {
  188. case IEEE80211_IF_TYPE_VLAN:
  189. list_add(&sdata->u.vlan.list, &sdata->u.vlan.ap->u.ap.vlans);
  190. /* no need to tell driver */
  191. break;
  192. case IEEE80211_IF_TYPE_MNTR:
  193. /* must be before the call to ieee80211_configure_filter */
  194. local->monitors++;
  195. if (local->monitors == 1) {
  196. netif_tx_lock_bh(local->mdev);
  197. ieee80211_configure_filter(local);
  198. netif_tx_unlock_bh(local->mdev);
  199. local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
  200. ieee80211_hw_config(local);
  201. }
  202. break;
  203. case IEEE80211_IF_TYPE_STA:
  204. case IEEE80211_IF_TYPE_IBSS:
  205. sdata->u.sta.flags &= ~IEEE80211_STA_PREV_BSSID_SET;
  206. /* fall through */
  207. default:
  208. conf.if_id = dev->ifindex;
  209. conf.type = sdata->type;
  210. conf.mac_addr = dev->dev_addr;
  211. res = local->ops->add_interface(local_to_hw(local), &conf);
  212. if (res && !local->open_count && local->ops->stop)
  213. local->ops->stop(local_to_hw(local));
  214. if (res)
  215. return res;
  216. ieee80211_if_config(dev);
  217. ieee80211_reset_erp_info(dev);
  218. ieee80211_enable_keys(sdata);
  219. if (sdata->type == IEEE80211_IF_TYPE_STA &&
  220. !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
  221. netif_carrier_off(dev);
  222. else
  223. netif_carrier_on(dev);
  224. }
  225. if (local->open_count == 0) {
  226. res = dev_open(local->mdev);
  227. WARN_ON(res);
  228. tasklet_enable(&local->tx_pending_tasklet);
  229. tasklet_enable(&local->tasklet);
  230. }
  231. local->open_count++;
  232. netif_start_queue(dev);
  233. return 0;
  234. }
  235. static int ieee80211_stop(struct net_device *dev)
  236. {
  237. struct ieee80211_sub_if_data *sdata;
  238. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  239. struct ieee80211_if_init_conf conf;
  240. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  241. netif_stop_queue(dev);
  242. dev_mc_unsync(local->mdev, dev);
  243. /* down all dependent devices, that is VLANs */
  244. if (sdata->type == IEEE80211_IF_TYPE_AP) {
  245. struct ieee80211_sub_if_data *vlan, *tmp;
  246. list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans,
  247. u.vlan.list)
  248. dev_close(vlan->dev);
  249. WARN_ON(!list_empty(&sdata->u.ap.vlans));
  250. }
  251. local->open_count--;
  252. switch (sdata->type) {
  253. case IEEE80211_IF_TYPE_VLAN:
  254. list_del(&sdata->u.vlan.list);
  255. sdata->u.vlan.ap = NULL;
  256. /* no need to tell driver */
  257. break;
  258. case IEEE80211_IF_TYPE_MNTR:
  259. local->monitors--;
  260. if (local->monitors == 0) {
  261. netif_tx_lock_bh(local->mdev);
  262. ieee80211_configure_filter(local);
  263. netif_tx_unlock_bh(local->mdev);
  264. local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
  265. ieee80211_hw_config(local);
  266. }
  267. break;
  268. case IEEE80211_IF_TYPE_STA:
  269. case IEEE80211_IF_TYPE_IBSS:
  270. sdata->u.sta.state = IEEE80211_DISABLED;
  271. del_timer_sync(&sdata->u.sta.timer);
  272. /*
  273. * When we get here, the interface is marked down.
  274. * Call synchronize_rcu() to wait for the RX path
  275. * should it be using the interface and enqueuing
  276. * frames at this very time on another CPU.
  277. */
  278. synchronize_rcu();
  279. skb_queue_purge(&sdata->u.sta.skb_queue);
  280. if (!local->ops->hw_scan &&
  281. local->scan_dev == sdata->dev) {
  282. local->sta_scanning = 0;
  283. cancel_delayed_work(&local->scan_work);
  284. }
  285. flush_workqueue(local->hw.workqueue);
  286. /* fall through */
  287. default:
  288. conf.if_id = dev->ifindex;
  289. conf.type = sdata->type;
  290. conf.mac_addr = dev->dev_addr;
  291. /* disable all keys for as long as this netdev is down */
  292. ieee80211_disable_keys(sdata);
  293. local->ops->remove_interface(local_to_hw(local), &conf);
  294. }
  295. if (local->open_count == 0) {
  296. if (netif_running(local->mdev))
  297. dev_close(local->mdev);
  298. if (local->ops->stop)
  299. local->ops->stop(local_to_hw(local));
  300. tasklet_disable(&local->tx_pending_tasklet);
  301. tasklet_disable(&local->tasklet);
  302. }
  303. return 0;
  304. }
  305. static void ieee80211_set_multicast_list(struct net_device *dev)
  306. {
  307. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  308. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  309. int allmulti, promisc, sdata_allmulti, sdata_promisc;
  310. allmulti = !!(dev->flags & IFF_ALLMULTI);
  311. promisc = !!(dev->flags & IFF_PROMISC);
  312. sdata_allmulti = sdata->flags & IEEE80211_SDATA_ALLMULTI;
  313. sdata_promisc = sdata->flags & IEEE80211_SDATA_PROMISC;
  314. if (allmulti != sdata_allmulti) {
  315. if (dev->flags & IFF_ALLMULTI)
  316. atomic_inc(&local->iff_allmultis);
  317. else
  318. atomic_dec(&local->iff_allmultis);
  319. sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
  320. }
  321. if (promisc != sdata_promisc) {
  322. if (dev->flags & IFF_PROMISC)
  323. atomic_inc(&local->iff_promiscs);
  324. else
  325. atomic_dec(&local->iff_promiscs);
  326. sdata->flags ^= IEEE80211_SDATA_PROMISC;
  327. }
  328. dev_mc_sync(local->mdev, dev);
  329. }
  330. static const struct header_ops ieee80211_header_ops = {
  331. .create = eth_header,
  332. .parse = header_parse_80211,
  333. .rebuild = eth_rebuild_header,
  334. .cache = eth_header_cache,
  335. .cache_update = eth_header_cache_update,
  336. };
  337. /* Must not be called for mdev */
  338. void ieee80211_if_setup(struct net_device *dev)
  339. {
  340. ether_setup(dev);
  341. dev->header_ops = &ieee80211_header_ops;
  342. dev->hard_start_xmit = ieee80211_subif_start_xmit;
  343. dev->wireless_handlers = &ieee80211_iw_handler_def;
  344. dev->set_multicast_list = ieee80211_set_multicast_list;
  345. dev->change_mtu = ieee80211_change_mtu;
  346. dev->open = ieee80211_open;
  347. dev->stop = ieee80211_stop;
  348. dev->destructor = ieee80211_if_free;
  349. }
  350. /* WDS specialties */
  351. int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr)
  352. {
  353. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  354. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  355. struct sta_info *sta;
  356. DECLARE_MAC_BUF(mac);
  357. if (compare_ether_addr(remote_addr, sdata->u.wds.remote_addr) == 0)
  358. return 0;
  359. /* Create STA entry for the new peer */
  360. sta = sta_info_add(local, dev, remote_addr, GFP_KERNEL);
  361. if (!sta)
  362. return -ENOMEM;
  363. sta_info_put(sta);
  364. /* Remove STA entry for the old peer */
  365. sta = sta_info_get(local, sdata->u.wds.remote_addr);
  366. if (sta) {
  367. sta_info_free(sta);
  368. sta_info_put(sta);
  369. } else {
  370. printk(KERN_DEBUG "%s: could not find STA entry for WDS link "
  371. "peer %s\n",
  372. dev->name, print_mac(mac, sdata->u.wds.remote_addr));
  373. }
  374. /* Update WDS link data */
  375. memcpy(&sdata->u.wds.remote_addr, remote_addr, ETH_ALEN);
  376. return 0;
  377. }
  378. /* everything else */
  379. static int __ieee80211_if_config(struct net_device *dev,
  380. struct sk_buff *beacon,
  381. struct ieee80211_tx_control *control)
  382. {
  383. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  384. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  385. struct ieee80211_if_conf conf;
  386. if (!local->ops->config_interface || !netif_running(dev))
  387. return 0;
  388. memset(&conf, 0, sizeof(conf));
  389. conf.type = sdata->type;
  390. if (sdata->type == IEEE80211_IF_TYPE_STA ||
  391. sdata->type == IEEE80211_IF_TYPE_IBSS) {
  392. conf.bssid = sdata->u.sta.bssid;
  393. conf.ssid = sdata->u.sta.ssid;
  394. conf.ssid_len = sdata->u.sta.ssid_len;
  395. } else if (sdata->type == IEEE80211_IF_TYPE_AP) {
  396. conf.ssid = sdata->u.ap.ssid;
  397. conf.ssid_len = sdata->u.ap.ssid_len;
  398. conf.beacon = beacon;
  399. conf.beacon_control = control;
  400. }
  401. return local->ops->config_interface(local_to_hw(local),
  402. dev->ifindex, &conf);
  403. }
  404. int ieee80211_if_config(struct net_device *dev)
  405. {
  406. return __ieee80211_if_config(dev, NULL, NULL);
  407. }
  408. int ieee80211_if_config_beacon(struct net_device *dev)
  409. {
  410. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  411. struct ieee80211_tx_control control;
  412. struct sk_buff *skb;
  413. if (!(local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
  414. return 0;
  415. skb = ieee80211_beacon_get(local_to_hw(local), dev->ifindex, &control);
  416. if (!skb)
  417. return -ENOMEM;
  418. return __ieee80211_if_config(dev, skb, &control);
  419. }
  420. int ieee80211_hw_config(struct ieee80211_local *local)
  421. {
  422. struct ieee80211_hw_mode *mode;
  423. struct ieee80211_channel *chan;
  424. int ret = 0;
  425. if (local->sta_scanning) {
  426. chan = local->scan_channel;
  427. mode = local->scan_hw_mode;
  428. } else {
  429. chan = local->oper_channel;
  430. mode = local->oper_hw_mode;
  431. }
  432. local->hw.conf.channel = chan->chan;
  433. local->hw.conf.channel_val = chan->val;
  434. if (!local->hw.conf.power_level) {
  435. local->hw.conf.power_level = chan->power_level;
  436. } else {
  437. local->hw.conf.power_level = min(chan->power_level,
  438. local->hw.conf.power_level);
  439. }
  440. local->hw.conf.freq = chan->freq;
  441. local->hw.conf.phymode = mode->mode;
  442. local->hw.conf.antenna_max = chan->antenna_max;
  443. local->hw.conf.chan = chan;
  444. local->hw.conf.mode = mode;
  445. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  446. printk(KERN_DEBUG "HW CONFIG: channel=%d freq=%d "
  447. "phymode=%d\n", local->hw.conf.channel, local->hw.conf.freq,
  448. local->hw.conf.phymode);
  449. #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
  450. if (local->open_count)
  451. ret = local->ops->config(local_to_hw(local), &local->hw.conf);
  452. return ret;
  453. }
  454. void ieee80211_erp_info_change_notify(struct net_device *dev, u8 changes)
  455. {
  456. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  457. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  458. if (local->ops->erp_ie_changed)
  459. local->ops->erp_ie_changed(local_to_hw(local), changes,
  460. !!(sdata->flags & IEEE80211_SDATA_USE_PROTECTION),
  461. !(sdata->flags & IEEE80211_SDATA_SHORT_PREAMBLE));
  462. }
  463. void ieee80211_reset_erp_info(struct net_device *dev)
  464. {
  465. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  466. sdata->flags &= ~(IEEE80211_SDATA_USE_PROTECTION |
  467. IEEE80211_SDATA_SHORT_PREAMBLE);
  468. ieee80211_erp_info_change_notify(dev,
  469. IEEE80211_ERP_CHANGE_PROTECTION |
  470. IEEE80211_ERP_CHANGE_PREAMBLE);
  471. }
  472. void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
  473. struct sk_buff *skb,
  474. struct ieee80211_tx_status *status)
  475. {
  476. struct ieee80211_local *local = hw_to_local(hw);
  477. struct ieee80211_tx_status *saved;
  478. int tmp;
  479. skb->dev = local->mdev;
  480. saved = kmalloc(sizeof(struct ieee80211_tx_status), GFP_ATOMIC);
  481. if (unlikely(!saved)) {
  482. if (net_ratelimit())
  483. printk(KERN_WARNING "%s: Not enough memory, "
  484. "dropping tx status", skb->dev->name);
  485. /* should be dev_kfree_skb_irq, but due to this function being
  486. * named _irqsafe instead of just _irq we can't be sure that
  487. * people won't call it from non-irq contexts */
  488. dev_kfree_skb_any(skb);
  489. return;
  490. }
  491. memcpy(saved, status, sizeof(struct ieee80211_tx_status));
  492. /* copy pointer to saved status into skb->cb for use by tasklet */
  493. memcpy(skb->cb, &saved, sizeof(saved));
  494. skb->pkt_type = IEEE80211_TX_STATUS_MSG;
  495. skb_queue_tail(status->control.flags & IEEE80211_TXCTL_REQ_TX_STATUS ?
  496. &local->skb_queue : &local->skb_queue_unreliable, skb);
  497. tmp = skb_queue_len(&local->skb_queue) +
  498. skb_queue_len(&local->skb_queue_unreliable);
  499. while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
  500. (skb = skb_dequeue(&local->skb_queue_unreliable))) {
  501. memcpy(&saved, skb->cb, sizeof(saved));
  502. kfree(saved);
  503. dev_kfree_skb_irq(skb);
  504. tmp--;
  505. I802_DEBUG_INC(local->tx_status_drop);
  506. }
  507. tasklet_schedule(&local->tasklet);
  508. }
  509. EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
  510. static void ieee80211_tasklet_handler(unsigned long data)
  511. {
  512. struct ieee80211_local *local = (struct ieee80211_local *) data;
  513. struct sk_buff *skb;
  514. struct ieee80211_rx_status rx_status;
  515. struct ieee80211_tx_status *tx_status;
  516. while ((skb = skb_dequeue(&local->skb_queue)) ||
  517. (skb = skb_dequeue(&local->skb_queue_unreliable))) {
  518. switch (skb->pkt_type) {
  519. case IEEE80211_RX_MSG:
  520. /* status is in skb->cb */
  521. memcpy(&rx_status, skb->cb, sizeof(rx_status));
  522. /* Clear skb->type in order to not confuse kernel
  523. * netstack. */
  524. skb->pkt_type = 0;
  525. __ieee80211_rx(local_to_hw(local), skb, &rx_status);
  526. break;
  527. case IEEE80211_TX_STATUS_MSG:
  528. /* get pointer to saved status out of skb->cb */
  529. memcpy(&tx_status, skb->cb, sizeof(tx_status));
  530. skb->pkt_type = 0;
  531. ieee80211_tx_status(local_to_hw(local),
  532. skb, tx_status);
  533. kfree(tx_status);
  534. break;
  535. default: /* should never get here! */
  536. printk(KERN_ERR "%s: Unknown message type (%d)\n",
  537. wiphy_name(local->hw.wiphy), skb->pkt_type);
  538. dev_kfree_skb(skb);
  539. break;
  540. }
  541. }
  542. }
  543. /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
  544. * make a prepared TX frame (one that has been given to hw) to look like brand
  545. * new IEEE 802.11 frame that is ready to go through TX processing again.
  546. * Also, tx_packet_data in cb is restored from tx_control. */
  547. static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
  548. struct ieee80211_key *key,
  549. struct sk_buff *skb,
  550. struct ieee80211_tx_control *control)
  551. {
  552. int hdrlen, iv_len, mic_len;
  553. struct ieee80211_tx_packet_data *pkt_data;
  554. pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
  555. pkt_data->ifindex = control->ifindex;
  556. pkt_data->flags = 0;
  557. if (control->flags & IEEE80211_TXCTL_REQ_TX_STATUS)
  558. pkt_data->flags |= IEEE80211_TXPD_REQ_TX_STATUS;
  559. if (control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)
  560. pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT;
  561. if (control->flags & IEEE80211_TXCTL_REQUEUE)
  562. pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
  563. pkt_data->queue = control->queue;
  564. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  565. if (!key)
  566. goto no_key;
  567. switch (key->conf.alg) {
  568. case ALG_WEP:
  569. iv_len = WEP_IV_LEN;
  570. mic_len = WEP_ICV_LEN;
  571. break;
  572. case ALG_TKIP:
  573. iv_len = TKIP_IV_LEN;
  574. mic_len = TKIP_ICV_LEN;
  575. break;
  576. case ALG_CCMP:
  577. iv_len = CCMP_HDR_LEN;
  578. mic_len = CCMP_MIC_LEN;
  579. break;
  580. default:
  581. goto no_key;
  582. }
  583. if (skb->len >= mic_len &&
  584. !(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
  585. skb_trim(skb, skb->len - mic_len);
  586. if (skb->len >= iv_len && skb->len > hdrlen) {
  587. memmove(skb->data + iv_len, skb->data, hdrlen);
  588. skb_pull(skb, iv_len);
  589. }
  590. no_key:
  591. {
  592. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  593. u16 fc = le16_to_cpu(hdr->frame_control);
  594. if ((fc & 0x8C) == 0x88) /* QoS Control Field */ {
  595. fc &= ~IEEE80211_STYPE_QOS_DATA;
  596. hdr->frame_control = cpu_to_le16(fc);
  597. memmove(skb->data + 2, skb->data, hdrlen - 2);
  598. skb_pull(skb, 2);
  599. }
  600. }
  601. }
  602. void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
  603. struct ieee80211_tx_status *status)
  604. {
  605. struct sk_buff *skb2;
  606. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  607. struct ieee80211_local *local = hw_to_local(hw);
  608. u16 frag, type;
  609. struct ieee80211_tx_status_rtap_hdr *rthdr;
  610. struct ieee80211_sub_if_data *sdata;
  611. int monitors;
  612. if (!status) {
  613. printk(KERN_ERR
  614. "%s: ieee80211_tx_status called with NULL status\n",
  615. wiphy_name(local->hw.wiphy));
  616. dev_kfree_skb(skb);
  617. return;
  618. }
  619. if (status->excessive_retries) {
  620. struct sta_info *sta;
  621. sta = sta_info_get(local, hdr->addr1);
  622. if (sta) {
  623. if (sta->flags & WLAN_STA_PS) {
  624. /* The STA is in power save mode, so assume
  625. * that this TX packet failed because of that.
  626. */
  627. status->excessive_retries = 0;
  628. status->flags |= IEEE80211_TX_STATUS_TX_FILTERED;
  629. }
  630. sta_info_put(sta);
  631. }
  632. }
  633. if (status->flags & IEEE80211_TX_STATUS_TX_FILTERED) {
  634. struct sta_info *sta;
  635. sta = sta_info_get(local, hdr->addr1);
  636. if (sta) {
  637. sta->tx_filtered_count++;
  638. /* Clear the TX filter mask for this STA when sending
  639. * the next packet. If the STA went to power save mode,
  640. * this will happen when it is waking up for the next
  641. * time. */
  642. sta->clear_dst_mask = 1;
  643. /* TODO: Is the WLAN_STA_PS flag always set here or is
  644. * the race between RX and TX status causing some
  645. * packets to be filtered out before 80211.o gets an
  646. * update for PS status? This seems to be the case, so
  647. * no changes are likely to be needed. */
  648. if (sta->flags & WLAN_STA_PS &&
  649. skb_queue_len(&sta->tx_filtered) <
  650. STA_MAX_TX_BUFFER) {
  651. ieee80211_remove_tx_extra(local, sta->key,
  652. skb,
  653. &status->control);
  654. skb_queue_tail(&sta->tx_filtered, skb);
  655. } else if (!(sta->flags & WLAN_STA_PS) &&
  656. !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) {
  657. /* Software retry the packet once */
  658. status->control.flags |= IEEE80211_TXCTL_REQUEUE;
  659. ieee80211_remove_tx_extra(local, sta->key,
  660. skb,
  661. &status->control);
  662. dev_queue_xmit(skb);
  663. } else {
  664. if (net_ratelimit()) {
  665. printk(KERN_DEBUG "%s: dropped TX "
  666. "filtered frame queue_len=%d "
  667. "PS=%d @%lu\n",
  668. wiphy_name(local->hw.wiphy),
  669. skb_queue_len(
  670. &sta->tx_filtered),
  671. !!(sta->flags & WLAN_STA_PS),
  672. jiffies);
  673. }
  674. dev_kfree_skb(skb);
  675. }
  676. sta_info_put(sta);
  677. return;
  678. }
  679. } else {
  680. /* FIXME: STUPID to call this with both local and local->mdev */
  681. rate_control_tx_status(local, local->mdev, skb, status);
  682. }
  683. ieee80211_led_tx(local, 0);
  684. /* SNMP counters
  685. * Fragments are passed to low-level drivers as separate skbs, so these
  686. * are actually fragments, not frames. Update frame counters only for
  687. * the first fragment of the frame. */
  688. frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
  689. type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
  690. if (status->flags & IEEE80211_TX_STATUS_ACK) {
  691. if (frag == 0) {
  692. local->dot11TransmittedFrameCount++;
  693. if (is_multicast_ether_addr(hdr->addr1))
  694. local->dot11MulticastTransmittedFrameCount++;
  695. if (status->retry_count > 0)
  696. local->dot11RetryCount++;
  697. if (status->retry_count > 1)
  698. local->dot11MultipleRetryCount++;
  699. }
  700. /* This counter shall be incremented for an acknowledged MPDU
  701. * with an individual address in the address 1 field or an MPDU
  702. * with a multicast address in the address 1 field of type Data
  703. * or Management. */
  704. if (!is_multicast_ether_addr(hdr->addr1) ||
  705. type == IEEE80211_FTYPE_DATA ||
  706. type == IEEE80211_FTYPE_MGMT)
  707. local->dot11TransmittedFragmentCount++;
  708. } else {
  709. if (frag == 0)
  710. local->dot11FailedCount++;
  711. }
  712. /* this was a transmitted frame, but now we want to reuse it */
  713. skb_orphan(skb);
  714. if (!local->monitors) {
  715. dev_kfree_skb(skb);
  716. return;
  717. }
  718. /* send frame to monitor interfaces now */
  719. if (skb_headroom(skb) < sizeof(*rthdr)) {
  720. printk(KERN_ERR "ieee80211_tx_status: headroom too small\n");
  721. dev_kfree_skb(skb);
  722. return;
  723. }
  724. rthdr = (struct ieee80211_tx_status_rtap_hdr*)
  725. skb_push(skb, sizeof(*rthdr));
  726. memset(rthdr, 0, sizeof(*rthdr));
  727. rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
  728. rthdr->hdr.it_present =
  729. cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
  730. (1 << IEEE80211_RADIOTAP_DATA_RETRIES));
  731. if (!(status->flags & IEEE80211_TX_STATUS_ACK) &&
  732. !is_multicast_ether_addr(hdr->addr1))
  733. rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
  734. if ((status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) &&
  735. (status->control.flags & IEEE80211_TXCTL_USE_CTS_PROTECT))
  736. rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
  737. else if (status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS)
  738. rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
  739. rthdr->data_retries = status->retry_count;
  740. rcu_read_lock();
  741. monitors = local->monitors;
  742. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  743. /*
  744. * Using the monitors counter is possibly racy, but
  745. * if the value is wrong we simply either clone the skb
  746. * once too much or forget sending it to one monitor iface
  747. * The latter case isn't nice but fixing the race is much
  748. * more complicated.
  749. */
  750. if (!monitors || !skb)
  751. goto out;
  752. if (sdata->type == IEEE80211_IF_TYPE_MNTR) {
  753. if (!netif_running(sdata->dev))
  754. continue;
  755. monitors--;
  756. if (monitors)
  757. skb2 = skb_clone(skb, GFP_ATOMIC);
  758. else
  759. skb2 = NULL;
  760. skb->dev = sdata->dev;
  761. /* XXX: is this sufficient for BPF? */
  762. skb_set_mac_header(skb, 0);
  763. skb->ip_summed = CHECKSUM_UNNECESSARY;
  764. skb->pkt_type = PACKET_OTHERHOST;
  765. skb->protocol = htons(ETH_P_802_2);
  766. memset(skb->cb, 0, sizeof(skb->cb));
  767. netif_rx(skb);
  768. skb = skb2;
  769. }
  770. }
  771. out:
  772. rcu_read_unlock();
  773. if (skb)
  774. dev_kfree_skb(skb);
  775. }
  776. EXPORT_SYMBOL(ieee80211_tx_status);
  777. struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
  778. const struct ieee80211_ops *ops)
  779. {
  780. struct net_device *mdev;
  781. struct ieee80211_local *local;
  782. struct ieee80211_sub_if_data *sdata;
  783. int priv_size;
  784. struct wiphy *wiphy;
  785. /* Ensure 32-byte alignment of our private data and hw private data.
  786. * We use the wiphy priv data for both our ieee80211_local and for
  787. * the driver's private data
  788. *
  789. * In memory it'll be like this:
  790. *
  791. * +-------------------------+
  792. * | struct wiphy |
  793. * +-------------------------+
  794. * | struct ieee80211_local |
  795. * +-------------------------+
  796. * | driver's private data |
  797. * +-------------------------+
  798. *
  799. */
  800. priv_size = ((sizeof(struct ieee80211_local) +
  801. NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
  802. priv_data_len;
  803. wiphy = wiphy_new(&mac80211_config_ops, priv_size);
  804. if (!wiphy)
  805. return NULL;
  806. wiphy->privid = mac80211_wiphy_privid;
  807. local = wiphy_priv(wiphy);
  808. local->hw.wiphy = wiphy;
  809. local->hw.priv = (char *)local +
  810. ((sizeof(struct ieee80211_local) +
  811. NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
  812. BUG_ON(!ops->tx);
  813. BUG_ON(!ops->start);
  814. BUG_ON(!ops->stop);
  815. BUG_ON(!ops->config);
  816. BUG_ON(!ops->add_interface);
  817. BUG_ON(!ops->remove_interface);
  818. BUG_ON(!ops->configure_filter);
  819. local->ops = ops;
  820. /* for now, mdev needs sub_if_data :/ */
  821. mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
  822. "wmaster%d", ether_setup);
  823. if (!mdev) {
  824. wiphy_free(wiphy);
  825. return NULL;
  826. }
  827. sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
  828. mdev->ieee80211_ptr = &sdata->wdev;
  829. sdata->wdev.wiphy = wiphy;
  830. local->hw.queues = 1; /* default */
  831. local->mdev = mdev;
  832. local->rx_pre_handlers = ieee80211_rx_pre_handlers;
  833. local->rx_handlers = ieee80211_rx_handlers;
  834. local->tx_handlers = ieee80211_tx_handlers;
  835. local->bridge_packets = 1;
  836. local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
  837. local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
  838. local->short_retry_limit = 7;
  839. local->long_retry_limit = 4;
  840. local->hw.conf.radio_enabled = 1;
  841. local->enabled_modes = ~0;
  842. INIT_LIST_HEAD(&local->modes_list);
  843. INIT_LIST_HEAD(&local->interfaces);
  844. INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work);
  845. ieee80211_rx_bss_list_init(mdev);
  846. sta_info_init(local);
  847. mdev->hard_start_xmit = ieee80211_master_start_xmit;
  848. mdev->open = ieee80211_master_open;
  849. mdev->stop = ieee80211_master_stop;
  850. mdev->type = ARPHRD_IEEE80211;
  851. mdev->header_ops = &ieee80211_header_ops;
  852. mdev->set_multicast_list = ieee80211_master_set_multicast_list;
  853. sdata->type = IEEE80211_IF_TYPE_AP;
  854. sdata->dev = mdev;
  855. sdata->local = local;
  856. sdata->u.ap.force_unicast_rateidx = -1;
  857. sdata->u.ap.max_ratectrl_rateidx = -1;
  858. ieee80211_if_sdata_init(sdata);
  859. /* no RCU needed since we're still during init phase */
  860. list_add_tail(&sdata->list, &local->interfaces);
  861. tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
  862. (unsigned long)local);
  863. tasklet_disable(&local->tx_pending_tasklet);
  864. tasklet_init(&local->tasklet,
  865. ieee80211_tasklet_handler,
  866. (unsigned long) local);
  867. tasklet_disable(&local->tasklet);
  868. skb_queue_head_init(&local->skb_queue);
  869. skb_queue_head_init(&local->skb_queue_unreliable);
  870. return local_to_hw(local);
  871. }
  872. EXPORT_SYMBOL(ieee80211_alloc_hw);
  873. int ieee80211_register_hw(struct ieee80211_hw *hw)
  874. {
  875. struct ieee80211_local *local = hw_to_local(hw);
  876. const char *name;
  877. int result;
  878. result = wiphy_register(local->hw.wiphy);
  879. if (result < 0)
  880. return result;
  881. name = wiphy_dev(local->hw.wiphy)->driver->name;
  882. local->hw.workqueue = create_singlethread_workqueue(name);
  883. if (!local->hw.workqueue) {
  884. result = -ENOMEM;
  885. goto fail_workqueue;
  886. }
  887. /*
  888. * The hardware needs headroom for sending the frame,
  889. * and we need some headroom for passing the frame to monitor
  890. * interfaces, but never both at the same time.
  891. */
  892. local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
  893. sizeof(struct ieee80211_tx_status_rtap_hdr));
  894. debugfs_hw_add(local);
  895. local->hw.conf.beacon_int = 1000;
  896. local->wstats_flags |= local->hw.max_rssi ?
  897. IW_QUAL_LEVEL_UPDATED : IW_QUAL_LEVEL_INVALID;
  898. local->wstats_flags |= local->hw.max_signal ?
  899. IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
  900. local->wstats_flags |= local->hw.max_noise ?
  901. IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
  902. if (local->hw.max_rssi < 0 || local->hw.max_noise < 0)
  903. local->wstats_flags |= IW_QUAL_DBM;
  904. result = sta_info_start(local);
  905. if (result < 0)
  906. goto fail_sta_info;
  907. rtnl_lock();
  908. result = dev_alloc_name(local->mdev, local->mdev->name);
  909. if (result < 0)
  910. goto fail_dev;
  911. memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
  912. SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy));
  913. result = register_netdevice(local->mdev);
  914. if (result < 0)
  915. goto fail_dev;
  916. ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
  917. ieee80211_if_set_type(local->mdev, IEEE80211_IF_TYPE_AP);
  918. result = ieee80211_init_rate_ctrl_alg(local, NULL);
  919. if (result < 0) {
  920. printk(KERN_DEBUG "%s: Failed to initialize rate control "
  921. "algorithm\n", wiphy_name(local->hw.wiphy));
  922. goto fail_rate;
  923. }
  924. result = ieee80211_wep_init(local);
  925. if (result < 0) {
  926. printk(KERN_DEBUG "%s: Failed to initialize wep\n",
  927. wiphy_name(local->hw.wiphy));
  928. goto fail_wep;
  929. }
  930. ieee80211_install_qdisc(local->mdev);
  931. /* add one default STA interface */
  932. result = ieee80211_if_add(local->mdev, "wlan%d", NULL,
  933. IEEE80211_IF_TYPE_STA);
  934. if (result)
  935. printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
  936. wiphy_name(local->hw.wiphy));
  937. local->reg_state = IEEE80211_DEV_REGISTERED;
  938. rtnl_unlock();
  939. ieee80211_led_init(local);
  940. return 0;
  941. fail_wep:
  942. rate_control_deinitialize(local);
  943. fail_rate:
  944. ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
  945. unregister_netdevice(local->mdev);
  946. fail_dev:
  947. rtnl_unlock();
  948. sta_info_stop(local);
  949. fail_sta_info:
  950. debugfs_hw_del(local);
  951. destroy_workqueue(local->hw.workqueue);
  952. fail_workqueue:
  953. wiphy_unregister(local->hw.wiphy);
  954. return result;
  955. }
  956. EXPORT_SYMBOL(ieee80211_register_hw);
  957. int ieee80211_register_hwmode(struct ieee80211_hw *hw,
  958. struct ieee80211_hw_mode *mode)
  959. {
  960. struct ieee80211_local *local = hw_to_local(hw);
  961. struct ieee80211_rate *rate;
  962. int i;
  963. INIT_LIST_HEAD(&mode->list);
  964. list_add_tail(&mode->list, &local->modes_list);
  965. local->hw_modes |= (1 << mode->mode);
  966. for (i = 0; i < mode->num_rates; i++) {
  967. rate = &(mode->rates[i]);
  968. rate->rate_inv = CHAN_UTIL_RATE_LCM / rate->rate;
  969. }
  970. ieee80211_prepare_rates(local, mode);
  971. if (!local->oper_hw_mode) {
  972. /* Default to this mode */
  973. local->hw.conf.phymode = mode->mode;
  974. local->oper_hw_mode = local->scan_hw_mode = mode;
  975. local->oper_channel = local->scan_channel = &mode->channels[0];
  976. local->hw.conf.mode = local->oper_hw_mode;
  977. local->hw.conf.chan = local->oper_channel;
  978. }
  979. if (!(hw->flags & IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED))
  980. ieee80211_set_default_regdomain(mode);
  981. return 0;
  982. }
  983. EXPORT_SYMBOL(ieee80211_register_hwmode);
  984. void ieee80211_unregister_hw(struct ieee80211_hw *hw)
  985. {
  986. struct ieee80211_local *local = hw_to_local(hw);
  987. struct ieee80211_sub_if_data *sdata, *tmp;
  988. int i;
  989. tasklet_kill(&local->tx_pending_tasklet);
  990. tasklet_kill(&local->tasklet);
  991. rtnl_lock();
  992. BUG_ON(local->reg_state != IEEE80211_DEV_REGISTERED);
  993. local->reg_state = IEEE80211_DEV_UNREGISTERED;
  994. /*
  995. * At this point, interface list manipulations are fine
  996. * because the driver cannot be handing us frames any
  997. * more and the tasklet is killed.
  998. */
  999. /*
  1000. * First, we remove all non-master interfaces. Do this because they
  1001. * may have bss pointer dependency on the master, and when we free
  1002. * the master these would be freed as well, breaking our list
  1003. * iteration completely.
  1004. */
  1005. list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
  1006. if (sdata->dev == local->mdev)
  1007. continue;
  1008. list_del(&sdata->list);
  1009. __ieee80211_if_del(local, sdata);
  1010. }
  1011. /* then, finally, remove the master interface */
  1012. __ieee80211_if_del(local, IEEE80211_DEV_TO_SUB_IF(local->mdev));
  1013. rtnl_unlock();
  1014. ieee80211_rx_bss_list_deinit(local->mdev);
  1015. ieee80211_clear_tx_pending(local);
  1016. sta_info_stop(local);
  1017. rate_control_deinitialize(local);
  1018. debugfs_hw_del(local);
  1019. for (i = 0; i < NUM_IEEE80211_MODES; i++) {
  1020. kfree(local->supp_rates[i]);
  1021. kfree(local->basic_rates[i]);
  1022. }
  1023. if (skb_queue_len(&local->skb_queue)
  1024. || skb_queue_len(&local->skb_queue_unreliable))
  1025. printk(KERN_WARNING "%s: skb_queue not empty\n",
  1026. wiphy_name(local->hw.wiphy));
  1027. skb_queue_purge(&local->skb_queue);
  1028. skb_queue_purge(&local->skb_queue_unreliable);
  1029. destroy_workqueue(local->hw.workqueue);
  1030. wiphy_unregister(local->hw.wiphy);
  1031. ieee80211_wep_free(local);
  1032. ieee80211_led_exit(local);
  1033. }
  1034. EXPORT_SYMBOL(ieee80211_unregister_hw);
  1035. void ieee80211_free_hw(struct ieee80211_hw *hw)
  1036. {
  1037. struct ieee80211_local *local = hw_to_local(hw);
  1038. ieee80211_if_free(local->mdev);
  1039. wiphy_free(local->hw.wiphy);
  1040. }
  1041. EXPORT_SYMBOL(ieee80211_free_hw);
  1042. static int __init ieee80211_init(void)
  1043. {
  1044. struct sk_buff *skb;
  1045. int ret;
  1046. BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb));
  1047. ret = ieee80211_wme_register();
  1048. if (ret) {
  1049. printk(KERN_DEBUG "ieee80211_init: failed to "
  1050. "initialize WME (err=%d)\n", ret);
  1051. return ret;
  1052. }
  1053. ieee80211_debugfs_netdev_init();
  1054. ieee80211_regdomain_init();
  1055. return 0;
  1056. }
  1057. static void __exit ieee80211_exit(void)
  1058. {
  1059. ieee80211_wme_unregister();
  1060. ieee80211_debugfs_netdev_exit();
  1061. }
  1062. subsys_initcall(ieee80211_init);
  1063. module_exit(ieee80211_exit);
  1064. MODULE_DESCRIPTION("IEEE 802.11 subsystem");
  1065. MODULE_LICENSE("GPL");