iface.c 33 KB

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