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