iface.c 33 KB

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