mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-10-23 04:47:56 +00:00
fix(nimble): Adding change to keep connection reattempt count per link
This commit is contained in:
+113
-46
@@ -73,6 +73,21 @@ static bool ble_gap_deferred_pvcy_replace;
|
||||
#undef SET_BIT
|
||||
#define SET_BIT(t, n) (t |= 1UL << (n))
|
||||
|
||||
/* Public APIs start at zero; only internal retries carry the old budget. */
|
||||
#if MYNEWT_VAL(BLE_EXT_ADV)
|
||||
static int ble_gap_ext_connect_internal(uint8_t own_addr_type,
|
||||
const ble_addr_t *peer_addr, int32_t duration_ms, uint8_t phy_mask,
|
||||
const struct ble_gap_conn_params *phy_1m_conn_params,
|
||||
const struct ble_gap_conn_params *phy_2m_conn_params,
|
||||
const struct ble_gap_conn_params *phy_coded_conn_params,
|
||||
uint8_t dbaf_filter_policy, ble_gap_event_fn *cb, void *cb_arg,
|
||||
uint8_t reattempt_count);
|
||||
#endif
|
||||
static int ble_gap_connect_internal(uint8_t own_addr_type,
|
||||
const ble_addr_t *peer_addr, int32_t duration_ms,
|
||||
const struct ble_gap_conn_params *conn_params,
|
||||
ble_gap_event_fn *cb, void *cb_arg, uint8_t reattempt_count);
|
||||
|
||||
/**
|
||||
* GAP - Generic Access Profile.
|
||||
*
|
||||
@@ -146,6 +161,9 @@ static const struct ble_gap_conn_params ble_gap_conn_params_dflt = {
|
||||
|
||||
#if NIMBLE_BLE_CONNECT && MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)
|
||||
struct ble_gap_connect_reattempt_ctxt {
|
||||
/* ACL that owns these parameters; NONE while initiating. */
|
||||
uint16_t conn_handle;
|
||||
bool conn_handle_valid;
|
||||
uint8_t own_addr_type;
|
||||
ble_addr_t peer_addr;
|
||||
uint8_t peer_addr_present:1;
|
||||
@@ -240,6 +258,9 @@ struct ble_gap_master_state {
|
||||
/* Effective Initiator_Filter_Policy sent to the controller. */
|
||||
uint8_t filt_policy;
|
||||
#endif
|
||||
#if NIMBLE_BLE_CONNECT && MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)
|
||||
uint8_t reattempt_count;
|
||||
#endif
|
||||
#if MYNEWT_VAL(BLE_PERIODIC_ADV_WITH_RESPONSES)
|
||||
uint8_t synchronized:1;
|
||||
uint8_t timeout_cancel_pending:1;
|
||||
@@ -1697,6 +1718,9 @@ ble_gap_master_reset_state(void)
|
||||
ble_gap_master.op = BLE_GAP_OP_NULL;
|
||||
ble_gap_master.exp_set = 0;
|
||||
ble_gap_master.conn.cancel = 0;
|
||||
#if NIMBLE_BLE_CONNECT && MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)
|
||||
ble_gap_master.conn.reattempt_count = 0;
|
||||
#endif
|
||||
#if MYNEWT_VAL(BLE_PERIODIC_ADV_WITH_RESPONSES)
|
||||
ble_gap_master.conn.synchronized = 0;
|
||||
ble_gap_master.conn.timeout_cancel_pending = 0;
|
||||
@@ -1998,20 +2022,36 @@ ble_gap_update_notify(uint16_t conn_handle, int status);
|
||||
|
||||
#if MYNEWT_VAL(BLE_ROLE_CENTRAL) || MYNEWT_VAL(BLE_ROLE_OBSERVER)
|
||||
int
|
||||
ble_gap_master_connect_reattempt(uint16_t conn_handle)
|
||||
ble_gap_master_connect_reattempt(uint16_t conn_handle, uint8_t reattempt_count)
|
||||
{
|
||||
struct ble_gap_snapshot snap;
|
||||
struct ble_gap_conn_desc conn;
|
||||
struct ble_gap_update_entry *entry;
|
||||
struct ble_gap_event event;
|
||||
struct ble_gap_connect_reattempt_ctxt retry;
|
||||
struct ble_hs_conn *hs_conn;
|
||||
int rc = BLE_HS_EUNKNOWN;
|
||||
|
||||
snap.desc = &conn;
|
||||
rc = ble_gap_find_snapshot(conn_handle, &snap);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
ble_hs_lock();
|
||||
hs_conn = ble_hs_conn_find(conn_handle);
|
||||
if (hs_conn == NULL) {
|
||||
ble_hs_unlock();
|
||||
return BLE_HS_ENOTCONN;
|
||||
}
|
||||
ble_gap_conn_to_snapshot(hs_conn, &snap);
|
||||
if (!ble_conn_reattempt.conn_handle_valid ||
|
||||
ble_conn_reattempt.conn_handle != conn_handle) {
|
||||
/* Another procedure has replaced the shared parameter cache. */
|
||||
ble_hs_unlock();
|
||||
return BLE_HS_EBUSY;
|
||||
}
|
||||
retry = ble_conn_reattempt;
|
||||
ble_hs_unlock();
|
||||
|
||||
if (conn.role == BLE_GAP_ROLE_MASTER) {
|
||||
/* Snapshot first: application callbacks may initiate another link. */
|
||||
ble_gap_reattempt_count(conn_handle, reattempt_count);
|
||||
/* If there was a connection update in progress, indicate to the
|
||||
* application that it did not complete.
|
||||
*/
|
||||
@@ -2031,6 +2071,9 @@ ble_gap_master_connect_reattempt(uint16_t conn_handle)
|
||||
#endif
|
||||
#if MYNEWT_VAL(BLE_GATTC)
|
||||
ble_gattc_connection_broken(conn_handle);
|
||||
#endif
|
||||
#if MYNEWT_VAL(BLE_GATT_CACHING)
|
||||
ble_gattc_cache_conn_broken(conn_handle);
|
||||
#endif
|
||||
ble_hs_flow_connection_broken(conn_handle);;
|
||||
|
||||
@@ -2047,33 +2090,23 @@ ble_gap_master_connect_reattempt(uint16_t conn_handle)
|
||||
#endif // MYNEWT_VAL(OPTIMIZE_MULTI_CONN)
|
||||
|
||||
#if MYNEWT_VAL(BLE_EXT_ADV)
|
||||
rc = ble_gap_ext_connect_internal(retry.own_addr_type,
|
||||
retry.peer_addr_present ? &retry.peer_addr : NULL,
|
||||
retry.duration_ms, retry.phy_mask,
|
||||
retry.phy_mask & BLE_GAP_LE_PHY_1M_MASK ? &retry.conn_params_1m : NULL,
|
||||
retry.phy_mask & BLE_GAP_LE_PHY_2M_MASK ? &retry.conn_params_2m : NULL,
|
||||
retry.phy_mask & BLE_GAP_LE_PHY_CODED_MASK ? &retry.conn_params_coded : NULL,
|
||||
#if MYNEWT_VAL(BLE_DBAF)
|
||||
rc = ble_gap_ext_connect_dbaf(ble_conn_reattempt.own_addr_type,
|
||||
(ble_conn_reattempt.peer_addr_present == 1 ? &ble_conn_reattempt.peer_addr : NULL),
|
||||
ble_conn_reattempt.duration_ms, ble_conn_reattempt.phy_mask,
|
||||
ble_conn_reattempt.phy_mask & BLE_GAP_LE_PHY_1M_MASK ? &ble_conn_reattempt.conn_params_1m : NULL,
|
||||
ble_conn_reattempt.phy_mask & BLE_GAP_LE_PHY_2M_MASK ? &ble_conn_reattempt.conn_params_2m : NULL,
|
||||
ble_conn_reattempt.phy_mask & BLE_GAP_LE_PHY_CODED_MASK ? &ble_conn_reattempt.conn_params_coded : NULL,
|
||||
ble_conn_reattempt.dbaf_filter_policy,
|
||||
ble_conn_reattempt.cb,
|
||||
ble_conn_reattempt.cb_arg);
|
||||
retry.dbaf_filter_policy,
|
||||
#else
|
||||
rc = ble_gap_ext_connect(ble_conn_reattempt.own_addr_type,
|
||||
(ble_conn_reattempt.peer_addr_present == 1 ? &ble_conn_reattempt.peer_addr : NULL),
|
||||
ble_conn_reattempt.duration_ms, ble_conn_reattempt.phy_mask,
|
||||
ble_conn_reattempt.phy_mask & BLE_GAP_LE_PHY_1M_MASK ? &ble_conn_reattempt.conn_params_1m : NULL,
|
||||
ble_conn_reattempt.phy_mask & BLE_GAP_LE_PHY_2M_MASK ? &ble_conn_reattempt.conn_params_2m : NULL,
|
||||
ble_conn_reattempt.phy_mask & BLE_GAP_LE_PHY_CODED_MASK ? &ble_conn_reattempt.conn_params_coded : NULL,
|
||||
ble_conn_reattempt.cb,
|
||||
ble_conn_reattempt.cb_arg);
|
||||
0,
|
||||
#endif
|
||||
snap.cb, snap.cb_arg, reattempt_count);
|
||||
#else
|
||||
rc = ble_gap_connect(ble_conn_reattempt.own_addr_type,
|
||||
(ble_conn_reattempt.peer_addr_present == 1 ? &ble_conn_reattempt.peer_addr : NULL),
|
||||
ble_conn_reattempt.duration_ms,
|
||||
&ble_conn_reattempt.conn_params_1m,
|
||||
ble_conn_reattempt.cb,
|
||||
ble_conn_reattempt.cb_arg);
|
||||
rc = ble_gap_connect_internal(retry.own_addr_type,
|
||||
retry.peer_addr_present ? &retry.peer_addr : NULL,
|
||||
retry.duration_ms, &retry.conn_params_1m,
|
||||
snap.cb, snap.cb_arg, reattempt_count);
|
||||
#endif // #if MYNEWT_VAL(BLE_EXT_ADV)
|
||||
|
||||
#if MYNEWT_VAL(OPTIMIZE_MULTI_CONN)
|
||||
@@ -2083,6 +2116,16 @@ ble_gap_master_connect_reattempt(uint16_t conn_handle)
|
||||
#endif // MYNEWT_VAL(OPTIMIZE_MULTI_CONN)
|
||||
|
||||
if (rc != 0) {
|
||||
/* The ACL was deleted above: the normal disconnect path can no
|
||||
* longer find its callback. Deliver exactly one terminal event.
|
||||
*/
|
||||
memset(&event, 0, sizeof(event));
|
||||
event.type = BLE_GAP_EVENT_DISCONNECT;
|
||||
event.disconnect.conn = conn;
|
||||
event.disconnect.reason = rc;
|
||||
ble_gap_event_listener_call(&event);
|
||||
ble_gap_call_event_cb(&event, snap.cb, snap.cb_arg);
|
||||
STATS_INC(ble_gap_stats, disconnect);
|
||||
return rc;
|
||||
}
|
||||
} else {
|
||||
@@ -4455,6 +4498,16 @@ ble_gap_rx_conn_complete(struct ble_gap_conn_complete *evt, uint8_t instance)
|
||||
conn->bhc_cb_arg = ble_gap_master.cb_arg;
|
||||
conn->bhc_flags |= BLE_HS_CONN_F_MASTER;
|
||||
conn->bhc_our_addr_type = ble_gap_master.conn.our_addr_type;
|
||||
#if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)
|
||||
conn->bhc_reattempt_count = ble_gap_master.conn.reattempt_count;
|
||||
#if MYNEWT_VAL(BLE_PERIODIC_ADV_WITH_RESPONSES)
|
||||
if (!ble_gap_master.conn.synchronized)
|
||||
#endif
|
||||
{
|
||||
ble_conn_reattempt.conn_handle = evt->connection_handle;
|
||||
ble_conn_reattempt.conn_handle_valid = true;
|
||||
}
|
||||
#endif
|
||||
ble_gap_master_reset_state();
|
||||
} else {
|
||||
#if MYNEWT_VAL(BLE_PERIODIC_ADV_WITH_RESPONSES)
|
||||
@@ -9971,6 +10024,11 @@ ble_gap_connect_with_synced(uint8_t own_addr_type, uint8_t advertising_handle,
|
||||
#endif
|
||||
ble_gap_master.conn.our_addr_type = own_addr_type;
|
||||
ble_gap_master.conn.synchronized = 1;
|
||||
#if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT) && NIMBLE_BLE_CONNECT
|
||||
/* Synchronized create does not populate the ordinary retry parameters. */
|
||||
ble_conn_reattempt.conn_handle_valid = false;
|
||||
ble_gap_master.conn.reattempt_count = 0;
|
||||
#endif
|
||||
if (peer_addr != NULL) {
|
||||
ble_gap_master.conn.peer_addr = *peer_addr;
|
||||
} else {
|
||||
@@ -10287,25 +10345,17 @@ ble_gap_ext_conn_create_tx(
|
||||
* connected;
|
||||
* Other nonzero on error.
|
||||
*/
|
||||
#if MYNEWT_VAL(BLE_DBAF)
|
||||
static int
|
||||
ble_gap_ext_connect_policy(uint8_t own_addr_type, const ble_addr_t *peer_addr,
|
||||
ble_gap_ext_connect_internal(uint8_t own_addr_type, const ble_addr_t *peer_addr,
|
||||
int32_t duration_ms, uint8_t phy_mask,
|
||||
const struct ble_gap_conn_params *phy_1m_conn_params,
|
||||
const struct ble_gap_conn_params *phy_2m_conn_params,
|
||||
const struct ble_gap_conn_params *phy_coded_conn_params,
|
||||
uint8_t dbaf_filter_policy,
|
||||
ble_gap_event_fn *cb, void *cb_arg)
|
||||
#else
|
||||
int
|
||||
ble_gap_ext_connect(uint8_t own_addr_type, const ble_addr_t *peer_addr,
|
||||
int32_t duration_ms, uint8_t phy_mask,
|
||||
const struct ble_gap_conn_params *phy_1m_conn_params,
|
||||
const struct ble_gap_conn_params *phy_2m_conn_params,
|
||||
const struct ble_gap_conn_params *phy_coded_conn_params,
|
||||
ble_gap_event_fn *cb, void *cb_arg)
|
||||
#endif
|
||||
ble_gap_event_fn *cb, void *cb_arg, uint8_t reattempt_count)
|
||||
{
|
||||
(void)reattempt_count;
|
||||
(void)dbaf_filter_policy;
|
||||
#if MYNEWT_VAL(BLE_ROLE_CENTRAL)
|
||||
ble_npl_time_t duration_ticks;
|
||||
#if MYNEWT_VAL(BLE_DBAF)
|
||||
@@ -10449,6 +10499,8 @@ ble_gap_ext_connect(uint8_t own_addr_type, const ble_addr_t *peer_addr,
|
||||
|
||||
#if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT) && NIMBLE_BLE_CONNECT
|
||||
ble_conn_reattempt.own_addr_type = own_addr_type;
|
||||
ble_conn_reattempt.conn_handle = BLE_HS_CONN_HANDLE_NONE;
|
||||
ble_conn_reattempt.conn_handle_valid = false;
|
||||
|
||||
if (peer_addr != NULL) {
|
||||
ble_conn_reattempt.peer_addr_present = 1;
|
||||
@@ -10463,6 +10515,7 @@ ble_gap_ext_connect(uint8_t own_addr_type, const ble_addr_t *peer_addr,
|
||||
#if MYNEWT_VAL(BLE_DBAF)
|
||||
ble_conn_reattempt.dbaf_filter_policy = dbaf_filter_policy;
|
||||
#endif
|
||||
ble_gap_master.conn.reattempt_count = reattempt_count;
|
||||
|
||||
if (phy_mask & BLE_GAP_LE_PHY_1M_MASK) {
|
||||
memcpy(&ble_conn_reattempt.conn_params_1m,
|
||||
@@ -10521,7 +10574,6 @@ done:
|
||||
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(BLE_DBAF)
|
||||
int
|
||||
ble_gap_ext_connect(uint8_t own_addr_type, const ble_addr_t *peer_addr,
|
||||
int32_t duration_ms, uint8_t phy_mask,
|
||||
@@ -10530,12 +10582,13 @@ ble_gap_ext_connect(uint8_t own_addr_type, const ble_addr_t *peer_addr,
|
||||
const struct ble_gap_conn_params *phy_coded_conn_params,
|
||||
ble_gap_event_fn *cb, void *cb_arg)
|
||||
{
|
||||
return ble_gap_ext_connect_policy(own_addr_type, peer_addr, duration_ms,
|
||||
return ble_gap_ext_connect_internal(own_addr_type, peer_addr, duration_ms,
|
||||
phy_mask, phy_1m_conn_params,
|
||||
phy_2m_conn_params, phy_coded_conn_params,
|
||||
0, cb, cb_arg);
|
||||
0, cb, cb_arg, 0);
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(BLE_DBAF)
|
||||
int
|
||||
ble_gap_ext_connect_dbaf(uint8_t own_addr_type, const ble_addr_t *peer_addr,
|
||||
int32_t duration_ms, uint8_t phy_mask,
|
||||
@@ -10545,10 +10598,10 @@ ble_gap_ext_connect_dbaf(uint8_t own_addr_type, const ble_addr_t *peer_addr,
|
||||
uint8_t filter_policy,
|
||||
ble_gap_event_fn *cb, void *cb_arg)
|
||||
{
|
||||
return ble_gap_ext_connect_policy(own_addr_type, peer_addr, duration_ms,
|
||||
return ble_gap_ext_connect_internal(own_addr_type, peer_addr, duration_ms,
|
||||
phy_mask, phy_1m_conn_params,
|
||||
phy_2m_conn_params, phy_coded_conn_params,
|
||||
filter_policy, cb, cb_arg);
|
||||
filter_policy, cb, cb_arg, 0);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -10559,11 +10612,22 @@ ble_gap_connect(uint8_t own_addr_type, const ble_addr_t *peer_addr,
|
||||
const struct ble_gap_conn_params *conn_params,
|
||||
ble_gap_event_fn *cb, void *cb_arg)
|
||||
{
|
||||
return ble_gap_connect_internal(own_addr_type, peer_addr, duration_ms,
|
||||
conn_params, cb, cb_arg, 0);
|
||||
}
|
||||
|
||||
static int
|
||||
ble_gap_connect_internal(uint8_t own_addr_type, const ble_addr_t *peer_addr,
|
||||
int32_t duration_ms,
|
||||
const struct ble_gap_conn_params *conn_params,
|
||||
ble_gap_event_fn *cb, void *cb_arg, uint8_t reattempt_count)
|
||||
{
|
||||
(void)reattempt_count;
|
||||
#if MYNEWT_VAL(BLE_ROLE_CENTRAL)
|
||||
#if MYNEWT_VAL(BLE_EXT_ADV)
|
||||
return ble_gap_ext_connect(own_addr_type, peer_addr, duration_ms,
|
||||
return ble_gap_ext_connect_internal(own_addr_type, peer_addr, duration_ms,
|
||||
BLE_GAP_LE_PHY_1M_MASK,
|
||||
conn_params, NULL, NULL, cb, cb_arg);
|
||||
conn_params, NULL, NULL, 0, cb, cb_arg, reattempt_count);
|
||||
#else
|
||||
uint32_t duration_ticks;
|
||||
ble_addr_t bhc_peer_addr;
|
||||
@@ -10705,6 +10769,9 @@ ble_gap_connect(uint8_t own_addr_type, const ble_addr_t *peer_addr,
|
||||
|
||||
#if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT) && NIMBLE_BLE_CONNECT
|
||||
ble_conn_reattempt.own_addr_type = own_addr_type;
|
||||
ble_conn_reattempt.conn_handle = BLE_HS_CONN_HANDLE_NONE;
|
||||
ble_conn_reattempt.conn_handle_valid = false;
|
||||
ble_gap_master.conn.reattempt_count = reattempt_count;
|
||||
if (peer_addr != NULL) {
|
||||
ble_conn_reattempt.peer_addr_present = 1;
|
||||
/* Store the original identity address, not the resolved RPA, so that
|
||||
|
||||
@@ -211,6 +211,9 @@ int ble_gap_dbg_update_active(uint16_t conn_handle);
|
||||
|
||||
#if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)
|
||||
void ble_gap_reattempt_count(uint16_t conn_handle, uint8_t count);
|
||||
#if NIMBLE_BLE_CONNECT && (MYNEWT_VAL(BLE_ROLE_CENTRAL) || MYNEWT_VAL(BLE_ROLE_OBSERVER))
|
||||
int ble_gap_master_connect_reattempt(uint16_t conn_handle, uint8_t reattempt_count);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void ble_gap_rx_data_len_change(const struct ble_hci_ev_le_subev_data_len_chg *ev);
|
||||
|
||||
@@ -83,6 +83,9 @@ struct ble_hs_conn {
|
||||
SLIST_ENTRY(ble_hs_conn) bhc_next;
|
||||
uint16_t bhc_handle;
|
||||
uint8_t bhc_our_addr_type;
|
||||
#if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)
|
||||
uint8_t bhc_reattempt_count;
|
||||
#endif
|
||||
uint8_t slave_conn : 1;
|
||||
#if MYNEWT_VAL(BLE_DEFER_CONN_EVENTS)
|
||||
uint8_t bhc_connect_delivered : 1;
|
||||
|
||||
@@ -35,16 +35,6 @@
|
||||
|
||||
#if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)
|
||||
|
||||
#if !MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
struct ble_gap_reattempt_ctxt {
|
||||
ble_addr_t peer_addr;
|
||||
uint8_t count;
|
||||
}reattempt_conn;
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(BLE_ROLE_CENTRAL) || MYNEWT_VAL(BLE_ROLE_OBSERVER)
|
||||
extern int ble_gap_master_connect_reattempt(uint16_t conn_handle);
|
||||
#endif
|
||||
#if MYNEWT_VAL(BLE_ROLE_PERIPHERAL) || MYNEWT_VAL(BLE_ROLE_BROADCASTER)
|
||||
extern int ble_gap_slave_adv_reattempt(void);
|
||||
#endif
|
||||
@@ -56,8 +46,7 @@ extern int slave_conn[MYNEWT_VAL(BLE_MAX_CONNECTIONS) + 1];
|
||||
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
|
||||
#if (NIMBLE_BLE_CONNECT && MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)) || \
|
||||
(NIMBLE_BLE_CONNECT && MYNEWT_VAL(BLE_EXT_ADV) && !MYNEWT_VAL(BLE_PERIODIC_ADV_WITH_RESPONSES)) || \
|
||||
#if (NIMBLE_BLE_CONNECT && MYNEWT_VAL(BLE_EXT_ADV) && !MYNEWT_VAL(BLE_PERIODIC_ADV_WITH_RESPONSES)) || \
|
||||
(NIMBLE_BLE_CONNECT && MYNEWT_VAL(BLE_EXT_ADV)) || \
|
||||
MYNEWT_VAL(BLE_QUEUE_CONG_CHECK) || \
|
||||
(MYNEWT_VAL(BLE_EXT_ADV) && ((NIMBLE_BLE_CONNECT && (MYNEWT_VAL(BLE_ROLE_PERIPHERAL) || MYNEWT_VAL(BLE_ROLE_BROADCASTER))) || \
|
||||
@@ -65,13 +54,6 @@ extern int slave_conn[MYNEWT_VAL(BLE_MAX_CONNECTIONS) + 1];
|
||||
|
||||
typedef struct {
|
||||
|
||||
#if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)
|
||||
struct ble_gap_reattempt_ctxt {
|
||||
ble_addr_t peer_addr;
|
||||
uint8_t count;
|
||||
} reattempt_ctx;
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(BLE_QUEUE_CONG_CHECK)
|
||||
struct ble_npl_mutex list_lock;
|
||||
uint16_t adv_list_count;
|
||||
@@ -87,7 +69,6 @@ typedef struct {
|
||||
|
||||
static ble_hci_ctx_t *ble_hci_ctx;
|
||||
|
||||
#define reattempt_conn (ble_hci_ctx->reattempt_ctx)
|
||||
#if MYNEWT_VAL(BLE_QUEUE_CONG_CHECK)
|
||||
#define adv_list_lock (ble_hci_ctx->list_lock)
|
||||
#define ble_adv_list_count (ble_hci_ctx->adv_list_count)
|
||||
@@ -386,8 +367,7 @@ static ble_hs_hci_evt_le_fn * const ble_hs_hci_evt_le_dispatch[] = {
|
||||
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
|
||||
#if (NIMBLE_BLE_CONNECT && MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)) || \
|
||||
(NIMBLE_BLE_CONNECT && MYNEWT_VAL(BLE_EXT_ADV) && !MYNEWT_VAL(BLE_PERIODIC_ADV_WITH_RESPONSES)) || \
|
||||
#if (NIMBLE_BLE_CONNECT && MYNEWT_VAL(BLE_EXT_ADV) && !MYNEWT_VAL(BLE_PERIODIC_ADV_WITH_RESPONSES)) || \
|
||||
(NIMBLE_BLE_CONNECT && MYNEWT_VAL(BLE_EXT_ADV)) || \
|
||||
MYNEWT_VAL(BLE_QUEUE_CONG_CHECK) || \
|
||||
(MYNEWT_VAL(BLE_EXT_ADV) && (MYNEWT_VAL(BLE_ROLE_PERIPHERAL) || MYNEWT_VAL(BLE_ROLE_BROADCASTER)))
|
||||
@@ -504,6 +484,7 @@ ble_hs_hci_evt_disconn_complete(uint8_t event_code, const void *data,
|
||||
const struct ble_hs_conn *conn;
|
||||
#if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)
|
||||
uint32_t conn_flags = 0;
|
||||
uint8_t reattempt_count = 0;
|
||||
int conn_slave = 0;
|
||||
bool conn_found = false;
|
||||
#endif
|
||||
@@ -523,6 +504,7 @@ ble_hs_hci_evt_disconn_complete(uint8_t event_code, const void *data,
|
||||
ble_hs_hci_add_avail_pkts(conn->bhc_outstanding_pkts);
|
||||
#if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)
|
||||
conn_flags = conn->bhc_flags;
|
||||
reattempt_count = conn->bhc_reattempt_count;
|
||||
conn_slave = conn->slave_conn;
|
||||
conn_found = true;
|
||||
#endif
|
||||
@@ -530,7 +512,7 @@ ble_hs_hci_evt_disconn_complete(uint8_t event_code, const void *data,
|
||||
ble_hs_unlock();
|
||||
|
||||
#if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)
|
||||
if (conn_found) {
|
||||
if (conn_found && ev->status == 0) {
|
||||
int rc;
|
||||
uint16_t conn_handle = le16toh(ev->conn_handle);
|
||||
|
||||
@@ -543,32 +525,20 @@ ble_hs_hci_evt_disconn_complete(uint8_t event_code, const void *data,
|
||||
* b. Connect event was not posted and 0x8 was received
|
||||
* Restart advertising in above reasons for slave.
|
||||
*/
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
if (ble_hs_hci_ensure_ctx()) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
goto skip_reattempt;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((conn_flags & BLE_HS_CONN_F_MASTER) && \
|
||||
(ev->reason == BLE_ERR_CONN_ESTABLISHMENT)) { // master
|
||||
if (reattempt_conn.count < MAX_REATTEMPT_ALLOWED) {
|
||||
if (reattempt_count < MAX_REATTEMPT_ALLOWED) {
|
||||
/* Go for connection */
|
||||
BLE_HS_LOG(INFO, "Reattempt connection; reason = 0x%x, status = %d,"
|
||||
"reattempt count = %d ", ev->reason, ev->status,
|
||||
reattempt_conn.count);
|
||||
reattempt_conn.count += 1;
|
||||
|
||||
ble_gap_reattempt_count(conn_handle, reattempt_conn.count);
|
||||
reattempt_count);
|
||||
reattempt_count += 1;
|
||||
#if MYNEWT_VAL(BLE_ROLE_CENTRAL) || MYNEWT_VAL(BLE_ROLE_OBSERVER)
|
||||
rc = ble_gap_master_connect_reattempt(conn_handle);
|
||||
rc = ble_gap_master_connect_reattempt(conn_handle, reattempt_count);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(INFO, "Master reconnect attempt failed; rc = %d", rc);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
/* Exhausted attempts */
|
||||
memset(&reattempt_conn, 0x0, sizeof (struct ble_gap_reattempt_ctxt));
|
||||
}
|
||||
}
|
||||
#if MYNEWT_VAL(BT_NIMBLE_MEM_OPTIMIZATION)
|
||||
@@ -606,15 +576,7 @@ ble_hs_hci_evt_disconn_complete(uint8_t event_code, const void *data,
|
||||
|
||||
return 0; // Restart advertising, so don't post disconnect event
|
||||
#endif
|
||||
} else {
|
||||
/* Normal disconnect. Reset the structure */
|
||||
memset(&reattempt_conn, 0x0, sizeof (struct ble_gap_reattempt_ctxt));
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
skip_reattempt:
|
||||
;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user