1b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde
2b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde#include "wifi_hal.h"
303c6b6f113931e168d3196c216084be4606216cbxinhe#include "gscan.h"
4b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde
5b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde#ifndef __WIFI_HAL_RTT_H__
6b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde#define __WIFI_HAL_RTT_H__
7b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde
8424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* Ranging status */
9424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpandetypedef enum {
10b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_STATUS_SUCCESS       = 0,
11b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_STATUS_FAILURE       = 1,           // general failure status
12b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_STATUS_FAIL_NO_RSP   = 2,           // target STA does not respond to request
13b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_STATUS_FAIL_REJECTED = 3,           // request rejected. Applies to 2-sided RTT only
14b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_STATUS_FAIL_NOT_SCHEDULED_YET  = 4,
15b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_STATUS_FAIL_TM_TIMEOUT         = 5, // timing measurement times out
16b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_STATUS_FAIL_AP_ON_DIFF_CHANNEL = 6, // Target on different channel, cannot range
17b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_STATUS_FAIL_NO_CAPABILITY  = 7,     // ranging not supported
18b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_STATUS_ABORTED             = 8,     // request aborted for unknown reason
19b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_STATUS_FAIL_INVALID_TS     = 9,     // Invalid T1-T4 timestamp
20b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_STATUS_FAIL_PROTOCOL       = 10,    // 11mc protocol failed
21b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_STATUS_FAIL_SCHEDULE       = 11,    // request could not be scheduled
22b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_STATUS_FAIL_BUSY_TRY_LATER = 12,    // responder cannot collaborate at time of request
23b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_STATUS_INVALID_REQ         = 13,    // bad request args
24b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_STATUS_NO_WIFI             = 14,    // WiFi not enabled
25b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_STATUS_FAIL_FTM_PARAM_OVERRIDE = 15 // Responder overrides param info, cannot range with new params
26424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande} wifi_rtt_status;
27424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande
28b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang/* RTT peer type */
29b4442c37ffd4aa4232a317131bff8f13669801edKevin Tangtypedef enum {
30b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_PEER_AP         = 0x1,
31b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_PEER_STA        = 0x2,
32b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_PEER_P2P_GO     = 0x3,
33b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_PEER_P2P_CLIENT = 0x4,
34b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_PEER_NAN        = 0x5
35b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang} rtt_peer_type;
36b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang
37b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang/* RTT Measurement Bandwidth */
38b4442c37ffd4aa4232a317131bff8f13669801edKevin Tangtypedef enum {
39b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    WIFI_RTT_BW_5   = 0x01,
40b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    WIFI_RTT_BW_10  = 0x02,
41b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    WIFI_RTT_BW_20  = 0x04,
42b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    WIFI_RTT_BW_40  = 0x08,
43b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    WIFI_RTT_BW_80  = 0x10,
44b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    WIFI_RTT_BW_160 = 0x20
45b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang} wifi_rtt_bw;
46b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang
47b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang/* RTT Measurement Preamble */
48b4442c37ffd4aa4232a317131bff8f13669801edKevin Tangtypedef enum {
49b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    WIFI_RTT_PREAMBLE_LEGACY = 0x1,
50b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    WIFI_RTT_PREAMBLE_HT     = 0x2,
51b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    WIFI_RTT_PREAMBLE_VHT    = 0x4
52b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang} wifi_rtt_preamble;
53424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande
54424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* RTT Type */
55424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpandetypedef enum {
56b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_TYPE_1_SIDED = 0x1,
57b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    RTT_TYPE_2_SIDED = 0x2,
58424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande} wifi_rtt_type;
59424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande
60424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* RTT configuration */
61b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapndetypedef struct {
62b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    mac_addr addr;                 // peer device mac address
63b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    wifi_rtt_type type;            // 1-sided or 2-sided RTT
64b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    rtt_peer_type peer;            // optional - peer device hint (STA, P2P, AP)
65b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    wifi_channel_info channel;     // Required for STA-AP mode, optional for P2P, NBD etc.
66b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    unsigned burst_period;         // Time interval between bursts (units: 100 ms).
67b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // Applies to 1-sided and 2-sided RTT multi-burst requests.
68b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // Range: 0-31, 0: no preference by initiator (2-sided RTT)
69b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    unsigned num_burst;            // Total number of RTT bursts to be executed. It will be
70b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // specified in the same way as the parameter "Number of
71b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // Burst Exponent" found in the FTM frame format. It
72b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // applies to both: 1-sided RTT and 2-sided RTT. Valid
73b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // values are 0 to 15 as defined in 802.11mc std.
74b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // 0 means single shot
75b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // The implication of this parameter on the maximum
76b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // number of RTT results is the following:
77b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // for 1-sided RTT: max num of RTT results = (2^num_burst)*(num_frames_per_burst)
78b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // for 2-sided RTT: max num of RTT results = (2^num_burst)*(num_frames_per_burst - 1)
79b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    unsigned num_frames_per_burst; // num of frames per burst.
80b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // Minimum value = 1, Maximum value = 31
81b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // For 2-sided this equals the number of FTM frames
82b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // to be attempted in a single burst. This also
83b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // equals the number of FTM frames that the
84b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // initiator will request that the responder send
85b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // in a single frame.
86b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    unsigned num_retries_per_rtt_frame; // number of retries for a failed RTT frame. Applies
87b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                        // to 1-sided RTT only. Minimum value = 0, Maximum value = 3
88b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang
89b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    //following fields are only valid for 2-side RTT
90b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    unsigned num_retries_per_ftmr; // Maximum number of retries that the initiator can
91b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // retry an FTMR frame.
92b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // Minimum value = 0, Maximum value = 3
93b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    byte LCI_request;              // 1: request LCI, 0: do not request LCI
94b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    byte LCR_request;              // 1: request LCR, 0: do not request LCR
95b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    unsigned burst_duration;       // Applies to 1-sided and 2-sided RTT. Valid values will
96b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // be 2-11 and 15 as specified by the 802.11mc std for
97b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // the FTM parameter burst duration. In a multi-burst
98b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // request, if responder overrides with larger value,
99b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // the initiator will return failure. In a single-burst
100b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // request if responder overrides with larger value,
101b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // the initiator will sent TMR_STOP to terminate RTT
102b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                   // at the end of the burst_duration it requested.
103b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    wifi_rtt_preamble preamble;    // RTT preamble to be used in the RTT frames
104b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    wifi_rtt_bw bw;                // RTT BW to be used in the RTT frames
105424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande} wifi_rtt_config;
106424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande
107b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang/* RTT results */
108b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapndetypedef struct {
109b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    mac_addr addr;                // device mac address
110b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    unsigned burst_num;           // burst number in a multi-burst request
111b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    unsigned measurement_number;  // Total RTT measurement frames attempted
112b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    unsigned success_number;      // Total successful RTT measurement frames
113b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    byte  number_per_burst_peer;  // Maximum number of "FTM frames per burst" supported by
114b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                  // the responder STA. Applies to 2-sided RTT only.
115b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                  // If reponder overrides with larger value:
116b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                  // - for single-burst request initiator will truncate the
117b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                  // larger value and send a TMR_STOP after receiving as
118b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                  // many frames as originally requested.
119b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                  // - for multi-burst request, initiator will return
120b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                  // failure right away.
121b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    wifi_rtt_status status;       // ranging status
122b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    byte retry_after_duration;    // When status == RTT_STATUS_FAIL_BUSY_TRY_LATER,
123b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                  // this will be the time provided by the responder as to
124b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                  // when the request can be tried again. Applies to 2-sided
125b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                  // RTT only. In sec, 1-31sec.
126b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    wifi_rtt_type type;           // RTT type
127b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    wifi_rssi rssi;               // average rssi in 0.5 dB steps e.g. 143 implies -71.5 dB
128b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    wifi_rssi rssi_spread;        // rssi spread in 0.5 dB steps e.g. 5 implies 2.5 dB spread (optional)
129b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    wifi_rate tx_rate;            // 1-sided RTT: TX rate of RTT frame.
130b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                  // 2-sided RTT: TX rate of initiator's Ack in response to FTM frame.
131b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    wifi_rate rx_rate;            // 1-sided RTT: TX rate of Ack from other side.
132b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                  // 2-sided RTT: TX rate of FTM frame coming from responder.
1338d44928adecbb620028079993ab90d8dd5675510Wei Wang    wifi_timespan rtt;            // round trip time in picoseconds
1348d44928adecbb620028079993ab90d8dd5675510Wei Wang    wifi_timespan rtt_sd;         // rtt standard deviation in picoseconds
1358d44928adecbb620028079993ab90d8dd5675510Wei Wang    wifi_timespan rtt_spread;     // difference between max and min rtt times recorded in picoseconds
1368d44928adecbb620028079993ab90d8dd5675510Wei Wang    int distance_mm;              // distance in mm (optional)
1378d44928adecbb620028079993ab90d8dd5675510Wei Wang    int distance_sd_mm;           // standard deviation in mm (optional)
1388d44928adecbb620028079993ab90d8dd5675510Wei Wang    int distance_spread_mm;       // difference between max and min distance recorded in mm (optional)
139b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    wifi_timestamp ts;            // time of the measurement (in microseconds since boot)
140b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    int burst_duration;           // in ms, actual time taken by the FW to finish one burst
141b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang                                  // measurement. Applies to 1-sided and 2-sided RTT.
14288aa64b95e2de18380721bda4e05f128cd5107a7Kumar Anand    int negotiated_burst_num;     // Number of bursts allowed by the responder. Applies
14388aa64b95e2de18380721bda4e05f128cd5107a7Kumar Anand                                  // to 2-sided RTT only.
14415fc62afbae23f233141e3db913f66acbe9f3551eccopark@broadcom.com    wifi_information_element *LCI; // for 11mc only
14515fc62afbae23f233141e3db913f66acbe9f3551eccopark@broadcom.com    wifi_information_element *LCR; // for 11mc only
146424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande} wifi_rtt_result;
147424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande
148424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* RTT result callback */
149424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpandetypedef struct {
15015fc62afbae23f233141e3db913f66acbe9f3551eccopark@broadcom.com    void (*on_rtt_results) (wifi_request_id id, unsigned num_results, wifi_rtt_result *rtt_result[]);
151424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande} wifi_rtt_event_handler;
152b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde
153424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* API to request RTT measurement */
154424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpandewifi_error wifi_rtt_range_request(wifi_request_id id, wifi_interface_handle iface,
155424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande        unsigned num_rtt_config, wifi_rtt_config rtt_config[], wifi_rtt_event_handler handler);
156b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde
157424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* API to cancel RTT measurements */
15893f677b67008faa0995d9283d04aa2ee3ef3a582Ashwinwifi_error wifi_rtt_range_cancel(wifi_request_id id,  wifi_interface_handle iface,
15993f677b67008faa0995d9283d04aa2ee3ef3a582Ashwin        unsigned num_devices, mac_addr addr[]);
160b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde
161424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* NBD ranging channel map */
162424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpandetypedef struct {
163b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    wifi_channel availablity[32]; // specifies the channel map for each of the 16 TU windows
16415fc62afbae23f233141e3db913f66acbe9f3551eccopark@broadcom.com    // frequency of 0 => unspecified; which means firmware is
16515fc62afbae23f233141e3db913f66acbe9f3551eccopark@broadcom.com    // free to do whatever it wants in this window.
166424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande} wifi_channel_map;
167424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande
168424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* API to start publishing the channel map on responder device in a NBD cluster.
169424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande   Responder device will take this request and schedule broadcasting the channel map
170424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande   in a NBD ranging attribute in a SDF. DE will automatically remove the ranging
171424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande   attribute from the OTA queue after number of DW specified by num_dw
172424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande   where Each DW is 512 TUs apart */
173424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpandewifi_error wifi_rtt_channel_map_set(wifi_request_id id,
174424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande        wifi_interface_handle iface, wifi_channel_map *params, unsigned num_dw);
175424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande
176424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* API to clear the channel map on the responder device in a NBD cluster.
177424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande   Responder device will cancel future ranging channel request, starting from next
178424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande   DW interval and will also stop broadcasting NBD ranging attribute in SDF */
179424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpandewifi_error wifi_rtt_channel_map_clear(wifi_request_id id,  wifi_interface_handle iface);
180424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande
181b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang// Preamble definition for bit mask used in wifi_rtt_capabilities
18203c6b6f113931e168d3196c216084be4606216cbxinhe#define PREAMBLE_LEGACY 0x1
18303c6b6f113931e168d3196c216084be4606216cbxinhe#define PREAMBLE_HT     0x2
18403c6b6f113931e168d3196c216084be4606216cbxinhe#define PREAMBLE_VHT    0x4
18503c6b6f113931e168d3196c216084be4606216cbxinhe
186b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang// BW definition for bit mask used in wifi_rtt_capabilities
187b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang#define BW_5_SUPPORT   0x1
188b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang#define BW_10_SUPPORT  0x2
189b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang#define BW_20_SUPPORT  0x4
190b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang#define BW_40_SUPPORT  0x8
191b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang#define BW_80_SUPPORT  0x10
192b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang#define BW_160_SUPPORT 0x20
19303c6b6f113931e168d3196c216084be4606216cbxinhe
194424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* RTT Capabilities */
195b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapndetypedef struct {
19615fc62afbae23f233141e3db913f66acbe9f3551eccopark@broadcom.com    byte rtt_one_sided_supported;  // if 1-sided rtt data collection is supported
19715fc62afbae23f233141e3db913f66acbe9f3551eccopark@broadcom.com    byte rtt_ftm_supported;        // if ftm rtt data collection is supported
198b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    byte lci_support;              // if initiator supports LCI request. Applies to 2-sided RTT
199b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    byte lcr_support;              // if initiator supports LCR request. Applies to 2-sided RTT
200b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    byte preamble_support;         // bit mask indicates what preamble is supported by initiator
201b4442c37ffd4aa4232a317131bff8f13669801edKevin Tang    byte bw_support;               // bit mask indicates what BW is supported by initiator
2028d44928adecbb620028079993ab90d8dd5675510Wei Wang    byte responder_supported;      // if 11mc responder mode is supported
2038d44928adecbb620028079993ab90d8dd5675510Wei Wang    byte mc_version;               // draft 11mc spec version supported by chip. For instance,
2048d44928adecbb620028079993ab90d8dd5675510Wei Wang                                   // version 4.0 should be 40 and version 4.3 should be 43 etc.
205424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande} wifi_rtt_capabilities;
206b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde
207424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/*  RTT capabilities of the device */
208424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpandewifi_error wifi_get_rtt_capabilities(wifi_interface_handle iface, wifi_rtt_capabilities *capabilities);
209b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde
210c5ab50d206f601f83510a41859e2d3a5884cd012xinhe/* debugging definitions */
211c5ab50d206f601f83510a41859e2d3a5884cd012xinheenum {
212c5ab50d206f601f83510a41859e2d3a5884cd012xinhe    RTT_DEBUG_DISABLE,
213c5ab50d206f601f83510a41859e2d3a5884cd012xinhe    RTT_DEBUG_LOG,
214c5ab50d206f601f83510a41859e2d3a5884cd012xinhe    RTT_DEBUG_PROTO,
215c5ab50d206f601f83510a41859e2d3a5884cd012xinhe    RTT_DEBUG_BURST,
216c5ab50d206f601f83510a41859e2d3a5884cd012xinhe    RTT_DEBUG_ACCURACY,
217c5ab50d206f601f83510a41859e2d3a5884cd012xinhe    RTT_DEBUG_LOGDETAIL
218c5ab50d206f601f83510a41859e2d3a5884cd012xinhe};  //rtt debug type
219c5ab50d206f601f83510a41859e2d3a5884cd012xinhe
220c5ab50d206f601f83510a41859e2d3a5884cd012xinheenum {
221c5ab50d206f601f83510a41859e2d3a5884cd012xinhe    RTT_DEBUG_FORMAT_TXT,
222c5ab50d206f601f83510a41859e2d3a5884cd012xinhe    RTT_DEBUG_FORMAT_BINARY
223c5ab50d206f601f83510a41859e2d3a5884cd012xinhe}; //rtt debug format
224c5ab50d206f601f83510a41859e2d3a5884cd012xinhe
225c5ab50d206f601f83510a41859e2d3a5884cd012xinhetypedef struct rtt_debug {
226c5ab50d206f601f83510a41859e2d3a5884cd012xinhe    unsigned version;
227c5ab50d206f601f83510a41859e2d3a5884cd012xinhe    unsigned len; // total length of after len field
228c5ab50d206f601f83510a41859e2d3a5884cd012xinhe    unsigned type;  // rtt debug type
229c5ab50d206f601f83510a41859e2d3a5884cd012xinhe    unsigned format; //rtt debug format
230c5ab50d206f601f83510a41859e2d3a5884cd012xinhe    char dbuf[0]; // debug content
231c5ab50d206f601f83510a41859e2d3a5884cd012xinhe} rtt_debug_t;
232c5ab50d206f601f83510a41859e2d3a5884cd012xinhe
233c5ab50d206f601f83510a41859e2d3a5884cd012xinhe/* set configuration for debug */
23415fc62afbae23f233141e3db913f66acbe9f3551eccopark@broadcom.comwifi_error wifi_rtt_debug_cfg(wifi_interface_handle h, unsigned rtt_dbg_type, char *cfgbuf, unsigned cfg_buf_size);
235c5ab50d206f601f83510a41859e2d3a5884cd012xinhe/* get the debug information */
236c5ab50d206f601f83510a41859e2d3a5884cd012xinhewifi_error wifi_rtt_debug_get(wifi_interface_handle h, rtt_debug_t **debugbuf);
237c5ab50d206f601f83510a41859e2d3a5884cd012xinhe/* free the debug buffer */
238c5ab50d206f601f83510a41859e2d3a5884cd012xinhewifi_error wifi_rtt_debug_free(wifi_interface_handle h, rtt_debug_t *debugbuf);
239c5ab50d206f601f83510a41859e2d3a5884cd012xinhe
240e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam/* API for setting LCI/LCR information to be provided to a requestor */
241e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyamtypedef enum {
242e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam    WIFI_MOTION_NOT_EXPECTED = 0, // Not expected to change location
243e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam    WIFI_MOTION_EXPECTED = 1,     // Expected to change location
244e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam    WIFI_MOTION_UNKNOWN  = 2,     // Movement pattern unknown
245e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam} wifi_motion_pattern;
246e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam
247e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyamtypedef struct {
248e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam    long latitude;              // latitude in degrees * 2^25 , 2's complement
249e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam    long longitude;             // latitude in degrees * 2^25 , 2's complement
250e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam    int  altitude;              // Altitude in units of 1/256 m
251e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam    byte latitude_unc;          // As defined in Section 2.3.2 of IETF RFC 6225
252e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam    byte longitude_unc;         // As defined in Section 2.3.2 of IETF RFC 6225
253e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam    byte altitude_unc;          // As defined in Section 2.4.5 from IETF RFC 6225:
254e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam
255e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam    //Following element for configuring the Z subelement
256e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam    wifi_motion_pattern motion_pattern;
257e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam    int  floor;                 // floor in units of 1/16th of floor. 0x80000000 if unknown.
258e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam    int  height_above_floor;    // in units of 1/64 m
259e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam    int  height_unc;            // in units of 1/64 m. 0 if unknown
260e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam} wifi_lci_information;
261e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam
262e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyamtypedef struct {
263e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam    char country_code[2];       // country code
264e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam    int  length;                // length of the info field
265e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam    char civic_info[256];       // Civic info to be copied in FTM frame
266e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam} wifi_lcr_information;
267e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam
268e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam// API to configure the LCI. Used in RTT Responder mode only
269e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyamwifi_error wifi_set_lci(wifi_request_id id, wifi_interface_handle iface,
270e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam                        wifi_lci_information *lci);
271e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam
272e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam// API to configure the LCR. Used in RTT Responder mode only.
273e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyamwifi_error wifi_set_lcr(wifi_request_id id, wifi_interface_handle iface,
274e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam                        wifi_lcr_information *lcr);
275e853591968f578dc8489f163a0027ef047c75ffeAmarnath Hullur Subramanyam
2768d44928adecbb620028079993ab90d8dd5675510Wei Wang/**
27788aa64b95e2de18380721bda4e05f128cd5107a7Kumar Anand * RTT Responder information
2788d44928adecbb620028079993ab90d8dd5675510Wei Wang */
27988aa64b95e2de18380721bda4e05f128cd5107a7Kumar Anandtypedef struct {
28088aa64b95e2de18380721bda4e05f128cd5107a7Kumar Anand    wifi_channel_info channel;
28188aa64b95e2de18380721bda4e05f128cd5107a7Kumar Anand    wifi_rtt_preamble preamble;
28288aa64b95e2de18380721bda4e05f128cd5107a7Kumar Anand} wifi_rtt_responder;
28388aa64b95e2de18380721bda4e05f128cd5107a7Kumar Anand
28488aa64b95e2de18380721bda4e05f128cd5107a7Kumar Anand/**
28588aa64b95e2de18380721bda4e05f128cd5107a7Kumar Anand * Get RTT responder information e.g. WiFi channel to enable responder on.
28688aa64b95e2de18380721bda4e05f128cd5107a7Kumar Anand */
28788aa64b95e2de18380721bda4e05f128cd5107a7Kumar Anandwifi_error wifi_rtt_get_responder_info(wifi_interface_handle iface,
28888aa64b95e2de18380721bda4e05f128cd5107a7Kumar Anand                                       wifi_rtt_responder *responder_info);
2898d44928adecbb620028079993ab90d8dd5675510Wei Wang
2908d44928adecbb620028079993ab90d8dd5675510Wei Wang/**
2918d44928adecbb620028079993ab90d8dd5675510Wei Wang * Enable RTT responder mode.
2928d44928adecbb620028079993ab90d8dd5675510Wei Wang * channel_hint - hint of the channel information where RTT responder should be enabled on.
2938d44928adecbb620028079993ab90d8dd5675510Wei Wang * max_duration_seconds - timeout of responder mode.
2948d44928adecbb620028079993ab90d8dd5675510Wei Wang * channel_used - channel used for RTT responder, NULL if responder is not enabled.
2958d44928adecbb620028079993ab90d8dd5675510Wei Wang */
2968d44928adecbb620028079993ab90d8dd5675510Wei Wangwifi_error wifi_enable_responder(wifi_request_id id, wifi_interface_handle iface,
2978d44928adecbb620028079993ab90d8dd5675510Wei Wang                                 wifi_channel_info channel_hint, unsigned max_duration_seconds,
29888aa64b95e2de18380721bda4e05f128cd5107a7Kumar Anand                                 wifi_rtt_responder *responder_info);
2998d44928adecbb620028079993ab90d8dd5675510Wei Wang
3008d44928adecbb620028079993ab90d8dd5675510Wei Wang/**
3018d44928adecbb620028079993ab90d8dd5675510Wei Wang * Disable RTT responder mode.
3028d44928adecbb620028079993ab90d8dd5675510Wei Wang */
3038d44928adecbb620028079993ab90d8dd5675510Wei Wangwifi_error wifi_disable_responder(wifi_request_id id, wifi_interface_handle iface);
3048d44928adecbb620028079993ab90d8dd5675510Wei Wang
305b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde#endif
306