mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-09-12 12:10:03 +00:00
nimble/host: Add HCI Commands/ events for connection subrating
This commit is contained in:
committed by
Andrzej Kaczmarek
parent
25f84900bb
commit
18203ccafc
@@ -138,6 +138,7 @@ struct hci_conn_update;
|
||||
#define BLE_GAP_EVENT_PATHLOSS_THRESHOLD 25
|
||||
#define BLE_GAP_EVENT_TRANSMIT_POWER 26
|
||||
#define BLE_GAP_EVENT_PARING_COMPLETE 27
|
||||
#define BLE_GAP_EVENT_SUBRATE_CHANGE 28
|
||||
|
||||
/*** Reason codes for the subscribe GAP event. */
|
||||
|
||||
@@ -1042,6 +1043,34 @@ struct ble_gap_event {
|
||||
/** The handle of the relevant connection. */
|
||||
uint16_t conn_handle;
|
||||
} pairing_complete;
|
||||
|
||||
#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
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2167,6 +2196,45 @@ 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
|
||||
*
|
||||
|
||||
@@ -1777,6 +1777,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)
|
||||
@@ -4663,6 +4683,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,7 +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);
|
||||
void ble_gap_rx_le_pathloss_threshold(const struct ble_hci_ev_le_subev_path_loss_threshold *ev);
|
||||
|
||||
@@ -64,10 +64,12 @@ 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
|
||||
{
|
||||
struct host_hci_stats {
|
||||
uint32_t events_rxd;
|
||||
uint32_t good_acks_rxd;
|
||||
uint32_t bad_acks_rxd;
|
||||
@@ -124,6 +126,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 \
|
||||
@@ -750,6 +755,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,
|
||||
|
||||
@@ -113,6 +113,11 @@ syscfg.defs:
|
||||
This enabled LE Power Control feature
|
||||
value: 0
|
||||
|
||||
BLE_CONN_SUBRATING:
|
||||
description: >
|
||||
This enables LE Connection Subrating feature
|
||||
value: 0
|
||||
|
||||
# Allow periodic sync transfer only if 5.1 or higher
|
||||
syscfg.restrictions:
|
||||
- "'BLE_PERIODIC_ADV_SYNC_TRANSFER == 0' || 'BLE_VERSION >= 51'"
|
||||
|
||||
@@ -478,6 +478,10 @@
|
||||
#define MYNEWT_VAL_BLE_POWER_CONTROL (0)
|
||||
#endif
|
||||
|
||||
#ifndef MYNEWT_VAL_BLE_CONN_SUBRATING
|
||||
#define MYNEWT_VAL_BLE_CONN_SUBRATING (0)
|
||||
#endif
|
||||
|
||||
#ifndef MYNEWT_VAL_BLE_ROLE_BROADCASTER
|
||||
#define MYNEWT_VAL_BLE_ROLE_BROADCASTER (1)
|
||||
#endif
|
||||
|
||||
@@ -479,6 +479,10 @@
|
||||
#define MYNEWT_VAL_BLE_POWER_CONTROL (0)
|
||||
#endif
|
||||
|
||||
#ifndef MYNEWT_VAL_BLE_CONN_SUBRATING
|
||||
#define MYNEWT_VAL_BLE_CONN_SUBRATING (0)
|
||||
#endif
|
||||
|
||||
#ifndef MYNEWT_VAL_BLE_ROLE_BROADCASTER
|
||||
#define MYNEWT_VAL_BLE_ROLE_BROADCASTER (1)
|
||||
#endif
|
||||
|
||||
@@ -478,6 +478,10 @@
|
||||
#define MYNEWT_VAL_BLE_POWER_CONTROL (0)
|
||||
#endif
|
||||
|
||||
#ifndef MYNEWT_VAL_BLE_CONN_SUBRATING
|
||||
#define MYNEWT_VAL_BLE_CONN_SUBRATING (0)
|
||||
#endif
|
||||
|
||||
#ifndef MYNEWT_VAL_BLE_ROLE_BROADCASTER
|
||||
#define MYNEWT_VAL_BLE_ROLE_BROADCASTER (1)
|
||||
#endif
|
||||
|
||||
@@ -477,6 +477,10 @@
|
||||
#define MYNEWT_VAL_BLE_POWER_CONTROL (0)
|
||||
#endif
|
||||
|
||||
#ifndef MYNEWT_VAL_BLE_CONN_SUBRATING
|
||||
#define MYNEWT_VAL_BLE_CONN_SUBRATING (0)
|
||||
#endif
|
||||
|
||||
#ifndef MYNEWT_VAL_BLE_ROLE_BROADCASTER
|
||||
#define MYNEWT_VAL_BLE_ROLE_BROADCASTER (1)
|
||||
#endif
|
||||
|
||||
@@ -842,6 +842,10 @@
|
||||
#define MYNEWT_VAL_BLE_POWER_CONTROL (0)
|
||||
#endif
|
||||
|
||||
#ifndef MYNEWT_VAL_BLE_CONN_SUBRATING
|
||||
#define MYNEWT_VAL_BLE_CONN_SUBRATING (0)
|
||||
#endif
|
||||
|
||||
#ifndef MYNEWT_VAL_BLE_ROLE_BROADCASTER
|
||||
#define MYNEWT_VAL_BLE_ROLE_BROADCASTER (1)
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user