mesh.c 22 KB

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