mesh.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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++ = IEEE80211_MESH_CONFIG_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. struct mesh_table *mesh_table_alloc(int size_order)
  240. {
  241. int i;
  242. struct mesh_table *newtbl;
  243. newtbl = kmalloc(sizeof(struct mesh_table), GFP_KERNEL);
  244. if (!newtbl)
  245. return NULL;
  246. newtbl->hash_buckets = kzalloc(sizeof(struct hlist_head) *
  247. (1 << size_order), GFP_KERNEL);
  248. if (!newtbl->hash_buckets) {
  249. kfree(newtbl);
  250. return NULL;
  251. }
  252. newtbl->hashwlock = kmalloc(sizeof(spinlock_t) *
  253. (1 << size_order), GFP_KERNEL);
  254. if (!newtbl->hashwlock) {
  255. kfree(newtbl->hash_buckets);
  256. kfree(newtbl);
  257. return NULL;
  258. }
  259. newtbl->size_order = size_order;
  260. newtbl->hash_mask = (1 << size_order) - 1;
  261. atomic_set(&newtbl->entries, 0);
  262. get_random_bytes(&newtbl->hash_rnd,
  263. sizeof(newtbl->hash_rnd));
  264. for (i = 0; i <= newtbl->hash_mask; i++)
  265. spin_lock_init(&newtbl->hashwlock[i]);
  266. return newtbl;
  267. }
  268. static void __mesh_table_free(struct mesh_table *tbl)
  269. {
  270. kfree(tbl->hash_buckets);
  271. kfree(tbl->hashwlock);
  272. kfree(tbl);
  273. }
  274. void mesh_table_free(struct mesh_table *tbl, bool free_leafs)
  275. {
  276. struct hlist_head *mesh_hash;
  277. struct hlist_node *p, *q;
  278. int i;
  279. mesh_hash = tbl->hash_buckets;
  280. for (i = 0; i <= tbl->hash_mask; i++) {
  281. spin_lock(&tbl->hashwlock[i]);
  282. hlist_for_each_safe(p, q, &mesh_hash[i]) {
  283. tbl->free_node(p, free_leafs);
  284. atomic_dec(&tbl->entries);
  285. }
  286. spin_unlock(&tbl->hashwlock[i]);
  287. }
  288. __mesh_table_free(tbl);
  289. }
  290. static void ieee80211_mesh_path_timer(unsigned long data)
  291. {
  292. struct ieee80211_sub_if_data *sdata =
  293. (struct ieee80211_sub_if_data *) data;
  294. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  295. struct ieee80211_local *local = sdata->local;
  296. queue_work(local->hw.workqueue, &ifmsh->work);
  297. }
  298. struct mesh_table *mesh_table_grow(struct mesh_table *tbl)
  299. {
  300. struct mesh_table *newtbl;
  301. struct hlist_head *oldhash;
  302. struct hlist_node *p, *q;
  303. int i;
  304. if (atomic_read(&tbl->entries)
  305. < tbl->mean_chain_len * (tbl->hash_mask + 1))
  306. goto endgrow;
  307. newtbl = mesh_table_alloc(tbl->size_order + 1);
  308. if (!newtbl)
  309. goto endgrow;
  310. newtbl->free_node = tbl->free_node;
  311. newtbl->mean_chain_len = tbl->mean_chain_len;
  312. newtbl->copy_node = tbl->copy_node;
  313. atomic_set(&newtbl->entries, atomic_read(&tbl->entries));
  314. oldhash = tbl->hash_buckets;
  315. for (i = 0; i <= tbl->hash_mask; i++)
  316. hlist_for_each(p, &oldhash[i])
  317. if (tbl->copy_node(p, newtbl) < 0)
  318. goto errcopy;
  319. return newtbl;
  320. errcopy:
  321. for (i = 0; i <= newtbl->hash_mask; i++) {
  322. hlist_for_each_safe(p, q, &newtbl->hash_buckets[i])
  323. tbl->free_node(p, 0);
  324. }
  325. __mesh_table_free(newtbl);
  326. endgrow:
  327. return NULL;
  328. }
  329. /**
  330. * ieee80211_new_mesh_header - create a new mesh header
  331. * @meshhdr: uninitialized mesh header
  332. * @sdata: mesh interface to be used
  333. *
  334. * Return the header length.
  335. */
  336. int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
  337. struct ieee80211_sub_if_data *sdata)
  338. {
  339. meshhdr->flags = 0;
  340. meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
  341. put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum);
  342. sdata->u.mesh.mesh_seqnum++;
  343. return 6;
  344. }
  345. static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
  346. struct ieee80211_if_mesh *ifmsh)
  347. {
  348. bool free_plinks;
  349. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  350. printk(KERN_DEBUG "%s: running mesh housekeeping\n",
  351. sdata->dev->name);
  352. #endif
  353. ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
  354. mesh_path_expire(sdata);
  355. free_plinks = mesh_plink_availables(sdata);
  356. if (free_plinks != sdata->u.mesh.accepting_plinks)
  357. ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
  358. ifmsh->housekeeping = false;
  359. mod_timer(&ifmsh->housekeeping_timer,
  360. round_jiffies(jiffies + IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
  361. }
  362. void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
  363. {
  364. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  365. struct ieee80211_local *local = sdata->local;
  366. ifmsh->housekeeping = true;
  367. queue_work(local->hw.workqueue, &ifmsh->work);
  368. ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON |
  369. IEEE80211_IFCC_BEACON_ENABLED);
  370. }
  371. void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
  372. {
  373. del_timer_sync(&sdata->u.mesh.housekeeping_timer);
  374. /*
  375. * If the timer fired while we waited for it, it will have
  376. * requeued the work. Now the work will be running again
  377. * but will not rearm the timer again because it checks
  378. * whether the interface is running, which, at this point,
  379. * it no longer is.
  380. */
  381. cancel_work_sync(&sdata->u.mesh.work);
  382. /*
  383. * When we get here, the interface is marked down.
  384. * Call synchronize_rcu() to wait for the RX path
  385. * should it be using the interface and enqueuing
  386. * frames at this very time on another CPU.
  387. */
  388. synchronize_rcu();
  389. skb_queue_purge(&sdata->u.mesh.skb_queue);
  390. }
  391. static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
  392. u16 stype,
  393. struct ieee80211_mgmt *mgmt,
  394. size_t len,
  395. struct ieee80211_rx_status *rx_status)
  396. {
  397. struct ieee80211_local *local = sdata->local;
  398. struct ieee802_11_elems elems;
  399. struct ieee80211_channel *channel;
  400. u32 supp_rates = 0;
  401. size_t baselen;
  402. int freq;
  403. enum ieee80211_band band = rx_status->band;
  404. /* ignore ProbeResp to foreign address */
  405. if (stype == IEEE80211_STYPE_PROBE_RESP &&
  406. compare_ether_addr(mgmt->da, sdata->dev->dev_addr))
  407. return;
  408. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  409. if (baselen > len)
  410. return;
  411. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  412. &elems);
  413. if (elems.ds_params && elems.ds_params_len == 1)
  414. freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
  415. else
  416. freq = rx_status->freq;
  417. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  418. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  419. return;
  420. if (elems.mesh_id && elems.mesh_config &&
  421. mesh_matches_local(&elems, sdata)) {
  422. supp_rates = ieee80211_sta_get_rates(local, &elems, band);
  423. mesh_neighbour_update(mgmt->sa, supp_rates, sdata,
  424. mesh_peer_accepts_plinks(&elems));
  425. }
  426. }
  427. static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
  428. struct ieee80211_mgmt *mgmt,
  429. size_t len,
  430. struct ieee80211_rx_status *rx_status)
  431. {
  432. switch (mgmt->u.action.category) {
  433. case PLINK_CATEGORY:
  434. mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
  435. break;
  436. case MESH_PATH_SEL_CATEGORY:
  437. mesh_rx_path_sel_frame(sdata, mgmt, len);
  438. break;
  439. }
  440. }
  441. static void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  442. struct sk_buff *skb)
  443. {
  444. struct ieee80211_rx_status *rx_status;
  445. struct ieee80211_if_mesh *ifmsh;
  446. struct ieee80211_mgmt *mgmt;
  447. u16 stype;
  448. ifmsh = &sdata->u.mesh;
  449. rx_status = (struct ieee80211_rx_status *) skb->cb;
  450. mgmt = (struct ieee80211_mgmt *) skb->data;
  451. stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
  452. switch (stype) {
  453. case IEEE80211_STYPE_PROBE_RESP:
  454. case IEEE80211_STYPE_BEACON:
  455. ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len,
  456. rx_status);
  457. break;
  458. case IEEE80211_STYPE_ACTION:
  459. ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status);
  460. break;
  461. }
  462. kfree_skb(skb);
  463. }
  464. static void ieee80211_mesh_work(struct work_struct *work)
  465. {
  466. struct ieee80211_sub_if_data *sdata =
  467. container_of(work, struct ieee80211_sub_if_data, u.mesh.work);
  468. struct ieee80211_local *local = sdata->local;
  469. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  470. struct sk_buff *skb;
  471. if (!netif_running(sdata->dev))
  472. return;
  473. if (local->sw_scanning || local->hw_scanning)
  474. return;
  475. while ((skb = skb_dequeue(&ifmsh->skb_queue)))
  476. ieee80211_mesh_rx_queued_mgmt(sdata, skb);
  477. if (ifmsh->preq_queue_len &&
  478. time_after(jiffies,
  479. ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval)))
  480. mesh_path_start_discovery(sdata);
  481. if (ifmsh->housekeeping)
  482. ieee80211_mesh_housekeeping(sdata, ifmsh);
  483. }
  484. void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local)
  485. {
  486. struct ieee80211_sub_if_data *sdata;
  487. rcu_read_lock();
  488. list_for_each_entry_rcu(sdata, &local->interfaces, list)
  489. if (ieee80211_vif_is_mesh(&sdata->vif))
  490. queue_work(local->hw.workqueue, &sdata->u.mesh.work);
  491. rcu_read_unlock();
  492. }
  493. void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
  494. {
  495. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  496. INIT_WORK(&ifmsh->work, ieee80211_mesh_work);
  497. setup_timer(&ifmsh->housekeeping_timer,
  498. ieee80211_mesh_housekeeping_timer,
  499. (unsigned long) sdata);
  500. skb_queue_head_init(&sdata->u.mesh.skb_queue);
  501. ifmsh->mshcfg.dot11MeshRetryTimeout = MESH_RET_T;
  502. ifmsh->mshcfg.dot11MeshConfirmTimeout = MESH_CONF_T;
  503. ifmsh->mshcfg.dot11MeshHoldingTimeout = MESH_HOLD_T;
  504. ifmsh->mshcfg.dot11MeshMaxRetries = MESH_MAX_RETR;
  505. ifmsh->mshcfg.dot11MeshTTL = MESH_TTL;
  506. ifmsh->mshcfg.auto_open_plinks = true;
  507. ifmsh->mshcfg.dot11MeshMaxPeerLinks =
  508. MESH_MAX_ESTAB_PLINKS;
  509. ifmsh->mshcfg.dot11MeshHWMPactivePathTimeout =
  510. MESH_PATH_TIMEOUT;
  511. ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval =
  512. MESH_PREQ_MIN_INT;
  513. ifmsh->mshcfg.dot11MeshHWMPnetDiameterTraversalTime =
  514. MESH_DIAM_TRAVERSAL_TIME;
  515. ifmsh->mshcfg.dot11MeshHWMPmaxPREQretries =
  516. MESH_MAX_PREQ_RETRIES;
  517. ifmsh->mshcfg.path_refresh_time =
  518. MESH_PATH_REFRESH_TIME;
  519. ifmsh->mshcfg.min_discovery_timeout =
  520. MESH_MIN_DISCOVERY_TIMEOUT;
  521. ifmsh->accepting_plinks = true;
  522. ifmsh->preq_id = 0;
  523. ifmsh->dsn = 0;
  524. atomic_set(&ifmsh->mpaths, 0);
  525. mesh_rmc_init(sdata);
  526. ifmsh->last_preq = jiffies;
  527. /* Allocate all mesh structures when creating the first mesh interface. */
  528. if (!mesh_allocated)
  529. ieee80211s_init();
  530. mesh_ids_set_default(ifmsh);
  531. setup_timer(&ifmsh->mesh_path_timer,
  532. ieee80211_mesh_path_timer,
  533. (unsigned long) sdata);
  534. INIT_LIST_HEAD(&ifmsh->preq_queue.list);
  535. spin_lock_init(&ifmsh->mesh_preq_queue_lock);
  536. }
  537. ieee80211_rx_result
  538. ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
  539. struct ieee80211_rx_status *rx_status)
  540. {
  541. struct ieee80211_local *local = sdata->local;
  542. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  543. struct ieee80211_mgmt *mgmt;
  544. u16 fc;
  545. if (skb->len < 24)
  546. return RX_DROP_MONITOR;
  547. mgmt = (struct ieee80211_mgmt *) skb->data;
  548. fc = le16_to_cpu(mgmt->frame_control);
  549. switch (fc & IEEE80211_FCTL_STYPE) {
  550. case IEEE80211_STYPE_PROBE_RESP:
  551. case IEEE80211_STYPE_BEACON:
  552. case IEEE80211_STYPE_ACTION:
  553. memcpy(skb->cb, rx_status, sizeof(*rx_status));
  554. skb_queue_tail(&ifmsh->skb_queue, skb);
  555. queue_work(local->hw.workqueue, &ifmsh->work);
  556. return RX_QUEUED;
  557. }
  558. return RX_CONTINUE;
  559. }