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