ieee80211.c 35 KB

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