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

📄 hid_keyboard_auth.c

📁 Csr 蓝牙键盘源码
💻 C
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2005-2006
Part of BlueLab 3.4.2-release

FILE NAME
    hid_keyboard_auth.c        
DESCRIPTION
    This file contains the authentication functions.
NOTES

*/

/****************************************************************************
    Header files
*/
#include "hid_keyboard.h"
#include "hid_keyboard_sm.h"
#include "hid_keyboard_auth.h"
#include "hid_keyboard_scan.h"

/*************************************************************************
NAME    
    appIsPinCodeEntry
DESCRIPTION
    Returns boolean indicating if pin code entry is currently in progress.
RETURNS
    bool - TRUE if pin code is being entered, FALSE otherwise.
*/
bool appIsPinCodeEntry(appTaskData *theApp)
{
    return theApp->auth_state == appAuthPinCode;
}

/*************************************************************************
NAME    
    appStartPinCodeEntry
DESCRIPTION
    This is called when authenticating has started, normally when a pin
    code indication is received.
RETURNS
    void     
*/
void appStartPinCodeEntry(appTaskData *theApp)
{
    MAIN_PRINT(("appStartPinCodeEntry\n"));
    
    /* Set pin code state */
    theApp->auth_state = appAuthPinCode;

    /* Initialise pin code entry */
    HidPinInit(&theApp->hid_pin);
    
    /* Check if we need to disconnect HID source */
    if (appGetState(theApp) == appCabledConnected)
    {
        /* Disconnect HID stream, so we get HID reports sent to task */
       	StreamDisconnect(StreamHidSource(), theApp->interrupt_sink);
    }

    /* Flash status LED */
    appLedUpdate(&theApp->led, 250, 250, 1);
    appLedSetPriority(&theApp->led, 1);

    /* Cancel any timeout message */
    MessageCancelAll(&theApp->task, APP_INTERNAL_PIN_CODE_TIMEOUT_IND);
    MessageCancelAll(&theApp->task, APP_INTERNAL_DISCOVERABLE_TIMEOUT_IND);
    
    /* Start pin code timeout */
    MessageSendLater(&theApp->task, APP_INTERNAL_PIN_CODE_TIMEOUT_IND, 0, D_SEC(APP_PIN_CODE_TIMEOUT));    

	/* Update inquiry scan and page scan */
    appUpdateScanEnable(theApp);
}

/*************************************************************************
NAME    
    appStopPinCodeEntry
DESCRIPTION
    This function stops pin code entry.
RETURNS
    void     
*/
void appStopPinCodeEntry(appTaskData *theApp, bool success)
{
    MAIN_PRINT(("appStopPinCodeEntry\n"));
    
    /* Set authenticating state */
    theApp->auth_state = success ? appAuthTrusted : appAuthIdle;

    /* Check if we need to reconnect HID source */
    if (appGetState(theApp) == appCabledConnected)
    {
        /* Connect HID transform in interrupt sink */
        StreamConnect(StreamHidSource(), theApp->interrupt_sink);
    }

    /* Stop flashing LED */
    appLedSetPriority(&theApp->led, 0);

    /* Cancel timeout message */
    MessageCancelAll(&theApp->task, APP_INTERNAL_PIN_CODE_TIMEOUT_IND);    

    /* Start discovery timeout if in discoverable state */
    if ((appGetState(theApp) == appDiscoverable) || (appGetState(theApp) == appDiscoverableConnecting))
        MessageSendLater(&theApp->task, APP_INTERNAL_DISCOVERABLE_TIMEOUT_IND, 0, D_SEC(APP_DISCOVERABLE_TIMEOUT));    

	/* Update inquiry scan and page scan */
    appUpdateScanEnable(theApp);
}

/*************************************************************************
NAME    
    appHandleDataPinCode
DESCRIPTION
    Handles data on interrupt channel passed down by firmware.  This
    function attempts to build up a pin code.
RETURNS
    void     
*/
void appHandleDataPinCode(appTaskData *theApp, Source source)
{
    int size;
       
    /* Loop, pulling packets from source */
    while ((size = SourceBoundary(source)) != 0)
    {
		const uint8 *ptr = SourceMap(source);
        hid_pin_status status;
              
        /* Attempt to handle input report */
        status = HidPinCodeHandleReport(&theApp->hid_pin, ptr, size);
        if (status == hid_pin_complete)
        {
            MAIN_PRINT(("Pin code entered\n"));
                
            /* We have complete pin code, send response */
            ConnectionSmPinCodeResponse(&theApp->auth_bd_addr, HidPinCodeLength(&theApp->hid_pin), HidPinCodeData(&theApp->hid_pin)); 
        }
        
		/* Discard the packet */
		SourceDrop(source, size);
    } 
}

⌨️ 快捷键说明

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