1 /* 2 * keyDeriveWep.c 3 * 4 * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 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 16 * distribution. 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. 20 * 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. 32 */ 33 34 /** \file wepBroadcastKeyDerivation.c 35 * \brief WEP broadcast key derivation implementation. 36 * 37 * \see wepBroadcastKeyDerivation.h 38 */ 39 40 /**************************************************************************** 41 * * 42 * MODULE: WEP broadcast key derivation * 43 * PURPOSE: WEP broadcast key derivation * 44 * * 45 ****************************************************************************/ 46 47 #define __FILE_ID__ FILE_ID_32 48 #include "osApi.h" 49 #include "report.h" 50 #include "rsnApi.h" 51 52 #include "keyDerive.h" 53 #include "keyDeriveWep.h" 54 55 #include "mainKeysSm.h" 56 57 /** 58 * 59 * rsn_wepBroadcastKeyDerivationInit 60 * 61 * \b Description: 62 * 63 * WEP broadcast key derivation init function: 64 * - Initializes the derive & remove callback functions 65 * - Resets the key material in the system control block 66 * 67 * \b ARGS: 68 * 69 * None 70 * 71 * \b RETURNS: 72 * 73 * TI_OK on success, TI_NOK otherwise. 74 */ 75 76 TI_STATUS keyDeriveWep_config(struct _keyDerive_t *pKeyDerive) 77 { 78 pKeyDerive->derive = keyDeriveWep_derive; 79 pKeyDerive->remove = keyDeriveWep_remove; 80 81 return TI_OK; 82 } 83 84 85 /** 86 * 87 * wepBroadcastKeyDerivationDerive 88 * 89 * \b Description: 90 * 91 * WEP broadcast key derivation function: 92 * - Decodes the key material. 93 * - Distribute the decoded key material to the driver. 94 * 95 * \b ARGS: 96 * 97 * I - p - Pointer to the encoded key material. 98 * 99 * \b RETURNS: 100 * 101 * TI_OK on success, TI_NOK otherwise. 102 */ 103 104 TI_STATUS keyDeriveWep_derive(struct _keyDerive_t *pKeyDerive, encodedKeyMaterial_t *pEncodedKey) 105 { 106 TI_STATUS status; 107 TSecurityKeys key; 108 109 if (pEncodedKey==NULL) 110 { 111 return TI_NOK; 112 } 113 114 if ((pEncodedKey->keyLen != DERIVE_WEP_KEY_LEN_40) && 115 (pEncodedKey->keyLen != DERIVE_WEP_KEY_LEN_104) && 116 (pEncodedKey->keyLen != DERIVE_WEP_KEY_LEN_232)) 117 { 118 TRACE1(pKeyDerive->hReport, REPORT_SEVERITY_ERROR, "DeriveWep_derive: ERROR: it is not WEP key lenghth (len=%d) !!!\n", pEncodedKey->keyLen); 119 return TI_NOK; 120 } 121 122 key.keyType = KEY_WEP; 123 key.keyIndex = (TI_UINT8)pEncodedKey->keyId; 124 key.encLen = (TI_UINT16)pEncodedKey->keyLen; 125 os_memoryCopy(pKeyDerive->hOs, (void *)key.encKey, pEncodedKey->pData, pEncodedKey->keyLen); 126 127 status = pKeyDerive->pMainKeys->setKey(pKeyDerive->pMainKeys, &key); 128 if (status == TI_OK) 129 { 130 os_memoryCopy(pKeyDerive->hOs, &pKeyDerive->key, pEncodedKey, sizeof(encodedKeyMaterial_t)); 131 } 132 133 return status; 134 } 135 136 /** 137 * 138 * wepBroadcastKeyDerivationRemove 139 * 140 * \b Description: 141 * 142 * WEP broadcast key removal function: 143 * - Remove the key material from the driver. 144 * 145 * \b ARGS: 146 * 147 * None. 148 * 149 * \b RETURNS: 150 * 151 * TI_OK on success, TI_NOK otherwise. 152 */ 153 154 TI_STATUS keyDeriveWep_remove(struct _keyDerive_t *pKeyDerive, encodedKeyMaterial_t *pEncodedKey) 155 { 156 TI_STATUS status; 157 TSecurityKeys key; 158 159 os_memoryZero(pKeyDerive->hOs, &key, sizeof(TSecurityKeys)); 160 key.keyType = KEY_WEP; 161 key.keyIndex = (TI_UINT8)pEncodedKey->keyId; 162 key.encLen = (TI_UINT16)pKeyDerive->key.keyLen; 163 MAC_COPY (key.macAddress, pEncodedKey->pData); 164 165 status = pKeyDerive->pMainKeys->removeKey(pKeyDerive->pMainKeys, &key); 166 if (status == TI_OK) 167 { 168 os_memoryZero(pKeyDerive->hOs, &pKeyDerive->key, sizeof(encodedKeyMaterial_t)); 169 } 170 171 return status; 172 } 173 174 175 176 TI_STATUS keyDeriveNone_config(struct _keyDerive_t *pKeyDerive) 177 { 178 pKeyDerive->derive = keyDeriveNone_derive; 179 pKeyDerive->remove = keyDeriveNone_remove; 180 181 return TI_OK; 182 } 183 184 185 TI_STATUS keyDeriveNone_derive(struct _keyDerive_t *pKeyDerive, encodedKeyMaterial_t *pEncodedKey) 186 { 187 TSecurityKeys key; 188 189 if (pEncodedKey==NULL) 190 { 191 return TI_NOK; 192 } 193 194 if ((pEncodedKey->keyLen != DERIVE_WEP_KEY_LEN_40) && 195 (pEncodedKey->keyLen != DERIVE_WEP_KEY_LEN_104) && 196 (pEncodedKey->keyLen != DERIVE_WEP_KEY_LEN_232)) 197 { 198 return TI_NOK; 199 } 200 201 key.keyType = KEY_WEP; 202 key.keyIndex = (TI_UINT8)pEncodedKey->keyId; 203 key.encLen = (TI_UINT16)pEncodedKey->keyLen; 204 os_memoryCopy(pKeyDerive->hOs, (void *)key.encKey, pEncodedKey->pData, pEncodedKey->keyLen); 205 206 pKeyDerive->pMainKeys->setKey(pKeyDerive->pMainKeys, &key); 207 208 return TI_OK; 209 } 210 211 212 /** 213 * 214 * keyDeriveNone_remove 215 * 216 * \b Description: 217 * 218 * WEP broadcast key removal function: 219 * - Remove the key material from the driver. 220 * 221 * \b ARGS: 222 * 223 * None. 224 * 225 * \b RETURNS: 226 * 227 * TI_OK on success, TI_NOK otherwise. 228 */ 229 230 TI_STATUS keyDeriveNone_remove(struct _keyDerive_t *pKeyDerive, encodedKeyMaterial_t *pEncodedKey) 231 { 232 233 return TI_OK; 234 } 235 236 237 238 239