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 <joakim.andersson@nordicsemi.no>
This commit is contained in:
parent
d3ea66d493
commit
cbf666ecc3
3 changed files with 24 additions and 0 deletions
|
@ -2173,6 +2173,10 @@ int bt_le_set_auto_conn(const bt_addr_le_t *addr,
|
||||||
{
|
{
|
||||||
struct bt_conn *conn;
|
struct bt_conn *conn;
|
||||||
|
|
||||||
|
if (!atomic_test_bit(bt_dev.flags, BT_DEV_READY)) {
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
if (param && !bt_le_conn_params_valid(param)) {
|
if (param && !bt_le_conn_params_valid(param)) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1767,6 +1767,10 @@ int bt_gatt_notify_cb(struct bt_conn *conn,
|
||||||
__ASSERT(params, "invalid parameters\n");
|
__ASSERT(params, "invalid parameters\n");
|
||||||
__ASSERT(params->attr, "invalid parameters\n");
|
__ASSERT(params->attr, "invalid parameters\n");
|
||||||
|
|
||||||
|
if (!atomic_test_bit(bt_dev.flags, BT_DEV_READY)) {
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
attr = params->attr;
|
attr = params->attr;
|
||||||
|
|
||||||
if (conn && conn->state != BT_CONN_CONNECTED) {
|
if (conn && conn->state != BT_CONN_CONNECTED) {
|
||||||
|
@ -1829,6 +1833,10 @@ int bt_gatt_indicate(struct bt_conn *conn,
|
||||||
__ASSERT(params, "invalid parameters\n");
|
__ASSERT(params, "invalid parameters\n");
|
||||||
__ASSERT(params->attr, "invalid parameters\n");
|
__ASSERT(params->attr, "invalid parameters\n");
|
||||||
|
|
||||||
|
if (!atomic_test_bit(bt_dev.flags, BT_DEV_READY)) {
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
attr = params->attr;
|
attr = params->attr;
|
||||||
|
|
||||||
if (conn && conn->state != BT_CONN_CONNECTED) {
|
if (conn && conn->state != BT_CONN_CONNECTED) {
|
||||||
|
|
|
@ -6425,6 +6425,10 @@ int bt_le_oob_get_local(u8_t id, struct bt_le_oob *oob)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
if (!atomic_test_bit(bt_dev.flags, BT_DEV_READY)) {
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
if (id >= CONFIG_BT_ID_MAX) {
|
if (id >= CONFIG_BT_ID_MAX) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -6459,6 +6463,10 @@ int bt_le_oob_set_sc_data(struct bt_conn *conn,
|
||||||
const struct bt_le_oob_sc_data *oobd_local,
|
const struct bt_le_oob_sc_data *oobd_local,
|
||||||
const struct bt_le_oob_sc_data *oobd_remote)
|
const struct bt_le_oob_sc_data *oobd_remote)
|
||||||
{
|
{
|
||||||
|
if (!atomic_test_bit(bt_dev.flags, BT_DEV_READY)) {
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
return bt_smp_le_oob_set_sc_data(conn, oobd_local, oobd_remote);
|
return bt_smp_le_oob_set_sc_data(conn, oobd_local, oobd_remote);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6466,6 +6474,10 @@ int bt_le_oob_get_sc_data(struct bt_conn *conn,
|
||||||
const struct bt_le_oob_sc_data **oobd_local,
|
const struct bt_le_oob_sc_data **oobd_local,
|
||||||
const struct bt_le_oob_sc_data **oobd_remote)
|
const struct bt_le_oob_sc_data **oobd_remote)
|
||||||
{
|
{
|
||||||
|
if (!atomic_test_bit(bt_dev.flags, BT_DEV_READY)) {
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
return bt_smp_le_oob_get_sc_data(conn, oobd_local, oobd_remote);
|
return bt_smp_le_oob_get_sc_data(conn, oobd_local, oobd_remote);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue