reserve l2cap packet buffer before using it

This commit is contained in:
matthias.ringwald@gmail.com 2014-04-03 15:16:45 +00:00
parent 2a373862b1
commit 7856fb3169
5 changed files with 36 additions and 3 deletions

View File

@ -82,6 +82,24 @@ 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_can_send_packet_now(uint16_t local_cid){
l2cap_channel_t *channel = l2cap_get_channel_for_local_cid(local_cid);
if (!channel) return 0;
if (!channel->packets_granted) return 0;
return hci_can_send_packet_now(HCI_ACL_DATA_PACKET);
}
int l2cap_can_send_packet_now_using_buffer(uint16_t local_cid){
l2cap_channel_t *channel = l2cap_get_channel_for_local_cid(local_cid);
if (!channel) return 0;
if (!channel->packets_granted) return 0;
return hci_can_send_packet_now_using_packet_buffer(HCI_ACL_DATA_PACKET);
}
int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len){
if (!hci_can_send_packet_now(HCI_ACL_DATA_PACKET)){
@ -109,11 +127,12 @@ int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t l
int l2cap_send_connectionless(uint16_t handle, uint16_t cid, uint8_t *data, uint16_t len){
if (!hci_can_send_packet_now(HCI_ACL_DATA_PACKET)){
if (!hci_can_send_packet_now_using_packet_buffer(HCI_ACL_DATA_PACKET)){
log_info("l2cap_send_internal cid %u, cannot send\n", cid);
return BTSTACK_ACL_BUFFERS_FULL;
}
hci_reserve_packet_buffer();
uint8_t *acl_buffer = hci_get_outgoing_acl_packet_buffer();
memcpy(&acl_buffer[8], data, len);

View File

@ -235,6 +235,13 @@ int l2cap_can_send_packet_now(uint16_t local_cid){
return hci_can_send_packet_now(HCI_ACL_DATA_PACKET);
}
int l2cap_can_send_packet_now_using_buffer(uint16_t local_cid){
l2cap_channel_t *channel = l2cap_get_channel_for_local_cid(local_cid);
if (!channel) return 0;
if (!channel->packets_granted) return 0;
return hci_can_send_packet_now_using_packet_buffer(HCI_ACL_DATA_PACKET);
}
uint16_t l2cap_get_remote_mtu_for_local_cid(uint16_t local_cid){
l2cap_channel_t * channel = l2cap_get_channel_for_local_cid(local_cid);
if (channel) {

View File

@ -196,8 +196,13 @@ typedef struct l2cap_signaling_response {
void l2cap_block_new_credits(uint8_t blocked);
int l2cap_can_send_packet_now(uint16_t local_cid); // non-blocking UART write
int l2cap_can_send_packet_now_using_buffer(uint16_t local_cid);
int l2cap_reserve_packet_buffer(void);
// get outgoing buffer and prepare data
uint8_t *l2cap_get_outgoing_buffer(void);

View File

@ -491,8 +491,9 @@ static rfcomm_service_t * rfcomm_service_for_channel(uint8_t server_channel){
*/
static int rfcomm_send_packet_for_multiplexer(rfcomm_multiplexer_t *multiplexer, uint8_t address, uint8_t control, uint8_t credits, uint8_t *data, uint16_t len){
if (!l2cap_can_send_packet_now(multiplexer->l2cap_cid)) return BTSTACK_ACL_BUFFERS_FULL;
if (!l2cap_can_send_packet_now_using_buffer(multiplexer->l2cap_cid)) return BTSTACK_ACL_BUFFERS_FULL;
l2cap_reserve_packet_buffer();
uint8_t * rfcomm_out_buffer = l2cap_get_outgoing_buffer();
uint16_t pos = 0;

View File

@ -109,8 +109,9 @@ void sdp_client_query(bd_addr_t remote, uint8_t * des_serviceSearchPattern, uint
static void try_to_send(uint16_t channel){
if (sdp_client_state != W2_SEND) return;
if (!l2cap_can_send_packet_now(channel)) return;
if (!l2cap_can_send_packet_now_using_buffer(channel)) return;
l2cap_reserve_packet_buffer();
uint8_t * data = l2cap_get_outgoing_buffer();
uint16_t request_len = 0;