static void discover_cb(struct avdtp *session, GSList *seps, struct avdtp_error *err, void *user_data) { struct a2dp_device *dev = user_data; struct a2dp_endpoint *endpoint = NULL; struct avdtp_remote_sep *rsep = NULL; GSList *l; for (l = endpoints; l; l = g_slist_next(l)) { endpoint = l->data; rsep = avdtp_find_remote_sep(session, endpoint->sep); if (rsep) break; } if (!rsep) { error("Unable to find matching endpoint"); goto failed; } if (select_configuration(dev, endpoint, rsep) < 0) goto failed; return; failed: avdtp_shutdown(session); }
static void discover_cb(struct avdtp *session, GSList *seps, struct avdtp_error *err, void *user_data) { struct avdtp_service_capability *service; GSList *caps = NULL; int ret; remote_sep = avdtp_find_remote_sep(avdtp, local_sep); if (!remote_sep) { printf("Unable to find matching endpoint\n"); avdtp_shutdown(session); return; } printf("Matching endpoint found\n"); service = avdtp_service_cap_new(AVDTP_MEDIA_TRANSPORT, NULL, 0); caps = g_slist_append(caps, service); service = avdtp_service_cap_new(AVDTP_MEDIA_CODEC, sbc_codec, sizeof(sbc_codec)); caps = g_slist_append(caps, service); ret = avdtp_set_configuration(avdtp, remote_sep, local_sep, caps, &avdtp_stream); g_slist_free_full(caps, g_free); if (ret < 0) { printf("Failed to set configuration (%s)\n", strerror(-ret)); avdtp_shutdown(session); } }
void avdtp_initiator_stream_config_subsm(avdtp_connection_t * connection, uint8_t *packet, uint16_t size, int offset, avdtp_context_t * context){ // int status = 0; avdtp_stream_endpoint_t * stream_endpoint = NULL; uint8_t remote_sep_index; avdtp_sep_t sep; if (connection->initiator_connection_state == AVDTP_SIGNALING_CONNECTION_INITIATOR_W4_ANSWER) { connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE; } else { stream_endpoint = avdtp_stream_endpoint_associated_with_acp_seid(connection->remote_seid, context); if (!stream_endpoint){ stream_endpoint = avdtp_stream_endpoint_with_seid(connection->local_seid, context); } if (!stream_endpoint) return; sep.seid = connection->remote_seid; if (stream_endpoint->initiator_config_state != AVDTP_INITIATOR_W4_ANSWER) return; stream_endpoint->initiator_config_state = AVDTP_INITIATOR_STREAM_CONFIG_IDLE; } switch (connection->signaling_packet.message_type){ case AVDTP_RESPONSE_ACCEPT_MSG: switch (connection->signaling_packet.signal_identifier){ case AVDTP_SI_DISCOVER:{ if (connection->signaling_packet.transaction_label != connection->initiator_transaction_label){ log_info(" unexpected transaction label, got %d, expected %d", connection->signaling_packet.transaction_label, connection->initiator_transaction_label); // status = BAD_HEADER_FORMAT; break; } if (size == 3){ log_info(" ERROR code %02x", packet[offset]); break; } int i; for (i = offset; i < size; i += 2){ sep.seid = packet[i] >> 2; offset++; if (sep.seid < 0x01 || sep.seid > 0x3E){ log_info(" invalid sep id"); // status = BAD_ACP_SEID; break; } sep.in_use = (packet[i] >> 1) & 0x01; sep.media_type = (avdtp_media_type_t)(packet[i+1] >> 4); sep.type = (avdtp_sep_type_t)((packet[i+1] >> 3) & 0x01); if (avdtp_find_remote_sep(connection, sep.seid) == 0xFF){ connection->remote_seps[connection->remote_seps_num++] = sep; } avdtp_signaling_emit_sep(context->avdtp_callback, connection->avdtp_cid, sep); } break; } case AVDTP_SI_GET_CAPABILITIES: case AVDTP_SI_GET_ALL_CAPABILITIES: sep.registered_service_categories = avdtp_unpack_service_capabilities(connection, &sep.capabilities, packet+offset, size-offset); if (get_bit16(sep.registered_service_categories, AVDTP_MEDIA_CODEC)){ switch (sep.capabilities.media_codec.media_codec_type){ case AVDTP_CODEC_SBC: avdtp_signaling_emit_media_codec_sbc_capability(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, connection->remote_seid, sep.capabilities.media_codec); break; default: avdtp_signaling_emit_media_codec_other_capability(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, connection->remote_seid, sep.capabilities.media_codec); break; } } 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, sep.configuration.media_codec); 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); break; } } break; case AVDTP_SI_RECONFIGURE: if (!stream_endpoint){ log_error("AVDTP_SI_RECONFIGURE: stream endpoint is null"); break; } sep.configured_service_categories = avdtp_unpack_service_capabilities(connection, &sep.configuration, connection->signaling_packet.command+4, connection->signaling_packet.size-4); // TODO check if configuration is supported remote_sep_index = avdtp_find_remote_sep(connection, sep.seid); if (remote_sep_index != 0xFF){ stream_endpoint->remote_sep_index = remote_sep_index; connection->remote_seps[stream_endpoint->remote_sep_index] = sep; stream_endpoint->state = AVDTP_STREAM_ENDPOINT_CONFIGURED; log_info("INT: update seid %d, to %p", connection->remote_seps[stream_endpoint->remote_sep_index].seid, stream_endpoint); } break; case AVDTP_SI_SET_CONFIGURATION:{ if (!stream_endpoint){ log_error("AVDTP_SI_SET_CONFIGURATION: stream endpoint is null"); break; } sep.configured_service_categories = stream_endpoint->remote_capabilities_bitmap; sep.configuration = stream_endpoint->remote_capabilities; sep.in_use = 1; // TODO check if configuration is supported // find or add sep remote_sep_index = avdtp_find_remote_sep(connection, sep.seid); if (remote_sep_index != 0xFF){ stream_endpoint->remote_sep_index = remote_sep_index; } else { stream_endpoint->remote_sep_index = connection->remote_seps_num; connection->remote_seps_num++; } connection->remote_seps[stream_endpoint->remote_sep_index] = sep; log_info("INT: configured remote seid %d, to %p", connection->remote_seps[stream_endpoint->remote_sep_index].seid, stream_endpoint); stream_endpoint->state = AVDTP_STREAM_ENDPOINT_CONFIGURED; break; } case AVDTP_SI_OPEN: if (!stream_endpoint){ log_error("AVDTP_SI_OPEN: stream endpoint is null"); break; } if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_W2_REQUEST_OPEN_STREAM) { log_error("AVDTP_SI_OPEN in wrong stream endpoint state"); return; } stream_endpoint->state = AVDTP_STREAM_ENDPOINT_W4_L2CAP_FOR_MEDIA_CONNECTED; connection->local_seid = stream_endpoint->sep.seid; l2cap_create_channel(context->packet_handler, connection->remote_addr, BLUETOOTH_PROTOCOL_AVDTP, 0xffff, NULL); return; case AVDTP_SI_START: if (!stream_endpoint){ log_error("AVDTP_SI_START: stream endpoint is null"); break; } if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_OPENED) { log_error("AVDTP_SI_START in wrong stream endpoint state"); return; } stream_endpoint->state = AVDTP_STREAM_ENDPOINT_STREAMING; break; case AVDTP_SI_SUSPEND: if (!stream_endpoint){ log_error("AVDTP_SI_SUSPEND: stream endpoint is null"); break; } if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_STREAMING) { log_error("AVDTP_SI_SUSPEND in wrong stream endpoint state"); return; } stream_endpoint->state = AVDTP_STREAM_ENDPOINT_OPENED; break; case AVDTP_SI_CLOSE: if (!stream_endpoint){ log_error("AVDTP_SI_CLOSE: stream endpoint is null"); break; } stream_endpoint->state = AVDTP_STREAM_ENDPOINT_CLOSING; break; case AVDTP_SI_ABORT: if (!stream_endpoint){ log_error("AVDTP_SI_ABORT: stream endpoint is null"); break; } stream_endpoint->state = AVDTP_STREAM_ENDPOINT_ABORTING; break; default: log_info(" AVDTP_RESPONSE_ACCEPT_MSG, signal %d not implemented", connection->signaling_packet.signal_identifier); break; } avdtp_signaling_emit_accept(context->avdtp_callback, connection->avdtp_cid, 0, connection->signaling_packet.signal_identifier); connection->initiator_transaction_label++; break; case AVDTP_RESPONSE_REJECT_MSG: log_info(" AVDTP_RESPONSE_REJECT_MSG signal %d", connection->signaling_packet.signal_identifier); avdtp_signaling_emit_reject(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, connection->signaling_packet.signal_identifier); return; case AVDTP_GENERAL_REJECT_MSG: log_info(" AVDTP_GENERAL_REJECT_MSG signal %d", connection->signaling_packet.signal_identifier); avdtp_signaling_emit_general_reject(context->avdtp_callback, connection->avdtp_cid, connection->local_seid, connection->signaling_packet.signal_identifier); return; default: break; } }