add provisions to log rfcomm credit handling, don't decrease incoming credits on incoming empty frames

This commit is contained in:
matthias.ringwald 2011-11-14 19:22:35 +00:00
parent fbe3c26d42
commit cafaaa77eb

View File

@ -95,6 +95,8 @@
#include "l2cap.h"
// used for debugging
// #define RFCOMM_LOG_CREDITS
// global rfcomm data
static uint16_t rfcomm_client_cid_generator; // used for client channel IDs
@ -163,6 +165,19 @@ static void rfcomm_emit_channel_open_failed_outgoing_memory(void * connection, b
(*app_packet_handler)(connection, HCI_EVENT_PACKET, 0, (uint8_t *) event, pos);
}
// data: event(8), len(8), creidts incoming(8), new credits incoming(8), credits outgoing(8)
static inline void rfcomm_emit_credit_status(rfcomm_channel_t * channel) {
#ifdef RFCOMM_LOG_CREDITS
uint8_t event[5];
event[0] = 0x88;
event[1] = sizeof(event) - 2;
event[2] = channel->credits_incoming;
event[3] = channel->new_credits_incoming;
event[4] = channel->credits_outgoing;
hci_dump_packet(HCI_EVENT_PACKET, 0, event, sizeof(event));
#endif
}
// data: event(8), len(8), rfcomm_cid(16)
static void rfcomm_emit_channel_closed(rfcomm_channel_t * channel) {
uint8_t event[4];
@ -907,6 +922,8 @@ static void rfcomm_hand_out_credits(void){
static void rfcomm_channel_send_credits(rfcomm_channel_t *channel, uint8_t credits){
rfcomm_send_uih_credits(channel->multiplexer, channel->dlci, credits);
channel->credits_incoming += credits;
rfcomm_emit_credit_status(channel);
}
static void rfcomm_channel_opened(rfcomm_channel_t *rfChannel){
@ -952,14 +969,17 @@ static void rfcomm_channel_packet_handler_uih(rfcomm_multiplexer_t *multiplexer,
rfcomm_channel_state_machine(channel, &channel_event);
}
// decrease incoming credit counter
if (channel->credits_incoming > 0){
channel->credits_incoming--;
}
// deliver payload
if (size - 1 > payload_offset){ // don't send empty frames, -1 for header checksum at end
// log_info( "RFCOMM data UIH_PF, size %u, channel %x\n", size-payload_offset-1, (int) rfChannel->connection);
// contains payload?
if (size - 1 > payload_offset){
// log_info( "RFCOMM data UIH_PF, size %u, channel %p\n", size-payload_offset-1, rfChannel->connection);
// decrease incoming credit counter
if (channel->credits_incoming > 0){
channel->credits_incoming--;
}
// deliver payload
(*app_packet_handler)(channel->connection, RFCOMM_DATA_PACKET, channel->rfcomm_cid,
&packet[payload_offset], size-payload_offset-1);
}
@ -969,6 +989,8 @@ static void rfcomm_channel_packet_handler_uih(rfcomm_multiplexer_t *multiplexer,
channel->new_credits_incoming = 0x30;
}
rfcomm_emit_credit_status(channel);
// we received new RFCOMM credits, hand them out if possible
rfcomm_hand_out_credits();
}