iface.c 33 KB

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