mesh.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. /*
  2. * Copyright (c) 2008 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 <asm/unaligned.h>
  11. #include "ieee80211_i.h"
  12. #include "mesh.h"
  13. #define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
  14. #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
  15. #define PP_OFFSET 1 /* Path Selection Protocol */
  16. #define PM_OFFSET 5 /* Path Selection Metric */
  17. #define CC_OFFSET 9 /* Congestion Control Mode */
  18. #define CAPAB_OFFSET 17
  19. #define ACCEPT_PLINKS 0x80
  20. int mesh_allocated;
  21. static struct kmem_cache *rm_cache;
  22. void ieee80211s_init(void)
  23. {
  24. mesh_pathtbl_init();
  25. mesh_allocated = 1;
  26. rm_cache = kmem_cache_create("mesh_rmc", sizeof(struct rmc_entry),
  27. 0, 0, NULL);
  28. }
  29. void ieee80211s_stop(void)
  30. {
  31. mesh_pathtbl_unregister();
  32. kmem_cache_destroy(rm_cache);
  33. }
  34. static void ieee80211_mesh_housekeeping_timer(unsigned long data)
  35. {
  36. struct ieee80211_sub_if_data *sdata = (void *) data;
  37. struct ieee80211_local *local = sdata->local;
  38. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  39. ifmsh->housekeeping = true;
  40. queue_work(local->hw.workqueue, &ifmsh->work);
  41. }
  42. /**
  43. * mesh_matches_local - check if the config of a mesh point matches ours
  44. *
  45. * @ie: information elements of a management frame from the mesh peer
  46. * @sdata: local mesh subif
  47. *
  48. * This function checks if the mesh configuration of a mesh point matches the
  49. * local mesh configuration, i.e. if both nodes belong to the same mesh network.
  50. */
  51. bool mesh_matches_local(struct ieee802_11_elems *ie, struct ieee80211_sub_if_data *sdata)
  52. {
  53. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  54. /*
  55. * As support for each feature is added, check for matching
  56. * - On mesh config capabilities
  57. * - Power Save Support En
  58. * - Sync support enabled
  59. * - Sync support active
  60. * - Sync support required from peer
  61. * - MDA enabled
  62. * - Power management control on fc
  63. */
  64. if (ifmsh->mesh_id_len == ie->mesh_id_len &&
  65. memcmp(ifmsh->mesh_id, ie->mesh_id, ie->mesh_id_len) == 0 &&
  66. memcmp(ifmsh->mesh_pp_id, ie->mesh_config + PP_OFFSET, 4) == 0 &&
  67. memcmp(ifmsh->mesh_pm_id, ie->mesh_config + PM_OFFSET, 4) == 0 &&
  68. memcmp(ifmsh->mesh_cc_id, ie->mesh_config + CC_OFFSET, 4) == 0)
  69. return true;
  70. return false;
  71. }
  72. /**
  73. * mesh_peer_accepts_plinks - check if an mp is willing to establish peer links
  74. *
  75. * @ie: information elements of a management frame from the mesh peer
  76. */
  77. bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie)
  78. {
  79. return (*(ie->mesh_config + CAPAB_OFFSET) & ACCEPT_PLINKS) != 0;
  80. }
  81. /**
  82. * mesh_accept_plinks_update: update accepting_plink in local mesh beacons
  83. *
  84. * @sdata: mesh interface in which mesh beacons are going to be updated
  85. */
  86. void mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata)
  87. {
  88. bool free_plinks;
  89. /* In case mesh_plink_free_count > 0 and mesh_plinktbl_capacity == 0,
  90. * the mesh interface might be able to establish plinks with peers that
  91. * are already on the table but are not on PLINK_ESTAB state. However,
  92. * in general the mesh interface is not accepting peer link requests
  93. * from new peers, and that must be reflected in the beacon
  94. */
  95. free_plinks = mesh_plink_availables(sdata);
  96. if (free_plinks != sdata->u.mesh.accepting_plinks)
  97. ieee80211_mesh_housekeeping_timer((unsigned long) sdata);
  98. }
  99. void mesh_ids_set_default(struct ieee80211_if_mesh *sta)
  100. {
  101. u8 def_id[4] = {0x00, 0x0F, 0xAC, 0xff};
  102. memcpy(sta->mesh_pp_id, def_id, 4);
  103. memcpy(sta->mesh_pm_id, def_id, 4);
  104. memcpy(sta->mesh_cc_id, def_id, 4);
  105. }
  106. int mesh_rmc_init(struct ieee80211_sub_if_data *sdata)
  107. {
  108. int i;
  109. sdata->u.mesh.rmc = kmalloc(sizeof(struct mesh_rmc), GFP_KERNEL);
  110. if (!sdata->u.mesh.rmc)
  111. return -ENOMEM;
  112. sdata->u.mesh.rmc->idx_mask = RMC_BUCKETS - 1;
  113. for (i = 0; i < RMC_BUCKETS; i++)
  114. INIT_LIST_HEAD(&sdata->u.mesh.rmc->bucket[i].list);
  115. return 0;
  116. }
  117. void mesh_rmc_free(struct ieee80211_sub_if_data *sdata)
  118. {
  119. struct mesh_rmc *rmc = sdata->u.mesh.rmc;
  120. struct rmc_entry *p, *n;
  121. int i;
  122. if (!sdata->u.mesh.rmc)
  123. return;
  124. for (i = 0; i < RMC_BUCKETS; i++)
  125. list_for_each_entry_safe(p, n, &rmc->bucket[i].list, list) {
  126. list_del(&p->list);
  127. kmem_cache_free(rm_cache, p);
  128. }
  129. kfree(rmc);
  130. sdata->u.mesh.rmc = NULL;
  131. }
  132. /**
  133. * mesh_rmc_check - Check frame in recent multicast cache and add if absent.
  134. *
  135. * @sa: source address
  136. * @mesh_hdr: mesh_header
  137. *
  138. * Returns: 0 if the frame is not in the cache, nonzero otherwise.
  139. *
  140. * Checks using the source address and the mesh sequence number if we have
  141. * received this frame lately. If the frame is not in the cache, it is added to
  142. * it.
  143. */
  144. int mesh_rmc_check(u8 *sa, struct ieee80211s_hdr *mesh_hdr,
  145. struct ieee80211_sub_if_data *sdata)
  146. {
  147. struct mesh_rmc *rmc = sdata->u.mesh.rmc;
  148. u32 seqnum = 0;
  149. int entries = 0;
  150. u8 idx;
  151. struct rmc_entry *p, *n;
  152. /* Don't care about endianness since only match matters */
  153. memcpy(&seqnum, &mesh_hdr->seqnum, sizeof(mesh_hdr->seqnum));
  154. idx = le32_to_cpu(mesh_hdr->seqnum) & rmc->idx_mask;
  155. list_for_each_entry_safe(p, n, &rmc->bucket[idx].list, list) {
  156. ++entries;
  157. if (time_after(jiffies, p->exp_time) ||
  158. (entries == RMC_QUEUE_MAX_LEN)) {
  159. list_del(&p->list);
  160. kmem_cache_free(rm_cache, p);
  161. --entries;
  162. } else if ((seqnum == p->seqnum)
  163. && (memcmp(sa, p->sa, ETH_ALEN) == 0))
  164. return -1;
  165. }
  166. p = kmem_cache_alloc(rm_cache, GFP_ATOMIC);
  167. if (!p) {
  168. printk(KERN_DEBUG "o11s: could not allocate RMC entry\n");
  169. return 0;
  170. }
  171. p->seqnum = seqnum;
  172. p->exp_time = jiffies + RMC_TIMEOUT;
  173. memcpy(p->sa, sa, ETH_ALEN);
  174. list_add(&p->list, &rmc->bucket[idx].list);
  175. return 0;
  176. }
  177. void mesh_mgmt_ies_add(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
  178. {
  179. struct ieee80211_local *local = sdata->local;
  180. struct ieee80211_supported_band *sband;
  181. u8 *pos;
  182. int len, i, rate;
  183. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  184. len = sband->n_bitrates;
  185. if (len > 8)
  186. len = 8;
  187. pos = skb_put(skb, len + 2);
  188. *pos++ = WLAN_EID_SUPP_RATES;
  189. *pos++ = len;
  190. for (i = 0; i < len; i++) {
  191. rate = sband->bitrates[i].bitrate;
  192. *pos++ = (u8) (rate / 5);
  193. }
  194. if (sband->n_bitrates > len) {
  195. pos = skb_put(skb, sband->n_bitrates - len + 2);
  196. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  197. *pos++ = sband->n_bitrates - len;
  198. for (i = len; i < sband->n_bitrates; i++) {
  199. rate = sband->bitrates[i].bitrate;
  200. *pos++ = (u8) (rate / 5);
  201. }
  202. }
  203. pos = skb_put(skb, 2 + sdata->u.mesh.mesh_id_len);
  204. *pos++ = WLAN_EID_MESH_ID;
  205. *pos++ = sdata->u.mesh.mesh_id_len;
  206. if (sdata->u.mesh.mesh_id_len)
  207. memcpy(pos, sdata->u.mesh.mesh_id, sdata->u.mesh.mesh_id_len);
  208. pos = skb_put(skb, 21);
  209. *pos++ = WLAN_EID_MESH_CONFIG;
  210. *pos++ = MESH_CFG_LEN;
  211. /* Version */
  212. *pos++ = 1;
  213. /* Active path selection protocol ID */
  214. memcpy(pos, sdata->u.mesh.mesh_pp_id, 4);
  215. pos += 4;
  216. /* Active path selection metric ID */
  217. memcpy(pos, sdata->u.mesh.mesh_pm_id, 4);
  218. pos += 4;
  219. /* Congestion control mode identifier */
  220. memcpy(pos, sdata->u.mesh.mesh_cc_id, 4);
  221. pos += 4;
  222. /* Channel precedence:
  223. * Not running simple channel unification protocol
  224. */
  225. memset(pos, 0x00, 4);
  226. pos += 4;
  227. /* Mesh capability */
  228. sdata->u.mesh.accepting_plinks = mesh_plink_availables(sdata);
  229. *pos++ = sdata->u.mesh.accepting_plinks ? ACCEPT_PLINKS : 0x00;
  230. *pos++ = 0x00;
  231. return;
  232. }
  233. u32 mesh_table_hash(u8 *addr, struct ieee80211_sub_if_data *sdata, struct mesh_table *tbl)
  234. {
  235. /* Use last four bytes of hw addr and interface index as hash index */
  236. return jhash_2words(*(u32 *)(addr+2), sdata->dev->ifindex, tbl->hash_rnd)
  237. & tbl->hash_mask;
  238. }
  239. u8 mesh_id_hash(u8 *mesh_id, int mesh_id_len)
  240. {
  241. if (!mesh_id_len)
  242. return 1;
  243. else if (mesh_id_len == 1)
  244. return (u8) mesh_id[0];
  245. else
  246. return (u8) (mesh_id[0] + 2 * mesh_id[1]);
  247. }
  248. struct mesh_table *mesh_table_alloc(int size_order)
  249. {
  250. int i;
  251. struct mesh_table *newtbl;
  252. newtbl = kmalloc(sizeof(struct mesh_table), GFP_KERNEL);
  253. if (!newtbl)
  254. return NULL;
  255. newtbl->hash_buckets = kzalloc(sizeof(struct hlist_head) *
  256. (1 << size_order), GFP_KERNEL);
  257. if (!newtbl->hash_buckets) {
  258. kfree(newtbl);
  259. return NULL;
  260. }
  261. newtbl->hashwlock = kmalloc(sizeof(spinlock_t) *
  262. (1 << size_order), GFP_KERNEL);
  263. if (!newtbl->hashwlock) {
  264. kfree(newtbl->hash_buckets);
  265. kfree(newtbl);
  266. return NULL;
  267. }
  268. newtbl->size_order = size_order;
  269. newtbl->hash_mask = (1 << size_order) - 1;
  270. atomic_set(&newtbl->entries, 0);
  271. get_random_bytes(&newtbl->hash_rnd,
  272. sizeof(newtbl->hash_rnd));
  273. for (i = 0; i <= newtbl->hash_mask; i++)
  274. spin_lock_init(&newtbl->hashwlock[i]);
  275. return newtbl;
  276. }
  277. static void __mesh_table_free(struct mesh_table *tbl)
  278. {
  279. kfree(tbl->hash_buckets);
  280. kfree(tbl->hashwlock);
  281. kfree(tbl);
  282. }
  283. void mesh_table_free(struct mesh_table *tbl, bool free_leafs)
  284. {
  285. struct hlist_head *mesh_hash;
  286. struct hlist_node *p, *q;
  287. int i;
  288. mesh_hash = tbl->hash_buckets;
  289. for (i = 0; i <= tbl->hash_mask; i++) {
  290. spin_lock(&tbl->hashwlock[i]);
  291. hlist_for_each_safe(p, q, &mesh_hash[i]) {
  292. tbl->free_node(p, free_leafs);
  293. atomic_dec(&tbl->entries);
  294. }
  295. spin_unlock(&tbl->hashwlock[i]);
  296. }
  297. __mesh_table_free(tbl);
  298. }
  299. static void ieee80211_mesh_path_timer(unsigned long data)
  300. {
  301. struct ieee80211_sub_if_data *sdata =
  302. (struct ieee80211_sub_if_data *) data;
  303. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  304. struct ieee80211_local *local = sdata->local;
  305. queue_work(local->hw.workqueue, &ifmsh->work);
  306. }
  307. struct mesh_table *mesh_table_grow(struct mesh_table *tbl)
  308. {
  309. struct mesh_table *newtbl;
  310. struct hlist_head *oldhash;
  311. struct hlist_node *p, *q;
  312. int i;
  313. if (atomic_read(&tbl->entries)
  314. < tbl->mean_chain_len * (tbl->hash_mask + 1))
  315. goto endgrow;
  316. newtbl = mesh_table_alloc(tbl->size_order + 1);
  317. if (!newtbl)
  318. goto endgrow;
  319. newtbl->free_node = tbl->free_node;
  320. newtbl->mean_chain_len = tbl->mean_chain_len;
  321. newtbl->copy_node = tbl->copy_node;
  322. atomic_set(&newtbl->entries, atomic_read(&tbl->entries));
  323. oldhash = tbl->hash_buckets;
  324. for (i = 0; i <= tbl->hash_mask; i++)
  325. hlist_for_each(p, &oldhash[i])
  326. if (tbl->copy_node(p, newtbl) < 0)
  327. goto errcopy;
  328. return newtbl;
  329. errcopy:
  330. for (i = 0; i <= newtbl->hash_mask; i++) {
  331. hlist_for_each_safe(p, q, &newtbl->hash_buckets[i])
  332. tbl->free_node(p, 0);
  333. }
  334. __mesh_table_free(newtbl);
  335. endgrow:
  336. return NULL;
  337. }
  338. /**
  339. * ieee80211_new_mesh_header - create a new mesh header
  340. * @meshhdr: uninitialized mesh header
  341. * @sdata: mesh interface to be used
  342. *
  343. * Return the header length.
  344. */
  345. int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
  346. struct ieee80211_sub_if_data *sdata)
  347. {
  348. meshhdr->flags = 0;
  349. meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
  350. put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum);
  351. sdata->u.mesh.mesh_seqnum++;
  352. return 6;
  353. }
  354. static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
  355. struct ieee80211_if_mesh *ifmsh)
  356. {
  357. bool free_plinks;
  358. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  359. printk(KERN_DEBUG "%s: running mesh housekeeping\n",
  360. sdata->dev->name);
  361. #endif
  362. ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
  363. mesh_path_expire(sdata);
  364. free_plinks = mesh_plink_availables(sdata);
  365. if (free_plinks != sdata->u.mesh.accepting_plinks)
  366. ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
  367. ifmsh->housekeeping = false;
  368. mod_timer(&ifmsh->housekeeping_timer,
  369. round_jiffies(jiffies + IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
  370. }
  371. void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
  372. {
  373. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  374. struct ieee80211_local *local = sdata->local;
  375. ifmsh->housekeeping = true;
  376. queue_work(local->hw.workqueue, &ifmsh->work);
  377. ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
  378. }
  379. void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
  380. {
  381. del_timer_sync(&sdata->u.mesh.housekeeping_timer);
  382. /*
  383. * If the timer fired while we waited for it, it will have
  384. * requeued the work. Now the work will be running again
  385. * but will not rearm the timer again because it checks
  386. * whether the interface is running, which, at this point,
  387. * it no longer is.
  388. */
  389. cancel_work_sync(&sdata->u.mesh.work);
  390. /*
  391. * When we get here, the interface is marked down.
  392. * Call synchronize_rcu() to wait for the RX path
  393. * should it be using the interface and enqueuing
  394. * frames at this very time on another CPU.
  395. */
  396. synchronize_rcu();
  397. skb_queue_purge(&sdata->u.mesh.skb_queue);
  398. }
  399. static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
  400. u16 stype,
  401. struct ieee80211_mgmt *mgmt,
  402. size_t len,
  403. struct ieee80211_rx_status *rx_status)
  404. {
  405. struct ieee80211_local *local= sdata->local;
  406. struct ieee802_11_elems elems;
  407. struct ieee80211_channel *channel;
  408. u64 supp_rates = 0;
  409. size_t baselen;
  410. int freq;
  411. enum ieee80211_band band = rx_status->band;
  412. /* ignore ProbeResp to foreign address */
  413. if (stype == IEEE80211_STYPE_PROBE_RESP &&
  414. compare_ether_addr(mgmt->da, sdata->dev->dev_addr))
  415. return;
  416. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  417. if (baselen > len)
  418. return;
  419. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  420. &elems);
  421. if (elems.ds_params && elems.ds_params_len == 1)
  422. freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
  423. else
  424. freq = rx_status->freq;
  425. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  426. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  427. return;
  428. if (elems.mesh_id && elems.mesh_config &&
  429. mesh_matches_local(&elems, sdata)) {
  430. supp_rates = ieee80211_sta_get_rates(local, &elems, band);
  431. mesh_neighbour_update(mgmt->sa, supp_rates, sdata,
  432. mesh_peer_accepts_plinks(&elems));
  433. }
  434. }
  435. static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
  436. struct ieee80211_mgmt *mgmt,
  437. size_t len,
  438. struct ieee80211_rx_status *rx_status)
  439. {
  440. switch (mgmt->u.action.category) {
  441. case PLINK_CATEGORY:
  442. mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
  443. break;
  444. case MESH_PATH_SEL_CATEGORY:
  445. mesh_rx_path_sel_frame(sdata, mgmt, len);
  446. break;
  447. }
  448. }
  449. static void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  450. struct sk_buff *skb)
  451. {
  452. struct ieee80211_rx_status *rx_status;
  453. struct ieee80211_if_mesh *ifmsh;
  454. struct ieee80211_mgmt *mgmt;
  455. u16 stype;
  456. ifmsh = &sdata->u.mesh;
  457. rx_status = (struct ieee80211_rx_status *) skb->cb;
  458. mgmt = (struct ieee80211_mgmt *) skb->data;
  459. stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
  460. switch (stype) {
  461. case IEEE80211_STYPE_PROBE_RESP:
  462. case IEEE80211_STYPE_BEACON:
  463. ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len,
  464. rx_status);
  465. break;
  466. case IEEE80211_STYPE_ACTION:
  467. ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status);
  468. break;
  469. }
  470. kfree_skb(skb);
  471. }
  472. static void ieee80211_mesh_work(struct work_struct *work)
  473. {
  474. struct ieee80211_sub_if_data *sdata =
  475. container_of(work, struct ieee80211_sub_if_data, u.mesh.work);
  476. struct ieee80211_local *local = sdata->local;
  477. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  478. struct sk_buff *skb;
  479. if (!netif_running(sdata->dev))
  480. return;
  481. if (local->sw_scanning || local->hw_scanning)
  482. return;
  483. while ((skb = skb_dequeue(&ifmsh->skb_queue)))
  484. ieee80211_mesh_rx_queued_mgmt(sdata, skb);
  485. if (ifmsh->preq_queue_len &&
  486. time_after(jiffies,
  487. ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval)))
  488. mesh_path_start_discovery(sdata);
  489. if (ifmsh->housekeeping)
  490. ieee80211_mesh_housekeeping(sdata, ifmsh);
  491. }
  492. void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local)
  493. {
  494. struct ieee80211_sub_if_data *sdata;
  495. rcu_read_lock();
  496. list_for_each_entry_rcu(sdata, &local->interfaces, list)
  497. if (ieee80211_vif_is_mesh(&sdata->vif))
  498. queue_work(local->hw.workqueue, &sdata->u.mesh.work);
  499. rcu_read_unlock();
  500. }
  501. void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
  502. {
  503. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  504. INIT_WORK(&ifmsh->work, ieee80211_mesh_work);
  505. setup_timer(&ifmsh->housekeeping_timer,
  506. ieee80211_mesh_housekeeping_timer,
  507. (unsigned long) sdata);
  508. skb_queue_head_init(&sdata->u.mesh.skb_queue);
  509. ifmsh->mshcfg.dot11MeshRetryTimeout = MESH_RET_T;
  510. ifmsh->mshcfg.dot11MeshConfirmTimeout = MESH_CONF_T;
  511. ifmsh->mshcfg.dot11MeshHoldingTimeout = MESH_HOLD_T;
  512. ifmsh->mshcfg.dot11MeshMaxRetries = MESH_MAX_RETR;
  513. ifmsh->mshcfg.dot11MeshTTL = MESH_TTL;
  514. ifmsh->mshcfg.auto_open_plinks = true;
  515. ifmsh->mshcfg.dot11MeshMaxPeerLinks =
  516. MESH_MAX_ESTAB_PLINKS;
  517. ifmsh->mshcfg.dot11MeshHWMPactivePathTimeout =
  518. MESH_PATH_TIMEOUT;
  519. ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval =
  520. MESH_PREQ_MIN_INT;
  521. ifmsh->mshcfg.dot11MeshHWMPnetDiameterTraversalTime =
  522. MESH_DIAM_TRAVERSAL_TIME;
  523. ifmsh->mshcfg.dot11MeshHWMPmaxPREQretries =
  524. MESH_MAX_PREQ_RETRIES;
  525. ifmsh->mshcfg.path_refresh_time =
  526. MESH_PATH_REFRESH_TIME;
  527. ifmsh->mshcfg.min_discovery_timeout =
  528. MESH_MIN_DISCOVERY_TIMEOUT;
  529. ifmsh->accepting_plinks = true;
  530. ifmsh->preq_id = 0;
  531. ifmsh->dsn = 0;
  532. atomic_set(&ifmsh->mpaths, 0);
  533. mesh_rmc_init(sdata);
  534. ifmsh->last_preq = jiffies;
  535. /* Allocate all mesh structures when creating the first mesh interface. */
  536. if (!mesh_allocated)
  537. ieee80211s_init();
  538. mesh_ids_set_default(ifmsh);
  539. setup_timer(&ifmsh->mesh_path_timer,
  540. ieee80211_mesh_path_timer,
  541. (unsigned long) sdata);
  542. INIT_LIST_HEAD(&ifmsh->preq_queue.list);
  543. spin_lock_init(&ifmsh->mesh_preq_queue_lock);
  544. }
  545. ieee80211_rx_result
  546. ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
  547. struct ieee80211_rx_status *rx_status)
  548. {
  549. struct ieee80211_local *local = sdata->local;
  550. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  551. struct ieee80211_mgmt *mgmt;
  552. u16 fc;
  553. if (skb->len < 24)
  554. return RX_DROP_MONITOR;
  555. mgmt = (struct ieee80211_mgmt *) skb->data;
  556. fc = le16_to_cpu(mgmt->frame_control);
  557. switch (fc & IEEE80211_FCTL_STYPE) {
  558. case IEEE80211_STYPE_PROBE_RESP:
  559. case IEEE80211_STYPE_BEACON:
  560. case IEEE80211_STYPE_ACTION:
  561. memcpy(skb->cb, rx_status, sizeof(*rx_status));
  562. skb_queue_tail(&ifmsh->skb_queue, skb);
  563. queue_work(local->hw.workqueue, &ifmsh->work);
  564. return RX_QUEUED;
  565. }
  566. return RX_CONTINUE;
  567. }