hc
2024-08-12 233ab1bd4c5697f5cdec94e60206e8c6ac609b4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/** @file parser.c
 *
 *  @brief This file defines function for 802.11 Management Frames Parsing
 *
 * Copyright (C) 2014-2017, Marvell International Ltd.
 *
 * This software file (the "File") is distributed by Marvell International
 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
 * (the "License").  You may use, redistribute and/or modify this File in
 * accordance with the terms and conditions of the License, a copy of which
 * is available by writing to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
 *
 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
 * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
 * this warranty disclaimer.
 */
 
/******************************************************
Change log:
    03/07/2014: Initial version
******************************************************/
/*****************************************************************************
*
* File: parser.c
*
*
*
* Author(s):    Rajesh Bhagwat
* Date:         2005-02-04
* Description:  802.11 Management Frames Parsing
*
******************************************************************************/
#include "wltypes.h"
#include "wl_mib.h"
#include "IEEE_types.h"
#include "parser.h"
#include "parser_rom.h"
 
#include "hostsa_ext_def.h"
#include "authenticator.h"
 
VendorSpecificIEType_e
IsEpigramHTElement(void *priv, uint8 *pBuffer)
{
   phostsa_private psapriv = (phostsa_private)priv;
   hostsa_util_fns *util_fns = &psapriv->util_fns;
   VendorSpecificIEType_e retVal = VendSpecIE_Other;
   const uint8 szMatchingCapElement[] = { 0x00, 0x90, 0x4c, 0x33 };
   const uint8 szMatchingInfoElement[] = { 0x00, 0x90, 0x4c, 0x34 };
 
   if (!memcmp(util_fns, pBuffer,
           szMatchingInfoElement, sizeof(szMatchingInfoElement))) {
       retVal = VendSpecIE_HT_Info;
   } else if (!memcmp(util_fns, pBuffer,
              szMatchingCapElement,
              sizeof(szMatchingCapElement))) {
       retVal = VendSpecIE_HT_Cap;
   }
 
   return retVal;
}
 
VendorSpecificIEType_e
IsWPSElement(void *priv, UINT8 *pBuffer)
{
   phostsa_private psapriv = (phostsa_private)priv;
   hostsa_util_fns *util_fns = &psapriv->util_fns;
   VendorSpecificIEType_e retVal = VendSpecIE_Other;
   const UINT8 szMatchingInfoElement[] = { 0x00, 0x50, 0xf2, 0x04 };
 
   if (!memcmp(util_fns, pBuffer,
           szMatchingInfoElement, sizeof(szMatchingInfoElement))) {
       retVal = VendSpecIE_WPS;
   }
 
   return retVal;
}
 
VendorSpecificIEType_e
IsSsIdLElement(void *priv, UINT8 *pBuffer)
{
   phostsa_private psapriv = (phostsa_private)priv;
   hostsa_util_fns *util_fns = &psapriv->util_fns;
   VendorSpecificIEType_e retVal = VendSpecIE_Other;
   const UINT8 szMatchingInfoElement[] = { 0x00, 0x50, 0xf2, 0x05, 0x00 };
 
   if (!memcmp(util_fns, pBuffer,
           szMatchingInfoElement, sizeof(szMatchingInfoElement))) {
       retVal = VendSpecIE_SsIdL;
   }
 
   return retVal;
}
 
int
ieBufValidate(UINT8 *pIe, int bufLen)
{
   while (bufLen) {
       UINT8 ieLen = *(pIe + 1);
       if (bufLen < (ieLen + 2)) {
           return MLME_FAILURE;
       }
       bufLen -= ieLen + 2;
       pIe += ieLen + 2;
   }
 
   return MLME_SUCCESS;
}
 
int
GetIEPointers(void *priv, UINT8 *pIe, int bufLen, IEPointers_t *pIePointers)
{
   phostsa_private psapriv = (phostsa_private)priv;
   hostsa_util_fns *util_fns = &psapriv->util_fns;
   memset(util_fns, pIePointers, 0x00, sizeof(IEPointers_t));
 
   while (bufLen) {
       if (bufLen < (*(pIe + 1) + 2)) {
           break;
       }
 
       /* Handle IEs not processed by ROM functions. */
       switch (*pIe) {
       case ELEM_ID_RSN:
           pIePointers->pRsn = (IEEEtypes_RSNElement_t *)pIe;
           break;
       case ELEM_ID_WAPI:
           pIePointers->pWapi = (IEEEtypes_WAPIElement_t *)pIe;
           break;
 
           /*  Add element not handled by ROM_parser_getIEPtr or
            **  override element processing in ROM_parser_getIEPtr
            **  here.
            */
       case ELEM_ID_VENDOR_SPECIFIC:
       default:
           if (ROM_parser_getIEPtr(priv, pIe, pIePointers) ==
               FALSE) {
               if ((*pIe) == ELEM_ID_VENDOR_SPECIFIC) {
                   if (IsWPSElement(priv, (pIe + 2))) {
                       pIePointers->pWps =
                           (IEEEtypes_WPSElement_t
                            *)pIe;
                   }
               }
               // Add your code to process vendor specific elements not
               // processed by above ROM_paser_getAssocIEPtr function.
           }
           break;
       }
       bufLen -= *(pIe + 1) + 2;
       pIe += *(pIe + 1) + 2;
   }
   return bufLen;
}
 
BOOLEAN
parser_getAssocIEs(void *priv, UINT8 *pIe,
          int bufLen, AssocIePointers_t *pIePointers)
{
   phostsa_private psapriv = (phostsa_private)priv;
   hostsa_util_fns *util_fns = &psapriv->util_fns;
   BOOLEAN ieParseSuccessful = TRUE;
 
   memset(util_fns, pIePointers, 0x00, sizeof(AssocIePointers_t));
 
   while (bufLen) {
       UINT8 ieType = *pIe;
       UINT8 ieLen = *(pIe + 1);
 
       if (bufLen < (ieLen + 2)) {
           ieParseSuccessful = FALSE;
           break;
       }
 
       switch (ieType) {
           // add code for elements not handled in ROM function.
       case ELEM_ID_AP_CHANNEL_REPORT:
           pIePointers->pApChanRpt =
               (IEEEtypes_ApChanRptElement_t *)pIe;
           break;
#ifdef TDLS
       case ELEM_ID_SUPPORTED_REGCLASS:
           pIePointers->pSuppRegClass =
               (IEEEtypes_SupportedRegClasses_t *)pIe;
           break;
#endif
 
           /*  The following 5 elements, HT CAP, HT INFO, 20/40 Coex,
              OBSS SCAN PARAM, and EXTENDED CAP, are ignored
              here if 11n is not compiled. When 11n is compiled these
              5 elements would be handled in ROM_parser_getAssocIEPtr
              routine.
 
            */
       case ELEM_ID_HT_CAPABILITY:
       case ELEM_ID_HT_INFORMATION:
       case ELEM_ID_2040_BSS_COEXISTENCE:
       case ELEM_ID_OBSS_SCAN_PARAM:
       case ELEM_ID_EXT_CAPABILITIES:
           /* Do not process these elements in ROM routine
              ROM_parser_getAssocIEPtr
              Note: a break here.
            */
           break;
 
           /*  Add element not handled by ROM_parser_getAssocIEPtr or
              override element processing in ROM_parser_getAssocIEPtr
              here.
              \
            */
 
       case ELEM_ID_VENDOR_SPECIFIC:
       default:
           if (ROM_parser_getAssocIEPtr(priv, pIe, pIePointers) ==
               FALSE) {
               // Add your code to process vendor specific elements not
               // processed by above ROM_paser_getAssocIEPtr function.
               if (!pIePointers->pHtCap ||
                   !pIePointers->pHtInfo) {
                   switch (IsEpigramHTElement
                       (priv, (pIe + 2))) {
 
                   case VendSpecIE_HT_Cap:
                       if (!pIePointers->pHtCap) {
                           *(pIe + 4) =
                               ELEM_ID_HT_CAPABILITY;
                           *(pIe + 5) =
                               sizeof
                               (IEEEtypes_HT_Capability_t);
                           pIePointers->pHtCap =
                               (IEEEtypes_HT_Capability_t
                                *)(pIe + 4);
                       }
                       break;
 
                   case VendSpecIE_HT_Info:
                       if (!pIePointers->pHtInfo) {
                           *(pIe + 4) =
                               ELEM_ID_HT_INFORMATION;
                           *(pIe + 5) =
                               sizeof
                               (IEEEtypes_HT_Information_t);
                           pIePointers->pHtInfo =
                               (IEEEtypes_HT_Information_t
                                *)(pIe + 4);
                       }
                       break;
 
                   case VendSpecIE_Other:
                   default:
                       break;
                   }
               }
           }
           break;
 
       }
       bufLen -= ieLen + 2;
       pIe += ieLen + 2;
   }
   return ieParseSuccessful;
}
 
UINT8
parser_countNumInfoElements(UINT8 *pIe, int bufLen)
{
   UINT8 ieCount = 0;
 
   while (bufLen) {
       if (bufLen < (*(pIe + 1) + 2)) {
           break;
       }
 
       ieCount++;
 
       bufLen -= *(pIe + 1) + 2;
       pIe += *(pIe + 1) + 2;
   }
 
   return ieCount;
}