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