mesh.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159
  1. /*
  2. * Copyright (c) 2008, 2009 open80211s Ltd.
  3. * Authors: Luis Carlos Cobo <luisca@cozybit.com>
  4. * Javier Cardona <javier@cozybit.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/slab.h>
  11. #include <asm/unaligned.h>
  12. #include "ieee80211_i.h"
  13. #include "mesh.h"
  14. static int mesh_allocated;
  15. static struct kmem_cache *rm_cache;
  16. bool mesh_action_is_path_sel(struct ieee80211_mgmt *mgmt)
  17. {
  18. return (mgmt->u.action.u.mesh_action.action_code ==
  19. WLAN_MESH_ACTION_HWMP_PATH_SELECTION);
  20. }
  21. void ieee80211s_init(void)
  22. {
  23. mesh_pathtbl_init();
  24. mesh_allocated = 1;
  25. rm_cache = kmem_cache_create("mesh_rmc", sizeof(struct rmc_entry),
  26. 0, 0, NULL);
  27. }
  28. void ieee80211s_stop(void)
  29. {
  30. if (!mesh_allocated)
  31. return;
  32. mesh_pathtbl_unregister();
  33. kmem_cache_destroy(rm_cache);
  34. }
  35. static void ieee80211_mesh_housekeeping_timer(unsigned long data)
  36. {
  37. struct ieee80211_sub_if_data *sdata = (void *) data;
  38. struct ieee80211_local *local = sdata->local;
  39. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  40. set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
  41. ieee80211_queue_work(&local->hw, &sdata->work);
  42. }
  43. /**
  44. * mesh_matches_local - check if the config of a mesh point matches ours
  45. *
  46. * @sdata: local mesh subif
  47. * @ie: information elements of a management frame from the mesh peer
  48. *
  49. * This function checks if the mesh configuration of a mesh point matches the
  50. * local mesh configuration, i.e. if both nodes belong to the same mesh network.
  51. */
  52. bool mesh_matches_local(struct ieee80211_sub_if_data *sdata,
  53. struct ieee802_11_elems *ie)
  54. {
  55. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  56. u32 basic_rates = 0;
  57. struct cfg80211_chan_def sta_chan_def;
  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. ieee80211_sta_get_rates(sdata, ie, ieee80211_get_sdata_band(sdata),
  77. &basic_rates);
  78. if (sdata->vif.bss_conf.basic_rates != basic_rates)
  79. return false;
  80. ieee80211_ht_oper_to_chandef(sdata->vif.bss_conf.chandef.chan,
  81. ie->ht_operation, &sta_chan_def);
  82. if (!cfg80211_chandef_compatible(&sdata->vif.bss_conf.chandef,
  83. &sta_chan_def))
  84. return false;
  85. return true;
  86. }
  87. /**
  88. * mesh_peer_accepts_plinks - check if an mp is willing to establish peer links
  89. *
  90. * @ie: information elements of a management frame from the mesh peer
  91. */
  92. bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie)
  93. {
  94. return (ie->mesh_config->meshconf_cap &
  95. IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS) != 0;
  96. }
  97. /**
  98. * mesh_accept_plinks_update - update accepting_plink in local mesh beacons
  99. *
  100. * @sdata: mesh interface in which mesh beacons are going to be updated
  101. *
  102. * Returns: beacon changed flag if the beacon content changed.
  103. */
  104. u32 mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata)
  105. {
  106. bool free_plinks;
  107. u32 changed = 0;
  108. /* In case mesh_plink_free_count > 0 and mesh_plinktbl_capacity == 0,
  109. * the mesh interface might be able to establish plinks with peers that
  110. * are already on the table but are not on PLINK_ESTAB state. However,
  111. * in general the mesh interface is not accepting peer link requests
  112. * from new peers, and that must be reflected in the beacon
  113. */
  114. free_plinks = mesh_plink_availables(sdata);
  115. if (free_plinks != sdata->u.mesh.accepting_plinks) {
  116. sdata->u.mesh.accepting_plinks = free_plinks;
  117. changed = BSS_CHANGED_BEACON;
  118. }
  119. return changed;
  120. }
  121. /*
  122. * mesh_sta_cleanup - clean up any mesh sta state
  123. *
  124. * @sta: mesh sta to clean up.
  125. */
  126. void mesh_sta_cleanup(struct sta_info *sta)
  127. {
  128. struct ieee80211_sub_if_data *sdata = sta->sdata;
  129. u32 changed;
  130. /*
  131. * maybe userspace handles peer allocation and peering, but in either
  132. * case the beacon is still generated by the kernel and we might need
  133. * an update.
  134. */
  135. changed = mesh_accept_plinks_update(sdata);
  136. if (!sdata->u.mesh.user_mpm) {
  137. changed |= mesh_plink_deactivate(sta);
  138. del_timer_sync(&sta->plink_timer);
  139. }
  140. if (changed)
  141. ieee80211_mbss_info_change_notify(sdata, changed);
  142. }
  143. int mesh_rmc_init(struct ieee80211_sub_if_data *sdata)
  144. {
  145. int i;
  146. sdata->u.mesh.rmc = kmalloc(sizeof(struct mesh_rmc), GFP_KERNEL);
  147. if (!sdata->u.mesh.rmc)
  148. return -ENOMEM;
  149. sdata->u.mesh.rmc->idx_mask = RMC_BUCKETS - 1;
  150. for (i = 0; i < RMC_BUCKETS; i++)
  151. INIT_LIST_HEAD(&sdata->u.mesh.rmc->bucket[i]);
  152. return 0;
  153. }
  154. void mesh_rmc_free(struct ieee80211_sub_if_data *sdata)
  155. {
  156. struct mesh_rmc *rmc = sdata->u.mesh.rmc;
  157. struct rmc_entry *p, *n;
  158. int i;
  159. if (!sdata->u.mesh.rmc)
  160. return;
  161. for (i = 0; i < RMC_BUCKETS; i++) {
  162. list_for_each_entry_safe(p, n, &rmc->bucket[i], list) {
  163. list_del(&p->list);
  164. kmem_cache_free(rm_cache, p);
  165. }
  166. }
  167. kfree(rmc);
  168. sdata->u.mesh.rmc = NULL;
  169. }
  170. /**
  171. * mesh_rmc_check - Check frame in recent multicast cache and add if absent.
  172. *
  173. * @sdata: interface
  174. * @sa: source address
  175. * @mesh_hdr: mesh_header
  176. *
  177. * Returns: 0 if the frame is not in the cache, nonzero otherwise.
  178. *
  179. * Checks using the source address and the mesh sequence number if we have
  180. * received this frame lately. If the frame is not in the cache, it is added to
  181. * it.
  182. */
  183. int mesh_rmc_check(struct ieee80211_sub_if_data *sdata,
  184. const u8 *sa, struct ieee80211s_hdr *mesh_hdr)
  185. {
  186. struct mesh_rmc *rmc = sdata->u.mesh.rmc;
  187. u32 seqnum = 0;
  188. int entries = 0;
  189. u8 idx;
  190. struct rmc_entry *p, *n;
  191. /* Don't care about endianness since only match matters */
  192. memcpy(&seqnum, &mesh_hdr->seqnum, sizeof(mesh_hdr->seqnum));
  193. idx = le32_to_cpu(mesh_hdr->seqnum) & rmc->idx_mask;
  194. list_for_each_entry_safe(p, n, &rmc->bucket[idx], list) {
  195. ++entries;
  196. if (time_after(jiffies, p->exp_time) ||
  197. entries == RMC_QUEUE_MAX_LEN) {
  198. list_del(&p->list);
  199. kmem_cache_free(rm_cache, p);
  200. --entries;
  201. } else if ((seqnum == p->seqnum) && ether_addr_equal(sa, p->sa))
  202. return -1;
  203. }
  204. p = kmem_cache_alloc(rm_cache, GFP_ATOMIC);
  205. if (!p)
  206. return 0;
  207. p->seqnum = seqnum;
  208. p->exp_time = jiffies + RMC_TIMEOUT;
  209. memcpy(p->sa, sa, ETH_ALEN);
  210. list_add(&p->list, &rmc->bucket[idx]);
  211. return 0;
  212. }
  213. int mesh_add_meshconf_ie(struct ieee80211_sub_if_data *sdata,
  214. struct sk_buff *skb)
  215. {
  216. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  217. u8 *pos, neighbors;
  218. u8 meshconf_len = sizeof(struct ieee80211_meshconf_ie);
  219. if (skb_tailroom(skb) < 2 + meshconf_len)
  220. return -ENOMEM;
  221. pos = skb_put(skb, 2 + meshconf_len);
  222. *pos++ = WLAN_EID_MESH_CONFIG;
  223. *pos++ = meshconf_len;
  224. /* Active path selection protocol ID */
  225. *pos++ = ifmsh->mesh_pp_id;
  226. /* Active path selection metric ID */
  227. *pos++ = ifmsh->mesh_pm_id;
  228. /* Congestion control mode identifier */
  229. *pos++ = ifmsh->mesh_cc_id;
  230. /* Synchronization protocol identifier */
  231. *pos++ = ifmsh->mesh_sp_id;
  232. /* Authentication Protocol identifier */
  233. *pos++ = ifmsh->mesh_auth_id;
  234. /* Mesh Formation Info - number of neighbors */
  235. neighbors = atomic_read(&ifmsh->estab_plinks);
  236. neighbors = min_t(int, neighbors, IEEE80211_MAX_MESH_PEERINGS);
  237. *pos++ = neighbors << 1;
  238. /* Mesh capability */
  239. *pos = 0x00;
  240. *pos |= ifmsh->mshcfg.dot11MeshForwarding ?
  241. IEEE80211_MESHCONF_CAPAB_FORWARDING : 0x00;
  242. *pos |= ifmsh->accepting_plinks ?
  243. IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS : 0x00;
  244. /* Mesh PS mode. See IEEE802.11-2012 8.4.2.100.8 */
  245. *pos |= ifmsh->ps_peers_deep_sleep ?
  246. IEEE80211_MESHCONF_CAPAB_POWER_SAVE_LEVEL : 0x00;
  247. *pos++ |= ifmsh->adjusting_tbtt ?
  248. IEEE80211_MESHCONF_CAPAB_TBTT_ADJUSTING : 0x00;
  249. *pos++ = 0x00;
  250. return 0;
  251. }
  252. int mesh_add_meshid_ie(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
  253. {
  254. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  255. u8 *pos;
  256. if (skb_tailroom(skb) < 2 + ifmsh->mesh_id_len)
  257. return -ENOMEM;
  258. pos = skb_put(skb, 2 + ifmsh->mesh_id_len);
  259. *pos++ = WLAN_EID_MESH_ID;
  260. *pos++ = ifmsh->mesh_id_len;
  261. if (ifmsh->mesh_id_len)
  262. memcpy(pos, ifmsh->mesh_id, ifmsh->mesh_id_len);
  263. return 0;
  264. }
  265. static int mesh_add_awake_window_ie(struct ieee80211_sub_if_data *sdata,
  266. struct sk_buff *skb)
  267. {
  268. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  269. u8 *pos;
  270. /* see IEEE802.11-2012 13.14.6 */
  271. if (ifmsh->ps_peers_light_sleep == 0 &&
  272. ifmsh->ps_peers_deep_sleep == 0 &&
  273. ifmsh->nonpeer_pm == NL80211_MESH_POWER_ACTIVE)
  274. return 0;
  275. if (skb_tailroom(skb) < 4)
  276. return -ENOMEM;
  277. pos = skb_put(skb, 2 + 2);
  278. *pos++ = WLAN_EID_MESH_AWAKE_WINDOW;
  279. *pos++ = 2;
  280. put_unaligned_le16(ifmsh->mshcfg.dot11MeshAwakeWindowDuration, pos);
  281. return 0;
  282. }
  283. int mesh_add_vendor_ies(struct ieee80211_sub_if_data *sdata,
  284. struct sk_buff *skb)
  285. {
  286. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  287. u8 offset, len;
  288. const u8 *data;
  289. if (!ifmsh->ie || !ifmsh->ie_len)
  290. return 0;
  291. /* fast-forward to vendor IEs */
  292. offset = ieee80211_ie_split_vendor(ifmsh->ie, ifmsh->ie_len, 0);
  293. if (offset) {
  294. len = ifmsh->ie_len - offset;
  295. data = ifmsh->ie + offset;
  296. if (skb_tailroom(skb) < len)
  297. return -ENOMEM;
  298. memcpy(skb_put(skb, len), data, len);
  299. }
  300. return 0;
  301. }
  302. int mesh_add_rsn_ie(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
  303. {
  304. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  305. u8 len = 0;
  306. const u8 *data;
  307. if (!ifmsh->ie || !ifmsh->ie_len)
  308. return 0;
  309. /* find RSN IE */
  310. data = ifmsh->ie;
  311. while (data < ifmsh->ie + ifmsh->ie_len) {
  312. if (*data == WLAN_EID_RSN) {
  313. len = data[1] + 2;
  314. break;
  315. }
  316. data++;
  317. }
  318. if (len) {
  319. if (skb_tailroom(skb) < len)
  320. return -ENOMEM;
  321. memcpy(skb_put(skb, len), data, len);
  322. }
  323. return 0;
  324. }
  325. static int mesh_add_ds_params_ie(struct ieee80211_sub_if_data *sdata,
  326. struct sk_buff *skb)
  327. {
  328. struct ieee80211_chanctx_conf *chanctx_conf;
  329. struct ieee80211_channel *chan;
  330. u8 *pos;
  331. if (skb_tailroom(skb) < 3)
  332. return -ENOMEM;
  333. rcu_read_lock();
  334. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  335. if (WARN_ON(!chanctx_conf)) {
  336. rcu_read_unlock();
  337. return -EINVAL;
  338. }
  339. chan = chanctx_conf->def.chan;
  340. rcu_read_unlock();
  341. pos = skb_put(skb, 2 + 1);
  342. *pos++ = WLAN_EID_DS_PARAMS;
  343. *pos++ = 1;
  344. *pos++ = ieee80211_frequency_to_channel(chan->center_freq);
  345. return 0;
  346. }
  347. int mesh_add_ht_cap_ie(struct ieee80211_sub_if_data *sdata,
  348. struct sk_buff *skb)
  349. {
  350. struct ieee80211_local *local = sdata->local;
  351. enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
  352. struct ieee80211_supported_band *sband;
  353. u8 *pos;
  354. sband = local->hw.wiphy->bands[band];
  355. if (!sband->ht_cap.ht_supported ||
  356. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT ||
  357. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_5 ||
  358. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_10)
  359. return 0;
  360. if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_cap))
  361. return -ENOMEM;
  362. pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_cap));
  363. ieee80211_ie_build_ht_cap(pos, &sband->ht_cap, sband->ht_cap.cap);
  364. return 0;
  365. }
  366. int mesh_add_ht_oper_ie(struct ieee80211_sub_if_data *sdata,
  367. struct sk_buff *skb)
  368. {
  369. struct ieee80211_local *local = sdata->local;
  370. struct ieee80211_chanctx_conf *chanctx_conf;
  371. struct ieee80211_channel *channel;
  372. enum nl80211_channel_type channel_type =
  373. cfg80211_get_chandef_type(&sdata->vif.bss_conf.chandef);
  374. struct ieee80211_supported_band *sband;
  375. struct ieee80211_sta_ht_cap *ht_cap;
  376. u8 *pos;
  377. rcu_read_lock();
  378. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  379. if (WARN_ON(!chanctx_conf)) {
  380. rcu_read_unlock();
  381. return -EINVAL;
  382. }
  383. channel = chanctx_conf->def.chan;
  384. rcu_read_unlock();
  385. sband = local->hw.wiphy->bands[channel->band];
  386. ht_cap = &sband->ht_cap;
  387. if (!ht_cap->ht_supported || channel_type == NL80211_CHAN_NO_HT)
  388. return 0;
  389. if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_operation))
  390. return -ENOMEM;
  391. pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_operation));
  392. ieee80211_ie_build_ht_oper(pos, ht_cap, &sdata->vif.bss_conf.chandef,
  393. sdata->vif.bss_conf.ht_operation_mode);
  394. return 0;
  395. }
  396. static void ieee80211_mesh_path_timer(unsigned long data)
  397. {
  398. struct ieee80211_sub_if_data *sdata =
  399. (struct ieee80211_sub_if_data *) data;
  400. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  401. }
  402. static void ieee80211_mesh_path_root_timer(unsigned long data)
  403. {
  404. struct ieee80211_sub_if_data *sdata =
  405. (struct ieee80211_sub_if_data *) data;
  406. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  407. set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
  408. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  409. }
  410. void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh)
  411. {
  412. if (ifmsh->mshcfg.dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)
  413. set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
  414. else {
  415. clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
  416. /* stop running timer */
  417. del_timer_sync(&ifmsh->mesh_path_root_timer);
  418. }
  419. }
  420. /**
  421. * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame
  422. * @hdr: 802.11 frame header
  423. * @fc: frame control field
  424. * @meshda: destination address in the mesh
  425. * @meshsa: source address address in the mesh. Same as TA, as frame is
  426. * locally originated.
  427. *
  428. * Return the length of the 802.11 (does not include a mesh control header)
  429. */
  430. int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc,
  431. const u8 *meshda, const u8 *meshsa)
  432. {
  433. if (is_multicast_ether_addr(meshda)) {
  434. *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
  435. /* DA TA SA */
  436. memcpy(hdr->addr1, meshda, ETH_ALEN);
  437. memcpy(hdr->addr2, meshsa, ETH_ALEN);
  438. memcpy(hdr->addr3, meshsa, ETH_ALEN);
  439. return 24;
  440. } else {
  441. *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
  442. /* RA TA DA SA */
  443. memset(hdr->addr1, 0, ETH_ALEN); /* RA is resolved later */
  444. memcpy(hdr->addr2, meshsa, ETH_ALEN);
  445. memcpy(hdr->addr3, meshda, ETH_ALEN);
  446. memcpy(hdr->addr4, meshsa, ETH_ALEN);
  447. return 30;
  448. }
  449. }
  450. /**
  451. * ieee80211_new_mesh_header - create a new mesh header
  452. * @sdata: mesh interface to be used
  453. * @meshhdr: uninitialized mesh header
  454. * @addr4or5: 1st address in the ae header, which may correspond to address 4
  455. * (if addr6 is NULL) or address 5 (if addr6 is present). It may
  456. * be NULL.
  457. * @addr6: 2nd address in the ae header, which corresponds to addr6 of the
  458. * mesh frame
  459. *
  460. * Return the header length.
  461. */
  462. int ieee80211_new_mesh_header(struct ieee80211_sub_if_data *sdata,
  463. struct ieee80211s_hdr *meshhdr,
  464. const char *addr4or5, const char *addr6)
  465. {
  466. if (WARN_ON(!addr4or5 && addr6))
  467. return 0;
  468. memset(meshhdr, 0, sizeof(*meshhdr));
  469. meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
  470. /* FIXME: racy -- TX on multiple queues can be concurrent */
  471. put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum);
  472. sdata->u.mesh.mesh_seqnum++;
  473. if (addr4or5 && !addr6) {
  474. meshhdr->flags |= MESH_FLAGS_AE_A4;
  475. memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN);
  476. return 2 * ETH_ALEN;
  477. } else if (addr4or5 && addr6) {
  478. meshhdr->flags |= MESH_FLAGS_AE_A5_A6;
  479. memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN);
  480. memcpy(meshhdr->eaddr2, addr6, ETH_ALEN);
  481. return 3 * ETH_ALEN;
  482. }
  483. return ETH_ALEN;
  484. }
  485. static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata)
  486. {
  487. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  488. u32 changed;
  489. ieee80211_sta_expire(sdata, ifmsh->mshcfg.plink_timeout * HZ);
  490. mesh_path_expire(sdata);
  491. changed = mesh_accept_plinks_update(sdata);
  492. ieee80211_mbss_info_change_notify(sdata, changed);
  493. mod_timer(&ifmsh->housekeeping_timer,
  494. round_jiffies(jiffies +
  495. IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
  496. }
  497. static void ieee80211_mesh_rootpath(struct ieee80211_sub_if_data *sdata)
  498. {
  499. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  500. u32 interval;
  501. mesh_path_tx_root_frame(sdata);
  502. if (ifmsh->mshcfg.dot11MeshHWMPRootMode == IEEE80211_PROACTIVE_RANN)
  503. interval = ifmsh->mshcfg.dot11MeshHWMPRannInterval;
  504. else
  505. interval = ifmsh->mshcfg.dot11MeshHWMProotInterval;
  506. mod_timer(&ifmsh->mesh_path_root_timer,
  507. round_jiffies(TU_TO_EXP_TIME(interval)));
  508. }
  509. static int
  510. ieee80211_mesh_build_beacon(struct ieee80211_if_mesh *ifmsh)
  511. {
  512. struct beacon_data *bcn;
  513. int head_len, tail_len;
  514. struct sk_buff *skb;
  515. struct ieee80211_mgmt *mgmt;
  516. struct ieee80211_chanctx_conf *chanctx_conf;
  517. enum ieee80211_band band;
  518. u8 *pos;
  519. struct ieee80211_sub_if_data *sdata;
  520. int hdr_len = offsetof(struct ieee80211_mgmt, u.beacon) +
  521. sizeof(mgmt->u.beacon);
  522. sdata = container_of(ifmsh, struct ieee80211_sub_if_data, u.mesh);
  523. rcu_read_lock();
  524. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  525. band = chanctx_conf->def.chan->band;
  526. rcu_read_unlock();
  527. head_len = hdr_len +
  528. 2 + /* NULL SSID */
  529. 2 + 8 + /* supported rates */
  530. 2 + 3; /* DS params */
  531. tail_len = 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
  532. 2 + sizeof(struct ieee80211_ht_cap) +
  533. 2 + sizeof(struct ieee80211_ht_operation) +
  534. 2 + ifmsh->mesh_id_len +
  535. 2 + sizeof(struct ieee80211_meshconf_ie) +
  536. 2 + sizeof(__le16) + /* awake window */
  537. ifmsh->ie_len;
  538. bcn = kzalloc(sizeof(*bcn) + head_len + tail_len, GFP_KERNEL);
  539. /* need an skb for IE builders to operate on */
  540. skb = dev_alloc_skb(max(head_len, tail_len));
  541. if (!bcn || !skb)
  542. goto out_free;
  543. /*
  544. * pointers go into the block we allocated,
  545. * memory is | beacon_data | head | tail |
  546. */
  547. bcn->head = ((u8 *) bcn) + sizeof(*bcn);
  548. /* fill in the head */
  549. mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len);
  550. memset(mgmt, 0, hdr_len);
  551. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  552. IEEE80211_STYPE_BEACON);
  553. eth_broadcast_addr(mgmt->da);
  554. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  555. memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
  556. ieee80211_mps_set_frame_flags(sdata, NULL, (void *) mgmt);
  557. mgmt->u.beacon.beacon_int =
  558. cpu_to_le16(sdata->vif.bss_conf.beacon_int);
  559. mgmt->u.beacon.capab_info |= cpu_to_le16(
  560. sdata->u.mesh.security ? WLAN_CAPABILITY_PRIVACY : 0);
  561. pos = skb_put(skb, 2);
  562. *pos++ = WLAN_EID_SSID;
  563. *pos++ = 0x0;
  564. if (ieee80211_add_srates_ie(sdata, skb, true, band) ||
  565. mesh_add_ds_params_ie(sdata, skb))
  566. goto out_free;
  567. bcn->head_len = skb->len;
  568. memcpy(bcn->head, skb->data, bcn->head_len);
  569. /* now the tail */
  570. skb_trim(skb, 0);
  571. bcn->tail = bcn->head + bcn->head_len;
  572. if (ieee80211_add_ext_srates_ie(sdata, skb, true, band) ||
  573. mesh_add_rsn_ie(sdata, skb) ||
  574. mesh_add_ht_cap_ie(sdata, skb) ||
  575. mesh_add_ht_oper_ie(sdata, skb) ||
  576. mesh_add_meshid_ie(sdata, skb) ||
  577. mesh_add_meshconf_ie(sdata, skb) ||
  578. mesh_add_awake_window_ie(sdata, skb) ||
  579. mesh_add_vendor_ies(sdata, skb))
  580. goto out_free;
  581. bcn->tail_len = skb->len;
  582. memcpy(bcn->tail, skb->data, bcn->tail_len);
  583. dev_kfree_skb(skb);
  584. rcu_assign_pointer(ifmsh->beacon, bcn);
  585. return 0;
  586. out_free:
  587. kfree(bcn);
  588. dev_kfree_skb(skb);
  589. return -ENOMEM;
  590. }
  591. static int
  592. ieee80211_mesh_rebuild_beacon(struct ieee80211_sub_if_data *sdata)
  593. {
  594. struct beacon_data *old_bcn;
  595. int ret;
  596. old_bcn = rcu_dereference_protected(sdata->u.mesh.beacon,
  597. lockdep_is_held(&sdata->wdev.mtx));
  598. ret = ieee80211_mesh_build_beacon(&sdata->u.mesh);
  599. if (ret)
  600. /* just reuse old beacon */
  601. return ret;
  602. if (old_bcn)
  603. kfree_rcu(old_bcn, rcu_head);
  604. return 0;
  605. }
  606. void ieee80211_mbss_info_change_notify(struct ieee80211_sub_if_data *sdata,
  607. u32 changed)
  608. {
  609. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  610. unsigned long bits = changed;
  611. u32 bit;
  612. if (!bits)
  613. return;
  614. /* if we race with running work, worst case this work becomes a noop */
  615. for_each_set_bit(bit, &bits, sizeof(changed) * BITS_PER_BYTE)
  616. set_bit(bit, &ifmsh->mbss_changed);
  617. set_bit(MESH_WORK_MBSS_CHANGED, &ifmsh->wrkq_flags);
  618. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  619. }
  620. int ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
  621. {
  622. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  623. struct ieee80211_local *local = sdata->local;
  624. u32 changed = BSS_CHANGED_BEACON |
  625. BSS_CHANGED_BEACON_ENABLED |
  626. BSS_CHANGED_HT |
  627. BSS_CHANGED_BASIC_RATES |
  628. BSS_CHANGED_BEACON_INT;
  629. local->fif_other_bss++;
  630. /* mesh ifaces must set allmulti to forward mcast traffic */
  631. atomic_inc(&local->iff_allmultis);
  632. ieee80211_configure_filter(local);
  633. ifmsh->mesh_cc_id = 0; /* Disabled */
  634. /* register sync ops from extensible synchronization framework */
  635. ifmsh->sync_ops = ieee80211_mesh_sync_ops_get(ifmsh->mesh_sp_id);
  636. ifmsh->adjusting_tbtt = false;
  637. ifmsh->sync_offset_clockdrift_max = 0;
  638. set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
  639. ieee80211_mesh_root_setup(ifmsh);
  640. ieee80211_queue_work(&local->hw, &sdata->work);
  641. sdata->vif.bss_conf.ht_operation_mode =
  642. ifmsh->mshcfg.ht_opmode;
  643. sdata->vif.bss_conf.enable_beacon = true;
  644. changed |= ieee80211_mps_local_status_update(sdata);
  645. if (ieee80211_mesh_build_beacon(ifmsh)) {
  646. ieee80211_stop_mesh(sdata);
  647. return -ENOMEM;
  648. }
  649. ieee80211_bss_info_change_notify(sdata, changed);
  650. netif_carrier_on(sdata->dev);
  651. return 0;
  652. }
  653. void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
  654. {
  655. struct ieee80211_local *local = sdata->local;
  656. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  657. struct beacon_data *bcn;
  658. netif_carrier_off(sdata->dev);
  659. /* stop the beacon */
  660. ifmsh->mesh_id_len = 0;
  661. sdata->vif.bss_conf.enable_beacon = false;
  662. clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
  663. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  664. bcn = rcu_dereference_protected(ifmsh->beacon,
  665. lockdep_is_held(&sdata->wdev.mtx));
  666. rcu_assign_pointer(ifmsh->beacon, NULL);
  667. kfree_rcu(bcn, rcu_head);
  668. /* flush STAs and mpaths on this iface */
  669. sta_info_flush(sdata);
  670. mesh_path_flush_by_iface(sdata);
  671. /* free all potentially still buffered group-addressed frames */
  672. local->total_ps_buffered -= skb_queue_len(&ifmsh->ps.bc_buf);
  673. skb_queue_purge(&ifmsh->ps.bc_buf);
  674. del_timer_sync(&sdata->u.mesh.housekeeping_timer);
  675. del_timer_sync(&sdata->u.mesh.mesh_path_root_timer);
  676. del_timer_sync(&sdata->u.mesh.mesh_path_timer);
  677. /* clear any mesh work (for next join) we may have accrued */
  678. ifmsh->wrkq_flags = 0;
  679. ifmsh->mbss_changed = 0;
  680. local->fif_other_bss--;
  681. atomic_dec(&local->iff_allmultis);
  682. ieee80211_configure_filter(local);
  683. }
  684. static void
  685. ieee80211_mesh_rx_probe_req(struct ieee80211_sub_if_data *sdata,
  686. struct ieee80211_mgmt *mgmt, size_t len)
  687. {
  688. struct ieee80211_local *local = sdata->local;
  689. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  690. struct sk_buff *presp;
  691. struct beacon_data *bcn;
  692. struct ieee80211_mgmt *hdr;
  693. struct ieee802_11_elems elems;
  694. size_t baselen;
  695. u8 *pos;
  696. pos = mgmt->u.probe_req.variable;
  697. baselen = (u8 *) pos - (u8 *) mgmt;
  698. if (baselen > len)
  699. return;
  700. ieee802_11_parse_elems(pos, len - baselen, false, &elems);
  701. if (!elems.mesh_id)
  702. return;
  703. /* 802.11-2012 10.1.4.3.2 */
  704. if ((!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
  705. !is_broadcast_ether_addr(mgmt->da)) ||
  706. elems.ssid_len != 0)
  707. return;
  708. if (elems.mesh_id_len != 0 &&
  709. (elems.mesh_id_len != ifmsh->mesh_id_len ||
  710. memcmp(elems.mesh_id, ifmsh->mesh_id, ifmsh->mesh_id_len)))
  711. return;
  712. rcu_read_lock();
  713. bcn = rcu_dereference(ifmsh->beacon);
  714. if (!bcn)
  715. goto out;
  716. presp = dev_alloc_skb(local->tx_headroom +
  717. bcn->head_len + bcn->tail_len);
  718. if (!presp)
  719. goto out;
  720. skb_reserve(presp, local->tx_headroom);
  721. memcpy(skb_put(presp, bcn->head_len), bcn->head, bcn->head_len);
  722. memcpy(skb_put(presp, bcn->tail_len), bcn->tail, bcn->tail_len);
  723. hdr = (struct ieee80211_mgmt *) presp->data;
  724. hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  725. IEEE80211_STYPE_PROBE_RESP);
  726. memcpy(hdr->da, mgmt->sa, ETH_ALEN);
  727. IEEE80211_SKB_CB(presp)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  728. ieee80211_tx_skb(sdata, presp);
  729. out:
  730. rcu_read_unlock();
  731. }
  732. static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
  733. u16 stype,
  734. struct ieee80211_mgmt *mgmt,
  735. size_t len,
  736. struct ieee80211_rx_status *rx_status)
  737. {
  738. struct ieee80211_local *local = sdata->local;
  739. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  740. struct ieee802_11_elems elems;
  741. struct ieee80211_channel *channel;
  742. size_t baselen;
  743. int freq;
  744. enum ieee80211_band band = rx_status->band;
  745. /* ignore ProbeResp to foreign address */
  746. if (stype == IEEE80211_STYPE_PROBE_RESP &&
  747. !ether_addr_equal(mgmt->da, sdata->vif.addr))
  748. return;
  749. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  750. if (baselen > len)
  751. return;
  752. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  753. false, &elems);
  754. /* ignore non-mesh or secure / unsecure mismatch */
  755. if ((!elems.mesh_id || !elems.mesh_config) ||
  756. (elems.rsn && sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) ||
  757. (!elems.rsn && sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE))
  758. return;
  759. if (elems.ds_params)
  760. freq = ieee80211_channel_to_frequency(elems.ds_params[0], band);
  761. else
  762. freq = rx_status->freq;
  763. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  764. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  765. return;
  766. if (mesh_matches_local(sdata, &elems))
  767. mesh_neighbour_update(sdata, mgmt->sa, &elems);
  768. if (ifmsh->sync_ops)
  769. ifmsh->sync_ops->rx_bcn_presp(sdata,
  770. stype, mgmt, &elems, rx_status);
  771. }
  772. static int mesh_fwd_csa_frame(struct ieee80211_sub_if_data *sdata,
  773. struct ieee80211_mgmt *mgmt, size_t len)
  774. {
  775. struct ieee80211_mgmt *mgmt_fwd;
  776. struct sk_buff *skb;
  777. struct ieee80211_local *local = sdata->local;
  778. u8 *pos = mgmt->u.action.u.chan_switch.variable;
  779. size_t offset_ttl;
  780. skb = dev_alloc_skb(local->tx_headroom + len);
  781. if (!skb)
  782. return -ENOMEM;
  783. skb_reserve(skb, local->tx_headroom);
  784. mgmt_fwd = (struct ieee80211_mgmt *) skb_put(skb, len);
  785. /* offset_ttl is based on whether the secondary channel
  786. * offset is available or not. Substract 1 from the mesh TTL
  787. * and disable the initiator flag before forwarding.
  788. */
  789. offset_ttl = (len < 42) ? 7 : 10;
  790. *(pos + offset_ttl) -= 1;
  791. *(pos + offset_ttl + 1) &= ~WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR;
  792. memcpy(mgmt_fwd, mgmt, len);
  793. eth_broadcast_addr(mgmt_fwd->da);
  794. memcpy(mgmt_fwd->sa, sdata->vif.addr, ETH_ALEN);
  795. memcpy(mgmt_fwd->bssid, sdata->vif.addr, ETH_ALEN);
  796. ieee80211_tx_skb(sdata, skb);
  797. return 0;
  798. }
  799. static void mesh_rx_csa_frame(struct ieee80211_sub_if_data *sdata,
  800. struct ieee80211_mgmt *mgmt, size_t len)
  801. {
  802. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  803. struct ieee802_11_elems elems;
  804. u16 pre_value;
  805. bool block_tx, fwd_csa = true;
  806. size_t baselen;
  807. u8 *pos, ttl;
  808. if (mgmt->u.action.u.measurement.action_code !=
  809. WLAN_ACTION_SPCT_CHL_SWITCH)
  810. return;
  811. pos = mgmt->u.action.u.chan_switch.variable;
  812. baselen = offsetof(struct ieee80211_mgmt,
  813. u.action.u.chan_switch.variable);
  814. ieee802_11_parse_elems(pos, len - baselen, false, &elems);
  815. ttl = elems.mesh_chansw_params_ie->mesh_ttl;
  816. if (!--ttl)
  817. fwd_csa = false;
  818. pre_value = le16_to_cpu(elems.mesh_chansw_params_ie->mesh_pre_value);
  819. if (ifmsh->pre_value >= pre_value)
  820. return;
  821. ifmsh->pre_value = pre_value;
  822. /* forward or re-broadcast the CSA frame */
  823. if (fwd_csa) {
  824. if (mesh_fwd_csa_frame(sdata, mgmt, len) < 0)
  825. mcsa_dbg(sdata, "Failed to forward the CSA frame");
  826. }
  827. /* block the Tx only after forwarding the CSA frame if required */
  828. block_tx = elems.mesh_chansw_params_ie->mesh_flags &
  829. WLAN_EID_CHAN_SWITCH_PARAM_TX_RESTRICT;
  830. if (block_tx)
  831. ieee80211_stop_queues_by_reason(&sdata->local->hw,
  832. IEEE80211_MAX_QUEUE_MAP,
  833. IEEE80211_QUEUE_STOP_REASON_CSA);
  834. }
  835. static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
  836. struct ieee80211_mgmt *mgmt,
  837. size_t len,
  838. struct ieee80211_rx_status *rx_status)
  839. {
  840. switch (mgmt->u.action.category) {
  841. case WLAN_CATEGORY_SELF_PROTECTED:
  842. switch (mgmt->u.action.u.self_prot.action_code) {
  843. case WLAN_SP_MESH_PEERING_OPEN:
  844. case WLAN_SP_MESH_PEERING_CLOSE:
  845. case WLAN_SP_MESH_PEERING_CONFIRM:
  846. mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
  847. break;
  848. }
  849. break;
  850. case WLAN_CATEGORY_MESH_ACTION:
  851. if (mesh_action_is_path_sel(mgmt))
  852. mesh_rx_path_sel_frame(sdata, mgmt, len);
  853. break;
  854. case WLAN_CATEGORY_SPECTRUM_MGMT:
  855. mesh_rx_csa_frame(sdata, mgmt, len);
  856. break;
  857. }
  858. }
  859. void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  860. struct sk_buff *skb)
  861. {
  862. struct ieee80211_rx_status *rx_status;
  863. struct ieee80211_mgmt *mgmt;
  864. u16 stype;
  865. sdata_lock(sdata);
  866. /* mesh already went down */
  867. if (!sdata->wdev.mesh_id_len)
  868. goto out;
  869. rx_status = IEEE80211_SKB_RXCB(skb);
  870. mgmt = (struct ieee80211_mgmt *) skb->data;
  871. stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
  872. switch (stype) {
  873. case IEEE80211_STYPE_PROBE_RESP:
  874. case IEEE80211_STYPE_BEACON:
  875. ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len,
  876. rx_status);
  877. break;
  878. case IEEE80211_STYPE_PROBE_REQ:
  879. ieee80211_mesh_rx_probe_req(sdata, mgmt, skb->len);
  880. break;
  881. case IEEE80211_STYPE_ACTION:
  882. ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status);
  883. break;
  884. }
  885. out:
  886. sdata_unlock(sdata);
  887. }
  888. static void mesh_bss_info_changed(struct ieee80211_sub_if_data *sdata)
  889. {
  890. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  891. u32 bit, changed = 0;
  892. for_each_set_bit(bit, &ifmsh->mbss_changed,
  893. sizeof(changed) * BITS_PER_BYTE) {
  894. clear_bit(bit, &ifmsh->mbss_changed);
  895. changed |= BIT(bit);
  896. }
  897. if (sdata->vif.bss_conf.enable_beacon &&
  898. (changed & (BSS_CHANGED_BEACON |
  899. BSS_CHANGED_HT |
  900. BSS_CHANGED_BASIC_RATES |
  901. BSS_CHANGED_BEACON_INT)))
  902. if (ieee80211_mesh_rebuild_beacon(sdata))
  903. return;
  904. ieee80211_bss_info_change_notify(sdata, changed);
  905. }
  906. void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata)
  907. {
  908. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  909. sdata_lock(sdata);
  910. /* mesh already went down */
  911. if (!sdata->wdev.mesh_id_len)
  912. goto out;
  913. if (ifmsh->preq_queue_len &&
  914. time_after(jiffies,
  915. ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval)))
  916. mesh_path_start_discovery(sdata);
  917. if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags))
  918. mesh_mpath_table_grow();
  919. if (test_and_clear_bit(MESH_WORK_GROW_MPP_TABLE, &ifmsh->wrkq_flags))
  920. mesh_mpp_table_grow();
  921. if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags))
  922. ieee80211_mesh_housekeeping(sdata);
  923. if (test_and_clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags))
  924. ieee80211_mesh_rootpath(sdata);
  925. if (test_and_clear_bit(MESH_WORK_DRIFT_ADJUST, &ifmsh->wrkq_flags))
  926. mesh_sync_adjust_tbtt(sdata);
  927. if (test_and_clear_bit(MESH_WORK_MBSS_CHANGED, &ifmsh->wrkq_flags))
  928. mesh_bss_info_changed(sdata);
  929. out:
  930. sdata_unlock(sdata);
  931. }
  932. void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local)
  933. {
  934. struct ieee80211_sub_if_data *sdata;
  935. rcu_read_lock();
  936. list_for_each_entry_rcu(sdata, &local->interfaces, list)
  937. if (ieee80211_vif_is_mesh(&sdata->vif) &&
  938. ieee80211_sdata_running(sdata))
  939. ieee80211_queue_work(&local->hw, &sdata->work);
  940. rcu_read_unlock();
  941. }
  942. void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
  943. {
  944. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  945. static u8 zero_addr[ETH_ALEN] = {};
  946. setup_timer(&ifmsh->housekeeping_timer,
  947. ieee80211_mesh_housekeeping_timer,
  948. (unsigned long) sdata);
  949. ifmsh->accepting_plinks = true;
  950. atomic_set(&ifmsh->mpaths, 0);
  951. mesh_rmc_init(sdata);
  952. ifmsh->last_preq = jiffies;
  953. ifmsh->next_perr = jiffies;
  954. ifmsh->chsw_init = false;
  955. /* Allocate all mesh structures when creating the first mesh interface. */
  956. if (!mesh_allocated)
  957. ieee80211s_init();
  958. setup_timer(&ifmsh->mesh_path_timer,
  959. ieee80211_mesh_path_timer,
  960. (unsigned long) sdata);
  961. setup_timer(&ifmsh->mesh_path_root_timer,
  962. ieee80211_mesh_path_root_timer,
  963. (unsigned long) sdata);
  964. INIT_LIST_HEAD(&ifmsh->preq_queue.list);
  965. skb_queue_head_init(&ifmsh->ps.bc_buf);
  966. spin_lock_init(&ifmsh->mesh_preq_queue_lock);
  967. spin_lock_init(&ifmsh->sync_offset_lock);
  968. RCU_INIT_POINTER(ifmsh->beacon, NULL);
  969. sdata->vif.bss_conf.bssid = zero_addr;
  970. }