mesh.c 20 KB

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