hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
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
/** @file parser_rom.c
 *
 *  @brief This file define the  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
******************************************************/
#include "parser_rom.h"
 
#include "hostsa_ext_def.h"
#include "authenticator.h"
 
#define WMM_IE_MIN_LEN  7
 
VendorSpecificIEType_e
IsWMMElement(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,
       0x02, 0x00, 0x01
   };
   const uint8 szMatchingParamElement[] = { 0x00, 0x50, 0xf2,
       0x02, 0x01, 0x01
   };
   const uint8 szMatchingTspecElement[] = { 0x00, 0x50, 0xf2,
       0x02, 0x02, 0x01
   };
 
   if (!memcmp(util_fns, pBuffer,
           szMatchingInfoElement, sizeof(szMatchingInfoElement))) {
       retVal = VendSpecIE_WMM_Info;
   } else if (!memcmp(util_fns, pBuffer,
              szMatchingParamElement,
              sizeof(szMatchingParamElement))) {
       retVal = VendSpecIE_WMM_Param;
   } else if (!memcmp(util_fns, pBuffer,
              szMatchingTspecElement,
              sizeof(szMatchingTspecElement))) {
       retVal = VendSpecIE_TSPEC;
   }
 
   return retVal;
}
 
VendorSpecificIEType_e
IsWPAElement(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,
       0x01, 0x01, 0x00
   };
 
   if (!memcmp(util_fns, pBuffer,
           szMatchingInfoElement, sizeof(szMatchingInfoElement))) {
       retVal = VendSpecIE_WPA;
   }
 
   return retVal;
}
 
BOOLEAN
ROM_parser_getIEPtr(void *priv, uint8 *pIe, IEPointers_t *pIePointers)
{
   BOOLEAN status = TRUE;
   switch (*pIe) {
   case ELEM_ID_SSID:
       pIePointers->pSsid = (IEEEtypes_SsIdElement_t *)pIe;
       break;
 
   case ELEM_ID_DS_PARAM_SET:
       pIePointers->pDsParam = (IEEEtypes_DsParamElement_t *)pIe;
       break;
 
   case ELEM_ID_TIM:
       pIePointers->pTim = (IEEEtypes_TimElement_t *)pIe;
       break;
 
   case ELEM_ID_SUPPORTED_RATES:
       pIePointers->pSupportedRates =
           (IEEEtypes_SuppRatesElement_t *)pIe;
       break;
 
   case ELEM_ID_EXT_SUPPORTED_RATES:
       pIePointers->pExtSupportedRates
           = (IEEEtypes_ExtSuppRatesElement_t *)pIe;
       break;
 
   case ELEM_ID_ERP_INFO:
       pIePointers->pErpInfo = (IEEEtypes_ERPInfoElement_t *)pIe;
       break;
 
   case ELEM_ID_IBSS_PARAM_SET:
       pIePointers->pIbssParam = (IEEEtypes_IbssParamElement_t *)pIe;
       break;
 
   case ELEM_ID_COUNTRY:
       pIePointers->pCountry = (IEEEtypes_CountryInfoElement_t *)pIe;
       break;
 
   case ELEM_ID_RSN:
       pIePointers->pRsn = (IEEEtypes_RSNElement_t *)pIe;
       break;
 
   case ELEM_ID_VENDOR_SPECIFIC:
 
       if (IsWPAElement(priv, (pIe + 2))) {
           pIePointers->pWpa = (IEEEtypes_WPAElement_t *)pIe;
       } else {
           switch (IsWMMElement(priv, (pIe + 2))) {
           case VendSpecIE_Other:
           case VendSpecIE_TSPEC:
           default:
               status = FALSE;
               break;
 
           case VendSpecIE_WMM_Info:
               pIePointers->pWmmInfo =
                   (IEEEtypes_WMM_InfoElement_t *)pIe;
               break;
 
           case VendSpecIE_WMM_Param:
               pIePointers->pWmmParam
                   = (IEEEtypes_WMM_ParamElement_t *)pIe;
               break;
           }
 
       }
       break;
   default:
       status = FALSE;
       break;
   }
 
   return status;
}
 
BOOLEAN
ROM_parser_getAssocIEPtr(void *priv, uint8 *pIe, AssocIePointers_t *pIePointers)
{
   BOOLEAN status = TRUE;
   switch (*pIe) {
   case ELEM_ID_SSID:
       pIePointers->pSsid = (IEEEtypes_SsIdElement_t *)pIe;
       break;
 
   case ELEM_ID_COUNTRY:
       pIePointers->pCountry = (IEEEtypes_CountryInfoElement_t *)pIe;
       break;
 
   case ELEM_ID_DS_PARAM_SET:
       pIePointers->pDsParam = (IEEEtypes_DsParamElement_t *)pIe;
       break;
 
   case ELEM_ID_SUPPORTED_RATES:
       pIePointers->pSupportedRates =
           (IEEEtypes_SuppRatesElement_t *)pIe;
       break;
 
   case ELEM_ID_EXT_SUPPORTED_RATES:
       pIePointers->pExtSupportedRates
           = (IEEEtypes_ExtSuppRatesElement_t *)pIe;
       break;
 
   case ELEM_ID_RSN:
       pIePointers->pRsn = (IEEEtypes_RSNElement_t *)pIe;
       break;
 
   case ELEM_ID_VENDOR_SPECIFIC:
       if (IsWPAElement(priv, (pIe + 2))) {
           pIePointers->pWpa = (IEEEtypes_WPAElement_t *)pIe;
       } else {
           switch (IsWMMElement(priv, (pIe + 2))) {
           case VendSpecIE_Other:
           case VendSpecIE_TSPEC:
           default:
               status = FALSE;
               break;
 
           case VendSpecIE_WMM_Info:
               pIePointers->pWmmInfo
                   = (IEEEtypes_WMM_InfoElement_t *)pIe;
               break;
 
           case VendSpecIE_WMM_Param:
               pIePointers->pWmmParam
                   = (IEEEtypes_WMM_ParamElement_t *)pIe;
               break;
           }
       }
       break;
   default:
       status = FALSE;
       break;
   }
 
   return status;
}
 
IEEEtypes_InfoElementHdr_t *
parser_getSpecificIE(IEEEtypes_ElementId_e elemId, UINT8 *pIe, int bufLen)
{
   if (!pIe) {
       return NULL;
   }
 
   while (bufLen) {
       if (bufLen < (*(pIe + 1) + 2)) {
           break;
       }
 
       if (*pIe == elemId) {
           return (IEEEtypes_InfoElementHdr_t *)pIe;
       }
 
       bufLen -= *(pIe + 1) + 2;
       pIe += *(pIe + 1) + 2;
   }
 
   return NULL;
}