4 * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name Texas Instruments nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 /** \file KeyParserWep.c
35 * \brief Wep key parser implementation.
40 /****************************************************************************
42 * MODULE: Wep Key Parser *
43 * PURPOSE: EAP parser implementation *
45 ****************************************************************************/
47 #define __FILE_ID__ FILE_ID_35
54 #include "keyParser.h"
55 #include "keyParserWep.h"
56 #include "mainKeysSm.h"
58 #include "unicastKeySM.h"
59 #include "broadcastKeySM.h"
62 TI_STATUS keyParserWep_recv(struct _keyParser_t *pKeyParser, TI_UINT8 *pKeyData, TI_UINT32 keyDataLen);
63 TI_STATUS keyParserWep_remove(struct _keyParser_t *pKeyParser, TI_UINT8 *pKeyData, TI_UINT32 keyDataLen);
67 * Function - Init KEY Parser module.
71 * Called by RSN Manager.
72 * Registers the function 'rsn_keyParserRecv()' at the distributor to receive KEY frames upon receiving a KEY_RECV event.
79 * TI_STATUS - 0 on success, any other value on failure.
83 TI_STATUS keyParserWep_config(struct _keyParser_t *pKeyParser)
85 pKeyParser->recv = keyParserWep_recv;
86 pKeyParser->replayReset = keyParser_nop;
87 pKeyParser->remove = keyParserWep_remove;
98 * WEP key Parser receive function:
99 * - Called by the utility or NDIS (Windows) upon receiving a WEP Key.
100 * - Filters the following keys:
102 * - Keys with size different than 40-bit, 104-bit and 232-bit
103 * - Keys with invalid key index
107 * I - pKeyParser - Pointer to the keyParser context \n
108 * I - pKeyData - A pointer to the Key Data. \n
109 * I - keyDataLen - The Key Data length. \n
113 * TI_OK on success, TI_NOK otherwise.
116 TI_STATUS keyParserWep_recv(struct _keyParser_t *pKeyParser,
117 TI_UINT8 *pKeyData, TI_UINT32 keyDataLen)
120 OS_802_11_KEY *pKeyDesc;
121 TSecurityKeys securityKey;
123 if (pKeyData == NULL)
125 TRACE0(pKeyParser->hReport, REPORT_SEVERITY_ERROR, "WEP_KEY_PARSER: ERROR: NULL KEY Data\n");
129 pKeyDesc = (OS_802_11_KEY*)pKeyData;
131 if ((pKeyDesc->KeyLength < MIN_KEY_LEN ) || (pKeyDesc->KeyLength >= MAX_KEY_LEN ))
133 TRACE1(pKeyParser->hReport, REPORT_SEVERITY_ERROR, "WEP_KEY_PARSER: ERROR: Key Length out of bounds=%d\n", pKeyDesc->KeyLength);
137 if (pKeyDesc->KeyIndex & WEP_KEY_REMAIN_BITS_MASK)
138 { /* the reamining bits in the key index are not 0 (when they should be) */
139 TRACE0(pKeyParser->hReport, REPORT_SEVERITY_ERROR, "WEP_KEY_PARSER: ERROR: Key index bits 8-29 should be 0 !!!\n");
143 securityKey.keyType = KEY_WEP;
144 securityKey.encLen = (TI_UINT16)pKeyDesc->KeyLength;
145 securityKey.keyIndex = pKeyDesc->KeyIndex;
146 os_memoryCopy(pKeyParser->hOs, (void *)securityKey.encKey, pKeyDesc->KeyMaterial, pKeyDesc->KeyLength);
148 TRACE2(pKeyParser->hReport, REPORT_SEVERITY_INFORMATION, "WEP_KEY_PARSER: Key received keyId=%x, keyLen=%d\n", pKeyDesc->KeyIndex, pKeyDesc->KeyLength);
151 /* We accept only 40, 104 or 232 -bit WEP keys*/
152 if (!((securityKey.encLen == WEP_KEY_LEN_40) || (securityKey.encLen == WEP_KEY_LEN_104)
153 || (securityKey.encLen == WEP_KEY_LEN_232)))
154 { /*Invalid key length*/
155 TRACE1(pKeyParser->hReport, REPORT_SEVERITY_ERROR, "WEP_KEY_PARSER: ERROR: Invalid Key length: %d !!!\n", securityKey.encLen);
158 /* configure key for Tx and Rx */
159 if (pKeyDesc->KeyIndex & WEP_KEY_TRANSMIT_MASK)
160 { /* configure default key for Tx - unicast */
161 status = pKeyParser->pParent->setDefaultKeyId(pKeyParser->pParent, (TI_UINT8)securityKey.keyIndex);
167 /* configure key for Tx - unicast, and Rx - broadcast*/
168 status = pKeyParser->pParent->setKey(pKeyParser->pParent, &securityKey);
175 TI_STATUS keyParserWep_remove(struct _keyParser_t *pKeyParser, TI_UINT8 *pKeyData, TI_UINT32 keyDataLen)
178 OS_802_11_KEY *pKeyDesc;
179 encodedKeyMaterial_t encodedKeyMaterial;
180 TI_UINT8 keyBuffer[MAC_ADDR_LEN+KEY_RSC_LEN+MAX_WEP_KEY_DATA_LENGTH];
182 if (pKeyData == NULL)
184 TRACE0(pKeyParser->hReport, REPORT_SEVERITY_ERROR, "EXT_KEY_PARSER: ERROR: NULL KEY Data\n");
188 pKeyDesc = (OS_802_11_KEY*)pKeyData;
190 if (pKeyDesc->KeyIndex & WEP_KEY_TRANSMIT_MASK)
191 { /* Bit 31 should always be zero */
192 TRACE0(pKeyParser->hReport, REPORT_SEVERITY_ERROR, "WEP_KEY_PARSER: ERROR: Remove TX key index\n");
196 encodedKeyMaterial.keyId = pKeyDesc->KeyIndex;
197 encodedKeyMaterial.keyLen = 0;
198 encodedKeyMaterial.pData = (char *) keyBuffer;
199 MAC_COPY (keyBuffer, pKeyDesc->BSSID);
201 /* which should we delete ????*/
202 status = pKeyParser->pBcastKey->pKeyDerive->remove(pKeyParser->pUcastKey->pKeyDerive, &encodedKeyMaterial);