4 #ifndef __WIFI_HAL_COMMON_H__
5 #define __WIFI_HAL_COMMON_H__
7 #define LOG_TAG "WifiHAL"
10 #include "nl80211_copy.h"
13 #define SOCKET_BUFFER_SIZE (32768U)
14 #define RECV_BUF_SIZE (4096)
15 #define DEFAULT_EVENT_CB_SIZE (64)
16 #define DEFAULT_CMD_SIZE (64)
17 #define DOT11_OUI_LEN 3
18 #define DOT11_MAX_SSID_LEN 32
20 #define MAX_PROBE_RESP_IE_LEN 2048
22 Vendor OUI - This is a unique identifier that identifies organization. Lets
23 code Android specific functions with Google OUI; although vendors can do more
24 with their own OUI's as well.
27 const uint32_t GOOGLE_OUI
= 0x001A11;
28 /* TODO: define vendor OUI here */
31 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
32 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
36 This enum defines ranges for various commands; commands themselves
37 can be defined in respective feature headers; i.e. find gscan command
38 definitions in gscan.cpp
42 /* Don't use 0 as a valid subcommand */
43 ANDROID_NL80211_SUBCMD_UNSPECIFIED
,
45 /* Define all vendor startup commands between 0x0 and 0x0FFF */
46 ANDROID_NL80211_SUBCMD_WIFI_RANGE_START
= 0x0001,
47 ANDROID_NL80211_SUBCMD_WIFI_RANGE_END
= 0x0FFF,
49 /* Define all GScan related commands between 0x1000 and 0x10FF */
50 ANDROID_NL80211_SUBCMD_GSCAN_RANGE_START
= 0x1000,
51 ANDROID_NL80211_SUBCMD_GSCAN_RANGE_END
= 0x10FF,
53 /* Define all RTT related commands between 0x1100 and 0x11FF */
54 ANDROID_NL80211_SUBCMD_RTT_RANGE_START
= 0x1100,
55 ANDROID_NL80211_SUBCMD_RTT_RANGE_END
= 0x11FF,
57 ANDROID_NL80211_SUBCMD_LSTATS_RANGE_START
= 0x1200,
58 ANDROID_NL80211_SUBCMD_LSTATS_RANGE_END
= 0x12FF,
60 /* Define all Logger related commands between 0x1400 and 0x14FF */
61 ANDROID_NL80211_SUBCMD_DEBUG_RANGE_START
= 0x1400,
62 ANDROID_NL80211_SUBCMD_DEBUG_RANGE_END
= 0x14FF,
64 /* Define all wifi offload related commands between 0x1600 and 0x16FF */
65 ANDROID_NL80211_SUBCMD_WIFI_OFFLOAD_RANGE_START
= 0x1600,
66 ANDROID_NL80211_SUBCMD_WIFI_OFFLOAD_RANGE_END
= 0x16FF,
68 /* This is reserved for future usage */
70 } ANDROID_VENDOR_SUB_COMMAND
;
73 WIFI_SUBCMD_GET_CHANNEL_LIST
= ANDROID_NL80211_SUBCMD_WIFI_RANGE_START
,
75 WIFI_SUBCMD_GET_FEATURE_SET
, /* 0x0002 */
76 WIFI_SUBCMD_GET_FEATURE_SET_MATRIX
, /* 0x0003 */
77 WIFI_SUBCMD_SET_PNO_RANDOM_MAC_OUI
, /* 0x0004 */
78 WIFI_SUBCMD_NODFS_SET
, /* 0x0005 */
79 WIFI_SUBCMD_SET_COUNTRY_CODE
, /* 0x0006 */
81 WIFI_SUBCMD_SET_RSSI_MONITOR
, /* 0x0007 */
82 /* Add more sub commands here */
86 GSCAN_SUBCMD_GET_CAPABILITIES
= ANDROID_NL80211_SUBCMD_GSCAN_RANGE_START
,
88 GSCAN_SUBCMD_SET_CONFIG
, /* 0x1001 */
89 GSCAN_SUBCMD_SET_SCAN_CONFIG
, /* 0x1002 */
90 GSCAN_SUBCMD_ENABLE_GSCAN
, /* 0x1003 */
91 GSCAN_SUBCMD_GET_SCAN_RESULTS
, /* 0x1004 */
92 GSCAN_SUBCMD_SCAN_RESULTS
, /* 0x1005 */
94 GSCAN_SUBCMD_SET_HOTLIST
, /* 0x1006 */
96 GSCAN_SUBCMD_SET_SIGNIFICANT_CHANGE_CONFIG
, /* 0x1007 */
97 GSCAN_SUBCMD_ENABLE_FULL_SCAN_RESULTS
, /* 0x1008 */
99 GSCAN_SUBCMD_SET_EPNO_SSID
= 0x100F, /* 0x100F */
101 GSCAN_SUBCMD_SET_SSID_WHITE_LIST
, /* 0x1010 */
102 GSCAN_SUBCMD_SET_ROAM_PARAMS
, /* 0x1011 */
103 GSCAN_SUBCMD_ENABLE_LAZY_ROAM
, /* 0x1012 */
104 GSCAN_SUBCMD_SET_BSSID_PREF
, /* 0x1013 */
105 GSCAN_SUBCMD_SET_BSSID_BLACKLIST
, /* 0x1014 */
107 GSCAN_SUBCMD_ANQPO_CONFIG
, /* 0x1015 */
108 /* Add more sub commands here */
113 WIFI_ATTRIBUTE_BAND
= 1,
114 WIFI_ATTRIBUTE_NUM_CHANNELS
,
115 WIFI_ATTRIBUTE_CHANNEL_LIST
,
117 WIFI_ATTRIBUTE_NUM_FEATURE_SET
,
118 WIFI_ATTRIBUTE_FEATURE_SET
,
119 WIFI_ATTRIBUTE_PNO_RANDOM_MAC_OUI
,
120 WIFI_ATTRIBUTE_NODFS_VALUE
,
121 WIFI_ATTRIBUTE_COUNTRY_CODE
,
123 WIFI_ATTRIBUTE_MAX_RSSI
,
124 WIFI_ATTRIBUTE_MIN_RSSI
,
125 WIFI_ATTRIBUTE_RSSI_MONITOR_START
,
129 GSCAN_EVENT_SIGNIFICANT_CHANGE_RESULTS
,
130 GSCAN_EVENT_HOTLIST_RESULTS_FOUND
,
131 GSCAN_EVENT_SCAN_RESULTS_AVAILABLE
,
132 GSCAN_EVENT_FULL_SCAN_RESULTS
,
134 GSCAN_EVENT_COMPLETE_SCAN
,
135 GSCAN_EVENT_HOTLIST_RESULTS_LOST
,
136 WIFI_EVENT_RSSI_MONITOR
,
137 GSCAN_EVENT_EPNO_EVENT
,
138 GSCAN_EVENT_ANQPO_HOTSPOT_MATCH
,
141 typedef void (*wifi_internal_event_handler
) (wifi_handle handle
, int events
);
149 nl_recvmsg_msg_cb_t cb_func
;
159 wifi_handle handle
; // handle to wifi data
160 char name
[8+1]; // interface name + trailing null
161 int id
; // id to use when talking to driver
166 struct nl_sock
*cmd_sock
; // command socket object
167 struct nl_sock
*event_sock
; // event socket object
168 int nl80211_family_id
; // family id for 80211 driver
169 int cleanup_socks
[2]; // sockets used to implement wifi_cleanup
171 bool in_event_loop
; // Indicates that event loop is active
172 bool clean_up
; // Indication to exit since cleanup has started
174 wifi_internal_event_handler event_handler
; // default event handler
175 wifi_cleaned_up_handler cleaned_up_handler
; // socket cleaned up handler
177 cb_info
*event_cb
; // event callbacks
178 int num_event_cb
; // number of event callbacks
179 int alloc_event_cb
; // number of allocated callback objects
180 pthread_mutex_t cb_lock
; // mutex for the event_cb access
182 cmd_info
*cmd
; // Outstanding commands
183 int num_cmd
; // number of commands
184 int alloc_cmd
; // number of commands allocated
186 interface_info
**interfaces
; // array of interfaces
187 int num_interfaces
; // number of interfaces
193 #define PNO_SSID_FOUND 0x1
194 #define PNO_SSID_LOST 0x2
196 typedef struct wifi_pno_result
{
197 unsigned char ssid
[DOT11_MAX_SSID_LEN
];
198 unsigned char ssid_len
;
205 typedef struct wifi_gscan_result
{
206 u64 ts
; // Time of discovery
207 u8 ssid
[DOT11_MAX_SSID_LEN
+1]; // null terminated
208 mac_addr bssid
; // BSSID
209 u32 channel
; // channel frequency in MHz
211 u64 rtt
; // in nanoseconds
212 u64 rtt_sd
; // standard deviation in rtt
213 u16 beacon_period
; // units are Kusec
214 u16 capability
; // Capability information
217 } wifi_gscan_result_t
;
219 typedef struct wifi_gscan_full_result
{
220 wifi_gscan_result_t fixed
;
221 u32 scan_ch_bucket
; // scan chbucket bitmask
222 u32 ie_length
; // byte length of Information Elements
223 u8 ie_data
[1]; // IE data to follow
224 } wifi_gscan_full_result_t
;
226 wifi_error
wifi_register_handler(wifi_handle handle
, int cmd
, nl_recvmsg_msg_cb_t func
, void *arg
);
227 wifi_error
wifi_register_vendor_handler(wifi_handle handle
,
228 uint32_t id
, int subcmd
, nl_recvmsg_msg_cb_t func
, void *arg
);
230 void wifi_unregister_handler(wifi_handle handle
, int cmd
);
231 void wifi_unregister_vendor_handler(wifi_handle handle
, uint32_t id
, int subcmd
);
233 wifi_error
wifi_register_cmd(wifi_handle handle
, int id
, WifiCommand
*cmd
);
234 WifiCommand
*wifi_unregister_cmd(wifi_handle handle
, int id
);
235 WifiCommand
*wifi_get_cmd(wifi_handle handle
, int id
);
236 void wifi_unregister_cmd(wifi_handle handle
, WifiCommand
*cmd
);
238 interface_info
*getIfaceInfo(wifi_interface_handle
);
239 wifi_handle
getWifiHandle(wifi_interface_handle handle
);
240 hal_info
*getHalInfo(wifi_handle handle
);
241 hal_info
*getHalInfo(wifi_interface_handle handle
);
242 wifi_handle
getWifiHandle(hal_info
*info
);
243 wifi_interface_handle
getIfaceHandle(interface_info
*info
);
244 wifi_error
wifi_cancel_cmd(wifi_request_id id
, wifi_interface_handle iface
);
246 // some common macros
248 #define min(x, y) ((x) < (y) ? (x) : (y))
249 #define max(x, y) ((x) > (y) ? (x) : (y))
251 #define NULL_CHECK_RETURN(ptr, str, ret) \
254 ALOGE("%s(): null pointer - #ptr (%s)\n", __FUNCTION__, str); \