@@ -32,13 +32,17 @@ static const struct bt_data ad_peer[] = {
3232/* Set aside space for name to be in scan response */
3333static struct bt_data sd_peer [1 ];
3434
35+ K_SEM_DEFINE (adv_sem , 1 , 1 );
36+
3537static void smp_adv (void )
3638{
3739 int ret ;
3840
3941 ret = bt_le_adv_start (BT_LE_ADV_CONN_FAST_2 , ad_peer , ARRAY_SIZE (ad_peer ), sd_peer ,
4042 ARRAY_SIZE (sd_peer ));
41- if (ret ) {
43+ if (ret == - EALREADY ) {
44+ return ;
45+ } else if (ret ) {
4246 LOG_ERR ("SMP_SVR Advertising failed to start (ret %d)" , ret );
4347 return ;
4448 }
@@ -58,9 +62,15 @@ static void dfu_disconnected_cb(struct bt_conn *conn, uint8_t reason)
5862 LOG_INF ("SMP disconnected 0x%02x\n" , reason );
5963}
6064
65+ static void dfu_recycled_cb (void )
66+ {
67+ k_sem_give (& adv_sem );
68+ }
69+
6170static struct bt_conn_cb dfu_conn_callbacks = {
6271 .connected = dfu_connected_cb ,
6372 .disconnected = dfu_disconnected_cb ,
73+ .recycled = dfu_recycled_cb ,
6474};
6575
6676static void dfu_set_bt_name (void )
@@ -113,9 +123,10 @@ void bt_mgmt_dfu_start(void)
113123
114124 bt_conn_cb_register (& dfu_conn_callbacks );
115125 dfu_set_bt_name ();
116- smp_adv ();
117126
118127 while (1 ) {
119- k_sleep (K_MSEC (100 ));
128+ /* In DFU mode, the device should always advertise */
129+ k_sem_take (& adv_sem , K_FOREVER );
130+ smp_adv ();
120131 }
121132}
0 commit comments