1b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde
2b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde#include "wifi_hal.h"
3b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde
4b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde#ifndef __WIFI_HAL_RTT_H__
5b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde#define __WIFI_HAL_RTT_H__
6b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde
7424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* channel operating width */
8424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande
9424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* Ranging status */
10424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpandetypedef enum {
11424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    RTT_STATUS_SUCCESS,
12424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    RTT_STATUS_FAILURE,
13424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    RTT_STATUS_FAIL_NO_RSP,
14424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    RTT_STATUS_FAIL_REJECTED,
15424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    RTT_STATUS_FAIL_NOT_SCHEDULED_YET,
16424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    RTT_STATUS_FAIL_TM_TIMEOUT,
17424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    RTT_STATUS_FAIL_AP_ON_DIFF_CHANNEL,
18424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    RTT_STATUS_FAIL_NO_CAPABILITY,
19424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    RTT_STATUS_ABORTED
20424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande} wifi_rtt_status;
21424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande
22424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande
23424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* RTT Type */
24424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpandetypedef enum {
25424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    RTT_TYPE_INVALID,
26424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    RTT_TYPE_1_SIDED,
27424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    RTT_TYPE_2_SIDED,
28424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    RTT_TYPE_AUTO,              // Two sided if remote supports; one sided otherwise
29424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande} wifi_rtt_type;
30424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande
31424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* RTT configuration */
32b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapndetypedef struct {
33424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    mac_addr addr;                     // peer device mac address
34424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    wifi_rtt_type type;                // optional - rtt type hint. RTT_TYPE_INVALID implies best effort
35424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    wifi_peer_type peer;               // optional - peer device hint (STA, P2P, AP)
36424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    wifi_channel_info channel;         // Required for STA-AP mode, optional for P2P, NBD etc.
37424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    byte continuous;                   // 0 = single shot or 1 = continuous ranging
38424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    unsigned interval;                 // interval of RTT measurement (unit ms) when continuous = true
39424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    unsigned num_measurements;         // total number of RTT measurements when continuous = true
40424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    unsigned num_samples_per_measurement; // num of packets in each RTT measurement
41424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    unsigned num_retries_per_measurement; // num of retries if sampling fails
42424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande} wifi_rtt_config;
43424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande
44424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* RTT results */
45b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapndetypedef struct {
46424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    mac_addr addr;               // device mac address
47424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    unsigned measurement_num;    // measurement number in case of continuous ranging
48424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    wifi_rtt_status status;      // ranging status
49424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    wifi_rtt_type type;          // RTT type
50424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    wifi_peer_type peer;         // peer device type (P2P, AP)
51424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    wifi_channel_info channel;   // channel information
52424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    wifi_rssi rssi;              // rssi in 0.5 dB steps e.g. 143 implies -71.5 dB
53424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    wifi_rssi rssi_spread;       // rssi spread in 0.5 dB steps e.g. 5 implies 2.5 dB spread (optional)
54424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    wifi_rate tx_rate;           // TX rate
55424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    wifi_timespan rtt;           // round trip time in nanoseconds
56424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    wifi_timespan rtt_sd;        // rtt standard deviation in nanoseconds
57424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    wifi_timespan rtt_spread;    // difference between max and min rtt times recorded
58424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    int distance;                // distance in cm (optional)
59424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    int distance_sd;             // standard deviation in cm (optional)
60424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    int distance_spread;         // difference between max and min distance recorded (optional)
61424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    wifi_timestamp ts;           // time of the measurement (in microseconds since boot)
62424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande} wifi_rtt_result;
63424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande
64424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* RTT result callback */
65424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpandetypedef struct {
66424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    void (*on_rtt_results) (wifi_request_id id, unsigned num_results, wifi_rtt_result rtt_result[]);
67424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande} wifi_rtt_event_handler;
68b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde
69424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* API to request RTT measurement */
70424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpandewifi_error wifi_rtt_range_request(wifi_request_id id, wifi_interface_handle iface,
71424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande        unsigned num_rtt_config, wifi_rtt_config rtt_config[], wifi_rtt_event_handler handler);
72b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde
73424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* API to cancel RTT measurements */
7493f677b67008faa0995d9283d04aa2ee3ef3a582Ashwinwifi_error wifi_rtt_range_cancel(wifi_request_id id,  wifi_interface_handle iface,
7593f677b67008faa0995d9283d04aa2ee3ef3a582Ashwin        unsigned num_devices, mac_addr addr[]);
76b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde
77424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* NBD ranging channel map */
78424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpandetypedef struct {
79424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande    wifi_channel availablity[32];           // specifies the channel map for each of the 16 TU windows
80424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande                                            // frequency of 0 => unspecified; which means firmware is
81424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande                                            // free to do whatever it wants in this window.
82424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande} wifi_channel_map;
83424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande
84424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* API to start publishing the channel map on responder device in a NBD cluster.
85424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande   Responder device will take this request and schedule broadcasting the channel map
86424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande   in a NBD ranging attribute in a SDF. DE will automatically remove the ranging
87424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande   attribute from the OTA queue after number of DW specified by num_dw
88424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande   where Each DW is 512 TUs apart */
89424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpandewifi_error wifi_rtt_channel_map_set(wifi_request_id id,
90424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande        wifi_interface_handle iface, wifi_channel_map *params, unsigned num_dw);
91424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande
92424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* API to clear the channel map on the responder device in a NBD cluster.
93424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande   Responder device will cancel future ranging channel request, starting from next
94424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande   DW interval and will also stop broadcasting NBD ranging attribute in SDF */
95424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpandewifi_error wifi_rtt_channel_map_clear(wifi_request_id id,  wifi_interface_handle iface);
96424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande
97424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/* RTT Capabilities */
98b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapndetypedef struct {
99424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande   byte rtt_one_sided_supported;  // if 1-sided rtt data collection is supported
100424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande   byte rtt_11v_supported;        // if 11v rtt data collection is supported
101424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande   byte rtt_ftm_supported;        // if ftm rtt data collection is supported
102424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande} wifi_rtt_capabilities;
103b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde
104424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpande/*  RTT capabilities of the device */
105424a9d0ac7615ca32990bdf49eafa68b2e052e20Vinit Deshpandewifi_error wifi_get_rtt_capabilities(wifi_interface_handle iface, wifi_rtt_capabilities *capabilities);
106b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde
107b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde#endif
108b80d32d2a1ba28f2b5dda7315e136a9ea14eda26Vinit Deshapnde
109