Home | History | Annotate | Download | only in Connection_Managment
      1 /*
      2  * keyDeriveCkip.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 #ifdef XCC_MODULE_INCLUDED
     48 #define __FILE_ID__  FILE_ID_30
     49 #include "osApi.h"
     50 #include "report.h"
     51 #include "rsnApi.h"
     52 
     53 
     54 #include "keyDerive.h"
     55 #include "keyDeriveCkip.h"
     56 
     57 #include "mainKeysSm.h"
     58 #include "mainSecSm.h"
     59 #include "admCtrl.h"
     60 
     61 /**
     62 *
     63 * keyDeriveCkip_config
     64 *
     65 * \b Description:
     66 *
     67 * CKIP key derivation init function:
     68 *							- Initializes the derive & remove callback functions
     69 *							- Resets the key material in the system control block
     70 *
     71 * \b ARGS:
     72 *
     73 *  None
     74 *
     75 * \b RETURNS:
     76 *
     77 *  TI_OK on success, TI_NOK otherwise.
     78 */
     79 
     80 TI_STATUS keyDeriveCkip_config(struct _keyDerive_t *pKeyDerive)
     81 {
     82     pKeyDerive->derive = keyDeriveCkip_derive;
     83     pKeyDerive->remove = keyDeriveCkip_remove;
     84 
     85     return TI_OK;
     86 }
     87 
     88 
     89 /**
     90 *
     91 * keyDeriveCkip_derive
     92 *
     93 * \b Description:
     94 *
     95 * CKIP key derivation function:
     96 *							- Decodes the key material.
     97 *							- Distribute the decoded key material to the driver.
     98 *
     99 * \b ARGS:
    100 *
    101 *  I - p - Pointer to the encoded key material.
    102 *
    103 * \b RETURNS:
    104 *
    105 *  TI_OK on success, TI_NOK otherwise.
    106 */
    107 
    108 TI_STATUS keyDeriveCkip_derive(struct _keyDerive_t *pKeyDerive, encodedKeyMaterial_t *pEncodedKey)
    109 {
    110     TI_STATUS           status;
    111     TSecurityKeys      key;
    112     TI_UINT8               ckipIndex, keyIndex;
    113     TI_UINT8               ckipKey[KEY_DERIVE_CKIP_ENC_LEN];
    114 
    115     key.keyType = KEY_XCC;
    116     key.keyIndex = (TI_UINT8)pEncodedKey->keyId;
    117 
    118     if (pEncodedKey->keyLen != KEY_DERIVE_CKIP_ENC_LEN)
    119     {
    120         if ((pEncodedKey->keyLen != KEY_DERIVE_CKIP_5_LEN) && (pEncodedKey->keyLen != KEY_DERIVE_CKIP_13_LEN))
    121         {
    122             TRACE1(pKeyDerive->hReport, REPORT_SEVERITY_ERROR, "KEY_DERIVE_CKIP: ERROR: wrong key length %d !!!\n", pEncodedKey->keyLen);
    123             return TI_NOK;
    124         }
    125 
    126         keyIndex=0;
    127         for (ckipIndex=0; ckipIndex<KEY_DERIVE_CKIP_ENC_LEN; ckipIndex++)
    128         {
    129            ckipKey[ckipIndex]= pEncodedKey->pData[keyIndex];
    130 		   keyIndex++;
    131 		   if (keyIndex >= pEncodedKey->keyLen)
    132 		   {
    133 				keyIndex = 0;
    134 		   }
    135            /*keyIndex = ((keyIndex+1) <pEncodedKey->keyLen) ? keyIndex+1 : 0;*/
    136         }
    137     }
    138     else
    139     {
    140         for (ckipIndex=0; ckipIndex<KEY_DERIVE_CKIP_ENC_LEN; ckipIndex++)
    141         {
    142            ckipKey[ckipIndex]= pEncodedKey->pData[ckipIndex];
    143         }
    144     }
    145 
    146     if (pKeyDerive->pMainKeys->pParent->pParent->pAdmCtrl->encrInSw)
    147     {
    148         key.encLen = KEY_DERIVE_CKIP_ENC_LEN;
    149     }
    150     else
    151     {
    152         key.encLen = pEncodedKey->keyLen;
    153     }
    154 
    155     /* Copy encryption key - not expand */
    156     os_memoryCopy(pKeyDerive->hOs, (void*)key.encKey, ckipKey, key.encLen);
    157     /* Copy the MIC keys */
    158     os_memoryCopy(pKeyDerive->hOs, (void*)key.micRxKey, ckipKey, KEY_DERIVE_CKIP_ENC_LEN);
    159     os_memoryCopy(pKeyDerive->hOs, (void*)key.micTxKey, ckipKey, KEY_DERIVE_CKIP_ENC_LEN);
    160 
    161     status = pKeyDerive->pMainKeys->setKey(pKeyDerive->pMainKeys, &key);
    162     if (status == TI_OK)
    163     {
    164         os_memoryCopy(pKeyDerive->hOs, &pKeyDerive->key, pEncodedKey, sizeof(encodedKeyMaterial_t));
    165     }
    166 
    167     return status;
    168 }
    169 
    170 /**
    171 *
    172 * wepBroadcastKeyDerivationRemove
    173 *
    174 * \b Description:
    175 *
    176 * WEP broadcast key removal function:
    177 *							- Remove the key material from the driver.
    178 *
    179 * \b ARGS:
    180 *
    181 *  None.
    182 *
    183 * \b RETURNS:
    184 *
    185 *  TI_OK on success, TI_NOK otherwise.
    186 */
    187 
    188 TI_STATUS keyDeriveCkip_remove(struct _keyDerive_t *pKeyDerive, encodedKeyMaterial_t *pEncodedKey)
    189 {
    190     TI_STATUS status;
    191     TSecurityKeys  key;
    192 
    193     os_memoryZero(pKeyDerive->hOs, &key, sizeof(TSecurityKeys));
    194     key.keyType = KEY_XCC;
    195     key.keyIndex = (TI_UINT8)pEncodedKey->keyId;
    196     key.encLen = KEY_DERIVE_CKIP_ENC_LEN;
    197 	MAC_COPY (key.macAddress, pEncodedKey->pData);
    198 
    199     status = pKeyDerive->pMainKeys->removeKey(pKeyDerive->pMainKeys, &key);
    200     if (status == TI_OK)
    201     {
    202         os_memoryZero(pKeyDerive->hOs, &pKeyDerive->key, sizeof(encodedKeyMaterial_t));
    203     }
    204 
    205     return status;
    206 }
    207 
    208 #endif /* XCC_MODULE_INCLUDED */
    209 
    210