/**
 * suppRsnFsmFree
 *
 * FUNCTION
 * Frees a previously allocated RSN Key FSM in a BP context. If the
 * RSN Key FSM is not yet allocated, then this is an error.
 * 
 * @param ctx the BP context whose FSM instance is to be freed
 *
 * @return ANI_OK if the operation succeeds
 */
int
suppRsnFsmFree(tBtampContext *ctx)
{
    tSuppRsnFsm *fsm;

    fsm = &ctx->uFsm.suppFsm;

    if( fsm->cryptHandle )
    {  
        vos_crypto_deinit( fsm->cryptHandle );
    }

    bapRsnClearTxRxCallbacks(); 

    if (fsm->lastEapol)
        aniAsfPacketFree(fsm->lastEapol);

    if( fsm->suppCtx )
    {
        if ( fsm->suppCtx->pmk )
        {
            aniAsfPacketFree(fsm->suppCtx->pmk);
        }
        vos_mem_free( fsm->suppCtx );
    }

    // Finally, clear everything out
    vos_mem_zero( fsm, sizeof(tSuppRsnFsm));

    return ANI_OK;
}
/**
 * authRsnFsmFree
 *
 * FUNCTION
 * Frees a previously allocated RSN Key FSM in a STA context. If the
 * RSN Key FSM is not yet allocated, then this is an error.
 * 
 * @param ctx the STA context whose FSM instance is to be freed
 *
 * @return ANI_OK if the operation succeeds
 */
int
authRsnFsmFree(tBtampContext *ctx)
{
    tAuthRsnFsm *fsm = &ctx->uFsm.authFsm;

    VOS_ASSERT(fsm);

    if( fsm->cryptHandle)
    {
        vos_crypto_deinit( fsm->cryptHandle );
    }
     
    bapRsnClearTxRxCallbacks(); 

    if ( fsm->staCtx )
    {
        fsm->staCtx->authRsnFsm = NULL;
    }

    if ( VOS_TIMER_STATE_UNUSED != fsm->msg2Timer.state ) vos_timer_destroy( &fsm->msg2Timer );
    if ( VOS_TIMER_STATE_UNUSED != fsm->msg4Timer.state ) vos_timer_destroy( &fsm->msg4Timer );

    if (fsm->lastEapol)
    {    
        aniAsfPacketFree(fsm->lastEapol);
        fsm->lastEapol = NULL; 
    }

    if( fsm->staCtx )
    {
        if( fsm->staCtx->pmk )
        {
            aniAsfPacketFree( fsm->staCtx->pmk );
            fsm->staCtx->pmk = NULL;
        }
       vos_mem_free(fsm->staCtx);
       fsm->staCtx = NULL; 
    }

    vos_mem_zero( fsm, sizeof(tAuthRsnFsm) );

    return ANI_OK;
}