gap: add gap_le_set_phy command

This commit is contained in:
Matthias Ringwald 2019-01-04 18:46:13 +01:00
parent e705510c28
commit b90f6e0afe
3 changed files with 41 additions and 0 deletions

View File

@ -396,6 +396,17 @@ int gap_auto_connection_stop(bd_addr_type_t address_typ, bd_addr_t address);
*/
void gap_auto_connection_stop_all(void);
/**
* @brief Set LE PHY
* @param con_handle
* @param all_phys 0 = set rx/tx, 1 = set only rx, 2 = set only tx
* @param tx_phys 1 = 1M, 2 = 2M, 4 = Coded
* @param rx_phys 1 = 1M, 2 = 2M, 4 = Coded
* @param phy_options 0 = no preferred coding for Coded, 1 = S=2 coding (500 kbit), 2 = S=8 coding (125 kbit)
* @returns 0 if ok
*/
uint8_t gap_le_set_phy(hci_con_handle_t con_handle, uint8_t all_phys, uint8_t tx_phys, uint8_t rx_phys, uint8_t phy_options);
/**
* @brief Get connection interval
* @return connection interval, otherwise 0 if error

View File

@ -202,6 +202,9 @@ static hci_connection_t * create_connection_for_bd_addr_and_type(bd_addr_t addr,
conn->num_acl_packets_sent = 0;
conn->num_sco_packets_sent = 0;
conn->le_con_parameter_update_state = CON_PARAMETER_UPDATE_NONE;
#ifdef ENABLE_BLE
conn->le_phy_update_all_phys = 0xff;
#endif
btstack_linked_list_add(&hci_stack->connections, (btstack_linked_item_t *) conn);
return conn;
}
@ -3509,6 +3512,12 @@ static void hci_run(void){
default:
break;
}
if (connection->le_phy_update_all_phys != 0xff){
uint8_t all_phys = connection->le_phy_update_all_phys;
connection->le_phy_update_all_phys = 0xff;
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;
}
#endif
}
@ -4535,6 +4544,20 @@ gap_connection_type_t gap_get_connection_type(hci_con_handle_t connection_handle
#ifdef ENABLE_BLE
uint8_t gap_le_set_phy(hci_con_handle_t connection_handle, uint8_t all_phys, uint8_t tx_phys, uint8_t rx_phys, uint8_t phy_options){
hci_connection_t * conn = hci_connection_for_handle(connection_handle);
if (!conn) return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
conn->le_phy_update_all_phys = all_phys;
conn->le_phy_update_tx_phys = tx_phys;
conn->le_phy_update_rx_phys = rx_phys;
conn->le_phy_update_phy_options = phy_options;
hci_run();
return 0;
}
#ifdef ENABLE_LE_CENTRAL
/**
* @brief Auto Connection Establishment - Start Connecting to device

View File

@ -527,6 +527,13 @@ typedef struct {
#ifdef ENABLE_BLE
uint16_t le_connection_interval;
// LE PHY Update via set phy command
uint8_t le_phy_update_all_phys; // 0xff for idle
uint8_t le_phy_update_tx_phys;
uint8_t le_phy_update_rx_phys;
int8_t le_phy_update_phy_options;
// LE Security Manager
sm_connection_t sm_connection;