Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************* |
| 3 | * Ralink Tech Inc. |
| 4 | * 5F., No.36, Taiyuan St., Jhubei City, |
| 5 | * Hsinchu County 302, |
| 6 | * Taiwan, R.O.C. |
| 7 | * |
| 8 | * (c) Copyright 2002-2007, Ralink Technology, Inc. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify * |
| 11 | * it under the terms of the GNU General Public License as published by * |
| 12 | * the Free Software Foundation; either version 2 of the License, or * |
| 13 | * (at your option) any later version. * |
| 14 | * * |
| 15 | * This program is distributed in the hope that it will be useful, * |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 18 | * GNU General Public License for more details. * |
| 19 | * * |
| 20 | * You should have received a copy of the GNU General Public License * |
| 21 | * along with this program; if not, write to the * |
| 22 | * Free Software Foundation, Inc., * |
| 23 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 24 | * * |
| 25 | ************************************************************************* |
| 26 | |
| 27 | Module Name: |
| 28 | sanity.c |
| 29 | |
| 30 | Abstract: |
| 31 | |
| 32 | Revision History: |
| 33 | Who When What |
| 34 | -------- ---------- ---------------------------------------------- |
| 35 | John Chang 2004-09-01 add WMM support |
| 36 | */ |
| 37 | #include "../rt_config.h" |
| 38 | |
| 39 | |
| 40 | extern UCHAR CISCO_OUI[]; |
| 41 | |
| 42 | extern UCHAR WPA_OUI[]; |
| 43 | extern UCHAR RSN_OUI[]; |
| 44 | extern UCHAR WME_INFO_ELEM[]; |
| 45 | extern UCHAR WME_PARM_ELEM[]; |
| 46 | extern UCHAR Ccx2QosInfo[]; |
| 47 | extern UCHAR RALINK_OUI[]; |
| 48 | extern UCHAR BROADCOM_OUI[]; |
| 49 | extern UCHAR WPS_OUI[]; |
| 50 | |
| 51 | /* |
| 52 | ========================================================================== |
| 53 | Description: |
| 54 | MLME message sanity check |
| 55 | Return: |
| 56 | TRUE if all parameters are OK, FALSE otherwise |
| 57 | |
| 58 | IRQL = DISPATCH_LEVEL |
| 59 | |
| 60 | ========================================================================== |
| 61 | */ |
| 62 | BOOLEAN MlmeAddBAReqSanity( |
| 63 | IN PRTMP_ADAPTER pAd, |
| 64 | IN VOID *Msg, |
| 65 | IN ULONG MsgLen, |
| 66 | OUT PUCHAR pAddr2) |
| 67 | { |
| 68 | PMLME_ADDBA_REQ_STRUCT pInfo; |
| 69 | |
| 70 | pInfo = (MLME_ADDBA_REQ_STRUCT *)Msg; |
| 71 | |
| 72 | if ((MsgLen != sizeof(MLME_ADDBA_REQ_STRUCT))) |
| 73 | { |
| 74 | DBGPRINT(RT_DEBUG_TRACE, ("MlmeAddBAReqSanity fail - message lenght not correct.\n")); |
| 75 | return FALSE; |
| 76 | } |
| 77 | |
| 78 | if ((pInfo->Wcid >= MAX_LEN_OF_MAC_TABLE)) |
| 79 | { |
| 80 | DBGPRINT(RT_DEBUG_TRACE, ("MlmeAddBAReqSanity fail - The peer Mac is not associated yet.\n")); |
| 81 | return FALSE; |
| 82 | } |
| 83 | |
| 84 | /* |
| 85 | if ((pInfo->BaBufSize > MAX_RX_REORDERBUF) || (pInfo->BaBufSize < 2)) |
| 86 | { |
| 87 | DBGPRINT(RT_DEBUG_TRACE, ("MlmeAddBAReqSanity fail - Rx Reordering buffer too big or too small\n")); |
| 88 | return FALSE; |
| 89 | } |
| 90 | */ |
| 91 | |
| 92 | if ((pInfo->pAddr[0]&0x01) == 0x01) |
| 93 | { |
| 94 | DBGPRINT(RT_DEBUG_TRACE, ("MlmeAddBAReqSanity fail - broadcast address not support BA\n")); |
| 95 | return FALSE; |
| 96 | } |
| 97 | |
| 98 | return TRUE; |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | ========================================================================== |
| 103 | Description: |
| 104 | MLME message sanity check |
| 105 | Return: |
| 106 | TRUE if all parameters are OK, FALSE otherwise |
| 107 | |
| 108 | IRQL = DISPATCH_LEVEL |
| 109 | |
| 110 | ========================================================================== |
| 111 | */ |
| 112 | BOOLEAN MlmeDelBAReqSanity( |
| 113 | IN PRTMP_ADAPTER pAd, |
| 114 | IN VOID *Msg, |
| 115 | IN ULONG MsgLen) |
| 116 | { |
| 117 | MLME_DELBA_REQ_STRUCT *pInfo; |
| 118 | pInfo = (MLME_DELBA_REQ_STRUCT *)Msg; |
| 119 | |
| 120 | if ((MsgLen != sizeof(MLME_DELBA_REQ_STRUCT))) |
| 121 | { |
| 122 | DBGPRINT(RT_DEBUG_ERROR, ("MlmeDelBAReqSanity fail - message lenght not correct.\n")); |
| 123 | return FALSE; |
| 124 | } |
| 125 | |
| 126 | if ((pInfo->Wcid >= MAX_LEN_OF_MAC_TABLE)) |
| 127 | { |
| 128 | DBGPRINT(RT_DEBUG_ERROR, ("MlmeDelBAReqSanity fail - The peer Mac is not associated yet.\n")); |
| 129 | return FALSE; |
| 130 | } |
| 131 | |
| 132 | if ((pInfo->TID & 0xf0)) |
| 133 | { |
| 134 | DBGPRINT(RT_DEBUG_ERROR, ("MlmeDelBAReqSanity fail - The peer TID is incorrect.\n")); |
| 135 | return FALSE; |
| 136 | } |
| 137 | |
| 138 | if (NdisEqualMemory(pAd->MacTab.Content[pInfo->Wcid].Addr, pInfo->Addr, MAC_ADDR_LEN) == 0) |
| 139 | { |
| 140 | DBGPRINT(RT_DEBUG_ERROR, ("MlmeDelBAReqSanity fail - the peer addr dosen't exist.\n")); |
| 141 | return FALSE; |
| 142 | } |
| 143 | |
| 144 | return TRUE; |
| 145 | } |
| 146 | |
| 147 | BOOLEAN PeerAddBAReqActionSanity( |
| 148 | IN PRTMP_ADAPTER pAd, |
| 149 | IN VOID *pMsg, |
| 150 | IN ULONG MsgLen, |
| 151 | OUT PUCHAR pAddr2) |
| 152 | { |
| 153 | PFRAME_802_11 pFrame = (PFRAME_802_11)pMsg; |
| 154 | PFRAME_ADDBA_REQ pAddFrame; |
| 155 | pAddFrame = (PFRAME_ADDBA_REQ)(pMsg); |
| 156 | if (MsgLen < (sizeof(FRAME_ADDBA_REQ))) |
| 157 | { |
| 158 | DBGPRINT(RT_DEBUG_ERROR,("PeerAddBAReqActionSanity: ADDBA Request frame length size = %ld incorrect\n", MsgLen)); |
| 159 | return FALSE; |
| 160 | } |
| 161 | // we support immediate BA. |
| 162 | *(USHORT *)(&pAddFrame->BaParm) = cpu2le16(*(USHORT *)(&pAddFrame->BaParm)); |
| 163 | pAddFrame->TimeOutValue = cpu2le16(pAddFrame->TimeOutValue); |
| 164 | pAddFrame->BaStartSeq.word = cpu2le16(pAddFrame->BaStartSeq.word); |
| 165 | |
| 166 | if (pAddFrame->BaParm.BAPolicy != IMMED_BA) |
| 167 | { |
| 168 | DBGPRINT(RT_DEBUG_ERROR,("PeerAddBAReqActionSanity: ADDBA Request Ba Policy[%d] not support\n", pAddFrame->BaParm.BAPolicy)); |
| 169 | DBGPRINT(RT_DEBUG_ERROR,("ADDBA Request. tid=%x, Bufsize=%x, AMSDUSupported=%x \n", pAddFrame->BaParm.TID, pAddFrame->BaParm.BufSize, pAddFrame->BaParm.AMSDUSupported)); |
| 170 | return FALSE; |
| 171 | } |
| 172 | |
| 173 | // we support immediate BA. |
| 174 | if (pAddFrame->BaParm.TID &0xfff0) |
| 175 | { |
| 176 | DBGPRINT(RT_DEBUG_ERROR,("PeerAddBAReqActionSanity: ADDBA Request incorrect TID = %d\n", pAddFrame->BaParm.TID)); |
| 177 | return FALSE; |
| 178 | } |
| 179 | COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2); |
| 180 | return TRUE; |
| 181 | } |
| 182 | |
| 183 | BOOLEAN PeerAddBARspActionSanity( |
| 184 | IN PRTMP_ADAPTER pAd, |
| 185 | IN VOID *pMsg, |
| 186 | IN ULONG MsgLen) |
| 187 | { |
| 188 | //PFRAME_802_11 pFrame = (PFRAME_802_11)pMsg; |
| 189 | PFRAME_ADDBA_RSP pAddFrame; |
| 190 | |
| 191 | pAddFrame = (PFRAME_ADDBA_RSP)(pMsg); |
| 192 | if (MsgLen < (sizeof(FRAME_ADDBA_RSP))) |
| 193 | { |
| 194 | DBGPRINT(RT_DEBUG_ERROR,("PeerAddBARspActionSanity: ADDBA Response frame length size = %ld incorrect\n", MsgLen)); |
| 195 | return FALSE; |
| 196 | } |
| 197 | // we support immediate BA. |
| 198 | *(USHORT *)(&pAddFrame->BaParm) = cpu2le16(*(USHORT *)(&pAddFrame->BaParm)); |
| 199 | pAddFrame->StatusCode = cpu2le16(pAddFrame->StatusCode); |
| 200 | pAddFrame->TimeOutValue = cpu2le16(pAddFrame->TimeOutValue); |
| 201 | |
| 202 | if (pAddFrame->BaParm.BAPolicy != IMMED_BA) |
| 203 | { |
| 204 | DBGPRINT(RT_DEBUG_ERROR,("PeerAddBAReqActionSanity: ADDBA Response Ba Policy[%d] not support\n", pAddFrame->BaParm.BAPolicy)); |
| 205 | return FALSE; |
| 206 | } |
| 207 | |
| 208 | // we support immediate BA. |
| 209 | if (pAddFrame->BaParm.TID &0xfff0) |
| 210 | { |
| 211 | DBGPRINT(RT_DEBUG_ERROR,("PeerAddBARspActionSanity: ADDBA Response incorrect TID = %d\n", pAddFrame->BaParm.TID)); |
| 212 | return FALSE; |
| 213 | } |
| 214 | return TRUE; |
| 215 | |
| 216 | } |
| 217 | |
| 218 | BOOLEAN PeerDelBAActionSanity( |
| 219 | IN PRTMP_ADAPTER pAd, |
| 220 | IN UCHAR Wcid, |
| 221 | IN VOID *pMsg, |
| 222 | IN ULONG MsgLen ) |
| 223 | { |
| 224 | //PFRAME_802_11 pFrame = (PFRAME_802_11)pMsg; |
| 225 | PFRAME_DELBA_REQ pDelFrame; |
| 226 | if (MsgLen != (sizeof(FRAME_DELBA_REQ))) |
| 227 | return FALSE; |
| 228 | |
| 229 | if (Wcid >= MAX_LEN_OF_MAC_TABLE) |
| 230 | return FALSE; |
| 231 | |
| 232 | pDelFrame = (PFRAME_DELBA_REQ)(pMsg); |
| 233 | |
| 234 | *(USHORT *)(&pDelFrame->DelbaParm) = cpu2le16(*(USHORT *)(&pDelFrame->DelbaParm)); |
| 235 | pDelFrame->ReasonCode = cpu2le16(pDelFrame->ReasonCode); |
| 236 | |
| 237 | if (pDelFrame->DelbaParm.TID &0xfff0) |
| 238 | return FALSE; |
| 239 | |
| 240 | return TRUE; |
| 241 | } |
| 242 | |
| 243 | /* |
| 244 | ========================================================================== |
| 245 | Description: |
| 246 | MLME message sanity check |
| 247 | Return: |
| 248 | TRUE if all parameters are OK, FALSE otherwise |
| 249 | |
| 250 | IRQL = DISPATCH_LEVEL |
| 251 | |
| 252 | ========================================================================== |
| 253 | */ |
| 254 | BOOLEAN PeerBeaconAndProbeRspSanity( |
| 255 | IN PRTMP_ADAPTER pAd, |
| 256 | IN VOID *Msg, |
| 257 | IN ULONG MsgLen, |
| 258 | IN UCHAR MsgChannel, |
| 259 | OUT PUCHAR pAddr2, |
| 260 | OUT PUCHAR pBssid, |
| 261 | OUT CHAR Ssid[], |
| 262 | OUT UCHAR *pSsidLen, |
| 263 | OUT UCHAR *pBssType, |
| 264 | OUT USHORT *pBeaconPeriod, |
| 265 | OUT UCHAR *pChannel, |
| 266 | OUT UCHAR *pNewChannel, |
| 267 | OUT LARGE_INTEGER *pTimestamp, |
| 268 | OUT CF_PARM *pCfParm, |
| 269 | OUT USHORT *pAtimWin, |
| 270 | OUT USHORT *pCapabilityInfo, |
| 271 | OUT UCHAR *pErp, |
| 272 | OUT UCHAR *pDtimCount, |
| 273 | OUT UCHAR *pDtimPeriod, |
| 274 | OUT UCHAR *pBcastFlag, |
| 275 | OUT UCHAR *pMessageToMe, |
| 276 | OUT UCHAR SupRate[], |
| 277 | OUT UCHAR *pSupRateLen, |
| 278 | OUT UCHAR ExtRate[], |
| 279 | OUT UCHAR *pExtRateLen, |
| 280 | OUT UCHAR *pCkipFlag, |
| 281 | OUT UCHAR *pAironetCellPowerLimit, |
| 282 | OUT PEDCA_PARM pEdcaParm, |
| 283 | OUT PQBSS_LOAD_PARM pQbssLoad, |
| 284 | OUT PQOS_CAPABILITY_PARM pQosCapability, |
| 285 | OUT ULONG *pRalinkIe, |
| 286 | OUT UCHAR *pHtCapabilityLen, |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 287 | OUT UCHAR *pPreNHtCapabilityLen, |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 288 | OUT HT_CAPABILITY_IE *pHtCapability, |
| 289 | OUT UCHAR *AddHtInfoLen, |
| 290 | OUT ADD_HT_INFO_IE *AddHtInfo, |
| 291 | OUT UCHAR *NewExtChannelOffset, // Ht extension channel offset(above or below) |
| 292 | OUT USHORT *LengthVIE, |
| 293 | OUT PNDIS_802_11_VARIABLE_IEs pVIE) |
| 294 | { |
| 295 | CHAR *Ptr; |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 296 | CHAR TimLen; |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 297 | PFRAME_802_11 pFrame; |
| 298 | PEID_STRUCT pEid; |
| 299 | UCHAR SubType; |
| 300 | UCHAR Sanity; |
| 301 | //UCHAR ECWMin, ECWMax; |
| 302 | //MAC_CSR9_STRUC Csr9; |
| 303 | ULONG Length = 0; |
| 304 | |
| 305 | // For some 11a AP which didn't have DS_IE, we use two conditions to decide the channel |
| 306 | // 1. If the AP is 11n enabled, then check the control channel. |
| 307 | // 2. If the AP didn't have any info about channel, use the channel we received this frame as the channel. (May inaccuracy!!) |
| 308 | UCHAR CtrlChannel = 0; |
| 309 | |
| 310 | // Add for 3 necessary EID field check |
| 311 | Sanity = 0; |
| 312 | |
| 313 | *pAtimWin = 0; |
| 314 | *pErp = 0; |
| 315 | *pDtimCount = 0; |
| 316 | *pDtimPeriod = 0; |
| 317 | *pBcastFlag = 0; |
| 318 | *pMessageToMe = 0; |
| 319 | *pExtRateLen = 0; |
| 320 | *pCkipFlag = 0; // Default of CkipFlag is 0 |
| 321 | *pAironetCellPowerLimit = 0xFF; // Default of AironetCellPowerLimit is 0xFF |
| 322 | *LengthVIE = 0; // Set the length of VIE to init value 0 |
| 323 | *pHtCapabilityLen = 0; // Set the length of VIE to init value 0 |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 324 | if (pAd->OpMode == OPMODE_STA) |
| 325 | *pPreNHtCapabilityLen = 0; // Set the length of VIE to init value 0 |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 326 | *AddHtInfoLen = 0; // Set the length of VIE to init value 0 |
| 327 | *pRalinkIe = 0; |
| 328 | *pNewChannel = 0; |
| 329 | *NewExtChannelOffset = 0xff; //Default 0xff means no such IE |
| 330 | pCfParm->bValid = FALSE; // default: no IE_CF found |
| 331 | pQbssLoad->bValid = FALSE; // default: no IE_QBSS_LOAD found |
| 332 | pEdcaParm->bValid = FALSE; // default: no IE_EDCA_PARAMETER found |
| 333 | pQosCapability->bValid = FALSE; // default: no IE_QOS_CAPABILITY found |
| 334 | |
| 335 | pFrame = (PFRAME_802_11)Msg; |
| 336 | |
| 337 | // get subtype from header |
| 338 | SubType = (UCHAR)pFrame->Hdr.FC.SubType; |
| 339 | |
| 340 | // get Addr2 and BSSID from header |
| 341 | COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2); |
| 342 | COPY_MAC_ADDR(pBssid, pFrame->Hdr.Addr3); |
| 343 | |
| 344 | // hex_dump("Beacon", Msg, MsgLen); |
| 345 | |
| 346 | Ptr = pFrame->Octet; |
| 347 | Length += LENGTH_802_11; |
| 348 | |
| 349 | // get timestamp from payload and advance the pointer |
| 350 | NdisMoveMemory(pTimestamp, Ptr, TIMESTAMP_LEN); |
| 351 | |
| 352 | pTimestamp->u.LowPart = cpu2le32(pTimestamp->u.LowPart); |
| 353 | pTimestamp->u.HighPart = cpu2le32(pTimestamp->u.HighPart); |
| 354 | |
| 355 | Ptr += TIMESTAMP_LEN; |
| 356 | Length += TIMESTAMP_LEN; |
| 357 | |
| 358 | // get beacon interval from payload and advance the pointer |
| 359 | NdisMoveMemory(pBeaconPeriod, Ptr, 2); |
| 360 | Ptr += 2; |
| 361 | Length += 2; |
| 362 | |
| 363 | // get capability info from payload and advance the pointer |
| 364 | NdisMoveMemory(pCapabilityInfo, Ptr, 2); |
| 365 | Ptr += 2; |
| 366 | Length += 2; |
| 367 | |
| 368 | if (CAP_IS_ESS_ON(*pCapabilityInfo)) |
| 369 | *pBssType = BSS_INFRA; |
| 370 | else |
| 371 | *pBssType = BSS_ADHOC; |
| 372 | |
| 373 | pEid = (PEID_STRUCT) Ptr; |
| 374 | |
| 375 | // get variable fields from payload and advance the pointer |
| 376 | while ((Length + 2 + pEid->Len) <= MsgLen) |
| 377 | { |
| 378 | // |
| 379 | // Secure copy VIE to VarIE[MAX_VIE_LEN] didn't overflow. |
| 380 | // |
| 381 | if ((*LengthVIE + pEid->Len + 2) >= MAX_VIE_LEN) |
| 382 | { |
| 383 | DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - Variable IEs out of resource [len(=%d) > MAX_VIE_LEN(=%d)]\n", |
| 384 | (*LengthVIE + pEid->Len + 2), MAX_VIE_LEN)); |
| 385 | break; |
| 386 | } |
| 387 | |
| 388 | switch(pEid->Eid) |
| 389 | { |
| 390 | case IE_SSID: |
| 391 | // Already has one SSID EID in this beacon, ignore the second one |
| 392 | if (Sanity & 0x1) |
| 393 | break; |
| 394 | if(pEid->Len <= MAX_LEN_OF_SSID) |
| 395 | { |
| 396 | NdisMoveMemory(Ssid, pEid->Octet, pEid->Len); |
| 397 | *pSsidLen = pEid->Len; |
| 398 | Sanity |= 0x1; |
| 399 | } |
| 400 | else |
| 401 | { |
| 402 | DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_SSID (len=%d)\n",pEid->Len)); |
| 403 | return FALSE; |
| 404 | } |
| 405 | break; |
| 406 | |
| 407 | case IE_SUPP_RATES: |
| 408 | if(pEid->Len <= MAX_LEN_OF_SUPPORTED_RATES) |
| 409 | { |
| 410 | Sanity |= 0x2; |
| 411 | NdisMoveMemory(SupRate, pEid->Octet, pEid->Len); |
| 412 | *pSupRateLen = pEid->Len; |
| 413 | |
| 414 | // TODO: 2004-09-14 not a good design here, cause it exclude extra rates |
| 415 | // from ScanTab. We should report as is. And filter out unsupported |
| 416 | // rates in MlmeAux. |
| 417 | // Check against the supported rates |
| 418 | // RTMPCheckRates(pAd, SupRate, pSupRateLen); |
| 419 | } |
| 420 | else |
| 421 | { |
| 422 | DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_SUPP_RATES (len=%d)\n",pEid->Len)); |
| 423 | return FALSE; |
| 424 | } |
| 425 | break; |
| 426 | |
| 427 | case IE_HT_CAP: |
| 428 | if (pEid->Len >= SIZE_HT_CAP_IE) //Note: allow extension.!! |
| 429 | { |
| 430 | NdisMoveMemory(pHtCapability, pEid->Octet, sizeof(HT_CAPABILITY_IE)); |
| 431 | *pHtCapabilityLen = SIZE_HT_CAP_IE; // Nnow we only support 26 bytes. |
| 432 | |
| 433 | *(USHORT *)(&pHtCapability->HtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->HtCapInfo)); |
| 434 | *(USHORT *)(&pHtCapability->ExtHtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->ExtHtCapInfo)); |
| 435 | |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 436 | IF_DEV_CONFIG_OPMODE_ON_STA(pAd) |
| 437 | { |
| 438 | *pPreNHtCapabilityLen = 0; // Nnow we only support 26 bytes. |
| 439 | |
| 440 | Ptr = (PUCHAR) pVIE; |
| 441 | NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid, pEid->Len + 2); |
| 442 | *LengthVIE += (pEid->Len + 2); |
| 443 | } |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 444 | } |
| 445 | else |
| 446 | { |
| 447 | DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - wrong IE_HT_CAP. pEid->Len = %d\n", pEid->Len)); |
| 448 | } |
| 449 | |
| 450 | break; |
| 451 | case IE_ADD_HT: |
| 452 | if (pEid->Len >= sizeof(ADD_HT_INFO_IE)) |
| 453 | { |
| 454 | // This IE allows extension, but we can ignore extra bytes beyond our knowledge , so only |
| 455 | // copy first sizeof(ADD_HT_INFO_IE) |
| 456 | NdisMoveMemory(AddHtInfo, pEid->Octet, sizeof(ADD_HT_INFO_IE)); |
| 457 | *AddHtInfoLen = SIZE_ADD_HT_INFO_IE; |
| 458 | |
| 459 | CtrlChannel = AddHtInfo->ControlChan; |
| 460 | |
| 461 | *(USHORT *)(&AddHtInfo->AddHtInfo2) = cpu2le16(*(USHORT *)(&AddHtInfo->AddHtInfo2)); |
| 462 | *(USHORT *)(&AddHtInfo->AddHtInfo3) = cpu2le16(*(USHORT *)(&AddHtInfo->AddHtInfo3)); |
| 463 | |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 464 | IF_DEV_CONFIG_OPMODE_ON_STA(pAd) |
| 465 | { |
| 466 | Ptr = (PUCHAR) pVIE; |
| 467 | NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid, pEid->Len + 2); |
| 468 | *LengthVIE += (pEid->Len + 2); |
| 469 | } |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 470 | } |
| 471 | else |
| 472 | { |
| 473 | DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - wrong IE_ADD_HT. \n")); |
| 474 | } |
| 475 | |
| 476 | break; |
| 477 | case IE_SECONDARY_CH_OFFSET: |
| 478 | if (pEid->Len == 1) |
| 479 | { |
| 480 | *NewExtChannelOffset = pEid->Octet[0]; |
| 481 | } |
| 482 | else |
| 483 | { |
| 484 | DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - wrong IE_SECONDARY_CH_OFFSET. \n")); |
| 485 | } |
| 486 | |
| 487 | break; |
| 488 | case IE_FH_PARM: |
| 489 | DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity(IE_FH_PARM) \n")); |
| 490 | break; |
| 491 | |
| 492 | case IE_DS_PARM: |
| 493 | if(pEid->Len == 1) |
| 494 | { |
| 495 | *pChannel = *pEid->Octet; |
Bartlomiej Zolnierkiewicz | 8471705 | 2009-04-26 16:05:49 +0200 | [diff] [blame] | 496 | |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 497 | IF_DEV_CONFIG_OPMODE_ON_STA(pAd) |
| 498 | { |
| 499 | if (ChannelSanity(pAd, *pChannel) == 0) |
| 500 | { |
| 501 | |
| 502 | return FALSE; |
| 503 | } |
| 504 | } |
Bartlomiej Zolnierkiewicz | 8471705 | 2009-04-26 16:05:49 +0200 | [diff] [blame] | 505 | |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 506 | Sanity |= 0x4; |
| 507 | } |
| 508 | else |
| 509 | { |
| 510 | DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_DS_PARM (len=%d)\n",pEid->Len)); |
| 511 | return FALSE; |
| 512 | } |
| 513 | break; |
| 514 | |
| 515 | case IE_CF_PARM: |
| 516 | if(pEid->Len == 6) |
| 517 | { |
| 518 | pCfParm->bValid = TRUE; |
| 519 | pCfParm->CfpCount = pEid->Octet[0]; |
| 520 | pCfParm->CfpPeriod = pEid->Octet[1]; |
| 521 | pCfParm->CfpMaxDuration = pEid->Octet[2] + 256 * pEid->Octet[3]; |
| 522 | pCfParm->CfpDurRemaining = pEid->Octet[4] + 256 * pEid->Octet[5]; |
| 523 | } |
| 524 | else |
| 525 | { |
| 526 | DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_CF_PARM\n")); |
| 527 | return FALSE; |
| 528 | } |
| 529 | break; |
| 530 | |
| 531 | case IE_IBSS_PARM: |
| 532 | if(pEid->Len == 2) |
| 533 | { |
| 534 | NdisMoveMemory(pAtimWin, pEid->Octet, pEid->Len); |
| 535 | } |
| 536 | else |
| 537 | { |
| 538 | DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAndProbeRspSanity - wrong IE_IBSS_PARM\n")); |
| 539 | return FALSE; |
| 540 | } |
| 541 | break; |
| 542 | |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 543 | case IE_TIM: |
| 544 | if(INFRA_ON(pAd) && SubType == SUBTYPE_BEACON) |
| 545 | { |
| 546 | GetTimBit((PUCHAR)pEid, pAd->StaActive.Aid, &TimLen, pBcastFlag, pDtimCount, pDtimPeriod, pMessageToMe); |
| 547 | } |
| 548 | break; |
Bartlomiej Zolnierkiewicz | 8471705 | 2009-04-26 16:05:49 +0200 | [diff] [blame] | 549 | |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 550 | case IE_CHANNEL_SWITCH_ANNOUNCEMENT: |
| 551 | if(pEid->Len == 3) |
| 552 | { |
| 553 | *pNewChannel = pEid->Octet[1]; //extract new channel number |
| 554 | } |
| 555 | break; |
| 556 | |
| 557 | // New for WPA |
| 558 | // CCX v2 has the same IE, we need to parse that too |
| 559 | // Wifi WMM use the same IE vale, need to parse that too |
| 560 | // case IE_WPA: |
| 561 | case IE_VENDOR_SPECIFIC: |
| 562 | // Check Broadcom/Atheros 802.11n OUI version, for HT Capability IE. |
| 563 | // This HT IE is before IEEE draft set HT IE value.2006-09-28 by Jan. |
| 564 | /*if (NdisEqualMemory(pEid->Octet, BROADCOM_OUI, 3) && (pEid->Len >= 4)) |
| 565 | { |
| 566 | if ((pEid->Octet[3] == OUI_BROADCOM_HT) && (pEid->Len >= 30)) |
| 567 | { |
| 568 | { |
| 569 | NdisMoveMemory(pHtCapability, &pEid->Octet[4], sizeof(HT_CAPABILITY_IE)); |
| 570 | *pHtCapabilityLen = SIZE_HT_CAP_IE; // Nnow we only support 26 bytes. |
| 571 | } |
| 572 | } |
| 573 | if ((pEid->Octet[3] == OUI_BROADCOM_HT) && (pEid->Len >= 26)) |
| 574 | { |
| 575 | { |
| 576 | NdisMoveMemory(AddHtInfo, &pEid->Octet[4], sizeof(ADD_HT_INFO_IE)); |
| 577 | *AddHtInfoLen = SIZE_ADD_HT_INFO_IE; // Nnow we only support 26 bytes. |
| 578 | } |
| 579 | } |
| 580 | } |
| 581 | */ |
| 582 | // Check the OUI version, filter out non-standard usage |
| 583 | if (NdisEqualMemory(pEid->Octet, RALINK_OUI, 3) && (pEid->Len == 7)) |
| 584 | { |
| 585 | //*pRalinkIe = pEid->Octet[3]; |
| 586 | if (pEid->Octet[3] != 0) |
| 587 | *pRalinkIe = pEid->Octet[3]; |
| 588 | else |
| 589 | *pRalinkIe = 0xf0000000; // Set to non-zero value (can't set bit0-2) to represent this is Ralink Chip. So at linkup, we will set ralinkchip flag. |
| 590 | } |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 591 | // This HT IE is before IEEE draft set HT IE value.2006-09-28 by Jan. |
| 592 | |
| 593 | // Other vendors had production before IE_HT_CAP value is assigned. To backward support those old-firmware AP, |
| 594 | // Check broadcom-defiend pre-802.11nD1.0 OUI for HT related IE, including HT Capatilities IE and HT Information IE |
| 595 | else if ((*pHtCapabilityLen == 0) && NdisEqualMemory(pEid->Octet, PRE_N_HT_OUI, 3) && (pEid->Len >= 4) && (pAd->OpMode == OPMODE_STA)) |
| 596 | { |
| 597 | if ((pEid->Octet[3] == OUI_PREN_HT_CAP) && (pEid->Len >= 30) && (*pHtCapabilityLen == 0)) |
| 598 | { |
| 599 | NdisMoveMemory(pHtCapability, &pEid->Octet[4], sizeof(HT_CAPABILITY_IE)); |
| 600 | *pPreNHtCapabilityLen = SIZE_HT_CAP_IE; |
| 601 | } |
| 602 | |
| 603 | if ((pEid->Octet[3] == OUI_PREN_ADD_HT) && (pEid->Len >= 26)) |
| 604 | { |
| 605 | NdisMoveMemory(AddHtInfo, &pEid->Octet[4], sizeof(ADD_HT_INFO_IE)); |
| 606 | *AddHtInfoLen = SIZE_ADD_HT_INFO_IE; |
| 607 | } |
| 608 | } |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 609 | else if (NdisEqualMemory(pEid->Octet, WPA_OUI, 4)) |
| 610 | { |
| 611 | // Copy to pVIE which will report to microsoft bssid list. |
| 612 | Ptr = (PUCHAR) pVIE; |
| 613 | NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid, pEid->Len + 2); |
| 614 | *LengthVIE += (pEid->Len + 2); |
| 615 | } |
| 616 | else if (NdisEqualMemory(pEid->Octet, WME_PARM_ELEM, 6) && (pEid->Len == 24)) |
| 617 | { |
| 618 | PUCHAR ptr; |
| 619 | int i; |
| 620 | |
| 621 | // parsing EDCA parameters |
| 622 | pEdcaParm->bValid = TRUE; |
| 623 | pEdcaParm->bQAck = FALSE; // pEid->Octet[0] & 0x10; |
| 624 | pEdcaParm->bQueueRequest = FALSE; // pEid->Octet[0] & 0x20; |
| 625 | pEdcaParm->bTxopRequest = FALSE; // pEid->Octet[0] & 0x40; |
| 626 | pEdcaParm->EdcaUpdateCount = pEid->Octet[6] & 0x0f; |
| 627 | pEdcaParm->bAPSDCapable = (pEid->Octet[6] & 0x80) ? 1 : 0; |
| 628 | ptr = &pEid->Octet[8]; |
| 629 | for (i=0; i<4; i++) |
| 630 | { |
| 631 | UCHAR aci = (*ptr & 0x60) >> 5; // b5~6 is AC INDEX |
| 632 | pEdcaParm->bACM[aci] = (((*ptr) & 0x10) == 0x10); // b5 is ACM |
| 633 | pEdcaParm->Aifsn[aci] = (*ptr) & 0x0f; // b0~3 is AIFSN |
| 634 | pEdcaParm->Cwmin[aci] = *(ptr+1) & 0x0f; // b0~4 is Cwmin |
| 635 | pEdcaParm->Cwmax[aci] = *(ptr+1) >> 4; // b5~8 is Cwmax |
| 636 | pEdcaParm->Txop[aci] = *(ptr+2) + 256 * (*(ptr+3)); // in unit of 32-us |
| 637 | ptr += 4; // point to next AC |
| 638 | } |
| 639 | } |
| 640 | else if (NdisEqualMemory(pEid->Octet, WME_INFO_ELEM, 6) && (pEid->Len == 7)) |
| 641 | { |
| 642 | // parsing EDCA parameters |
| 643 | pEdcaParm->bValid = TRUE; |
| 644 | pEdcaParm->bQAck = FALSE; // pEid->Octet[0] & 0x10; |
| 645 | pEdcaParm->bQueueRequest = FALSE; // pEid->Octet[0] & 0x20; |
| 646 | pEdcaParm->bTxopRequest = FALSE; // pEid->Octet[0] & 0x40; |
| 647 | pEdcaParm->EdcaUpdateCount = pEid->Octet[6] & 0x0f; |
| 648 | pEdcaParm->bAPSDCapable = (pEid->Octet[6] & 0x80) ? 1 : 0; |
| 649 | |
| 650 | // use default EDCA parameter |
| 651 | pEdcaParm->bACM[QID_AC_BE] = 0; |
| 652 | pEdcaParm->Aifsn[QID_AC_BE] = 3; |
| 653 | pEdcaParm->Cwmin[QID_AC_BE] = CW_MIN_IN_BITS; |
| 654 | pEdcaParm->Cwmax[QID_AC_BE] = CW_MAX_IN_BITS; |
| 655 | pEdcaParm->Txop[QID_AC_BE] = 0; |
| 656 | |
| 657 | pEdcaParm->bACM[QID_AC_BK] = 0; |
| 658 | pEdcaParm->Aifsn[QID_AC_BK] = 7; |
| 659 | pEdcaParm->Cwmin[QID_AC_BK] = CW_MIN_IN_BITS; |
| 660 | pEdcaParm->Cwmax[QID_AC_BK] = CW_MAX_IN_BITS; |
| 661 | pEdcaParm->Txop[QID_AC_BK] = 0; |
| 662 | |
| 663 | pEdcaParm->bACM[QID_AC_VI] = 0; |
| 664 | pEdcaParm->Aifsn[QID_AC_VI] = 2; |
| 665 | pEdcaParm->Cwmin[QID_AC_VI] = CW_MIN_IN_BITS-1; |
| 666 | pEdcaParm->Cwmax[QID_AC_VI] = CW_MAX_IN_BITS; |
| 667 | pEdcaParm->Txop[QID_AC_VI] = 96; // AC_VI: 96*32us ~= 3ms |
| 668 | |
| 669 | pEdcaParm->bACM[QID_AC_VO] = 0; |
| 670 | pEdcaParm->Aifsn[QID_AC_VO] = 2; |
| 671 | pEdcaParm->Cwmin[QID_AC_VO] = CW_MIN_IN_BITS-2; |
| 672 | pEdcaParm->Cwmax[QID_AC_VO] = CW_MAX_IN_BITS-1; |
| 673 | pEdcaParm->Txop[QID_AC_VO] = 48; // AC_VO: 48*32us ~= 1.5ms |
| 674 | } |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 675 | else |
| 676 | { |
| 677 | } |
| 678 | |
| 679 | break; |
| 680 | |
| 681 | case IE_EXT_SUPP_RATES: |
| 682 | if (pEid->Len <= MAX_LEN_OF_SUPPORTED_RATES) |
| 683 | { |
| 684 | NdisMoveMemory(ExtRate, pEid->Octet, pEid->Len); |
| 685 | *pExtRateLen = pEid->Len; |
| 686 | |
| 687 | // TODO: 2004-09-14 not a good design here, cause it exclude extra rates |
| 688 | // from ScanTab. We should report as is. And filter out unsupported |
| 689 | // rates in MlmeAux. |
| 690 | // Check against the supported rates |
| 691 | // RTMPCheckRates(pAd, ExtRate, pExtRateLen); |
| 692 | } |
| 693 | break; |
| 694 | |
| 695 | case IE_ERP: |
| 696 | if (pEid->Len == 1) |
| 697 | { |
| 698 | *pErp = (UCHAR)pEid->Octet[0]; |
| 699 | } |
| 700 | break; |
| 701 | |
| 702 | case IE_AIRONET_CKIP: |
| 703 | // 0. Check Aironet IE length, it must be larger or equal to 28 |
| 704 | // Cisco AP350 used length as 28 |
| 705 | // Cisco AP12XX used length as 30 |
| 706 | if (pEid->Len < (CKIP_NEGOTIATION_LENGTH - 2)) |
| 707 | break; |
| 708 | |
| 709 | // 1. Copy CKIP flag byte to buffer for process |
| 710 | *pCkipFlag = *(pEid->Octet + 8); |
| 711 | break; |
| 712 | |
| 713 | case IE_AP_TX_POWER: |
| 714 | // AP Control of Client Transmit Power |
| 715 | //0. Check Aironet IE length, it must be 6 |
| 716 | if (pEid->Len != 0x06) |
| 717 | break; |
| 718 | |
| 719 | // Get cell power limit in dBm |
| 720 | if (NdisEqualMemory(pEid->Octet, CISCO_OUI, 3) == 1) |
| 721 | *pAironetCellPowerLimit = *(pEid->Octet + 4); |
| 722 | break; |
| 723 | |
| 724 | // WPA2 & 802.11i RSN |
| 725 | case IE_RSN: |
| 726 | // There is no OUI for version anymore, check the group cipher OUI before copying |
| 727 | if (RTMPEqualMemory(pEid->Octet + 2, RSN_OUI, 3)) |
| 728 | { |
| 729 | // Copy to pVIE which will report to microsoft bssid list. |
| 730 | Ptr = (PUCHAR) pVIE; |
| 731 | NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid, pEid->Len + 2); |
| 732 | *LengthVIE += (pEid->Len + 2); |
| 733 | } |
| 734 | break; |
Bartlomiej Zolnierkiewicz | 6fabd4e | 2009-04-26 16:05:16 +0200 | [diff] [blame] | 735 | |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 736 | default: |
| 737 | break; |
| 738 | } |
| 739 | |
| 740 | Length = Length + 2 + pEid->Len; // Eid[1] + Len[1]+ content[Len] |
| 741 | pEid = (PEID_STRUCT)((UCHAR*)pEid + 2 + pEid->Len); |
| 742 | } |
| 743 | |
| 744 | // For some 11a AP. it did not have the channel EID, patch here |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 745 | IF_DEV_CONFIG_OPMODE_ON_STA(pAd) |
| 746 | { |
| 747 | UCHAR LatchRfChannel = MsgChannel; |
| 748 | if ((pAd->LatchRfRegs.Channel > 14) && ((Sanity & 0x4) == 0)) |
| 749 | { |
| 750 | if (CtrlChannel != 0) |
| 751 | *pChannel = CtrlChannel; |
| 752 | else |
| 753 | *pChannel = LatchRfChannel; |
| 754 | Sanity |= 0x4; |
| 755 | } |
| 756 | } |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 757 | |
| 758 | if (Sanity != 0x7) |
| 759 | { |
| 760 | DBGPRINT(RT_DEBUG_WARN, ("PeerBeaconAndProbeRspSanity - missing field, Sanity=0x%02x\n", Sanity)); |
| 761 | return FALSE; |
| 762 | } |
| 763 | else |
| 764 | { |
| 765 | return TRUE; |
| 766 | } |
| 767 | |
| 768 | } |
| 769 | |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 770 | /* |
| 771 | ========================================================================== |
| 772 | Description: |
| 773 | MLME message sanity check |
| 774 | Return: |
| 775 | TRUE if all parameters are OK, FALSE otherwise |
| 776 | ========================================================================== |
| 777 | */ |
| 778 | BOOLEAN MlmeScanReqSanity( |
| 779 | IN PRTMP_ADAPTER pAd, |
| 780 | IN VOID *Msg, |
| 781 | IN ULONG MsgLen, |
| 782 | OUT UCHAR *pBssType, |
| 783 | OUT CHAR Ssid[], |
| 784 | OUT UCHAR *pSsidLen, |
| 785 | OUT UCHAR *pScanType) |
| 786 | { |
| 787 | MLME_SCAN_REQ_STRUCT *Info; |
| 788 | |
| 789 | Info = (MLME_SCAN_REQ_STRUCT *)(Msg); |
| 790 | *pBssType = Info->BssType; |
| 791 | *pSsidLen = Info->SsidLen; |
| 792 | NdisMoveMemory(Ssid, Info->Ssid, *pSsidLen); |
| 793 | *pScanType = Info->ScanType; |
| 794 | |
| 795 | if ((*pBssType == BSS_INFRA || *pBssType == BSS_ADHOC || *pBssType == BSS_ANY) |
| 796 | && (*pScanType == SCAN_ACTIVE || *pScanType == SCAN_PASSIVE |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 797 | || *pScanType == SCAN_CISCO_PASSIVE || *pScanType == SCAN_CISCO_ACTIVE |
| 798 | || *pScanType == SCAN_CISCO_CHANNEL_LOAD || *pScanType == SCAN_CISCO_NOISE |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 799 | )) |
| 800 | { |
| 801 | return TRUE; |
| 802 | } |
| 803 | else |
| 804 | { |
| 805 | DBGPRINT(RT_DEBUG_TRACE, ("MlmeScanReqSanity fail - wrong BssType or ScanType\n")); |
| 806 | return FALSE; |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | // IRQL = DISPATCH_LEVEL |
| 811 | UCHAR ChannelSanity( |
| 812 | IN PRTMP_ADAPTER pAd, |
| 813 | IN UCHAR channel) |
| 814 | { |
| 815 | int i; |
| 816 | |
| 817 | for (i = 0; i < pAd->ChannelListNum; i ++) |
| 818 | { |
| 819 | if (channel == pAd->ChannelList[i].Channel) |
| 820 | return 1; |
| 821 | } |
| 822 | return 0; |
| 823 | } |
| 824 | |
| 825 | /* |
| 826 | ========================================================================== |
| 827 | Description: |
| 828 | MLME message sanity check |
| 829 | Return: |
| 830 | TRUE if all parameters are OK, FALSE otherwise |
| 831 | |
| 832 | IRQL = DISPATCH_LEVEL |
| 833 | |
| 834 | ========================================================================== |
| 835 | */ |
| 836 | BOOLEAN PeerDeauthSanity( |
| 837 | IN PRTMP_ADAPTER pAd, |
| 838 | IN VOID *Msg, |
| 839 | IN ULONG MsgLen, |
| 840 | OUT PUCHAR pAddr2, |
| 841 | OUT USHORT *pReason) |
| 842 | { |
| 843 | PFRAME_802_11 pFrame = (PFRAME_802_11)Msg; |
| 844 | |
| 845 | COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2); |
| 846 | NdisMoveMemory(pReason, &pFrame->Octet[0], 2); |
| 847 | |
| 848 | return TRUE; |
| 849 | } |
| 850 | |
| 851 | /* |
| 852 | ========================================================================== |
| 853 | Description: |
| 854 | MLME message sanity check |
| 855 | Return: |
| 856 | TRUE if all parameters are OK, FALSE otherwise |
| 857 | |
| 858 | IRQL = DISPATCH_LEVEL |
| 859 | |
| 860 | ========================================================================== |
| 861 | */ |
| 862 | BOOLEAN PeerAuthSanity( |
| 863 | IN PRTMP_ADAPTER pAd, |
| 864 | IN VOID *Msg, |
| 865 | IN ULONG MsgLen, |
| 866 | OUT PUCHAR pAddr, |
| 867 | OUT USHORT *pAlg, |
| 868 | OUT USHORT *pSeq, |
| 869 | OUT USHORT *pStatus, |
| 870 | CHAR *pChlgText) |
| 871 | { |
| 872 | PFRAME_802_11 pFrame = (PFRAME_802_11)Msg; |
| 873 | |
| 874 | COPY_MAC_ADDR(pAddr, pFrame->Hdr.Addr2); |
| 875 | NdisMoveMemory(pAlg, &pFrame->Octet[0], 2); |
| 876 | NdisMoveMemory(pSeq, &pFrame->Octet[2], 2); |
| 877 | NdisMoveMemory(pStatus, &pFrame->Octet[4], 2); |
| 878 | |
| 879 | if ((*pAlg == Ndis802_11AuthModeOpen) |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 880 | ) |
| 881 | { |
| 882 | if (*pSeq == 1 || *pSeq == 2) |
| 883 | { |
| 884 | return TRUE; |
| 885 | } |
| 886 | else |
| 887 | { |
| 888 | DBGPRINT(RT_DEBUG_TRACE, ("PeerAuthSanity fail - wrong Seg#\n")); |
| 889 | return FALSE; |
| 890 | } |
| 891 | } |
| 892 | else if (*pAlg == Ndis802_11AuthModeShared) |
| 893 | { |
| 894 | if (*pSeq == 1 || *pSeq == 4) |
| 895 | { |
| 896 | return TRUE; |
| 897 | } |
| 898 | else if (*pSeq == 2 || *pSeq == 3) |
| 899 | { |
| 900 | NdisMoveMemory(pChlgText, &pFrame->Octet[8], CIPHER_TEXT_LEN); |
| 901 | return TRUE; |
| 902 | } |
| 903 | else |
| 904 | { |
| 905 | DBGPRINT(RT_DEBUG_TRACE, ("PeerAuthSanity fail - wrong Seg#\n")); |
| 906 | return FALSE; |
| 907 | } |
| 908 | } |
| 909 | else |
| 910 | { |
| 911 | DBGPRINT(RT_DEBUG_TRACE, ("PeerAuthSanity fail - wrong algorithm\n")); |
| 912 | return FALSE; |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | /* |
| 917 | ========================================================================== |
| 918 | Description: |
| 919 | MLME message sanity check |
| 920 | Return: |
| 921 | TRUE if all parameters are OK, FALSE otherwise |
| 922 | ========================================================================== |
| 923 | */ |
| 924 | BOOLEAN MlmeAuthReqSanity( |
| 925 | IN PRTMP_ADAPTER pAd, |
| 926 | IN VOID *Msg, |
| 927 | IN ULONG MsgLen, |
| 928 | OUT PUCHAR pAddr, |
| 929 | OUT ULONG *pTimeout, |
| 930 | OUT USHORT *pAlg) |
| 931 | { |
| 932 | MLME_AUTH_REQ_STRUCT *pInfo; |
| 933 | |
| 934 | pInfo = (MLME_AUTH_REQ_STRUCT *)Msg; |
| 935 | COPY_MAC_ADDR(pAddr, pInfo->Addr); |
| 936 | *pTimeout = pInfo->Timeout; |
| 937 | *pAlg = pInfo->Alg; |
| 938 | |
| 939 | if (((*pAlg == Ndis802_11AuthModeShared) ||(*pAlg == Ndis802_11AuthModeOpen) |
Greg Kroah-Hartman | e642f09 | 2009-02-25 16:14:55 -0800 | [diff] [blame] | 940 | ) && |
| 941 | ((*pAddr & 0x01) == 0)) |
| 942 | { |
| 943 | return TRUE; |
| 944 | } |
| 945 | else |
| 946 | { |
| 947 | DBGPRINT(RT_DEBUG_TRACE, ("MlmeAuthReqSanity fail - wrong algorithm\n")); |
| 948 | return FALSE; |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | /* |
| 953 | ========================================================================== |
| 954 | Description: |
| 955 | MLME message sanity check |
| 956 | Return: |
| 957 | TRUE if all parameters are OK, FALSE otherwise |
| 958 | |
| 959 | IRQL = DISPATCH_LEVEL |
| 960 | |
| 961 | ========================================================================== |
| 962 | */ |
| 963 | BOOLEAN MlmeAssocReqSanity( |
| 964 | IN PRTMP_ADAPTER pAd, |
| 965 | IN VOID *Msg, |
| 966 | IN ULONG MsgLen, |
| 967 | OUT PUCHAR pApAddr, |
| 968 | OUT USHORT *pCapabilityInfo, |
| 969 | OUT ULONG *pTimeout, |
| 970 | OUT USHORT *pListenIntv) |
| 971 | { |
| 972 | MLME_ASSOC_REQ_STRUCT *pInfo; |
| 973 | |
| 974 | pInfo = (MLME_ASSOC_REQ_STRUCT *)Msg; |
| 975 | *pTimeout = pInfo->Timeout; // timeout |
| 976 | COPY_MAC_ADDR(pApAddr, pInfo->Addr); // AP address |
| 977 | *pCapabilityInfo = pInfo->CapabilityInfo; // capability info |
| 978 | *pListenIntv = pInfo->ListenIntv; |
| 979 | |
| 980 | return TRUE; |
| 981 | } |
| 982 | |
| 983 | /* |
| 984 | ========================================================================== |
| 985 | Description: |
| 986 | MLME message sanity check |
| 987 | Return: |
| 988 | TRUE if all parameters are OK, FALSE otherwise |
| 989 | |
| 990 | IRQL = DISPATCH_LEVEL |
| 991 | |
| 992 | ========================================================================== |
| 993 | */ |
| 994 | BOOLEAN PeerDisassocSanity( |
| 995 | IN PRTMP_ADAPTER pAd, |
| 996 | IN VOID *Msg, |
| 997 | IN ULONG MsgLen, |
| 998 | OUT PUCHAR pAddr2, |
| 999 | OUT USHORT *pReason) |
| 1000 | { |
| 1001 | PFRAME_802_11 pFrame = (PFRAME_802_11)Msg; |
| 1002 | |
| 1003 | COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2); |
| 1004 | NdisMoveMemory(pReason, &pFrame->Octet[0], 2); |
| 1005 | |
| 1006 | return TRUE; |
| 1007 | } |
| 1008 | |
| 1009 | /* |
| 1010 | ======================================================================== |
| 1011 | Routine Description: |
| 1012 | Sanity check NetworkType (11b, 11g or 11a) |
| 1013 | |
| 1014 | Arguments: |
| 1015 | pBss - Pointer to BSS table. |
| 1016 | |
| 1017 | Return Value: |
| 1018 | Ndis802_11DS .......(11b) |
| 1019 | Ndis802_11OFDM24....(11g) |
| 1020 | Ndis802_11OFDM5.....(11a) |
| 1021 | |
| 1022 | IRQL = DISPATCH_LEVEL |
| 1023 | |
| 1024 | ======================================================================== |
| 1025 | */ |
| 1026 | NDIS_802_11_NETWORK_TYPE NetworkTypeInUseSanity( |
| 1027 | IN PBSS_ENTRY pBss) |
| 1028 | { |
| 1029 | NDIS_802_11_NETWORK_TYPE NetWorkType; |
| 1030 | UCHAR rate, i; |
| 1031 | |
| 1032 | NetWorkType = Ndis802_11DS; |
| 1033 | |
| 1034 | if (pBss->Channel <= 14) |
| 1035 | { |
| 1036 | // |
| 1037 | // First check support Rate. |
| 1038 | // |
| 1039 | for (i = 0; i < pBss->SupRateLen; i++) |
| 1040 | { |
| 1041 | rate = pBss->SupRate[i] & 0x7f; // Mask out basic rate set bit |
| 1042 | if ((rate == 2) || (rate == 4) || (rate == 11) || (rate == 22)) |
| 1043 | { |
| 1044 | continue; |
| 1045 | } |
| 1046 | else |
| 1047 | { |
| 1048 | // |
| 1049 | // Otherwise (even rate > 108) means Ndis802_11OFDM24 |
| 1050 | // |
| 1051 | NetWorkType = Ndis802_11OFDM24; |
| 1052 | break; |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | // |
| 1057 | // Second check Extend Rate. |
| 1058 | // |
| 1059 | if (NetWorkType != Ndis802_11OFDM24) |
| 1060 | { |
| 1061 | for (i = 0; i < pBss->ExtRateLen; i++) |
| 1062 | { |
| 1063 | rate = pBss->SupRate[i] & 0x7f; // Mask out basic rate set bit |
| 1064 | if ((rate == 2) || (rate == 4) || (rate == 11) || (rate == 22)) |
| 1065 | { |
| 1066 | continue; |
| 1067 | } |
| 1068 | else |
| 1069 | { |
| 1070 | // |
| 1071 | // Otherwise (even rate > 108) means Ndis802_11OFDM24 |
| 1072 | // |
| 1073 | NetWorkType = Ndis802_11OFDM24; |
| 1074 | break; |
| 1075 | } |
| 1076 | } |
| 1077 | } |
| 1078 | } |
| 1079 | else |
| 1080 | { |
| 1081 | NetWorkType = Ndis802_11OFDM5; |
| 1082 | } |
| 1083 | |
| 1084 | if (pBss->HtCapabilityLen != 0) |
| 1085 | { |
| 1086 | if (NetWorkType == Ndis802_11OFDM5) |
| 1087 | NetWorkType = Ndis802_11OFDM5_N; |
| 1088 | else |
| 1089 | NetWorkType = Ndis802_11OFDM24_N; |
| 1090 | } |
| 1091 | |
| 1092 | return NetWorkType; |
| 1093 | } |
| 1094 | |
| 1095 | /* |
| 1096 | ========================================================================== |
| 1097 | Description: |
| 1098 | WPA message sanity check |
| 1099 | Return: |
| 1100 | TRUE if all parameters are OK, FALSE otherwise |
| 1101 | ========================================================================== |
| 1102 | */ |
| 1103 | BOOLEAN PeerWpaMessageSanity( |
| 1104 | IN PRTMP_ADAPTER pAd, |
| 1105 | IN PEAPOL_PACKET pMsg, |
| 1106 | IN ULONG MsgLen, |
| 1107 | IN UCHAR MsgType, |
| 1108 | IN MAC_TABLE_ENTRY *pEntry) |
| 1109 | { |
| 1110 | UCHAR mic[LEN_KEY_DESC_MIC], digest[80], KEYDATA[MAX_LEN_OF_RSNIE]; |
| 1111 | BOOLEAN bReplayDiff = FALSE; |
| 1112 | BOOLEAN bWPA2 = FALSE; |
| 1113 | KEY_INFO EapolKeyInfo; |
| 1114 | UCHAR GroupKeyIndex = 0; |
| 1115 | |
| 1116 | |
| 1117 | NdisZeroMemory(mic, sizeof(mic)); |
| 1118 | NdisZeroMemory(digest, sizeof(digest)); |
| 1119 | NdisZeroMemory(KEYDATA, sizeof(KEYDATA)); |
| 1120 | NdisZeroMemory((PUCHAR)&EapolKeyInfo, sizeof(EapolKeyInfo)); |
| 1121 | |
| 1122 | NdisMoveMemory((PUCHAR)&EapolKeyInfo, (PUCHAR)&pMsg->KeyDesc.KeyInfo, sizeof(KEY_INFO)); |
| 1123 | |
| 1124 | *((USHORT *)&EapolKeyInfo) = cpu2le16(*((USHORT *)&EapolKeyInfo)); |
| 1125 | |
| 1126 | // Choose WPA2 or not |
| 1127 | if ((pEntry->AuthMode == Ndis802_11AuthModeWPA2) || (pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK)) |
| 1128 | bWPA2 = TRUE; |
| 1129 | |
| 1130 | // 0. Check MsgType |
| 1131 | if ((MsgType > EAPOL_GROUP_MSG_2) || (MsgType < EAPOL_PAIR_MSG_1)) |
| 1132 | { |
| 1133 | DBGPRINT(RT_DEBUG_ERROR, ("The message type is invalid(%d)! \n", MsgType)); |
| 1134 | return FALSE; |
| 1135 | } |
| 1136 | |
| 1137 | // 1. Replay counter check |
| 1138 | if (MsgType == EAPOL_PAIR_MSG_1 || MsgType == EAPOL_PAIR_MSG_3 || MsgType == EAPOL_GROUP_MSG_1) // For supplicant |
| 1139 | { |
| 1140 | // First validate replay counter, only accept message with larger replay counter. |
| 1141 | // Let equal pass, some AP start with all zero replay counter |
| 1142 | UCHAR ZeroReplay[LEN_KEY_DESC_REPLAY]; |
| 1143 | |
| 1144 | NdisZeroMemory(ZeroReplay, LEN_KEY_DESC_REPLAY); |
| 1145 | if ((RTMPCompareMemory(pMsg->KeyDesc.ReplayCounter, pEntry->R_Counter, LEN_KEY_DESC_REPLAY) != 1) && |
| 1146 | (RTMPCompareMemory(pMsg->KeyDesc.ReplayCounter, ZeroReplay, LEN_KEY_DESC_REPLAY) != 0)) |
| 1147 | { |
| 1148 | bReplayDiff = TRUE; |
| 1149 | } |
| 1150 | } |
| 1151 | else if (MsgType == EAPOL_PAIR_MSG_2 || MsgType == EAPOL_PAIR_MSG_4 || MsgType == EAPOL_GROUP_MSG_2) // For authenticator |
| 1152 | { |
| 1153 | // check Replay Counter coresponds to MSG from authenticator, otherwise discard |
| 1154 | if (!NdisEqualMemory(pMsg->KeyDesc.ReplayCounter, pEntry->R_Counter, LEN_KEY_DESC_REPLAY)) |
| 1155 | { |
| 1156 | bReplayDiff = TRUE; |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | // Replay Counter different condition |
| 1161 | if (bReplayDiff) |
| 1162 | { |
| 1163 | // send wireless event - for replay counter different |
| 1164 | if (pAd->CommonCfg.bWirelessEvent) |
| 1165 | RTMPSendWirelessEvent(pAd, IW_REPLAY_COUNTER_DIFF_EVENT_FLAG, pEntry->Addr, pEntry->apidx, 0); |
| 1166 | |
| 1167 | if (MsgType < EAPOL_GROUP_MSG_1) |
| 1168 | { |
| 1169 | DBGPRINT(RT_DEBUG_ERROR, ("Replay Counter Different in pairwise msg %d of 4-way handshake!\n", MsgType)); |
| 1170 | } |
| 1171 | else |
| 1172 | { |
| 1173 | DBGPRINT(RT_DEBUG_ERROR, ("Replay Counter Different in group msg %d of 2-way handshake!\n", (MsgType - EAPOL_PAIR_MSG_4))); |
| 1174 | } |
| 1175 | |
| 1176 | hex_dump("Receive replay counter ", pMsg->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY); |
| 1177 | hex_dump("Current replay counter ", pEntry->R_Counter, LEN_KEY_DESC_REPLAY); |
| 1178 | return FALSE; |
| 1179 | } |
| 1180 | |
| 1181 | // 2. Verify MIC except Pairwise Msg1 |
| 1182 | if (MsgType != EAPOL_PAIR_MSG_1) |
| 1183 | { |
| 1184 | UCHAR rcvd_mic[LEN_KEY_DESC_MIC]; |
| 1185 | |
| 1186 | // Record the received MIC for check later |
| 1187 | NdisMoveMemory(rcvd_mic, pMsg->KeyDesc.KeyMic, LEN_KEY_DESC_MIC); |
| 1188 | NdisZeroMemory(pMsg->KeyDesc.KeyMic, LEN_KEY_DESC_MIC); |
| 1189 | |
| 1190 | if (pEntry->WepStatus == Ndis802_11Encryption2Enabled) // TKIP |
| 1191 | { |
| 1192 | hmac_md5(pEntry->PTK, LEN_EAP_MICK, (PUCHAR)pMsg, MsgLen, mic); |
| 1193 | } |
| 1194 | else if (pEntry->WepStatus == Ndis802_11Encryption3Enabled) // AES |
| 1195 | { |
| 1196 | HMAC_SHA1((PUCHAR)pMsg, MsgLen, pEntry->PTK, LEN_EAP_MICK, digest); |
| 1197 | NdisMoveMemory(mic, digest, LEN_KEY_DESC_MIC); |
| 1198 | } |
| 1199 | |
| 1200 | if (!NdisEqualMemory(rcvd_mic, mic, LEN_KEY_DESC_MIC)) |
| 1201 | { |
| 1202 | // send wireless event - for MIC different |
| 1203 | if (pAd->CommonCfg.bWirelessEvent) |
| 1204 | RTMPSendWirelessEvent(pAd, IW_MIC_DIFF_EVENT_FLAG, pEntry->Addr, pEntry->apidx, 0); |
| 1205 | |
| 1206 | if (MsgType < EAPOL_GROUP_MSG_1) |
| 1207 | { |
| 1208 | DBGPRINT(RT_DEBUG_ERROR, ("MIC Different in pairwise msg %d of 4-way handshake!\n", MsgType)); |
| 1209 | } |
| 1210 | else |
| 1211 | { |
| 1212 | DBGPRINT(RT_DEBUG_ERROR, ("MIC Different in group msg %d of 2-way handshake!\n", (MsgType - EAPOL_PAIR_MSG_4))); |
| 1213 | } |
| 1214 | |
| 1215 | hex_dump("Received MIC", rcvd_mic, LEN_KEY_DESC_MIC); |
| 1216 | hex_dump("Desired MIC", mic, LEN_KEY_DESC_MIC); |
| 1217 | |
| 1218 | return FALSE; |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | // Extract the context of the Key Data field if it exist |
| 1223 | // The field in pairwise_msg_2_WPA1(WPA2) & pairwise_msg_3_WPA1 is un-encrypted. |
| 1224 | // The field in group_msg_1_WPA1(WPA2) & pairwise_msg_3_WPA2 is encrypted. |
| 1225 | if (pMsg->KeyDesc.KeyDataLen[1] > 0) |
| 1226 | { |
| 1227 | // Decrypt this field |
| 1228 | if ((MsgType == EAPOL_PAIR_MSG_3 && bWPA2) || (MsgType == EAPOL_GROUP_MSG_1)) |
| 1229 | { |
| 1230 | if(pEntry->WepStatus == Ndis802_11Encryption3Enabled) |
| 1231 | { |
| 1232 | // AES |
| 1233 | AES_GTK_KEY_UNWRAP(&pEntry->PTK[16], KEYDATA, pMsg->KeyDesc.KeyDataLen[1],pMsg->KeyDesc.KeyData); |
| 1234 | } |
| 1235 | else |
| 1236 | { |
| 1237 | INT i; |
| 1238 | UCHAR Key[32]; |
| 1239 | // Decrypt TKIP GTK |
| 1240 | // Construct 32 bytes RC4 Key |
| 1241 | NdisMoveMemory(Key, pMsg->KeyDesc.KeyIv, 16); |
| 1242 | NdisMoveMemory(&Key[16], &pEntry->PTK[16], 16); |
| 1243 | ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, Key, 32); |
| 1244 | //discard first 256 bytes |
| 1245 | for(i = 0; i < 256; i++) |
| 1246 | ARCFOUR_BYTE(&pAd->PrivateInfo.WEPCONTEXT); |
| 1247 | // Decrypt GTK. Becareful, there is no ICV to check the result is correct or not |
| 1248 | ARCFOUR_DECRYPT(&pAd->PrivateInfo.WEPCONTEXT, KEYDATA, pMsg->KeyDesc.KeyData, pMsg->KeyDesc.KeyDataLen[1]); |
| 1249 | } |
| 1250 | |
| 1251 | if (!bWPA2 && (MsgType == EAPOL_GROUP_MSG_1)) |
| 1252 | GroupKeyIndex = EapolKeyInfo.KeyIndex; |
| 1253 | |
| 1254 | } |
| 1255 | else if ((MsgType == EAPOL_PAIR_MSG_2) || (MsgType == EAPOL_PAIR_MSG_3 && !bWPA2)) |
| 1256 | { |
| 1257 | NdisMoveMemory(KEYDATA, pMsg->KeyDesc.KeyData, pMsg->KeyDesc.KeyDataLen[1]); |
| 1258 | } |
| 1259 | else |
| 1260 | { |
| 1261 | |
| 1262 | return TRUE; |
| 1263 | } |
| 1264 | |
| 1265 | // Parse Key Data field to |
| 1266 | // 1. verify RSN IE for pairwise_msg_2_WPA1(WPA2) ,pairwise_msg_3_WPA1(WPA2) |
| 1267 | // 2. verify KDE format for pairwise_msg_3_WPA2, group_msg_1_WPA2 |
| 1268 | // 3. update shared key for pairwise_msg_3_WPA2, group_msg_1_WPA1(WPA2) |
| 1269 | if (!RTMPParseEapolKeyData(pAd, KEYDATA, pMsg->KeyDesc.KeyDataLen[1], GroupKeyIndex, MsgType, bWPA2, pEntry)) |
| 1270 | { |
| 1271 | return FALSE; |
| 1272 | } |
| 1273 | } |
| 1274 | |
| 1275 | return TRUE; |
| 1276 | |
| 1277 | } |