From 63274943dc2f677232eb422a237a7be72c3669d0 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Tue, 17 Dec 2019 15:21:50 +0100 Subject: [PATCH] avdtp: introduce is_initiator param in accept and reject events --- src/btstack_defines.h | 11 +++++++---- src/btstack_event.h | 33 ++++++++++++++++++++++++++++++--- src/classic/a2dp_source.c | 2 +- src/classic/avdtp.c | 11 ++++++++--- src/classic/avdtp_acceptor.c | 9 +++------ src/classic/avdtp_initiator.c | 10 +++++----- src/classic/avdtp_util.c | 15 +++++++++------ src/classic/avdtp_util.h | 6 +++--- 8 files changed, 66 insertions(+), 31 deletions(-) diff --git a/src/btstack_defines.h b/src/btstack_defines.h index e71691acb..789b2ce41 100644 --- a/src/btstack_defines.h +++ b/src/btstack_defines.h @@ -1674,28 +1674,31 @@ typedef uint8_t sm_key_t[16]; /** AVDTP Subevent */ /** - * @format 1211 + * @format 12111 * @param subevent_code * @param avdtp_cid * @param local_seid + * @param is_initiator * @param signal_identifier */ #define AVDTP_SUBEVENT_SIGNALING_ACCEPT 0x01 /** - * @format 1211 + * @format 12111 * @param subevent_code * @param avdtp_cid - * @param local_seid + * @param local_seid + * @param is_initiator * @param signal_identifier */ #define AVDTP_SUBEVENT_SIGNALING_REJECT 0x02 /** - * @format 1211 + * @format 12111 * @param subevent_code * @param avdtp_cid * @param local_seid + * @param is_initiator * @param signal_identifier */ #define AVDTP_SUBEVENT_SIGNALING_GENERAL_REJECT 0x03 diff --git a/src/btstack_event.h b/src/btstack_event.h index c330aa528..b74afdd1c 100644 --- a/src/btstack_event.h +++ b/src/btstack_event.h @@ -4284,6 +4284,15 @@ static inline uint16_t avdtp_subevent_signaling_accept_get_avdtp_cid(const uint8 static inline uint8_t avdtp_subevent_signaling_accept_get_local_seid(const uint8_t * event){ return event[5]; } +/** + * @brief Get field is_initiator from event AVDTP_SUBEVENT_SIGNALING_ACCEPT + * @param event packet + * @return is_initiator + * @note: btstack_type 1 + */ +static inline uint8_t avdtp_subevent_signaling_accept_get_is_initiator(const uint8_t * event){ + return event[6]; +} /** * @brief Get field signal_identifier from event AVDTP_SUBEVENT_SIGNALING_ACCEPT * @param event packet @@ -4291,7 +4300,7 @@ static inline uint8_t avdtp_subevent_signaling_accept_get_local_seid(const uint8 * @note: btstack_type 1 */ static inline uint8_t avdtp_subevent_signaling_accept_get_signal_identifier(const uint8_t * event){ - return event[6]; + return event[7]; } /** @@ -4312,6 +4321,15 @@ static inline uint16_t avdtp_subevent_signaling_reject_get_avdtp_cid(const uint8 static inline uint8_t avdtp_subevent_signaling_reject_get_local_seid(const uint8_t * event){ return event[5]; } +/** + * @brief Get field is_initiator from event AVDTP_SUBEVENT_SIGNALING_REJECT + * @param event packet + * @return is_initiator + * @note: btstack_type 1 + */ +static inline uint8_t avdtp_subevent_signaling_reject_get_is_initiator(const uint8_t * event){ + return event[6]; +} /** * @brief Get field signal_identifier from event AVDTP_SUBEVENT_SIGNALING_REJECT * @param event packet @@ -4319,7 +4337,7 @@ static inline uint8_t avdtp_subevent_signaling_reject_get_local_seid(const uint8 * @note: btstack_type 1 */ static inline uint8_t avdtp_subevent_signaling_reject_get_signal_identifier(const uint8_t * event){ - return event[6]; + return event[7]; } /** @@ -4340,6 +4358,15 @@ static inline uint16_t avdtp_subevent_signaling_general_reject_get_avdtp_cid(con static inline uint8_t avdtp_subevent_signaling_general_reject_get_local_seid(const uint8_t * event){ return event[5]; } +/** + * @brief Get field is_initiator from event AVDTP_SUBEVENT_SIGNALING_GENERAL_REJECT + * @param event packet + * @return is_initiator + * @note: btstack_type 1 + */ +static inline uint8_t avdtp_subevent_signaling_general_reject_get_is_initiator(const uint8_t * event){ + return event[6]; +} /** * @brief Get field signal_identifier from event AVDTP_SUBEVENT_SIGNALING_GENERAL_REJECT * @param event packet @@ -4347,7 +4374,7 @@ static inline uint8_t avdtp_subevent_signaling_general_reject_get_local_seid(con * @note: btstack_type 1 */ static inline uint8_t avdtp_subevent_signaling_general_reject_get_signal_identifier(const uint8_t * event){ - return event[6]; + return event[7]; } /** diff --git a/src/classic/a2dp_source.c b/src/classic/a2dp_source.c index 130702bfa..fec168407 100644 --- a/src/classic/a2dp_source.c +++ b/src/classic/a2dp_source.c @@ -397,7 +397,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe // TODO check cid signal_identifier = avdtp_subevent_signaling_accept_get_signal_identifier(packet); cid = avdtp_subevent_signaling_accept_get_avdtp_cid(packet); - log_info("A2DP cmd %s accepted , cid 0x%2x, local seid %d, active remote seid %d", avdtp_si2str(signal_identifier), cid, avdtp_subevent_signaling_accept_get_local_seid(packet), sc.active_remote_sep->seid); + log_info("A2DP cmd %s accepted , cid 0x%2x, local seid %d", avdtp_si2str(signal_identifier), cid, avdtp_subevent_signaling_accept_get_local_seid(packet)); switch (app_state){ case A2DP_W2_GET_CAPABILITIES: diff --git a/src/classic/avdtp.c b/src/classic/avdtp.c index 8804dbde1..560703e79 100644 --- a/src/classic/avdtp.c +++ b/src/classic/avdtp.c @@ -96,11 +96,16 @@ void avdtp_configuration_timeout_handler(btstack_timer_source_t * timer){ void avdtp_configuration_timer_start(avdtp_connection_t * connection){ avdtp_stream_endpoint_t * stream_endpoint = (avdtp_stream_endpoint_t*) connection->active_stream_endpoint; if (!stream_endpoint) { - log_error("avdtp_configuration_timeout_handler: no initiator stream endpoint for seid %d", connection->initiator_local_seid); + log_error("avdtp_configuration_timer_start: no initiator stream endpoint for seid %d", connection->initiator_local_seid); return; } - if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_CONFIGURATION_SUBSTATEMACHINE) return; - + + if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_CONFIGURATION_SUBSTATEMACHINE){ + log_info("avdtp_configuration_timer_start: stream endpoint in wrong state %d, expected %d", stream_endpoint->state, AVDTP_STREAM_ENDPOINT_CONFIGURATION_SUBSTATEMACHINE); + return; + } + log_info("avdtp_configuration_timer_start: start"); + btstack_run_loop_remove_timer(&connection->configuration_timer); btstack_run_loop_set_timer_handler(&connection->configuration_timer, avdtp_configuration_timeout_handler); btstack_run_loop_set_timer_context(&connection->configuration_timer, connection); diff --git a/src/classic/avdtp_acceptor.c b/src/classic/avdtp_acceptor.c index d9c105c71..04b46f9b6 100644 --- a/src/classic/avdtp_acceptor.c +++ b/src/classic/avdtp_acceptor.c @@ -129,7 +129,7 @@ static void avdtp_acceptor_handle_configuration_command(avdtp_connection_t *conn } avdtp_emit_configuration(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), avdtp_remote_seid(stream_endpoint), &sep.configuration, sep.configured_service_categories); - avdtp_signaling_emit_accept(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), connection->acceptor_signaling_packet.signal_identifier); + avdtp_signaling_emit_accept(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), connection->acceptor_signaling_packet.signal_identifier, false); } void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t * packet, uint16_t size, int offset, avdtp_context_t * context){ @@ -383,9 +383,6 @@ void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t connection->reject_signal_identifier = connection->acceptor_signaling_packet.signal_identifier; break; } - - //stream_endpoint->state = AVDTP_STREAM_ENDPOINT_SUSPENDING; - //stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_SUSPEND_STREAM; break; default: log_info("ACP: NOT IMPLEMENTED, Reject signal_identifier %02x", connection->acceptor_signaling_packet.signal_identifier); @@ -537,7 +534,7 @@ void avdtp_acceptor_stream_config_subsm_run(avdtp_connection_t * connection, avd connection->configuration_state = AVDTP_CONFIGURATION_STATE_REMOTE_CONFIGURED; // TODO: consider reconfiguration avdtp_acceptor_send_accept_response(cid, trid, AVDTP_SI_SET_CONFIGURATION); - avdtp_signaling_emit_accept(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), connection->acceptor_signaling_packet.signal_identifier); + avdtp_signaling_emit_accept(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), connection->acceptor_signaling_packet.signal_identifier, false); break; case AVDTP_ACCEPTOR_W2_ANSWER_RECONFIGURE: log_info("ACP: DONE "); @@ -603,7 +600,7 @@ void avdtp_acceptor_stream_config_subsm_run(avdtp_connection_t * connection, avd sent = 0; break; } - avdtp_signaling_emit_accept(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), connection->acceptor_signaling_packet.signal_identifier); + avdtp_signaling_emit_accept(context->avdtp_callback, connection->avdtp_cid, avdtp_local_seid(stream_endpoint), connection->acceptor_signaling_packet.signal_identifier, false); // check fragmentation if ((connection->acceptor_signaling_packet.packet_type != AVDTP_SINGLE_PACKET) && (connection->acceptor_signaling_packet.packet_type != AVDTP_END_PACKET)){ avdtp_request_can_send_now_acceptor(connection, connection->l2cap_signaling_cid); diff --git a/src/classic/avdtp_initiator.c b/src/classic/avdtp_initiator.c index 252896927..5221e2aca 100644 --- a/src/classic/avdtp_initiator.c +++ b/src/classic/avdtp_initiator.c @@ -246,7 +246,7 @@ void avdtp_initiator_stream_config_subsm(avdtp_connection_t * connection, uint8_ log_info(" AVDTP_RESPONSE_ACCEPT_MSG, signal %d not implemented", connection->initiator_signaling_packet.signal_identifier); break; } - avdtp_signaling_emit_accept(context->avdtp_callback, connection->avdtp_cid, 0, connection->initiator_signaling_packet.signal_identifier); + avdtp_signaling_emit_accept(context->avdtp_callback, connection->avdtp_cid, 0, connection->initiator_signaling_packet.signal_identifier, true); connection->initiator_transaction_label++; break; case AVDTP_RESPONSE_REJECT_MSG: @@ -259,12 +259,12 @@ void avdtp_initiator_stream_config_subsm(avdtp_connection_t * connection, uint8_ default: break; } - log_info(" AVDTP_RESPONSE_REJECT_MSG signal %d", connection->initiator_signaling_packet.signal_identifier); - avdtp_signaling_emit_reject(context->avdtp_callback, connection->avdtp_cid, connection->initiator_local_seid, connection->initiator_signaling_packet.signal_identifier); + log_info(" AVDTP_RESPONSE_REJECT_MSG signal %s", avdtp_si2str(connection->initiator_signaling_packet.signal_identifier)); + avdtp_signaling_emit_reject(context->avdtp_callback, connection->avdtp_cid, connection->initiator_local_seid, connection->initiator_signaling_packet.signal_identifier, true); return; case AVDTP_GENERAL_REJECT_MSG: - log_info(" AVDTP_GENERAL_REJECT_MSG signal %d", connection->initiator_signaling_packet.signal_identifier); - avdtp_signaling_emit_general_reject(context->avdtp_callback, connection->avdtp_cid, connection->initiator_local_seid, connection->initiator_signaling_packet.signal_identifier); + log_info(" AVDTP_GENERAL_REJECT_MSG signal %s", avdtp_si2str(connection->initiator_signaling_packet.signal_identifier)); + avdtp_signaling_emit_general_reject(context->avdtp_callback, connection->avdtp_cid, connection->initiator_local_seid, connection->initiator_signaling_packet.signal_identifier, true); return; default: break; diff --git a/src/classic/avdtp_util.c b/src/classic/avdtp_util.c index 1db3c92e0..a7e30b912 100644 --- a/src/classic/avdtp_util.c +++ b/src/classic/avdtp_util.c @@ -657,9 +657,9 @@ void avdtp_signaling_emit_delay(btstack_packet_handler_t callback, uint16_t avdt (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event)); } -void avdtp_signaling_emit_accept(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t local_seid, avdtp_signal_identifier_t identifier){ +void avdtp_signaling_emit_accept(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t local_seid, avdtp_signal_identifier_t identifier, bool is_initiator){ if (!callback) return; - uint8_t event[7]; + uint8_t event[8]; int pos = 0; event[pos++] = HCI_EVENT_AVDTP_META; event[pos++] = sizeof(event) - 2; @@ -667,13 +667,14 @@ void avdtp_signaling_emit_accept(btstack_packet_handler_t callback, uint16_t avd little_endian_store_16(event, pos, avdtp_cid); pos += 2; event[pos++] = local_seid; + event[pos++] = is_initiator ? 1 : 0; event[pos++] = identifier; (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event)); } -void avdtp_signaling_emit_reject(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t local_seid, avdtp_signal_identifier_t identifier){ +void avdtp_signaling_emit_reject(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t local_seid, avdtp_signal_identifier_t identifier, bool is_initiator){ if (!callback) return; - uint8_t event[7]; + uint8_t event[8]; int pos = 0; event[pos++] = HCI_EVENT_AVDTP_META; event[pos++] = sizeof(event) - 2; @@ -681,13 +682,14 @@ void avdtp_signaling_emit_reject(btstack_packet_handler_t callback, uint16_t avd little_endian_store_16(event, pos, avdtp_cid); pos += 2; event[pos++] = local_seid; + event[pos++] = is_initiator ? 1 : 0; event[pos++] = identifier; (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event)); } -void avdtp_signaling_emit_general_reject(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t local_seid, avdtp_signal_identifier_t identifier){ +void avdtp_signaling_emit_general_reject(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t local_seid, avdtp_signal_identifier_t identifier, bool is_initiator){ if (!callback) return; - uint8_t event[7]; + uint8_t event[8]; int pos = 0; event[pos++] = HCI_EVENT_AVDTP_META; event[pos++] = sizeof(event) - 2; @@ -695,6 +697,7 @@ void avdtp_signaling_emit_general_reject(btstack_packet_handler_t callback, uint little_endian_store_16(event, pos, avdtp_cid); pos += 2; event[pos++] = local_seid; + event[pos++] = is_initiator ? 1 : 0; event[pos++] = identifier; (*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event)); } diff --git a/src/classic/avdtp_util.h b/src/classic/avdtp_util.h index f093b803e..28caee175 100644 --- a/src/classic/avdtp_util.h +++ b/src/classic/avdtp_util.h @@ -88,9 +88,9 @@ void avdtp_signaling_emit_sep(btstack_packet_handler_t callback, uint16_t avdtp_ void avdtp_signaling_emit_sep_done(btstack_packet_handler_t callback, uint16_t avdtp_cid); void avdtp_signaling_emit_delay(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t local_seid, uint16_t delay); -void avdtp_signaling_emit_accept(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t seid, avdtp_signal_identifier_t identifier); -void avdtp_signaling_emit_general_reject(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t int_seid, avdtp_signal_identifier_t identifier); -void avdtp_signaling_emit_reject(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t int_seid, avdtp_signal_identifier_t identifier); +void avdtp_signaling_emit_accept(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t seid, avdtp_signal_identifier_t identifier, bool is_initiator); +void avdtp_signaling_emit_general_reject(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t int_seid, avdtp_signal_identifier_t identifier, bool is_initiator); +void avdtp_signaling_emit_reject(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t int_seid, avdtp_signal_identifier_t identifier, bool is_initiator); void avdtp_streaming_emit_can_send_media_packet_now(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t int_seid, uint16_t sequence_number); void avdtp_emit_capabilities(btstack_packet_handler_t callback, uint16_t avdtp_cid, uint8_t local_seid, uint8_t remote_seid, avdtp_capabilities_t * configuration, uint16_t configured_service_categories);