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