mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-09-14 21:20:06 +00:00
Added change to send event to user about reattempt connection attempt
count
This commit is contained in:
committed by
Abhinav Kudnar
parent
88335c4b65
commit
a6075627e8
@@ -157,6 +157,7 @@ struct hci_conn_update;
|
||||
#define BLE_GAP_EVENT_SUBRATE_CHANGE 28
|
||||
#define BLE_GAP_EVENT_VS_HCI 29
|
||||
#define BLE_GAP_EVENT_BIGINFO_REPORT 30
|
||||
#define BLE_GAP_EVENT_REATTEMPT_COUNT 31
|
||||
|
||||
/*** Reason codes for the subscribe GAP event. */
|
||||
|
||||
@@ -1152,10 +1153,26 @@ struct ble_gap_event {
|
||||
uint8_t length;
|
||||
} vs_hci;
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)
|
||||
/**
|
||||
* Represents a event mentioning connection reattempt
|
||||
* count
|
||||
*
|
||||
* Valid for the following event types:
|
||||
* o BLE_GAP_EVENT_REATTEMPT_COUNT
|
||||
*/
|
||||
struct {
|
||||
/* Connection handle */
|
||||
uint16_t conn_handle;
|
||||
|
||||
/* Reattempt connection attempt count */
|
||||
uint8_t count;
|
||||
} reattempt_cnt;
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
#if MYNEWT_VAL(OPTIMIZE_MULTI_CONN)
|
||||
/** @brief multiple Connection parameters */
|
||||
struct ble_gap_multi_conn_params {
|
||||
|
||||
@@ -117,7 +117,7 @@ static const struct ble_gap_conn_params ble_gap_conn_params_dflt = {
|
||||
};
|
||||
#endif
|
||||
|
||||
#if NIMBLE_BLE_CONNECT && CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT
|
||||
#if NIMBLE_BLE_CONNECT && MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)
|
||||
struct ble_gap_connect_reattempt_ctxt {
|
||||
uint8_t own_addr_type;
|
||||
ble_addr_t peer_addr;
|
||||
@@ -1018,7 +1018,7 @@ ble_gap_master_connect_cancelled(void)
|
||||
}
|
||||
}
|
||||
|
||||
#if CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT
|
||||
#if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)
|
||||
static void
|
||||
ble_gap_update_notify(uint16_t conn_handle, int status);
|
||||
|
||||
@@ -1102,6 +1102,19 @@ ble_gap_master_connect_reattempt(uint16_t conn_handle)
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void ble_gap_reattempt_count(uint16_t conn_handle, uint8_t count)
|
||||
{
|
||||
struct ble_gap_event event;
|
||||
uint16_t handle = conn_handle;
|
||||
|
||||
memset(&event, 0, sizeof event);
|
||||
event.type = BLE_GAP_EVENT_REATTEMPT_COUNT;
|
||||
event.reattempt_cnt.count = count;
|
||||
event.reattempt_cnt.conn_handle = le16toh(conn_handle);
|
||||
|
||||
ble_gap_call_conn_event_cb(&event, handle);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -5720,7 +5733,7 @@ ble_gap_connect(uint8_t own_addr_type, const ble_addr_t *peer_addr,
|
||||
|
||||
ble_gap_master.op = BLE_GAP_OP_M_CONN;
|
||||
|
||||
#if CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT
|
||||
#if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)
|
||||
/* ble_gap_connect_reattempt save the connection parameters */
|
||||
if ((cb_arg != NULL) && conn_cookie_enabled) {
|
||||
struct ble_gap_conn_desc *conn_desc = cb_arg;
|
||||
|
||||
@@ -159,6 +159,10 @@ void ble_gap_deinit(void);
|
||||
int ble_gap_dbg_update_active(uint16_t conn_handle);
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)
|
||||
void ble_gap_reattempt_count(uint16_t conn_handle, uint8_t count);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "ble_hs_resolv_priv.h"
|
||||
#include "esp_nimble_mem.h"
|
||||
|
||||
#if CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT
|
||||
#if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)
|
||||
struct ble_gap_reattempt_ctxt {
|
||||
ble_addr_t peer_addr;
|
||||
uint8_t count;
|
||||
@@ -197,7 +197,7 @@ ble_hs_hci_evt_le_dispatch_find(uint8_t event_code)
|
||||
return ble_hs_hci_evt_le_dispatch[event_code];
|
||||
}
|
||||
|
||||
#if CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT
|
||||
#if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)
|
||||
static int
|
||||
ble_gap_find_reattempt_conn_idx(const struct ble_hs_conn *conn)
|
||||
{
|
||||
@@ -232,9 +232,10 @@ ble_hs_hci_evt_disconn_complete(uint8_t event_code, const void *data,
|
||||
}
|
||||
ble_hs_unlock();
|
||||
|
||||
#if CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT
|
||||
#if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT)
|
||||
if (ev->reason == BLE_ERR_CONN_ESTABLISHMENT) {
|
||||
int rc, i, idx;
|
||||
uint16_t handle;
|
||||
|
||||
idx = ble_gap_find_reattempt_conn_idx(conn);
|
||||
|
||||
@@ -271,6 +272,10 @@ ble_hs_hci_evt_disconn_complete(uint8_t event_code, const void *data,
|
||||
|
||||
reattempt_conn[idx].peer_addr.type = conn->bhc_peer_addr.type;
|
||||
|
||||
handle = le16toh(ev->conn_handle);
|
||||
/* Post event to interested application */
|
||||
ble_gap_reattempt_count(handle, reattempt_conn[idx].count);
|
||||
|
||||
rc = ble_gap_master_connect_reattempt(ev->conn_handle);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(DEBUG, "Master reconnect attempt failed; rc = %d", rc);
|
||||
@@ -279,8 +284,8 @@ ble_hs_hci_evt_disconn_complete(uint8_t event_code, const void *data,
|
||||
memset(&reattempt_conn[idx].peer_addr, 0x0, BLE_DEV_ADDR_LEN);
|
||||
reattempt_conn[idx].count = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
/* Disconnect completed with some other reason than
|
||||
* BLE_ERR_CONN_ESTABLISHMENT, reset the corresponding reattempt count
|
||||
* */
|
||||
|
||||
Reference in New Issue
Block a user