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 */
102enum brcmf_scan_status {
103	BRCMF_SCAN_STATUS_BUSY,
104	BRCMF_SCAN_STATUS_ABORT,
105	BRCMF_SCAN_STATUS_SUPPRESS,
106};
107
108/* dongle configuration */
109struct 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 */
117struct brcmf_cfg80211_security {
118	u32 wpa_versions;
119	u32 auth_type;
120	u32 cipher_pairwise;
121	u32 cipher_group;
122};
123
124enum 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 * enum brcmf_profile_fwauth - firmware authenticator profile
133 *
134 * @BRCMF_PROFILE_FWAUTH_NONE: no firmware authenticator
135 * @BRCMF_PROFILE_FWAUTH_PSK: authenticator for WPA/WPA2-PSK
136 * @BRCMF_PROFILE_FWAUTH_SAE: authenticator for SAE
137 */
138enum brcmf_profile_fwauth {
139	BRCMF_PROFILE_FWAUTH_NONE,
140	BRCMF_PROFILE_FWAUTH_PSK,
141	BRCMF_PROFILE_FWAUTH_SAE
142};
143
144/**
145 * struct brcmf_cfg80211_profile - profile information.
146 *
147 * @bssid: bssid of joined/joining ibss.
148 * @sec: security information.
149 * @key: key information
150 */
151struct brcmf_cfg80211_profile {
152	u8 bssid[ETH_ALEN];
153	struct brcmf_cfg80211_security sec;
154	struct brcmf_wsec_key key[BRCMF_MAX_DEFAULT_KEYS];
155	enum brcmf_profile_fwsup use_fwsup;
156	u16 use_fwauth;
157	bool is_ft;
158};
159
160/**
161 * enum brcmf_vif_status - bit indices for vif status.
162 *
163 * @BRCMF_VIF_STATUS_READY: ready for operation.
164 * @BRCMF_VIF_STATUS_CONNECTING: connect/join in progress.
165 * @BRCMF_VIF_STATUS_CONNECTED: connected/joined successfully.
166 * @BRCMF_VIF_STATUS_DISCONNECTING: disconnect/disable in progress.
167 * @BRCMF_VIF_STATUS_AP_CREATED: AP operation started.
168 * @BRCMF_VIF_STATUS_EAP_SUCCUSS: EAPOL handshake successful.
169 * @BRCMF_VIF_STATUS_ASSOC_SUCCESS: successful SET_SSID received.
170 */
171enum brcmf_vif_status {
172	BRCMF_VIF_STATUS_READY,
173	BRCMF_VIF_STATUS_CONNECTING,
174	BRCMF_VIF_STATUS_CONNECTED,
175	BRCMF_VIF_STATUS_DISCONNECTING,
176	BRCMF_VIF_STATUS_AP_CREATED,
177	BRCMF_VIF_STATUS_EAP_SUCCESS,
178	BRCMF_VIF_STATUS_ASSOC_SUCCESS,
179};
180
181/**
182 * struct vif_saved_ie - holds saved IEs for a virtual interface.
183 *
184 * @probe_req_ie: IE info for probe request.
185 * @probe_res_ie: IE info for probe response.
186 * @beacon_ie: IE info for beacon frame.
187 * @assoc_res_ie: IE info for association response frame.
188 * @probe_req_ie_len: IE info length for probe request.
189 * @probe_res_ie_len: IE info length for probe response.
190 * @beacon_ie_len: IE info length for beacon frame.
191 * @assoc_res_ie_len: IE info length for association response frame.
192 */
193struct vif_saved_ie {
194	u8  probe_req_ie[IE_MAX_LEN];
195	u8  probe_res_ie[IE_MAX_LEN];
196	u8  beacon_ie[IE_MAX_LEN];
197	u8  assoc_req_ie[IE_MAX_LEN];
198	u8  assoc_res_ie[IE_MAX_LEN];
199	u32 probe_req_ie_len;
200	u32 probe_res_ie_len;
201	u32 beacon_ie_len;
202	u32 assoc_req_ie_len;
203	u32 assoc_res_ie_len;
204};
205
206/**
207 * struct brcmf_cfg80211_vif - virtual interface specific information.
208 *
209 * @ifp: lower layer interface pointer
210 * @wdev: wireless device.
211 * @profile: profile information.
212 * @sme_state: SME state using enum brcmf_vif_status bits.
213 * @list: linked list.
214 * @mgmt_rx_reg: registered rx mgmt frame types.
215 * @mbss: Multiple BSS type, set if not first AP (not relevant for P2P).
216 */
217struct brcmf_cfg80211_vif {
218	struct brcmf_if *ifp;
219	struct wireless_dev wdev;
220	struct brcmf_cfg80211_profile profile;
221	unsigned long sme_state;
222	struct vif_saved_ie saved_ie;
223	struct list_head list;
224	u16 mgmt_rx_reg;
225	bool mbss;
226	int is_11d;
227};
228
229/* association inform */
230struct brcmf_cfg80211_connect_info {
231	u8 *req_ie;
232	s32 req_ie_len;
233	u8 *resp_ie;
234	s32 resp_ie_len;
235};
236
237/* assoc ie length */
238struct brcmf_cfg80211_assoc_ielen_le {
239	__le32 req_len;
240	__le32 resp_len;
241};
242
243struct brcmf_cfg80211_edcf_acparam {
244	u8 ACI;
245	u8 ECW;
246	u16 TXOP;        /* stored in network order (ls octet first) */
247};
248
249/* dongle escan state */
250enum wl_escan_state {
251	WL_ESCAN_STATE_IDLE,
252	WL_ESCAN_STATE_SCANNING
253};
254
255struct escan_info {
256	u32 escan_state;
257	u8 *escan_buf;
258	struct wiphy *wiphy;
259	struct brcmf_if *ifp;
260	s32 (*run)(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp,
261		   struct cfg80211_scan_request *request);
262};
263
264/**
265 * struct brcmf_cfg80211_vif_event - virtual interface event information.
266 *
267 * @vif_wq: waitqueue awaiting interface event from firmware.
268 * @vif_event_lock: protects other members in this structure.
269 * @vif_complete: completion for net attach.
270 * @action: either add, change, or delete.
271 * @vif: virtual interface object related to the event.
272 */
273struct brcmf_cfg80211_vif_event {
274	wait_queue_head_t vif_wq;
275	spinlock_t vif_event_lock;
276	u8 action;
277	struct brcmf_cfg80211_vif *vif;
278};
279
280/**
281 * struct brcmf_cfg80211_wowl - wowl related information.
282 *
283 * @active: set on suspend, cleared on resume.
284 * @pre_pmmode: firmware PM mode at entering suspend.
285 * @nd: net dectect data.
286 * @nd_info: helper struct to pass to cfg80211.
287 * @nd_data_wait: wait queue to sync net detect data.
288 * @nd_data_completed: completion for net detect data.
289 * @nd_enabled: net detect enabled.
290 */
291struct brcmf_cfg80211_wowl {
292	bool active;
293	u32 pre_pmmode;
294	struct cfg80211_wowlan_nd_match *nd;
295	struct cfg80211_wowlan_nd_info *nd_info;
296	wait_queue_head_t nd_data_wait;
297	bool nd_data_completed;
298	bool nd_enabled;
299};
300
301/**
302 * struct brcmf_cfg80211_info - dongle private data of cfg80211 interface
303 *
304 * @wiphy: wiphy object for cfg80211 interface.
305 * @ops: pointer to copy of ops as registered with wiphy object.
306 * @conf: dongle configuration.
307 * @p2p: peer-to-peer specific information.
308 * @btcoex: Bluetooth coexistence information.
309 * @scan_request: cfg80211 scan request object.
310 * @usr_sync: mainly for dongle up/down synchronization.
311 * @bss_list: bss_list holding scanned ap information.
312 * @bss_info: bss information for cfg80211 layer.
313 * @conn_info: association info.
314 * @pmk_list: wpa2 pmk list.
315 * @scan_status: scan activity on the dongle.
316 * @pub: common driver information.
317 * @channel: current channel.
318 * @int_escan_map: bucket map for which internal e-scan is done.
319 * @ibss_starter: indicates this sta is ibss starter.
320 * @pwr_save: indicate whether dongle to support power save mode.
321 * @dongle_up: indicate whether dongle up or not.
322 * @roam_on: on/off switch for dongle self-roaming.
323 * @scan_tried: indicates if first scan attempted.
324 * @dcmd_buf: dcmd buffer.
325 * @extra_buf: mainly to grab assoc information.
326 * @debugfsdir: debugfs folder for this device.
327 * @escan_info: escan information.
328 * @escan_timeout: Timer for catch scan timeout.
329 * @escan_timeout_work: scan timeout worker.
330 * @vif_list: linked list of vif instances.
331 * @vif_cnt: number of vif instances.
332 * @vif_event: vif event signalling.
333 * @wowl: wowl related information.
334 * @pno: information of pno module.
335 */
336struct brcmf_cfg80211_info {
337	struct wiphy *wiphy;
338	struct brcmf_cfg80211_conf *conf;
339	struct brcmf_p2p_info p2p;
340	struct brcmf_btcoex_info *btcoex;
341	struct cfg80211_scan_request *scan_request;
342	struct mutex usr_sync;
343	struct wl_cfg80211_bss_info *bss_info;
344	struct brcmf_cfg80211_connect_info conn_info;
345	struct brcmf_pmk_list_le pmk_list;
346	unsigned long scan_status;
347	struct brcmf_pub *pub;
348	u32 channel;
349	u32 int_escan_map;
350	bool ibss_starter;
351	bool pwr_save;
352	bool dongle_up;
353	bool scan_tried;
354	u8 *dcmd_buf;
355	u8 *extra_buf;
356	struct dentry *debugfsdir;
357	struct escan_info escan_info;
358	struct timer_list escan_timeout;
359	struct work_struct escan_timeout_work;
360	struct list_head vif_list;
361	struct brcmf_cfg80211_vif_event vif_event;
362	struct completion vif_disabled;
363	struct brcmu_d11inf d11inf;
364	struct brcmf_assoclist_le assoclist;
365	struct brcmf_cfg80211_wowl wowl;
366	struct brcmf_pno_info *pno;
367	u8 ac_priority[MAX_8021D_PRIO];
368};
369
370/**
371 * struct brcmf_tlv - tag_ID/length/value_buffer tuple.
372 *
373 * @id: tag identifier.
374 * @len: number of bytes in value buffer.
375 * @data: value buffer.
376 */
377struct brcmf_tlv {
378	u8 id;
379	u8 len;
380	u8 data[1];
381};
382
383static inline struct wiphy *cfg_to_wiphy(struct brcmf_cfg80211_info *cfg)
384{
385	return cfg->wiphy;
386}
387
388static inline struct brcmf_cfg80211_info *wiphy_to_cfg(struct wiphy *w)
389{
390	struct brcmf_pub *drvr = wiphy_priv(w);
391	return drvr->config;
392}
393
394static inline struct brcmf_cfg80211_info *wdev_to_cfg(struct wireless_dev *wd)
395{
396	return wiphy_to_cfg(wd->wiphy);
397}
398
399static inline struct brcmf_cfg80211_vif *wdev_to_vif(struct wireless_dev *wdev)
400{
401	return container_of(wdev, struct brcmf_cfg80211_vif, wdev);
402}
403
404static inline
405struct net_device *cfg_to_ndev(struct brcmf_cfg80211_info *cfg)
406{
407	return brcmf_get_ifp(cfg->pub, 0)->ndev;
408}
409
410static inline struct brcmf_cfg80211_info *ndev_to_cfg(struct net_device *ndev)
411{
412	return wdev_to_cfg(ndev->ieee80211_ptr);
413}
414
415static inline struct brcmf_cfg80211_profile *ndev_to_prof(struct net_device *nd)
416{
417	struct brcmf_if *ifp = netdev_priv(nd);
418	return &ifp->vif->profile;
419}
420
421static inline struct brcmf_cfg80211_vif *ndev_to_vif(struct net_device *ndev)
422{
423	struct brcmf_if *ifp = netdev_priv(ndev);
424	return ifp->vif;
425}
426
427static inline struct
428brcmf_cfg80211_connect_info *cfg_to_conn(struct brcmf_cfg80211_info *cfg)
429{
430	return &cfg->conn_info;
431}
432
433struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
434						  struct cfg80211_ops *ops,
435						  bool p2pdev_forced);
436void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg);
437s32 brcmf_cfg80211_up(struct net_device *ndev);
438s32 brcmf_cfg80211_down(struct net_device *ndev);
439struct cfg80211_ops *brcmf_cfg80211_get_ops(struct brcmf_mp_device *settings);
440enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp);
441
442struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
443					   enum nl80211_iftype type);
444void brcmf_free_vif(struct brcmf_cfg80211_vif *vif);
445
446s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag,
447			  const u8 *vndr_ie_buf, u32 vndr_ie_len);
448s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif);
449u16 channel_to_chanspec(struct brcmu_d11inf *d11inf,
450			struct ieee80211_channel *ch);
451bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg,
452			     unsigned long state);
453void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
454				  struct brcmf_cfg80211_vif *vif);
455bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg);
456int brcmf_cfg80211_wait_vif_event(struct brcmf_cfg80211_info *cfg,
457				  u8 action, ulong timeout);
458s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
459				struct brcmf_if *ifp, bool aborted,
460				bool fw_abort);
461void brcmf_set_mpc(struct brcmf_if *ndev, int mpc);
462void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg);
463void brcmf_cfg80211_free_netdev(struct net_device *ndev);
464
465#endif /* BRCMFMAC_CFG80211_H */
466