📄 hci.cxx
字号:
static void InquiryResult (unsigned char num_responses, unsigned char *pbuffer) {
IFDBG(DebugOut (DEBUG_HCI_TRACE, L"InquiryResultEvent num = %d\n", num_responses));
for ( ; num_responses != 0 ; --num_responses, pbuffer += 14) {
HCIPacket *pPacket = FindCommandPacket (gpHCI->pPacketsPending, HCI_Inquiry);
HCI_CONTEXT *pOwner = VerifyContext (pPacket ? pPacket->pOwner : gpHCI->pPeriodicInquiryOwner);
void *pCallContext = pPacket ? pPacket->pCallContext : NULL;
if (! pOwner) {
IFDBG(DebugOut (DEBUG_WARN, L"Orphaned inquiry result event (no owner).\n"));
break;
}
HCI_InquiryResultEvent pCallback = pOwner->ei.hci_InquiryResultEvent;
if (! pCallback) {
IFDBG(DebugOut (DEBUG_WARN, L"InquiryResult:: no handler\n"));
break;
}
void *pUserContext = pOwner->pUserContext;
BD_ADDR b;
memcpy (&b, pbuffer, sizeof(BD_ADDR));
unsigned int cod = pbuffer[9] | (pbuffer[10] << 8) | (pbuffer[11] << 16);
unsigned short offset = pbuffer[12] | (pbuffer[13] << 8);
InquiryResultList *pInq = gpHCI->pInquiryResults;
while (pInq && (pInq->irb.ba != b))
pInq = pInq->pNext;
if (! pInq) {
pInq = new InquiryResultList;
if (pInq) {
pInq->pNext = gpHCI->pInquiryResults;
gpHCI->pInquiryResults = pInq;
}
}
if (pInq) {
pInq->irb.dwTick = GetTickCount ();
pInq->irb.ba = b;
pInq->irb.page_scan_repetition_mode = pbuffer[6];
pInq->irb.page_scan_period_mode = pbuffer[7];
pInq->irb.page_scan_mode = pbuffer[8];
pInq->irb.class_of_device = cod;
pInq->irb.clock_offset = offset;
}
#if defined (BTH_LONG_TERM_STATE)
if ((pbuffer[6] != 0) || (pbuffer[7] != 0) || (pbuffer[8] != 0))
btutil_PersistPeerInfo (&b, BTH_STATE_HCI_SCAN_MODES, pbuffer + 6);
#endif
gpHCI->AddRef ();
IFDBG(DebugOut (DEBUG_HCI_CALLBACK, L"InquiryResultEvent:: going into callback\n"));
gpHCI->Unlock ();
__try {
pCallback (pUserContext, pCallContext, &b, pbuffer[6], pbuffer[7], pbuffer[8], cod, offset);
} __except (1) {
IFDBG(DebugOut (DEBUG_ERROR, L"InquiryResultEvent:: exception in callback\n"));
}
gpHCI->Lock ();
IFDBG(DebugOut (DEBUG_HCI_CALLBACK, L"InquiryResultEvent:: came from callback\n"));
gpHCI->Release ();
if (gpHCI->eStage != Connected)
break;
}
}
static void ConnectionRequest (BD_ADDR *pba, unsigned int class_of_device, unsigned char link_type) {
IFDBG(DebugOut (DEBUG_HCI_TRACE, L"ConnectionRequest bd_addr = %04x%08x cod = %06x link = %d\n", pba->NAP, pba->SAP, class_of_device, link_type));
HCI_CONTEXT *pOwner = gpHCI->pContexts;
while (pOwner && ((0 == (pOwner->uiControl & BTH_CONTROL_ROUTE_BY_ADDR)) || (pOwner->ba != *pba)))
pOwner = pOwner->pNext;
if (! pOwner) {
pOwner = gpHCI->pContexts;
while (pOwner && ((0 == (pOwner->uiControl & BTH_CONTROL_ROUTE_BY_COD)) || (pOwner->class_of_device != class_of_device)))
pOwner = pOwner->pNext;
}
if (! pOwner) {
pOwner = gpHCI->pContexts;
while (pOwner && ((0 == (pOwner->uiControl & BTH_CONTROL_ROUTE_BY_LINKTYPE)) || (pOwner->link_type != link_type)))
pOwner = pOwner->pNext;
}
if (! pOwner) {
pOwner = gpHCI->pContexts;
while (pOwner && (0 == (pOwner->uiControl & BTH_CONTROL_ROUTE_ALL)))
pOwner = pOwner->pNext;
}
if (! pOwner) {
IFDBG(DebugOut (DEBUG_WARN, L"No context for connection request - ignored\n"));
return;
}
HCI_ConnectionRequestEvent pCallback = pOwner->ei.hci_ConnectionRequestEvent;
if (! pCallback) {
IFDBG(DebugOut (DEBUG_WARN, L"ConnectionRequest:: no handler\n"));
return;
}
void *pUserContext = pOwner->pUserContext;
ConnReqData *pCR = new ConnReqData;
if (pCR) {
pCR->ba = *pba;
pCR->cod = class_of_device;
pCR->pNext = gpHCI->pConnReqData;
gpHCI->pConnReqData = pCR;
}
gpHCI->AddRef ();
IFDBG(DebugOut (DEBUG_HCI_CALLBACK, L"ConnectionRequest:: going into callback\n"));
gpHCI->Unlock ();
__try {
pCallback (pUserContext, NULL, pba, class_of_device, link_type);
} __except (1) {
IFDBG(DebugOut (DEBUG_ERROR, L"ConnectionRequest:: exception in callback\n"));
}
gpHCI->Lock ();
IFDBG(DebugOut (DEBUG_HCI_CALLBACK, L"ConnectionRequest:: came from callback\n"));
gpHCI->Release ();
}
static void DisconnectionComplete (unsigned char status, unsigned short h, unsigned char reason) {
IFDBG(DebugOut (DEBUG_HCI_TRACE, L"DisconnectionComplete status = %d handle = 0x%04x reason = 0x%02x\n", status, h, reason));
HCIPacket *pPacket = ExtractCommandPacket (&gpHCI->pPacketsPending, HCI_Disconnect, h);
BasebandConnection *pC = FindConnection (h);
if ((! pPacket) && (! pC)) {
IFDBG(DebugOut (DEBUG_WARN, L"Orphaned disconnection complete event (h = 0x%08x)\n", h));
return;
}
HCI_CONTEXT *pOwner = NULL;
void *pCallContext = NULL;
if (pPacket) {
pOwner = VerifyContext (pPacket->pOwner);
pCallContext = pOwner ? pPacket->pCallContext : NULL;
delete pPacket;
}
if ((! pOwner) && pC)
pOwner = VerifyContext (pC->pOwner);
if (! pOwner) {
IFDBG(DebugOut (DEBUG_WARN, L"Orphaned disconnection complete event (no owner).\n"));
return;
}
if ((status == 0) && pC) {
if (gpHCI->pConnections == pC)
gpHCI->pConnections = gpHCI->pConnections->pNext;
else {
BasebandConnection *pCParent = gpHCI->pConnections;
while (pCParent && (pCParent->pNext != pC))
pCParent = pCParent->pNext;
if (pCParent)
pCParent->pNext = pC->pNext;
else
SVSUTIL_ASSERT (0);
}
delete pC;
}
HCI_DisconnectionCompleteEvent pCallback = pOwner->ei.hci_DisconnectionCompleteEvent;
if (! pCallback) {
IFDBG(DebugOut (DEBUG_WARN, L"DisconnectionComplete:: no handler\n"));
return;
}
void *pUserContext = pOwner->pUserContext;
gpHCI->AddRef ();
IFDBG(DebugOut (DEBUG_HCI_CALLBACK, L"DisconnectionComplete:: going into callback\n"));
gpHCI->Unlock ();
__try {
pCallback (pUserContext, pCallContext, status, h, reason);
} __except (1) {
IFDBG(DebugOut (DEBUG_ERROR, L"DisconnectionComplete:: exception in callback\n"));
}
gpHCI->Lock ();
IFDBG(DebugOut (DEBUG_HCI_CALLBACK, L"DisconnectionComplete:: came from callback\n"));
gpHCI->Release ();
}
static void AuthenticationComplete (unsigned char status, unsigned short h) {
IFDBG(DebugOut (DEBUG_HCI_TRACE, L"AuthenticationComplete status = %d handle = 0x%04x\n", status, h));
BasebandConnection *pConnection = FindConnection (h);
if (pConnection)
pConnection->fAuthenticated = TRUE;
HCIPacket *pPacket = ExtractCommandPacket (&gpHCI->pPacketsPending, HCI_Authentication_Requested, h);
HCI_CONTEXT *pOwner = NULL;
void *pCallContext = NULL;
if (pPacket) {
pOwner = VerifyContext (pPacket->pOwner);
pCallContext = pOwner && pOwner->ei.hci_AuthenticationCompleteEvent ? pPacket->pCallContext : NULL;
delete pPacket;
} else if (pConnection)
pOwner = VerifyContext (pConnection->pOwner);
if (pOwner && (! pOwner->ei.hci_AuthenticationCompleteEvent))
pOwner = NULL;
if (! pOwner) {
pOwner = gpHCI->pContexts;
while (pOwner && (0 == (pOwner->uiControl & BTH_CONTROL_ROUTE_SECURITY)))
pOwner = pOwner->pNext;
}
if (pOwner && (! pOwner->ei.hci_AuthenticationCompleteEvent))
pOwner = NULL;
if (! pOwner) {
pOwner = gpHCI->pContexts;
while (pOwner && (0 == (pOwner->uiControl & BTH_CONTROL_ROUTE_ALL)))
pOwner = pOwner->pNext;
}
if (pOwner && (! pOwner->ei.hci_AuthenticationCompleteEvent))
pOwner = NULL;
if (! pOwner) {
IFDBG(DebugOut (DEBUG_WARN, L"Orphaned auth complete event.\n"));
return;
}
HCI_AuthenticationCompleteEvent pCallback = pOwner->ei.hci_AuthenticationCompleteEvent;
void *pUserContext = pOwner->pUserContext;
gpHCI->AddRef ();
IFDBG(DebugOut (DEBUG_HCI_CALLBACK, L"AuthenticationComplete:: going into callback\n"));
gpHCI->Unlock ();
__try {
pCallback (pUserContext, pCallContext, status, h);
} __except (1) {
IFDBG(DebugOut (DEBUG_ERROR, L"AuthenticationComplete:: exception in callback\n"));
}
gpHCI->Lock ();
IFDBG(DebugOut (DEBUG_HCI_CALLBACK, L"AuthenticationComplete:: came from callback\n"));
gpHCI->Release ();
}
static void RemoteNameRequestComplete (unsigned char status, BD_ADDR *pba, unsigned char *pbname) {
IFDBG(DebugOut (DEBUG_HCI_TRACE, L"RemoteNameRequestComplete : status = %d bd_addr = %04x%08x\n", status, pba->NAP, pba->SAP));
HCIPacket *pPacket = ExtractCommandPacket (&gpHCI->pPacketsPending, HCI_Remote_Name_Request, pba);
if (! pPacket) {
IFDBG(DebugOut (DEBUG_WARN, L"Orphaned remote name read complete event (ba = %04x%08x)\n", pba->NAP, pba->SAP));
return;
}
HCI_CONTEXT *pOwner = VerifyContext (pPacket->pOwner);
void *pCallContext = pPacket->pCallContext;
delete pPacket;
if (! pOwner) {
IFDBG(DebugOut (DEBUG_WARN, L"Orphaned remote name read complete event.\n"));
return;
}
HCI_RemoteNameRequestCompleteEvent pCallback = pOwner->ei.hci_RemoteNameRequestCompleteEvent;
if (! pCallback) {
IFDBG(DebugOut (DEBUG_WARN, L"RemoteNameRequestComplete:: no handler\n"));
return;
}
void *pUserContext = pOwner->pUserContext;
gpHCI->AddRef ();
IFDBG(DebugOut (DEBUG_HCI_CALLBACK, L"RemoteNameRequestComplete:: going into callback\n"));
gpHCI->Unlock ();
__try {
pCallback (pUserContext, pCallContext, status, pba, pbname);
} __except (1) {
IFDBG(DebugOut (DEBUG_ERROR, L"RemoteNameRequestComplete:: exception in callback\n"));
}
gpHCI->Lock ();
IFDBG(DebugOut (DEBUG_HCI_CALLBACK, L"RemoteNameRequestComplete:: came from callback\n"));
gpHCI->Release ();
}
static void EncryptionChange (unsigned char status, unsigned short connection_handle, unsigned char encryption_enable) {
IFDBG(DebugOut (DEBUG_HCI_TRACE, L"EncryptionChangeEvent : status = %d h = 0x%04x, ee = %d\n", status, connection_handle, encryption_enable));
BasebandConnection *pConnection = FindConnection (connection_handle);
if (pConnection)
pConnection->fEncrypted = encryption_enable ? TRUE : FALSE;
HCIPacket *pPacket = ExtractCommandPacket (&gpHCI->pPacketsPending, HCI_Set_Connection_Encryption, connection_handle);
HCI_CONTEXT *pOwner = NULL;
void *pCallContext = NULL;
if (pPacket) {
pOwner = VerifyContext (pPacket->pOwner);
pCallContext = pOwner && pOwner->ei.hci_EncryptionChangeEvent ? pPacket->pCallContext : NULL;
delete pPacket;
} else if (pConnection)
pOwner = VerifyContext (pConnection->pOwner);
if (pOwner && (! pOwner->ei.hci_EncryptionChangeEvent))
pOwner = NULL;
if (! pOwner) {
pOwner = gpHCI->pContexts;
while (pOwner && (0 == (pOwner->uiControl & BTH_CONTROL_ROUTE_SECURITY)))
pOwner = pOwner->pNext;
}
if (pOwner && (! pOwner->ei.hci_EncryptionChangeEvent))
pOwner = NULL;
if (! pOwner) {
pOwner = gpHCI->pContexts;
while (pOwner && (0 == (pOwner->uiControl & BTH_CONTROL_ROUTE_ALL)))
pOwner = pOwner->pNext;
}
if (pOwner && (! pOwner->ei.hci_EncryptionChangeEvent))
pOwner = NULL;
if (! pOwner) {
IFDBG(DebugOut (DEBUG_WARN, L"Orphaned encryption change event (h = 0x%04x)\n", connection_handle));
return;
}
HCI_EncryptionChangeEvent pCallback = pOwner->ei.hci_EncryptionChangeEvent;
void *pUserContext = pOwner->pUserContext;
gpHCI->AddRef ();
IFDBG(DebugOut (DEBUG_HCI_CALLBACK, L"EncryptionChangeEvent:: going into callback\n"));
gpHCI->Unlock ();
__try {
pCallback (pUserContext, pCallContext, status, connection_handle, encryption_enable);
} __except (1) {
IFDBG(DebugOut (DEBUG_ERROR, L"EncryptionChangeEvent:: exception in callback\n"));
}
gpHCI->Lock ();
IFDBG(DebugOut (DEBUG_HCI_CALLBACK, L"EncryptionChangeEvent:: came from callback\n"));
gpHCI->Release ();
}
static void ChangeConnectionLinkKey (unsigned char status, unsigned short connection_handle) {
IFDBG(DebugOut (DEBUG_HCI_TRACE, L"ChangeConnectionLinkKeyEvent : status = %d h = 0x%04x\n", status, connection_handle));
HCIPacket *pPacket = ExtractCommandPacket (&gpHCI->pPacketsPending, HCI_Change_Connection_Link_Key, connection_handle);
HCI_CONTEXT *pOwner = NULL;
void *pCallContext = NULL;
if (pPacket) {
pOwner = VerifyContext (pPacket->pOwner);
pCallContext = pPacket->pCallContext;
delete pPacket;
}
if (! pOwner) {
IFDBG(DebugOut (DEBUG_WARN, L"Orphaned change connection link key event (h = 0x%04x)\n", connection_handle));
return;
}
HCI_ChangeConnectionLinkKeyCompleteEvent pCallback = pOwner->ei.hci_ChangeConnectionLinkKeyCompleteEvent;
if (! pCallback) {
IFDBG(DebugOut (DEBUG_WARN, L"ChangeConnectionLinkKey:: no handler\n"));
return;
}
void *pUserContext = pOwner->pUserContext;
gpHCI->AddRef ();
IFDBG(DebugOut (DEBUG_HCI_CALLBACK, L"ChangeConnectionLinkKeyEvent:: going into callback\n"));
gpHCI->Unlock ();
__try {
pCallback (pUserContext, pCallContext, status, connection_handle);
} __except (1) {
IFDBG(DebugOut (DEBUG_ERROR, L"ChangeConnectionLinkKeyEvent:: exception in callback\n"));
}
gpHCI->Lock ();
IFDBG(DebugOut (DEBUG_HCI_CALLBACK, L"ChangeConnectionLinkKeyEvent:: came from callback\n"));
gpHCI->Release ();
}
static void MasterLinkKeyComplete (unsigned char status, unsigned short h, unsigned char flag) {
IFDBG(DebugOut (DEBUG_HCI_TRACE, L"MasterLinkKeyCompleteEvent : status = %d h = 0x%04x, flag = %d\n", s
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -