mesh.c 20 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->wrkq_flags |= MESH_WORK_HOUSEKEEPING;
  42. if (local->quiescing) {
  43. set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
  44. return;
  45. }
  46. ieee80211_queue_work(&local->hw, &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 ieee80211_mesh_path_timer(unsigned long data)
  275. {
  276. struct ieee80211_sub_if_data *sdata =
  277. (struct ieee80211_sub_if_data *) data;
  278. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  279. struct ieee80211_local *local = sdata->local;
  280. if (local->quiescing) {
  281. set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
  282. return;
  283. }
  284. ieee80211_queue_work(&local->hw, &ifmsh->work);
  285. }
  286. /**
  287. * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame
  288. * @hdr: 802.11 frame header
  289. * @fc: frame control field
  290. * @meshda: destination address in the mesh
  291. * @meshsa: source address address in the mesh. Same as TA, as frame is
  292. * locally originated.
  293. *
  294. * Return the length of the 802.11 (does not include a mesh control header)
  295. */
  296. int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc, char
  297. *meshda, char *meshsa) {
  298. if (is_multicast_ether_addr(meshda)) {
  299. *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
  300. /* DA TA SA */
  301. memcpy(hdr->addr1, meshda, ETH_ALEN);
  302. memcpy(hdr->addr2, meshsa, ETH_ALEN);
  303. memcpy(hdr->addr3, meshsa, ETH_ALEN);
  304. return 24;
  305. } else {
  306. *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
  307. IEEE80211_FCTL_TODS);
  308. /* RA TA DA SA */
  309. memset(hdr->addr1, 0, ETH_ALEN); /* RA is resolved later */
  310. memcpy(hdr->addr2, meshsa, ETH_ALEN);
  311. memcpy(hdr->addr3, meshda, ETH_ALEN);
  312. memcpy(hdr->addr4, meshsa, ETH_ALEN);
  313. return 30;
  314. }
  315. }
  316. /**
  317. * ieee80211_new_mesh_header - create a new mesh header
  318. * @meshhdr: uninitialized mesh header
  319. * @sdata: mesh interface to be used
  320. * @addr4: addr4 of the mesh frame (1st in ae header)
  321. * may be NULL
  322. * @addr5: addr5 of the mesh frame (1st or 2nd in ae header)
  323. * may be NULL unless addr6 is present
  324. * @addr6: addr6 of the mesh frame (2nd or 3rd in ae header)
  325. * may be NULL unless addr5 is present
  326. *
  327. * Return the header length.
  328. */
  329. int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
  330. struct ieee80211_sub_if_data *sdata, char *addr4,
  331. char *addr5, char *addr6)
  332. {
  333. int aelen = 0;
  334. memset(meshhdr, 0, sizeof(meshhdr));
  335. meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
  336. put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum);
  337. sdata->u.mesh.mesh_seqnum++;
  338. if (addr4) {
  339. meshhdr->flags |= MESH_FLAGS_AE_A4;
  340. aelen += ETH_ALEN;
  341. memcpy(meshhdr->eaddr1, addr4, ETH_ALEN);
  342. }
  343. if (addr5 && addr6) {
  344. meshhdr->flags |= MESH_FLAGS_AE_A5_A6;
  345. aelen += 2 * ETH_ALEN;
  346. if (!addr4) {
  347. memcpy(meshhdr->eaddr1, addr5, ETH_ALEN);
  348. memcpy(meshhdr->eaddr2, addr6, ETH_ALEN);
  349. } else {
  350. memcpy(meshhdr->eaddr2, addr5, ETH_ALEN);
  351. memcpy(meshhdr->eaddr3, addr6, ETH_ALEN);
  352. }
  353. }
  354. return 6 + aelen;
  355. }
  356. static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
  357. struct ieee80211_if_mesh *ifmsh)
  358. {
  359. bool free_plinks;
  360. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  361. printk(KERN_DEBUG "%s: running mesh housekeeping\n",
  362. sdata->dev->name);
  363. #endif
  364. ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
  365. mesh_path_expire(sdata);
  366. free_plinks = mesh_plink_availables(sdata);
  367. if (free_plinks != sdata->u.mesh.accepting_plinks)
  368. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
  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->wrkq_flags |= MESH_WORK_HOUSEKEEPING;
  398. ieee80211_queue_work(&local->hw, &ifmsh->work);
  399. sdata->vif.bss_conf.beacon_int = MESH_DEFAULT_BEACON_INTERVAL;
  400. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON |
  401. BSS_CHANGED_BEACON_ENABLED |
  402. BSS_CHANGED_BEACON_INT);
  403. }
  404. void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
  405. {
  406. del_timer_sync(&sdata->u.mesh.housekeeping_timer);
  407. /*
  408. * If the timer fired while we waited for it, it will have
  409. * requeued the work. Now the work will be running again
  410. * but will not rearm the timer again because it checks
  411. * whether the interface is running, which, at this point,
  412. * it no longer is.
  413. */
  414. cancel_work_sync(&sdata->u.mesh.work);
  415. /*
  416. * When we get here, the interface is marked down.
  417. * Call synchronize_rcu() to wait for the RX path
  418. * should it be using the interface and enqueuing
  419. * frames at this very time on another CPU.
  420. */
  421. rcu_barrier(); /* Wait for RX path and call_rcu()'s */
  422. skb_queue_purge(&sdata->u.mesh.skb_queue);
  423. }
  424. static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
  425. u16 stype,
  426. struct ieee80211_mgmt *mgmt,
  427. size_t len,
  428. struct ieee80211_rx_status *rx_status)
  429. {
  430. struct ieee80211_local *local = sdata->local;
  431. struct ieee802_11_elems elems;
  432. struct ieee80211_channel *channel;
  433. u32 supp_rates = 0;
  434. size_t baselen;
  435. int freq;
  436. enum ieee80211_band band = rx_status->band;
  437. /* ignore ProbeResp to foreign address */
  438. if (stype == IEEE80211_STYPE_PROBE_RESP &&
  439. compare_ether_addr(mgmt->da, sdata->dev->dev_addr))
  440. return;
  441. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  442. if (baselen > len)
  443. return;
  444. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  445. &elems);
  446. if (elems.ds_params && elems.ds_params_len == 1)
  447. freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
  448. else
  449. freq = rx_status->freq;
  450. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  451. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  452. return;
  453. if (elems.mesh_id && elems.mesh_config &&
  454. mesh_matches_local(&elems, sdata)) {
  455. supp_rates = ieee80211_sta_get_rates(local, &elems, band);
  456. mesh_neighbour_update(mgmt->sa, supp_rates, sdata,
  457. mesh_peer_accepts_plinks(&elems));
  458. }
  459. }
  460. static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
  461. struct ieee80211_mgmt *mgmt,
  462. size_t len,
  463. struct ieee80211_rx_status *rx_status)
  464. {
  465. switch (mgmt->u.action.category) {
  466. case PLINK_CATEGORY:
  467. mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
  468. break;
  469. case MESH_PATH_SEL_CATEGORY:
  470. mesh_rx_path_sel_frame(sdata, mgmt, len);
  471. break;
  472. }
  473. }
  474. static void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  475. struct sk_buff *skb)
  476. {
  477. struct ieee80211_rx_status *rx_status;
  478. struct ieee80211_if_mesh *ifmsh;
  479. struct ieee80211_mgmt *mgmt;
  480. u16 stype;
  481. ifmsh = &sdata->u.mesh;
  482. rx_status = IEEE80211_SKB_RXCB(skb);
  483. mgmt = (struct ieee80211_mgmt *) skb->data;
  484. stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
  485. switch (stype) {
  486. case IEEE80211_STYPE_PROBE_RESP:
  487. case IEEE80211_STYPE_BEACON:
  488. ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len,
  489. rx_status);
  490. break;
  491. case IEEE80211_STYPE_ACTION:
  492. ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status);
  493. break;
  494. }
  495. kfree_skb(skb);
  496. }
  497. static void ieee80211_mesh_work(struct work_struct *work)
  498. {
  499. struct ieee80211_sub_if_data *sdata =
  500. container_of(work, struct ieee80211_sub_if_data, u.mesh.work);
  501. struct ieee80211_local *local = sdata->local;
  502. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  503. struct sk_buff *skb;
  504. if (!netif_running(sdata->dev))
  505. return;
  506. if (local->scanning)
  507. return;
  508. while ((skb = skb_dequeue(&ifmsh->skb_queue)))
  509. ieee80211_mesh_rx_queued_mgmt(sdata, skb);
  510. if (ifmsh->preq_queue_len &&
  511. time_after(jiffies,
  512. ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval)))
  513. mesh_path_start_discovery(sdata);
  514. if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags))
  515. mesh_mpath_table_grow();
  516. if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags))
  517. mesh_mpp_table_grow();
  518. if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags))
  519. ieee80211_mesh_housekeeping(sdata, ifmsh);
  520. }
  521. void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local)
  522. {
  523. struct ieee80211_sub_if_data *sdata;
  524. rcu_read_lock();
  525. list_for_each_entry_rcu(sdata, &local->interfaces, list)
  526. if (ieee80211_vif_is_mesh(&sdata->vif))
  527. ieee80211_queue_work(&local->hw, &sdata->u.mesh.work);
  528. rcu_read_unlock();
  529. }
  530. void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
  531. {
  532. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  533. INIT_WORK(&ifmsh->work, ieee80211_mesh_work);
  534. setup_timer(&ifmsh->housekeeping_timer,
  535. ieee80211_mesh_housekeeping_timer,
  536. (unsigned long) sdata);
  537. skb_queue_head_init(&sdata->u.mesh.skb_queue);
  538. ifmsh->mshcfg.dot11MeshRetryTimeout = MESH_RET_T;
  539. ifmsh->mshcfg.dot11MeshConfirmTimeout = MESH_CONF_T;
  540. ifmsh->mshcfg.dot11MeshHoldingTimeout = MESH_HOLD_T;
  541. ifmsh->mshcfg.dot11MeshMaxRetries = MESH_MAX_RETR;
  542. ifmsh->mshcfg.dot11MeshTTL = MESH_TTL;
  543. ifmsh->mshcfg.auto_open_plinks = true;
  544. ifmsh->mshcfg.dot11MeshMaxPeerLinks =
  545. MESH_MAX_ESTAB_PLINKS;
  546. ifmsh->mshcfg.dot11MeshHWMPactivePathTimeout =
  547. MESH_PATH_TIMEOUT;
  548. ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval =
  549. MESH_PREQ_MIN_INT;
  550. ifmsh->mshcfg.dot11MeshHWMPnetDiameterTraversalTime =
  551. MESH_DIAM_TRAVERSAL_TIME;
  552. ifmsh->mshcfg.dot11MeshHWMPmaxPREQretries =
  553. MESH_MAX_PREQ_RETRIES;
  554. ifmsh->mshcfg.path_refresh_time =
  555. MESH_PATH_REFRESH_TIME;
  556. ifmsh->mshcfg.min_discovery_timeout =
  557. MESH_MIN_DISCOVERY_TIMEOUT;
  558. ifmsh->accepting_plinks = true;
  559. ifmsh->preq_id = 0;
  560. ifmsh->dsn = 0;
  561. atomic_set(&ifmsh->mpaths, 0);
  562. mesh_rmc_init(sdata);
  563. ifmsh->last_preq = jiffies;
  564. /* Allocate all mesh structures when creating the first mesh interface. */
  565. if (!mesh_allocated)
  566. ieee80211s_init();
  567. mesh_ids_set_default(ifmsh);
  568. setup_timer(&ifmsh->mesh_path_timer,
  569. ieee80211_mesh_path_timer,
  570. (unsigned long) sdata);
  571. INIT_LIST_HEAD(&ifmsh->preq_queue.list);
  572. spin_lock_init(&ifmsh->mesh_preq_queue_lock);
  573. }
  574. ieee80211_rx_result
  575. ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
  576. {
  577. struct ieee80211_local *local = sdata->local;
  578. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  579. struct ieee80211_mgmt *mgmt;
  580. u16 fc;
  581. if (skb->len < 24)
  582. return RX_DROP_MONITOR;
  583. mgmt = (struct ieee80211_mgmt *) skb->data;
  584. fc = le16_to_cpu(mgmt->frame_control);
  585. switch (fc & IEEE80211_FCTL_STYPE) {
  586. case IEEE80211_STYPE_ACTION:
  587. if (skb->len < IEEE80211_MIN_ACTION_SIZE)
  588. return RX_DROP_MONITOR;
  589. /* fall through */
  590. case IEEE80211_STYPE_PROBE_RESP:
  591. case IEEE80211_STYPE_BEACON:
  592. skb_queue_tail(&ifmsh->skb_queue, skb);
  593. ieee80211_queue_work(&local->hw, &ifmsh->work);
  594. return RX_QUEUED;
  595. }
  596. return RX_CONTINUE;
  597. }