1981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* 2981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * keyDerive.c 3981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * 4981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved. 5981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * All rights reserved. 6981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * 7981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Redistribution and use in source and binary forms, with or without 8981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * modification, are permitted provided that the following conditions 9981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * are met: 10981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * 11981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * * Redistributions of source code must retain the above copyright 12981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * notice, this list of conditions and the following disclaimer. 13981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * * Redistributions in binary form must reproduce the above copyright 14981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * notice, this list of conditions and the following disclaimer in 15981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * the documentation and/or other materials provided with the 16981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * distribution. 17981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * * Neither the name Texas Instruments nor the names of its 18981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * contributors may be used to endorse or promote products derived 19981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * from this software without specific prior written permission. 20981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * 21981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */ 33981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 34981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/** \file keyDeriveSM.c 35981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief station unicast key SM implementation 36981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * 37981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \see keyDeriveSM.h 38981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*/ 39981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 40981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**************************************************************************** 41981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * * 42981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * MODULE: station unicast key SM * 43981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * PURPOSE: station unicast key SM implementation * 44981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * * 45981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ****************************************************************************/ 46981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 47981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define __FILE_ID__ FILE_ID_28 48981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "osApi.h" 49981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "report.h" 50981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "rsnApi.h" 51981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 52981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "keyDerive.h" 53981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "keyDeriveWep.h" 54981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "keyDeriveTkip.h" 55981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "keyDeriveAes.h" 56981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#ifdef XCC_MODULE_INCLUDED 57981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "keyDeriveCkip.h" 58981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#endif 59981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 60981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/** 61981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 62981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* Function - Init KEY Parser module. 63981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 64981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* \b Description: 65981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 66981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* Called by RSN Manager. 67981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* Registers the function 'rsn_KeyDeriveRecv()' at the distributor to receive KEY frames upon receiving a KEY_RECV event. 68981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 69981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* \b ARGS: 70981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 71981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 72981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* \b RETURNS: 73981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 74981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* TI_STATUS - 0 on success, any other value on failure. 75981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 76981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*/ 77981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 78981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtkeyDerive_t* keyDerive_create(TI_HANDLE hOs) 79981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{ 80981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt keyDerive_t *pKeyDerive; 81981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 82981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt /* allocate key parser context memory */ 83981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt pKeyDerive = (keyDerive_t*)os_memoryAlloc(hOs, sizeof(keyDerive_t)); 84981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt if (pKeyDerive == NULL) 85981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt { 86981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt return NULL; 87981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt } 88981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 89981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt os_memoryZero(hOs, pKeyDerive, sizeof(keyDerive_t)); 90981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 91981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt pKeyDerive->hOs = hOs; 92981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 93981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt return pKeyDerive; 94981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt} 95981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 96981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/** 97981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 98981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* Function - Init KEY Parser module. 99981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 100981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* \b Description: 101981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 102981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* Called by RSN Manager. 103981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* Registers the function 'rsn_KeyDeriveRecv()' at the distributor to receive KEY frames upon receiving a KEY_RECV event. 104981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 105981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* \b ARGS: 106981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 107981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 108981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* \b RETURNS: 109981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 110981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* TI_STATUS - 0 on success, any other value on failure. 111981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 112981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*/ 113981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 114981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_STATUS keyDerive_unload(struct _keyDerive_t *pKeyDerive) 115981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{ 116981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt /* free key parser context memory */ 117981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt os_memoryFree(pKeyDerive->hOs, pKeyDerive, sizeof(keyDerive_t)); 118981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 119981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt return TI_OK; 120981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt} 121981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 122981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/** 123981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 124981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* Function - Init KEY Parser module. 125981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 126981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* \b Description: 127981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 128981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* Called by RSN Manager. 129981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* Registers the function 'rsn_KeyDeriveRecv()' at the distributor to receive KEY frames upon receiving a KEY_RECV event. 130981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 131981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* \b ARGS: 132981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 133981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 134981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* \b RETURNS: 135981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 136981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* TI_STATUS - 0 on success, any other value on failure. 137981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt* 138981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*/ 139981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 140981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_STATUS keyDerive_config(struct _keyDerive_t *pKeyDerive, 141981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt ECipherSuite cipher, 142981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt struct _mainKeys_t *pMainKeys, 143981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt TI_HANDLE hReport, 144981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt TI_HANDLE hOs) 145981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{ 146981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 147981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt TI_STATUS status = TI_NOK; 148981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 149981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt pKeyDerive->hReport = hReport; 150981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt pKeyDerive->hOs = hOs; 151981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt pKeyDerive->pMainKeys = pMainKeys; 152981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 153981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt switch (cipher) 154981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt { 155981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt case TWD_CIPHER_NONE: 156981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt status = keyDeriveNone_config(pKeyDerive); 157981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt break; 158981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt case TWD_CIPHER_WEP: 159981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt case TWD_CIPHER_WEP104: 160981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt status = keyDeriveWep_config(pKeyDerive); 161981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt break; 162981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt case TWD_CIPHER_TKIP: 163981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt status = keyDeriveTkip_config(pKeyDerive); 164981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt break; 165981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#ifdef XCC_MODULE_INCLUDED 166981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt case TWD_CIPHER_CKIP: 167981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt status = keyDeriveCkip_config(pKeyDerive); 168981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt break; 169981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#endif 170981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 171981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt case TWD_CIPHER_AES_CCMP: 172981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt status = keyDeriveAes_config(pKeyDerive); 173981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt break; 174981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt default: 175981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt return TI_NOK; 176981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt } 177981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 178981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt return status; 179981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt} 180981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 181981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 182981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 183