PageRenderTime 80ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 0ms

/net/mac80211/iface.c

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