diff --git a/port/arduino/BTstack.h b/port/arduino/BTstack.h index 75012f6aa..ccdac7ff6 100644 --- a/port/arduino/BTstack.h +++ b/port/arduino/BTstack.h @@ -1,7 +1,12 @@ /** * Arduino Wrapper for BTstack */ -#pragma once +#ifndef __ARDUINO_BTSTACK_H +#define __ARDUINO_BTSTACK_H + +#if defined __cplusplus +extern "C" { +#endif #include "ble/att.h" #include "btstack_util.h" @@ -187,4 +192,10 @@ public: uint16_t addGATTCharacteristicDynamic(UUID * uuid, uint16_t flags, uint16_t characteristic_id); }; - extern BTstackManager BTstack; \ No newline at end of file +extern BTstackManager BTstack; + +#if defined __cplusplus +} +#endif + +#endif // __ARDUINO_BTSTACK_H \ No newline at end of file diff --git a/port/libusb/main.c b/port/libusb/main.c index a623813c3..d37051677 100644 --- a/port/libusb/main.c +++ b/port/libusb/main.c @@ -91,7 +91,7 @@ int main(int argc, const char * argv[]){ hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER); // init HCI - cosnt hci_transport_t * transport = hci_transport_usb_instance(); + const hci_transport_t * transport = hci_transport_usb_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_fs; hci_init(transport, NULL, remote_db); diff --git a/src/classic/rfcomm.c b/src/classic/rfcomm.c index 2cd89b7ce..b504b8b3c 100644 --- a/src/classic/rfcomm.c +++ b/src/classic/rfcomm.c @@ -1924,6 +1924,10 @@ int rfcomm_send_prepared(uint16_t rfcomm_cid, uint16_t len){ int err = rfcomm_assert_send_valid(channel, len); if (err) return err; + if (l2cap_can_send_prepared_packet_now(channel->multiplexer->l2cap_cid)){ + log_error("rfcomm_send_prepared: l2cap cannot send now"); + return BTSTACK_ACL_BUFFERS_FULL; + } // send might cause l2cap to emit new credits, update counters first channel->credits_outgoing--; @@ -1932,10 +1936,10 @@ int rfcomm_send_prepared(uint16_t rfcomm_cid, uint16_t len){ if (result != 0) { channel->credits_outgoing++; - log_info("rfcomm_send: error %d", result); + log_error("rfcomm_send_prepared: error %d", result); return result; } - + return result; } @@ -1948,11 +1952,19 @@ int rfcomm_send(uint16_t rfcomm_cid, uint8_t *data, uint16_t len){ int err = rfcomm_assert_send_valid(channel, len); if (err) return err; + if (l2cap_can_send_packet_now(channel->multiplexer->l2cap_cid)){ + log_error("rfcomm_send_internal: l2cap cannot send now"); + return BTSTACK_ACL_BUFFERS_FULL; + } rfcomm_reserve_packet_buffer(); uint8_t * rfcomm_payload = rfcomm_get_outgoing_buffer(); memcpy(rfcomm_payload, data, len); - return rfcomm_send_prepared(rfcomm_cid, len); + err = rfcomm_send_prepared(rfcomm_cid, len); + if (err){ + rfcomm_release_packet_buffer(); + } + return err; } // Sends Local Lnie Status, see LINE_STATUS_.. diff --git a/src/l2cap.c b/src/l2cap.c index 8fb7b93f0..2c81b81ef 100644 --- a/src/l2cap.c +++ b/src/l2cap.c @@ -205,6 +205,12 @@ int l2cap_can_send_packet_now(uint16_t local_cid){ return hci_can_send_acl_packet_now(channel->handle); } +int l2cap_can_send_prepared_packet_now(uint16_t local_cid){ + l2cap_channel_t *channel = l2cap_get_channel_for_local_cid(local_cid); + if (!channel) return 0; + return hci_can_send_prepared_acl_packet_now(channel->handle); +} + int l2cap_can_send_fixed_channel_packet_now(uint16_t handle){ return hci_can_send_acl_packet_now(handle); } diff --git a/src/l2cap.h b/src/l2cap.h index db064539f..d99307790 100644 --- a/src/l2cap.h +++ b/src/l2cap.h @@ -162,7 +162,7 @@ typedef struct l2cap_signaling_response { } l2cap_signaling_response_t; -// internal use + int l2cap_can_send_fixed_channel_packet_now(uint16_t handle); void l2cap_register_fixed_channel(btstack_packet_handler_t packet_handler, uint16_t channel_id); int l2cap_send_connectionless(uint16_t handle, uint16_t cid, uint8_t *data, uint16_t len); @@ -244,6 +244,7 @@ void l2cap_decline_connection(uint16_t local_cid, uint8_t reason); * @brief Check if outgoing buffer is available and that there's space on the Bluetooth module */ int l2cap_can_send_packet_now(uint16_t local_cid); +int l2cap_can_send_prepared_packet_now(uint16_t local_cid); /** * @brief Reserve outgoing buffer