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 #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 45 46 47 48 typedef struct _android_wifi_priv_cmd { 49 char *buf; 50 int used_len; 51 int total_len; 52 } android_wifi_priv_cmd; 53 54 #ifdef CONFIG_COMPAT 55 typedef struct _compat_android_wifi_priv_cmd { 56 compat_caddr_t buf; 57 int used_len; 58 int total_len; 59 } compat_android_wifi_priv_cmd; 60 #endif /* CONFIG_COMPAT */ 61 62 /** 63 * Android platform dependent functions, feel free to add Android specific functions here 64 * (save the macros in dhd). Please do NOT declare functions that are NOT exposed to dhd 65 * or cfg, define them as static in wl_android.c 66 */ 67 68 /* message levels */ 69 #define ANDROID_ERROR_LEVEL 0x0001 70 #define ANDROID_TRACE_LEVEL 0x0002 71 #define ANDROID_INFO_LEVEL 0x0004 72 #define ANDROID_EVENT_LEVEL 0x0008 73 74 #define ANDROID_MSG(x) \ 75 do { \ 76 if (android_msg_level & ANDROID_ERROR_LEVEL) { \ 77 printk(KERN_ERR "ANDROID-MSG) "); \ 78 printk x; \ 79 } \ 80 } while (0) 81 #define ANDROID_ERROR(x) \ 82 do { \ 83 if (android_msg_level & ANDROID_ERROR_LEVEL) { \ 84 printk(KERN_ERR "ANDROID-ERROR) "); \ 85 printk x; \ 86 } \ 87 } while (0) 88 #define ANDROID_TRACE(x) \ 89 do { \ 90 if (android_msg_level & ANDROID_TRACE_LEVEL) { \ 91 printk(KERN_ERR "ANDROID-TRACE) "); \ 92 printk x; \ 93 } \ 94 } while (0) 95 #define ANDROID_INFO(x) \ 96 do { \ 97 if (android_msg_level & ANDROID_INFO_LEVEL) { \ 98 printk(KERN_ERR "ANDROID-INFO) "); \ 99 printk x; \ 100 } \ 101 } while (0) 102 #define ANDROID_EVENT(x) \ 103 do { \ 104 if (android_msg_level & ANDROID_EVENT_LEVEL) { \ 105 printk(KERN_ERR "ANDROID-EVENT) "); \ 106 printk x; \ 107 } \ 108 } while (0) 109 110 /** 111 * wl_android_init will be called from module init function (dhd_module_init now), similarly 112 * wl_android_exit will be called from module exit function (dhd_module_cleanup now) 113 */ 114 int wl_android_init(void); 115 int wl_android_exit(void); 116 void wl_android_post_init(void); 117 int wl_android_wifi_on(struct net_device *dev); 118 int wl_android_wifi_off(struct net_device *dev, bool on_failure); 119 int wl_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd); 120 int wl_handle_private_cmd(struct net_device *net, char *command, u32 cmd_len); 121 122 s32 wl_netlink_send_msg(int pid, int type, int seq, const void *data, size_t size); 123 #ifdef WL_EXT_IAPSTA 124 int wl_ext_iapsta_attach_netdev(struct net_device *net, int ifidx, uint8 bssidx); 125 int wl_ext_iapsta_attach_name(struct net_device *net, int ifidx); 126 int wl_ext_iapsta_dettach_netdev(struct net_device *net, int ifidx); 127 u32 wl_ext_iapsta_update_channel(struct net_device *dev, u32 channel); 128 int wl_ext_iapsta_alive_preinit(struct net_device *dev); 129 int wl_ext_iapsta_alive_postinit(struct net_device *dev); 130 int wl_ext_iapsta_event(struct net_device *dev, wl_event_msg_t *e, void* data); 131 int wl_ext_iapsta_attach(dhd_pub_t *pub); 132 void wl_ext_iapsta_dettach(dhd_pub_t *pub); 133 bool wl_ext_check_mesh_creating(struct net_device *net); 134 extern int op_mode; 135 #endif 136 typedef struct bcol_gtk_para { 137 int enable; 138 int ptk_len; 139 char ptk[64]; 140 char replay[8]; 141 } bcol_gtk_para_t; 142 int wl_android_ext_priv_cmd(struct net_device *net, char *command, int total_len, 143 int *bytes_written); 144 enum wl_ext_status { 145 WL_EXT_STATUS_DISCONNECTING = 0, 146 WL_EXT_STATUS_DISCONNECTED, 147 WL_EXT_STATUS_SCAN, 148 WL_EXT_STATUS_CONNECTING, 149 WL_EXT_STATUS_CONNECTED, 150 WL_EXT_STATUS_ADD_KEY, 151 WL_EXT_STATUS_AP_ENABLED, 152 WL_EXT_STATUS_DELETE_STA, 153 WL_EXT_STATUS_STA_DISCONNECTED, 154 WL_EXT_STATUS_STA_CONNECTED, 155 WL_EXT_STATUS_AP_DISABLED 156 }; 157 typedef struct wl_conn_info { 158 struct net_device *dev; 159 dhd_pub_t *dhd; 160 uint8 bssidx; 161 wlc_ssid_t ssid; 162 struct ether_addr bssid; 163 uint16 channel; 164 struct delayed_work pm_enable_work; 165 struct mutex pm_sync; 166 } wl_conn_info_t; 167 #if defined(WL_WIRELESS_EXT) 168 s32 wl_ext_connect(struct net_device *dev, wl_conn_info_t *conn_info); 169 void wl_ext_pm_work_handler(struct work_struct *work); 170 void wl_ext_add_remove_pm_enable_work(struct wl_conn_info *conn_info, bool add); 171 #endif /* defined(WL_WIRELESS_EXT) */ 172 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)) 173 #define strnicmp(str1, str2, len) strncasecmp((str1), (str2), (len)) 174 #endif 175 176 /* hostap mac mode */ 177 #define MACLIST_MODE_DISABLED 0 178 #define MACLIST_MODE_DENY 1 179 #define MACLIST_MODE_ALLOW 2 180 181 /* max number of assoc list */ 182 #define MAX_NUM_OF_ASSOCLIST 64 183 184 /* Bandwidth */ 185 #define WL_CH_BANDWIDTH_20MHZ 20 186 #define WL_CH_BANDWIDTH_40MHZ 40 187 #define WL_CH_BANDWIDTH_80MHZ 80 188 /* max number of mac filter list 189 * restrict max number to 10 as maximum cmd string size is 255 190 */ 191 #define MAX_NUM_MAC_FILT 10 192 193 int wl_android_set_ap_mac_list(struct net_device *dev, int macmode, struct maclist *maclist); 194 195 /* terence: 196 * BSSCACHE: Cache bss list 197 * RSSAVG: Average RSSI of BSS list 198 * RSSIOFFSET: RSSI offset 199 * SORT_BSS_BY_RSSI: Sort BSS by RSSI 200 */ 201 202 #define RSSI_MAXVAL -2 203 #define RSSI_MINVAL -200 204 205 #if defined(ESCAN_RESULT_PATCH) 206 #define REPEATED_SCAN_RESULT_CNT 2 207 #else 208 #define REPEATED_SCAN_RESULT_CNT 1 209 #endif 210 211 #if defined(RSSIAVG) || defined(RSSIOFFSET) 212 extern int g_wifi_on; 213 #endif 214 215 #if defined(RSSIAVG) 216 #define RSSIAVG_LEN (4*REPEATED_SCAN_RESULT_CNT) 217 #define RSSICACHE_TIMEOUT 15 218 219 typedef struct wl_rssi_cache { 220 struct wl_rssi_cache *next; 221 int dirty; 222 struct timeval tv; 223 struct ether_addr BSSID; 224 int16 RSSI[RSSIAVG_LEN]; 225 } wl_rssi_cache_t; 226 227 typedef struct wl_rssi_cache_ctrl { 228 wl_rssi_cache_t *m_cache_head; 229 } wl_rssi_cache_ctrl_t; 230 231 void wl_free_rssi_cache(wl_rssi_cache_ctrl_t *rssi_cache_ctrl); 232 void wl_delete_dirty_rssi_cache(wl_rssi_cache_ctrl_t *rssi_cache_ctrl); 233 void wl_delete_disconnected_rssi_cache(wl_rssi_cache_ctrl_t *rssi_cache_ctrl, u8 *bssid); 234 void wl_reset_rssi_cache(wl_rssi_cache_ctrl_t *rssi_cache_ctrl); 235 void wl_update_rssi_cache(wl_rssi_cache_ctrl_t *rssi_cache_ctrl, wl_scan_results_t *ss_list); 236 int wl_update_connected_rssi_cache(struct net_device *net, wl_rssi_cache_ctrl_t *rssi_cache_ctrl, int *rssi_avg); 237 int16 wl_get_avg_rssi(wl_rssi_cache_ctrl_t *rssi_cache_ctrl, void *addr); 238 #endif 239 240 #if defined(RSSIOFFSET) 241 #define RSSI_OFFSET 5 242 #if defined(RSSIOFFSET_NEW) 243 #define RSSI_OFFSET_MAXVAL -80 244 #define RSSI_OFFSET_MINVAL -94 245 #define RSSI_OFFSET_INTVAL ((RSSI_OFFSET_MAXVAL-RSSI_OFFSET_MINVAL)/RSSI_OFFSET) 246 #endif 247 #define BCM4330_CHIP_ID 0x4330 248 #define BCM4330B2_CHIP_REV 4 249 int wl_update_rssi_offset(struct net_device *net, int rssi); 250 #endif 251 252 #if defined(BSSCACHE) 253 #define BSSCACHE_TIMEOUT 15 254 255 typedef struct wl_bss_cache { 256 struct wl_bss_cache *next; 257 int dirty; 258 struct timeval tv; 259 wl_scan_results_t results; 260 } wl_bss_cache_t; 261 262 typedef struct wl_bss_cache_ctrl { 263 wl_bss_cache_t *m_cache_head; 264 } wl_bss_cache_ctrl_t; 265 266 void wl_free_bss_cache(wl_bss_cache_ctrl_t *bss_cache_ctrl); 267 void wl_delete_dirty_bss_cache(wl_bss_cache_ctrl_t *bss_cache_ctrl); 268 void wl_delete_disconnected_bss_cache(wl_bss_cache_ctrl_t *bss_cache_ctrl, u8 *bssid); 269 void wl_reset_bss_cache(wl_bss_cache_ctrl_t *bss_cache_ctrl); 270 void wl_update_bss_cache(wl_bss_cache_ctrl_t *bss_cache_ctrl, 271 #if defined(RSSIAVG) 272 wl_rssi_cache_ctrl_t *rssi_cache_ctrl, 273 #endif 274 wl_scan_results_t *ss_list); 275 void wl_release_bss_cache_ctrl(wl_bss_cache_ctrl_t *bss_cache_ctrl); 276 #endif 277 int wl_ext_get_best_channel(struct net_device *net, 278 #if defined(BSSCACHE) 279 wl_bss_cache_ctrl_t *bss_cache_ctrl, 280 #else 281 struct wl_scan_results *bss_list, 282 #endif 283 int ioctl_ver, int *best_2g_ch, int *best_5g_ch 284 ); 285 #endif /* _wl_android_ */ 286