emit configuration and capabilities

This commit is contained in:
Milanka Ringwald 2017-01-16 14:40:25 +01:00
parent e145da5176
commit ea7bd52950
7 changed files with 570 additions and 171 deletions

View File

@ -1247,15 +1247,15 @@ typedef uint8_t sm_key_t[16];
* @param subevent_code
* @param con_handle
* @param media_type
* @param sampling_frequency
* @param channel_mode
* @param block_length
* @param subbands
* @param allocation_method
* @param sampling_frequency_bitmap
* @param channel_mode_bitmap
* @param block_length_bitmap
* @param subbands_bitmap
* @param allocation_method_bitmap
* @param min_bitpool_value
* @param max_bitpool_value
*/
#define AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC 0x05
#define AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CAPABILITY 0x05
/**
* @format 1H122
@ -1266,6 +1266,34 @@ typedef uint8_t sm_key_t[16];
* @param media_codec_information_len
* @param media_codec_information
*/
#define AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER 0x06
#define AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CAPABILITY 0x06
/**
* @format 1H11211111111
* @param subevent_code
* @param con_handle
* @param reconfigure
* @param media_type
* @param sampling_frequency
* @param channel_mode
* @param num_channels
* @param block_length
* @param subbands
* @param allocation_method
* @param min_bitpool_value
* @param max_bitpool_value
*/
#define AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION 0x07
/**
* @format 1H1122
* @param subevent_code
* @param con_handle
* @param reconfigure
* @param media_type
* @param media_codec_type
* @param media_codec_information_len
* @param media_codec_information
*/
#define AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CONFIGURATION 0x08
#endif

View File

@ -3887,124 +3887,270 @@ static inline uint8_t avdtp_subevent_signaling_done_get_status(const uint8_t * e
}
/**
* @brief Get field con_handle from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC
* @brief Get field con_handle from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CAPABILITY
* @param event packet
* @return con_handle
* @note: btstack_type H
*/
static inline hci_con_handle_t avdtp_subevent_signaling_media_codec_sbc_get_con_handle(const uint8_t * event){
static inline hci_con_handle_t avdtp_subevent_signaling_media_codec_sbc_capability_get_con_handle(const uint8_t * event){
return little_endian_read_16(event, 3);
}
/**
* @brief Get field media_type from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC
* @brief Get field media_type from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CAPABILITY
* @param event packet
* @return media_type
* @note: btstack_type 1
*/
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_get_media_type(const uint8_t * event){
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_capability_get_media_type(const uint8_t * event){
return event[5];
}
/**
* @brief Get field sampling_frequency from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC
* @brief Get field sampling_frequency_bitmap from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CAPABILITY
* @param event packet
* @return sampling_frequency
* @return sampling_frequency_bitmap
* @note: btstack_type 1
*/
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_get_sampling_frequency(const uint8_t * event){
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_capability_get_sampling_frequency_bitmap(const uint8_t * event){
return event[6];
}
/**
* @brief Get field channel_mode from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC
* @brief Get field channel_mode_bitmap from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CAPABILITY
* @param event packet
* @return channel_mode
* @return channel_mode_bitmap
* @note: btstack_type 1
*/
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_get_channel_mode(const uint8_t * event){
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_capability_get_channel_mode_bitmap(const uint8_t * event){
return event[7];
}
/**
* @brief Get field block_length from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC
* @brief Get field block_length_bitmap from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CAPABILITY
* @param event packet
* @return block_length
* @return block_length_bitmap
* @note: btstack_type 1
*/
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_get_block_length(const uint8_t * event){
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_capability_get_block_length_bitmap(const uint8_t * event){
return event[8];
}
/**
* @brief Get field subbands from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC
* @brief Get field subbands_bitmap from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CAPABILITY
* @param event packet
* @return subbands
* @return subbands_bitmap
* @note: btstack_type 1
*/
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_get_subbands(const uint8_t * event){
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_capability_get_subbands_bitmap(const uint8_t * event){
return event[9];
}
/**
* @brief Get field allocation_method from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC
* @brief Get field allocation_method_bitmap from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CAPABILITY
* @param event packet
* @return allocation_method
* @return allocation_method_bitmap
* @note: btstack_type 1
*/
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_get_allocation_method(const uint8_t * event){
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_capability_get_allocation_method_bitmap(const uint8_t * event){
return event[10];
}
/**
* @brief Get field min_bitpool_value from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC
* @brief Get field min_bitpool_value from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CAPABILITY
* @param event packet
* @return min_bitpool_value
* @note: btstack_type 1
*/
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_get_min_bitpool_value(const uint8_t * event){
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_capability_get_min_bitpool_value(const uint8_t * event){
return event[11];
}
/**
* @brief Get field max_bitpool_value from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC
* @brief Get field max_bitpool_value from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CAPABILITY
* @param event packet
* @return max_bitpool_value
* @note: btstack_type 1
*/
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_get_max_bitpool_value(const uint8_t * event){
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_capability_get_max_bitpool_value(const uint8_t * event){
return event[12];
}
/**
* @brief Get field con_handle from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER
* @brief Get field con_handle from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CAPABILITY
* @param event packet
* @return con_handle
* @note: btstack_type H
*/
static inline hci_con_handle_t avdtp_subevent_signaling_media_codec_other_get_con_handle(const uint8_t * event){
static inline hci_con_handle_t avdtp_subevent_signaling_media_codec_other_capability_get_con_handle(const uint8_t * event){
return little_endian_read_16(event, 3);
}
/**
* @brief Get field media_type from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER
* @brief Get field media_type from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CAPABILITY
* @param event packet
* @return media_type
* @note: btstack_type 1
*/
static inline uint8_t avdtp_subevent_signaling_media_codec_other_get_media_type(const uint8_t * event){
static inline uint8_t avdtp_subevent_signaling_media_codec_other_capability_get_media_type(const uint8_t * event){
return event[5];
}
/**
* @brief Get field media_codec_type from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER
* @brief Get field media_codec_type from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CAPABILITY
* @param event packet
* @return media_codec_type
* @note: btstack_type 2
*/
static inline uint16_t avdtp_subevent_signaling_media_codec_other_get_media_codec_type(const uint8_t * event){
static inline uint16_t avdtp_subevent_signaling_media_codec_other_capability_get_media_codec_type(const uint8_t * event){
return little_endian_read_16(event, 6);
}
/**
* @brief Get field media_codec_information_len from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER
* @brief Get field media_codec_information_len from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CAPABILITY
* @param event packet
* @return media_codec_information_len
* @note: btstack_type 2
*/
static inline uint16_t avdtp_subevent_signaling_media_codec_other_get_media_codec_information_len(const uint8_t * event){
static inline uint16_t avdtp_subevent_signaling_media_codec_other_capability_get_media_codec_information_len(const uint8_t * event){
return little_endian_read_16(event, 8);
}
/**
* @brief Get field con_handle from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION
* @param event packet
* @return con_handle
* @note: btstack_type H
*/
static inline hci_con_handle_t avdtp_subevent_signaling_media_codec_sbc_configuration_get_con_handle(const uint8_t * event){
return little_endian_read_16(event, 3);
}
/**
* @brief Get field reconfigure from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION
* @param event packet
* @return reconfigure
* @note: btstack_type 1
*/
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_configuration_get_reconfigure(const uint8_t * event){
return event[5];
}
/**
* @brief Get field media_type from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION
* @param event packet
* @return media_type
* @note: btstack_type 1
*/
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_configuration_get_media_type(const uint8_t * event){
return event[6];
}
/**
* @brief Get field sampling_frequency from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION
* @param event packet
* @return sampling_frequency
* @note: btstack_type 2
*/
static inline uint16_t avdtp_subevent_signaling_media_codec_sbc_configuration_get_sampling_frequency(const uint8_t * event){
return little_endian_read_16(event, 7);
}
/**
* @brief Get field channel_mode from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION
* @param event packet
* @return channel_mode
* @note: btstack_type 1
*/
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_configuration_get_channel_mode(const uint8_t * event){
return event[9];
}
/**
* @brief Get field num_channels from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION
* @param event packet
* @return num_channels
* @note: btstack_type 1
*/
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_configuration_get_num_channels(const uint8_t * event){
return event[10];
}
/**
* @brief Get field block_length from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION
* @param event packet
* @return block_length
* @note: btstack_type 1
*/
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_configuration_get_block_length(const uint8_t * event){
return event[11];
}
/**
* @brief Get field subbands from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION
* @param event packet
* @return subbands
* @note: btstack_type 1
*/
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_configuration_get_subbands(const uint8_t * event){
return event[12];
}
/**
* @brief Get field allocation_method from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION
* @param event packet
* @return allocation_method
* @note: btstack_type 1
*/
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_configuration_get_allocation_method(const uint8_t * event){
return event[13];
}
/**
* @brief Get field min_bitpool_value from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION
* @param event packet
* @return min_bitpool_value
* @note: btstack_type 1
*/
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_configuration_get_min_bitpool_value(const uint8_t * event){
return event[14];
}
/**
* @brief Get field max_bitpool_value from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION
* @param event packet
* @return max_bitpool_value
* @note: btstack_type 1
*/
static inline uint8_t avdtp_subevent_signaling_media_codec_sbc_configuration_get_max_bitpool_value(const uint8_t * event){
return event[15];
}
/**
* @brief Get field con_handle from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CONFIGURATION
* @param event packet
* @return con_handle
* @note: btstack_type H
*/
static inline hci_con_handle_t avdtp_subevent_signaling_media_codec_other_configuration_get_con_handle(const uint8_t * event){
return little_endian_read_16(event, 3);
}
/**
* @brief Get field reconfigure from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CONFIGURATION
* @param event packet
* @return reconfigure
* @note: btstack_type 1
*/
static inline uint8_t avdtp_subevent_signaling_media_codec_other_configuration_get_reconfigure(const uint8_t * event){
return event[5];
}
/**
* @brief Get field media_type from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CONFIGURATION
* @param event packet
* @return media_type
* @note: btstack_type 1
*/
static inline uint8_t avdtp_subevent_signaling_media_codec_other_configuration_get_media_type(const uint8_t * event){
return event[6];
}
/**
* @brief Get field media_codec_type from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CONFIGURATION
* @param event packet
* @return media_codec_type
* @note: btstack_type 2
*/
static inline uint16_t avdtp_subevent_signaling_media_codec_other_configuration_get_media_codec_type(const uint8_t * event){
return little_endian_read_16(event, 7);
}
/**
* @brief Get field media_codec_information_len from event AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CONFIGURATION
* @param event packet
* @return media_codec_information_len
* @note: btstack_type 2
*/
static inline uint16_t avdtp_subevent_signaling_media_codec_other_configuration_get_media_codec_information_len(const uint8_t * event){
return little_endian_read_16(event, 9);
}
/* API_END */

View File

@ -85,28 +85,29 @@ int avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, avdtp_st
printf(" ACP: AVDTP_ACCEPTOR_W2_ANSWER_SET_CONFIGURATION \n");
stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_ANSWER_SET_CONFIGURATION;
connection->reject_service_category = 0;
stream_endpoint->remote_sep_index = 0xFF;
avdtp_sep_t sep;
sep.seid = connection->signaling_packet.command[offset++] >> 2;
sep.registered_service_categories = avdtp_unpack_service_capabilities(connection, &sep.capabilities, connection->signaling_packet.command+offset, packet_size-offset);
sep.configured_service_categories = avdtp_unpack_service_capabilities(connection, &sep.configuration, connection->signaling_packet.command+offset, packet_size-offset);
sep.in_use = 1;
if (connection->error_code){
printf("fire capabilities parsing errors \n");
printf("fire configuration parsing errors \n");
connection->reject_signal_identifier = connection->signaling_packet.signal_identifier;
stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_REJECT_CATEGORY_WITH_ERROR_CODE;
break;
}
printf(" ACP .. seid %d\n", sep.seid);
// 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){
stream_endpoint->remote_sep_index = i;
}
}
printf(" ACP .. seid %d, index %02x\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){
// reject if already configured
@ -114,7 +115,7 @@ int avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, avdtp_st
// find first registered category and fire the error
connection->reject_service_category = 0;
for (i = 1; i < 9; i++){
if (get_bit16(sep.registered_service_categories, i)){
if (get_bit16(sep.configured_service_categories, i)){
connection->reject_service_category = i;
break;
}
@ -135,13 +136,13 @@ int avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, avdtp_st
}
break;
if (get_bit16(sep.registered_service_categories, AVDTP_MEDIA_CODEC)){
switch (sep.capabilities.media_codec.media_codec_type){
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(avdtp_sink_callback, connection->con_handle, sep.capabilities.media_codec);
avdtp_signaling_emit_media_codec_sbc_configuration(avdtp_sink_callback, connection->con_handle, sep.configuration.media_codec);
break;
default:
avdtp_signaling_emit_media_codec_other(avdtp_sink_callback, connection->con_handle, sep.capabilities.media_codec);
avdtp_signaling_emit_media_codec_other_configuration(avdtp_sink_callback, connection->con_handle, sep.configuration.media_codec);
break;
}
}
@ -149,27 +150,18 @@ int avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, avdtp_st
break;
}
case AVDTP_SI_RECONFIGURE:{
// if (stream_endpoint->state < AVDTP_STREAM_ENDPOINT_OPENED){
// printf(" ACP: AVDTP_SI_RECONFIGURE, bad state %d \n", stream_endpoint->state);
// stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_REJECT_WITH_ERROR_CODE;
// connection->error_code = BAD_STATE;
// connection->reject_signal_identifier = connection->signaling_packet.signal_identifier;
// break;
// }
stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_ANSWER_RECONFIGURE;
connection->reject_service_category = 0;
stream_endpoint->remote_sep_index = 0xFF;
avdtp_sep_t sep;
sep.seid = packet[2] >> 2;
sep.seid = connection->query_seid;
printf(" ACP: AVDTP_ACCEPTOR_W2_ANSWER_RECONFIGURE seid %d\n", sep.seid);
// printf_hexdump(connection->signaling_packet.command, packet_size);
sep.registered_service_categories = avdtp_unpack_service_capabilities(connection, &sep.capabilities, connection->signaling_packet.command+3, packet_size-3);
sep.configured_service_categories = avdtp_unpack_service_capabilities(connection, &sep.configuration, connection->signaling_packet.command+offset, packet_size-offset);
if (connection->error_code){
// fire capabilities parsing errors
// fire configuration parsing errors
connection->reject_signal_identifier = connection->signaling_packet.signal_identifier;
stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_REJECT_CATEGORY_WITH_ERROR_CODE;
break;
@ -177,6 +169,7 @@ int avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, avdtp_st
// 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){
stream_endpoint->remote_sep_index = i;
@ -190,8 +183,22 @@ int avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, avdtp_st
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);
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_reconfiguration(avdtp_sink_callback, connection->con_handle, sep.capabilities.media_codec);
break;
default:
avdtp_signaling_emit_media_codec_other_reconfiguration(avdtp_sink_callback, connection->con_handle, sep.capabilities.media_codec);
break;
}
}
avdtp_signaling_emit_done(avdtp_sink_callback, connection->con_handle, 0);
break;
}
case AVDTP_SI_GET_CONFIGURATION:
printf(" ACP: AVDTP_ACCEPTOR_W2_ANSWER_GET_CONFIGURATION\n");
stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_ANSWER_GET_CONFIGURATION;
@ -257,7 +264,6 @@ int avdtp_acceptor_stream_config_subsm(avdtp_connection_t * connection, avdtp_st
switch (stream_endpoint->state){
case AVDTP_STREAM_ENDPOINT_OPENED:
case AVDTP_STREAM_ENDPOINT_STREAMING:
printf(" ACP: AVDTP_ACCEPTOR_W2_ANSWER_SUSPEND_STREAM\n");
stream_endpoint->state = AVDTP_STREAM_ENDPOINT_OPENED;
connection->num_suspended_seids--;
if (connection->num_suspended_seids <= 0){
@ -341,7 +347,7 @@ int avdtp_acceptor_stream_config_subsm_run(avdtp_connection_t * connection, avdt
uint8_t * out_buffer;
uint16_t pos;
int status = 0;
switch (acceptor_config_state){
case AVDTP_ACCEPTOR_STREAM_CONFIG_IDLE:
break;
@ -381,7 +387,7 @@ int avdtp_acceptor_stream_config_subsm_run(avdtp_connection_t * connection, avdt
case AVDTP_ACCEPTOR_W2_ANSWER_GET_CONFIGURATION:{
avdtp_sep_t sep = stream_endpoint->remote_seps[stream_endpoint->remote_sep_index];
avdtp_prepare_capabilities(&connection->signaling_packet, trid, sep.registered_service_categories, sep.capabilities, AVDTP_SI_GET_CONFIGURATION);
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();
pos = avdtp_signaling_create_fragment(cid, &connection->signaling_packet, out_buffer);
@ -419,26 +425,32 @@ int avdtp_acceptor_stream_config_subsm_run(avdtp_connection_t * connection, avdt
avdtp_acceptor_send_accept_response(cid, trid, AVDTP_SI_SUSPEND);
break;
case AVDTP_ACCEPTOR_W2_REJECT_UNKNOWN_CMD:
status = 1;
printf(" ACP: DONE REJECT\n");
connection->reject_signal_identifier = 0;
avdtp_acceptor_send_response_reject(cid, reject_signal_identifier, trid);
break;
case AVDTP_ACCEPTOR_W2_REJECT_CATEGORY_WITH_ERROR_CODE:
status = 1;
printf(" ACP: DONE REJECT CATEGORY\n");
connection->reject_service_category = 0;
avdtp_acceptor_send_response_reject_service_category(cid, reject_signal_identifier, reject_service_category, error_code, trid);
break;
case AVDTP_ACCEPTOR_W2_REJECT_WITH_ERROR_CODE:
status = 1;
printf(" ACP: DONE REJECT\n");
connection->reject_signal_identifier = 0;
connection->error_code = 0;
avdtp_acceptor_send_response_reject_with_error_code(cid, reject_signal_identifier, error_code, trid);
break;
default:
status = 0;
printf(" ACP: NOT IMPLEMENTED\n");
return 0;
sent = 0;
}
avdtp_signaling_emit_done(avdtp_sink_callback, connection->con_handle, status);
if (connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET && connection->signaling_packet.packet_type != AVDTP_END_PACKET){
stream_endpoint->acceptor_config_state = acceptor_config_state;
connection->wait_to_send_acceptor = 1;

View File

@ -720,10 +720,11 @@ static int handle_l2cap_data_packet_for_signaling_connection(avdtp_connection_t
}
break;
case AVDTP_RESPONSE_ACCEPT_MSG:
printf(" AVDTP_RESPONSE_ACCEPT_MSG, identifier %d\n", connection->signaling_packet.signal_identifier);
printf(" AVDTP_RESPONSE_ACCEPT_MSG: ");
switch (connection->signaling_packet.signal_identifier){
case AVDTP_SI_DISCOVER:{
printf("AVDTP_SI_DISCOVER\n");
if (connection->signaling_packet.transaction_label != connection->initiator_transaction_label){
printf(" unexpected transaction label, got %d, expected %d\n", connection->signaling_packet.transaction_label, connection->initiator_transaction_label);
return 0;
@ -755,48 +756,88 @@ static int handle_l2cap_data_packet_for_signaling_connection(avdtp_connection_t
}
case AVDTP_SI_GET_CAPABILITIES:
case AVDTP_SI_GET_ALL_CAPABILITIES:
case AVDTP_SI_GET_CONFIGURATION:{
case AVDTP_SI_GET_ALL_CAPABILITIES:{
printf("AVDTP_SI_GET(_ALL)_CAPABILITIES\n");
avdtp_sep_t sep;
sep.seid = connection->query_seid;
sep.registered_service_categories = avdtp_unpack_service_capabilities(connection, &sep.capabilities, packet+offset, size-offset);
printf_hexdump(packet, size);
// printf_hexdump(packet, size);
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(avdtp_sink_callback, connection->con_handle, sep.capabilities.media_codec);
avdtp_signaling_emit_media_codec_sbc_capability(avdtp_sink_callback, connection->con_handle, sep.capabilities.media_codec);
break;
default:
avdtp_signaling_emit_media_codec_other(avdtp_sink_callback, connection->con_handle, sep.capabilities.media_codec);
avdtp_signaling_emit_media_codec_other_capability(avdtp_sink_callback, connection->con_handle, sep.capabilities.media_codec);
break;
}
}
avdtp_signaling_emit_done(avdtp_sink_callback, connection->con_handle, 0);
//avdtp_signaling_emit_done(avdtp_sink_callback, connection->con_handle, 0);
connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE;
return 0;
}
case AVDTP_SI_SUSPEND:
connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE;
stream_endpoint = get_avdtp_stream_endpoint_for_seid(connection->query_seid);
if (!stream_endpoint) {
avdtp_signaling_emit_done(avdtp_sink_callback, connection->con_handle, 0);
case AVDTP_SI_GET_CONFIGURATION:{
printf("AVDTP_SI_GET_CONFIGURATION 0\n");
avdtp_sep_t sep;
sep.seid = connection->query_seid;
sep.configured_service_categories = avdtp_unpack_service_capabilities(connection, &sep.configuration, packet+offset, size-offset);
sep.in_use = 1;
printf(" INT .. seid %d, configured services 0%02x\n", sep.seid, sep.configured_service_categories);
// find or add sep
// int i = 0;
// int remote_sep_index = 0xFF;
// for (i=0; i < stream_endpoint->remote_seps_num; i++){
// if (stream_endpoint->remote_seps[i].seid == sep.seid){
// remote_sep_index = i;
// }
// }
// if (remote_sep_index != 0xFF){
// stream_endpoint->remote_seps[remote_sep_index] = sep;
// printf(" ACP: update seid %d \n", stream_endpoint->remote_seps[remote_sep_index].seid);
// } else {
// // add new
// stream_endpoint->remote_seps_num++;
// stream_endpoint->remote_seps[stream_endpoint->remote_seps_num] = sep;
// printf(" ACP: add seid %d\n", stream_endpoint->remote_seps[stream_endpoint->remote_seps_num].seid);
// }
if (get_bit16(sep.configured_service_categories, AVDTP_MEDIA_CODEC)){
printf(" AVDTP_SI_GET_CONFIGURATION 1 %d\n", sep.capabilities.media_codec.media_codec_type);
switch (sep.capabilities.media_codec.media_codec_type){
case AVDTP_CODEC_SBC:
avdtp_signaling_emit_media_codec_sbc_configuration(avdtp_sink_callback, connection->con_handle, sep.capabilities.media_codec);
break;
default:
avdtp_signaling_emit_media_codec_other_configuration(avdtp_sink_callback, connection->con_handle, sep.capabilities.media_codec);
break;
}
return 0;
}
stream_endpoint->state = AVDTP_STREAM_ENDPOINT_OPENED;
printf(" AVDTP_SI_GET_CONFIGURATION 2\n");
avdtp_signaling_emit_done(avdtp_sink_callback, connection->con_handle, 0);
connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE;
return 0;
}
case AVDTP_SI_SET_CONFIGURATION:{
printf("AVDTP_SI_SET_CONFIGURATION\n");
connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE;
stream_endpoint = get_avdtp_stream_endpoint_for_seid(connection->int_seid);
if (!stream_endpoint) {
avdtp_signaling_emit_done(avdtp_sink_callback, connection->con_handle, 1);
return 0;
}
avdtp_sep_t sep;
sep.seid = connection->signaling_packet.command[3] >> 2;
sep.registered_service_categories = avdtp_unpack_service_capabilities(connection, &sep.capabilities, connection->signaling_packet.command+4, connection->signaling_packet.size-4);
sep.seid = connection->query_seid;
sep.configured_service_categories = connection->remote_capabilities_bitmap;
sep.configuration = connection->remote_capabilities;
sep.in_use = 1;
// find or add sep
@ -824,7 +865,56 @@ static int handle_l2cap_data_packet_for_signaling_connection(avdtp_connection_t
avdtp_signaling_emit_done(avdtp_sink_callback, connection->con_handle, 0);
return 0;
}
case AVDTP_SI_RECONFIGURE:
printf("AVDTP_SI_RECONFIGURE\n");
connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE;
stream_endpoint = get_avdtp_stream_endpoint_for_seid(connection->int_seid);
if (!stream_endpoint) {
avdtp_signaling_emit_done(avdtp_sink_callback, connection->con_handle, 1);
return 0;
}
avdtp_sep_t sep;
sep.seid = connection->query_seid;
sep.configured_service_categories = avdtp_unpack_service_capabilities(connection, &sep.configuration, connection->signaling_packet.command+4, connection->signaling_packet.size-4);
sep.in_use = 1;
// 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){
stream_endpoint->remote_sep_index = i;
break;
}
}
if (stream_endpoint->remote_sep_index != 0xFF){
stream_endpoint->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);
} else {
// add error
}
avdtp_signaling_emit_done(avdtp_sink_callback, connection->con_handle, 0);
return 0;
case AVDTP_SI_SUSPEND:
printf("AVDTP_SI_SUSPEND\n");
connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE;
stream_endpoint = get_avdtp_stream_endpoint_for_seid(connection->query_seid);
if (!stream_endpoint) {
avdtp_signaling_emit_done(avdtp_sink_callback, connection->con_handle, 0);
return 0;
}
stream_endpoint->state = AVDTP_STREAM_ENDPOINT_OPENED;
avdtp_signaling_emit_done(avdtp_sink_callback, connection->con_handle, 0);
return 0;
case AVDTP_SI_START:
printf("AVDTP_SI_START\n");
connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE;
stream_endpoint = get_avdtp_stream_endpoint_for_seid(connection->query_seid);
if (!stream_endpoint) {
@ -835,6 +925,7 @@ static int handle_l2cap_data_packet_for_signaling_connection(avdtp_connection_t
avdtp_signaling_emit_done(avdtp_sink_callback, connection->con_handle, 0);
break;
case AVDTP_SI_OPEN:
printf("AVDTP_SI_OPEN\n");
connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE;
stream_endpoint = get_avdtp_stream_endpoint_for_seid(connection->query_seid);
if (!stream_endpoint) {
@ -846,6 +937,7 @@ static int handle_l2cap_data_packet_for_signaling_connection(avdtp_connection_t
return 0;
case AVDTP_SI_CLOSE:
printf("AVDTP_SI_CLOSE\n");
connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE;
stream_endpoint = get_avdtp_stream_endpoint_for_seid(connection->query_seid);
if (!stream_endpoint) {
@ -857,6 +949,7 @@ static int handle_l2cap_data_packet_for_signaling_connection(avdtp_connection_t
return 0;
case AVDTP_SI_ABORT:
printf("AVDTP_SI_ABORT\n");
connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE;
stream_endpoint = get_avdtp_stream_endpoint_for_seid(connection->query_seid);
if (!stream_endpoint) {
@ -867,10 +960,6 @@ static int handle_l2cap_data_packet_for_signaling_connection(avdtp_connection_t
avdtp_signaling_emit_done(avdtp_sink_callback, connection->con_handle, 0);
return 0;
case AVDTP_SI_RECONFIGURE:
connection->initiator_connection_state = AVDTP_SIGNALING_CONNECTION_INITIATOR_IDLE;
avdtp_signaling_emit_done(avdtp_sink_callback, connection->con_handle, 0);
return 0;
default:
avdtp_signaling_emit_done(avdtp_sink_callback, connection->con_handle, 1);
printf(" AVDTP_RESPONSE_ACCEPT_MSG, signal %d not implemented\n", connection->signaling_packet.signal_identifier);

View File

@ -153,22 +153,37 @@ typedef struct {
uint8_t max_bitpool_value;
} adtvp_media_codec_information_sbc_t;
typedef struct {
int num_channels;
int sampling_frequency;
int channel_mode;
int block_length;
int subbands;
int allocation_method;
int min_bitpool_value;
int max_bitpool_value;
int frames_per_buffer;
} avdtp_media_codec_configuration_sbc_t;
// mac: static bd_addr_t remote = {0x04, 0x0C, 0xCE, 0xE4, 0x85, 0xD3};
// pts: static bd_addr_t remote = {0x00, 0x1B, 0xDC, 0x08, 0x0A, 0xA5};
static bd_addr_t remote = {0x00, 0x1B, 0xDC, 0x08, 0x0A, 0xA5};
static uint16_t con_handle = 0;
static uint8_t sdp_avdtp_sink_service_buffer[150];
static avdtp_sep_t sep;
static adtvp_media_codec_information_sbc_t sbc;
static uint16_t remote_capabilities_bitmap;
static avdtp_capabilities_t remote_capabilities;
static adtvp_media_codec_information_sbc_t sbc_capability;
static avdtp_media_codec_configuration_sbc_t sbc_configuration;
static uint16_t remote_configuration_bitmap;
static avdtp_capabilities_t remote_configuration;
typedef enum {
AVDTP_APPLICATION_IDLE,
AVDTP_APPLICATION_W2_DISCOVER_SEPS,
AVDTP_APPLICATION_W2_GET_CAPABILITIES,
AVDTP_APPLICATION_W2_GET_ALL_CAPABILITIES,
AVDTP_APPLICATION_W2_SET_CAPABILITIES,
AVDTP_APPLICATION_W2_SET_CONFIGURATION,
AVDTP_APPLICATION_W2_SUSPEND_STREAM_WITH_SEID,
AVDTP_APPLICATION_W2_RECONFIGURE_WITH_SEID,
AVDTP_APPLICATION_W2_OPEN_STREAM_WITH_SEID,
@ -184,57 +199,11 @@ static btstack_packet_callback_registration_t hci_event_callback_registration;
static int media_initialized = 0;
static int init_media_processing(adtvp_media_codec_information_sbc_t media_codec_sbc){
int num_channels = NUM_CHANNELS;
int sample_rate = SAMPLE_RATE;
int frames_per_buffer = FRAMES_PER_BUFFER;
int subbands = 8;
int block_length = 16;
if (media_codec_sbc.channel_mode_bitmap & AVDTP_SBC_MONO){
num_channels = 1;
}
if ( (media_codec_sbc.channel_mode_bitmap & AVDTP_SBC_JOINT_STEREO) ||
(media_codec_sbc.channel_mode_bitmap & AVDTP_SBC_STEREO) ||
(media_codec_sbc.channel_mode_bitmap & AVDTP_SBC_DUAL_CHANNEL) ){
num_channels = 2;
}
if (media_codec_sbc.sampling_frequency_bitmap & AVDTP_SBC_16000){
sample_rate = 16000;
}
if (media_codec_sbc.sampling_frequency_bitmap & AVDTP_SBC_32000){
sample_rate = 32000;
}
if (media_codec_sbc.sampling_frequency_bitmap & AVDTP_SBC_44100){
sample_rate = 44100;
}
if (media_codec_sbc.sampling_frequency_bitmap & AVDTP_SBC_48000){
sample_rate = 48000;
}
if (media_codec_sbc.subbands_bitmap & AVDTP_SBC_SUBBANDS_4){
subbands = 4;
}
if (media_codec_sbc.subbands_bitmap & AVDTP_SBC_SUBBANDS_8){
subbands = 8;
}
if (media_codec_sbc.block_length_bitmap & AVDTP_SBC_BLOCK_LENGTH_4){
block_length = 4;
}
if (media_codec_sbc.block_length_bitmap & AVDTP_SBC_BLOCK_LENGTH_8){
block_length = 8;
}
if (media_codec_sbc.block_length_bitmap & AVDTP_SBC_BLOCK_LENGTH_12){
block_length = 12;
}
if (media_codec_sbc.block_length_bitmap & AVDTP_SBC_BLOCK_LENGTH_16){
block_length = 16;
}
frames_per_buffer = subbands * block_length;
static int init_media_processing(avdtp_media_codec_configuration_sbc_t configuration){
int num_channels = configuration.num_channels;
int sample_rate = configuration.sampling_frequency;
int frames_per_buffer = configuration.frames_per_buffer;
#ifdef STORE_SBC_TO_WAV_FILE
btstack_sbc_decoder_init(&state, mode, handle_pcm_data, NULL);
wav_writer_open(wav_filename, num_channels, sample_rate);
@ -370,7 +339,7 @@ static void handle_l2cap_media_data_packet(avdtp_stream_endpoint_t * stream_endp
#endif
}
static void dump_media_codec_sbc(adtvp_media_codec_information_sbc_t media_codec_sbc){
static void dump_sbc_capability(adtvp_media_codec_information_sbc_t media_codec_sbc){
printf("Received media codec capability:\n");
printf(" - sampling_frequency: 0x%02x\n", media_codec_sbc.sampling_frequency_bitmap);
printf(" - channel_mode: 0x%02x\n", media_codec_sbc.channel_mode_bitmap);
@ -380,6 +349,17 @@ static void dump_media_codec_sbc(adtvp_media_codec_information_sbc_t media_codec
printf(" - bitpool_value [%d, %d] \n", media_codec_sbc.min_bitpool_value, media_codec_sbc.max_bitpool_value);
}
static void dump_sbc_configuration(avdtp_media_codec_configuration_sbc_t configuration){
printf("Received media codec configuration:\n");
printf(" - num_channels: %d\n", configuration.num_channels);
printf(" - sampling_frequency: %d\n", configuration.sampling_frequency);
printf(" - channel_mode: %d\n", configuration.channel_mode);
printf(" - block_length: %d\n", configuration.block_length);
printf(" - subbands: %d\n", configuration.subbands);
printf(" - allocation_method: %d\n", configuration.allocation_method);
printf(" - bitpool_value [%d, %d] \n", configuration.min_bitpool_value, configuration.max_bitpool_value);
}
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
bd_addr_t event_addr;
@ -424,18 +404,33 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
sep.type = avdtp_subevent_signaling_sep_found_get_sep_type(packet);
printf("found sep: seid %u, in_use %d, media type %d, sep type %d (1-SNK)\n", sep.seid, sep.in_use, sep.media_type, sep.type);
break;
case AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC:
sbc.sampling_frequency_bitmap = avdtp_subevent_signaling_media_codec_sbc_get_sampling_frequency(packet);
sbc.channel_mode_bitmap = avdtp_subevent_signaling_media_codec_sbc_get_channel_mode(packet);
sbc.block_length_bitmap = avdtp_subevent_signaling_media_codec_sbc_get_block_length(packet);
sbc.subbands_bitmap = avdtp_subevent_signaling_media_codec_sbc_get_subbands(packet);
sbc.allocation_method_bitmap = avdtp_subevent_signaling_media_codec_sbc_get_allocation_method(packet);
sbc.min_bitpool_value = avdtp_subevent_signaling_media_codec_sbc_get_min_bitpool_value(packet);
sbc.max_bitpool_value = avdtp_subevent_signaling_media_codec_sbc_get_max_bitpool_value(packet);
dump_media_codec_sbc(sbc);
init_media_processing(sbc);
case AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CAPABILITY:
app_state = AVDTP_APPLICATION_IDLE;
sbc_capability.sampling_frequency_bitmap = avdtp_subevent_signaling_media_codec_sbc_capability_get_sampling_frequency_bitmap(packet);
sbc_capability.channel_mode_bitmap = avdtp_subevent_signaling_media_codec_sbc_capability_get_channel_mode_bitmap(packet);
sbc_capability.block_length_bitmap = avdtp_subevent_signaling_media_codec_sbc_capability_get_block_length_bitmap(packet);
sbc_capability.subbands_bitmap = avdtp_subevent_signaling_media_codec_sbc_capability_get_subbands_bitmap(packet);
sbc_capability.allocation_method_bitmap = avdtp_subevent_signaling_media_codec_sbc_capability_get_allocation_method_bitmap(packet);
sbc_capability.min_bitpool_value = avdtp_subevent_signaling_media_codec_sbc_capability_get_min_bitpool_value(packet);
sbc_capability.max_bitpool_value = avdtp_subevent_signaling_media_codec_sbc_capability_get_max_bitpool_value(packet);
dump_sbc_capability(sbc_capability);
break;
case AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER:
case AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION:{
app_state = AVDTP_APPLICATION_IDLE;
sbc_configuration.num_channels = avdtp_subevent_signaling_media_codec_sbc_configuration_get_num_channels(packet);
sbc_configuration.sampling_frequency = avdtp_subevent_signaling_media_codec_sbc_configuration_get_sampling_frequency(packet);
sbc_configuration.channel_mode = avdtp_subevent_signaling_media_codec_sbc_configuration_get_channel_mode(packet);
sbc_configuration.block_length = avdtp_subevent_signaling_media_codec_sbc_configuration_get_block_length(packet);
sbc_configuration.subbands = avdtp_subevent_signaling_media_codec_sbc_configuration_get_subbands(packet);
sbc_configuration.allocation_method = avdtp_subevent_signaling_media_codec_sbc_configuration_get_allocation_method(packet);
sbc_configuration.min_bitpool_value = avdtp_subevent_signaling_media_codec_sbc_configuration_get_min_bitpool_value(packet);
sbc_configuration.max_bitpool_value = avdtp_subevent_signaling_media_codec_sbc_configuration_get_max_bitpool_value(packet);
sbc_configuration.frames_per_buffer = sbc_configuration.subbands * sbc_configuration.block_length;
dump_sbc_configuration(sbc_configuration);
init_media_processing(sbc_configuration);
break;
}
case AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CAPABILITY:
printf(" received non SBC codec. not implemented\n");
break;
case AVDTP_SUBEVENT_SIGNALING_DONE:
@ -508,23 +503,23 @@ static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callbac
app_state = AVDTP_APPLICATION_W2_GET_CAPABILITIES;
avdtp_sink_get_capabilities(con_handle, sep.seid);
break;
case 'f':
app_state = AVDTP_APPLICATION_W2_GET_CONFIGURATION;
avdtp_sink_get_configuration(con_handle, sep.seid);
break;
case 'a':
app_state = AVDTP_APPLICATION_W2_GET_ALL_CAPABILITIES;
avdtp_sink_get_all_capabilities(con_handle, sep.seid);
break;
case 'f':
app_state = AVDTP_APPLICATION_W2_GET_CONFIGURATION;
avdtp_sink_get_configuration(con_handle, sep.seid);
break;
case 's':
app_state = AVDTP_APPLICATION_W2_SET_CAPABILITIES;
remote_capabilities_bitmap = store_bit16(remote_capabilities_bitmap, AVDTP_MEDIA_CODEC, 1);
remote_capabilities.media_codec.media_type = AVDTP_AUDIO;
remote_capabilities.media_codec.media_codec_type = AVDTP_CODEC_SBC;
app_state = AVDTP_APPLICATION_W2_SET_CONFIGURATION;
remote_configuration_bitmap = store_bit16(remote_configuration_bitmap, AVDTP_MEDIA_CODEC, 1);
remote_configuration.media_codec.media_type = AVDTP_AUDIO;
remote_configuration.media_codec.media_codec_type = AVDTP_CODEC_SBC;
remote_capabilities.media_codec.media_codec_information_len = sizeof(media_sbc_codec_info);
remote_capabilities.media_codec.media_codec_information = media_sbc_codec_info;
avdtp_sink_set_configuration(con_handle, sep.seid, 1, remote_capabilities_bitmap, remote_capabilities);
remote_configuration.media_codec.media_codec_information_len = sizeof(media_sbc_codec_info);
remote_configuration.media_codec.media_codec_information = media_sbc_codec_info;
avdtp_sink_set_configuration(con_handle, sep.seid, 1, remote_configuration_bitmap, remote_configuration);
break;
case 'R':
app_state = AVDTP_APPLICATION_W2_RECONFIGURE_WITH_SEID;

View File

@ -148,7 +148,7 @@ int avdtp_pack_service_capabilities(uint8_t * buffer, int size, avdtp_capabiliti
static int avdtp_unpack_service_capabilities_has_errors(avdtp_connection_t * connection, avdtp_service_category_t category, uint8_t cap_len){
connection->error_code = 0;
if (category == AVDTP_SERVICE_CATEGORY_INVALID_0 || category == AVDTP_SERVICE_CATEGORY_INVALID_FF){
if (category == AVDTP_SERVICE_CATEGORY_INVALID_0 ){//|| category == AVDTP_SERVICE_CATEGORY_INVALID_FF){
printf(" ERROR: BAD SERVICE CATEGORY %d\n", category);
connection->reject_service_category = category;
connection->error_code = BAD_SERV_CATEGORY;
@ -259,12 +259,14 @@ uint16_t avdtp_unpack_service_capabilities(avdtp_connection_t * connection, avdt
caps->multiplexing_mode.tcid[i] = packet[pos++] >> 7;
}
break;
case AVDTP_MEDIA_CODEC:
case AVDTP_MEDIA_CODEC:
printf(" unpack AVDTP_MEDIA_CODEC ");
caps->media_codec.media_type = packet[pos++] >> 4;
caps->media_codec.media_codec_type = packet[pos++];
caps->media_codec.media_codec_information_len = cap_len - 2;
caps->media_codec.media_codec_information = &packet[pos];
pos += caps->media_codec.media_codec_information_len;
printf(" media_codec_information_len %d \n", caps->media_codec.media_codec_information_len);
break;
case AVDTP_MEDIA_TRANSPORT:
case AVDTP_REPORTING:
@ -428,13 +430,13 @@ void avdtp_signaling_emit_done(btstack_packet_handler_t callback, uint16_t con_h
(*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
void avdtp_signaling_emit_media_codec_sbc(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec){
void avdtp_signaling_emit_media_codec_sbc_capability(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec){
if (!callback) return;
uint8_t event[13];
int pos = 0;
event[pos++] = HCI_EVENT_AVDTP_META;
event[pos++] = sizeof(event) - 2;
event[pos++] = AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC;
event[pos++] = AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CAPABILITY;
little_endian_store_16(event, pos, con_handle);
pos += 2;
event[pos++] = media_codec.media_type;
@ -448,13 +450,13 @@ void avdtp_signaling_emit_media_codec_sbc(btstack_packet_handler_t callback, uin
(*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
void avdtp_signaling_emit_media_codec_other(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec){
void avdtp_signaling_emit_media_codec_other_capability(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec){
if (!callback) return;
uint8_t event[109];
uint8_t event[109];
int pos = 0;
event[pos++] = HCI_EVENT_AVDTP_META;
event[pos++] = sizeof(event) - 2;
event[pos++] = AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER;
event[pos++] = AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CAPABILITY;
little_endian_store_16(event, pos, con_handle);
pos += 2;
event[pos++] = media_codec.media_type;
@ -463,6 +465,128 @@ void avdtp_signaling_emit_media_codec_other(btstack_packet_handler_t callback, u
little_endian_store_16(event, pos, media_codec.media_codec_information_len);
pos += 2;
memcpy(event+pos, media_codec.media_codec_information, media_codec.media_codec_information_len);
(*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
static inline void avdtp_signaling_emit_media_codec_sbc(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec, uint8_t reconfigure){
if (!callback) return;
uint8_t event[15];
int pos = 0;
event[pos++] = HCI_EVENT_AVDTP_META;
event[pos++] = sizeof(event) - 2;
event[pos++] = AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION;
little_endian_store_16(event, pos, con_handle);
pos += 2;
event[pos++] = reconfigure;
printf("avdtp_signaling_emit_media_codec_sbc 1\n");
uint8_t num_channels = 0;
uint16_t sampling_frequency = 0;
uint8_t subbands = 0;
uint8_t block_length = 0;
uint8_t sampling_frequency_bitmap = media_codec.media_codec_information[0] >> 4;
uint8_t channel_mode_bitmap = media_codec.media_codec_information[0] & 0x0F;
uint8_t block_length_bitmap = media_codec.media_codec_information[1] >> 4;
uint8_t subbands_bitmap = (media_codec.media_codec_information[1] & 0x0F) >> 2;
if (channel_mode_bitmap & AVDTP_SBC_MONO){
num_channels = 1;
}
if ( (channel_mode_bitmap & AVDTP_SBC_JOINT_STEREO) ||
(channel_mode_bitmap & AVDTP_SBC_STEREO) ||
(channel_mode_bitmap & AVDTP_SBC_DUAL_CHANNEL) ){
num_channels = 2;
}
if (sampling_frequency_bitmap & AVDTP_SBC_16000){
sampling_frequency = 16000;
}
if (sampling_frequency_bitmap & AVDTP_SBC_32000){
sampling_frequency = 32000;
}
if (sampling_frequency_bitmap & AVDTP_SBC_44100){
sampling_frequency = 44100;
}
if (sampling_frequency_bitmap & AVDTP_SBC_48000){
sampling_frequency = 48000;
}
if (subbands_bitmap & AVDTP_SBC_SUBBANDS_4){
subbands = 4;
}
if (subbands_bitmap & AVDTP_SBC_SUBBANDS_8){
subbands = 8;
}
if (block_length_bitmap & AVDTP_SBC_BLOCK_LENGTH_4){
block_length = 4;
}
if (block_length_bitmap & AVDTP_SBC_BLOCK_LENGTH_8){
block_length = 8;
}
if (block_length_bitmap & AVDTP_SBC_BLOCK_LENGTH_12){
block_length = 12;
}
if (block_length_bitmap & AVDTP_SBC_BLOCK_LENGTH_16){
block_length = 16;
}
printf("avdtp_signaling_emit_media_codec_sbc 2\n");
event[pos++] = media_codec.media_type;
little_endian_store_16(event, pos, sampling_frequency);
pos += 2;
event[pos++] = channel_mode_bitmap;
event[pos++] = num_channels;
event[pos++] = block_length;
event[pos++] = subbands;
event[pos++] = media_codec.media_codec_information[1] & 0x03;
event[pos++] = media_codec.media_codec_information[2];
event[pos++] = media_codec.media_codec_information[3];
printf("avdtp_signaling_emit_media_codec_sbc 3\n");
(*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
void avdtp_signaling_emit_media_codec_sbc_configuration(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec){
if (!callback) return;
avdtp_signaling_emit_media_codec_sbc(callback, con_handle, media_codec, 0);
}
void avdtp_signaling_emit_media_codec_sbc_reconfiguration(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec){
if (!callback) return;
avdtp_signaling_emit_media_codec_sbc(callback, con_handle, media_codec, 1);
}
static inline void avdtp_signaling_emit_media_codec_other(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec, uint8_t reconfigure){
uint8_t event[110];
int pos = 0;
event[pos++] = HCI_EVENT_AVDTP_META;
event[pos++] = sizeof(event) - 2;
event[pos++] = AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_OTHER_CONFIGURATION;
little_endian_store_16(event, pos, con_handle);
pos += 2;
event[pos++] = reconfigure;
event[pos++] = media_codec.media_type;
little_endian_store_16(event, pos, media_codec.media_codec_type);
pos += 2;
little_endian_store_16(event, pos, media_codec.media_codec_information_len);
pos += 2;
printf("avdtp_signaling_emit_media_codec_other pos %d, info len %d\n", pos, media_codec.media_codec_information_len);
memcpy(event+pos, media_codec.media_codec_information, media_codec.media_codec_information_len);
(*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
void avdtp_signaling_emit_media_codec_other_configuration(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec){
if (!callback) return;
avdtp_signaling_emit_media_codec_other(callback, con_handle, media_codec, 0);
}
void avdtp_signaling_emit_media_codec_other_reconfiguration(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec){
if (!callback) return;
avdtp_signaling_emit_media_codec_other(callback, con_handle, media_codec, 1);
}

View File

@ -66,8 +66,13 @@ int avdtp_signaling_create_fragment(uint16_t cid, avdtp_signaling_packet_t * sig
void avdtp_signaling_emit_connection_established(btstack_packet_handler_t callback, uint16_t con_handle, bd_addr_t addr, uint8_t status);
void avdtp_signaling_emit_sep(btstack_packet_handler_t callback, uint16_t con_handle, avdtp_sep_t sep);
void avdtp_signaling_emit_done(btstack_packet_handler_t callback, uint16_t con_handle, uint8_t status);
void avdtp_signaling_emit_media_codec_sbc(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec);
void avdtp_signaling_emit_media_codec_other(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec);
void avdtp_signaling_emit_media_codec_sbc_capability(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec);
void avdtp_signaling_emit_media_codec_other_capability(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec);
void avdtp_signaling_emit_media_codec_sbc_configuration(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec);
void avdtp_signaling_emit_media_codec_other_configuration(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec);
void avdtp_signaling_emit_media_codec_sbc_reconfiguration(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec);
void avdtp_signaling_emit_media_codec_other_reconfiguration(btstack_packet_handler_t callback, uint16_t con_handle, adtvp_media_codec_capabilities_t media_codec);
#if defined __cplusplus
}