Skip to content

Commit cbf666e

Browse files
joerchancarlescufi
authored andcommitted
Bluetooth: Host: Check that bluetooth device is ready
Check that the bluetooth device has in fact been initialized before continuing with public API calls. This could lead to crashes when using state that has not yet been initialized. Signed-off-by: Joakim Andersson <[email protected]>
1 parent d3ea66d commit cbf666e

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

subsys/bluetooth/host/conn.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,10 @@ int bt_le_set_auto_conn(const bt_addr_le_t *addr,
21732173
{
21742174
struct bt_conn *conn;
21752175

2176+
if (!atomic_test_bit(bt_dev.flags, BT_DEV_READY)) {
2177+
return -EAGAIN;
2178+
}
2179+
21762180
if (param && !bt_le_conn_params_valid(param)) {
21772181
return -EINVAL;
21782182
}

subsys/bluetooth/host/gatt.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,6 +1767,10 @@ int bt_gatt_notify_cb(struct bt_conn *conn,
17671767
__ASSERT(params, "invalid parameters\n");
17681768
__ASSERT(params->attr, "invalid parameters\n");
17691769

1770+
if (!atomic_test_bit(bt_dev.flags, BT_DEV_READY)) {
1771+
return -EAGAIN;
1772+
}
1773+
17701774
attr = params->attr;
17711775

17721776
if (conn && conn->state != BT_CONN_CONNECTED) {
@@ -1829,6 +1833,10 @@ int bt_gatt_indicate(struct bt_conn *conn,
18291833
__ASSERT(params, "invalid parameters\n");
18301834
__ASSERT(params->attr, "invalid parameters\n");
18311835

1836+
if (!atomic_test_bit(bt_dev.flags, BT_DEV_READY)) {
1837+
return -EAGAIN;
1838+
}
1839+
18321840
attr = params->attr;
18331841

18341842
if (conn && conn->state != BT_CONN_CONNECTED) {

subsys/bluetooth/host/hci_core.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6425,6 +6425,10 @@ int bt_le_oob_get_local(u8_t id, struct bt_le_oob *oob)
64256425
{
64266426
int err;
64276427

6428+
if (!atomic_test_bit(bt_dev.flags, BT_DEV_READY)) {
6429+
return -EAGAIN;
6430+
}
6431+
64286432
if (id >= CONFIG_BT_ID_MAX) {
64296433
return -EINVAL;
64306434
}
@@ -6459,13 +6463,21 @@ int bt_le_oob_set_sc_data(struct bt_conn *conn,
64596463
const struct bt_le_oob_sc_data *oobd_local,
64606464
const struct bt_le_oob_sc_data *oobd_remote)
64616465
{
6466+
if (!atomic_test_bit(bt_dev.flags, BT_DEV_READY)) {
6467+
return -EAGAIN;
6468+
}
6469+
64626470
return bt_smp_le_oob_set_sc_data(conn, oobd_local, oobd_remote);
64636471
}
64646472

64656473
int bt_le_oob_get_sc_data(struct bt_conn *conn,
64666474
const struct bt_le_oob_sc_data **oobd_local,
64676475
const struct bt_le_oob_sc_data **oobd_remote)
64686476
{
6477+
if (!atomic_test_bit(bt_dev.flags, BT_DEV_READY)) {
6478+
return -EAGAIN;
6479+
}
6480+
64696481
return bt_smp_le_oob_get_sc_data(conn, oobd_local, oobd_remote);
64706482
}
64716483
#endif

0 commit comments

Comments
 (0)