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