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 int wifi_radio; 16 typedef int wifi_channel; 17 18 /* channel operating width */ 19 typedef enum { 20 WIFI_CHAN_WIDTH_20 = 0, 21 WIFI_CHAN_WIDTH_40 = 1, 22 WIFI_CHAN_WIDTH_80 = 2, 23 WIFI_CHAN_WIDTH_160 = 3, 24 WIFI_CHAN_WIDTH_80P80 = 4, 25 WIFI_CHAN_WIDTH_5 = 5, 26 WIFI_CHAN_WIDTH_10 = 6, 27 WIFI_CHAN_WIDTH_INVALID = -1 28 } wifi_channel_width; 29 30 typedef enum { 31 WIFI_DISCONNECTED = 0, 32 WIFI_AUTHENTICATING = 1, 33 WIFI_ASSOCIATING = 2, 34 WIFI_ASSOCIATED = 3, 35 WIFI_EAPOL_STARTED = 4, // if done by firmware/driver 36 WIFI_EAPOL_COMPLETED = 5, // if done by firmware/driver 37 } wifi_connection_state; 38 39 typedef enum { 40 WIFI_ROAMING_IDLE = 0, 41 WIFI_ROAMING_ACTIVE = 1, 42 } wifi_roam_state; 43 44 typedef enum { 45 WIFI_INTERFACE_STA = 0, 46 WIFI_INTERFACE_SOFTAP = 1, 47 WIFI_INTERFACE_IBSS = 2, 48 WIFI_INTERFACE_P2P_CLIENT = 3, 49 WIFI_INTERFACE_P2P_GO = 4, 50 WIFI_INTERFACE_NAN = 5, 51 WIFI_INTERFACE_MESH = 6, 52 WIFI_INTERFACE_UNKNOWN = -1 53 } wifi_interface_mode; 54 55 #define WIFI_CAPABILITY_QOS 0x00000001 // set for QOS association 56 #define WIFI_CAPABILITY_PROTECTED 0x00000002 // set for protected association (802.11 beacon frame control protected bit set) 57 #define WIFI_CAPABILITY_INTERWORKING 0x00000004 // set if 802.11 Extended Capabilities element interworking bit is set 58 #define WIFI_CAPABILITY_HS20 0x00000008 // set for HS20 association 59 #define WIFI_CAPABILITY_SSID_UTF8 0x00000010 // set is 802.11 Extended Capabilities element UTF-8 SSID bit is set 60 #define WIFI_CAPABILITY_COUNTRY 0x00000020 // set is 802.11 Country Element is present 61 62 typedef struct { 63 wifi_interface_mode mode; // interface mode 64 u8 mac_addr[6]; // interface mac address (self) 65 wifi_connection_state state; // connection state (valid for STA, CLI only) 66 wifi_roam_state roaming; // roaming state 67 u32 capabilities; // WIFI_CAPABILITY_XXX (self) 68 u8 ssid[33]; // null terminated SSID 69 u8 bssid[6]; // bssid 70 u8 ap_country_str[3]; // country string advertised by AP 71 u8 country_str[3]; // country string for this association 72 } wifi_interface_link_layer_info; 73 74 /* channel information */ 75 typedef struct { 76 wifi_channel_width width; // channel width (20, 40, 80, 80+80, 160) 77 wifi_channel center_freq; // primary 20 MHz channel 78 wifi_channel center_freq0; // center frequency (MHz) first segment 79 wifi_channel center_freq1; // center frequency (MHz) second segment 80 } wifi_channel_info; 81 82 /* wifi rate */ 83 typedef struct { 84 u32 preamble :3; // 0: OFDM, 1:CCK, 2:HT 3:VHT 4..7 reserved 85 u32 nss :2; // 0:1x1, 1:2x2, 3:3x3, 4:4x4 86 u32 bw :3; // 0:20MHz, 1:40Mhz, 2:80Mhz, 3:160Mhz 87 u32 rateMcsIdx :8; // OFDM/CCK rate code would be as per ieee std in the units of 0.5mbps 88 // HT/VHT it would be mcs index 89 u32 reserved :16; // reserved 90 u32 bitrate; // units of 100 Kbps 91 } wifi_rate; 92 93 /* channel statistics */ 94 typedef struct { 95 wifi_channel_info channel; // channel 96 u32 on_time; // msecs the radio is awake (32 bits number accruing over time) 97 u32 cca_busy_time; // msecs the CCA register is busy (32 bits number accruing over time) 98 } wifi_channel_stat; 99 100 /* radio statistics */ 101 typedef struct { 102 wifi_radio radio; // wifi radio (if multiple radio supported) 103 u32 on_time; // msecs the radio is awake (32 bits number accruing over time) 104 u32 tx_time; // msecs the radio is transmitting (32 bits number accruing over time) 105 u32 rx_time; // msecs the radio is in active receive (32 bits number accruing over time) 106 u32 on_time_scan; // msecs the radio is awake due to all scan (32 bits number accruing over time) 107 u32 on_time_nbd; // msecs the radio is awake due to NAN (32 bits number accruing over time) 108 u32 on_time_gscan; // msecs the radio is awake due to G?scan (32 bits number accruing over time) 109 u32 on_time_roam_scan; // msecs the radio is awake due to roam?scan (32 bits number accruing over time) 110 u32 on_time_pno_scan; // msecs the radio is awake due to PNO scan (32 bits number accruing over time) 111 u32 on_time_hs20; // msecs the radio is awake due to HS2.0 scans and GAS exchange (32 bits number accruing over time) 112 u32 num_channels; // number of channels 113 wifi_channel_stat channels[]; // channel statistics 114 } wifi_radio_stat; 115 116 /* per rate statistics */ 117 typedef struct { 118 wifi_rate rate; // rate information 119 u32 tx_mpdu; // number of successfully transmitted data pkts (ACK rcvd) 120 u32 rx_mpdu; // number of received data pkts 121 u32 mpdu_lost; // number of data packet losses (no ACK) 122 u32 retries; // total number of data pkt retries 123 u32 retries_short; // number of short data pkt retries 124 u32 retries_long; // number of long data pkt retries 125 } wifi_rate_stat; 126 127 /* access categories */ 128 typedef enum { 129 WIFI_AC_VO = 0, 130 WIFI_AC_VI = 1, 131 WIFI_AC_BE = 2, 132 WIFI_AC_BK = 3, 133 WIFI_AC_MAX = 4, 134 } wifi_traffic_ac; 135 136 /* wifi peer type */ 137 typedef enum 138 { 139 WIFI_PEER_STA, 140 WIFI_PEER_AP, 141 WIFI_PEER_P2P_GO, 142 WIFI_PEER_P2P_CLIENT, 143 WIFI_PEER_NAN, 144 WIFI_PEER_TDLS, 145 WIFI_PEER_INVALID, 146 } wifi_peer_type; 147 148 /* per peer statistics */ 149 typedef struct { 150 wifi_peer_type type; // peer type (AP, TDLS, GO etc.) 151 u8 peer_mac_address[6]; // mac address 152 u32 capabilities; // peer WIFI_CAPABILITY_XXX 153 u32 num_rate; // number of rates 154 wifi_rate_stat rate_stats[]; // per rate statistics, number of entries = num_rate 155 } wifi_peer_info; 156 157 /* per access category statistics */ 158 typedef struct { 159 wifi_traffic_ac ac; // access category (VI, VO, BE, BK) 160 u32 tx_mpdu; // number of successfully transmitted unicast data pkts (ACK rcvd) 161 u32 rx_mpdu; // number of received unicast mpdus 162 u32 tx_mcast; // number of succesfully transmitted multicast data packets 163 // STA case: implies ACK received from AP for the unicast packet in which mcast pkt was sent 164 u32 rx_mcast; // number of received multicast data packets 165 u32 rx_ampdu; // number of received unicast a-mpdus 166 u32 tx_ampdu; // number of transmitted unicast a-mpdus 167 u32 mpdu_lost; // number of data pkt losses (no ACK) 168 u32 retries; // total number of data pkt retries 169 u32 retries_short; // number of short data pkt retries 170 u32 retries_long; // number of long data pkt retries 171 u32 contention_time_min; // data pkt min contention time (usecs) 172 u32 contention_time_max; // data pkt max contention time (usecs) 173 u32 contention_time_avg; // data pkt avg contention time (usecs) 174 u32 contention_num_samples; // num of data pkts used for contention statistics 175 } wifi_wmm_ac_stat; 176 177 /* interface statistics */ 178 typedef struct { 179 wifi_interface_handle iface; // wifi interface 180 wifi_interface_link_layer_info info; // current state of the interface 181 u32 beacon_rx; // access point beacon received count from connected AP 182 u32 mgmt_rx; // access point mgmt frames received count from connected AP (including Beacon) 183 u32 mgmt_action_rx; // action frames received count 184 u32 mgmt_action_tx; // action frames transmit count 185 wifi_rssi rssi_mgmt; // access Point Beacon and Management frames RSSI (averaged) 186 wifi_rssi rssi_data; // access Point Data Frames RSSI (averaged) from connected AP 187 wifi_rssi rssi_ack; // access Point ACK RSSI (averaged) from connected AP 188 wifi_wmm_ac_stat ac[WIFI_AC_MAX]; // per ac data packet statistics 189 u32 num_peers; // number of peers 190 wifi_peer_info peer_info[]; // per peer statistics 191 } wifi_iface_stat; 192 193 /* configuration params */ 194 typedef struct { 195 u32 mpdu_size_threshold; // threshold to classify the pkts as short or long 196 // packet size < mpdu_size_threshold => short 197 u32 aggressive_statistics_gathering; // set for field debug mode. Driver should collect all statistics regardless of performance impact. 198 } wifi_link_layer_params; 199 200 /* API to trigger the link layer statistics collection. 201 Unless his API is invoked - link layer statistics will not be collected. 202 Radio statistics (once started) do not stop or get reset unless wifi_clear_link_stats is invoked 203 Interface statistics (once started) reset and start afresh after each connection */ 204 wifi_error wifi_set_link_stats(wifi_interface_handle iface, wifi_link_layer_params params); 205 206 /* callback for reporting link layer stats */ 207 typedef struct { 208 void (*on_link_stats_results) (wifi_request_id id, wifi_iface_stat *iface_stat, 209 int num_radios, wifi_radio_stat *radio_stat); 210 } wifi_stats_result_handler; 211 212 /* api to collect the link layer statistics for a given iface and all the radio stats */ 213 wifi_error wifi_get_link_stats(wifi_request_id id, 214 wifi_interface_handle iface, wifi_stats_result_handler handler); 215 216 /* wifi statistics bitmap */ 217 #define WIFI_STATS_RADIO 0x00000001 // all radio statistics 218 #define WIFI_STATS_RADIO_CCA 0x00000002 // cca_busy_time (within radio statistics) 219 #define WIFI_STATS_RADIO_CHANNELS 0x00000004 // all channel statistics (within radio statistics) 220 #define WIFI_STATS_RADIO_SCAN 0x00000008 // all scan statistics (within radio statistics) 221 #define WIFI_STATS_IFACE 0x00000010 // all interface statistics 222 #define WIFI_STATS_IFACE_TXRATE 0x00000020 // all tx rate statistics (within interface statistics) 223 #define WIFI_STATS_IFACE_AC 0x00000040 // all ac statistics (within interface statistics) 224 #define WIFI_STATS_IFACE_CONTENTION 0x00000080 // all contention (min, max, avg) statistics (within ac statisctics) 225 226 /* clear api to reset statistics, stats_clear_rsp_mask identifies what stats have been cleared 227 stop_req = 1 will imply whether to stop the statistics collection. 228 stop_rsp = 1 will imply that stop_req was honored and statistics collection was stopped. 229 */ 230 wifi_error wifi_clear_link_stats(wifi_interface_handle iface, 231 u32 stats_clear_req_mask, u32 *stats_clear_rsp_mask, u8 stop_req, u8 *stop_rsp); 232 233 #ifdef __cplusplus 234 } 235 #endif /* __cplusplus */ 236 237 #endif /*__WIFI_HAL_STATS_ */ 238 239