mesh.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2008, 2009 open80211s Ltd.
  4. * Copyright (C) 2018 - 2022 Intel Corporation
  5. * Authors: Luis Carlos Cobo <[email protected]>
  6. * Javier Cardona <[email protected]>
  7. */
  8. #include <linux/slab.h>
  9. #include <asm/unaligned.h>
  10. #include "ieee80211_i.h"
  11. #include "mesh.h"
  12. #include "driver-ops.h"
  13. static int mesh_allocated;
  14. static struct kmem_cache *rm_cache;
  15. bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt)
  16. {
  17. return (mgmt->u.action.u.mesh_action.action_code ==
  18. WLAN_MESH_ACTION_HWMP_PATH_SELECTION);
  19. }
  20. void ieee80211s_init(void)
  21. {
  22. mesh_allocated = 1;
  23. rm_cache = kmem_cache_create("mesh_rmc", sizeof(struct rmc_entry),
  24. 0, 0, NULL);
  25. }
  26. void ieee80211s_stop(void)
  27. {
  28. if (!mesh_allocated)
  29. return;
  30. kmem_cache_destroy(rm_cache);
  31. }
  32. static void ieee80211_mesh_housekeeping_timer(struct timer_list *t)
  33. {
  34. struct ieee80211_sub_if_data *sdata =
  35. from_timer(sdata, t, u.mesh.housekeeping_timer);
  36. struct ieee80211_local *local = sdata->local;
  37. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  38. set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
  39. ieee80211_queue_work(&local->hw, &sdata->work);
  40. }
  41. /**
  42. * mesh_matches_local - check if the config of a mesh point matches ours
  43. *
  44. * @sdata: local mesh subif
  45. * @ie: information elements of a management frame from the mesh peer
  46. *
  47. * This function checks if the mesh configuration of a mesh point matches the
  48. * local mesh configuration, i.e. if both nodes belong to the same mesh network.
  49. */
  50. bool mesh_matches_local(struct ieee80211_sub_if_data *sdata,
  51. struct ieee802_11_elems *ie)
  52. {
  53. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  54. u32 basic_rates = 0;
  55. struct cfg80211_chan_def sta_chan_def;
  56. struct ieee80211_supported_band *sband;
  57. u32 vht_cap_info = 0;
  58. /*
  59. * As support for each feature is added, check for matching
  60. * - On mesh config capabilities
  61. * - Power Save Support En
  62. * - Sync support enabled
  63. * - Sync support active
  64. * - Sync support required from peer
  65. * - MDA enabled
  66. * - Power management control on fc
  67. */
  68. if (!(ifmsh->mesh_id_len == ie->mesh_id_len &&
  69. memcmp(ifmsh->mesh_id, ie->mesh_id, ie->mesh_id_len) == 0 &&
  70. (ifmsh->mesh_pp_id == ie->mesh_config->meshconf_psel) &&
  71. (ifmsh->mesh_pm_id == ie->mesh_config->meshconf_pmetric) &&
  72. (ifmsh->mesh_cc_id == ie->mesh_config->meshconf_congest) &&
  73. (ifmsh->mesh_sp_id == ie->mesh_config->meshconf_synch) &&
  74. (ifmsh->mesh_auth_id == ie->mesh_config->meshconf_auth)))
  75. return false;
  76. sband = ieee80211_get_sband(sdata);
  77. if (!sband)
  78. return false;
  79. ieee80211_sta_get_rates(sdata, ie, sband->band,
  80. &basic_rates);
  81. if (sdata->vif.bss_conf.basic_rates != basic_rates)
  82. return false;
  83. cfg80211_chandef_create(&sta_chan_def, sdata->vif.bss_conf.chandef.chan,
  84. NL80211_CHAN_NO_HT);
  85. ieee80211_chandef_ht_oper(ie->ht_operation, &sta_chan_def);
  86. if (ie->vht_cap_elem)
  87. vht_cap_info = le32_to_cpu(ie->vht_cap_elem->vht_cap_info);
  88. ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info,
  89. ie->vht_operation, ie->ht_operation,
  90. &sta_chan_def);
  91. ieee80211_chandef_he_6ghz_oper(sdata, ie->he_operation, NULL,
  92. &sta_chan_def);
  93. if (!cfg80211_chandef_compatible(&sdata->vif.bss_conf.chandef,
  94. &sta_chan_def))
  95. return false;
  96. return true;
  97. }
  98. /**
  99. * mesh_peer_accepts_plinks - check if an mp is willing to establish peer links
  100. *
  101. * @ie: information elements of a management frame from the mesh peer
  102. */
  103. bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie)
  104. {
  105. return (ie->mesh_config->meshconf_cap &
  106. IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS) != 0;
  107. }
  108. /**
  109. * mesh_accept_plinks_update - update accepting_plink in local mesh beacons
  110. *
  111. * @sdata: mesh interface in which mesh beacons are going to be updated
  112. *
  113. * Returns: beacon changed flag if the beacon content changed.
  114. */
  115. u32 mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata)
  116. {
  117. bool free_plinks;
  118. u32 changed = 0;
  119. /* In case mesh_plink_free_count > 0 and mesh_plinktbl_capacity == 0,
  120. * the mesh interface might be able to establish plinks with peers that
  121. * are already on the table but are not on PLINK_ESTAB state. However,
  122. * in general the mesh interface is not accepting peer link requests
  123. * from new peers, and that must be reflected in the beacon
  124. */
  125. free_plinks = mesh_plink_availables(sdata);
  126. if (free_plinks != sdata->u.mesh.accepting_plinks) {
  127. sdata->u.mesh.accepting_plinks = free_plinks;
  128. changed = BSS_CHANGED_BEACON;
  129. }
  130. return changed;
  131. }
  132. /*
  133. * mesh_sta_cleanup - clean up any mesh sta state
  134. *
  135. * @sta: mesh sta to clean up.
  136. */
  137. void mesh_sta_cleanup(struct sta_info *sta)
  138. {
  139. struct ieee80211_sub_if_data *sdata = sta->sdata;
  140. u32 changed = mesh_plink_deactivate(sta);
  141. if (changed)
  142. ieee80211_mbss_info_change_notify(sdata, changed);
  143. }
  144. int mesh_rmc_init(struct ieee80211_sub_if_data *sdata)
  145. {
  146. int i;
  147. sdata->u.mesh.rmc = kmalloc(sizeof(struct mesh_rmc), GFP_KERNEL);
  148. if (!sdata->u.mesh.rmc)
  149. return -ENOMEM;
  150. sdata->u.mesh.rmc->idx_mask = RMC_BUCKETS - 1;
  151. for (i = 0; i < RMC_BUCKETS; i++)
  152. INIT_HLIST_HEAD(&sdata->u.mesh.rmc->bucket[i]);
  153. return 0;
  154. }
  155. void mesh_rmc_free(struct ieee80211_sub_if_data *sdata)
  156. {
  157. struct mesh_rmc *rmc = sdata->u.mesh.rmc;
  158. struct rmc_entry *p;
  159. struct hlist_node *n;
  160. int i;
  161. if (!sdata->u.mesh.rmc)
  162. return;
  163. for (i = 0; i < RMC_BUCKETS; i++) {
  164. hlist_for_each_entry_safe(p, n, &rmc->bucket[i], list) {
  165. hlist_del(&p->list);
  166. kmem_cache_free(rm_cache, p);
  167. }
  168. }
  169. kfree(rmc);
  170. sdata->u.mesh.rmc = NULL;
  171. }
  172. /**
  173. * mesh_rmc_check - Check frame in recent multicast cache and add if absent.
  174. *
  175. * @sdata: interface
  176. * @sa: source address
  177. * @mesh_hdr: mesh_header
  178. *
  179. * Returns: 0 if the frame is not in the cache, nonzero otherwise.
  180. *
  181. * Checks using the source address and the mesh sequence number if we have
  182. * received this frame lately. If the frame is not in the cache, it is added to
  183. * it.
  184. */
  185. int mesh_rmc_check(struct ieee80211_sub_if_data *sdata,
  186. const u8 *sa, struct ieee80211s_hdr *mesh_hdr)
  187. {
  188. struct mesh_rmc *rmc = sdata->u.mesh.rmc;
  189. u32 seqnum = 0;
  190. int entries = 0;
  191. u8 idx;
  192. struct rmc_entry *p;
  193. struct hlist_node *n;
  194. if (!rmc)
  195. return -1;
  196. /* Don't care about endianness since only match matters */
  197. memcpy(&seqnum, &mesh_hdr->seqnum, sizeof(mesh_hdr->seqnum));
  198. idx = le32_to_cpu(mesh_hdr->seqnum) & rmc->idx_mask;
  199. hlist_for_each_entry_safe(p, n, &rmc->bucket[idx], list) {
  200. ++entries;
  201. if (time_after(jiffies, p->exp_time) ||
  202. entries == RMC_QUEUE_MAX_LEN) {
  203. hlist_del(&p->list);
  204. kmem_cache_free(rm_cache, p);
  205. --entries;
  206. } else if ((seqnum == p->seqnum) && ether_addr_equal(sa, p->sa))
  207. return -1;
  208. }
  209. p = kmem_cache_alloc(rm_cache, GFP_ATOMIC);
  210. if (!p)
  211. return 0;
  212. p->seqnum = seqnum;
  213. p->exp_time = jiffies + RMC_TIMEOUT;
  214. memcpy(p->sa, sa, ETH_ALEN);
  215. hlist_add_head(&p->list, &rmc->bucket[idx]);
  216. return 0;
  217. }
  218. int mesh_add_meshconf_ie(struct ieee80211_sub_if_data *sdata,
  219. struct sk_buff *skb)
  220. {
  221. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  222. u8 *pos, neighbors;
  223. u8 meshconf_len = sizeof(struct ieee80211_meshconf_ie);
  224. bool is_connected_to_gate = ifmsh->num_gates > 0 ||
  225. ifmsh->mshcfg.dot11MeshGateAnnouncementProtocol ||
  226. ifmsh->mshcfg.dot11MeshConnectedToMeshGate;
  227. bool is_connected_to_as = ifmsh->mshcfg.dot11MeshConnectedToAuthServer;
  228. if (skb_tailroom(skb) < 2 + meshconf_len)
  229. return -ENOMEM;
  230. pos = skb_put(skb, 2 + meshconf_len);
  231. *pos++ = WLAN_EID_MESH_CONFIG;
  232. *pos++ = meshconf_len;
  233. /* save a pointer for quick updates in pre-tbtt */
  234. ifmsh->meshconf_offset = pos - skb->data;
  235. /* Active path selection protocol ID */
  236. *pos++ = ifmsh->mesh_pp_id;
  237. /* Active path selection metric ID */
  238. *pos++ = ifmsh->mesh_pm_id;
  239. /* Congestion control mode identifier */
  240. *pos++ = ifmsh->mesh_cc_id;
  241. /* Synchronization protocol identifier */
  242. *pos++ = ifmsh->mesh_sp_id;
  243. /* Authentication Protocol identifier */
  244. *pos++ = ifmsh->mesh_auth_id;
  245. /* Mesh Formation Info - number of neighbors */
  246. neighbors = atomic_read(&ifmsh->estab_plinks);
  247. neighbors = min_t(int, neighbors, IEEE80211_MAX_MESH_PEERINGS);
  248. *pos++ = (is_connected_to_as << 7) |
  249. (neighbors << 1) |
  250. is_connected_to_gate;
  251. /* Mesh capability */
  252. *pos = 0x00;
  253. *pos |= ifmsh->mshcfg.dot11MeshForwarding ?
  254. IEEE80211_MESHCONF_CAPAB_FORWARDING : 0x00;
  255. *pos |= ifmsh->accepting_plinks ?
  256. IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS : 0x00;
  257. /* Mesh PS mode. See IEEE802.11-2012 8.4.2.100.8 */
  258. *pos |= ifmsh->ps_peers_deep_sleep ?
  259. IEEE80211_MESHCONF_CAPAB_POWER_SAVE_LEVEL : 0x00;
  260. return 0;
  261. }
  262. int mesh_add_meshid_ie(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
  263. {
  264. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  265. u8 *pos;
  266. if (skb_tailroom(skb) < 2 + ifmsh->mesh_id_len)
  267. return -ENOMEM;
  268. pos = skb_put(skb, 2 + ifmsh->mesh_id_len);
  269. *pos++ = WLAN_EID_MESH_ID;
  270. *pos++ = ifmsh->mesh_id_len;
  271. if (ifmsh->mesh_id_len)
  272. memcpy(pos, ifmsh->mesh_id, ifmsh->mesh_id_len);
  273. return 0;
  274. }
  275. static int mesh_add_awake_window_ie(struct ieee80211_sub_if_data *sdata,
  276. struct sk_buff *skb)
  277. {
  278. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  279. u8 *pos;
  280. /* see IEEE802.11-2012 13.14.6 */
  281. if (ifmsh->ps_peers_light_sleep == 0 &&
  282. ifmsh->ps_peers_deep_sleep == 0 &&
  283. ifmsh->nonpeer_pm == NL80211_MESH_POWER_ACTIVE)
  284. return 0;
  285. if (skb_tailroom(skb) < 4)
  286. return -ENOMEM;
  287. pos = skb_put(skb, 2 + 2);
  288. *pos++ = WLAN_EID_MESH_AWAKE_WINDOW;
  289. *pos++ = 2;
  290. put_unaligned_le16(ifmsh->mshcfg.dot11MeshAwakeWindowDuration, pos);
  291. return 0;
  292. }
  293. int mesh_add_vendor_ies(struct ieee80211_sub_if_data *sdata,
  294. struct sk_buff *skb)
  295. {
  296. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  297. u8 offset, len;
  298. const u8 *data;
  299. if (!ifmsh->ie || !ifmsh->ie_len)
  300. return 0;
  301. /* fast-forward to vendor IEs */
  302. offset = ieee80211_ie_split_vendor(ifmsh->ie, ifmsh->ie_len, 0);
  303. if (offset < ifmsh->ie_len) {
  304. len = ifmsh->ie_len - offset;
  305. data = ifmsh->ie + offset;
  306. if (skb_tailroom(skb) < len)
  307. return -ENOMEM;
  308. skb_put_data(skb, data, len);
  309. }
  310. return 0;
  311. }
  312. int mesh_add_rsn_ie(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
  313. {
  314. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  315. u8 len = 0;
  316. const u8 *data;
  317. if (!ifmsh->ie || !ifmsh->ie_len)
  318. return 0;
  319. /* find RSN IE */
  320. data = cfg80211_find_ie(WLAN_EID_RSN, ifmsh->ie, ifmsh->ie_len);
  321. if (!data)
  322. return 0;
  323. len = data[1] + 2;
  324. if (skb_tailroom(skb) < len)
  325. return -ENOMEM;
  326. skb_put_data(skb, data, len);
  327. return 0;
  328. }
  329. static int mesh_add_ds_params_ie(struct ieee80211_sub_if_data *sdata,
  330. struct sk_buff *skb)
  331. {
  332. struct ieee80211_chanctx_conf *chanctx_conf;
  333. struct ieee80211_channel *chan;
  334. u8 *pos;
  335. if (skb_tailroom(skb) < 3)
  336. return -ENOMEM;
  337. rcu_read_lock();
  338. chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
  339. if (WARN_ON(!chanctx_conf)) {
  340. rcu_read_unlock();
  341. return -EINVAL;
  342. }
  343. chan = chanctx_conf->def.chan;
  344. rcu_read_unlock();
  345. pos = skb_put(skb, 2 + 1);
  346. *pos++ = WLAN_EID_DS_PARAMS;
  347. *pos++ = 1;
  348. *pos++ = ieee80211_frequency_to_channel(chan->center_freq);
  349. return 0;
  350. }
  351. int mesh_add_ht_cap_ie(struct ieee80211_sub_if_data *sdata,
  352. struct sk_buff *skb)
  353. {
  354. struct ieee80211_supported_band *sband;
  355. u8 *pos;
  356. sband = ieee80211_get_sband(sdata);
  357. if (!sband)
  358. return -EINVAL;
  359. /* HT not allowed in 6 GHz */
  360. if (sband->band == NL80211_BAND_6GHZ)
  361. return 0;
  362. if (!sband->ht_cap.ht_supported ||
  363. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT ||
  364. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 ||
  365. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10)
  366. return 0;
  367. if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_cap))
  368. return -ENOMEM;
  369. pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_cap));
  370. ieee80211_ie_build_ht_cap(pos, &sband->ht_cap, sband->ht_cap.cap);
  371. return 0;
  372. }
  373. int mesh_add_ht_oper_ie(struct ieee80211_sub_if_data *sdata,
  374. struct sk_buff *skb)
  375. {
  376. struct ieee80211_local *local = sdata->local;
  377. struct ieee80211_chanctx_conf *chanctx_conf;
  378. struct ieee80211_channel *channel;
  379. struct ieee80211_supported_band *sband;
  380. struct ieee80211_sta_ht_cap *ht_cap;
  381. u8 *pos;
  382. rcu_read_lock();
  383. chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
  384. if (WARN_ON(!chanctx_conf)) {
  385. rcu_read_unlock();
  386. return -EINVAL;
  387. }
  388. channel = chanctx_conf->def.chan;
  389. rcu_read_unlock();
  390. sband = local->hw.wiphy->bands[channel->band];
  391. ht_cap = &sband->ht_cap;
  392. /* HT not allowed in 6 GHz */
  393. if (sband->band == NL80211_BAND_6GHZ)
  394. return 0;
  395. if (!ht_cap->ht_supported ||
  396. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT ||
  397. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 ||
  398. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10)
  399. return 0;
  400. if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_operation))
  401. return -ENOMEM;
  402. pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_operation));
  403. ieee80211_ie_build_ht_oper(pos, ht_cap, &sdata->vif.bss_conf.chandef,
  404. sdata->vif.bss_conf.ht_operation_mode,
  405. false);
  406. return 0;
  407. }
  408. int mesh_add_vht_cap_ie(struct ieee80211_sub_if_data *sdata,
  409. struct sk_buff *skb)
  410. {
  411. struct ieee80211_supported_band *sband;
  412. u8 *pos;
  413. sband = ieee80211_get_sband(sdata);
  414. if (!sband)
  415. return -EINVAL;
  416. /* VHT not allowed in 6 GHz */
  417. if (sband->band == NL80211_BAND_6GHZ)
  418. return 0;
  419. if (!sband->vht_cap.vht_supported ||
  420. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT ||
  421. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 ||
  422. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10)
  423. return 0;
  424. if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_vht_cap))
  425. return -ENOMEM;
  426. pos = skb_put(skb, 2 + sizeof(struct ieee80211_vht_cap));
  427. ieee80211_ie_build_vht_cap(pos, &sband->vht_cap, sband->vht_cap.cap);
  428. return 0;
  429. }
  430. int mesh_add_vht_oper_ie(struct ieee80211_sub_if_data *sdata,
  431. struct sk_buff *skb)
  432. {
  433. struct ieee80211_local *local = sdata->local;
  434. struct ieee80211_chanctx_conf *chanctx_conf;
  435. struct ieee80211_channel *channel;
  436. struct ieee80211_supported_band *sband;
  437. struct ieee80211_sta_vht_cap *vht_cap;
  438. u8 *pos;
  439. rcu_read_lock();
  440. chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
  441. if (WARN_ON(!chanctx_conf)) {
  442. rcu_read_unlock();
  443. return -EINVAL;
  444. }
  445. channel = chanctx_conf->def.chan;
  446. rcu_read_unlock();
  447. sband = local->hw.wiphy->bands[channel->band];
  448. vht_cap = &sband->vht_cap;
  449. /* VHT not allowed in 6 GHz */
  450. if (sband->band == NL80211_BAND_6GHZ)
  451. return 0;
  452. if (!vht_cap->vht_supported ||
  453. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT ||
  454. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 ||
  455. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10)
  456. return 0;
  457. if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_vht_operation))
  458. return -ENOMEM;
  459. pos = skb_put(skb, 2 + sizeof(struct ieee80211_vht_operation));
  460. ieee80211_ie_build_vht_oper(pos, vht_cap,
  461. &sdata->vif.bss_conf.chandef);
  462. return 0;
  463. }
  464. int mesh_add_he_cap_ie(struct ieee80211_sub_if_data *sdata,
  465. struct sk_buff *skb, u8 ie_len)
  466. {
  467. const struct ieee80211_sta_he_cap *he_cap;
  468. struct ieee80211_supported_band *sband;
  469. u8 *pos;
  470. sband = ieee80211_get_sband(sdata);
  471. if (!sband)
  472. return -EINVAL;
  473. he_cap = ieee80211_get_he_iftype_cap(sband, NL80211_IFTYPE_MESH_POINT);
  474. if (!he_cap ||
  475. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT ||
  476. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 ||
  477. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10)
  478. return 0;
  479. if (skb_tailroom(skb) < ie_len)
  480. return -ENOMEM;
  481. pos = skb_put(skb, ie_len);
  482. ieee80211_ie_build_he_cap(0, pos, he_cap, pos + ie_len);
  483. return 0;
  484. }
  485. int mesh_add_he_oper_ie(struct ieee80211_sub_if_data *sdata,
  486. struct sk_buff *skb)
  487. {
  488. const struct ieee80211_sta_he_cap *he_cap;
  489. struct ieee80211_supported_band *sband;
  490. u32 len;
  491. u8 *pos;
  492. sband = ieee80211_get_sband(sdata);
  493. if (!sband)
  494. return -EINVAL;
  495. he_cap = ieee80211_get_he_iftype_cap(sband, NL80211_IFTYPE_MESH_POINT);
  496. if (!he_cap ||
  497. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT ||
  498. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 ||
  499. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10)
  500. return 0;
  501. len = 2 + 1 + sizeof(struct ieee80211_he_operation);
  502. if (sdata->vif.bss_conf.chandef.chan->band == NL80211_BAND_6GHZ)
  503. len += sizeof(struct ieee80211_he_6ghz_oper);
  504. if (skb_tailroom(skb) < len)
  505. return -ENOMEM;
  506. pos = skb_put(skb, len);
  507. ieee80211_ie_build_he_oper(pos, &sdata->vif.bss_conf.chandef);
  508. return 0;
  509. }
  510. int mesh_add_he_6ghz_cap_ie(struct ieee80211_sub_if_data *sdata,
  511. struct sk_buff *skb)
  512. {
  513. struct ieee80211_supported_band *sband;
  514. const struct ieee80211_sband_iftype_data *iftd;
  515. sband = ieee80211_get_sband(sdata);
  516. if (!sband)
  517. return -EINVAL;
  518. iftd = ieee80211_get_sband_iftype_data(sband,
  519. NL80211_IFTYPE_MESH_POINT);
  520. /* The device doesn't support HE in mesh mode or at all */
  521. if (!iftd)
  522. return 0;
  523. ieee80211_ie_build_he_6ghz_cap(sdata, sdata->deflink.smps_mode, skb);
  524. return 0;
  525. }
  526. static void ieee80211_mesh_path_timer(struct timer_list *t)
  527. {
  528. struct ieee80211_sub_if_data *sdata =
  529. from_timer(sdata, t, u.mesh.mesh_path_timer);
  530. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  531. }
  532. static void ieee80211_mesh_path_root_timer(struct timer_list *t)
  533. {
  534. struct ieee80211_sub_if_data *sdata =
  535. from_timer(sdata, t, u.mesh.mesh_path_root_timer);
  536. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  537. set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
  538. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  539. }
  540. void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh)
  541. {
  542. if (ifmsh->mshcfg.dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)
  543. set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
  544. else {
  545. clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
  546. /* stop running timer */
  547. del_timer_sync(&ifmsh->mesh_path_root_timer);
  548. }
  549. }
  550. static void
  551. ieee80211_mesh_update_bss_params(struct ieee80211_sub_if_data *sdata,
  552. u8 *ie, u8 ie_len)
  553. {
  554. struct ieee80211_supported_band *sband;
  555. const struct element *cap;
  556. const struct ieee80211_he_operation *he_oper = NULL;
  557. sband = ieee80211_get_sband(sdata);
  558. if (!sband)
  559. return;
  560. if (!ieee80211_get_he_iftype_cap(sband, NL80211_IFTYPE_MESH_POINT) ||
  561. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT ||
  562. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 ||
  563. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10)
  564. return;
  565. sdata->vif.bss_conf.he_support = true;
  566. cap = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_OPERATION, ie, ie_len);
  567. if (cap && cap->datalen >= 1 + sizeof(*he_oper) &&
  568. cap->datalen >= 1 + ieee80211_he_oper_size(cap->data + 1))
  569. he_oper = (void *)(cap->data + 1);
  570. if (he_oper)
  571. sdata->vif.bss_conf.he_oper.params =
  572. __le32_to_cpu(he_oper->he_oper_params);
  573. }
  574. /**
  575. * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame
  576. * @hdr: 802.11 frame header
  577. * @fc: frame control field
  578. * @meshda: destination address in the mesh
  579. * @meshsa: source address in the mesh. Same as TA, as frame is
  580. * locally originated.
  581. *
  582. * Return the length of the 802.11 (does not include a mesh control header)
  583. */
  584. int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc,
  585. const u8 *meshda, const u8 *meshsa)
  586. {
  587. if (is_multicast_ether_addr(meshda)) {
  588. *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
  589. /* DA TA SA */
  590. memcpy(hdr->addr1, meshda, ETH_ALEN);
  591. memcpy(hdr->addr2, meshsa, ETH_ALEN);
  592. memcpy(hdr->addr3, meshsa, ETH_ALEN);
  593. return 24;
  594. } else {
  595. *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
  596. /* RA TA DA SA */
  597. eth_zero_addr(hdr->addr1); /* RA is resolved later */
  598. memcpy(hdr->addr2, meshsa, ETH_ALEN);
  599. memcpy(hdr->addr3, meshda, ETH_ALEN);
  600. memcpy(hdr->addr4, meshsa, ETH_ALEN);
  601. return 30;
  602. }
  603. }
  604. /**
  605. * ieee80211_new_mesh_header - create a new mesh header
  606. * @sdata: mesh interface to be used
  607. * @meshhdr: uninitialized mesh header
  608. * @addr4or5: 1st address in the ae header, which may correspond to address 4
  609. * (if addr6 is NULL) or address 5 (if addr6 is present). It may
  610. * be NULL.
  611. * @addr6: 2nd address in the ae header, which corresponds to addr6 of the
  612. * mesh frame
  613. *
  614. * Return the header length.
  615. */
  616. unsigned int ieee80211_new_mesh_header(struct ieee80211_sub_if_data *sdata,
  617. struct ieee80211s_hdr *meshhdr,
  618. const char *addr4or5, const char *addr6)
  619. {
  620. if (WARN_ON(!addr4or5 && addr6))
  621. return 0;
  622. memset(meshhdr, 0, sizeof(*meshhdr));
  623. meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
  624. /* FIXME: racy -- TX on multiple queues can be concurrent */
  625. put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum);
  626. sdata->u.mesh.mesh_seqnum++;
  627. if (addr4or5 && !addr6) {
  628. meshhdr->flags |= MESH_FLAGS_AE_A4;
  629. memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN);
  630. return 2 * ETH_ALEN;
  631. } else if (addr4or5 && addr6) {
  632. meshhdr->flags |= MESH_FLAGS_AE_A5_A6;
  633. memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN);
  634. memcpy(meshhdr->eaddr2, addr6, ETH_ALEN);
  635. return 3 * ETH_ALEN;
  636. }
  637. return ETH_ALEN;
  638. }
  639. static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata)
  640. {
  641. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  642. u32 changed;
  643. if (ifmsh->mshcfg.plink_timeout > 0)
  644. ieee80211_sta_expire(sdata, ifmsh->mshcfg.plink_timeout * HZ);
  645. mesh_path_expire(sdata);
  646. changed = mesh_accept_plinks_update(sdata);
  647. ieee80211_mbss_info_change_notify(sdata, changed);
  648. mod_timer(&ifmsh->housekeeping_timer,
  649. round_jiffies(jiffies +
  650. IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
  651. }
  652. static void ieee80211_mesh_rootpath(struct ieee80211_sub_if_data *sdata)
  653. {
  654. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  655. u32 interval;
  656. mesh_path_tx_root_frame(sdata);
  657. if (ifmsh->mshcfg.dot11MeshHWMPRootMode == IEEE80211_PROACTIVE_RANN)
  658. interval = ifmsh->mshcfg.dot11MeshHWMPRannInterval;
  659. else
  660. interval = ifmsh->mshcfg.dot11MeshHWMProotInterval;
  661. mod_timer(&ifmsh->mesh_path_root_timer,
  662. round_jiffies(TU_TO_EXP_TIME(interval)));
  663. }
  664. static int
  665. ieee80211_mesh_build_beacon(struct ieee80211_if_mesh *ifmsh)
  666. {
  667. struct beacon_data *bcn;
  668. int head_len, tail_len;
  669. struct sk_buff *skb;
  670. struct ieee80211_mgmt *mgmt;
  671. struct ieee80211_chanctx_conf *chanctx_conf;
  672. struct mesh_csa_settings *csa;
  673. enum nl80211_band band;
  674. u8 ie_len_he_cap;
  675. u8 *pos;
  676. struct ieee80211_sub_if_data *sdata;
  677. int hdr_len = offsetofend(struct ieee80211_mgmt, u.beacon);
  678. sdata = container_of(ifmsh, struct ieee80211_sub_if_data, u.mesh);
  679. rcu_read_lock();
  680. chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
  681. band = chanctx_conf->def.chan->band;
  682. rcu_read_unlock();
  683. ie_len_he_cap = ieee80211_ie_len_he_cap(sdata,
  684. NL80211_IFTYPE_MESH_POINT);
  685. head_len = hdr_len +
  686. 2 + /* NULL SSID */
  687. /* Channel Switch Announcement */
  688. 2 + sizeof(struct ieee80211_channel_sw_ie) +
  689. /* Mesh Channel Switch Parameters */
  690. 2 + sizeof(struct ieee80211_mesh_chansw_params_ie) +
  691. /* Channel Switch Wrapper + Wide Bandwidth CSA IE */
  692. 2 + 2 + sizeof(struct ieee80211_wide_bw_chansw_ie) +
  693. 2 + sizeof(struct ieee80211_sec_chan_offs_ie) +
  694. 2 + 8 + /* supported rates */
  695. 2 + 3; /* DS params */
  696. tail_len = 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
  697. 2 + sizeof(struct ieee80211_ht_cap) +
  698. 2 + sizeof(struct ieee80211_ht_operation) +
  699. 2 + ifmsh->mesh_id_len +
  700. 2 + sizeof(struct ieee80211_meshconf_ie) +
  701. 2 + sizeof(__le16) + /* awake window */
  702. 2 + sizeof(struct ieee80211_vht_cap) +
  703. 2 + sizeof(struct ieee80211_vht_operation) +
  704. ie_len_he_cap +
  705. 2 + 1 + sizeof(struct ieee80211_he_operation) +
  706. sizeof(struct ieee80211_he_6ghz_oper) +
  707. 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa) +
  708. ifmsh->ie_len;
  709. bcn = kzalloc(sizeof(*bcn) + head_len + tail_len, GFP_KERNEL);
  710. /* need an skb for IE builders to operate on */
  711. skb = __dev_alloc_skb(max(head_len, tail_len), GFP_KERNEL);
  712. if (!bcn || !skb)
  713. goto out_free;
  714. /*
  715. * pointers go into the block we allocated,
  716. * memory is | beacon_data | head | tail |
  717. */
  718. bcn->head = ((u8 *) bcn) + sizeof(*bcn);
  719. /* fill in the head */
  720. mgmt = skb_put_zero(skb, hdr_len);
  721. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  722. IEEE80211_STYPE_BEACON);
  723. eth_broadcast_addr(mgmt->da);
  724. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  725. memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
  726. ieee80211_mps_set_frame_flags(sdata, NULL, (void *) mgmt);
  727. mgmt->u.beacon.beacon_int =
  728. cpu_to_le16(sdata->vif.bss_conf.beacon_int);
  729. mgmt->u.beacon.capab_info |= cpu_to_le16(
  730. sdata->u.mesh.security ? WLAN_CAPABILITY_PRIVACY : 0);
  731. pos = skb_put(skb, 2);
  732. *pos++ = WLAN_EID_SSID;
  733. *pos++ = 0x0;
  734. rcu_read_lock();
  735. csa = rcu_dereference(ifmsh->csa);
  736. if (csa) {
  737. enum nl80211_channel_type ct;
  738. struct cfg80211_chan_def *chandef;
  739. int ie_len = 2 + sizeof(struct ieee80211_channel_sw_ie) +
  740. 2 + sizeof(struct ieee80211_mesh_chansw_params_ie);
  741. pos = skb_put_zero(skb, ie_len);
  742. *pos++ = WLAN_EID_CHANNEL_SWITCH;
  743. *pos++ = 3;
  744. *pos++ = 0x0;
  745. *pos++ = ieee80211_frequency_to_channel(
  746. csa->settings.chandef.chan->center_freq);
  747. bcn->cntdwn_current_counter = csa->settings.count;
  748. bcn->cntdwn_counter_offsets[0] = hdr_len + 6;
  749. *pos++ = csa->settings.count;
  750. *pos++ = WLAN_EID_CHAN_SWITCH_PARAM;
  751. *pos++ = 6;
  752. if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT) {
  753. *pos++ = ifmsh->mshcfg.dot11MeshTTL;
  754. *pos |= WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR;
  755. } else {
  756. *pos++ = ifmsh->chsw_ttl;
  757. }
  758. *pos++ |= csa->settings.block_tx ?
  759. WLAN_EID_CHAN_SWITCH_PARAM_TX_RESTRICT : 0x00;
  760. put_unaligned_le16(WLAN_REASON_MESH_CHAN, pos);
  761. pos += 2;
  762. put_unaligned_le16(ifmsh->pre_value, pos);
  763. pos += 2;
  764. switch (csa->settings.chandef.width) {
  765. case NL80211_CHAN_WIDTH_40:
  766. ie_len = 2 + sizeof(struct ieee80211_sec_chan_offs_ie);
  767. pos = skb_put_zero(skb, ie_len);
  768. *pos++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET; /* EID */
  769. *pos++ = 1; /* len */
  770. ct = cfg80211_get_chandef_type(&csa->settings.chandef);
  771. if (ct == NL80211_CHAN_HT40PLUS)
  772. *pos++ = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  773. else
  774. *pos++ = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  775. break;
  776. case NL80211_CHAN_WIDTH_80:
  777. case NL80211_CHAN_WIDTH_80P80:
  778. case NL80211_CHAN_WIDTH_160:
  779. /* Channel Switch Wrapper + Wide Bandwidth CSA IE */
  780. ie_len = 2 + 2 +
  781. sizeof(struct ieee80211_wide_bw_chansw_ie);
  782. pos = skb_put_zero(skb, ie_len);
  783. *pos++ = WLAN_EID_CHANNEL_SWITCH_WRAPPER; /* EID */
  784. *pos++ = 5; /* len */
  785. /* put sub IE */
  786. chandef = &csa->settings.chandef;
  787. ieee80211_ie_build_wide_bw_cs(pos, chandef);
  788. break;
  789. default:
  790. break;
  791. }
  792. }
  793. rcu_read_unlock();
  794. if (ieee80211_add_srates_ie(sdata, skb, true, band) ||
  795. mesh_add_ds_params_ie(sdata, skb))
  796. goto out_free;
  797. bcn->head_len = skb->len;
  798. memcpy(bcn->head, skb->data, bcn->head_len);
  799. /* now the tail */
  800. skb_trim(skb, 0);
  801. bcn->tail = bcn->head + bcn->head_len;
  802. if (ieee80211_add_ext_srates_ie(sdata, skb, true, band) ||
  803. mesh_add_rsn_ie(sdata, skb) ||
  804. mesh_add_ht_cap_ie(sdata, skb) ||
  805. mesh_add_ht_oper_ie(sdata, skb) ||
  806. mesh_add_meshid_ie(sdata, skb) ||
  807. mesh_add_meshconf_ie(sdata, skb) ||
  808. mesh_add_awake_window_ie(sdata, skb) ||
  809. mesh_add_vht_cap_ie(sdata, skb) ||
  810. mesh_add_vht_oper_ie(sdata, skb) ||
  811. mesh_add_he_cap_ie(sdata, skb, ie_len_he_cap) ||
  812. mesh_add_he_oper_ie(sdata, skb) ||
  813. mesh_add_he_6ghz_cap_ie(sdata, skb) ||
  814. mesh_add_vendor_ies(sdata, skb))
  815. goto out_free;
  816. bcn->tail_len = skb->len;
  817. memcpy(bcn->tail, skb->data, bcn->tail_len);
  818. ieee80211_mesh_update_bss_params(sdata, bcn->tail, bcn->tail_len);
  819. bcn->meshconf = (struct ieee80211_meshconf_ie *)
  820. (bcn->tail + ifmsh->meshconf_offset);
  821. dev_kfree_skb(skb);
  822. rcu_assign_pointer(ifmsh->beacon, bcn);
  823. return 0;
  824. out_free:
  825. kfree(bcn);
  826. dev_kfree_skb(skb);
  827. return -ENOMEM;
  828. }
  829. static int
  830. ieee80211_mesh_rebuild_beacon(struct ieee80211_sub_if_data *sdata)
  831. {
  832. struct beacon_data *old_bcn;
  833. int ret;
  834. old_bcn = sdata_dereference(sdata->u.mesh.beacon, sdata);
  835. ret = ieee80211_mesh_build_beacon(&sdata->u.mesh);
  836. if (ret)
  837. /* just reuse old beacon */
  838. return ret;
  839. if (old_bcn)
  840. kfree_rcu(old_bcn, rcu_head);
  841. return 0;
  842. }
  843. void ieee80211_mbss_info_change_notify(struct ieee80211_sub_if_data *sdata,
  844. u32 changed)
  845. {
  846. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  847. unsigned long bits = changed;
  848. u32 bit;
  849. if (!bits)
  850. return;
  851. /* if we race with running work, worst case this work becomes a noop */
  852. for_each_set_bit(bit, &bits, sizeof(changed) * BITS_PER_BYTE)
  853. set_bit(bit, &ifmsh->mbss_changed);
  854. set_bit(MESH_WORK_MBSS_CHANGED, &ifmsh->wrkq_flags);
  855. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  856. }
  857. int ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
  858. {
  859. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  860. struct ieee80211_local *local = sdata->local;
  861. u32 changed = BSS_CHANGED_BEACON |
  862. BSS_CHANGED_BEACON_ENABLED |
  863. BSS_CHANGED_HT |
  864. BSS_CHANGED_BASIC_RATES |
  865. BSS_CHANGED_BEACON_INT |
  866. BSS_CHANGED_MCAST_RATE;
  867. local->fif_other_bss++;
  868. /* mesh ifaces must set allmulti to forward mcast traffic */
  869. atomic_inc(&local->iff_allmultis);
  870. ieee80211_configure_filter(local);
  871. ifmsh->mesh_cc_id = 0; /* Disabled */
  872. /* register sync ops from extensible synchronization framework */
  873. ifmsh->sync_ops = ieee80211_mesh_sync_ops_get(ifmsh->mesh_sp_id);
  874. ifmsh->sync_offset_clockdrift_max = 0;
  875. set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
  876. ieee80211_mesh_root_setup(ifmsh);
  877. ieee80211_queue_work(&local->hw, &sdata->work);
  878. sdata->vif.bss_conf.ht_operation_mode =
  879. ifmsh->mshcfg.ht_opmode;
  880. sdata->vif.bss_conf.enable_beacon = true;
  881. changed |= ieee80211_mps_local_status_update(sdata);
  882. if (ieee80211_mesh_build_beacon(ifmsh)) {
  883. ieee80211_stop_mesh(sdata);
  884. return -ENOMEM;
  885. }
  886. ieee80211_recalc_dtim(local, sdata);
  887. ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed);
  888. netif_carrier_on(sdata->dev);
  889. return 0;
  890. }
  891. void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
  892. {
  893. struct ieee80211_local *local = sdata->local;
  894. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  895. struct beacon_data *bcn;
  896. netif_carrier_off(sdata->dev);
  897. /* flush STAs and mpaths on this iface */
  898. sta_info_flush(sdata);
  899. ieee80211_free_keys(sdata, true);
  900. mesh_path_flush_by_iface(sdata);
  901. /* stop the beacon */
  902. ifmsh->mesh_id_len = 0;
  903. sdata->vif.bss_conf.enable_beacon = false;
  904. sdata->beacon_rate_set = false;
  905. clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
  906. ieee80211_link_info_change_notify(sdata, &sdata->deflink,
  907. BSS_CHANGED_BEACON_ENABLED);
  908. /* remove beacon */
  909. bcn = sdata_dereference(ifmsh->beacon, sdata);
  910. RCU_INIT_POINTER(ifmsh->beacon, NULL);
  911. kfree_rcu(bcn, rcu_head);
  912. /* free all potentially still buffered group-addressed frames */
  913. local->total_ps_buffered -= skb_queue_len(&ifmsh->ps.bc_buf);
  914. skb_queue_purge(&ifmsh->ps.bc_buf);
  915. del_timer_sync(&sdata->u.mesh.housekeeping_timer);
  916. del_timer_sync(&sdata->u.mesh.mesh_path_root_timer);
  917. del_timer_sync(&sdata->u.mesh.mesh_path_timer);
  918. /* clear any mesh work (for next join) we may have accrued */
  919. ifmsh->wrkq_flags = 0;
  920. ifmsh->mbss_changed = 0;
  921. local->fif_other_bss--;
  922. atomic_dec(&local->iff_allmultis);
  923. ieee80211_configure_filter(local);
  924. }
  925. static void ieee80211_mesh_csa_mark_radar(struct ieee80211_sub_if_data *sdata)
  926. {
  927. int err;
  928. /* if the current channel is a DFS channel, mark the channel as
  929. * unavailable.
  930. */
  931. err = cfg80211_chandef_dfs_required(sdata->local->hw.wiphy,
  932. &sdata->vif.bss_conf.chandef,
  933. NL80211_IFTYPE_MESH_POINT);
  934. if (err > 0)
  935. cfg80211_radar_event(sdata->local->hw.wiphy,
  936. &sdata->vif.bss_conf.chandef, GFP_ATOMIC);
  937. }
  938. static bool
  939. ieee80211_mesh_process_chnswitch(struct ieee80211_sub_if_data *sdata,
  940. struct ieee802_11_elems *elems, bool beacon)
  941. {
  942. struct cfg80211_csa_settings params;
  943. struct ieee80211_csa_ie csa_ie;
  944. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  945. struct ieee80211_supported_band *sband;
  946. int err;
  947. ieee80211_conn_flags_t conn_flags = 0;
  948. u32 vht_cap_info = 0;
  949. sdata_assert_lock(sdata);
  950. sband = ieee80211_get_sband(sdata);
  951. if (!sband)
  952. return false;
  953. switch (sdata->vif.bss_conf.chandef.width) {
  954. case NL80211_CHAN_WIDTH_20_NOHT:
  955. conn_flags |= IEEE80211_CONN_DISABLE_HT;
  956. fallthrough;
  957. case NL80211_CHAN_WIDTH_20:
  958. conn_flags |= IEEE80211_CONN_DISABLE_40MHZ;
  959. fallthrough;
  960. case NL80211_CHAN_WIDTH_40:
  961. conn_flags |= IEEE80211_CONN_DISABLE_VHT;
  962. break;
  963. default:
  964. break;
  965. }
  966. if (elems->vht_cap_elem)
  967. vht_cap_info =
  968. le32_to_cpu(elems->vht_cap_elem->vht_cap_info);
  969. memset(&params, 0, sizeof(params));
  970. err = ieee80211_parse_ch_switch_ie(sdata, elems, sband->band,
  971. vht_cap_info,
  972. conn_flags, sdata->vif.addr,
  973. &csa_ie);
  974. if (err < 0)
  975. return false;
  976. if (err)
  977. return false;
  978. /* Mark the channel unavailable if the reason for the switch is
  979. * regulatory.
  980. */
  981. if (csa_ie.reason_code == WLAN_REASON_MESH_CHAN_REGULATORY)
  982. ieee80211_mesh_csa_mark_radar(sdata);
  983. params.chandef = csa_ie.chandef;
  984. params.count = csa_ie.count;
  985. if (!cfg80211_chandef_usable(sdata->local->hw.wiphy, &params.chandef,
  986. IEEE80211_CHAN_DISABLED) ||
  987. !cfg80211_reg_can_beacon(sdata->local->hw.wiphy, &params.chandef,
  988. NL80211_IFTYPE_MESH_POINT)) {
  989. sdata_info(sdata,
  990. "mesh STA %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), aborting\n",
  991. sdata->vif.addr,
  992. params.chandef.chan->center_freq,
  993. params.chandef.width,
  994. params.chandef.center_freq1,
  995. params.chandef.center_freq2);
  996. return false;
  997. }
  998. err = cfg80211_chandef_dfs_required(sdata->local->hw.wiphy,
  999. &params.chandef,
  1000. NL80211_IFTYPE_MESH_POINT);
  1001. if (err < 0)
  1002. return false;
  1003. if (err > 0 && !ifmsh->userspace_handles_dfs) {
  1004. sdata_info(sdata,
  1005. "mesh STA %pM switches to channel requiring DFS (%d MHz, width:%d, CF1/2: %d/%d MHz), aborting\n",
  1006. sdata->vif.addr,
  1007. params.chandef.chan->center_freq,
  1008. params.chandef.width,
  1009. params.chandef.center_freq1,
  1010. params.chandef.center_freq2);
  1011. return false;
  1012. }
  1013. params.radar_required = err;
  1014. if (cfg80211_chandef_identical(&params.chandef,
  1015. &sdata->vif.bss_conf.chandef)) {
  1016. mcsa_dbg(sdata,
  1017. "received csa with an identical chandef, ignoring\n");
  1018. return true;
  1019. }
  1020. mcsa_dbg(sdata,
  1021. "received channel switch announcement to go to channel %d MHz\n",
  1022. params.chandef.chan->center_freq);
  1023. params.block_tx = csa_ie.mode & WLAN_EID_CHAN_SWITCH_PARAM_TX_RESTRICT;
  1024. if (beacon) {
  1025. ifmsh->chsw_ttl = csa_ie.ttl - 1;
  1026. if (ifmsh->pre_value >= csa_ie.pre_value)
  1027. return false;
  1028. ifmsh->pre_value = csa_ie.pre_value;
  1029. }
  1030. if (ifmsh->chsw_ttl >= ifmsh->mshcfg.dot11MeshTTL)
  1031. return false;
  1032. ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_REPEATER;
  1033. if (ieee80211_channel_switch(sdata->local->hw.wiphy, sdata->dev,
  1034. &params) < 0)
  1035. return false;
  1036. return true;
  1037. }
  1038. static void
  1039. ieee80211_mesh_rx_probe_req(struct ieee80211_sub_if_data *sdata,
  1040. struct ieee80211_mgmt *mgmt, size_t len)
  1041. {
  1042. struct ieee80211_local *local = sdata->local;
  1043. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1044. struct sk_buff *presp;
  1045. struct beacon_data *bcn;
  1046. struct ieee80211_mgmt *hdr;
  1047. struct ieee802_11_elems *elems;
  1048. size_t baselen;
  1049. u8 *pos;
  1050. pos = mgmt->u.probe_req.variable;
  1051. baselen = (u8 *) pos - (u8 *) mgmt;
  1052. if (baselen > len)
  1053. return;
  1054. elems = ieee802_11_parse_elems(pos, len - baselen, false, NULL);
  1055. if (!elems)
  1056. return;
  1057. if (!elems->mesh_id)
  1058. goto free;
  1059. /* 802.11-2012 10.1.4.3.2 */
  1060. if ((!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
  1061. !is_broadcast_ether_addr(mgmt->da)) ||
  1062. elems->ssid_len != 0)
  1063. goto free;
  1064. if (elems->mesh_id_len != 0 &&
  1065. (elems->mesh_id_len != ifmsh->mesh_id_len ||
  1066. memcmp(elems->mesh_id, ifmsh->mesh_id, ifmsh->mesh_id_len)))
  1067. goto free;
  1068. rcu_read_lock();
  1069. bcn = rcu_dereference(ifmsh->beacon);
  1070. if (!bcn)
  1071. goto out;
  1072. presp = dev_alloc_skb(local->tx_headroom +
  1073. bcn->head_len + bcn->tail_len);
  1074. if (!presp)
  1075. goto out;
  1076. skb_reserve(presp, local->tx_headroom);
  1077. skb_put_data(presp, bcn->head, bcn->head_len);
  1078. skb_put_data(presp, bcn->tail, bcn->tail_len);
  1079. hdr = (struct ieee80211_mgmt *) presp->data;
  1080. hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1081. IEEE80211_STYPE_PROBE_RESP);
  1082. memcpy(hdr->da, mgmt->sa, ETH_ALEN);
  1083. IEEE80211_SKB_CB(presp)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  1084. ieee80211_tx_skb(sdata, presp);
  1085. out:
  1086. rcu_read_unlock();
  1087. free:
  1088. kfree(elems);
  1089. }
  1090. static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
  1091. u16 stype,
  1092. struct ieee80211_mgmt *mgmt,
  1093. size_t len,
  1094. struct ieee80211_rx_status *rx_status)
  1095. {
  1096. struct ieee80211_local *local = sdata->local;
  1097. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1098. struct ieee802_11_elems *elems;
  1099. struct ieee80211_channel *channel;
  1100. size_t baselen;
  1101. int freq;
  1102. enum nl80211_band band = rx_status->band;
  1103. /* ignore ProbeResp to foreign address */
  1104. if (stype == IEEE80211_STYPE_PROBE_RESP &&
  1105. !ether_addr_equal(mgmt->da, sdata->vif.addr))
  1106. return;
  1107. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  1108. if (baselen > len)
  1109. return;
  1110. elems = ieee802_11_parse_elems(mgmt->u.probe_resp.variable,
  1111. len - baselen,
  1112. false, NULL);
  1113. if (!elems)
  1114. return;
  1115. /* ignore non-mesh or secure / unsecure mismatch */
  1116. if ((!elems->mesh_id || !elems->mesh_config) ||
  1117. (elems->rsn && sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) ||
  1118. (!elems->rsn && sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE))
  1119. goto free;
  1120. if (elems->ds_params)
  1121. freq = ieee80211_channel_to_frequency(elems->ds_params[0], band);
  1122. else
  1123. freq = rx_status->freq;
  1124. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  1125. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  1126. goto free;
  1127. if (mesh_matches_local(sdata, elems)) {
  1128. mpl_dbg(sdata, "rssi_threshold=%d,rx_status->signal=%d\n",
  1129. sdata->u.mesh.mshcfg.rssi_threshold, rx_status->signal);
  1130. if (!sdata->u.mesh.user_mpm ||
  1131. sdata->u.mesh.mshcfg.rssi_threshold == 0 ||
  1132. sdata->u.mesh.mshcfg.rssi_threshold < rx_status->signal)
  1133. mesh_neighbour_update(sdata, mgmt->sa, elems,
  1134. rx_status);
  1135. if (ifmsh->csa_role != IEEE80211_MESH_CSA_ROLE_INIT &&
  1136. !sdata->vif.bss_conf.csa_active)
  1137. ieee80211_mesh_process_chnswitch(sdata, elems, true);
  1138. }
  1139. if (ifmsh->sync_ops)
  1140. ifmsh->sync_ops->rx_bcn_presp(sdata, stype, mgmt, len,
  1141. elems->mesh_config, rx_status);
  1142. free:
  1143. kfree(elems);
  1144. }
  1145. int ieee80211_mesh_finish_csa(struct ieee80211_sub_if_data *sdata)
  1146. {
  1147. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1148. struct mesh_csa_settings *tmp_csa_settings;
  1149. int ret = 0;
  1150. int changed = 0;
  1151. /* Reset the TTL value and Initiator flag */
  1152. ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
  1153. ifmsh->chsw_ttl = 0;
  1154. /* Remove the CSA and MCSP elements from the beacon */
  1155. tmp_csa_settings = sdata_dereference(ifmsh->csa, sdata);
  1156. RCU_INIT_POINTER(ifmsh->csa, NULL);
  1157. if (tmp_csa_settings)
  1158. kfree_rcu(tmp_csa_settings, rcu_head);
  1159. ret = ieee80211_mesh_rebuild_beacon(sdata);
  1160. if (ret)
  1161. return -EINVAL;
  1162. changed |= BSS_CHANGED_BEACON;
  1163. mcsa_dbg(sdata, "complete switching to center freq %d MHz",
  1164. sdata->vif.bss_conf.chandef.chan->center_freq);
  1165. return changed;
  1166. }
  1167. int ieee80211_mesh_csa_beacon(struct ieee80211_sub_if_data *sdata,
  1168. struct cfg80211_csa_settings *csa_settings)
  1169. {
  1170. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1171. struct mesh_csa_settings *tmp_csa_settings;
  1172. int ret = 0;
  1173. lockdep_assert_held(&sdata->wdev.mtx);
  1174. tmp_csa_settings = kmalloc(sizeof(*tmp_csa_settings),
  1175. GFP_ATOMIC);
  1176. if (!tmp_csa_settings)
  1177. return -ENOMEM;
  1178. memcpy(&tmp_csa_settings->settings, csa_settings,
  1179. sizeof(struct cfg80211_csa_settings));
  1180. rcu_assign_pointer(ifmsh->csa, tmp_csa_settings);
  1181. ret = ieee80211_mesh_rebuild_beacon(sdata);
  1182. if (ret) {
  1183. tmp_csa_settings = rcu_dereference(ifmsh->csa);
  1184. RCU_INIT_POINTER(ifmsh->csa, NULL);
  1185. kfree_rcu(tmp_csa_settings, rcu_head);
  1186. return ret;
  1187. }
  1188. return BSS_CHANGED_BEACON;
  1189. }
  1190. static int mesh_fwd_csa_frame(struct ieee80211_sub_if_data *sdata,
  1191. struct ieee80211_mgmt *mgmt, size_t len,
  1192. struct ieee802_11_elems *elems)
  1193. {
  1194. struct ieee80211_mgmt *mgmt_fwd;
  1195. struct sk_buff *skb;
  1196. struct ieee80211_local *local = sdata->local;
  1197. skb = dev_alloc_skb(local->tx_headroom + len);
  1198. if (!skb)
  1199. return -ENOMEM;
  1200. skb_reserve(skb, local->tx_headroom);
  1201. mgmt_fwd = skb_put(skb, len);
  1202. elems->mesh_chansw_params_ie->mesh_ttl--;
  1203. elems->mesh_chansw_params_ie->mesh_flags &=
  1204. ~WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR;
  1205. memcpy(mgmt_fwd, mgmt, len);
  1206. eth_broadcast_addr(mgmt_fwd->da);
  1207. memcpy(mgmt_fwd->sa, sdata->vif.addr, ETH_ALEN);
  1208. memcpy(mgmt_fwd->bssid, sdata->vif.addr, ETH_ALEN);
  1209. ieee80211_tx_skb(sdata, skb);
  1210. return 0;
  1211. }
  1212. static void mesh_rx_csa_frame(struct ieee80211_sub_if_data *sdata,
  1213. struct ieee80211_mgmt *mgmt, size_t len)
  1214. {
  1215. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1216. struct ieee802_11_elems *elems;
  1217. u16 pre_value;
  1218. bool fwd_csa = true;
  1219. size_t baselen;
  1220. u8 *pos;
  1221. if (mgmt->u.action.u.measurement.action_code !=
  1222. WLAN_ACTION_SPCT_CHL_SWITCH)
  1223. return;
  1224. pos = mgmt->u.action.u.chan_switch.variable;
  1225. baselen = offsetof(struct ieee80211_mgmt,
  1226. u.action.u.chan_switch.variable);
  1227. elems = ieee802_11_parse_elems(pos, len - baselen, true, NULL);
  1228. if (!elems)
  1229. return;
  1230. if (!mesh_matches_local(sdata, elems))
  1231. goto free;
  1232. ifmsh->chsw_ttl = elems->mesh_chansw_params_ie->mesh_ttl;
  1233. if (!--ifmsh->chsw_ttl)
  1234. fwd_csa = false;
  1235. pre_value = le16_to_cpu(elems->mesh_chansw_params_ie->mesh_pre_value);
  1236. if (ifmsh->pre_value >= pre_value)
  1237. goto free;
  1238. ifmsh->pre_value = pre_value;
  1239. if (!sdata->vif.bss_conf.csa_active &&
  1240. !ieee80211_mesh_process_chnswitch(sdata, elems, false)) {
  1241. mcsa_dbg(sdata, "Failed to process CSA action frame");
  1242. goto free;
  1243. }
  1244. /* forward or re-broadcast the CSA frame */
  1245. if (fwd_csa) {
  1246. if (mesh_fwd_csa_frame(sdata, mgmt, len, elems) < 0)
  1247. mcsa_dbg(sdata, "Failed to forward the CSA frame");
  1248. }
  1249. free:
  1250. kfree(elems);
  1251. }
  1252. static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
  1253. struct ieee80211_mgmt *mgmt,
  1254. size_t len,
  1255. struct ieee80211_rx_status *rx_status)
  1256. {
  1257. switch (mgmt->u.action.category) {
  1258. case WLAN_CATEGORY_SELF_PROTECTED:
  1259. switch (mgmt->u.action.u.self_prot.action_code) {
  1260. case WLAN_SP_MESH_PEERING_OPEN:
  1261. case WLAN_SP_MESH_PEERING_CLOSE:
  1262. case WLAN_SP_MESH_PEERING_CONFIRM:
  1263. mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
  1264. break;
  1265. }
  1266. break;
  1267. case WLAN_CATEGORY_MESH_ACTION:
  1268. if (mesh_action_is_path_sel(mgmt))
  1269. mesh_rx_path_sel_frame(sdata, mgmt, len);
  1270. break;
  1271. case WLAN_CATEGORY_SPECTRUM_MGMT:
  1272. mesh_rx_csa_frame(sdata, mgmt, len);
  1273. break;
  1274. }
  1275. }
  1276. void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  1277. struct sk_buff *skb)
  1278. {
  1279. struct ieee80211_rx_status *rx_status;
  1280. struct ieee80211_mgmt *mgmt;
  1281. u16 stype;
  1282. sdata_lock(sdata);
  1283. /* mesh already went down */
  1284. if (!sdata->u.mesh.mesh_id_len)
  1285. goto out;
  1286. rx_status = IEEE80211_SKB_RXCB(skb);
  1287. mgmt = (struct ieee80211_mgmt *) skb->data;
  1288. stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
  1289. switch (stype) {
  1290. case IEEE80211_STYPE_PROBE_RESP:
  1291. case IEEE80211_STYPE_BEACON:
  1292. ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len,
  1293. rx_status);
  1294. break;
  1295. case IEEE80211_STYPE_PROBE_REQ:
  1296. ieee80211_mesh_rx_probe_req(sdata, mgmt, skb->len);
  1297. break;
  1298. case IEEE80211_STYPE_ACTION:
  1299. ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status);
  1300. break;
  1301. }
  1302. out:
  1303. sdata_unlock(sdata);
  1304. }
  1305. static void mesh_bss_info_changed(struct ieee80211_sub_if_data *sdata)
  1306. {
  1307. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1308. u32 bit, changed = 0;
  1309. for_each_set_bit(bit, &ifmsh->mbss_changed,
  1310. sizeof(changed) * BITS_PER_BYTE) {
  1311. clear_bit(bit, &ifmsh->mbss_changed);
  1312. changed |= BIT(bit);
  1313. }
  1314. if (sdata->vif.bss_conf.enable_beacon &&
  1315. (changed & (BSS_CHANGED_BEACON |
  1316. BSS_CHANGED_HT |
  1317. BSS_CHANGED_BASIC_RATES |
  1318. BSS_CHANGED_BEACON_INT)))
  1319. if (ieee80211_mesh_rebuild_beacon(sdata))
  1320. return;
  1321. ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed);
  1322. }
  1323. void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata)
  1324. {
  1325. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1326. sdata_lock(sdata);
  1327. /* mesh already went down */
  1328. if (!sdata->u.mesh.mesh_id_len)
  1329. goto out;
  1330. if (ifmsh->preq_queue_len &&
  1331. time_after(jiffies,
  1332. ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval)))
  1333. mesh_path_start_discovery(sdata);
  1334. if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags))
  1335. ieee80211_mesh_housekeeping(sdata);
  1336. if (test_and_clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags))
  1337. ieee80211_mesh_rootpath(sdata);
  1338. if (test_and_clear_bit(MESH_WORK_DRIFT_ADJUST, &ifmsh->wrkq_flags))
  1339. mesh_sync_adjust_tsf(sdata);
  1340. if (test_and_clear_bit(MESH_WORK_MBSS_CHANGED, &ifmsh->wrkq_flags))
  1341. mesh_bss_info_changed(sdata);
  1342. out:
  1343. sdata_unlock(sdata);
  1344. }
  1345. void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
  1346. {
  1347. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1348. static u8 zero_addr[ETH_ALEN] = {};
  1349. timer_setup(&ifmsh->housekeeping_timer,
  1350. ieee80211_mesh_housekeeping_timer, 0);
  1351. ifmsh->accepting_plinks = true;
  1352. atomic_set(&ifmsh->mpaths, 0);
  1353. mesh_rmc_init(sdata);
  1354. ifmsh->last_preq = jiffies;
  1355. ifmsh->next_perr = jiffies;
  1356. ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
  1357. /* Allocate all mesh structures when creating the first mesh interface. */
  1358. if (!mesh_allocated)
  1359. ieee80211s_init();
  1360. mesh_pathtbl_init(sdata);
  1361. timer_setup(&ifmsh->mesh_path_timer, ieee80211_mesh_path_timer, 0);
  1362. timer_setup(&ifmsh->mesh_path_root_timer,
  1363. ieee80211_mesh_path_root_timer, 0);
  1364. INIT_LIST_HEAD(&ifmsh->preq_queue.list);
  1365. skb_queue_head_init(&ifmsh->ps.bc_buf);
  1366. spin_lock_init(&ifmsh->mesh_preq_queue_lock);
  1367. spin_lock_init(&ifmsh->sync_offset_lock);
  1368. RCU_INIT_POINTER(ifmsh->beacon, NULL);
  1369. sdata->vif.bss_conf.bssid = zero_addr;
  1370. }
  1371. void ieee80211_mesh_teardown_sdata(struct ieee80211_sub_if_data *sdata)
  1372. {
  1373. mesh_rmc_free(sdata);
  1374. mesh_pathtbl_unregister(sdata);
  1375. }