Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * Copyright (c) 2008, 2009 open80211s Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Copyright (C) 2019 Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Author:     Luis Carlos Cobo <luisca@cozybit.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include "wme.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include "mesh.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #define TEST_FRAME_LEN	8192
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #define MAX_METRIC	0xffffffff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #define ARITH_SHIFT	8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #define LINK_FAIL_THRESH 95
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #define MAX_PREQ_QUEUE_LEN	64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) static void mesh_queue_preq(struct mesh_path *, u8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) static inline u32 u32_field_get(const u8 *preq_elem, int offset, bool ae)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) 	if (ae)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) 		offset += 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) 	return get_unaligned_le32(preq_elem + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) static inline u16 u16_field_get(const u8 *preq_elem, int offset, bool ae)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) 	if (ae)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 		offset += 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 	return get_unaligned_le16(preq_elem + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) /* HWMP IE processing macros */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #define AE_F			(1<<6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #define AE_F_SET(x)		(*x & AE_F)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #define PREQ_IE_FLAGS(x)	(*(x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #define PREQ_IE_HOPCOUNT(x)	(*(x + 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #define PREQ_IE_TTL(x)		(*(x + 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #define PREQ_IE_PREQ_ID(x)	u32_field_get(x, 3, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #define PREQ_IE_ORIG_ADDR(x)	(x + 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #define PREQ_IE_ORIG_SN(x)	u32_field_get(x, 13, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #define PREQ_IE_LIFETIME(x)	u32_field_get(x, 17, AE_F_SET(x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #define PREQ_IE_METRIC(x) 	u32_field_get(x, 21, AE_F_SET(x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #define PREQ_IE_TARGET_F(x)	(*(AE_F_SET(x) ? x + 32 : x + 26))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #define PREQ_IE_TARGET_ADDR(x) 	(AE_F_SET(x) ? x + 33 : x + 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #define PREQ_IE_TARGET_SN(x) 	u32_field_get(x, 33, AE_F_SET(x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #define PREP_IE_FLAGS(x)	PREQ_IE_FLAGS(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #define PREP_IE_HOPCOUNT(x)	PREQ_IE_HOPCOUNT(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #define PREP_IE_TTL(x)		PREQ_IE_TTL(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #define PREP_IE_ORIG_ADDR(x)	(AE_F_SET(x) ? x + 27 : x + 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #define PREP_IE_ORIG_SN(x)	u32_field_get(x, 27, AE_F_SET(x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #define PREP_IE_LIFETIME(x)	u32_field_get(x, 13, AE_F_SET(x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #define PREP_IE_METRIC(x)	u32_field_get(x, 17, AE_F_SET(x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #define PREP_IE_TARGET_ADDR(x)	(x + 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) #define PREP_IE_TARGET_SN(x)	u32_field_get(x, 9, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) #define PERR_IE_TTL(x)		(*(x))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #define PERR_IE_TARGET_FLAGS(x)	(*(x + 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) #define PERR_IE_TARGET_ADDR(x)	(x + 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) #define PERR_IE_TARGET_SN(x)	u32_field_get(x, 9, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) #define PERR_IE_TARGET_RCODE(x)	u16_field_get(x, 13, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #define MSEC_TO_TU(x) (x*1000/1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) #define SN_GT(x, y) ((s32)(y - x) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) #define SN_LT(x, y) ((s32)(x - y) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) #define MAX_SANE_SN_DELTA 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) static inline u32 SN_DELTA(u32 x, u32 y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	return x >= y ? x - y : y - x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) #define net_traversal_jiffies(s) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	msecs_to_jiffies(s->u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) #define default_lifetime(s) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	MSEC_TO_TU(s->u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) #define min_preq_int_jiff(s) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	(msecs_to_jiffies(s->u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) #define max_preq_retries(s) (s->u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) #define disc_timeout_jiff(s) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	msecs_to_jiffies(sdata->u.mesh.mshcfg.min_discovery_timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) #define root_path_confirmation_jiffies(s) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	msecs_to_jiffies(sdata->u.mesh.mshcfg.dot11MeshHWMPconfirmationInterval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) enum mpath_frame_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	MPATH_PREQ = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 	MPATH_PREP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	MPATH_PERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	MPATH_RANN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) static const u8 broadcast_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) static int mesh_path_sel_frame_tx(enum mpath_frame_type action, u8 flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 				  const u8 *orig_addr, u32 orig_sn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 				  u8 target_flags, const u8 *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 				  u32 target_sn, const u8 *da,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 				  u8 hop_count, u8 ttl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 				  u32 lifetime, u32 metric, u32 preq_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 				  struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	struct ieee80211_mgmt *mgmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	u8 *pos, ie_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	int hdr_len = offsetofend(struct ieee80211_mgmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 				  u.action.u.mesh_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	skb = dev_alloc_skb(local->tx_headroom +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 			    hdr_len +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 			    2 + 37); /* max HWMP IE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	skb_reserve(skb, local->tx_headroom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	mgmt = skb_put_zero(skb, hdr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 					  IEEE80211_STYPE_ACTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	memcpy(mgmt->da, da, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	/* BSSID == SA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	mgmt->u.action.category = WLAN_CATEGORY_MESH_ACTION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	mgmt->u.action.u.mesh_action.action_code =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 					WLAN_MESH_ACTION_HWMP_PATH_SELECTION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	switch (action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	case MPATH_PREQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 		mhwmp_dbg(sdata, "sending PREQ to %pM\n", target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 		ie_len = 37;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 		pos = skb_put(skb, 2 + ie_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 		*pos++ = WLAN_EID_PREQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	case MPATH_PREP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 		mhwmp_dbg(sdata, "sending PREP to %pM\n", orig_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 		ie_len = 31;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 		pos = skb_put(skb, 2 + ie_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 		*pos++ = WLAN_EID_PREP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	case MPATH_RANN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 		mhwmp_dbg(sdata, "sending RANN from %pM\n", orig_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 		ie_len = sizeof(struct ieee80211_rann_ie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 		pos = skb_put(skb, 2 + ie_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 		*pos++ = WLAN_EID_RANN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 		return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	*pos++ = ie_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	*pos++ = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	*pos++ = hop_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	*pos++ = ttl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	if (action == MPATH_PREP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 		memcpy(pos, target, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 		pos += ETH_ALEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 		put_unaligned_le32(target_sn, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 		pos += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 		if (action == MPATH_PREQ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 			put_unaligned_le32(preq_id, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 			pos += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 		memcpy(pos, orig_addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 		pos += ETH_ALEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 		put_unaligned_le32(orig_sn, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 		pos += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	put_unaligned_le32(lifetime, pos); /* interval for RANN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	pos += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	put_unaligned_le32(metric, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	pos += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	if (action == MPATH_PREQ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 		*pos++ = 1; /* destination count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 		*pos++ = target_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 		memcpy(pos, target, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 		pos += ETH_ALEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 		put_unaligned_le32(target_sn, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 		pos += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	} else if (action == MPATH_PREP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 		memcpy(pos, orig_addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 		pos += ETH_ALEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 		put_unaligned_le32(orig_sn, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 		pos += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	ieee80211_tx_skb(sdata, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) /*  Headroom is not adjusted.  Caller should ensure that skb has sufficient
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199)  *  headroom in case the frame is encrypted. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) static void prepare_frame_for_deferred_tx(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 		struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	skb_reset_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	skb_reset_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	skb_reset_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	/* Send all internal mgmt frames on VO. Accordingly set TID to 7. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	skb_set_queue_mapping(skb, IEEE80211_AC_VO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	skb->priority = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	info->control.vif = &sdata->vif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	ieee80211_set_qos_hdr(sdata, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	ieee80211_mps_set_frame_flags(sdata, NULL, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221)  * mesh_path_error_tx - Sends a PERR mesh management frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223)  * @ttl: allowed remaining hops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224)  * @target: broken destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225)  * @target_sn: SN of the broken destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226)  * @target_rcode: reason code for this PERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227)  * @ra: node this frame is addressed to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228)  * @sdata: local mesh subif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230)  * Note: This function may be called with driver locks taken that the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231)  * also acquires in the TX path.  To avoid a deadlock we don't transmit the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232)  * frame directly but add it to the pending queue instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) int mesh_path_error_tx(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 		       u8 ttl, const u8 *target, u32 target_sn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 		       u16 target_rcode, const u8 *ra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	struct ieee80211_mgmt *mgmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	u8 *pos, ie_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	int hdr_len = offsetofend(struct ieee80211_mgmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 				  u.action.u.mesh_action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	if (time_before(jiffies, ifmsh->next_perr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	skb = dev_alloc_skb(local->tx_headroom +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 			    sdata->encrypt_headroom +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 			    IEEE80211_ENCRYPT_TAILROOM +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 			    hdr_len +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 			    2 + 15 /* PERR IE */);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	skb_reserve(skb, local->tx_headroom + sdata->encrypt_headroom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	mgmt = skb_put_zero(skb, hdr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 					  IEEE80211_STYPE_ACTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	memcpy(mgmt->da, ra, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	/* BSSID == SA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	mgmt->u.action.category = WLAN_CATEGORY_MESH_ACTION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	mgmt->u.action.u.mesh_action.action_code =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 					WLAN_MESH_ACTION_HWMP_PATH_SELECTION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	ie_len = 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	pos = skb_put(skb, 2 + ie_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	*pos++ = WLAN_EID_PERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	*pos++ = ie_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	/* ttl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	*pos++ = ttl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	/* number of destinations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	*pos++ = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	/* Flags field has AE bit only as defined in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	 * sec 8.4.2.117 IEEE802.11-2012
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	*pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	pos++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	memcpy(pos, target, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	pos += ETH_ALEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	put_unaligned_le32(target_sn, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	pos += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	put_unaligned_le16(target_rcode, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	/* see note in function header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	prepare_frame_for_deferred_tx(sdata, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	ifmsh->next_perr = TU_TO_EXP_TIME(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 				   ifmsh->mshcfg.dot11MeshHWMPperrMinInterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	ieee80211_add_pending_skb(local, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) void ieee80211s_update_metric(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 			      struct sta_info *sta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 			      struct ieee80211_tx_status *st)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	struct ieee80211_tx_info *txinfo = st->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	int failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	struct rate_info rinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	failed = !(txinfo->flags & IEEE80211_TX_STAT_ACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	/* moving average, scaled to 100.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	 * feed failure as 100 and success as 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	ewma_mesh_fail_avg_add(&sta->mesh->fail_avg, failed * 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	if (ewma_mesh_fail_avg_read(&sta->mesh->fail_avg) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 			LINK_FAIL_THRESH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		mesh_plink_broken(sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	sta_set_rate_info_tx(sta, &sta->tx_stats.last_rate, &rinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	ewma_mesh_tx_rate_avg_add(&sta->mesh->tx_rate_avg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 				  cfg80211_calculate_bitrate(&rinfo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) u32 airtime_link_metric_get(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 			    struct sta_info *sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	/* This should be adjusted for each device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	int device_constant = 1 << ARITH_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	int test_frame_len = TEST_FRAME_LEN << ARITH_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	int s_unit = 1 << ARITH_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	int rate, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	u32 tx_time, estimated_retx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	u64 result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	unsigned long fail_avg =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 		ewma_mesh_fail_avg_read(&sta->mesh->fail_avg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 		return MAX_METRIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	/* Try to get rate based on HW/SW RC algorithm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	 * Rate is returned in units of Kbps, correct this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	 * to comply with airtime calculation units
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	 * Round up in case we get rate < 100Kbps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	rate = DIV_ROUND_UP(sta_get_expected_throughput(sta), 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	if (rate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 		err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		if (fail_avg > LINK_FAIL_THRESH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 			return MAX_METRIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		rate = ewma_mesh_tx_rate_avg_read(&sta->mesh->tx_rate_avg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 		if (WARN_ON(!rate))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 			return MAX_METRIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 		err = (fail_avg << ARITH_SHIFT) / 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	/* bitrate is in units of 100 Kbps, while we need rate in units of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	 * 1Mbps. This will be corrected on tx_time computation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	tx_time = (device_constant + 10 * test_frame_len / rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	estimated_retx = ((1 << (2 * ARITH_SHIFT)) / (s_unit - err));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	result = ((u64)tx_time * estimated_retx) >> (2 * ARITH_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	return (u32)result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364)  * hwmp_route_info_get - Update routing info to originator and transmitter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366)  * @sdata: local mesh subif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367)  * @mgmt: mesh management frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368)  * @hwmp_ie: hwmp information element (PREP or PREQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369)  * @action: type of hwmp ie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371)  * This function updates the path routing information to the originator and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372)  * transmitter of a HWMP PREQ or PREP frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374)  * Returns: metric to frame originator or 0 if the frame should not be further
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375)  * processed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377)  * Notes: this function is the only place (besides user-provided info) where
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378)  * path routing information is updated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 			       struct ieee80211_mgmt *mgmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 			       const u8 *hwmp_ie, enum mpath_frame_type action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	struct mesh_path *mpath;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	bool fresh_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	const u8 *orig_addr, *ta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	u32 orig_sn, orig_metric;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	unsigned long orig_lifetime, exp_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	u32 last_hop_metric, new_metric;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	bool process = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	u8 hopcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	sta = sta_info_get(sdata, mgmt->sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	if (!sta) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	last_hop_metric = airtime_link_metric_get(local, sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	/* Update and check originator routing info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	fresh_info = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	switch (action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	case MPATH_PREQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		orig_addr = PREQ_IE_ORIG_ADDR(hwmp_ie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 		orig_sn = PREQ_IE_ORIG_SN(hwmp_ie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 		orig_lifetime = PREQ_IE_LIFETIME(hwmp_ie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		orig_metric = PREQ_IE_METRIC(hwmp_ie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 		hopcount = PREQ_IE_HOPCOUNT(hwmp_ie) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	case MPATH_PREP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 		/* Originator here refers to the MP that was the target in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		 * Path Request. We divert from the nomenclature in the draft
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 		 * so that we can easily use a single function to gather path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 		 * information from both PREQ and PREP frames.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		orig_addr = PREP_IE_TARGET_ADDR(hwmp_ie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 		orig_sn = PREP_IE_TARGET_SN(hwmp_ie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 		orig_lifetime = PREP_IE_LIFETIME(hwmp_ie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 		orig_metric = PREP_IE_METRIC(hwmp_ie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 		hopcount = PREP_IE_HOPCOUNT(hwmp_ie) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	new_metric = orig_metric + last_hop_metric;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	if (new_metric < orig_metric)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 		new_metric = MAX_METRIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	exp_time = TU_TO_EXP_TIME(orig_lifetime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	if (ether_addr_equal(orig_addr, sdata->vif.addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		/* This MP is the originator, we are not interested in this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 		 * frame, except for updating transmitter's path info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 		process = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 		fresh_info = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		mpath = mesh_path_lookup(sdata, orig_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		if (mpath) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 			spin_lock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 			if (mpath->flags & MESH_PATH_FIXED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 				fresh_info = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 			else if ((mpath->flags & MESH_PATH_ACTIVE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 			    (mpath->flags & MESH_PATH_SN_VALID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 				if (SN_GT(mpath->sn, orig_sn) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 				    (mpath->sn == orig_sn &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 				     (rcu_access_pointer(mpath->next_hop) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 						      sta ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 					      mult_frac(new_metric, 10, 9) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 					      new_metric) >= mpath->metric)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 					process = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 					fresh_info = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 			} else if (!(mpath->flags & MESH_PATH_ACTIVE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 				bool have_sn, newer_sn, bounced;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 				have_sn = mpath->flags & MESH_PATH_SN_VALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 				newer_sn = have_sn && SN_GT(orig_sn, mpath->sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 				bounced = have_sn &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 					  (SN_DELTA(orig_sn, mpath->sn) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 							MAX_SANE_SN_DELTA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 				if (!have_sn || newer_sn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 					/* if SN is newer than what we had
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 					 * then we can take it */;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 				} else if (bounced) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 					/* if SN is way different than what
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 					 * we had then assume the other side
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 					 * rebooted or restarted */;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 					process = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 					fresh_info = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 			mpath = mesh_path_add(sdata, orig_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 			if (IS_ERR(mpath)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 				rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 			spin_lock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		if (fresh_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 			if (rcu_access_pointer(mpath->next_hop) != sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 				mpath->path_change_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 			mesh_path_assign_nexthop(mpath, sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 			mpath->flags |= MESH_PATH_SN_VALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 			mpath->metric = new_metric;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 			mpath->sn = orig_sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 			mpath->exp_time = time_after(mpath->exp_time, exp_time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 					  ?  mpath->exp_time : exp_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 			mpath->hop_count = hopcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 			mesh_path_activate(mpath);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 			spin_unlock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 			ewma_mesh_fail_avg_init(&sta->mesh->fail_avg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 			/* init it at a low value - 0 start is tricky */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 			ewma_mesh_fail_avg_add(&sta->mesh->fail_avg, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 			mesh_path_tx_pending(mpath);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 			/* draft says preq_id should be saved to, but there does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 			 * not seem to be any use for it, skipping by now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 			spin_unlock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	/* Update and check transmitter routing info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	ta = mgmt->sa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	if (ether_addr_equal(orig_addr, ta))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 		fresh_info = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 		fresh_info = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 		mpath = mesh_path_lookup(sdata, ta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 		if (mpath) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 			spin_lock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 			if ((mpath->flags & MESH_PATH_FIXED) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 			    ((mpath->flags & MESH_PATH_ACTIVE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 			     ((rcu_access_pointer(mpath->next_hop) != sta ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 				       mult_frac(last_hop_metric, 10, 9) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 				       last_hop_metric) > mpath->metric)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 				fresh_info = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 			mpath = mesh_path_add(sdata, ta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 			if (IS_ERR(mpath)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 				rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 			spin_lock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 		if (fresh_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 			if (rcu_access_pointer(mpath->next_hop) != sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 				mpath->path_change_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 			mesh_path_assign_nexthop(mpath, sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 			mpath->metric = last_hop_metric;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 			mpath->exp_time = time_after(mpath->exp_time, exp_time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 					  ?  mpath->exp_time : exp_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 			mpath->hop_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 			mesh_path_activate(mpath);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 			spin_unlock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 			ewma_mesh_fail_avg_init(&sta->mesh->fail_avg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 			/* init it at a low value - 0 start is tricky */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 			ewma_mesh_fail_avg_add(&sta->mesh->fail_avg, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 			mesh_path_tx_pending(mpath);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 			spin_unlock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	return process ? new_metric : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) static void hwmp_preq_frame_process(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 				    struct ieee80211_mgmt *mgmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 				    const u8 *preq_elem, u32 orig_metric)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	struct mesh_path *mpath = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	const u8 *target_addr, *orig_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	const u8 *da;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	u8 target_flags, ttl, flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	u32 orig_sn, target_sn, lifetime, target_metric = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	bool reply = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	bool forward = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	bool root_is_gate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	/* Update target SN, if present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	target_addr = PREQ_IE_TARGET_ADDR(preq_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	orig_addr = PREQ_IE_ORIG_ADDR(preq_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	target_sn = PREQ_IE_TARGET_SN(preq_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	orig_sn = PREQ_IE_ORIG_SN(preq_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	target_flags = PREQ_IE_TARGET_F(preq_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	/* Proactive PREQ gate announcements */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	flags = PREQ_IE_FLAGS(preq_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	root_is_gate = !!(flags & RANN_FLAG_IS_GATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	mhwmp_dbg(sdata, "received PREQ from %pM\n", orig_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	if (ether_addr_equal(target_addr, sdata->vif.addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 		mhwmp_dbg(sdata, "PREQ is for us\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 		forward = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 		reply = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		target_metric = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 		if (SN_GT(target_sn, ifmsh->sn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 			ifmsh->sn = target_sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		if (time_after(jiffies, ifmsh->last_sn_update +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 					net_traversal_jiffies(sdata)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 		    time_before(jiffies, ifmsh->last_sn_update)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 			++ifmsh->sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 			ifmsh->last_sn_update = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 		target_sn = ifmsh->sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	} else if (is_broadcast_ether_addr(target_addr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 		   (target_flags & IEEE80211_PREQ_TO_FLAG)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 		rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 		mpath = mesh_path_lookup(sdata, orig_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 		if (mpath) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 			if (flags & IEEE80211_PREQ_PROACTIVE_PREP_FLAG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 				reply = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 				target_addr = sdata->vif.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 				target_sn = ++ifmsh->sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 				target_metric = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 				ifmsh->last_sn_update = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 			if (root_is_gate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 				mesh_path_add_gate(mpath);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 		rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 		mpath = mesh_path_lookup(sdata, target_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 		if (mpath) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 			if ((!(mpath->flags & MESH_PATH_SN_VALID)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 					SN_LT(mpath->sn, target_sn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 				mpath->sn = target_sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 				mpath->flags |= MESH_PATH_SN_VALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 			} else if ((!(target_flags & IEEE80211_PREQ_TO_FLAG)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 					(mpath->flags & MESH_PATH_ACTIVE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 				reply = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 				target_metric = mpath->metric;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 				target_sn = mpath->sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 				/* Case E2 of sec 13.10.9.3 IEEE 802.11-2012*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 				target_flags |= IEEE80211_PREQ_TO_FLAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	if (reply) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 		lifetime = PREQ_IE_LIFETIME(preq_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		ttl = ifmsh->mshcfg.element_ttl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 		if (ttl != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 			mhwmp_dbg(sdata, "replying to the PREQ\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 			mesh_path_sel_frame_tx(MPATH_PREP, 0, orig_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 					       orig_sn, 0, target_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 					       target_sn, mgmt->sa, 0, ttl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 					       lifetime, target_metric, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 					       sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 			ifmsh->mshstats.dropped_frames_ttl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	if (forward && ifmsh->mshcfg.dot11MeshForwarding) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 		u32 preq_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		u8 hopcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 		ttl = PREQ_IE_TTL(preq_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 		lifetime = PREQ_IE_LIFETIME(preq_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 		if (ttl <= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 			ifmsh->mshstats.dropped_frames_ttl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 		mhwmp_dbg(sdata, "forwarding the PREQ from %pM\n", orig_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		--ttl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 		preq_id = PREQ_IE_PREQ_ID(preq_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		hopcount = PREQ_IE_HOPCOUNT(preq_elem) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		da = (mpath && mpath->is_root) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 			mpath->rann_snd_addr : broadcast_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 		if (flags & IEEE80211_PREQ_PROACTIVE_PREP_FLAG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 			target_addr = PREQ_IE_TARGET_ADDR(preq_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 			target_sn = PREQ_IE_TARGET_SN(preq_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 		mesh_path_sel_frame_tx(MPATH_PREQ, flags, orig_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 				       orig_sn, target_flags, target_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 				       target_sn, da, hopcount, ttl, lifetime,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 				       orig_metric, preq_id, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		if (!is_multicast_ether_addr(da))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 			ifmsh->mshstats.fwded_unicast++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 			ifmsh->mshstats.fwded_mcast++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		ifmsh->mshstats.fwded_frames++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) static inline struct sta_info *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) next_hop_deref_protected(struct mesh_path *mpath)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	return rcu_dereference_protected(mpath->next_hop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 					 lockdep_is_held(&mpath->state_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) static void hwmp_prep_frame_process(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 				    struct ieee80211_mgmt *mgmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 				    const u8 *prep_elem, u32 metric)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	struct mesh_path *mpath;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	const u8 *target_addr, *orig_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	u8 ttl, hopcount, flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	u8 next_hop[ETH_ALEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	u32 target_sn, orig_sn, lifetime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	mhwmp_dbg(sdata, "received PREP from %pM\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 		  PREP_IE_TARGET_ADDR(prep_elem));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	orig_addr = PREP_IE_ORIG_ADDR(prep_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	if (ether_addr_equal(orig_addr, sdata->vif.addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 		/* destination, no forwarding required */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	if (!ifmsh->mshcfg.dot11MeshForwarding)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	ttl = PREP_IE_TTL(prep_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	if (ttl <= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 		sdata->u.mesh.mshstats.dropped_frames_ttl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	mpath = mesh_path_lookup(sdata, orig_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	if (mpath)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		spin_lock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	if (!(mpath->flags & MESH_PATH_ACTIVE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 		spin_unlock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	memcpy(next_hop, next_hop_deref_protected(mpath)->sta.addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	spin_unlock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	--ttl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	flags = PREP_IE_FLAGS(prep_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	lifetime = PREP_IE_LIFETIME(prep_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	hopcount = PREP_IE_HOPCOUNT(prep_elem) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	target_addr = PREP_IE_TARGET_ADDR(prep_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	target_sn = PREP_IE_TARGET_SN(prep_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	orig_sn = PREP_IE_ORIG_SN(prep_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	mesh_path_sel_frame_tx(MPATH_PREP, flags, orig_addr, orig_sn, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 			       target_addr, target_sn, next_hop, hopcount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 			       ttl, lifetime, metric, 0, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	sdata->u.mesh.mshstats.fwded_unicast++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	sdata->u.mesh.mshstats.fwded_frames++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	sdata->u.mesh.mshstats.dropped_frames_no_route++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) static void hwmp_perr_frame_process(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 				    struct ieee80211_mgmt *mgmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 				    const u8 *perr_elem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	struct mesh_path *mpath;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	u8 ttl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	const u8 *ta, *target_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	u32 target_sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	u16 target_rcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	ta = mgmt->sa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	ttl = PERR_IE_TTL(perr_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	if (ttl <= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 		ifmsh->mshstats.dropped_frames_ttl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	ttl--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	target_addr = PERR_IE_TARGET_ADDR(perr_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	target_sn = PERR_IE_TARGET_SN(perr_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	target_rcode = PERR_IE_TARGET_RCODE(perr_elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	mpath = mesh_path_lookup(sdata, target_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	if (mpath) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 		struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 		spin_lock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		sta = next_hop_deref_protected(mpath);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 		if (mpath->flags & MESH_PATH_ACTIVE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		    ether_addr_equal(ta, sta->sta.addr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 		    !(mpath->flags & MESH_PATH_FIXED) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		    (!(mpath->flags & MESH_PATH_SN_VALID) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 		    SN_GT(target_sn, mpath->sn)  || target_sn == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 			mpath->flags &= ~MESH_PATH_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 			if (target_sn != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 				mpath->sn = target_sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 				mpath->sn += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 			spin_unlock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 			if (!ifmsh->mshcfg.dot11MeshForwarding)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 				goto endperr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 			mesh_path_error_tx(sdata, ttl, target_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 					   target_sn, target_rcode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 					   broadcast_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 			spin_unlock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) endperr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) static void hwmp_rann_frame_process(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 				    struct ieee80211_mgmt *mgmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 				    const struct ieee80211_rann_ie *rann)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	struct mesh_path *mpath;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	u8 ttl, flags, hopcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	const u8 *orig_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	u32 orig_sn, new_metric, orig_metric, last_hop_metric, interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	bool root_is_gate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	ttl = rann->rann_ttl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	flags = rann->rann_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	root_is_gate = !!(flags & RANN_FLAG_IS_GATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	orig_addr = rann->rann_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	orig_sn = le32_to_cpu(rann->rann_seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	interval = le32_to_cpu(rann->rann_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	hopcount = rann->rann_hopcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	hopcount++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	orig_metric = le32_to_cpu(rann->rann_metric);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	/*  Ignore our own RANNs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	if (ether_addr_equal(orig_addr, sdata->vif.addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	mhwmp_dbg(sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 		  "received RANN from %pM via neighbour %pM (is_gate=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 		  orig_addr, mgmt->sa, root_is_gate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	sta = sta_info_get(sdata, mgmt->sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	if (!sta) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	last_hop_metric = airtime_link_metric_get(local, sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	new_metric = orig_metric + last_hop_metric;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	if (new_metric < orig_metric)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 		new_metric = MAX_METRIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	mpath = mesh_path_lookup(sdata, orig_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	if (!mpath) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		mpath = mesh_path_add(sdata, orig_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		if (IS_ERR(mpath)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 			rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 			sdata->u.mesh.mshstats.dropped_frames_no_route++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	if (!(SN_LT(mpath->sn, orig_sn)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	    !(mpath->sn == orig_sn && new_metric < mpath->rann_metric)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	if ((!(mpath->flags & (MESH_PATH_ACTIVE | MESH_PATH_RESOLVING)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	     (time_after(jiffies, mpath->last_preq_to_root +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 				  root_path_confirmation_jiffies(sdata)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	     time_before(jiffies, mpath->last_preq_to_root))) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	     !(mpath->flags & MESH_PATH_FIXED) && (ttl != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 		mhwmp_dbg(sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 			  "time to refresh root mpath %pM\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 			  orig_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 		mesh_queue_preq(mpath, PREQ_Q_F_START | PREQ_Q_F_REFRESH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 		mpath->last_preq_to_root = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	mpath->sn = orig_sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	mpath->rann_metric = new_metric;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	mpath->is_root = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	/* Recording RANNs sender address to send individually
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	 * addressed PREQs destined for root mesh STA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	memcpy(mpath->rann_snd_addr, mgmt->sa, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	if (root_is_gate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		mesh_path_add_gate(mpath);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	if (ttl <= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 		ifmsh->mshstats.dropped_frames_ttl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	ttl--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	if (ifmsh->mshcfg.dot11MeshForwarding) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 		mesh_path_sel_frame_tx(MPATH_RANN, flags, orig_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 				       orig_sn, 0, NULL, 0, broadcast_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 				       hopcount, ttl, interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 				       new_metric, 0, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) void mesh_rx_path_sel_frame(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 			    struct ieee80211_mgmt *mgmt, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	struct ieee802_11_elems elems;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	size_t baselen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	u32 path_metric;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	/* need action_code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	if (len < IEEE80211_MIN_ACTION_SIZE + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	sta = sta_info_get(sdata, mgmt->sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	if (!sta || sta->mesh->plink_state != NL80211_PLINK_ESTAB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	baselen = (u8 *) mgmt->u.action.u.mesh_action.variable - (u8 *) mgmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	ieee802_11_parse_elems(mgmt->u.action.u.mesh_action.variable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 			       len - baselen, false, &elems, mgmt->bssid, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	if (elems.preq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 		if (elems.preq_len != 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 			/* Right now we support just 1 destination and no AE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 		path_metric = hwmp_route_info_get(sdata, mgmt, elems.preq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 						  MPATH_PREQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		if (path_metric)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 			hwmp_preq_frame_process(sdata, mgmt, elems.preq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 						path_metric);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	if (elems.prep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 		if (elems.prep_len != 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 			/* Right now we support no AE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 		path_metric = hwmp_route_info_get(sdata, mgmt, elems.prep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 						  MPATH_PREP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		if (path_metric)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 			hwmp_prep_frame_process(sdata, mgmt, elems.prep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 						path_metric);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	if (elems.perr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		if (elems.perr_len != 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 			/* Right now we support only one destination per PERR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 		hwmp_perr_frame_process(sdata, mgmt, elems.perr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	if (elems.rann)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 		hwmp_rann_frame_process(sdata, mgmt, elems.rann);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963)  * mesh_queue_preq - queue a PREQ to a given destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965)  * @mpath: mesh path to discover
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966)  * @flags: special attributes of the PREQ to be sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968)  * Locking: the function must be called from within a rcu read lock block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) static void mesh_queue_preq(struct mesh_path *mpath, u8 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	struct ieee80211_sub_if_data *sdata = mpath->sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	struct mesh_preq_queue *preq_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	preq_node = kmalloc(sizeof(struct mesh_preq_queue), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	if (!preq_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 		mhwmp_dbg(sdata, "could not allocate PREQ node\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	spin_lock_bh(&ifmsh->mesh_preq_queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	if (ifmsh->preq_queue_len == MAX_PREQ_QUEUE_LEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 		spin_unlock_bh(&ifmsh->mesh_preq_queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		kfree(preq_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 		if (printk_ratelimit())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 			mhwmp_dbg(sdata, "PREQ node queue full\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	spin_lock(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	if (mpath->flags & MESH_PATH_REQ_QUEUED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 		spin_unlock(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 		spin_unlock_bh(&ifmsh->mesh_preq_queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 		kfree(preq_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	memcpy(preq_node->dst, mpath->dst, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	preq_node->flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	mpath->flags |= MESH_PATH_REQ_QUEUED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	spin_unlock(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	list_add_tail(&preq_node->list, &ifmsh->preq_queue.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	++ifmsh->preq_queue_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	spin_unlock_bh(&ifmsh->mesh_preq_queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	if (time_after(jiffies, ifmsh->last_preq + min_preq_int_jiff(sdata)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 		ieee80211_queue_work(&sdata->local->hw, &sdata->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	else if (time_before(jiffies, ifmsh->last_preq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 		/* avoid long wait if did not send preqs for a long time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 		 * and jiffies wrapped around
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 		ifmsh->last_preq = jiffies - min_preq_int_jiff(sdata) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 		ieee80211_queue_work(&sdata->local->hw, &sdata->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 		mod_timer(&ifmsh->mesh_path_timer, ifmsh->last_preq +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 						min_preq_int_jiff(sdata));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025)  * mesh_path_start_discovery - launch a path discovery from the PREQ queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)  * @sdata: local mesh subif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	struct mesh_preq_queue *preq_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	struct mesh_path *mpath;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	u8 ttl, target_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	const u8 *da;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	u32 lifetime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	spin_lock_bh(&ifmsh->mesh_preq_queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	if (!ifmsh->preq_queue_len ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		time_before(jiffies, ifmsh->last_preq +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 				min_preq_int_jiff(sdata))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 		spin_unlock_bh(&ifmsh->mesh_preq_queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	preq_node = list_first_entry(&ifmsh->preq_queue.list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 			struct mesh_preq_queue, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	list_del(&preq_node->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	--ifmsh->preq_queue_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	spin_unlock_bh(&ifmsh->mesh_preq_queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	mpath = mesh_path_lookup(sdata, preq_node->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	if (!mpath)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 		goto enddiscovery;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	spin_lock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	if (mpath->flags & (MESH_PATH_DELETED | MESH_PATH_FIXED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 		spin_unlock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 		goto enddiscovery;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	mpath->flags &= ~MESH_PATH_REQ_QUEUED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	if (preq_node->flags & PREQ_Q_F_START) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		if (mpath->flags & MESH_PATH_RESOLVING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 			spin_unlock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 			goto enddiscovery;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 			mpath->flags &= ~MESH_PATH_RESOLVED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 			mpath->flags |= MESH_PATH_RESOLVING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 			mpath->discovery_retries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 			mpath->discovery_timeout = disc_timeout_jiff(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	} else if (!(mpath->flags & MESH_PATH_RESOLVING) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 			mpath->flags & MESH_PATH_RESOLVED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 		mpath->flags &= ~MESH_PATH_RESOLVING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 		spin_unlock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 		goto enddiscovery;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	ifmsh->last_preq = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	if (time_after(jiffies, ifmsh->last_sn_update +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 				net_traversal_jiffies(sdata)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	    time_before(jiffies, ifmsh->last_sn_update)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 		++ifmsh->sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 		sdata->u.mesh.last_sn_update = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	lifetime = default_lifetime(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	ttl = sdata->u.mesh.mshcfg.element_ttl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	if (ttl == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 		sdata->u.mesh.mshstats.dropped_frames_ttl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 		spin_unlock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 		goto enddiscovery;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	if (preq_node->flags & PREQ_Q_F_REFRESH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 		target_flags |= IEEE80211_PREQ_TO_FLAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 		target_flags &= ~IEEE80211_PREQ_TO_FLAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	spin_unlock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	da = (mpath->is_root) ? mpath->rann_snd_addr : broadcast_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	mesh_path_sel_frame_tx(MPATH_PREQ, 0, sdata->vif.addr, ifmsh->sn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 			       target_flags, mpath->dst, mpath->sn, da, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 			       ttl, lifetime, 0, ifmsh->preq_id++, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	spin_lock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	if (!(mpath->flags & MESH_PATH_DELETED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 		mod_timer(&mpath->timer, jiffies + mpath->discovery_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	spin_unlock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) enddiscovery:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	kfree(preq_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)  * mesh_nexthop_resolve - lookup next hop; conditionally start path discovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)  * @skb: 802.11 frame to be sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121)  * @sdata: network subif the frame will be sent through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)  * Lookup next hop for given skb and start path discovery if no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)  * forwarding information is found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126)  * Returns: 0 if the next hop was found and -ENOENT if the frame was queued.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127)  * skb is freeed here if no mpath could be allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) int mesh_nexthop_resolve(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 			 struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	struct mesh_path *mpath;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	struct sk_buff *skb_to_free = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	u8 *target_addr = hdr->addr3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	/* Nulls are only sent to peers for PS and should be pre-addressed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	if (ieee80211_is_qos_nullfunc(hdr->frame_control))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	/* Allow injected packets to bypass mesh routing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	if (info->control.flags & IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	if (!mesh_nexthop_lookup(sdata, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	/* no nexthop found, start resolving */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	mpath = mesh_path_lookup(sdata, target_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	if (!mpath) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 		mpath = mesh_path_add(sdata, target_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 		if (IS_ERR(mpath)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 			mesh_path_discard_frame(sdata, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 			return PTR_ERR(mpath);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	if (!(mpath->flags & MESH_PATH_RESOLVING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	    mesh_path_sel_is_hwmp(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 		mesh_queue_preq(mpath, PREQ_Q_F_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	if (skb_queue_len(&mpath->frame_queue) >= MESH_FRAME_QUEUE_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 		skb_to_free = skb_dequeue(&mpath->frame_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	ieee80211_set_qos_hdr(sdata, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	skb_queue_tail(&mpath->frame_queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	if (skb_to_free)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 		mesh_path_discard_frame(sdata, skb_to_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176)  * mesh_nexthop_lookup_nolearn - try to set next hop without path discovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)  * @skb: 802.11 frame to be sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178)  * @sdata: network subif the frame will be sent through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)  * Check if the meshDA (addr3) of a unicast frame is a direct neighbor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181)  * And if so, set the RA (addr1) to it to transmit to this node directly,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)  * avoiding PREQ/PREP path discovery.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184)  * Returns: 0 if the next hop was found and -ENOENT otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) static int mesh_nexthop_lookup_nolearn(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 				       struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	if (is_multicast_ether_addr(hdr->addr1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	sta = sta_info_get(sdata, hdr->addr3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	if (!sta || sta->mesh->plink_state != NL80211_PLINK_ESTAB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	memcpy(hdr->addr1, hdr->addr3, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 	memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)  * mesh_nexthop_lookup - put the appropriate next hop on a mesh frame. Calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)  * this function is considered "using" the associated mpath, so preempt a path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212)  * refresh if this mpath expires soon.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214)  * @skb: 802.11 frame to be sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215)  * @sdata: network subif the frame will be sent through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217)  * Returns: 0 if the next hop was found. Nonzero otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) int mesh_nexthop_lookup(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 			struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	struct mesh_path *mpath;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	struct sta_info *next_hop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	u8 *target_addr = hdr->addr3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	if (ifmsh->mshcfg.dot11MeshNolearn &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	    !mesh_nexthop_lookup_nolearn(sdata, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	mpath = mesh_path_lookup(sdata, target_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	if (!mpath || !(mpath->flags & MESH_PATH_ACTIVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	if (time_after(jiffies,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 		       mpath->exp_time -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 		       msecs_to_jiffies(sdata->u.mesh.mshcfg.path_refresh_time)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	    ether_addr_equal(sdata->vif.addr, hdr->addr4) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	    !(mpath->flags & MESH_PATH_RESOLVING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	    !(mpath->flags & MESH_PATH_FIXED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 		mesh_queue_preq(mpath, PREQ_Q_F_START | PREQ_Q_F_REFRESH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	next_hop = rcu_dereference(mpath->next_hop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 	if (next_hop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 		memcpy(hdr->addr1, next_hop->sta.addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 		memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 		ieee80211_mps_set_frame_flags(sdata, next_hop, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) void mesh_path_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 	struct mesh_path *mpath = from_timer(mpath, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	struct ieee80211_sub_if_data *sdata = mpath->sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	if (sdata->local->quiescing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	spin_lock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	if (mpath->flags & MESH_PATH_RESOLVED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 			(!(mpath->flags & MESH_PATH_RESOLVING))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 		mpath->flags &= ~(MESH_PATH_RESOLVING | MESH_PATH_RESOLVED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 		spin_unlock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	} else if (mpath->discovery_retries < max_preq_retries(sdata)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 		++mpath->discovery_retries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 		mpath->discovery_timeout *= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 		mpath->flags &= ~MESH_PATH_REQ_QUEUED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 		spin_unlock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 		mesh_queue_preq(mpath, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 		mpath->flags &= ~(MESH_PATH_RESOLVING |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 				  MESH_PATH_RESOLVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 				  MESH_PATH_REQ_QUEUED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 		mpath->exp_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 		spin_unlock_bh(&mpath->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 		if (!mpath->is_gate && mesh_gate_num(sdata) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 			ret = mesh_path_send_to_gates(mpath);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 				mhwmp_dbg(sdata, "no gate was reachable\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 			mesh_path_flush_pending(mpath);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) void mesh_path_tx_root_frame(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	u32 interval = ifmsh->mshcfg.dot11MeshHWMPRannInterval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 	u8 flags, target_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	flags = (ifmsh->mshcfg.dot11MeshGateAnnouncementProtocol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 			? RANN_FLAG_IS_GATE : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	switch (ifmsh->mshcfg.dot11MeshHWMPRootMode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	case IEEE80211_PROACTIVE_RANN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 		mesh_path_sel_frame_tx(MPATH_RANN, flags, sdata->vif.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 				       ++ifmsh->sn, 0, NULL, 0, broadcast_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 				       0, ifmsh->mshcfg.element_ttl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 				       interval, 0, 0, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	case IEEE80211_PROACTIVE_PREQ_WITH_PREP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 		flags |= IEEE80211_PREQ_PROACTIVE_PREP_FLAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 	case IEEE80211_PROACTIVE_PREQ_NO_PREP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 		interval = ifmsh->mshcfg.dot11MeshHWMPactivePathToRootTimeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 		target_flags |= IEEE80211_PREQ_TO_FLAG |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 				IEEE80211_PREQ_USN_FLAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 		mesh_path_sel_frame_tx(MPATH_PREQ, flags, sdata->vif.addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 				       ++ifmsh->sn, target_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 				       (u8 *) broadcast_addr, 0, broadcast_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 				       0, ifmsh->mshcfg.element_ttl, interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 				       0, ifmsh->preq_id++, sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 		mhwmp_dbg(sdata, "Proactive mechanism not supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) }