ieee80211.c 38 KB

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