mesh.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  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. u8 neighbors;
  198. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  199. len = sband->n_bitrates;
  200. if (len > 8)
  201. len = 8;
  202. pos = skb_put(skb, len + 2);
  203. *pos++ = WLAN_EID_SUPP_RATES;
  204. *pos++ = len;
  205. for (i = 0; i < len; i++) {
  206. rate = sband->bitrates[i].bitrate;
  207. *pos++ = (u8) (rate / 5);
  208. }
  209. if (sband->n_bitrates > len) {
  210. pos = skb_put(skb, sband->n_bitrates - len + 2);
  211. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  212. *pos++ = sband->n_bitrates - len;
  213. for (i = len; i < sband->n_bitrates; i++) {
  214. rate = sband->bitrates[i].bitrate;
  215. *pos++ = (u8) (rate / 5);
  216. }
  217. }
  218. if (sband->band == IEEE80211_BAND_2GHZ) {
  219. pos = skb_put(skb, 2 + 1);
  220. *pos++ = WLAN_EID_DS_PARAMS;
  221. *pos++ = 1;
  222. *pos++ = ieee80211_frequency_to_channel(local->hw.conf.channel->center_freq);
  223. }
  224. pos = skb_put(skb, 2 + sdata->u.mesh.mesh_id_len);
  225. *pos++ = WLAN_EID_MESH_ID;
  226. *pos++ = sdata->u.mesh.mesh_id_len;
  227. if (sdata->u.mesh.mesh_id_len)
  228. memcpy(pos, sdata->u.mesh.mesh_id, sdata->u.mesh.mesh_id_len);
  229. pos = skb_put(skb, 2 + IEEE80211_MESH_CONFIG_LEN);
  230. *pos++ = WLAN_EID_MESH_CONFIG;
  231. *pos++ = IEEE80211_MESH_CONFIG_LEN;
  232. /* Active path selection protocol ID */
  233. *pos++ = sdata->u.mesh.mesh_pp_id;
  234. /* Active path selection metric ID */
  235. *pos++ = sdata->u.mesh.mesh_pm_id;
  236. /* Congestion control mode identifier */
  237. *pos++ = sdata->u.mesh.mesh_cc_id;
  238. /* Synchronization protocol identifier */
  239. *pos++ = sdata->u.mesh.mesh_sp_id;
  240. /* Authentication Protocol identifier */
  241. *pos++ = sdata->u.mesh.mesh_auth_id;
  242. /* Mesh Formation Info - number of neighbors */
  243. neighbors = atomic_read(&sdata->u.mesh.mshstats.estab_plinks);
  244. /* Number of neighbor mesh STAs or 15 whichever is smaller */
  245. neighbors = (neighbors > 15) ? 15 : neighbors;
  246. *pos++ = neighbors << 1;
  247. /* Mesh capability */
  248. sdata->u.mesh.accepting_plinks = mesh_plink_availables(sdata);
  249. *pos = MESHCONF_CAPAB_FORWARDING;
  250. *pos++ |= sdata->u.mesh.accepting_plinks ?
  251. MESHCONF_CAPAB_ACCEPT_PLINKS : 0x00;
  252. *pos++ = 0x00;
  253. return;
  254. }
  255. u32 mesh_table_hash(u8 *addr, struct ieee80211_sub_if_data *sdata, struct mesh_table *tbl)
  256. {
  257. /* Use last four bytes of hw addr and interface index as hash index */
  258. return jhash_2words(*(u32 *)(addr+2), sdata->dev->ifindex, tbl->hash_rnd)
  259. & tbl->hash_mask;
  260. }
  261. struct mesh_table *mesh_table_alloc(int size_order)
  262. {
  263. int i;
  264. struct mesh_table *newtbl;
  265. newtbl = kmalloc(sizeof(struct mesh_table), GFP_KERNEL);
  266. if (!newtbl)
  267. return NULL;
  268. newtbl->hash_buckets = kzalloc(sizeof(struct hlist_head) *
  269. (1 << size_order), GFP_KERNEL);
  270. if (!newtbl->hash_buckets) {
  271. kfree(newtbl);
  272. return NULL;
  273. }
  274. newtbl->hashwlock = kmalloc(sizeof(spinlock_t) *
  275. (1 << size_order), GFP_KERNEL);
  276. if (!newtbl->hashwlock) {
  277. kfree(newtbl->hash_buckets);
  278. kfree(newtbl);
  279. return NULL;
  280. }
  281. newtbl->size_order = size_order;
  282. newtbl->hash_mask = (1 << size_order) - 1;
  283. atomic_set(&newtbl->entries, 0);
  284. get_random_bytes(&newtbl->hash_rnd,
  285. sizeof(newtbl->hash_rnd));
  286. for (i = 0; i <= newtbl->hash_mask; i++)
  287. spin_lock_init(&newtbl->hashwlock[i]);
  288. return newtbl;
  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. if (local->quiescing) {
  297. set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
  298. return;
  299. }
  300. ieee80211_queue_work(&local->hw, &ifmsh->work);
  301. }
  302. /**
  303. * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame
  304. * @hdr: 802.11 frame header
  305. * @fc: frame control field
  306. * @meshda: destination address in the mesh
  307. * @meshsa: source address address in the mesh. Same as TA, as frame is
  308. * locally originated.
  309. *
  310. * Return the length of the 802.11 (does not include a mesh control header)
  311. */
  312. int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc, char
  313. *meshda, char *meshsa) {
  314. if (is_multicast_ether_addr(meshda)) {
  315. *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
  316. /* DA TA SA */
  317. memcpy(hdr->addr1, meshda, ETH_ALEN);
  318. memcpy(hdr->addr2, meshsa, ETH_ALEN);
  319. memcpy(hdr->addr3, meshsa, ETH_ALEN);
  320. return 24;
  321. } else {
  322. *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
  323. IEEE80211_FCTL_TODS);
  324. /* RA TA DA SA */
  325. memset(hdr->addr1, 0, ETH_ALEN); /* RA is resolved later */
  326. memcpy(hdr->addr2, meshsa, ETH_ALEN);
  327. memcpy(hdr->addr3, meshda, ETH_ALEN);
  328. memcpy(hdr->addr4, meshsa, ETH_ALEN);
  329. return 30;
  330. }
  331. }
  332. /**
  333. * ieee80211_new_mesh_header - create a new mesh header
  334. * @meshhdr: uninitialized mesh header
  335. * @sdata: mesh interface to be used
  336. * @addr4: addr4 of the mesh frame (1st in ae header)
  337. * may be NULL
  338. * @addr5: addr5 of the mesh frame (1st or 2nd in ae header)
  339. * may be NULL unless addr6 is present
  340. * @addr6: addr6 of the mesh frame (2nd or 3rd in ae header)
  341. * may be NULL unless addr5 is present
  342. *
  343. * Return the header length.
  344. */
  345. int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
  346. struct ieee80211_sub_if_data *sdata, char *addr4,
  347. char *addr5, char *addr6)
  348. {
  349. int aelen = 0;
  350. memset(meshhdr, 0, sizeof(meshhdr));
  351. meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
  352. put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum);
  353. sdata->u.mesh.mesh_seqnum++;
  354. if (addr4) {
  355. meshhdr->flags |= MESH_FLAGS_AE_A4;
  356. aelen += ETH_ALEN;
  357. memcpy(meshhdr->eaddr1, addr4, ETH_ALEN);
  358. }
  359. if (addr5 && addr6) {
  360. meshhdr->flags |= MESH_FLAGS_AE_A5_A6;
  361. aelen += 2 * ETH_ALEN;
  362. if (!addr4) {
  363. memcpy(meshhdr->eaddr1, addr5, ETH_ALEN);
  364. memcpy(meshhdr->eaddr2, addr6, ETH_ALEN);
  365. } else {
  366. memcpy(meshhdr->eaddr2, addr5, ETH_ALEN);
  367. memcpy(meshhdr->eaddr3, addr6, ETH_ALEN);
  368. }
  369. }
  370. return 6 + aelen;
  371. }
  372. static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
  373. struct ieee80211_if_mesh *ifmsh)
  374. {
  375. bool free_plinks;
  376. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  377. printk(KERN_DEBUG "%s: running mesh housekeeping\n",
  378. sdata->dev->name);
  379. #endif
  380. ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
  381. mesh_path_expire(sdata);
  382. free_plinks = mesh_plink_availables(sdata);
  383. if (free_plinks != sdata->u.mesh.accepting_plinks)
  384. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
  385. mod_timer(&ifmsh->housekeeping_timer,
  386. round_jiffies(jiffies + IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
  387. }
  388. #ifdef CONFIG_PM
  389. void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata)
  390. {
  391. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  392. /* might restart the timer but that doesn't matter */
  393. cancel_work_sync(&ifmsh->work);
  394. /* use atomic bitops in case both timers fire at the same time */
  395. if (del_timer_sync(&ifmsh->housekeeping_timer))
  396. set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
  397. if (del_timer_sync(&ifmsh->mesh_path_timer))
  398. set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
  399. }
  400. void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata)
  401. {
  402. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  403. if (test_and_clear_bit(TMR_RUNNING_HK, &ifmsh->timers_running))
  404. add_timer(&ifmsh->housekeeping_timer);
  405. if (test_and_clear_bit(TMR_RUNNING_MP, &ifmsh->timers_running))
  406. add_timer(&ifmsh->mesh_path_timer);
  407. }
  408. #endif
  409. void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
  410. {
  411. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  412. struct ieee80211_local *local = sdata->local;
  413. set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
  414. ieee80211_queue_work(&local->hw, &ifmsh->work);
  415. sdata->vif.bss_conf.beacon_int = MESH_DEFAULT_BEACON_INTERVAL;
  416. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON |
  417. BSS_CHANGED_BEACON_ENABLED |
  418. BSS_CHANGED_BEACON_INT);
  419. }
  420. void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
  421. {
  422. del_timer_sync(&sdata->u.mesh.housekeeping_timer);
  423. /*
  424. * If the timer fired while we waited for it, it will have
  425. * requeued the work. Now the work will be running again
  426. * but will not rearm the timer again because it checks
  427. * whether the interface is running, which, at this point,
  428. * it no longer is.
  429. */
  430. cancel_work_sync(&sdata->u.mesh.work);
  431. /*
  432. * When we get here, the interface is marked down.
  433. * Call synchronize_rcu() to wait for the RX path
  434. * should it be using the interface and enqueuing
  435. * frames at this very time on another CPU.
  436. */
  437. rcu_barrier(); /* Wait for RX path and call_rcu()'s */
  438. skb_queue_purge(&sdata->u.mesh.skb_queue);
  439. }
  440. static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
  441. u16 stype,
  442. struct ieee80211_mgmt *mgmt,
  443. size_t len,
  444. struct ieee80211_rx_status *rx_status)
  445. {
  446. struct ieee80211_local *local = sdata->local;
  447. struct ieee802_11_elems elems;
  448. struct ieee80211_channel *channel;
  449. u32 supp_rates = 0;
  450. size_t baselen;
  451. int freq;
  452. enum ieee80211_band band = rx_status->band;
  453. /* ignore ProbeResp to foreign address */
  454. if (stype == IEEE80211_STYPE_PROBE_RESP &&
  455. compare_ether_addr(mgmt->da, sdata->dev->dev_addr))
  456. return;
  457. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  458. if (baselen > len)
  459. return;
  460. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  461. &elems);
  462. if (elems.ds_params && elems.ds_params_len == 1)
  463. freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
  464. else
  465. freq = rx_status->freq;
  466. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  467. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  468. return;
  469. if (elems.mesh_id && elems.mesh_config &&
  470. mesh_matches_local(&elems, sdata)) {
  471. supp_rates = ieee80211_sta_get_rates(local, &elems, band);
  472. mesh_neighbour_update(mgmt->sa, supp_rates, sdata,
  473. mesh_peer_accepts_plinks(&elems));
  474. }
  475. }
  476. static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
  477. struct ieee80211_mgmt *mgmt,
  478. size_t len,
  479. struct ieee80211_rx_status *rx_status)
  480. {
  481. switch (mgmt->u.action.category) {
  482. case MESH_PLINK_CATEGORY:
  483. mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
  484. break;
  485. case MESH_PATH_SEL_CATEGORY:
  486. mesh_rx_path_sel_frame(sdata, mgmt, len);
  487. break;
  488. }
  489. }
  490. static void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  491. struct sk_buff *skb)
  492. {
  493. struct ieee80211_rx_status *rx_status;
  494. struct ieee80211_if_mesh *ifmsh;
  495. struct ieee80211_mgmt *mgmt;
  496. u16 stype;
  497. ifmsh = &sdata->u.mesh;
  498. rx_status = IEEE80211_SKB_RXCB(skb);
  499. mgmt = (struct ieee80211_mgmt *) skb->data;
  500. stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
  501. switch (stype) {
  502. case IEEE80211_STYPE_PROBE_RESP:
  503. case IEEE80211_STYPE_BEACON:
  504. ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len,
  505. rx_status);
  506. break;
  507. case IEEE80211_STYPE_ACTION:
  508. ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status);
  509. break;
  510. }
  511. kfree_skb(skb);
  512. }
  513. static void ieee80211_mesh_work(struct work_struct *work)
  514. {
  515. struct ieee80211_sub_if_data *sdata =
  516. container_of(work, struct ieee80211_sub_if_data, u.mesh.work);
  517. struct ieee80211_local *local = sdata->local;
  518. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  519. struct sk_buff *skb;
  520. if (!netif_running(sdata->dev))
  521. return;
  522. if (local->scanning)
  523. return;
  524. while ((skb = skb_dequeue(&ifmsh->skb_queue)))
  525. ieee80211_mesh_rx_queued_mgmt(sdata, skb);
  526. if (ifmsh->preq_queue_len &&
  527. time_after(jiffies,
  528. ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval)))
  529. mesh_path_start_discovery(sdata);
  530. if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags))
  531. mesh_mpath_table_grow();
  532. if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags))
  533. mesh_mpp_table_grow();
  534. if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags))
  535. ieee80211_mesh_housekeeping(sdata, ifmsh);
  536. }
  537. void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local)
  538. {
  539. struct ieee80211_sub_if_data *sdata;
  540. rcu_read_lock();
  541. list_for_each_entry_rcu(sdata, &local->interfaces, list)
  542. if (ieee80211_vif_is_mesh(&sdata->vif))
  543. ieee80211_queue_work(&local->hw, &sdata->u.mesh.work);
  544. rcu_read_unlock();
  545. }
  546. void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
  547. {
  548. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  549. INIT_WORK(&ifmsh->work, ieee80211_mesh_work);
  550. setup_timer(&ifmsh->housekeeping_timer,
  551. ieee80211_mesh_housekeeping_timer,
  552. (unsigned long) sdata);
  553. skb_queue_head_init(&sdata->u.mesh.skb_queue);
  554. ifmsh->mshcfg.dot11MeshRetryTimeout = MESH_RET_T;
  555. ifmsh->mshcfg.dot11MeshConfirmTimeout = MESH_CONF_T;
  556. ifmsh->mshcfg.dot11MeshHoldingTimeout = MESH_HOLD_T;
  557. ifmsh->mshcfg.dot11MeshMaxRetries = MESH_MAX_RETR;
  558. ifmsh->mshcfg.dot11MeshTTL = MESH_TTL;
  559. ifmsh->mshcfg.auto_open_plinks = true;
  560. ifmsh->mshcfg.dot11MeshMaxPeerLinks =
  561. MESH_MAX_ESTAB_PLINKS;
  562. ifmsh->mshcfg.dot11MeshHWMPactivePathTimeout =
  563. MESH_PATH_TIMEOUT;
  564. ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval =
  565. MESH_PREQ_MIN_INT;
  566. ifmsh->mshcfg.dot11MeshHWMPnetDiameterTraversalTime =
  567. MESH_DIAM_TRAVERSAL_TIME;
  568. ifmsh->mshcfg.dot11MeshHWMPmaxPREQretries =
  569. MESH_MAX_PREQ_RETRIES;
  570. ifmsh->mshcfg.path_refresh_time =
  571. MESH_PATH_REFRESH_TIME;
  572. ifmsh->mshcfg.min_discovery_timeout =
  573. MESH_MIN_DISCOVERY_TIMEOUT;
  574. ifmsh->accepting_plinks = true;
  575. ifmsh->preq_id = 0;
  576. ifmsh->sn = 0;
  577. atomic_set(&ifmsh->mpaths, 0);
  578. mesh_rmc_init(sdata);
  579. ifmsh->last_preq = jiffies;
  580. /* Allocate all mesh structures when creating the first mesh interface. */
  581. if (!mesh_allocated)
  582. ieee80211s_init();
  583. mesh_ids_set_default(ifmsh);
  584. setup_timer(&ifmsh->mesh_path_timer,
  585. ieee80211_mesh_path_timer,
  586. (unsigned long) sdata);
  587. INIT_LIST_HEAD(&ifmsh->preq_queue.list);
  588. spin_lock_init(&ifmsh->mesh_preq_queue_lock);
  589. }
  590. ieee80211_rx_result
  591. ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
  592. {
  593. struct ieee80211_local *local = sdata->local;
  594. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  595. struct ieee80211_mgmt *mgmt;
  596. u16 fc;
  597. if (skb->len < 24)
  598. return RX_DROP_MONITOR;
  599. mgmt = (struct ieee80211_mgmt *) skb->data;
  600. fc = le16_to_cpu(mgmt->frame_control);
  601. switch (fc & IEEE80211_FCTL_STYPE) {
  602. case IEEE80211_STYPE_ACTION:
  603. if (skb->len < IEEE80211_MIN_ACTION_SIZE)
  604. return RX_DROP_MONITOR;
  605. /* fall through */
  606. case IEEE80211_STYPE_PROBE_RESP:
  607. case IEEE80211_STYPE_BEACON:
  608. skb_queue_tail(&ifmsh->skb_queue, skb);
  609. ieee80211_queue_work(&local->hw, &ifmsh->work);
  610. return RX_QUEUED;
  611. }
  612. return RX_CONTINUE;
  613. }