mesh.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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. #define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
  15. #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
  16. #define IEEE80211_MESH_RANN_INTERVAL (1 * HZ)
  17. #define MESHCONF_CAPAB_ACCEPT_PLINKS 0x01
  18. #define MESHCONF_CAPAB_FORWARDING 0x08
  19. #define TMR_RUNNING_HK 0
  20. #define TMR_RUNNING_MP 1
  21. #define TMR_RUNNING_MPR 2
  22. int mesh_allocated;
  23. static struct kmem_cache *rm_cache;
  24. void ieee80211s_init(void)
  25. {
  26. mesh_pathtbl_init();
  27. mesh_allocated = 1;
  28. rm_cache = kmem_cache_create("mesh_rmc", sizeof(struct rmc_entry),
  29. 0, 0, NULL);
  30. }
  31. void ieee80211s_stop(void)
  32. {
  33. mesh_pathtbl_unregister();
  34. kmem_cache_destroy(rm_cache);
  35. }
  36. static void ieee80211_mesh_housekeeping_timer(unsigned long data)
  37. {
  38. struct ieee80211_sub_if_data *sdata = (void *) data;
  39. struct ieee80211_local *local = sdata->local;
  40. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  41. set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
  42. if (local->quiescing) {
  43. set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
  44. return;
  45. }
  46. ieee80211_queue_work(&local->hw, &sdata->work);
  47. }
  48. /**
  49. * mesh_matches_local - check if the config of a mesh point matches ours
  50. *
  51. * @ie: information elements of a management frame from the mesh peer
  52. * @sdata: local mesh subif
  53. *
  54. * This function checks if the mesh configuration of a mesh point matches the
  55. * local mesh configuration, i.e. if both nodes belong to the same mesh network.
  56. */
  57. bool mesh_matches_local(struct ieee802_11_elems *ie, struct ieee80211_sub_if_data *sdata)
  58. {
  59. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  60. /*
  61. * As support for each feature is added, check for matching
  62. * - On mesh config capabilities
  63. * - Power Save Support En
  64. * - Sync support enabled
  65. * - Sync support active
  66. * - Sync support required from peer
  67. * - MDA enabled
  68. * - Power management control on fc
  69. */
  70. if (ifmsh->mesh_id_len == ie->mesh_id_len &&
  71. memcmp(ifmsh->mesh_id, ie->mesh_id, ie->mesh_id_len) == 0 &&
  72. (ifmsh->mesh_pp_id == ie->mesh_config->meshconf_psel) &&
  73. (ifmsh->mesh_pm_id == ie->mesh_config->meshconf_pmetric) &&
  74. (ifmsh->mesh_cc_id == ie->mesh_config->meshconf_congest) &&
  75. (ifmsh->mesh_sp_id == ie->mesh_config->meshconf_synch) &&
  76. (ifmsh->mesh_auth_id == ie->mesh_config->meshconf_auth))
  77. return true;
  78. return false;
  79. }
  80. /**
  81. * mesh_peer_accepts_plinks - check if an mp is willing to establish peer links
  82. *
  83. * @ie: information elements of a management frame from the mesh peer
  84. */
  85. bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie)
  86. {
  87. return (ie->mesh_config->meshconf_cap &
  88. MESHCONF_CAPAB_ACCEPT_PLINKS) != 0;
  89. }
  90. /**
  91. * mesh_accept_plinks_update: update accepting_plink in local mesh beacons
  92. *
  93. * @sdata: mesh interface in which mesh beacons are going to be updated
  94. */
  95. void mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata)
  96. {
  97. bool free_plinks;
  98. /* In case mesh_plink_free_count > 0 and mesh_plinktbl_capacity == 0,
  99. * the mesh interface might be able to establish plinks with peers that
  100. * are already on the table but are not on PLINK_ESTAB state. However,
  101. * in general the mesh interface is not accepting peer link requests
  102. * from new peers, and that must be reflected in the beacon
  103. */
  104. free_plinks = mesh_plink_availables(sdata);
  105. if (free_plinks != sdata->u.mesh.accepting_plinks)
  106. ieee80211_mesh_housekeeping_timer((unsigned long) sdata);
  107. }
  108. int mesh_rmc_init(struct ieee80211_sub_if_data *sdata)
  109. {
  110. int i;
  111. sdata->u.mesh.rmc = kmalloc(sizeof(struct mesh_rmc), GFP_KERNEL);
  112. if (!sdata->u.mesh.rmc)
  113. return -ENOMEM;
  114. sdata->u.mesh.rmc->idx_mask = RMC_BUCKETS - 1;
  115. for (i = 0; i < RMC_BUCKETS; i++)
  116. INIT_LIST_HEAD(&sdata->u.mesh.rmc->bucket[i].list);
  117. return 0;
  118. }
  119. void mesh_rmc_free(struct ieee80211_sub_if_data *sdata)
  120. {
  121. struct mesh_rmc *rmc = sdata->u.mesh.rmc;
  122. struct rmc_entry *p, *n;
  123. int i;
  124. if (!sdata->u.mesh.rmc)
  125. return;
  126. for (i = 0; i < RMC_BUCKETS; i++)
  127. list_for_each_entry_safe(p, n, &rmc->bucket[i].list, list) {
  128. list_del(&p->list);
  129. kmem_cache_free(rm_cache, p);
  130. }
  131. kfree(rmc);
  132. sdata->u.mesh.rmc = NULL;
  133. }
  134. /**
  135. * mesh_rmc_check - Check frame in recent multicast cache and add if absent.
  136. *
  137. * @sa: source address
  138. * @mesh_hdr: mesh_header
  139. *
  140. * Returns: 0 if the frame is not in the cache, nonzero otherwise.
  141. *
  142. * Checks using the source address and the mesh sequence number if we have
  143. * received this frame lately. If the frame is not in the cache, it is added to
  144. * it.
  145. */
  146. int mesh_rmc_check(u8 *sa, struct ieee80211s_hdr *mesh_hdr,
  147. struct ieee80211_sub_if_data *sdata)
  148. {
  149. struct mesh_rmc *rmc = sdata->u.mesh.rmc;
  150. u32 seqnum = 0;
  151. int entries = 0;
  152. u8 idx;
  153. struct rmc_entry *p, *n;
  154. /* Don't care about endianness since only match matters */
  155. memcpy(&seqnum, &mesh_hdr->seqnum, sizeof(mesh_hdr->seqnum));
  156. idx = le32_to_cpu(mesh_hdr->seqnum) & rmc->idx_mask;
  157. list_for_each_entry_safe(p, n, &rmc->bucket[idx].list, list) {
  158. ++entries;
  159. if (time_after(jiffies, p->exp_time) ||
  160. (entries == RMC_QUEUE_MAX_LEN)) {
  161. list_del(&p->list);
  162. kmem_cache_free(rm_cache, p);
  163. --entries;
  164. } else if ((seqnum == p->seqnum) &&
  165. (memcmp(sa, p->sa, ETH_ALEN) == 0))
  166. return -1;
  167. }
  168. p = kmem_cache_alloc(rm_cache, GFP_ATOMIC);
  169. if (!p) {
  170. printk(KERN_DEBUG "o11s: could not allocate RMC entry\n");
  171. return 0;
  172. }
  173. p->seqnum = seqnum;
  174. p->exp_time = jiffies + RMC_TIMEOUT;
  175. memcpy(p->sa, sa, ETH_ALEN);
  176. list_add(&p->list, &rmc->bucket[idx].list);
  177. return 0;
  178. }
  179. void mesh_mgmt_ies_add(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
  180. {
  181. struct ieee80211_local *local = sdata->local;
  182. struct ieee80211_supported_band *sband;
  183. u8 *pos;
  184. int len, i, rate;
  185. u8 neighbors;
  186. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  187. len = sband->n_bitrates;
  188. if (len > 8)
  189. len = 8;
  190. pos = skb_put(skb, len + 2);
  191. *pos++ = WLAN_EID_SUPP_RATES;
  192. *pos++ = len;
  193. for (i = 0; i < len; i++) {
  194. rate = sband->bitrates[i].bitrate;
  195. *pos++ = (u8) (rate / 5);
  196. }
  197. if (sband->n_bitrates > len) {
  198. pos = skb_put(skb, sband->n_bitrates - len + 2);
  199. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  200. *pos++ = sband->n_bitrates - len;
  201. for (i = len; i < sband->n_bitrates; i++) {
  202. rate = sband->bitrates[i].bitrate;
  203. *pos++ = (u8) (rate / 5);
  204. }
  205. }
  206. if (sband->band == IEEE80211_BAND_2GHZ) {
  207. pos = skb_put(skb, 2 + 1);
  208. *pos++ = WLAN_EID_DS_PARAMS;
  209. *pos++ = 1;
  210. *pos++ = ieee80211_frequency_to_channel(local->hw.conf.channel->center_freq);
  211. }
  212. pos = skb_put(skb, 2 + sdata->u.mesh.mesh_id_len);
  213. *pos++ = WLAN_EID_MESH_ID;
  214. *pos++ = sdata->u.mesh.mesh_id_len;
  215. if (sdata->u.mesh.mesh_id_len)
  216. memcpy(pos, sdata->u.mesh.mesh_id, sdata->u.mesh.mesh_id_len);
  217. pos = skb_put(skb, 2 + sizeof(struct ieee80211_meshconf_ie));
  218. *pos++ = WLAN_EID_MESH_CONFIG;
  219. *pos++ = sizeof(struct ieee80211_meshconf_ie);
  220. /* Active path selection protocol ID */
  221. *pos++ = sdata->u.mesh.mesh_pp_id;
  222. /* Active path selection metric ID */
  223. *pos++ = sdata->u.mesh.mesh_pm_id;
  224. /* Congestion control mode identifier */
  225. *pos++ = sdata->u.mesh.mesh_cc_id;
  226. /* Synchronization protocol identifier */
  227. *pos++ = sdata->u.mesh.mesh_sp_id;
  228. /* Authentication Protocol identifier */
  229. *pos++ = sdata->u.mesh.mesh_auth_id;
  230. /* Mesh Formation Info - number of neighbors */
  231. neighbors = atomic_read(&sdata->u.mesh.mshstats.estab_plinks);
  232. /* Number of neighbor mesh STAs or 15 whichever is smaller */
  233. neighbors = (neighbors > 15) ? 15 : neighbors;
  234. *pos++ = neighbors << 1;
  235. /* Mesh capability */
  236. sdata->u.mesh.accepting_plinks = mesh_plink_availables(sdata);
  237. *pos = MESHCONF_CAPAB_FORWARDING;
  238. *pos++ |= sdata->u.mesh.accepting_plinks ?
  239. MESHCONF_CAPAB_ACCEPT_PLINKS : 0x00;
  240. *pos++ = 0x00;
  241. if (sdata->u.mesh.ie) {
  242. int len = sdata->u.mesh.ie_len;
  243. const u8 *data = sdata->u.mesh.ie;
  244. if (skb_tailroom(skb) > len)
  245. memcpy(skb_put(skb, len), data, len);
  246. }
  247. }
  248. static void ieee80211_mesh_path_timer(unsigned long data)
  249. {
  250. struct ieee80211_sub_if_data *sdata =
  251. (struct ieee80211_sub_if_data *) data;
  252. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  253. struct ieee80211_local *local = sdata->local;
  254. if (local->quiescing) {
  255. set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
  256. return;
  257. }
  258. ieee80211_queue_work(&local->hw, &sdata->work);
  259. }
  260. static void ieee80211_mesh_path_root_timer(unsigned long data)
  261. {
  262. struct ieee80211_sub_if_data *sdata =
  263. (struct ieee80211_sub_if_data *) data;
  264. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  265. struct ieee80211_local *local = sdata->local;
  266. set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
  267. if (local->quiescing) {
  268. set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running);
  269. return;
  270. }
  271. ieee80211_queue_work(&local->hw, &sdata->work);
  272. }
  273. void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh)
  274. {
  275. if (ifmsh->mshcfg.dot11MeshHWMPRootMode)
  276. set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
  277. else {
  278. clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
  279. /* stop running timer */
  280. del_timer_sync(&ifmsh->mesh_path_root_timer);
  281. }
  282. }
  283. /**
  284. * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame
  285. * @hdr: 802.11 frame header
  286. * @fc: frame control field
  287. * @meshda: destination address in the mesh
  288. * @meshsa: source address address in the mesh. Same as TA, as frame is
  289. * locally originated.
  290. *
  291. * Return the length of the 802.11 (does not include a mesh control header)
  292. */
  293. int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc,
  294. const u8 *meshda, const u8 *meshsa)
  295. {
  296. if (is_multicast_ether_addr(meshda)) {
  297. *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
  298. /* DA TA SA */
  299. memcpy(hdr->addr1, meshda, ETH_ALEN);
  300. memcpy(hdr->addr2, meshsa, ETH_ALEN);
  301. memcpy(hdr->addr3, meshsa, ETH_ALEN);
  302. return 24;
  303. } else {
  304. *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
  305. IEEE80211_FCTL_TODS);
  306. /* RA TA DA SA */
  307. memset(hdr->addr1, 0, ETH_ALEN); /* RA is resolved later */
  308. memcpy(hdr->addr2, meshsa, ETH_ALEN);
  309. memcpy(hdr->addr3, meshda, ETH_ALEN);
  310. memcpy(hdr->addr4, meshsa, ETH_ALEN);
  311. return 30;
  312. }
  313. }
  314. /**
  315. * ieee80211_new_mesh_header - create a new mesh header
  316. * @meshhdr: uninitialized mesh header
  317. * @sdata: mesh interface to be used
  318. * @addr4or5: 1st address in the ae header, which may correspond to address 4
  319. * (if addr6 is NULL) or address 5 (if addr6 is present). It may
  320. * be NULL.
  321. * @addr6: 2nd address in the ae header, which corresponds to addr6 of the
  322. * mesh frame
  323. *
  324. * Return the header length.
  325. */
  326. int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
  327. struct ieee80211_sub_if_data *sdata, char *addr4or5,
  328. char *addr6)
  329. {
  330. int aelen = 0;
  331. BUG_ON(!addr4or5 && addr6);
  332. memset(meshhdr, 0, sizeof(*meshhdr));
  333. meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
  334. put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum);
  335. sdata->u.mesh.mesh_seqnum++;
  336. if (addr4or5 && !addr6) {
  337. meshhdr->flags |= MESH_FLAGS_AE_A4;
  338. aelen += ETH_ALEN;
  339. memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN);
  340. } else if (addr4or5 && addr6) {
  341. meshhdr->flags |= MESH_FLAGS_AE_A5_A6;
  342. aelen += 2 * ETH_ALEN;
  343. memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN);
  344. memcpy(meshhdr->eaddr2, addr6, ETH_ALEN);
  345. }
  346. return 6 + aelen;
  347. }
  348. static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
  349. struct ieee80211_if_mesh *ifmsh)
  350. {
  351. bool free_plinks;
  352. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  353. printk(KERN_DEBUG "%s: running mesh housekeeping\n",
  354. sdata->name);
  355. #endif
  356. ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
  357. mesh_path_expire(sdata);
  358. free_plinks = mesh_plink_availables(sdata);
  359. if (free_plinks != sdata->u.mesh.accepting_plinks)
  360. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
  361. mod_timer(&ifmsh->housekeeping_timer,
  362. round_jiffies(jiffies + IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
  363. }
  364. static void ieee80211_mesh_rootpath(struct ieee80211_sub_if_data *sdata)
  365. {
  366. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  367. mesh_path_tx_root_frame(sdata);
  368. mod_timer(&ifmsh->mesh_path_root_timer,
  369. round_jiffies(jiffies + IEEE80211_MESH_RANN_INTERVAL));
  370. }
  371. #ifdef CONFIG_PM
  372. void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata)
  373. {
  374. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  375. /* use atomic bitops in case both timers fire at the same time */
  376. if (del_timer_sync(&ifmsh->housekeeping_timer))
  377. set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
  378. if (del_timer_sync(&ifmsh->mesh_path_timer))
  379. set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
  380. if (del_timer_sync(&ifmsh->mesh_path_root_timer))
  381. set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running);
  382. }
  383. void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata)
  384. {
  385. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  386. if (test_and_clear_bit(TMR_RUNNING_HK, &ifmsh->timers_running))
  387. add_timer(&ifmsh->housekeeping_timer);
  388. if (test_and_clear_bit(TMR_RUNNING_MP, &ifmsh->timers_running))
  389. add_timer(&ifmsh->mesh_path_timer);
  390. if (test_and_clear_bit(TMR_RUNNING_MPR, &ifmsh->timers_running))
  391. add_timer(&ifmsh->mesh_path_root_timer);
  392. ieee80211_mesh_root_setup(ifmsh);
  393. }
  394. #endif
  395. void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
  396. {
  397. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  398. struct ieee80211_local *local = sdata->local;
  399. local->fif_other_bss++;
  400. /* mesh ifaces must set allmulti to forward mcast traffic */
  401. atomic_inc(&local->iff_allmultis);
  402. ieee80211_configure_filter(local);
  403. ifmsh->mesh_cc_id = 0; /* Disabled */
  404. ifmsh->mesh_sp_id = 0; /* Neighbor Offset */
  405. ifmsh->mesh_auth_id = 0; /* Disabled */
  406. set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
  407. ieee80211_mesh_root_setup(ifmsh);
  408. ieee80211_queue_work(&local->hw, &sdata->work);
  409. sdata->vif.bss_conf.beacon_int = MESH_DEFAULT_BEACON_INTERVAL;
  410. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON |
  411. BSS_CHANGED_BEACON_ENABLED |
  412. BSS_CHANGED_BEACON_INT);
  413. }
  414. void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
  415. {
  416. struct ieee80211_local *local = sdata->local;
  417. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  418. ifmsh->mesh_id_len = 0;
  419. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  420. sta_info_flush(local, NULL);
  421. del_timer_sync(&sdata->u.mesh.housekeeping_timer);
  422. del_timer_sync(&sdata->u.mesh.mesh_path_root_timer);
  423. /*
  424. * If the timer fired while we waited for it, it will have
  425. * requeued the work. Now the work will be running again
  426. * but will not rearm the timer again because it checks
  427. * whether the interface is running, which, at this point,
  428. * it no longer is.
  429. */
  430. cancel_work_sync(&sdata->work);
  431. local->fif_other_bss--;
  432. atomic_dec(&local->iff_allmultis);
  433. ieee80211_configure_filter(local);
  434. }
  435. static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
  436. u16 stype,
  437. struct ieee80211_mgmt *mgmt,
  438. size_t len,
  439. struct ieee80211_rx_status *rx_status)
  440. {
  441. struct ieee80211_local *local = sdata->local;
  442. struct ieee802_11_elems elems;
  443. struct ieee80211_channel *channel;
  444. u32 supp_rates = 0;
  445. size_t baselen;
  446. int freq;
  447. enum ieee80211_band band = rx_status->band;
  448. /* ignore ProbeResp to foreign address */
  449. if (stype == IEEE80211_STYPE_PROBE_RESP &&
  450. compare_ether_addr(mgmt->da, sdata->vif.addr))
  451. return;
  452. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  453. if (baselen > len)
  454. return;
  455. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  456. &elems);
  457. /* ignore beacons from secure mesh peers if our security is off */
  458. if (elems.rsn_len && sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE)
  459. return;
  460. if (elems.ds_params && elems.ds_params_len == 1)
  461. freq = ieee80211_channel_to_frequency(elems.ds_params[0], band);
  462. else
  463. freq = rx_status->freq;
  464. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  465. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  466. return;
  467. if (elems.mesh_id && elems.mesh_config &&
  468. mesh_matches_local(&elems, sdata)) {
  469. supp_rates = ieee80211_sta_get_rates(local, &elems, band);
  470. mesh_neighbour_update(mgmt->sa, supp_rates, sdata, &elems);
  471. }
  472. }
  473. static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
  474. struct ieee80211_mgmt *mgmt,
  475. size_t len,
  476. struct ieee80211_rx_status *rx_status)
  477. {
  478. switch (mgmt->u.action.category) {
  479. case WLAN_CATEGORY_MESH_ACTION:
  480. mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
  481. break;
  482. case WLAN_CATEGORY_MESH_PATH_SEL:
  483. mesh_rx_path_sel_frame(sdata, mgmt, len);
  484. break;
  485. }
  486. }
  487. void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  488. struct sk_buff *skb)
  489. {
  490. struct ieee80211_rx_status *rx_status;
  491. struct ieee80211_mgmt *mgmt;
  492. u16 stype;
  493. rx_status = IEEE80211_SKB_RXCB(skb);
  494. mgmt = (struct ieee80211_mgmt *) skb->data;
  495. stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
  496. switch (stype) {
  497. case IEEE80211_STYPE_PROBE_RESP:
  498. case IEEE80211_STYPE_BEACON:
  499. ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len,
  500. rx_status);
  501. break;
  502. case IEEE80211_STYPE_ACTION:
  503. ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status);
  504. break;
  505. }
  506. }
  507. void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata)
  508. {
  509. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  510. if (ifmsh->preq_queue_len &&
  511. time_after(jiffies,
  512. ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval)))
  513. mesh_path_start_discovery(sdata);
  514. if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags))
  515. mesh_mpath_table_grow();
  516. if (test_and_clear_bit(MESH_WORK_GROW_MPP_TABLE, &ifmsh->wrkq_flags))
  517. mesh_mpp_table_grow();
  518. if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags))
  519. ieee80211_mesh_housekeeping(sdata, ifmsh);
  520. if (test_and_clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags))
  521. ieee80211_mesh_rootpath(sdata);
  522. }
  523. void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local)
  524. {
  525. struct ieee80211_sub_if_data *sdata;
  526. rcu_read_lock();
  527. list_for_each_entry_rcu(sdata, &local->interfaces, list)
  528. if (ieee80211_vif_is_mesh(&sdata->vif))
  529. ieee80211_queue_work(&local->hw, &sdata->work);
  530. rcu_read_unlock();
  531. }
  532. void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
  533. {
  534. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  535. setup_timer(&ifmsh->housekeeping_timer,
  536. ieee80211_mesh_housekeeping_timer,
  537. (unsigned long) sdata);
  538. ifmsh->accepting_plinks = true;
  539. ifmsh->preq_id = 0;
  540. ifmsh->sn = 0;
  541. atomic_set(&ifmsh->mpaths, 0);
  542. mesh_rmc_init(sdata);
  543. ifmsh->last_preq = jiffies;
  544. /* Allocate all mesh structures when creating the first mesh interface. */
  545. if (!mesh_allocated)
  546. ieee80211s_init();
  547. setup_timer(&ifmsh->mesh_path_timer,
  548. ieee80211_mesh_path_timer,
  549. (unsigned long) sdata);
  550. setup_timer(&ifmsh->mesh_path_root_timer,
  551. ieee80211_mesh_path_root_timer,
  552. (unsigned long) sdata);
  553. INIT_LIST_HEAD(&ifmsh->preq_queue.list);
  554. spin_lock_init(&ifmsh->mesh_preq_queue_lock);
  555. }