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