mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-18 05:42:49 +00:00
add asserts to check if buffer was reserved before calling send prepared
This commit is contained in:
parent
640925c0e2
commit
c8b9416af2
@ -92,12 +92,17 @@ int l2cap_reserve_packet_buffer(void){
|
|||||||
|
|
||||||
int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len){
|
int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len){
|
||||||
|
|
||||||
|
if (!hci_is_packet_buffer_reserved()){
|
||||||
|
log_error("l2cap_send_prepared_connectionless called without reserving packet first");
|
||||||
|
return BTSTACK_ACL_BUFFERS_FULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (!hci_can_send_packet_now(HCI_ACL_DATA_PACKET)){
|
if (!hci_can_send_packet_now(HCI_ACL_DATA_PACKET)){
|
||||||
log_info("l2cap_send_prepared_to_handle cid %u, cannot send\n", cid);
|
log_info("l2cap_send_prepared_connectionless handle %u,, cid %u, cannot send\n", handle, cid);
|
||||||
return BTSTACK_ACL_BUFFERS_FULL;
|
return BTSTACK_ACL_BUFFERS_FULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_debug("l2cap_send_prepared_to_handle cid %u, handle %u\n", cid, handle);
|
log_debug("l2cap_send_prepared_connectionless handle %u, cid %u\n", handle, cid);
|
||||||
|
|
||||||
uint8_t *acl_buffer = hci_get_outgoing_acl_packet_buffer();
|
uint8_t *acl_buffer = hci_get_outgoing_acl_packet_buffer();
|
||||||
|
|
||||||
@ -118,7 +123,7 @@ 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){
|
int l2cap_send_connectionless(uint16_t handle, uint16_t cid, uint8_t *data, uint16_t len){
|
||||||
|
|
||||||
if (!hci_can_send_packet_now_using_packet_buffer(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);
|
log_info("l2cap_send_connectionless cid %u, cannot send\n", cid);
|
||||||
return BTSTACK_ACL_BUFFERS_FULL;
|
return BTSTACK_ACL_BUFFERS_FULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,6 +279,11 @@ int hci_can_send_packet_now_using_packet_buffer(uint8_t packet_type){
|
|||||||
return hci_can_send_packet_now(packet_type);
|
return hci_can_send_packet_now(packet_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// used for internal checks in l2cap[-le].c
|
||||||
|
int hci_is_packet_buffer_reserved(void){
|
||||||
|
return hci_stack->hci_packet_buffer_reserved;
|
||||||
|
}
|
||||||
|
|
||||||
// reserves outgoing packet buffer. @returns 1 if successful
|
// reserves outgoing packet buffer. @returns 1 if successful
|
||||||
int hci_reserve_packet_buffer(void){
|
int hci_reserve_packet_buffer(void){
|
||||||
if (hci_stack->hci_packet_buffer_reserved) return 0;
|
if (hci_stack->hci_packet_buffer_reserved) return 0;
|
||||||
@ -309,7 +314,7 @@ int hci_send_acl_packet(uint8_t *packet, int size){
|
|||||||
int err = hci_stack->hci_transport->send_packet(HCI_ACL_DATA_PACKET, packet, size);
|
int err = hci_stack->hci_transport->send_packet(HCI_ACL_DATA_PACKET, packet, size);
|
||||||
|
|
||||||
// free packet buffer for synchronous transport implementations
|
// free packet buffer for synchronous transport implementations
|
||||||
if (hci_transport_synchronous()){
|
if (hci_transport_synchronous() && (packet == hci_stack->hci_packet_buffer)){
|
||||||
hci_stack->hci_packet_buffer_reserved = 0;
|
hci_stack->hci_packet_buffer_reserved = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1721,7 +1726,7 @@ int hci_send_cmd_packet(uint8_t *packet, int size){
|
|||||||
int err = 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
|
// free packet buffer for synchronous transport implementations
|
||||||
if (hci_transport_synchronous()){
|
if (hci_transport_synchronous() && (packet == hci_stack->hci_packet_buffer)){
|
||||||
hci_stack->hci_packet_buffer_reserved = 0;
|
hci_stack->hci_packet_buffer_reserved = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,6 +394,9 @@ int hci_can_send_packet_now_using_packet_buffer(uint8_t packet_type);
|
|||||||
// reserves outgoing packet buffer. @returns 1 if successful
|
// reserves outgoing packet buffer. @returns 1 if successful
|
||||||
int hci_reserve_packet_buffer(void);
|
int hci_reserve_packet_buffer(void);
|
||||||
|
|
||||||
|
// used for internal checks in l2cap[-le].c
|
||||||
|
int hci_is_packet_buffer_reserved(void);
|
||||||
|
|
||||||
// get point to packet buffer
|
// get point to packet buffer
|
||||||
uint8_t* hci_get_outgoing_acl_packet_buffer(void);
|
uint8_t* hci_get_outgoing_acl_packet_buffer(void);
|
||||||
|
|
||||||
|
26
src/l2cap.c
26
src/l2cap.c
@ -351,25 +351,30 @@ int l2cap_reserve_packet_buffer(void){
|
|||||||
|
|
||||||
int l2cap_send_prepared(uint16_t local_cid, uint16_t len){
|
int l2cap_send_prepared(uint16_t local_cid, uint16_t len){
|
||||||
|
|
||||||
if (!hci_can_send_packet_now(HCI_ACL_DATA_PACKET)){
|
if (!hci_is_packet_buffer_reserved()){
|
||||||
log_info("l2cap_send_internal cid 0x%02x, cannot send\n", local_cid);
|
log_error("l2cap_send_prepared called without reserving packet first");
|
||||||
return BTSTACK_ACL_BUFFERS_FULL;
|
return BTSTACK_ACL_BUFFERS_FULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!hci_can_send_packet_now(HCI_ACL_DATA_PACKET)){
|
||||||
|
log_info("l2cap_send_prepared cid 0x%02x, cannot send\n", local_cid);
|
||||||
|
return BTSTACK_ACL_BUFFERS_FULL;
|
||||||
|
}
|
||||||
|
|
||||||
l2cap_channel_t * channel = l2cap_get_channel_for_local_cid(local_cid);
|
l2cap_channel_t * channel = l2cap_get_channel_for_local_cid(local_cid);
|
||||||
if (!channel) {
|
if (!channel) {
|
||||||
log_error("l2cap_send_internal no channel for cid 0x%02x\n", local_cid);
|
log_error("l2cap_send_prepared no channel for cid 0x%02x\n", local_cid);
|
||||||
return -1; // TODO: define error
|
return -1; // TODO: define error
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channel->packets_granted == 0){
|
if (channel->packets_granted == 0){
|
||||||
log_error("l2cap_send_internal cid 0x%02x, no credits!\n", local_cid);
|
log_error("l2cap_send_prepared cid 0x%02x, no credits!\n", local_cid);
|
||||||
return -1; // TODO: define error
|
return -1; // TODO: define error
|
||||||
}
|
}
|
||||||
|
|
||||||
--channel->packets_granted;
|
--channel->packets_granted;
|
||||||
|
|
||||||
log_debug("l2cap_send_internal cid 0x%02x, handle %u, 1 credit used, credits left %u;\n",
|
log_debug("l2cap_send_prepared cid 0x%02x, handle %u, 1 credit used, credits left %u;\n",
|
||||||
local_cid, channel->handle, channel->packets_granted);
|
local_cid, channel->handle, channel->packets_granted);
|
||||||
|
|
||||||
uint8_t *acl_buffer = hci_get_outgoing_acl_packet_buffer();
|
uint8_t *acl_buffer = hci_get_outgoing_acl_packet_buffer();
|
||||||
@ -392,12 +397,17 @@ int l2cap_send_prepared(uint16_t local_cid, uint16_t len){
|
|||||||
|
|
||||||
int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len){
|
int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len){
|
||||||
|
|
||||||
|
if (!hci_is_packet_buffer_reserved()){
|
||||||
|
log_error("l2cap_send_prepared_connectionless called without reserving packet first");
|
||||||
|
return BTSTACK_ACL_BUFFERS_FULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (!hci_can_send_packet_now(HCI_ACL_DATA_PACKET)){
|
if (!hci_can_send_packet_now(HCI_ACL_DATA_PACKET)){
|
||||||
log_info("l2cap_send_prepared_to_handle cid 0x%02x, cannot send\n", cid);
|
log_info("l2cap_send_prepared_connectionless handle 0x%02x, cid 0x%02x, cannot send\n", handle, cid);
|
||||||
return BTSTACK_ACL_BUFFERS_FULL;
|
return BTSTACK_ACL_BUFFERS_FULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_debug("l2cap_send_prepared_to_handle cid 0x%02x, handle %u\n", cid, handle);
|
log_debug("l2cap_send_prepared_connectionless handle %u, cid 0x%02x\n", handle, cid);
|
||||||
|
|
||||||
uint8_t *acl_buffer = hci_get_outgoing_acl_packet_buffer();
|
uint8_t *acl_buffer = hci_get_outgoing_acl_packet_buffer();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user