From 7e16d633d24cbbf720c2bc9f2b8823015a79d8bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Ga=C5=82at?= Date: Tue, 12 Nov 2024 16:01:40 +0000 Subject: [PATCH] app: allow DFU and Sidewalk to run in parallel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit remove disabling of Sidewalk when entering to DFU mode Signed-off-by: Robert Gałat --- Kconfig | 4 -- Kconfig.dependencies | 8 +++ samples/sid_end_device/Kconfig.defconfig | 4 ++ samples/sid_end_device/src/hello/app.c | 4 -- .../src/sensor_monitoring/app.c | 2 - subsys/sal/common/CMakeLists.txt | 2 + subsys/sal/common/sid_ifc/bt_app_callbacks.c | 2 +- subsys/sal/common/sid_ifc/bt_app_callbacks.h | 9 ++- subsys/sal/sid_pal/include/sid_ble_advert.h | 7 ++ subsys/sal/sid_pal/src/sid_ble_adapter.c | 4 +- subsys/sal/sid_pal/src/sid_ble_advert.c | 70 ++++++++++++++----- tests/unit_tests/pal_ble_adapter/Kconfig | 4 +- tests/unit_tests/pal_ble_adapter/src/main.c | 8 ++- tests/unit_tests/sid_ble_advert/Kconfig | 10 +-- tests/unit_tests/sid_ble_connection/Kconfig | 6 +- .../unit_tests/sid_ble_connection/src/main.c | 29 +++++--- utils/sidewalk_dfu/nordic_dfu.c | 35 +++++++--- 17 files changed, 141 insertions(+), 67 deletions(-) diff --git a/Kconfig b/Kconfig index f49c5ebc6c..2dd48b1f12 100644 --- a/Kconfig +++ b/Kconfig @@ -14,10 +14,6 @@ if SIDEWALK config MAIN_STACK_SIZE default 2048 -config BT_ID_MAX - default 3 if SIDEWALK_DFU - default 2 - config SIDEWALK_SUBGHZ_SUPPORT bool "Enable Sub-GHz link type support in Sidewalk libraries" default y diff --git a/Kconfig.dependencies b/Kconfig.dependencies index 519592afb2..9e1c1f5a04 100644 --- a/Kconfig.dependencies +++ b/Kconfig.dependencies @@ -38,6 +38,14 @@ config SIDEWALK_BLE help Sidewalk Bluetooth Low Energy (BLE) module +config BT_ID_MAX + default 3 if SIDEWALK_DFU + default 2 + +config BT_APP_IFC + bool "Enable BT app wrapper" + default y if SIDEWALK_BLE + config SIDEWALK_ASSERT bool default SIDEWALK diff --git a/samples/sid_end_device/Kconfig.defconfig b/samples/sid_end_device/Kconfig.defconfig index 43e2b58986..f04ac7c907 100644 --- a/samples/sid_end_device/Kconfig.defconfig +++ b/samples/sid_end_device/Kconfig.defconfig @@ -46,6 +46,10 @@ config BT_EXT_ADV_MAX_ADV_SET default 3 if SIDEWALK_DFU default 2 +config BT_MAX_CONN + default 2 if SIDEWALK_DFU + default 1 + config NVS_LOOKUP_CACHE_SIZE default 256 if NVS diff --git a/samples/sid_end_device/src/hello/app.c b/samples/sid_end_device/src/hello/app.c index 18ada34b85..13d37e0e65 100644 --- a/samples/sid_end_device/src/hello/app.c +++ b/samples/sid_end_device/src/hello/app.c @@ -269,13 +269,9 @@ static void app_btn_dfu_state(uint32_t unused) ARG_UNUSED(unused); static bool go_to_dfu_state = true; if (go_to_dfu_state) { - sidewalk_event_send(sidewalk_event_exit, NULL, NULL); sidewalk_event_send(app_event_enter_dfu_mode, NULL, NULL); - application_state_working(&global_state_notifier, false); } else { sidewalk_event_send(app_event_exit_dfu_mode, NULL, NULL); - sidewalk_event_send(sidewalk_event_autostart, NULL, NULL); - application_state_working(&global_state_notifier, true); } go_to_dfu_state = !go_to_dfu_state; diff --git a/samples/sid_end_device/src/sensor_monitoring/app.c b/samples/sid_end_device/src/sensor_monitoring/app.c index 04fc08a72b..98595732ef 100644 --- a/samples/sid_end_device/src/sensor_monitoring/app.c +++ b/samples/sid_end_device/src/sensor_monitoring/app.c @@ -182,11 +182,9 @@ static void app_btn_dfu_state(uint32_t unused) ARG_UNUSED(unused); static bool go_to_dfu_state = true; if (go_to_dfu_state) { - sidewalk_event_send(sidewalk_event_exit, NULL, NULL); sidewalk_event_send(app_event_enter_dfu_mode, NULL, NULL); } else { sidewalk_event_send(app_event_exit_dfu_mode, NULL, NULL); - sidewalk_event_send(sidewalk_event_autostart, NULL, NULL); } go_to_dfu_state = !go_to_dfu_state; diff --git a/subsys/sal/common/CMakeLists.txt b/subsys/sal/common/CMakeLists.txt index 61bf74755a..1eedcc5d14 100644 --- a/subsys/sal/common/CMakeLists.txt +++ b/subsys/sal/common/CMakeLists.txt @@ -9,3 +9,5 @@ zephyr_include_directories(sid_pal_ifc) zephyr_include_directories(sid_time_ops) add_subdirectory_ifdef(CONFIG_SIDEWALK_ON_DEV_CERT sid_on_dev_cert) + +zephyr_library_sources(sid_ifc/bt_app_callbacks.c) diff --git a/subsys/sal/common/sid_ifc/bt_app_callbacks.c b/subsys/sal/common/sid_ifc/bt_app_callbacks.c index 17cc97b7ee..ef6d79d6ab 100644 --- a/subsys/sal/common/sid_ifc/bt_app_callbacks.c +++ b/subsys/sal/common/sid_ifc/bt_app_callbacks.c @@ -23,8 +23,8 @@ int app_bt_enable(bt_ready_cb_t cb) bt_enable_count++; if (cb) { cb(0); - return 0; } + return 0; } int app_bt_disable() diff --git a/subsys/sal/common/sid_ifc/bt_app_callbacks.h b/subsys/sal/common/sid_ifc/bt_app_callbacks.h index 7abf0d24e9..bf16225c64 100644 --- a/subsys/sal/common/sid_ifc/bt_app_callbacks.h +++ b/subsys/sal/common/sid_ifc/bt_app_callbacks.h @@ -10,21 +10,20 @@ #include #include +#if defined (CONFIG_BT_APP_IFC) int app_bt_enable(bt_ready_cb_t cb); int app_bt_disable(); enum BT_id_values{ _BT_ID_DEFAULT = BT_ID_DEFAULT, - #if defined (CONFIG_SIDEWALK) BT_ID_SIDEWALK, - #endif #if defined (CONFIG_SIDEWALK_DFU) BT_ID_SMP_DFU, #endif - _BT_ID_MAX = CONFIG_BT_ID_MAX + _BT_ID_MAX }; -BUILD_ASSERT(_BT_ID_MAX <= CONFIG_BT_ID_MAX, "Too many BT Ids! Configured limit is %d, but used %d", CONFIG_BT_ID_MAX, _BT_ID_MAX); - +BUILD_ASSERT(_BT_ID_MAX <= CONFIG_BT_ID_MAX, "Too many BT Ids! increase CONFIG_BT_ID_MAX, to match _BT_ID_MAX"); +#endif #endif diff --git a/subsys/sal/sid_pal/include/sid_ble_advert.h b/subsys/sal/sid_pal/include/sid_ble_advert.h index 27c343abce..65255850bc 100644 --- a/subsys/sal/sid_pal/include/sid_ble_advert.h +++ b/subsys/sal/sid_pal/include/sid_ble_advert.h @@ -16,6 +16,13 @@ */ int sid_ble_advert_init(void); +/** + * @brief Deinitialize Bluetooth Advertising. + * + * @return Zero on success or (negative) error code on failure. + */ +int sid_ble_advert_deinit(void); + /** * @brief Start Bluetooth advertising. * diff --git a/subsys/sal/sid_pal/src/sid_ble_adapter.c b/subsys/sal/sid_pal/src/sid_ble_adapter.c index 7da3f39bb2..1bad31c8aa 100644 --- a/subsys/sal/sid_pal/src/sid_ble_adapter.c +++ b/subsys/sal/sid_pal/src/sid_ble_adapter.c @@ -222,7 +222,7 @@ static int create_ble_id(void) /* Check if Bluetooth identites weren't already created. */ bt_id_get(NULL, &count); if (count > BT_ID_SIDEWALK) { - return BT_ID_SIDEWALK; + return 0; } do { @@ -438,7 +438,7 @@ static sid_error_t ble_adapter_deinit(void) { LOG_DBG("Sidewalk -> BLE"); sid_ble_conn_deinit(); - + sid_ble_advert_deinit(); bt_id_delete(BT_ID_SIDEWALK); bt_id_reset(BT_ID_SIDEWALK, NULL, NULL); int err = app_bt_disable(); diff --git a/subsys/sal/sid_pal/src/sid_ble_advert.c b/subsys/sal/sid_pal/src/sid_ble_advert.c index a0a64577fc..106f59e2fb 100644 --- a/subsys/sal/sid_pal/src/sid_ble_advert.c +++ b/subsys/sal/sid_pal/src/sid_ble_advert.c @@ -10,11 +10,13 @@ #include #include +#include #include #include #include #include +#include LOG_MODULE_REGISTER(sid_ble_advert, CONFIG_SIDEWALK_BLE_ADAPTER_LOG_LEVEL); @@ -37,7 +39,7 @@ LOG_MODULE_REGISTER(sid_ble_advert, CONFIG_SIDEWALK_BLE_ADAPTER_LOG_LEVEL); /* Advertising parameters. */ static struct bt_le_adv_param adv_param_fast = { - .id = CONFIG_SIDEWALK_BLE_ID, + .id = BT_ID_SIDEWALK, .options = (AMA_ADV_OPTIONS), .interval_min = MS_TO_INTERVAL_VAL(CONFIG_SIDEWALK_BLE_ADV_INT_FAST), .interval_max = MS_TO_INTERVAL_VAL(CONFIG_SIDEWALK_BLE_ADV_INT_FAST + @@ -45,15 +47,15 @@ static struct bt_le_adv_param adv_param_fast = { }; static struct bt_le_adv_param adv_param_slow = { - .id = CONFIG_SIDEWALK_BLE_ID, + .id = BT_ID_SIDEWALK, .options = (AMA_ADV_OPTIONS), .interval_min = MS_TO_INTERVAL_VAL(CONFIG_SIDEWALK_BLE_ADV_INT_SLOW), .interval_max = MS_TO_INTERVAL_VAL(CONFIG_SIDEWALK_BLE_ADV_INT_SLOW + CONFIG_SIDEWALK_BLE_ADV_INT_PRECISION), }; -static struct bt_le_ext_adv *adv_set_fast; -static struct bt_le_ext_adv *adv_set_slow; +static struct bt_le_ext_adv *adv_set_fast = NULL; +static struct bt_le_ext_adv *adv_set_slow = NULL; /** * @brief Advertising data items values size in bytes. @@ -114,18 +116,24 @@ static void change_advertisement_interval(struct k_work *work) struct bt_le_ext_adv_start_param ext_adv_start_param = { 0 }; if (BLE_ADV_FAST == atomic_get(&adv_state)) { - if (bt_le_ext_adv_stop(adv_set_fast)) { + int err = 0; + err = bt_le_ext_adv_stop(adv_set_fast); + if (err) { atomic_set(&adv_state, BLE_ADV_DISABLE); + LOG_ERR("Failed to stop fast adv errno %d (%s)", err, strerror(err)); return; } - - if (bt_le_ext_adv_set_data(adv_set_slow, adv_data, ARRAY_SIZE(adv_data), NULL, 0)) { + err = bt_le_ext_adv_set_data(adv_set_slow, adv_data, ARRAY_SIZE(adv_data), NULL, 0); + if (err) { atomic_set(&adv_state, BLE_ADV_DISABLE); + LOG_ERR("Failed to set adv data to slow adv errno %d (%s)", err, + strerror(err)); return; } - - if (bt_le_ext_adv_start(adv_set_slow, &ext_adv_start_param)) { + err = bt_le_ext_adv_start(adv_set_slow, &ext_adv_start_param); + if (err) { atomic_set(&adv_state, BLE_ADV_DISABLE); + LOG_ERR("Failed to start slow adv errno %d (%s)", err, strerror(err)); return; } @@ -138,36 +146,60 @@ static void change_advertisement_interval(struct k_work *work) int sid_ble_advert_init(void) { int ret; - - ret = bt_le_ext_adv_create(&adv_param_fast, NULL, &adv_set_fast); - if (ret) { - LOG_ERR("Failed to create fast advertising set"); - return ret; + if (adv_set_fast == NULL) { + ret = bt_le_ext_adv_create(&adv_param_fast, NULL, &adv_set_fast); + if (ret) { + LOG_ERR("Failed to create fast advertising set errno %d (%s)", ret, + strerror(ret)); + return ret; + } } - ret = bt_le_ext_adv_create(&adv_param_slow, NULL, &adv_set_slow); - if (ret) { - LOG_ERR("Failed to create slow advertising set"); - return ret; + if (adv_set_slow == NULL) { + ret = bt_le_ext_adv_create(&adv_param_slow, NULL, &adv_set_slow); + if (ret) { + LOG_ERR("Failed to create slow advertising set errno %d (%s)", ret, + strerror(ret)); + return ret; + } } return 0; } +int sid_ble_advert_deinit(void) +{ + int err = bt_le_ext_adv_delete(adv_set_fast); + if (err) { + LOG_ERR("Failed to delete adv_set_fast errno %d (%s)", err, strerror(err)); + return err; + } + adv_set_fast = NULL; + err = bt_le_ext_adv_delete(adv_set_slow); + if (err) { + LOG_ERR("Failed to delete adv_set_slow errno %d (%s)", err, strerror(err)); + return err; + } + adv_set_slow = NULL; + return 0; +} + int sid_ble_advert_start(void) { k_work_reschedule(&change_adv_work, K_SECONDS(CONFIG_SIDEWALK_BLE_ADV_INT_TRANSITION)); struct bt_le_ext_adv_start_param ext_adv_start_param = { 0 }; - int err; + int err = 0; err = bt_le_ext_adv_set_data(adv_set_fast, adv_data, ARRAY_SIZE(adv_data), NULL, 0); if (err) { + LOG_ERR("Failed to set adv data errno: %d (%s)", err, strerror(err)); return err; } err = bt_le_ext_adv_start(adv_set_fast, &ext_adv_start_param); if (err) { + LOG_ERR("Failed to start adv errno: %d (%s)", err, strerror(err)); return err; } diff --git a/tests/unit_tests/pal_ble_adapter/Kconfig b/tests/unit_tests/pal_ble_adapter/Kconfig index 67222c2460..2fd294e7d8 100644 --- a/tests/unit_tests/pal_ble_adapter/Kconfig +++ b/tests/unit_tests/pal_ble_adapter/Kconfig @@ -31,8 +31,8 @@ config SIDEWALK_LOG_LEVEL config SIDEWALK_BLE_ADAPTER_LOG_LEVEL default 0 -config SIDEWALK_BLE_ID - default 1 +config BT_APP_IFC + default y config BT_ID_MAX default 2 diff --git a/tests/unit_tests/pal_ble_adapter/src/main.c b/tests/unit_tests/pal_ble_adapter/src/main.c index a608686bd0..e682840263 100644 --- a/tests/unit_tests/pal_ble_adapter/src/main.c +++ b/tests/unit_tests/pal_ble_adapter/src/main.c @@ -18,6 +18,7 @@ #include #include #include +#include #include @@ -174,13 +175,15 @@ void test_sid_pal_ble_adapter_init(void) TEST_ASSERT_EQUAL(SID_ERROR_NONE, sid_pal_ble_adapter_create(&p_test_ble_ifc)); - bt_id_create_fake.return_val = CONFIG_SIDEWALK_BLE_ID; + bt_id_create_fake.return_val = BT_ID_SIDEWALK; __cmock_sid_ble_conn_init_Expect(); __cmock_sid_ble_advert_init_IgnoreAndReturn(0); TEST_ASSERT_EQUAL(SID_ERROR_NONE, p_test_ble_ifc->init(&test_ble_cfg)); + app_bt_disable(); __cmock_sid_ble_conn_init_Expect(); TEST_ASSERT_EQUAL(SID_ERROR_NONE, p_test_ble_ifc->init(NULL)); + app_bt_disable(); bt_enable_fake.return_val = -ENOENT; TEST_ASSERT_EQUAL(SID_ERROR_GENERIC, p_test_ble_ifc->init(&test_ble_cfg)); @@ -193,11 +196,12 @@ void test_sid_pal_ble_adapter_deinit(void) TEST_ASSERT_EQUAL(SID_ERROR_NONE, sid_pal_ble_adapter_create(&p_test_ble_ifc)); __cmock_settings_load_ExpectAndReturn(ESUCCESS); __cmock_sid_ble_conn_init_Expect(); - bt_id_create_fake.return_val = CONFIG_SIDEWALK_BLE_ID; + bt_id_create_fake.return_val = BT_ID_SIDEWALK; __cmock_sid_ble_advert_init_IgnoreAndReturn(0); TEST_ASSERT_EQUAL(SID_ERROR_NONE, p_test_ble_ifc->init(&test_ble_cfg)); __cmock_sid_ble_conn_deinit_Expect(); + __cmock_sid_ble_advert_deinit_IgnoreAndReturn(0); TEST_ASSERT_EQUAL(SID_ERROR_NONE, p_test_ble_ifc->deinit()); } diff --git a/tests/unit_tests/sid_ble_advert/Kconfig b/tests/unit_tests/sid_ble_advert/Kconfig index 296292f60e..a1fb4da783 100644 --- a/tests/unit_tests/sid_ble_advert/Kconfig +++ b/tests/unit_tests/sid_ble_advert/Kconfig @@ -9,6 +9,12 @@ config SIDEWALK_BUILD config SIDEWALK_LOG_LEVEL default 0 +config BT_ID_MAX + default 2 + +config BT_APP_IFC + default y + module = SIDEWALK_BLE_ADAPTER module-str = Sidewalk BLE interface source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config" @@ -29,8 +35,4 @@ config SIDEWALK_BLE_ADV_INT_TRANSITION int "test value for Sidewalk configuration macro" default 30 -config SIDEWALK_BLE_ID - int "test value for Sidewalk configuration" - default 1 - source "Kconfig.zephyr" diff --git a/tests/unit_tests/sid_ble_connection/Kconfig b/tests/unit_tests/sid_ble_connection/Kconfig index 081b348335..cb92a98f62 100644 --- a/tests/unit_tests/sid_ble_connection/Kconfig +++ b/tests/unit_tests/sid_ble_connection/Kconfig @@ -12,10 +12,10 @@ config SIDEWALK_LOG_LEVEL config SIDEWALK_BLE_ADAPTER_LOG_LEVEL default 0 -config SIDEWALK_BLE_ID - default 1 - config BT_ID_MAX default 2 +config BT_APP_IFC + default y + source "Kconfig.zephyr" diff --git a/tests/unit_tests/sid_ble_connection/src/main.c b/tests/unit_tests/sid_ble_connection/src/main.c index bfcaf0d77d..3b09bb3a42 100644 --- a/tests/unit_tests/sid_ble_connection/src/main.c +++ b/tests/unit_tests/sid_ble_connection/src/main.c @@ -15,6 +15,7 @@ #include #include +#include DEFINE_FFF_GLOBALS; @@ -24,7 +25,7 @@ FAKE_VALUE_FUNC(struct bt_conn *, bt_conn_ref, struct bt_conn *); FAKE_VOID_FUNC(bt_conn_unref, struct bt_conn *); FAKE_VALUE_FUNC(const bt_addr_le_t *, bt_conn_get_dst, const struct bt_conn *); FAKE_VALUE_FUNC(int, bt_conn_disconnect, struct bt_conn *, uint8_t); -FAKE_VALUE_FUNC(int,bt_conn_get_info,const struct bt_conn *, struct bt_conn_info *); +FAKE_VALUE_FUNC(int, bt_conn_get_info, const struct bt_conn *, struct bt_conn_info *); #define FFF_FAKES_LIST(FAKE) \ FAKE(bt_conn_cb_register) \ @@ -32,7 +33,7 @@ FAKE_VALUE_FUNC(int,bt_conn_get_info,const struct bt_conn *, struct bt_conn_info FAKE(bt_conn_ref) \ FAKE(bt_conn_unref) \ FAKE(bt_conn_get_dst) \ - FAKE(bt_conn_disconnect)\ + FAKE(bt_conn_disconnect) \ FAKE(bt_conn_get_info) #define CONNECTED (true) @@ -104,8 +105,9 @@ void test_sid_ble_conn_params_get(void) TEST_ASSERT_NULL(params); } -int bt_conn_get_info_fake1(const struct bt_conn * a, struct bt_conn_info * b){ - b->id = CONFIG_SIDEWALK_BLE_ID; +int bt_conn_get_info_fake1(const struct bt_conn *a, struct bt_conn_info *b) +{ + b->id = BT_ID_SIDEWALK; return 0; } @@ -122,9 +124,9 @@ void test_sid_ble_conn_positive(void) bt_conn_get_dst_fake.return_val = &test_addr; bt_conn_ref_fake.return_val = &test_conn; - int (*custom_fakes[])(const struct bt_conn *, struct bt_conn_info *) = {bt_conn_get_info_fake1}; + int (*custom_fakes[])(const struct bt_conn *, + struct bt_conn_info *) = { bt_conn_get_info_fake1 }; SET_CUSTOM_FAKE_SEQ(bt_conn_get_info, custom_fakes, 1); - sid_ble_conn_deinit(); sid_ble_conn_init(); @@ -153,7 +155,8 @@ void test_sid_ble_set_conn_cb_positive(void) bt_conn_get_dst_fake.return_val = &test_addr; bt_conn_ref_fake.return_val = &test_conn; - int (*custom_fakes[])(const struct bt_conn *, struct bt_conn_info *) = {bt_conn_get_info_fake1}; + int (*custom_fakes[])(const struct bt_conn *, + struct bt_conn_info *) = { bt_conn_get_info_fake1 }; SET_CUSTOM_FAKE_SEQ(bt_conn_get_info, custom_fakes, 1); sid_ble_conn_init(); @@ -185,7 +188,8 @@ void test_sid_ble_conn_cb_set_call_count(void) bt_conn_get_dst_fake.return_val = &test_addr; bt_conn_ref_fake.return_val = &test_conn; - int (*custom_fakes[])(const struct bt_conn *, struct bt_conn_info *) = {bt_conn_get_info_fake1}; + int (*custom_fakes[])(const struct bt_conn *, + struct bt_conn_info *) = { bt_conn_get_info_fake1 }; SET_CUSTOM_FAKE_SEQ(bt_conn_get_info, custom_fakes, 1); sid_ble_conn_init(); @@ -222,7 +226,8 @@ void test_sid_ble_disconnected_wrong_conn(void) bt_conn_get_dst_fake.return_val = &test_addr; bt_conn_ref_fake.return_val = &test_conn; - int (*custom_fakes[])(const struct bt_conn *, struct bt_conn_info *) = {bt_conn_get_info_fake1}; + int (*custom_fakes[])(const struct bt_conn *, + struct bt_conn_info *) = { bt_conn_get_info_fake1 }; SET_CUSTOM_FAKE_SEQ(bt_conn_get_info, custom_fakes, 1); sid_ble_conn_init(); @@ -249,7 +254,8 @@ void test_sid_ble_cb_set_before_init(void) struct bt_conn test_conn = { .dummy = 0xDC }; bt_conn_ref_fake.return_val = &test_conn; - int (*custom_fakes[])(const struct bt_conn *, struct bt_conn_info *) = {bt_conn_get_info_fake1}; + int (*custom_fakes[])(const struct bt_conn *, + struct bt_conn_info *) = { bt_conn_get_info_fake1 }; SET_CUSTOM_FAKE_SEQ(bt_conn_get_info, custom_fakes, 1); sid_ble_conn_deinit(); @@ -287,7 +293,8 @@ void test_sid_ble_conn_mtu_callback_curent_connection(void) sid_ble_conn_init(); bt_conn_ref_fake.return_val = &curr_conn; - int (*custom_fakes[])(const struct bt_conn *, struct bt_conn_info *) = {bt_conn_get_info_fake1}; + int (*custom_fakes[])(const struct bt_conn *, + struct bt_conn_info *) = { bt_conn_get_info_fake1 }; SET_CUSTOM_FAKE_SEQ(bt_conn_get_info, custom_fakes, 1); __cmock_sid_ble_adapter_conn_connected_ExpectAnyArgs(); diff --git a/utils/sidewalk_dfu/nordic_dfu.c b/utils/sidewalk_dfu/nordic_dfu.c index e9f5335dcb..225c80e87a 100644 --- a/utils/sidewalk_dfu/nordic_dfu.c +++ b/utils/sidewalk_dfu/nordic_dfu.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -20,7 +21,7 @@ LOG_MODULE_REGISTER(nordic_dfu, CONFIG_SIDEWALK_LOG_LEVEL); #define LED_PERIOD_TOGGLE_ALL 500 #define LED_PERIOD_LOADING_WHEEL 150 -static struct bt_le_ext_adv *adv; +static struct bt_le_ext_adv *adv = NULL; static struct bt_le_ext_adv_start_param ext_adv_param = { .num_events = 0, .timeout = 0 }; static struct bt_le_adv_param adv_params = { .id = BT_ID_DEFAULT, .sid = 0, @@ -56,7 +57,7 @@ static int create_ble_id(void) /* Check if Bluetooth identites weren't already created. */ bt_id_get(NULL, &count); if (count > BT_ID_SMP_DFU) { - return BT_ID_SMP_DFU; + return 0; } do { @@ -150,19 +151,31 @@ int nordic_dfu_ble_start(void) int err = app_bt_enable(NULL); if (err && err != -EALREADY) { - LOG_ERR("Bluetooth enable failed (err %d)", err); + LOG_ERR("Bluetooth enable failed (err %d %s)", err, strerror(err)); return err; } mgmt_callback_register(&dfu_mode_mgmt_cb); + int ret = create_ble_id(); + if (ret < 0) { + LOG_ERR("Failed to create BLE ID errno %d %s", ret, strerror(ret)); + return err; + } - adv_params.id = create_ble_id(); + adv_params.id = BT_ID_SMP_DFU; err = bt_le_ext_adv_create(&adv_params, NULL, &adv); + if (err) { + LOG_ERR("Bluetooth advertising create failed (err %d %s)", err, strerror(err)); + return err; + } err = bt_le_ext_adv_set_data(adv, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd)); + if (err) { + LOG_ERR("Bluetooth advertising data set failed (err %d %s)", err, strerror(err)); + return err; + } err = bt_le_ext_adv_start(adv, &ext_adv_param); - if (err) { - LOG_ERR("Bluetooth advertising start failed (err %d)", err); + LOG_ERR("Bluetooth advertising start failed (err %d %s)", err, strerror(err)); return err; } @@ -186,13 +199,19 @@ int nordic_dfu_ble_stop(void) int err = bt_le_ext_adv_stop(adv); if (err) { - LOG_ERR("Bluetooth advertising stop failed (err %d)", err); + LOG_ERR("Bluetooth advertising stop failed (err %d %s)", err, strerror(err)); + return err; + } + err = bt_le_ext_adv_delete(adv); + if (err) { + LOG_ERR("Bluetooth advertising delete failed (err %d %s)", err, strerror(err)); return err; } + adv = NULL; err = app_bt_disable(); if (err) { - LOG_ERR("Bluetooth disable failed (err %d)", err); + LOG_ERR("Bluetooth disable failed (err %d %s)", err, strerror(err)); return err; }