diff --git a/src/gap.h b/src/gap.h index 0d83d5cac..422d113a3 100644 --- a/src/gap.h +++ b/src/gap.h @@ -982,6 +982,19 @@ void gap_set_connection_parameter_range(le_connection_parameter_range_t * range) */ int gap_connection_parameter_range_included(le_connection_parameter_range_t * existing_range, uint16_t le_conn_interval_min, uint16_t le_conn_interval_max, uint16_t le_conn_latency, uint16_t le_supervision_timeout); +/** + * @brief Request an update of the connection subrating for a given LE connection + * @param handle + * @param subrate_min + * @param subrate_max + * @param max_latency (in units of subrated connection intervals) + * @param continuation_number (Minimum number of underlying connection events to remain active after a packet containing a Link Layer PDU with a non-zero Length field is sent or received) + * @param supervision_timeout (unit: 10ms) range: 10..3200 (100 ms to 32 s) + * @return status + */ +uint8_t gap_request_connection_subrating(hci_con_handle_t con_handle, uint16_t subrate_min, uint16_t subrate_max, + uint16_t max_latency, uint16_t continuation_number, uint16_t supervision_timeout); + /** * @brief Set max number of connections in LE Peripheral role (if Bluetooth Controller supports it) * @note: default: 1 diff --git a/src/hci.c b/src/hci.c index 78e88a2e5..94a7efb22 100644 --- a/src/hci.c +++ b/src/hci.c @@ -7602,6 +7602,13 @@ static bool hci_run_general_pending_commands(void){ hci_send_cmd(&hci_le_set_phy, connection->con_handle, all_phys, connection->le_phy_update_tx_phys, connection->le_phy_update_rx_phys, connection->le_phy_update_phy_options); return true; } + if (connection->le_subrate_min > 0){ + uint16_t subrate_min = connection->le_subrate_min; + connection->le_subrate_min = 0; + hci_send_cmd(&hci_le_subrate_request, connection->con_handle, subrate_min, connection->le_subrate_max, connection->le_subrate_max_latency, + connection->le_subrate_continuation_number, connection->le_supervision_timeout); + return true; + } #ifdef ENABLE_LE_PERIODIC_ADVERTISING if (connection->le_past_sync_handle != HCI_CON_HANDLE_INVALID){ hci_con_handle_t sync_handle = connection->le_past_sync_handle; @@ -8723,6 +8730,20 @@ int gap_request_connection_parameter_update(hci_con_handle_t con_handle, uint16_ return 0; } +uint8_t gap_request_connection_subrating(hci_con_handle_t con_handle, uint16_t subrate_min, uint16_t subrate_max, + uint16_t max_latency, uint16_t continuation_number, uint16_t supervision_timeout){ + hci_connection_t * connection = hci_connection_for_handle(con_handle); + if (!connection) return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; + + connection->le_subrate_min = subrate_min; + connection->le_subrate_max = subrate_max; + connection->le_subrate_max_latency = max_latency; + connection->le_subrate_continuation_number = continuation_number; + connection->le_supervision_timeout = supervision_timeout; + hci_run(); + return ERROR_CODE_SUCCESS; +} + #ifdef ENABLE_LE_PERIPHERAL #ifdef ENABLE_LE_EXTENDED_ADVERTISING diff --git a/src/hci.h b/src/hci.h index 183c2f001..e64ac111a 100644 --- a/src/hci.h +++ b/src/hci.h @@ -200,7 +200,7 @@ typedef enum { CON_PARAMETER_UPDATE_SEND_RESPONSE, CON_PARAMETER_UPDATE_CHANGE_HCI_CON_PARAMETERS, CON_PARAMETER_UPDATE_DENY, - // HCI - in respnose to HCI_SUBEVENT_LE_REMOTE_CONNECTION_PARAMETER_REQUEST + // HCI - in response to HCI_SUBEVENT_LE_REMOTE_CONNECTION_PARAMETER_REQUEST CON_PARAMETER_UPDATE_REPLY, CON_PARAMETER_UPDATE_NEGATIVE_REPLY, } le_con_parameter_update_state_t; @@ -668,6 +668,13 @@ typedef struct { uint8_t le_phy_update_rx_phys; int8_t le_phy_update_phy_options; + // LE Subrating + uint16_t le_subrate_min; + uint16_t le_subrate_max; + uint16_t le_subrate_max_latency; + uint16_t le_subrate_continuation_number; + uint16_t le_subrate_supervision_timeout; + // LE Security Manager sm_connection_t sm_connection;