mesh.c 19 KB

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