mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-26 12:35:25 +00:00
add flag to track if hci packet buffer is reserved
This commit is contained in:
parent
e65f2926ef
commit
6b4af23d08
41
src/hci.c
41
src/hci.c
@ -273,6 +273,24 @@ int hci_can_send_packet_now(uint8_t packet_type){
|
||||
}
|
||||
}
|
||||
|
||||
// same as hci_can_send_packet_now, but also checks if packet buffer is free for use
|
||||
int hci_can_send_packet_now_using_packet_buffer(uint8_t packet_type){
|
||||
if (hci_stack->hci_packet_buffer_reserved) return 0;
|
||||
return hci_can_send_packet_now(packet_type);
|
||||
}
|
||||
|
||||
// reserves outgoing packet buffer. @returns 1 if successful
|
||||
int hci_reserve_packet_buffer(void){
|
||||
if (hci_stack->hci_packet_buffer_reserved) return 0;
|
||||
hci_stack->hci_packet_buffer_reserved = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// assumption: synchronous implementations don't provide can_send_packet_now as they don't keep the buffer after the call
|
||||
int hci_transport_synchronous(void){
|
||||
return hci_stack->hci_transport->can_send_packet_now == NULL;
|
||||
}
|
||||
|
||||
int hci_send_acl_packet(uint8_t *packet, int size){
|
||||
|
||||
// check for free places on BT module
|
||||
@ -289,7 +307,12 @@ int hci_send_acl_packet(uint8_t *packet, int size){
|
||||
|
||||
// send packet
|
||||
int err = hci_stack->hci_transport->send_packet(HCI_ACL_DATA_PACKET, packet, size);
|
||||
|
||||
|
||||
// free packet buffer for synchronous transport implementations
|
||||
if (hci_transport_synchronous()){
|
||||
hci_stack->hci_packet_buffer_reserved = 0;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -806,6 +829,12 @@ static void event_handler(uint8_t *packet, int size){
|
||||
}
|
||||
break;
|
||||
|
||||
case DAEMON_EVENT_HCI_PACKET_SENT:
|
||||
// free packet buffer for asynchronous transport
|
||||
if (hci_transport_synchronous()) break;
|
||||
hci_stack->hci_packet_buffer_reserved = 0;
|
||||
break;
|
||||
|
||||
#ifdef HAVE_BLE
|
||||
case HCI_EVENT_LE_META:
|
||||
switch (packet[2]) {
|
||||
@ -1688,9 +1717,15 @@ int hci_send_cmd_packet(uint8_t *packet, int size){
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
hci_stack->num_cmd_packets--;
|
||||
return hci_stack->hci_transport->send_packet(HCI_COMMAND_DATA_PACKET, packet, size);
|
||||
int err = hci_stack->hci_transport->send_packet(HCI_COMMAND_DATA_PACKET, packet, size);
|
||||
|
||||
// free packet buffer for synchronous transport implementations
|
||||
if (hci_transport_synchronous()){
|
||||
hci_stack->hci_packet_buffer_reserved = 0;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
// disconnect because of security block
|
||||
|
13
src/hci.h
13
src/hci.h
@ -323,7 +323,8 @@ typedef struct {
|
||||
linked_list_t connections;
|
||||
|
||||
// single buffer for HCI Command assembly
|
||||
uint8_t hci_packet_buffer[HCI_PACKET_BUFFER_SIZE]; // opcode (16), len(8)
|
||||
uint8_t hci_packet_buffer[HCI_PACKET_BUFFER_SIZE]; // opcode (16), len(8)
|
||||
uint8_t hci_packet_buffer_reserved;
|
||||
|
||||
/* host to controller flow control */
|
||||
uint8_t num_cmd_packets;
|
||||
@ -386,6 +387,15 @@ int hci_send_acl_packet(uint8_t *packet, int size);
|
||||
|
||||
// non-blocking UART driver needs
|
||||
int hci_can_send_packet_now(uint8_t packet_type);
|
||||
|
||||
// same as hci_can_send_packet_now, but also checks if packet buffer is free for use
|
||||
int hci_can_send_packet_now_using_packet_buffer(uint8_t packet_type);
|
||||
|
||||
// reserves outgoing packet buffer. @returns 1 if successful
|
||||
int hci_reserve_packet_buffer(void);
|
||||
|
||||
// get point to packet buffer
|
||||
uint8_t* hci_get_outgoing_acl_packet_buffer(void);
|
||||
|
||||
bd_addr_t * hci_local_bd_addr(void);
|
||||
hci_connection_t * hci_connection_for_handle(hci_con_handle_t con_handle);
|
||||
@ -395,7 +405,6 @@ uint8_t hci_number_free_acl_slots(void);
|
||||
int hci_authentication_active_for_handle(hci_con_handle_t handle);
|
||||
uint16_t hci_max_acl_data_packet_length(void);
|
||||
uint16_t hci_usable_acl_packet_types(void);
|
||||
uint8_t* hci_get_outgoing_acl_packet_buffer(void);
|
||||
|
||||
//
|
||||
void hci_emit_state(void);
|
||||
|
@ -339,6 +339,10 @@ uint8_t *l2cap_get_outgoing_buffer(void){
|
||||
return hci_get_outgoing_acl_packet_buffer() + COMPLETE_L2CAP_HEADER; // 8 bytes
|
||||
}
|
||||
|
||||
int l2cap_reserve_packet_buffer(void){
|
||||
return hci_reserve_packet_buffer();
|
||||
}
|
||||
|
||||
int l2cap_send_prepared(uint16_t local_cid, uint16_t len){
|
||||
|
||||
if (!hci_can_send_packet_now(HCI_ACL_DATA_PACKET)){
|
||||
|
Loading…
x
Reference in New Issue
Block a user