77
88#if PBDRV_CONFIG_BLUETOOTH_BTSTACK
99
10+ #include <btstack_config.h>
11+
1012#include <assert.h>
1113#include <inttypes.h>
1214#include <stdio.h>
1618#include <btstack.h>
1719#include <btstack_run_loop.h>
1820
21+ #include <gap.h>
22+ #include <lwrb/lwrb.h>
23+
1924#include <pbdrv/bluetooth.h>
2025#include <pbdrv/clock.h>
2126
27+ #include <pbio/int_math.h>
2228#include <pbio/os.h>
2329#include <pbio/protocol.h>
2430#include <pbio/version.h>
@@ -338,12 +344,21 @@ static bool pbdrv_bluetooth_btstack_ble_supported(void) {
338344 return chipset_info && chipset_info -> supports_ble ;
339345}
340346
347+ void pbdrv_bluetooth_classic_init (void );
348+ void pbdrv_bluetooth_btstack_handle_classic_security_packet (uint8_t * packet , uint16_t size );
349+
341350// currently, this function just handles the Powered Up handset control.
342351static void packet_handler (uint8_t packet_type , uint16_t channel , uint8_t * packet , uint16_t size ) {
343352
344353 // Platform-specific platform handler has priority.
345354 pbdrv_bluetooth_btstack_platform_packet_handler (packet_type , channel , packet , size );
346355
356+ if (packet_type == HCI_EVENT_PACKET ) {
357+ // We have a separate handler for classic security packets,
358+ // which we don't mix in here for clarity's sake.
359+ pbdrv_bluetooth_btstack_handle_classic_security_packet (packet , size );
360+ }
361+
347362 switch (hci_event_packet_get_type (packet )) {
348363 case HCI_EVENT_COMMAND_COMPLETE : {
349364 const uint8_t * rp = hci_event_command_complete_get_return_parameters (packet );
@@ -1172,6 +1187,18 @@ pbio_error_t pbdrv_bluetooth_stop_observing_func(pbio_os_state_t *state, void *c
11721187 PBIO_OS_ASYNC_END (PBIO_SUCCESS );
11731188}
11741189
1190+ void pbdrv_bluetooth_local_address (bdaddr_t addr ) {
1191+ gap_local_bd_addr (addr );
1192+ }
1193+
1194+ const char * pbdrv_bluetooth_bdaddr_to_str (const bdaddr_t addr ) {
1195+ return bd_addr_to_str (addr );
1196+ }
1197+
1198+ bool pbdrv_bluetooth_str_to_bdaddr (const char * str , bdaddr_t addr ) {
1199+ return sscanf_bd_addr (str , addr ) == 1 ;
1200+ }
1201+
11751202static void pbdrv_bluetooth_inquiry_unpack_scan_event (uint8_t * event_packet , pbdrv_bluetooth_inquiry_result_t * result ) {
11761203
11771204 gap_event_inquiry_result_get_bd_addr (event_packet , result -> bdaddr );
@@ -1426,6 +1453,7 @@ void pbdrv_bluetooth_init_hci(void) {
14261453 hci_dump_enable_log_level (HCI_DUMP_LOG_LEVEL_INFO , true);
14271454 hci_dump_enable_log_level (HCI_DUMP_LOG_LEVEL_ERROR , true);
14281455 hci_dump_enable_log_level (HCI_DUMP_LOG_LEVEL_DEBUG , true);
1456+ hci_dump_enable_packet_log (false);
14291457 #endif
14301458
14311459 static btstack_packet_callback_registration_t hci_event_callback_registration ;
@@ -1471,6 +1499,8 @@ void pbdrv_bluetooth_init_hci(void) {
14711499 // GATT Client setup
14721500 gatt_client_init ();
14731501
1502+ pbdrv_bluetooth_classic_init ();
1503+
14741504 #if PBDRV_CONFIG_BLUETOOTH_BTSTACK_NUM_LE_HOSTS
14751505 // setup ATT server
14761506 att_server_init (profile_data , att_read_callback , NULL );
@@ -1488,7 +1518,7 @@ void pbdrv_bluetooth_init_hci(void) {
14881518 (void )pybricks_configured ;
14891519 (void )nordic_spp_packet_handler ;
14901520 (void )sm_packet_handler ;
1491- #endif // PBDRV_CONFIG_BLUETOOTH_BTSTACK_LE
1521+ #endif // PBDRV_CONFIG_BLUETOOTH_BTSTACK_NUM_LE_HOSTS
14921522
14931523 bluetooth_thread_err = PBIO_ERROR_AGAIN ;
14941524 bluetooth_thread_state = 0 ;
0 commit comments