mesh.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  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. struct cfg80211_chan_def sta_chan_def;
  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, ieee80211_get_sdata_band(sdata),
  88. &basic_rates);
  89. if (sdata->vif.bss_conf.basic_rates != basic_rates)
  90. goto mismatch;
  91. ieee80211_ht_oper_to_chandef(sdata->vif.bss_conf.chandef.chan,
  92. ie->ht_operation, &sta_chan_def);
  93. if (!cfg80211_chandef_compatible(&sdata->vif.bss_conf.chandef,
  94. &sta_chan_def))
  95. goto mismatch;
  96. return true;
  97. mismatch:
  98. return false;
  99. }
  100. /**
  101. * mesh_peer_accepts_plinks - check if an mp is willing to establish peer links
  102. *
  103. * @ie: information elements of a management frame from the mesh peer
  104. */
  105. bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie)
  106. {
  107. return (ie->mesh_config->meshconf_cap &
  108. IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS) != 0;
  109. }
  110. /**
  111. * mesh_accept_plinks_update - update accepting_plink in local mesh beacons
  112. *
  113. * @sdata: mesh interface in which mesh beacons are going to be updated
  114. *
  115. * Returns: beacon changed flag if the beacon content changed.
  116. */
  117. u32 mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata)
  118. {
  119. bool free_plinks;
  120. u32 changed = 0;
  121. /* In case mesh_plink_free_count > 0 and mesh_plinktbl_capacity == 0,
  122. * the mesh interface might be able to establish plinks with peers that
  123. * are already on the table but are not on PLINK_ESTAB state. However,
  124. * in general the mesh interface is not accepting peer link requests
  125. * from new peers, and that must be reflected in the beacon
  126. */
  127. free_plinks = mesh_plink_availables(sdata);
  128. if (free_plinks != sdata->u.mesh.accepting_plinks) {
  129. sdata->u.mesh.accepting_plinks = free_plinks;
  130. changed = BSS_CHANGED_BEACON;
  131. }
  132. return changed;
  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->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. *pos = IEEE80211_MESHCONF_CAPAB_FORWARDING;
  231. *pos |= ifmsh->accepting_plinks ?
  232. IEEE80211_MESHCONF_CAPAB_ACCEPT_PLINKS : 0x00;
  233. *pos++ |= ifmsh->adjusting_tbtt ?
  234. IEEE80211_MESHCONF_CAPAB_TBTT_ADJUSTING : 0x00;
  235. *pos++ = 0x00;
  236. return 0;
  237. }
  238. int
  239. mesh_add_meshid_ie(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
  240. {
  241. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  242. u8 *pos;
  243. if (skb_tailroom(skb) < 2 + ifmsh->mesh_id_len)
  244. return -ENOMEM;
  245. pos = skb_put(skb, 2 + ifmsh->mesh_id_len);
  246. *pos++ = WLAN_EID_MESH_ID;
  247. *pos++ = ifmsh->mesh_id_len;
  248. if (ifmsh->mesh_id_len)
  249. memcpy(pos, ifmsh->mesh_id, ifmsh->mesh_id_len);
  250. return 0;
  251. }
  252. int
  253. mesh_add_vendor_ies(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
  254. {
  255. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  256. u8 offset, len;
  257. const u8 *data;
  258. if (!ifmsh->ie || !ifmsh->ie_len)
  259. return 0;
  260. /* fast-forward to vendor IEs */
  261. offset = ieee80211_ie_split_vendor(ifmsh->ie, ifmsh->ie_len, 0);
  262. if (offset) {
  263. len = ifmsh->ie_len - offset;
  264. data = ifmsh->ie + offset;
  265. if (skb_tailroom(skb) < len)
  266. return -ENOMEM;
  267. memcpy(skb_put(skb, len), data, len);
  268. }
  269. return 0;
  270. }
  271. int
  272. mesh_add_rsn_ie(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
  273. {
  274. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  275. u8 len = 0;
  276. const u8 *data;
  277. if (!ifmsh->ie || !ifmsh->ie_len)
  278. return 0;
  279. /* find RSN IE */
  280. data = ifmsh->ie;
  281. while (data < ifmsh->ie + ifmsh->ie_len) {
  282. if (*data == WLAN_EID_RSN) {
  283. len = data[1] + 2;
  284. break;
  285. }
  286. data++;
  287. }
  288. if (len) {
  289. if (skb_tailroom(skb) < len)
  290. return -ENOMEM;
  291. memcpy(skb_put(skb, len), data, len);
  292. }
  293. return 0;
  294. }
  295. int mesh_add_ds_params_ie(struct sk_buff *skb,
  296. struct ieee80211_sub_if_data *sdata)
  297. {
  298. struct ieee80211_local *local = sdata->local;
  299. struct ieee80211_supported_band *sband;
  300. struct ieee80211_chanctx_conf *chanctx_conf;
  301. struct ieee80211_channel *chan;
  302. u8 *pos;
  303. if (skb_tailroom(skb) < 3)
  304. return -ENOMEM;
  305. rcu_read_lock();
  306. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  307. if (WARN_ON(!chanctx_conf)) {
  308. rcu_read_unlock();
  309. return -EINVAL;
  310. }
  311. chan = chanctx_conf->def.chan;
  312. rcu_read_unlock();
  313. sband = local->hw.wiphy->bands[chan->band];
  314. if (sband->band == IEEE80211_BAND_2GHZ) {
  315. pos = skb_put(skb, 2 + 1);
  316. *pos++ = WLAN_EID_DS_PARAMS;
  317. *pos++ = 1;
  318. *pos++ = ieee80211_frequency_to_channel(chan->center_freq);
  319. }
  320. return 0;
  321. }
  322. int mesh_add_ht_cap_ie(struct sk_buff *skb,
  323. struct ieee80211_sub_if_data *sdata)
  324. {
  325. struct ieee80211_local *local = sdata->local;
  326. enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
  327. struct ieee80211_supported_band *sband;
  328. u8 *pos;
  329. sband = local->hw.wiphy->bands[band];
  330. if (!sband->ht_cap.ht_supported ||
  331. sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
  332. return 0;
  333. if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_cap))
  334. return -ENOMEM;
  335. pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_cap));
  336. ieee80211_ie_build_ht_cap(pos, &sband->ht_cap, sband->ht_cap.cap);
  337. return 0;
  338. }
  339. int mesh_add_ht_oper_ie(struct sk_buff *skb,
  340. struct ieee80211_sub_if_data *sdata)
  341. {
  342. struct ieee80211_local *local = sdata->local;
  343. struct ieee80211_chanctx_conf *chanctx_conf;
  344. struct ieee80211_channel *channel;
  345. enum nl80211_channel_type channel_type =
  346. cfg80211_get_chandef_type(&sdata->vif.bss_conf.chandef);
  347. struct ieee80211_supported_band *sband;
  348. struct ieee80211_sta_ht_cap *ht_cap;
  349. u8 *pos;
  350. rcu_read_lock();
  351. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  352. if (WARN_ON(!chanctx_conf)) {
  353. rcu_read_unlock();
  354. return -EINVAL;
  355. }
  356. channel = chanctx_conf->def.chan;
  357. rcu_read_unlock();
  358. sband = local->hw.wiphy->bands[channel->band];
  359. ht_cap = &sband->ht_cap;
  360. if (!ht_cap->ht_supported || channel_type == NL80211_CHAN_NO_HT)
  361. return 0;
  362. if (skb_tailroom(skb) < 2 + sizeof(struct ieee80211_ht_operation))
  363. return -ENOMEM;
  364. pos = skb_put(skb, 2 + sizeof(struct ieee80211_ht_operation));
  365. ieee80211_ie_build_ht_oper(pos, ht_cap, &sdata->vif.bss_conf.chandef,
  366. sdata->vif.bss_conf.ht_operation_mode);
  367. return 0;
  368. }
  369. static void ieee80211_mesh_path_timer(unsigned long data)
  370. {
  371. struct ieee80211_sub_if_data *sdata =
  372. (struct ieee80211_sub_if_data *) data;
  373. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  374. struct ieee80211_local *local = sdata->local;
  375. if (local->quiescing) {
  376. set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
  377. return;
  378. }
  379. ieee80211_queue_work(&local->hw, &sdata->work);
  380. }
  381. static void ieee80211_mesh_path_root_timer(unsigned long data)
  382. {
  383. struct ieee80211_sub_if_data *sdata =
  384. (struct ieee80211_sub_if_data *) data;
  385. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  386. struct ieee80211_local *local = sdata->local;
  387. set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
  388. if (local->quiescing) {
  389. set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running);
  390. return;
  391. }
  392. ieee80211_queue_work(&local->hw, &sdata->work);
  393. }
  394. void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh)
  395. {
  396. if (ifmsh->mshcfg.dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)
  397. set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
  398. else {
  399. clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
  400. /* stop running timer */
  401. del_timer_sync(&ifmsh->mesh_path_root_timer);
  402. }
  403. }
  404. /**
  405. * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame
  406. * @hdr: 802.11 frame header
  407. * @fc: frame control field
  408. * @meshda: destination address in the mesh
  409. * @meshsa: source address address in the mesh. Same as TA, as frame is
  410. * locally originated.
  411. *
  412. * Return the length of the 802.11 (does not include a mesh control header)
  413. */
  414. int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc,
  415. const u8 *meshda, const u8 *meshsa)
  416. {
  417. if (is_multicast_ether_addr(meshda)) {
  418. *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
  419. /* DA TA SA */
  420. memcpy(hdr->addr1, meshda, ETH_ALEN);
  421. memcpy(hdr->addr2, meshsa, ETH_ALEN);
  422. memcpy(hdr->addr3, meshsa, ETH_ALEN);
  423. return 24;
  424. } else {
  425. *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
  426. /* RA TA DA SA */
  427. memset(hdr->addr1, 0, ETH_ALEN); /* RA is resolved later */
  428. memcpy(hdr->addr2, meshsa, ETH_ALEN);
  429. memcpy(hdr->addr3, meshda, ETH_ALEN);
  430. memcpy(hdr->addr4, meshsa, ETH_ALEN);
  431. return 30;
  432. }
  433. }
  434. /**
  435. * ieee80211_new_mesh_header - create a new mesh header
  436. * @meshhdr: uninitialized mesh header
  437. * @sdata: mesh interface to be used
  438. * @addr4or5: 1st address in the ae header, which may correspond to address 4
  439. * (if addr6 is NULL) or address 5 (if addr6 is present). It may
  440. * be NULL.
  441. * @addr6: 2nd address in the ae header, which corresponds to addr6 of the
  442. * mesh frame
  443. *
  444. * Return the header length.
  445. */
  446. int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
  447. struct ieee80211_sub_if_data *sdata, char *addr4or5,
  448. char *addr6)
  449. {
  450. int aelen = 0;
  451. BUG_ON(!addr4or5 && addr6);
  452. memset(meshhdr, 0, sizeof(*meshhdr));
  453. meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
  454. put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum);
  455. sdata->u.mesh.mesh_seqnum++;
  456. if (addr4or5 && !addr6) {
  457. meshhdr->flags |= MESH_FLAGS_AE_A4;
  458. aelen += ETH_ALEN;
  459. memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN);
  460. } else if (addr4or5 && addr6) {
  461. meshhdr->flags |= MESH_FLAGS_AE_A5_A6;
  462. aelen += 2 * ETH_ALEN;
  463. memcpy(meshhdr->eaddr1, addr4or5, ETH_ALEN);
  464. memcpy(meshhdr->eaddr2, addr6, ETH_ALEN);
  465. }
  466. return 6 + aelen;
  467. }
  468. static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
  469. struct ieee80211_if_mesh *ifmsh)
  470. {
  471. u32 changed;
  472. ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
  473. mesh_path_expire(sdata);
  474. changed = mesh_accept_plinks_update(sdata);
  475. ieee80211_bss_info_change_notify(sdata, changed);
  476. mod_timer(&ifmsh->housekeeping_timer,
  477. round_jiffies(jiffies + IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
  478. }
  479. static void ieee80211_mesh_rootpath(struct ieee80211_sub_if_data *sdata)
  480. {
  481. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  482. u32 interval;
  483. mesh_path_tx_root_frame(sdata);
  484. if (ifmsh->mshcfg.dot11MeshHWMPRootMode == IEEE80211_PROACTIVE_RANN)
  485. interval = ifmsh->mshcfg.dot11MeshHWMPRannInterval;
  486. else
  487. interval = ifmsh->mshcfg.dot11MeshHWMProotInterval;
  488. mod_timer(&ifmsh->mesh_path_root_timer,
  489. round_jiffies(TU_TO_EXP_TIME(interval)));
  490. }
  491. #ifdef CONFIG_PM
  492. void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata)
  493. {
  494. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  495. /* use atomic bitops in case all timers fire at the same time */
  496. if (del_timer_sync(&ifmsh->housekeeping_timer))
  497. set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
  498. if (del_timer_sync(&ifmsh->mesh_path_timer))
  499. set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
  500. if (del_timer_sync(&ifmsh->mesh_path_root_timer))
  501. set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running);
  502. }
  503. void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata)
  504. {
  505. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  506. if (test_and_clear_bit(TMR_RUNNING_HK, &ifmsh->timers_running))
  507. add_timer(&ifmsh->housekeeping_timer);
  508. if (test_and_clear_bit(TMR_RUNNING_MP, &ifmsh->timers_running))
  509. add_timer(&ifmsh->mesh_path_timer);
  510. if (test_and_clear_bit(TMR_RUNNING_MPR, &ifmsh->timers_running))
  511. add_timer(&ifmsh->mesh_path_root_timer);
  512. ieee80211_mesh_root_setup(ifmsh);
  513. }
  514. #endif
  515. void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
  516. {
  517. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  518. struct ieee80211_local *local = sdata->local;
  519. local->fif_other_bss++;
  520. /* mesh ifaces must set allmulti to forward mcast traffic */
  521. atomic_inc(&local->iff_allmultis);
  522. ieee80211_configure_filter(local);
  523. ifmsh->mesh_cc_id = 0; /* Disabled */
  524. ifmsh->mesh_auth_id = 0; /* Disabled */
  525. /* register sync ops from extensible synchronization framework */
  526. ifmsh->sync_ops = ieee80211_mesh_sync_ops_get(ifmsh->mesh_sp_id);
  527. ifmsh->adjusting_tbtt = false;
  528. ifmsh->sync_offset_clockdrift_max = 0;
  529. set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
  530. ieee80211_mesh_root_setup(ifmsh);
  531. ieee80211_queue_work(&local->hw, &sdata->work);
  532. sdata->vif.bss_conf.ht_operation_mode =
  533. ifmsh->mshcfg.ht_opmode;
  534. sdata->vif.bss_conf.beacon_int = MESH_DEFAULT_BEACON_INTERVAL;
  535. sdata->vif.bss_conf.basic_rates =
  536. ieee80211_mandatory_rates(sdata->local,
  537. ieee80211_get_sdata_band(sdata));
  538. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON |
  539. BSS_CHANGED_BEACON_ENABLED |
  540. BSS_CHANGED_HT |
  541. BSS_CHANGED_BASIC_RATES |
  542. BSS_CHANGED_BEACON_INT);
  543. netif_carrier_on(sdata->dev);
  544. }
  545. void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
  546. {
  547. struct ieee80211_local *local = sdata->local;
  548. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  549. netif_carrier_off(sdata->dev);
  550. /* stop the beacon */
  551. ifmsh->mesh_id_len = 0;
  552. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
  553. /* flush STAs and mpaths on this iface */
  554. sta_info_flush(sdata->local, sdata);
  555. mesh_path_flush_by_iface(sdata);
  556. del_timer_sync(&sdata->u.mesh.housekeeping_timer);
  557. del_timer_sync(&sdata->u.mesh.mesh_path_root_timer);
  558. del_timer_sync(&sdata->u.mesh.mesh_path_timer);
  559. /*
  560. * If the timer fired while we waited for it, it will have
  561. * requeued the work. Now the work will be running again
  562. * but will not rearm the timer again because it checks
  563. * whether the interface is running, which, at this point,
  564. * it no longer is.
  565. */
  566. cancel_work_sync(&sdata->work);
  567. local->fif_other_bss--;
  568. atomic_dec(&local->iff_allmultis);
  569. ieee80211_configure_filter(local);
  570. sdata->u.mesh.timers_running = 0;
  571. }
  572. static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
  573. u16 stype,
  574. struct ieee80211_mgmt *mgmt,
  575. size_t len,
  576. struct ieee80211_rx_status *rx_status)
  577. {
  578. struct ieee80211_local *local = sdata->local;
  579. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  580. struct ieee802_11_elems elems;
  581. struct ieee80211_channel *channel;
  582. size_t baselen;
  583. int freq;
  584. enum ieee80211_band band = rx_status->band;
  585. /* ignore ProbeResp to foreign address */
  586. if (stype == IEEE80211_STYPE_PROBE_RESP &&
  587. !ether_addr_equal(mgmt->da, sdata->vif.addr))
  588. return;
  589. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  590. if (baselen > len)
  591. return;
  592. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  593. &elems);
  594. /* ignore non-mesh or secure / unsecure mismatch */
  595. if ((!elems.mesh_id || !elems.mesh_config) ||
  596. (elems.rsn && sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) ||
  597. (!elems.rsn && sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE))
  598. return;
  599. if (elems.ds_params && elems.ds_params_len == 1)
  600. freq = ieee80211_channel_to_frequency(elems.ds_params[0], band);
  601. else
  602. freq = rx_status->freq;
  603. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  604. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  605. return;
  606. if (mesh_matches_local(sdata, &elems))
  607. mesh_neighbour_update(sdata, mgmt->sa, &elems);
  608. if (ifmsh->sync_ops)
  609. ifmsh->sync_ops->rx_bcn_presp(sdata,
  610. stype, mgmt, &elems, rx_status);
  611. }
  612. static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
  613. struct ieee80211_mgmt *mgmt,
  614. size_t len,
  615. struct ieee80211_rx_status *rx_status)
  616. {
  617. switch (mgmt->u.action.category) {
  618. case WLAN_CATEGORY_SELF_PROTECTED:
  619. switch (mgmt->u.action.u.self_prot.action_code) {
  620. case WLAN_SP_MESH_PEERING_OPEN:
  621. case WLAN_SP_MESH_PEERING_CLOSE:
  622. case WLAN_SP_MESH_PEERING_CONFIRM:
  623. mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
  624. break;
  625. }
  626. break;
  627. case WLAN_CATEGORY_MESH_ACTION:
  628. if (mesh_action_is_path_sel(mgmt))
  629. mesh_rx_path_sel_frame(sdata, mgmt, len);
  630. break;
  631. }
  632. }
  633. void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  634. struct sk_buff *skb)
  635. {
  636. struct ieee80211_rx_status *rx_status;
  637. struct ieee80211_mgmt *mgmt;
  638. u16 stype;
  639. rx_status = IEEE80211_SKB_RXCB(skb);
  640. mgmt = (struct ieee80211_mgmt *) skb->data;
  641. stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
  642. switch (stype) {
  643. case IEEE80211_STYPE_PROBE_RESP:
  644. case IEEE80211_STYPE_BEACON:
  645. ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len,
  646. rx_status);
  647. break;
  648. case IEEE80211_STYPE_ACTION:
  649. ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status);
  650. break;
  651. }
  652. }
  653. void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata)
  654. {
  655. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  656. if (ifmsh->preq_queue_len &&
  657. time_after(jiffies,
  658. ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval)))
  659. mesh_path_start_discovery(sdata);
  660. if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags))
  661. mesh_mpath_table_grow();
  662. if (test_and_clear_bit(MESH_WORK_GROW_MPP_TABLE, &ifmsh->wrkq_flags))
  663. mesh_mpp_table_grow();
  664. if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags))
  665. ieee80211_mesh_housekeeping(sdata, ifmsh);
  666. if (test_and_clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags))
  667. ieee80211_mesh_rootpath(sdata);
  668. if (test_and_clear_bit(MESH_WORK_DRIFT_ADJUST, &ifmsh->wrkq_flags))
  669. mesh_sync_adjust_tbtt(sdata);
  670. }
  671. void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local)
  672. {
  673. struct ieee80211_sub_if_data *sdata;
  674. rcu_read_lock();
  675. list_for_each_entry_rcu(sdata, &local->interfaces, list)
  676. if (ieee80211_vif_is_mesh(&sdata->vif))
  677. ieee80211_queue_work(&local->hw, &sdata->work);
  678. rcu_read_unlock();
  679. }
  680. void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
  681. {
  682. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  683. setup_timer(&ifmsh->housekeeping_timer,
  684. ieee80211_mesh_housekeeping_timer,
  685. (unsigned long) sdata);
  686. ifmsh->accepting_plinks = true;
  687. ifmsh->preq_id = 0;
  688. ifmsh->sn = 0;
  689. ifmsh->num_gates = 0;
  690. atomic_set(&ifmsh->mpaths, 0);
  691. mesh_rmc_init(sdata);
  692. ifmsh->last_preq = jiffies;
  693. ifmsh->next_perr = jiffies;
  694. /* Allocate all mesh structures when creating the first mesh interface. */
  695. if (!mesh_allocated)
  696. ieee80211s_init();
  697. setup_timer(&ifmsh->mesh_path_timer,
  698. ieee80211_mesh_path_timer,
  699. (unsigned long) sdata);
  700. setup_timer(&ifmsh->mesh_path_root_timer,
  701. ieee80211_mesh_path_root_timer,
  702. (unsigned long) sdata);
  703. INIT_LIST_HEAD(&ifmsh->preq_queue.list);
  704. spin_lock_init(&ifmsh->mesh_preq_queue_lock);
  705. spin_lock_init(&ifmsh->sync_offset_lock);
  706. }