mesh.c 22 KB

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