wifi: add bcm driver 1.579.77.41.1 (r)
[GitHub/LineageOS/G12/android_hardware_amlogic_kernel-modules_dhd-driver.git] / bcmdhd.1.579.77.41.1.cn / wl_android.h
1 /*
2 * Linux cfg80211 driver - Android related functions
3 *
4 * Copyright (C) 1999-2017, Broadcom Corporation
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 *
27 * $Id: wl_android.h 607319 2015-12-18 14:16:55Z $
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
37 /* If any feature uses the Generic Netlink Interface, put it here to enable WL_GENL
38 * automatically
39 */
40 #if defined(BT_WIFI_HANDOVER)
41 #define WL_GENL
42 #endif
43
44
45
46 typedef struct _android_wifi_priv_cmd {
47 char *buf;
48 int used_len;
49 int total_len;
50 } android_wifi_priv_cmd;
51
52 #ifdef CONFIG_COMPAT
53 typedef struct _compat_android_wifi_priv_cmd {
54 compat_caddr_t buf;
55 int used_len;
56 int total_len;
57 } compat_android_wifi_priv_cmd;
58 #endif /* CONFIG_COMPAT */
59
60 /**
61 * Android platform dependent functions, feel free to add Android specific functions here
62 * (save the macros in dhd). Please do NOT declare functions that are NOT exposed to dhd
63 * or cfg, define them as static in wl_android.c
64 */
65
66 /* message levels */
67 #define ANDROID_ERROR_LEVEL 0x0001
68 #define ANDROID_TRACE_LEVEL 0x0002
69 #define ANDROID_INFO_LEVEL 0x0004
70
71 #define ANDROID_ERROR(x) \
72 do { \
73 if (android_msg_level & ANDROID_ERROR_LEVEL) { \
74 printk(KERN_ERR "ANDROID-ERROR) "); \
75 printk x; \
76 } \
77 } while (0)
78 #define ANDROID_TRACE(x) \
79 do { \
80 if (android_msg_level & ANDROID_TRACE_LEVEL) { \
81 printk(KERN_ERR "ANDROID-TRACE) "); \
82 printk x; \
83 } \
84 } while (0)
85 #define ANDROID_INFO(x) \
86 do { \
87 if (android_msg_level & ANDROID_INFO_LEVEL) { \
88 printk(KERN_ERR "ANDROID-INFO) "); \
89 printk x; \
90 } \
91 } while (0)
92
93 /**
94 * wl_android_init will be called from module init function (dhd_module_init now), similarly
95 * wl_android_exit will be called from module exit function (dhd_module_cleanup now)
96 */
97 int wl_android_init(void);
98 int wl_android_exit(void);
99 void wl_android_post_init(void);
100 int wl_android_wifi_on(struct net_device *dev);
101 int wl_android_wifi_off(struct net_device *dev, bool on_failure);
102 int wl_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd);
103 int wl_handle_private_cmd(struct net_device *net, char *command, u32 cmd_len);
104
105 s32 wl_netlink_send_msg(int pid, int type, int seq, const void *data, size_t size);
106 #ifdef WL_EXT_IAPSTA
107 int wl_android_ext_attach_netdev(struct net_device *net, uint8 bssidx);
108 int wl_android_ext_dettach_netdev(void);
109 void wl_android_ext_iapsta_disconnect_sta(struct net_device *dev, u32 channel);
110 #endif
111 int wl_android_ext_priv_cmd(struct net_device *net, char *command, int total_len,
112 int *bytes_written);
113 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0))
114 #define strnicmp(str1, str2, len) strncasecmp((str1), (str2), (len))
115 #endif
116
117 typedef enum IF_STATE {
118 IF_STATE_INIT = 1,
119 IF_STATE_DISALBE,
120 IF_STATE_ENABLE
121 } if_state_t;
122
123 typedef enum APSTAMODE {
124 ISTAONLY_MODE = 1,
125 IAPONLY_MODE,
126 IAPSTA_MODE,
127 IDUALAP_MODE,
128 IGOSTA_MODE,
129 IGCSTA_MODE
130 } apstamode_t;
131
132 typedef enum IFMODE {
133 ISTA_MODE = 1,
134 IAP_MODE
135 } ifmode_t;
136
137 typedef enum BGNMODE {
138 IEEE80211B = 1,
139 IEEE80211G,
140 IEEE80211BG,
141 IEEE80211BGN,
142 IEEE80211BGNAC
143 } bgnmode_t;
144
145 typedef enum AUTHMODE {
146 AUTH_OPEN,
147 AUTH_SHARED,
148 AUTH_WPAPSK,
149 AUTH_WPA2PSK,
150 AUTH_WPAWPA2PSK
151 } authmode_t;
152
153 typedef enum ENCMODE {
154 ENC_NONE,
155 ENC_WEP,
156 ENC_TKIP,
157 ENC_AES,
158 ENC_TKIPAES
159 } encmode_t;
160
161 /* i/f query */
162 typedef struct wl_if_info {
163 struct net_device *dev;
164 if_state_t ifstate;
165 ifmode_t ifmode;
166 uint bssidx;
167 char ifname[IFNAMSIZ+1];
168 char ssid[DOT11_MAX_SSID_LEN];
169 struct ether_addr bssid;
170 bgnmode_t bgnmode;
171 int hidden;
172 int maxassoc;
173 uint16 channel;
174 authmode_t amode;
175 encmode_t emode;
176 char key[100];
177 } wl_apsta_if_t;
178
179 typedef struct wl_apsta_params {
180 struct wl_if_info pif; // primary device
181 struct wl_if_info vif; // virtual device
182 int ioctl_ver;
183 bool init;
184 apstamode_t apstamode;
185 } wl_apsta_params_t;
186
187 /* hostap mac mode */
188 #define MACLIST_MODE_DISABLED 0
189 #define MACLIST_MODE_DENY 1
190 #define MACLIST_MODE_ALLOW 2
191
192 /* max number of assoc list */
193 #define MAX_NUM_OF_ASSOCLIST 64
194
195 /* Bandwidth */
196 #define WL_CH_BANDWIDTH_20MHZ 20
197 #define WL_CH_BANDWIDTH_40MHZ 40
198 #define WL_CH_BANDWIDTH_80MHZ 80
199 /* max number of mac filter list
200 * restrict max number to 10 as maximum cmd string size is 255
201 */
202 #define MAX_NUM_MAC_FILT 10
203
204 int wl_android_set_ap_mac_list(struct net_device *dev, int macmode, struct maclist *maclist);
205
206 /* terence:
207 * BSSCACHE: Cache bss list
208 * RSSAVG: Average RSSI of BSS list
209 * RSSIOFFSET: RSSI offset
210 * SORT_BSS_BY_RSSI: Sort BSS by RSSI
211 */
212 //#define BSSCACHE
213 //#define RSSIAVG
214 //#define RSSIOFFSET
215 //#define RSSIOFFSET_NEW
216 //#define SORT_BSS_BY_RSSI
217
218 #define RSSI_MAXVAL -2
219 #define RSSI_MINVAL -200
220
221 #if defined(ESCAN_RESULT_PATCH)
222 #define REPEATED_SCAN_RESULT_CNT 2
223 #else
224 #define REPEATED_SCAN_RESULT_CNT 1
225 #endif
226
227 #if defined(RSSIAVG)
228 #define RSSIAVG_LEN (4*REPEATED_SCAN_RESULT_CNT)
229 #define RSSICACHE_TIMEOUT 15
230
231 typedef struct wl_rssi_cache {
232 struct wl_rssi_cache *next;
233 int dirty;
234 struct timeval tv;
235 struct ether_addr BSSID;
236 int16 RSSI[RSSIAVG_LEN];
237 } wl_rssi_cache_t;
238
239 typedef struct wl_rssi_cache_ctrl {
240 wl_rssi_cache_t *m_cache_head;
241 } wl_rssi_cache_ctrl_t;
242
243 void wl_free_rssi_cache(wl_rssi_cache_ctrl_t *rssi_cache_ctrl);
244 void wl_delete_dirty_rssi_cache(wl_rssi_cache_ctrl_t *rssi_cache_ctrl);
245 void wl_delete_disconnected_rssi_cache(wl_rssi_cache_ctrl_t *rssi_cache_ctrl, u8 *bssid);
246 void wl_reset_rssi_cache(wl_rssi_cache_ctrl_t *rssi_cache_ctrl);
247 void wl_update_rssi_cache(wl_rssi_cache_ctrl_t *rssi_cache_ctrl, wl_scan_results_t *ss_list);
248 int wl_update_connected_rssi_cache(struct net_device *net, wl_rssi_cache_ctrl_t *rssi_cache_ctrl, int *rssi_avg);
249 int16 wl_get_avg_rssi(wl_rssi_cache_ctrl_t *rssi_cache_ctrl, void *addr);
250 #endif
251
252 #if defined(RSSIOFFSET)
253 #define RSSI_OFFSET 5
254 #if defined(RSSIOFFSET_NEW)
255 #define RSSI_OFFSET_MAXVAL -80
256 #define RSSI_OFFSET_MINVAL -94
257 #define RSSI_OFFSET_INTVAL ((RSSI_OFFSET_MAXVAL-RSSI_OFFSET_MINVAL)/RSSI_OFFSET)
258 #endif
259 #define BCM4330_CHIP_ID 0x4330
260 #define BCM4330B2_CHIP_REV 4
261 int wl_update_rssi_offset(struct net_device *net, int rssi);
262 #endif
263
264 #if defined(BSSCACHE)
265 #define BSSCACHE_TIMEOUT 15
266
267 typedef struct wl_bss_cache {
268 struct wl_bss_cache *next;
269 int dirty;
270 struct timeval tv;
271 wl_scan_results_t results;
272 } wl_bss_cache_t;
273
274 typedef struct wl_bss_cache_ctrl {
275 wl_bss_cache_t *m_cache_head;
276 } wl_bss_cache_ctrl_t;
277
278 void wl_free_bss_cache(wl_bss_cache_ctrl_t *bss_cache_ctrl);
279 void wl_delete_dirty_bss_cache(wl_bss_cache_ctrl_t *bss_cache_ctrl);
280 void wl_delete_disconnected_bss_cache(wl_bss_cache_ctrl_t *bss_cache_ctrl, u8 *bssid);
281 void wl_reset_bss_cache(wl_bss_cache_ctrl_t *bss_cache_ctrl);
282 void wl_update_bss_cache(wl_bss_cache_ctrl_t *bss_cache_ctrl,
283 #if defined(RSSIAVG)
284 wl_rssi_cache_ctrl_t *rssi_cache_ctrl,
285 #endif
286 wl_scan_results_t *ss_list);
287 void wl_release_bss_cache_ctrl(wl_bss_cache_ctrl_t *bss_cache_ctrl);
288 #endif
289 #endif /* _wl_android_ */