mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-09-17 22:49:55 +00:00
Stack support for Connection subrating
This commit is contained in:
committed by
Roshan Bangar
parent
64408f1852
commit
f90ce9791f
@@ -137,6 +137,7 @@ struct hci_conn_update;
|
||||
#define BLE_GAP_EVENT_PERIODIC_TRANSFER 24
|
||||
#define BLE_GAP_EVENT_PATHLOSS_THRESHOLD 25
|
||||
#define BLE_GAP_EVENT_TRANSMIT_POWER 26
|
||||
#define BLE_GAP_EVENT_SUBRATE_CHANGE 27
|
||||
|
||||
/*** Reason codes for the subscribe GAP event. */
|
||||
|
||||
@@ -1022,6 +1023,33 @@ struct ble_gap_event {
|
||||
/** Delta indicating change in transmit Power Level */
|
||||
uint8_t delta;
|
||||
} transmit_power;
|
||||
#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
|
||||
};
|
||||
};
|
||||
@@ -2197,6 +2225,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
|
||||
*
|
||||
|
||||
@@ -1923,6 +1923,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)
|
||||
@@ -4955,6 +4975,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
|
||||
|
||||
#if MYNEWT_VAL(BLE_POWER_CONTROL)
|
||||
void ble_gap_rx_transmit_power_report(const struct ble_hci_ev_le_subev_transmit_power_report *ev);
|
||||
|
||||
@@ -81,6 +81,9 @@ static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_periodic_adv_sync_transfer;
|
||||
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_pathloss_threshold;
|
||||
static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_transmit_power_report;
|
||||
#endif
|
||||
#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
|
||||
@@ -141,6 +144,9 @@ static ble_hs_hci_evt_le_fn * const ble_hs_hci_evt_le_dispatch[] = {
|
||||
[BLE_HCI_LE_SUBEV_PATH_LOSS_THRESHOLD] = ble_hs_hci_evt_le_pathloss_threshold,
|
||||
[BLE_HCI_LE_SUBEV_TRANSMIT_POWER_REPORT] = ble_hs_hci_evt_le_transmit_power_report,
|
||||
#endif
|
||||
#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 \
|
||||
@@ -857,6 +863,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,
|
||||
|
||||
@@ -240,6 +240,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,
|
||||
|
||||
Reference in New Issue
Block a user