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 /*  Key mapping keys require a BSSID */
137 struct ndis_802_11_key {
138 	u32           Length;             /*  Length of this structure */
139 	u32           KeyIndex;
140 	u32           KeyLength;          /*  length of key in bytes */
141 	unsigned char BSSID[ETH_ALEN];
142 	unsigned long long KeyRSC;
143 	u8           KeyMaterial[32];  /* var len depending on above field */
144 };
145 
146 struct ndis_802_11_remove_key {
147 	u32                   Length;        /*  Length */
148 	u32                   KeyIndex;
149 	unsigned char BSSID[ETH_ALEN];
150 };
151 
152 struct ndis_802_11_wep {
153 	u32     Length;        /*  Length of this structure */
154 	u32     KeyIndex;      /*  0 is the per-client key,
155 				  * 1-N are the global keys */
156 	u32     KeyLength;     /*  length of key in bytes */
157 	u8     KeyMaterial[16];/*  variable len depending on above field */
158 };
159 
160 struct ndis_802_11_auth_req {
161 	u32 Length;            /*  Length of structure */
162 	unsigned char Bssid[ETH_ALEN];
163 	u32 Flags;
164 };
165 
166 enum ndis_802_11_status_type {
167 	Ndis802_11StatusType_Authentication,
168 	Ndis802_11StatusType_MediaStreamMode,
169 	Ndis802_11StatusType_PMKID_CandidateList,
170 	Ndis802_11StatusTypeMax    /*  not a real type, defined as
171 				    * an upper bound */
172 };
173 
174 struct ndis_802_11_status_ind {
175 	enum ndis_802_11_status_type StatusType;
176 };
177 
178 /*  mask for authentication/integrity fields */
179 #define NDIS_802_11_AUTH_REQUEST_AUTH_FIELDS        	0x0f
180 #define NDIS_802_11_AUTH_REQUEST_REAUTH			0x01
181 #define NDIS_802_11_AUTH_REQUEST_KEYUPDATE		0x02
182 #define NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR		0x06
183 #define NDIS_802_11_AUTH_REQUEST_GROUP_ERROR		0x0E
184 
185 /*  MIC check time, 60 seconds. */
186 #define MIC_CHECK_TIME	60000000
187 
188 struct ndis_802_11_auth_evt {
189 	struct ndis_802_11_status_ind       Status;
190 	struct ndis_802_11_auth_req  Request[1];
191 };
192 
193 struct ndis_802_11_test {
194 	u32 Length;
195 	u32 Type;
196 	union {
197 		struct ndis_802_11_auth_evt AuthenticationEvent;
198 		NDIS_802_11_RSSI RssiTrigger;
199 	} tt;
200 };
201 
202 #ifndef Ndis802_11APMode
203 #define Ndis802_11APMode (Ndis802_11InfrastructureMax+1)
204 #endif
205 
206 struct wlan_phy_info {
207 	u8	SignalStrength;/* in percentage) */
208 	u8	SignalQuality;/* in percentage) */
209 	u8	Optimum_antenna;  /* for Antenna diversity */
210 	u8	Reserved_0;
211 };
212 
213 struct wlan_bcn_info {
214 	/* these infor get from rtw_get_encrypt_info when
215 	 *	 * translate scan to UI */
216 	u8 encryp_protocol;/* ENCRYP_PROTOCOL_E: OPEN/WEP/WPA/WPA2/WAPI */
217 	int group_cipher; /* WPA/WPA2 group cipher */
218 	int pairwise_cipher;/* WPA/WPA2/WEP pairwise cipher */
219 	int is_8021x;
220 
221 	/* bwmode 20/40 and ch_offset UP/LOW */
222 	unsigned short	ht_cap_info;
223 	unsigned char	ht_info_infos_0;
224 };
225 
226 /* temporally add #pragma pack for structure alignment issue of
227 *   struct wlan_bssid_ex and get_struct wlan_bssid_ex_sz()
228 */
229 struct wlan_bssid_ex {
230 	u32  Length;
231 	unsigned char MacAddress[ETH_ALEN];
232 	u8  Reserved[2];/* 0]: IS beacon frame */
233 	struct ndis_802_11_ssid  Ssid;
234 	u32  Privacy;
235 	NDIS_802_11_RSSI  Rssi;/* in dBM,raw data ,get from PHY) */
236 	enum  NDIS_802_11_NETWORK_TYPE  NetworkTypeInUse;
237 	struct ndis_802_11_config  Configuration;
238 	enum ndis_802_11_network_infra  InfrastructureMode;
239 	unsigned char SupportedRates[NDIS_802_11_LENGTH_RATES_EX];
240 	struct wlan_phy_info	PhyInfo;
241 	u32  IELength;
242 	u8  IEs[MAX_IE_SZ];	/* timestamp, beacon interval, and
243 				 * capability information) */
244 } __packed;
245 
get_wlan_bssid_ex_sz(struct wlan_bssid_ex * bss)246 static inline uint get_wlan_bssid_ex_sz(struct wlan_bssid_ex *bss)
247 {
248 	return sizeof(struct wlan_bssid_ex) - MAX_IE_SZ + bss->IELength;
249 }
250 
251 struct	wlan_network {
252 	struct list_head list;
253 	int	network_type;	/* refer to ieee80211.h for WIRELESS_11B/G */
254 	int	fixed;		/*  set fixed when not to be removed
255 				 *  in site-surveying */
256 	unsigned long	last_scanned; /* timestamp for the network */
257 	int	aid;		/* will only be valid when a BSS is joinned. */
258 	int	join_res;
259 	struct wlan_bssid_ex	network; /* must be the last item */
260 	struct wlan_bcn_info	BcnInfo;
261 };
262 
263 enum VRTL_CARRIER_SENSE {
264 	DISABLE_VCS,
265 	ENABLE_VCS,
266 	AUTO_VCS
267 };
268 
269 enum VCS_TYPE {
270 	NONE_VCS,
271 	RTS_CTS,
272 	CTS_TO_SELF
273 };
274 
275 #define PWR_CAM 0
276 #define PWR_MINPS 1
277 #define PWR_MAXPS 2
278 #define PWR_UAPSD 3
279 #define PWR_VOIP 4
280 
281 enum UAPSD_MAX_SP {
282 	NO_LIMIT,
283 	TWO_MSDU,
284 	FOUR_MSDU,
285 	SIX_MSDU
286 };
287 
288 #define NUM_PRE_AUTH_KEY 16
289 #define NUM_PMKID_CACHE NUM_PRE_AUTH_KEY
290 
291 /*
292 *	WPA2
293 */
294 
295 struct pmkid_candidate {
296 	unsigned char BSSID[ETH_ALEN];
297 	u32 Flags;
298 };
299 
300 struct ndis_802_11_pmkid_list {
301 	u32 Version;       /*  Version of the structure */
302 	u32 NumCandidates; /*  No. of pmkid candidates */
303 	struct pmkid_candidate CandidateList[1];
304 };
305 
306 struct ndis_802_11_auth_encrypt {
307 	enum ndis_802_11_auth_mode AuthModeSupported;
308 	enum ndis_802_11_wep_status EncryptStatusSupported;
309 };
310 
311 struct ndis_802_11_cap {
312 	u32  Length;
313 	u32  Version;
314 	u32  NoOfPMKIDs;
315 	u32  NoOfAuthEncryptPairsSupported;
316 	struct ndis_802_11_auth_encrypt AuthenticationEncryptionSupported[1];
317 };
318 
319 u8 key_2char2num(u8 hch, u8 lch);
320 u8 key_char2num(u8 ch);
321 u8 str_2char2num(u8 hch, u8 lch);
322 
323 #endif /* ifndef WLAN_BSSDEF_H_ */
324