hci: use bool for can send now API functions

This commit is contained in:
Matthias Ringwald 2021-09-06 15:19:49 +02:00
parent cafc12e80b
commit 1972f31fe7
2 changed files with 36 additions and 32 deletions

View File

@ -631,45 +631,45 @@ static int hci_can_send_comand_packet_transport(void){
}
// new functions replacing hci_can_send_packet_now[_using_packet_buffer]
int hci_can_send_command_packet_now(void){
if (hci_can_send_comand_packet_transport() == 0) return 0;
bool hci_can_send_command_packet_now(void){
if (hci_can_send_comand_packet_transport() == 0) return false;
return hci_stack->num_cmd_packets > 0u;
}
static int hci_transport_can_send_prepared_packet_now(uint8_t packet_type){
// check for async hci transport implementations
if (!hci_stack->hci_transport->can_send_packet_now) return 1;
if (!hci_stack->hci_transport->can_send_packet_now) return true;
return hci_stack->hci_transport->can_send_packet_now(packet_type);
}
static int hci_can_send_prepared_acl_packet_for_address_type(bd_addr_type_t address_type){
if (!hci_transport_can_send_prepared_packet_now(HCI_ACL_DATA_PACKET)) return 0;
static bool hci_can_send_prepared_acl_packet_for_address_type(bd_addr_type_t address_type){
if (!hci_transport_can_send_prepared_packet_now(HCI_ACL_DATA_PACKET)) return false;
return hci_number_free_acl_slots_for_connection_type(address_type) > 0;
}
int hci_can_send_acl_le_packet_now(void){
if (hci_stack->hci_packet_buffer_reserved) return 0;
bool hci_can_send_acl_le_packet_now(void){
if (hci_stack->hci_packet_buffer_reserved) return false;
return hci_can_send_prepared_acl_packet_for_address_type(BD_ADDR_TYPE_LE_PUBLIC);
}
int hci_can_send_prepared_acl_packet_now(hci_con_handle_t con_handle) {
if (!hci_transport_can_send_prepared_packet_now(HCI_ACL_DATA_PACKET)) return 0;
bool hci_can_send_prepared_acl_packet_now(hci_con_handle_t con_handle) {
if (!hci_transport_can_send_prepared_packet_now(HCI_ACL_DATA_PACKET)) return false;
return hci_number_free_acl_slots_for_handle(con_handle) > 0;
}
int hci_can_send_acl_packet_now(hci_con_handle_t con_handle){
if (hci_stack->hci_packet_buffer_reserved) return 0;
bool hci_can_send_acl_packet_now(hci_con_handle_t con_handle){
if (hci_stack->hci_packet_buffer_reserved) return false;
return hci_can_send_prepared_acl_packet_now(con_handle);
}
#ifdef ENABLE_CLASSIC
int hci_can_send_acl_classic_packet_now(void){
if (hci_stack->hci_packet_buffer_reserved) return 0;
bool hci_can_send_acl_classic_packet_now(void){
if (hci_stack->hci_packet_buffer_reserved) return false;
return hci_can_send_prepared_acl_packet_for_address_type(BD_ADDR_TYPE_ACL);
}
int hci_can_send_prepared_sco_packet_now(void){
if (!hci_transport_can_send_prepared_packet_now(HCI_SCO_DATA_PACKET)) return 0;
bool hci_can_send_prepared_sco_packet_now(void){
if (!hci_transport_can_send_prepared_packet_now(HCI_SCO_DATA_PACKET)) return false;
if (hci_have_usb_transport()){
return hci_stack->sco_can_send_now;
} else {
@ -677,8 +677,8 @@ int hci_can_send_prepared_sco_packet_now(void){
}
}
int hci_can_send_sco_packet_now(void){
if (hci_stack->hci_packet_buffer_reserved) return 0;
bool hci_can_send_sco_packet_now(void){
if (hci_stack->hci_packet_buffer_reserved) return false;
return hci_can_send_prepared_sco_packet_now();
}
@ -877,7 +877,7 @@ int hci_send_sco_packet_buffer(int size){
if (hci_have_usb_transport()){
// token used
hci_stack->sco_can_send_now = 0;
hci_stack->sco_can_send_now = false;
} else {
if (hci_stack->synchronous_flow_control_enabled){
connection->num_packets_sent++;
@ -2669,7 +2669,7 @@ static void event_handler(uint8_t *packet, uint16_t size){
}
// trigger can send now
if (hci_have_usb_transport()){
hci_stack->sco_can_send_now = 1;
hci_stack->sco_can_send_now = true;
}
#endif
#ifdef HAVE_SCO_TRANSPORT
@ -3120,7 +3120,7 @@ static void event_handler(uint8_t *packet, uint16_t size){
#ifdef ENABLE_CLASSIC
case HCI_EVENT_SCO_CAN_SEND_NOW:
// For SCO, we do the can_send_now_check here
hci_stack->sco_can_send_now = 1;
hci_stack->sco_can_send_now = true;
hci_notify_if_sco_can_send_now();
return;

View File

@ -901,7 +901,7 @@ typedef struct {
uint8_t le_acl_packets_total_num;
uint16_t le_data_packets_length;
uint8_t sco_waiting_for_can_send_now;
uint8_t sco_can_send_now;
bool sco_can_send_now;
/* local supported features */
uint8_t local_supported_features[8];
@ -1178,8 +1178,9 @@ void hci_register_sco_packet_handler(btstack_packet_handler_t handler);
/**
* @brief Check if CMD packet can be sent to controller
* @return true if command can be sent
*/
int hci_can_send_command_packet_now(void);
bool hci_can_send_command_packet_now(void);
/**
* @brief Creates and sends HCI command packets based on a template and a list of parameters. Will return error if outgoing data buffer is occupied.
@ -1204,23 +1205,21 @@ void hci_request_sco_can_send_now_event(void);
/**
* @brief Check HCI packet buffer and if SCO packet can be sent to controller
* @return true if sco packet can be sent
*/
int hci_can_send_sco_packet_now(void);
bool hci_can_send_sco_packet_now(void);
/**
* @brief Check if SCO packet can be sent to controller
* @return true if sco packet can be sent
*/
int hci_can_send_prepared_sco_packet_now(void);
bool hci_can_send_prepared_sco_packet_now(void);
/**
* @brief Send SCO packet prepared in HCI packet buffer
*/
int hci_send_sco_packet_buffer(int size);
// Outgoing packet buffer, also used for SCO packets
// see hci_can_send_prepared_sco_packet_now amn hci_send_sco_packet_buffer
/**
* Reserves outgoing packet buffer.
* @return true on success
@ -1269,28 +1268,33 @@ hci_connection_t * hci_connection_for_bd_addr_and_type(const bd_addr_t addr, bd_
/**
* Check if outgoing packet buffer is reserved. Used for internal checks in l2cap.c
* @return true if packet buffer is reserved
*/
bool hci_is_packet_buffer_reserved(void);
/**
* Check hci packet buffer is free and a classic acl packet can be sent to controller
* @return true if ACL Classic packet can be sent now
*/
int hci_can_send_acl_classic_packet_now(void);
bool hci_can_send_acl_classic_packet_now(void);
/**
* Check hci packet buffer is free and an LE acl packet can be sent to controller
* @return true if ACL LE packet can be sent now
*/
int hci_can_send_acl_le_packet_now(void);
bool hci_can_send_acl_le_packet_now(void);
/**
* Check hci packet buffer is free and an acl packet for the given handle can be sent to controller
* @return true if ACL packet for con_handle can be sent now
*/
int hci_can_send_acl_packet_now(hci_con_handle_t con_handle);
bool hci_can_send_acl_packet_now(hci_con_handle_t con_handle);
/**
* Check if acl packet for the given handle can be sent to controller
* @return true if ACL packet for con_handle can be sent now
*/
int hci_can_send_prepared_acl_packet_now(hci_con_handle_t con_handle);
bool hci_can_send_prepared_acl_packet_now(hci_con_handle_t con_handle);
/**
* Send acl packet prepared in hci packet buffer