ieee80211.c 38 KB

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