mesh.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  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, &sdata->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. int mesh_rmc_init(struct ieee80211_sub_if_data *sdata)
  109. {
  110. int i;
  111. sdata->u.mesh.rmc = kmalloc(sizeof(struct mesh_rmc), GFP_KERNEL);
  112. if (!sdata->u.mesh.rmc)
  113. return -ENOMEM;
  114. sdata->u.mesh.rmc->idx_mask = RMC_BUCKETS - 1;
  115. for (i = 0; i < RMC_BUCKETS; i++)
  116. INIT_LIST_HEAD(&sdata->u.mesh.rmc->bucket[i].list);
  117. return 0;
  118. }
  119. void mesh_rmc_free(struct ieee80211_sub_if_data *sdata)
  120. {
  121. struct mesh_rmc *rmc = sdata->u.mesh.rmc;
  122. struct rmc_entry *p, *n;
  123. int i;
  124. if (!sdata->u.mesh.rmc)
  125. return;
  126. for (i = 0; i < RMC_BUCKETS; i++)
  127. list_for_each_entry_safe(p, n, &rmc->bucket[i].list, list) {
  128. list_del(&p->list);
  129. kmem_cache_free(rm_cache, p);
  130. }
  131. kfree(rmc);
  132. sdata->u.mesh.rmc = NULL;
  133. }
  134. /**
  135. * mesh_rmc_check - Check frame in recent multicast cache and add if absent.
  136. *
  137. * @sa: source address
  138. * @mesh_hdr: mesh_header
  139. *
  140. * Returns: 0 if the frame is not in the cache, nonzero otherwise.
  141. *
  142. * Checks using the source address and the mesh sequence number if we have
  143. * received this frame lately. If the frame is not in the cache, it is added to
  144. * it.
  145. */
  146. int mesh_rmc_check(u8 *sa, struct ieee80211s_hdr *mesh_hdr,
  147. struct ieee80211_sub_if_data *sdata)
  148. {
  149. struct mesh_rmc *rmc = sdata->u.mesh.rmc;
  150. u32 seqnum = 0;
  151. int entries = 0;
  152. u8 idx;
  153. struct rmc_entry *p, *n;
  154. /* Don't care about endianness since only match matters */
  155. memcpy(&seqnum, &mesh_hdr->seqnum, sizeof(mesh_hdr->seqnum));
  156. idx = le32_to_cpu(mesh_hdr->seqnum) & rmc->idx_mask;
  157. list_for_each_entry_safe(p, n, &rmc->bucket[idx].list, list) {
  158. ++entries;
  159. if (time_after(jiffies, p->exp_time) ||
  160. (entries == RMC_QUEUE_MAX_LEN)) {
  161. list_del(&p->list);
  162. kmem_cache_free(rm_cache, p);
  163. --entries;
  164. } else if ((seqnum == p->seqnum) &&
  165. (memcmp(sa, p->sa, ETH_ALEN) == 0))
  166. return -1;
  167. }
  168. p = kmem_cache_alloc(rm_cache, GFP_ATOMIC);
  169. if (!p) {
  170. printk(KERN_DEBUG "o11s: could not allocate RMC entry\n");
  171. return 0;
  172. }
  173. p->seqnum = seqnum;
  174. p->exp_time = jiffies + RMC_TIMEOUT;
  175. memcpy(p->sa, sa, ETH_ALEN);
  176. list_add(&p->list, &rmc->bucket[idx].list);
  177. return 0;
  178. }
  179. void mesh_mgmt_ies_add(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
  180. {
  181. struct ieee80211_local *local = sdata->local;
  182. struct ieee80211_supported_band *sband;
  183. u8 *pos;
  184. int len, i, rate;
  185. u8 neighbors;
  186. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  187. len = sband->n_bitrates;
  188. if (len > 8)
  189. len = 8;
  190. pos = skb_put(skb, len + 2);
  191. *pos++ = WLAN_EID_SUPP_RATES;
  192. *pos++ = len;
  193. for (i = 0; i < len; i++) {
  194. rate = sband->bitrates[i].bitrate;
  195. *pos++ = (u8) (rate / 5);
  196. }
  197. if (sband->n_bitrates > len) {
  198. pos = skb_put(skb, sband->n_bitrates - len + 2);
  199. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  200. *pos++ = sband->n_bitrates - len;
  201. for (i = len; i < sband->n_bitrates; i++) {
  202. rate = sband->bitrates[i].bitrate;
  203. *pos++ = (u8) (rate / 5);
  204. }
  205. }
  206. if (sband->band == IEEE80211_BAND_2GHZ) {
  207. pos = skb_put(skb, 2 + 1);
  208. *pos++ = WLAN_EID_DS_PARAMS;
  209. *pos++ = 1;
  210. *pos++ = ieee80211_frequency_to_channel(local->hw.conf.channel->center_freq);
  211. }
  212. pos = skb_put(skb, 2 + sdata->u.mesh.mesh_id_len);
  213. *pos++ = WLAN_EID_MESH_ID;
  214. *pos++ = sdata->u.mesh.mesh_id_len;
  215. if (sdata->u.mesh.mesh_id_len)
  216. memcpy(pos, sdata->u.mesh.mesh_id, sdata->u.mesh.mesh_id_len);
  217. pos = skb_put(skb, 2 + sizeof(struct ieee80211_meshconf_ie));
  218. *pos++ = WLAN_EID_MESH_CONFIG;
  219. *pos++ = sizeof(struct ieee80211_meshconf_ie);
  220. /* Active path selection protocol ID */
  221. *pos++ = sdata->u.mesh.mesh_pp_id;
  222. /* Active path selection metric ID */
  223. *pos++ = sdata->u.mesh.mesh_pm_id;
  224. /* Congestion control mode identifier */
  225. *pos++ = sdata->u.mesh.mesh_cc_id;
  226. /* Synchronization protocol identifier */
  227. *pos++ = sdata->u.mesh.mesh_sp_id;
  228. /* Authentication Protocol identifier */
  229. *pos++ = sdata->u.mesh.mesh_auth_id;
  230. /* Mesh Formation Info - number of neighbors */
  231. neighbors = atomic_read(&sdata->u.mesh.mshstats.estab_plinks);
  232. /* Number of neighbor mesh STAs or 15 whichever is smaller */
  233. neighbors = (neighbors > 15) ? 15 : neighbors;
  234. *pos++ = neighbors << 1;
  235. /* Mesh capability */
  236. sdata->u.mesh.accepting_plinks = mesh_plink_availables(sdata);
  237. *pos = MESHCONF_CAPAB_FORWARDING;
  238. *pos++ |= sdata->u.mesh.accepting_plinks ?
  239. MESHCONF_CAPAB_ACCEPT_PLINKS : 0x00;
  240. *pos++ = 0x00;
  241. if (sdata->u.mesh.vendor_ie) {
  242. int len = sdata->u.mesh.vendor_ie_len;
  243. const u8 *data = sdata->u.mesh.vendor_ie;
  244. if (skb_tailroom(skb) > len)
  245. memcpy(skb_put(skb, len), data, len);
  246. }
  247. }
  248. u32 mesh_table_hash(u8 *addr, struct ieee80211_sub_if_data *sdata, struct mesh_table *tbl)
  249. {
  250. /* Use last four bytes of hw addr and interface index as hash index */
  251. return jhash_2words(*(u32 *)(addr+2), sdata->dev->ifindex, tbl->hash_rnd)
  252. & tbl->hash_mask;
  253. }
  254. struct mesh_table *mesh_table_alloc(int size_order)
  255. {
  256. int i;
  257. struct mesh_table *newtbl;
  258. newtbl = kmalloc(sizeof(struct mesh_table), GFP_KERNEL);
  259. if (!newtbl)
  260. return NULL;
  261. newtbl->hash_buckets = kzalloc(sizeof(struct hlist_head) *
  262. (1 << size_order), GFP_KERNEL);
  263. if (!newtbl->hash_buckets) {
  264. kfree(newtbl);
  265. return NULL;
  266. }
  267. newtbl->hashwlock = kmalloc(sizeof(spinlock_t) *
  268. (1 << size_order), GFP_KERNEL);
  269. if (!newtbl->hashwlock) {
  270. kfree(newtbl->hash_buckets);
  271. kfree(newtbl);
  272. return NULL;
  273. }
  274. newtbl->size_order = size_order;
  275. newtbl->hash_mask = (1 << size_order) - 1;
  276. atomic_set(&newtbl->entries, 0);
  277. get_random_bytes(&newtbl->hash_rnd,
  278. sizeof(newtbl->hash_rnd));
  279. for (i = 0; i <= newtbl->hash_mask; i++)
  280. spin_lock_init(&newtbl->hashwlock[i]);
  281. return newtbl;
  282. }
  283. static void ieee80211_mesh_path_timer(unsigned long data)
  284. {
  285. struct ieee80211_sub_if_data *sdata =
  286. (struct ieee80211_sub_if_data *) data;
  287. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  288. struct ieee80211_local *local = sdata->local;
  289. if (local->quiescing) {
  290. set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
  291. return;
  292. }
  293. ieee80211_queue_work(&local->hw, &sdata->work);
  294. }
  295. static void ieee80211_mesh_path_root_timer(unsigned long data)
  296. {
  297. struct ieee80211_sub_if_data *sdata =
  298. (struct ieee80211_sub_if_data *) data;
  299. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  300. struct ieee80211_local *local = sdata->local;
  301. set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
  302. if (local->quiescing) {
  303. set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running);
  304. return;
  305. }
  306. ieee80211_queue_work(&local->hw, &sdata->work);
  307. }
  308. void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh)
  309. {
  310. if (ifmsh->mshcfg.dot11MeshHWMPRootMode)
  311. set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
  312. else {
  313. clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
  314. /* stop running timer */
  315. del_timer_sync(&ifmsh->mesh_path_root_timer);
  316. }
  317. }
  318. /**
  319. * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame
  320. * @hdr: 802.11 frame header
  321. * @fc: frame control field
  322. * @meshda: destination address in the mesh
  323. * @meshsa: source address address in the mesh. Same as TA, as frame is
  324. * locally originated.
  325. *
  326. * Return the length of the 802.11 (does not include a mesh control header)
  327. */
  328. int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc,
  329. const u8 *meshda, const u8 *meshsa)
  330. {
  331. if (is_multicast_ether_addr(meshda)) {
  332. *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
  333. /* DA TA SA */
  334. memcpy(hdr->addr1, meshda, ETH_ALEN);
  335. memcpy(hdr->addr2, meshsa, ETH_ALEN);
  336. memcpy(hdr->addr3, meshsa, ETH_ALEN);
  337. return 24;
  338. } else {
  339. *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
  340. IEEE80211_FCTL_TODS);
  341. /* RA TA DA SA */
  342. memset(hdr->addr1, 0, ETH_ALEN); /* RA is resolved later */
  343. memcpy(hdr->addr2, meshsa, ETH_ALEN);
  344. memcpy(hdr->addr3, meshda, ETH_ALEN);
  345. memcpy(hdr->addr4, meshsa, ETH_ALEN);
  346. return 30;
  347. }
  348. }
  349. /**
  350. * ieee80211_new_mesh_header - create a new mesh header
  351. * @meshhdr: uninitialized mesh header
  352. * @sdata: mesh interface to be used
  353. * @addr4or5: 1st address in the ae header, which may correspond to address 4
  354. * (if addr6 is NULL) or address 5 (if addr6 is present). It may
  355. * be NULL.
  356. * @addr6: 2nd address in the ae header, which corresponds to addr6 of the
  357. * mesh frame
  358. *
  359. * Return the header length.
  360. */
  361. int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
  362. struct ieee80211_sub_if_data *sdata, char *addr4or5,
  363. char *addr6)
  364. {
  365. int aelen = 0;
  366. BUG_ON(!addr4or5 && addr6);
  367. memset(meshhdr, 0, sizeof(*meshhdr));
  368. meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
  369. put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum);
  370. sdata->u.mesh.mesh_seqnum++;
  371. if (addr4or5 && !addr6) {
  372. meshhdr->flags |= MESH_FLAGS_AE_A4;
  373. aelen += ETH_ALEN;
  374. memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN);
  375. } else if (addr4or5 && addr6) {
  376. meshhdr->flags |= MESH_FLAGS_AE_A5_A6;
  377. aelen += 2 * ETH_ALEN;
  378. memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN);
  379. memcpy(meshhdr->eaddr2, addr6, ETH_ALEN);
  380. }
  381. return 6 + aelen;
  382. }
  383. static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
  384. struct ieee80211_if_mesh *ifmsh)
  385. {
  386. bool free_plinks;
  387. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  388. printk(KERN_DEBUG "%s: running mesh housekeeping\n",
  389. sdata->name);
  390. #endif
  391. ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
  392. mesh_path_expire(sdata);
  393. free_plinks = mesh_plink_availables(sdata);
  394. if (free_plinks != sdata->u.mesh.accepting_plinks)
  395. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
  396. mod_timer(&ifmsh->housekeeping_timer,
  397. round_jiffies(jiffies + IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
  398. }
  399. static void ieee80211_mesh_rootpath(struct ieee80211_sub_if_data *sdata)
  400. {
  401. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  402. mesh_path_tx_root_frame(sdata);
  403. mod_timer(&ifmsh->mesh_path_root_timer,
  404. round_jiffies(jiffies + IEEE80211_MESH_RANN_INTERVAL));
  405. }
  406. #ifdef CONFIG_PM
  407. void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata)
  408. {
  409. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  410. /* use atomic bitops in case both timers fire at the same time */
  411. if (del_timer_sync(&ifmsh->housekeeping_timer))
  412. set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
  413. if (del_timer_sync(&ifmsh->mesh_path_timer))
  414. set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
  415. if (del_timer_sync(&ifmsh->mesh_path_root_timer))
  416. set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running);
  417. }
  418. void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata)
  419. {
  420. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  421. if (test_and_clear_bit(TMR_RUNNING_HK, &ifmsh->timers_running))
  422. add_timer(&ifmsh->housekeeping_timer);
  423. if (test_and_clear_bit(TMR_RUNNING_MP, &ifmsh->timers_running))
  424. add_timer(&ifmsh->mesh_path_timer);
  425. if (test_and_clear_bit(TMR_RUNNING_MPR, &ifmsh->timers_running))
  426. add_timer(&ifmsh->mesh_path_root_timer);
  427. ieee80211_mesh_root_setup(ifmsh);
  428. }
  429. #endif
  430. void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
  431. {
  432. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  433. struct ieee80211_local *local = sdata->local;
  434. local->fif_other_bss++;
  435. /* mesh ifaces must set allmulti to forward mcast traffic */
  436. atomic_inc(&local->iff_allmultis);
  437. ieee80211_configure_filter(local);
  438. ifmsh->mesh_cc_id = 0; /* Disabled */
  439. ifmsh->mesh_sp_id = 0; /* Neighbor Offset */
  440. ifmsh->mesh_auth_id = 0; /* Disabled */
  441. set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
  442. ieee80211_mesh_root_setup(ifmsh);
  443. ieee80211_queue_work(&local->hw, &sdata->work);
  444. sdata->vif.bss_conf.beacon_int = MESH_DEFAULT_BEACON_INTERVAL;
  445. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON |
  446. BSS_CHANGED_BEACON_ENABLED |
  447. BSS_CHANGED_BEACON_INT);
  448. }
  449. void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
  450. {
  451. struct ieee80211_local *local = sdata->local;
  452. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  453. ifmsh->mesh_id_len = 0;
  454. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  455. sta_info_flush(local, NULL);
  456. del_timer_sync(&sdata->u.mesh.housekeeping_timer);
  457. del_timer_sync(&sdata->u.mesh.mesh_path_root_timer);
  458. /*
  459. * If the timer fired while we waited for it, it will have
  460. * requeued the work. Now the work will be running again
  461. * but will not rearm the timer again because it checks
  462. * whether the interface is running, which, at this point,
  463. * it no longer is.
  464. */
  465. cancel_work_sync(&sdata->work);
  466. local->fif_other_bss--;
  467. atomic_dec(&local->iff_allmultis);
  468. ieee80211_configure_filter(local);
  469. }
  470. static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
  471. u16 stype,
  472. struct ieee80211_mgmt *mgmt,
  473. size_t len,
  474. struct ieee80211_rx_status *rx_status)
  475. {
  476. struct ieee80211_local *local = sdata->local;
  477. struct ieee802_11_elems elems;
  478. struct ieee80211_channel *channel;
  479. u32 supp_rates = 0;
  480. size_t baselen;
  481. int freq;
  482. enum ieee80211_band band = rx_status->band;
  483. /* ignore ProbeResp to foreign address */
  484. if (stype == IEEE80211_STYPE_PROBE_RESP &&
  485. compare_ether_addr(mgmt->da, sdata->vif.addr))
  486. return;
  487. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  488. if (baselen > len)
  489. return;
  490. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  491. &elems);
  492. if (elems.ds_params && elems.ds_params_len == 1)
  493. freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
  494. else
  495. freq = rx_status->freq;
  496. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  497. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  498. return;
  499. if (elems.mesh_id && elems.mesh_config &&
  500. mesh_matches_local(&elems, sdata)) {
  501. supp_rates = ieee80211_sta_get_rates(local, &elems, band);
  502. mesh_neighbour_update(mgmt->sa, supp_rates, sdata,
  503. mesh_peer_accepts_plinks(&elems));
  504. }
  505. }
  506. static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
  507. struct ieee80211_mgmt *mgmt,
  508. size_t len,
  509. struct ieee80211_rx_status *rx_status)
  510. {
  511. switch (mgmt->u.action.category) {
  512. case WLAN_CATEGORY_MESH_PLINK:
  513. mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
  514. break;
  515. case WLAN_CATEGORY_MESH_PATH_SEL:
  516. mesh_rx_path_sel_frame(sdata, mgmt, len);
  517. break;
  518. }
  519. }
  520. void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  521. struct sk_buff *skb)
  522. {
  523. struct ieee80211_rx_status *rx_status;
  524. struct ieee80211_if_mesh *ifmsh;
  525. struct ieee80211_mgmt *mgmt;
  526. u16 stype;
  527. ifmsh = &sdata->u.mesh;
  528. rx_status = IEEE80211_SKB_RXCB(skb);
  529. mgmt = (struct ieee80211_mgmt *) skb->data;
  530. stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
  531. switch (stype) {
  532. case IEEE80211_STYPE_PROBE_RESP:
  533. case IEEE80211_STYPE_BEACON:
  534. ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len,
  535. rx_status);
  536. break;
  537. case IEEE80211_STYPE_ACTION:
  538. ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status);
  539. break;
  540. }
  541. }
  542. void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata)
  543. {
  544. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  545. if (ifmsh->preq_queue_len &&
  546. time_after(jiffies,
  547. ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval)))
  548. mesh_path_start_discovery(sdata);
  549. if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags))
  550. mesh_mpath_table_grow();
  551. if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags))
  552. mesh_mpp_table_grow();
  553. if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags))
  554. ieee80211_mesh_housekeeping(sdata, ifmsh);
  555. if (test_and_clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags))
  556. ieee80211_mesh_rootpath(sdata);
  557. }
  558. void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local)
  559. {
  560. struct ieee80211_sub_if_data *sdata;
  561. rcu_read_lock();
  562. list_for_each_entry_rcu(sdata, &local->interfaces, list)
  563. if (ieee80211_vif_is_mesh(&sdata->vif))
  564. ieee80211_queue_work(&local->hw, &sdata->work);
  565. rcu_read_unlock();
  566. }
  567. void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
  568. {
  569. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  570. setup_timer(&ifmsh->housekeeping_timer,
  571. ieee80211_mesh_housekeeping_timer,
  572. (unsigned long) sdata);
  573. ifmsh->accepting_plinks = true;
  574. ifmsh->preq_id = 0;
  575. ifmsh->sn = 0;
  576. atomic_set(&ifmsh->mpaths, 0);
  577. mesh_rmc_init(sdata);
  578. ifmsh->last_preq = jiffies;
  579. /* Allocate all mesh structures when creating the first mesh interface. */
  580. if (!mesh_allocated)
  581. ieee80211s_init();
  582. setup_timer(&ifmsh->mesh_path_timer,
  583. ieee80211_mesh_path_timer,
  584. (unsigned long) sdata);
  585. setup_timer(&ifmsh->mesh_path_root_timer,
  586. ieee80211_mesh_path_root_timer,
  587. (unsigned long) sdata);
  588. INIT_LIST_HEAD(&ifmsh->preq_queue.list);
  589. spin_lock_init(&ifmsh->mesh_preq_queue_lock);
  590. }