1818#include <zephyr/mgmt/mcumgr/smp/smp.h>
1919#include <zephyr/mgmt/mcumgr/transport/smp.h>
2020#include <zephyr/mgmt/mcumgr/transport/smp_bt.h>
21+ #include <zephyr/mgmt/mcumgr/mgmt/handlers.h>
2122#include <errno.h>
2223
2324#include <mgmt/mcumgr/transport/smp_internal.h>
2425#include <mgmt/mcumgr/transport/smp_reassembly.h>
2526
26- #ifdef CONFIG_MCUMGR_TRANSPORT_BT_AUTOMATIC_INIT
27- #include <zephyr/mgmt/mcumgr/mgmt/handlers.h>
28- #endif
29-
3027#include <zephyr/logging/log.h>
3128LOG_MODULE_DECLARE (mcumgr_smp , CONFIG_MCUMGR_SMP_LOG_LEVEL );
3229
@@ -90,10 +87,6 @@ static uint8_t next_id;
9087static struct smp_transport smp_bt_transport ;
9188static struct conn_param_data conn_data [CONFIG_BT_MAX_CONN ];
9289
93- #ifdef CONFIG_MCUMGR_TRANSPORT_BT_AUTOMATIC_INIT
94- static K_SEM_DEFINE (bt_ready_sem , 0 , 1 ) ;
95- #endif
96-
9790/* SMP service.
9891 * {8D53DC1D-1DB7-4CD3-868B-8A527460AA84}
9992 */
@@ -106,6 +99,15 @@ static struct bt_uuid_128 smp_bt_svc_uuid = BT_UUID_INIT_128(
10699static struct bt_uuid_128 smp_bt_chr_uuid = BT_UUID_INIT_128 (
107100 BT_UUID_128_ENCODE (0xda2e7828 , 0xfbce , 0x4e01 , 0xae9e , 0x261174997c48 ));
108101
102+ static void connected (struct bt_conn * conn , uint8_t err );
103+ static void disconnected (struct bt_conn * conn , uint8_t reason );
104+
105+ /* Bluetooth connection callback handlers */
106+ BT_CONN_CB_DEFINE (mcumgr_bt_callbacks ) = {
107+ .connected = connected ,
108+ .disconnected = disconnected ,
109+ };
110+
109111/* Helper function that allocates conn_param_data for a conn. */
110112static struct conn_param_data * conn_param_data_alloc (struct bt_conn * conn )
111113{
@@ -634,35 +636,13 @@ static bool smp_bt_query_valid_check(struct net_buf *nb, void *arg)
634636 return true;
635637}
636638
637- #ifdef CONFIG_MCUMGR_TRANSPORT_BT_AUTOMATIC_INIT_WAIT
638- static void bt_ready (int err )
639- {
640- if (err ) {
641- LOG_ERR ("Bluetooth init failed (err %d)" , err );
642- return ;
643- }
644-
645- LOG_INF ("Bluetooth initialised" );
646-
647- k_sem_give (& bt_ready_sem );
648- }
649- #endif
650-
651- void smp_bt_start (void )
639+ static void smp_bt_setup (void )
652640{
653641 int rc ;
654642 uint8_t i = 0 ;
655643
656644 next_id = 1 ;
657645
658- /* Register BT callbacks */
659- static struct bt_conn_cb conn_callbacks = {
660- .connected = connected ,
661- .disconnected = disconnected ,
662- };
663-
664- bt_conn_cb_register (& conn_callbacks );
665-
666646 if (IS_ENABLED (CONFIG_MCUMGR_SMP_BT_CONN_PARAM_CONTROL )) {
667647 conn_param_control_init ();
668648 }
@@ -683,26 +663,4 @@ void smp_bt_start(void)
683663 }
684664}
685665
686- #ifdef CONFIG_MCUMGR_TRANSPORT_BT_AUTOMATIC_INIT
687- static void smp_bt_setup (void )
688- {
689- /* Enable Bluetooth */
690- #ifdef CONFIG_MCUMGR_TRANSPORT_BT_AUTOMATIC_INIT_WAIT
691- int rc = bt_enable (bt_ready );
692- #else
693- int rc = bt_enable (NULL );
694- #endif
695-
696- if (rc != 0 ) {
697- LOG_ERR ("Bluetooth init failed (err %d)" , rc );
698- } else {
699- #ifdef CONFIG_MCUMGR_TRANSPORT_BT_AUTOMATIC_INIT_WAIT
700- k_sem_take (& bt_ready_sem , K_FOREVER );
701- #endif
702- }
703-
704- smp_bt_start ();
705- }
706-
707666MCUMGR_HANDLER_DEFINE (smp_bt , smp_bt_setup );
708- #endif
0 commit comments