• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Portions copyright (C) 2017 Broadcom Limited
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #include <hardware_legacy/wifi_hal.h>
20 
21 #ifndef __WIFI_HAL_COMMON_H__
22 #define __WIFI_HAL_COMMON_H__
23 
24 #define LOG_TAG  "WifiHAL"
25 
26 #include <log/log.h>
27 #include "nl80211_copy.h"
28 #include "sync.h"
29 
30 #define SOCKET_BUFFER_SIZE      (32768U)
31 #define RECV_BUF_SIZE           (4096)
32 #define DEFAULT_EVENT_CB_SIZE   (64)
33 #define DEFAULT_CMD_SIZE        (64)
34 #define DOT11_OUI_LEN             3
35 #define DOT11_MAX_SSID_LEN        32
36 
37 #define ETHERTYPE_IP            0x0800          /* IP */
38 #define ETHERTYPE_IPV6          0x86dd          /* IP protocol version 6 */
39 #define MAX_PROBE_RESP_IE_LEN      2048
40 /*
41  Vendor OUI - This is a unique identifier that identifies organization. Lets
42  code Android specific functions with Google OUI; although vendors can do more
43  with their own OUI's as well.
44  */
45 
46 const uint32_t GOOGLE_OUI = 0x001A11;
47 const uint32_t BRCM_OUI =  0x001018;
48 /* TODO: define vendor OUI here */
49 
50 
51 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
52 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
53 
54 #define NMR2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5], (a)[6], (a)[7]
55 #define NMRSTR "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x"
56 #define NAN_MASTER_RANK_LEN 8
57 #define NAN_SCID_INFO_LEN   16
58 
59 #define SAR_CONFIG_SCENARIO_COUNT      100
60 #define MAX_NUM_RADIOS 3
61 #define MAX_CMD_RESP_BUF_LEN 8192
62 
63 #define NL_MSG_MAX_LEN                  5120u
64 #define NAN_DEFAULT_RX_CHAINS_SUPPORTED 2u
65 
66 /* nl_msg->nm_nlh->nlmsg_len is added by data len of the attributes
67  * NL80211_ATTR_VENDOR_ID, NL80211_ATTR_VENDOR_SUBCMD,
68  * NL80211_ATTR_IFINDEX, APF_PROGRAM_LEN by 56u
69  * To keep the additioanl room and aligned,
70  * keeping the overhead of 128u
71  */
72 #define NL_MSG_HDR_OVERHEAD_LEN		128u
73 #define NL_MSG_DEFAULT_LEN		(getpagesize() - NL_MSG_HDR_OVERHEAD_LEN)
74 
75 /*
76  This enum defines ranges for various commands; commands themselves
77  can be defined in respective feature headers; i.e. find gscan command
78  definitions in gscan.cpp
79  */
80 
81 typedef int (*nl_recvmsg_msg_cb_t)(struct nl_msg *msg, void *arg);
82 typedef enum {
83     /* don't use 0 as a valid subcommand */
84     VENDOR_NL80211_SUBCMD_UNSPECIFIED,
85 
86     /* define all vendor startup commands between 0x0 and 0x0FFF */
87     VENDOR_NL80211_SUBCMD_RANGE_START = 0x0001,
88     VENDOR_NL80211_SUBCMD_RANGE_END   = 0x0FFF,
89 
90     /* define all GScan related commands between 0x1000 and 0x10FF */
91     ANDROID_NL80211_SUBCMD_GSCAN_RANGE_START = 0x1000,
92     ANDROID_NL80211_SUBCMD_GSCAN_RANGE_END   = 0x10FF,
93 
94     /* define all NearbyDiscovery related commands between 0x1100 and 0x11FF */
95     ANDROID_NL80211_SUBCMD_NBD_RANGE_START = 0x1100,
96     ANDROID_NL80211_SUBCMD_NBD_RANGE_END   = 0x11FF,
97 
98     /* define all RTT related commands between 0x1100 and 0x11FF */
99     ANDROID_NL80211_SUBCMD_RTT_RANGE_START = 0x1100,
100     ANDROID_NL80211_SUBCMD_RTT_RANGE_END   = 0x11FF,
101 
102     ANDROID_NL80211_SUBCMD_LSTATS_RANGE_START = 0x1200,
103     ANDROID_NL80211_SUBCMD_LSTATS_RANGE_END   = 0x12FF,
104 
105     /* define all Logger related commands between 0x1400 and 0x14FF */
106     ANDROID_NL80211_SUBCMD_DEBUG_RANGE_START = 0x1400,
107     ANDROID_NL80211_SUBCMD_DEBUG_RANGE_END   = 0x14FF,
108 
109     /* define all wifi offload related commands between 0x1600 and 0x16FF */
110     ANDROID_NL80211_SUBCMD_WIFI_OFFLOAD_RANGE_START = 0x1600,
111     ANDROID_NL80211_SUBCMD_WIFI_OFFLOAD_RANGE_END   = 0x16FF,
112 
113     /* define all NAN related commands between 0x1700 and 0x17FF */
114     ANDROID_NL80211_SUBCMD_NAN_RANGE_START = 0x1700,
115     ANDROID_NL80211_SUBCMD_NAN_RANGE_END   = 0x17FF,
116 
117     /* define all Android Packet Filter related commands between 0x1800 and 0x18FF */
118     ANDROID_NL80211_SUBCMD_PKT_FILTER_RANGE_START = 0x1800,
119     ANDROID_NL80211_SUBCMD_PKT_FILTER_RANGE_END   = 0x18FF,
120 
121     /* define all tx power related commands between 0x1900 and 0x1910 */
122     ANDROID_NL80211_SUBCMD_TX_POWER_RANGE_START = 0x1900,
123     ANDROID_NL80211_SUBCMD_TX_POWER_RANGE_END	 = 0x1910,
124 
125     /* define all thermal mode related commands between 0x1920 and 0x192F */
126     ANDROID_NL80211_SUBCMD_MITIGATION_RANGE_START = 0x1920,
127     ANDROID_NL80211_SUBCMD_MITIGATION_RANGE_END   = 0x192F,
128 
129     /* define all DSCP related commands between 0x2000 and 0x20FF */
130     ANDROID_NL80211_SUBCMD_DSCP_RANGE_START =	0x2000,
131     ANDROID_NL80211_SUBCMD_DSCP_RANGE_END   =	0x20FF,
132 
133     /* define all Channel Avoidance related commands between 0x2100 and 0x211F */
134     ANDROID_NL80211_SUBCMD_CHAVOID_RANGE_START =    0x2100,
135     ANDROID_NL80211_SUBCMD_CHAVOID_RANGE_END   =    0x211F,
136 
137     /* define all OTA Download related commands between 0x2120 and 0x212F */
138     ANDROID_NL80211_SUBCMD_OTA_DOWNLOAD_START	= 0x2120,
139     ANDROID_NL80211_SUBCMD_OTA_DOWNLOAD_END	= 0x212F,
140 
141     /* define all VOIP mode config related commands between 0x2130 and 0x213F */
142     ANDROID_NL80211_SUBCMD_VIOP_MODE_START =	    0x2130,
143     ANDROID_NL80211_SUBCMD_VIOP_MODE_END =	    0x213F,
144 
145     /* define all TWT related commands between 0x2140 and 0x214F */
146     ANDROID_NL80211_SUBCMD_TWT_START =              0x2140,
147     ANDROID_NL80211_SUBCMD_TWT_END =                0x214F,
148 
149     /* define all Usable Channel related commands between 0x2150 and 0x215F */
150     ANDROID_NL80211_SUBCMD_USABLE_CHANNEL_START =   0x2150,
151     ANDROID_NL80211_SUBCMD_USABLE_CHANNEL_END =     0x215F,
152 
153     /* define all init/deinit related commands between 0x2160 and 0x216F */
154     ANDROID_NL80211_SUBCMD_INIT_DEINIT_RANGE_START = 0x2160,
155     ANDROID_NL80211_SUBCMD_INIT_DEINIT_RANGE_END   = 0x216F,
156 
157     /* This is reserved for future usage */
158 
159 } ANDROID_VENDOR_SUB_COMMAND;
160 
161 typedef enum {
162 
163     GSCAN_SUBCMD_GET_CAPABILITIES = ANDROID_NL80211_SUBCMD_GSCAN_RANGE_START,
164 
165     GSCAN_SUBCMD_SET_CONFIG,                            /* 0x1001 */
166 
167     GSCAN_SUBCMD_SET_SCAN_CONFIG,                       /* 0x1002 */
168     GSCAN_SUBCMD_ENABLE_GSCAN,                          /* 0x1003 */
169     GSCAN_SUBCMD_GET_SCAN_RESULTS,                      /* 0x1004 */
170     GSCAN_SUBCMD_SCAN_RESULTS,                          /* 0x1005 */
171 
172     GSCAN_SUBCMD_SET_HOTLIST,                           /* 0x1006 */
173 
174     GSCAN_SUBCMD_SET_SIGNIFICANT_CHANGE_CONFIG,         /* 0x1007 */
175     GSCAN_SUBCMD_ENABLE_FULL_SCAN_RESULTS,              /* 0x1008 */
176     GSCAN_SUBCMD_GET_CHANNEL_LIST,                       /* 0x1009 */
177 
178     WIFI_SUBCMD_GET_FEATURE_SET,                         /* 0x100A */
179     WIFI_SUBCMD_GET_FEATURE_SET_MATRIX,                  /* 0x100B */
180     WIFI_SUBCMD_SET_PNO_RANDOM_MAC_OUI,                  /* 0x100C */
181     WIFI_SUBCMD_NODFS_SET,                               /* 0x100D */
182     WIFI_SUBCMD_SET_COUNTRY_CODE,                        /* 0x100E */
183     /* Add more sub commands here */
184     GSCAN_SUBCMD_SET_EPNO_SSID,                          /* 0x100F */
185 
186     WIFI_SUBCMD_SET_SSID_WHITE_LIST,                     /* 0x1010 */
187     WIFI_SUBCMD_SET_ROAM_PARAMS,                         /* 0x1011 */
188     WIFI_SUBCMD_ENABLE_LAZY_ROAM,                        /* 0x1012 */
189     WIFI_SUBCMD_SET_BSSID_PREF,                          /* 0x1013 */
190     WIFI_SUBCMD_SET_BSSID_BLACKLIST,                     /* 0x1014 */
191 
192     GSCAN_SUBCMD_ANQPO_CONFIG,                           /* 0x1015 */
193     WIFI_SUBCMD_SET_RSSI_MONITOR,                        /* 0x1016 */
194     WIFI_SUBCMD_CONFIG_ND_OFFLOAD,                       /* 0x1017 */
195     WIFI_SUBCMD_CONFIG_TCPACK_SUP,                       /* 0x1018 */
196     WIFI_SUBCMD_FW_ROAM_POLICY,                          /* 0x1019 */
197     WIFI_SUBCMD_ROAM_CAPABILITY,                         /* 0x101a */
198     WIFI_SUBCMD_SET_LATENCY_MODE,                        /* 0x101b */
199     WIFI_SUBCMD_SET_MULTISTA_PRIMARY_CONNECTION,         /* 0x101c */
200     WIFI_SUBCMD_SET_MULTISTA_USE_CASE,                   /* 0x101d */
201     WIFI_SUBCMD_SET_DTIM_CONFIG,                         /* 0x101e */
202     WIFI_SUBCMD_CONFIG_INDOOR_STATE,
203 
204     GSCAN_SUBCMD_MAX,
205 
206     /* NAN related */
207     NAN_SUBCMD_ENABLE = ANDROID_NL80211_SUBCMD_NAN_RANGE_START,
208     NAN_SUBCMD_DISABLE,                                 /* 0x1701 */
209     NAN_SUBCMD_PUBLISH,                                 /* 0x1702 */
210     NAN_SUBCMD_SUBSCRIBE,                               /* 0x1703 */
211     NAN_SUBCMD_PUBLISH_CANCEL,                          /* 0x1704 */
212     NAN_SUBCMD_SUBSCRIBE_CANCEL,                        /* 0x1705 */
213     NAN_SUBCMD_TRANSMIT_FOLLOWUP,                       /* 0x1706 */
214     NAN_SUBCMD_CONFIG,                                  /* 0x1707 */
215     NAN_SUBCMD_TCA,                                     /* 0x1708 */
216     NAN_SUBCMD_STATS,                                   /* 0x1709 */
217     NAN_SUBCMD_GET_CAPABILITIES,                        /* 0x170A */
218     NAN_SUBCMD_DATA_PATH_IFACE_CREATE,                  /* 0x170B */
219     NAN_SUBCMD_DATA_PATH_IFACE_DELETE,                  /* 0x170C */
220     NAN_SUBCMD_DATA_PATH_REQUEST,                       /* 0x170D */
221     NAN_SUBCMD_DATA_PATH_RESPONSE,                      /* 0x170E */
222     NAN_SUBCMD_DATA_PATH_END,                           /* 0x170F */
223     NAN_SUBCMD_DATA_PATH_SEC_INFO,                      /* 0x1710 */
224     NAN_SUBCMD_VERSION_INFO,                            /* 0x1711 */
225     NAN_SUBCMD_ENABLE_MERGE,                            /* 0x1712 */
226     APF_SUBCMD_GET_CAPABILITIES = ANDROID_NL80211_SUBCMD_PKT_FILTER_RANGE_START,
227     APF_SUBCMD_SET_FILTER,
228     APF_SUBCMD_READ_FILTER,
229     WIFI_SUBCMD_TX_POWER_SCENARIO = ANDROID_NL80211_SUBCMD_TX_POWER_RANGE_START,
230     WIFI_SUBCMD_THERMAL_MITIGATION = ANDROID_NL80211_SUBCMD_MITIGATION_RANGE_START,
231     DSCP_SUBCMD_SET_TABLE = ANDROID_NL80211_SUBCMD_DSCP_RANGE_START,
232     DSCP_SUBCMD_RESET_TABLE,			    	/* 0x2001 */
233     CHAVOID_SUBCMD_SET_CONFIG = ANDROID_NL80211_SUBCMD_CHAVOID_RANGE_START,
234 
235     TWT_SUBCMD_GETCAPABILITY	= ANDROID_NL80211_SUBCMD_TWT_START,
236     TWT_SUBCMD_SETUP_REQUEST,
237     TWT_SUBCMD_TEAR_DOWN_REQUEST,
238     TWT_SUBCMD_INFO_FRAME_REQUEST,
239     TWT_SUBCMD_GETSTATS,
240     TWT_SUBCMD_CLR_STATS,
241 
242     WIFI_SUBCMD_CONFIG_VOIP_MODE = ANDROID_NL80211_SUBCMD_VIOP_MODE_START,
243 
244     WIFI_SUBCMD_GET_OTA_CURRUNT_INFO = ANDROID_NL80211_SUBCMD_OTA_DOWNLOAD_START,
245     WIFI_SUBCMD_OTA_UPDATE,
246     WIFI_SUBCMD_USABLE_CHANNEL = ANDROID_NL80211_SUBCMD_USABLE_CHANNEL_START,
247     WIFI_SUBCMD_TRIGGER_SSR = ANDROID_NL80211_SUBCMD_INIT_DEINIT_RANGE_START,
248     WIFI_SUBCMD_GET_RADIO_COMBO_MATRIX,
249 } WIFI_SUB_COMMAND;
250 
251 typedef enum {
252     BRCM_RESERVED1				= 0,
253     BRCM_RESERVED2				= 1,
254     GSCAN_EVENT_SIGNIFICANT_CHANGE_RESULTS	= 2,
255     GSCAN_EVENT_HOTLIST_RESULTS_FOUND		= 3,
256     GSCAN_EVENT_SCAN_RESULTS_AVAILABLE		= 4,
257     GSCAN_EVENT_FULL_SCAN_RESULTS		= 5,
258     RTT_EVENT_COMPLETE				= 6,
259     GSCAN_EVENT_COMPLETE_SCAN			= 7,
260     GSCAN_EVENT_HOTLIST_RESULTS_LOST		= 8,
261     GSCAN_EVENT_EPNO_EVENT			= 9,
262     GOOGLE_DEBUG_RING_EVENT			= 10,
263     GOOGLE_DEBUG_MEM_DUMP_EVENT			= 11,
264     GSCAN_EVENT_ANQPO_HOTSPOT_MATCH		= 12,
265     GOOGLE_RSSI_MONITOR_EVENT			= 13,
266     GOOGLE_MKEEP_ALIVE				= 14,
267 
268     /*
269      * BRCM specific events should be placed after the Generic events
270      * in order to match between the DHD and HAL
271      */
272     NAN_EVENT_ENABLED				= 15,
273     NAN_EVENT_DISABLED				= 16,
274     NAN_EVENT_SUBSCRIBE_MATCH			= 17,
275     NAN_EVENT_PUBLISH_REPLIED_IND		= 18,
276     NAN_EVENT_PUBLISH_TERMINATED		= 19,
277     NAN_EVENT_SUBSCRIBE_TERMINATED		= 20,
278     NAN_EVENT_DE_EVENT				= 21,
279     NAN_EVENT_FOLLOWUP				= 22,
280     NAN_EVENT_TRANSMIT_FOLLOWUP_IND		= 23,
281     NAN_EVENT_DATA_REQUEST			= 24,
282     NAN_EVENT_DATA_CONFIRMATION			= 25,
283     NAN_EVENT_DATA_END				= 26,
284     NAN_EVENT_BEACON				= 27,
285     NAN_EVENT_SDF				= 28,
286     NAN_EVENT_TCA				= 29,
287     NAN_EVENT_SUBSCRIBE_UNMATCH			= 30,
288     NAN_EVENT_UNKNOWN				= 31,
289     BRCM_VENDOR_EVENT_HANGED			= 33,
290     ROAM_EVENT_START,
291     GOOGLE_FILE_DUMP_EVENT			= 37,
292     NAN_ASYNC_RESPONSE_DISABLED			= 40,
293     BRCM_VENDOR_EVENT_TWT			= 43,
294     BRCM_TPUT_DUMP_EVENT			= 44,
295     NAN_EVENT_MATCH_EXPIRY			= 45
296 } WIFI_EVENT;
297 
298 typedef void (*wifi_internal_event_handler) (wifi_handle handle, int events);
299 
300 class WifiCommand;
301 
302 typedef struct {
303     int nl_cmd;
304     uint32_t vendor_id;
305     int vendor_subcmd;
306     nl_recvmsg_msg_cb_t cb_func;
307     void *cb_arg;
308 } cb_info;
309 
310 typedef struct {
311     wifi_request_id id;
312     WifiCommand *cmd;
313 } cmd_info;
314 
315 typedef struct {
316     wifi_handle handle;                             // handle to wifi data
317     char name[IFNAMSIZ+1];                          // interface name + trailing null
318     int  id;                                        // id to use when talking to driver
319     bool is_virtual;                                // mark each iface as virtual or static
320 } interface_info;
321 
322 typedef struct {
323 
324     struct nl_sock *cmd_sock;                       // command socket object
325     struct nl_sock *event_sock;                     // event socket object
326     int nl80211_family_id;                          // family id for 80211 driver
327     int cleanup_socks[2];                           // sockets used to implement wifi_cleanup
328 
329     bool in_event_loop;                             // Indicates that event loop is active
330     bool clean_up;                                  // Indication to exit since cleanup has started
331 
332     wifi_internal_event_handler event_handler;      // default event handler
333     wifi_cleaned_up_handler cleaned_up_handler;     // socket cleaned up handler
334 
335     cb_info *event_cb;                              // event callbacks
336     int num_event_cb;                               // number of event callbacks
337     int alloc_event_cb;                             // number of allocated callback objects
338     pthread_mutex_t cb_lock;                        // mutex for the event_cb access
339 
340     cmd_info *cmd;                                  // Outstanding commands
341     int num_cmd;                                    // number of commands
342     int alloc_cmd;                                  // number of commands allocated
343 
344     interface_info **interfaces;                    // array of interfaces
345     int num_interfaces;                             // number of interfaces
346     int max_num_interfaces;                         // max number of interfaces
347     wifi_subsystem_restart_handler restart_handler; // trigger sub system handler
348 
349 
350     // add other details
351 } hal_info;
352 
353 #define PNO_SSID_FOUND  0x1
354 #define PNO_SSID_LOST    0x2
355 
356 typedef struct wifi_pno_result {
357     unsigned char ssid[DOT11_MAX_SSID_LEN];
358     unsigned char ssid_len;
359     signed char rssi;
360     u16 channel;
361     u16 flags;
362     mac_addr  bssid;
363 } wifi_pno_result_t;
364 
365 typedef struct wifi_gscan_result {
366     u64 ts;                           // Time of discovery
367     u8 ssid[DOT11_MAX_SSID_LEN+1];    // null terminated
368     mac_addr bssid;                   // BSSID
369     u32 channel;                      // channel frequency in MHz
370     s32 rssi;                         // in db
371     u64 rtt;                          // in nanoseconds
372     u64 rtt_sd;                       // standard deviation in rtt
373     u16 beacon_period;                // units are Kusec
374     u16 capability;                   // Capability information
375     u32 pad;
376 } wifi_gscan_result_t;
377 
378 typedef struct wifi_gscan_full_result {
379     wifi_gscan_result_t fixed;
380     u32 scan_ch_bucket;              // scan chbucket bitmask
381     u32 ie_length;                   // byte length of Information Elements
382     u8  ie_data[1];                  // IE data to follow
383 } wifi_gscan_full_result_t;
384 
385 void twt_deinit_handler();
386 
387 typedef enum {
388     TWT_EVENT_INVALID          = 0,
389     TWT_SETUP_RESPONSE         = 1,
390     TWT_TEARDOWN_COMPLETION    = 2,
391     TWT_INFORM_FRAME           = 3,
392     TWT_NOTIFY                 = 4,
393     TWT_EVENT_LAST
394 } TwtEventType;
395 
396 typedef enum {
397     TWT_INVALID			= 0,
398     TWT_SETUP_REQUEST		= 1,
399     TWT_INFO_FRAME_REQUEST	= 2,
400     TWT_TEAR_DOWN_REQUEST	= 3,
401     TWT_LAST
402 } TwtRequestType;
403 
404 typedef enum {
405     TWT_ATTRIBUTE_INVALID		= 0,
406     TWT_ATTRIBUTE_CONFIG_ID		= 1,
407     TWT_ATTRIBUTE_NEG_TYPE		= 2,
408     TWT_ATTRIBUTE_TRIGGER_TYPE		= 3,
409     TWT_ATTRIBUTE_WAKE_DUR_US		= 4,
410     TWT_ATTRIBUTE_WAKE_INT_US		= 5,
411     TWT_ATTRIBUTE_WAKE_INT_MIN_US	= 6,
412     TWT_ATTRIBUTE_WAKE_INT_MAX_US	= 7,
413     TWT_ATTRIBUTE_WAKE_DUR_MIN_US	= 8,
414     TWT_ATTRIBUTE_WAKE_DUR_MAX_US	= 9,
415     TWT_ATTRIBUTE_AVG_PKT_SIZE		= 10,
416     TWT_ATTRIBUTE_AVG_PKT_NUM		= 11,
417     TWT_ATTRIBUTE_WAKE_TIME_OFF_US	= 12,
418     TWT_ATTRIBUTE_ALL_TWT		= 13,
419     TWT_ATTRIBUTE_RESUME_TIME_US	= 14,
420     TWT_ATTRIBUTE_AVG_EOSP_DUR		= 15,
421     TWT_ATTRIBUTE_EOSP_COUNT		= 16,
422     TWT_ATTRIBUTE_NUM_SP		= 17,
423     TWT_ATTRIBUTE_DEVICE_CAP		= 18,
424     TWT_ATTRIBUTE_PEER_CAP		= 19,
425     TWT_ATTRIBUTE_STATUS		= 20,
426     TWT_ATTRIBUTE_REASON_CODE		= 21,
427     TWT_ATTRIBUTE_RESUMED		= 22,
428     TWT_ATTRIBUTE_NOTIFICATION		= 23,
429     TWT_ATTRIBUTE_SUB_EVENT		= 24,
430     TWT_ATTRIBUTE_NUM_PEER_STATS	= 25,
431     TWT_ATTRIBUTE_AVG_PKT_NUM_TX	= 26,
432     TWT_ATTRIBUTE_AVG_PKT_SIZE_TX	= 27,
433     TWT_ATTRIBUTE_AVG_PKT_NUM_RX	= 28,
434     TWT_ATTRIBUTE_AVG_PKT_SIZE_RX	= 29,
435     TWT_ATTRIBUTE_MAX
436 } TWT_ATTRIBUTE;
437 
438 wifi_error wifi_register_handler(wifi_handle handle, int cmd, nl_recvmsg_msg_cb_t func, void *arg);
439 wifi_error wifi_register_vendor_handler(wifi_handle handle,
440             uint32_t id, int subcmd, nl_recvmsg_msg_cb_t func, void *arg);
441 
442 void wifi_unregister_handler(wifi_handle handle, int cmd);
443 void wifi_unregister_vendor_handler_without_lock(wifi_handle handle, uint32_t id, int subcmd);
444 void wifi_unregister_vendor_handler(wifi_handle handle, uint32_t id, int subcmd);
445 
446 wifi_error wifi_register_cmd(wifi_handle handle, int id, WifiCommand *cmd);
447 WifiCommand *wifi_unregister_cmd(wifi_handle handle, int id);
448 WifiCommand *wifi_get_cmd(wifi_handle handle, int id);
449 void wifi_unregister_cmd(wifi_handle handle, WifiCommand *cmd);
450 
451 interface_info *getIfaceInfo(wifi_interface_handle);
452 wifi_handle getWifiHandle(wifi_interface_handle handle);
453 hal_info *getHalInfo(wifi_handle handle);
454 hal_info *getHalInfo(wifi_interface_handle handle);
455 wifi_handle getWifiHandle(hal_info *info);
456 wifi_interface_handle getIfaceHandle(interface_info *info);
457 wifi_error wifi_cancel_cmd(wifi_request_id id, wifi_interface_handle iface);
458 wifi_error wifi_get_cancel_cmd(wifi_request_id id, wifi_interface_handle iface);
459 wifi_error nan_deinit_handler();
460 wifi_error wifi_start_hal(wifi_interface_handle iface);
461 wifi_error wifi_stop_hal(wifi_interface_handle iface);
462 wifi_interface_handle wifi_get_wlan_interface(wifi_handle info,
463 	    wifi_interface_handle *ifaceHandles, int numIfaceHandles);
464 #ifdef RING_DUMP
465 wifi_error wifi_start_ring_dump(wifi_interface_handle iface,
466             wifi_ring_buffer_data_handler ring_handle);
467 wifi_error wifi_stop_ring_dump(wifi_interface_handle iface);
468 #endif /* RING_DUMP */
469 wifi_error wifi_hal_ota_update(wifi_interface_handle iface, uint32_t ota_version);
470 wifi_error wifi_hal_preInit(wifi_interface_handle iface);
471 /* API to get wake reason statistics */
472 wifi_error wifi_get_wake_reason_stats(wifi_interface_handle handle,
473         WLAN_DRIVER_WAKE_REASON_CNT *wifi_wake_reason_cnt);
474 wifi_error wifi_virtual_interface_create(wifi_handle handle, const char* ifname,
475         wifi_interface_type iface_type);
476 wifi_error wifi_virtual_interface_delete(wifi_handle handle, const char* ifname);
477 wifi_error wifi_set_coex_unsafe_channels(wifi_handle handle, u32 num_channels,
478                                          wifi_coex_unsafe_channel channels[], u32 restrictions);
479 wifi_error wifi_set_voip_mode(wifi_interface_handle handle, wifi_voip_mode mode);
480 wifi_error wifi_set_dtim_config(wifi_interface_handle handle, u32 multiplier);
481 void set_hautil_mode(bool halutil_mode);
482 bool get_halutil_mode();
483 
484 /* API's to support TWT */
485 
486 /**@brief twt_get_capability
487  *        Request TWT capability
488  * @param wifi_interface_handle:
489  * @return Synchronous wifi_error and TwtCapabilitySet
490  */
491 wifi_error twt_get_capability(wifi_interface_handle iface, TwtCapabilitySet* twt_cap_set);
492 
493 /**@brief twt_register_handler
494  *        Request to register TWT callback
495  * @param wifi_interface_handle:
496  * @param TwtCallbackHandler:
497  * @return Synchronous wifi_error
498  */
499 wifi_error twt_register_handler(wifi_interface_handle iface, TwtCallbackHandler handler);
500 
501 /**@brief twt_setup_request
502  *        Request to send TWT setup frame
503  * @param wifi_interface_handle:
504  * @param TwtSetupRequest:
505  * @return Synchronous wifi_error
506  * @return Asynchronous EventTwtSetupResponse CB return TwtSetupResponse
507  */
508 wifi_error twt_setup_request(wifi_interface_handle iface, TwtSetupRequest* msg);
509 
510 /**@brief twt_teardown_request
511  *        Request to send TWT teardown frame
512  * @param wifi_interface_handle:
513  * @param TwtTeardownRequest:
514  * @return Synchronous wifi_error
515  * @return Asynchronous EventTwtTeardownCompletion CB return TwtTeardownCompletion
516  * TwtTeardownCompletion may also be received due to other events
517  * like CSA, BTCX, TWT scheduler, MultiConnection, peer-initiated teardown, etc.
518  */
519 wifi_error twt_teardown_request(wifi_interface_handle iface, TwtTeardownRequest* msg);
520 
521 /**@brief twt_info_frame_request
522  *        Request to send TWT info frame
523  * @param wifi_interface_handle:
524  * @param TwtInfoFrameRequest:
525  * @return Synchronous wifi_error
526  * @return Asynchronous EventTwtInfoFrameReceived CB return TwtInfoFrameReceived
527  * Driver may also receive Peer-initiated TwtInfoFrame
528  */
529 wifi_error twt_info_frame_request(wifi_interface_handle iface, TwtInfoFrameRequest* msg);
530 
531 /**@brief twt_get_stats
532  *        Request to get TWT stats
533  * @param wifi_interface_handle:
534  * @param config_id:
535  * @return Synchronous wifi_error and TwtStats
536  */
537 wifi_error twt_get_stats(wifi_interface_handle iface, u8 config_id, TwtStats* stats);
538 
539 /**@brief twt_clear_stats
540  *        Request to clear TWT stats
541  * @param wifi_interface_handle:
542  * @param config_id:
543  * @return Synchronous wifi_error
544  */
545 wifi_error twt_clear_stats(wifi_interface_handle iface, u8 config_id);
546 
547 wifi_error wifi_trigger_subsystem_restart(wifi_handle handle);
548 // some common macros
549 
550 #define min(x, y)       ((x) < (y) ? (x) : (y))
551 #define max(x, y)       ((x) > (y) ? (x) : (y))
552 
553 #define NULL_CHECK_RETURN(ptr, str, ret) \
554     do { \
555         if (!(ptr)) { \
556             ALOGE("%s(): null pointer - #ptr (%s)\n", __FUNCTION__, str); \
557             return ret; \
558         } \
559     } while (0)
560 
561 #endif
562 
563