1 // SPDX-License-Identifier: ISC 2 /* 3 * Copyright (c) 2010 Broadcom Corporation 4 */ 5 6 #ifndef BRCMFMAC_CFG80211_H 7 #define BRCMFMAC_CFG80211_H 8 9 /* for brcmu_d11inf */ 10 #include <brcmu_d11.h> 11 12 #include "core.h" 13 #include "fwil_types.h" 14 #include "p2p.h" 15 16 #define BRCMF_SCAN_IE_LEN_MAX 2048 17 18 #define WL_NUM_SCAN_MAX 10 19 #define WL_TLV_INFO_MAX 1024 20 #define WL_BSS_INFO_MAX 2048 21 #define WL_ASSOC_INFO_MAX 512 /* assoc related fil max buf */ 22 #define WL_EXTRA_BUF_MAX 2048 23 #define WL_ROAM_TRIGGER_LEVEL -75 24 #define WL_ROAM_DELTA 20 25 26 /* WME Access Category Indices (ACIs) */ 27 #define AC_BE 0 /* Best Effort */ 28 #define AC_BK 1 /* Background */ 29 #define AC_VI 2 /* Video */ 30 #define AC_VO 3 /* Voice */ 31 #define EDCF_AC_COUNT 4 32 #define MAX_8021D_PRIO 8 33 34 #define EDCF_ACI_MASK 0x60 35 #define EDCF_ACI_SHIFT 5 36 #define EDCF_ACM_MASK 0x10 37 #define EDCF_ECWMIN_MASK 0x0f 38 #define EDCF_ECWMAX_SHIFT 4 39 #define EDCF_AIFSN_MASK 0x0f 40 #define EDCF_AIFSN_MAX 15 41 #define EDCF_ECWMAX_MASK 0xf0 42 43 /* Keep BRCMF_ESCAN_BUF_SIZE below 64K (65536). Allocing over 64K can be 44 * problematic on some systems and should be avoided. 45 */ 46 #define BRCMF_ESCAN_BUF_SIZE 65000 47 #define BRCMF_ESCAN_TIMER_INTERVAL_MS 10000 /* E-Scan timeout */ 48 49 #define WL_ESCAN_ACTION_START 1 50 #define WL_ESCAN_ACTION_CONTINUE 2 51 #define WL_ESCAN_ACTION_ABORT 3 52 53 #define WL_AUTH_SHARED_KEY 1 /* d11 shared authentication */ 54 #define IE_MAX_LEN 512 55 56 /* IE TLV processing */ 57 #define TLV_LEN_OFF 1 /* length offset */ 58 #define TLV_HDR_LEN 2 /* header length */ 59 #define TLV_BODY_OFF 2 /* body offset */ 60 #define TLV_OUI_LEN 3 /* oui id length */ 61 62 /* 802.11 Mgmt Packet flags */ 63 #define BRCMF_VNDR_IE_BEACON_FLAG 0x1 64 #define BRCMF_VNDR_IE_PRBRSP_FLAG 0x2 65 #define BRCMF_VNDR_IE_ASSOCRSP_FLAG 0x4 66 #define BRCMF_VNDR_IE_AUTHRSP_FLAG 0x8 67 #define BRCMF_VNDR_IE_PRBREQ_FLAG 0x10 68 #define BRCMF_VNDR_IE_ASSOCREQ_FLAG 0x20 69 /* vendor IE in IW advertisement protocol ID field */ 70 #define BRCMF_VNDR_IE_IWAPID_FLAG 0x40 71 /* allow custom IE id */ 72 #define BRCMF_VNDR_IE_CUSTOM_FLAG 0x100 73 74 /* P2P Action Frames flags (spec ordered) */ 75 #define BRCMF_VNDR_IE_GONREQ_FLAG 0x001000 76 #define BRCMF_VNDR_IE_GONRSP_FLAG 0x002000 77 #define BRCMF_VNDR_IE_GONCFM_FLAG 0x004000 78 #define BRCMF_VNDR_IE_INVREQ_FLAG 0x008000 79 #define BRCMF_VNDR_IE_INVRSP_FLAG 0x010000 80 #define BRCMF_VNDR_IE_DISREQ_FLAG 0x020000 81 #define BRCMF_VNDR_IE_DISRSP_FLAG 0x040000 82 #define BRCMF_VNDR_IE_PRDREQ_FLAG 0x080000 83 #define BRCMF_VNDR_IE_PRDRSP_FLAG 0x100000 84 85 #define BRCMF_VNDR_IE_P2PAF_SHIFT 12 86 87 #define BRCMF_MAX_DEFAULT_KEYS 6 88 89 /* beacon loss timeout defaults */ 90 #define BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_ON 2 91 #define BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_OFF 4 92 93 #define BRCMF_VIF_EVENT_TIMEOUT msecs_to_jiffies(1500) 94 95 /** 96 * enum brcmf_scan_status - scan engine status 97 * 98 * @BRCMF_SCAN_STATUS_BUSY: scanning in progress on dongle. 99 * @BRCMF_SCAN_STATUS_ABORT: scan being aborted on dongle. 100 * @BRCMF_SCAN_STATUS_SUPPRESS: scanning is suppressed in driver. 101 */ 102 enum brcmf_scan_status { 103 BRCMF_SCAN_STATUS_BUSY, 104 BRCMF_SCAN_STATUS_ABORT, 105 BRCMF_SCAN_STATUS_SUPPRESS, 106 }; 107 108 /* dongle configuration */ 109 struct brcmf_cfg80211_conf { 110 u32 frag_threshold; 111 u32 rts_threshold; 112 u32 retry_short; 113 u32 retry_long; 114 }; 115 116 /* security information with currently associated ap */ 117 struct brcmf_cfg80211_security { 118 u32 wpa_versions; 119 u32 auth_type; 120 u32 cipher_pairwise; 121 u32 cipher_group; 122 }; 123 124 enum brcmf_profile_fwsup { 125 BRCMF_PROFILE_FWSUP_NONE, 126 BRCMF_PROFILE_FWSUP_PSK, 127 BRCMF_PROFILE_FWSUP_1X, 128 BRCMF_PROFILE_FWSUP_SAE 129 }; 130 131 /** 132 * struct brcmf_cfg80211_profile - profile information. 133 * 134 * @bssid: bssid of joined/joining ibss. 135 * @sec: security information. 136 * @key: key information 137 */ 138 struct brcmf_cfg80211_profile { 139 u8 bssid[ETH_ALEN]; 140 struct brcmf_cfg80211_security sec; 141 struct brcmf_wsec_key key[BRCMF_MAX_DEFAULT_KEYS]; 142 enum brcmf_profile_fwsup use_fwsup; 143 bool is_ft; 144 }; 145 146 /** 147 * enum brcmf_vif_status - bit indices for vif status. 148 * 149 * @BRCMF_VIF_STATUS_READY: ready for operation. 150 * @BRCMF_VIF_STATUS_CONNECTING: connect/join in progress. 151 * @BRCMF_VIF_STATUS_CONNECTED: connected/joined successfully. 152 * @BRCMF_VIF_STATUS_DISCONNECTING: disconnect/disable in progress. 153 * @BRCMF_VIF_STATUS_AP_CREATED: AP operation started. 154 * @BRCMF_VIF_STATUS_EAP_SUCCUSS: EAPOL handshake successful. 155 * @BRCMF_VIF_STATUS_ASSOC_SUCCESS: successful SET_SSID received. 156 */ 157 enum brcmf_vif_status { 158 BRCMF_VIF_STATUS_READY, 159 BRCMF_VIF_STATUS_CONNECTING, 160 BRCMF_VIF_STATUS_CONNECTED, 161 BRCMF_VIF_STATUS_DISCONNECTING, 162 BRCMF_VIF_STATUS_AP_CREATED, 163 BRCMF_VIF_STATUS_EAP_SUCCESS, 164 BRCMF_VIF_STATUS_ASSOC_SUCCESS, 165 }; 166 167 /** 168 * struct vif_saved_ie - holds saved IEs for a virtual interface. 169 * 170 * @probe_req_ie: IE info for probe request. 171 * @probe_res_ie: IE info for probe response. 172 * @beacon_ie: IE info for beacon frame. 173 * @assoc_res_ie: IE info for association response frame. 174 * @probe_req_ie_len: IE info length for probe request. 175 * @probe_res_ie_len: IE info length for probe response. 176 * @beacon_ie_len: IE info length for beacon frame. 177 * @assoc_res_ie_len: IE info length for association response frame. 178 */ 179 struct vif_saved_ie { 180 u8 probe_req_ie[IE_MAX_LEN]; 181 u8 probe_res_ie[IE_MAX_LEN]; 182 u8 beacon_ie[IE_MAX_LEN]; 183 u8 assoc_req_ie[IE_MAX_LEN]; 184 u8 assoc_res_ie[IE_MAX_LEN]; 185 u32 probe_req_ie_len; 186 u32 probe_res_ie_len; 187 u32 beacon_ie_len; 188 u32 assoc_req_ie_len; 189 u32 assoc_res_ie_len; 190 }; 191 192 /** 193 * struct brcmf_cfg80211_vif - virtual interface specific information. 194 * 195 * @ifp: lower layer interface pointer 196 * @wdev: wireless device. 197 * @profile: profile information. 198 * @sme_state: SME state using enum brcmf_vif_status bits. 199 * @list: linked list. 200 * @mgmt_rx_reg: registered rx mgmt frame types. 201 * @mbss: Multiple BSS type, set if not first AP (not relevant for P2P). 202 */ 203 struct brcmf_cfg80211_vif { 204 struct brcmf_if *ifp; 205 struct wireless_dev wdev; 206 struct brcmf_cfg80211_profile profile; 207 unsigned long sme_state; 208 struct vif_saved_ie saved_ie; 209 struct list_head list; 210 u16 mgmt_rx_reg; 211 bool mbss; 212 int is_11d; 213 }; 214 215 /* association inform */ 216 struct brcmf_cfg80211_connect_info { 217 u8 *req_ie; 218 s32 req_ie_len; 219 u8 *resp_ie; 220 s32 resp_ie_len; 221 }; 222 223 /* assoc ie length */ 224 struct brcmf_cfg80211_assoc_ielen_le { 225 __le32 req_len; 226 __le32 resp_len; 227 }; 228 229 struct brcmf_cfg80211_edcf_acparam { 230 u8 ACI; 231 u8 ECW; 232 u16 TXOP; /* stored in network order (ls octet first) */ 233 }; 234 235 /* dongle escan state */ 236 enum wl_escan_state { 237 WL_ESCAN_STATE_IDLE, 238 WL_ESCAN_STATE_SCANNING 239 }; 240 241 struct escan_info { 242 u32 escan_state; 243 u8 *escan_buf; 244 struct wiphy *wiphy; 245 struct brcmf_if *ifp; 246 s32 (*run)(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp, 247 struct cfg80211_scan_request *request); 248 }; 249 250 /** 251 * struct brcmf_cfg80211_vif_event - virtual interface event information. 252 * 253 * @vif_wq: waitqueue awaiting interface event from firmware. 254 * @vif_event_lock: protects other members in this structure. 255 * @vif_complete: completion for net attach. 256 * @action: either add, change, or delete. 257 * @vif: virtual interface object related to the event. 258 */ 259 struct brcmf_cfg80211_vif_event { 260 wait_queue_head_t vif_wq; 261 spinlock_t vif_event_lock; 262 u8 action; 263 struct brcmf_cfg80211_vif *vif; 264 }; 265 266 /** 267 * struct brcmf_cfg80211_wowl - wowl related information. 268 * 269 * @active: set on suspend, cleared on resume. 270 * @pre_pmmode: firmware PM mode at entering suspend. 271 * @nd: net dectect data. 272 * @nd_info: helper struct to pass to cfg80211. 273 * @nd_data_wait: wait queue to sync net detect data. 274 * @nd_data_completed: completion for net detect data. 275 * @nd_enabled: net detect enabled. 276 */ 277 struct brcmf_cfg80211_wowl { 278 bool active; 279 u32 pre_pmmode; 280 struct cfg80211_wowlan_nd_match *nd; 281 struct cfg80211_wowlan_nd_info *nd_info; 282 wait_queue_head_t nd_data_wait; 283 bool nd_data_completed; 284 bool nd_enabled; 285 }; 286 287 /** 288 * struct brcmf_cfg80211_info - dongle private data of cfg80211 interface 289 * 290 * @wiphy: wiphy object for cfg80211 interface. 291 * @ops: pointer to copy of ops as registered with wiphy object. 292 * @conf: dongle configuration. 293 * @p2p: peer-to-peer specific information. 294 * @btcoex: Bluetooth coexistence information. 295 * @scan_request: cfg80211 scan request object. 296 * @usr_sync: mainly for dongle up/down synchronization. 297 * @bss_list: bss_list holding scanned ap information. 298 * @bss_info: bss information for cfg80211 layer. 299 * @conn_info: association info. 300 * @pmk_list: wpa2 pmk list. 301 * @scan_status: scan activity on the dongle. 302 * @pub: common driver information. 303 * @channel: current channel. 304 * @int_escan_map: bucket map for which internal e-scan is done. 305 * @ibss_starter: indicates this sta is ibss starter. 306 * @pwr_save: indicate whether dongle to support power save mode. 307 * @dongle_up: indicate whether dongle up or not. 308 * @roam_on: on/off switch for dongle self-roaming. 309 * @scan_tried: indicates if first scan attempted. 310 * @dcmd_buf: dcmd buffer. 311 * @extra_buf: mainly to grab assoc information. 312 * @debugfsdir: debugfs folder for this device. 313 * @escan_info: escan information. 314 * @escan_timeout: Timer for catch scan timeout. 315 * @escan_timeout_work: scan timeout worker. 316 * @vif_list: linked list of vif instances. 317 * @vif_cnt: number of vif instances. 318 * @vif_event: vif event signalling. 319 * @wowl: wowl related information. 320 * @pno: information of pno module. 321 */ 322 struct brcmf_cfg80211_info { 323 struct wiphy *wiphy; 324 struct brcmf_cfg80211_conf *conf; 325 struct brcmf_p2p_info p2p; 326 struct brcmf_btcoex_info *btcoex; 327 struct cfg80211_scan_request *scan_request; 328 struct mutex usr_sync; 329 struct wl_cfg80211_bss_info *bss_info; 330 struct brcmf_cfg80211_connect_info conn_info; 331 struct brcmf_pmk_list_le pmk_list; 332 unsigned long scan_status; 333 struct brcmf_pub *pub; 334 u32 channel; 335 u32 int_escan_map; 336 bool ibss_starter; 337 bool pwr_save; 338 bool dongle_up; 339 bool scan_tried; 340 u8 *dcmd_buf; 341 u8 *extra_buf; 342 struct dentry *debugfsdir; 343 struct escan_info escan_info; 344 struct timer_list escan_timeout; 345 struct work_struct escan_timeout_work; 346 struct list_head vif_list; 347 struct brcmf_cfg80211_vif_event vif_event; 348 struct completion vif_disabled; 349 struct brcmu_d11inf d11inf; 350 struct brcmf_assoclist_le assoclist; 351 struct brcmf_cfg80211_wowl wowl; 352 struct brcmf_pno_info *pno; 353 u8 ac_priority[MAX_8021D_PRIO]; 354 }; 355 356 /** 357 * struct brcmf_tlv - tag_ID/length/value_buffer tuple. 358 * 359 * @id: tag identifier. 360 * @len: number of bytes in value buffer. 361 * @data: value buffer. 362 */ 363 struct brcmf_tlv { 364 u8 id; 365 u8 len; 366 u8 data[1]; 367 }; 368 369 static inline struct wiphy *cfg_to_wiphy(struct brcmf_cfg80211_info *cfg) 370 { 371 return cfg->wiphy; 372 } 373 374 static inline struct brcmf_cfg80211_info *wiphy_to_cfg(struct wiphy *w) 375 { 376 struct brcmf_pub *drvr = wiphy_priv(w); 377 return drvr->config; 378 } 379 380 static inline struct brcmf_cfg80211_info *wdev_to_cfg(struct wireless_dev *wd) 381 { 382 return wiphy_to_cfg(wd->wiphy); 383 } 384 385 static inline struct brcmf_cfg80211_vif *wdev_to_vif(struct wireless_dev *wdev) 386 { 387 return container_of(wdev, struct brcmf_cfg80211_vif, wdev); 388 } 389 390 static inline 391 struct net_device *cfg_to_ndev(struct brcmf_cfg80211_info *cfg) 392 { 393 return brcmf_get_ifp(cfg->pub, 0)->ndev; 394 } 395 396 static inline struct brcmf_cfg80211_info *ndev_to_cfg(struct net_device *ndev) 397 { 398 return wdev_to_cfg(ndev->ieee80211_ptr); 399 } 400 401 static inline struct brcmf_cfg80211_profile *ndev_to_prof(struct net_device *nd) 402 { 403 struct brcmf_if *ifp = netdev_priv(nd); 404 return &ifp->vif->profile; 405 } 406 407 static inline struct brcmf_cfg80211_vif *ndev_to_vif(struct net_device *ndev) 408 { 409 struct brcmf_if *ifp = netdev_priv(ndev); 410 return ifp->vif; 411 } 412 413 static inline struct 414 brcmf_cfg80211_connect_info *cfg_to_conn(struct brcmf_cfg80211_info *cfg) 415 { 416 return &cfg->conn_info; 417 } 418 419 struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr, 420 struct cfg80211_ops *ops, 421 bool p2pdev_forced); 422 void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg); 423 s32 brcmf_cfg80211_up(struct net_device *ndev); 424 s32 brcmf_cfg80211_down(struct net_device *ndev); 425 struct cfg80211_ops *brcmf_cfg80211_get_ops(struct brcmf_mp_device *settings); 426 enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp); 427 428 struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg, 429 enum nl80211_iftype type); 430 void brcmf_free_vif(struct brcmf_cfg80211_vif *vif); 431 432 s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag, 433 const u8 *vndr_ie_buf, u32 vndr_ie_len); 434 s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif); 435 u16 channel_to_chanspec(struct brcmu_d11inf *d11inf, 436 struct ieee80211_channel *ch); 437 bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg, 438 unsigned long state); 439 void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg, 440 struct brcmf_cfg80211_vif *vif); 441 bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg); 442 int brcmf_cfg80211_wait_vif_event(struct brcmf_cfg80211_info *cfg, 443 u8 action, ulong timeout); 444 s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg, 445 struct brcmf_if *ifp, bool aborted, 446 bool fw_abort); 447 void brcmf_set_mpc(struct brcmf_if *ndev, int mpc); 448 void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg); 449 void brcmf_cfg80211_free_netdev(struct net_device *ndev); 450 451 #endif /* BRCMFMAC_CFG80211_H */ 452