iface.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316
  1. /*
  2. * Interface handling (except master interface)
  3. *
  4. * Copyright 2002-2005, Instant802 Networks, Inc.
  5. * Copyright 2005-2006, Devicescape Software, Inc.
  6. * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
  7. * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/slab.h>
  14. #include <linux/kernel.h>
  15. #include <linux/if_arp.h>
  16. #include <linux/netdevice.h>
  17. #include <linux/rtnetlink.h>
  18. #include <net/mac80211.h>
  19. #include <net/ieee80211_radiotap.h>
  20. #include "ieee80211_i.h"
  21. #include "sta_info.h"
  22. #include "debugfs_netdev.h"
  23. #include "mesh.h"
  24. #include "led.h"
  25. #include "driver-ops.h"
  26. #include "wme.h"
  27. /**
  28. * DOC: Interface list locking
  29. *
  30. * The interface list in each struct ieee80211_local is protected
  31. * three-fold:
  32. *
  33. * (1) modifications may only be done under the RTNL
  34. * (2) modifications and readers are protected against each other by
  35. * the iflist_mtx.
  36. * (3) modifications are done in an RCU manner so atomic readers
  37. * can traverse the list in RCU-safe blocks.
  38. *
  39. * As a consequence, reads (traversals) of the list can be protected
  40. * by either the RTNL, the iflist_mtx or RCU.
  41. */
  42. static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
  43. {
  44. int meshhdrlen;
  45. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  46. meshhdrlen = (sdata->vif.type == NL80211_IFTYPE_MESH_POINT) ? 5 : 0;
  47. /* FIX: what would be proper limits for MTU?
  48. * This interface uses 802.3 frames. */
  49. if (new_mtu < 256 ||
  50. new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6 - meshhdrlen) {
  51. return -EINVAL;
  52. }
  53. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  54. printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
  55. #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
  56. dev->mtu = new_mtu;
  57. return 0;
  58. }
  59. static int ieee80211_change_mac(struct net_device *dev, void *addr)
  60. {
  61. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  62. struct sockaddr *sa = addr;
  63. int ret;
  64. if (ieee80211_sdata_running(sdata))
  65. return -EBUSY;
  66. ret = eth_mac_addr(dev, sa);
  67. if (ret == 0)
  68. memcpy(sdata->vif.addr, sa->sa_data, ETH_ALEN);
  69. return ret;
  70. }
  71. static inline int identical_mac_addr_allowed(int type1, int type2)
  72. {
  73. return type1 == NL80211_IFTYPE_MONITOR ||
  74. type2 == NL80211_IFTYPE_MONITOR ||
  75. (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_WDS) ||
  76. (type1 == NL80211_IFTYPE_WDS &&
  77. (type2 == NL80211_IFTYPE_WDS ||
  78. type2 == NL80211_IFTYPE_AP)) ||
  79. (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_AP_VLAN) ||
  80. (type1 == NL80211_IFTYPE_AP_VLAN &&
  81. (type2 == NL80211_IFTYPE_AP ||
  82. type2 == NL80211_IFTYPE_AP_VLAN));
  83. }
  84. static int ieee80211_open(struct net_device *dev)
  85. {
  86. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  87. struct ieee80211_sub_if_data *nsdata;
  88. struct ieee80211_local *local = sdata->local;
  89. struct sta_info *sta;
  90. u32 changed = 0;
  91. int res;
  92. u32 hw_reconf_flags = 0;
  93. u8 null_addr[ETH_ALEN] = {0};
  94. /* fail early if user set an invalid address */
  95. if (compare_ether_addr(dev->dev_addr, null_addr) &&
  96. !is_valid_ether_addr(dev->dev_addr))
  97. return -EADDRNOTAVAIL;
  98. /* we hold the RTNL here so can safely walk the list */
  99. list_for_each_entry(nsdata, &local->interfaces, list) {
  100. struct net_device *ndev = nsdata->dev;
  101. if (ndev != dev && ieee80211_sdata_running(nsdata)) {
  102. /*
  103. * Allow only a single IBSS interface to be up at any
  104. * time. This is restricted because beacon distribution
  105. * cannot work properly if both are in the same IBSS.
  106. *
  107. * To remove this restriction we'd have to disallow them
  108. * from setting the same SSID on different IBSS interfaces
  109. * belonging to the same hardware. Then, however, we're
  110. * faced with having to adopt two different TSF timers...
  111. */
  112. if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
  113. nsdata->vif.type == NL80211_IFTYPE_ADHOC)
  114. return -EBUSY;
  115. /*
  116. * The remaining checks are only performed for interfaces
  117. * with the same MAC address.
  118. */
  119. if (compare_ether_addr(dev->dev_addr, ndev->dev_addr))
  120. continue;
  121. /*
  122. * check whether it may have the same address
  123. */
  124. if (!identical_mac_addr_allowed(sdata->vif.type,
  125. nsdata->vif.type))
  126. return -ENOTUNIQ;
  127. /*
  128. * can only add VLANs to enabled APs
  129. */
  130. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  131. nsdata->vif.type == NL80211_IFTYPE_AP)
  132. sdata->bss = &nsdata->u.ap;
  133. }
  134. }
  135. switch (sdata->vif.type) {
  136. case NL80211_IFTYPE_WDS:
  137. if (!is_valid_ether_addr(sdata->u.wds.remote_addr))
  138. return -ENOLINK;
  139. break;
  140. case NL80211_IFTYPE_AP_VLAN:
  141. if (!sdata->bss)
  142. return -ENOLINK;
  143. list_add(&sdata->u.vlan.list, &sdata->bss->vlans);
  144. break;
  145. case NL80211_IFTYPE_AP:
  146. sdata->bss = &sdata->u.ap;
  147. break;
  148. case NL80211_IFTYPE_MESH_POINT:
  149. if (!ieee80211_vif_is_mesh(&sdata->vif))
  150. break;
  151. /* mesh ifaces must set allmulti to forward mcast traffic */
  152. atomic_inc(&local->iff_allmultis);
  153. break;
  154. case NL80211_IFTYPE_STATION:
  155. case NL80211_IFTYPE_MONITOR:
  156. case NL80211_IFTYPE_ADHOC:
  157. /* no special treatment */
  158. break;
  159. case NL80211_IFTYPE_UNSPECIFIED:
  160. case NUM_NL80211_IFTYPES:
  161. /* cannot happen */
  162. WARN_ON(1);
  163. break;
  164. }
  165. if (local->open_count == 0) {
  166. res = drv_start(local);
  167. if (res)
  168. goto err_del_bss;
  169. if (local->ops->napi_poll)
  170. napi_enable(&local->napi);
  171. /* we're brought up, everything changes */
  172. hw_reconf_flags = ~0;
  173. ieee80211_led_radio(local, true);
  174. }
  175. /*
  176. * Check all interfaces and copy the hopefully now-present
  177. * MAC address to those that have the special null one.
  178. */
  179. list_for_each_entry(nsdata, &local->interfaces, list) {
  180. struct net_device *ndev = nsdata->dev;
  181. /*
  182. * No need to check running since we do not allow
  183. * it to start up with this invalid address.
  184. */
  185. if (compare_ether_addr(null_addr, ndev->dev_addr) == 0) {
  186. memcpy(ndev->dev_addr,
  187. local->hw.wiphy->perm_addr,
  188. ETH_ALEN);
  189. memcpy(ndev->perm_addr, ndev->dev_addr, ETH_ALEN);
  190. }
  191. }
  192. /*
  193. * Validate the MAC address for this device.
  194. */
  195. if (!is_valid_ether_addr(dev->dev_addr)) {
  196. if (!local->open_count)
  197. drv_stop(local);
  198. return -EADDRNOTAVAIL;
  199. }
  200. switch (sdata->vif.type) {
  201. case NL80211_IFTYPE_AP_VLAN:
  202. /* no need to tell driver */
  203. break;
  204. case NL80211_IFTYPE_MONITOR:
  205. if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
  206. local->cooked_mntrs++;
  207. break;
  208. }
  209. /* must be before the call to ieee80211_configure_filter */
  210. local->monitors++;
  211. if (local->monitors == 1) {
  212. local->hw.conf.flags |= IEEE80211_CONF_MONITOR;
  213. hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
  214. }
  215. if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
  216. local->fif_fcsfail++;
  217. if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
  218. local->fif_plcpfail++;
  219. if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) {
  220. local->fif_control++;
  221. local->fif_pspoll++;
  222. }
  223. if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
  224. local->fif_other_bss++;
  225. ieee80211_configure_filter(local);
  226. netif_carrier_on(dev);
  227. break;
  228. default:
  229. res = drv_add_interface(local, &sdata->vif);
  230. if (res)
  231. goto err_stop;
  232. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  233. local->fif_other_bss++;
  234. ieee80211_configure_filter(local);
  235. ieee80211_start_mesh(sdata);
  236. } else if (sdata->vif.type == NL80211_IFTYPE_AP) {
  237. local->fif_pspoll++;
  238. ieee80211_configure_filter(local);
  239. }
  240. changed |= ieee80211_reset_erp_info(sdata);
  241. ieee80211_bss_info_change_notify(sdata, changed);
  242. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  243. netif_carrier_off(dev);
  244. else
  245. netif_carrier_on(dev);
  246. }
  247. if (sdata->vif.type == NL80211_IFTYPE_WDS) {
  248. /* Create STA entry for the WDS peer */
  249. sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
  250. GFP_KERNEL);
  251. if (!sta) {
  252. res = -ENOMEM;
  253. goto err_del_interface;
  254. }
  255. /* no locking required since STA is not live yet */
  256. sta->flags |= WLAN_STA_AUTHORIZED;
  257. res = sta_info_insert(sta);
  258. if (res) {
  259. /* STA has been freed */
  260. goto err_del_interface;
  261. }
  262. }
  263. /*
  264. * set_multicast_list will be invoked by the networking core
  265. * which will check whether any increments here were done in
  266. * error and sync them down to the hardware as filter flags.
  267. */
  268. if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
  269. atomic_inc(&local->iff_allmultis);
  270. if (sdata->flags & IEEE80211_SDATA_PROMISC)
  271. atomic_inc(&local->iff_promiscs);
  272. mutex_lock(&local->mtx);
  273. hw_reconf_flags |= __ieee80211_recalc_idle(local);
  274. mutex_unlock(&local->mtx);
  275. local->open_count++;
  276. if (hw_reconf_flags) {
  277. ieee80211_hw_config(local, hw_reconf_flags);
  278. /*
  279. * set default queue parameters so drivers don't
  280. * need to initialise the hardware if the hardware
  281. * doesn't start up with sane defaults
  282. */
  283. ieee80211_set_wmm_default(sdata);
  284. }
  285. ieee80211_recalc_ps(local, -1);
  286. netif_tx_start_all_queues(dev);
  287. return 0;
  288. err_del_interface:
  289. drv_remove_interface(local, &sdata->vif);
  290. err_stop:
  291. if (!local->open_count)
  292. drv_stop(local);
  293. err_del_bss:
  294. sdata->bss = NULL;
  295. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  296. list_del(&sdata->u.vlan.list);
  297. return res;
  298. }
  299. static int ieee80211_stop(struct net_device *dev)
  300. {
  301. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  302. struct ieee80211_local *local = sdata->local;
  303. unsigned long flags;
  304. struct sk_buff *skb, *tmp;
  305. u32 hw_reconf_flags = 0;
  306. int i;
  307. /*
  308. * Stop TX on this interface first.
  309. */
  310. netif_tx_stop_all_queues(dev);
  311. /*
  312. * Purge work for this interface.
  313. */
  314. ieee80211_work_purge(sdata);
  315. /*
  316. * Remove all stations associated with this interface.
  317. *
  318. * This must be done before calling ops->remove_interface()
  319. * because otherwise we can later invoke ops->sta_notify()
  320. * whenever the STAs are removed, and that invalidates driver
  321. * assumptions about always getting a vif pointer that is valid
  322. * (because if we remove a STA after ops->remove_interface()
  323. * the driver will have removed the vif info already!)
  324. *
  325. * We could relax this and only unlink the stations from the
  326. * hash table and list but keep them on a per-sdata list that
  327. * will be inserted back again when the interface is brought
  328. * up again, but I don't currently see a use case for that,
  329. * except with WDS which gets a STA entry created when it is
  330. * brought up.
  331. */
  332. sta_info_flush(local, sdata);
  333. /*
  334. * Don't count this interface for promisc/allmulti while it
  335. * is down. dev_mc_unsync() will invoke set_multicast_list
  336. * on the master interface which will sync these down to the
  337. * hardware as filter flags.
  338. */
  339. if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
  340. atomic_dec(&local->iff_allmultis);
  341. if (sdata->flags & IEEE80211_SDATA_PROMISC)
  342. atomic_dec(&local->iff_promiscs);
  343. if (sdata->vif.type == NL80211_IFTYPE_AP)
  344. local->fif_pspoll--;
  345. netif_addr_lock_bh(dev);
  346. spin_lock_bh(&local->filter_lock);
  347. __hw_addr_unsync(&local->mc_list, &dev->mc, dev->addr_len);
  348. spin_unlock_bh(&local->filter_lock);
  349. netif_addr_unlock_bh(dev);
  350. ieee80211_configure_filter(local);
  351. del_timer_sync(&local->dynamic_ps_timer);
  352. cancel_work_sync(&local->dynamic_ps_enable_work);
  353. /* APs need special treatment */
  354. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  355. struct ieee80211_sub_if_data *vlan, *tmpsdata;
  356. struct beacon_data *old_beacon = sdata->u.ap.beacon;
  357. /* remove beacon */
  358. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  359. synchronize_rcu();
  360. kfree(old_beacon);
  361. /* down all dependent devices, that is VLANs */
  362. list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans,
  363. u.vlan.list)
  364. dev_close(vlan->dev);
  365. WARN_ON(!list_empty(&sdata->u.ap.vlans));
  366. }
  367. local->open_count--;
  368. switch (sdata->vif.type) {
  369. case NL80211_IFTYPE_AP_VLAN:
  370. list_del(&sdata->u.vlan.list);
  371. /* no need to tell driver */
  372. break;
  373. case NL80211_IFTYPE_MONITOR:
  374. if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
  375. local->cooked_mntrs--;
  376. break;
  377. }
  378. local->monitors--;
  379. if (local->monitors == 0) {
  380. local->hw.conf.flags &= ~IEEE80211_CONF_MONITOR;
  381. hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
  382. }
  383. if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
  384. local->fif_fcsfail--;
  385. if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
  386. local->fif_plcpfail--;
  387. if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) {
  388. local->fif_pspoll--;
  389. local->fif_control--;
  390. }
  391. if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
  392. local->fif_other_bss--;
  393. ieee80211_configure_filter(local);
  394. break;
  395. case NL80211_IFTYPE_STATION:
  396. del_timer_sync(&sdata->u.mgd.chswitch_timer);
  397. del_timer_sync(&sdata->u.mgd.timer);
  398. del_timer_sync(&sdata->u.mgd.conn_mon_timer);
  399. del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
  400. /*
  401. * If any of the timers fired while we waited for it, it will
  402. * have queued its work. Now the work will be running again
  403. * but will not rearm the timer again because it checks
  404. * whether the interface is running, which, at this point,
  405. * it no longer is.
  406. */
  407. cancel_work_sync(&sdata->u.mgd.chswitch_work);
  408. cancel_work_sync(&sdata->u.mgd.monitor_work);
  409. cancel_work_sync(&sdata->u.mgd.beacon_connection_loss_work);
  410. /* fall through */
  411. case NL80211_IFTYPE_ADHOC:
  412. if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
  413. del_timer_sync(&sdata->u.ibss.timer);
  414. /* fall through */
  415. case NL80211_IFTYPE_MESH_POINT:
  416. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  417. /* other_bss and allmulti are always set on mesh
  418. * ifaces */
  419. local->fif_other_bss--;
  420. atomic_dec(&local->iff_allmultis);
  421. ieee80211_configure_filter(local);
  422. ieee80211_stop_mesh(sdata);
  423. }
  424. /* fall through */
  425. default:
  426. flush_work(&sdata->work);
  427. /*
  428. * When we get here, the interface is marked down.
  429. * Call synchronize_rcu() to wait for the RX path
  430. * should it be using the interface and enqueuing
  431. * frames at this very time on another CPU.
  432. */
  433. synchronize_rcu();
  434. skb_queue_purge(&sdata->skb_queue);
  435. if (local->scan_sdata == sdata)
  436. ieee80211_scan_cancel(local);
  437. /*
  438. * Disable beaconing for AP and mesh, IBSS can't
  439. * still be joined to a network at this point.
  440. */
  441. if (sdata->vif.type == NL80211_IFTYPE_AP ||
  442. sdata->vif.type == NL80211_IFTYPE_MESH_POINT) {
  443. ieee80211_bss_info_change_notify(sdata,
  444. BSS_CHANGED_BEACON_ENABLED);
  445. }
  446. /* free all remaining keys, there shouldn't be any */
  447. ieee80211_free_keys(sdata);
  448. drv_remove_interface(local, &sdata->vif);
  449. }
  450. sdata->bss = NULL;
  451. mutex_lock(&local->mtx);
  452. hw_reconf_flags |= __ieee80211_recalc_idle(local);
  453. mutex_unlock(&local->mtx);
  454. ieee80211_recalc_ps(local, -1);
  455. if (local->open_count == 0) {
  456. if (local->ops->napi_poll)
  457. napi_disable(&local->napi);
  458. ieee80211_clear_tx_pending(local);
  459. ieee80211_stop_device(local);
  460. /* no reconfiguring after stop! */
  461. hw_reconf_flags = 0;
  462. }
  463. /* do after stop to avoid reconfiguring when we stop anyway */
  464. if (hw_reconf_flags)
  465. ieee80211_hw_config(local, hw_reconf_flags);
  466. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  467. for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
  468. skb_queue_walk_safe(&local->pending[i], skb, tmp) {
  469. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  470. if (info->control.vif == &sdata->vif) {
  471. __skb_unlink(skb, &local->pending[i]);
  472. dev_kfree_skb_irq(skb);
  473. }
  474. }
  475. }
  476. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  477. return 0;
  478. }
  479. static void ieee80211_set_multicast_list(struct net_device *dev)
  480. {
  481. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  482. struct ieee80211_local *local = sdata->local;
  483. int allmulti, promisc, sdata_allmulti, sdata_promisc;
  484. allmulti = !!(dev->flags & IFF_ALLMULTI);
  485. promisc = !!(dev->flags & IFF_PROMISC);
  486. sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
  487. sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC);
  488. if (allmulti != sdata_allmulti) {
  489. if (dev->flags & IFF_ALLMULTI)
  490. atomic_inc(&local->iff_allmultis);
  491. else
  492. atomic_dec(&local->iff_allmultis);
  493. sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
  494. }
  495. if (promisc != sdata_promisc) {
  496. if (dev->flags & IFF_PROMISC)
  497. atomic_inc(&local->iff_promiscs);
  498. else
  499. atomic_dec(&local->iff_promiscs);
  500. sdata->flags ^= IEEE80211_SDATA_PROMISC;
  501. }
  502. spin_lock_bh(&local->filter_lock);
  503. __hw_addr_sync(&local->mc_list, &dev->mc, dev->addr_len);
  504. spin_unlock_bh(&local->filter_lock);
  505. ieee80211_queue_work(&local->hw, &local->reconfig_filter);
  506. }
  507. /*
  508. * Called when the netdev is removed or, by the code below, before
  509. * the interface type changes.
  510. */
  511. static void ieee80211_teardown_sdata(struct net_device *dev)
  512. {
  513. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  514. struct ieee80211_local *local = sdata->local;
  515. struct beacon_data *beacon;
  516. struct sk_buff *skb;
  517. int flushed;
  518. int i;
  519. /* free extra data */
  520. ieee80211_free_keys(sdata);
  521. ieee80211_debugfs_remove_netdev(sdata);
  522. for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
  523. __skb_queue_purge(&sdata->fragments[i].skb_list);
  524. sdata->fragment_next = 0;
  525. switch (sdata->vif.type) {
  526. case NL80211_IFTYPE_AP:
  527. beacon = sdata->u.ap.beacon;
  528. rcu_assign_pointer(sdata->u.ap.beacon, NULL);
  529. synchronize_rcu();
  530. kfree(beacon);
  531. while ((skb = skb_dequeue(&sdata->u.ap.ps_bc_buf))) {
  532. local->total_ps_buffered--;
  533. dev_kfree_skb(skb);
  534. }
  535. break;
  536. case NL80211_IFTYPE_MESH_POINT:
  537. if (ieee80211_vif_is_mesh(&sdata->vif))
  538. mesh_rmc_free(sdata);
  539. break;
  540. case NL80211_IFTYPE_ADHOC:
  541. if (WARN_ON(sdata->u.ibss.presp))
  542. kfree_skb(sdata->u.ibss.presp);
  543. break;
  544. case NL80211_IFTYPE_STATION:
  545. case NL80211_IFTYPE_WDS:
  546. case NL80211_IFTYPE_AP_VLAN:
  547. case NL80211_IFTYPE_MONITOR:
  548. break;
  549. case NL80211_IFTYPE_UNSPECIFIED:
  550. case NUM_NL80211_IFTYPES:
  551. BUG();
  552. break;
  553. }
  554. flushed = sta_info_flush(local, sdata);
  555. WARN_ON(flushed);
  556. }
  557. static u16 ieee80211_netdev_select_queue(struct net_device *dev,
  558. struct sk_buff *skb)
  559. {
  560. return ieee80211_select_queue(IEEE80211_DEV_TO_SUB_IF(dev), skb);
  561. }
  562. static const struct net_device_ops ieee80211_dataif_ops = {
  563. .ndo_open = ieee80211_open,
  564. .ndo_stop = ieee80211_stop,
  565. .ndo_uninit = ieee80211_teardown_sdata,
  566. .ndo_start_xmit = ieee80211_subif_start_xmit,
  567. .ndo_set_multicast_list = ieee80211_set_multicast_list,
  568. .ndo_change_mtu = ieee80211_change_mtu,
  569. .ndo_set_mac_address = ieee80211_change_mac,
  570. .ndo_select_queue = ieee80211_netdev_select_queue,
  571. };
  572. static u16 ieee80211_monitor_select_queue(struct net_device *dev,
  573. struct sk_buff *skb)
  574. {
  575. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  576. struct ieee80211_local *local = sdata->local;
  577. struct ieee80211_hdr *hdr;
  578. struct ieee80211_radiotap_header *rtap = (void *)skb->data;
  579. u8 *p;
  580. if (local->hw.queues < 4)
  581. return 0;
  582. if (skb->len < 4 ||
  583. skb->len < le16_to_cpu(rtap->it_len) + 2 /* frame control */)
  584. return 0; /* doesn't matter, frame will be dropped */
  585. hdr = (void *)((u8 *)skb->data + le16_to_cpu(rtap->it_len));
  586. if (!ieee80211_is_data(hdr->frame_control)) {
  587. skb->priority = 7;
  588. return ieee802_1d_to_ac[skb->priority];
  589. }
  590. if (!ieee80211_is_data_qos(hdr->frame_control)) {
  591. skb->priority = 0;
  592. return ieee802_1d_to_ac[skb->priority];
  593. }
  594. p = ieee80211_get_qos_ctl(hdr);
  595. skb->priority = *p & IEEE80211_QOS_CTL_TAG1D_MASK;
  596. return ieee80211_downgrade_queue(local, skb);
  597. }
  598. static const struct net_device_ops ieee80211_monitorif_ops = {
  599. .ndo_open = ieee80211_open,
  600. .ndo_stop = ieee80211_stop,
  601. .ndo_uninit = ieee80211_teardown_sdata,
  602. .ndo_start_xmit = ieee80211_monitor_start_xmit,
  603. .ndo_set_multicast_list = ieee80211_set_multicast_list,
  604. .ndo_change_mtu = ieee80211_change_mtu,
  605. .ndo_set_mac_address = eth_mac_addr,
  606. .ndo_select_queue = ieee80211_monitor_select_queue,
  607. };
  608. static void ieee80211_if_setup(struct net_device *dev)
  609. {
  610. ether_setup(dev);
  611. dev->netdev_ops = &ieee80211_dataif_ops;
  612. dev->destructor = free_netdev;
  613. }
  614. static void ieee80211_iface_work(struct work_struct *work)
  615. {
  616. struct ieee80211_sub_if_data *sdata =
  617. container_of(work, struct ieee80211_sub_if_data, work);
  618. struct ieee80211_local *local = sdata->local;
  619. struct sk_buff *skb;
  620. struct sta_info *sta;
  621. struct ieee80211_ra_tid *ra_tid;
  622. if (!ieee80211_sdata_running(sdata))
  623. return;
  624. if (local->scanning)
  625. return;
  626. /*
  627. * ieee80211_queue_work() should have picked up most cases,
  628. * here we'll pick the rest.
  629. */
  630. if (WARN(local->suspended,
  631. "interface work scheduled while going to suspend\n"))
  632. return;
  633. /* first process frames */
  634. while ((skb = skb_dequeue(&sdata->skb_queue))) {
  635. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  636. if (skb->pkt_type == IEEE80211_SDATA_QUEUE_AGG_START) {
  637. ra_tid = (void *)&skb->cb;
  638. ieee80211_start_tx_ba_cb(&sdata->vif, ra_tid->ra,
  639. ra_tid->tid);
  640. } else if (skb->pkt_type == IEEE80211_SDATA_QUEUE_AGG_STOP) {
  641. ra_tid = (void *)&skb->cb;
  642. ieee80211_stop_tx_ba_cb(&sdata->vif, ra_tid->ra,
  643. ra_tid->tid);
  644. } else if (ieee80211_is_action(mgmt->frame_control) &&
  645. mgmt->u.action.category == WLAN_CATEGORY_BACK) {
  646. int len = skb->len;
  647. mutex_lock(&local->sta_mtx);
  648. sta = sta_info_get_bss(sdata, mgmt->sa);
  649. if (sta) {
  650. switch (mgmt->u.action.u.addba_req.action_code) {
  651. case WLAN_ACTION_ADDBA_REQ:
  652. ieee80211_process_addba_request(
  653. local, sta, mgmt, len);
  654. break;
  655. case WLAN_ACTION_ADDBA_RESP:
  656. ieee80211_process_addba_resp(local, sta,
  657. mgmt, len);
  658. break;
  659. case WLAN_ACTION_DELBA:
  660. ieee80211_process_delba(sdata, sta,
  661. mgmt, len);
  662. break;
  663. default:
  664. WARN_ON(1);
  665. break;
  666. }
  667. }
  668. mutex_unlock(&local->sta_mtx);
  669. } else if (ieee80211_is_data_qos(mgmt->frame_control)) {
  670. struct ieee80211_hdr *hdr = (void *)mgmt;
  671. /*
  672. * So the frame isn't mgmt, but frame_control
  673. * is at the right place anyway, of course, so
  674. * the if statement is correct.
  675. *
  676. * Warn if we have other data frame types here,
  677. * they must not get here.
  678. */
  679. WARN_ON(hdr->frame_control &
  680. cpu_to_le16(IEEE80211_STYPE_NULLFUNC));
  681. WARN_ON(!(hdr->seq_ctrl &
  682. cpu_to_le16(IEEE80211_SCTL_FRAG)));
  683. /*
  684. * This was a fragment of a frame, received while
  685. * a block-ack session was active. That cannot be
  686. * right, so terminate the session.
  687. */
  688. mutex_lock(&local->sta_mtx);
  689. sta = sta_info_get_bss(sdata, mgmt->sa);
  690. if (sta) {
  691. u16 tid = *ieee80211_get_qos_ctl(hdr) &
  692. IEEE80211_QOS_CTL_TID_MASK;
  693. __ieee80211_stop_rx_ba_session(
  694. sta, tid, WLAN_BACK_RECIPIENT,
  695. WLAN_REASON_QSTA_REQUIRE_SETUP);
  696. }
  697. mutex_unlock(&local->sta_mtx);
  698. } else switch (sdata->vif.type) {
  699. case NL80211_IFTYPE_STATION:
  700. ieee80211_sta_rx_queued_mgmt(sdata, skb);
  701. break;
  702. case NL80211_IFTYPE_ADHOC:
  703. ieee80211_ibss_rx_queued_mgmt(sdata, skb);
  704. break;
  705. case NL80211_IFTYPE_MESH_POINT:
  706. if (!ieee80211_vif_is_mesh(&sdata->vif))
  707. break;
  708. ieee80211_mesh_rx_queued_mgmt(sdata, skb);
  709. break;
  710. default:
  711. WARN(1, "frame for unexpected interface type");
  712. break;
  713. }
  714. kfree_skb(skb);
  715. }
  716. /* then other type-dependent work */
  717. switch (sdata->vif.type) {
  718. case NL80211_IFTYPE_STATION:
  719. ieee80211_sta_work(sdata);
  720. break;
  721. case NL80211_IFTYPE_ADHOC:
  722. ieee80211_ibss_work(sdata);
  723. break;
  724. case NL80211_IFTYPE_MESH_POINT:
  725. if (!ieee80211_vif_is_mesh(&sdata->vif))
  726. break;
  727. ieee80211_mesh_work(sdata);
  728. break;
  729. default:
  730. break;
  731. }
  732. }
  733. /*
  734. * Helper function to initialise an interface to a specific type.
  735. */
  736. static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
  737. enum nl80211_iftype type)
  738. {
  739. /* clear type-dependent union */
  740. memset(&sdata->u, 0, sizeof(sdata->u));
  741. /* and set some type-dependent values */
  742. sdata->vif.type = type;
  743. sdata->dev->netdev_ops = &ieee80211_dataif_ops;
  744. sdata->wdev.iftype = type;
  745. /* only monitor differs */
  746. sdata->dev->type = ARPHRD_ETHER;
  747. skb_queue_head_init(&sdata->skb_queue);
  748. INIT_WORK(&sdata->work, ieee80211_iface_work);
  749. switch (type) {
  750. case NL80211_IFTYPE_AP:
  751. skb_queue_head_init(&sdata->u.ap.ps_bc_buf);
  752. INIT_LIST_HEAD(&sdata->u.ap.vlans);
  753. break;
  754. case NL80211_IFTYPE_STATION:
  755. ieee80211_sta_setup_sdata(sdata);
  756. break;
  757. case NL80211_IFTYPE_ADHOC:
  758. ieee80211_ibss_setup_sdata(sdata);
  759. break;
  760. case NL80211_IFTYPE_MESH_POINT:
  761. if (ieee80211_vif_is_mesh(&sdata->vif))
  762. ieee80211_mesh_init_sdata(sdata);
  763. break;
  764. case NL80211_IFTYPE_MONITOR:
  765. sdata->dev->type = ARPHRD_IEEE80211_RADIOTAP;
  766. sdata->dev->netdev_ops = &ieee80211_monitorif_ops;
  767. sdata->u.mntr_flags = MONITOR_FLAG_CONTROL |
  768. MONITOR_FLAG_OTHER_BSS;
  769. break;
  770. case NL80211_IFTYPE_WDS:
  771. case NL80211_IFTYPE_AP_VLAN:
  772. break;
  773. case NL80211_IFTYPE_UNSPECIFIED:
  774. case NUM_NL80211_IFTYPES:
  775. BUG();
  776. break;
  777. }
  778. ieee80211_debugfs_add_netdev(sdata);
  779. }
  780. int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
  781. enum nl80211_iftype type)
  782. {
  783. ASSERT_RTNL();
  784. if (type == sdata->vif.type)
  785. return 0;
  786. /* Setting ad-hoc mode on non-IBSS channel is not supported. */
  787. if (sdata->local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS &&
  788. type == NL80211_IFTYPE_ADHOC)
  789. return -EOPNOTSUPP;
  790. /*
  791. * We could, here, on changes between IBSS/STA/MESH modes,
  792. * invoke an MLME function instead that disassociates etc.
  793. * and goes into the requested mode.
  794. */
  795. if (ieee80211_sdata_running(sdata))
  796. return -EBUSY;
  797. /* Purge and reset type-dependent state. */
  798. ieee80211_teardown_sdata(sdata->dev);
  799. ieee80211_setup_sdata(sdata, type);
  800. /* reset some values that shouldn't be kept across type changes */
  801. sdata->vif.bss_conf.basic_rates =
  802. ieee80211_mandatory_rates(sdata->local,
  803. sdata->local->hw.conf.channel->band);
  804. sdata->drop_unencrypted = 0;
  805. if (type == NL80211_IFTYPE_STATION)
  806. sdata->u.mgd.use_4addr = false;
  807. return 0;
  808. }
  809. static void ieee80211_assign_perm_addr(struct ieee80211_local *local,
  810. struct net_device *dev,
  811. enum nl80211_iftype type)
  812. {
  813. struct ieee80211_sub_if_data *sdata;
  814. u64 mask, start, addr, val, inc;
  815. u8 *m;
  816. u8 tmp_addr[ETH_ALEN];
  817. int i;
  818. /* default ... something at least */
  819. memcpy(dev->perm_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
  820. if (is_zero_ether_addr(local->hw.wiphy->addr_mask) &&
  821. local->hw.wiphy->n_addresses <= 1)
  822. return;
  823. mutex_lock(&local->iflist_mtx);
  824. switch (type) {
  825. case NL80211_IFTYPE_MONITOR:
  826. /* doesn't matter */
  827. break;
  828. case NL80211_IFTYPE_WDS:
  829. case NL80211_IFTYPE_AP_VLAN:
  830. /* match up with an AP interface */
  831. list_for_each_entry(sdata, &local->interfaces, list) {
  832. if (sdata->vif.type != NL80211_IFTYPE_AP)
  833. continue;
  834. memcpy(dev->perm_addr, sdata->vif.addr, ETH_ALEN);
  835. break;
  836. }
  837. /* keep default if no AP interface present */
  838. break;
  839. default:
  840. /* assign a new address if possible -- try n_addresses first */
  841. for (i = 0; i < local->hw.wiphy->n_addresses; i++) {
  842. bool used = false;
  843. list_for_each_entry(sdata, &local->interfaces, list) {
  844. if (memcmp(local->hw.wiphy->addresses[i].addr,
  845. sdata->vif.addr, ETH_ALEN) == 0) {
  846. used = true;
  847. break;
  848. }
  849. }
  850. if (!used) {
  851. memcpy(dev->perm_addr,
  852. local->hw.wiphy->addresses[i].addr,
  853. ETH_ALEN);
  854. break;
  855. }
  856. }
  857. /* try mask if available */
  858. if (is_zero_ether_addr(local->hw.wiphy->addr_mask))
  859. break;
  860. m = local->hw.wiphy->addr_mask;
  861. mask = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
  862. ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
  863. ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
  864. if (__ffs64(mask) + hweight64(mask) != fls64(mask)) {
  865. /* not a contiguous mask ... not handled now! */
  866. printk(KERN_DEBUG "not contiguous\n");
  867. break;
  868. }
  869. m = local->hw.wiphy->perm_addr;
  870. start = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
  871. ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
  872. ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
  873. inc = 1ULL<<__ffs64(mask);
  874. val = (start & mask);
  875. addr = (start & ~mask) | (val & mask);
  876. do {
  877. bool used = false;
  878. tmp_addr[5] = addr >> 0*8;
  879. tmp_addr[4] = addr >> 1*8;
  880. tmp_addr[3] = addr >> 2*8;
  881. tmp_addr[2] = addr >> 3*8;
  882. tmp_addr[1] = addr >> 4*8;
  883. tmp_addr[0] = addr >> 5*8;
  884. val += inc;
  885. list_for_each_entry(sdata, &local->interfaces, list) {
  886. if (memcmp(tmp_addr, sdata->vif.addr,
  887. ETH_ALEN) == 0) {
  888. used = true;
  889. break;
  890. }
  891. }
  892. if (!used) {
  893. memcpy(dev->perm_addr, tmp_addr, ETH_ALEN);
  894. break;
  895. }
  896. addr = (start & ~mask) | (val & mask);
  897. } while (addr != start);
  898. break;
  899. }
  900. mutex_unlock(&local->iflist_mtx);
  901. }
  902. int ieee80211_if_add(struct ieee80211_local *local, const char *name,
  903. struct net_device **new_dev, enum nl80211_iftype type,
  904. struct vif_params *params)
  905. {
  906. struct net_device *ndev;
  907. struct ieee80211_sub_if_data *sdata = NULL;
  908. int ret, i;
  909. ASSERT_RTNL();
  910. ndev = alloc_netdev_mq(sizeof(*sdata) + local->hw.vif_data_size,
  911. name, ieee80211_if_setup, local->hw.queues);
  912. if (!ndev)
  913. return -ENOMEM;
  914. dev_net_set(ndev, wiphy_net(local->hw.wiphy));
  915. ndev->needed_headroom = local->tx_headroom +
  916. 4*6 /* four MAC addresses */
  917. + 2 + 2 + 2 + 2 /* ctl, dur, seq, qos */
  918. + 6 /* mesh */
  919. + 8 /* rfc1042/bridge tunnel */
  920. - ETH_HLEN /* ethernet hard_header_len */
  921. + IEEE80211_ENCRYPT_HEADROOM;
  922. ndev->needed_tailroom = IEEE80211_ENCRYPT_TAILROOM;
  923. ret = dev_alloc_name(ndev, ndev->name);
  924. if (ret < 0)
  925. goto fail;
  926. ieee80211_assign_perm_addr(local, ndev, type);
  927. memcpy(ndev->dev_addr, ndev->perm_addr, ETH_ALEN);
  928. SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy));
  929. /* don't use IEEE80211_DEV_TO_SUB_IF because it checks too much */
  930. sdata = netdev_priv(ndev);
  931. ndev->ieee80211_ptr = &sdata->wdev;
  932. memcpy(sdata->vif.addr, ndev->dev_addr, ETH_ALEN);
  933. memcpy(sdata->name, ndev->name, IFNAMSIZ);
  934. /* initialise type-independent data */
  935. sdata->wdev.wiphy = local->hw.wiphy;
  936. sdata->local = local;
  937. sdata->dev = ndev;
  938. #ifdef CONFIG_INET
  939. sdata->arp_filter_state = true;
  940. #endif
  941. for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
  942. skb_queue_head_init(&sdata->fragments[i].skb_list);
  943. INIT_LIST_HEAD(&sdata->key_list);
  944. for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
  945. struct ieee80211_supported_band *sband;
  946. sband = local->hw.wiphy->bands[i];
  947. sdata->rc_rateidx_mask[i] =
  948. sband ? (1 << sband->n_bitrates) - 1 : 0;
  949. }
  950. /* setup type-dependent data */
  951. ieee80211_setup_sdata(sdata, type);
  952. if (params) {
  953. ndev->ieee80211_ptr->use_4addr = params->use_4addr;
  954. if (type == NL80211_IFTYPE_STATION)
  955. sdata->u.mgd.use_4addr = params->use_4addr;
  956. }
  957. ret = register_netdevice(ndev);
  958. if (ret)
  959. goto fail;
  960. if (ieee80211_vif_is_mesh(&sdata->vif) &&
  961. params && params->mesh_id_len)
  962. ieee80211_sdata_set_mesh_id(sdata,
  963. params->mesh_id_len,
  964. params->mesh_id);
  965. mutex_lock(&local->iflist_mtx);
  966. list_add_tail_rcu(&sdata->list, &local->interfaces);
  967. mutex_unlock(&local->iflist_mtx);
  968. if (new_dev)
  969. *new_dev = ndev;
  970. return 0;
  971. fail:
  972. free_netdev(ndev);
  973. return ret;
  974. }
  975. void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata)
  976. {
  977. ASSERT_RTNL();
  978. mutex_lock(&sdata->local->iflist_mtx);
  979. list_del_rcu(&sdata->list);
  980. mutex_unlock(&sdata->local->iflist_mtx);
  981. synchronize_rcu();
  982. unregister_netdevice(sdata->dev);
  983. }
  984. /*
  985. * Remove all interfaces, may only be called at hardware unregistration
  986. * time because it doesn't do RCU-safe list removals.
  987. */
  988. void ieee80211_remove_interfaces(struct ieee80211_local *local)
  989. {
  990. struct ieee80211_sub_if_data *sdata, *tmp;
  991. LIST_HEAD(unreg_list);
  992. ASSERT_RTNL();
  993. mutex_lock(&local->iflist_mtx);
  994. list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
  995. list_del(&sdata->list);
  996. unregister_netdevice_queue(sdata->dev, &unreg_list);
  997. }
  998. mutex_unlock(&local->iflist_mtx);
  999. unregister_netdevice_many(&unreg_list);
  1000. }
  1001. static u32 ieee80211_idle_off(struct ieee80211_local *local,
  1002. const char *reason)
  1003. {
  1004. if (!(local->hw.conf.flags & IEEE80211_CONF_IDLE))
  1005. return 0;
  1006. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1007. printk(KERN_DEBUG "%s: device no longer idle - %s\n",
  1008. wiphy_name(local->hw.wiphy), reason);
  1009. #endif
  1010. local->hw.conf.flags &= ~IEEE80211_CONF_IDLE;
  1011. return IEEE80211_CONF_CHANGE_IDLE;
  1012. }
  1013. static u32 ieee80211_idle_on(struct ieee80211_local *local)
  1014. {
  1015. if (local->hw.conf.flags & IEEE80211_CONF_IDLE)
  1016. return 0;
  1017. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1018. printk(KERN_DEBUG "%s: device now idle\n",
  1019. wiphy_name(local->hw.wiphy));
  1020. #endif
  1021. drv_flush(local, false);
  1022. local->hw.conf.flags |= IEEE80211_CONF_IDLE;
  1023. return IEEE80211_CONF_CHANGE_IDLE;
  1024. }
  1025. u32 __ieee80211_recalc_idle(struct ieee80211_local *local)
  1026. {
  1027. struct ieee80211_sub_if_data *sdata;
  1028. int count = 0;
  1029. bool working = false, scanning = false;
  1030. struct ieee80211_work *wk;
  1031. #ifdef CONFIG_PROVE_LOCKING
  1032. WARN_ON(debug_locks && !lockdep_rtnl_is_held() &&
  1033. !lockdep_is_held(&local->iflist_mtx));
  1034. #endif
  1035. lockdep_assert_held(&local->mtx);
  1036. list_for_each_entry(sdata, &local->interfaces, list) {
  1037. if (!ieee80211_sdata_running(sdata)) {
  1038. sdata->vif.bss_conf.idle = true;
  1039. continue;
  1040. }
  1041. sdata->old_idle = sdata->vif.bss_conf.idle;
  1042. /* do not count disabled managed interfaces */
  1043. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  1044. !sdata->u.mgd.associated) {
  1045. sdata->vif.bss_conf.idle = true;
  1046. continue;
  1047. }
  1048. /* do not count unused IBSS interfaces */
  1049. if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
  1050. !sdata->u.ibss.ssid_len) {
  1051. sdata->vif.bss_conf.idle = true;
  1052. continue;
  1053. }
  1054. /* count everything else */
  1055. count++;
  1056. }
  1057. list_for_each_entry(wk, &local->work_list, list) {
  1058. working = true;
  1059. wk->sdata->vif.bss_conf.idle = false;
  1060. }
  1061. if (local->scan_sdata) {
  1062. scanning = true;
  1063. local->scan_sdata->vif.bss_conf.idle = false;
  1064. }
  1065. list_for_each_entry(sdata, &local->interfaces, list) {
  1066. if (sdata->old_idle == sdata->vif.bss_conf.idle)
  1067. continue;
  1068. if (!ieee80211_sdata_running(sdata))
  1069. continue;
  1070. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_IDLE);
  1071. }
  1072. if (working)
  1073. return ieee80211_idle_off(local, "working");
  1074. if (scanning)
  1075. return ieee80211_idle_off(local, "scanning");
  1076. if (!count)
  1077. return ieee80211_idle_on(local);
  1078. else
  1079. return ieee80211_idle_off(local, "in use");
  1080. return 0;
  1081. }
  1082. void ieee80211_recalc_idle(struct ieee80211_local *local)
  1083. {
  1084. u32 chg;
  1085. mutex_lock(&local->iflist_mtx);
  1086. chg = __ieee80211_recalc_idle(local);
  1087. mutex_unlock(&local->iflist_mtx);
  1088. if (chg)
  1089. ieee80211_hw_config(local, chg);
  1090. }
  1091. static int netdev_notify(struct notifier_block *nb,
  1092. unsigned long state,
  1093. void *ndev)
  1094. {
  1095. struct net_device *dev = ndev;
  1096. struct ieee80211_sub_if_data *sdata;
  1097. if (state != NETDEV_CHANGENAME)
  1098. return 0;
  1099. if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
  1100. return 0;
  1101. if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
  1102. return 0;
  1103. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1104. memcpy(sdata->name, dev->name, IFNAMSIZ);
  1105. ieee80211_debugfs_rename_netdev(sdata);
  1106. return 0;
  1107. }
  1108. static struct notifier_block mac80211_netdev_notifier = {
  1109. .notifier_call = netdev_notify,
  1110. };
  1111. int ieee80211_iface_init(void)
  1112. {
  1113. return register_netdevice_notifier(&mac80211_netdev_notifier);
  1114. }
  1115. void ieee80211_iface_exit(void)
  1116. {
  1117. unregister_netdevice_notifier(&mac80211_netdev_notifier);
  1118. }