avdtp: use separate local_cid for acceptor and initiator

This commit is contained in:
Matthias Ringwald 2019-12-16 15:30:48 +01:00
parent 96dcd0f431
commit 5bd73fa2fd
5 changed files with 46 additions and 45 deletions

View File

@ -84,7 +84,7 @@ void avdtp_configuration_timeout_handler(btstack_timer_source_t * timer){
}
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->local_seid);
log_error("avdtp_configuration_timeout_handler: no initiator stream endpoint for seid %d", connection->initiator_local_seid);
return;
}
if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_CONFIGURATION_SUBSTATEMACHINE) return;
@ -96,7 +96,7 @@ 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->local_seid);
log_error("avdtp_configuration_timeout_handler: no initiator stream endpoint for seid %d", connection->initiator_local_seid);
return;
}
if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_CONFIGURATION_SUBSTATEMACHINE) return;
@ -616,14 +616,14 @@ void avdtp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet
}
// now, we're only dealing with media connections
stream_endpoint = avdtp_stream_endpoint_for_seid(connection->local_seid, context);
stream_endpoint = avdtp_stream_endpoint_for_signaling_cid(local_cid, context);
if (!stream_endpoint) {
log_info("L2CAP_EVENT_INCOMING_CONNECTION no streamendpoint found for seid %d", connection->local_seid);
log_info("L2CAP_EVENT_INCOMING_CONNECTION no streamendpoint found for local cid %x", local_cid);
l2cap_decline_connection(local_cid);
break;
}
log_info("Checking l2cap_media_cid %d, for local seid %d, state of stream endpoint %d", stream_endpoint->l2cap_media_cid, connection->local_seid, stream_endpoint->state);
log_info("Checking l2cap_media_cid %d, state of stream endpoint %d", stream_endpoint->l2cap_media_cid, stream_endpoint->state);
if (stream_endpoint->l2cap_media_cid != 0){
l2cap_decline_connection(local_cid);
break;
@ -669,16 +669,15 @@ void avdtp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet
break;
}
connection->l2cap_signaling_cid = local_cid;
connection->local_seid = 0;
connection->state = AVDTP_SIGNALING_CONNECTION_OPENED;
log_info("AVDTP_SIGNALING_CONNECTION_OPENED, connection %p, l2cap_signaling_cid 0x%02x, avdtp_cid 0x%02x", connection, local_cid, connection->avdtp_cid);
avdtp_signaling_emit_connection_established(context->avdtp_callback, connection->avdtp_cid, event_addr, 0);
break;
}
stream_endpoint = avdtp_stream_endpoint_for_seid(connection->local_seid, context);
stream_endpoint = avdtp_stream_endpoint_for_signaling_cid(connection->l2cap_signaling_cid, context);
if (!stream_endpoint){
log_info("L2CAP_EVENT_CHANNEL_OPENED: stream_endpoint not found");
log_info("L2CAP_EVENT_CHANNEL_OPENED: stream_endpoint not found for signaling cid 0x%02x", connection->l2cap_signaling_cid);
return;
}
@ -821,7 +820,7 @@ uint8_t avdtp_open_stream(uint16_t avdtp_cid, uint8_t local_seid, uint8_t remote
connection->initiator_transaction_label++;
connection->initiator_remote_seid = remote_seid;
connection->local_seid = local_seid;
connection->initiator_local_seid = local_seid;
stream_endpoint->initiator_config_state = AVDTP_INITIATOR_W2_OPEN_STREAM;
stream_endpoint->state = AVDTP_STREAM_ENDPOINT_W2_REQUEST_OPEN_STREAM;
avdtp_request_can_send_now_initiator(connection, connection->l2cap_signaling_cid);
@ -852,7 +851,7 @@ uint8_t avdtp_start_stream(uint16_t avdtp_cid, uint8_t local_seid, avdtp_context
}
stream_endpoint->start_stream = 1;
connection->local_seid = local_seid;
connection->initiator_local_seid = local_seid;
connection->initiator_remote_seid = stream_endpoint->remote_sep.seid;
avdtp_request_can_send_now_initiator(connection, connection->l2cap_signaling_cid);
return ERROR_CODE_SUCCESS;
@ -881,7 +880,7 @@ uint8_t avdtp_stop_stream(uint16_t avdtp_cid, uint8_t local_seid, avdtp_context_
}
stream_endpoint->stop_stream = 1;
connection->local_seid = local_seid;
connection->initiator_local_seid = local_seid;
connection->initiator_remote_seid = stream_endpoint->remote_sep.seid;
avdtp_request_can_send_now_initiator(connection, connection->l2cap_signaling_cid);
return ERROR_CODE_SUCCESS;
@ -910,7 +909,7 @@ uint8_t avdtp_abort_stream(uint16_t avdtp_cid, uint8_t local_seid, avdtp_context
}
stream_endpoint->abort_stream = 1;
connection->local_seid = local_seid;
connection->initiator_local_seid = local_seid;
connection->initiator_remote_seid = stream_endpoint->remote_sep.seid;
avdtp_request_can_send_now_initiator(connection, connection->l2cap_signaling_cid);
return ERROR_CODE_SUCCESS;
@ -938,7 +937,7 @@ uint8_t avdtp_suspend_stream(uint16_t avdtp_cid, uint8_t local_seid, avdtp_conte
}
stream_endpoint->suspend_stream = 1;
connection->local_seid = local_seid;
connection->initiator_local_seid = local_seid;
connection->initiator_remote_seid = stream_endpoint->remote_sep.seid;
avdtp_request_can_send_now_initiator(connection, connection->l2cap_signaling_cid);
return ERROR_CODE_SUCCESS;
@ -1044,7 +1043,7 @@ uint8_t avdtp_set_configuration(uint16_t avdtp_cid, uint8_t local_seid, uint8_t
connection->initiator_transaction_label++;
connection->initiator_remote_seid = remote_seid;
connection->local_seid = local_seid;
connection->initiator_local_seid = local_seid;
stream_endpoint->remote_configuration_bitmap = configured_services_bitmap;
stream_endpoint->remote_configuration = configuration;
stream_endpoint->initiator_config_state = AVDTP_INITIATOR_W2_SET_CONFIGURATION;
@ -1084,7 +1083,7 @@ uint8_t avdtp_reconfigure(uint16_t avdtp_cid, uint8_t local_seid, uint8_t remote
connection->initiator_transaction_label++;
connection->initiator_remote_seid = remote_seid;
connection->local_seid = local_seid;
connection->initiator_local_seid = local_seid;
stream_endpoint->remote_configuration_bitmap = configured_services_bitmap;
stream_endpoint->remote_configuration = configuration;
stream_endpoint->initiator_config_state = AVDTP_INITIATOR_W2_RECONFIGURE_STREAM_WITH_SEID;

View File

@ -404,9 +404,11 @@ typedef struct {
uint8_t disconnect;
uint8_t local_seid;
uint8_t initiator_local_seid;
uint8_t initiator_remote_seid;
uint8_t acceptor_local_seid;
uint16_t delay_ms;
// for repeating the set_configuration

View File

@ -161,8 +161,8 @@ void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t
case AVDTP_SI_OPEN:
case AVDTP_SI_RECONFIGURE:
case AVDTP_SI_DELAYREPORT:
connection->local_seid = packet[offset++] >> 2;
stream_endpoint = avdtp_stream_endpoint_with_seid(connection->local_seid, context);
connection->acceptor_local_seid = packet[offset++] >> 2;
stream_endpoint = avdtp_stream_endpoint_with_seid(connection->acceptor_local_seid, context);
if (!stream_endpoint){
log_info("ACP: cmd %d - RESPONSE REJECT", connection->acceptor_signaling_packet.signal_identifier);
connection->error_code = BAD_ACP_SEID;
@ -172,7 +172,7 @@ void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t
connection->acceptor_connection_state = AVDTP_SIGNALING_CONNECTION_ACCEPTOR_W2_REJECT_WITH_ERROR_CODE;
if (connection->acceptor_signaling_packet.signal_identifier == AVDTP_SI_RECONFIGURE){
connection->reject_service_category = connection->local_seid;
connection->reject_service_category = connection->acceptor_local_seid;
connection->acceptor_connection_state = AVDTP_SIGNALING_CONNECTION_ACCEPTOR_W2_REJECT_CATEGORY_WITH_ERROR_CODE;
}
connection->reject_signal_identifier = connection->acceptor_signaling_packet.signal_identifier;
@ -196,19 +196,19 @@ void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t
if (connection->num_suspended_seids == 0) {
log_info("ACP: CATEGORY RESPONSE REJECT BAD_ACP_SEID");
connection->error_code = BAD_ACP_SEID;
connection->reject_service_category = connection->local_seid;
connection->reject_service_category = connection->acceptor_local_seid;
connection->acceptor_connection_state = AVDTP_SIGNALING_CONNECTION_ACCEPTOR_W2_REJECT_CATEGORY_WITH_ERROR_CODE;
connection->reject_signal_identifier = connection->acceptor_signaling_packet.signal_identifier;
avdtp_request_can_send_now_acceptor(connection, connection->l2cap_signaling_cid);
return;
}
// deal with first susspended seid
connection->local_seid = connection->suspended_seids[0];
stream_endpoint = avdtp_stream_endpoint_with_seid(connection->local_seid, context);
connection->acceptor_local_seid = connection->suspended_seids[0];
stream_endpoint = avdtp_stream_endpoint_with_seid(connection->acceptor_local_seid, context);
if (!stream_endpoint){
log_info("ACP: stream_endpoint not found, CATEGORY RESPONSE REJECT BAD_ACP_SEID");
connection->error_code = BAD_ACP_SEID;
connection->reject_service_category = connection->local_seid;
connection->reject_service_category = connection->acceptor_local_seid;
connection->acceptor_connection_state = AVDTP_SIGNALING_CONNECTION_ACCEPTOR_W2_REJECT_CATEGORY_WITH_ERROR_CODE;
connection->reject_signal_identifier = connection->acceptor_signaling_packet.signal_identifier;
connection->num_suspended_seids = 0;
@ -241,7 +241,7 @@ void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t
case AVDTP_SI_DELAYREPORT:
log_info("ACP: AVDTP_ACCEPTOR_W2_ANSWER_DELAY_REPORT");
stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_ANSWER_DELAY_REPORT;
avdtp_signaling_emit_delay(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, big_endian_read_16(packet, offset));
avdtp_signaling_emit_delay(context->avdtp_callback, connection->avdtp_cid, connection->acceptor_local_seid, big_endian_read_16(packet, offset));
break;
case AVDTP_SI_GET_ALL_CAPABILITIES:
@ -276,7 +276,7 @@ void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t
connection->reject_service_category = 0;
avdtp_sep_t sep;
sep.seid = connection->local_seid;
sep.seid = connection->acceptor_local_seid;
log_info("ACP: AVDTP_ACCEPTOR_W2_ANSWER_RECONFIGURE seid %d", sep.seid);
sep.configured_service_categories = avdtp_unpack_service_capabilities(connection, connection->acceptor_signaling_packet.signal_identifier, &sep.configuration, connection->acceptor_signaling_packet.command+offset, packet_size-offset);
if (connection->error_code){
@ -317,7 +317,7 @@ void avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, uint8_t
log_info("ACP: AVDTP_STREAM_ENDPOINT_W2_ANSWER_OPEN_STREAM");
stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_ANSWER_OPEN_STREAM;
stream_endpoint->state = AVDTP_STREAM_ENDPOINT_W4_L2CAP_FOR_MEDIA_CONNECTED;
connection->local_seid = stream_endpoint->sep.seid;
connection->acceptor_local_seid = stream_endpoint->sep.seid;
break;
case AVDTP_SI_START:
if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_OPENED){
@ -482,7 +482,7 @@ void avdtp_acceptor_stream_config_subsm_run(avdtp_connection_t * connection, avd
return;
}
avdtp_stream_endpoint_t * stream_endpoint = avdtp_stream_endpoint_for_seid(connection->local_seid, context);
avdtp_stream_endpoint_t * stream_endpoint = avdtp_stream_endpoint_for_seid(connection->acceptor_local_seid, context);
if (!stream_endpoint) return;
uint8_t reject_service_category = connection->reject_service_category;

View File

@ -83,7 +83,7 @@ void avdtp_initiator_stream_config_subsm(avdtp_connection_t * connection, uint8_
} else {
stream_endpoint = avdtp_stream_endpoint_associated_with_acp_seid(connection->initiator_remote_seid, context);
if (!stream_endpoint){
stream_endpoint = avdtp_stream_endpoint_with_seid(connection->local_seid, context);
stream_endpoint = avdtp_stream_endpoint_with_seid(connection->initiator_local_seid, context);
}
if (!stream_endpoint) return;
sep.seid = connection->initiator_remote_seid;
@ -128,21 +128,21 @@ void avdtp_initiator_stream_config_subsm(avdtp_connection_t * connection, uint8_
case AVDTP_SI_GET_CAPABILITIES:
case AVDTP_SI_GET_ALL_CAPABILITIES:
sep.registered_service_categories = avdtp_unpack_service_capabilities(connection, connection->initiator_signaling_packet.signal_identifier, &sep.capabilities, packet+offset, size-offset);
avdtp_emit_capabilities(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, connection->initiator_remote_seid, &sep.capabilities, sep.registered_service_categories);
avdtp_emit_capabilities(context->avdtp_callback, connection->avdtp_cid, connection->initiator_local_seid, connection->initiator_remote_seid, &sep.capabilities, sep.registered_service_categories);
break;
case AVDTP_SI_DELAYREPORT:
avdtp_signaling_emit_delay(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, little_endian_read_16(packet, offset));
avdtp_signaling_emit_delay(context->avdtp_callback, connection->avdtp_cid, connection->initiator_local_seid, little_endian_read_16(packet, offset));
break;
case AVDTP_SI_GET_CONFIGURATION:
// sep.configured_service_categories = avdtp_unpack_service_capabilities(connection, &sep.configuration, packet+offset, size-offset);
// if (get_bit16(sep.configured_service_categories, AVDTP_MEDIA_CODEC)){
// switch (sep.configuration.media_codec.media_codec_type){
// case AVDTP_CODEC_SBC:
// avdtp_signaling_emit_media_codec_sbc_configuration(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, connection->remote_seid,
// avdtp_signaling_emit_media_codec_sbc_configuration(context->avdtp_callback, connection->avdtp_cid, connection->initiator_local_seid, connection->remote_seid,
// sep.configuration.media_codec.media_type, sep.configuration.media_codec.media_codec_information);
// break;
// default:
// avdtp_signaling_emit_media_codec_other_configuration(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, connection->remote_seid, sep.configuration.media_codec);
// avdtp_signaling_emit_media_codec_other_configuration(context->avdtp_callback, connection->avdtp_cid, connection->initiator_local_seid, connection->remote_seid, sep.configuration.media_codec);
// break;
// }
// }
@ -182,12 +182,12 @@ void avdtp_initiator_stream_config_subsm(avdtp_connection_t * connection, uint8_
switch (stream_endpoint->media_codec_type){
case AVDTP_CODEC_SBC:
avdtp_signaling_emit_media_codec_sbc_configuration(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, connection->initiator_remote_seid,
avdtp_signaling_emit_media_codec_sbc_configuration(context->avdtp_callback, connection->avdtp_cid, connection->initiator_local_seid, connection->initiator_remote_seid,
stream_endpoint->media_type, stream_endpoint->media_codec_sbc_info);
break;
default:
// TODO: we don\t have codec info to emit config
avdtp_signaling_emit_media_codec_other_configuration(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, connection->initiator_remote_seid, sep.configuration.media_codec);
avdtp_signaling_emit_media_codec_other_configuration(context->avdtp_callback, connection->avdtp_cid, connection->initiator_local_seid, connection->initiator_remote_seid, sep.configuration.media_codec);
break;
}
break;
@ -203,7 +203,7 @@ void avdtp_initiator_stream_config_subsm(avdtp_connection_t * connection, uint8_
return;
}
stream_endpoint->state = AVDTP_STREAM_ENDPOINT_W4_L2CAP_FOR_MEDIA_CONNECTED;
connection->local_seid = stream_endpoint->sep.seid;
connection->initiator_local_seid = stream_endpoint->sep.seid;
l2cap_create_channel(context->packet_handler, connection->remote_addr, BLUETOOTH_PSM_AVDTP, 0xffff, NULL);
return;
case AVDTP_SI_START:
@ -260,11 +260,11 @@ void avdtp_initiator_stream_config_subsm(avdtp_connection_t * connection, uint8_
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->local_seid, 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);
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->local_seid, 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);
return;
default:
break;
@ -312,7 +312,7 @@ void avdtp_initiator_stream_config_subsm_run(avdtp_connection_t * connection, av
stream_endpoint = avdtp_stream_endpoint_associated_with_acp_seid(connection->initiator_remote_seid, context);
if (!stream_endpoint){
stream_endpoint = avdtp_stream_endpoint_with_seid(connection->local_seid, context);
stream_endpoint = avdtp_stream_endpoint_with_seid(connection->initiator_local_seid, context);
}
if (!stream_endpoint) return;
@ -322,7 +322,7 @@ void avdtp_initiator_stream_config_subsm_run(avdtp_connection_t * connection, av
if (stream_endpoint->start_stream){
stream_endpoint->start_stream = 0;
if (stream_endpoint->state == AVDTP_STREAM_ENDPOINT_OPENED){
connection->local_seid = stream_endpoint->sep.seid;
connection->initiator_local_seid = stream_endpoint->sep.seid;
connection->initiator_remote_seid = stream_endpoint->remote_sep.seid;
avdtp_initiator_send_signaling_cmd_with_seid(connection->l2cap_signaling_cid, AVDTP_SI_START, connection->initiator_transaction_label++, connection->initiator_remote_seid);
return;
@ -333,7 +333,7 @@ void avdtp_initiator_stream_config_subsm_run(avdtp_connection_t * connection, av
if (stream_endpoint->stop_stream){
stream_endpoint->stop_stream = 0;
if (stream_endpoint->state >= AVDTP_STREAM_ENDPOINT_OPENED){
connection->local_seid = stream_endpoint->sep.seid;
connection->initiator_local_seid = stream_endpoint->sep.seid;
connection->initiator_remote_seid = stream_endpoint->remote_sep.seid;
avdtp_initiator_send_signaling_cmd_with_seid(connection->l2cap_signaling_cid, AVDTP_SI_CLOSE, connection->initiator_transaction_label++, connection->initiator_remote_seid);
return;
@ -347,7 +347,7 @@ void avdtp_initiator_stream_config_subsm_run(avdtp_connection_t * connection, av
case AVDTP_STREAM_ENDPOINT_CLOSING:
case AVDTP_STREAM_ENDPOINT_OPENED:
case AVDTP_STREAM_ENDPOINT_STREAMING:
connection->local_seid = stream_endpoint->sep.seid;
connection->initiator_local_seid = stream_endpoint->sep.seid;
connection->initiator_remote_seid = stream_endpoint->remote_sep.seid;
stream_endpoint->state = AVDTP_STREAM_ENDPOINT_ABORTING;
avdtp_initiator_send_signaling_cmd_with_seid(connection->l2cap_signaling_cid, AVDTP_SI_ABORT, connection->initiator_transaction_label++, connection->initiator_remote_seid);
@ -360,7 +360,7 @@ void avdtp_initiator_stream_config_subsm_run(avdtp_connection_t * connection, av
if (stream_endpoint->suspend_stream){
stream_endpoint->suspend_stream = 0;
if (stream_endpoint->state == AVDTP_STREAM_ENDPOINT_STREAMING){
connection->local_seid = stream_endpoint->sep.seid;
connection->initiator_local_seid = stream_endpoint->sep.seid;
connection->initiator_remote_seid = stream_endpoint->remote_sep.seid;
stream_endpoint->state = AVDTP_STREAM_ENDPOINT_STREAMING;
avdtp_initiator_send_signaling_cmd_with_seid(connection->l2cap_signaling_cid, AVDTP_SI_SUSPEND, connection->initiator_transaction_label, connection->initiator_remote_seid);
@ -384,10 +384,10 @@ void avdtp_initiator_stream_config_subsm_run(avdtp_connection_t * connection, av
log_info("initiator SM stop sending SET_CONFIGURATION cmd:");
break;
}
log_info("INT: AVDTP_INITIATOR_W2_(RE)CONFIGURATION bitmap, int seid %d, acp seid %d", connection->local_seid, connection->initiator_remote_seid);
log_info("INT: AVDTP_INITIATOR_W2_(RE)CONFIGURATION bitmap, int seid %d, acp seid %d", connection->initiator_local_seid, connection->initiator_remote_seid);
// log_info_hexdump( connection->remote_capabilities.media_codec.media_codec_information, connection->remote_capabilities.media_codec.media_codec_information_len);
connection->initiator_signaling_packet.acp_seid = connection->initiator_remote_seid;
connection->initiator_signaling_packet.int_seid = connection->local_seid;
connection->initiator_signaling_packet.int_seid = connection->initiator_local_seid;
connection->initiator_signaling_packet.signal_identifier = AVDTP_SI_SET_CONFIGURATION;
stream_endpoint->state = AVDTP_STREAM_ENDPOINT_CONFIGURATION_SUBSTATEMACHINE;

View File

@ -222,7 +222,7 @@ uint8_t avdtp_sink_delay_report(uint16_t avdtp_cid, uint8_t local_seid, uint16_t
connection->initiator_transaction_label++;
connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_W2_SEND_DELAY_REPORT;
connection->delay_ms = delay_100us;
connection->local_seid = local_seid;
connection->initiator_local_seid = local_seid;
connection->initiator_remote_seid = stream_endpoint->remote_sep.seid;
avdtp_request_can_send_now_initiator(connection, connection->l2cap_signaling_cid);
return ERROR_CODE_SUCCESS;