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