From 8ee7c9dadd27719c0c89757fa8a8c2a93e6fa0c0 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Tue, 19 May 2020 11:01:06 +0200 Subject: [PATCH] avrcp browsing: move disconnect to AVRCP API --- example/avrcp_browsing_client.c | 53 ++++++++++++------------- src/classic/avrcp.c | 25 ++++++++---- src/classic/avrcp.h | 3 +- src/classic/avrcp_browsing_controller.c | 4 -- src/classic/avrcp_browsing_controller.h | 8 ---- src/classic/avrcp_browsing_target.c | 4 -- 6 files changed, 44 insertions(+), 53 deletions(-) diff --git a/example/avrcp_browsing_client.c b/example/avrcp_browsing_client.c index 22787f2fe..f3c3424a9 100644 --- a/example/avrcp_browsing_client.c +++ b/example/avrcp_browsing_client.c @@ -369,7 +369,7 @@ static void avrcp_browsing_packet_handler(uint8_t packet_type, uint16_t channel, } default: - log_error("AVRCP browsing: unknown browsable item type 0%02x", data_type); + log_error("AVRCP Browsing: unknown browsable item type 0%02x", data_type); break; } break; @@ -386,12 +386,12 @@ static void avrcp_browsing_packet_handler(uint8_t packet_type, uint16_t channel, local_cid = avrcp_subevent_incoming_browsing_connection_get_browsing_cid(packet); printf("AVRCP_SUBEVENT_INCOMING_BROWSING_CONNECTION cid 0x%02x\n", local_cid); if (browsing_cid != 0 && browsing_cid != local_cid) { - printf("AVRCP Browsing Client connection failed, expected 0x%02X l2cap cid, received 0x%02X\n", browsing_cid, local_cid); + printf("AVRCP Browsing: connection failed, expected 0x%02X l2cap cid, received 0x%02X\n", browsing_cid, local_cid); avrcp_browsing_decline_incoming_connection(browsing_cid); return; } browsing_cid = local_cid; - printf("AVRCP Browsing Client configure incoming connection, browsing cid 0x%02x\n", browsing_cid); + printf("AVRCP Browsing: configure incoming connection, browsing cid 0x%02x\n", browsing_cid); avrcp_browsing_configure_incoming_connection(browsing_cid, ertm_buffer, sizeof(ertm_buffer), &ertm_config); break; @@ -399,13 +399,13 @@ static void avrcp_browsing_packet_handler(uint8_t packet_type, uint16_t channel, local_cid = avrcp_subevent_browsing_connection_established_get_browsing_cid(packet); printf("AVRCP_SUBEVENT_BROWSING_CONNECTION_ESTABLISHED cid 0x%02x\n", local_cid); if (browsing_cid != 0 && browsing_cid != local_cid) { - printf("AVRCP Browsing Client connection failed, expected 0x%02X l2cap cid, received 0x%02X\n", browsing_cid, local_cid); + printf("AVRCP Browsing: connection failed, expected 0x%02X l2cap cid, received 0x%02X\n", browsing_cid, local_cid); return; } status = avrcp_subevent_browsing_connection_established_get_status(packet); if (status != ERROR_CODE_SUCCESS){ - printf("AVRCP Browsing Client connection failed: status 0x%02x\n", status); + printf("AVRCP Browsing: connection failed: status 0x%02x\n", status); browsing_cid = 0; return; } @@ -413,11 +413,11 @@ static void avrcp_browsing_packet_handler(uint8_t packet_type, uint16_t channel, browsing_cid = local_cid; avrcp_browsing_connected = 1; avrcp_subevent_browsing_connection_established_get_bd_addr(packet, address); - printf("AVRCP Browsing Client connected\n"); + printf("AVRCP Browsing: connected\n"); return; } case AVRCP_SUBEVENT_BROWSING_CONNECTION_RELEASED: - printf("AVRCP Browsing Controller released\n"); + printf("AVRCP Browsing: disconnected\n"); browsing_cid = 0; avrcp_browsing_connected = 0; return; @@ -426,13 +426,13 @@ static void avrcp_browsing_packet_handler(uint8_t packet_type, uint16_t channel, browsing_query_active = false; browsing_uid_counter = 0; if (avrcp_subevent_browsing_done_get_browsing_status(packet) != AVRCP_BROWSING_ERROR_CODE_SUCCESS){ - printf("AVRCP Browsing query done with browsing status 0x%02x, bluetooth status 0x%02x.\n", + printf("AVRCP Browsing: query done with browsing status 0x%02x, bluetooth status 0x%02x\n", avrcp_subevent_browsing_done_get_browsing_status(packet), avrcp_subevent_browsing_done_get_bluetooth_status(packet)); break; } browsing_uid_counter = avrcp_subevent_browsing_done_get_uid_counter(packet); - printf("DONE, browsing_uid_counter %d.\n", browsing_uid_counter); + printf("AVRCP Browsing: browsing_uid_counter %d\n", browsing_uid_counter); break; default: @@ -450,11 +450,11 @@ static void avrcp_browsing_packet_handler(uint8_t packet_type, uint16_t channel, static void show_usage(void){ bd_addr_t iut_address; gap_local_bd_addr(iut_address); - printf("\n--- Bluetooth AVRCP Controller Connection Test Console %s ---\n", bd_addr_to_str(iut_address)); - printf("c - AVRCP create connection to addr %s\n", bd_addr_to_str(device_addr)); - printf("C - AVRCP disconnect\n"); - printf("e - AVRCP Browsing Controller create connection to addr %s\n", bd_addr_to_str(device_addr)); - printf("E - AVRCP Browsing Controller disconnect\n"); + printf("\n--- Bluetooth AVRCP Browsing Service Test Console %s ---\n", bd_addr_to_str(iut_address)); + printf("c - AVRCP Service create connection to addr %s\n", bd_addr_to_str(device_addr)); + printf("C - AVRCP Service disconnect\n"); + printf("e - AVRCP Browsing Service create connection to addr %s\n", bd_addr_to_str(device_addr)); + printf("E - AVRCP Browsing Service disconnect\n"); printf("I - Set first found player as addressed player\n"); printf("O - Set first found player as browsed player\n"); @@ -482,33 +482,33 @@ static void stdin_process(char cmd){ switch (cmd){ case 'c': - printf(" - Create AVRCP connection for control to addr %s.\n", bd_addr_to_str(device_addr)); + printf(" - Connect to AVRCP Service on addr %s.\n", bd_addr_to_str(device_addr)); status = avrcp_connect(device_addr, &avrcp_cid); break; case 'C': if (avrcp_connected){ - printf(" - AVRCP disconnect from addr %s.\n", bd_addr_to_str(device_addr)); + printf(" - AVRCP Service disconnect from addr %s.\n", bd_addr_to_str(device_addr)); status = avrcp_disconnect(avrcp_cid); break; } - printf("AVRCP service already disconnected\n"); + printf("AVRCP Service already disconnected\n"); break; case 'e': if (!avrcp_connected) { - printf(" You must first create AVRCP connection for control to addr %s.\n", bd_addr_to_str(device_addr)); + printf(" You must first connect to AVRCP Service on addr %s.\n", bd_addr_to_str(device_addr)); break; } - printf(" - Create AVRCP connection for browsing to addr %s.\n", bd_addr_to_str(device_addr)); + printf(" - Connect to AVRCP Browsing Service at addr %s.\n", bd_addr_to_str(device_addr)); status = avrcp_browsing_connect(device_addr, ertm_buffer, sizeof(ertm_buffer), &ertm_config, &browsing_cid); break; case 'E': if (avrcp_browsing_connected){ - printf(" - AVRCP Browsing Controller disconnect from addr %s.\n", bd_addr_to_str(device_addr)); - status = avrcp_browsing_controller_disconnect(browsing_cid); + printf(" - AVRCP Browsing Service disconnect from addr %s.\n", bd_addr_to_str(device_addr)); + status = avrcp_browsing_disconnect(browsing_cid); break; } - printf("AVRCP Browsing Controller already disconnected\n"); + printf("AVRCP Browsing Service already disconnected\n"); break; case '\n': case '\r': @@ -517,22 +517,21 @@ static void stdin_process(char cmd){ default: if (!avrcp_browsing_connected){ show_usage(); - printf("Please connect the AVRCP Browsing client\n"); break; } switch (cmd) { case 'I': if (player_index < 0) { - printf("Get media players first\n"); + printf("AVRCP Browsing:Get media players first\n"); break; } - printf("Set addressed player\n"); + printf("AVRCP Browsing:Set addressed player\n"); status = avrcp_controller_set_addressed_player(avrcp_cid, players[0]); break; case 'O': if (player_index < 0) { - printf("Get media players first\n"); + printf("AVRCP Browsing:Get media players first\n"); break; } printf("Set browsed player\n"); @@ -579,7 +578,7 @@ static void stdin_process(char cmd){ } if (status != ERROR_CODE_SUCCESS){ - printf("Could not perform command, status 0x%2x\n", status); + printf("AVRCP Browsing: Could not perform command, status 0x%2x\n", status); } } #endif diff --git a/src/classic/avrcp.c b/src/classic/avrcp.c index 8de2146dd..1c8c2b739 100644 --- a/src/classic/avrcp.c +++ b/src/classic/avrcp.c @@ -1272,7 +1272,7 @@ uint8_t avrcp_browsing_configure_incoming_connection(uint16_t avrcp_browsing_cid if (!connection_controller->browsing_connection){ return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; } - if (!connection_controller->browsing_connection){ + if (!connection_target->browsing_connection){ return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; } @@ -1307,7 +1307,7 @@ uint8_t avrcp_browsing_decline_incoming_connection(uint16_t avrcp_browsing_cid){ if (!connection_controller->browsing_connection){ return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; } - if (!connection_controller->browsing_connection){ + if (!connection_target->browsing_connection){ return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; } @@ -1322,15 +1322,24 @@ uint8_t avrcp_browsing_decline_incoming_connection(uint16_t avrcp_browsing_cid){ return ERROR_CODE_SUCCESS; } -uint8_t avrcp_browsing_disconnect(uint16_t avrcp_browsing_cid, avrcp_role_t avrcp_role){ - avrcp_connection_t * avrcp_connection = get_avrcp_connection_for_browsing_cid_for_role(avrcp_role, avrcp_browsing_cid); - if (!avrcp_connection){ - log_error("Could not find a connection."); +uint8_t avrcp_browsing_disconnect(uint16_t avrcp_browsing_cid){ + avrcp_connection_t * connection_controller = get_avrcp_connection_for_browsing_cid_for_role(AVRCP_CONTROLLER, avrcp_browsing_cid); + if (!connection_controller){ + return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; + } + avrcp_connection_t * connection_target = get_avrcp_connection_for_browsing_cid_for_role(AVRCP_TARGET, avrcp_browsing_cid); + if (!connection_target){ return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; } - if (avrcp_connection->browsing_connection->state != AVCTP_CONNECTION_OPENED) return ERROR_CODE_COMMAND_DISALLOWED; - l2cap_disconnect(avrcp_connection->browsing_connection->l2cap_browsing_cid, 0); + if (!connection_controller->browsing_connection){ + return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; + } + if (!connection_target->browsing_connection){ + return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; + } + + l2cap_disconnect(connection_controller->browsing_connection->l2cap_browsing_cid, 0); return ERROR_CODE_SUCCESS; } diff --git a/src/classic/avrcp.h b/src/classic/avrcp.h index f0ffb2eca..2cf804f7c 100644 --- a/src/classic/avrcp.h +++ b/src/classic/avrcp.h @@ -642,10 +642,9 @@ uint8_t avrcp_browsing_decline_incoming_connection(uint16_t avrcp_browsing_cid); /** * @brief Disconnect from AVRCP Browsing service * @param avrcp_browsing_cid - * @param avrcp_role * @returns status */ -uint8_t avrcp_browsing_disconnect(uint16_t avrcp_browsing_cid, avrcp_role_t avrcp_role); +uint8_t avrcp_browsing_disconnect(uint16_t avrcp_browsing_cid); /* API_END */ diff --git a/src/classic/avrcp_browsing_controller.c b/src/classic/avrcp_browsing_controller.c index b07dc9e29..d8ae45b44 100644 --- a/src/classic/avrcp_browsing_controller.c +++ b/src/classic/avrcp_browsing_controller.c @@ -515,10 +515,6 @@ void avrcp_browsing_controller_register_packet_handler(btstack_packet_handler_t avrcp_controller_context.browsing_avrcp_callback = callback; } -uint8_t avrcp_browsing_controller_disconnect(uint16_t avrcp_browsing_cid){ - return avrcp_browsing_disconnect(avrcp_browsing_cid, AVRCP_CONTROLLER); -} - uint8_t avrcp_browsing_controller_get_item_attributes_for_scope(uint16_t avrcp_browsing_cid, uint8_t * uid, uint16_t uid_counter, uint32_t attr_bitmap, avrcp_browsing_scope_t scope){ avrcp_connection_t * avrcp_connection = get_avrcp_connection_for_browsing_cid_for_role(AVRCP_CONTROLLER, avrcp_browsing_cid); if (!avrcp_connection){ diff --git a/src/classic/avrcp_browsing_controller.h b/src/classic/avrcp_browsing_controller.h index e2e03c8e3..e7073be49 100644 --- a/src/classic/avrcp_browsing_controller.h +++ b/src/classic/avrcp_browsing_controller.h @@ -109,14 +109,6 @@ void avrcp_browsing_controller_init(void); */ void avrcp_browsing_controller_register_packet_handler(btstack_packet_handler_t callback); - -/** - * @brief Disconnect from AVRCP target - * @param avrcp_browsing_cid - * @returns status - */ -uint8_t avrcp_browsing_controller_disconnect(uint16_t avrcp_browsing_cid); - /** * @brief Retrieve a list of media players. * @param avrcp_browsing_cid diff --git a/src/classic/avrcp_browsing_target.c b/src/classic/avrcp_browsing_target.c index 65e94afcc..be24215be 100644 --- a/src/classic/avrcp_browsing_target.c +++ b/src/classic/avrcp_browsing_target.c @@ -212,10 +212,6 @@ void avrcp_browsing_target_register_packet_handler(btstack_packet_handler_t call avrcp_target_context.browsing_avrcp_callback = callback; } -uint8_t avrcp_browsing_target_disconnect(uint16_t avrcp_browsing_cid){ - return avrcp_browsing_disconnect(avrcp_browsing_cid, AVRCP_TARGET); -} - uint8_t avrcp_subevent_browsing_get_folder_items_response(uint16_t avrcp_browsing_cid, uint16_t uid_counter, uint8_t * attr_list, uint16_t attr_list_size){ avrcp_connection_t * avrcp_connection = get_avrcp_connection_for_browsing_cid_for_role(AVRCP_TARGET, avrcp_browsing_cid); if (!avrcp_connection){