Merge pull request #681 from felis/parse_extended_result

Parse Extended Inquiry Result events and fix parsing class of device …
This commit is contained in:
Kristian Sloth Lauszus 2021-12-19 21:18:50 +01:00 committed by GitHub
commit 651d7b094c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

15
BTD.cpp
View file

@ -504,16 +504,21 @@ void BTD::HCI_event_task() {
break; break;
case EV_INQUIRY_RESULT: case EV_INQUIRY_RESULT:
case EV_EXTENDED_INQUIRY_RESULT:
if(hcibuf[2]) { // Check that there is more than zero responses if(hcibuf[2]) { // Check that there is more than zero responses
#ifdef EXTRADEBUG #ifdef EXTRADEBUG
Notify(PSTR("\r\nNumber of responses: "), 0x80); Notify(PSTR("\r\nNumber of responses: "), 0x80);
Notify(hcibuf[2], 0x80); Notify(hcibuf[2], 0x80); // This will always be 1 for an extended inquiry result
#endif #endif
for(uint8_t i = 0; i < hcibuf[2]; i++) { for(uint8_t i = 0; i < hcibuf[2]; i++) {
uint8_t offset = 8 * hcibuf[2] + 3 * i; uint8_t classOfDevice_offset;
if(hcibuf[0] == EV_INQUIRY_RESULT)
classOfDevice_offset = 9 * hcibuf[2]; // 6-byte bd_addr, 1 byte page_scan_repetition_mode, 2 byte reserved
else
classOfDevice_offset = 8 * hcibuf[2]; // 6-byte bd_addr, 1 byte page_scan_repetition_mode, 1 byte reserved
for(uint8_t j = 0; j < 3; j++) for(uint8_t j = 0; j < 3; j++)
classOfDevice[j] = hcibuf[j + 4 + offset]; classOfDevice[j] = hcibuf[3 + classOfDevice_offset + 3 * i + j];
#ifdef EXTRADEBUG #ifdef EXTRADEBUG
Notify(PSTR("\r\nClass of device: "), 0x80); Notify(PSTR("\r\nClass of device: "), 0x80);
@ -528,7 +533,7 @@ void BTD::HCI_event_task() {
checkRemoteName = true; // Check remote name to distinguish between the different controllers checkRemoteName = true; // Check remote name to distinguish between the different controllers
for(uint8_t j = 0; j < 6; j++) for(uint8_t j = 0; j < 6; j++)
disc_bdaddr[j] = hcibuf[j + 3 + 6 * i]; disc_bdaddr[j] = hcibuf[3 + 6 * i + j];
hci_set_flag(HCI_FLAG_DEVICE_FOUND); hci_set_flag(HCI_FLAG_DEVICE_FOUND);
break; break;
@ -544,7 +549,7 @@ void BTD::HCI_event_task() {
Notify(PSTR("\r\nGamepad found"), 0x80); Notify(PSTR("\r\nGamepad found"), 0x80);
#endif #endif
for(uint8_t j = 0; j < 6; j++) for(uint8_t j = 0; j < 6; j++)
disc_bdaddr[j] = hcibuf[j + 3 + 6 * i]; disc_bdaddr[j] = hcibuf[3 + 6 * i + j];
hci_set_flag(HCI_FLAG_DEVICE_FOUND); hci_set_flag(HCI_FLAG_DEVICE_FOUND);
break; break;

1
BTD.h
View file

@ -104,6 +104,7 @@
#define EV_LOOPBACK_COMMAND 0x19 #define EV_LOOPBACK_COMMAND 0x19
#define EV_PAGE_SCAN_REP_MODE 0x20 #define EV_PAGE_SCAN_REP_MODE 0x20
#define EV_READ_REMOTE_EXTENDED_FEATURES_COMPLETE 0x23 #define EV_READ_REMOTE_EXTENDED_FEATURES_COMPLETE 0x23
#define EV_EXTENDED_INQUIRY_RESULT 0x2F
#define EV_IO_CAPABILITY_REQUEST 0x31 #define EV_IO_CAPABILITY_REQUEST 0x31
#define EV_IO_CAPABILITY_RESPONSE 0x32 #define EV_IO_CAPABILITY_RESPONSE 0x32
#define EV_USER_CONFIRMATION_REQUEST 0x33 #define EV_USER_CONFIRMATION_REQUEST 0x33