use stock libstlport
[GitHub/mt8127/android_device_alcatel_ttab.git] / wifi_hal / common.h
CommitLineData
f3fa1980
S
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#define DOT11_MAX_SSID_LEN 32
19
20#define MAX_PROBE_RESP_IE_LEN 2048
21/*
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.
25 */
26
27const uint32_t GOOGLE_OUI = 0x001A11;
28/* TODO: define vendor OUI here */
29
30#ifndef MAC2STR
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"
33#endif
34
35/*
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
39 */
40
41typedef enum {
42 /* Don't use 0 as a valid subcommand */
43 ANDROID_NL80211_SUBCMD_UNSPECIFIED,
44
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,
48
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,
52
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,
56
57 ANDROID_NL80211_SUBCMD_LSTATS_RANGE_START = 0x1200,
58 ANDROID_NL80211_SUBCMD_LSTATS_RANGE_END = 0x12FF,
59
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,
63
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,
67
68 /* This is reserved for future usage */
69
70} ANDROID_VENDOR_SUB_COMMAND;
71
72typedef enum {
73 WIFI_SUBCMD_GET_CHANNEL_LIST = ANDROID_NL80211_SUBCMD_WIFI_RANGE_START,
74
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 */
80
81 WIFI_SUBCMD_SET_RSSI_MONITOR, /* 0x0007 */
82 /* Add more sub commands here */
83} WIFI_SUB_COMMAND;
84
85typedef enum {
86 GSCAN_SUBCMD_GET_CAPABILITIES = ANDROID_NL80211_SUBCMD_GSCAN_RANGE_START,
87
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 */
93
94 GSCAN_SUBCMD_SET_HOTLIST, /* 0x1006 */
95
96 GSCAN_SUBCMD_SET_SIGNIFICANT_CHANGE_CONFIG, /* 0x1007 */
97 GSCAN_SUBCMD_ENABLE_FULL_SCAN_RESULTS, /* 0x1008 */
98
99 GSCAN_SUBCMD_SET_EPNO_SSID = 0x100F, /* 0x100F */
100
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 */
106
107 GSCAN_SUBCMD_ANQPO_CONFIG, /* 0x1015 */
108 /* Add more sub commands here */
109
110} GSCAN_SUB_COMMAND;
111
112typedef enum {
113 WIFI_ATTRIBUTE_BAND = 1,
114 WIFI_ATTRIBUTE_NUM_CHANNELS,
115 WIFI_ATTRIBUTE_CHANNEL_LIST,
116
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,
122
123 WIFI_ATTRIBUTE_MAX_RSSI,
124 WIFI_ATTRIBUTE_MIN_RSSI,
125 WIFI_ATTRIBUTE_RSSI_MONITOR_START,
126} WIFI_ATTRIBUTE;
127
128typedef enum {
129 GSCAN_EVENT_SIGNIFICANT_CHANGE_RESULTS,
130 GSCAN_EVENT_HOTLIST_RESULTS_FOUND,
131 GSCAN_EVENT_SCAN_RESULTS_AVAILABLE,
132 GSCAN_EVENT_FULL_SCAN_RESULTS,
133 RTT_EVENT_COMPLETE,
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,
139} WIFI_VENDOR_EVENT;
140
141typedef void (*wifi_internal_event_handler) (wifi_handle handle, int events);
142
143class WifiCommand;
144
145typedef struct {
146 int nl_cmd;
147 uint32_t vendor_id;
148 int vendor_subcmd;
149 nl_recvmsg_msg_cb_t cb_func;
150 void *cb_arg;
151} cb_info;
152
153typedef struct {
154 wifi_request_id id;
155 WifiCommand *cmd;
156} cmd_info;
157
158typedef struct {
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
162} interface_info;
163
164typedef struct {
165
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
170
171 bool in_event_loop; // Indicates that event loop is active
172 bool clean_up; // Indication to exit since cleanup has started
173
174 wifi_internal_event_handler event_handler; // default event handler
175 wifi_cleaned_up_handler cleaned_up_handler; // socket cleaned up handler
176
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
181
182 cmd_info *cmd; // Outstanding commands
183 int num_cmd; // number of commands
184 int alloc_cmd; // number of commands allocated
185
186 interface_info **interfaces; // array of interfaces
187 int num_interfaces; // number of interfaces
188
189
190 // add other details
191} hal_info;
192
193#define PNO_SSID_FOUND 0x1
194#define PNO_SSID_LOST 0x2
195
196typedef struct wifi_pno_result {
197 unsigned char ssid[DOT11_MAX_SSID_LEN];
198 unsigned char ssid_len;
199 signed char rssi;
200 u16 channel;
201 u16 flags;
202 mac_addr bssid;
203} wifi_pno_result_t;
204
205typedef 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
210 s32 rssi; // in db
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
215 u32 ie_length;
216 char ie_data[1];
217} wifi_gscan_result_t;
218
219typedef 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;
225
226wifi_error wifi_register_handler(wifi_handle handle, int cmd, nl_recvmsg_msg_cb_t func, void *arg);
227wifi_error wifi_register_vendor_handler(wifi_handle handle,
228 uint32_t id, int subcmd, nl_recvmsg_msg_cb_t func, void *arg);
229
230void wifi_unregister_handler(wifi_handle handle, int cmd);
231void wifi_unregister_vendor_handler(wifi_handle handle, uint32_t id, int subcmd);
232
233wifi_error wifi_register_cmd(wifi_handle handle, int id, WifiCommand *cmd);
234WifiCommand *wifi_unregister_cmd(wifi_handle handle, int id);
235WifiCommand *wifi_get_cmd(wifi_handle handle, int id);
236void wifi_unregister_cmd(wifi_handle handle, WifiCommand *cmd);
237
238interface_info *getIfaceInfo(wifi_interface_handle);
239wifi_handle getWifiHandle(wifi_interface_handle handle);
240hal_info *getHalInfo(wifi_handle handle);
241hal_info *getHalInfo(wifi_interface_handle handle);
242wifi_handle getWifiHandle(hal_info *info);
243wifi_interface_handle getIfaceHandle(interface_info *info);
244wifi_error wifi_cancel_cmd(wifi_request_id id, wifi_interface_handle iface);
245
246// some common macros
247
248#define min(x, y) ((x) < (y) ? (x) : (y))
249#define max(x, y) ((x) > (y) ? (x) : (y))
250
251#define NULL_CHECK_RETURN(ptr, str, ret) \
252 do { \
253 if (!(ptr)) { \
254 ALOGE("%s(): null pointer - #ptr (%s)\n", __FUNCTION__, str); \
255 return ret; \
256 } \
257 } while (0)
258
259#endif
260