mesh.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  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 <asm/unaligned.h>
  11. #include "ieee80211_i.h"
  12. #include "mesh.h"
  13. #define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
  14. #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
  15. #define IEEE80211_MESH_RANN_INTERVAL (1 * HZ)
  16. #define MESHCONF_CAPAB_ACCEPT_PLINKS 0x01
  17. #define MESHCONF_CAPAB_FORWARDING 0x08
  18. #define TMR_RUNNING_HK 0
  19. #define TMR_RUNNING_MP 1
  20. #define TMR_RUNNING_MPR 2
  21. int mesh_allocated;
  22. static struct kmem_cache *rm_cache;
  23. void ieee80211s_init(void)
  24. {
  25. mesh_pathtbl_init();
  26. mesh_allocated = 1;
  27. rm_cache = kmem_cache_create("mesh_rmc", sizeof(struct rmc_entry),
  28. 0, 0, NULL);
  29. }
  30. void ieee80211s_stop(void)
  31. {
  32. mesh_pathtbl_unregister();
  33. kmem_cache_destroy(rm_cache);
  34. }
  35. static void ieee80211_mesh_housekeeping_timer(unsigned long data)
  36. {
  37. struct ieee80211_sub_if_data *sdata = (void *) data;
  38. struct ieee80211_local *local = sdata->local;
  39. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  40. set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
  41. if (local->quiescing) {
  42. set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
  43. return;
  44. }
  45. ieee80211_queue_work(&local->hw, &ifmsh->work);
  46. }
  47. /**
  48. * mesh_matches_local - check if the config of a mesh point matches ours
  49. *
  50. * @ie: information elements of a management frame from the mesh peer
  51. * @sdata: local mesh subif
  52. *
  53. * This function checks if the mesh configuration of a mesh point matches the
  54. * local mesh configuration, i.e. if both nodes belong to the same mesh network.
  55. */
  56. bool mesh_matches_local(struct ieee802_11_elems *ie, struct ieee80211_sub_if_data *sdata)
  57. {
  58. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  59. /*
  60. * As support for each feature is added, check for matching
  61. * - On mesh config capabilities
  62. * - Power Save Support En
  63. * - Sync support enabled
  64. * - Sync support active
  65. * - Sync support required from peer
  66. * - MDA enabled
  67. * - Power management control on fc
  68. */
  69. if (ifmsh->mesh_id_len == ie->mesh_id_len &&
  70. memcmp(ifmsh->mesh_id, ie->mesh_id, ie->mesh_id_len) == 0 &&
  71. (ifmsh->mesh_pp_id == ie->mesh_config->meshconf_psel) &&
  72. (ifmsh->mesh_pm_id == ie->mesh_config->meshconf_pmetric) &&
  73. (ifmsh->mesh_cc_id == ie->mesh_config->meshconf_congest) &&
  74. (ifmsh->mesh_sp_id == ie->mesh_config->meshconf_synch) &&
  75. (ifmsh->mesh_auth_id == ie->mesh_config->meshconf_auth))
  76. return true;
  77. return false;
  78. }
  79. /**
  80. * mesh_peer_accepts_plinks - check if an mp is willing to establish peer links
  81. *
  82. * @ie: information elements of a management frame from the mesh peer
  83. */
  84. bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie)
  85. {
  86. return (ie->mesh_config->meshconf_cap &
  87. MESHCONF_CAPAB_ACCEPT_PLINKS) != 0;
  88. }
  89. /**
  90. * mesh_accept_plinks_update: update accepting_plink in local mesh beacons
  91. *
  92. * @sdata: mesh interface in which mesh beacons are going to be updated
  93. */
  94. void mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata)
  95. {
  96. bool free_plinks;
  97. /* In case mesh_plink_free_count > 0 and mesh_plinktbl_capacity == 0,
  98. * the mesh interface might be able to establish plinks with peers that
  99. * are already on the table but are not on PLINK_ESTAB state. However,
  100. * in general the mesh interface is not accepting peer link requests
  101. * from new peers, and that must be reflected in the beacon
  102. */
  103. free_plinks = mesh_plink_availables(sdata);
  104. if (free_plinks != sdata->u.mesh.accepting_plinks)
  105. ieee80211_mesh_housekeeping_timer((unsigned long) sdata);
  106. }
  107. void mesh_ids_set_default(struct ieee80211_if_mesh *sta)
  108. {
  109. sta->mesh_pp_id = 0; /* HWMP */
  110. sta->mesh_pm_id = 0; /* Airtime */
  111. sta->mesh_cc_id = 0; /* Disabled */
  112. sta->mesh_sp_id = 0; /* Neighbor Offset */
  113. sta->mesh_auth_id = 0; /* Disabled */
  114. }
  115. int mesh_rmc_init(struct ieee80211_sub_if_data *sdata)
  116. {
  117. int i;
  118. sdata->u.mesh.rmc = kmalloc(sizeof(struct mesh_rmc), GFP_KERNEL);
  119. if (!sdata->u.mesh.rmc)
  120. return -ENOMEM;
  121. sdata->u.mesh.rmc->idx_mask = RMC_BUCKETS - 1;
  122. for (i = 0; i < RMC_BUCKETS; i++)
  123. INIT_LIST_HEAD(&sdata->u.mesh.rmc->bucket[i].list);
  124. return 0;
  125. }
  126. void mesh_rmc_free(struct ieee80211_sub_if_data *sdata)
  127. {
  128. struct mesh_rmc *rmc = sdata->u.mesh.rmc;
  129. struct rmc_entry *p, *n;
  130. int i;
  131. if (!sdata->u.mesh.rmc)
  132. return;
  133. for (i = 0; i < RMC_BUCKETS; i++)
  134. list_for_each_entry_safe(p, n, &rmc->bucket[i].list, list) {
  135. list_del(&p->list);
  136. kmem_cache_free(rm_cache, p);
  137. }
  138. kfree(rmc);
  139. sdata->u.mesh.rmc = NULL;
  140. }
  141. /**
  142. * mesh_rmc_check - Check frame in recent multicast cache and add if absent.
  143. *
  144. * @sa: source address
  145. * @mesh_hdr: mesh_header
  146. *
  147. * Returns: 0 if the frame is not in the cache, nonzero otherwise.
  148. *
  149. * Checks using the source address and the mesh sequence number if we have
  150. * received this frame lately. If the frame is not in the cache, it is added to
  151. * it.
  152. */
  153. int mesh_rmc_check(u8 *sa, struct ieee80211s_hdr *mesh_hdr,
  154. struct ieee80211_sub_if_data *sdata)
  155. {
  156. struct mesh_rmc *rmc = sdata->u.mesh.rmc;
  157. u32 seqnum = 0;
  158. int entries = 0;
  159. u8 idx;
  160. struct rmc_entry *p, *n;
  161. /* Don't care about endianness since only match matters */
  162. memcpy(&seqnum, &mesh_hdr->seqnum, sizeof(mesh_hdr->seqnum));
  163. idx = le32_to_cpu(mesh_hdr->seqnum) & rmc->idx_mask;
  164. list_for_each_entry_safe(p, n, &rmc->bucket[idx].list, list) {
  165. ++entries;
  166. if (time_after(jiffies, p->exp_time) ||
  167. (entries == RMC_QUEUE_MAX_LEN)) {
  168. list_del(&p->list);
  169. kmem_cache_free(rm_cache, p);
  170. --entries;
  171. } else if ((seqnum == p->seqnum) &&
  172. (memcmp(sa, p->sa, ETH_ALEN) == 0))
  173. return -1;
  174. }
  175. p = kmem_cache_alloc(rm_cache, GFP_ATOMIC);
  176. if (!p) {
  177. printk(KERN_DEBUG "o11s: could not allocate RMC entry\n");
  178. return 0;
  179. }
  180. p->seqnum = seqnum;
  181. p->exp_time = jiffies + RMC_TIMEOUT;
  182. memcpy(p->sa, sa, ETH_ALEN);
  183. list_add(&p->list, &rmc->bucket[idx].list);
  184. return 0;
  185. }
  186. void mesh_mgmt_ies_add(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
  187. {
  188. struct ieee80211_local *local = sdata->local;
  189. struct ieee80211_supported_band *sband;
  190. u8 *pos;
  191. int len, i, rate;
  192. u8 neighbors;
  193. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  194. len = sband->n_bitrates;
  195. if (len > 8)
  196. len = 8;
  197. pos = skb_put(skb, len + 2);
  198. *pos++ = WLAN_EID_SUPP_RATES;
  199. *pos++ = len;
  200. for (i = 0; i < len; i++) {
  201. rate = sband->bitrates[i].bitrate;
  202. *pos++ = (u8) (rate / 5);
  203. }
  204. if (sband->n_bitrates > len) {
  205. pos = skb_put(skb, sband->n_bitrates - len + 2);
  206. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  207. *pos++ = sband->n_bitrates - len;
  208. for (i = len; i < sband->n_bitrates; i++) {
  209. rate = sband->bitrates[i].bitrate;
  210. *pos++ = (u8) (rate / 5);
  211. }
  212. }
  213. if (sband->band == IEEE80211_BAND_2GHZ) {
  214. pos = skb_put(skb, 2 + 1);
  215. *pos++ = WLAN_EID_DS_PARAMS;
  216. *pos++ = 1;
  217. *pos++ = ieee80211_frequency_to_channel(local->hw.conf.channel->center_freq);
  218. }
  219. pos = skb_put(skb, 2 + sdata->u.mesh.mesh_id_len);
  220. *pos++ = WLAN_EID_MESH_ID;
  221. *pos++ = sdata->u.mesh.mesh_id_len;
  222. if (sdata->u.mesh.mesh_id_len)
  223. memcpy(pos, sdata->u.mesh.mesh_id, sdata->u.mesh.mesh_id_len);
  224. pos = skb_put(skb, 2 + sizeof(struct ieee80211_meshconf_ie));
  225. *pos++ = WLAN_EID_MESH_CONFIG;
  226. *pos++ = sizeof(struct ieee80211_meshconf_ie);
  227. /* Active path selection protocol ID */
  228. *pos++ = sdata->u.mesh.mesh_pp_id;
  229. /* Active path selection metric ID */
  230. *pos++ = sdata->u.mesh.mesh_pm_id;
  231. /* Congestion control mode identifier */
  232. *pos++ = sdata->u.mesh.mesh_cc_id;
  233. /* Synchronization protocol identifier */
  234. *pos++ = sdata->u.mesh.mesh_sp_id;
  235. /* Authentication Protocol identifier */
  236. *pos++ = sdata->u.mesh.mesh_auth_id;
  237. /* Mesh Formation Info - number of neighbors */
  238. neighbors = atomic_read(&sdata->u.mesh.mshstats.estab_plinks);
  239. /* Number of neighbor mesh STAs or 15 whichever is smaller */
  240. neighbors = (neighbors > 15) ? 15 : neighbors;
  241. *pos++ = neighbors << 1;
  242. /* Mesh capability */
  243. sdata->u.mesh.accepting_plinks = mesh_plink_availables(sdata);
  244. *pos = MESHCONF_CAPAB_FORWARDING;
  245. *pos++ |= sdata->u.mesh.accepting_plinks ?
  246. MESHCONF_CAPAB_ACCEPT_PLINKS : 0x00;
  247. *pos++ = 0x00;
  248. return;
  249. }
  250. u32 mesh_table_hash(u8 *addr, struct ieee80211_sub_if_data *sdata, struct mesh_table *tbl)
  251. {
  252. /* Use last four bytes of hw addr and interface index as hash index */
  253. return jhash_2words(*(u32 *)(addr+2), sdata->dev->ifindex, tbl->hash_rnd)
  254. & tbl->hash_mask;
  255. }
  256. struct mesh_table *mesh_table_alloc(int size_order)
  257. {
  258. int i;
  259. struct mesh_table *newtbl;
  260. newtbl = kmalloc(sizeof(struct mesh_table), GFP_KERNEL);
  261. if (!newtbl)
  262. return NULL;
  263. newtbl->hash_buckets = kzalloc(sizeof(struct hlist_head) *
  264. (1 << size_order), GFP_KERNEL);
  265. if (!newtbl->hash_buckets) {
  266. kfree(newtbl);
  267. return NULL;
  268. }
  269. newtbl->hashwlock = kmalloc(sizeof(spinlock_t) *
  270. (1 << size_order), GFP_KERNEL);
  271. if (!newtbl->hashwlock) {
  272. kfree(newtbl->hash_buckets);
  273. kfree(newtbl);
  274. return NULL;
  275. }
  276. newtbl->size_order = size_order;
  277. newtbl->hash_mask = (1 << size_order) - 1;
  278. atomic_set(&newtbl->entries, 0);
  279. get_random_bytes(&newtbl->hash_rnd,
  280. sizeof(newtbl->hash_rnd));
  281. for (i = 0; i <= newtbl->hash_mask; i++)
  282. spin_lock_init(&newtbl->hashwlock[i]);
  283. return newtbl;
  284. }
  285. static void ieee80211_mesh_path_timer(unsigned long data)
  286. {
  287. struct ieee80211_sub_if_data *sdata =
  288. (struct ieee80211_sub_if_data *) data;
  289. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  290. struct ieee80211_local *local = sdata->local;
  291. if (local->quiescing) {
  292. set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
  293. return;
  294. }
  295. ieee80211_queue_work(&local->hw, &ifmsh->work);
  296. }
  297. static void ieee80211_mesh_path_root_timer(unsigned long data)
  298. {
  299. struct ieee80211_sub_if_data *sdata =
  300. (struct ieee80211_sub_if_data *) data;
  301. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  302. struct ieee80211_local *local = sdata->local;
  303. set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
  304. if (local->quiescing) {
  305. set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running);
  306. return;
  307. }
  308. ieee80211_queue_work(&local->hw, &ifmsh->work);
  309. }
  310. void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh)
  311. {
  312. if (ifmsh->mshcfg.dot11MeshHWMPRootMode)
  313. set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
  314. else {
  315. clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
  316. /* stop running timer */
  317. del_timer_sync(&ifmsh->mesh_path_root_timer);
  318. }
  319. }
  320. /**
  321. * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame
  322. * @hdr: 802.11 frame header
  323. * @fc: frame control field
  324. * @meshda: destination address in the mesh
  325. * @meshsa: source address address in the mesh. Same as TA, as frame is
  326. * locally originated.
  327. *
  328. * Return the length of the 802.11 (does not include a mesh control header)
  329. */
  330. int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc,
  331. const u8 *meshda, const u8 *meshsa)
  332. {
  333. if (is_multicast_ether_addr(meshda)) {
  334. *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
  335. /* DA TA SA */
  336. memcpy(hdr->addr1, meshda, ETH_ALEN);
  337. memcpy(hdr->addr2, meshsa, ETH_ALEN);
  338. memcpy(hdr->addr3, meshsa, ETH_ALEN);
  339. return 24;
  340. } else {
  341. *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
  342. IEEE80211_FCTL_TODS);
  343. /* RA TA DA SA */
  344. memset(hdr->addr1, 0, ETH_ALEN); /* RA is resolved later */
  345. memcpy(hdr->addr2, meshsa, ETH_ALEN);
  346. memcpy(hdr->addr3, meshda, ETH_ALEN);
  347. memcpy(hdr->addr4, meshsa, ETH_ALEN);
  348. return 30;
  349. }
  350. }
  351. /**
  352. * ieee80211_new_mesh_header - create a new mesh header
  353. * @meshhdr: uninitialized mesh header
  354. * @sdata: mesh interface to be used
  355. * @addr4: addr4 of the mesh frame (1st in ae header)
  356. * may be NULL
  357. * @addr5: addr5 of the mesh frame (1st or 2nd in ae header)
  358. * may be NULL unless addr6 is present
  359. * @addr6: addr6 of the mesh frame (2nd or 3rd in ae header)
  360. * may be NULL unless addr5 is present
  361. *
  362. * Return the header length.
  363. */
  364. int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
  365. struct ieee80211_sub_if_data *sdata, char *addr4,
  366. char *addr5, char *addr6)
  367. {
  368. int aelen = 0;
  369. memset(meshhdr, 0, sizeof(*meshhdr));
  370. meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
  371. put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum);
  372. sdata->u.mesh.mesh_seqnum++;
  373. if (addr4) {
  374. meshhdr->flags |= MESH_FLAGS_AE_A4;
  375. aelen += ETH_ALEN;
  376. memcpy(meshhdr->eaddr1, addr4, ETH_ALEN);
  377. }
  378. if (addr5 && addr6) {
  379. meshhdr->flags |= MESH_FLAGS_AE_A5_A6;
  380. aelen += 2 * ETH_ALEN;
  381. if (!addr4) {
  382. memcpy(meshhdr->eaddr1, addr5, ETH_ALEN);
  383. memcpy(meshhdr->eaddr2, addr6, ETH_ALEN);
  384. } else {
  385. memcpy(meshhdr->eaddr2, addr5, ETH_ALEN);
  386. memcpy(meshhdr->eaddr3, addr6, ETH_ALEN);
  387. }
  388. }
  389. return 6 + aelen;
  390. }
  391. static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
  392. struct ieee80211_if_mesh *ifmsh)
  393. {
  394. bool free_plinks;
  395. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  396. printk(KERN_DEBUG "%s: running mesh housekeeping\n",
  397. sdata->dev->name);
  398. #endif
  399. ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
  400. mesh_path_expire(sdata);
  401. free_plinks = mesh_plink_availables(sdata);
  402. if (free_plinks != sdata->u.mesh.accepting_plinks)
  403. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
  404. mod_timer(&ifmsh->housekeeping_timer,
  405. round_jiffies(jiffies + IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
  406. }
  407. static void ieee80211_mesh_rootpath(struct ieee80211_sub_if_data *sdata)
  408. {
  409. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  410. mesh_path_tx_root_frame(sdata);
  411. mod_timer(&ifmsh->mesh_path_root_timer,
  412. round_jiffies(jiffies + IEEE80211_MESH_RANN_INTERVAL));
  413. }
  414. #ifdef CONFIG_PM
  415. void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata)
  416. {
  417. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  418. /* might restart the timer but that doesn't matter */
  419. cancel_work_sync(&ifmsh->work);
  420. /* use atomic bitops in case both timers fire at the same time */
  421. if (del_timer_sync(&ifmsh->housekeeping_timer))
  422. set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
  423. if (del_timer_sync(&ifmsh->mesh_path_timer))
  424. set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
  425. if (del_timer_sync(&ifmsh->mesh_path_root_timer))
  426. set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running);
  427. }
  428. void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata)
  429. {
  430. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  431. if (test_and_clear_bit(TMR_RUNNING_HK, &ifmsh->timers_running))
  432. add_timer(&ifmsh->housekeeping_timer);
  433. if (test_and_clear_bit(TMR_RUNNING_MP, &ifmsh->timers_running))
  434. add_timer(&ifmsh->mesh_path_timer);
  435. if (test_and_clear_bit(TMR_RUNNING_MPR, &ifmsh->timers_running))
  436. add_timer(&ifmsh->mesh_path_root_timer);
  437. ieee80211_mesh_root_setup(ifmsh);
  438. }
  439. #endif
  440. void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
  441. {
  442. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  443. struct ieee80211_local *local = sdata->local;
  444. set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
  445. ieee80211_mesh_root_setup(ifmsh);
  446. ieee80211_queue_work(&local->hw, &ifmsh->work);
  447. sdata->vif.bss_conf.beacon_int = MESH_DEFAULT_BEACON_INTERVAL;
  448. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON |
  449. BSS_CHANGED_BEACON_ENABLED |
  450. BSS_CHANGED_BEACON_INT);
  451. }
  452. void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
  453. {
  454. del_timer_sync(&sdata->u.mesh.housekeeping_timer);
  455. del_timer_sync(&sdata->u.mesh.mesh_path_root_timer);
  456. /*
  457. * If the timer fired while we waited for it, it will have
  458. * requeued the work. Now the work will be running again
  459. * but will not rearm the timer again because it checks
  460. * whether the interface is running, which, at this point,
  461. * it no longer is.
  462. */
  463. cancel_work_sync(&sdata->u.mesh.work);
  464. /*
  465. * When we get here, the interface is marked down.
  466. * Call synchronize_rcu() to wait for the RX path
  467. * should it be using the interface and enqueuing
  468. * frames at this very time on another CPU.
  469. */
  470. rcu_barrier(); /* Wait for RX path and call_rcu()'s */
  471. skb_queue_purge(&sdata->u.mesh.skb_queue);
  472. }
  473. static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
  474. u16 stype,
  475. struct ieee80211_mgmt *mgmt,
  476. size_t len,
  477. struct ieee80211_rx_status *rx_status)
  478. {
  479. struct ieee80211_local *local = sdata->local;
  480. struct ieee802_11_elems elems;
  481. struct ieee80211_channel *channel;
  482. u32 supp_rates = 0;
  483. size_t baselen;
  484. int freq;
  485. enum ieee80211_band band = rx_status->band;
  486. /* ignore ProbeResp to foreign address */
  487. if (stype == IEEE80211_STYPE_PROBE_RESP &&
  488. compare_ether_addr(mgmt->da, sdata->dev->dev_addr))
  489. return;
  490. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  491. if (baselen > len)
  492. return;
  493. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  494. &elems);
  495. if (elems.ds_params && elems.ds_params_len == 1)
  496. freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
  497. else
  498. freq = rx_status->freq;
  499. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  500. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  501. return;
  502. if (elems.mesh_id && elems.mesh_config &&
  503. mesh_matches_local(&elems, sdata)) {
  504. supp_rates = ieee80211_sta_get_rates(local, &elems, band);
  505. mesh_neighbour_update(mgmt->sa, supp_rates, sdata,
  506. mesh_peer_accepts_plinks(&elems));
  507. }
  508. }
  509. static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
  510. struct ieee80211_mgmt *mgmt,
  511. size_t len,
  512. struct ieee80211_rx_status *rx_status)
  513. {
  514. switch (mgmt->u.action.category) {
  515. case MESH_PLINK_CATEGORY:
  516. mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
  517. break;
  518. case MESH_PATH_SEL_CATEGORY:
  519. mesh_rx_path_sel_frame(sdata, mgmt, len);
  520. break;
  521. }
  522. }
  523. static void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  524. struct sk_buff *skb)
  525. {
  526. struct ieee80211_rx_status *rx_status;
  527. struct ieee80211_if_mesh *ifmsh;
  528. struct ieee80211_mgmt *mgmt;
  529. u16 stype;
  530. ifmsh = &sdata->u.mesh;
  531. rx_status = IEEE80211_SKB_RXCB(skb);
  532. mgmt = (struct ieee80211_mgmt *) skb->data;
  533. stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
  534. switch (stype) {
  535. case IEEE80211_STYPE_PROBE_RESP:
  536. case IEEE80211_STYPE_BEACON:
  537. ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len,
  538. rx_status);
  539. break;
  540. case IEEE80211_STYPE_ACTION:
  541. ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status);
  542. break;
  543. }
  544. kfree_skb(skb);
  545. }
  546. static void ieee80211_mesh_work(struct work_struct *work)
  547. {
  548. struct ieee80211_sub_if_data *sdata =
  549. container_of(work, struct ieee80211_sub_if_data, u.mesh.work);
  550. struct ieee80211_local *local = sdata->local;
  551. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  552. struct sk_buff *skb;
  553. if (!netif_running(sdata->dev))
  554. return;
  555. if (local->scanning)
  556. return;
  557. while ((skb = skb_dequeue(&ifmsh->skb_queue)))
  558. ieee80211_mesh_rx_queued_mgmt(sdata, skb);
  559. if (ifmsh->preq_queue_len &&
  560. time_after(jiffies,
  561. ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval)))
  562. mesh_path_start_discovery(sdata);
  563. if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags))
  564. mesh_mpath_table_grow();
  565. if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags))
  566. mesh_mpp_table_grow();
  567. if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags))
  568. ieee80211_mesh_housekeeping(sdata, ifmsh);
  569. if (test_and_clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags))
  570. ieee80211_mesh_rootpath(sdata);
  571. }
  572. void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local)
  573. {
  574. struct ieee80211_sub_if_data *sdata;
  575. rcu_read_lock();
  576. list_for_each_entry_rcu(sdata, &local->interfaces, list)
  577. if (ieee80211_vif_is_mesh(&sdata->vif))
  578. ieee80211_queue_work(&local->hw, &sdata->u.mesh.work);
  579. rcu_read_unlock();
  580. }
  581. void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
  582. {
  583. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  584. INIT_WORK(&ifmsh->work, ieee80211_mesh_work);
  585. setup_timer(&ifmsh->housekeeping_timer,
  586. ieee80211_mesh_housekeeping_timer,
  587. (unsigned long) sdata);
  588. skb_queue_head_init(&sdata->u.mesh.skb_queue);
  589. ifmsh->mshcfg.dot11MeshRetryTimeout = MESH_RET_T;
  590. ifmsh->mshcfg.dot11MeshConfirmTimeout = MESH_CONF_T;
  591. ifmsh->mshcfg.dot11MeshHoldingTimeout = MESH_HOLD_T;
  592. ifmsh->mshcfg.dot11MeshMaxRetries = MESH_MAX_RETR;
  593. ifmsh->mshcfg.dot11MeshTTL = MESH_TTL;
  594. ifmsh->mshcfg.auto_open_plinks = true;
  595. ifmsh->mshcfg.dot11MeshMaxPeerLinks =
  596. MESH_MAX_ESTAB_PLINKS;
  597. ifmsh->mshcfg.dot11MeshHWMPactivePathTimeout =
  598. MESH_PATH_TIMEOUT;
  599. ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval =
  600. MESH_PREQ_MIN_INT;
  601. ifmsh->mshcfg.dot11MeshHWMPnetDiameterTraversalTime =
  602. MESH_DIAM_TRAVERSAL_TIME;
  603. ifmsh->mshcfg.dot11MeshHWMPmaxPREQretries =
  604. MESH_MAX_PREQ_RETRIES;
  605. ifmsh->mshcfg.path_refresh_time =
  606. MESH_PATH_REFRESH_TIME;
  607. ifmsh->mshcfg.min_discovery_timeout =
  608. MESH_MIN_DISCOVERY_TIMEOUT;
  609. ifmsh->accepting_plinks = true;
  610. ifmsh->preq_id = 0;
  611. ifmsh->sn = 0;
  612. atomic_set(&ifmsh->mpaths, 0);
  613. mesh_rmc_init(sdata);
  614. ifmsh->last_preq = jiffies;
  615. /* Allocate all mesh structures when creating the first mesh interface. */
  616. if (!mesh_allocated)
  617. ieee80211s_init();
  618. mesh_ids_set_default(ifmsh);
  619. setup_timer(&ifmsh->mesh_path_timer,
  620. ieee80211_mesh_path_timer,
  621. (unsigned long) sdata);
  622. setup_timer(&ifmsh->mesh_path_root_timer,
  623. ieee80211_mesh_path_root_timer,
  624. (unsigned long) sdata);
  625. INIT_LIST_HEAD(&ifmsh->preq_queue.list);
  626. spin_lock_init(&ifmsh->mesh_preq_queue_lock);
  627. }
  628. ieee80211_rx_result
  629. ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
  630. {
  631. struct ieee80211_local *local = sdata->local;
  632. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  633. struct ieee80211_mgmt *mgmt;
  634. u16 fc;
  635. if (skb->len < 24)
  636. return RX_DROP_MONITOR;
  637. mgmt = (struct ieee80211_mgmt *) skb->data;
  638. fc = le16_to_cpu(mgmt->frame_control);
  639. switch (fc & IEEE80211_FCTL_STYPE) {
  640. case IEEE80211_STYPE_ACTION:
  641. if (skb->len < IEEE80211_MIN_ACTION_SIZE)
  642. return RX_DROP_MONITOR;
  643. /* fall through */
  644. case IEEE80211_STYPE_PROBE_RESP:
  645. case IEEE80211_STYPE_BEACON:
  646. skb_queue_tail(&ifmsh->skb_queue, skb);
  647. ieee80211_queue_work(&local->hw, &ifmsh->work);
  648. return RX_QUEUED;
  649. }
  650. return RX_CONTINUE;
  651. }