From 1ed1a3bdafef692e9cd3c65342717c5f57ee3bba Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 1 Apr 2016 11:56:47 +0200 Subject: [PATCH] benp: add bnep_request_can_send_now_event() --- src/classic/bnep.c | 27 ++++++++++++++++++++++++--- src/classic/bnep.h | 11 +++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/classic/bnep.c b/src/classic/bnep.c index 8bee860d1..6d0c96924 100644 --- a/src/classic/bnep.c +++ b/src/classic/bnep.c @@ -370,7 +370,26 @@ int bnep_can_send_packet_now(uint16_t bnep_cid) return 0; } - return l2cap_can_send_packet_now(channel->l2cap_cid); + int can_send = l2cap_can_send_packet_now(channel->l2cap_cid); + + if (!can_send){ + channel->waiting_for_can_send_now = 1; + } + + return can_send; +} + +void bnep_request_can_send_now_event(uint16_t bnep_cid) +{ + bnep_channel_t *channel = bnep_channel_for_l2cap_cid(bnep_cid); + + if (!channel){ + log_error("bnep_request_can_send_now_event cid 0x%02x doesn't exist!", bnep_cid); + return; + } + + channel->waiting_for_can_send_now = 1; + l2cap_request_can_send_now_event(bnep_cid); } @@ -1477,9 +1496,11 @@ static void bnep_channel_state_machine(bnep_channel_t* channel, bnep_channel_eve return; } - /* If the event was not yet handled, notify the application layer */ - bnep_emit_ready_to_send(channel); + if (channel->waiting_for_can_send_now){ + channel->waiting_for_can_send_now = 0; + bnep_emit_ready_to_send(channel); + } } } diff --git a/src/classic/bnep.h b/src/classic/bnep.h index 8a004914e..02ca43e27 100644 --- a/src/classic/bnep.h +++ b/src/classic/bnep.h @@ -139,6 +139,9 @@ typedef struct { int retry_count; // number of retries for CONTROL SETUP MSG // l2cap packet handler btstack_packet_handler_t packet_handler; + + uint8_t waiting_for_can_send_now; + } bnep_channel_t; /* Internal BNEP service descriptor */ @@ -166,6 +169,14 @@ void bnep_init(void); */ int bnep_can_send_packet_now(uint16_t bnep_cid); +/** + * @brief Request emission of BNEP_CAN_SEND_NOW as soon as possible + * @note BNEP_CAN_SEND_NOW might be emitted during call to this function + * so packet handler should be ready to handle it + * @param bnep_cid + */ +void bnep_request_can_send_now_event(uint16_t bnep_cid); + /** * @brief Send a data packet. */