Skip to content

Commit 4402e8a

Browse files
laurensvalkjaguilar
andcommitted
pbio/drv/bluetooth_btstack: Read full HCI version info payload.
Co-authored-by: James Aguilar <aguilar.james@gmail.com>
1 parent b3c6702 commit 4402e8a

5 files changed

Lines changed: 35 additions & 12 deletions

File tree

lib/pbio/drv/bluetooth/bluetooth_btstack.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,23 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
228228
const uint8_t *rp = hci_event_command_complete_get_return_parameters(packet);
229229
switch (hci_event_command_complete_get_command_opcode(packet)) {
230230
case HCI_OPCODE_HCI_READ_LOCAL_VERSION_INFORMATION: {
231-
uint16_t lmp_pal_subversion = pbio_get_uint16_le(&rp[7]);
232-
pbdrv_bluetooth_btstack_set_chipset(lmp_pal_subversion);
231+
pbdrv_bluetooth_btstack_device_discriminator_t info;
232+
info.hci_version = rp[1];
233+
info.hci_revision = pbio_get_uint16_le(&rp[2]);
234+
info.lmp_pal_version = rp[4];
235+
info.manufacturer = pbio_get_uint16_le(&rp[5]);
236+
info.lmp_pal_subversion = pbio_get_uint16_le(&rp[7]);
237+
pbdrv_bluetooth_btstack_set_chipset(&info);
233238

234239
#if DEBUG
235240
// Show version in ev3dev format.
236-
uint16_t chip = (lmp_pal_subversion & 0x7C00) >> 10;
237-
uint16_t min_ver = (lmp_pal_subversion & 0x007F);
238-
uint16_t maj_ver = (lmp_pal_subversion & 0x0380) >> 7;
239-
if (lmp_pal_subversion & 0x8000) {
241+
uint16_t chip = (info.lmp_pal_subversion & 0x7C00) >> 10;
242+
uint16_t min_ver = (info.lmp_pal_subversion & 0x007F);
243+
uint16_t maj_ver = (info.lmp_pal_subversion & 0x0380) >> 7;
244+
if (info.lmp_pal_subversion & 0x8000) {
240245
maj_ver |= 0x0008;
241246
}
242-
DEBUG_PRINT("LMP %04x: TIInit_%d.%d.%d.bts\n", lmp_pal_subversion, chip, maj_ver, min_ver);
247+
DEBUG_PRINT("LMP %04x: TIInit_%d.%d.%d.bts\n", info.lmp_pal_subversion, chip, maj_ver, min_ver);
243248
#endif
244249
break;
245250
}

lib/pbio/drv/bluetooth/bluetooth_btstack.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,31 @@ typedef struct {
3737
const uint32_t init_script_size;
3838
} pbdrv_bluetooth_btstack_chipset_info_t;
3939

40+
/**
41+
* Device discriminator info from the HCI read local version information command.
42+
*/
43+
typedef struct {
44+
/** HCI version. */
45+
uint8_t hci_version;
46+
/** HCI revision. */
47+
uint16_t hci_revision;
48+
/** LMP/PAL version. */
49+
uint8_t lmp_pal_version;
50+
/** Manufacturer. */
51+
uint16_t manufacturer;
52+
/** LMP/PAL subversion. */
53+
uint16_t lmp_pal_subversion;
54+
} pbdrv_bluetooth_btstack_device_discriminator_t;
55+
4056
/**
4157
* Hook called when BTstack reads the local version information.
4258
*
4359
* This is called _after_ hci_set_chipset but _before_ the init script is sent
4460
* over the wire, so this can be used to dynamically select the init script.
61+
*
62+
* @param device_info The device information read from the Bluetooth chip.
4563
*/
46-
void pbdrv_bluetooth_btstack_set_chipset(uint16_t lmp_pal_subversion);
64+
void pbdrv_bluetooth_btstack_set_chipset(pbdrv_bluetooth_btstack_device_discriminator_t *device_info);
4765

4866
typedef struct {
4967
const hci_transport_t *(*transport_instance)(void);

lib/pbio/drv/bluetooth/bluetooth_btstack_ev3.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ pbio_error_t pbdrv_bluetooth_btstack_platform_init(void) {
7373
void pbdrv_bluetooth_btstack_platform_poll(void) {
7474
}
7575

76-
void pbdrv_bluetooth_btstack_set_chipset(uint16_t lmp_pal_subversion) {
77-
const pbdrv_bluetooth_btstack_chipset_info_t *info = lmp_pal_subversion == cc2560_info.lmp_version ?
76+
void pbdrv_bluetooth_btstack_set_chipset(pbdrv_bluetooth_btstack_device_discriminator_t *device_info) {
77+
const pbdrv_bluetooth_btstack_chipset_info_t *info = device_info->lmp_pal_subversion == cc2560_info.lmp_version ?
7878
&cc2560_info : &cc2560a_info;
7979
btstack_chipset_cc256x_set_init_script((uint8_t *)info->init_script, info->init_script_size);
8080

lib/pbio/drv/bluetooth/bluetooth_btstack_stm32_hal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pbio_error_t pbdrv_bluetooth_btstack_platform_init(void) {
3333
void pbdrv_bluetooth_btstack_platform_poll(void) {
3434
}
3535

36-
void pbdrv_bluetooth_btstack_set_chipset(uint16_t lmp_pal_subversion) {
36+
void pbdrv_bluetooth_btstack_set_chipset(pbdrv_bluetooth_btstack_device_discriminator_t *device_info) {
3737

3838
const pbdrv_bluetooth_btstack_platform_data_t *pdata =
3939
&pbdrv_bluetooth_btstack_platform_data;

lib/pbio/test/drv/test_bluetooth_btstack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ static void handle_data_source(btstack_data_source_t *ds, btstack_data_source_c
770770
}
771771
}
772772

773-
void pbdrv_bluetooth_btstack_set_chipset(uint16_t lmp_pal_subversion) {
773+
void pbdrv_bluetooth_btstack_set_chipset(pbdrv_bluetooth_btstack_device_discriminator_t *device_info) {
774774
}
775775

776776
pbio_error_t pbdrv_bluetooth_btstack_platform_init(void) {

0 commit comments

Comments
 (0)