Skip to content

applications: connectivity_bridge: resume bt advertising when disconn… #22278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions applications/connectivity_bridge/src/modules/ble_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ LOG_MODULE_REGISTER(MODULE, CONFIG_BRIDGE_BLE_LOG_LEVEL);
#define ATT_MIN_PAYLOAD 20 /* Minimum L2CAP MTU minus ATT header */

static void bt_send_work_handler(struct k_work *work);
static void bt_adv_resume_work_handler(struct k_work *work);
static void adv_start(bool resume);

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

static K_SEM_DEFINE(ble_tx_sem, 0, 1);

static K_WORK_DEFINE(bt_send_work, bt_send_work_handler);
static K_WORK_DEFINE(bt_adv_resume_work, bt_adv_resume_work_handler);

static struct bt_conn *current_conn;
static struct bt_gatt_exchange_params exchange_params;
Expand Down Expand Up @@ -130,9 +133,18 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
APP_EVENT_SUBMIT(event);
}

static void recycled(void)
{
if (atomic_get(&active)) {
/* Resume advertising outside of ISR context */
k_work_submit(&bt_adv_resume_work);
}
}

static struct bt_conn_cb conn_callbacks = {
.connected = connected,
.disconnected = disconnected,
.recycled = recycled,
};

static void bt_send_work_handler(struct k_work *work)
Expand Down Expand Up @@ -166,6 +178,11 @@ static void bt_send_work_handler(struct k_work *work)
}
}

static void bt_adv_resume_work_handler(struct k_work *work)
{
adv_start(true);
}

static void bt_receive_cb(struct bt_conn *conn, const uint8_t *const data,
uint16_t len)
{
Expand Down Expand Up @@ -211,7 +228,7 @@ static struct bt_nus_cb nus_cb = {
.sent = bt_sent_cb,
};

static void adv_start(void)
static void adv_start(bool resume)
{
int err;

Expand All @@ -229,7 +246,7 @@ static void adv_start(void)
ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
if (err) {
LOG_ERR("bt_le_adv_start: %d", err);
} else {
} else if (!resume) {
module_set_state(MODULE_STATE_READY);
}
}
Expand Down Expand Up @@ -287,7 +304,7 @@ static void bt_ready(int err)
#endif

if (atomic_get(&active)) {
adv_start();
adv_start(false);
}
}

Expand Down Expand Up @@ -377,7 +394,7 @@ static bool app_event_handler(const struct app_event_header *aeh)
case BLE_CTRL_ENABLE:
if (!atomic_set(&active, true)) {
short_range_rf_front_end_enable();
adv_start();
adv_start(false);
}
break;
case BLE_CTRL_DISABLE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ Applications
Connectivity bridge
-------------------

|no_changes_yet_note|
* Fixed to resume Bluetooth connectable advertising after a disconnect.


IPC radio firmware
------------------
Expand Down