Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 13 additions & 36 deletions src/nimble/nimble/host/src/ble_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ static uint8_t pawr_adv_handle;
static uint16_t pawr_sync_handle;
#endif

int slave_conn[MYNEWT_VAL(BLE_MAX_CONNECTIONS) + 1];
static void ble_gap_update_entry_free(struct ble_gap_update_entry *entry);

#if NIMBLE_BLE_CONNECT
Expand Down Expand Up @@ -1557,8 +1556,6 @@ ble_gap_conn_broken(uint16_t conn_handle, int reason)
struct ble_gap_update_entry *entry;
struct ble_gap_snapshot snap;
struct ble_gap_event event;
struct ble_hs_conn *conn;
bool send = 1;
int rc;

memset(&event, 0, sizeof event);
Expand Down Expand Up @@ -1595,19 +1592,6 @@ ble_gap_conn_broken(uint16_t conn_handle, int reason)
#endif
ble_hs_flow_connection_broken(conn_handle);;

ble_hs_lock();
conn = ble_hs_conn_find(conn_handle);
ble_hs_unlock();

// Send disconnect event in slave role if connect was sent
if ((conn != NULL) && !(conn->bhc_flags & BLE_HS_CONN_F_MASTER)) {
if (slave_conn[conn_handle]) {
slave_conn[conn_handle] = 0;
} else {
send = 0;
}
}

ble_hs_atomic_conn_delete(conn_handle);

g_max_tx_time[conn_handle] = 0;
Expand All @@ -1618,10 +1602,8 @@ ble_gap_conn_broken(uint16_t conn_handle, int reason)
event.type = BLE_GAP_EVENT_DISCONNECT;
event.disconnect.reason = reason;

if (send) {
ble_gap_event_listener_call(&event);
ble_gap_call_event_cb(&event, snap.cb, snap.cb_arg);
}
ble_gap_event_listener_call(&event);
ble_gap_call_event_cb(&event, snap.cb, snap.cb_arg);

STATS_INC(ble_gap_stats, disconnect);
#endif
Expand Down Expand Up @@ -2770,9 +2752,11 @@ ble_gap_rx_conn_complete(struct ble_gap_conn_complete *evt, uint8_t instance)
pawr_adv_handle = evt->adv_handle;
#endif


if (evt->role == BLE_HCI_LE_CONN_COMPLETE_ROLE_SLAVE) {
ble_gap_event_connect_call(evt->connection_handle, evt->status);
ble_gap_rd_rem_ver_tx(evt->connection_handle);
} else {
} else { // master
ble_gap_rd_rem_sup_feat_tx(evt->connection_handle);
}

Expand Down Expand Up @@ -2832,17 +2816,10 @@ ble_gap_rx_rd_rem_sup_feat_complete(const struct ble_hci_ev_le_subev_rd_rem_used

ble_hs_unlock();

if ((conn != NULL) && (conn->bhc_flags & BLE_HS_CONN_F_MASTER)) {
if ((conn != NULL) && ev->status == 0) {
conn->supported_feat = get_le32(ev->features);
ble_gap_rd_rem_ver_tx(ev->conn_handle);
} else {
if ((conn != NULL) && (ev->status == 0)) {
conn->supported_feat = get_le32(ev->features);
}

if (conn != NULL) {
ble_gap_event_connect_call(ev->conn_handle, ev->status);
slave_conn[ev->conn_handle] = 1;
if (conn->bhc_flags & BLE_HS_CONN_F_MASTER) {
ble_gap_rd_rem_ver_tx(ev->conn_handle);
}
}
#endif
Expand All @@ -2864,11 +2841,11 @@ ble_gap_rx_rd_rem_ver_info_complete(const struct ble_hci_ev_rd_rem_ver_info_cmp
conn->bhc_rd_rem_ver_params.manufacturer = ev->manufacturer;
conn->bhc_rd_rem_ver_params.subversion = ev->subversion;

if ((conn != NULL) && !(conn->bhc_flags & BLE_HS_CONN_F_MASTER)) {
ble_gap_rd_rem_sup_feat_tx(ev->conn_handle);
} else {
if ((conn != NULL) && (ev->status == 0)) {
ble_gap_event_connect_call(ev->conn_handle, ev->status);
if ((conn != NULL)) {
if (conn->bhc_flags & BLE_HS_CONN_F_MASTER) {
ble_gap_event_connect_call(ev->conn_handle, 0);
} else {
ble_gap_rd_rem_sup_feat_tx(ev->conn_handle);
}
}
#endif
Expand Down
8 changes: 3 additions & 5 deletions src/nimble/nimble/host/src/ble_hs_hci_evt.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ struct ble_gap_reattempt_ctxt {

extern int ble_gap_master_connect_reattempt(uint16_t conn_handle);
extern int ble_gap_slave_adv_reattempt(void);
extern int slave_conn[MYNEWT_VAL(BLE_MAX_CONNECTIONS) + 1];
#endif

#if MYNEWT_VAL(BLE_QUEUE_CONG_CHECK)
Expand Down Expand Up @@ -285,17 +284,16 @@ ble_hs_hci_evt_disconn_complete(uint8_t event_code, const void *data,
memset(&reattempt_conn, 0x0, sizeof (struct ble_gap_reattempt_ctxt));
}
}
else if (!(conn->bhc_flags & BLE_HS_CONN_F_MASTER) && \
((ev->reason == BLE_ERR_CONN_ESTABLISHMENT) || \
(!slave_conn[ev->conn_handle] && ev->reason == BLE_ERR_CONN_SPVN_TMO))) { //slave
else if (!(conn->bhc_flags & BLE_HS_CONN_F_MASTER) &&
ev->reason == BLE_ERR_CONN_SPVN_TMO) { //slave

BLE_HS_LOG(INFO, "Reattempt advertising; reason: 0x%x, status = %x",
ev->reason, ev->status);
ble_l2cap_sig_conn_broken(ev->conn_handle, BLE_ERR_CONN_ESTABLISHMENT);
ble_sm_connection_broken(ev->conn_handle);
ble_gatts_connection_broken(ev->conn_handle);
ble_gattc_connection_broken(ev->conn_handle);
ble_hs_flow_connection_broken(ev->conn_handle);;
ble_hs_flow_connection_broken(ev->conn_handle);
#if MYNEWT_VAL(BLE_GATT_CACHING)
ble_gattc_cache_conn_broken(ev->conn_handle);
#endif
Expand Down