ieee80211.c 38 KB

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