⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 headset_auth.c

📁 bc5_stereo:bluetooth stereo Headset CODE 支持A2DP HSP 和 HSP 。可作为车载免提。BlueLab 2007环境下编译
💻 C
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2005-2007

FILE NAME
    headset_auth.c        

DESCRIPTION
    This file contains the Authentication functionality for the AV Headset 
    Application

NOTES

*/

/****************************************************************************
    Header files
*/

#include "headset_a2dp_connection.h"
#include "headset_auth.h"
#include "headset_configmanager.h"
#include "headset_debug.h"
#include "headset_hfp_slc.h"
#include "headset_statemanager.h"

#include <connection.h>
#include <ps.h>


#ifdef DEBUG_AUTH
    #define AUTH_DEBUG(x) DEBUG(x)    
#else
    #define AUTH_DEBUG(x) 
#endif   


/****************************************************************************
    LOCAL FUNCTION PROTOTYPES
*/

static bool AuthCanHeadsetConnect ( hsTaskData * pApp ) ;

static bool AuthCanHeadsetPair ( hsTaskData * pApp ) ;


/****************************************************************************
  FUNCTIONS
*/

/**************************************************************************/
void headsetHandlePinCodeInd(hsTaskData * pApp , const CL_SM_PIN_CODE_IND_T* ind)
{
    uint16 pin_length = 0;
    uint8 pin[16];
    
    if ( AuthCanHeadsetPair (pApp) )
    {
	    
		AUTH_DEBUG(("auth: Can Pin\n")) ;
			
    	/* Do we have a fixed pin in PS, if not reject pairing */
    	if ((pin_length = PsFullRetrieve(PSKEY_FIXED_PIN, pin, 16)) == 0 || pin_length > 16)
    	{
        	/* Set length to 0 indicating we're rejecting the PIN request */
        	AUTH_DEBUG(("auth : failed to get pin\n")) ;
        	pin_length = 0; 
    	}	
	} 
    /* Respond to the PIN code request */
    ConnectionSmPinCodeResponse(&ind->bd_addr, pin_length, pin); 
}


/*****************************************************************************/
void headsetHandleAuthoriseInd(hsTaskData * pApp , const CL_SM_AUTHORISE_IND_T *ind)
{
	
	bool lAuthorised = FALSE ;
	
	if ( AuthCanHeadsetConnect(pApp) )
	{
		lAuthorised = TRUE ;
	}
	
	AUTH_DEBUG(("auth: Authorised [%d]\n" , lAuthorised)) ;
	    
    /*complete the authentication with the authorised or not flag*/		
    ConnectionSmAuthoriseResponse(&ind->bd_addr, ind->protocol_id, ind->channel, ind->incoming, lAuthorised);
}


/*****************************************************************************/
void headsetHandleAuthenticateCfm(hsTaskData * pApp , const CL_SM_AUTHENTICATE_CFM_T *cfm)
{
    if (cfm->status == auth_status_success)
    {
		(void)PsStore(PSKEY_LAST_PAIRED_DEVICE, &cfm->bd_addr, sizeof(bdaddr)); 
        /* Send a user event to the app for indication purposes */
        MessageSend (&pApp->task , EventPairingSuccessful , 0 );
    }
}


/****************************************************************************
NAME    
    AuthCanHeadsetPair 
    
DESCRIPTION
    Helper function to indicate if pairing is allowed.

RETURNS
    bool
*/
static bool AuthCanHeadsetPair ( hsTaskData * pApp )
{
	bool lCanPair = FALSE ;
	
	/*if we are in pairing mode*/
	if (stateManagerGetHfpState() == headsetConnDiscoverable)
	{
	    lCanPair = TRUE ;
		AUTH_DEBUG(("auth: is ConnDisco\n")) ;
	}	    		
    
	/*or if we initiated the connection*/
	if ( hfpSlcIsConnecting( pApp ) || a2dpIsConnecting( pApp) )
	{
		lCanPair = TRUE ;
		AUTH_DEBUG(("auth: is Initiated\n")) ;
	}
 
    return lCanPair ;
}


/****************************************************************************
NAME    
    AuthCanHeadsetConnect 
    
DESCRIPTION
    Helper function to indicate if connecting is allowed.

RETURNS
    bool
*/
static bool AuthCanHeadsetConnect ( hsTaskData * pApp )
{
	bool lCanConnect = FALSE ;
	
	/* If the headset is on then authorise */
	if (stateManagerGetHfpState() != headsetPoweringOn)
	{
		lCanConnect = TRUE ;
		AUTH_DEBUG(("auth: headset is on\n")) ;
	}
		
    return lCanConnect ;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -