mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Check HCI Handle using function in BluetoothService class
This commit is contained in:
parent
106aff6411
commit
285b21cdbc
5 changed files with 16 additions and 26 deletions
20
BTD.h
20
BTD.h
|
@ -189,21 +189,6 @@
|
|||
|
||||
#define PAIR 1
|
||||
|
||||
/* acl_handle_ok or it's a new connection */
|
||||
#if 0
|
||||
#define UHS_ACL_HANDLE_OK(x, y) ((uint16_t)(x[0]) | (uint16_t)(x[1] << 8)) == (y | 0x2000U)
|
||||
#else
|
||||
/*
|
||||
* Better implementation.
|
||||
* o One place for this code, it is reused four times in the source.
|
||||
* Perhaps it is better as a function.
|
||||
* o This should be faster since the && operation can early exit, this means
|
||||
* the shift would only be performed if the first byte matches.
|
||||
* o Casting is eliminated.
|
||||
* o How does this compare in code size? No difference. It is a free optimization.
|
||||
*/
|
||||
#define UHS_ACL_HANDLE_OK(x, y) ((x[0] == (y & 0xff)) && (x[1] == ((y >> 8) | 0x20)))
|
||||
#endif
|
||||
class BluetoothService;
|
||||
|
||||
/**
|
||||
|
@ -609,6 +594,11 @@ protected:
|
|||
*/
|
||||
virtual void onInit() = 0;
|
||||
|
||||
/** Used to check if the incoming L2CAP data matches the HCI Handle */
|
||||
bool checkHciHandle(uint8_t *buf, uint16_t handle) {
|
||||
return (buf[0] == (handle & 0xFF)) && (buf[1] == ((handle >> 8) | 0x20));
|
||||
}
|
||||
|
||||
/** Pointer to function called in onInit(). */
|
||||
void (*pFuncOnInit)(void);
|
||||
|
||||
|
|
|
@ -65,8 +65,8 @@ void BTHID::ACLData(uint8_t* l2capinbuf) {
|
|||
}
|
||||
}
|
||||
}
|
||||
//if((l2capinbuf[0] | (uint16_t)l2capinbuf[1] << 8) == (hci_handle | 0x2000U)) { // acl_handle_ok or it's a new connection
|
||||
if(UHS_ACL_HANDLE_OK(l2capinbuf, hci_handle)) { // acl_handle_ok or it's a new connection
|
||||
|
||||
if(checkHciHandle(l2capinbuf, hci_handle)) { // acl_handle_ok
|
||||
if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { // l2cap_control - Channel ID for ACL-U
|
||||
if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
|
||||
#ifdef DEBUG_USB_HOST
|
||||
|
|
|
@ -241,10 +241,10 @@ void PS3BT::ACLData(uint8_t* ACLData) {
|
|||
}
|
||||
}
|
||||
}
|
||||
//if((ACLData[0] | (uint16_t)ACLData[1] << 8) == (hci_handle | 0x2000U)) { //acl_handle_ok
|
||||
if(UHS_ACL_HANDLE_OK(ACLData, hci_handle)) { //acl_handle_ok
|
||||
|
||||
if(checkHciHandle(ACLData, hci_handle)) { // acl_handle_ok
|
||||
memcpy(l2capinbuf, ACLData, BULK_MAXPKTSIZE);
|
||||
if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { //l2cap_control - Channel ID for ACL-U
|
||||
if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { // l2cap_control - Channel ID for ACL-U
|
||||
if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
|
||||
#ifdef DEBUG_USB_HOST
|
||||
Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);
|
||||
|
|
6
SPP.cpp
6
SPP.cpp
|
@ -95,9 +95,9 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
|
|||
}
|
||||
}
|
||||
}
|
||||
//if((l2capinbuf[0] | (uint16_t)l2capinbuf[1] << 8) == (hci_handle | 0x2000U)) { // acl_handle_ok
|
||||
if(UHS_ACL_HANDLE_OK(l2capinbuf, hci_handle)) { // acl_handle_ok
|
||||
if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { //l2cap_control - Channel ID for ACL-U
|
||||
|
||||
if(checkHciHandle(l2capinbuf, hci_handle)) { // acl_handle_ok
|
||||
if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { // l2cap_control - Channel ID for ACL-U
|
||||
if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
|
||||
#ifdef DEBUG_USB_HOST
|
||||
Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);
|
||||
|
|
6
Wii.cpp
6
Wii.cpp
|
@ -142,9 +142,9 @@ void WII::ACLData(uint8_t* l2capinbuf) {
|
|||
}
|
||||
}
|
||||
}
|
||||
//if((l2capinbuf[0] | (uint16_t)l2capinbuf[1] << 8) == (hci_handle | 0x2000U)) { // acl_handle_ok or it's a new connection
|
||||
if(UHS_ACL_HANDLE_OK(l2capinbuf, hci_handle)) { // acl_handle_ok or it's a new connection
|
||||
if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { //l2cap_control - Channel ID for ACL-U
|
||||
|
||||
if(checkHciHandle(l2capinbuf, hci_handle)) { // acl_handle_ok
|
||||
if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { // l2cap_control - Channel ID for ACL-U
|
||||
if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
|
||||
#ifdef DEBUG_USB_HOST
|
||||
Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);
|
||||
|
|
Loading…
Reference in a new issue