xref: /OK3568_Linux_fs/external/rkwifibt/drivers/infineon/dhd_rtt.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Broadcom Dongle Host Driver (DHD), RTT
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Portions of this code are copyright (c) 2021 Cypress Semiconductor Corporation
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Copyright (C) 1999-2017, Broadcom Corporation
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  *      Unless you and Broadcom execute a separate written software license
9*4882a593Smuzhiyun  * agreement governing use of this software, this software is licensed to you
10*4882a593Smuzhiyun  * under the terms of the GNU General Public License version 2 (the "GPL"),
11*4882a593Smuzhiyun  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
12*4882a593Smuzhiyun  * following added to such license:
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  *      As a special exception, the copyright holders of this software give you
15*4882a593Smuzhiyun  * permission to link this software with independent modules, and to copy and
16*4882a593Smuzhiyun  * distribute the resulting executable under terms of your choice, provided that
17*4882a593Smuzhiyun  * you also meet, for each linked independent module, the terms and conditions of
18*4882a593Smuzhiyun  * the license of that module.  An independent module is a module which is not
19*4882a593Smuzhiyun  * derived from this software.  The special exception does not apply to any
20*4882a593Smuzhiyun  * modifications of the software.
21*4882a593Smuzhiyun  *
22*4882a593Smuzhiyun  *      Notwithstanding the above, under no circumstances may you combine this
23*4882a593Smuzhiyun  * software in any way with any other Broadcom software provided under a license
24*4882a593Smuzhiyun  * other than the GPL, without Broadcom's express prior written consent.
25*4882a593Smuzhiyun  *
26*4882a593Smuzhiyun  *
27*4882a593Smuzhiyun  * <<Broadcom-WL-IPTag/Open:>>
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  * $Id$
30*4882a593Smuzhiyun  */
31*4882a593Smuzhiyun #ifndef __DHD_RTT_H__
32*4882a593Smuzhiyun #define __DHD_RTT_H__
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun #include "dngl_stats.h"
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun #define RTT_MAX_TARGET_CNT 50
37*4882a593Smuzhiyun #define RTT_MAX_FRAME_CNT 25
38*4882a593Smuzhiyun #define RTT_MAX_RETRY_CNT 10
39*4882a593Smuzhiyun #define DEFAULT_FTM_CNT 6
40*4882a593Smuzhiyun #define DEFAULT_RETRY_CNT 6
41*4882a593Smuzhiyun #define DEFAULT_FTM_FREQ 5180
42*4882a593Smuzhiyun #define DEFAULT_FTM_CNTR_FREQ0 5210
43*4882a593Smuzhiyun #define RTT_MAX_GEOFENCE_TARGET_CNT 8
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun #define TARGET_INFO_SIZE(count) (sizeof(rtt_target_info_t) * count)
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun #define TARGET_TYPE(target) (target->type)
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun #define RTT_IS_ENABLED(rtt_status) (rtt_status->status == RTT_ENABLED)
50*4882a593Smuzhiyun #define RTT_IS_STOPPED(rtt_status) (rtt_status->status == RTT_STOPPED)
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun #ifndef BIT
53*4882a593Smuzhiyun #define BIT(x) (1 << (x))
54*4882a593Smuzhiyun #endif // endif
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun /* DSSS, CCK and 802.11n rates in [500kbps] units */
57*4882a593Smuzhiyun #define WL_MAXRATE	108	/* in 500kbps units */
58*4882a593Smuzhiyun #define WL_RATE_1M	2	/* in 500kbps units */
59*4882a593Smuzhiyun #define WL_RATE_2M	4	/* in 500kbps units */
60*4882a593Smuzhiyun #define WL_RATE_5M5	11	/* in 500kbps units */
61*4882a593Smuzhiyun #define WL_RATE_11M	22	/* in 500kbps units */
62*4882a593Smuzhiyun #define WL_RATE_6M	12	/* in 500kbps units */
63*4882a593Smuzhiyun #define WL_RATE_9M	18	/* in 500kbps units */
64*4882a593Smuzhiyun #define WL_RATE_12M	24	/* in 500kbps units */
65*4882a593Smuzhiyun #define WL_RATE_18M	36	/* in 500kbps units */
66*4882a593Smuzhiyun #define WL_RATE_24M	48	/* in 500kbps units */
67*4882a593Smuzhiyun #define WL_RATE_36M	72	/* in 500kbps units */
68*4882a593Smuzhiyun #define WL_RATE_48M	96	/* in 500kbps units */
69*4882a593Smuzhiyun #define WL_RATE_54M	108	/* in 500kbps units */
70*4882a593Smuzhiyun #define GET_RTTSTATE(dhd) ((rtt_status_info_t *)dhd->rtt_state)
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun /* RTT Retry Timer Interval */
73*4882a593Smuzhiyun #define DHD_RTT_RETRY_TIMER_INTERVAL_MS		3000u
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun #define DHD_RTT_INVALID_TARGET_INDEX		-1
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun enum rtt_role {
78*4882a593Smuzhiyun 	RTT_INITIATOR = 0,
79*4882a593Smuzhiyun 	RTT_TARGET = 1
80*4882a593Smuzhiyun };
81*4882a593Smuzhiyun enum rtt_status {
82*4882a593Smuzhiyun 	RTT_STOPPED = 0,
83*4882a593Smuzhiyun 	RTT_STARTED = 1,
84*4882a593Smuzhiyun 	RTT_ENABLED = 2
85*4882a593Smuzhiyun };
86*4882a593Smuzhiyun typedef int64_t wifi_timestamp; /* In microseconds (us) */
87*4882a593Smuzhiyun typedef int64_t wifi_timespan;
88*4882a593Smuzhiyun typedef int32 wifi_rssi_rtt;
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun typedef enum {
91*4882a593Smuzhiyun 	RTT_INVALID,
92*4882a593Smuzhiyun 	RTT_ONE_WAY,
93*4882a593Smuzhiyun 	RTT_TWO_WAY,
94*4882a593Smuzhiyun 	RTT_AUTO
95*4882a593Smuzhiyun } rtt_type_t;
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun /* RTT peer type */
98*4882a593Smuzhiyun typedef enum {
99*4882a593Smuzhiyun 	RTT_PEER_AP         = 0x1,
100*4882a593Smuzhiyun 	RTT_PEER_STA        = 0x2,
101*4882a593Smuzhiyun 	RTT_PEER_P2P_GO     = 0x3,
102*4882a593Smuzhiyun 	RTT_PEER_P2P_CLIENT = 0x4,
103*4882a593Smuzhiyun 	RTT_PEER_NAN        = 0x5,
104*4882a593Smuzhiyun 	RTT_PEER_INVALID    = 0x6
105*4882a593Smuzhiyun } rtt_peer_type_t;
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun /* Ranging status */
108*4882a593Smuzhiyun typedef enum rtt_reason {
109*4882a593Smuzhiyun 	RTT_STATUS_SUCCESS       = 0,
110*4882a593Smuzhiyun 	RTT_STATUS_FAILURE       = 1,           // general failure status
111*4882a593Smuzhiyun 	RTT_STATUS_FAIL_NO_RSP   = 2,           // target STA does not respond to request
112*4882a593Smuzhiyun 	RTT_STATUS_FAIL_REJECTED = 3,           // request rejected. Applies to 2-sided RTT only
113*4882a593Smuzhiyun 	RTT_STATUS_FAIL_NOT_SCHEDULED_YET  = 4,
114*4882a593Smuzhiyun 	RTT_STATUS_FAIL_TM_TIMEOUT         = 5, // timing measurement times out
115*4882a593Smuzhiyun 	RTT_STATUS_FAIL_AP_ON_DIFF_CHANNEL = 6, // Target on different channel, cannot range
116*4882a593Smuzhiyun 	RTT_STATUS_FAIL_NO_CAPABILITY  = 7,     // ranging not supported
117*4882a593Smuzhiyun 	RTT_STATUS_ABORTED             = 8,     // request aborted for unknown reason
118*4882a593Smuzhiyun 	RTT_STATUS_FAIL_INVALID_TS     = 9,     // Invalid T1-T4 timestamp
119*4882a593Smuzhiyun 	RTT_STATUS_FAIL_PROTOCOL       = 10,    // 11mc protocol failed
120*4882a593Smuzhiyun 	RTT_STATUS_FAIL_SCHEDULE       = 11,    // request could not be scheduled
121*4882a593Smuzhiyun 	RTT_STATUS_FAIL_BUSY_TRY_LATER = 12,    // responder cannot collaborate at time of request
122*4882a593Smuzhiyun 	RTT_STATUS_INVALID_REQ         = 13,    // bad request args
123*4882a593Smuzhiyun 	RTT_STATUS_NO_WIFI             = 14,    // WiFi not enabled Responder overrides param info
124*4882a593Smuzhiyun 						// cannot range with new params
125*4882a593Smuzhiyun 	RTT_STATUS_FAIL_FTM_PARAM_OVERRIDE = 15
126*4882a593Smuzhiyun } rtt_reason_t;
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun enum {
129*4882a593Smuzhiyun 	RTT_CAP_ONE_WAY	 = BIT(0),
130*4882a593Smuzhiyun 	/* IEEE802.11mc */
131*4882a593Smuzhiyun 	RTT_CAP_FTM_WAY  = BIT(1)
132*4882a593Smuzhiyun };
133*4882a593Smuzhiyun 
134*4882a593Smuzhiyun enum {
135*4882a593Smuzhiyun 	RTT_FEATURE_LCI = BIT(0),
136*4882a593Smuzhiyun 	RTT_FEATURE_LCR = BIT(1),
137*4882a593Smuzhiyun 	RTT_FEATURE_PREAMBLE = BIT(2),
138*4882a593Smuzhiyun 	RTT_FEATURE_BW = BIT(3)
139*4882a593Smuzhiyun };
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun enum {
142*4882a593Smuzhiyun 	RTT_PREAMBLE_LEGACY = BIT(0),
143*4882a593Smuzhiyun 	RTT_PREAMBLE_HT = BIT(1),
144*4882a593Smuzhiyun 	RTT_PREAMBLE_VHT = BIT(2)
145*4882a593Smuzhiyun };
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun enum {
148*4882a593Smuzhiyun 	RTT_BW_5 = BIT(0),
149*4882a593Smuzhiyun 	RTT_BW_10 = BIT(1),
150*4882a593Smuzhiyun 	RTT_BW_20 = BIT(2),
151*4882a593Smuzhiyun 	RTT_BW_40 = BIT(3),
152*4882a593Smuzhiyun 	RTT_BW_80 = BIT(4),
153*4882a593Smuzhiyun 	RTT_BW_160 = BIT(5)
154*4882a593Smuzhiyun };
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun enum rtt_rate_bw {
157*4882a593Smuzhiyun 	RTT_RATE_20M,
158*4882a593Smuzhiyun 	RTT_RATE_40M,
159*4882a593Smuzhiyun 	RTT_RATE_80M,
160*4882a593Smuzhiyun 	RTT_RATE_160M
161*4882a593Smuzhiyun };
162*4882a593Smuzhiyun 
163*4882a593Smuzhiyun typedef enum ranging_type {
164*4882a593Smuzhiyun 	RTT_TYPE_INVALID	=	0,
165*4882a593Smuzhiyun 	RTT_TYPE_LEGACY		=	1,
166*4882a593Smuzhiyun 	RTT_TYPE_NAN_DIRECTED	=	2,
167*4882a593Smuzhiyun 	RTT_TYPE_NAN_GEOFENCE	=	3
168*4882a593Smuzhiyun } ranging_type_t;
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun #define FTM_MAX_NUM_BURST_EXP	14
171*4882a593Smuzhiyun #define HAS_11MC_CAP(cap) (cap & RTT_CAP_FTM_WAY)
172*4882a593Smuzhiyun #define HAS_ONEWAY_CAP(cap) (cap & RTT_CAP_ONE_WAY)
173*4882a593Smuzhiyun #define HAS_RTT_CAP(cap) (HAS_ONEWAY_CAP(cap) || HAS_11MC_CAP(cap))
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun typedef struct wifi_channel_info {
176*4882a593Smuzhiyun 	wifi_channel_width_t width;
177*4882a593Smuzhiyun 	wifi_channel center_freq; /* primary 20 MHz channel */
178*4882a593Smuzhiyun 	wifi_channel center_freq0; /* center freq (MHz) first segment */
179*4882a593Smuzhiyun 	wifi_channel center_freq1; /* center freq (MHz) second segment valid for 80 + 80 */
180*4882a593Smuzhiyun } wifi_channel_info_t;
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun typedef struct wifi_rate {
183*4882a593Smuzhiyun 	uint32 preamble :3; /* 0: OFDM, 1: CCK, 2 : HT, 3: VHT, 4..7 reserved */
184*4882a593Smuzhiyun 	uint32 nss		:2; /* 1 : 1x1, 2: 2x2, 3: 3x3, 4: 4x4 */
185*4882a593Smuzhiyun 	uint32 bw		:3; /* 0: 20Mhz, 1: 40Mhz, 2: 80Mhz, 3: 160Mhz */
186*4882a593Smuzhiyun 	/* OFDM/CCK rate code would be as per IEEE std in the unit of 0.5 mb
187*4882a593Smuzhiyun 	* HT/VHT it would be mcs index
188*4882a593Smuzhiyun 	*/
189*4882a593Smuzhiyun 	uint32 rateMcsIdx :8;
190*4882a593Smuzhiyun 	uint32 reserved :16; /* reserved */
191*4882a593Smuzhiyun 	uint32 bitrate;	/* unit of 100 Kbps */
192*4882a593Smuzhiyun } wifi_rate_t;
193*4882a593Smuzhiyun 
194*4882a593Smuzhiyun typedef struct rtt_target_info {
195*4882a593Smuzhiyun 	struct ether_addr addr;
196*4882a593Smuzhiyun 	struct ether_addr local_addr;
197*4882a593Smuzhiyun 	rtt_type_t type; /* rtt_type */
198*4882a593Smuzhiyun 	rtt_peer_type_t peer; /* peer type */
199*4882a593Smuzhiyun 	wifi_channel_info_t channel; /* channel information */
200*4882a593Smuzhiyun 	chanspec_t chanspec; /* chanspec for channel */
201*4882a593Smuzhiyun 	bool	disable; /* disable for RTT measurement */
202*4882a593Smuzhiyun 	/*
203*4882a593Smuzhiyun 	* Time interval between bursts (units: 100 ms).
204*4882a593Smuzhiyun 	* Applies to 1-sided and 2-sided RTT multi-burst requests.
205*4882a593Smuzhiyun 	* Range: 0-31, 0: no preference by initiator (2-sided RTT)
206*4882a593Smuzhiyun 	*/
207*4882a593Smuzhiyun 	uint32	burst_period;
208*4882a593Smuzhiyun 	/*
209*4882a593Smuzhiyun 	* Total number of RTT bursts to be executed. It will be
210*4882a593Smuzhiyun 	* specified in the same way as the parameter "Number of
211*4882a593Smuzhiyun 	* Burst Exponent" found in the FTM frame format. It
212*4882a593Smuzhiyun 	* applies to both: 1-sided RTT and 2-sided RTT. Valid
213*4882a593Smuzhiyun 	* values are 0 to 15 as defined in 802.11mc std.
214*4882a593Smuzhiyun 	* 0 means single shot
215*4882a593Smuzhiyun 	* The implication of this parameter on the maximum
216*4882a593Smuzhiyun 	* number of RTT results is the following:
217*4882a593Smuzhiyun 	* for 1-sided RTT: max num of RTT results = (2^num_burst)*(num_frames_per_burst)
218*4882a593Smuzhiyun 	* for 2-sided RTT: max num of RTT results = (2^num_burst)*(num_frames_per_burst - 1)
219*4882a593Smuzhiyun 	*/
220*4882a593Smuzhiyun 	uint16 num_burst;
221*4882a593Smuzhiyun 	/*
222*4882a593Smuzhiyun 	* num of frames per burst.
223*4882a593Smuzhiyun 	* Minimum value = 1, Maximum value = 31
224*4882a593Smuzhiyun 	* For 2-sided this equals the number of FTM frames
225*4882a593Smuzhiyun 	* to be attempted in a single burst. This also
226*4882a593Smuzhiyun 	* equals the number of FTM frames that the
227*4882a593Smuzhiyun 	* initiator will request that the responder send
228*4882a593Smuzhiyun 	* in a single frame
229*4882a593Smuzhiyun 	*/
230*4882a593Smuzhiyun 	uint32 num_frames_per_burst;
231*4882a593Smuzhiyun 	/*
232*4882a593Smuzhiyun 	 * num of frames in each RTT burst
233*4882a593Smuzhiyun 	 * for single side, measurement result num = frame number
234*4882a593Smuzhiyun 	 * for 2 side RTT, measurement result num  = frame number - 1
235*4882a593Smuzhiyun 	 */
236*4882a593Smuzhiyun 	uint32 num_retries_per_ftm; /* retry time for RTT measurment frame */
237*4882a593Smuzhiyun 	/* following fields are only valid for 2 side RTT */
238*4882a593Smuzhiyun 	uint32 num_retries_per_ftmr;
239*4882a593Smuzhiyun 	uint8  LCI_request;
240*4882a593Smuzhiyun 	uint8  LCR_request;
241*4882a593Smuzhiyun 	/*
242*4882a593Smuzhiyun 	* Applies to 1-sided and 2-sided RTT. Valid values will
243*4882a593Smuzhiyun 	* be 2-11 and 15 as specified by the 802.11mc std for
244*4882a593Smuzhiyun 	* the FTM parameter burst duration. In a multi-burst
245*4882a593Smuzhiyun 	* request, if responder overrides with larger value,
246*4882a593Smuzhiyun 	* the initiator will return failure. In a single-burst
247*4882a593Smuzhiyun 	* request if responder overrides with larger value,
248*4882a593Smuzhiyun 	* the initiator will sent TMR_STOP to terminate RTT
249*4882a593Smuzhiyun 	* at the end of the burst_duration it requested.
250*4882a593Smuzhiyun 	*/
251*4882a593Smuzhiyun 	uint32 burst_duration;
252*4882a593Smuzhiyun 	uint32 burst_timeout;
253*4882a593Smuzhiyun 	uint8  preamble; /* 1 - Legacy, 2 - HT, 4 - VHT */
254*4882a593Smuzhiyun 	uint8  bw;  /* 5, 10, 20, 40, 80, 160 */
255*4882a593Smuzhiyun } rtt_target_info_t;
256*4882a593Smuzhiyun 
257*4882a593Smuzhiyun typedef struct rtt_goefence_target_info {
258*4882a593Smuzhiyun 	bool valid;
259*4882a593Smuzhiyun 	struct ether_addr peer_addr;
260*4882a593Smuzhiyun } rtt_geofence_target_info_t;
261*4882a593Smuzhiyun 
262*4882a593Smuzhiyun typedef struct rtt_config_params {
263*4882a593Smuzhiyun 	int8 rtt_target_cnt;
264*4882a593Smuzhiyun 	rtt_target_info_t *target_info;
265*4882a593Smuzhiyun } rtt_config_params_t;
266*4882a593Smuzhiyun 
267*4882a593Smuzhiyun typedef struct rtt_geofence_cfg {
268*4882a593Smuzhiyun 	int8 geofence_target_cnt;
269*4882a593Smuzhiyun 	bool rtt_in_progress;
270*4882a593Smuzhiyun 	bool role_concurr_state;
271*4882a593Smuzhiyun 	int8 cur_target_idx;
272*4882a593Smuzhiyun 	rtt_geofence_target_info_t geofence_target_info[RTT_MAX_GEOFENCE_TARGET_CNT];
273*4882a593Smuzhiyun } rtt_geofence_cfg_t;
274*4882a593Smuzhiyun 
275*4882a593Smuzhiyun /*
276*4882a593Smuzhiyun  * Keep Adding more reasons
277*4882a593Smuzhiyun  * going forward if needed
278*4882a593Smuzhiyun  */
279*4882a593Smuzhiyun enum rtt_schedule_reason {
280*4882a593Smuzhiyun 	RTT_SCHED_HOST_TRIGGER		= 1, /* On host command for directed RTT */
281*4882a593Smuzhiyun 	RTT_SCHED_SUB_MATCH		= 2, /* on Sub Match for svc with range req */
282*4882a593Smuzhiyun 	RTT_SCHED_DIR_TRIGGER_FAIL	= 3, /* On failure of Directed RTT Trigger */
283*4882a593Smuzhiyun 	RTT_SCHED_DP_END		= 4, /* ON NDP End event from fw */
284*4882a593Smuzhiyun 	RTT_SCHED_DP_REJECTED		= 5, /* On receving reject dp event from fw */
285*4882a593Smuzhiyun 	RTT_SCHED_RNG_RPT_DIRECTED	= 6, /* On Ranging report for directed RTT */
286*4882a593Smuzhiyun 	RTT_SCHED_RNG_TERM		= 7, /* On Range Term Indicator */
287*4882a593Smuzhiyun 	RTT_SHCED_HOST_DIRECTED_TERM	= 8, /* On host terminating directed RTT sessions */
288*4882a593Smuzhiyun 	RTT_SCHED_RNG_RPT_GEOFENCE	= 9, /* On Ranging report for geofence RTT */
289*4882a593Smuzhiyun 	RTT_SCHED_RTT_RETRY_GEOFENCE	= 10 /* On Geofence Retry */
290*4882a593Smuzhiyun };
291*4882a593Smuzhiyun 
292*4882a593Smuzhiyun /*
293*4882a593Smuzhiyun  * Keep Adding more invalid RTT states
294*4882a593Smuzhiyun  * going forward if needed
295*4882a593Smuzhiyun  */
296*4882a593Smuzhiyun enum rtt_invalid_state {
297*4882a593Smuzhiyun 	RTT_STATE_VALID			= 0, /* RTT state is valid */
298*4882a593Smuzhiyun 	RTT_STATE_INV_REASON_NDP_EXIST	= 1 /* RTT state invalid as ndp exists */
299*4882a593Smuzhiyun };
300*4882a593Smuzhiyun 
301*4882a593Smuzhiyun typedef struct rtt_status_info {
302*4882a593Smuzhiyun 	dhd_pub_t	*dhd;
303*4882a593Smuzhiyun 	int8		status;   /* current status for the current entry */
304*4882a593Smuzhiyun 	int8		txchain; /* current device tx chain */
305*4882a593Smuzhiyun 	int		pm; /* to save current value of pm */
306*4882a593Smuzhiyun 	int8		pm_restore; /* flag to reset the old value of pm */
307*4882a593Smuzhiyun 	int8		cur_idx; /* current entry to do RTT */
308*4882a593Smuzhiyun 	bool		all_cancel; /* cancel all request once we got the cancel requet */
309*4882a593Smuzhiyun 	uint32		flags; /* indicate whether device is configured as initiator or target */
310*4882a593Smuzhiyun 	struct capability {
311*4882a593Smuzhiyun 		int32 proto     :8;
312*4882a593Smuzhiyun 		int32 feature   :8;
313*4882a593Smuzhiyun 		int32 preamble  :8;
314*4882a593Smuzhiyun 		int32 bw        :8;
315*4882a593Smuzhiyun 	} rtt_capa; /* rtt capability */
316*4882a593Smuzhiyun 	struct			mutex rtt_mutex;
317*4882a593Smuzhiyun 	struct			mutex geofence_mutex;
318*4882a593Smuzhiyun 	rtt_config_params_t	rtt_config;
319*4882a593Smuzhiyun 	rtt_geofence_cfg_t	geofence_cfg;
320*4882a593Smuzhiyun 	struct work_struct	work;
321*4882a593Smuzhiyun 	struct list_head	noti_fn_list;
322*4882a593Smuzhiyun 	struct list_head	rtt_results_cache; /* store results for RTT */
323*4882a593Smuzhiyun 	int			rtt_sched_reason; /* rtt_schedule_reason: what scheduled RTT */
324*4882a593Smuzhiyun 	struct delayed_work	proxd_timeout; /* Proxd Timeout work */
325*4882a593Smuzhiyun 	struct delayed_work	rtt_retry_timer;   /* Timer for retry RTT after all targets done */
326*4882a593Smuzhiyun } rtt_status_info_t;
327*4882a593Smuzhiyun 
328*4882a593Smuzhiyun typedef struct rtt_report {
329*4882a593Smuzhiyun 	struct ether_addr addr;
330*4882a593Smuzhiyun 	unsigned int burst_num; /* # of burst inside a multi-burst request */
331*4882a593Smuzhiyun 	unsigned int ftm_num; /* total RTT measurement frames attempted */
332*4882a593Smuzhiyun 	unsigned int success_num; /* total successful RTT measurement frames */
333*4882a593Smuzhiyun 	uint8  num_per_burst_peer; /* max number of FTM number per burst the peer support */
334*4882a593Smuzhiyun 	rtt_reason_t status; /* raging status */
335*4882a593Smuzhiyun 	/* in s, 11mc only, only for RTT_REASON_FAIL_BUSY_TRY_LATER, 1- 31s */
336*4882a593Smuzhiyun 	uint8 retry_after_duration;
337*4882a593Smuzhiyun 	rtt_type_t type; /* rtt type */
338*4882a593Smuzhiyun 	wifi_rssi_rtt  rssi; /* average rssi in 0.5 dB steps e.g. 143 implies -71.5 dB */
339*4882a593Smuzhiyun 	wifi_rssi_rtt  rssi_spread; /* rssi spread in 0.5 db steps e.g. 5 implies 2.5 spread */
340*4882a593Smuzhiyun 	/*
341*4882a593Smuzhiyun 	* 1-sided RTT: TX rate of RTT frame.
342*4882a593Smuzhiyun 	* 2-sided RTT: TX rate of initiator's Ack in response to FTM frame.
343*4882a593Smuzhiyun 	*/
344*4882a593Smuzhiyun 	wifi_rate_t tx_rate;
345*4882a593Smuzhiyun 	/*
346*4882a593Smuzhiyun 	* 1-sided RTT: TX rate of Ack from other side.
347*4882a593Smuzhiyun 	* 2-sided RTT: TX rate of FTM frame coming from responder.
348*4882a593Smuzhiyun 	*/
349*4882a593Smuzhiyun 	wifi_rate_t rx_rate;
350*4882a593Smuzhiyun 	wifi_timespan rtt;	/*  round trip time in 0.1 nanoseconds */
351*4882a593Smuzhiyun 	wifi_timespan rtt_sd;	/* rtt standard deviation in 0.1 nanoseconds */
352*4882a593Smuzhiyun 	wifi_timespan rtt_spread; /* difference between max and min rtt times recorded */
353*4882a593Smuzhiyun 	int distance; /* distance in cm (optional) */
354*4882a593Smuzhiyun 	int distance_sd; /* standard deviation in cm (optional) */
355*4882a593Smuzhiyun 	int distance_spread; /* difference between max and min distance recorded (optional) */
356*4882a593Smuzhiyun 	wifi_timestamp ts; /* time of the measurement (in microseconds since boot) */
357*4882a593Smuzhiyun 	int burst_duration; /* in ms, how long the FW time is to fininish one burst measurement */
358*4882a593Smuzhiyun 	int negotiated_burst_num; /* Number of bursts allowed by the responder */
359*4882a593Smuzhiyun 	bcm_tlv_t *LCI; /* LCI Report */
360*4882a593Smuzhiyun 	bcm_tlv_t *LCR; /* Location Civic Report */
361*4882a593Smuzhiyun } rtt_report_t;
362*4882a593Smuzhiyun #define RTT_REPORT_SIZE (sizeof(rtt_report_t))
363*4882a593Smuzhiyun 
364*4882a593Smuzhiyun /* rtt_results_header to maintain rtt result list per mac address */
365*4882a593Smuzhiyun typedef struct rtt_results_header {
366*4882a593Smuzhiyun 	struct ether_addr peer_mac;
367*4882a593Smuzhiyun 	uint32 result_cnt;
368*4882a593Smuzhiyun 	uint32 result_tot_len; /* sum of report_len of rtt_result */
369*4882a593Smuzhiyun 	struct list_head list;
370*4882a593Smuzhiyun 	struct list_head result_list;
371*4882a593Smuzhiyun } rtt_results_header_t;
372*4882a593Smuzhiyun struct rtt_result_detail {
373*4882a593Smuzhiyun 	uint8 num_ota_meas;
374*4882a593Smuzhiyun 	uint32 result_flags;
375*4882a593Smuzhiyun };
376*4882a593Smuzhiyun /* rtt_result to link all of rtt_report */
377*4882a593Smuzhiyun typedef struct rtt_result {
378*4882a593Smuzhiyun 	struct list_head list;
379*4882a593Smuzhiyun 	struct rtt_report report;
380*4882a593Smuzhiyun 	int32 report_len; /* total length of rtt_report */
381*4882a593Smuzhiyun 	struct rtt_result_detail rtt_detail;
382*4882a593Smuzhiyun 	int32 detail_len;
383*4882a593Smuzhiyun } rtt_result_t;
384*4882a593Smuzhiyun 
385*4882a593Smuzhiyun /* RTT Capabilities */
386*4882a593Smuzhiyun typedef struct rtt_capabilities {
387*4882a593Smuzhiyun 	uint8 rtt_one_sided_supported;  /* if 1-sided rtt data collection is supported */
388*4882a593Smuzhiyun 	uint8 rtt_ftm_supported;        /* if ftm rtt data collection is supported */
389*4882a593Smuzhiyun 	uint8 lci_support;		/* location configuration information */
390*4882a593Smuzhiyun 	uint8 lcr_support;		/* Civic Location */
391*4882a593Smuzhiyun 	uint8 preamble_support;         /* bit mask indicate what preamble is supported */
392*4882a593Smuzhiyun 	uint8 bw_support;               /* bit mask indicate what BW is supported */
393*4882a593Smuzhiyun } rtt_capabilities_t;
394*4882a593Smuzhiyun 
395*4882a593Smuzhiyun /* RTT responder information */
396*4882a593Smuzhiyun typedef struct wifi_rtt_responder {
397*4882a593Smuzhiyun 	wifi_channel_info channel;   /* channel of responder */
398*4882a593Smuzhiyun 	uint8 preamble;             /* preamble supported by responder */
399*4882a593Smuzhiyun } wifi_rtt_responder_t;
400*4882a593Smuzhiyun 
401*4882a593Smuzhiyun typedef void (*dhd_rtt_compl_noti_fn)(void *ctx, void *rtt_data);
402*4882a593Smuzhiyun /* Linux wrapper to call common dhd_rtt_set_cfg */
403*4882a593Smuzhiyun int
404*4882a593Smuzhiyun dhd_dev_rtt_set_cfg(struct net_device *dev, void *buf);
405*4882a593Smuzhiyun 
406*4882a593Smuzhiyun int
407*4882a593Smuzhiyun dhd_dev_rtt_cancel_cfg(struct net_device *dev, struct ether_addr *mac_list, int mac_cnt);
408*4882a593Smuzhiyun 
409*4882a593Smuzhiyun int
410*4882a593Smuzhiyun dhd_dev_rtt_register_noti_callback(struct net_device *dev, void *ctx,
411*4882a593Smuzhiyun 	dhd_rtt_compl_noti_fn noti_fn);
412*4882a593Smuzhiyun 
413*4882a593Smuzhiyun int
414*4882a593Smuzhiyun dhd_dev_rtt_unregister_noti_callback(struct net_device *dev, dhd_rtt_compl_noti_fn noti_fn);
415*4882a593Smuzhiyun 
416*4882a593Smuzhiyun int
417*4882a593Smuzhiyun dhd_dev_rtt_capability(struct net_device *dev, rtt_capabilities_t *capa);
418*4882a593Smuzhiyun 
419*4882a593Smuzhiyun int
420*4882a593Smuzhiyun dhd_dev_rtt_avail_channel(struct net_device *dev, wifi_channel_info *channel_info);
421*4882a593Smuzhiyun 
422*4882a593Smuzhiyun int
423*4882a593Smuzhiyun dhd_dev_rtt_enable_responder(struct net_device *dev, wifi_channel_info *channel_info);
424*4882a593Smuzhiyun 
425*4882a593Smuzhiyun int
426*4882a593Smuzhiyun dhd_dev_rtt_cancel_responder(struct net_device *dev);
427*4882a593Smuzhiyun /* export to upper layer */
428*4882a593Smuzhiyun chanspec_t
429*4882a593Smuzhiyun dhd_rtt_convert_to_chspec(wifi_channel_info_t channel);
430*4882a593Smuzhiyun 
431*4882a593Smuzhiyun int
432*4882a593Smuzhiyun dhd_rtt_idx_to_burst_duration(uint idx);
433*4882a593Smuzhiyun 
434*4882a593Smuzhiyun int
435*4882a593Smuzhiyun dhd_rtt_set_cfg(dhd_pub_t *dhd, rtt_config_params_t *params);
436*4882a593Smuzhiyun 
437*4882a593Smuzhiyun void dhd_rtt_set_role_concurrency_state(dhd_pub_t *dhd, bool state);
438*4882a593Smuzhiyun 
439*4882a593Smuzhiyun bool dhd_rtt_get_role_concurrency_state(dhd_pub_t *dhd);
440*4882a593Smuzhiyun 
441*4882a593Smuzhiyun int8 dhd_rtt_get_geofence_target_cnt(dhd_pub_t *dhd);
442*4882a593Smuzhiyun 
443*4882a593Smuzhiyun #ifdef WL_NAN
444*4882a593Smuzhiyun void dhd_rtt_set_geofence_rtt_state(dhd_pub_t *dhd, bool state);
445*4882a593Smuzhiyun 
446*4882a593Smuzhiyun bool dhd_rtt_get_geofence_rtt_state(dhd_pub_t *dhd);
447*4882a593Smuzhiyun 
448*4882a593Smuzhiyun rtt_geofence_target_info_t*
449*4882a593Smuzhiyun dhd_rtt_get_geofence_target_head(dhd_pub_t *dhd);
450*4882a593Smuzhiyun 
451*4882a593Smuzhiyun rtt_geofence_target_info_t*
452*4882a593Smuzhiyun dhd_rtt_get_geofence_current_target(dhd_pub_t *dhd);
453*4882a593Smuzhiyun 
454*4882a593Smuzhiyun rtt_geofence_target_info_t*
455*4882a593Smuzhiyun dhd_rtt_get_geofence_target(dhd_pub_t *dhd, struct ether_addr* peer_addr,
456*4882a593Smuzhiyun 	int8 *index);
457*4882a593Smuzhiyun 
458*4882a593Smuzhiyun int
459*4882a593Smuzhiyun dhd_rtt_add_geofence_target(dhd_pub_t *dhd, rtt_geofence_target_info_t  *target);
460*4882a593Smuzhiyun 
461*4882a593Smuzhiyun int
462*4882a593Smuzhiyun dhd_rtt_remove_geofence_target(dhd_pub_t *dhd, struct ether_addr *peer_addr);
463*4882a593Smuzhiyun 
464*4882a593Smuzhiyun int
465*4882a593Smuzhiyun dhd_rtt_delete_geofence_target_list(dhd_pub_t *dhd);
466*4882a593Smuzhiyun 
467*4882a593Smuzhiyun int
468*4882a593Smuzhiyun dhd_rtt_delete_nan_session(dhd_pub_t *dhd);
469*4882a593Smuzhiyun #endif /* WL_NAN */
470*4882a593Smuzhiyun 
471*4882a593Smuzhiyun uint8
472*4882a593Smuzhiyun dhd_rtt_invalid_states(struct net_device *ndev, struct ether_addr *peer_addr);
473*4882a593Smuzhiyun 
474*4882a593Smuzhiyun void
475*4882a593Smuzhiyun dhd_rtt_schedule_rtt_work_thread(dhd_pub_t *dhd, int sched_reason);
476*4882a593Smuzhiyun 
477*4882a593Smuzhiyun int
478*4882a593Smuzhiyun dhd_rtt_stop(dhd_pub_t *dhd, struct ether_addr *mac_list, int mac_cnt);
479*4882a593Smuzhiyun 
480*4882a593Smuzhiyun int
481*4882a593Smuzhiyun dhd_rtt_register_noti_callback(dhd_pub_t *dhd, void *ctx, dhd_rtt_compl_noti_fn noti_fn);
482*4882a593Smuzhiyun 
483*4882a593Smuzhiyun int
484*4882a593Smuzhiyun dhd_rtt_unregister_noti_callback(dhd_pub_t *dhd, dhd_rtt_compl_noti_fn noti_fn);
485*4882a593Smuzhiyun 
486*4882a593Smuzhiyun int
487*4882a593Smuzhiyun dhd_rtt_event_handler(dhd_pub_t *dhd, wl_event_msg_t *event, void *event_data);
488*4882a593Smuzhiyun 
489*4882a593Smuzhiyun int
490*4882a593Smuzhiyun dhd_rtt_capability(dhd_pub_t *dhd, rtt_capabilities_t *capa);
491*4882a593Smuzhiyun 
492*4882a593Smuzhiyun int
493*4882a593Smuzhiyun dhd_rtt_avail_channel(dhd_pub_t *dhd, wifi_channel_info *channel_info);
494*4882a593Smuzhiyun 
495*4882a593Smuzhiyun int
496*4882a593Smuzhiyun dhd_rtt_enable_responder(dhd_pub_t *dhd, wifi_channel_info *channel_info);
497*4882a593Smuzhiyun 
498*4882a593Smuzhiyun int
499*4882a593Smuzhiyun dhd_rtt_cancel_responder(dhd_pub_t *dhd);
500*4882a593Smuzhiyun 
501*4882a593Smuzhiyun int
502*4882a593Smuzhiyun dhd_rtt_init(dhd_pub_t *dhd);
503*4882a593Smuzhiyun 
504*4882a593Smuzhiyun int
505*4882a593Smuzhiyun dhd_rtt_deinit(dhd_pub_t *dhd);
506*4882a593Smuzhiyun 
507*4882a593Smuzhiyun #ifdef WL_CFG80211
508*4882a593Smuzhiyun int dhd_rtt_handle_nan_rtt_session_end(dhd_pub_t *dhd,
509*4882a593Smuzhiyun 	struct ether_addr *peer);
510*4882a593Smuzhiyun 
511*4882a593Smuzhiyun void dhd_rtt_move_geofence_cur_target_idx_to_next(dhd_pub_t *dhd);
512*4882a593Smuzhiyun 
513*4882a593Smuzhiyun int8 dhd_rtt_get_geofence_cur_target_idx(dhd_pub_t *dhd);
514*4882a593Smuzhiyun #endif /* WL_CFG80211 */
515*4882a593Smuzhiyun 
516*4882a593Smuzhiyun #endif /* __DHD_RTT_H__ */
517