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 | ||
19 | /* | |
20 | Vendor OUI - This is a unique identifier that identifies organization. Lets | |
21 | code Android specific functions with Google OUI; although vendors can do more | |
22 | with their own OUI's as well. | |
23 | */ | |
24 | ||
25 | const uint32_t GOOGLE_OUI = 0x001A11; | |
26 | /* TODO: define vendor OUI here */ | |
27 | ||
28 | ||
29 | /* | |
30 | This enum defines ranges for various commands; commands themselves | |
31 | can be defined in respective feature headers; i.e. find gscan command | |
32 | definitions in gscan.cpp | |
33 | */ | |
34 | ||
35 | typedef enum { | |
36 | /* don't use 0 as a valid subcommand */ | |
37 | VENDOR_NL80211_SUBCMD_UNSPECIFIED, | |
38 | ||
39 | /* define all vendor startup commands between 0x0 and 0x0FFF */ | |
40 | VENDOR_NL80211_SUBCMD_RANGE_START = 0x0001, | |
41 | VENDOR_NL80211_SUBCMD_RANGE_END = 0x0FFF, | |
42 | ||
43 | /* define all GScan related commands between 0x1000 and 0x10FF */ | |
44 | ANDROID_NL80211_SUBCMD_GSCAN_RANGE_START = 0x1000, | |
45 | ANDROID_NL80211_SUBCMD_GSCAN_RANGE_END = 0x10FF, | |
46 | ||
47 | /* define all NearbyDiscovery related commands between 0x1100 and 0x11FF */ | |
48 | ANDROID_NL80211_SUBCMD_NBD_RANGE_START = 0x1100, | |
49 | ANDROID_NL80211_SUBCMD_NBD_RANGE_END = 0x11FF, | |
50 | ||
51 | /* define all RTT related commands between 0x1100 and 0x11FF */ | |
52 | ANDROID_NL80211_SUBCMD_RTT_RANGE_START = 0x1100, | |
53 | ANDROID_NL80211_SUBCMD_RTT_RANGE_END = 0x11FF, | |
54 | ||
55 | ANDROID_NL80211_SUBCMD_LSTATS_RANGE_START = 0x1200, | |
56 | ANDROID_NL80211_SUBCMD_LSTATS_RANGE_END = 0x12FF, | |
57 | ||
3c0c6ab1 PG |
58 | /* define all wifi offload related commands between 0x1400 and 0x14FF */ |
59 | ANDROID_NL80211_SUBCMD_WIFI_OFFLOAD_RANGE_START = 0x1400, | |
60 | ANDROID_NL80211_SUBCMD_WIFI_OFFLOAD_RANGE_END = 0x14FF, | |
61 | ||
62 | /* This is reserved for future usage */ | |
7753f181 DD |
63 | |
64 | } ANDROID_VENDOR_SUB_COMMAND; | |
65 | ||
66 | typedef enum { | |
67 | SLSI_NL80211_VENDOR_SUBCMD_GET_CAPABILITIES = ANDROID_NL80211_SUBCMD_GSCAN_RANGE_START, | |
68 | SLSI_NL80211_VENDOR_SUBCMD_GET_VALID_CHANNELS, | |
69 | SLSI_NL80211_VENDOR_SUBCMD_ADD_GSCAN, | |
70 | SLSI_NL80211_VENDOR_SUBCMD_DEL_GSCAN, | |
71 | SLSI_NL80211_VENDOR_SUBCMD_GET_SCAN_RESULTS, | |
72 | SLSI_NL80211_VENDOR_SUBCMD_SET_BSSID_HOTLIST, | |
73 | SLSI_NL80211_VENDOR_SUBCMD_RESET_BSSID_HOTLIST, | |
74 | SLSI_NL80211_VENDOR_SUBCMD_GET_HOTLIST_RESULTS, | |
75 | SLSI_NL80211_VENDOR_SUBCMD_SET_SIGNIFICANT_CHANGE, | |
76 | SLSI_NL80211_VENDOR_SUBCMD_RESET_SIGNIFICANT_CHANGE, | |
77 | SLSI_NL80211_VENDOR_SUBCMD_SET_GSCAN_OUI, | |
3c0c6ab1 | 78 | SLSI_NL80211_VENDOR_SUBCMD_SET_NODFS, |
10d7569e | 79 | /*Add any GSCAN subcmds before this*/ |
3c0c6ab1 | 80 | SLSI_NL80211_VENDOR_SUBCMD_START_KEEP_ALIVE_OFFLOAD, |
6ff2d683 JPS |
81 | SLSI_NL80211_VENDOR_SUBCMD_STOP_KEEP_ALIVE_OFFLOAD, |
82 | SLSI_NL80211_VENDOR_SUBCMD_SET_BSSID_BLACKLIST, | |
83 | SLSI_NL80211_VENDOR_SUBCMD_SET_EPNO_LIST, | |
84 | SLSI_NL80211_VENDOR_SUBCMD_SET_HS_LIST, | |
f425b4a8 | 85 | SLSI_NL80211_VENDOR_SUBCMD_RESET_HS_LIST, |
d583845d JPS |
86 | SLSI_NL80211_VENDOR_SUBCMD_SET_RSSI_MONITOR, |
87 | SLSI_NL80211_VENDOR_SUBCMD_LLS_SET_INFO, | |
88 | SLSI_NL80211_VENDOR_SUBCMD_LLS_GET_INFO, | |
89 | SLSI_NL80211_VENDOR_SUBCMD_LLS_CLEAR_INFO | |
7753f181 DD |
90 | } WIFI_SUB_COMMAND; |
91 | ||
92 | typedef enum { | |
93 | GSCAN_EVENT_SIGNIFICANT_CHANGE_RESULTS , | |
94 | GSCAN_EVENT_HOTLIST_RESULTS_FOUND, | |
95 | GSCAN_EVENT_SCAN_RESULTS_AVAILABLE, | |
96 | GSCAN_EVENT_FULL_SCAN_RESULTS, | |
97 | GSCAN_EVENT_COMPLETE_SCAN, | |
6ff2d683 JPS |
98 | GSCAN_EVENT_HOTLIST_RESULTS_LOST, |
99 | WIFI_SUBCMD_KEY_MGMT_ROAM_AUTH, /* Handled by supplicant. not in Wifi-HAL */ | |
100 | WIFI_HANGED_EVENT, | |
101 | WIFI_EPNO_EVENT, | |
f425b4a8 PG |
102 | WIFI_HOTSPOT_MATCH, |
103 | WIFI_RSSI_REPORT_EVENT | |
104 | ||
7753f181 DD |
105 | } WIFI_EVENT; |
106 | ||
107 | typedef void (*wifi_internal_event_handler) (wifi_handle handle, int events); | |
108 | ||
109 | class WifiCommand; | |
110 | ||
111 | typedef struct { | |
112 | int nl_cmd; | |
113 | uint32_t vendor_id; | |
114 | int vendor_subcmd; | |
115 | nl_recvmsg_msg_cb_t cb_func; | |
116 | void *cb_arg; | |
117 | } cb_info; | |
118 | ||
119 | typedef struct { | |
120 | wifi_request_id id; | |
121 | WifiCommand *cmd; | |
122 | } cmd_info; | |
123 | ||
124 | typedef struct { | |
125 | wifi_handle handle; // handle to wifi data | |
126 | char name[8+1]; // interface name + trailing null | |
127 | int id; // id to use when talking to driver | |
128 | } interface_info; | |
129 | ||
130 | typedef struct { | |
131 | ||
132 | struct nl_sock *cmd_sock; // command socket object | |
133 | struct nl_sock *event_sock; // event socket object | |
134 | int nl80211_family_id; // family id for 80211 driver | |
135 | int cleanup_socks[2]; // sockets used to implement wifi_cleanup | |
136 | ||
137 | bool in_event_loop; // Indicates that event loop is active | |
138 | bool clean_up; // Indication to clean up the socket | |
139 | ||
140 | wifi_internal_event_handler event_handler; // default event handler | |
141 | wifi_cleaned_up_handler cleaned_up_handler; // socket cleaned up handler | |
142 | ||
143 | cb_info *event_cb; // event callbacks | |
144 | int num_event_cb; // number of event callbacks | |
145 | int alloc_event_cb; // number of allocated callback objects | |
146 | pthread_mutex_t cb_lock; // mutex for the event_cb access | |
147 | ||
148 | cmd_info *cmd; // Outstanding commands | |
149 | int num_cmd; // number of commands | |
150 | int alloc_cmd; // number of commands allocated | |
151 | ||
152 | interface_info **interfaces; // array of interfaces | |
153 | int num_interfaces; // number of interfaces | |
154 | ||
155 | ||
156 | // add other details | |
157 | } hal_info; | |
158 | ||
159 | wifi_error wifi_register_handler(wifi_handle handle, int cmd, nl_recvmsg_msg_cb_t func, void *arg); | |
160 | wifi_error wifi_register_vendor_handler(wifi_handle handle, | |
161 | uint32_t id, int subcmd, nl_recvmsg_msg_cb_t func, void *arg); | |
162 | ||
163 | void wifi_unregister_handler(wifi_handle handle, int cmd); | |
164 | void wifi_unregister_vendor_handler(wifi_handle handle, uint32_t id, int subcmd); | |
165 | ||
166 | wifi_error wifi_register_cmd(wifi_handle handle, int id, WifiCommand *cmd); | |
167 | WifiCommand *wifi_unregister_cmd(wifi_handle handle, int id); | |
168 | WifiCommand *wifi_get_cmd(wifi_handle handle, int id); | |
169 | void wifi_unregister_cmd(wifi_handle handle, WifiCommand *cmd); | |
f425b4a8 | 170 | wifi_error wifi_cancel_cmd(wifi_request_id id, wifi_interface_handle iface); |
7753f181 DD |
171 | |
172 | interface_info *getIfaceInfo(wifi_interface_handle); | |
173 | wifi_handle getWifiHandle(wifi_interface_handle handle); | |
174 | hal_info *getHalInfo(wifi_handle handle); | |
175 | hal_info *getHalInfo(wifi_interface_handle handle); | |
176 | wifi_handle getWifiHandle(hal_info *info); | |
177 | wifi_interface_handle getIfaceHandle(interface_info *info); | |
178 | ||
179 | ||
180 | // some common macros | |
181 | ||
182 | #define min(x, y) ((x) < (y) ? (x) : (y)) | |
183 | #define max(x, y) ((x) > (y) ? (x) : (y)) | |
184 | ||
185 | #endif | |
186 |