mesh.c 22 KB

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