Commit | Line | Data |
---|---|---|
d2839953 RC |
1 | /* |
2 | * Linux cfg80211 driver - Android related functions | |
3 | * | |
965f77c4 | 4 | * Copyright (C) 1999-2019, Broadcom. |
d2839953 RC |
5 | * |
6 | * Unless you and Broadcom execute a separate written software license | |
7 | * agreement governing use of this software, this software is licensed to you | |
8 | * under the terms of the GNU General Public License version 2 (the "GPL"), | |
9 | * available at http://www.broadcom.com/licenses/GPLv2.php, with the | |
10 | * following added to such license: | |
11 | * | |
12 | * As a special exception, the copyright holders of this software give you | |
13 | * permission to link this software with independent modules, and to copy and | |
14 | * distribute the resulting executable under terms of your choice, provided that | |
15 | * you also meet, for each linked independent module, the terms and conditions of | |
16 | * the license of that module. An independent module is a module which is not | |
17 | * derived from this software. The special exception does not apply to any | |
18 | * modifications of the software. | |
19 | * | |
20 | * Notwithstanding the above, under no circumstances may you combine this | |
21 | * software in any way with any other Broadcom software provided under a license | |
22 | * other than the GPL, without Broadcom's express prior written consent. | |
23 | * | |
24 | * | |
25 | * <<Broadcom-WL-IPTag/Open:>> | |
26 | * | |
965f77c4 | 27 | * $Id: wl_android.h 794110 2018-12-12 05:03:21Z $ |
d2839953 RC |
28 | */ |
29 | ||
30 | #ifndef _wl_android_ | |
31 | #define _wl_android_ | |
32 | ||
33 | #include <linux/module.h> | |
34 | #include <linux/netdevice.h> | |
35 | #include <wldev_common.h> | |
36 | #include <dngl_stats.h> | |
37 | #include <dhd.h> | |
38 | ||
39 | /* If any feature uses the Generic Netlink Interface, put it here to enable WL_GENL | |
40 | * automatically | |
41 | */ | |
42 | #if defined(BT_WIFI_HANDOVER) | |
43 | #define WL_GENL | |
44 | #endif // endif | |
45 | ||
46 | #ifdef WL_GENL | |
47 | #include <net/genetlink.h> | |
48 | #endif // endif | |
49 | ||
50 | typedef struct _android_wifi_priv_cmd { | |
51 | char *buf; | |
52 | int used_len; | |
53 | int total_len; | |
54 | } android_wifi_priv_cmd; | |
55 | ||
56 | #ifdef CONFIG_COMPAT | |
57 | typedef struct _compat_android_wifi_priv_cmd { | |
58 | compat_caddr_t buf; | |
59 | int used_len; | |
60 | int total_len; | |
61 | } compat_android_wifi_priv_cmd; | |
62 | #endif /* CONFIG_COMPAT */ | |
63 | ||
64 | /** | |
65 | * Android platform dependent functions, feel free to add Android specific functions here | |
66 | * (save the macros in dhd). Please do NOT declare functions that are NOT exposed to dhd | |
67 | * or cfg, define them as static in wl_android.c | |
68 | */ | |
69 | ||
70 | /* message levels */ | |
965f77c4 RC |
71 | #define ANDROID_ERROR_LEVEL (1 << 0) |
72 | #define ANDROID_TRACE_LEVEL (1 << 1) | |
73 | #define ANDROID_INFO_LEVEL (1 << 2) | |
74 | #define ANDROID_SCAN_LEVEL (1 << 3) | |
75 | #define ANDROID_DBG_LEVEL (1 << 4) | |
76 | #define ANDROID_MSG_LEVEL (1 << 0) | |
d2839953 | 77 | |
965f77c4 | 78 | #define WL_MSG(name, arg1, args...) \ |
47fa5ad5 | 79 | do { \ |
965f77c4 RC |
80 | if (android_msg_level & ANDROID_MSG_LEVEL) { \ |
81 | printk(KERN_ERR "[dhd-%s] %s : " arg1, name, __func__, ## args); \ | |
d2839953 RC |
82 | } \ |
83 | } while (0) | |
84 | ||
3910ce8e LJ |
85 | #define WL_MSG_PRINT_RATE_LIMIT_PERIOD 1000000000u /* 1s in units of ns */ |
86 | #define WL_MSG_RLMT(name, cmp, size, arg1, args...) \ | |
87 | do { \ | |
88 | if (android_msg_level & ANDROID_MSG_LEVEL) { \ | |
89 | static uint64 __err_ts = 0; \ | |
90 | static uint32 __err_cnt = 0; \ | |
91 | uint64 __cur_ts = 0; \ | |
92 | static uint8 static_tmp[size]; \ | |
93 | __cur_ts = local_clock(); \ | |
94 | if (__err_ts == 0 || (__cur_ts > __err_ts && \ | |
95 | (__cur_ts - __err_ts > WL_MSG_PRINT_RATE_LIMIT_PERIOD)) || \ | |
96 | memcmp(&static_tmp, cmp, size)) { \ | |
97 | __err_ts = __cur_ts; \ | |
98 | memcpy(static_tmp, cmp, size); \ | |
99 | printk(KERN_ERR "[dhd-%s] %s : [%u times] " arg1, \ | |
100 | name, __func__, __err_cnt, ## args); \ | |
101 | __err_cnt = 0; \ | |
102 | } else { \ | |
103 | ++__err_cnt; \ | |
104 | } \ | |
105 | } \ | |
106 | } while (0) | |
107 | ||
d2839953 RC |
108 | /** |
109 | * wl_android_init will be called from module init function (dhd_module_init now), similarly | |
110 | * wl_android_exit will be called from module exit function (dhd_module_cleanup now) | |
111 | */ | |
112 | int wl_android_init(void); | |
113 | int wl_android_exit(void); | |
114 | void wl_android_post_init(void); | |
115 | int wl_android_wifi_on(struct net_device *dev); | |
116 | int wl_android_wifi_off(struct net_device *dev, bool on_failure); | |
117 | int wl_android_priv_cmd(struct net_device *net, struct ifreq *ifr); | |
118 | int wl_handle_private_cmd(struct net_device *net, char *command, u32 cmd_len); | |
119 | #ifdef WL_EXT_IAPSTA | |
120 | int wl_ext_iapsta_attach_netdev(struct net_device *net, int ifidx, uint8 bssidx); | |
121 | int wl_ext_iapsta_attach_name(struct net_device *net, int ifidx); | |
122 | int wl_ext_iapsta_dettach_netdev(struct net_device *net, int ifidx); | |
3910ce8e LJ |
123 | int wl_ext_iapsta_update_net_device(struct net_device *net, int ifidx); |
124 | void wl_ext_add_remove_pm_enable_work(struct net_device *dev, bool add); | |
125 | #ifdef PROPTX_MAXCOUNT | |
126 | void wl_ext_update_wlfc_maxcount(struct dhd_pub *dhd); | |
127 | int wl_ext_get_wlfc_maxcount(struct dhd_pub *dhd, int ifidx); | |
128 | #endif /* PROPTX_MAXCOUNT */ | |
d2839953 RC |
129 | int wl_ext_iapsta_alive_preinit(struct net_device *dev); |
130 | int wl_ext_iapsta_alive_postinit(struct net_device *dev); | |
d2839953 RC |
131 | int wl_ext_iapsta_attach(dhd_pub_t *pub); |
132 | void wl_ext_iapsta_dettach(dhd_pub_t *pub); | |
965f77c4 | 133 | #ifdef WL_CFG80211 |
3910ce8e | 134 | u32 wl_ext_iapsta_update_channel(dhd_pub_t *dhd, struct net_device *dev, u32 channel); |
965f77c4 | 135 | void wl_ext_iapsta_update_iftype(struct net_device *net, int ifidx, int wl_iftype); |
3910ce8e | 136 | bool wl_ext_iapsta_iftype_enabled(struct net_device *net, int wl_iftype); |
965f77c4 | 137 | void wl_ext_iapsta_ifadding(struct net_device *net, int ifidx); |
3910ce8e | 138 | bool wl_ext_iapsta_mesh_creating(struct net_device *net); |
965f77c4 | 139 | #endif |
d2839953 RC |
140 | extern int op_mode; |
141 | #endif | |
47fa5ad5 RC |
142 | typedef struct bcol_gtk_para { |
143 | int enable; | |
144 | int ptk_len; | |
145 | char ptk[64]; | |
146 | char replay[8]; | |
147 | } bcol_gtk_para_t; | |
3910ce8e LJ |
148 | #define ACS_FW_BIT (1<<0) |
149 | #define ACS_DRV_BIT (1<<1) | |
965f77c4 RC |
150 | #if defined(WL_EXT_IAPSTA) || defined(USE_IW) |
151 | typedef enum WL_EVENT_PRIO { | |
152 | PRIO_EVENT_IAPSTA, | |
153 | PRIO_EVENT_ESCAN, | |
154 | PRIO_EVENT_WEXT | |
155 | }wl_event_prio_t; | |
156 | s32 wl_ext_event_attach(struct net_device *dev, dhd_pub_t *dhdp); | |
157 | void wl_ext_event_dettach(dhd_pub_t *dhdp); | |
158 | int wl_ext_event_attach_netdev(struct net_device *net, int ifidx, uint8 bssidx); | |
159 | int wl_ext_event_dettach_netdev(struct net_device *net, int ifidx); | |
160 | int wl_ext_event_register(struct net_device *dev, dhd_pub_t *dhd, | |
161 | uint32 event, void *cb_func, void *data, wl_event_prio_t prio); | |
162 | void wl_ext_event_deregister(struct net_device *dev, dhd_pub_t *dhd, | |
163 | uint32 event, void *cb_func); | |
164 | void wl_ext_event_send(void *params, const wl_event_msg_t * e, void *data); | |
165 | #endif | |
3910ce8e | 166 | int wl_ext_autochannel(struct net_device *dev, uint acs, uint32 band); |
d2839953 RC |
167 | int wl_android_ext_priv_cmd(struct net_device *net, char *command, int total_len, |
168 | int *bytes_written); | |
965f77c4 | 169 | void wl_ext_get_sec(struct net_device *dev, int ifmode, char *sec, int total_len); |
3910ce8e LJ |
170 | bool wl_ext_check_scan(struct net_device *dev, dhd_pub_t *dhdp); |
171 | #if defined(WL_CFG80211) || defined(WL_ESCAN) | |
172 | void wl_ext_user_sync(struct dhd_pub *dhd, int ifidx, bool lock); | |
173 | bool wl_ext_event_complete(struct dhd_pub *dhd, int ifidx); | |
174 | #endif | |
175 | #if defined(WL_CFG80211) | |
176 | void wl_ext_bss_iovar_war(struct net_device *dev, s32 *val); | |
177 | #endif | |
d2839953 RC |
178 | enum wl_ext_status { |
179 | WL_EXT_STATUS_DISCONNECTING = 0, | |
180 | WL_EXT_STATUS_DISCONNECTED, | |
181 | WL_EXT_STATUS_SCAN, | |
182 | WL_EXT_STATUS_CONNECTING, | |
183 | WL_EXT_STATUS_CONNECTED, | |
184 | WL_EXT_STATUS_ADD_KEY, | |
185 | WL_EXT_STATUS_AP_ENABLED, | |
186 | WL_EXT_STATUS_DELETE_STA, | |
187 | WL_EXT_STATUS_STA_DISCONNECTED, | |
188 | WL_EXT_STATUS_STA_CONNECTED, | |
189 | WL_EXT_STATUS_AP_DISABLED | |
190 | }; | |
191 | typedef struct wl_conn_info { | |
192 | uint8 bssidx; | |
193 | wlc_ssid_t ssid; | |
194 | struct ether_addr bssid; | |
195 | uint16 channel; | |
196 | } wl_conn_info_t; | |
47fa5ad5 | 197 | #if defined(WL_WIRELESS_EXT) |
d2839953 | 198 | s32 wl_ext_connect(struct net_device *dev, wl_conn_info_t *conn_info); |
47fa5ad5 | 199 | #endif /* defined(WL_WIRELESS_EXT) */ |
d2839953 RC |
200 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)) |
201 | #define strnicmp(str1, str2, len) strncasecmp((str1), (str2), (len)) | |
202 | #endif | |
203 | ||
204 | #ifdef WL_GENL | |
205 | typedef struct bcm_event_hdr { | |
206 | u16 event_type; | |
207 | u16 len; | |
208 | } bcm_event_hdr_t; | |
209 | ||
210 | /* attributes (variables): the index in this enum is used as a reference for the type, | |
211 | * userspace application has to indicate the corresponding type | |
212 | * the policy is used for security considerations | |
213 | */ | |
214 | enum { | |
215 | BCM_GENL_ATTR_UNSPEC, | |
216 | BCM_GENL_ATTR_STRING, | |
217 | BCM_GENL_ATTR_MSG, | |
218 | __BCM_GENL_ATTR_MAX | |
219 | }; | |
220 | #define BCM_GENL_ATTR_MAX (__BCM_GENL_ATTR_MAX - 1) | |
221 | ||
222 | /* commands: enumeration of all commands (functions), | |
223 | * used by userspace application to identify command to be ececuted | |
224 | */ | |
225 | enum { | |
226 | BCM_GENL_CMD_UNSPEC, | |
227 | BCM_GENL_CMD_MSG, | |
228 | __BCM_GENL_CMD_MAX | |
229 | }; | |
230 | #define BCM_GENL_CMD_MAX (__BCM_GENL_CMD_MAX - 1) | |
231 | ||
232 | /* Enum values used by the BCM supplicant to identify the events */ | |
233 | enum { | |
234 | BCM_E_UNSPEC, | |
235 | BCM_E_SVC_FOUND, | |
236 | BCM_E_DEV_FOUND, | |
237 | BCM_E_DEV_LOST, | |
238 | #ifdef BT_WIFI_HANDOVER | |
239 | BCM_E_DEV_BT_WIFI_HO_REQ, | |
240 | #endif // endif | |
241 | BCM_E_MAX | |
242 | }; | |
243 | ||
244 | s32 wl_genl_send_msg(struct net_device *ndev, u32 event_type, | |
245 | const u8 *string, u16 len, u8 *hdr, u16 hdrlen); | |
246 | #endif /* WL_GENL */ | |
247 | s32 wl_netlink_send_msg(int pid, int type, int seq, const void *data, size_t size); | |
248 | ||
249 | /* hostap mac mode */ | |
250 | #define MACLIST_MODE_DISABLED 0 | |
251 | #define MACLIST_MODE_DENY 1 | |
252 | #define MACLIST_MODE_ALLOW 2 | |
253 | ||
254 | /* max number of assoc list */ | |
255 | #define MAX_NUM_OF_ASSOCLIST 64 | |
256 | ||
257 | /* Bandwidth */ | |
258 | #define WL_CH_BANDWIDTH_20MHZ 20 | |
259 | #define WL_CH_BANDWIDTH_40MHZ 40 | |
260 | #define WL_CH_BANDWIDTH_80MHZ 80 | |
261 | /* max number of mac filter list | |
262 | * restrict max number to 10 as maximum cmd string size is 255 | |
263 | */ | |
264 | #define MAX_NUM_MAC_FILT 10 | |
965f77c4 RC |
265 | #define WL_GET_BAND(ch) (((uint)(ch) <= CH_MAX_2G_CHANNEL) ? \ |
266 | WLC_BAND_2G : WLC_BAND_5G) | |
d2839953 RC |
267 | |
268 | int wl_android_set_ap_mac_list(struct net_device *dev, int macmode, struct maclist *maclist); | |
269 | #ifdef WL_BCNRECV | |
270 | extern int wl_android_bcnrecv_config(struct net_device *ndev, char *data, | |
271 | int total_len); | |
272 | extern int wl_android_bcnrecv_stop(struct net_device *ndev, uint reason); | |
273 | extern int wl_android_bcnrecv_resume(struct net_device *ndev); | |
274 | extern int wl_android_bcnrecv_suspend(struct net_device *ndev); | |
965f77c4 RC |
275 | extern int wl_android_bcnrecv_event(struct net_device *ndev, |
276 | uint attr_type, uint status, uint reason, uint8 *data, uint data_len); | |
d2839953 | 277 | #endif /* WL_BCNRECV */ |
965f77c4 RC |
278 | #ifdef WL_CAC_TS |
279 | #define TSPEC_UPLINK_DIRECTION (0 << 5) /* uplink direction traffic stream */ | |
280 | #define TSPEC_DOWNLINK_DIRECTION (1 << 5) /* downlink direction traffic stream */ | |
281 | #define TSPEC_BI_DIRECTION (3 << 5) /* bi direction traffic stream */ | |
282 | #define TSPEC_EDCA_ACCESS (1 << 7) /* EDCA access policy */ | |
283 | #define TSPEC_UAPSD_PSB (1 << 2) /* U-APSD power saving behavior */ | |
284 | #define TSPEC_TSINFO_TID_SHIFT 1 /* TID Shift */ | |
285 | #define TSPEC_TSINFO_PRIO_SHIFT 3 /* PRIO Shift */ | |
286 | #define TSPEC_MAX_ACCESS_CATEGORY 3 | |
287 | #define TSPEC_MAX_USER_PRIO 7 | |
288 | #define TSPEC_MAX_DIALOG_TOKEN 255 | |
289 | #define TSPEC_MAX_SURPLUS_BW 12410 | |
290 | #define TSPEC_MIN_SURPLUS_BW 11210 | |
291 | #define TSPEC_MAX_MSDU_SIZE 1520 | |
292 | #define TSPEC_DEF_MEAN_DATA_RATE 120000 | |
293 | #define TSPEC_DEF_MIN_PHY_RATE 6000000 | |
294 | #define TSPEC_DEF_DIALOG_TOKEN 7 | |
295 | #endif /* WL_CAC_TS */ | |
d2839953 RC |
296 | |
297 | /* terence: | |
298 | * BSSCACHE: Cache bss list | |
299 | * RSSAVG: Average RSSI of BSS list | |
300 | * RSSIOFFSET: RSSI offset | |
301 | * SORT_BSS_BY_RSSI: Sort BSS by RSSI | |
302 | */ | |
303 | //#define BSSCACHE | |
304 | //#define RSSIAVG | |
305 | //#define RSSIOFFSET | |
306 | //#define RSSIOFFSET_NEW | |
307 | //#define SORT_BSS_BY_RSSI | |
308 | ||
309 | #define RSSI_MAXVAL -2 | |
310 | #define RSSI_MINVAL -200 | |
311 | ||
312 | #if defined(ESCAN_RESULT_PATCH) | |
313 | #define REPEATED_SCAN_RESULT_CNT 2 | |
314 | #else | |
315 | #define REPEATED_SCAN_RESULT_CNT 1 | |
316 | #endif | |
317 | ||
318 | #if defined(RSSIAVG) || defined(RSSIOFFSET) | |
319 | extern int g_wifi_on; | |
320 | #endif | |
321 | ||
322 | #if defined(RSSIAVG) | |
323 | #define RSSIAVG_LEN (4*REPEATED_SCAN_RESULT_CNT) | |
324 | #define RSSICACHE_TIMEOUT 15 | |
325 | ||
326 | typedef struct wl_rssi_cache { | |
327 | struct wl_rssi_cache *next; | |
328 | int dirty; | |
329 | struct timeval tv; | |
330 | struct ether_addr BSSID; | |
331 | int16 RSSI[RSSIAVG_LEN]; | |
332 | } wl_rssi_cache_t; | |
333 | ||
334 | typedef struct wl_rssi_cache_ctrl { | |
335 | wl_rssi_cache_t *m_cache_head; | |
336 | } wl_rssi_cache_ctrl_t; | |
337 | ||
338 | void wl_free_rssi_cache(wl_rssi_cache_ctrl_t *rssi_cache_ctrl); | |
339 | void wl_delete_dirty_rssi_cache(wl_rssi_cache_ctrl_t *rssi_cache_ctrl); | |
340 | void wl_delete_disconnected_rssi_cache(wl_rssi_cache_ctrl_t *rssi_cache_ctrl, u8 *bssid); | |
341 | void wl_reset_rssi_cache(wl_rssi_cache_ctrl_t *rssi_cache_ctrl); | |
342 | void wl_update_rssi_cache(wl_rssi_cache_ctrl_t *rssi_cache_ctrl, wl_scan_results_t *ss_list); | |
343 | int wl_update_connected_rssi_cache(struct net_device *net, wl_rssi_cache_ctrl_t *rssi_cache_ctrl, int *rssi_avg); | |
344 | int16 wl_get_avg_rssi(wl_rssi_cache_ctrl_t *rssi_cache_ctrl, void *addr); | |
345 | #endif | |
346 | ||
347 | #if defined(RSSIOFFSET) | |
348 | #define RSSI_OFFSET 5 | |
349 | #if defined(RSSIOFFSET_NEW) | |
350 | #define RSSI_OFFSET_MAXVAL -80 | |
351 | #define RSSI_OFFSET_MINVAL -94 | |
352 | #define RSSI_OFFSET_INTVAL ((RSSI_OFFSET_MAXVAL-RSSI_OFFSET_MINVAL)/RSSI_OFFSET) | |
353 | #endif | |
354 | #define BCM4330_CHIP_ID 0x4330 | |
355 | #define BCM4330B2_CHIP_REV 4 | |
356 | int wl_update_rssi_offset(struct net_device *net, int rssi); | |
357 | #endif | |
358 | ||
359 | #if defined(BSSCACHE) | |
360 | #define BSSCACHE_TIMEOUT 15 | |
361 | ||
362 | typedef struct wl_bss_cache { | |
363 | struct wl_bss_cache *next; | |
364 | int dirty; | |
3910ce8e | 365 | struct osl_timespec tv; |
d2839953 RC |
366 | wl_scan_results_t results; |
367 | } wl_bss_cache_t; | |
368 | ||
369 | typedef struct wl_bss_cache_ctrl { | |
370 | wl_bss_cache_t *m_cache_head; | |
371 | } wl_bss_cache_ctrl_t; | |
372 | ||
373 | void wl_free_bss_cache(wl_bss_cache_ctrl_t *bss_cache_ctrl); | |
374 | void wl_delete_dirty_bss_cache(wl_bss_cache_ctrl_t *bss_cache_ctrl); | |
375 | void wl_delete_disconnected_bss_cache(wl_bss_cache_ctrl_t *bss_cache_ctrl, u8 *bssid); | |
376 | void wl_reset_bss_cache(wl_bss_cache_ctrl_t *bss_cache_ctrl); | |
377 | void wl_update_bss_cache(wl_bss_cache_ctrl_t *bss_cache_ctrl, | |
378 | #if defined(RSSIAVG) | |
379 | wl_rssi_cache_ctrl_t *rssi_cache_ctrl, | |
380 | #endif | |
381 | wl_scan_results_t *ss_list); | |
382 | void wl_release_bss_cache_ctrl(wl_bss_cache_ctrl_t *bss_cache_ctrl); | |
383 | #endif | |
384 | int wl_ext_get_best_channel(struct net_device *net, | |
385 | #if defined(BSSCACHE) | |
386 | wl_bss_cache_ctrl_t *bss_cache_ctrl, | |
387 | #else | |
388 | struct wl_scan_results *bss_list, | |
389 | #endif | |
390 | int ioctl_ver, int *best_2g_ch, int *best_5g_ch | |
391 | ); | |
392 | #endif /* _wl_android_ */ |