mesh.c 21 KB

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