xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/wl_android.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Linux cfg80211 driver - Android related functions
3  *
4  * Copyright (C) 2020, Broadcom.
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  *
21  * <<Broadcom-WL-IPTag/Dual:>>
22  */
23 
24 #ifndef _wl_android_
25 #define _wl_android_
26 
27 #include <linux/module.h>
28 #include <linux/netdevice.h>
29 #include <wldev_common.h>
30 #include <dngl_stats.h>
31 #include <dhd.h>
32 #include <wl_android_ext.h>
33 #ifdef WL_EXT_IAPSTA
34 #ifdef WL_ESCAN
35 #include <wl_escan.h>
36 #endif /* WL_ESCAN */
37 #include <wl_iapsta.h>
38 #endif /* WL_IAPSTA */
39 #if defined(WL_EXT_IAPSTA) || defined(USE_IW) || defined(WL_ESCAN) || \
40 	(defined(WL_EXT_GENL) && defined(SENDPROB))
41 #ifndef WL_EVENT
42 #define WL_EVENT
43 #endif
44 #include <wl_event.h>
45 #endif
46 
47 /* If any feature uses the Generic Netlink Interface, put it here to enable WL_GENL
48  * automatically
49  */
50 #if defined(WL_SDO) || defined(BT_WIFI_HANDOVER)
51 #define WL_GENL
52 #endif
53 
54 #ifdef WL_GENL
55 #include <net/genetlink.h>
56 #endif
57 
58 typedef struct _android_wifi_priv_cmd {
59     char *buf;
60     int used_len;
61     int total_len;
62 } android_wifi_priv_cmd;
63 
64 #ifdef CONFIG_COMPAT
65 typedef struct _compat_android_wifi_priv_cmd {
66     compat_caddr_t buf;
67     int used_len;
68     int total_len;
69 } compat_android_wifi_priv_cmd;
70 #endif /* CONFIG_COMPAT */
71 
72 /**
73  * Android platform dependent functions, feel free to add Android specific functions here
74  * (save the macros in dhd). Please do NOT declare functions that are NOT exposed to dhd
75  * or cfg, define them as static in wl_android.c
76  */
77 
78 /* message levels */
79 #define ANDROID_ERROR_LEVEL	(1 << 0)
80 #define ANDROID_TRACE_LEVEL	(1 << 1)
81 #define ANDROID_INFO_LEVEL	(1 << 2)
82 #define ANDROID_SCAN_LEVEL	(1 << 3)
83 #define ANDROID_DBG_LEVEL	(1 << 4)
84 #define ANDROID_TPUT_LEVEL	(1 << 8)
85 #define ANDROID_MSG_LEVEL	(1 << 0)
86 
87 #define WL_MSG(name, arg1, args...) \
88 	do { \
89 		if (android_msg_level & ANDROID_MSG_LEVEL) { \
90 			printf("[%s] %s : " arg1, name, __func__, ## args); \
91 		} \
92 	} while (0)
93 
94 #define WL_MSG_PRINT_RATE_LIMIT_PERIOD 1000000000u /* 1s in units of ns */
95 #define WL_MSG_RLMT(name, cmp, size, arg1, args...) \
96 do {	\
97 	if (android_msg_level & ANDROID_MSG_LEVEL) {	\
98 		static uint64 __err_ts = 0; \
99 		static uint32 __err_cnt = 0; \
100 		uint64 __cur_ts = 0; \
101 		static uint8 static_tmp[size]; \
102 		__cur_ts = osl_localtime_ns(); \
103 		if (__err_ts == 0 || (__cur_ts > __err_ts && \
104 		(__cur_ts - __err_ts > WL_MSG_PRINT_RATE_LIMIT_PERIOD)) || \
105 		memcmp(&static_tmp, cmp, size)) { \
106 			__err_ts = __cur_ts; \
107 			memcpy(static_tmp, cmp, size); \
108 			printf("[%s] %s : [%u times] " arg1, \
109 				name, __func__, __err_cnt, ## args); \
110 			__err_cnt = 0; \
111 		} else { \
112 			++__err_cnt; \
113 		} \
114 	}	\
115 } while (0)
116 
117 /**
118  * wl_android_init will be called from module init function (dhd_module_init now), similarly
119  * wl_android_exit will be called from module exit function (dhd_module_cleanup now)
120  */
121 int wl_android_init(void);
122 int wl_android_exit(void);
123 void wl_android_post_init(void);
124 void wl_android_set_wifi_on_flag(bool enable);
125 #if defined(WLAN_ACCEL_BOOT)
126 int wl_android_wifi_accel_on(struct net_device *dev, bool force_reg_on);
127 int wl_android_wifi_accel_off(struct net_device *dev, bool force_reg_on);
128 #endif /* WLAN_ACCEL_BOOT */
129 int wl_android_wifi_on(struct net_device *dev);
130 int wl_android_wifi_off(struct net_device *dev, bool on_failure);
131 int wl_android_priv_cmd(struct net_device *net, struct ifreq *ifr);
132 int wl_handle_private_cmd(struct net_device *net, char *command, u32 cmd_len);
133 #ifdef WL_CFG80211
134 int wl_android_set_spect(struct net_device *dev, int spect);
135 s32 wl_android_get_band_chanspecs(struct net_device *ndev, void *buf, s32 buflen,
136 	chanspec_band_t band, bool acs_req);
137 #endif
138 
139 #ifdef WL_GENL
140 typedef struct bcm_event_hdr {
141 	u16 event_type;
142 	u16 len;
143 } bcm_event_hdr_t;
144 
145 /* attributes (variables): the index in this enum is used as a reference for the type,
146  *             userspace application has to indicate the corresponding type
147  *             the policy is used for security considerations
148  */
149 enum {
150 	BCM_GENL_ATTR_UNSPEC,
151 	BCM_GENL_ATTR_STRING,
152 	BCM_GENL_ATTR_MSG,
153 	__BCM_GENL_ATTR_MAX
154 };
155 #define BCM_GENL_ATTR_MAX (__BCM_GENL_ATTR_MAX - 1)
156 
157 /* commands: enumeration of all commands (functions),
158  * used by userspace application to identify command to be ececuted
159  */
160 enum {
161 	BCM_GENL_CMD_UNSPEC,
162 	BCM_GENL_CMD_MSG,
163 	__BCM_GENL_CMD_MAX
164 };
165 #define BCM_GENL_CMD_MAX (__BCM_GENL_CMD_MAX - 1)
166 
167 /* Enum values used by the BCM supplicant to identify the events */
168 enum {
169 	BCM_E_UNSPEC,
170 	BCM_E_SVC_FOUND,
171 	BCM_E_DEV_FOUND,
172 	BCM_E_DEV_LOST,
173 #ifdef BT_WIFI_HANDOVER
174 	BCM_E_DEV_BT_WIFI_HO_REQ,
175 #endif
176 	BCM_E_MAX
177 };
178 
179 s32 wl_genl_send_msg(struct net_device *ndev, u32 event_type,
180 	const u8 *string, u16 len, u8 *hdr, u16 hdrlen);
181 #endif /* WL_GENL */
182 s32 wl_netlink_send_msg(int pid, int type, int seq, const void *data, size_t size);
183 
184 /* hostap mac mode */
185 #define MACLIST_MODE_DISABLED   0
186 #define MACLIST_MODE_DENY       1
187 #define MACLIST_MODE_ALLOW      2
188 
189 /* max number of assoc list */
190 #define MAX_NUM_OF_ASSOCLIST    64
191 
192 /* Bandwidth */
193 #define WL_CH_BANDWIDTH_20MHZ 20
194 #define WL_CH_BANDWIDTH_40MHZ 40
195 #define WL_CH_BANDWIDTH_80MHZ 80
196 #define WL_CH_BANDWIDTH_160MHZ 160
197 
198 /* max number of mac filter list
199  * restrict max number to 10 as maximum cmd string size is 255
200  */
201 #define MAX_NUM_MAC_FILT        10
202 #define	WL_GET_BAND(ch)	(((uint)(ch) <= CH_MAX_2G_CHANNEL) ?	\
203 	WLC_BAND_2G : WLC_BAND_5G)
204 
205 /* SoftAP auto channel feature */
206 #define APCS_BAND_2G_LEGACY1	20
207 #define APCS_BAND_2G_LEGACY2	0
208 #define APCS_BAND_AUTO		"band=auto"
209 #define APCS_BAND_2G		"band=2g"
210 #define APCS_BAND_5G		"band=5g"
211 #define APCS_BAND_6G		"band=6g"
212 #define FREQ_STR		"freq="
213 #define APCS_MAX_2G_CHANNELS	11
214 #define APCS_MAX_RETRY		10
215 #define APCS_DEFAULT_2G_CH	1
216 #define APCS_DEFAULT_5G_CH	149
217 #define APCS_DEFAULT_6G_CH	5
218 
219 int wl_android_set_ap_mac_list(struct net_device *dev, int macmode, struct maclist *maclist);
220 #ifdef WL_BCNRECV
221 extern int wl_android_bcnrecv_config(struct net_device *ndev, char *data,
222 		int total_len);
223 extern int wl_android_bcnrecv_stop(struct net_device *ndev, uint reason);
224 extern int wl_android_bcnrecv_resume(struct net_device *ndev);
225 extern int wl_android_bcnrecv_suspend(struct net_device *ndev);
226 extern int wl_android_bcnrecv_event(struct net_device *ndev,
227 		uint attr_type, uint status, uint reason, uint8 *data, uint data_len);
228 #endif /* WL_BCNRECV */
229 #ifdef WL_CAC_TS
230 #define TSPEC_UPLINK_DIRECTION (0 << 5)	/* uplink direction traffic stream */
231 #define TSPEC_DOWNLINK_DIRECTION (1 << 5)	/* downlink direction traffic stream */
232 #define TSPEC_BI_DIRECTION (3 << 5)	/* bi direction traffic stream */
233 #define TSPEC_EDCA_ACCESS (1 << 7)	/* EDCA access policy */
234 #define TSPEC_UAPSD_PSB (1 << 2)		/* U-APSD power saving behavior */
235 #define TSPEC_TSINFO_TID_SHIFT 1		/* TID Shift */
236 #define TSPEC_TSINFO_PRIO_SHIFT 3		/* PRIO Shift */
237 #define TSPEC_MAX_ACCESS_CATEGORY 3
238 #define TSPEC_MAX_USER_PRIO	7
239 #define TSPEC_MAX_DIALOG_TOKEN	255
240 #define TSPEC_MAX_SURPLUS_BW 12410
241 #define TSPEC_MIN_SURPLUS_BW 11210
242 #define TSPEC_MAX_MSDU_SIZE 1520
243 #define TSPEC_DEF_MEAN_DATA_RATE 120000
244 #define TSPEC_DEF_MIN_PHY_RATE 6000000
245 #define TSPEC_DEF_DIALOG_TOKEN 7
246 #endif /* WL_CAC_TS */
247 
248 #ifdef WL_SUPPORT_AUTO_CHANNEL
249 #define WLC_ACS_BAND_INVALID	0xffffu
250 #endif /* WL_SUPPORT_AUTO_CHANNEL */
251 #define WL_PRIV_CMD_LEN 64
252 #endif /* _wl_android_ */
253