mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-14 01:27:41 +00:00
handle sdp query
This commit is contained in:
parent
1c326df36c
commit
692c060596
@ -50,7 +50,37 @@
|
||||
#include "avdtp_acceptor.h"
|
||||
#include "avdtp_initiator.h"
|
||||
|
||||
static int record_id = -1;
|
||||
static uint8_t attribute_value[1000];
|
||||
static const unsigned int attribute_value_buffer_size = sizeof(attribute_value);
|
||||
|
||||
typedef struct {
|
||||
avdtp_connection_t * connection;
|
||||
btstack_packet_handler_t avdtp_callback;
|
||||
avdtp_sep_type_t query_role;
|
||||
btstack_packet_handler_t packet_handler;
|
||||
} avdtp_sdp_query_context_t;
|
||||
|
||||
static avdtp_sdp_query_context_t sdp_query_context;
|
||||
|
||||
static void (*handle_media_data)(avdtp_stream_endpoint_t * stream_endpoint, uint8_t *packet, uint16_t size);
|
||||
static void avdtp_handle_sdp_client_query_result(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
|
||||
void avdtp_connect(bd_addr_t remote, avdtp_sep_type_t query_role, avdtp_context_t * avdtp_context){
|
||||
sdp_query_context.connection = NULL;
|
||||
avdtp_connection_t * connection = avdtp_connection_for_bd_addr(remote, avdtp_context);
|
||||
if (!connection){
|
||||
connection = avdtp_create_connection(remote, avdtp_context);
|
||||
}
|
||||
if (connection->state != AVDTP_SIGNALING_CONNECTION_IDLE) return;
|
||||
connection->state = AVDTP_SIGNALING_W4_SDP_QUERY_COMPLETE;
|
||||
sdp_query_context.connection = connection;
|
||||
sdp_query_context.query_role = query_role;
|
||||
sdp_query_context.avdtp_callback = avdtp_context->avdtp_callback;
|
||||
sdp_query_context.packet_handler = avdtp_context->packet_handler;
|
||||
|
||||
sdp_client_query_uuid16(&avdtp_handle_sdp_client_query_result, remote, BLUETOOTH_PROTOCOL_AVDTP);
|
||||
}
|
||||
|
||||
void avdtp_register_media_transport_category(avdtp_stream_endpoint_t * stream_endpoint){
|
||||
if (!stream_endpoint){
|
||||
@ -272,6 +302,119 @@ static void stream_endpoint_state_machine(avdtp_connection_t * connection, avdtp
|
||||
}
|
||||
}
|
||||
|
||||
static void avdtp_handle_sdp_client_query_result(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
UNUSED(packet_type);
|
||||
UNUSED(channel);
|
||||
UNUSED(size);
|
||||
|
||||
des_iterator_t des_list_it;
|
||||
des_iterator_t prot_it;
|
||||
uint32_t avdtp_remote_uuid = 0;
|
||||
uint16_t avdtp_l2cap_psm = 0;
|
||||
uint16_t avdtp_version = 0;
|
||||
|
||||
if (!sdp_query_context.connection) return;
|
||||
|
||||
switch (hci_event_packet_get_type(packet)){
|
||||
case SDP_EVENT_QUERY_ATTRIBUTE_VALUE:
|
||||
// Handle new SDP record
|
||||
if (sdp_event_query_attribute_byte_get_record_id(packet) != record_id) {
|
||||
record_id = sdp_event_query_attribute_byte_get_record_id(packet);
|
||||
printf("SDP Record: Nr: %d\n", record_id);
|
||||
}
|
||||
|
||||
if (sdp_event_query_attribute_byte_get_attribute_length(packet) <= attribute_value_buffer_size) {
|
||||
attribute_value[sdp_event_query_attribute_byte_get_data_offset(packet)] = sdp_event_query_attribute_byte_get_data(packet);
|
||||
|
||||
if ((uint16_t)(sdp_event_query_attribute_byte_get_data_offset(packet)+1) == sdp_event_query_attribute_byte_get_attribute_length(packet)) {
|
||||
|
||||
switch(sdp_event_query_attribute_byte_get_attribute_id(packet)) {
|
||||
case BLUETOOTH_ATTRIBUTE_SERVICE_CLASS_ID_LIST:
|
||||
if (de_get_element_type(attribute_value) != DE_DES) break;
|
||||
for (des_iterator_init(&des_list_it, attribute_value); des_iterator_has_more(&des_list_it); des_iterator_next(&des_list_it)) {
|
||||
uint8_t * element = des_iterator_get_element(&des_list_it);
|
||||
if (de_get_element_type(element) != DE_UUID) continue;
|
||||
uint32_t uuid = de_get_uuid32(element);
|
||||
switch (uuid){
|
||||
case BLUETOOTH_SERVICE_CLASS_AUDIO_SOURCE:
|
||||
if (sdp_query_context.query_role != AVDTP_SOURCE) {
|
||||
sdp_query_context.connection->state = AVDTP_SIGNALING_CONNECTION_IDLE;
|
||||
avdtp_signaling_emit_connection_established(sdp_query_context.avdtp_callback, sdp_query_context.connection->l2cap_signaling_cid, sdp_query_context.connection->remote_addr, 0);
|
||||
break;
|
||||
}
|
||||
printf("SDP Attribute 0x%04x: AVDTP SOURCE protocol UUID: 0x%04x\n", sdp_event_query_attribute_byte_get_attribute_id(packet), uuid);
|
||||
avdtp_remote_uuid = uuid;
|
||||
break;
|
||||
case BLUETOOTH_SERVICE_CLASS_AUDIO_SINK:
|
||||
if (sdp_query_context.query_role != AVDTP_SINK) {
|
||||
sdp_query_context.connection->state = AVDTP_SIGNALING_CONNECTION_IDLE;
|
||||
avdtp_signaling_emit_connection_established(sdp_query_context.avdtp_callback, sdp_query_context.connection->l2cap_signaling_cid, sdp_query_context.connection->remote_addr, 0);
|
||||
break;
|
||||
}
|
||||
printf("SDP Attribute 0x%04x: AVDTP SINK protocol UUID: 0x%04x\n", sdp_event_query_attribute_byte_get_attribute_id(packet), uuid);
|
||||
avdtp_remote_uuid = uuid;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case BLUETOOTH_ATTRIBUTE_PROTOCOL_DESCRIPTOR_LIST: {
|
||||
printf("SDP Attribute: 0x%04x\n", sdp_event_query_attribute_byte_get_attribute_id(packet));
|
||||
|
||||
for (des_iterator_init(&des_list_it, attribute_value); des_iterator_has_more(&des_list_it); des_iterator_next(&des_list_it)) {
|
||||
uint8_t *des_element;
|
||||
uint8_t *element;
|
||||
uint32_t uuid;
|
||||
|
||||
if (des_iterator_get_type(&des_list_it) != DE_DES) continue;
|
||||
|
||||
des_element = des_iterator_get_element(&des_list_it);
|
||||
des_iterator_init(&prot_it, des_element);
|
||||
element = des_iterator_get_element(&prot_it);
|
||||
|
||||
if (de_get_element_type(element) != DE_UUID) continue;
|
||||
|
||||
uuid = de_get_uuid32(element);
|
||||
switch (uuid){
|
||||
case BLUETOOTH_PROTOCOL_L2CAP:
|
||||
if (!des_iterator_has_more(&prot_it)) continue;
|
||||
des_iterator_next(&prot_it);
|
||||
de_element_get_uint16(des_iterator_get_element(&prot_it), &avdtp_l2cap_psm);
|
||||
break;
|
||||
case BLUETOOTH_PROTOCOL_AVDTP:
|
||||
if (!des_iterator_has_more(&prot_it)) continue;
|
||||
des_iterator_next(&prot_it);
|
||||
de_element_get_uint16(des_iterator_get_element(&prot_it), &avdtp_version);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("l2cap_psm 0x%04x, avdtp_version 0x%04x\n", avdtp_l2cap_psm, avdtp_version);
|
||||
|
||||
/* Create AVDTP connection */
|
||||
sdp_query_context.connection->state = AVDTP_SIGNALING_CONNECTION_W4_L2CAP_CONNECTED;
|
||||
l2cap_create_channel(sdp_query_context.packet_handler, sdp_query_context.connection->remote_addr, avdtp_l2cap_psm, l2cap_max_mtu(), NULL);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "SDP attribute value buffer size exceeded: available %d, required %d\n", attribute_value_buffer_size, sdp_event_query_attribute_byte_get_attribute_length(packet));
|
||||
}
|
||||
break;
|
||||
|
||||
case SDP_EVENT_QUERY_COMPLETE:
|
||||
fprintf(stderr, "General query done with status %d.\n", sdp_event_query_complete_get_status(packet));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void avdtp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size, avdtp_context_t * context){
|
||||
bd_addr_t event_addr;
|
||||
hci_con_handle_t con_handle;
|
||||
|
@ -493,6 +493,7 @@ void avdtp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet
|
||||
avdtp_connection_t * avdtp_create_connection(bd_addr_t remote_addr, avdtp_context_t * context);
|
||||
avdtp_stream_endpoint_t * avdtp_create_stream_endpoint(avdtp_sep_type_t sep_type, avdtp_media_type_t media_type, avdtp_context_t * context);
|
||||
|
||||
void avdtp_connect(bd_addr_t remote, avdtp_sep_type_t query_role, avdtp_context_t * context);
|
||||
void avdtp_disconnect(uint16_t avdtp_cid, avdtp_context_t * context);
|
||||
void avdtp_open_stream(uint16_t avdtp_cid, uint8_t int_seid, uint8_t acp_seid, avdtp_context_t * context);
|
||||
void avdtp_start_stream(uint8_t int_seid, avdtp_context_t * context);
|
||||
@ -520,6 +521,7 @@ uint8_t avdtp_choose_sbc_max_bitpool_value(avdtp_stream_endpoint_t * stream_endp
|
||||
uint8_t avdtp_choose_sbc_min_bitpool_value(avdtp_stream_endpoint_t * stream_endpoint, uint8_t remote_min_bitpool_value);
|
||||
|
||||
uint8_t avdtp_stream_endpoint_seid(avdtp_stream_endpoint_t * stream_endpoint);
|
||||
|
||||
#if defined __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -137,14 +137,8 @@ void avdtp_sink_register_packet_handler(btstack_packet_handler_t callback){
|
||||
avdtp_sink_context.avdtp_callback = callback;
|
||||
}
|
||||
|
||||
void avdtp_sink_connect(bd_addr_t bd_addr){
|
||||
avdtp_connection_t * connection = avdtp_connection_for_bd_addr(bd_addr, &avdtp_sink_context);
|
||||
if (!connection){
|
||||
connection = avdtp_create_connection(bd_addr, &avdtp_sink_context);
|
||||
}
|
||||
if (connection->state != AVDTP_SIGNALING_CONNECTION_IDLE) return;
|
||||
connection->state = AVDTP_SIGNALING_CONNECTION_W4_L2CAP_CONNECTED;
|
||||
l2cap_create_channel(packet_handler, connection->remote_addr, BLUETOOTH_PROTOCOL_AVDTP, 0xffff, NULL);
|
||||
void avdtp_sink_connect(bd_addr_t remote){
|
||||
avdtp_connect(remote, AVDTP_SOURCE, &avdtp_sink_context);
|
||||
}
|
||||
|
||||
void avdtp_sink_disconnect(uint16_t avdtp_cid){
|
||||
|
@ -52,12 +52,8 @@
|
||||
#include "avdtp_source.h"
|
||||
|
||||
static avdtp_context_t * avdtp_source_context;
|
||||
static avdtp_connection_t * avtdp_connection_doing_sdp_query = NULL;
|
||||
static int record_id = -1;
|
||||
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
|
||||
static uint8_t attribute_value[1000];
|
||||
static const unsigned int attribute_value_buffer_size = sizeof(attribute_value);
|
||||
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
|
||||
void avdtp_source_register_media_transport_category(uint8_t seid){
|
||||
avdtp_stream_endpoint_t * stream_endpoint = avdtp_stream_endpoint_for_seid(seid, avdtp_source_context);
|
||||
@ -111,118 +107,8 @@ void avdtp_source_register_packet_handler(btstack_packet_handler_t callback){
|
||||
avdtp_source_context->avdtp_callback = callback;
|
||||
}
|
||||
|
||||
static void avdtp_source_handle_sdp_client_query_result(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
UNUSED(packet_type);
|
||||
UNUSED(channel);
|
||||
UNUSED(size);
|
||||
|
||||
des_iterator_t des_list_it;
|
||||
des_iterator_t prot_it;
|
||||
uint32_t avdtp_remote_uuid = 0;
|
||||
uint16_t avdtp_l2cap_psm = 0;
|
||||
uint16_t avdtp_version = 0;
|
||||
|
||||
if (!avtdp_connection_doing_sdp_query) return;
|
||||
|
||||
switch (hci_event_packet_get_type(packet)){
|
||||
case SDP_EVENT_QUERY_ATTRIBUTE_VALUE:
|
||||
// Handle new SDP record
|
||||
if (sdp_event_query_attribute_byte_get_record_id(packet) != record_id) {
|
||||
record_id = sdp_event_query_attribute_byte_get_record_id(packet);
|
||||
printf("SDP Record: Nr: %d\n", record_id);
|
||||
}
|
||||
|
||||
if (sdp_event_query_attribute_byte_get_attribute_length(packet) <= attribute_value_buffer_size) {
|
||||
attribute_value[sdp_event_query_attribute_byte_get_data_offset(packet)] = sdp_event_query_attribute_byte_get_data(packet);
|
||||
|
||||
if ((uint16_t)(sdp_event_query_attribute_byte_get_data_offset(packet)+1) == sdp_event_query_attribute_byte_get_attribute_length(packet)) {
|
||||
|
||||
switch(sdp_event_query_attribute_byte_get_attribute_id(packet)) {
|
||||
case BLUETOOTH_ATTRIBUTE_SERVICE_CLASS_ID_LIST:
|
||||
if (de_get_element_type(attribute_value) != DE_DES) break;
|
||||
for (des_iterator_init(&des_list_it, attribute_value); des_iterator_has_more(&des_list_it); des_iterator_next(&des_list_it)) {
|
||||
uint8_t * element = des_iterator_get_element(&des_list_it);
|
||||
if (de_get_element_type(element) != DE_UUID) continue;
|
||||
uint32_t uuid = de_get_uuid32(element);
|
||||
switch (uuid){
|
||||
case BLUETOOTH_SERVICE_CLASS_AUDIO_SOURCE:
|
||||
printf("SDP Attribute 0x%04x: AVDTP SOURCE protocol UUID: 0x%04x\n", sdp_event_query_attribute_byte_get_attribute_id(packet), uuid);
|
||||
avdtp_remote_uuid = uuid;
|
||||
break;
|
||||
case BLUETOOTH_SERVICE_CLASS_AUDIO_SINK:
|
||||
printf("SDP Attribute 0x%04x: AVDTP SINK protocol UUID: 0x%04x\n", sdp_event_query_attribute_byte_get_attribute_id(packet), uuid);
|
||||
avdtp_remote_uuid = uuid;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case BLUETOOTH_ATTRIBUTE_PROTOCOL_DESCRIPTOR_LIST: {
|
||||
printf("SDP Attribute: 0x%04x\n", sdp_event_query_attribute_byte_get_attribute_id(packet));
|
||||
|
||||
for (des_iterator_init(&des_list_it, attribute_value); des_iterator_has_more(&des_list_it); des_iterator_next(&des_list_it)) {
|
||||
uint8_t *des_element;
|
||||
uint8_t *element;
|
||||
uint32_t uuid;
|
||||
|
||||
if (des_iterator_get_type(&des_list_it) != DE_DES) continue;
|
||||
|
||||
des_element = des_iterator_get_element(&des_list_it);
|
||||
des_iterator_init(&prot_it, des_element);
|
||||
element = des_iterator_get_element(&prot_it);
|
||||
|
||||
if (de_get_element_type(element) != DE_UUID) continue;
|
||||
|
||||
uuid = de_get_uuid32(element);
|
||||
switch (uuid){
|
||||
case BLUETOOTH_PROTOCOL_L2CAP:
|
||||
if (!des_iterator_has_more(&prot_it)) continue;
|
||||
des_iterator_next(&prot_it);
|
||||
de_element_get_uint16(des_iterator_get_element(&prot_it), &avdtp_l2cap_psm);
|
||||
break;
|
||||
case BLUETOOTH_PROTOCOL_AVDTP:
|
||||
if (!des_iterator_has_more(&prot_it)) continue;
|
||||
des_iterator_next(&prot_it);
|
||||
de_element_get_uint16(des_iterator_get_element(&prot_it), &avdtp_version);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("l2cap_psm 0x%04x, avdtp_version 0x%04x\n", avdtp_l2cap_psm, avdtp_version);
|
||||
|
||||
/* Create AVDTP connection */
|
||||
avtdp_connection_doing_sdp_query->state = AVDTP_SIGNALING_CONNECTION_W4_L2CAP_CONNECTED;
|
||||
l2cap_create_channel(packet_handler, avtdp_connection_doing_sdp_query->remote_addr, avdtp_l2cap_psm, l2cap_max_mtu(), NULL);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "SDP attribute value buffer size exceeded: available %d, required %d\n", attribute_value_buffer_size, sdp_event_query_attribute_byte_get_attribute_length(packet));
|
||||
}
|
||||
break;
|
||||
|
||||
case SDP_EVENT_QUERY_COMPLETE:
|
||||
fprintf(stderr, "General query done with status %d.\n", sdp_event_query_complete_get_status(packet));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void avdtp_source_connect(bd_addr_t remote){
|
||||
avtdp_connection_doing_sdp_query = NULL;
|
||||
avdtp_connection_t * connection = avdtp_connection_for_bd_addr(remote, avdtp_source_context);
|
||||
if (!connection){
|
||||
connection = avdtp_create_connection(remote, avdtp_source_context);
|
||||
}
|
||||
if (connection->state != AVDTP_SIGNALING_CONNECTION_IDLE) return;
|
||||
avtdp_connection_doing_sdp_query = connection;
|
||||
connection->state = AVDTP_SIGNALING_W4_SDP_QUERY_COMPLETE;
|
||||
sdp_client_query_uuid16(&avdtp_source_handle_sdp_client_query_result, remote, BLUETOOTH_PROTOCOL_AVDTP);
|
||||
avdtp_connect(remote, AVDTP_SINK, avdtp_source_context);
|
||||
}
|
||||
|
||||
void avdtp_source_disconnect(uint16_t con_handle){
|
||||
|
@ -1,21 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
import math
|
||||
import sys
|
||||
|
||||
SAMPLES = 100
|
||||
VALUES_PER_LINE = 10
|
||||
|
||||
print ('''
|
||||
// input signal: pre-computed sine wave, 160 Hz at 16000 kHz
|
||||
static const int16_t sine_int16[] = {''')
|
||||
items = 0
|
||||
for sample in range(SAMPLES):
|
||||
angle = (sample * 360.0) / SAMPLES
|
||||
sine = math.sin(math.radians(angle))
|
||||
rescaled = int(round(sine * 32767))
|
||||
print ("%6d, " % rescaled),
|
||||
items += 1
|
||||
if items == VALUES_PER_LINE:
|
||||
items = 0
|
||||
print
|
||||
print( "};")
|
Loading…
x
Reference in New Issue
Block a user