ieee80211.c 37 KB

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