1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /* Copyright(c) 2007 - 2011 Realtek Corporation. */
3 
4 #ifndef __WLAN_BSSDEF_H__
5 #define __WLAN_BSSDEF_H__
6 
7 #define MAX_IE_SZ			768
8 
9 #define NDIS_802_11_LENGTH_SSID         32
10 #define NDIS_802_11_LENGTH_RATES        8
11 #define NDIS_802_11_LENGTH_RATES_EX     16
12 
13 #define NDIS_802_11_RSSI long           /*  in dBm */
14 
15 struct ndis_802_11_ssid {
16 	u32  SsidLength;
17 	u8  Ssid[32];
18 };
19 
20 enum NDIS_802_11_NETWORK_TYPE {
21 	Ndis802_11FH,
22 	Ndis802_11DS,
23 	Ndis802_11OFDM5,
24 	Ndis802_11OFDM24,
25 	Ndis802_11NetworkTypeMax    /*  dummy upper bound */
26 };
27 
28 struct ndis_802_11_config_fh {
29 	u32           Length;		/*  Length of structure */
30 	u32           HopPattern;	/*  As defined by 802.11, MSB set */
31 	u32           HopSet;		/*  to one if non-802.11 */
32 	u32           DwellTime;	/*  units are Kusec */
33 };
34 
35 /*
36  *	FW will only save the channel number in DSConfig.
37  *	ODI Handler will convert the channel number to freq. number.
38  */
39 struct ndis_802_11_config {
40 	u32           Length;             /*  Length of structure */
41 	u32           BeaconPeriod;       /*  units are Kusec */
42 	u32           ATIMWindow;         /*  units are Kusec */
43 	u32           DSConfig;           /*  Frequency, units are kHz */
44 	struct ndis_802_11_config_fh    FHConfig;
45 };
46 
47 enum ndis_802_11_network_infra {
48 	Ndis802_11IBSS,
49 	Ndis802_11Infrastructure,
50 	Ndis802_11AutoUnknown,
51 	Ndis802_11InfrastructureMax,     /*  dummy upper bound */
52 	Ndis802_11APMode
53 };
54 
55 struct ndis_802_11_fixed_ie {
56 	u8  Timestamp[8];
57 	u16  BeaconInterval;
58 	u16  Capabilities;
59 };
60 
61 struct ndis_802_11_var_ie {
62 	u8  ElementID;
63 	u8  Length;
64 	u8  data[];
65 };
66 
67 /*
68  * Length is the 4 bytes multiples of the sume of
69  *	[ETH_ALEN] + 2 + sizeof (struct ndis_802_11_ssid) + sizeof (u32)
70  *	+ sizeof (NDIS_802_11_RSSI) + sizeof (enum NDIS_802_11_NETWORK_TYPE)
71  *	+ sizeof (struct ndis_802_11_config)
72  *	+ NDIS_802_11_LENGTH_RATES_EX + IELength
73  *
74  * Except the IELength, all other fields are fixed length.
75  * Therefore, we can define a macro to represent the partial sum. */
76 
77 enum ndis_802_11_auth_mode {
78 	Ndis802_11AuthModeOpen,
79 	Ndis802_11AuthModeShared,
80 	Ndis802_11AuthModeAutoSwitch,
81 	Ndis802_11AuthModeWPA,
82 	Ndis802_11AuthModeWPAPSK,
83 	Ndis802_11AuthModeWPANone,
84 	Ndis802_11AuthModeWAPI,
85 	Ndis802_11AuthModeMax	/*  Not a real mode, upper bound */
86 };
87 
88 enum ndis_802_11_wep_status {
89 	Ndis802_11WEPEnabled,
90 	Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled,
91 	Ndis802_11WEPDisabled,
92 	Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled,
93 	Ndis802_11WEPKeyAbsent,
94 	Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent,
95 	Ndis802_11WEPNotSupported,
96 	Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported,
97 	Ndis802_11Encryption2Enabled,
98 	Ndis802_11Encryption2KeyAbsent,
99 	Ndis802_11Encryption3Enabled,
100 	Ndis802_11Encryption3KeyAbsent,
101 	Ndis802_11_EncryptionWAPI
102 };
103 
104 #define NDIS_802_11_AI_REQFI_CAPABILITIES      1
105 #define NDIS_802_11_AI_REQFI_LISTENINTERVAL    2
106 #define NDIS_802_11_AI_REQFI_CURRENTAPADDRESS  4
107 
108 #define NDIS_802_11_AI_RESFI_CAPABILITIES      1
109 #define NDIS_802_11_AI_RESFI_STATUSCODE        2
110 #define NDIS_802_11_AI_RESFI_ASSOCIATIONID     4
111 
112 struct ndis_802_11_ai_reqfi {
113     u16 Capabilities;
114     u16 ListenInterval;
115     unsigned char CurrentAPAddress[ETH_ALEN];
116 };
117 
118 struct ndis_802_11_ai_resfi {
119     u16 Capabilities;
120     u16 StatusCode;
121     u16 AssociationId;
122 };
123 
124 struct ndis_802_11_assoc_info {
125 	u32  Length;
126 	u16 AvailableRequestFixedIEs;
127 	struct ndis_802_11_ai_reqfi    RequestFixedIEs;
128 	u32  RequestIELength;
129 	u32  OffsetRequestIEs;
130 	u16 AvailableResponseFixedIEs;
131 	struct ndis_802_11_ai_resfi    ResponseFixedIEs;
132 	u32  ResponseIELength;
133 	u32  OffsetResponseIEs;
134 };
135 
136 enum ndis_802_11_reload_def {
137 	Ndis802_11ReloadWEPKeys
138 };
139 
140 /*  Key mapping keys require a BSSID */
141 struct ndis_802_11_key {
142 	u32           Length;             /*  Length of this structure */
143 	u32           KeyIndex;
144 	u32           KeyLength;          /*  length of key in bytes */
145 	unsigned char BSSID[ETH_ALEN];
146 	unsigned long long KeyRSC;
147 	u8           KeyMaterial[32];  /* var len depending on above field */
148 };
149 
150 struct ndis_802_11_remove_key {
151 	u32                   Length;        /*  Length */
152 	u32                   KeyIndex;
153 	unsigned char BSSID[ETH_ALEN];
154 };
155 
156 struct ndis_802_11_wep {
157 	u32     Length;        /*  Length of this structure */
158 	u32     KeyIndex;      /*  0 is the per-client key,
159 				  * 1-N are the global keys */
160 	u32     KeyLength;     /*  length of key in bytes */
161 	u8     KeyMaterial[16];/*  variable len depending on above field */
162 };
163 
164 struct ndis_802_11_auth_req {
165 	u32 Length;            /*  Length of structure */
166 	unsigned char Bssid[ETH_ALEN];
167 	u32 Flags;
168 };
169 
170 enum ndis_802_11_status_type {
171 	Ndis802_11StatusType_Authentication,
172 	Ndis802_11StatusType_MediaStreamMode,
173 	Ndis802_11StatusType_PMKID_CandidateList,
174 	Ndis802_11StatusTypeMax    /*  not a real type, defined as
175 				    * an upper bound */
176 };
177 
178 struct ndis_802_11_status_ind {
179 	enum ndis_802_11_status_type StatusType;
180 };
181 
182 /*  mask for authentication/integrity fields */
183 #define NDIS_802_11_AUTH_REQUEST_AUTH_FIELDS        	0x0f
184 #define NDIS_802_11_AUTH_REQUEST_REAUTH			0x01
185 #define NDIS_802_11_AUTH_REQUEST_KEYUPDATE		0x02
186 #define NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR		0x06
187 #define NDIS_802_11_AUTH_REQUEST_GROUP_ERROR		0x0E
188 
189 /*  MIC check time, 60 seconds. */
190 #define MIC_CHECK_TIME	60000000
191 
192 struct ndis_802_11_auth_evt {
193 	struct ndis_802_11_status_ind       Status;
194 	struct ndis_802_11_auth_req  Request[1];
195 };
196 
197 struct ndis_802_11_test {
198 	u32 Length;
199 	u32 Type;
200 	union {
201 		struct ndis_802_11_auth_evt AuthenticationEvent;
202 		NDIS_802_11_RSSI RssiTrigger;
203 	} tt;
204 };
205 
206 #ifndef Ndis802_11APMode
207 #define Ndis802_11APMode (Ndis802_11InfrastructureMax+1)
208 #endif
209 
210 struct wlan_phy_info {
211 	u8	SignalStrength;/* in percentage) */
212 	u8	SignalQuality;/* in percentage) */
213 	u8	Optimum_antenna;  /* for Antenna diversity */
214 	u8	Reserved_0;
215 };
216 
217 struct wlan_bcn_info {
218 	/* these infor get from rtw_get_encrypt_info when
219 	 *	 * translate scan to UI */
220 	u8 encryp_protocol;/* ENCRYP_PROTOCOL_E: OPEN/WEP/WPA/WPA2/WAPI */
221 	int group_cipher; /* WPA/WPA2 group cipher */
222 	int pairwise_cipher;/* WPA/WPA2/WEP pairwise cipher */
223 	int is_8021x;
224 
225 	/* bwmode 20/40 and ch_offset UP/LOW */
226 	unsigned short	ht_cap_info;
227 	unsigned char	ht_info_infos_0;
228 };
229 
230 /* temporally add #pragma pack for structure alignment issue of
231 *   struct wlan_bssid_ex and get_struct wlan_bssid_ex_sz()
232 */
233 struct wlan_bssid_ex {
234 	u32  Length;
235 	unsigned char MacAddress[ETH_ALEN];
236 	u8  Reserved[2];/* 0]: IS beacon frame */
237 	struct ndis_802_11_ssid  Ssid;
238 	u32  Privacy;
239 	NDIS_802_11_RSSI  Rssi;/* in dBM,raw data ,get from PHY) */
240 	enum  NDIS_802_11_NETWORK_TYPE  NetworkTypeInUse;
241 	struct ndis_802_11_config  Configuration;
242 	enum ndis_802_11_network_infra  InfrastructureMode;
243 	unsigned char SupportedRates[NDIS_802_11_LENGTH_RATES_EX];
244 	struct wlan_phy_info	PhyInfo;
245 	u32  IELength;
246 	u8  IEs[MAX_IE_SZ];	/* timestamp, beacon interval, and
247 				 * capability information) */
248 } __packed;
249 
get_wlan_bssid_ex_sz(struct wlan_bssid_ex * bss)250 static inline uint get_wlan_bssid_ex_sz(struct wlan_bssid_ex *bss)
251 {
252 	return sizeof(struct wlan_bssid_ex) - MAX_IE_SZ + bss->IELength;
253 }
254 
255 struct	wlan_network {
256 	struct list_head list;
257 	int	network_type;	/* refer to ieee80211.h for WIRELESS_11B/G */
258 	int	fixed;		/*  set fixed when not to be removed
259 				 *  in site-surveying */
260 	unsigned long	last_scanned; /* timestamp for the network */
261 	int	aid;		/* will only be valid when a BSS is joinned. */
262 	int	join_res;
263 	struct wlan_bssid_ex	network; /* must be the last item */
264 	struct wlan_bcn_info	BcnInfo;
265 };
266 
267 enum VRTL_CARRIER_SENSE {
268 	DISABLE_VCS,
269 	ENABLE_VCS,
270 	AUTO_VCS
271 };
272 
273 enum VCS_TYPE {
274 	NONE_VCS,
275 	RTS_CTS,
276 	CTS_TO_SELF
277 };
278 
279 #define PWR_CAM 0
280 #define PWR_MINPS 1
281 #define PWR_MAXPS 2
282 #define PWR_UAPSD 3
283 #define PWR_VOIP 4
284 
285 enum UAPSD_MAX_SP {
286 	NO_LIMIT,
287 	TWO_MSDU,
288 	FOUR_MSDU,
289 	SIX_MSDU
290 };
291 
292 #define NUM_PRE_AUTH_KEY 16
293 #define NUM_PMKID_CACHE NUM_PRE_AUTH_KEY
294 
295 /*
296 *	WPA2
297 */
298 
299 struct pmkid_candidate {
300 	unsigned char BSSID[ETH_ALEN];
301 	u32 Flags;
302 };
303 
304 struct ndis_802_11_pmkid_list {
305 	u32 Version;       /*  Version of the structure */
306 	u32 NumCandidates; /*  No. of pmkid candidates */
307 	struct pmkid_candidate CandidateList[1];
308 };
309 
310 struct ndis_802_11_auth_encrypt {
311 	enum ndis_802_11_auth_mode AuthModeSupported;
312 	enum ndis_802_11_wep_status EncryptStatusSupported;
313 };
314 
315 struct ndis_802_11_cap {
316 	u32  Length;
317 	u32  Version;
318 	u32  NoOfPMKIDs;
319 	u32  NoOfAuthEncryptPairsSupported;
320 	struct ndis_802_11_auth_encrypt AuthenticationEncryptionSupported[1];
321 };
322 
323 u8 key_2char2num(u8 hch, u8 lch);
324 u8 key_char2num(u8 ch);
325 u8 str_2char2num(u8 hch, u8 lch);
326 
327 #endif /* ifndef WLAN_BSSDEF_H_ */
328