Skip to content

Commit 3f172e7

Browse files
committed
applications: connectivity_bridge: resume bt advertising when disconnected
Resume BT advertising when disconnected. Signed-off-by: Audun Korneliussen <[email protected]>
1 parent e715696 commit 3f172e7

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

applications/connectivity_bridge/src/modules/ble_handler.c

+21-4
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@ LOG_MODULE_REGISTER(MODULE, CONFIG_BRIDGE_BLE_LOG_LEVEL);
3838
#define ATT_MIN_PAYLOAD 20 /* Minimum L2CAP MTU minus ATT header */
3939

4040
static void bt_send_work_handler(struct k_work *work);
41+
static void bt_adv_resume_work_handler(struct k_work *work);
42+
static void adv_start(bool resume);
4143

4244
K_MEM_SLAB_DEFINE(ble_rx_slab, BLE_RX_BLOCK_SIZE, BLE_RX_BUF_COUNT, BLE_SLAB_ALIGNMENT);
4345
RING_BUF_DECLARE(ble_tx_ring_buf, BLE_TX_BUF_SIZE);
4446

4547
static K_SEM_DEFINE(ble_tx_sem, 0, 1);
4648

4749
static K_WORK_DEFINE(bt_send_work, bt_send_work_handler);
50+
static K_WORK_DEFINE(bt_adv_resume_work, bt_adv_resume_work_handler);
4851

4952
static struct bt_conn *current_conn;
5053
static struct bt_gatt_exchange_params exchange_params;
@@ -130,9 +133,18 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
130133
APP_EVENT_SUBMIT(event);
131134
}
132135

136+
static void recycled(void)
137+
{
138+
if (atomic_get(&active)) {
139+
/* Resume advertising outside of ISR context */
140+
k_work_submit(&bt_adv_resume_work);
141+
}
142+
}
143+
133144
static struct bt_conn_cb conn_callbacks = {
134145
.connected = connected,
135146
.disconnected = disconnected,
147+
.recycled = recycled,
136148
};
137149

138150
static void bt_send_work_handler(struct k_work *work)
@@ -166,6 +178,11 @@ static void bt_send_work_handler(struct k_work *work)
166178
}
167179
}
168180

181+
static void bt_adv_resume_work_handler(struct k_work *work)
182+
{
183+
adv_start(true);
184+
}
185+
169186
static void bt_receive_cb(struct bt_conn *conn, const uint8_t *const data,
170187
uint16_t len)
171188
{
@@ -211,7 +228,7 @@ static struct bt_nus_cb nus_cb = {
211228
.sent = bt_sent_cb,
212229
};
213230

214-
static void adv_start(void)
231+
static void adv_start(bool resume)
215232
{
216233
int err;
217234

@@ -229,7 +246,7 @@ static void adv_start(void)
229246
ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
230247
if (err) {
231248
LOG_ERR("bt_le_adv_start: %d", err);
232-
} else {
249+
} else if (!resume) {
233250
module_set_state(MODULE_STATE_READY);
234251
}
235252
}
@@ -287,7 +304,7 @@ static void bt_ready(int err)
287304
#endif
288305

289306
if (atomic_get(&active)) {
290-
adv_start();
307+
adv_start(false);
291308
}
292309
}
293310

@@ -377,7 +394,7 @@ static bool app_event_handler(const struct app_event_header *aeh)
377394
case BLE_CTRL_ENABLE:
378395
if (!atomic_set(&active, true)) {
379396
short_range_rf_front_end_enable();
380-
adv_start();
397+
adv_start(false);
381398
}
382399
break;
383400
case BLE_CTRL_DISABLE:

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ Applications
190190
Connectivity bridge
191191
-------------------
192192

193-
|no_changes_yet_note|
193+
* Fixed to resume Bluetooth connectable advertising after a disconnect.
194+
194195

195196
IPC radio firmware
196197
------------------

0 commit comments

Comments
 (0)