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