From a449c50a6887c2b545b3354297c8d9ce09d91c94 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 5 Jan 2016 17:21:16 +0100 Subject: [PATCH] remove hand out credit code in l2cap/rfcomm. --- platform/daemon/src/daemon.c | 55 ++++++++++++++++++++++++++++++++++++ src/classic/rfcomm.c | 49 +------------------------------- src/l2cap.c | 32 --------------------- 3 files changed, 56 insertions(+), 80 deletions(-) diff --git a/platform/daemon/src/daemon.c b/platform/daemon/src/daemon.c index a1e1be2ef..59aa23d46 100644 --- a/platform/daemon/src/daemon.c +++ b/platform/daemon/src/daemon.c @@ -197,6 +197,61 @@ static void * sdp_client_query_connection; static int loggingEnabled; +// stashed code from l2cap.c and rfcomm.c -- needed for new implementation +#if 0 +static void l2cap_emit_credits(l2cap_channel_t *channel, uint8_t credits) { + + log_info("L2CAP_EVENT_CREDITS local_cid 0x%x credits %u", channel->local_cid, credits); + + uint8_t event[5]; + event[0] = L2CAP_EVENT_CREDITS; + event[1] = sizeof(event) - 2; + bt_store_16(event, 2, channel->local_cid); + event[4] = credits; + hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); + l2cap_dispatch(channel, HCI_EVENT_PACKET, event, sizeof(event)); +} + +static void l2cap_hand_out_credits(void){ + linked_list_iterator_t it; + linked_list_iterator_init(&it, &l2cap_channels); + while (linked_list_iterator_has_next(&it)){ + l2cap_channel_t * channel = (l2cap_channel_t *) linked_list_iterator_next(&it); + if (channel->state != L2CAP_STATE_OPEN) continue; + if (!hci_number_free_acl_slots_for_handle(channel->handle)) return; + l2cap_emit_credits(channel, 1); + } +} +static void rfcomm_emit_credits(rfcomm_channel_t * channel, uint8_t credits) { + log_info("RFCOMM_EVENT_CREDITS cid 0x%02x credits %u", channel->rfcomm_cid, credits); + uint8_t event[5]; + event[0] = RFCOMM_EVENT_CREDITS; + event[1] = sizeof(event) - 2; + bt_store_16(event, 2, channel->rfcomm_cid); + event[4] = credits; + hci_dump_packet(HCI_EVENT_PACKET, 0, event, sizeof(event)); + (*app_packet_handler)(HCI_EVENT_PACKET, 0, (uint8_t *) event, sizeof(event)); +} +static void rfcomm_hand_out_credits(void){ + linked_item_t * it; + for (it = (linked_item_t *) rfcomm_channels; it ; it = it->next){ + rfcomm_channel_t * channel = (rfcomm_channel_t *) it; + if (channel->state != RFCOMM_CHANNEL_OPEN) { + // log_info("RFCOMM_EVENT_CREDITS: multiplexer not open"); + continue; + } + if (!channel->credits_outgoing) { + // log_info("RFCOMM_EVENT_CREDITS: no outgoing credits"); + continue; + } + // channel open, multiplexer has l2cap credits and we didn't hand out credit before -> go! + // log_info("RFCOMM_EVENT_CREDITS: 1"); + rfcomm_emit_credits(channel, 1); + } +} + +#endif + static void dummy_bluetooth_status_handler(BLUETOOTH_STATE state){ log_info("Bluetooth status: %u\n", state); }; diff --git a/src/classic/rfcomm.c b/src/classic/rfcomm.c index 3145f173d..f5e44312a 100644 --- a/src/classic/rfcomm.c +++ b/src/classic/rfcomm.c @@ -88,7 +88,6 @@ static void (*app_packet_handler)(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); static void rfcomm_run(void); -static void rfcomm_hand_out_credits(void); static void rfcomm_channel_state_machine(rfcomm_channel_t *channel, rfcomm_channel_event_t *event); static void rfcomm_channel_state_machine_2(rfcomm_multiplexer_t * multiplexer, uint8_t dlci, rfcomm_channel_event_t *event); static int rfcomm_channel_ready_for_open(rfcomm_channel_t *channel); @@ -144,17 +143,6 @@ static void rfcomm_emit_channel_closed(rfcomm_channel_t * channel) { (*app_packet_handler)(HCI_EVENT_PACKET, 0, (uint8_t *) event, sizeof(event)); } -static void rfcomm_emit_credits(rfcomm_channel_t * channel, uint8_t credits) { - log_info("RFCOMM_EVENT_CREDITS cid 0x%02x credits %u", channel->rfcomm_cid, credits); - uint8_t event[5]; - event[0] = RFCOMM_EVENT_CREDITS; - event[1] = sizeof(event) - 2; - bt_store_16(event, 2, channel->rfcomm_cid); - event[4] = credits; - hci_dump_packet(HCI_EVENT_PACKET, 0, event, sizeof(event)); - (*app_packet_handler)(HCI_EVENT_PACKET, 0, (uint8_t *) event, sizeof(event)); -} - static void rfcomm_emit_remote_line_status(rfcomm_channel_t *channel, uint8_t line_status){ log_info("RFCOMM_EVENT_REMOTE_LINE_STATUS cid 0x%02x c, line status 0x%x", channel->rfcomm_cid, line_status); uint8_t event[5]; @@ -877,18 +865,6 @@ static int rfcomm_multiplexer_hci_event_handler(uint8_t *packet, uint16_t size){ return 1; // l2cap disconnect -> state = RFCOMM_MULTIPLEXER_CLOSED; - - case L2CAP_EVENT_CREDITS: - // data: event(8), len(8), local_cid(16), credits(8) - l2cap_cid = READ_BT_16(packet, 2); - multiplexer = rfcomm_multiplexer_for_l2cap_cid(l2cap_cid); - if (!multiplexer) break; - - rfcomm_run(); - - if (multiplexer->state != RFCOMM_MULTIPLEXER_OPEN) break; - rfcomm_hand_out_credits(); - return 1; case DAEMON_EVENT_HCI_PACKET_SENT: // testing DMA done code @@ -1117,24 +1093,6 @@ static void rfcomm_multiplexer_state_machine(rfcomm_multiplexer_t * multiplexer, // MARK: RFCOMM CHANNEL -static void rfcomm_hand_out_credits(void){ - linked_item_t * it; - for (it = (linked_item_t *) rfcomm_channels; it ; it = it->next){ - rfcomm_channel_t * channel = (rfcomm_channel_t *) it; - if (channel->state != RFCOMM_CHANNEL_OPEN) { - // log_info("RFCOMM_EVENT_CREDITS: multiplexer not open"); - continue; - } - if (!channel->credits_outgoing) { - // log_info("RFCOMM_EVENT_CREDITS: no outgoing credits"); - continue; - } - // channel open, multiplexer has l2cap credits and we didn't hand out credit before -> go! - // log_info("RFCOMM_EVENT_CREDITS: 1"); - rfcomm_emit_credits(channel, 1); - } -} - 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; @@ -1147,7 +1105,6 @@ static void rfcomm_channel_opened(rfcomm_channel_t *rfChannel){ rfChannel->state = RFCOMM_CHANNEL_OPEN; rfcomm_emit_channel_opened(rfChannel, 0); rfcomm_emit_port_configuration(rfChannel); - rfcomm_hand_out_credits(); // remove (potential) timer rfcomm_multiplexer_t *multiplexer = rfChannel->multiplexer; @@ -1203,8 +1160,6 @@ static void rfcomm_channel_packet_handler_uih(rfcomm_multiplexer_t *multiplexer, if (!channel->incoming_flow_control && channel->credits_incoming < 5){ channel->new_credits_incoming =RFCOMM_CREDITS; } - // we received new RFCOMM credits, hand them out if possible - rfcomm_hand_out_credits(); } static void rfcomm_channel_accept_pn(rfcomm_channel_t *channel, rfcomm_channel_event_pn_t *event){ @@ -1982,9 +1937,7 @@ int rfcomm_send_prepared(uint16_t rfcomm_cid, uint16_t len){ log_info("rfcomm_send_internal: error %d", result); return result; } - - rfcomm_hand_out_credits(); - + return result; } diff --git a/src/l2cap.c b/src/l2cap.c index da3518ca1..fa8b28a25 100644 --- a/src/l2cap.c +++ b/src/l2cap.c @@ -187,30 +187,6 @@ static void l2cap_emit_connection_parameter_update_response(uint16_t handle, uin (*packet_handler)(HCI_EVENT_PACKET, 0, event, sizeof(event)); } -static void l2cap_emit_credits(l2cap_channel_t *channel, uint8_t credits) { - - log_info("L2CAP_EVENT_CREDITS local_cid 0x%x credits %u", channel->local_cid, credits); - - uint8_t event[5]; - event[0] = L2CAP_EVENT_CREDITS; - event[1] = sizeof(event) - 2; - bt_store_16(event, 2, channel->local_cid); - event[4] = credits; - hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); - l2cap_dispatch(channel, HCI_EVENT_PACKET, event, sizeof(event)); -} - -static void l2cap_hand_out_credits(void){ - linked_list_iterator_t it; - linked_list_iterator_init(&it, &l2cap_channels); - while (linked_list_iterator_has_next(&it)){ - l2cap_channel_t * channel = (l2cap_channel_t *) linked_list_iterator_next(&it); - if (channel->state != L2CAP_STATE_OPEN) continue; - if (!hci_number_free_acl_slots_for_handle(channel->handle)) return; - l2cap_emit_credits(channel, 1); - } -} - static l2cap_channel_t * l2cap_get_channel_for_local_cid(uint16_t local_cid){ linked_list_iterator_t it; linked_list_iterator_init(&it, &l2cap_channels); @@ -391,8 +367,6 @@ int l2cap_send_prepared(uint16_t local_cid, uint16_t len){ // send int err = hci_send_acl_packet_buffer(len+8); - l2cap_hand_out_credits(); - return err; } @@ -425,8 +399,6 @@ int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t l // send int err = hci_send_acl_packet_buffer(len+8); - l2cap_hand_out_credits(); - return err; } @@ -648,7 +620,6 @@ static void l2cap_run(void){ if (l2cap_channel_ready_for_open(channel)){ channel->state = L2CAP_STATE_OPEN; l2cap_emit_channel_opened(channel, 0); // success - l2cap_emit_credits(channel, 1); } break; @@ -898,7 +869,6 @@ static void l2cap_event_handler(uint8_t *packet, uint16_t size){ case HCI_EVENT_NUMBER_OF_COMPLETED_PACKETS: l2cap_run(); // try sending signaling packets first - l2cap_hand_out_credits(); break; // HCI Connection Timeouts @@ -921,7 +891,6 @@ static void l2cap_event_handler(uint8_t *packet, uint16_t size){ case DAEMON_EVENT_HCI_PACKET_SENT: l2cap_run(); // try sending signaling packets first - l2cap_hand_out_credits(); linked_list_iterator_init(&it, &l2cap_channels); while (linked_list_iterator_has_next(&it)){ @@ -1256,7 +1225,6 @@ static void l2cap_signaling_handler_channel(l2cap_channel_t *channel, uint8_t *c // for open: channel->state = L2CAP_STATE_OPEN; l2cap_emit_channel_opened(channel, 0); - l2cap_emit_credits(channel, 1); } break;