ieee80211.c 38 KB

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