iface.c 33 KB

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