diff --git a/subsys/bluetooth/host/adv.c b/subsys/bluetooth/host/adv.c index 423a88e4cf4..db71858f8f2 100644 --- a/subsys/bluetooth/host/adv.c +++ b/subsys/bluetooth/host/adv.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "addr_internal.h" #include "hci_core.h" @@ -1566,6 +1567,12 @@ int bt_le_ext_adv_create(const struct bt_le_adv_param *param, return -EAGAIN; } + CHECKIF(out_adv == NULL) { + LOG_DBG("out_adv is NULL"); + + return -EINVAL; + } + if (!valid_adv_ext_param(param)) { return -EINVAL; } @@ -1591,6 +1598,12 @@ int bt_le_ext_adv_create(const struct bt_le_adv_param *param, int bt_le_ext_adv_update_param(struct bt_le_ext_adv *adv, const struct bt_le_adv_param *param) { + CHECKIF(adv == NULL) { + LOG_DBG("adv is NULL"); + + return -EINVAL; + } + if (!valid_adv_ext_param(param)) { return -EINVAL; } @@ -1625,6 +1638,12 @@ int bt_le_ext_adv_start(struct bt_le_ext_adv *adv, struct bt_conn *conn = NULL; int err; + CHECKIF(adv == NULL) { + LOG_DBG("adv is NULL"); + + return -EINVAL; + } + if (atomic_test_bit(adv->flags, BT_ADV_ENABLED)) { return -EALREADY; } @@ -1682,6 +1701,12 @@ int bt_le_ext_adv_start(struct bt_le_ext_adv *adv, int bt_le_ext_adv_stop(struct bt_le_ext_adv *adv) { + CHECKIF(adv == NULL) { + LOG_DBG("adv is NULL"); + + return -EINVAL; + } + (void)bt_le_lim_adv_cancel_timeout(adv); atomic_clear_bit(adv->flags, BT_ADV_PERSIST); @@ -1712,6 +1737,12 @@ int bt_le_ext_adv_set_data(struct bt_le_ext_adv *adv, { bool ext_adv, scannable; + CHECKIF(adv == NULL) { + LOG_DBG("adv is NULL"); + + return -EINVAL; + } + ext_adv = atomic_test_bit(adv->flags, BT_ADV_EXT_ADV); scannable = atomic_test_bit(adv->flags, BT_ADV_SCANNABLE); @@ -1736,6 +1767,12 @@ int bt_le_ext_adv_delete(struct bt_le_ext_adv *adv) return -ENOTSUP; } + CHECKIF(adv == NULL) { + LOG_DBG("adv is NULL"); + + return -EINVAL; + } + /* Advertising set should be stopped first */ if (atomic_test_bit(adv->flags, BT_ADV_ENABLED)) { return -EINVAL; @@ -1815,6 +1852,12 @@ int bt_le_per_adv_set_param(struct bt_le_ext_adv *adv, return -ENOTSUP; } + CHECKIF(adv == NULL) { + LOG_DBG("adv is NULL"); + + return -EINVAL; + } + if (atomic_test_bit(adv->flags, BT_ADV_SCANNABLE)) { return -EINVAL; } else if (atomic_test_bit(adv->flags, BT_ADV_CONNECTABLE)) { @@ -1887,6 +1930,12 @@ int bt_le_per_adv_set_data(const struct bt_le_ext_adv *adv, return -ENOTSUP; } + CHECKIF(adv == NULL) { + LOG_DBG("adv is NULL"); + + return -EINVAL; + } + if (!atomic_test_bit(adv->flags, BT_PER_ADV_PARAMS_SET)) { return -EINVAL; } @@ -1922,6 +1971,12 @@ int bt_le_per_adv_set_subevent_data(const struct bt_le_ext_adv *adv, uint8_t num return -ENOTSUP; } + CHECKIF(adv == NULL) { + LOG_DBG("adv is NULL"); + + return -EINVAL; + } + for (size_t i = 0; i < num_subevents; i++) { cmd_length += sizeof(struct bt_hci_cp_le_set_pawr_subevent_data_element); cmd_length += params[i].data->len; @@ -1963,6 +2018,12 @@ static int bt_le_per_adv_enable(struct bt_le_ext_adv *adv, bool enable) return -ENOTSUP; } + CHECKIF(adv == NULL) { + LOG_DBG("adv is NULL"); + + return -EINVAL; + } + /* TODO: We could setup some default ext adv params if not already set*/ if (!atomic_test_bit(adv->flags, BT_PER_ADV_PARAMS_SET)) { return -EINVAL;