diff --git a/src/classic/avdtp.c b/src/classic/avdtp.c index c13cbd248..3bffd7838 100644 --- a/src/classic/avdtp.c +++ b/src/classic/avdtp.c @@ -247,8 +247,6 @@ static void stream_endpoint_state_machine(avdtp_connection_t * connection, avdtp stream_endpoint->state = AVDTP_STREAM_ENDPOINT_IDLE; stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_STREAM_CONFIG_IDLE; stream_endpoint->initiator_config_state = AVDTP_INITIATOR_STREAM_CONFIG_IDLE; - stream_endpoint->remote_seps_num = 0; - memset(stream_endpoint->remote_seps, 0, sizeof(avdtp_sep_t)*MAX_NUM_SEPS); stream_endpoint->remote_sep_index = 0; break; } diff --git a/src/classic/avdtp.h b/src/classic/avdtp.h index 8c460e58e..38fed782d 100644 --- a/src/classic/avdtp.h +++ b/src/classic/avdtp.h @@ -422,6 +422,10 @@ typedef struct { uint8_t reject_service_category; avdtp_signal_identifier_t reject_signal_identifier; uint8_t error_code; + + // store configurations with remote seps + avdtp_sep_t remote_seps[MAX_NUM_SEPS]; + uint8_t remote_seps_num; } avdtp_connection_t; @@ -440,10 +444,6 @@ typedef struct avdtp_stream_endpoint { // active connection avdtp_connection_t * connection; - // store configurations with remote seps - avdtp_sep_t remote_seps[MAX_NUM_SEPS]; - uint8_t remote_seps_num; - // currently active remote seid uint8_t remote_sep_index; // register request for media L2cap connection release diff --git a/src/classic/avdtp_acceptor.c b/src/classic/avdtp_acceptor.c index e6c1ca28a..308ecde0f 100644 --- a/src/classic/avdtp_acceptor.c +++ b/src/classic/avdtp_acceptor.c @@ -215,15 +215,15 @@ void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t // find or add sep int i; stream_endpoint->remote_sep_index = 0xFF; - for (i=0; i < stream_endpoint->remote_seps_num; i++){ - if (stream_endpoint->remote_seps[i].seid == sep.seid){ + for (i=0; i < stream_endpoint->connection->remote_seps_num; i++){ + if (stream_endpoint->connection->remote_seps[i].seid == sep.seid){ stream_endpoint->remote_sep_index = i; } } printf(" ACP .. seid %d, index %d\n", sep.seid, stream_endpoint->remote_sep_index); if (stream_endpoint->remote_sep_index != 0xFF){ - if (stream_endpoint->remote_seps[stream_endpoint->remote_sep_index].in_use){ + if (stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index].in_use){ // reject if already configured connection->error_code = SEP_IN_USE; // find first registered category and fire the error @@ -237,16 +237,16 @@ void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t connection->reject_signal_identifier = connection->signaling_packet.signal_identifier; stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_REJECT_CATEGORY_WITH_ERROR_CODE; } else { - stream_endpoint->remote_seps[stream_endpoint->remote_sep_index] = sep; - printf(" ACP: update seid %d, to %p\n", stream_endpoint->remote_seps[stream_endpoint->remote_sep_index].seid, stream_endpoint); + stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index] = sep; + printf(" ACP: update seid %d, to %p\n", stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index].seid, stream_endpoint); } } else { // add new printf(" ACP: seid %d not found in %p\n", sep.seid, stream_endpoint); - stream_endpoint->remote_sep_index = stream_endpoint->remote_seps_num; - stream_endpoint->remote_seps_num++; - stream_endpoint->remote_seps[stream_endpoint->remote_sep_index] = sep; - printf(" ACP: add seid %d, to %p\n", stream_endpoint->remote_seps[stream_endpoint->remote_sep_index].seid, stream_endpoint); + stream_endpoint->remote_sep_index = stream_endpoint->connection->remote_seps_num; + stream_endpoint->connection->remote_seps_num++; + stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index] = sep; + printf(" ACP: add seid %d, to %p\n", stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index].seid, stream_endpoint); } if (get_bit16(sep.configured_service_categories, AVDTP_MEDIA_CODEC)){ switch (sep.configuration.media_codec.media_codec_type){ @@ -282,8 +282,8 @@ void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t // find sep or raise error int i; stream_endpoint->remote_sep_index = 0xFF; - for (i = 0; i < stream_endpoint->remote_seps_num; i++){ - if (stream_endpoint->remote_seps[i].seid == sep.seid){ + for (i = 0; i < stream_endpoint->connection->remote_seps_num; i++){ + if (stream_endpoint->connection->remote_seps[i].seid == sep.seid){ stream_endpoint->remote_sep_index = i; } } @@ -295,8 +295,8 @@ void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t connection->reject_signal_identifier = connection->signaling_packet.signal_identifier; break; } - stream_endpoint->remote_seps[stream_endpoint->remote_sep_index] = sep; - printf(" ACP: update seid %d, to %p\n", stream_endpoint->remote_seps[stream_endpoint->remote_sep_index].seid, stream_endpoint); + stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index] = sep; + printf(" ACP: update seid %d, to %p\n", stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index].seid, stream_endpoint); if (get_bit16(sep.configured_service_categories, AVDTP_MEDIA_CODEC)){ switch (sep.capabilities.media_codec.media_codec_type){ @@ -549,7 +549,7 @@ void avdtp_acceptor_stream_config_subsm_run(avdtp_connection_t * connection, avd break; case AVDTP_ACCEPTOR_W2_ANSWER_GET_CONFIGURATION:{ - avdtp_sep_t sep = stream_endpoint->remote_seps[stream_endpoint->remote_sep_index]; + avdtp_sep_t sep = stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index]; avdtp_prepare_capabilities(&connection->signaling_packet, trid, sep.configured_service_categories, sep.configuration, AVDTP_SI_GET_CONFIGURATION); l2cap_reserve_packet_buffer(); out_buffer = l2cap_get_outgoing_buffer(); diff --git a/src/classic/avdtp_initiator.c b/src/classic/avdtp_initiator.c index 5fd7ca99d..e752a9409 100644 --- a/src/classic/avdtp_initiator.c +++ b/src/classic/avdtp_initiator.c @@ -160,9 +160,9 @@ void avdtp_initiator_stream_config_subsm(avdtp_connection_t * connection, uint8_ remote_sep_index = avdtp_get_index_of_remote_stream_endpoint_with_seid(stream_endpoint, sep.seid); if (remote_sep_index != 0xFF){ stream_endpoint->remote_sep_index = remote_sep_index; - stream_endpoint->remote_seps[stream_endpoint->remote_sep_index] = sep; + stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index] = sep; stream_endpoint->state = AVDTP_STREAM_ENDPOINT_CONFIGURED; - printf(" INT: update seid %d, to %p\n", stream_endpoint->remote_seps[stream_endpoint->remote_sep_index].seid, stream_endpoint); + printf(" INT: update seid %d, to %p\n", stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index].seid, stream_endpoint); } break; @@ -178,11 +178,11 @@ void avdtp_initiator_stream_config_subsm(avdtp_connection_t * connection, uint8_ if (remote_sep_index != 0xFF){ stream_endpoint->remote_sep_index = remote_sep_index; } else { - stream_endpoint->remote_sep_index = stream_endpoint->remote_seps_num; - stream_endpoint->remote_seps_num++; + stream_endpoint->remote_sep_index = stream_endpoint->connection->remote_seps_num; + stream_endpoint->connection->remote_seps_num++; } - stream_endpoint->remote_seps[stream_endpoint->remote_sep_index] = sep; - printf(" INT: configured remote seid %d, to %p\n", stream_endpoint->remote_seps[stream_endpoint->remote_sep_index].seid, stream_endpoint); + stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index] = sep; + printf(" INT: configured remote seid %d, to %p\n", stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index].seid, stream_endpoint); stream_endpoint->state = AVDTP_STREAM_ENDPOINT_CONFIGURED; break; } diff --git a/src/classic/avdtp_util.c b/src/classic/avdtp_util.c index 94a3bcae2..c47d5dbdc 100644 --- a/src/classic/avdtp_util.c +++ b/src/classic/avdtp_util.c @@ -59,9 +59,7 @@ void avdtp_initialize_stream_endpoint(avdtp_stream_endpoint_t * stream_endpoint) stream_endpoint->initiator_config_state = AVDTP_INITIATOR_STREAM_CONFIG_IDLE; stream_endpoint->remote_sep_index = 0; stream_endpoint->media_disconnect = 0; - stream_endpoint->remote_seps_num = 0; stream_endpoint->sep.in_use = 0; - memset(stream_endpoint->remote_seps, 0, sizeof(stream_endpoint->remote_seps)); stream_endpoint->remote_sep_index = 0; } @@ -146,7 +144,8 @@ avdtp_stream_endpoint_t * avdtp_stream_endpoint_associated_with_acp_seid(uint16_ while (btstack_linked_list_iterator_has_next(&it)){ avdtp_stream_endpoint_t * stream_endpoint = (avdtp_stream_endpoint_t *)btstack_linked_list_iterator_next(&it); if (stream_endpoint->remote_sep_index >= 0 && stream_endpoint->remote_sep_index < MAX_NUM_SEPS){ - if (stream_endpoint->remote_seps[stream_endpoint->remote_sep_index].seid == acp_seid){ + if (!stream_endpoint->connection) continue; + if (stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index].seid == acp_seid){ return stream_endpoint; } } @@ -789,12 +788,13 @@ void avdtp_request_can_send_now_self(avdtp_connection_t * connection, uint16_t l } uint8_t avdtp_get_index_of_remote_stream_endpoint_with_seid(avdtp_stream_endpoint_t * stream_endpoint, uint16_t seid){ - if (stream_endpoint->remote_seps[stream_endpoint->remote_sep_index].seid == seid){ + if (!stream_endpoint->connection) return 0xFF; + if (stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index].seid == seid){ return stream_endpoint->remote_sep_index; } int i; - for (i=0; i < stream_endpoint->remote_seps_num; i++){ - if (stream_endpoint->remote_seps[i].seid == seid){ + for (i=0; i < stream_endpoint->connection->remote_seps_num; i++){ + if (stream_endpoint->connection->remote_seps[i].seid == seid){ return i; } }