1 /** \file wepBroadcastKeyDerivation.c 2 * \brief WEP broadcast key derivation implementation. 3 * 4 * \see wepBroadcastKeyDerivation.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 broadcast key derivation * 44 * PURPOSE: WEP broadcast key derivation * 45 * * 46 ****************************************************************************/ 47 48 #include "osApi.h" 49 #include "utils.h" 50 #include "report.h" 51 #include "rsnApi.h" 52 53 #include "keyDerive.h" 54 #include "keyDeriveTkip.h" 55 56 #include "mainKeysSm.h" 57 58 /** 59 * 60 * keyDeriveTkip_config 61 * 62 * \b Description: 63 * 64 * TKIP key derivation init function: 65 * - Initializes the derive & remove callback functions 66 * - Resets the key material in the system control block 67 * 68 * \b ARGS: 69 * 70 * None 71 * 72 * \b RETURNS: 73 * 74 * OK on success, NOK otherwise. 75 */ 76 77 TI_STATUS keyDeriveTkip_config(struct _keyDerive_t *pKeyDerive) 78 { 79 pKeyDerive->derive = keyDeriveTkip_derive; 80 pKeyDerive->remove = keyDeriveTkip_remove; 81 82 return OK; 83 } 84 85 86 /** 87 * 88 * keyDeriveTkip_derive 89 * 90 * \b Description: 91 * 92 * TKIP key derivation function: 93 * - Decodes the key material. 94 * - Distribute the decoded key material to the driver. 95 * 96 * \b ARGS: 97 * 98 * I - p - Pointer to the encoded key material. 99 * 100 * \b RETURNS: 101 * 102 * OK on success, NOK otherwise. 103 */ 104 105 TI_STATUS keyDeriveTkip_derive(struct _keyDerive_t *pKeyDerive, encodedKeyMaterial_t *pEncodedKey) 106 { 107 TI_STATUS status; 108 securityKeys_t key; 109 keyMaterialTkip_t *keyMaterialTkip; 110 111 if (pEncodedKey==NULL) 112 { 113 return NOK; 114 } 115 116 key.keyType = TKIP_KEY; 117 key.keyIndex = (UINT8)pEncodedKey->keyId; 118 key.encLen = KEY_DERIVE_TKIP_ENC_LEN; 119 120 121 if (pEncodedKey->keyLen < sizeof(keyMaterialTkip_t)) 122 { 123 WLAN_REPORT_ERROR(pKeyDerive->hReport, RSN_MODULE_LOG, 124 ("KEY_DERIVE_TKIP: ERROR: wrong key length %d !!!\n", key.encLen)); 125 return NOK; 126 } 127 128 keyMaterialTkip = (keyMaterialTkip_t*)pEncodedKey->pData; 129 /* Copy encryption key */ 130 os_memoryCopy(pKeyDerive->hOs, (void *)key.encKey, (void *)keyMaterialTkip->encKey, KEY_DERIVE_TKIP_ENC_LEN); 131 if (pEncodedKey->keyId & 0x10000000) 132 { /* Copy MIC RX */ 133 os_memoryCopy(pKeyDerive->hOs, (void *)key.micTxKey, (void *)keyMaterialTkip->micRxKey, KEY_DERIVE_TKIP_MIC_LEN); 134 /* Copy MIC RX */ 135 os_memoryCopy(pKeyDerive->hOs, (void *)key.micRxKey, (void *)keyMaterialTkip->micTxKey, KEY_DERIVE_TKIP_MIC_LEN); 136 } 137 else 138 { /* Copy MIC RX */ 139 os_memoryCopy(pKeyDerive->hOs, (void *)key.micRxKey, (void *)keyMaterialTkip->micRxKey, KEY_DERIVE_TKIP_MIC_LEN); 140 /* Copy MIC RX */ 141 os_memoryCopy(pKeyDerive->hOs, (void *)key.micTxKey, (void *)keyMaterialTkip->micTxKey, KEY_DERIVE_TKIP_MIC_LEN); 142 } 143 144 /* Copy MAC address key */ 145 os_memoryCopy(pKeyDerive->hOs, (void *)key.macAddress.addr, (void *)keyMaterialTkip->macAddress, MAC_ADDR_LEN); 146 /* Copy RSC */ 147 os_memoryCopy(pKeyDerive->hOs, (void *)key.keyRsc, (void *)keyMaterialTkip->keyRSC, KEY_RSC_LEN); 148 149 150 status = pKeyDerive->pMainKeys->setKey(pKeyDerive->pMainKeys, &key); 151 if (status == OK) 152 { 153 os_memoryCopy(pKeyDerive->hOs, &pKeyDerive->key, pEncodedKey, sizeof(encodedKeyMaterial_t)); 154 } 155 156 return status; 157 } 158 159 /** 160 * 161 * wepBroadcastKeyDerivationRemove 162 * 163 * \b Description: 164 * 165 * WEP broadcast key removal function: 166 * - Remove the key material from the driver. 167 * 168 * \b ARGS: 169 * 170 * None. 171 * 172 * \b RETURNS: 173 * 174 * OK on success, NOK otherwise. 175 */ 176 177 TI_STATUS keyDeriveTkip_remove(struct _keyDerive_t *pKeyDerive, encodedKeyMaterial_t *pEncodedKey) 178 { 179 TI_STATUS status; 180 securityKeys_t key; 181 182 os_memoryZero(pKeyDerive->hOs, &key, sizeof(securityKeys_t)); 183 key.keyType = TKIP_KEY; 184 key.keyIndex = (UINT8)pEncodedKey->keyId; 185 key.encLen = KEY_DERIVE_TKIP_ENC_LEN; 186 os_memoryCopy(pKeyDerive->hOs, (void *)key.macAddress.addr, pEncodedKey->pData, MAC_ADDR_LEN); 187 188 status = pKeyDerive->pMainKeys->removeKey(pKeyDerive->pMainKeys, &key); 189 if (status == OK) 190 { 191 os_memoryZero(pKeyDerive->hOs, &pKeyDerive->key, sizeof(encodedKeyMaterial_t)); 192 } 193 194 return status; 195 } 196 197