Commit | Line | Data |
---|---|---|
7753f181 DD |
1 | |
2 | #include "wifi_hal.h" | |
3 | ||
4 | #ifndef __WIFI_HAL_COMMON_H__ | |
5 | #define __WIFI_HAL_COMMON_H__ | |
6 | ||
7 | #define LOG_TAG "WifiHAL" | |
8 | ||
9 | #include <utils/Log.h> | |
10 | #include "nl80211_copy.h" | |
11 | #include "sync.h" | |
12 | ||
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 | ||
02b2b8ab S |
19 | typedef struct { |
20 | int num_bssid; | |
21 | mac_addr bssids[MAX_BLACKLIST_BSSID]; | |
22 | } wifi_bssid_params; | |
23 | ||
7753f181 DD |
24 | /* |
25 | Vendor OUI - This is a unique identifier that identifies organization. Lets | |
26 | code Android specific functions with Google OUI; although vendors can do more | |
27 | with their own OUI's as well. | |
28 | */ | |
29 | ||
30 | const uint32_t GOOGLE_OUI = 0x001A11; | |
31 | /* TODO: define vendor OUI here */ | |
32 | ||
02b2b8ab S |
33 | typedef enum { |
34 | ||
35 | GSCAN_ATTRIBUTE_NUM_BUCKETS = 10, | |
36 | GSCAN_ATTRIBUTE_BASE_PERIOD, | |
37 | GSCAN_ATTRIBUTE_BUCKETS_BAND, | |
38 | GSCAN_ATTRIBUTE_BUCKET_ID, | |
39 | GSCAN_ATTRIBUTE_BUCKET_PERIOD, | |
40 | GSCAN_ATTRIBUTE_BUCKET_NUM_CHANNELS, | |
41 | GSCAN_ATTRIBUTE_BUCKET_CHANNELS, | |
42 | GSCAN_ATTRIBUTE_NUM_AP_PER_SCAN, | |
43 | GSCAN_ATTRIBUTE_REPORT_THRESHOLD, | |
44 | GSCAN_ATTRIBUTE_NUM_SCANS_TO_CACHE, | |
45 | GSCAN_ATTRIBUTE_REPORT_THRESHOLD_NUM_SCANS, | |
46 | GSCAN_ATTRIBUTE_BAND = GSCAN_ATTRIBUTE_BUCKETS_BAND, | |
47 | ||
48 | GSCAN_ATTRIBUTE_ENABLE_FEATURE = 20, | |
49 | GSCAN_ATTRIBUTE_SCAN_RESULTS_COMPLETE, /* indicates no more results */ | |
50 | GSCAN_ATTRIBUTE_REPORT_EVENTS, | |
51 | ||
52 | /* remaining reserved for additional attributes */ | |
53 | GSCAN_ATTRIBUTE_NUM_OF_RESULTS = 30, | |
54 | GSCAN_ATTRIBUTE_SCAN_RESULTS, /* flat array of wifi_scan_result */ | |
55 | GSCAN_ATTRIBUTE_NUM_CHANNELS, | |
56 | GSCAN_ATTRIBUTE_CHANNEL_LIST, | |
57 | GSCAN_ATTRIBUTE_SCAN_ID, | |
58 | GSCAN_ATTRIBUTE_SCAN_FLAGS, | |
59 | GSCAN_ATTRIBUTE_SCAN_BUCKET_BIT, | |
60 | ||
61 | /* remaining reserved for additional attributes */ | |
62 | ||
63 | GSCAN_ATTRIBUTE_SSID = 40, | |
64 | GSCAN_ATTRIBUTE_BSSID, | |
65 | GSCAN_ATTRIBUTE_CHANNEL, | |
66 | GSCAN_ATTRIBUTE_RSSI, | |
67 | GSCAN_ATTRIBUTE_TIMESTAMP, | |
68 | GSCAN_ATTRIBUTE_RTT, | |
69 | GSCAN_ATTRIBUTE_RTTSD, | |
70 | ||
71 | /* remaining reserved for additional attributes */ | |
72 | ||
73 | GSCAN_ATTRIBUTE_HOTLIST_BSSIDS = 50, | |
74 | GSCAN_ATTRIBUTE_RSSI_LOW, | |
75 | GSCAN_ATTRIBUTE_RSSI_HIGH, | |
76 | GSCAN_ATTRIBUTE_HOTLIST_ELEM, | |
77 | GSCAN_ATTRIBUTE_HOTLIST_FLUSH, | |
78 | GSCAN_ATTRIBUTE_CHANNEL_NUMBER, | |
79 | ||
80 | /* remaining reserved for additional attributes */ | |
81 | GSCAN_ATTRIBUTE_RSSI_SAMPLE_SIZE = 60, | |
82 | GSCAN_ATTRIBUTE_LOST_AP_SAMPLE_SIZE, | |
83 | GSCAN_ATTRIBUTE_MIN_BREACHING, | |
84 | GSCAN_ATTRIBUTE_SIGNIFICANT_CHANGE_BSSIDS, | |
85 | ||
86 | GSCAN_ATTRIBUTE_BUCKET_STEP_COUNT = 70, | |
87 | GSCAN_ATTRIBUTE_BUCKET_EXPONENT, | |
88 | GSCAN_ATTRIBUTE_BUCKET_MAX_PERIOD, | |
89 | ||
90 | GSCAN_ATTRIBUTE_NUM_BSSID, | |
91 | GSCAN_ATTRIBUTE_BLACKLIST_BSSID, | |
92 | ||
93 | GSCAN_ATTRIBUTE_MAX | |
94 | ||
95 | } GSCAN_ATTRIBUTE; | |
7753f181 DD |
96 | |
97 | /* | |
98 | This enum defines ranges for various commands; commands themselves | |
99 | can be defined in respective feature headers; i.e. find gscan command | |
100 | definitions in gscan.cpp | |
101 | */ | |
102 | ||
103 | typedef enum { | |
104 | /* don't use 0 as a valid subcommand */ | |
105 | VENDOR_NL80211_SUBCMD_UNSPECIFIED, | |
106 | ||
107 | /* define all vendor startup commands between 0x0 and 0x0FFF */ | |
108 | VENDOR_NL80211_SUBCMD_RANGE_START = 0x0001, | |
109 | VENDOR_NL80211_SUBCMD_RANGE_END = 0x0FFF, | |
110 | ||
111 | /* define all GScan related commands between 0x1000 and 0x10FF */ | |
112 | ANDROID_NL80211_SUBCMD_GSCAN_RANGE_START = 0x1000, | |
113 | ANDROID_NL80211_SUBCMD_GSCAN_RANGE_END = 0x10FF, | |
114 | ||
115 | /* define all NearbyDiscovery related commands between 0x1100 and 0x11FF */ | |
116 | ANDROID_NL80211_SUBCMD_NBD_RANGE_START = 0x1100, | |
117 | ANDROID_NL80211_SUBCMD_NBD_RANGE_END = 0x11FF, | |
118 | ||
119 | /* define all RTT related commands between 0x1100 and 0x11FF */ | |
120 | ANDROID_NL80211_SUBCMD_RTT_RANGE_START = 0x1100, | |
121 | ANDROID_NL80211_SUBCMD_RTT_RANGE_END = 0x11FF, | |
122 | ||
123 | ANDROID_NL80211_SUBCMD_LSTATS_RANGE_START = 0x1200, | |
124 | ANDROID_NL80211_SUBCMD_LSTATS_RANGE_END = 0x12FF, | |
125 | ||
cdc775c7 HG |
126 | /* define all Logger related commands between 0x1400 and 0x14FF */ |
127 | ANDROID_NL80211_SUBCMD_DEBUG_RANGE_START = 0x1400, | |
128 | ANDROID_NL80211_SUBCMD_DEBUG_RANGE_END = 0x14FF, | |
129 | ||
3c0c6ab1 PG |
130 | /* define all wifi offload related commands between 0x1400 and 0x14FF */ |
131 | ANDROID_NL80211_SUBCMD_WIFI_OFFLOAD_RANGE_START = 0x1400, | |
132 | ANDROID_NL80211_SUBCMD_WIFI_OFFLOAD_RANGE_END = 0x14FF, | |
133 | ||
134 | /* This is reserved for future usage */ | |
7753f181 DD |
135 | |
136 | } ANDROID_VENDOR_SUB_COMMAND; | |
137 | ||
138 | typedef enum { | |
139 | SLSI_NL80211_VENDOR_SUBCMD_GET_CAPABILITIES = ANDROID_NL80211_SUBCMD_GSCAN_RANGE_START, | |
140 | SLSI_NL80211_VENDOR_SUBCMD_GET_VALID_CHANNELS, | |
141 | SLSI_NL80211_VENDOR_SUBCMD_ADD_GSCAN, | |
142 | SLSI_NL80211_VENDOR_SUBCMD_DEL_GSCAN, | |
143 | SLSI_NL80211_VENDOR_SUBCMD_GET_SCAN_RESULTS, | |
144 | SLSI_NL80211_VENDOR_SUBCMD_SET_BSSID_HOTLIST, | |
145 | SLSI_NL80211_VENDOR_SUBCMD_RESET_BSSID_HOTLIST, | |
146 | SLSI_NL80211_VENDOR_SUBCMD_GET_HOTLIST_RESULTS, | |
147 | SLSI_NL80211_VENDOR_SUBCMD_SET_SIGNIFICANT_CHANGE, | |
148 | SLSI_NL80211_VENDOR_SUBCMD_RESET_SIGNIFICANT_CHANGE, | |
149 | SLSI_NL80211_VENDOR_SUBCMD_SET_GSCAN_OUI, | |
3c0c6ab1 | 150 | SLSI_NL80211_VENDOR_SUBCMD_SET_NODFS, |
10d7569e | 151 | /*Add any GSCAN subcmds before this*/ |
3c0c6ab1 | 152 | SLSI_NL80211_VENDOR_SUBCMD_START_KEEP_ALIVE_OFFLOAD, |
6ff2d683 JPS |
153 | SLSI_NL80211_VENDOR_SUBCMD_STOP_KEEP_ALIVE_OFFLOAD, |
154 | SLSI_NL80211_VENDOR_SUBCMD_SET_BSSID_BLACKLIST, | |
155 | SLSI_NL80211_VENDOR_SUBCMD_SET_EPNO_LIST, | |
156 | SLSI_NL80211_VENDOR_SUBCMD_SET_HS_LIST, | |
f425b4a8 | 157 | SLSI_NL80211_VENDOR_SUBCMD_RESET_HS_LIST, |
d583845d JPS |
158 | SLSI_NL80211_VENDOR_SUBCMD_SET_RSSI_MONITOR, |
159 | SLSI_NL80211_VENDOR_SUBCMD_LLS_SET_INFO, | |
160 | SLSI_NL80211_VENDOR_SUBCMD_LLS_GET_INFO, | |
0318783f | 161 | SLSI_NL80211_VENDOR_SUBCMD_LLS_CLEAR_INFO, |
1fdbd4c1 | 162 | SLSI_NL80211_VENDOR_SUBCMD_GET_FEATURE_SET, |
de14a5c9 H |
163 | SLSI_NL80211_VENDOR_SUBCMD_SET_COUNTRY_CODE, |
164 | SLSI_NL80211_VENDOR_SUBCMD_CONFIGURE_ND_OFFLOAD | |
165 | ||
7753f181 DD |
166 | } WIFI_SUB_COMMAND; |
167 | ||
168 | typedef enum { | |
169 | GSCAN_EVENT_SIGNIFICANT_CHANGE_RESULTS , | |
170 | GSCAN_EVENT_HOTLIST_RESULTS_FOUND, | |
171 | GSCAN_EVENT_SCAN_RESULTS_AVAILABLE, | |
172 | GSCAN_EVENT_FULL_SCAN_RESULTS, | |
173 | GSCAN_EVENT_COMPLETE_SCAN, | |
6ff2d683 JPS |
174 | GSCAN_EVENT_HOTLIST_RESULTS_LOST, |
175 | WIFI_SUBCMD_KEY_MGMT_ROAM_AUTH, /* Handled by supplicant. not in Wifi-HAL */ | |
176 | WIFI_HANGED_EVENT, | |
177 | WIFI_EPNO_EVENT, | |
f425b4a8 | 178 | WIFI_HOTSPOT_MATCH, |
cdc775c7 HG |
179 | WIFI_RSSI_REPORT_EVENT, |
180 | ENHANCE_LOGGER_RING_EVENT, | |
181 | ENHANCE_LOGGER_MEM_DUMP_EVENT | |
f425b4a8 | 182 | |
7753f181 DD |
183 | } WIFI_EVENT; |
184 | ||
185 | typedef void (*wifi_internal_event_handler) (wifi_handle handle, int events); | |
186 | ||
187 | class WifiCommand; | |
188 | ||
189 | typedef struct { | |
190 | int nl_cmd; | |
191 | uint32_t vendor_id; | |
192 | int vendor_subcmd; | |
193 | nl_recvmsg_msg_cb_t cb_func; | |
194 | void *cb_arg; | |
195 | } cb_info; | |
196 | ||
197 | typedef struct { | |
198 | wifi_request_id id; | |
199 | WifiCommand *cmd; | |
200 | } cmd_info; | |
201 | ||
202 | typedef struct { | |
203 | wifi_handle handle; // handle to wifi data | |
204 | char name[8+1]; // interface name + trailing null | |
205 | int id; // id to use when talking to driver | |
206 | } interface_info; | |
207 | ||
208 | typedef struct { | |
209 | ||
210 | struct nl_sock *cmd_sock; // command socket object | |
211 | struct nl_sock *event_sock; // event socket object | |
212 | int nl80211_family_id; // family id for 80211 driver | |
213 | int cleanup_socks[2]; // sockets used to implement wifi_cleanup | |
214 | ||
215 | bool in_event_loop; // Indicates that event loop is active | |
216 | bool clean_up; // Indication to clean up the socket | |
217 | ||
218 | wifi_internal_event_handler event_handler; // default event handler | |
219 | wifi_cleaned_up_handler cleaned_up_handler; // socket cleaned up handler | |
220 | ||
221 | cb_info *event_cb; // event callbacks | |
222 | int num_event_cb; // number of event callbacks | |
223 | int alloc_event_cb; // number of allocated callback objects | |
224 | pthread_mutex_t cb_lock; // mutex for the event_cb access | |
225 | ||
226 | cmd_info *cmd; // Outstanding commands | |
227 | int num_cmd; // number of commands | |
228 | int alloc_cmd; // number of commands allocated | |
229 | ||
230 | interface_info **interfaces; // array of interfaces | |
231 | int num_interfaces; // number of interfaces | |
232 | ||
233 | ||
234 | // add other details | |
235 | } hal_info; | |
236 | ||
237 | wifi_error wifi_register_handler(wifi_handle handle, int cmd, nl_recvmsg_msg_cb_t func, void *arg); | |
238 | wifi_error wifi_register_vendor_handler(wifi_handle handle, | |
239 | uint32_t id, int subcmd, nl_recvmsg_msg_cb_t func, void *arg); | |
240 | ||
241 | void wifi_unregister_handler(wifi_handle handle, int cmd); | |
242 | void wifi_unregister_vendor_handler(wifi_handle handle, uint32_t id, int subcmd); | |
243 | ||
244 | wifi_error wifi_register_cmd(wifi_handle handle, int id, WifiCommand *cmd); | |
245 | WifiCommand *wifi_unregister_cmd(wifi_handle handle, int id); | |
246 | WifiCommand *wifi_get_cmd(wifi_handle handle, int id); | |
247 | void wifi_unregister_cmd(wifi_handle handle, WifiCommand *cmd); | |
f425b4a8 | 248 | wifi_error wifi_cancel_cmd(wifi_request_id id, wifi_interface_handle iface); |
7753f181 DD |
249 | |
250 | interface_info *getIfaceInfo(wifi_interface_handle); | |
251 | wifi_handle getWifiHandle(wifi_interface_handle handle); | |
252 | hal_info *getHalInfo(wifi_handle handle); | |
253 | hal_info *getHalInfo(wifi_interface_handle handle); | |
254 | wifi_handle getWifiHandle(hal_info *info); | |
255 | wifi_interface_handle getIfaceHandle(interface_info *info); | |
256 | ||
257 | ||
258 | // some common macros | |
259 | ||
260 | #define min(x, y) ((x) < (y) ? (x) : (y)) | |
261 | #define max(x, y) ((x) > (y) ? (x) : (y)) | |
262 | ||
cdc775c7 HG |
263 | #define NULL_CHECK_RETURN(ptr, str, ret) \ |
264 | do { \ | |
265 | if (!(ptr)) { \ | |
266 | ALOGE("%s(): null pointer - #ptr (%s)\n", __FUNCTION__, str); \ | |
267 | return ret; \ | |
268 | } \ | |
269 | } while (0) | |
270 | ||
7753f181 DD |
271 | #endif |
272 |