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