1 #include "wifi_hal.h"
2 
3 #ifndef __WIFI_HAL_STATS_H
4 #define __WIFI_HAL_STATS_H
5 
6 #ifdef __cplusplus
7 extern "C"
8 {
9 #endif /* __cplusplus */
10 
11 #define STATS_MAJOR_VERSION      1
12 #define STATS_MINOR_VERSION      0
13 #define STATS_MICRO_VERSION      0
14 
15 typedef enum {
16     WIFI_DISCONNECTED = 0,
17     WIFI_AUTHENTICATING = 1,
18     WIFI_ASSOCIATING = 2,
19     WIFI_ASSOCIATED = 3,
20     WIFI_EAPOL_STARTED = 4,   // if done by firmware/driver
21     WIFI_EAPOL_COMPLETED = 5, // if done by firmware/driver
22 } wifi_connection_state;
23 
24 typedef enum {
25     WIFI_ROAMING_IDLE = 0,
26     WIFI_ROAMING_ACTIVE = 1,
27 } wifi_roam_state;
28 
29 typedef enum {
30     WIFI_INTERFACE_STA = 0,
31     WIFI_INTERFACE_SOFTAP = 1,
32     WIFI_INTERFACE_IBSS = 2,
33     WIFI_INTERFACE_P2P_CLIENT = 3,
34     WIFI_INTERFACE_P2P_GO = 4,
35     WIFI_INTERFACE_NAN = 5,
36     WIFI_INTERFACE_MESH = 6,
37     WIFI_INTERFACE_TDLS = 7,
38     WIFI_INTERFACE_UNKNOWN = -1
39  } wifi_interface_mode;
40 
41 #define WIFI_CAPABILITY_QOS          0x00000001     // set for QOS association
42 #define WIFI_CAPABILITY_PROTECTED    0x00000002     // set for protected association (802.11 beacon frame control protected bit set)
43 #define WIFI_CAPABILITY_INTERWORKING 0x00000004     // set if 802.11 Extended Capabilities element interworking bit is set
44 #define WIFI_CAPABILITY_HS20         0x00000008     // set for HS20 association
45 #define WIFI_CAPABILITY_SSID_UTF8    0x00000010     // set is 802.11 Extended Capabilities element UTF-8 SSID bit is set
46 #define WIFI_CAPABILITY_COUNTRY      0x00000020     // set is 802.11 Country Element is present
47 
48 typedef struct {
49    wifi_interface_mode mode;          // interface mode
50    u8 mac_addr[6];                    // interface mac address (self)
51    wifi_connection_state state;       // connection state (valid for STA, CLI only)
52    wifi_roam_state roaming;           // roaming state
53    u32 capabilities;                  // WIFI_CAPABILITY_XXX (self)
54    u8 ssid[33];                       // null terminated SSID
55    u8 bssid[6];                       // bssid
56    u8 ap_country_str[3];              // country string advertised by AP
57    u8 country_str[3];                 // country string for this association
58    u8 time_slicing_duty_cycle_percent;// if this iface is being served using time slicing on a radio with one or more ifaces (i.e MCC), then the duty cycle assigned to this iface in %.
59                                       // If not using time slicing (i.e SCC or DBS), set to 100.
60 } wifi_interface_link_layer_info;
61 
62 /* channel information */
63 typedef struct {
64    wifi_channel_width width;   // channel width (20, 40, 80, 80+80, 160)
65    wifi_channel center_freq;   // primary 20 MHz channel
66    wifi_channel center_freq0;  // center frequency (MHz) first segment
67    wifi_channel center_freq1;  // center frequency (MHz) second segment
68 } wifi_channel_info;
69 
70 /* wifi rate */
71 typedef struct {
72    u32 preamble   :3;   // 0: OFDM, 1:CCK, 2:HT 3:VHT 4:HE 5..7 reserved
73    u32 nss        :2;   // 0:1x1, 1:2x2, 3:3x3, 4:4x4
74    u32 bw         :3;   // 0:20MHz, 1:40Mhz, 2:80Mhz, 3:160Mhz
75    u32 rateMcsIdx :8;   // OFDM/CCK rate code would be as per ieee std in the units of 0.5mbps
76                         // HT/VHT/HE it would be mcs index
77    u32 reserved  :16;   // reserved
78    u32 bitrate;         // units of 100 Kbps
79 } wifi_rate;
80 
81 /* channel statistics */
82 typedef struct {
83    wifi_channel_info channel;  // channel
84    u32 on_time;                // msecs the radio is awake (32 bits number accruing over time)
85    u32 cca_busy_time;          // msecs the CCA register is busy (32 bits number accruing over time)
86 } wifi_channel_stat;
87 
88 // Max number of tx power levels. The actual number vary per device and is specified by |num_tx_levels|
89 #define RADIO_STAT_MAX_TX_LEVELS 256
90 
91 /* radio statistics */
92 typedef struct {
93    wifi_radio radio;                      // wifi radio (if multiple radio supported)
94    u32 on_time;                           // msecs the radio is awake (32 bits number accruing over time)
95    u32 tx_time;                           // msecs the radio is transmitting (32 bits number accruing over time)
96    u32 num_tx_levels;                     // number of radio transmit power levels
97    u32 *tx_time_per_levels;               // pointer to an array of radio transmit per power levels in
98                                           // msecs accured over time
99    u32 rx_time;                           // msecs the radio is in active receive (32 bits number accruing over time)
100    u32 on_time_scan;                      // msecs the radio is awake due to all scan (32 bits number accruing over time)
101    u32 on_time_nbd;                       // msecs the radio is awake due to NAN (32 bits number accruing over time)
102    u32 on_time_gscan;                     // msecs the radio is awake due to G?scan (32 bits number accruing over time)
103    u32 on_time_roam_scan;                 // msecs the radio is awake due to roam?scan (32 bits number accruing over time)
104    u32 on_time_pno_scan;                  // msecs the radio is awake due to PNO scan (32 bits number accruing over time)
105    u32 on_time_hs20;                      // msecs the radio is awake due to HS2.0 scans and GAS exchange (32 bits number accruing over time)
106    u32 num_channels;                      // number of channels
107    wifi_channel_stat channels[];          // channel statistics
108 } wifi_radio_stat;
109 
110 /**
111  * Packet statistics reporting by firmware is performed on MPDU basi (i.e. counters increase by 1 for each MPDU)
112  * As well, "data packet" in associated comments, shall be interpreted as 802.11 data packet,
113  * that is, 802.11 frame control subtype == 2 and excluding management and control frames.
114  *
115  * As an example, in the case of transmission of an MSDU fragmented in 16 MPDUs which are transmitted
116  * OTA in a 16 units long a-mpdu, for which a block ack is received with 5 bits set:
117  *          tx_mpdu : shall increase by 5
118  *          retries : shall increase by 16
119  *          tx_ampdu : shall increase by 1
120  * data packet counters shall not increase regardless of the number of BAR potentially sent by device for this a-mpdu
121  * data packet counters shall not increase regardless of the number of BA received by device for this a-mpdu
122  *
123  * For each subsequent retransmission of the 11 remaining non ACK'ed mpdus
124  * (regardless of the fact that they are transmitted in a-mpdu or not)
125  *          retries : shall increase by 1
126  *
127  * If no subsequent BA or ACK are received from AP, until packet lifetime expires for those 11 packet that were not ACK'ed
128  *          mpdu_lost : shall increase by 11
129  */
130 
131 /* per rate statistics */
132 typedef struct {
133    wifi_rate rate;     // rate information
134    u32 tx_mpdu;        // number of successfully transmitted data pkts (ACK rcvd)
135    u32 rx_mpdu;        // number of received data pkts
136    u32 mpdu_lost;      // number of data packet losses (no ACK)
137    u32 retries;        // total number of data pkt retries
138    u32 retries_short;  // number of short data pkt retries
139    u32 retries_long;   // number of long data pkt retries
140 } wifi_rate_stat;
141 
142 /* access categories */
143 typedef enum {
144    WIFI_AC_VO  = 0,
145    WIFI_AC_VI  = 1,
146    WIFI_AC_BE  = 2,
147    WIFI_AC_BK  = 3,
148    WIFI_AC_MAX = 4,
149 } wifi_traffic_ac;
150 
151 /* wifi peer type */
152 typedef enum
153 {
154    WIFI_PEER_STA,
155    WIFI_PEER_AP,
156    WIFI_PEER_P2P_GO,
157    WIFI_PEER_P2P_CLIENT,
158    WIFI_PEER_NAN,
159    WIFI_PEER_TDLS,
160    WIFI_PEER_INVALID,
161 } wifi_peer_type;
162 
163 /* per peer statistics */
164 typedef struct bssload_info {
165     u16 sta_count;    // station count
166     u16 chan_util;    // channel utilization
167     u8 PAD[4];
168 } bssload_info_t;
169 
170 typedef struct {
171    wifi_peer_type type;           // peer type (AP, TDLS, GO etc.)
172    u8 peer_mac_address[6];        // mac address
173    u32 capabilities;              // peer WIFI_CAPABILITY_XXX
174    bssload_info_t bssload;        // STA count and CU
175    u32 num_rate;                  // number of rates
176    wifi_rate_stat rate_stats[];   // per rate statistics, number of entries  = num_rate
177 } wifi_peer_info;
178 
179 /* Per access category statistics */
180 typedef struct {
181    wifi_traffic_ac ac;             // access category (VI, VO, BE, BK)
182    u32 tx_mpdu;                    // number of successfully transmitted unicast data pkts (ACK rcvd)
183    u32 rx_mpdu;                    // number of received unicast data packets
184    u32 tx_mcast;                   // number of succesfully transmitted multicast data packets
185                                    // STA case: implies ACK received from AP for the unicast packet in which mcast pkt was sent
186    u32 rx_mcast;                   // number of received multicast data packets
187    u32 rx_ampdu;                   // number of received unicast a-mpdus; support of this counter is optional
188    u32 tx_ampdu;                   // number of transmitted unicast a-mpdus; support of this counter is optional
189    u32 mpdu_lost;                  // number of data pkt losses (no ACK)
190    u32 retries;                    // total number of data pkt retries
191    u32 retries_short;              // number of short data pkt retries
192    u32 retries_long;               // number of long data pkt retries
193    u32 contention_time_min;        // data pkt min contention time (usecs)
194    u32 contention_time_max;        // data pkt max contention time (usecs)
195    u32 contention_time_avg;        // data pkt avg contention time (usecs)
196    u32 contention_num_samples;     // num of data pkts used for contention statistics
197 } wifi_wmm_ac_stat;
198 
199 /* interface statistics */
200 typedef struct {
201    wifi_interface_handle iface;          // wifi interface
202    wifi_interface_link_layer_info info;  // current state of the interface
203    u32 beacon_rx;                        // access point beacon received count from connected AP
204    u64 average_tsf_offset;               // average beacon offset encountered (beacon_TSF - TBTT)
205                                          // The average_tsf_offset field is used so as to calculate the
206                                          // typical beacon contention time on the channel as well may be
207                                          // used to debug beacon synchronization and related power consumption issue
208    u32 leaky_ap_detected;                // indicate that this AP typically leaks packets beyond the driver guard time.
209    u32 leaky_ap_avg_num_frames_leaked;  // average number of frame leaked by AP after frame with PM bit set was ACK'ed by AP
210    u32 leaky_ap_guard_time;              // guard time currently in force (when implementing IEEE power management based on
211                                          // frame control PM bit), How long driver waits before shutting down the radio and
212                                          // after receiving an ACK for a data frame with PM bit set)
213    u32 mgmt_rx;                          // access point mgmt frames received count from connected AP (including Beacon)
214    u32 mgmt_action_rx;                   // action frames received count
215    u32 mgmt_action_tx;                   // action frames transmit count
216    wifi_rssi rssi_mgmt;                  // access Point Beacon and Management frames RSSI (averaged)
217    wifi_rssi rssi_data;                  // access Point Data Frames RSSI (averaged) from connected AP
218    wifi_rssi rssi_ack;                   // access Point ACK RSSI (averaged) from connected AP
219    wifi_wmm_ac_stat ac[WIFI_AC_MAX];     // per ac data packet statistics
220    u32 num_peers;                        // number of peers
221    wifi_peer_info peer_info[];           // per peer statistics
222 } wifi_iface_stat;
223 
224 /* configuration params */
225 typedef struct {
226    u32 mpdu_size_threshold;             // threshold to classify the pkts as short or long
227                                         // packet size < mpdu_size_threshold => short
228    u32 aggressive_statistics_gathering; // set for field debug mode. Driver should collect all statistics regardless of performance impact.
229 } wifi_link_layer_params;
230 
231 /* API to trigger the link layer statistics collection.
232    Unless his API is invoked - link layer statistics will not be collected.
233    Radio statistics (once started) do not stop or get reset unless wifi_clear_link_stats is invoked
234    Interface statistics (once started) reset and start afresh after each connection */
235 wifi_error wifi_set_link_stats(wifi_interface_handle iface, wifi_link_layer_params params);
236 
237 /* callback for reporting link layer stats */
238 typedef struct {
239   void (*on_link_stats_results) (wifi_request_id id, wifi_iface_stat *iface_stat,
240          int num_radios, wifi_radio_stat *radio_stat);
241 } wifi_stats_result_handler;
242 
243 /* api to collect the link layer statistics for a given iface and all the radio stats */
244 wifi_error wifi_get_link_stats(wifi_request_id id,
245         wifi_interface_handle iface, wifi_stats_result_handler handler);
246 
247 /* wifi statistics bitmap  */
248 #define WIFI_STATS_RADIO              0x00000001      // all radio statistics
249 #define WIFI_STATS_RADIO_CCA          0x00000002      // cca_busy_time (within radio statistics)
250 #define WIFI_STATS_RADIO_CHANNELS     0x00000004      // all channel statistics (within radio statistics)
251 #define WIFI_STATS_RADIO_SCAN         0x00000008      // all scan statistics (within radio statistics)
252 #define WIFI_STATS_IFACE              0x00000010      // all interface statistics
253 #define WIFI_STATS_IFACE_TXRATE       0x00000020      // all tx rate statistics (within interface statistics)
254 #define WIFI_STATS_IFACE_AC           0x00000040      // all ac statistics (within interface statistics)
255 #define WIFI_STATS_IFACE_CONTENTION   0x00000080      // all contention (min, max, avg) statistics (within ac statisctics)
256 
257 /* clear api to reset statistics, stats_clear_rsp_mask identifies what stats have been cleared
258    stop_req = 1 will imply whether to stop the statistics collection.
259    stop_rsp = 1 will imply that stop_req was honored and statistics collection was stopped.
260  */
261 wifi_error wifi_clear_link_stats(wifi_interface_handle iface,
262       u32 stats_clear_req_mask, u32 *stats_clear_rsp_mask, u8 stop_req, u8 *stop_rsp);
263 
264 #ifdef __cplusplus
265 }
266 #endif /* __cplusplus */
267 
268 #endif /*__WIFI_HAL_STATS_ */
269 
270