From b93f89661ecd1d19be40311be96b92932960a800 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Mon, 22 Nov 2021 10:04:47 +0100 Subject: [PATCH] l2cap: drop reason param in l2cap_disconnect --- CHANGELOG.md | 1 + platform/daemon/src/daemon.c | 5 ++--- platform/daemon/src/daemon_cmds.c | 3 +-- src/classic/avdtp.c | 4 ++-- src/classic/avdtp_initiator.c | 4 ++-- src/classic/avrcp.c | 4 ++-- src/classic/avrcp_browsing.c | 2 +- src/classic/bnep.c | 2 +- src/classic/hid_device.c | 10 +++++----- src/classic/hid_host.c | 10 +++++----- src/classic/rfcomm.c | 10 +++++----- src/classic/sdp_client.c | 4 ++-- src/l2cap.c | 12 +++++------- src/l2cap.h | 4 +++- test/l2cap-channel/l2cap_cbm_test.cpp | 4 ++-- test/l2cap-channel/l2cap_ecbm_test.cpp | 8 ++++---- test/pts/classic_test.c | 2 +- test/pts/l2cap_cbm_ecbm.c | 4 ++-- test/pts/l2cap_test.c | 2 +- test/sdp_client/mock.c | 2 +- 20 files changed, 48 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff9f5191c..8d265ab13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - L2CAP: provide status instead of undocumented int error code and bool for API functions - L2CAP: remote features not required for SDP connections - L2CAP: replaced l2cap_register_packet_handler with l2cap_add_event_handler to register multiple handlers +- L2CAP: drop reason parameter in l2cap_disconnect - L2CAP: use official terminology for L2CAP channel modes - ENABLE_L2CAP_LE_CREDIT_BASED_FLOW_CONTROL_MODE replaces ENABLE_LE_DATA_CHANNELS - RFCOMM: `RFCOMM_EVENT_PORT_CONFIGURATION` contains rfcomm_cid and remote flag, emitted for query config - RFCOMM: provide status instead of undocumented int error code and bool for API functions diff --git a/platform/daemon/src/daemon.c b/platform/daemon/src/daemon.c index 6dc9b07ab..794e33546 100644 --- a/platform/daemon/src/daemon.c +++ b/platform/daemon/src/daemon.c @@ -549,7 +549,7 @@ static void daemon_l2cap_close_connection(client_state_t * daemon_client){ btstack_linked_list_iterator_init(&it, l2cap_cids); while (btstack_linked_list_iterator_has_next(&it)){ btstack_linked_list_uint32_t * item = (btstack_linked_list_uint32_t*) btstack_linked_list_iterator_next(&it); - l2cap_disconnect(item->value, 0); // note: reason isn't used + l2cap_disconnect(item->value); btstack_linked_list_remove(l2cap_cids, (btstack_linked_item_t *) item); free(item); } @@ -985,8 +985,7 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui break; case L2CAP_DISCONNECT: cid = little_endian_read_16(packet, 3); - reason = packet[5]; - l2cap_disconnect(cid, reason); + l2cap_disconnect(cid); break; case L2CAP_REGISTER_SERVICE: psm = little_endian_read_16(packet, 3); diff --git a/platform/daemon/src/daemon_cmds.c b/platform/daemon/src/daemon_cmds.c index f714046ff..c415aa152 100644 --- a/platform/daemon/src/daemon_cmds.c +++ b/platform/daemon/src/daemon_cmds.c @@ -117,10 +117,9 @@ const hci_cmd_t l2cap_create_channel_mtu_cmd = { /** * @param channel (16) - * @param reason (16) */ const hci_cmd_t l2cap_disconnect_cmd = { - DAEMON_OPCODE_L2CAP_DISCONNECT, "21" + DAEMON_OPCODE_L2CAP_DISCONNECT, "2" }; /** diff --git a/src/classic/avdtp.c b/src/classic/avdtp.c index 6b748204b..f82aa6c82 100644 --- a/src/classic/avdtp.c +++ b/src/classic/avdtp.c @@ -1072,7 +1072,7 @@ uint8_t avdtp_disconnect(uint16_t avdtp_cid){ case AVDTP_STREAM_ENDPOINT_OPENED: case AVDTP_STREAM_ENDPOINT_STREAMING: stream_endpoint->state = AVDTP_STREAM_ENDPOINT_W4_L2CAP_FOR_MEDIA_DISCONNECTED; - l2cap_disconnect(stream_endpoint->l2cap_media_cid, 0); + l2cap_disconnect(stream_endpoint->l2cap_media_cid); break; default: break; @@ -1080,7 +1080,7 @@ uint8_t avdtp_disconnect(uint16_t avdtp_cid){ } connection->state = AVDTP_SIGNALING_CONNECTION_W4_L2CAP_DISCONNECTED; - l2cap_disconnect(connection->l2cap_signaling_cid, 0); + l2cap_disconnect(connection->l2cap_signaling_cid); return ERROR_CODE_SUCCESS; } diff --git a/src/classic/avdtp_initiator.c b/src/classic/avdtp_initiator.c index 8b18cb827..b3838d3c8 100644 --- a/src/classic/avdtp_initiator.c +++ b/src/classic/avdtp_initiator.c @@ -238,7 +238,7 @@ void avdtp_initiator_stream_config_subsm(avdtp_connection_t *connection, uint8_t case AVDTP_STREAM_ENDPOINT_STREAMING: stream_endpoint_for_event = stream_endpoint; stream_endpoint->state = AVDTP_STREAM_ENDPOINT_CLOSING; - l2cap_disconnect(stream_endpoint->l2cap_media_cid, 0); + l2cap_disconnect(stream_endpoint->l2cap_media_cid); break; default: break; @@ -256,7 +256,7 @@ void avdtp_initiator_stream_config_subsm(avdtp_connection_t *connection, uint8_t case AVDTP_STREAM_ENDPOINT_STREAMING: stream_endpoint_for_event = stream_endpoint; stream_endpoint->state = AVDTP_STREAM_ENDPOINT_ABORTING; - l2cap_disconnect(stream_endpoint->l2cap_media_cid, 0); + l2cap_disconnect(stream_endpoint->l2cap_media_cid); break; default: break; diff --git a/src/classic/avrcp.c b/src/classic/avrcp.c index 1655648ea..0f5145932 100644 --- a/src/classic/avrcp.c +++ b/src/classic/avrcp.c @@ -919,9 +919,9 @@ uint8_t avrcp_disconnect(uint16_t avrcp_cid){ return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; } if (connection_controller->browsing_connection){ - l2cap_disconnect(connection_controller->browsing_connection->l2cap_browsing_cid, 0); + l2cap_disconnect(connection_controller->browsing_connection->l2cap_browsing_cid); } - l2cap_disconnect(connection_controller->l2cap_signaling_cid, 0); + l2cap_disconnect(connection_controller->l2cap_signaling_cid); return ERROR_CODE_SUCCESS; } diff --git a/src/classic/avrcp_browsing.c b/src/classic/avrcp_browsing.c index d2ad6f682..63ca4ac0a 100644 --- a/src/classic/avrcp_browsing.c +++ b/src/classic/avrcp_browsing.c @@ -636,7 +636,7 @@ uint8_t avrcp_browsing_disconnect(uint16_t avrcp_browsing_cid){ return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; } - l2cap_disconnect(connection_controller->browsing_connection->l2cap_browsing_cid, 0); + l2cap_disconnect(connection_controller->browsing_connection->l2cap_browsing_cid); return ERROR_CODE_SUCCESS; } diff --git a/src/classic/bnep.c b/src/classic/bnep.c index b49d4b747..5a8c19b96 100644 --- a/src/classic/bnep.c +++ b/src/classic/bnep.c @@ -814,7 +814,7 @@ static void bnep_channel_finalize(bnep_channel_t *channel) /* Free ressources and then close the l2cap channel */ bnep_channel_free(channel); - l2cap_disconnect(l2cap_cid, 0x13); + l2cap_disconnect(l2cap_cid); } static int bnep_handle_connection_request(bnep_channel_t *channel, uint8_t *packet, uint16_t size) diff --git a/src/classic/hid_device.c b/src/classic/hid_device.c index 7c22e5da6..7b29d7f0f 100644 --- a/src/classic/hid_device.c +++ b/src/classic/hid_device.c @@ -963,7 +963,7 @@ void hid_device_disconnect_interrupt_channel(uint16_t hid_cid){ } log_info("Disconnect from interrupt channel HID Host"); if (hid_device->interrupt_cid){ - l2cap_disconnect(hid_device->interrupt_cid, 0); // reason isn't used + l2cap_disconnect(hid_device->interrupt_cid); } } @@ -975,7 +975,7 @@ void hid_device_disconnect_control_channel(uint16_t hid_cid){ } log_info("Disconnect from control channel HID Host"); if (hid_device->control_cid){ - l2cap_disconnect(hid_device->control_cid, 0); // reason isn't used + l2cap_disconnect(hid_device->control_cid); } } @@ -987,11 +987,11 @@ void hid_device_disconnect(uint16_t hid_cid){ } log_info("Disconnect from HID Host"); if (hid_device->interrupt_cid){ - l2cap_disconnect(hid_device->interrupt_cid, 0); // reason isn't used + l2cap_disconnect(hid_device->interrupt_cid); } if (hid_device->control_cid){ - l2cap_disconnect(hid_device->control_cid, 0); // reason isn't used - } + l2cap_disconnect(hid_device->control_cid); + } } int hid_device_in_boot_protocol_mode(uint16_t hid_cid){ diff --git a/src/classic/hid_host.c b/src/classic/hid_host.c index e95ef9550..5b4c2846d 100644 --- a/src/classic/hid_host.c +++ b/src/classic/hid_host.c @@ -368,10 +368,10 @@ static void hid_host_finalize_connection(hid_host_connection_t * connection){ connection->control_cid = 0; if (interrupt_cid != 0){ - l2cap_disconnect(interrupt_cid, 0); + l2cap_disconnect(interrupt_cid); } if (control_cid != 0){ - l2cap_disconnect(control_cid, 0); + l2cap_disconnect(control_cid); } btstack_linked_list_remove(&hid_host_connections, (btstack_linked_item_t*) connection); btstack_memory_hid_host_connection_free(connection); @@ -904,7 +904,7 @@ static void hid_host_packet_handler(uint8_t packet_type, uint16_t channel, uint8 connection->interrupt_cid = 0; if (connection->state == HID_HOST_W4_INTERRUPT_CONNECTION_DISCONNECTED){ connection->state = HID_HOST_W4_CONTROL_CONNECTION_DISCONNECTED; - l2cap_disconnect(connection->control_cid, 0); + l2cap_disconnect(connection->control_cid); } break; } @@ -1158,13 +1158,13 @@ void hid_host_disconnect(uint16_t hid_cid){ if (connection->interrupt_cid){ connection->state = HID_HOST_W4_INTERRUPT_CONNECTION_DISCONNECTED; - l2cap_disconnect(connection->interrupt_cid, 0); // reason isn't used + l2cap_disconnect(connection->interrupt_cid); return; } if (connection->control_cid){ connection->state = HID_HOST_W4_CONTROL_CONNECTION_DISCONNECTED; - l2cap_disconnect(connection->control_cid, 0); // reason isn't used + l2cap_disconnect(connection->control_cid); return; } } diff --git a/src/classic/rfcomm.c b/src/classic/rfcomm.c index bd1e848fd..b017759ba 100644 --- a/src/classic/rfcomm.c +++ b/src/classic/rfcomm.c @@ -918,7 +918,7 @@ static void rfcomm_multiplexer_timer_handler(btstack_timer_source_t *timer){ log_info("handler timeout: shutting down multiplexer! (no channels)"); uint16_t l2cap_cid = multiplexer->l2cap_cid; rfcomm_multiplexer_finalize(multiplexer); - l2cap_disconnect(l2cap_cid, 0x13); + l2cap_disconnect(l2cap_cid); } static void rfcomm_multiplexer_prepare_idle_timer(rfcomm_multiplexer_t * multiplexer){ @@ -1242,7 +1242,7 @@ static int rfcomm_multiplexer_l2cap_packet_handler(uint16_t channel, uint8_t *pa log_info("Received DM #0"); log_info("-> Closing down multiplexer"); rfcomm_multiplexer_finalize(multiplexer); - l2cap_disconnect(l2cap_cid, 0x13); + l2cap_disconnect(l2cap_cid); return 1; case BT_RFCOMM_UIH: @@ -1253,7 +1253,7 @@ static int rfcomm_multiplexer_l2cap_packet_handler(uint16_t channel, uint8_t *pa log_info("Received Multiplexer close down command"); log_info("-> Closing down multiplexer"); rfcomm_multiplexer_finalize(multiplexer); - l2cap_disconnect(l2cap_cid, 0x13); + l2cap_disconnect(l2cap_cid); return 1; } switch (packet[payload_offset]){ @@ -1262,7 +1262,7 @@ static int rfcomm_multiplexer_l2cap_packet_handler(uint16_t channel, uint8_t *pa log_info("Received Multiplexer close down command"); log_info("-> Closing down multiplexer"); rfcomm_multiplexer_finalize(multiplexer); - l2cap_disconnect(l2cap_cid, 0x13); + l2cap_disconnect(l2cap_cid); return 1; case BT_RFCOMM_FCON_CMD: @@ -1373,7 +1373,7 @@ static void rfcomm_multiplexer_state_machine(rfcomm_multiplexer_t * multiplexer, rfcomm_send_ua(multiplexer, 0); rfcomm_multiplexer_finalize(multiplexer); - l2cap_disconnect(l2cap_cid, 0x13); + l2cap_disconnect(l2cap_cid); break; case RFCOMM_MULTIPLEXER_OPEN: // respond to test command diff --git a/src/classic/sdp_client.c b/src/classic/sdp_client.c index fe6225d90..28f13fa39 100644 --- a/src/classic/sdp_client.c +++ b/src/classic/sdp_client.c @@ -464,7 +464,7 @@ void sdp_client_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p switch (sdp_client_pdu_id){ case SDP_ErrorResponse: log_error("Received error response with code %u, disconnecting", packet[2]); - l2cap_disconnect(sdp_client_sdp_cid, 0); + l2cap_disconnect(sdp_client_sdp_cid); return; #ifdef ENABLE_SDP_EXTRA_QUERIES case SDP_ServiceSearchResponse: @@ -486,7 +486,7 @@ void sdp_client_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p if (sdp_client_continuation_state_len == 0){ log_debug("SDP Client Query DONE! "); sdp_client_state = QUERY_COMPLETE; - l2cap_disconnect(sdp_client_sdp_cid, 0); + l2cap_disconnect(sdp_client_sdp_cid); return; } // prepare next request and send diff --git a/src/l2cap.c b/src/l2cap.c index 439d23a3a..9c85f2467 100644 --- a/src/l2cap.c +++ b/src/l2cap.c @@ -2459,16 +2459,14 @@ uint8_t l2cap_create_channel(btstack_packet_handler_t channel_packet_handler, bd return ERROR_CODE_SUCCESS; } -void l2cap_disconnect(uint16_t local_cid, uint8_t reason){ - log_info("disconnect local_cid 0x%x reason 0x%x", local_cid, reason); - UNUSED(reason); - // find channel for local_cid +uint8_t l2cap_disconnect(uint16_t local_cid){ l2cap_channel_t * channel = l2cap_get_channel_for_local_cid(local_cid); - if (channel) { - channel->state = L2CAP_STATE_WILL_SEND_DISCONNECT_REQUEST; + if (!channel) { + return L2CAP_LOCAL_CID_DOES_NOT_EXIST; } - // process + channel->state = L2CAP_STATE_WILL_SEND_DISCONNECT_REQUEST; l2cap_run(); + return ERROR_CODE_SUCCESS; } static void l2cap_handle_connection_failed_for_addr(bd_addr_t address, uint8_t status){ diff --git a/src/l2cap.h b/src/l2cap.h index 6d51c9512..f226113a0 100644 --- a/src/l2cap.h +++ b/src/l2cap.h @@ -501,8 +501,10 @@ uint8_t l2cap_create_channel(btstack_packet_handler_t packet_handler, bd_addr_t /** * @brief Disconnects L2CAP channel with given identifier. + * @param local_cid + * @return status ERROR_CODE_SUCCESS if successful or L2CAP_LOCAL_CID_DOES_NOT_EXIST */ -void l2cap_disconnect(uint16_t local_cid, uint8_t reason); +uint8_t l2cap_disconnect(uint16_t local_cid); /** * @brief Queries the maximal transfer unit (MTU) for L2CAP channel with given identifier. diff --git a/test/l2cap-channel/l2cap_cbm_test.cpp b/test/l2cap-channel/l2cap_cbm_test.cpp index 708684701..6fe04b0cf 100644 --- a/test/l2cap-channel/l2cap_cbm_test.cpp +++ b/test/l2cap-channel/l2cap_cbm_test.cpp @@ -199,7 +199,7 @@ TEST(L2CAP_CHANNELS, some_functions){ l2cap_cbm_unregister_service(TEST_PSM); l2cap_cbm_accept_connection(0X01, NULL, 0, 0); l2cap_cbm_decline_connection(0x01, L2CAP_CBM_CONNECTION_RESULT_NO_RESOURCES_AVAILABLE); - l2cap_cbm_disconnect(0x01); + l2cap_disconnect(0x01); } TEST(L2CAP_CHANNELS, outgoing_no_connection){ @@ -235,7 +235,7 @@ TEST(L2CAP_CHANNELS, outgoing_1){ // print_acl("le_data_channel_data_1", mock_hci_transport_outgoing_packet_buffer, mock_hci_transport_outgoing_packet_size); // simulate data mock_hci_transport_receive_packet(HCI_ACL_DATA_PACKET, le_data_channel_data_1, sizeof(le_data_channel_data_1)); - l2cap_cbm_disconnect(l2cap_cid); + l2cap_disconnect(l2cap_cid); } TEST(L2CAP_CHANNELS, incoming_1){ diff --git a/test/l2cap-channel/l2cap_ecbm_test.cpp b/test/l2cap-channel/l2cap_ecbm_test.cpp index 21b111db7..2c2e5b8f4 100644 --- a/test/l2cap-channel/l2cap_ecbm_test.cpp +++ b/test/l2cap-channel/l2cap_ecbm_test.cpp @@ -496,8 +496,8 @@ TEST(L2CAP_CHANNELS, outgoing_le_disconnect_initiator){ CHECK_EQUAL(ERROR_CODE_SUCCESS, status); mock_hci_transport_receive_packet(HCI_ACL_DATA_PACKET, l2cap_enhanced_data_channel_le_conn_response_2_success, sizeof(l2cap_enhanced_data_channel_le_conn_response_2_success)); CHECK_EQUAL(2, num_l2cap_channel_opened); - l2cap_ecbm_disconnect(l2cap_cids[0]); - l2cap_ecbm_disconnect(l2cap_cids[1]); + l2cap_disconnect(l2cap_cids[0]); + l2cap_disconnect(l2cap_cids[1]); mock_hci_transport_receive_packet(HCI_ACL_DATA_PACKET, l2cap_enhanced_data_channel_le_disconnect_response_1, sizeof(l2cap_enhanced_data_channel_le_disconnect_response_1)); mock_hci_transport_receive_packet(HCI_ACL_DATA_PACKET, l2cap_enhanced_data_channel_le_disconnect_response_2, sizeof(l2cap_enhanced_data_channel_le_disconnect_response_2)); CHECK_EQUAL(2, num_l2cap_channel_closed); @@ -524,8 +524,8 @@ TEST(L2CAP_CHANNELS, outgoing_classic_disconnect_initiator){ CHECK_EQUAL(ERROR_CODE_SUCCESS, status); mock_hci_transport_receive_packet(HCI_ACL_DATA_PACKET, l2cap_enhanced_data_channel_classic_conn_response_2_success, sizeof(l2cap_enhanced_data_channel_classic_conn_response_2_success)); CHECK_EQUAL(2, num_l2cap_channel_opened); - l2cap_ecbm_disconnect(l2cap_cids[0]); - l2cap_ecbm_disconnect(l2cap_cids[1]); + l2cap_disconnect(l2cap_cids[0]); + l2cap_disconnect(l2cap_cids[1]); mock_hci_transport_receive_packet(HCI_ACL_DATA_PACKET, l2cap_enhanced_data_channel_classic_disconnect_response_1, sizeof(l2cap_enhanced_data_channel_classic_disconnect_response_1)); mock_hci_transport_receive_packet(HCI_ACL_DATA_PACKET, l2cap_enhanced_data_channel_classic_disconnect_response_2, sizeof(l2cap_enhanced_data_channel_classic_disconnect_response_2)); CHECK_EQUAL(2, num_l2cap_channel_closed); diff --git a/test/pts/classic_test.c b/test/pts/classic_test.c index 292e325e4..871ed23c4 100644 --- a/test/pts/classic_test.c +++ b/test/pts/classic_test.c @@ -631,7 +631,7 @@ static void stdin_process(char c){ break; case 's': printf("L2CAP Channel Closed\n"); - l2cap_disconnect(local_cid, 0); + l2cap_disconnect(local_cid); break; case 'x': printf("Outgoing L2CAP Channels to SDP will also require SSP\n"); diff --git a/test/pts/l2cap_cbm_ecbm.c b/test/pts/l2cap_cbm_ecbm.c index 4615c109c..e5f625934 100644 --- a/test/pts/l2cap_cbm_ecbm.c +++ b/test/pts/l2cap_cbm_ecbm.c @@ -514,10 +514,10 @@ static void stdin_process(char buffer){ case 't': if (enhanced_data_channel){ printf("Disconnect channel 0x%02x\n", cid_enhanced); - l2cap_ecbm_disconnect(cid_enhanced); + l2cap_disconnect(cid_enhanced); } else { printf("Disconnect channel 0x%02x\n", cid_le); - l2cap_cbm_disconnect(cid_le); + l2cap_disconnect(cid_le); } break; diff --git a/test/pts/l2cap_test.c b/test/pts/l2cap_test.c index 2bcf0fc13..b0a0dd3e6 100644 --- a/test/pts/l2cap_test.c +++ b/test/pts/l2cap_test.c @@ -196,7 +196,7 @@ static void stdin_process(char buffer){ break; case 'd': printf("L2CAP Channel Closed\n"); - l2cap_disconnect(local_cid, 0); + l2cap_disconnect(local_cid); break; case 'e': printf("L2CAP Enhanced Retransmission Mode (ERTM) optional\n"); diff --git a/test/sdp_client/mock.c b/test/sdp_client/mock.c index 5d3a8eac4..a7a47533d 100644 --- a/test/sdp_client/mock.c +++ b/test/sdp_client/mock.c @@ -21,7 +21,7 @@ extern "C" uint8_t l2cap_create_channel(btstack_packet_handler_t handler, bd_add packet_handler = handler; return 0x41; } -extern "C" void l2cap_disconnect(uint16_t local_cid, uint8_t reason){ +extern "C" void l2cap_disconnect(uint16_t local_cid){ } extern "C" uint8_t *l2cap_get_outgoing_buffer(void){ return NULL;