mesh.c 22 KB

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