Skip to content

Commit 98fa91c

Browse files
committed
drv/bluetooth: use address type when connecting
The LEGO Mario hub uses a random BLE address, so we need to store this information from the advertising data and use it when connecting. We can also drop the Mario attribute handle hack since Mario seems to be working without it now (this may have been fixed earlier in a4a85dd or it could be due to this change but wasn't tested until now).
1 parent 51bdd09 commit 98fa91c

File tree

3 files changed

+5
-20
lines changed

3 files changed

+5
-20
lines changed

lib/pbio/drv/bluetooth/bluetooth_stm32_bluenrg.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ static PT_THREAD(scan_and_connect_task(struct pt *pt, pbio_task_t *task)) {
435435
}
436436

437437
// save the Bluetooth address for later
438-
// addr_type = subevt->bdaddr_type;
438+
context->bdaddr_type = subevt->bdaddr_type;
439439
memcpy(context->bdaddr, subevt->bdaddr, 6);
440440

441441
break;
@@ -482,9 +482,7 @@ static PT_THREAD(scan_and_connect_task(struct pt *pt, pbio_task_t *task)) {
482482
assert(!remote_handle);
483483

484484
PT_WAIT_WHILE(pt, write_xfer_size);
485-
// REVISIT: might want to store address type from advertising data and pass
486-
// it in here instead of assuming public address type
487-
aci_gap_create_connection_begin(0x0060, 0x0030, PUBLIC_ADDR, context->bdaddr,
485+
aci_gap_create_connection_begin(0x0060, 0x0030, context->bdaddr_type, context->bdaddr,
488486
PUBLIC_ADDR, 0x0010 >> 1, 0x0030 >> 1, 4, 720 / 10, 0x0010, 0x0030);
489487
PT_WAIT_UNTIL(pt, hci_command_status);
490488
context->status = aci_gap_create_connection_end();
@@ -530,12 +528,6 @@ static PT_THREAD(scan_and_connect_task(struct pt *pt, pbio_task_t *task)) {
530528
});
531529
});
532530

533-
// HACK: Characteristics of LEGO Mario are not properly found by aci_gatt_disc_charac_by_uuid_begin().
534-
// remote_lwp3_char_handle for mario is hard coded for now
535-
if (context->hub_kind == LWP3_HUB_KIND_MARIO) {
536-
remote_lwp3_char_handle = 0x0011;
537-
}
538-
539531
// enable notifications
540532

541533
static const uint16_t enable = 0x0001;

lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ static PT_THREAD(scan_and_connect_task(struct pt *pt, pbio_task_t *task)) {
468468
}
469469

470470
// save the Bluetooth address for later
471-
// addr_type = read_buf[10];
471+
context->bdaddr_type = read_buf[10];
472472
memcpy(context->bdaddr, &read_buf[11], 6);
473473

474474
break;
@@ -510,9 +510,7 @@ static PT_THREAD(scan_and_connect_task(struct pt *pt, pbio_task_t *task)) {
510510
assert(remote_handle == NO_CONNECTION);
511511

512512
PT_WAIT_WHILE(pt, write_xfer_size);
513-
// REVISIT: might want to store address type from advertising data and pass
514-
// it in here instead of assuming public address type
515-
GAP_EstablishLinkReq(0, 0, ADDRTYPE_PUBLIC, context->bdaddr);
513+
GAP_EstablishLinkReq(0, 0, context->bdaddr_type, context->bdaddr);
516514
PT_WAIT_UNTIL(pt, hci_command_status);
517515

518516
context->status = read_buf[8]; // debug
@@ -577,12 +575,6 @@ static PT_THREAD(scan_and_connect_task(struct pt *pt, pbio_task_t *task)) {
577575
});
578576
});
579577

580-
// HACK: Characteristics of LEGO Mario are not properly found by GATT_DiscCharsByUUID().
581-
// remote_lwp3_char_handle for mario is hard coded for now
582-
if (context->hub_kind == LWP3_HUB_KIND_MARIO) {
583-
remote_lwp3_char_handle = 0x0012;
584-
}
585-
586578
// enable notifications
587579

588580
retry:

lib/pbio/include/pbdrv/bluetooth.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ void pbdrv_bluetooth_set_notification_handler(pbdrv_bluetooth_receive_handler_t
152152
typedef struct {
153153
lwp3_hub_kind_t hub_kind;
154154
uint8_t status;
155+
uint8_t bdaddr_type;
155156
uint8_t bdaddr[6];
156157
char name[20];
157158
} pbdrv_bluetooth_scan_and_connect_context_t;

0 commit comments

Comments
 (0)