mesh.c 22 KB

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