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