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