iface.c 46 KB

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