[APR-2053]wlbt: NAN R2 integration fxes
[GitHub/MotorolaMobilityLLC/hardware-samsung_slsi-scsc_wifibt-wifi_hal.git] / common.h
CommitLineData
7753f181
DD
1
2#include "wifi_hal.h"
3
4#ifndef __WIFI_HAL_COMMON_H__
5#define __WIFI_HAL_COMMON_H__
6
d3a587e8
JPS
7#ifdef LOG_TAG
8#undef LOG_TAG
9#endif
7753f181
DD
10#define LOG_TAG "WifiHAL"
11
12#include <utils/Log.h>
13#include "nl80211_copy.h"
14#include "sync.h"
15
16#define SOCKET_BUFFER_SIZE (32768U)
17#define RECV_BUF_SIZE (4096)
18#define DEFAULT_EVENT_CB_SIZE (64)
19#define DEFAULT_CMD_SIZE (64)
20#define DOT11_OUI_LEN 3
21
02b2b8ab
S
22typedef struct {
23 int num_bssid;
24 mac_addr bssids[MAX_BLACKLIST_BSSID];
25} wifi_bssid_params;
26
7753f181
DD
27/*
28 Vendor OUI - This is a unique identifier that identifies organization. Lets
29 code Android specific functions with Google OUI; although vendors can do more
30 with their own OUI's as well.
31 */
32
33const uint32_t GOOGLE_OUI = 0x001A11;
34/* TODO: define vendor OUI here */
35
02b2b8ab
S
36typedef enum {
37
38 GSCAN_ATTRIBUTE_NUM_BUCKETS = 10,
39 GSCAN_ATTRIBUTE_BASE_PERIOD,
40 GSCAN_ATTRIBUTE_BUCKETS_BAND,
41 GSCAN_ATTRIBUTE_BUCKET_ID,
42 GSCAN_ATTRIBUTE_BUCKET_PERIOD,
43 GSCAN_ATTRIBUTE_BUCKET_NUM_CHANNELS,
44 GSCAN_ATTRIBUTE_BUCKET_CHANNELS,
45 GSCAN_ATTRIBUTE_NUM_AP_PER_SCAN,
46 GSCAN_ATTRIBUTE_REPORT_THRESHOLD,
47 GSCAN_ATTRIBUTE_NUM_SCANS_TO_CACHE,
48 GSCAN_ATTRIBUTE_REPORT_THRESHOLD_NUM_SCANS,
49 GSCAN_ATTRIBUTE_BAND = GSCAN_ATTRIBUTE_BUCKETS_BAND,
50
51 GSCAN_ATTRIBUTE_ENABLE_FEATURE = 20,
52 GSCAN_ATTRIBUTE_SCAN_RESULTS_COMPLETE, /* indicates no more results */
53 GSCAN_ATTRIBUTE_REPORT_EVENTS,
54
55 /* remaining reserved for additional attributes */
56 GSCAN_ATTRIBUTE_NUM_OF_RESULTS = 30,
57 GSCAN_ATTRIBUTE_SCAN_RESULTS, /* flat array of wifi_scan_result */
58 GSCAN_ATTRIBUTE_NUM_CHANNELS,
59 GSCAN_ATTRIBUTE_CHANNEL_LIST,
60 GSCAN_ATTRIBUTE_SCAN_ID,
61 GSCAN_ATTRIBUTE_SCAN_FLAGS,
62 GSCAN_ATTRIBUTE_SCAN_BUCKET_BIT,
63
02b2b8ab
S
64 /* remaining reserved for additional attributes */
65 GSCAN_ATTRIBUTE_RSSI_SAMPLE_SIZE = 60,
66 GSCAN_ATTRIBUTE_LOST_AP_SAMPLE_SIZE,
67 GSCAN_ATTRIBUTE_MIN_BREACHING,
68 GSCAN_ATTRIBUTE_SIGNIFICANT_CHANGE_BSSIDS,
69
70 GSCAN_ATTRIBUTE_BUCKET_STEP_COUNT = 70,
71 GSCAN_ATTRIBUTE_BUCKET_EXPONENT,
72 GSCAN_ATTRIBUTE_BUCKET_MAX_PERIOD,
73
74 GSCAN_ATTRIBUTE_NUM_BSSID,
75 GSCAN_ATTRIBUTE_BLACKLIST_BSSID,
76
77 GSCAN_ATTRIBUTE_MAX
78
79} GSCAN_ATTRIBUTE;
7753f181
DD
80
81/*
82 This enum defines ranges for various commands; commands themselves
83 can be defined in respective feature headers; i.e. find gscan command
84 definitions in gscan.cpp
85 */
86
87typedef enum {
88 /* don't use 0 as a valid subcommand */
89 VENDOR_NL80211_SUBCMD_UNSPECIFIED,
90
91 /* define all vendor startup commands between 0x0 and 0x0FFF */
92 VENDOR_NL80211_SUBCMD_RANGE_START = 0x0001,
93 VENDOR_NL80211_SUBCMD_RANGE_END = 0x0FFF,
94
95 /* define all GScan related commands between 0x1000 and 0x10FF */
96 ANDROID_NL80211_SUBCMD_GSCAN_RANGE_START = 0x1000,
97 ANDROID_NL80211_SUBCMD_GSCAN_RANGE_END = 0x10FF,
98
99 /* define all NearbyDiscovery related commands between 0x1100 and 0x11FF */
100 ANDROID_NL80211_SUBCMD_NBD_RANGE_START = 0x1100,
101 ANDROID_NL80211_SUBCMD_NBD_RANGE_END = 0x11FF,
102
103 /* define all RTT related commands between 0x1100 and 0x11FF */
104 ANDROID_NL80211_SUBCMD_RTT_RANGE_START = 0x1100,
105 ANDROID_NL80211_SUBCMD_RTT_RANGE_END = 0x11FF,
106
107 ANDROID_NL80211_SUBCMD_LSTATS_RANGE_START = 0x1200,
108 ANDROID_NL80211_SUBCMD_LSTATS_RANGE_END = 0x12FF,
109
cdc775c7
HG
110 /* define all Logger related commands between 0x1400 and 0x14FF */
111 ANDROID_NL80211_SUBCMD_DEBUG_RANGE_START = 0x1400,
112 ANDROID_NL80211_SUBCMD_DEBUG_RANGE_END = 0x14FF,
113
3c0c6ab1
PG
114 /* define all wifi offload related commands between 0x1400 and 0x14FF */
115 ANDROID_NL80211_SUBCMD_WIFI_OFFLOAD_RANGE_START = 0x1400,
116 ANDROID_NL80211_SUBCMD_WIFI_OFFLOAD_RANGE_END = 0x14FF,
117
d3a587e8
JPS
118 /* Range for NAN commands */
119 ANDROID_NL80211_SUBCMD_NAN_RANGE_START = 0x1500,
120 ANDROID_NL80211_SUBCMD_NAN_RANGE_END = 0x15FF,
3c0c6ab1 121 /* This is reserved for future usage */
7753f181 122
5822f843
SP
123 /* define all APF related commands between 0x1600 and 0x16FF */
124 ANDROID_NL80211_SUBCMD_APF_RANGE_START = 0x1600,
125 ANDROID_NL80211_SUBCMD_APF_RANGE_END = 0x16FF,
126
7753f181
DD
127} ANDROID_VENDOR_SUB_COMMAND;
128
129typedef enum {
130 SLSI_NL80211_VENDOR_SUBCMD_GET_CAPABILITIES = ANDROID_NL80211_SUBCMD_GSCAN_RANGE_START,
131 SLSI_NL80211_VENDOR_SUBCMD_GET_VALID_CHANNELS,
132 SLSI_NL80211_VENDOR_SUBCMD_ADD_GSCAN,
133 SLSI_NL80211_VENDOR_SUBCMD_DEL_GSCAN,
134 SLSI_NL80211_VENDOR_SUBCMD_GET_SCAN_RESULTS,
29b5ae02
HG
135 /**********Deprecated now due to fapi updates.Do not remove*/
136 SLSI_NL80211_VENDOR_SUBCMD_SET_BSSID_HOTLIST,
137 SLSI_NL80211_VENDOR_SUBCMD_RESET_BSSID_HOTLIST,
138 SLSI_NL80211_VENDOR_SUBCMD_GET_HOTLIST_RESULTS,
139 SLSI_NL80211_VENDOR_SUBCMD_SET_SIGNIFICANT_CHANGE,
140 SLSI_NL80211_VENDOR_SUBCMD_RESET_SIGNIFICANT_CHANGE,
141 /******************************************/
7753f181 142 SLSI_NL80211_VENDOR_SUBCMD_SET_GSCAN_OUI,
3c0c6ab1
PG
143 SLSI_NL80211_VENDOR_SUBCMD_SET_NODFS,
144 SLSI_NL80211_VENDOR_SUBCMD_START_KEEP_ALIVE_OFFLOAD,
6ff2d683
JPS
145 SLSI_NL80211_VENDOR_SUBCMD_STOP_KEEP_ALIVE_OFFLOAD,
146 SLSI_NL80211_VENDOR_SUBCMD_SET_BSSID_BLACKLIST,
147 SLSI_NL80211_VENDOR_SUBCMD_SET_EPNO_LIST,
148 SLSI_NL80211_VENDOR_SUBCMD_SET_HS_LIST,
f425b4a8 149 SLSI_NL80211_VENDOR_SUBCMD_RESET_HS_LIST,
d583845d
JPS
150 SLSI_NL80211_VENDOR_SUBCMD_SET_RSSI_MONITOR,
151 SLSI_NL80211_VENDOR_SUBCMD_LLS_SET_INFO,
152 SLSI_NL80211_VENDOR_SUBCMD_LLS_GET_INFO,
0318783f 153 SLSI_NL80211_VENDOR_SUBCMD_LLS_CLEAR_INFO,
1fdbd4c1 154 SLSI_NL80211_VENDOR_SUBCMD_GET_FEATURE_SET,
de14a5c9 155 SLSI_NL80211_VENDOR_SUBCMD_SET_COUNTRY_CODE,
d3a587e8 156 SLSI_NL80211_VENDOR_SUBCMD_CONFIGURE_ND_OFFLOAD,
47e18f37
JPS
157 SLSI_NL80211_VENDOR_SUBCMD_GET_ROAMING_CAPABILITIES,
158 SLSI_NL80211_VENDOR_SUBCMD_SET_ROAMING_STATE,
f8204f99 159 SLSI_NL80211_VENDOR_SUBCMD_SET_LATENCY_MODE,
d3a587e8
JPS
160
161 SLSI_NL80211_VENDOR_SUBCMD_NAN_ENABLE = ANDROID_NL80211_SUBCMD_NAN_RANGE_START,
162 SLSI_NL80211_VENDOR_SUBCMD_NAN_DISABLE,
163 SLSI_NL80211_VENDOR_SUBCMD_NAN_PUBLISH,
164 SLSI_NL80211_VENDOR_SUBCMD_NAN_PUBLISHCANCEL,
165 SLSI_NL80211_VENDOR_SUBCMD_NAN_SUBSCRIBE,
166 SLSI_NL80211_VENDOR_SUBCMD_NAN_SUBSCRIBECANCEL,
167 SLSI_NL80211_VENDOR_SUBCMD_NAN_TXFOLLOWUP,
168 SLSI_NL80211_VENDOR_SUBCMD_NAN_CONFIG,
47e18f37 169 SLSI_NL80211_VENDOR_SUBCMD_NAN_CAPABILITIES,
c2afddcb
JPS
170 SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_INTERFACE_CREATE,
171 SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_INTERFACE_DELETE,
172 SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_REQUEST_INITIATOR,
173 SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_INDICATION_RESPONSE,
174 SLSI_NL80211_VENDOR_SUBCMD_NAN_DATA_END,
47e18f37
JPS
175 SLSI_NL80211_VENDOR_SUBCMD_RTT_GET_CAPABILITIES = ANDROID_NL80211_SUBCMD_RTT_RANGE_START,
176 SLSI_NL80211_VENDOR_SUBCMD_RTT_RANGE_START,
5822f843
SP
177 SLSI_NL80211_VENDOR_SUBCMD_RTT_RANGE_CANCEL,
178
179 SLSI_NL80211_VENDOR_SUBCMD_APF_SET_FILTER = ANDROID_NL80211_SUBCMD_APF_RANGE_START,
180 SLSI_NL80211_VENDOR_SUBCMD_APF_GET_CAPABILITIES,
181 SLSI_NL80211_VENDOR_SUBCMD_APF_READ_FILTER
7753f181
DD
182} WIFI_SUB_COMMAND;
183
184typedef enum {
29b5ae02
HG
185 /**********Deprecated now due to fapi updates.Do not remove*/
186 GSCAN_EVENT_SIGNIFICANT_CHANGE_RESULTS ,
187 GSCAN_EVENT_HOTLIST_RESULTS_FOUND,
188 /******************************************/
7753f181
DD
189 GSCAN_EVENT_SCAN_RESULTS_AVAILABLE,
190 GSCAN_EVENT_FULL_SCAN_RESULTS,
191 GSCAN_EVENT_COMPLETE_SCAN,
29b5ae02
HG
192 /**********Deprecated now due to fapi updates.Do not remove*/
193 GSCAN_EVENT_HOTLIST_RESULTS_LOST,
194 /******************************************/
6ff2d683
JPS
195 WIFI_SUBCMD_KEY_MGMT_ROAM_AUTH, /* Handled by supplicant. not in Wifi-HAL */
196 WIFI_HANGED_EVENT,
197 WIFI_EPNO_EVENT,
f425b4a8 198 WIFI_HOTSPOT_MATCH,
cdc775c7
HG
199 WIFI_RSSI_REPORT_EVENT,
200 ENHANCE_LOGGER_RING_EVENT,
d3a587e8 201 ENHANCE_LOGGER_MEM_DUMP_EVENT,
c2afddcb
JPS
202 /* NAN events start */
203 SLSI_NAN_EVENT_RESPONSE = 13,
d3a587e8
JPS
204 SLSI_NAN_EVENT_PUBLISH_TERMINATED,
205 SLSI_NAN_EVENT_MATCH,
206 SLSI_NAN_EVENT_MATCH_EXPIRED,
207 SLSI_NAN_EVENT_SUBSCRIBE_TERMINATED,
208 SLSI_NAN_EVENT_FOLLOWUP,
209 SLSI_NAN_EVENT_DISCOVERY_ENGINE,
47e18f37 210 SLSI_NAN_EVENT_DISABLED,
47e18f37 211 SLSI_RTT_RESULT_EVENT,
c6066999 212 SLSI_RTT_EVENT_COMPLETE,
650a9e6a
JPS
213 WIFI_ACS_EVENT, /* Handled by supplicant. not in Wifi-HAL */
214 SLSI_NL80211_VENDOR_FORWARD_BEACON,
215 SLSI_NL80211_VENDOR_FORWARD_BEACON_ABORT,
c2afddcb
JPS
216 SLSI_NAN_EVENT_TRANSMIT_FOLLOWUP_STATUS,
217 /* NAN DATA PATH EVENTS*/
218 SLSI_NAN_EVENT_NDP_REQ = 24,
219 SLSI_NAN_EVENT_NDP_CFM,
220 SLSI_NAN_EVENT_NDP_END
f425b4a8 221
7753f181
DD
222} WIFI_EVENT;
223
224typedef void (*wifi_internal_event_handler) (wifi_handle handle, int events);
225
226class WifiCommand;
227
228typedef struct {
229 int nl_cmd;
230 uint32_t vendor_id;
231 int vendor_subcmd;
232 nl_recvmsg_msg_cb_t cb_func;
233 void *cb_arg;
234} cb_info;
235
236typedef struct {
237 wifi_request_id id;
238 WifiCommand *cmd;
239} cmd_info;
240
241typedef struct {
242 wifi_handle handle; // handle to wifi data
243 char name[8+1]; // interface name + trailing null
244 int id; // id to use when talking to driver
245} interface_info;
246
247typedef struct {
248
249 struct nl_sock *cmd_sock; // command socket object
250 struct nl_sock *event_sock; // event socket object
251 int nl80211_family_id; // family id for 80211 driver
252 int cleanup_socks[2]; // sockets used to implement wifi_cleanup
253
254 bool in_event_loop; // Indicates that event loop is active
255 bool clean_up; // Indication to clean up the socket
256
257 wifi_internal_event_handler event_handler; // default event handler
258 wifi_cleaned_up_handler cleaned_up_handler; // socket cleaned up handler
259
260 cb_info *event_cb; // event callbacks
261 int num_event_cb; // number of event callbacks
262 int alloc_event_cb; // number of allocated callback objects
263 pthread_mutex_t cb_lock; // mutex for the event_cb access
264
265 cmd_info *cmd; // Outstanding commands
266 int num_cmd; // number of commands
267 int alloc_cmd; // number of commands allocated
268
269 interface_info **interfaces; // array of interfaces
270 int num_interfaces; // number of interfaces
271
650a9e6a 272 WifiCommand *nanCmd;
7753f181
DD
273
274 // add other details
275} hal_info;
276
277wifi_error wifi_register_handler(wifi_handle handle, int cmd, nl_recvmsg_msg_cb_t func, void *arg);
278wifi_error wifi_register_vendor_handler(wifi_handle handle,
279 uint32_t id, int subcmd, nl_recvmsg_msg_cb_t func, void *arg);
280
281void wifi_unregister_handler(wifi_handle handle, int cmd);
282void wifi_unregister_vendor_handler(wifi_handle handle, uint32_t id, int subcmd);
283
284wifi_error wifi_register_cmd(wifi_handle handle, int id, WifiCommand *cmd);
285WifiCommand *wifi_unregister_cmd(wifi_handle handle, int id);
286WifiCommand *wifi_get_cmd(wifi_handle handle, int id);
287void wifi_unregister_cmd(wifi_handle handle, WifiCommand *cmd);
f425b4a8 288wifi_error wifi_cancel_cmd(wifi_request_id id, wifi_interface_handle iface);
7753f181
DD
289
290interface_info *getIfaceInfo(wifi_interface_handle);
291wifi_handle getWifiHandle(wifi_interface_handle handle);
292hal_info *getHalInfo(wifi_handle handle);
293hal_info *getHalInfo(wifi_interface_handle handle);
294wifi_handle getWifiHandle(hal_info *info);
295wifi_interface_handle getIfaceHandle(interface_info *info);
296
650a9e6a
JPS
297void wifi_set_nan_cmd(wifi_handle handle, WifiCommand *cmd);
298void wifi_reset_nan_cmd(wifi_handle handle);
299WifiCommand *wifi_get_nan_cmd(wifi_handle handle);
7753f181
DD
300// some common macros
301
302#define min(x, y) ((x) < (y) ? (x) : (y))
303#define max(x, y) ((x) > (y) ? (x) : (y))
304
cdc775c7
HG
305#define NULL_CHECK_RETURN(ptr, str, ret) \
306 do { \
307 if (!(ptr)) { \
308 ALOGE("%s(): null pointer - #ptr (%s)\n", __FUNCTION__, str); \
309 return ret; \
310 } \
311 } while (0)
7753f181
DD
312#endif
313