OSDN Git Service

fix to hal interface
[android-x86/hardware-libhardware_legacy.git] / include / hardware_legacy / wifi_logger.h
1 #include "wifi_hal.h"\r
2 \r
3 #ifndef __WIFI_HAL_LOGGER_H\r
4 #define __WIFI_HAL_LOGGER_H\r
5 \r
6 #ifdef __cplusplus\r
7 extern "C"\r
8 {\r
9 #endif /* __cplusplus */\r
10 \r
11 #define LOGGER_MAJOR_VERSION      1\r
12 #define LOGGER_MINOR_VERSION      0\r
13 #define LOGGER_MICRO_VERSION      0\r
14 \r
15 \r
16 \r
17 /**\r
18  * WiFi logger life cycle is as follow:\r
19  *\r
20  * - at initialization time, framework will call wifi_get_ring_buffers_status so as to obtain the\r
21  * names and list of supported buffers\r
22  * - when WiFi operation start framework will call wifi_start_logging so as to trigger log collection\r
23  * - Developper UI will provide an option to the user, so as it can set the verbose level of individual buffer\r
24  *    as reported by wifi_get_ring_buffers_status\r
25  * - during wifi operations, driver will periodically report per ring data to framework by invoking the\r
26  *    on_ring_buffer_data call back\r
27  * - when capturing a bug report, framework will indicate to driver that all the data has to be uploaded,\r
28  *   urgently, by calling wifi_get_ring_data\r
29  *\r
30  * The data uploaded by driver will be stored by framework in separate files, with one stream of file per ring.\r
31  * Framework will store the files in pcapng format, allowing for easy merging and parsing with network\r
32  * analyzer tools.\r
33  */\r
34 \r
35 \r
36 typedef int wifi_radio;\r
37 typedef int wifi_ring_buffer_id;\r
38 \r
39 #define PER_PACKET_ENTRY_FLAGS_DIRECTION_TX 1 //  0: TX, 1: RX\r
40 #define PER_PACKET_ENTRY_FLAGS_TX_SUCCESS 2 // whether packet was transmitted or received/decrypted successfully\r
41 #define PER_PACKET_ENTRY_FLAGS_80211_HEADER 4 // has full 802.11 header, else has 802.3 header\r
42 #define PER_PACKET_ENTRY_FLAGS_PROTECTED 8  // whether packet was encrypted\r
43 \r
44 typedef struct {\r
45     u8 flags;\r
46     u8 tid; // transmit or received tid\r
47     u16 MCS; // modulation and bandwidth\r
48     u8 rssi; // TX: RSSI of ACK for that packet\r
49              // RX: RSSI of packet\r
50     u8 num_retries; // number of attempted retries\r
51     u16 last_transmit_rate; // last transmit rate in .5 mbps\r
52     u16 link_layer_transmit_sequence; // transmit/reeive sequence for that MPDU packet\r
53     u64 firmware_entry_timestamp;  // TX: firmware timestamp (us) when packet is queued within firmware buffer\r
54                                    // for SDIO/HSIC or into PCIe buffer\r
55                                    // RX : firmware receive timestamp\r
56     u64 start_contention_timestamp; // firmware timestamp (us) when packet start contending for the\r
57                                     // medium for the first time, at head of its AC queue,\r
58                                     // or as part of an MPDU or A-MPDU. This timestamp is not updated\r
59                                     // for each retry, only the first transmit attempt.\r
60     u64 transmit_success_timestamp; // fimrware timestamp (us) when packet is successfully transmitted\r
61                                     // or aborted because it has exhausted its maximum number of retries\r
62     u8 data[0]; // packet data. The length of packet data is determined by the entry_size field of\r
63                 // the wifi_ring_buffer_entry structure. It is expected that first bytes of the\r
64                 // packet, or packet headers only (up to TCP or RTP/UDP headers) will be copied into the ring\r
65 } wifi_ring_per_packet_status_entry __attribute__((packed));\r
66 \r
67 static char per_packet_status_ring_name[] = "wifi_per_packet_status"; // Ring buffer name for per-packet status ring\r
68 \r
69 // Below events refer to the wifi_connectivity_event ring and shall be supported\r
70 \r
71 #define WIFI_EVENT_ASSOCIATION_REQUESTED 0 // driver receive association command from kernel\r
72 #define WIFI_EVENT_AUTH_COMPLETE 1\r
73 #define WIFI_EVENT_ASSOC_COMPLETE 2\r
74 #define WIFI_EVENT_FW_AUTH_STARTED 3 // received firmware event indicating auth frames are sent\r
75 #define WIFI_EVENT_FW_ASSOC_STARTED 4 // received firmware event indicating assoc frames are sent\r
76 #define WIFI_EVENT_FW_RE_ASSOC_STARTED 5 // received firmware event indicating reassoc frames are sent\r
77 #define WIFI_EVENT_DRIVER_SCAN_REQUESTED 6\r
78 #define WIFI_EVENT_DRIVER_SCAN_RESULT_FOUND 7\r
79 #define WIFI_EVENT_DRIVER_SCAN_COMPLETE 8\r
80 #define WIFI_EVENT_G_SCAN_STARTED 9\r
81 #define WIFI_EVENT_G_SCAN_COMPLETE 10\r
82 #define WIFI_EVENT_DISASSOCIATION_REQUESTED 11\r
83 #define WIFI_EVENT_RE_ASSOCIATION_REQUESTED 12\r
84 #define WIFI_EVENT_ROAM_REQUESTED 13\r
85 #define WIFI_EVENT_BEACON_RECEIVED 14 // received beacon from AP (event enabled only in verbose mode)\r
86 #define WIFI_EVENT_ROAM_SCAN_STARTED 15 // firmware has triggered a roam scan (not g-scan)\r
87 #define WIFI_EVENT_ROAM_SCAN_COMPLETE 16 // firmware has completed a roam scan (not g-scan)\r
88 #define WIFI_EVENT_ROAM_SEARCH_STARTED 17 // firmware has started searching for roam candidates (with reason =xx)\r
89 #define WIFI_EVENT_ROAM_SEARCH_STOPPED 18 // firmware has stopped searching for roam candidates (with reason =xx)\r
90 #define WIFI_EVENT_CHANNEL_SWITCH_ANOUNCEMENT 20 // received channel switch anouncement from AP\r
91 #define WIFI_EVENT_FW_EAPOL_FRAME_TRANSMIT_START 21 // fw start transmit eapol frame, with EAPOL index 1-4\r
92 #define WIFI_EVENT_FW_EAPOL_FRAME_TRANSMIT_STOP 22 // fw gives up eapol frame, with rate, success/failure and number retries\r
93 #define WIFI_EVENT_DRIVER_EAPOL_FRAME_TRANSMIT_REQUESTED 23 // kernel queue EAPOL for transmission in tdriver\r
94                                                             // with EAPOL index 1-4\r
95 #define WIFI_EVENT_FW_EAPOL_FRAME_RECEIVED 24 // with rate, regardless of the fact that EAPOL frame\r
96                                            // is accepted or rejected by firmware\r
97 #define WIFI_EVENT_DRIVER_EAPOL_FRAME_RECEIVED 26 // with rate, and eapol index, driver has received\r
98                                                   // EAPOL frame and will queue it up to wpa_supplicant\r
99 #define WIFI_EVENT_BLOCK_ACK_NEGOTIATION_COMPLETE 27 // with success/failure, parameters\r
100 #define WIFI_EVENT_BT_COEX_BT_SCO_START 28\r
101 #define WIFI_EVENT_BT_COEX_BT_SCO_STOP 29\r
102 #define WIFI_EVENT_BT_COEX_BT_SCAN_START 30 // for paging/scan etc..., when BT starts transmiting\r
103                                             //    twice per BT slot\r
104 #define WIFI_EVENT_BT_COEX_BT_SCAN_STOP 31\r
105 #define WIFI_EVENT_BT_COEX_BT_HID_START 32\r
106 #define WIFI_EVENT_BT_COEX_BT_HID_STOP 33\r
107 #define WIFI_EVENT_ROAM_AUTH_STARTED 34 // firmware sends auth frame in roaming to next candidate\r
108 #define WIFI_EVENT_ROAM_AUTH_COMPLETE 35 // firmware receive auth confirm from ap\r
109 #define WIFI_EVENT_ROAM_ASSOC_STARTED 36 // firmware sends assoc/reassoc frame in\r
110                                          //     roaming to next candidate\r
111 #define WIFI_EVENT_ROAM_ASSOC_COMPLETE 37 // firmware receive assoc/reassoc confirm from ap\r
112 \r
113 \r
114 \r
115 // Parameters of wifi logger events are TLVs\r
116 // Event parameters tags are defined as:\r
117 #define WIFI_TAG_VENDOR_SPECIFIC 0 // take a byte stream as parameter\r
118 #define WIFI_TAG_BSSID 1 // takes a 6 bytes MAC address as parameter\r
119 #define WIFI_TAG_ADDR 2 // takes a 6 bytes MAC address as parameter\r
120 #define WIFI_TAG_SSID 3 // takes a 32 bytes SSID address as parameter\r
121 #define WIFI_TAG_STATUS 4 // takes an integer as parameter\r
122 #define WIFI_TAG_CHANNEL_SPEC 5 // takes one or more wifi_channel_spec as parameter\r
123 #define WIFI_TAG_WAKE_LOCK_EVENT 6 // takes a wake_lock_event struct as parameter\r
124 #define WIFI_TAG_ADDR1 7 // takes a 6 bytes MAC address as parameter\r
125 #define WIFI_TAG_ADDR2 8 // takes a 6 bytes MAC address as parameter\r
126 #define WIFI_TAG_ADDR3 9 // takes a 6 bytes MAC address as parameter\r
127 #define WIFI_TAG_ADDR4 10 // takes a 6 bytes MAC address as parameter\r
128 #define WIFI_TAG_TSF 11 // take a 64 bits TSF value as parameter\r
129 #define WIFI_TAG_IE 12  // take one or more specific 802.11 IEs parameter, IEs are in turn indicated\r
130                         // in TLV format as per 802.11 spec\r
131 #define WIFI_TAG_INTERFACE 13 // take interface name as parameter\r
132 #define WIFI_TAG_REASON_CODE 14 // take a reason code as per 802.11 as parameter\r
133 #define WIFI_TAG_RATE_MBPS 15 // take a wifi rate in 0.5 mbps\r
134 \r
135 typedef struct {\r
136     u16 tag;\r
137     u16 length; // length of value\r
138     u8 value[0];\r
139 } tlv_log __attribute__((packed));\r
140 \r
141 typedef struct {\r
142     u16 event;\r
143     tlv_log tlvs[0];    // separate parameter structure per event to be provided and optional data\r
144                         // the event_data is expected to include an official android part, with some\r
145                         // parameter as transmit rate, num retries, num scan result found etc...\r
146                         // as well, event_data can include a vendor proprietary part which is\r
147                         // understood by the developer only.\r
148 } wifi_ring_buffer_driver_connectivity_event __attribute__((packed));\r
149 \r
150 // Ring buffer name for connectivity events ring\r
151 static char connectivity_event_ring_name[] = "wifi_connectivity_events";\r
152 \r
153 // Ring buffer name for power events ring. note that power event are extremely frequents\r
154 // and thus should be stored in their own ring/file so as not to clobber connectivity events\r
155 \r
156 typedef struct {\r
157     int status;   // 0 taken, 1 released\r
158     int reason;   // reason why this wake lock is taken\r
159     char name[0]; // null terminated\r
160 } wake_lock_event __attribute__((packed));\r
161 \r
162 typedef struct {\r
163     u16 event;\r
164     tlv_log tlvs[0];\r
165 } wifi_power_event __attribute__((packed));\r
166 \r
167 static char power_event_ring_name[] = "wifi_power_events";\r
168 \r
169 /**\r
170  * This structure represent a logger entry within a ring buffer.\r
171  * Wifi driver are responsible to manage the ring buffer and write the debug\r
172  * information into those rings.\r
173  *\r
174  * In general, the debug entries can be used to store meaningful 802.11 information (SME, MLME,\r
175  * connection and packet statistics) as well as vendor proprietary data that is specific to a\r
176  * specific driver or chipset.\r
177  * Binary entries can be used so as to store packet data or vendor specific information and\r
178  * will be treated as blobs of data by android.\r
179  *\r
180  * A user land process will be started by framework so as to periodically retrieve the\r
181  * data logged by drivers into their ring buffer, store the data into log files and include\r
182  * the logs into android bugreports.\r
183  */\r
184 \r
185 #define RING_BUFFER_ENTRY_FLAGS_HAS_BINARY 1 // set for binary entries\r
186 #define RING_BUFFER_ENTRY_FLAGS_HAS_TIMESTAMP 2 // set if 64 bits timestamp is present\r
187 \r
188 typedef struct {\r
189     u16 entry_size;\r
190     u8 flags;\r
191     u8 type; // Per ring specific\r
192     u64 timestamp; //present if has_timestamp bit is set.\r
193     union {\r
194         u8 data[0];\r
195         wifi_ring_buffer_driver_connectivity_event connectivity_event;\r
196         wifi_ring_per_packet_status_entry packet_status;\r
197         wifi_power_event power_event;\r
198         };\r
199 } wifi_ring_buffer_entry __attribute__((packed));\r
200 \r
201 #define WIFI_RING_BUFFER_FLAG_HAS_BINARY_ENTRIES 0x00000001     // set if binary entries are present\r
202 #define WIFI_RING_BUFFER_FLAG_HAS_ASCII_ENTRIES  0x00000002     // set if ascii entries are present\r
203 \r
204 /* ring buffer params */\r
205 /**\r
206  * written_bytes and read_bytes implement a producer consumer API\r
207  *     hence written_bytes >= read_bytes\r
208  * a modulo arithmetic of the buffer size has to be applied to those counters:\r
209  * actual offset into ring buffer = written_bytes % ring_buffer_byte_size\r
210  *\r
211  */\r
212 typedef struct {\r
213    u8 name[32];\r
214    u32 flags;\r
215    wifi_ring_buffer_id ring_id; // unique integer representing the ring\r
216    u32 ring_buffer_byte_size;   // total memory size allocated for the buffer\r
217    u32 verbose_level; //\r
218    u32 written_bytes; // number of bytes that was written to the buffer by driver, monotonously increasing integer\r
219    u32 read_bytes;  // number of bytes that was read from the buffer by user land, monotonously increasing integer\r
220    u32 written_records;  // number of records that was written to the buffer by driver, monotonously increasing integer\r
221 \r
222 } wifi_ring_buffer_status;\r
223 \r
224 /**\r
225  * Callback for reporting ring data\r
226  *\r
227  * The ring buffer data collection is event based:\r
228  *    - driver calls on_ring_buffer_data when new records are available, the wifi_ring_buffer_status\r
229  *      passed up to framework in the call back indicates to framework if more data is available in\r
230  *      the ring buffer. It is not expected that driver will necessarily always empty the ring\r
231  *      immediately as data is available, instead driver will report data every X seconds or if\r
232  *      N bytes are available.\r
233  *    - in the case where a bug report has to be captured, framework will require driver to upload\r
234  *      all data immediately. This is indicated to driver when framework calls wifi_get_ringdata.\r
235  *      When framework calls wifi_get_ring_data, driver will start sending all available data in the\r
236  *      indicated ring by repeatedly invoking the on_ring_buffer_data callback\r
237  *\r
238  * The callback is called by driver whenever new data is\r
239  */\r
240 typedef struct {\r
241   void (*on_ring_buffer_data) (wifi_request_id id, wifi_ring_buffer_id ring_id, char *buffer, int buffer_size, wifi_ring_buffer_status *status);\r
242 } wifi_ring_buffer_data_handler;\r
243 \r
244 \r
245 /* api for framework to indicate driver has to upload and drain all data of a given ring */\r
246 wifi_error wifi_get_ring_data(wifi_request_id id,\r
247         wifi_interface_handle iface, wifi_ring_buffer_id ring_id);\r
248 \r
249 \r
250 /**\r
251  * API to trigger the debug collection.\r
252  *  Unless his API is invoked - logging is not triggered.\r
253  *  - verbose_level 0 corresponds to no collection\r
254  *  - verbose_level 1 correspond to normal log level, with minimal user impact. this is the default value\r
255  *  - verbose_level 2 are enabled when user is lazily trying to reproduce a problem, wifi performances and power\r
256  *     can be impacted but device should not otherwise be significantly impacted\r
257  *  - verbose_level 3+ are used when trying to actively debug a problem\r
258  *\r
259  * buffer_name represent the name of the ring for which data collection shall start.\r
260  *\r
261  * flags: TBD parameter used to enable/disable specific events on a ring\r
262  * max_interval: maximum interval in seconds for driver to invoke on_ring_buffer_data, ignore if zero\r
263  * min_data_size: minimum data size in buffer for driver to invoke on_ring_buffer_data, ignore if zero\r
264  */\r
265 \r
266 wifi_error wifi_start_logging(wifi_interface_handle iface, u32 verbose_level, u32 flags, u32 max_interval_sec, u32 min_data_size, u8 *buffer_name, wifi_ring_buffer_data_handler handler);\r
267 \r
268 /* api to get the status of all ring buffers supported by driver */\r
269 wifi_error wifi_get_ring_buffers_status(wifi_request_id id,\r
270         wifi_interface_handle iface, u32 num_buffers, wifi_ring_buffer_status *status);\r
271 \r
272 /* api to collect a firmware memory dump for a given iface */\r
273 wifi_error wifi_get_firmware_memory_dump(wifi_request_id id,\r
274         wifi_interface_handle iface, char ** buffer, int *buffer_size);\r
275 \r
276 /* api to collect a firmware version string */\r
277 wifi_error wifi_get_firmware_version(wifi_request_id id,\r
278         wifi_interface_handle iface, char *buffer, int buffer_size);\r
279 \r
280 /* api to collect a driver version string */\r
281 wifi_error wifi_get_driver_version(wifi_request_id id,\r
282         wifi_interface_handle iface, char *buffer, int buffer_size);\r
283 \r
284 \r
285 /* api to collect driver records */\r
286 wifi_error wifi_get_ringdata(wifi_request_id id,\r
287         wifi_interface_handle iface, wifi_ring_buffer_id ring_id);\r
288 \r
289 \r
290 /* Feature set */\r
291 #define WIFI_LOGGER_MEMORY_DUMP_SUPPORTED 1\r
292 #define WIFI_LOGGER_PER_PACKET_TX_RX_STATUS_SUPPORTED 2\r
293 \r
294 wifi_error wifi_get_logger_supported_feature_set(wifi_interface_handle handle, unsigned int *support);\r
295 \r
296 \r
297 #ifdef __cplusplus\r
298 }\r
299 #endif /* __cplusplus */\r
300 \r
301 #endif /*__WIFI_HAL_STATS_ */\r
302 \r