ieee80211.c 37 KB

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