mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-09-16 22:19:54 +00:00
Stack support for Connection subrating
This commit is contained in:
@@ -135,6 +135,7 @@ struct hci_conn_update;
|
||||
#define BLE_GAP_EVENT_PERIODIC_SYNC_LOST 22
|
||||
#define BLE_GAP_EVENT_SCAN_REQ_RCVD 23
|
||||
#define BLE_GAP_EVENT_PERIODIC_TRANSFER 24
|
||||
#define BLE_GAP_EVENT_SUBRATE_CHANGE 25
|
||||
|
||||
/*** Reason codes for the subscribe GAP event. */
|
||||
|
||||
@@ -972,6 +973,33 @@ struct ble_gap_event {
|
||||
/** Advertiser clock accuracy */
|
||||
uint8_t adv_clk_accuracy;
|
||||
} periodic_transfer;
|
||||
#endif
|
||||
#if MYNEWT_VAL(BLE_CONN_SUBRATING)
|
||||
/**
|
||||
* Represents a subrate change event that indicates connection subrate update procedure
|
||||
* has completed and some parameters have changed Valid for
|
||||
* the following event types:
|
||||
* o BLE_GAP_EVENT_SUBRATE_CHANGE
|
||||
*/
|
||||
struct {
|
||||
/** BLE_ERR_SUCCESS on success or error code on failure */
|
||||
uint8_t status;
|
||||
|
||||
/** Connection Handle */
|
||||
uint16_t conn_handle;
|
||||
|
||||
/** Subrate Factor */
|
||||
uint16_t subrate_factor;
|
||||
|
||||
/** Peripheral Latency */
|
||||
uint16_t periph_latency;
|
||||
|
||||
/** Continuation Number */
|
||||
uint16_t cont_num;
|
||||
|
||||
/** Supervision Timeout */
|
||||
uint16_t supervision_tmo;
|
||||
} subrate_change;
|
||||
#endif
|
||||
};
|
||||
};
|
||||
@@ -2113,6 +2141,46 @@ int ble_gap_set_prefered_default_le_phy(uint8_t tx_phys_mask,
|
||||
int ble_gap_set_prefered_le_phy(uint16_t conn_handle, uint8_t tx_phys_mask,
|
||||
uint8_t rx_phys_mask, uint16_t phy_opts);
|
||||
|
||||
#if MYNEWT_VAL(BLE_CONN_SUBRATING)
|
||||
/**
|
||||
* Set default subrate
|
||||
*
|
||||
* @param subrate_min Min subrate factor allowed in request by a peripheral
|
||||
* @param subrate_max Max subrate factor allowed in request by a peripheral
|
||||
* @param max_latency Max peripheral latency allowed in units of
|
||||
* subrated conn interval.
|
||||
*
|
||||
* @param cont_num Min number of underlying conn event to remain active
|
||||
* after a packet containing PDU with non-zero length field
|
||||
* is sent or received in request by a peripheral.
|
||||
*
|
||||
* @param supervision_timeout Max supervision timeout allowed in request by a peripheral
|
||||
*/
|
||||
int ble_gap_set_default_subrate(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency,
|
||||
uint16_t cont_num, uint16_t supervision_timeout);
|
||||
|
||||
/**
|
||||
* Subrate Request
|
||||
*
|
||||
* @param conn_handle Connection Handle of the ACL.
|
||||
* @param subrate_min Min subrate factor to be applied
|
||||
* @param subrate_max Max subrate factor to be applied
|
||||
* @param max_latency Max peripheral latency allowed in units of
|
||||
* subrated conn interval.
|
||||
*
|
||||
* @param cont_num Min number of underlying conn event to remain active
|
||||
* after a packet containing PDU with non-zero length field
|
||||
* is sent or received in request by a peripheral.
|
||||
*
|
||||
* @param supervision_timeout Max supervision timeout allowed for this connection
|
||||
*/
|
||||
|
||||
int
|
||||
ble_gap_subrate_req(uint16_t conn_handle, uint16_t subrate_min, uint16_t subrate_max,
|
||||
uint16_t max_latency, uint16_t cont_num,
|
||||
uint16_t supervision_timeout);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Event listener structure
|
||||
*
|
||||
|
||||
@@ -1875,6 +1875,26 @@ ble_gap_rx_periodic_adv_sync_transfer(const struct ble_hci_ev_le_subev_periodic_
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(BLE_CONN_SUBRATING)
|
||||
void
|
||||
ble_gap_rx_subrate_change(const struct ble_hci_ev_le_subev_subrate_change *ev)
|
||||
{
|
||||
struct ble_gap_event event;
|
||||
|
||||
memset(&event, 0x0, sizeof event);
|
||||
|
||||
event.type = BLE_GAP_EVENT_SUBRATE_CHANGE;
|
||||
event.subrate_change.status = ev->status;
|
||||
event.subrate_change.conn_handle = le16toh(ev->conn_handle);
|
||||
event.subrate_change.subrate_factor = le16toh(ev->subrate_factor);
|
||||
event.subrate_change.periph_latency = le16toh(ev->periph_latency);
|
||||
event.subrate_change.cont_num = le16toh(ev->cont_num);
|
||||
event.subrate_change.supervision_tmo = le16toh(ev->supervision_tmo);
|
||||
|
||||
ble_gap_event_listener_call(&event);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
static int
|
||||
ble_gap_rd_rem_sup_feat_tx(uint16_t handle)
|
||||
@@ -4894,6 +4914,46 @@ ble_gap_conn_create_tx(uint8_t own_addr_type, const ble_addr_t *peer_addr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(BLE_CONN_SUBRATING)
|
||||
int
|
||||
ble_gap_set_default_subrate(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency,
|
||||
uint16_t cont_num, uint16_t supervision_tmo)
|
||||
{
|
||||
struct ble_hci_le_set_default_subrate_cp cmd;
|
||||
uint16_t opcode;
|
||||
|
||||
cmd.subrate_min = htole16(subrate_min);
|
||||
cmd.subrate_max = htole16(subrate_max);
|
||||
cmd.max_latency = htole16(max_latency);
|
||||
cmd.cont_num = htole16(cont_num);
|
||||
cmd.supervision_tmo = htole16(supervision_tmo);
|
||||
|
||||
opcode = BLE_HCI_OP(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_DEFAULT_SUBRATE);
|
||||
|
||||
return ble_hs_hci_cmd_tx(opcode, &cmd, sizeof(cmd), NULL, 0);
|
||||
}
|
||||
|
||||
int
|
||||
ble_gap_subrate_req(uint16_t conn_handle, uint16_t subrate_min, uint16_t subrate_max,
|
||||
uint16_t max_latency, uint16_t cont_num,
|
||||
uint16_t supervision_tmo)
|
||||
{
|
||||
struct ble_hci_le_subrate_req_cp cmd;
|
||||
uint16_t opcode;
|
||||
|
||||
cmd.conn_handle = htole16(conn_handle);
|
||||
cmd.subrate_min = htole16(subrate_min);
|
||||
cmd.subrate_max = htole16(subrate_max);
|
||||
cmd.max_latency = htole16(max_latency);
|
||||
cmd.cont_num = htole16(cont_num);
|
||||
cmd.supervision_tmo = htole16(supervision_tmo);
|
||||
|
||||
opcode = BLE_HCI_OP(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SUBRATE_REQ);
|
||||
|
||||
return ble_hs_hci_cmd_tx(opcode, &cmd, sizeof(cmd), NULL, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(BLE_EXT_ADV)
|
||||
#if MYNEWT_VAL(BLE_ROLE_CENTRAL)
|
||||
static int
|
||||
|
||||
@@ -92,6 +92,9 @@ void ble_gap_rx_scan_req_rcvd(const struct ble_hci_ev_le_subev_scan_req_rcvd *ev
|
||||
#endif
|
||||
void ble_gap_rx_adv_report(struct ble_gap_disc_desc *desc);
|
||||
void ble_gap_rx_rd_rem_sup_feat_complete(const struct ble_hci_ev_le_subev_rd_rem_used_feat *ev);
|
||||
#if MYNEWT_VAL(BLE_CONN_SUBRATING)
|
||||
void ble_gap_rx_subrate_change(const struct ble_hci_ev_le_subev_subrate_change *ev);
|
||||
#endif
|
||||
|
||||
struct ble_gap_conn_complete
|
||||
{
|
||||
|
||||
@@ -79,6 +79,9 @@ static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_periodic_adv_rpt;
|
||||
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_periodic_adv_sync_lost;
|
||||
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_scan_req_rcvd;
|
||||
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_periodic_adv_sync_transfer;
|
||||
#if MYNEWT_VAL(BLE_CONN_SUBRATING)
|
||||
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_subrate_change;
|
||||
#endif
|
||||
|
||||
/* Statistics */
|
||||
struct host_hci_stats
|
||||
@@ -135,6 +138,9 @@ static ble_hs_hci_evt_le_fn * const ble_hs_hci_evt_le_dispatch[] = {
|
||||
[BLE_HCI_LE_SUBEV_ADV_SET_TERMINATED] = ble_hs_hci_evt_le_adv_set_terminated,
|
||||
[BLE_HCI_LE_SUBEV_SCAN_REQ_RCVD] = ble_hs_hci_evt_le_scan_req_rcvd,
|
||||
[BLE_HCI_LE_SUBEV_PERIODIC_ADV_SYNC_TRANSFER] = ble_hs_hci_evt_le_periodic_adv_sync_transfer,
|
||||
#if MYNEWT_VAL(BLE_CONN_SUBRATING)
|
||||
[BLE_HCI_LE_SUBEV_SUBRATE_CHANGE] = ble_hs_hci_evt_le_subrate_change,
|
||||
#endif
|
||||
};
|
||||
|
||||
#define BLE_HS_HCI_EVT_LE_DISPATCH_SZ \
|
||||
@@ -820,6 +826,23 @@ ble_hs_hci_evt_le_scan_req_rcvd(uint8_t subevent, const void *data,
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(BLE_CONN_SUBRATING)
|
||||
static int
|
||||
ble_hs_hci_evt_le_subrate_change(uint8_t subevent, const void *data,
|
||||
unsigned int len)
|
||||
{
|
||||
const struct ble_hci_ev_le_subev_subrate_change *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
ble_gap_rx_subrate_change(ev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
static int
|
||||
ble_hs_hci_evt_le_conn_upd_complete(uint8_t subevent, const void *data,
|
||||
|
||||
@@ -238,6 +238,16 @@ ble_hs_startup_le_set_evmask_tx(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(BLE_CONN_SUBRATING)
|
||||
if (version >= BLE_HCI_VER_BCS_5_3) {
|
||||
/**
|
||||
* Enable the following LE events:
|
||||
* 0x0000000400000000 LE Subrate change event
|
||||
*/
|
||||
mask |= 0x0000000400000000;
|
||||
}
|
||||
#endif
|
||||
|
||||
cmd.event_mask = htole64(mask);
|
||||
|
||||
rc = ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_LE,
|
||||
|
||||
@@ -1061,6 +1061,25 @@ struct ble_hci_le_set_host_feat_cp {
|
||||
uint8_t val;
|
||||
} __attribute__((packed));
|
||||
|
||||
#define BLE_HCI_OCF_LE_SET_DEFAULT_SUBRATE (0x007D)
|
||||
struct ble_hci_le_set_default_subrate_cp {
|
||||
uint16_t subrate_min;
|
||||
uint16_t subrate_max;
|
||||
uint16_t max_latency;
|
||||
uint16_t cont_num;
|
||||
uint16_t supervision_tmo;
|
||||
} __attribute__((packed));
|
||||
|
||||
#define BLE_HCI_OCF_LE_SUBRATE_REQ (0x007E)
|
||||
struct ble_hci_le_subrate_req_cp {
|
||||
uint16_t conn_handle;
|
||||
uint16_t subrate_min;
|
||||
uint16_t subrate_max;
|
||||
uint16_t max_latency;
|
||||
uint16_t cont_num;
|
||||
uint16_t supervision_tmo;
|
||||
} __attribute__((packed));
|
||||
|
||||
/* --- Vendor specific commands (OGF 0x00FF) */
|
||||
#define BLE_HCI_OCF_VS_RD_STATIC_ADDR (0x0001)
|
||||
struct ble_hci_vs_rd_static_addr_rp {
|
||||
@@ -1790,6 +1809,18 @@ struct ble_hci_ev_le_subev_biginfo_adv_report {
|
||||
uint8_t encryption;
|
||||
} __attribute__((packed));
|
||||
|
||||
#define BLE_HCI_LE_SUBEV_SUBRATE_CHANGE (0x23)
|
||||
struct ble_hci_ev_le_subev_subrate_change {
|
||||
uint8_t subev_code;
|
||||
uint8_t status;
|
||||
uint16_t conn_handle;
|
||||
uint16_t subrate_factor;
|
||||
uint16_t periph_latency;
|
||||
uint16_t cont_num;
|
||||
uint16_t supervision_tmo;
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
/* Data buffer overflow event */
|
||||
#define BLE_HCI_EVENT_ACL_BUF_OVERFLOW (0x01)
|
||||
|
||||
@@ -1832,6 +1863,7 @@ struct ble_hci_ev_le_subev_biginfo_adv_report {
|
||||
#define BLE_HCI_VER_BCS_5_0 (9)
|
||||
#define BLE_HCI_VER_BCS_5_1 (10)
|
||||
#define BLE_HCI_VER_BCS_5_2 (11)
|
||||
#define BLE_HCI_VER_BCS_5_3 (12)
|
||||
|
||||
#define BLE_LMP_VER_BCS_1_0b (0)
|
||||
#define BLE_LMP_VER_BCS_1_1 (1)
|
||||
@@ -1845,6 +1877,7 @@ struct ble_hci_ev_le_subev_biginfo_adv_report {
|
||||
#define BLE_LMP_VER_BCS_5_0 (9)
|
||||
#define BLE_LMP_VER_BCS_5_1 (10)
|
||||
#define BLE_LMP_VER_BCS_5_2 (11)
|
||||
#define BLE_LMP_VER_BCS_5_3 (12)
|
||||
|
||||
/* selected HCI and LMP version */
|
||||
#if MYNEWT_VAL(BLE_VERSION) == 50
|
||||
|
||||
Reference in New Issue
Block a user