ieee80211.c 35 KB

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