1/* 2 * broadcastKeySM.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 broadcastKeySM.c 35 * \brief broadcast key SM implementation 36 * 37 * \see broadcastKeySM.h 38*/ 39 40/**************************************************************************** 41 * * 42 * MODULE: broadcast key SM * 43 * PURPOSE: broadcast key SM implementation * 44 * * 45 ****************************************************************************/ 46 47#define __FILE_ID__ FILE_ID_24 48#include "osApi.h" 49#include "report.h" 50#include "rsnApi.h" 51 52#include "keyDerive.h" 53 54#include "broadcastKeySM.h" 55#include "broadcastKey802_1x.h" 56#include "broadcastKeyNone.h" 57 58/** number of states in the state machine */ 59#define BCAST_KEY_MAX_NUM_STATES 3 60 61/** number of events in the state machine */ 62#define BCAST_KEY_MAX_NUM_EVENTS 4 63 64 65/** 66* 67* Function - Init KEY Parser module. 68* 69* \b Description: 70* 71* Called by RSN Manager. 72* Registers the function 'rsn_BroadcastKeyRecv()' at the distributor to receive KEY frames upon receiving a KEY_RECV event. 73* 74* \b ARGS: 75* 76* 77* \b RETURNS: 78* 79* TI_STATUS - 0 on success, any other value on failure. 80* 81*/ 82 83broadcastKey_t* broadcastKey_create(TI_HANDLE hOs) 84{ 85 TI_STATUS status; 86 broadcastKey_t *pBroadcastKey; 87 88 /* allocate key parser context memory */ 89 pBroadcastKey = (broadcastKey_t*)os_memoryAlloc(hOs, sizeof(broadcastKey_t)); 90 if (pBroadcastKey == NULL) 91 { 92 return NULL; 93 } 94 95 os_memoryZero(hOs, pBroadcastKey, sizeof(broadcastKey_t)); 96 97 /* allocate memory for association state machine */ 98 status = fsm_Create(hOs, &pBroadcastKey->pBcastKeySm, BCAST_KEY_MAX_NUM_STATES, BCAST_KEY_MAX_NUM_EVENTS); 99 if (status != TI_OK) 100 { 101 os_memoryFree(hOs, pBroadcastKey, sizeof(broadcastKey_t)); 102 return NULL; 103 } 104 105 pBroadcastKey->pKeyDerive = keyDerive_create(hOs); 106 if (pBroadcastKey->pKeyDerive == NULL) 107 { 108 fsm_Unload(hOs, pBroadcastKey->pBcastKeySm); 109 os_memoryFree(hOs, pBroadcastKey, sizeof(broadcastKey_t)); 110 return NULL; 111 } 112 113 pBroadcastKey->hOs = hOs; 114 115 return pBroadcastKey; 116} 117 118/** 119* 120* Function - Init KEY Parser module. 121* 122* \b Description: 123* 124* Called by RSN Manager. 125* Registers the function 'rsn_BroadcastKeyRecv()' at the distributor to receive KEY frames upon receiving a KEY_RECV event. 126* 127* \b ARGS: 128* 129* 130* \b RETURNS: 131* 132* TI_STATUS - 0 on success, any other value on failure. 133* 134*/ 135 136TI_STATUS broadcastKey_unload(struct _broadcastKey_t *pBroadcastKey) 137{ 138 TI_STATUS status; 139 140 status = keyDerive_unload(pBroadcastKey->pKeyDerive); 141 142 if (status != TI_OK) 143 { 144 TRACE0(pBroadcastKey->hReport, REPORT_SEVERITY_CONSOLE, "BCAST_KEY_SM: Error in unloading key derivation module\n"); 145 WLAN_OS_REPORT(("BCAST_KEY_SM: Error in unloading key derivation module\n")); 146 } 147 148 status = fsm_Unload(pBroadcastKey->hOs, pBroadcastKey->pBcastKeySm); 149 if (status != TI_OK) 150 { 151 TRACE0(pBroadcastKey->hReport, REPORT_SEVERITY_CONSOLE, "BCAST_KEY_SM: Error in unloading state machine\n"); 152 WLAN_OS_REPORT(("BCAST_KEY_SM: Error in unloading state machine\n")); 153 } 154 155 /* free key parser context memory */ 156 os_memoryFree(pBroadcastKey->hOs, pBroadcastKey, sizeof(broadcastKey_t)); 157 158 return TI_OK; 159} 160 161/** 162* 163* Function - Init KEY Parser module. 164* 165* \b Description: 166* 167* Called by RSN Manager. 168* Registers the function 'rsn_BroadcastKeyRecv()' at the distributor to receive KEY frames upon receiving a KEY_RECV event. 169* 170* \b ARGS: 171* 172* 173* \b RETURNS: 174* 175* TI_STATUS - 0 on success, any other value on failure. 176* 177*/ 178 179TI_STATUS broadcastKey_config(struct _broadcastKey_t *pBroadcastKey, 180 TRsnPaeConfig *pPaeConfig, 181 struct _mainKeys_t *pParent, 182 TI_HANDLE hReport, 183 TI_HANDLE hOs) 184{ 185 TI_STATUS status = TI_NOK; 186 187 pBroadcastKey->hReport = hReport; 188 pBroadcastKey->hOs = hOs; 189 pBroadcastKey->pParent = pParent; 190 191 /* configure according to the keyMng suite and cipher suite */ 192 switch (pPaeConfig->keyExchangeProtocol) 193 { 194 case RSN_KEY_MNG_NONE: 195 status = broadcastKeyNone_config(pBroadcastKey); 196 break; 197 case RSN_KEY_MNG_802_1X: 198 if (pPaeConfig->broadcastSuite == TWD_CIPHER_NONE) 199 { 200 status = broadcastKeyNone_config(pBroadcastKey); 201 } else { 202 status = broadcastKey802_1x_config(pBroadcastKey); 203 } 204 break; 205 default: 206 status = broadcastKeyNone_config(pBroadcastKey); 207 break; 208 } 209 210 status = keyDerive_config(pBroadcastKey->pKeyDerive, pPaeConfig->broadcastSuite, pParent, hReport, hOs); 211 212 return status; 213} 214 215 216TI_STATUS broadcastKeySmUnexpected(struct _broadcastKey_t *pBroadcastKey) 217{ 218TRACE0(pBroadcastKey->hReport, REPORT_SEVERITY_ERROR, "BROADCAST_KEY_SM: ERROR: UnExpected Event\n"); 219 220 return(TI_NOK); 221} 222 223TI_STATUS broadcastKeySmNop(struct _broadcastKey_t *pBroadcastKey) 224{ 225 return(TI_OK); 226} 227 228