• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * File: 80211mgr.c
20  *
21  * Purpose: Handles the 802.11 management support functions
22  *
23  * Author: Lyndon Chen
24  *
25  * Date: May 8, 2002
26  *
27  * Functions:
28  *      vMgrEncodeBeacon - Encode the Beacon frame
29  *      vMgrDecodeBeacon - Decode the Beacon frame
30  *      vMgrEncodeIBSSATIM - Encode the IBSS ATIM frame
31  *      vMgrDecodeIBSSATIM - Decode the IBSS ATIM frame
32  *      vMgrEncodeDisassociation - Encode the Disassociation frame
33  *      vMgrDecodeDisassociation - Decode the Disassociation frame
34  *      vMgrEncodeAssocRequest - Encode the Association request frame
35  *      vMgrDecodeAssocRequest - Decode the Association request frame
36  *      vMgrEncodeAssocResponse - Encode the Association response frame
37  *      vMgrDecodeAssocResponse - Decode the Association response frame
38  *      vMgrEncodeReAssocRequest - Encode the ReAssociation request frame
39  *      vMgrDecodeReAssocRequest - Decode the ReAssociation request frame
40  *      vMgrEncodeProbeRequest - Encode the Probe request frame
41  *      vMgrDecodeProbeRequest - Decode the Probe request frame
42  *      vMgrEncodeProbeResponse - Encode the Probe response frame
43  *      vMgrDecodeProbeResponse - Decode the Probe response frame
44  *      vMgrEncodeAuthen - Encode the Authentication frame
45  *      vMgrDecodeAuthen - Decode the Authentication frame
46  *      vMgrEncodeDeauthen - Encode the DeAuthentication frame
47  *      vMgrDecodeDeauthen - Decode the DeAuthentication frame
48  *      vMgrEncodeReassocResponse - Encode the Reassociation response frame
49  *      vMgrDecodeReassocResponse - Decode the Reassociation response frame
50  *
51  * Revision History:
52  *
53  */
54 
55 #include "tmacro.h"
56 #include "tether.h"
57 #include "80211mgr.h"
58 #include "80211hdr.h"
59 #include "device.h"
60 #include "wpa.h"
61 
62 /*---------------------  Static Definitions -------------------------*/
63 
64 /*---------------------  Static Classes  ----------------------------*/
65 
66 /*---------------------  Static Functions  --------------------------*/
67 
68 /*---------------------  Export Variables  --------------------------*/
69 
70 /*---------------------  Export Functions  --------------------------*/
71 
72 /*+
73  *
74  * Routine Description:
75  * Encode Beacon frame body offset
76  *
77  * Return Value:
78  *    None.
79  *
80  -*/
81 
82 void
vMgrEncodeBeacon(PWLAN_FR_BEACON pFrame)83 vMgrEncodeBeacon(
84 	PWLAN_FR_BEACON  pFrame
85 )
86 {
87 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
88 
89 	/* Fixed Fields */
90 	pFrame->pqwTimestamp = (__le64 *)
91 				(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
92 				 WLAN_BEACON_OFF_TS);
93 	pFrame->pwBeaconInterval = (unsigned short *)
94 				(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
95 				 WLAN_BEACON_OFF_BCN_INT);
96 	pFrame->pwCapInfo = (unsigned short *)
97 			    (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
98 			     WLAN_BEACON_OFF_CAPINFO);
99 
100 	pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_BEACON_OFF_SSID;
101 }
102 
103 /*+
104  *
105  * Routine Description:
106  * Decode Beacon frame body offset
107  *
108  *
109  * Return Value:
110  *    None.
111  *
112  -*/
113 
114 void
vMgrDecodeBeacon(PWLAN_FR_BEACON pFrame)115 vMgrDecodeBeacon(
116 	PWLAN_FR_BEACON  pFrame
117 )
118 {
119 	PWLAN_IE        pItem;
120 
121 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
122 
123 	/* Fixed Fields */
124 	pFrame->pqwTimestamp = (__le64 *)
125 				(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
126 				 WLAN_BEACON_OFF_TS);
127 	pFrame->pwBeaconInterval = (unsigned short *)
128 				   (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
129 				    WLAN_BEACON_OFF_BCN_INT);
130 	pFrame->pwCapInfo = (unsigned short *)
131 			    (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
132 			     WLAN_BEACON_OFF_CAPINFO);
133 
134 	/* Information elements */
135 	pItem = (PWLAN_IE)((unsigned char *)
136 			   (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))) +
137 			    WLAN_BEACON_OFF_SSID);
138 	while (((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) {
139 		switch (pItem->byElementID) {
140 		case WLAN_EID_SSID:
141 			if (pFrame->pSSID == NULL)
142 				pFrame->pSSID = (PWLAN_IE_SSID)pItem;
143 			break;
144 		case WLAN_EID_SUPP_RATES:
145 			if (pFrame->pSuppRates == NULL)
146 				pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
147 			break;
148 		case WLAN_EID_FH_PARMS:
149 			/* pFrame->pFHParms = (PWLAN_IE_FH_PARMS)pItem; */
150 			break;
151 		case WLAN_EID_DS_PARMS:
152 			if (pFrame->pDSParms == NULL)
153 				pFrame->pDSParms = (PWLAN_IE_DS_PARMS)pItem;
154 			break;
155 		case WLAN_EID_CF_PARMS:
156 			if (pFrame->pCFParms == NULL)
157 				pFrame->pCFParms = (PWLAN_IE_CF_PARMS)pItem;
158 			break;
159 		case WLAN_EID_IBSS_PARMS:
160 			if (pFrame->pIBSSParms == NULL)
161 				pFrame->pIBSSParms = (PWLAN_IE_IBSS_PARMS)pItem;
162 			break;
163 		case WLAN_EID_TIM:
164 			if (pFrame->pTIM == NULL)
165 				pFrame->pTIM = (PWLAN_IE_TIM)pItem;
166 			break;
167 
168 		case WLAN_EID_RSN:
169 			if (pFrame->pRSN == NULL)
170 				pFrame->pRSN = (PWLAN_IE_RSN)pItem;
171 			break;
172 		case WLAN_EID_RSN_WPA:
173 			if (pFrame->pRSNWPA == NULL) {
174 				if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true)
175 					pFrame->pRSNWPA =
176 						       (PWLAN_IE_RSN_EXT)pItem;
177 			}
178 			break;
179 
180 		case WLAN_EID_ERP:
181 			if (pFrame->pERP == NULL)
182 				pFrame->pERP = (PWLAN_IE_ERP)pItem;
183 			break;
184 		case WLAN_EID_EXTSUPP_RATES:
185 			if (pFrame->pExtSuppRates == NULL)
186 				pFrame->pExtSuppRates =
187 						    (PWLAN_IE_SUPP_RATES)pItem;
188 			break;
189 
190 		case WLAN_EID_COUNTRY:      /* 7 */
191 			if (pFrame->pIE_Country == NULL)
192 				pFrame->pIE_Country = (PWLAN_IE_COUNTRY)pItem;
193 			break;
194 
195 		case WLAN_EID_PWR_CONSTRAINT:   /* 32 */
196 			if (pFrame->pIE_PowerConstraint == NULL)
197 				pFrame->pIE_PowerConstraint =
198 						      (PWLAN_IE_PW_CONST)pItem;
199 			break;
200 
201 		case WLAN_EID_CH_SWITCH:    /* 37 */
202 			if (pFrame->pIE_CHSW == NULL)
203 				pFrame->pIE_CHSW = (PWLAN_IE_CH_SW)pItem;
204 			break;
205 
206 		case WLAN_EID_QUIET:        /* 40 */
207 			if (pFrame->pIE_Quiet == NULL)
208 				pFrame->pIE_Quiet = (PWLAN_IE_QUIET)pItem;
209 			break;
210 
211 		case WLAN_EID_IBSS_DFS:
212 			if (pFrame->pIE_IBSSDFS == NULL)
213 				pFrame->pIE_IBSSDFS = (PWLAN_IE_IBSS_DFS)pItem;
214 			break;
215 
216 		default:
217 			pr_debug("Unrecognized EID=%dd in beacon decode\n",
218 				 pItem->byElementID);
219 			break;
220 
221 		}
222 		pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
223 	}
224 }
225 
226 /*+
227  *
228  * Routine Description:
229  *  Encode IBSS ATIM
230  *
231  *
232  * Return Value:
233  *    None.
234  *
235  -*/
236 
237 void
vMgrEncodeIBSSATIM(PWLAN_FR_IBSSATIM pFrame)238 vMgrEncodeIBSSATIM(
239 	PWLAN_FR_IBSSATIM   pFrame
240 )
241 {
242 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
243 	pFrame->len = WLAN_HDR_ADDR3_LEN;
244 }
245 
246 /*+
247  *
248  * Routine Description:
249  *  Decode IBSS ATIM
250  *
251  *
252  * Return Value:
253  *    None.
254  *
255  -*/
256 
257 void
vMgrDecodeIBSSATIM(PWLAN_FR_IBSSATIM pFrame)258 vMgrDecodeIBSSATIM(
259 	PWLAN_FR_IBSSATIM   pFrame
260 )
261 {
262 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
263 }
264 
265 /*+
266  *
267  * Routine Description:
268  *  Encode Disassociation
269  *
270  *
271  * Return Value:
272  *    None.
273  *
274  -*/
275 
276 void
vMgrEncodeDisassociation(PWLAN_FR_DISASSOC pFrame)277 vMgrEncodeDisassociation(
278 	PWLAN_FR_DISASSOC  pFrame
279 )
280 {
281 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
282 
283 	/* Fixed Fields */
284 	pFrame->pwReason = (unsigned short *)
285 			   (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
286 			    WLAN_DISASSOC_OFF_REASON);
287 	pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_DISASSOC_OFF_REASON +
288 		      sizeof(*(pFrame->pwReason));
289 }
290 
291 /*+
292  *
293  * Routine Description:
294  *  Decode Disassociation
295  *
296  *
297  * Return Value:
298  *    None.
299  *
300  -*/
301 
302 void
vMgrDecodeDisassociation(PWLAN_FR_DISASSOC pFrame)303 vMgrDecodeDisassociation(
304 	PWLAN_FR_DISASSOC  pFrame
305 )
306 {
307 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
308 
309 	/* Fixed Fields */
310 	pFrame->pwReason = (unsigned short *)
311 			   (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
312 			    WLAN_DISASSOC_OFF_REASON);
313 }
314 
315 /*+
316  *
317  * Routine Description:
318  *  Encode Association Request
319  *
320  *
321  * Return Value:
322  *    None.
323  *
324  -*/
325 
326 void
vMgrEncodeAssocRequest(PWLAN_FR_ASSOCREQ pFrame)327 vMgrEncodeAssocRequest(
328 	PWLAN_FR_ASSOCREQ  pFrame
329 )
330 {
331 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
332 	/* Fixed Fields */
333 	pFrame->pwCapInfo = (unsigned short *)
334 			    (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
335 			     WLAN_ASSOCREQ_OFF_CAP_INFO);
336 	pFrame->pwListenInterval = (unsigned short *)
337 				   (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
338 				    WLAN_ASSOCREQ_OFF_LISTEN_INT);
339 	pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_ASSOCREQ_OFF_LISTEN_INT +
340 		      sizeof(*(pFrame->pwListenInterval));
341 }
342 
343 /*+
344  *
345  * Routine Description: (AP)
346  *  Decode Association Request
347  *
348  *
349  * Return Value:
350  *    None.
351  *
352  -*/
353 
354 void
vMgrDecodeAssocRequest(PWLAN_FR_ASSOCREQ pFrame)355 vMgrDecodeAssocRequest(
356 	PWLAN_FR_ASSOCREQ  pFrame
357 )
358 {
359 	PWLAN_IE   pItem;
360 
361 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
362 	/* Fixed Fields */
363 	pFrame->pwCapInfo = (unsigned short *)
364 			    (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
365 			     WLAN_ASSOCREQ_OFF_CAP_INFO);
366 	pFrame->pwListenInterval = (unsigned short *)
367 				   (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
368 				    WLAN_ASSOCREQ_OFF_LISTEN_INT);
369 
370 	/* Information elements */
371 	pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
372 			   + WLAN_ASSOCREQ_OFF_SSID);
373 
374 	while (((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) {
375 		switch (pItem->byElementID) {
376 		case WLAN_EID_SSID:
377 			if (pFrame->pSSID == NULL)
378 				pFrame->pSSID = (PWLAN_IE_SSID)pItem;
379 			break;
380 		case WLAN_EID_SUPP_RATES:
381 			if (pFrame->pSuppRates == NULL)
382 				pFrame->pSuppRates =
383 						   (PWLAN_IE_SUPP_RATES)pItem;
384 			break;
385 
386 		case WLAN_EID_RSN:
387 			if (pFrame->pRSN == NULL)
388 				pFrame->pRSN = (PWLAN_IE_RSN)pItem;
389 			break;
390 		case WLAN_EID_RSN_WPA:
391 			if (pFrame->pRSNWPA == NULL) {
392 				if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true)
393 					pFrame->pRSNWPA =
394 						       (PWLAN_IE_RSN_EXT)pItem;
395 			}
396 			break;
397 		case WLAN_EID_EXTSUPP_RATES:
398 			if (pFrame->pExtSuppRates == NULL)
399 				pFrame->pExtSuppRates =
400 						    (PWLAN_IE_SUPP_RATES)pItem;
401 			break;
402 
403 		default:
404 			pr_debug("Unrecognized EID=%dd in assocreq decode\n",
405 				 pItem->byElementID);
406 			break;
407 		}
408 		pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
409 	}
410 }
411 
412 /*+
413  *
414  * Routine Description: (AP)
415  *  Encode Association Response
416  *
417  *
418  * Return Value:
419  *    None.
420  *
421  -*/
422 
423 void
vMgrEncodeAssocResponse(PWLAN_FR_ASSOCRESP pFrame)424 vMgrEncodeAssocResponse(
425 	PWLAN_FR_ASSOCRESP  pFrame
426 )
427 {
428 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
429 
430 	/* Fixed Fields */
431 	pFrame->pwCapInfo = (unsigned short *)
432 			    (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
433 			     WLAN_ASSOCRESP_OFF_CAP_INFO);
434 	pFrame->pwStatus = (unsigned short *)
435 			   (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
436 			    WLAN_ASSOCRESP_OFF_STATUS);
437 	pFrame->pwAid = (unsigned short *)
438 			(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
439 			 WLAN_ASSOCRESP_OFF_AID);
440 	pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_ASSOCRESP_OFF_AID +
441 		      sizeof(*(pFrame->pwAid));
442 }
443 
444 /*+
445  *
446  * Routine Description:
447  *  Decode Association Response
448  *
449  *
450  * Return Value:
451  *    None.
452  *
453  -*/
454 
455 void
vMgrDecodeAssocResponse(PWLAN_FR_ASSOCRESP pFrame)456 vMgrDecodeAssocResponse(
457 	PWLAN_FR_ASSOCRESP  pFrame
458 )
459 {
460 	PWLAN_IE   pItem;
461 
462 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
463 
464 	/* Fixed Fields */
465 	pFrame->pwCapInfo = (unsigned short *)
466 			    (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
467 			     WLAN_ASSOCRESP_OFF_CAP_INFO);
468 	pFrame->pwStatus = (unsigned short *)
469 			   (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
470 			    WLAN_ASSOCRESP_OFF_STATUS);
471 	pFrame->pwAid = (unsigned short *)
472 			(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
473 			 WLAN_ASSOCRESP_OFF_AID);
474 
475 	/* Information elements */
476 	pFrame->pSuppRates  = (PWLAN_IE_SUPP_RATES)
477 			      (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
478 			       WLAN_ASSOCRESP_OFF_SUPP_RATES);
479 
480 	pItem = (PWLAN_IE)(pFrame->pSuppRates);
481 	pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
482 
483 	if ((((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) &&
484 	    (pItem->byElementID == WLAN_EID_EXTSUPP_RATES)) {
485 		pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
486 		pr_debug("pFrame->pExtSuppRates=[%p]\n", pItem);
487 	} else {
488 		pFrame->pExtSuppRates = NULL;
489 	}
490 }
491 
492 /*+
493  *
494  * Routine Description:
495  *  Encode Reassociation Request
496  *
497  *
498  * Return Value:
499  *    None.
500  *
501  -*/
502 
503 void
vMgrEncodeReassocRequest(PWLAN_FR_REASSOCREQ pFrame)504 vMgrEncodeReassocRequest(
505 	PWLAN_FR_REASSOCREQ  pFrame
506 )
507 {
508 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
509 
510 	/* Fixed Fields */
511 	pFrame->pwCapInfo = (unsigned short *)
512 			    (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
513 			     WLAN_REASSOCREQ_OFF_CAP_INFO);
514 	pFrame->pwListenInterval = (unsigned short *)
515 				   (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
516 				    WLAN_REASSOCREQ_OFF_LISTEN_INT);
517 	pFrame->pAddrCurrAP = (PIEEE_ADDR)
518 			      (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
519 			       WLAN_REASSOCREQ_OFF_CURR_AP);
520 	pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_REASSOCREQ_OFF_CURR_AP +
521 		      sizeof(*(pFrame->pAddrCurrAP));
522 }
523 
524 /*+
525  *
526  * Routine Description: (AP)
527  *  Decode Reassociation Request
528  *
529  *
530  * Return Value:
531  *    None.
532  *
533  -*/
534 
535 void
vMgrDecodeReassocRequest(PWLAN_FR_REASSOCREQ pFrame)536 vMgrDecodeReassocRequest(
537 	PWLAN_FR_REASSOCREQ  pFrame
538 )
539 {
540 	PWLAN_IE   pItem;
541 
542 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
543 
544 	/* Fixed Fields */
545 	pFrame->pwCapInfo = (unsigned short *)
546 			    (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
547 			     WLAN_REASSOCREQ_OFF_CAP_INFO);
548 	pFrame->pwListenInterval = (unsigned short *)
549 				   (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
550 				    WLAN_REASSOCREQ_OFF_LISTEN_INT);
551 	pFrame->pAddrCurrAP = (PIEEE_ADDR)
552 			      (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
553 			       WLAN_REASSOCREQ_OFF_CURR_AP);
554 
555 	/* Information elements */
556 	pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
557 			   + WLAN_REASSOCREQ_OFF_SSID);
558 
559 	while (((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) {
560 		switch (pItem->byElementID) {
561 		case WLAN_EID_SSID:
562 			if (pFrame->pSSID == NULL)
563 				pFrame->pSSID = (PWLAN_IE_SSID)pItem;
564 			break;
565 		case WLAN_EID_SUPP_RATES:
566 			if (pFrame->pSuppRates == NULL)
567 				pFrame->pSuppRates =
568 						    (PWLAN_IE_SUPP_RATES)pItem;
569 			break;
570 
571 		case WLAN_EID_RSN:
572 			if (pFrame->pRSN == NULL)
573 				pFrame->pRSN = (PWLAN_IE_RSN)pItem;
574 			break;
575 		case WLAN_EID_RSN_WPA:
576 			if (pFrame->pRSNWPA == NULL) {
577 				if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true)
578 					pFrame->pRSNWPA =
579 						       (PWLAN_IE_RSN_EXT)pItem;
580 			}
581 			break;
582 
583 		case WLAN_EID_EXTSUPP_RATES:
584 			if (pFrame->pExtSuppRates == NULL)
585 				pFrame->pExtSuppRates =
586 						    (PWLAN_IE_SUPP_RATES)pItem;
587 			break;
588 		default:
589 			pr_debug("Unrecognized EID=%dd in reassocreq decode\n",
590 				 pItem->byElementID);
591 			break;
592 		}
593 		pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
594 	}
595 }
596 
597 /*+
598  *
599  * Routine Description:
600  *  Encode Probe Request
601  *
602  *
603  * Return Value:
604  *    None.
605  *
606  -*/
607 
608 void
vMgrEncodeProbeRequest(PWLAN_FR_PROBEREQ pFrame)609 vMgrEncodeProbeRequest(
610 	PWLAN_FR_PROBEREQ  pFrame
611 )
612 {
613 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
614 	pFrame->len = WLAN_HDR_ADDR3_LEN;
615 }
616 
617 /*+
618  *
619  * Routine Description:
620  *  Decode Probe Request
621  *
622  *
623  * Return Value:
624  *    None.
625  *
626  -*/
627 
628 void
vMgrDecodeProbeRequest(PWLAN_FR_PROBEREQ pFrame)629 vMgrDecodeProbeRequest(
630 	PWLAN_FR_PROBEREQ  pFrame
631 )
632 {
633 	PWLAN_IE   pItem;
634 
635 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
636 
637 	/* Information elements */
638 	pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)));
639 
640 	while (((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) {
641 		switch (pItem->byElementID) {
642 		case WLAN_EID_SSID:
643 			if (pFrame->pSSID == NULL)
644 				pFrame->pSSID = (PWLAN_IE_SSID)pItem;
645 			break;
646 
647 		case WLAN_EID_SUPP_RATES:
648 			if (pFrame->pSuppRates == NULL)
649 				pFrame->pSuppRates =
650 						   (PWLAN_IE_SUPP_RATES)pItem;
651 			break;
652 
653 		case WLAN_EID_EXTSUPP_RATES:
654 			if (pFrame->pExtSuppRates == NULL)
655 				pFrame->pExtSuppRates =
656 						    (PWLAN_IE_SUPP_RATES)pItem;
657 			break;
658 
659 		default:
660 			pr_debug("Bad EID=%dd in probereq\n",
661 				 pItem->byElementID);
662 			break;
663 		}
664 
665 		pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 +  pItem->len);
666 	}
667 }
668 
669 /*+
670  *
671  * Routine Description:
672  *  Encode Probe Response
673  *
674  *
675  * Return Value:
676  *    None.
677  *
678  -*/
679 
680 void
vMgrEncodeProbeResponse(PWLAN_FR_PROBERESP pFrame)681 vMgrEncodeProbeResponse(
682 	PWLAN_FR_PROBERESP  pFrame
683 )
684 {
685 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
686 
687 	/* Fixed Fields */
688 	pFrame->pqwTimestamp = (__le64 *)
689 			       (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
690 				WLAN_PROBERESP_OFF_TS);
691 	pFrame->pwBeaconInterval = (unsigned short *)
692 				   (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
693 				    WLAN_PROBERESP_OFF_BCN_INT);
694 	pFrame->pwCapInfo = (unsigned short *)
695 			    (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
696 			     WLAN_PROBERESP_OFF_CAP_INFO);
697 
698 	pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_PROBERESP_OFF_CAP_INFO +
699 		      sizeof(*(pFrame->pwCapInfo));
700 }
701 
702 /*+
703  *
704  * Routine Description:
705  *  Decode Probe Response
706  *
707  *
708  * Return Value:
709  *    None.
710  *
711  -*/
712 
713 void
vMgrDecodeProbeResponse(PWLAN_FR_PROBERESP pFrame)714 vMgrDecodeProbeResponse(
715 	PWLAN_FR_PROBERESP  pFrame
716 )
717 {
718 	PWLAN_IE    pItem;
719 
720 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
721 
722 	/* Fixed Fields */
723 	pFrame->pqwTimestamp = (__le64 *)
724 			       (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
725 				WLAN_PROBERESP_OFF_TS);
726 	pFrame->pwBeaconInterval = (unsigned short *)
727 				   (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
728 				    WLAN_PROBERESP_OFF_BCN_INT);
729 	pFrame->pwCapInfo = (unsigned short *)
730 			    (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
731 			     WLAN_PROBERESP_OFF_CAP_INFO);
732 
733 	/* Information elements */
734 	pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
735 			   + WLAN_PROBERESP_OFF_SSID);
736 
737 	while (((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) {
738 		switch (pItem->byElementID) {
739 		case WLAN_EID_SSID:
740 			if (pFrame->pSSID == NULL)
741 				pFrame->pSSID = (PWLAN_IE_SSID)pItem;
742 			break;
743 		case WLAN_EID_SUPP_RATES:
744 			if (pFrame->pSuppRates == NULL)
745 				pFrame->pSuppRates =
746 						   (PWLAN_IE_SUPP_RATES)pItem;
747 			break;
748 		case WLAN_EID_FH_PARMS:
749 			break;
750 		case WLAN_EID_DS_PARMS:
751 			if (pFrame->pDSParms == NULL)
752 				pFrame->pDSParms = (PWLAN_IE_DS_PARMS)pItem;
753 			break;
754 		case WLAN_EID_CF_PARMS:
755 			if (pFrame->pCFParms == NULL)
756 				pFrame->pCFParms = (PWLAN_IE_CF_PARMS)pItem;
757 			break;
758 		case WLAN_EID_IBSS_PARMS:
759 			if (pFrame->pIBSSParms == NULL)
760 				pFrame->pIBSSParms =
761 						   (PWLAN_IE_IBSS_PARMS)pItem;
762 			break;
763 
764 		case WLAN_EID_RSN:
765 			if (pFrame->pRSN == NULL)
766 				pFrame->pRSN = (PWLAN_IE_RSN)pItem;
767 			break;
768 		case WLAN_EID_RSN_WPA:
769 			if (pFrame->pRSNWPA == NULL) {
770 				if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true)
771 					pFrame->pRSNWPA =
772 						       (PWLAN_IE_RSN_EXT)pItem;
773 			}
774 			break;
775 		case WLAN_EID_ERP:
776 			if (pFrame->pERP == NULL)
777 				pFrame->pERP = (PWLAN_IE_ERP)pItem;
778 			break;
779 		case WLAN_EID_EXTSUPP_RATES:
780 			if (pFrame->pExtSuppRates == NULL)
781 				pFrame->pExtSuppRates =
782 						    (PWLAN_IE_SUPP_RATES)pItem;
783 			break;
784 
785 		case WLAN_EID_COUNTRY:      /* 7 */
786 			if (pFrame->pIE_Country == NULL)
787 				pFrame->pIE_Country = (PWLAN_IE_COUNTRY)pItem;
788 			break;
789 
790 		case WLAN_EID_PWR_CONSTRAINT:   /* 32 */
791 			if (pFrame->pIE_PowerConstraint == NULL)
792 				pFrame->pIE_PowerConstraint =
793 						      (PWLAN_IE_PW_CONST)pItem;
794 			break;
795 
796 		case WLAN_EID_CH_SWITCH:    /* 37 */
797 			if (pFrame->pIE_CHSW == NULL)
798 				pFrame->pIE_CHSW = (PWLAN_IE_CH_SW)pItem;
799 			break;
800 
801 		case WLAN_EID_QUIET:        /* 40 */
802 			if (pFrame->pIE_Quiet == NULL)
803 				pFrame->pIE_Quiet = (PWLAN_IE_QUIET)pItem;
804 			break;
805 
806 		case WLAN_EID_IBSS_DFS:
807 			if (pFrame->pIE_IBSSDFS == NULL)
808 				pFrame->pIE_IBSSDFS = (PWLAN_IE_IBSS_DFS)pItem;
809 			break;
810 
811 		default:
812 			pr_debug("Bad EID=%dd in proberesp\n",
813 				 pItem->byElementID);
814 			break;
815 		}
816 
817 		pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 +  pItem->len);
818 	}
819 }
820 
821 /*+
822  *
823  * Routine Description:
824  *     Encode Authentication frame
825  *
826  *
827  * Return Value:
828  *    None.
829  *
830  -*/
831 
832 void
vMgrEncodeAuthen(PWLAN_FR_AUTHEN pFrame)833 vMgrEncodeAuthen(
834 	PWLAN_FR_AUTHEN  pFrame
835 )
836 {
837 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
838 
839 	/* Fixed Fields */
840 	pFrame->pwAuthAlgorithm = (unsigned short *)
841 				  (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
842 				   WLAN_AUTHEN_OFF_AUTH_ALG);
843 	pFrame->pwAuthSequence = (unsigned short *)
844 				 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
845 				  WLAN_AUTHEN_OFF_AUTH_SEQ);
846 	pFrame->pwStatus = (unsigned short *)
847 			   (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
848 			    WLAN_AUTHEN_OFF_STATUS);
849 	pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_AUTHEN_OFF_STATUS +
850 		      sizeof(*(pFrame->pwStatus));
851 }
852 
853 /*+
854  *
855  * Routine Description:
856  *   Decode Authentication
857  *
858  *
859  * Return Value:
860  *    None.
861  *
862  -*/
863 
864 void
vMgrDecodeAuthen(PWLAN_FR_AUTHEN pFrame)865 vMgrDecodeAuthen(
866 	PWLAN_FR_AUTHEN  pFrame
867 )
868 {
869 	PWLAN_IE    pItem;
870 
871 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
872 
873 	/* Fixed Fields */
874 	pFrame->pwAuthAlgorithm = (unsigned short *)
875 				  (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
876 				   WLAN_AUTHEN_OFF_AUTH_ALG);
877 	pFrame->pwAuthSequence = (unsigned short *)
878 				 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
879 				  WLAN_AUTHEN_OFF_AUTH_SEQ);
880 	pFrame->pwStatus = (unsigned short *)
881 			   (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
882 			    WLAN_AUTHEN_OFF_STATUS);
883 
884 	/* Information elements */
885 	pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
886 			   + WLAN_AUTHEN_OFF_CHALLENGE);
887 
888 	if (((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len) &&
889 	    pItem->byElementID == WLAN_EID_CHALLENGE)
890 		pFrame->pChallenge = (PWLAN_IE_CHALLENGE)pItem;
891 }
892 
893 /*+
894  *
895  * Routine Description:
896  *   Encode Authentication
897  *
898  *
899  * Return Value:
900  *    None.
901  *
902  -*/
903 
904 void
vMgrEncodeDeauthen(PWLAN_FR_DEAUTHEN pFrame)905 vMgrEncodeDeauthen(
906 	PWLAN_FR_DEAUTHEN  pFrame
907 )
908 {
909 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
910 
911 	/* Fixed Fields */
912 	pFrame->pwReason = (unsigned short *)
913 			   (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
914 			    WLAN_DEAUTHEN_OFF_REASON);
915 	pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_DEAUTHEN_OFF_REASON +
916 		      sizeof(*(pFrame->pwReason));
917 }
918 
919 /*+
920  *
921  * Routine Description:
922  *   Decode Deauthentication
923  *
924  *
925  * Return Value:
926  *    None.
927  *
928  -*/
929 
930 void
vMgrDecodeDeauthen(PWLAN_FR_DEAUTHEN pFrame)931 vMgrDecodeDeauthen(
932 	PWLAN_FR_DEAUTHEN  pFrame
933 )
934 {
935 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
936 
937 	/* Fixed Fields */
938 	pFrame->pwReason = (unsigned short *)
939 			   (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
940 			    WLAN_DEAUTHEN_OFF_REASON);
941 }
942 
943 /*+
944  *
945  * Routine Description: (AP)
946  *   Encode Reassociation Response
947  *
948  *
949  * Return Value:
950  *    None.
951  *
952  -*/
953 
954 void
vMgrEncodeReassocResponse(PWLAN_FR_REASSOCRESP pFrame)955 vMgrEncodeReassocResponse(
956 	PWLAN_FR_REASSOCRESP  pFrame
957 )
958 {
959 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
960 
961 	/* Fixed Fields */
962 	pFrame->pwCapInfo = (unsigned short *)
963 			    (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
964 			     WLAN_REASSOCRESP_OFF_CAP_INFO);
965 	pFrame->pwStatus = (unsigned short *)
966 			   (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
967 			    WLAN_REASSOCRESP_OFF_STATUS);
968 	pFrame->pwAid = (unsigned short *)
969 			(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
970 			 WLAN_REASSOCRESP_OFF_AID);
971 
972 	pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_REASSOCRESP_OFF_AID +
973 		      sizeof(*(pFrame->pwAid));
974 }
975 
976 /*+
977  *
978  * Routine Description:
979  *   Decode Reassociation Response
980  *
981  *
982  * Return Value:
983  *    None.
984  *
985  -*/
986 
987 void
vMgrDecodeReassocResponse(PWLAN_FR_REASSOCRESP pFrame)988 vMgrDecodeReassocResponse(
989 	PWLAN_FR_REASSOCRESP  pFrame
990 )
991 {
992 	PWLAN_IE   pItem;
993 
994 	pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
995 
996 	/* Fixed Fields */
997 	pFrame->pwCapInfo = (unsigned short *)
998 			    (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
999 			     WLAN_REASSOCRESP_OFF_CAP_INFO);
1000 	pFrame->pwStatus = (unsigned short *)
1001 			   (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
1002 			    WLAN_REASSOCRESP_OFF_STATUS);
1003 	pFrame->pwAid = (unsigned short *)
1004 			(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
1005 			 WLAN_REASSOCRESP_OFF_AID);
1006 
1007 	/* Information elements */
1008 	pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)
1009 			     (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
1010 			      WLAN_REASSOCRESP_OFF_SUPP_RATES);
1011 
1012 	pItem = (PWLAN_IE)(pFrame->pSuppRates);
1013 	pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
1014 
1015 	if ((((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) &&
1016 	    (pItem->byElementID == WLAN_EID_EXTSUPP_RATES)) {
1017 		pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
1018 	}
1019 }
1020