blob: 8be7fd38aefaf618b0f7293ae9be800801b69d4a [file] [log] [blame]
Nate Jiang7a7fd842022-12-06 17:11:13 -08001
2#include "gscan.h"
3#include "wifi_hal.h"
4
5#ifndef __WIFI_HAL_RTT_H__
6#define __WIFI_HAL_RTT_H__
7
8/* Ranging status */
9typedef enum {
10 RTT_STATUS_SUCCESS = 0,
11 RTT_STATUS_FAILURE = 1, // general failure status
12 RTT_STATUS_FAIL_NO_RSP = 2, // target STA does not respond to request
13 RTT_STATUS_FAIL_REJECTED = 3, // request rejected. Applies to 2-sided RTT only
14 RTT_STATUS_FAIL_NOT_SCHEDULED_YET = 4,
15 RTT_STATUS_FAIL_TM_TIMEOUT = 5, // timing measurement times out
16 RTT_STATUS_FAIL_AP_ON_DIFF_CHANNEL = 6, // Target on different channel, cannot range
17 RTT_STATUS_FAIL_NO_CAPABILITY = 7, // ranging not supported
18 RTT_STATUS_ABORTED = 8, // request aborted for unknown reason
19 RTT_STATUS_FAIL_INVALID_TS = 9, // Invalid T1-T4 timestamp
20 RTT_STATUS_FAIL_PROTOCOL = 10, // 11mc protocol failed
21 RTT_STATUS_FAIL_SCHEDULE = 11, // request could not be scheduled
22 RTT_STATUS_FAIL_BUSY_TRY_LATER = 12, // responder cannot collaborate at time of request
23 RTT_STATUS_INVALID_REQ = 13, // bad request args
24 RTT_STATUS_NO_WIFI = 14, // WiFi not enabled
25 RTT_STATUS_FAIL_FTM_PARAM_OVERRIDE =
26 15, // Responder overrides param info, cannot range with new params
27 RTT_STATUS_NAN_RANGING_PROTOCOL_FAILURE = 16, // Negotiation failure
28 RTT_STATUS_NAN_RANGING_CONCURRENCY_NOT_SUPPORTED = 17, // concurrency not supported (NDP+RTT)
29} wifi_rtt_status;
30
31/* RTT peer type */
32typedef enum {
33 RTT_PEER_AP = 0x1,
34 RTT_PEER_STA = 0x2,
35 RTT_PEER_P2P_GO = 0x3,
36 RTT_PEER_P2P_CLIENT = 0x4,
37 RTT_PEER_NAN = 0x5
38} rtt_peer_type;
39
40/* RTT Measurement Bandwidth */
41typedef enum {
42 WIFI_RTT_BW_5 = 0x01,
43 WIFI_RTT_BW_10 = 0x02,
44 WIFI_RTT_BW_20 = 0x04,
45 WIFI_RTT_BW_40 = 0x08,
46 WIFI_RTT_BW_80 = 0x10,
47 WIFI_RTT_BW_160 = 0x20,
48 WIFI_RTT_BW_320 = 0x40
49} wifi_rtt_bw;
50
51/* RTT Measurement Preamble */
52typedef enum {
53 WIFI_RTT_PREAMBLE_LEGACY = 0x1,
54 WIFI_RTT_PREAMBLE_HT = 0x2,
55 WIFI_RTT_PREAMBLE_VHT = 0x4,
56 WIFI_RTT_PREAMBLE_HE = 0x8,
57 WIFI_RTT_PREAMBLE_EHT = 0x10,
58} wifi_rtt_preamble;
59
60/* RTT Type */
61typedef enum {
62 RTT_TYPE_1_SIDED = 0x1,
63 RTT_TYPE_2_SIDED = 0x2,
64} wifi_rtt_type;
65
66/* RTT configuration */
67typedef struct {
68 mac_addr addr; // peer device mac address
69 wifi_rtt_type type; // 1-sided or 2-sided RTT
70 rtt_peer_type peer; // optional - peer device hint (STA, P2P, AP)
71 wifi_channel_info channel; // Required for STA-AP mode, optional for P2P, NBD etc.
72 unsigned burst_period; // Time interval between bursts (units: 100 ms).
73 // Applies to 1-sided and 2-sided RTT multi-burst requests.
74 // Range: 0-31, 0: no preference by initiator (2-sided RTT)
75 unsigned num_burst; // Total number of RTT bursts to be executed. It will be
76 // specified in the same way as the parameter "Number of
77 // Burst Exponent" found in the FTM frame format. It
78 // applies to both: 1-sided RTT and 2-sided RTT. Valid
79 // values are 0 to 15 as defined in 802.11mc std.
80 // 0 means single shot
81 // The implication of this parameter on the maximum
82 // number of RTT results is the following:
83 // for 1-sided RTT: max num of RTT results =
84 // (2^num_burst)*(num_frames_per_burst) for 2-sided RTT: max num of RTT
85 // results = (2^num_burst)*(num_frames_per_burst - 1)
86 unsigned num_frames_per_burst; // num of frames per burst.
87 // Minimum value = 1, Maximum value = 31
88 // For 2-sided this equals the number of FTM frames
89 // to be attempted in a single burst. This also
90 // equals the number of FTM frames that the
91 // initiator will request that the responder send
92 // in a single frame.
93 unsigned
94 num_retries_per_rtt_frame; // number of retries for a failed RTT frame. Applies
95 // to 1-sided RTT only. Minimum value = 0, Maximum value = 3
96
97 // following fields are only valid for 2-side RTT
98 unsigned num_retries_per_ftmr; // Maximum number of retries that the initiator can
99 // retry an FTMR frame.
100 // Minimum value = 0, Maximum value = 3
101 byte LCI_request; // 1: request LCI, 0: do not request LCI
102 byte LCR_request; // 1: request LCR, 0: do not request LCR
103 unsigned burst_duration; // Applies to 1-sided and 2-sided RTT. Valid values will
104 // be 2-11 and 15 as specified by the 802.11mc std for
105 // the FTM parameter burst duration. In a multi-burst
106 // request, if responder overrides with larger value,
107 // the initiator will return failure. In a single-burst
108 // request if responder overrides with larger value,
109 // the initiator will sent TMR_STOP to terminate RTT
110 // at the end of the burst_duration it requested.
111 wifi_rtt_preamble preamble; // RTT preamble to be used in the RTT frames
112 wifi_rtt_bw bw; // RTT BW to be used in the RTT frames
113} wifi_rtt_config;
114
115/* RTT results */
116typedef struct {
117 mac_addr addr; // device mac address
118 unsigned burst_num; // burst number in a multi-burst request
119 unsigned measurement_number; // Total RTT measurement frames attempted
120 unsigned success_number; // Total successful RTT measurement frames
121 byte number_per_burst_peer; // Maximum number of "FTM frames per burst" supported by
122 // the responder STA. Applies to 2-sided RTT only.
123 // If reponder overrides with larger value:
124 // - for single-burst request initiator will truncate the
125 // larger value and send a TMR_STOP after receiving as
126 // many frames as originally requested.
127 // - for multi-burst request, initiator will return
128 // failure right away.
129 wifi_rtt_status status; // ranging status
130 byte retry_after_duration; // When status == RTT_STATUS_FAIL_BUSY_TRY_LATER,
131 // this will be the time provided by the responder as to
132 // when the request can be tried again. Applies to 2-sided
133 // RTT only. In sec, 1-31sec.
134 wifi_rtt_type type; // RTT type
135 wifi_rssi rssi; // average rssi in 0.5 dB steps e.g. 143 implies -71.5 dB
136 wifi_rssi rssi_spread; // rssi spread in 0.5 dB steps e.g. 5 implies 2.5 dB spread (optional)
137 wifi_rate tx_rate; // 1-sided RTT: TX rate of RTT frame.
138 // 2-sided RTT: TX rate of initiator's Ack in response to FTM frame.
139 wifi_rate rx_rate; // 1-sided RTT: TX rate of Ack from other side.
140 // 2-sided RTT: TX rate of FTM frame coming from responder.
141 wifi_timespan rtt; // round trip time in picoseconds
142 wifi_timespan rtt_sd; // rtt standard deviation in picoseconds
143 wifi_timespan rtt_spread; // difference between max and min rtt times recorded in picoseconds
144 int distance_mm; // distance in mm (optional)
145 int distance_sd_mm; // standard deviation in mm (optional)
146 int distance_spread_mm; // difference between max and min distance recorded in mm (optional)
147 wifi_timestamp ts; // time of the measurement (in microseconds since boot)
148 int burst_duration; // in ms, actual time taken by the FW to finish one burst
149 // measurement. Applies to 1-sided and 2-sided RTT.
150 int negotiated_burst_num; // Number of bursts allowed by the responder. Applies
151 // to 2-sided RTT only.
152 wifi_information_element* LCI; // for 11mc only
153 wifi_information_element* LCR; // for 11mc only
154} wifi_rtt_result;
155
156/* RTT result callback */
157typedef struct {
158 void (*on_rtt_results)(wifi_request_id id, unsigned num_results, wifi_rtt_result* rtt_result[]);
159} wifi_rtt_event_handler;
160
161/* API to request RTT measurement */
162wifi_error wifi_rtt_range_request(wifi_request_id id, wifi_interface_handle iface,
163 unsigned num_rtt_config, wifi_rtt_config rtt_config[],
164 wifi_rtt_event_handler handler);
165
166/* API to cancel RTT measurements */
167wifi_error wifi_rtt_range_cancel(wifi_request_id id, wifi_interface_handle iface,
168 unsigned num_devices, mac_addr addr[]);
169
170/* NBD ranging channel map */
171typedef struct {
172 wifi_channel availablity[32]; // specifies the channel map for each of the 16 TU windows
173 // frequency of 0 => unspecified; which means firmware is
174 // free to do whatever it wants in this window.
175} wifi_channel_map;
176
177/* API to start publishing the channel map on responder device in a NBD cluster.
178 Responder device will take this request and schedule broadcasting the channel map
179 in a NBD ranging attribute in a SDF. DE will automatically remove the ranging
180 attribute from the OTA queue after number of DW specified by num_dw
181 where Each DW is 512 TUs apart */
182wifi_error wifi_rtt_channel_map_set(wifi_request_id id, wifi_interface_handle iface,
183 wifi_channel_map* params, unsigned num_dw);
184
185/* API to clear the channel map on the responder device in a NBD cluster.
186 Responder device will cancel future ranging channel request, starting from “next”
187 DW interval and will also stop broadcasting NBD ranging attribute in SDF */
188wifi_error wifi_rtt_channel_map_clear(wifi_request_id id, wifi_interface_handle iface);
189
190// Preamble definition for bit mask used in wifi_rtt_capabilities
191#define PREAMBLE_LEGACY 0x1
192#define PREAMBLE_HT 0x2
193#define PREAMBLE_VHT 0x4
194#define PREAMBLE_HE 0x8
195#define PREAMBLE_EHT 0x10
196
197// BW definition for bit mask used in wifi_rtt_capabilities
198#define BW_5_SUPPORT 0x1
199#define BW_10_SUPPORT 0x2
200#define BW_20_SUPPORT 0x4
201#define BW_40_SUPPORT 0x8
202#define BW_80_SUPPORT 0x10
203#define BW_160_SUPPORT 0x20
204#define BW_320_SUPPORT 0x40
205
206/* RTT Capabilities */
207typedef struct {
208 byte rtt_one_sided_supported; // if 1-sided rtt data collection is supported
209 byte rtt_ftm_supported; // if ftm rtt data collection is supported
210 byte lci_support; // if initiator supports LCI request. Applies to 2-sided RTT
211 byte lcr_support; // if initiator supports LCR request. Applies to 2-sided RTT
212 byte preamble_support; // bit mask indicates what preamble is supported by initiator
213 byte bw_support; // bit mask indicates what BW is supported by initiator
214 byte responder_supported; // if 11mc responder mode is supported
215 byte mc_version; // draft 11mc spec version supported by chip. For instance,
216 // version 4.0 should be 40 and version 4.3 should be 43 etc.
217} wifi_rtt_capabilities;
218
219/* RTT capabilities of the device */
220wifi_error wifi_get_rtt_capabilities(wifi_interface_handle iface,
221 wifi_rtt_capabilities* capabilities);
222
223/* debugging definitions */
224enum {
225 RTT_DEBUG_DISABLE,
226 RTT_DEBUG_LOG,
227 RTT_DEBUG_PROTO,
228 RTT_DEBUG_BURST,
229 RTT_DEBUG_ACCURACY,
230 RTT_DEBUG_LOGDETAIL
231}; // rtt debug type
232
233enum { RTT_DEBUG_FORMAT_TXT, RTT_DEBUG_FORMAT_BINARY }; // rtt debug format
234
235typedef struct rtt_debug {
236 unsigned version;
237 unsigned len; // total length of after len field
238 unsigned type; // rtt debug type
239 unsigned format; // rtt debug format
240 char dbuf[0]; // debug content
241} rtt_debug_t;
242
243/* set configuration for debug */
244wifi_error wifi_rtt_debug_cfg(wifi_interface_handle h, unsigned rtt_dbg_type, char* cfgbuf,
245 unsigned cfg_buf_size);
246/* get the debug information */
247wifi_error wifi_rtt_debug_get(wifi_interface_handle h, rtt_debug_t** debugbuf);
248/* free the debug buffer */
249wifi_error wifi_rtt_debug_free(wifi_interface_handle h, rtt_debug_t* debugbuf);
250
251/* API for setting LCI/LCR information to be provided to a requestor */
252typedef enum {
253 WIFI_MOTION_NOT_EXPECTED = 0, // Not expected to change location
254 WIFI_MOTION_EXPECTED = 1, // Expected to change location
255 WIFI_MOTION_UNKNOWN = 2, // Movement pattern unknown
256} wifi_motion_pattern;
257
258typedef struct {
259 long latitude; // latitude in degrees * 2^25 , 2's complement
260 long longitude; // latitude in degrees * 2^25 , 2's complement
261 int altitude; // Altitude in units of 1/256 m
262 byte latitude_unc; // As defined in Section 2.3.2 of IETF RFC 6225
263 byte longitude_unc; // As defined in Section 2.3.2 of IETF RFC 6225
264 byte altitude_unc; // As defined in Section 2.4.5 from IETF RFC 6225:
265
266 // Following element for configuring the Z subelement
267 wifi_motion_pattern motion_pattern;
268 int floor; // floor in units of 1/16th of floor. 0x80000000 if unknown.
269 int height_above_floor; // in units of 1/64 m
270 int height_unc; // in units of 1/64 m. 0 if unknown
271} wifi_lci_information;
272
273typedef struct {
274 char country_code[2]; // country code
275 int length; // length of the info field
276 char civic_info[256]; // Civic info to be copied in FTM frame
277} wifi_lcr_information;
278
279// API to configure the LCI. Used in RTT Responder mode only
280wifi_error wifi_set_lci(wifi_request_id id, wifi_interface_handle iface, wifi_lci_information* lci);
281
282// API to configure the LCR. Used in RTT Responder mode only.
283wifi_error wifi_set_lcr(wifi_request_id id, wifi_interface_handle iface, wifi_lcr_information* lcr);
284
285/**
286 * RTT Responder information
287 */
288typedef struct {
289 wifi_channel_info channel;
290 wifi_rtt_preamble preamble;
291} wifi_rtt_responder;
292
293/**
294 * Get RTT responder information e.g. WiFi channel to enable responder on.
295 */
296wifi_error wifi_rtt_get_responder_info(wifi_interface_handle iface,
297 wifi_rtt_responder* responder_info);
298
299/**
300 * Enable RTT responder mode.
301 * channel_hint - hint of the channel information where RTT responder should be enabled on.
302 * max_duration_seconds - timeout of responder mode.
303 * channel_used - channel used for RTT responder, NULL if responder is not enabled.
304 */
305wifi_error wifi_enable_responder(wifi_request_id id, wifi_interface_handle iface,
306 wifi_channel_info channel_hint, unsigned max_duration_seconds,
307 wifi_rtt_responder* responder_info);
308
309/**
310 * Disable RTT responder mode.
311 */
312wifi_error wifi_disable_responder(wifi_request_id id, wifi_interface_handle iface);
313
314#endif