mesh.c 23 KB

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