mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-06-05 21:04:49 +00:00
Nimble: Check stack status before executing stack command
Added change of checking stack status in the APIs exposed to user
This commit is contained in:
+137
-14
@@ -431,6 +431,10 @@ ble_gap_conn_find(uint16_t handle, struct ble_gap_conn_desc *out_desc)
|
||||
{
|
||||
struct ble_hs_conn *conn;
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
ble_hs_lock();
|
||||
|
||||
conn = ble_hs_conn_find(handle);
|
||||
@@ -500,6 +504,10 @@ ble_gap_extract_conn_cb(uint16_t conn_handle,
|
||||
int
|
||||
ble_gap_set_priv_mode(const ble_addr_t *peer_addr, uint8_t priv_mode)
|
||||
{
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
return ble_hs_pvcy_set_mode(peer_addr, priv_mode);
|
||||
}
|
||||
|
||||
@@ -512,6 +520,10 @@ ble_gap_read_le_phy(uint16_t conn_handle, uint8_t *tx_phy, uint8_t *rx_phy)
|
||||
uint8_t rsplen;
|
||||
int rc;
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
ble_hs_lock();
|
||||
conn = ble_hs_conn_find(conn_handle);
|
||||
ble_hs_unlock();
|
||||
@@ -549,6 +561,10 @@ ble_gap_set_prefered_default_le_phy(uint8_t tx_phys_mask, uint8_t rx_phys_mask)
|
||||
uint8_t buf[BLE_HCI_LE_SET_DEFAULT_PHY_LEN];
|
||||
int rc;
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
rc = ble_hs_hci_cmd_build_le_set_default_phy(tx_phys_mask, rx_phys_mask,
|
||||
buf, sizeof(buf));
|
||||
if (rc != 0) {
|
||||
@@ -568,6 +584,10 @@ ble_gap_set_prefered_le_phy(uint16_t conn_handle, uint8_t tx_phys_mask,
|
||||
uint8_t buf[BLE_HCI_LE_SET_PHY_LEN];
|
||||
int rc;
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
ble_hs_lock();
|
||||
conn = ble_hs_conn_find(conn_handle);
|
||||
ble_hs_unlock();
|
||||
@@ -1686,6 +1706,10 @@ ble_gap_set_event_cb(uint16_t conn_handle, ble_gap_event_fn *cb, void *cb_arg)
|
||||
{
|
||||
struct ble_hs_conn *conn;
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
ble_hs_lock();
|
||||
|
||||
conn = ble_hs_conn_find(conn_handle);
|
||||
@@ -1795,6 +1819,10 @@ ble_gap_wl_set(const ble_addr_t *addrs, uint8_t white_list_count)
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(BLE_HOST_BASED_PRIVACY)
|
||||
if (ble_host_rpa_enabled()) {
|
||||
return BLE_HS_ENOTSUP;
|
||||
@@ -2126,6 +2154,10 @@ ble_gap_adv_start(uint8_t own_addr_type, const ble_addr_t *direct_addr,
|
||||
|
||||
STATS_INC(ble_gap_stats, adv_start);
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
ble_hs_lock();
|
||||
|
||||
rc = ble_gap_adv_validate(own_addr_type, direct_addr, adv_params);
|
||||
@@ -2142,11 +2174,6 @@ ble_gap_adv_start(uint8_t own_addr_type, const ble_addr_t *direct_addr,
|
||||
}
|
||||
}
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
rc = BLE_HS_EDISABLED;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (ble_gap_is_preempted()) {
|
||||
rc = BLE_HS_EPREEMPTED;
|
||||
goto done;
|
||||
@@ -2278,6 +2305,11 @@ ble_gap_adv_set_fields(const struct ble_hs_adv_fields *adv_fields)
|
||||
uint8_t buf_sz;
|
||||
int rc;
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
|
||||
rc = ble_hs_adv_set_fields(adv_fields, buf, &buf_sz, sizeof buf);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
@@ -2302,6 +2334,10 @@ ble_gap_adv_rsp_set_fields(const struct ble_hs_adv_fields *rsp_fields)
|
||||
uint8_t buf_sz;
|
||||
int rc;
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
rc = ble_hs_adv_set_fields(rsp_fields, buf, &buf_sz, sizeof buf);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
@@ -2318,6 +2354,10 @@ ble_gap_adv_rsp_set_fields(const struct ble_hs_adv_fields *rsp_fields)
|
||||
int
|
||||
ble_gap_adv_active(void)
|
||||
{
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
return ble_gap_adv_active_instance(0);
|
||||
}
|
||||
|
||||
@@ -2472,6 +2512,10 @@ ble_gap_ext_adv_configure(uint8_t instance,
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
rc = ble_gap_ext_adv_params_validate(params);
|
||||
if (rc) {
|
||||
return rc;
|
||||
@@ -2539,6 +2583,10 @@ ble_gap_ext_adv_set_addr(uint8_t instance, const ble_addr_t *addr)
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
ble_hs_lock();
|
||||
rc = ble_gap_ext_adv_set_addr_no_lock(instance, addr->val);
|
||||
ble_hs_unlock();
|
||||
@@ -2559,6 +2607,10 @@ ble_gap_ext_adv_start(uint8_t instance, int duration, int max_events)
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
ble_hs_lock();
|
||||
if (!ble_gap_slave[instance].configured) {
|
||||
ble_hs_unlock();
|
||||
@@ -2693,6 +2745,10 @@ ble_gap_ext_adv_stop(uint8_t instance)
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
ble_hs_lock();
|
||||
rc = ble_gap_ext_adv_stop_no_lock(instance);
|
||||
ble_hs_unlock();
|
||||
@@ -2840,6 +2896,10 @@ ble_gap_ext_adv_set_data(uint8_t instance, struct os_mbuf *data)
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
ble_hs_lock();
|
||||
rc = ble_gap_ext_adv_set_data_validate(instance, data);
|
||||
if (rc != 0) {
|
||||
@@ -2907,6 +2967,10 @@ ble_gap_ext_adv_rsp_set_data(uint8_t instance, struct os_mbuf *data)
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
ble_hs_lock();
|
||||
rc = ble_gap_ext_adv_rsp_set_validate(instance, data);
|
||||
if (rc != 0) {
|
||||
@@ -2935,6 +2999,10 @@ ble_gap_ext_adv_remove(uint8_t instance)
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
ble_hs_lock();
|
||||
if (!ble_gap_slave[instance].configured) {
|
||||
ble_hs_unlock();
|
||||
@@ -3135,6 +3203,10 @@ ble_gap_disc_cancel(void)
|
||||
|
||||
int rc;
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
ble_hs_lock();
|
||||
rc = ble_gap_disc_cancel_no_lock();
|
||||
ble_hs_unlock();
|
||||
@@ -3229,6 +3301,10 @@ ble_gap_ext_disc(uint8_t own_addr_type, uint16_t duration, uint16_t period,
|
||||
|
||||
STATS_INC(ble_gap_stats, discover);
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
ble_hs_lock();
|
||||
|
||||
rc = ble_gap_disc_ext_validate(own_addr_type);
|
||||
@@ -3339,6 +3415,10 @@ ble_gap_disc(uint8_t own_addr_type, int32_t duration_ms,
|
||||
return BLE_HS_ENOTSUP;
|
||||
#else
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(BLE_EXT_ADV)
|
||||
struct ble_gap_ext_disc_params p = {0};
|
||||
|
||||
@@ -3631,6 +3711,10 @@ ble_gap_ext_connect(uint8_t own_addr_type, const ble_addr_t *peer_addr,
|
||||
|
||||
STATS_INC(ble_gap_stats, initiate);
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
ble_hs_lock();
|
||||
|
||||
if (ble_gap_conn_active()) {
|
||||
@@ -3643,10 +3727,6 @@ ble_gap_ext_connect(uint8_t own_addr_type, const ble_addr_t *peer_addr,
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
if (ble_gap_is_preempted()) {
|
||||
rc = BLE_HS_EPREEMPTED;
|
||||
goto done;
|
||||
@@ -3748,6 +3828,10 @@ ble_gap_connect(uint8_t own_addr_type, const ble_addr_t *peer_addr,
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(BLE_EXT_ADV)
|
||||
return ble_gap_ext_connect(own_addr_type, peer_addr, duration_ms,
|
||||
BLE_GAP_LE_PHY_1M_MASK,
|
||||
@@ -3770,11 +3854,6 @@ ble_gap_connect(uint8_t own_addr_type, const ble_addr_t *peer_addr,
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
rc = BLE_HS_EDISABLED;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (ble_gap_is_preempted()) {
|
||||
rc = BLE_HS_EPREEMPTED;
|
||||
goto done;
|
||||
@@ -3879,6 +3958,10 @@ ble_gap_terminate(uint16_t conn_handle, uint8_t hci_reason)
|
||||
|
||||
STATS_INC(ble_gap_stats, terminate);
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
ble_hs_lock();
|
||||
|
||||
conn = ble_hs_conn_find(conn_handle);
|
||||
@@ -3979,6 +4062,10 @@ ble_gap_conn_cancel(void)
|
||||
|
||||
int rc;
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
ble_hs_lock();
|
||||
rc = ble_gap_conn_cancel_no_lock();
|
||||
ble_hs_unlock();
|
||||
@@ -4259,6 +4346,10 @@ ble_gap_update_params(uint16_t conn_handle,
|
||||
|
||||
l2cap_update = 0;
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
/* Validate parameters with a spec */
|
||||
if (!ble_gap_validate_conn_params(params)) {
|
||||
return BLE_HS_EINVAL;
|
||||
@@ -4354,6 +4445,10 @@ ble_gap_security_initiate(uint16_t conn_handle)
|
||||
|
||||
STATS_INC(ble_gap_stats, security_initiate);
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
ble_hs_lock();
|
||||
conn = ble_hs_conn_find(conn_handle);
|
||||
if (conn != NULL) {
|
||||
@@ -4412,6 +4507,10 @@ ble_gap_pair_initiate(uint16_t conn_handle)
|
||||
{
|
||||
int rc;
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
rc = ble_sm_pair_initiate(conn_handle);
|
||||
|
||||
return rc;
|
||||
@@ -4432,6 +4531,10 @@ ble_gap_encryption_initiate(uint16_t conn_handle,
|
||||
ble_hs_conn_flags_t conn_flags;
|
||||
int rc;
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
rc = ble_hs_atomic_conn_flags(conn_handle, &conn_flags);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
@@ -4455,6 +4558,10 @@ ble_gap_unpair(const ble_addr_t *peer_addr)
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
ble_hs_lock();
|
||||
|
||||
conn = ble_hs_conn_find_by_addr(peer_addr);
|
||||
@@ -4477,6 +4584,10 @@ ble_gap_unpair_oldest_peer(void)
|
||||
int num_peers;
|
||||
int rc;
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
rc = ble_store_util_bonded_peers(
|
||||
&oldest_peer_id_addr, &num_peers, 1);
|
||||
if (rc != 0) {
|
||||
@@ -4502,6 +4613,10 @@ ble_gap_unpair_oldest_except(const ble_addr_t *peer_addr)
|
||||
int num_peers;
|
||||
int rc, i;
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
rc = ble_store_util_bonded_peers(
|
||||
&peer_id_addrs[0], &num_peers, MYNEWT_VAL(BLE_STORE_MAX_BONDS));
|
||||
if (rc != 0) {
|
||||
@@ -4627,6 +4742,10 @@ ble_gap_conn_rssi(uint16_t conn_handle, int8_t *out_rssi)
|
||||
{
|
||||
int rc;
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
rc = ble_hs_hci_util_read_rssi(conn_handle, out_rssi);
|
||||
return rc;
|
||||
}
|
||||
@@ -4868,6 +4987,10 @@ ble_gap_event_listener_register(struct ble_gap_event_listener *listener,
|
||||
struct ble_gap_event_listener *evl = NULL;
|
||||
int rc;
|
||||
|
||||
if (!ble_hs_is_enabled()) {
|
||||
return BLE_HS_EDISABLED;
|
||||
}
|
||||
|
||||
SLIST_FOREACH(evl, &ble_gap_event_listener_list, link) {
|
||||
if (evl == listener) {
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user