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

📄 headset_security.c

📁 针对bluelab3.42的handsfree车载蓝牙的参考
💻 C
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2006
Part of BlueLab 3.4.2-release

FILE NAME
    headset_security.c        

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

*/


/****************************************************************************
    Header files
*/
#include "headset_private.h"
#include "av_stream_control.h"
#include "headset_common.h"
#include "headset_security.h"
#include "headset_tones.h"
#include "hfp_slc.h"

#include <stdlib.h>
#include <stdio.h>
#include <ps.h>
#include <pio.h>


/**************************************************************************/
void headsetHandlePinCodeInd(const headsetTaskData *app, const CL_SM_PIN_CODE_IND_T *ind)
{
    uint16 pin_length = 0;
    uint8 pin[16];
	uint8 pin_security;
	if ((PsRetrieve(HEADSET_SECURITY, &pin_security, sizeof(uint8))) ==0)
		pin_security = 1;
    
    /*  Only send our PIN if the headset is in pairing mode (and the security PS Key is set), 
        or we initiated a connection.
    */
    if (isHeadsetPairing(app) | (pin_security == 0) | (app->headset_connecting_hfp) | (app->headset_connecting_av))
    {
        /* Do we have a fixed pin in PS, if not reject pairing (by setting the length to zero) */ 
        if ((pin_length = PsFullRetrieve(PSKEY_FIXED_PIN, pin, 16)) == 0 || pin_length > 16)
            pin_length = 0; 
    }
    
    /* Respond to the PIN code request */
    ConnectionSmPinCodeResponse(&ind->bd_addr, pin_length, pin); 
}

/*****************************************************************************/
void headsetHandleAuthoriseInd(const CL_SM_AUTHORISE_IND_T *ind)
{
    ConnectionSmAuthoriseResponse(&ind->bd_addr, ind->protocol_id, ind->channel, ind->incoming, 1);
}

/*****************************************************************************/
void headsetHandleAuthenticateCfm(const CL_SM_AUTHENTICATE_CFM_T *cfm)
{
	bdaddr addr;  
    if (cfm->status == auth_status_success)
    {
		addr = cfm->bd_addr;
        /* Pairing complete so send a pair mode end message immediately */
        (void) MessageCancelAll(getAppTask(), APP_PAIR_MODE_END_IND);
        MessageSend(getAppTask(), APP_PAIR_MODE_END_IND, 0);
		(void)PsStore(LAST_PAIRED_DEVICE, &addr, sizeof(bdaddr)); 
		
    }
}

/*****************************************************************************/
void headsetEnterPairingMode(headsetTaskData *app)
{
    app->pairing_enabled = 1;
    
    /* Update the flashing LEDs */
    app->led_state |= LED_PAIRING; 
    (void) MessageCancelAll(getAppTask(), APP_LED_UPDATE_IND);
	(void) MessageCancelAll(getAppTask(), APP_INIT_LED_UPDATE_IND);
	MessageSendLater(getAppTask(), APP_LED_UPDATE_IND, 0,0);
    headsetPlayTone(app, tone_type_pairing);
  
    /* Set the pairing timeout */
    MessageSendLater(getAppTask(), APP_PAIR_MODE_END_IND, 0, PAIRING_TIMEOUT);
}


/*****************************************************************************/
void headsetExitPairingMode(headsetTaskData *app)
{
    /* No longer in pairing mode */
    app->pairing_enabled = 0;

    /* Update the flashing LEDs */
    app->led_state &= ~LED_PAIRING;
	PioSet(LED_RED, 0);
}
/*****************************************************************************/
void headsetClearPairedDevices(headsetTaskData *app)
{
	
	
	/*Set up message for LED indication of paired list reset*/
	APP_ON_EVENT_LED_UPDATE_IND_T* message;
	message = malloc(sizeof(APP_ON_EVENT_LED_UPDATE_IND_T));
	ConnectionSmDeleteAllAuthDevices(HEADSET_MSG_BASE);
	
	
	/*If the device is in pairing mode disable pairing*/
	if (isHeadsetPairing(app))
		MessageSend(getAppTask(), APP_PAIR_MODE_END_IND, 0);
	
	/* Close down any active AV link */
    if ((app->a2dp_state == avHeadsetA2dpConnected) || (app->a2dp_state == avHeadsetA2dpStreaming))
    {
        A2dpCloseAll(app->a2dp);
    }
    /* Close down any active AVRCP link */
    if (app->avrcp_state == avHeadsetAvrcpConnected)
        AvrcpDisconnect(app->avrcp);
  
    /* Close down any active AG link */
    if ((app->hfp_state != headsetInitialising) && (app->hfp_state != headsetReady))
        hfpHeadsetDisconnectSlc(app);
	
	/* Reset the last used AG  */   
    (void )PsStore (LAST_USED_AG, 0, 0);
    
    /* Reset the Last used AV source */
    (void)PsStore (LAST_USED_AV_SOURCE ,0 ,0);
	
	/* Reset the codec type of the Last used AV source */
    (void)PsStore (LAST_USED_AV_SOURCE_SEP ,0 ,0);
	
	/*Clear the last paired device*/
	(void)PsStore (LAST_PAIRED_DEVICE ,0 ,0);
    
    
	
	/*Update LED indication*/
	app->led_state |= LED_DEL_PAIRED_LIST;
	message->count=0;
	message->id = APP_PAIR_RESET_LED_UPDATE_IND;
    MessageSendLater(getAppTask(), message->id, message, 1000);
	
}

⌨️ 快捷键说明

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