iface.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813
  1. /*
  2. * Interface handling
  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. bool __ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata)
  44. {
  45. struct ieee80211_chanctx_conf *chanctx_conf;
  46. int power;
  47. rcu_read_lock();
  48. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  49. if (!chanctx_conf) {
  50. rcu_read_unlock();
  51. return false;
  52. }
  53. power = ieee80211_chandef_max_power(&chanctx_conf->def);
  54. rcu_read_unlock();
  55. if (sdata->user_power_level != IEEE80211_UNSET_POWER_LEVEL)
  56. power = min(power, sdata->user_power_level);
  57. if (sdata->ap_power_level != IEEE80211_UNSET_POWER_LEVEL)
  58. power = min(power, sdata->ap_power_level);
  59. if (power != sdata->vif.bss_conf.txpower) {
  60. sdata->vif.bss_conf.txpower = power;
  61. ieee80211_hw_config(sdata->local, 0);
  62. return true;
  63. }
  64. return false;
  65. }
  66. void ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata)
  67. {
  68. if (__ieee80211_recalc_txpower(sdata))
  69. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_TXPOWER);
  70. }
  71. static u32 __ieee80211_idle_off(struct ieee80211_local *local)
  72. {
  73. if (!(local->hw.conf.flags & IEEE80211_CONF_IDLE))
  74. return 0;
  75. local->hw.conf.flags &= ~IEEE80211_CONF_IDLE;
  76. return IEEE80211_CONF_CHANGE_IDLE;
  77. }
  78. static u32 __ieee80211_idle_on(struct ieee80211_local *local)
  79. {
  80. if (local->hw.conf.flags & IEEE80211_CONF_IDLE)
  81. return 0;
  82. ieee80211_flush_queues(local, NULL);
  83. local->hw.conf.flags |= IEEE80211_CONF_IDLE;
  84. return IEEE80211_CONF_CHANGE_IDLE;
  85. }
  86. static u32 __ieee80211_recalc_idle(struct ieee80211_local *local,
  87. bool force_active)
  88. {
  89. bool working = false, scanning, active;
  90. unsigned int led_trig_start = 0, led_trig_stop = 0;
  91. struct ieee80211_roc_work *roc;
  92. lockdep_assert_held(&local->mtx);
  93. active = force_active ||
  94. !list_empty(&local->chanctx_list) ||
  95. local->monitors;
  96. if (!local->ops->remain_on_channel) {
  97. list_for_each_entry(roc, &local->roc_list, list) {
  98. working = true;
  99. break;
  100. }
  101. }
  102. scanning = test_bit(SCAN_SW_SCANNING, &local->scanning) ||
  103. test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning);
  104. if (working || scanning)
  105. led_trig_start |= IEEE80211_TPT_LEDTRIG_FL_WORK;
  106. else
  107. led_trig_stop |= IEEE80211_TPT_LEDTRIG_FL_WORK;
  108. if (active)
  109. led_trig_start |= IEEE80211_TPT_LEDTRIG_FL_CONNECTED;
  110. else
  111. led_trig_stop |= IEEE80211_TPT_LEDTRIG_FL_CONNECTED;
  112. ieee80211_mod_tpt_led_trig(local, led_trig_start, led_trig_stop);
  113. if (working || scanning || active)
  114. return __ieee80211_idle_off(local);
  115. return __ieee80211_idle_on(local);
  116. }
  117. u32 ieee80211_idle_off(struct ieee80211_local *local)
  118. {
  119. return __ieee80211_recalc_idle(local, true);
  120. }
  121. void ieee80211_recalc_idle(struct ieee80211_local *local)
  122. {
  123. u32 change = __ieee80211_recalc_idle(local, false);
  124. if (change)
  125. ieee80211_hw_config(local, change);
  126. }
  127. static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
  128. {
  129. if (new_mtu < 256 || new_mtu > IEEE80211_MAX_DATA_LEN)
  130. return -EINVAL;
  131. dev->mtu = new_mtu;
  132. return 0;
  133. }
  134. static int ieee80211_verify_mac(struct ieee80211_sub_if_data *sdata, u8 *addr,
  135. bool check_dup)
  136. {
  137. struct ieee80211_local *local = sdata->local;
  138. struct ieee80211_sub_if_data *iter;
  139. u64 new, mask, tmp;
  140. u8 *m;
  141. int ret = 0;
  142. if (is_zero_ether_addr(local->hw.wiphy->addr_mask))
  143. return 0;
  144. m = addr;
  145. new = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
  146. ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
  147. ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
  148. m = local->hw.wiphy->addr_mask;
  149. mask = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
  150. ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
  151. ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
  152. if (!check_dup)
  153. return ret;
  154. mutex_lock(&local->iflist_mtx);
  155. list_for_each_entry(iter, &local->interfaces, list) {
  156. if (iter == sdata)
  157. continue;
  158. if (iter->vif.type == NL80211_IFTYPE_MONITOR &&
  159. !(iter->u.mntr_flags & MONITOR_FLAG_ACTIVE))
  160. continue;
  161. m = iter->vif.addr;
  162. tmp = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
  163. ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
  164. ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
  165. if ((new & ~mask) != (tmp & ~mask)) {
  166. ret = -EINVAL;
  167. break;
  168. }
  169. }
  170. mutex_unlock(&local->iflist_mtx);
  171. return ret;
  172. }
  173. static int ieee80211_change_mac(struct net_device *dev, void *addr)
  174. {
  175. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  176. struct sockaddr *sa = addr;
  177. bool check_dup = true;
  178. int ret;
  179. if (ieee80211_sdata_running(sdata))
  180. return -EBUSY;
  181. if (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
  182. !(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))
  183. check_dup = false;
  184. ret = ieee80211_verify_mac(sdata, sa->sa_data, check_dup);
  185. if (ret)
  186. return ret;
  187. ret = eth_mac_addr(dev, sa);
  188. if (ret == 0)
  189. memcpy(sdata->vif.addr, sa->sa_data, ETH_ALEN);
  190. return ret;
  191. }
  192. static inline int identical_mac_addr_allowed(int type1, int type2)
  193. {
  194. return type1 == NL80211_IFTYPE_MONITOR ||
  195. type2 == NL80211_IFTYPE_MONITOR ||
  196. type1 == NL80211_IFTYPE_P2P_DEVICE ||
  197. type2 == NL80211_IFTYPE_P2P_DEVICE ||
  198. (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_WDS) ||
  199. (type1 == NL80211_IFTYPE_WDS &&
  200. (type2 == NL80211_IFTYPE_WDS ||
  201. type2 == NL80211_IFTYPE_AP)) ||
  202. (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_AP_VLAN) ||
  203. (type1 == NL80211_IFTYPE_AP_VLAN &&
  204. (type2 == NL80211_IFTYPE_AP ||
  205. type2 == NL80211_IFTYPE_AP_VLAN));
  206. }
  207. static int ieee80211_check_concurrent_iface(struct ieee80211_sub_if_data *sdata,
  208. enum nl80211_iftype iftype)
  209. {
  210. struct ieee80211_local *local = sdata->local;
  211. struct ieee80211_sub_if_data *nsdata;
  212. ASSERT_RTNL();
  213. /* we hold the RTNL here so can safely walk the list */
  214. list_for_each_entry(nsdata, &local->interfaces, list) {
  215. if (nsdata != sdata && ieee80211_sdata_running(nsdata)) {
  216. /*
  217. * Allow only a single IBSS interface to be up at any
  218. * time. This is restricted because beacon distribution
  219. * cannot work properly if both are in the same IBSS.
  220. *
  221. * To remove this restriction we'd have to disallow them
  222. * from setting the same SSID on different IBSS interfaces
  223. * belonging to the same hardware. Then, however, we're
  224. * faced with having to adopt two different TSF timers...
  225. */
  226. if (iftype == NL80211_IFTYPE_ADHOC &&
  227. nsdata->vif.type == NL80211_IFTYPE_ADHOC)
  228. return -EBUSY;
  229. /*
  230. * will not add another interface while any channel
  231. * switch is active.
  232. */
  233. if (nsdata->vif.csa_active)
  234. return -EBUSY;
  235. /*
  236. * The remaining checks are only performed for interfaces
  237. * with the same MAC address.
  238. */
  239. if (!ether_addr_equal(sdata->vif.addr,
  240. nsdata->vif.addr))
  241. continue;
  242. /*
  243. * check whether it may have the same address
  244. */
  245. if (!identical_mac_addr_allowed(iftype,
  246. nsdata->vif.type))
  247. return -ENOTUNIQ;
  248. /*
  249. * can only add VLANs to enabled APs
  250. */
  251. if (iftype == NL80211_IFTYPE_AP_VLAN &&
  252. nsdata->vif.type == NL80211_IFTYPE_AP)
  253. sdata->bss = &nsdata->u.ap;
  254. }
  255. }
  256. return 0;
  257. }
  258. static int ieee80211_check_queues(struct ieee80211_sub_if_data *sdata,
  259. enum nl80211_iftype iftype)
  260. {
  261. int n_queues = sdata->local->hw.queues;
  262. int i;
  263. if (iftype != NL80211_IFTYPE_P2P_DEVICE) {
  264. for (i = 0; i < IEEE80211_NUM_ACS; i++) {
  265. if (WARN_ON_ONCE(sdata->vif.hw_queue[i] ==
  266. IEEE80211_INVAL_HW_QUEUE))
  267. return -EINVAL;
  268. if (WARN_ON_ONCE(sdata->vif.hw_queue[i] >=
  269. n_queues))
  270. return -EINVAL;
  271. }
  272. }
  273. if ((iftype != NL80211_IFTYPE_AP &&
  274. iftype != NL80211_IFTYPE_P2P_GO &&
  275. iftype != NL80211_IFTYPE_MESH_POINT) ||
  276. !(sdata->local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)) {
  277. sdata->vif.cab_queue = IEEE80211_INVAL_HW_QUEUE;
  278. return 0;
  279. }
  280. if (WARN_ON_ONCE(sdata->vif.cab_queue == IEEE80211_INVAL_HW_QUEUE))
  281. return -EINVAL;
  282. if (WARN_ON_ONCE(sdata->vif.cab_queue >= n_queues))
  283. return -EINVAL;
  284. return 0;
  285. }
  286. void ieee80211_adjust_monitor_flags(struct ieee80211_sub_if_data *sdata,
  287. const int offset)
  288. {
  289. struct ieee80211_local *local = sdata->local;
  290. u32 flags = sdata->u.mntr_flags;
  291. #define ADJUST(_f, _s) do { \
  292. if (flags & MONITOR_FLAG_##_f) \
  293. local->fif_##_s += offset; \
  294. } while (0)
  295. ADJUST(FCSFAIL, fcsfail);
  296. ADJUST(PLCPFAIL, plcpfail);
  297. ADJUST(CONTROL, control);
  298. ADJUST(CONTROL, pspoll);
  299. ADJUST(OTHER_BSS, other_bss);
  300. #undef ADJUST
  301. }
  302. static void ieee80211_set_default_queues(struct ieee80211_sub_if_data *sdata)
  303. {
  304. struct ieee80211_local *local = sdata->local;
  305. int i;
  306. for (i = 0; i < IEEE80211_NUM_ACS; i++) {
  307. if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
  308. sdata->vif.hw_queue[i] = IEEE80211_INVAL_HW_QUEUE;
  309. else if (local->hw.queues >= IEEE80211_NUM_ACS)
  310. sdata->vif.hw_queue[i] = i;
  311. else
  312. sdata->vif.hw_queue[i] = 0;
  313. }
  314. sdata->vif.cab_queue = IEEE80211_INVAL_HW_QUEUE;
  315. }
  316. int ieee80211_add_virtual_monitor(struct ieee80211_local *local)
  317. {
  318. struct ieee80211_sub_if_data *sdata;
  319. int ret;
  320. if (!(local->hw.flags & IEEE80211_HW_WANT_MONITOR_VIF))
  321. return 0;
  322. ASSERT_RTNL();
  323. if (local->monitor_sdata)
  324. return 0;
  325. sdata = kzalloc(sizeof(*sdata) + local->hw.vif_data_size, GFP_KERNEL);
  326. if (!sdata)
  327. return -ENOMEM;
  328. /* set up data */
  329. sdata->local = local;
  330. sdata->vif.type = NL80211_IFTYPE_MONITOR;
  331. snprintf(sdata->name, IFNAMSIZ, "%s-monitor",
  332. wiphy_name(local->hw.wiphy));
  333. ieee80211_set_default_queues(sdata);
  334. ret = drv_add_interface(local, sdata);
  335. if (WARN_ON(ret)) {
  336. /* ok .. stupid driver, it asked for this! */
  337. kfree(sdata);
  338. return ret;
  339. }
  340. ret = ieee80211_check_queues(sdata, NL80211_IFTYPE_MONITOR);
  341. if (ret) {
  342. kfree(sdata);
  343. return ret;
  344. }
  345. ret = ieee80211_vif_use_channel(sdata, &local->monitor_chandef,
  346. IEEE80211_CHANCTX_EXCLUSIVE);
  347. if (ret) {
  348. drv_remove_interface(local, sdata);
  349. kfree(sdata);
  350. return ret;
  351. }
  352. mutex_lock(&local->iflist_mtx);
  353. rcu_assign_pointer(local->monitor_sdata, sdata);
  354. mutex_unlock(&local->iflist_mtx);
  355. return 0;
  356. }
  357. void ieee80211_del_virtual_monitor(struct ieee80211_local *local)
  358. {
  359. struct ieee80211_sub_if_data *sdata;
  360. if (!(local->hw.flags & IEEE80211_HW_WANT_MONITOR_VIF))
  361. return;
  362. ASSERT_RTNL();
  363. mutex_lock(&local->iflist_mtx);
  364. sdata = rcu_dereference_protected(local->monitor_sdata,
  365. lockdep_is_held(&local->iflist_mtx));
  366. if (!sdata) {
  367. mutex_unlock(&local->iflist_mtx);
  368. return;
  369. }
  370. rcu_assign_pointer(local->monitor_sdata, NULL);
  371. mutex_unlock(&local->iflist_mtx);
  372. synchronize_net();
  373. ieee80211_vif_release_channel(sdata);
  374. drv_remove_interface(local, sdata);
  375. kfree(sdata);
  376. }
  377. /*
  378. * NOTE: Be very careful when changing this function, it must NOT return
  379. * an error on interface type changes that have been pre-checked, so most
  380. * checks should be in ieee80211_check_concurrent_iface.
  381. */
  382. int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
  383. {
  384. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  385. struct net_device *dev = wdev->netdev;
  386. struct ieee80211_local *local = sdata->local;
  387. struct sta_info *sta;
  388. u32 changed = 0;
  389. int res;
  390. u32 hw_reconf_flags = 0;
  391. switch (sdata->vif.type) {
  392. case NL80211_IFTYPE_WDS:
  393. if (!is_valid_ether_addr(sdata->u.wds.remote_addr))
  394. return -ENOLINK;
  395. break;
  396. case NL80211_IFTYPE_AP_VLAN: {
  397. struct ieee80211_sub_if_data *master;
  398. if (!sdata->bss)
  399. return -ENOLINK;
  400. list_add(&sdata->u.vlan.list, &sdata->bss->vlans);
  401. master = container_of(sdata->bss,
  402. struct ieee80211_sub_if_data, u.ap);
  403. sdata->control_port_protocol =
  404. master->control_port_protocol;
  405. sdata->control_port_no_encrypt =
  406. master->control_port_no_encrypt;
  407. sdata->vif.cab_queue = master->vif.cab_queue;
  408. memcpy(sdata->vif.hw_queue, master->vif.hw_queue,
  409. sizeof(sdata->vif.hw_queue));
  410. break;
  411. }
  412. case NL80211_IFTYPE_AP:
  413. sdata->bss = &sdata->u.ap;
  414. break;
  415. case NL80211_IFTYPE_MESH_POINT:
  416. case NL80211_IFTYPE_STATION:
  417. case NL80211_IFTYPE_MONITOR:
  418. case NL80211_IFTYPE_ADHOC:
  419. case NL80211_IFTYPE_P2P_DEVICE:
  420. /* no special treatment */
  421. break;
  422. case NL80211_IFTYPE_UNSPECIFIED:
  423. case NUM_NL80211_IFTYPES:
  424. case NL80211_IFTYPE_P2P_CLIENT:
  425. case NL80211_IFTYPE_P2P_GO:
  426. /* cannot happen */
  427. WARN_ON(1);
  428. break;
  429. }
  430. if (local->open_count == 0) {
  431. res = drv_start(local);
  432. if (res)
  433. goto err_del_bss;
  434. /* we're brought up, everything changes */
  435. hw_reconf_flags = ~0;
  436. ieee80211_led_radio(local, true);
  437. ieee80211_mod_tpt_led_trig(local,
  438. IEEE80211_TPT_LEDTRIG_FL_RADIO, 0);
  439. }
  440. /*
  441. * Copy the hopefully now-present MAC address to
  442. * this interface, if it has the special null one.
  443. */
  444. if (dev && is_zero_ether_addr(dev->dev_addr)) {
  445. memcpy(dev->dev_addr,
  446. local->hw.wiphy->perm_addr,
  447. ETH_ALEN);
  448. memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
  449. if (!is_valid_ether_addr(dev->dev_addr)) {
  450. res = -EADDRNOTAVAIL;
  451. goto err_stop;
  452. }
  453. }
  454. switch (sdata->vif.type) {
  455. case NL80211_IFTYPE_AP_VLAN:
  456. /* no need to tell driver, but set carrier and chanctx */
  457. if (rtnl_dereference(sdata->bss->beacon)) {
  458. ieee80211_vif_vlan_copy_chanctx(sdata);
  459. netif_carrier_on(dev);
  460. } else {
  461. netif_carrier_off(dev);
  462. }
  463. break;
  464. case NL80211_IFTYPE_MONITOR:
  465. if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
  466. local->cooked_mntrs++;
  467. break;
  468. }
  469. if (sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE) {
  470. res = drv_add_interface(local, sdata);
  471. if (res)
  472. goto err_stop;
  473. } else if (local->monitors == 0 && local->open_count == 0) {
  474. res = ieee80211_add_virtual_monitor(local);
  475. if (res)
  476. goto err_stop;
  477. }
  478. /* must be before the call to ieee80211_configure_filter */
  479. local->monitors++;
  480. if (local->monitors == 1) {
  481. local->hw.conf.flags |= IEEE80211_CONF_MONITOR;
  482. hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
  483. }
  484. ieee80211_adjust_monitor_flags(sdata, 1);
  485. ieee80211_configure_filter(local);
  486. mutex_lock(&local->mtx);
  487. ieee80211_recalc_idle(local);
  488. mutex_unlock(&local->mtx);
  489. netif_carrier_on(dev);
  490. break;
  491. default:
  492. if (coming_up) {
  493. ieee80211_del_virtual_monitor(local);
  494. res = drv_add_interface(local, sdata);
  495. if (res)
  496. goto err_stop;
  497. res = ieee80211_check_queues(sdata,
  498. ieee80211_vif_type_p2p(&sdata->vif));
  499. if (res)
  500. goto err_del_interface;
  501. }
  502. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  503. local->fif_pspoll++;
  504. local->fif_probe_req++;
  505. ieee80211_configure_filter(local);
  506. } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  507. local->fif_probe_req++;
  508. }
  509. if (sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE)
  510. changed |= ieee80211_reset_erp_info(sdata);
  511. ieee80211_bss_info_change_notify(sdata, changed);
  512. switch (sdata->vif.type) {
  513. case NL80211_IFTYPE_STATION:
  514. case NL80211_IFTYPE_ADHOC:
  515. case NL80211_IFTYPE_AP:
  516. case NL80211_IFTYPE_MESH_POINT:
  517. netif_carrier_off(dev);
  518. break;
  519. case NL80211_IFTYPE_WDS:
  520. case NL80211_IFTYPE_P2P_DEVICE:
  521. break;
  522. default:
  523. /* not reached */
  524. WARN_ON(1);
  525. }
  526. /*
  527. * set default queue parameters so drivers don't
  528. * need to initialise the hardware if the hardware
  529. * doesn't start up with sane defaults
  530. */
  531. ieee80211_set_wmm_default(sdata, true);
  532. }
  533. set_bit(SDATA_STATE_RUNNING, &sdata->state);
  534. if (sdata->vif.type == NL80211_IFTYPE_WDS) {
  535. /* Create STA entry for the WDS peer */
  536. sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
  537. GFP_KERNEL);
  538. if (!sta) {
  539. res = -ENOMEM;
  540. goto err_del_interface;
  541. }
  542. sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
  543. sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
  544. sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
  545. res = sta_info_insert(sta);
  546. if (res) {
  547. /* STA has been freed */
  548. goto err_del_interface;
  549. }
  550. rate_control_rate_init(sta);
  551. netif_carrier_on(dev);
  552. } else if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
  553. rcu_assign_pointer(local->p2p_sdata, sdata);
  554. }
  555. /*
  556. * set_multicast_list will be invoked by the networking core
  557. * which will check whether any increments here were done in
  558. * error and sync them down to the hardware as filter flags.
  559. */
  560. if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
  561. atomic_inc(&local->iff_allmultis);
  562. if (sdata->flags & IEEE80211_SDATA_PROMISC)
  563. atomic_inc(&local->iff_promiscs);
  564. if (coming_up)
  565. local->open_count++;
  566. if (hw_reconf_flags)
  567. ieee80211_hw_config(local, hw_reconf_flags);
  568. ieee80211_recalc_ps(local, -1);
  569. if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
  570. sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
  571. /* XXX: for AP_VLAN, actually track AP queues */
  572. netif_tx_start_all_queues(dev);
  573. } else if (dev) {
  574. unsigned long flags;
  575. int n_acs = IEEE80211_NUM_ACS;
  576. int ac;
  577. if (local->hw.queues < IEEE80211_NUM_ACS)
  578. n_acs = 1;
  579. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  580. if (sdata->vif.cab_queue == IEEE80211_INVAL_HW_QUEUE ||
  581. (local->queue_stop_reasons[sdata->vif.cab_queue] == 0 &&
  582. skb_queue_empty(&local->pending[sdata->vif.cab_queue]))) {
  583. for (ac = 0; ac < n_acs; ac++) {
  584. int ac_queue = sdata->vif.hw_queue[ac];
  585. if (local->queue_stop_reasons[ac_queue] == 0 &&
  586. skb_queue_empty(&local->pending[ac_queue]))
  587. netif_start_subqueue(dev, ac);
  588. }
  589. }
  590. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  591. }
  592. return 0;
  593. err_del_interface:
  594. drv_remove_interface(local, sdata);
  595. err_stop:
  596. if (!local->open_count)
  597. drv_stop(local);
  598. err_del_bss:
  599. sdata->bss = NULL;
  600. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  601. list_del(&sdata->u.vlan.list);
  602. /* might already be clear but that doesn't matter */
  603. clear_bit(SDATA_STATE_RUNNING, &sdata->state);
  604. return res;
  605. }
  606. static int ieee80211_open(struct net_device *dev)
  607. {
  608. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  609. int err;
  610. /* fail early if user set an invalid address */
  611. if (!is_valid_ether_addr(dev->dev_addr))
  612. return -EADDRNOTAVAIL;
  613. err = ieee80211_check_concurrent_iface(sdata, sdata->vif.type);
  614. if (err)
  615. return err;
  616. return ieee80211_do_open(&sdata->wdev, true);
  617. }
  618. static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
  619. bool going_down)
  620. {
  621. struct ieee80211_local *local = sdata->local;
  622. unsigned long flags;
  623. struct sk_buff *skb, *tmp;
  624. u32 hw_reconf_flags = 0;
  625. int i, flushed;
  626. struct ps_data *ps;
  627. clear_bit(SDATA_STATE_RUNNING, &sdata->state);
  628. if (rcu_access_pointer(local->scan_sdata) == sdata)
  629. ieee80211_scan_cancel(local);
  630. /*
  631. * Stop TX on this interface first.
  632. */
  633. if (sdata->dev)
  634. netif_tx_stop_all_queues(sdata->dev);
  635. ieee80211_roc_purge(local, sdata);
  636. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  637. ieee80211_mgd_stop(sdata);
  638. /*
  639. * Remove all stations associated with this interface.
  640. *
  641. * This must be done before calling ops->remove_interface()
  642. * because otherwise we can later invoke ops->sta_notify()
  643. * whenever the STAs are removed, and that invalidates driver
  644. * assumptions about always getting a vif pointer that is valid
  645. * (because if we remove a STA after ops->remove_interface()
  646. * the driver will have removed the vif info already!)
  647. *
  648. * This is relevant only in WDS mode, in all other modes we've
  649. * already removed all stations when disconnecting or similar,
  650. * so warn otherwise.
  651. *
  652. * We call sta_info_flush_cleanup() later, to combine RCU waits.
  653. */
  654. flushed = sta_info_flush_defer(sdata);
  655. WARN_ON_ONCE((sdata->vif.type != NL80211_IFTYPE_WDS && flushed > 0) ||
  656. (sdata->vif.type == NL80211_IFTYPE_WDS && flushed != 1));
  657. /* don't count this interface for promisc/allmulti while it is down */
  658. if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
  659. atomic_dec(&local->iff_allmultis);
  660. if (sdata->flags & IEEE80211_SDATA_PROMISC)
  661. atomic_dec(&local->iff_promiscs);
  662. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  663. local->fif_pspoll--;
  664. local->fif_probe_req--;
  665. } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  666. local->fif_probe_req--;
  667. }
  668. if (sdata->dev) {
  669. netif_addr_lock_bh(sdata->dev);
  670. spin_lock_bh(&local->filter_lock);
  671. __hw_addr_unsync(&local->mc_list, &sdata->dev->mc,
  672. sdata->dev->addr_len);
  673. spin_unlock_bh(&local->filter_lock);
  674. netif_addr_unlock_bh(sdata->dev);
  675. }
  676. del_timer_sync(&local->dynamic_ps_timer);
  677. cancel_work_sync(&local->dynamic_ps_enable_work);
  678. cancel_work_sync(&sdata->recalc_smps);
  679. sdata->vif.csa_active = false;
  680. cancel_work_sync(&sdata->csa_finalize_work);
  681. cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
  682. if (sdata->wdev.cac_started) {
  683. WARN_ON(local->suspended);
  684. mutex_lock(&local->iflist_mtx);
  685. ieee80211_vif_release_channel(sdata);
  686. mutex_unlock(&local->iflist_mtx);
  687. cfg80211_cac_event(sdata->dev, NL80211_RADAR_CAC_ABORTED,
  688. GFP_KERNEL);
  689. }
  690. /* APs need special treatment */
  691. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  692. struct ieee80211_sub_if_data *vlan, *tmpsdata;
  693. /* down all dependent devices, that is VLANs */
  694. list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans,
  695. u.vlan.list)
  696. dev_close(vlan->dev);
  697. WARN_ON(!list_empty(&sdata->u.ap.vlans));
  698. } else if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
  699. /* remove all packets in parent bc_buf pointing to this dev */
  700. ps = &sdata->bss->ps;
  701. spin_lock_irqsave(&ps->bc_buf.lock, flags);
  702. skb_queue_walk_safe(&ps->bc_buf, skb, tmp) {
  703. if (skb->dev == sdata->dev) {
  704. __skb_unlink(skb, &ps->bc_buf);
  705. local->total_ps_buffered--;
  706. ieee80211_free_txskb(&local->hw, skb);
  707. }
  708. }
  709. spin_unlock_irqrestore(&ps->bc_buf.lock, flags);
  710. }
  711. if (going_down)
  712. local->open_count--;
  713. switch (sdata->vif.type) {
  714. case NL80211_IFTYPE_AP_VLAN:
  715. list_del(&sdata->u.vlan.list);
  716. rcu_assign_pointer(sdata->vif.chanctx_conf, NULL);
  717. /* no need to tell driver */
  718. break;
  719. case NL80211_IFTYPE_MONITOR:
  720. if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
  721. local->cooked_mntrs--;
  722. break;
  723. }
  724. local->monitors--;
  725. if (local->monitors == 0) {
  726. local->hw.conf.flags &= ~IEEE80211_CONF_MONITOR;
  727. hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR;
  728. }
  729. ieee80211_adjust_monitor_flags(sdata, -1);
  730. break;
  731. case NL80211_IFTYPE_P2P_DEVICE:
  732. /* relies on synchronize_rcu() below */
  733. rcu_assign_pointer(local->p2p_sdata, NULL);
  734. /* fall through */
  735. default:
  736. cancel_work_sync(&sdata->work);
  737. /*
  738. * When we get here, the interface is marked down.
  739. *
  740. * sta_info_flush_cleanup() requires rcu_barrier()
  741. * first to wait for the station call_rcu() calls
  742. * to complete, and we also need synchronize_rcu()
  743. * to wait for the RX path in case it is using the
  744. * interface and enqueuing frames at this very time on
  745. * another CPU.
  746. */
  747. synchronize_rcu();
  748. rcu_barrier();
  749. sta_info_flush_cleanup(sdata);
  750. /*
  751. * Free all remaining keys, there shouldn't be any,
  752. * except maybe in WDS mode?
  753. */
  754. ieee80211_free_keys(sdata);
  755. /* fall through */
  756. case NL80211_IFTYPE_AP:
  757. skb_queue_purge(&sdata->skb_queue);
  758. }
  759. sdata->bss = NULL;
  760. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  761. for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
  762. skb_queue_walk_safe(&local->pending[i], skb, tmp) {
  763. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  764. if (info->control.vif == &sdata->vif) {
  765. __skb_unlink(skb, &local->pending[i]);
  766. ieee80211_free_txskb(&local->hw, skb);
  767. }
  768. }
  769. }
  770. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  771. if (local->open_count == 0)
  772. ieee80211_clear_tx_pending(local);
  773. /*
  774. * If the interface goes down while suspended, presumably because
  775. * the device was unplugged and that happens before our resume,
  776. * then the driver is already unconfigured and the remainder of
  777. * this function isn't needed.
  778. * XXX: what about WoWLAN? If the device has software state, e.g.
  779. * memory allocated, it might expect teardown commands from
  780. * mac80211 here?
  781. */
  782. if (local->suspended) {
  783. WARN_ON(local->wowlan);
  784. WARN_ON(rtnl_dereference(local->monitor_sdata));
  785. return;
  786. }
  787. switch (sdata->vif.type) {
  788. case NL80211_IFTYPE_AP_VLAN:
  789. break;
  790. case NL80211_IFTYPE_MONITOR:
  791. if (local->monitors == 0)
  792. ieee80211_del_virtual_monitor(local);
  793. mutex_lock(&local->mtx);
  794. ieee80211_recalc_idle(local);
  795. mutex_unlock(&local->mtx);
  796. if (!(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))
  797. break;
  798. /* fall through */
  799. default:
  800. if (going_down)
  801. drv_remove_interface(local, sdata);
  802. }
  803. ieee80211_recalc_ps(local, -1);
  804. if (local->open_count == 0) {
  805. ieee80211_stop_device(local);
  806. /* no reconfiguring after stop! */
  807. return;
  808. }
  809. /* do after stop to avoid reconfiguring when we stop anyway */
  810. ieee80211_configure_filter(local);
  811. ieee80211_hw_config(local, hw_reconf_flags);
  812. if (local->monitors == local->open_count)
  813. ieee80211_add_virtual_monitor(local);
  814. }
  815. static int ieee80211_stop(struct net_device *dev)
  816. {
  817. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  818. ieee80211_do_stop(sdata, true);
  819. return 0;
  820. }
  821. static void ieee80211_set_multicast_list(struct net_device *dev)
  822. {
  823. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  824. struct ieee80211_local *local = sdata->local;
  825. int allmulti, promisc, sdata_allmulti, sdata_promisc;
  826. allmulti = !!(dev->flags & IFF_ALLMULTI);
  827. promisc = !!(dev->flags & IFF_PROMISC);
  828. sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
  829. sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC);
  830. if (allmulti != sdata_allmulti) {
  831. if (dev->flags & IFF_ALLMULTI)
  832. atomic_inc(&local->iff_allmultis);
  833. else
  834. atomic_dec(&local->iff_allmultis);
  835. sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
  836. }
  837. if (promisc != sdata_promisc) {
  838. if (dev->flags & IFF_PROMISC)
  839. atomic_inc(&local->iff_promiscs);
  840. else
  841. atomic_dec(&local->iff_promiscs);
  842. sdata->flags ^= IEEE80211_SDATA_PROMISC;
  843. }
  844. /*
  845. * TODO: If somebody needs this on AP interfaces,
  846. * it can be enabled easily but multicast
  847. * addresses from VLANs need to be synced.
  848. */
  849. if (sdata->vif.type != NL80211_IFTYPE_MONITOR &&
  850. sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  851. sdata->vif.type != NL80211_IFTYPE_AP)
  852. drv_set_multicast_list(local, sdata, &dev->mc);
  853. spin_lock_bh(&local->filter_lock);
  854. __hw_addr_sync(&local->mc_list, &dev->mc, dev->addr_len);
  855. spin_unlock_bh(&local->filter_lock);
  856. ieee80211_queue_work(&local->hw, &local->reconfig_filter);
  857. }
  858. /*
  859. * Called when the netdev is removed or, by the code below, before
  860. * the interface type changes.
  861. */
  862. static void ieee80211_teardown_sdata(struct ieee80211_sub_if_data *sdata)
  863. {
  864. int flushed;
  865. int i;
  866. /* free extra data */
  867. ieee80211_free_keys(sdata);
  868. ieee80211_debugfs_remove_netdev(sdata);
  869. for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
  870. __skb_queue_purge(&sdata->fragments[i].skb_list);
  871. sdata->fragment_next = 0;
  872. if (ieee80211_vif_is_mesh(&sdata->vif))
  873. mesh_rmc_free(sdata);
  874. flushed = sta_info_flush(sdata);
  875. WARN_ON(flushed);
  876. }
  877. static void ieee80211_uninit(struct net_device *dev)
  878. {
  879. ieee80211_teardown_sdata(IEEE80211_DEV_TO_SUB_IF(dev));
  880. }
  881. static u16 ieee80211_netdev_select_queue(struct net_device *dev,
  882. struct sk_buff *skb)
  883. {
  884. return ieee80211_select_queue(IEEE80211_DEV_TO_SUB_IF(dev), skb);
  885. }
  886. static const struct net_device_ops ieee80211_dataif_ops = {
  887. .ndo_open = ieee80211_open,
  888. .ndo_stop = ieee80211_stop,
  889. .ndo_uninit = ieee80211_uninit,
  890. .ndo_start_xmit = ieee80211_subif_start_xmit,
  891. .ndo_set_rx_mode = ieee80211_set_multicast_list,
  892. .ndo_change_mtu = ieee80211_change_mtu,
  893. .ndo_set_mac_address = ieee80211_change_mac,
  894. .ndo_select_queue = ieee80211_netdev_select_queue,
  895. };
  896. static u16 ieee80211_monitor_select_queue(struct net_device *dev,
  897. struct sk_buff *skb)
  898. {
  899. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  900. struct ieee80211_local *local = sdata->local;
  901. struct ieee80211_hdr *hdr;
  902. struct ieee80211_radiotap_header *rtap = (void *)skb->data;
  903. if (local->hw.queues < IEEE80211_NUM_ACS)
  904. return 0;
  905. if (skb->len < 4 ||
  906. skb->len < le16_to_cpu(rtap->it_len) + 2 /* frame control */)
  907. return 0; /* doesn't matter, frame will be dropped */
  908. hdr = (void *)((u8 *)skb->data + le16_to_cpu(rtap->it_len));
  909. return ieee80211_select_queue_80211(sdata, skb, hdr);
  910. }
  911. static const struct net_device_ops ieee80211_monitorif_ops = {
  912. .ndo_open = ieee80211_open,
  913. .ndo_stop = ieee80211_stop,
  914. .ndo_uninit = ieee80211_uninit,
  915. .ndo_start_xmit = ieee80211_monitor_start_xmit,
  916. .ndo_set_rx_mode = ieee80211_set_multicast_list,
  917. .ndo_change_mtu = ieee80211_change_mtu,
  918. .ndo_set_mac_address = ieee80211_change_mac,
  919. .ndo_select_queue = ieee80211_monitor_select_queue,
  920. };
  921. static void ieee80211_if_setup(struct net_device *dev)
  922. {
  923. ether_setup(dev);
  924. dev->priv_flags &= ~IFF_TX_SKB_SHARING;
  925. dev->netdev_ops = &ieee80211_dataif_ops;
  926. dev->destructor = free_netdev;
  927. }
  928. static void ieee80211_iface_work(struct work_struct *work)
  929. {
  930. struct ieee80211_sub_if_data *sdata =
  931. container_of(work, struct ieee80211_sub_if_data, work);
  932. struct ieee80211_local *local = sdata->local;
  933. struct sk_buff *skb;
  934. struct sta_info *sta;
  935. struct ieee80211_ra_tid *ra_tid;
  936. if (!ieee80211_sdata_running(sdata))
  937. return;
  938. if (local->scanning)
  939. return;
  940. /*
  941. * ieee80211_queue_work() should have picked up most cases,
  942. * here we'll pick the rest.
  943. */
  944. if (WARN(local->suspended,
  945. "interface work scheduled while going to suspend\n"))
  946. return;
  947. /* first process frames */
  948. while ((skb = skb_dequeue(&sdata->skb_queue))) {
  949. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  950. if (skb->pkt_type == IEEE80211_SDATA_QUEUE_AGG_START) {
  951. ra_tid = (void *)&skb->cb;
  952. ieee80211_start_tx_ba_cb(&sdata->vif, ra_tid->ra,
  953. ra_tid->tid);
  954. } else if (skb->pkt_type == IEEE80211_SDATA_QUEUE_AGG_STOP) {
  955. ra_tid = (void *)&skb->cb;
  956. ieee80211_stop_tx_ba_cb(&sdata->vif, ra_tid->ra,
  957. ra_tid->tid);
  958. } else if (ieee80211_is_action(mgmt->frame_control) &&
  959. mgmt->u.action.category == WLAN_CATEGORY_BACK) {
  960. int len = skb->len;
  961. mutex_lock(&local->sta_mtx);
  962. sta = sta_info_get_bss(sdata, mgmt->sa);
  963. if (sta) {
  964. switch (mgmt->u.action.u.addba_req.action_code) {
  965. case WLAN_ACTION_ADDBA_REQ:
  966. ieee80211_process_addba_request(
  967. local, sta, mgmt, len);
  968. break;
  969. case WLAN_ACTION_ADDBA_RESP:
  970. ieee80211_process_addba_resp(local, sta,
  971. mgmt, len);
  972. break;
  973. case WLAN_ACTION_DELBA:
  974. ieee80211_process_delba(sdata, sta,
  975. mgmt, len);
  976. break;
  977. default:
  978. WARN_ON(1);
  979. break;
  980. }
  981. }
  982. mutex_unlock(&local->sta_mtx);
  983. } else if (ieee80211_is_data_qos(mgmt->frame_control)) {
  984. struct ieee80211_hdr *hdr = (void *)mgmt;
  985. /*
  986. * So the frame isn't mgmt, but frame_control
  987. * is at the right place anyway, of course, so
  988. * the if statement is correct.
  989. *
  990. * Warn if we have other data frame types here,
  991. * they must not get here.
  992. */
  993. WARN_ON(hdr->frame_control &
  994. cpu_to_le16(IEEE80211_STYPE_NULLFUNC));
  995. WARN_ON(!(hdr->seq_ctrl &
  996. cpu_to_le16(IEEE80211_SCTL_FRAG)));
  997. /*
  998. * This was a fragment of a frame, received while
  999. * a block-ack session was active. That cannot be
  1000. * right, so terminate the session.
  1001. */
  1002. mutex_lock(&local->sta_mtx);
  1003. sta = sta_info_get_bss(sdata, mgmt->sa);
  1004. if (sta) {
  1005. u16 tid = *ieee80211_get_qos_ctl(hdr) &
  1006. IEEE80211_QOS_CTL_TID_MASK;
  1007. __ieee80211_stop_rx_ba_session(
  1008. sta, tid, WLAN_BACK_RECIPIENT,
  1009. WLAN_REASON_QSTA_REQUIRE_SETUP,
  1010. true);
  1011. }
  1012. mutex_unlock(&local->sta_mtx);
  1013. } else switch (sdata->vif.type) {
  1014. case NL80211_IFTYPE_STATION:
  1015. ieee80211_sta_rx_queued_mgmt(sdata, skb);
  1016. break;
  1017. case NL80211_IFTYPE_ADHOC:
  1018. ieee80211_ibss_rx_queued_mgmt(sdata, skb);
  1019. break;
  1020. case NL80211_IFTYPE_MESH_POINT:
  1021. if (!ieee80211_vif_is_mesh(&sdata->vif))
  1022. break;
  1023. ieee80211_mesh_rx_queued_mgmt(sdata, skb);
  1024. break;
  1025. default:
  1026. WARN(1, "frame for unexpected interface type");
  1027. break;
  1028. }
  1029. kfree_skb(skb);
  1030. }
  1031. /* then other type-dependent work */
  1032. switch (sdata->vif.type) {
  1033. case NL80211_IFTYPE_STATION:
  1034. ieee80211_sta_work(sdata);
  1035. break;
  1036. case NL80211_IFTYPE_ADHOC:
  1037. ieee80211_ibss_work(sdata);
  1038. break;
  1039. case NL80211_IFTYPE_MESH_POINT:
  1040. if (!ieee80211_vif_is_mesh(&sdata->vif))
  1041. break;
  1042. ieee80211_mesh_work(sdata);
  1043. break;
  1044. default:
  1045. break;
  1046. }
  1047. }
  1048. static void ieee80211_recalc_smps_work(struct work_struct *work)
  1049. {
  1050. struct ieee80211_sub_if_data *sdata =
  1051. container_of(work, struct ieee80211_sub_if_data, recalc_smps);
  1052. ieee80211_recalc_smps(sdata);
  1053. }
  1054. /*
  1055. * Helper function to initialise an interface to a specific type.
  1056. */
  1057. static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
  1058. enum nl80211_iftype type)
  1059. {
  1060. /* clear type-dependent union */
  1061. memset(&sdata->u, 0, sizeof(sdata->u));
  1062. /* and set some type-dependent values */
  1063. sdata->vif.type = type;
  1064. sdata->vif.p2p = false;
  1065. sdata->wdev.iftype = type;
  1066. sdata->control_port_protocol = cpu_to_be16(ETH_P_PAE);
  1067. sdata->control_port_no_encrypt = false;
  1068. sdata->noack_map = 0;
  1069. /* only monitor/p2p-device differ */
  1070. if (sdata->dev) {
  1071. sdata->dev->netdev_ops = &ieee80211_dataif_ops;
  1072. sdata->dev->type = ARPHRD_ETHER;
  1073. }
  1074. skb_queue_head_init(&sdata->skb_queue);
  1075. INIT_WORK(&sdata->work, ieee80211_iface_work);
  1076. INIT_WORK(&sdata->recalc_smps, ieee80211_recalc_smps_work);
  1077. INIT_WORK(&sdata->csa_finalize_work, ieee80211_csa_finalize_work);
  1078. switch (type) {
  1079. case NL80211_IFTYPE_P2P_GO:
  1080. type = NL80211_IFTYPE_AP;
  1081. sdata->vif.type = type;
  1082. sdata->vif.p2p = true;
  1083. /* fall through */
  1084. case NL80211_IFTYPE_AP:
  1085. skb_queue_head_init(&sdata->u.ap.ps.bc_buf);
  1086. INIT_LIST_HEAD(&sdata->u.ap.vlans);
  1087. sdata->vif.bss_conf.bssid = sdata->vif.addr;
  1088. break;
  1089. case NL80211_IFTYPE_P2P_CLIENT:
  1090. type = NL80211_IFTYPE_STATION;
  1091. sdata->vif.type = type;
  1092. sdata->vif.p2p = true;
  1093. /* fall through */
  1094. case NL80211_IFTYPE_STATION:
  1095. sdata->vif.bss_conf.bssid = sdata->u.mgd.bssid;
  1096. ieee80211_sta_setup_sdata(sdata);
  1097. break;
  1098. case NL80211_IFTYPE_ADHOC:
  1099. sdata->vif.bss_conf.bssid = sdata->u.ibss.bssid;
  1100. ieee80211_ibss_setup_sdata(sdata);
  1101. break;
  1102. case NL80211_IFTYPE_MESH_POINT:
  1103. if (ieee80211_vif_is_mesh(&sdata->vif))
  1104. ieee80211_mesh_init_sdata(sdata);
  1105. break;
  1106. case NL80211_IFTYPE_MONITOR:
  1107. sdata->dev->type = ARPHRD_IEEE80211_RADIOTAP;
  1108. sdata->dev->netdev_ops = &ieee80211_monitorif_ops;
  1109. sdata->u.mntr_flags = MONITOR_FLAG_CONTROL |
  1110. MONITOR_FLAG_OTHER_BSS;
  1111. break;
  1112. case NL80211_IFTYPE_WDS:
  1113. sdata->vif.bss_conf.bssid = NULL;
  1114. break;
  1115. case NL80211_IFTYPE_AP_VLAN:
  1116. break;
  1117. case NL80211_IFTYPE_P2P_DEVICE:
  1118. sdata->vif.bss_conf.bssid = sdata->vif.addr;
  1119. break;
  1120. case NL80211_IFTYPE_UNSPECIFIED:
  1121. case NUM_NL80211_IFTYPES:
  1122. BUG();
  1123. break;
  1124. }
  1125. ieee80211_debugfs_add_netdev(sdata);
  1126. }
  1127. static int ieee80211_runtime_change_iftype(struct ieee80211_sub_if_data *sdata,
  1128. enum nl80211_iftype type)
  1129. {
  1130. struct ieee80211_local *local = sdata->local;
  1131. int ret, err;
  1132. enum nl80211_iftype internal_type = type;
  1133. bool p2p = false;
  1134. ASSERT_RTNL();
  1135. if (!local->ops->change_interface)
  1136. return -EBUSY;
  1137. switch (sdata->vif.type) {
  1138. case NL80211_IFTYPE_AP:
  1139. case NL80211_IFTYPE_STATION:
  1140. case NL80211_IFTYPE_ADHOC:
  1141. /*
  1142. * Could maybe also all others here?
  1143. * Just not sure how that interacts
  1144. * with the RX/config path e.g. for
  1145. * mesh.
  1146. */
  1147. break;
  1148. default:
  1149. return -EBUSY;
  1150. }
  1151. switch (type) {
  1152. case NL80211_IFTYPE_AP:
  1153. case NL80211_IFTYPE_STATION:
  1154. case NL80211_IFTYPE_ADHOC:
  1155. /*
  1156. * Could probably support everything
  1157. * but WDS here (WDS do_open can fail
  1158. * under memory pressure, which this
  1159. * code isn't prepared to handle).
  1160. */
  1161. break;
  1162. case NL80211_IFTYPE_P2P_CLIENT:
  1163. p2p = true;
  1164. internal_type = NL80211_IFTYPE_STATION;
  1165. break;
  1166. case NL80211_IFTYPE_P2P_GO:
  1167. p2p = true;
  1168. internal_type = NL80211_IFTYPE_AP;
  1169. break;
  1170. default:
  1171. return -EBUSY;
  1172. }
  1173. ret = ieee80211_check_concurrent_iface(sdata, internal_type);
  1174. if (ret)
  1175. return ret;
  1176. ieee80211_do_stop(sdata, false);
  1177. ieee80211_teardown_sdata(sdata);
  1178. ret = drv_change_interface(local, sdata, internal_type, p2p);
  1179. if (ret)
  1180. type = ieee80211_vif_type_p2p(&sdata->vif);
  1181. /*
  1182. * Ignore return value here, there's not much we can do since
  1183. * the driver changed the interface type internally already.
  1184. * The warnings will hopefully make driver authors fix it :-)
  1185. */
  1186. ieee80211_check_queues(sdata, type);
  1187. ieee80211_setup_sdata(sdata, type);
  1188. err = ieee80211_do_open(&sdata->wdev, false);
  1189. WARN(err, "type change: do_open returned %d", err);
  1190. return ret;
  1191. }
  1192. int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
  1193. enum nl80211_iftype type)
  1194. {
  1195. int ret;
  1196. ASSERT_RTNL();
  1197. if (type == ieee80211_vif_type_p2p(&sdata->vif))
  1198. return 0;
  1199. if (ieee80211_sdata_running(sdata)) {
  1200. ret = ieee80211_runtime_change_iftype(sdata, type);
  1201. if (ret)
  1202. return ret;
  1203. } else {
  1204. /* Purge and reset type-dependent state. */
  1205. ieee80211_teardown_sdata(sdata);
  1206. ieee80211_setup_sdata(sdata, type);
  1207. }
  1208. /* reset some values that shouldn't be kept across type changes */
  1209. sdata->drop_unencrypted = 0;
  1210. if (type == NL80211_IFTYPE_STATION)
  1211. sdata->u.mgd.use_4addr = false;
  1212. return 0;
  1213. }
  1214. static void ieee80211_assign_perm_addr(struct ieee80211_local *local,
  1215. u8 *perm_addr, enum nl80211_iftype type)
  1216. {
  1217. struct ieee80211_sub_if_data *sdata;
  1218. u64 mask, start, addr, val, inc;
  1219. u8 *m;
  1220. u8 tmp_addr[ETH_ALEN];
  1221. int i;
  1222. /* default ... something at least */
  1223. memcpy(perm_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
  1224. if (is_zero_ether_addr(local->hw.wiphy->addr_mask) &&
  1225. local->hw.wiphy->n_addresses <= 1)
  1226. return;
  1227. mutex_lock(&local->iflist_mtx);
  1228. switch (type) {
  1229. case NL80211_IFTYPE_MONITOR:
  1230. /* doesn't matter */
  1231. break;
  1232. case NL80211_IFTYPE_WDS:
  1233. case NL80211_IFTYPE_AP_VLAN:
  1234. /* match up with an AP interface */
  1235. list_for_each_entry(sdata, &local->interfaces, list) {
  1236. if (sdata->vif.type != NL80211_IFTYPE_AP)
  1237. continue;
  1238. memcpy(perm_addr, sdata->vif.addr, ETH_ALEN);
  1239. break;
  1240. }
  1241. /* keep default if no AP interface present */
  1242. break;
  1243. case NL80211_IFTYPE_P2P_CLIENT:
  1244. case NL80211_IFTYPE_P2P_GO:
  1245. if (local->hw.flags & IEEE80211_HW_P2P_DEV_ADDR_FOR_INTF) {
  1246. list_for_each_entry(sdata, &local->interfaces, list) {
  1247. if (sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE)
  1248. continue;
  1249. if (!ieee80211_sdata_running(sdata))
  1250. continue;
  1251. memcpy(perm_addr, sdata->vif.addr, ETH_ALEN);
  1252. goto out_unlock;
  1253. }
  1254. }
  1255. /* otherwise fall through */
  1256. default:
  1257. /* assign a new address if possible -- try n_addresses first */
  1258. for (i = 0; i < local->hw.wiphy->n_addresses; i++) {
  1259. bool used = false;
  1260. list_for_each_entry(sdata, &local->interfaces, list) {
  1261. if (memcmp(local->hw.wiphy->addresses[i].addr,
  1262. sdata->vif.addr, ETH_ALEN) == 0) {
  1263. used = true;
  1264. break;
  1265. }
  1266. }
  1267. if (!used) {
  1268. memcpy(perm_addr,
  1269. local->hw.wiphy->addresses[i].addr,
  1270. ETH_ALEN);
  1271. break;
  1272. }
  1273. }
  1274. /* try mask if available */
  1275. if (is_zero_ether_addr(local->hw.wiphy->addr_mask))
  1276. break;
  1277. m = local->hw.wiphy->addr_mask;
  1278. mask = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
  1279. ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
  1280. ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
  1281. if (__ffs64(mask) + hweight64(mask) != fls64(mask)) {
  1282. /* not a contiguous mask ... not handled now! */
  1283. pr_info("not contiguous\n");
  1284. break;
  1285. }
  1286. /*
  1287. * Pick address of existing interface in case user changed
  1288. * MAC address manually, default to perm_addr.
  1289. */
  1290. m = local->hw.wiphy->perm_addr;
  1291. list_for_each_entry(sdata, &local->interfaces, list) {
  1292. if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
  1293. continue;
  1294. m = sdata->vif.addr;
  1295. break;
  1296. }
  1297. start = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
  1298. ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
  1299. ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
  1300. inc = 1ULL<<__ffs64(mask);
  1301. val = (start & mask);
  1302. addr = (start & ~mask) | (val & mask);
  1303. do {
  1304. bool used = false;
  1305. tmp_addr[5] = addr >> 0*8;
  1306. tmp_addr[4] = addr >> 1*8;
  1307. tmp_addr[3] = addr >> 2*8;
  1308. tmp_addr[2] = addr >> 3*8;
  1309. tmp_addr[1] = addr >> 4*8;
  1310. tmp_addr[0] = addr >> 5*8;
  1311. val += inc;
  1312. list_for_each_entry(sdata, &local->interfaces, list) {
  1313. if (memcmp(tmp_addr, sdata->vif.addr,
  1314. ETH_ALEN) == 0) {
  1315. used = true;
  1316. break;
  1317. }
  1318. }
  1319. if (!used) {
  1320. memcpy(perm_addr, tmp_addr, ETH_ALEN);
  1321. break;
  1322. }
  1323. addr = (start & ~mask) | (val & mask);
  1324. } while (addr != start);
  1325. break;
  1326. }
  1327. out_unlock:
  1328. mutex_unlock(&local->iflist_mtx);
  1329. }
  1330. static void ieee80211_cleanup_sdata_stas_wk(struct work_struct *wk)
  1331. {
  1332. struct ieee80211_sub_if_data *sdata;
  1333. sdata = container_of(wk, struct ieee80211_sub_if_data, cleanup_stations_wk);
  1334. ieee80211_cleanup_sdata_stas(sdata);
  1335. }
  1336. int ieee80211_if_add(struct ieee80211_local *local, const char *name,
  1337. struct wireless_dev **new_wdev, enum nl80211_iftype type,
  1338. struct vif_params *params)
  1339. {
  1340. struct net_device *ndev = NULL;
  1341. struct ieee80211_sub_if_data *sdata = NULL;
  1342. int ret, i;
  1343. int txqs = 1;
  1344. ASSERT_RTNL();
  1345. if (type == NL80211_IFTYPE_P2P_DEVICE) {
  1346. struct wireless_dev *wdev;
  1347. sdata = kzalloc(sizeof(*sdata) + local->hw.vif_data_size,
  1348. GFP_KERNEL);
  1349. if (!sdata)
  1350. return -ENOMEM;
  1351. wdev = &sdata->wdev;
  1352. sdata->dev = NULL;
  1353. strlcpy(sdata->name, name, IFNAMSIZ);
  1354. ieee80211_assign_perm_addr(local, wdev->address, type);
  1355. memcpy(sdata->vif.addr, wdev->address, ETH_ALEN);
  1356. } else {
  1357. if (local->hw.queues >= IEEE80211_NUM_ACS)
  1358. txqs = IEEE80211_NUM_ACS;
  1359. ndev = alloc_netdev_mqs(sizeof(*sdata) +
  1360. local->hw.vif_data_size,
  1361. name, ieee80211_if_setup, txqs, 1);
  1362. if (!ndev)
  1363. return -ENOMEM;
  1364. dev_net_set(ndev, wiphy_net(local->hw.wiphy));
  1365. ndev->needed_headroom = local->tx_headroom +
  1366. 4*6 /* four MAC addresses */
  1367. + 2 + 2 + 2 + 2 /* ctl, dur, seq, qos */
  1368. + 6 /* mesh */
  1369. + 8 /* rfc1042/bridge tunnel */
  1370. - ETH_HLEN /* ethernet hard_header_len */
  1371. + IEEE80211_ENCRYPT_HEADROOM;
  1372. ndev->needed_tailroom = IEEE80211_ENCRYPT_TAILROOM;
  1373. ret = dev_alloc_name(ndev, ndev->name);
  1374. if (ret < 0) {
  1375. free_netdev(ndev);
  1376. return ret;
  1377. }
  1378. ieee80211_assign_perm_addr(local, ndev->perm_addr, type);
  1379. memcpy(ndev->dev_addr, ndev->perm_addr, ETH_ALEN);
  1380. SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy));
  1381. /* don't use IEEE80211_DEV_TO_SUB_IF -- it checks too much */
  1382. sdata = netdev_priv(ndev);
  1383. ndev->ieee80211_ptr = &sdata->wdev;
  1384. memcpy(sdata->vif.addr, ndev->dev_addr, ETH_ALEN);
  1385. memcpy(sdata->name, ndev->name, IFNAMSIZ);
  1386. sdata->dev = ndev;
  1387. }
  1388. /* initialise type-independent data */
  1389. sdata->wdev.wiphy = local->hw.wiphy;
  1390. sdata->local = local;
  1391. for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
  1392. skb_queue_head_init(&sdata->fragments[i].skb_list);
  1393. INIT_LIST_HEAD(&sdata->key_list);
  1394. spin_lock_init(&sdata->cleanup_stations_lock);
  1395. INIT_LIST_HEAD(&sdata->cleanup_stations);
  1396. INIT_WORK(&sdata->cleanup_stations_wk, ieee80211_cleanup_sdata_stas_wk);
  1397. INIT_DELAYED_WORK(&sdata->dfs_cac_timer_work,
  1398. ieee80211_dfs_cac_timer_work);
  1399. INIT_DELAYED_WORK(&sdata->dec_tailroom_needed_wk,
  1400. ieee80211_delayed_tailroom_dec);
  1401. for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
  1402. struct ieee80211_supported_band *sband;
  1403. sband = local->hw.wiphy->bands[i];
  1404. sdata->rc_rateidx_mask[i] =
  1405. sband ? (1 << sband->n_bitrates) - 1 : 0;
  1406. if (sband)
  1407. memcpy(sdata->rc_rateidx_mcs_mask[i],
  1408. sband->ht_cap.mcs.rx_mask,
  1409. sizeof(sdata->rc_rateidx_mcs_mask[i]));
  1410. else
  1411. memset(sdata->rc_rateidx_mcs_mask[i], 0,
  1412. sizeof(sdata->rc_rateidx_mcs_mask[i]));
  1413. }
  1414. ieee80211_set_default_queues(sdata);
  1415. sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
  1416. sdata->user_power_level = local->user_power_level;
  1417. /* setup type-dependent data */
  1418. ieee80211_setup_sdata(sdata, type);
  1419. if (ndev) {
  1420. if (params) {
  1421. ndev->ieee80211_ptr->use_4addr = params->use_4addr;
  1422. if (type == NL80211_IFTYPE_STATION)
  1423. sdata->u.mgd.use_4addr = params->use_4addr;
  1424. }
  1425. ndev->features |= local->hw.netdev_features;
  1426. ret = register_netdevice(ndev);
  1427. if (ret) {
  1428. free_netdev(ndev);
  1429. return ret;
  1430. }
  1431. }
  1432. mutex_lock(&local->iflist_mtx);
  1433. list_add_tail_rcu(&sdata->list, &local->interfaces);
  1434. mutex_unlock(&local->iflist_mtx);
  1435. if (new_wdev)
  1436. *new_wdev = &sdata->wdev;
  1437. return 0;
  1438. }
  1439. void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata)
  1440. {
  1441. ASSERT_RTNL();
  1442. mutex_lock(&sdata->local->iflist_mtx);
  1443. list_del_rcu(&sdata->list);
  1444. mutex_unlock(&sdata->local->iflist_mtx);
  1445. synchronize_rcu();
  1446. if (sdata->dev) {
  1447. unregister_netdevice(sdata->dev);
  1448. } else {
  1449. cfg80211_unregister_wdev(&sdata->wdev);
  1450. kfree(sdata);
  1451. }
  1452. }
  1453. void ieee80211_sdata_stop(struct ieee80211_sub_if_data *sdata)
  1454. {
  1455. if (WARN_ON_ONCE(!test_bit(SDATA_STATE_RUNNING, &sdata->state)))
  1456. return;
  1457. ieee80211_do_stop(sdata, true);
  1458. ieee80211_teardown_sdata(sdata);
  1459. }
  1460. /*
  1461. * Remove all interfaces, may only be called at hardware unregistration
  1462. * time because it doesn't do RCU-safe list removals.
  1463. */
  1464. void ieee80211_remove_interfaces(struct ieee80211_local *local)
  1465. {
  1466. struct ieee80211_sub_if_data *sdata, *tmp;
  1467. LIST_HEAD(unreg_list);
  1468. LIST_HEAD(wdev_list);
  1469. ASSERT_RTNL();
  1470. /*
  1471. * Close all AP_VLAN interfaces first, as otherwise they
  1472. * might be closed while the AP interface they belong to
  1473. * is closed, causing unregister_netdevice_many() to crash.
  1474. */
  1475. list_for_each_entry(sdata, &local->interfaces, list)
  1476. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  1477. dev_close(sdata->dev);
  1478. mutex_lock(&local->iflist_mtx);
  1479. list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
  1480. list_del(&sdata->list);
  1481. if (sdata->dev)
  1482. unregister_netdevice_queue(sdata->dev, &unreg_list);
  1483. else
  1484. list_add(&sdata->list, &wdev_list);
  1485. }
  1486. mutex_unlock(&local->iflist_mtx);
  1487. unregister_netdevice_many(&unreg_list);
  1488. list_del(&unreg_list);
  1489. list_for_each_entry_safe(sdata, tmp, &wdev_list, list) {
  1490. list_del(&sdata->list);
  1491. cfg80211_unregister_wdev(&sdata->wdev);
  1492. kfree(sdata);
  1493. }
  1494. }
  1495. static int netdev_notify(struct notifier_block *nb,
  1496. unsigned long state, void *ptr)
  1497. {
  1498. struct net_device *dev = netdev_notifier_info_to_dev(ptr);
  1499. struct ieee80211_sub_if_data *sdata;
  1500. if (state != NETDEV_CHANGENAME)
  1501. return 0;
  1502. if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
  1503. return 0;
  1504. if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
  1505. return 0;
  1506. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1507. memcpy(sdata->name, dev->name, IFNAMSIZ);
  1508. ieee80211_debugfs_rename_netdev(sdata);
  1509. return 0;
  1510. }
  1511. static struct notifier_block mac80211_netdev_notifier = {
  1512. .notifier_call = netdev_notify,
  1513. };
  1514. int ieee80211_iface_init(void)
  1515. {
  1516. return register_netdevice_notifier(&mac80211_netdev_notifier);
  1517. }
  1518. void ieee80211_iface_exit(void)
  1519. {
  1520. unregister_netdevice_notifier(&mac80211_netdev_notifier);
  1521. }