From 8c9bb29ec24759ba592d72f79417df812fd8a97f Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 17 Dec 2021 21:03:22 +0100 Subject: [PATCH] example: init SM if LE supported to avoid issue with Android Cross-Transport Key-Derivation --- CHANGELOG.md | 8 ++++++++ example/a2dp_sink_demo.c | 7 +++++++ example/a2dp_source_demo.c | 7 +++++++ example/avrcp_browsing_client.c | 5 +++++ example/gap_dedicated_bonding.c | 7 +++++++ example/hfp_ag_demo.c | 5 +++++ example/hfp_hf_demo.c | 5 +++++ example/hid_host_demo.c | 9 +++++++-- example/hid_keyboard_demo.c | 5 +++++ example/hid_mouse_demo.c | 5 +++++ example/hsp_ag_demo.c | 5 +++++ example/hsp_hs_demo.c | 5 +++++ example/pan_lwip_http_server.c | 5 +++++ example/panu_demo.c | 6 +++++- example/pbap_client_demo.c | 15 +++++++-------- example/spp_counter.c | 5 +++++ example/spp_flowcontrol.c | 7 +++++++ example/spp_streamer.c | 5 +++++ example/spp_streamer_client.c | 5 +++++ src/btstack.h | 2 ++ 20 files changed, 112 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34affa92f..62e689004 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed ### Changed +## Release v1.5.1 + +### Fixed +- pbap_client: support disconnect while operation is ongoing + +### Changed +- Example: init SM if LE supported to avoid issue with Android Cross-Transport Key-Derivation + ## Release v1.5.0 diff --git a/example/a2dp_sink_demo.c b/example/a2dp_sink_demo.c index 36d558966..2d2197596 100644 --- a/example/a2dp_sink_demo.c +++ b/example/a2dp_sink_demo.c @@ -213,7 +213,14 @@ static void stdin_process(char cmd); #endif static int a2dp_and_avrcp_setup(void){ + l2cap_init(); + +#ifdef ENABLE_BLE + // Initialize LE Security Manager. Needed for cross-transport key derivation + sm_init(); +#endif + // Initialize AVDTP Sink a2dp_sink_init(); a2dp_sink_register_packet_handler(&a2dp_sink_packet_handler); diff --git a/example/a2dp_source_demo.c b/example/a2dp_source_demo.c index d63ae6342..d9597359b 100644 --- a/example/a2dp_source_demo.c +++ b/example/a2dp_source_demo.c @@ -249,10 +249,17 @@ static void stdin_process(char cmd); static void a2dp_demo_hexcmod_configure_sample_rate(int sample_rate); static int a2dp_source_and_avrcp_services_init(void){ + // Request role change on reconnecting headset to always use them in slave mode hci_set_master_slave_policy(0); l2cap_init(); + +#ifdef ENABLE_BLE + // Initialize LE Security Manager. Needed for cross-transport key derivation + sm_init(); +#endif + // Initialize A2DP Source a2dp_source_init(); a2dp_source_register_packet_handler(&a2dp_source_packet_handler); diff --git a/example/avrcp_browsing_client.c b/example/avrcp_browsing_client.c index 0acdbc4d0..c31f4119e 100644 --- a/example/avrcp_browsing_client.c +++ b/example/avrcp_browsing_client.c @@ -246,6 +246,11 @@ int btstack_main(int argc, const char * argv[]){ // Initialize L2CAP. l2cap_init(); +#ifdef ENABLE_BLE + // Initialize LE Security Manager. Needed for cross-transport key derivation + sm_init(); +#endif + a2dp_sink_init(); a2dp_sink_register_packet_handler(&a2dp_sink_packet_handler); diff --git a/example/gap_dedicated_bonding.c b/example/gap_dedicated_bonding.c index 5de57ec23..1ac478fb0 100644 --- a/example/gap_dedicated_bonding.c +++ b/example/gap_dedicated_bonding.c @@ -77,6 +77,13 @@ int btstack_main(int argc, const char * argv[]){ hci_event_callback_registration.callback = &packet_handler; hci_add_event_handler(&hci_event_callback_registration); + l2cap_init(); + +#ifdef ENABLE_BLE + // Initialize LE Security Manager. Needed for cross-transport key derivation + sm_init(); +#endif + // turn on! hci_power_control(HCI_POWER_ON); diff --git a/example/hfp_ag_demo.c b/example/hfp_ag_demo.c index f8a337557..b256ff71b 100644 --- a/example/hfp_ag_demo.c +++ b/example/hfp_ag_demo.c @@ -706,6 +706,11 @@ int btstack_main(int argc, const char * argv[]){ // L2CAP l2cap_init(); +#ifdef ENABLE_BLE + // Initialize LE Security Manager. Needed for cross-transport key derivation + sm_init(); +#endif + uint16_t supported_features = (1< #include -#include "btstack_run_loop.h" -#include "l2cap.h" -#include "classic/rfcomm.h" -#include "btstack_event.h" -#include "classic/goep_client.h" -#include "classic/pbap_client.h" +#include "btstack.h" #ifdef HAVE_BTSTACK_STDIN #include "btstack_stdin.h" @@ -370,13 +365,17 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe int btstack_main(int argc, const char * argv[]); int btstack_main(int argc, const char * argv[]){ - (void)argc; (void)argv; - + // init L2CAP l2cap_init(); +#ifdef ENABLE_BLE + // Initialize LE Security Manager. Needed for cross-transport key derivation + sm_init(); +#endif + // init RFCOM rfcomm_init(); diff --git a/example/spp_counter.c b/example/spp_counter.c index d6045371b..e88ff9d9c 100644 --- a/example/spp_counter.c +++ b/example/spp_counter.c @@ -90,6 +90,11 @@ static void spp_service_setup(void){ l2cap_init(); +#ifdef ENABLE_BLE + // Initialize LE Security Manager. Needed for cross-transport key derivation + sm_init(); +#endif + rfcomm_init(); rfcomm_register_service(packet_handler, RFCOMM_SERVER_CHANNEL, 0xffff); // reserved channel, mtu limited by l2cap diff --git a/example/spp_flowcontrol.c b/example/spp_flowcontrol.c index ac582f648..0240eea3f 100644 --- a/example/spp_flowcontrol.c +++ b/example/spp_flowcontrol.c @@ -200,6 +200,13 @@ int btstack_main(int argc, const char * argv[]){ (void)argc; (void)argv; + l2cap_init(); + +#ifdef ENABLE_BLE + // Initialize LE Security Manager. Needed for cross-transport key derivation + sm_init(); +#endif + spp_service_setup(); one_shot_timer_setup(); diff --git a/example/spp_streamer.c b/example/spp_streamer.c index 605789bad..361a5742d 100644 --- a/example/spp_streamer.c +++ b/example/spp_streamer.c @@ -283,6 +283,11 @@ int btstack_main(int argc, const char * argv[]) l2cap_init(); +#ifdef ENABLE_BLE + // Initialize LE Security Manager. Needed for cross-transport key derivation + sm_init(); +#endif + rfcomm_init(); rfcomm_register_service(packet_handler, RFCOMM_SERVER_CHANNEL, 0xffff); diff --git a/example/spp_streamer_client.c b/example/spp_streamer_client.c index 53b586ba7..b277b3dc7 100644 --- a/example/spp_streamer_client.c +++ b/example/spp_streamer_client.c @@ -392,6 +392,11 @@ int btstack_main(int argc, const char * argv[]){ l2cap_init(); +#ifdef ENABLE_BLE + // Initialize LE Security Manager. Needed for cross-transport key derivation + sm_init(); +#endif + rfcomm_init(); #ifdef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE_FOR_RFCOMM diff --git a/src/btstack.h b/src/btstack.h index 131e9811b..b074d184d 100644 --- a/src/btstack.h +++ b/src/btstack.h @@ -129,6 +129,7 @@ #include "classic/btstack_sbc.h" #include "classic/device_id_server.h" #include "classic/gatt_sdp.h" +#include "classic/goep_client.h" #include "classic/hfp.h" #include "classic/hfp_ag.h" #include "classic/hfp_hf.h" @@ -137,6 +138,7 @@ #include "classic/hsp_ag.h" #include "classic/hsp_hs.h" #include "classic/pan.h" +#include "classic/pbap_client.h" #include "classic/rfcomm.h" #include "classic/sdp_client.h" #include "classic/sdp_client_rfcomm.h"