mesh.c 20 KB

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