📄 handle_connection.c
字号:
/****************************************************************************
DESCRIPTION
Implementation for handling connection library messages and functionality
FILE
handle_connection.c
*/
/****************************************************************************
Header files
*/
#include <connection.h>
#include <print.h>
#include <ps.h>
#include "main.h"
#include "handle_connection.h"
#include "handle_pbap.h"
/* Message Handler Prototypes */
static void handleClInitCfm(applicationTaskData *pTask, CL_INIT_CFM_T *pMsg);
static void handleClSmAuthoriseInf(applicationTaskData *pTask, CL_SM_AUTHORISE_IND_T *pMsg);
static void handleClPinCodeInd(applicationTaskData *pTask, CL_SM_PIN_CODE_IND_T *pMsg);
/* Interface Functions */
/*
Set Discoverability State
*/
void conSetDiscoverability(bool pState)
{
hci_scan_enable lMode = (pState) ? hci_scan_enable_inq_and_page : hci_scan_enable_off;
PRINT(("conSetDiscoverability [%d]\n", pState));
ConnectionWriteScanEnable(lMode);
}
/*
Connection Library Message Handler
*/
void handleConnectionMessages(applicationTaskData *pTask, MessageId pId, Message pMessage)
{
switch (pId)
{
case CL_INIT_CFM:
handleClInitCfm(pTask, (CL_INIT_CFM_T *)pMessage);
break;
case CL_SM_AUTHORISE_IND:
handleClSmAuthoriseInf(pTask, (CL_SM_AUTHORISE_IND_T *)pMessage);
break;
case CL_SM_PIN_CODE_IND:
handleClPinCodeInd(pTask, (CL_SM_PIN_CODE_IND_T *)pMessage);
break;
/* Ignored Messages */
case CL_DM_ACL_OPENED_IND:
PRINT(("CL_DM_ACL_OPENED_IND [ignored]\n"));
break;
case CL_DM_ACL_CLOSED_IND:
PRINT(("CL_DM_ACL_CLOSED_IND [ignored]\n"));
break;
default:
PRINT(("Unhandled Connection Message\n"));
break;
}
}
/* Message Handlers */
static void handleClInitCfm(applicationTaskData *pTask, CL_INIT_CFM_T *pMsg)
{
PRINT(("CL_INIT_CFM\n"));
if (pTask->appState == AppStateUninitialised)
{
if (pMsg->status == success)
{
setState(&pTask->appState, AppStateConInited);
/* Allow incomming SDP searches without security */
ConnectionSmSetSdpSecurityIn(TRUE);
/* Initialise PBAP Server */
initPbap(pTask);
}
else
{
PRINT((" UNABLE TO INITIALISE THE CONNECTION LIBRARY\n"));
}
}
else
{
PRINT((" CONNECTION LIBRARY ALREADY INITIALISED\n"));
}
}
static void handleClSmAuthoriseInf(applicationTaskData *pTask, CL_SM_AUTHORISE_IND_T *pMsg)
{
bool lAuth = FALSE; /* Assume reject */
PRINT(("CL_SM_AUTHORISE_IND\n"));
PRINT((" BD Addr : 0x%X 0x%X 0x%X,%X\n", pMsg->bd_addr.nap, pMsg->bd_addr.uap, (uint16)(pMsg->bd_addr.lap>>16), (uint16)(pMsg->bd_addr.lap&0xFFFF)));
if ((pTask->appState == AppStateAppIdle) || (pTask->appState == AppStateConnecting))
{ /* Application idle, we can accept a connection */
PRINT((" Accepting connection\n"));
setState(&pTask->appState, AppStateConnecting);
lAuth = TRUE;
}
else
{ /* Application busy, reject the connection */
PRINT((" Rejecting Connection [State = %d]\n", pTask->appState));
}
ConnectionSmAuthoriseResponse(&pMsg->bd_addr, pMsg->protocol_id, pMsg->channel, pMsg->incoming, lAuth);
}
static void handleClPinCodeInd(applicationTaskData *pTask, CL_SM_PIN_CODE_IND_T *pMsg)
{
uint8 lPincode[16];
uint16 lLen;
PRINT(("CL_SM_PIN_CODE_IND\n"));
lLen = PsFullRetrieve(PSKEY_FIXED_PIN, lPincode, 16);
ConnectionSmPinCodeResponse(&pMsg->bd_addr, lLen, lPincode);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -