mesh_hwmp.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. /*
  2. * Copyright (c) 2008, 2009 open80211s Ltd.
  3. * Author: Luis Carlos Cobo <luisca@cozybit.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include <linux/slab.h>
  10. #include "wme.h"
  11. #include "mesh.h"
  12. #ifdef CONFIG_MAC80211_VERBOSE_MHWMP_DEBUG
  13. #define mhwmp_dbg(fmt, args...) \
  14. printk(KERN_DEBUG "Mesh HWMP (%s): " fmt "\n", sdata->name, ##args)
  15. #else
  16. #define mhwmp_dbg(fmt, args...) do { (void)(0); } while (0)
  17. #endif
  18. #define TEST_FRAME_LEN 8192
  19. #define MAX_METRIC 0xffffffff
  20. #define ARITH_SHIFT 8
  21. /* Number of frames buffered per destination for unresolved destinations */
  22. #define MESH_FRAME_QUEUE_LEN 10
  23. #define MAX_PREQ_QUEUE_LEN 64
  24. /* Destination only */
  25. #define MP_F_DO 0x1
  26. /* Reply and forward */
  27. #define MP_F_RF 0x2
  28. /* Unknown Sequence Number */
  29. #define MP_F_USN 0x01
  30. /* Reason code Present */
  31. #define MP_F_RCODE 0x02
  32. static void mesh_queue_preq(struct mesh_path *, u8);
  33. static inline u32 u32_field_get(u8 *preq_elem, int offset, bool ae)
  34. {
  35. if (ae)
  36. offset += 6;
  37. return get_unaligned_le32(preq_elem + offset);
  38. }
  39. static inline u32 u16_field_get(u8 *preq_elem, int offset, bool ae)
  40. {
  41. if (ae)
  42. offset += 6;
  43. return get_unaligned_le16(preq_elem + offset);
  44. }
  45. /* HWMP IE processing macros */
  46. #define AE_F (1<<6)
  47. #define AE_F_SET(x) (*x & AE_F)
  48. #define PREQ_IE_FLAGS(x) (*(x))
  49. #define PREQ_IE_HOPCOUNT(x) (*(x + 1))
  50. #define PREQ_IE_TTL(x) (*(x + 2))
  51. #define PREQ_IE_PREQ_ID(x) u32_field_get(x, 3, 0)
  52. #define PREQ_IE_ORIG_ADDR(x) (x + 7)
  53. #define PREQ_IE_ORIG_SN(x) u32_field_get(x, 13, 0)
  54. #define PREQ_IE_LIFETIME(x) u32_field_get(x, 17, AE_F_SET(x))
  55. #define PREQ_IE_METRIC(x) u32_field_get(x, 21, AE_F_SET(x))
  56. #define PREQ_IE_TARGET_F(x) (*(AE_F_SET(x) ? x + 32 : x + 26))
  57. #define PREQ_IE_TARGET_ADDR(x) (AE_F_SET(x) ? x + 33 : x + 27)
  58. #define PREQ_IE_TARGET_SN(x) u32_field_get(x, 33, AE_F_SET(x))
  59. #define PREP_IE_FLAGS(x) PREQ_IE_FLAGS(x)
  60. #define PREP_IE_HOPCOUNT(x) PREQ_IE_HOPCOUNT(x)
  61. #define PREP_IE_TTL(x) PREQ_IE_TTL(x)
  62. #define PREP_IE_ORIG_ADDR(x) (AE_F_SET(x) ? x + 27 : x + 21)
  63. #define PREP_IE_ORIG_SN(x) u32_field_get(x, 27, AE_F_SET(x))
  64. #define PREP_IE_LIFETIME(x) u32_field_get(x, 13, AE_F_SET(x))
  65. #define PREP_IE_METRIC(x) u32_field_get(x, 17, AE_F_SET(x))
  66. #define PREP_IE_TARGET_ADDR(x) (x + 3)
  67. #define PREP_IE_TARGET_SN(x) u32_field_get(x, 9, 0)
  68. #define PERR_IE_TTL(x) (*(x))
  69. #define PERR_IE_TARGET_FLAGS(x) (*(x + 2))
  70. #define PERR_IE_TARGET_ADDR(x) (x + 3)
  71. #define PERR_IE_TARGET_SN(x) u32_field_get(x, 9, 0)
  72. #define PERR_IE_TARGET_RCODE(x) u16_field_get(x, 13, 0)
  73. #define MSEC_TO_TU(x) (x*1000/1024)
  74. #define SN_GT(x, y) ((long) (y) - (long) (x) < 0)
  75. #define SN_LT(x, y) ((long) (x) - (long) (y) < 0)
  76. #define net_traversal_jiffies(s) \
  77. msecs_to_jiffies(s->u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime)
  78. #define default_lifetime(s) \
  79. MSEC_TO_TU(s->u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout)
  80. #define min_preq_int_jiff(s) \
  81. (msecs_to_jiffies(s->u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval))
  82. #define max_preq_retries(s) (s->u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries)
  83. #define disc_timeout_jiff(s) \
  84. msecs_to_jiffies(sdata->u.mesh.mshcfg.min_discovery_timeout)
  85. enum mpath_frame_type {
  86. MPATH_PREQ = 0,
  87. MPATH_PREP,
  88. MPATH_PERR,
  89. MPATH_RANN
  90. };
  91. static const u8 broadcast_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  92. static int mesh_path_sel_frame_tx(enum mpath_frame_type action, u8 flags,
  93. u8 *orig_addr, __le32 orig_sn, u8 target_flags, u8 *target,
  94. __le32 target_sn, const u8 *da, u8 hop_count, u8 ttl,
  95. __le32 lifetime, __le32 metric, __le32 preq_id,
  96. struct ieee80211_sub_if_data *sdata)
  97. {
  98. struct ieee80211_local *local = sdata->local;
  99. struct sk_buff *skb;
  100. struct ieee80211_mgmt *mgmt;
  101. u8 *pos, ie_len;
  102. int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.mesh_action) +
  103. sizeof(mgmt->u.action.u.mesh_action);
  104. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  105. hdr_len +
  106. 2 + 37); /* max HWMP IE */
  107. if (!skb)
  108. return -1;
  109. skb_reserve(skb, local->hw.extra_tx_headroom);
  110. mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len);
  111. memset(mgmt, 0, hdr_len);
  112. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  113. IEEE80211_STYPE_ACTION);
  114. memcpy(mgmt->da, da, ETH_ALEN);
  115. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  116. /* BSSID == SA */
  117. memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
  118. mgmt->u.action.category = WLAN_CATEGORY_MESH_ACTION;
  119. mgmt->u.action.u.mesh_action.action_code =
  120. WLAN_MESH_ACTION_HWMP_PATH_SELECTION;
  121. switch (action) {
  122. case MPATH_PREQ:
  123. mhwmp_dbg("sending PREQ to %pM", target);
  124. ie_len = 37;
  125. pos = skb_put(skb, 2 + ie_len);
  126. *pos++ = WLAN_EID_PREQ;
  127. break;
  128. case MPATH_PREP:
  129. mhwmp_dbg("sending PREP to %pM", target);
  130. ie_len = 31;
  131. pos = skb_put(skb, 2 + ie_len);
  132. *pos++ = WLAN_EID_PREP;
  133. break;
  134. case MPATH_RANN:
  135. mhwmp_dbg("sending RANN from %pM", orig_addr);
  136. ie_len = sizeof(struct ieee80211_rann_ie);
  137. pos = skb_put(skb, 2 + ie_len);
  138. *pos++ = WLAN_EID_RANN;
  139. break;
  140. default:
  141. kfree_skb(skb);
  142. return -ENOTSUPP;
  143. break;
  144. }
  145. *pos++ = ie_len;
  146. *pos++ = flags;
  147. *pos++ = hop_count;
  148. *pos++ = ttl;
  149. if (action == MPATH_PREP) {
  150. memcpy(pos, target, ETH_ALEN);
  151. pos += ETH_ALEN;
  152. memcpy(pos, &target_sn, 4);
  153. pos += 4;
  154. } else {
  155. if (action == MPATH_PREQ) {
  156. memcpy(pos, &preq_id, 4);
  157. pos += 4;
  158. }
  159. memcpy(pos, orig_addr, ETH_ALEN);
  160. pos += ETH_ALEN;
  161. memcpy(pos, &orig_sn, 4);
  162. pos += 4;
  163. }
  164. memcpy(pos, &lifetime, 4); /* interval for RANN */
  165. pos += 4;
  166. memcpy(pos, &metric, 4);
  167. pos += 4;
  168. if (action == MPATH_PREQ) {
  169. *pos++ = 1; /* destination count */
  170. *pos++ = target_flags;
  171. memcpy(pos, target, ETH_ALEN);
  172. pos += ETH_ALEN;
  173. memcpy(pos, &target_sn, 4);
  174. pos += 4;
  175. } else if (action == MPATH_PREP) {
  176. memcpy(pos, orig_addr, ETH_ALEN);
  177. pos += ETH_ALEN;
  178. memcpy(pos, &orig_sn, 4);
  179. pos += 4;
  180. }
  181. ieee80211_tx_skb(sdata, skb);
  182. return 0;
  183. }
  184. /* Headroom is not adjusted. Caller should ensure that skb has sufficient
  185. * headroom in case the frame is encrypted. */
  186. static void prepare_frame_for_deferred_tx(struct ieee80211_sub_if_data *sdata,
  187. struct sk_buff *skb)
  188. {
  189. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  190. skb_set_mac_header(skb, 0);
  191. skb_set_network_header(skb, 0);
  192. skb_set_transport_header(skb, 0);
  193. /* Send all internal mgmt frames on VO. Accordingly set TID to 7. */
  194. skb_set_queue_mapping(skb, IEEE80211_AC_VO);
  195. skb->priority = 7;
  196. info->control.vif = &sdata->vif;
  197. ieee80211_set_qos_hdr(sdata, skb);
  198. }
  199. /**
  200. * mesh_send_path error - Sends a PERR mesh management frame
  201. *
  202. * @target: broken destination
  203. * @target_sn: SN of the broken destination
  204. * @target_rcode: reason code for this PERR
  205. * @ra: node this frame is addressed to
  206. *
  207. * Note: This function may be called with driver locks taken that the driver
  208. * also acquires in the TX path. To avoid a deadlock we don't transmit the
  209. * frame directly but add it to the pending queue instead.
  210. */
  211. int mesh_path_error_tx(u8 ttl, u8 *target, __le32 target_sn,
  212. __le16 target_rcode, const u8 *ra,
  213. struct ieee80211_sub_if_data *sdata)
  214. {
  215. struct ieee80211_local *local = sdata->local;
  216. struct sk_buff *skb;
  217. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  218. struct ieee80211_mgmt *mgmt;
  219. u8 *pos, ie_len;
  220. int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.mesh_action) +
  221. sizeof(mgmt->u.action.u.mesh_action);
  222. if (time_before(jiffies, ifmsh->next_perr))
  223. return -EAGAIN;
  224. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  225. hdr_len +
  226. 2 + 15 /* PERR IE */);
  227. if (!skb)
  228. return -1;
  229. skb_reserve(skb, local->tx_headroom + local->hw.extra_tx_headroom);
  230. mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len);
  231. memset(mgmt, 0, hdr_len);
  232. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  233. IEEE80211_STYPE_ACTION);
  234. memcpy(mgmt->da, ra, ETH_ALEN);
  235. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  236. /* BSSID == SA */
  237. memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
  238. mgmt->u.action.category = WLAN_CATEGORY_MESH_ACTION;
  239. mgmt->u.action.u.mesh_action.action_code =
  240. WLAN_MESH_ACTION_HWMP_PATH_SELECTION;
  241. ie_len = 15;
  242. pos = skb_put(skb, 2 + ie_len);
  243. *pos++ = WLAN_EID_PERR;
  244. *pos++ = ie_len;
  245. /* ttl */
  246. *pos++ = ttl;
  247. /* number of destinations */
  248. *pos++ = 1;
  249. /*
  250. * flags bit, bit 1 is unset if we know the sequence number and
  251. * bit 2 is set if we have a reason code
  252. */
  253. *pos = 0;
  254. if (!target_sn)
  255. *pos |= MP_F_USN;
  256. if (target_rcode)
  257. *pos |= MP_F_RCODE;
  258. pos++;
  259. memcpy(pos, target, ETH_ALEN);
  260. pos += ETH_ALEN;
  261. memcpy(pos, &target_sn, 4);
  262. pos += 4;
  263. memcpy(pos, &target_rcode, 2);
  264. /* see note in function header */
  265. prepare_frame_for_deferred_tx(sdata, skb);
  266. ifmsh->next_perr = TU_TO_EXP_TIME(
  267. ifmsh->mshcfg.dot11MeshHWMPperrMinInterval);
  268. ieee80211_add_pending_skb(local, skb);
  269. return 0;
  270. }
  271. void ieee80211s_update_metric(struct ieee80211_local *local,
  272. struct sta_info *stainfo, struct sk_buff *skb)
  273. {
  274. struct ieee80211_tx_info *txinfo = IEEE80211_SKB_CB(skb);
  275. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  276. int failed;
  277. if (!ieee80211_is_data(hdr->frame_control))
  278. return;
  279. failed = !(txinfo->flags & IEEE80211_TX_STAT_ACK);
  280. /* moving average, scaled to 100 */
  281. stainfo->fail_avg = ((80 * stainfo->fail_avg + 5) / 100 + 20 * failed);
  282. if (stainfo->fail_avg > 95)
  283. mesh_plink_broken(stainfo);
  284. }
  285. static u32 airtime_link_metric_get(struct ieee80211_local *local,
  286. struct sta_info *sta)
  287. {
  288. struct ieee80211_supported_band *sband;
  289. /* This should be adjusted for each device */
  290. int device_constant = 1 << ARITH_SHIFT;
  291. int test_frame_len = TEST_FRAME_LEN << ARITH_SHIFT;
  292. int s_unit = 1 << ARITH_SHIFT;
  293. int rate, err;
  294. u32 tx_time, estimated_retx;
  295. u64 result;
  296. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  297. if (sta->fail_avg >= 100)
  298. return MAX_METRIC;
  299. if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
  300. return MAX_METRIC;
  301. err = (sta->fail_avg << ARITH_SHIFT) / 100;
  302. /* bitrate is in units of 100 Kbps, while we need rate in units of
  303. * 1Mbps. This will be corrected on tx_time computation.
  304. */
  305. rate = sband->bitrates[sta->last_tx_rate.idx].bitrate;
  306. tx_time = (device_constant + 10 * test_frame_len / rate);
  307. estimated_retx = ((1 << (2 * ARITH_SHIFT)) / (s_unit - err));
  308. result = (tx_time * estimated_retx) >> (2 * ARITH_SHIFT) ;
  309. return (u32)result;
  310. }
  311. /**
  312. * hwmp_route_info_get - Update routing info to originator and transmitter
  313. *
  314. * @sdata: local mesh subif
  315. * @mgmt: mesh management frame
  316. * @hwmp_ie: hwmp information element (PREP or PREQ)
  317. *
  318. * This function updates the path routing information to the originator and the
  319. * transmitter of a HWMP PREQ or PREP frame.
  320. *
  321. * Returns: metric to frame originator or 0 if the frame should not be further
  322. * processed
  323. *
  324. * Notes: this function is the only place (besides user-provided info) where
  325. * path routing information is updated.
  326. */
  327. static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
  328. struct ieee80211_mgmt *mgmt,
  329. u8 *hwmp_ie, enum mpath_frame_type action)
  330. {
  331. struct ieee80211_local *local = sdata->local;
  332. struct mesh_path *mpath;
  333. struct sta_info *sta;
  334. bool fresh_info;
  335. u8 *orig_addr, *ta;
  336. u32 orig_sn, orig_metric;
  337. unsigned long orig_lifetime, exp_time;
  338. u32 last_hop_metric, new_metric;
  339. bool process = true;
  340. rcu_read_lock();
  341. sta = sta_info_get(sdata, mgmt->sa);
  342. if (!sta) {
  343. rcu_read_unlock();
  344. return 0;
  345. }
  346. last_hop_metric = airtime_link_metric_get(local, sta);
  347. /* Update and check originator routing info */
  348. fresh_info = true;
  349. switch (action) {
  350. case MPATH_PREQ:
  351. orig_addr = PREQ_IE_ORIG_ADDR(hwmp_ie);
  352. orig_sn = PREQ_IE_ORIG_SN(hwmp_ie);
  353. orig_lifetime = PREQ_IE_LIFETIME(hwmp_ie);
  354. orig_metric = PREQ_IE_METRIC(hwmp_ie);
  355. break;
  356. case MPATH_PREP:
  357. /* Originator here refers to the MP that was the target in the
  358. * Path Request. We divert from the nomenclature in the draft
  359. * so that we can easily use a single function to gather path
  360. * information from both PREQ and PREP frames.
  361. */
  362. orig_addr = PREP_IE_TARGET_ADDR(hwmp_ie);
  363. orig_sn = PREP_IE_TARGET_SN(hwmp_ie);
  364. orig_lifetime = PREP_IE_LIFETIME(hwmp_ie);
  365. orig_metric = PREP_IE_METRIC(hwmp_ie);
  366. break;
  367. default:
  368. rcu_read_unlock();
  369. return 0;
  370. }
  371. new_metric = orig_metric + last_hop_metric;
  372. if (new_metric < orig_metric)
  373. new_metric = MAX_METRIC;
  374. exp_time = TU_TO_EXP_TIME(orig_lifetime);
  375. if (memcmp(orig_addr, sdata->vif.addr, ETH_ALEN) == 0) {
  376. /* This MP is the originator, we are not interested in this
  377. * frame, except for updating transmitter's path info.
  378. */
  379. process = false;
  380. fresh_info = false;
  381. } else {
  382. mpath = mesh_path_lookup(orig_addr, sdata);
  383. if (mpath) {
  384. spin_lock_bh(&mpath->state_lock);
  385. if (mpath->flags & MESH_PATH_FIXED)
  386. fresh_info = false;
  387. else if ((mpath->flags & MESH_PATH_ACTIVE) &&
  388. (mpath->flags & MESH_PATH_SN_VALID)) {
  389. if (SN_GT(mpath->sn, orig_sn) ||
  390. (mpath->sn == orig_sn &&
  391. new_metric >= mpath->metric)) {
  392. process = false;
  393. fresh_info = false;
  394. }
  395. }
  396. } else {
  397. mesh_path_add(orig_addr, sdata);
  398. mpath = mesh_path_lookup(orig_addr, sdata);
  399. if (!mpath) {
  400. rcu_read_unlock();
  401. return 0;
  402. }
  403. spin_lock_bh(&mpath->state_lock);
  404. }
  405. if (fresh_info) {
  406. mesh_path_assign_nexthop(mpath, sta);
  407. mpath->flags |= MESH_PATH_SN_VALID;
  408. mpath->metric = new_metric;
  409. mpath->sn = orig_sn;
  410. mpath->exp_time = time_after(mpath->exp_time, exp_time)
  411. ? mpath->exp_time : exp_time;
  412. mesh_path_activate(mpath);
  413. spin_unlock_bh(&mpath->state_lock);
  414. mesh_path_tx_pending(mpath);
  415. /* draft says preq_id should be saved to, but there does
  416. * not seem to be any use for it, skipping by now
  417. */
  418. } else
  419. spin_unlock_bh(&mpath->state_lock);
  420. }
  421. /* Update and check transmitter routing info */
  422. ta = mgmt->sa;
  423. if (memcmp(orig_addr, ta, ETH_ALEN) == 0)
  424. fresh_info = false;
  425. else {
  426. fresh_info = true;
  427. mpath = mesh_path_lookup(ta, sdata);
  428. if (mpath) {
  429. spin_lock_bh(&mpath->state_lock);
  430. if ((mpath->flags & MESH_PATH_FIXED) ||
  431. ((mpath->flags & MESH_PATH_ACTIVE) &&
  432. (last_hop_metric > mpath->metric)))
  433. fresh_info = false;
  434. } else {
  435. mesh_path_add(ta, sdata);
  436. mpath = mesh_path_lookup(ta, sdata);
  437. if (!mpath) {
  438. rcu_read_unlock();
  439. return 0;
  440. }
  441. spin_lock_bh(&mpath->state_lock);
  442. }
  443. if (fresh_info) {
  444. mesh_path_assign_nexthop(mpath, sta);
  445. mpath->metric = last_hop_metric;
  446. mpath->exp_time = time_after(mpath->exp_time, exp_time)
  447. ? mpath->exp_time : exp_time;
  448. mesh_path_activate(mpath);
  449. spin_unlock_bh(&mpath->state_lock);
  450. mesh_path_tx_pending(mpath);
  451. } else
  452. spin_unlock_bh(&mpath->state_lock);
  453. }
  454. rcu_read_unlock();
  455. return process ? new_metric : 0;
  456. }
  457. static void hwmp_preq_frame_process(struct ieee80211_sub_if_data *sdata,
  458. struct ieee80211_mgmt *mgmt,
  459. u8 *preq_elem, u32 metric)
  460. {
  461. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  462. struct mesh_path *mpath;
  463. u8 *target_addr, *orig_addr;
  464. u8 target_flags, ttl;
  465. u32 orig_sn, target_sn, lifetime;
  466. bool reply = false;
  467. bool forward = true;
  468. /* Update target SN, if present */
  469. target_addr = PREQ_IE_TARGET_ADDR(preq_elem);
  470. orig_addr = PREQ_IE_ORIG_ADDR(preq_elem);
  471. target_sn = PREQ_IE_TARGET_SN(preq_elem);
  472. orig_sn = PREQ_IE_ORIG_SN(preq_elem);
  473. target_flags = PREQ_IE_TARGET_F(preq_elem);
  474. mhwmp_dbg("received PREQ from %pM", orig_addr);
  475. if (memcmp(target_addr, sdata->vif.addr, ETH_ALEN) == 0) {
  476. mhwmp_dbg("PREQ is for us");
  477. forward = false;
  478. reply = true;
  479. metric = 0;
  480. if (time_after(jiffies, ifmsh->last_sn_update +
  481. net_traversal_jiffies(sdata)) ||
  482. time_before(jiffies, ifmsh->last_sn_update)) {
  483. target_sn = ++ifmsh->sn;
  484. ifmsh->last_sn_update = jiffies;
  485. }
  486. } else {
  487. rcu_read_lock();
  488. mpath = mesh_path_lookup(target_addr, sdata);
  489. if (mpath) {
  490. if ((!(mpath->flags & MESH_PATH_SN_VALID)) ||
  491. SN_LT(mpath->sn, target_sn)) {
  492. mpath->sn = target_sn;
  493. mpath->flags |= MESH_PATH_SN_VALID;
  494. } else if ((!(target_flags & MP_F_DO)) &&
  495. (mpath->flags & MESH_PATH_ACTIVE)) {
  496. reply = true;
  497. metric = mpath->metric;
  498. target_sn = mpath->sn;
  499. if (target_flags & MP_F_RF)
  500. target_flags |= MP_F_DO;
  501. else
  502. forward = false;
  503. }
  504. }
  505. rcu_read_unlock();
  506. }
  507. if (reply) {
  508. lifetime = PREQ_IE_LIFETIME(preq_elem);
  509. ttl = ifmsh->mshcfg.element_ttl;
  510. if (ttl != 0) {
  511. mhwmp_dbg("replying to the PREQ");
  512. mesh_path_sel_frame_tx(MPATH_PREP, 0, orig_addr,
  513. cpu_to_le32(orig_sn), 0, target_addr,
  514. cpu_to_le32(target_sn), mgmt->sa, 0, ttl,
  515. cpu_to_le32(lifetime), cpu_to_le32(metric),
  516. 0, sdata);
  517. } else
  518. ifmsh->mshstats.dropped_frames_ttl++;
  519. }
  520. if (forward) {
  521. u32 preq_id;
  522. u8 hopcount, flags;
  523. ttl = PREQ_IE_TTL(preq_elem);
  524. lifetime = PREQ_IE_LIFETIME(preq_elem);
  525. if (ttl <= 1) {
  526. ifmsh->mshstats.dropped_frames_ttl++;
  527. return;
  528. }
  529. mhwmp_dbg("forwarding the PREQ from %pM", orig_addr);
  530. --ttl;
  531. flags = PREQ_IE_FLAGS(preq_elem);
  532. preq_id = PREQ_IE_PREQ_ID(preq_elem);
  533. hopcount = PREQ_IE_HOPCOUNT(preq_elem) + 1;
  534. mesh_path_sel_frame_tx(MPATH_PREQ, flags, orig_addr,
  535. cpu_to_le32(orig_sn), target_flags, target_addr,
  536. cpu_to_le32(target_sn), broadcast_addr,
  537. hopcount, ttl, cpu_to_le32(lifetime),
  538. cpu_to_le32(metric), cpu_to_le32(preq_id),
  539. sdata);
  540. ifmsh->mshstats.fwded_mcast++;
  541. ifmsh->mshstats.fwded_frames++;
  542. }
  543. }
  544. static inline struct sta_info *
  545. next_hop_deref_protected(struct mesh_path *mpath)
  546. {
  547. return rcu_dereference_protected(mpath->next_hop,
  548. lockdep_is_held(&mpath->state_lock));
  549. }
  550. static void hwmp_prep_frame_process(struct ieee80211_sub_if_data *sdata,
  551. struct ieee80211_mgmt *mgmt,
  552. u8 *prep_elem, u32 metric)
  553. {
  554. struct mesh_path *mpath;
  555. u8 *target_addr, *orig_addr;
  556. u8 ttl, hopcount, flags;
  557. u8 next_hop[ETH_ALEN];
  558. u32 target_sn, orig_sn, lifetime;
  559. mhwmp_dbg("received PREP from %pM", PREP_IE_ORIG_ADDR(prep_elem));
  560. orig_addr = PREP_IE_ORIG_ADDR(prep_elem);
  561. if (memcmp(orig_addr, sdata->vif.addr, ETH_ALEN) == 0)
  562. /* destination, no forwarding required */
  563. return;
  564. ttl = PREP_IE_TTL(prep_elem);
  565. if (ttl <= 1) {
  566. sdata->u.mesh.mshstats.dropped_frames_ttl++;
  567. return;
  568. }
  569. rcu_read_lock();
  570. mpath = mesh_path_lookup(orig_addr, sdata);
  571. if (mpath)
  572. spin_lock_bh(&mpath->state_lock);
  573. else
  574. goto fail;
  575. if (!(mpath->flags & MESH_PATH_ACTIVE)) {
  576. spin_unlock_bh(&mpath->state_lock);
  577. goto fail;
  578. }
  579. memcpy(next_hop, next_hop_deref_protected(mpath)->sta.addr, ETH_ALEN);
  580. spin_unlock_bh(&mpath->state_lock);
  581. --ttl;
  582. flags = PREP_IE_FLAGS(prep_elem);
  583. lifetime = PREP_IE_LIFETIME(prep_elem);
  584. hopcount = PREP_IE_HOPCOUNT(prep_elem) + 1;
  585. target_addr = PREP_IE_TARGET_ADDR(prep_elem);
  586. target_sn = PREP_IE_TARGET_SN(prep_elem);
  587. orig_sn = PREP_IE_ORIG_SN(prep_elem);
  588. mesh_path_sel_frame_tx(MPATH_PREP, flags, orig_addr,
  589. cpu_to_le32(orig_sn), 0, target_addr,
  590. cpu_to_le32(target_sn), next_hop, hopcount,
  591. ttl, cpu_to_le32(lifetime), cpu_to_le32(metric),
  592. 0, sdata);
  593. rcu_read_unlock();
  594. sdata->u.mesh.mshstats.fwded_unicast++;
  595. sdata->u.mesh.mshstats.fwded_frames++;
  596. return;
  597. fail:
  598. rcu_read_unlock();
  599. sdata->u.mesh.mshstats.dropped_frames_no_route++;
  600. }
  601. static void hwmp_perr_frame_process(struct ieee80211_sub_if_data *sdata,
  602. struct ieee80211_mgmt *mgmt, u8 *perr_elem)
  603. {
  604. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  605. struct mesh_path *mpath;
  606. u8 ttl;
  607. u8 *ta, *target_addr;
  608. u32 target_sn;
  609. u16 target_rcode;
  610. ta = mgmt->sa;
  611. ttl = PERR_IE_TTL(perr_elem);
  612. if (ttl <= 1) {
  613. ifmsh->mshstats.dropped_frames_ttl++;
  614. return;
  615. }
  616. ttl--;
  617. target_addr = PERR_IE_TARGET_ADDR(perr_elem);
  618. target_sn = PERR_IE_TARGET_SN(perr_elem);
  619. target_rcode = PERR_IE_TARGET_RCODE(perr_elem);
  620. rcu_read_lock();
  621. mpath = mesh_path_lookup(target_addr, sdata);
  622. if (mpath) {
  623. spin_lock_bh(&mpath->state_lock);
  624. if (mpath->flags & MESH_PATH_ACTIVE &&
  625. memcmp(ta, next_hop_deref_protected(mpath)->sta.addr,
  626. ETH_ALEN) == 0 &&
  627. (!(mpath->flags & MESH_PATH_SN_VALID) ||
  628. SN_GT(target_sn, mpath->sn))) {
  629. mpath->flags &= ~MESH_PATH_ACTIVE;
  630. mpath->sn = target_sn;
  631. spin_unlock_bh(&mpath->state_lock);
  632. mesh_path_error_tx(ttl, target_addr, cpu_to_le32(target_sn),
  633. cpu_to_le16(target_rcode),
  634. broadcast_addr, sdata);
  635. } else
  636. spin_unlock_bh(&mpath->state_lock);
  637. }
  638. rcu_read_unlock();
  639. }
  640. static void hwmp_rann_frame_process(struct ieee80211_sub_if_data *sdata,
  641. struct ieee80211_mgmt *mgmt,
  642. struct ieee80211_rann_ie *rann)
  643. {
  644. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  645. struct mesh_path *mpath;
  646. u8 ttl, flags, hopcount;
  647. u8 *orig_addr;
  648. u32 orig_sn, metric;
  649. u32 interval = ifmsh->mshcfg.dot11MeshHWMPRannInterval;
  650. bool root_is_gate;
  651. ttl = rann->rann_ttl;
  652. if (ttl <= 1) {
  653. ifmsh->mshstats.dropped_frames_ttl++;
  654. return;
  655. }
  656. ttl--;
  657. flags = rann->rann_flags;
  658. root_is_gate = !!(flags & RANN_FLAG_IS_GATE);
  659. orig_addr = rann->rann_addr;
  660. orig_sn = rann->rann_seq;
  661. hopcount = rann->rann_hopcount;
  662. hopcount++;
  663. metric = rann->rann_metric;
  664. /* Ignore our own RANNs */
  665. if (memcmp(orig_addr, sdata->vif.addr, ETH_ALEN) == 0)
  666. return;
  667. mhwmp_dbg("received RANN from %pM (is_gate=%d)", orig_addr,
  668. root_is_gate);
  669. rcu_read_lock();
  670. mpath = mesh_path_lookup(orig_addr, sdata);
  671. if (!mpath) {
  672. mesh_path_add(orig_addr, sdata);
  673. mpath = mesh_path_lookup(orig_addr, sdata);
  674. if (!mpath) {
  675. rcu_read_unlock();
  676. sdata->u.mesh.mshstats.dropped_frames_no_route++;
  677. return;
  678. }
  679. }
  680. if ((!(mpath->flags & (MESH_PATH_ACTIVE | MESH_PATH_RESOLVING)) ||
  681. time_after(jiffies, mpath->exp_time - 1*HZ)) &&
  682. !(mpath->flags & MESH_PATH_FIXED)) {
  683. mhwmp_dbg("%s time to refresh root mpath %pM", sdata->name,
  684. orig_addr);
  685. mesh_queue_preq(mpath, PREQ_Q_F_START | PREQ_Q_F_REFRESH);
  686. }
  687. if (mpath->sn < orig_sn) {
  688. mesh_path_sel_frame_tx(MPATH_RANN, flags, orig_addr,
  689. cpu_to_le32(orig_sn),
  690. 0, NULL, 0, broadcast_addr,
  691. hopcount, ttl, cpu_to_le32(interval),
  692. cpu_to_le32(metric + mpath->metric),
  693. 0, sdata);
  694. mpath->sn = orig_sn;
  695. }
  696. if (root_is_gate)
  697. mesh_path_add_gate(mpath);
  698. rcu_read_unlock();
  699. }
  700. void mesh_rx_path_sel_frame(struct ieee80211_sub_if_data *sdata,
  701. struct ieee80211_mgmt *mgmt,
  702. size_t len)
  703. {
  704. struct ieee802_11_elems elems;
  705. size_t baselen;
  706. u32 last_hop_metric;
  707. struct sta_info *sta;
  708. /* need action_code */
  709. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  710. return;
  711. rcu_read_lock();
  712. sta = sta_info_get(sdata, mgmt->sa);
  713. if (!sta || sta->plink_state != NL80211_PLINK_ESTAB) {
  714. rcu_read_unlock();
  715. return;
  716. }
  717. rcu_read_unlock();
  718. baselen = (u8 *) mgmt->u.action.u.mesh_action.variable - (u8 *) mgmt;
  719. ieee802_11_parse_elems(mgmt->u.action.u.mesh_action.variable,
  720. len - baselen, &elems);
  721. if (elems.preq) {
  722. if (elems.preq_len != 37)
  723. /* Right now we support just 1 destination and no AE */
  724. return;
  725. last_hop_metric = hwmp_route_info_get(sdata, mgmt, elems.preq,
  726. MPATH_PREQ);
  727. if (last_hop_metric)
  728. hwmp_preq_frame_process(sdata, mgmt, elems.preq,
  729. last_hop_metric);
  730. }
  731. if (elems.prep) {
  732. if (elems.prep_len != 31)
  733. /* Right now we support no AE */
  734. return;
  735. last_hop_metric = hwmp_route_info_get(sdata, mgmt, elems.prep,
  736. MPATH_PREP);
  737. if (last_hop_metric)
  738. hwmp_prep_frame_process(sdata, mgmt, elems.prep,
  739. last_hop_metric);
  740. }
  741. if (elems.perr) {
  742. if (elems.perr_len != 15)
  743. /* Right now we support only one destination per PERR */
  744. return;
  745. hwmp_perr_frame_process(sdata, mgmt, elems.perr);
  746. }
  747. if (elems.rann)
  748. hwmp_rann_frame_process(sdata, mgmt, elems.rann);
  749. }
  750. /**
  751. * mesh_queue_preq - queue a PREQ to a given destination
  752. *
  753. * @mpath: mesh path to discover
  754. * @flags: special attributes of the PREQ to be sent
  755. *
  756. * Locking: the function must be called from within a rcu read lock block.
  757. *
  758. */
  759. static void mesh_queue_preq(struct mesh_path *mpath, u8 flags)
  760. {
  761. struct ieee80211_sub_if_data *sdata = mpath->sdata;
  762. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  763. struct mesh_preq_queue *preq_node;
  764. preq_node = kmalloc(sizeof(struct mesh_preq_queue), GFP_ATOMIC);
  765. if (!preq_node) {
  766. mhwmp_dbg("could not allocate PREQ node");
  767. return;
  768. }
  769. spin_lock_bh(&ifmsh->mesh_preq_queue_lock);
  770. if (ifmsh->preq_queue_len == MAX_PREQ_QUEUE_LEN) {
  771. spin_unlock_bh(&ifmsh->mesh_preq_queue_lock);
  772. kfree(preq_node);
  773. if (printk_ratelimit())
  774. mhwmp_dbg("PREQ node queue full");
  775. return;
  776. }
  777. spin_lock(&mpath->state_lock);
  778. if (mpath->flags & MESH_PATH_REQ_QUEUED) {
  779. spin_unlock(&mpath->state_lock);
  780. spin_unlock_bh(&ifmsh->mesh_preq_queue_lock);
  781. kfree(preq_node);
  782. return;
  783. }
  784. memcpy(preq_node->dst, mpath->dst, ETH_ALEN);
  785. preq_node->flags = flags;
  786. mpath->flags |= MESH_PATH_REQ_QUEUED;
  787. spin_unlock(&mpath->state_lock);
  788. list_add_tail(&preq_node->list, &ifmsh->preq_queue.list);
  789. ++ifmsh->preq_queue_len;
  790. spin_unlock_bh(&ifmsh->mesh_preq_queue_lock);
  791. if (time_after(jiffies, ifmsh->last_preq + min_preq_int_jiff(sdata)))
  792. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  793. else if (time_before(jiffies, ifmsh->last_preq)) {
  794. /* avoid long wait if did not send preqs for a long time
  795. * and jiffies wrapped around
  796. */
  797. ifmsh->last_preq = jiffies - min_preq_int_jiff(sdata) - 1;
  798. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  799. } else
  800. mod_timer(&ifmsh->mesh_path_timer, ifmsh->last_preq +
  801. min_preq_int_jiff(sdata));
  802. }
  803. /**
  804. * mesh_path_start_discovery - launch a path discovery from the PREQ queue
  805. *
  806. * @sdata: local mesh subif
  807. */
  808. void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata)
  809. {
  810. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  811. struct mesh_preq_queue *preq_node;
  812. struct mesh_path *mpath;
  813. u8 ttl, target_flags;
  814. u32 lifetime;
  815. spin_lock_bh(&ifmsh->mesh_preq_queue_lock);
  816. if (!ifmsh->preq_queue_len ||
  817. time_before(jiffies, ifmsh->last_preq +
  818. min_preq_int_jiff(sdata))) {
  819. spin_unlock_bh(&ifmsh->mesh_preq_queue_lock);
  820. return;
  821. }
  822. preq_node = list_first_entry(&ifmsh->preq_queue.list,
  823. struct mesh_preq_queue, list);
  824. list_del(&preq_node->list);
  825. --ifmsh->preq_queue_len;
  826. spin_unlock_bh(&ifmsh->mesh_preq_queue_lock);
  827. rcu_read_lock();
  828. mpath = mesh_path_lookup(preq_node->dst, sdata);
  829. if (!mpath)
  830. goto enddiscovery;
  831. spin_lock_bh(&mpath->state_lock);
  832. mpath->flags &= ~MESH_PATH_REQ_QUEUED;
  833. if (preq_node->flags & PREQ_Q_F_START) {
  834. if (mpath->flags & MESH_PATH_RESOLVING) {
  835. spin_unlock_bh(&mpath->state_lock);
  836. goto enddiscovery;
  837. } else {
  838. mpath->flags &= ~MESH_PATH_RESOLVED;
  839. mpath->flags |= MESH_PATH_RESOLVING;
  840. mpath->discovery_retries = 0;
  841. mpath->discovery_timeout = disc_timeout_jiff(sdata);
  842. }
  843. } else if (!(mpath->flags & MESH_PATH_RESOLVING) ||
  844. mpath->flags & MESH_PATH_RESOLVED) {
  845. mpath->flags &= ~MESH_PATH_RESOLVING;
  846. spin_unlock_bh(&mpath->state_lock);
  847. goto enddiscovery;
  848. }
  849. ifmsh->last_preq = jiffies;
  850. if (time_after(jiffies, ifmsh->last_sn_update +
  851. net_traversal_jiffies(sdata)) ||
  852. time_before(jiffies, ifmsh->last_sn_update)) {
  853. ++ifmsh->sn;
  854. sdata->u.mesh.last_sn_update = jiffies;
  855. }
  856. lifetime = default_lifetime(sdata);
  857. ttl = sdata->u.mesh.mshcfg.element_ttl;
  858. if (ttl == 0) {
  859. sdata->u.mesh.mshstats.dropped_frames_ttl++;
  860. spin_unlock_bh(&mpath->state_lock);
  861. goto enddiscovery;
  862. }
  863. if (preq_node->flags & PREQ_Q_F_REFRESH)
  864. target_flags = MP_F_DO;
  865. else
  866. target_flags = MP_F_RF;
  867. spin_unlock_bh(&mpath->state_lock);
  868. mesh_path_sel_frame_tx(MPATH_PREQ, 0, sdata->vif.addr,
  869. cpu_to_le32(ifmsh->sn), target_flags, mpath->dst,
  870. cpu_to_le32(mpath->sn), broadcast_addr, 0,
  871. ttl, cpu_to_le32(lifetime), 0,
  872. cpu_to_le32(ifmsh->preq_id++), sdata);
  873. mod_timer(&mpath->timer, jiffies + mpath->discovery_timeout);
  874. enddiscovery:
  875. rcu_read_unlock();
  876. kfree(preq_node);
  877. }
  878. /**
  879. * mesh_nexthop_lookup - put the appropriate next hop on a mesh frame
  880. *
  881. * @skb: 802.11 frame to be sent
  882. * @sdata: network subif the frame will be sent through
  883. *
  884. * Returns: 0 if the next hop was found. Nonzero otherwise. If no next hop is
  885. * found, the function will start a path discovery and queue the frame so it is
  886. * sent when the path is resolved. This means the caller must not free the skb
  887. * in this case.
  888. */
  889. int mesh_nexthop_lookup(struct sk_buff *skb,
  890. struct ieee80211_sub_if_data *sdata)
  891. {
  892. struct sk_buff *skb_to_free = NULL;
  893. struct mesh_path *mpath;
  894. struct sta_info *next_hop;
  895. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  896. u8 *target_addr = hdr->addr3;
  897. int err = 0;
  898. rcu_read_lock();
  899. mpath = mesh_path_lookup(target_addr, sdata);
  900. if (!mpath) {
  901. mesh_path_add(target_addr, sdata);
  902. mpath = mesh_path_lookup(target_addr, sdata);
  903. if (!mpath) {
  904. sdata->u.mesh.mshstats.dropped_frames_no_route++;
  905. err = -ENOSPC;
  906. goto endlookup;
  907. }
  908. }
  909. if (mpath->flags & MESH_PATH_ACTIVE) {
  910. if (time_after(jiffies,
  911. mpath->exp_time -
  912. msecs_to_jiffies(sdata->u.mesh.mshcfg.path_refresh_time)) &&
  913. !memcmp(sdata->vif.addr, hdr->addr4, ETH_ALEN) &&
  914. !(mpath->flags & MESH_PATH_RESOLVING) &&
  915. !(mpath->flags & MESH_PATH_FIXED)) {
  916. mesh_queue_preq(mpath,
  917. PREQ_Q_F_START | PREQ_Q_F_REFRESH);
  918. }
  919. next_hop = rcu_dereference(mpath->next_hop);
  920. if (next_hop) {
  921. memcpy(hdr->addr1, next_hop->sta.addr, ETH_ALEN);
  922. memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
  923. } else
  924. err = -ENOENT;
  925. } else {
  926. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  927. if (!(mpath->flags & MESH_PATH_RESOLVING)) {
  928. /* Start discovery only if it is not running yet */
  929. mesh_queue_preq(mpath, PREQ_Q_F_START);
  930. }
  931. if (skb_queue_len(&mpath->frame_queue) >= MESH_FRAME_QUEUE_LEN)
  932. skb_to_free = skb_dequeue(&mpath->frame_queue);
  933. info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
  934. ieee80211_set_qos_hdr(sdata, skb);
  935. skb_queue_tail(&mpath->frame_queue, skb);
  936. if (skb_to_free)
  937. mesh_path_discard_frame(skb_to_free, sdata);
  938. err = -ENOENT;
  939. }
  940. endlookup:
  941. rcu_read_unlock();
  942. return err;
  943. }
  944. void mesh_path_timer(unsigned long data)
  945. {
  946. struct mesh_path *mpath = (void *) data;
  947. struct ieee80211_sub_if_data *sdata = mpath->sdata;
  948. int ret;
  949. if (sdata->local->quiescing)
  950. return;
  951. spin_lock_bh(&mpath->state_lock);
  952. if (mpath->flags & MESH_PATH_RESOLVED ||
  953. (!(mpath->flags & MESH_PATH_RESOLVING))) {
  954. mpath->flags &= ~(MESH_PATH_RESOLVING | MESH_PATH_RESOLVED);
  955. spin_unlock_bh(&mpath->state_lock);
  956. } else if (mpath->discovery_retries < max_preq_retries(sdata)) {
  957. ++mpath->discovery_retries;
  958. mpath->discovery_timeout *= 2;
  959. mpath->flags &= ~MESH_PATH_REQ_QUEUED;
  960. spin_unlock_bh(&mpath->state_lock);
  961. mesh_queue_preq(mpath, 0);
  962. } else {
  963. mpath->flags = 0;
  964. mpath->exp_time = jiffies;
  965. spin_unlock_bh(&mpath->state_lock);
  966. if (!mpath->is_gate && mesh_gate_num(sdata) > 0) {
  967. ret = mesh_path_send_to_gates(mpath);
  968. if (ret)
  969. mhwmp_dbg("no gate was reachable");
  970. } else
  971. mesh_path_flush_pending(mpath);
  972. }
  973. }
  974. void
  975. mesh_path_tx_root_frame(struct ieee80211_sub_if_data *sdata)
  976. {
  977. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  978. u32 interval = ifmsh->mshcfg.dot11MeshHWMPRannInterval;
  979. u8 flags;
  980. flags = (ifmsh->mshcfg.dot11MeshGateAnnouncementProtocol)
  981. ? RANN_FLAG_IS_GATE : 0;
  982. mesh_path_sel_frame_tx(MPATH_RANN, flags, sdata->vif.addr,
  983. cpu_to_le32(++ifmsh->sn),
  984. 0, NULL, 0, broadcast_addr,
  985. 0, sdata->u.mesh.mshcfg.element_ttl,
  986. cpu_to_le32(interval), 0, 0, sdata);
  987. }