1/** \file KeyParserWep.c 2 * \brief Wep key parser implementation. 3 * 4 * \see keyParser.h 5*/ 6/**************************************************************************** 7**+-----------------------------------------------------------------------+** 8**| |** 9**| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved. |** 10**| All rights reserved. |** 11**| |** 12**| Redistribution and use in source and binary forms, with or without |** 13**| modification, are permitted provided that the following conditions |** 14**| are met: |** 15**| |** 16**| * Redistributions of source code must retain the above copyright |** 17**| notice, this list of conditions and the following disclaimer. |** 18**| * Redistributions in binary form must reproduce the above copyright |** 19**| notice, this list of conditions and the following disclaimer in |** 20**| the documentation and/or other materials provided with the |** 21**| distribution. |** 22**| * Neither the name Texas Instruments nor the names of its |** 23**| contributors may be used to endorse or promote products derived |** 24**| from this software without specific prior written permission. |** 25**| |** 26**| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |** 27**| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |** 28**| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |** 29**| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |** 30**| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |** 31**| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |** 32**| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |** 33**| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |** 34**| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |** 35**| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |** 36**| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |** 37**| |** 38**+-----------------------------------------------------------------------+** 39****************************************************************************/ 40 41/**************************************************************************** 42 * * 43 * MODULE: Wep Key Parser * 44 * PURPOSE: EAP parser implementation * 45 * * 46 ****************************************************************************/ 47 48#include "osTIType.h" 49#include "osApi.h" 50#include "report.h" 51#include "utils.h" 52 53#include "keyTypes.h" 54 55#include "keyParser.h" 56#include "keyParserWep.h" 57#include "mainKeysSm.h" 58 59#include "unicastKeySM.h" 60#include "broadcastKeySM.h" 61 62 63TI_STATUS keyParserWep_recv(struct _keyParser_t *pKeyParser, UINT8 *pKeyData, UINT32 keyDataLen); 64TI_STATUS keyParserWep_remove(struct _keyParser_t *pKeyParser, UINT8 *pKeyData, UINT32 keyDataLen); 65 66/** 67* 68* Function - Init KEY Parser module. 69* 70* \b Description: 71* 72* Called by RSN Manager. 73* Registers the function 'rsn_keyParserRecv()' at the distributor to receive KEY frames upon receiving a KEY_RECV event. 74* 75* \b ARGS: 76* 77* 78* \b RETURNS: 79* 80* TI_STATUS - 0 on success, any other value on failure. 81* 82*/ 83 84TI_STATUS keyParserWep_config(struct _keyParser_t *pKeyParser) 85{ 86 pKeyParser->recv = keyParserWep_recv; 87 pKeyParser->replayReset = keyParser_nop; 88 pKeyParser->remove = keyParserWep_remove; 89 return OK; 90} 91 92 93/** 94* 95* keyParserWep_recv 96* 97* \b Description: 98* 99* WEP key Parser receive function: 100* - Called by the utility or NDIS (Windows) upon receiving a WEP Key. 101* - Filters the following keys: 102* - Per Client Keys 103* - Keys with size different than 40-bit, 104-bit and 232-bit 104* - Keys with invalid key index 105* 106* \b ARGS: 107* 108* I - pKeyParser - Pointer to the keyParser context \n 109* I - pKeyData - A pointer to the Key Data. \n 110* I - keyDataLen - The Key Data length. \n 111* 112* \b RETURNS: 113* 114* OK on success, NOK otherwise. 115* 116*/ 117TI_STATUS keyParserWep_recv(struct _keyParser_t *pKeyParser, 118 UINT8 *pKeyData, UINT32 keyDataLen) 119{ 120 TI_STATUS status; 121 OS_802_11_KEY *pKeyDesc; 122 securityKeys_t securityKey; 123 124 if (pKeyData == NULL) 125 { 126 WLAN_REPORT_ERROR(pKeyParser->hReport, RSN_MODULE_LOG, 127 ("WEP_KEY_PARSER: ERROR: NULL KEY Data\n")); 128 return NOK; 129 } 130 131 pKeyDesc = (OS_802_11_KEY*)pKeyData; 132 133 if ((pKeyDesc->KeyLength < MIN_KEY_LEN ) || (pKeyDesc->KeyLength >= MAX_KEY_LEN )) 134 { 135 WLAN_REPORT_ERROR(pKeyParser->hReport, RSN_MODULE_LOG, 136 ("WEP_KEY_PARSER: ERROR: Key Length out of bounds=%d\n", pKeyDesc->KeyLength)); 137 return NOK; 138 } 139 140 if (pKeyDesc->KeyIndex & WEP_KEY_REMAIN_BITS_MASK) 141 { /* the reamining bits in the key index are not 0 (when they should be) */ 142 WLAN_REPORT_ERROR(pKeyParser->hReport, RSN_MODULE_LOG, 143 ("WEP_KEY_PARSER: ERROR: Key index bits 8-29 should be 0 !!!\n")); 144 return NOK; 145 } 146 147 securityKey.keyType = WEP_KEY; 148 securityKey.encLen = (UINT16)pKeyDesc->KeyLength; 149 securityKey.keyIndex = pKeyDesc->KeyIndex; 150 os_memoryCopy(pKeyParser->hOs, (void *)securityKey.encKey, pKeyDesc->KeyMaterial, pKeyDesc->KeyLength); 151 152 WLAN_REPORT_INFORMATION(pKeyParser->hReport, RSN_MODULE_LOG, 153 ("WEP_KEY_PARSER: Key received keyId=%x, keyLen=%d\n", 154 pKeyDesc->KeyIndex, pKeyDesc->KeyLength)); 155 156 157 /* We accept only 40, 104 or 232 -bit WEP keys*/ 158 if (!((securityKey.encLen == WEP_KEY_LEN_40) || (securityKey.encLen == WEP_KEY_LEN_104) 159 || (securityKey.encLen == WEP_KEY_LEN_232))) 160 { /*Invalid key length*/ 161 WLAN_REPORT_ERROR(pKeyParser->hReport, RSN_MODULE_LOG, 162 ("WEP_KEY_PARSER: ERROR: Invalid Key length: %d !!!\n", securityKey.encLen)); 163 return NOK; 164 } 165 /* configure key for Tx and Rx */ 166 if (pKeyDesc->KeyIndex & WEP_KEY_TRANSMIT_MASK) 167 { /* configure default key for Tx - unicast */ 168 status = pKeyParser->pParent->setDefaultKeyId(pKeyParser->pParent, (UINT8)securityKey.keyIndex); 169 if (status!=OK) 170 { 171 return status; 172 } 173 } 174 /* configure key for Tx - unicast, and Rx - broadcast*/ 175 status = pKeyParser->pParent->setKey(pKeyParser->pParent, &securityKey); 176 177 return status; 178} 179 180 181 182TI_STATUS keyParserWep_remove(struct _keyParser_t *pKeyParser, UINT8 *pKeyData, UINT32 keyDataLen) 183{ 184 TI_STATUS status; 185 OS_802_11_KEY *pKeyDesc; 186 encodedKeyMaterial_t encodedKeyMaterial; 187 UINT8 keyBuffer[MAC_ADDR_LEN+KEY_RSC_LEN+MAX_WEP_KEY_DATA_LENGTH]; 188 189 if (pKeyData == NULL) 190 { 191 WLAN_REPORT_ERROR(pKeyParser->hReport, RSN_MODULE_LOG, 192 ("EXT_KEY_PARSER: ERROR: NULL KEY Data\n")); 193 return NOK; 194 } 195 196 pKeyDesc = (OS_802_11_KEY*)pKeyData; 197 198 if (pKeyDesc->KeyIndex & WEP_KEY_TRANSMIT_MASK) 199 { /* Bit 31 should always be zero */ 200 WLAN_REPORT_ERROR(pKeyParser->hReport, RSN_MODULE_LOG, 201 ("WEP_KEY_PARSER: ERROR: Remove TX key index\n")); 202 return NOK; 203 } 204 205 encodedKeyMaterial.keyId = pKeyDesc->KeyIndex; 206 encodedKeyMaterial.keyLen = 0; 207 encodedKeyMaterial.pData = (char *) keyBuffer; 208 os_memoryCopy(pKeyParser->hOs, keyBuffer, pKeyDesc->BSSID, MAC_ADDR_LEN); 209 210 /* which should we delete ????*/ 211 status = pKeyParser->pBcastKey->pKeyDerive->remove(pKeyParser->pUcastKey->pKeyDerive, &encodedKeyMaterial); 212 return status; 213 214} 215