mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-15 03:40:42 +00:00
implement acp reconfigure
This commit is contained in:
parent
602833f48b
commit
33ad0f3ff1
@ -308,6 +308,7 @@ typedef enum {
|
|||||||
AVDTP_ACCEPTOR_W2_ANSWER_GET_CAPABILITIES,
|
AVDTP_ACCEPTOR_W2_ANSWER_GET_CAPABILITIES,
|
||||||
AVDTP_ACCEPTOR_W2_ANSWER_GET_ALL_CAPABILITIES,
|
AVDTP_ACCEPTOR_W2_ANSWER_GET_ALL_CAPABILITIES,
|
||||||
AVDTP_ACCEPTOR_W2_ANSWER_SET_CONFIGURATION,
|
AVDTP_ACCEPTOR_W2_ANSWER_SET_CONFIGURATION,
|
||||||
|
AVDTP_ACCEPTOR_W2_ANSWER_RECONFIGURE,
|
||||||
AVDTP_ACCEPTOR_W2_ANSWER_GET_CONFIGURATION,
|
AVDTP_ACCEPTOR_W2_ANSWER_GET_CONFIGURATION,
|
||||||
AVDTP_ACCEPTOR_W2_ANSWER_OPEN_STREAM,
|
AVDTP_ACCEPTOR_W2_ANSWER_OPEN_STREAM,
|
||||||
AVDTP_ACCEPTOR_W4_L2CAP_FOR_MEDIA_CONNECTED,
|
AVDTP_ACCEPTOR_W4_L2CAP_FOR_MEDIA_CONNECTED,
|
||||||
@ -392,6 +393,7 @@ typedef struct avdtp_stream_endpoint {
|
|||||||
uint8_t remote_sep_index;
|
uint8_t remote_sep_index;
|
||||||
// register request for L2cap connection release
|
// register request for L2cap connection release
|
||||||
uint8_t disconnect;
|
uint8_t disconnect;
|
||||||
|
uint8_t failed_reconfigure_service_category;
|
||||||
} avdtp_stream_endpoint_t;
|
} avdtp_stream_endpoint_t;
|
||||||
|
|
||||||
#if defined __cplusplus
|
#if defined __cplusplus
|
||||||
|
@ -97,7 +97,6 @@ static int avdtp_pack_service_capabilities(uint8_t * buffer, int size, avdtp_cap
|
|||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static uint16_t avdtp_unpack_service_capabilities(avdtp_capabilities_t * caps, uint8_t * packet, uint16_t size){
|
static uint16_t avdtp_unpack_service_capabilities(avdtp_capabilities_t * caps, uint8_t * packet, uint16_t size){
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
uint16_t registered_service_categories = 0;
|
uint16_t registered_service_categories = 0;
|
||||||
@ -201,7 +200,7 @@ static int avdtp_acceptor_send_accept_response(uint16_t cid, avdtp_signal_ident
|
|||||||
int avdtp_acceptor_stream_config_subsm(avdtp_stream_endpoint_t * stream_endpoint, avdtp_signaling_packet_header_t * signaling_header, uint8_t *packet, uint16_t size){
|
int avdtp_acceptor_stream_config_subsm(avdtp_stream_endpoint_t * stream_endpoint, avdtp_signaling_packet_header_t * signaling_header, uint8_t *packet, uint16_t size){
|
||||||
if (!stream_endpoint) return 0;
|
if (!stream_endpoint) return 0;
|
||||||
int request_to_send = 1;
|
int request_to_send = 1;
|
||||||
|
// TODO remove signaling header
|
||||||
switch (stream_endpoint->acceptor_config_state){
|
switch (stream_endpoint->acceptor_config_state){
|
||||||
case AVDTP_ACCEPTOR_STREAM_CONFIG_IDLE:
|
case AVDTP_ACCEPTOR_STREAM_CONFIG_IDLE:
|
||||||
switch (signaling_header->signal_identifier){
|
switch (signaling_header->signal_identifier){
|
||||||
@ -229,6 +228,40 @@ int avdtp_acceptor_stream_config_subsm(avdtp_stream_endpoint_t * stream_endpoint
|
|||||||
stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_ANSWER_SET_CONFIGURATION;
|
stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_ANSWER_SET_CONFIGURATION;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case AVDTP_SI_RECONFIGURE:{
|
||||||
|
printf(" ACP: AVDTP_ACCEPTOR_W2_ANSWER_RECONFIGURE \n");
|
||||||
|
avdtp_sep_t sep;
|
||||||
|
sep.seid = packet[3] >> 2;
|
||||||
|
// find or add sep
|
||||||
|
int i;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uint16_t service_categories = avdtp_unpack_service_capabilities(&sep.capabilities, packet+4, size-4);
|
||||||
|
printf(" service_categories 0x%2x\n", service_categories);
|
||||||
|
stream_endpoint->failed_reconfigure_service_category = 0;
|
||||||
|
|
||||||
|
uint16_t remaining_service_categories = service_categories;
|
||||||
|
if (get_bit16(service_categories, AVDTP_MEDIA_CODEC-1)){
|
||||||
|
printf(" ACP: reconfigure media, not implemented\n");
|
||||||
|
remaining_service_categories = store_bit16(service_categories, AVDTP_MEDIA_CODEC-1, 0);
|
||||||
|
}
|
||||||
|
if (get_bit16(service_categories, AVDTP_CONTENT_PROTECTION-1)){
|
||||||
|
printf(" ACP: reconfigure content protection, not implemented\n");
|
||||||
|
remaining_service_categories = store_bit16(service_categories, AVDTP_CONTENT_PROTECTION-1, 0);
|
||||||
|
}
|
||||||
|
stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_ANSWER_RECONFIGURE;
|
||||||
|
if (!remaining_service_categories) break;
|
||||||
|
printf("remained service_categories 0x%2x\n", remaining_service_categories);
|
||||||
|
for (i = 1; i < 9; i++){
|
||||||
|
if (get_bit16(service_categories, i-1)){
|
||||||
|
stream_endpoint->failed_reconfigure_service_category = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case AVDTP_SI_OPEN:
|
case AVDTP_SI_OPEN:
|
||||||
if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_CONFIGURED) return 0;
|
if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_CONFIGURED) return 0;
|
||||||
printf(" ACP: AVDTP_STREAM_ENDPOINT_W2_ANSWER_OPEN_STREAM\n");
|
printf(" ACP: AVDTP_STREAM_ENDPOINT_W2_ANSWER_OPEN_STREAM\n");
|
||||||
@ -240,15 +273,6 @@ int avdtp_acceptor_stream_config_subsm(avdtp_stream_endpoint_t * stream_endpoint
|
|||||||
stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_ANSWER_GET_CONFIGURATION;
|
stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_ANSWER_GET_CONFIGURATION;
|
||||||
stream_endpoint->connection->acceptor_transaction_label = signaling_header->transaction_label;
|
stream_endpoint->connection->acceptor_transaction_label = signaling_header->transaction_label;
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
printf(" ACP: NOT IMPLEMENTED, Reject signal_identifier %02x\n", signaling_header->signal_identifier);
|
|
||||||
stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_REJECT_UNKNOWN_CMD;
|
|
||||||
stream_endpoint->unknown_signal_identifier = signaling_header->signal_identifier;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case AVDTP_ACCEPTOR_W2_ANSWER_OPEN_STREAM:
|
|
||||||
switch (signaling_header->signal_identifier){
|
|
||||||
case AVDTP_SI_START:
|
case AVDTP_SI_START:
|
||||||
if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_OPENED) return 0;
|
if (stream_endpoint->state != AVDTP_STREAM_ENDPOINT_OPENED) return 0;
|
||||||
printf(" ACP: AVDTP_ACCEPTOR_W2_ANSWER_START_STREAM\n");
|
printf(" ACP: AVDTP_ACCEPTOR_W2_ANSWER_START_STREAM\n");
|
||||||
@ -256,13 +280,11 @@ int avdtp_acceptor_stream_config_subsm(avdtp_stream_endpoint_t * stream_endpoint
|
|||||||
stream_endpoint->connection->acceptor_transaction_label = signaling_header->transaction_label;
|
stream_endpoint->connection->acceptor_transaction_label = signaling_header->transaction_label;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf(" ACP: AVDTP_ACCEPTOR_W2_ANSWER_OPEN_STREAM unhandled signal %d ", signaling_header->signal_identifier);
|
printf(" ACP: NOT IMPLEMENTED, Reject signal_identifier %02x\n", signaling_header->signal_identifier);
|
||||||
return 0;
|
stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_REJECT_UNKNOWN_CMD;
|
||||||
}
|
stream_endpoint->unknown_signal_identifier = signaling_header->signal_identifier;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case AVDTP_ACCEPTOR_W2_ANSWER_START_STREAM:
|
|
||||||
printf(" AVDTP_ACCEPTOR_W2_ANSWER_START_STREAM state %d, si %d \n", stream_endpoint->state, signaling_header->signal_identifier);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -276,6 +298,13 @@ int avdtp_acceptor_stream_config_subsm(avdtp_stream_endpoint_t * stream_endpoint
|
|||||||
return request_to_send;
|
return request_to_send;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int avdtp_acceptor_send_response_reject_service_category(uint16_t cid, avdtp_signal_identifier_t identifier, uint8_t category, uint8_t transaction_label){
|
||||||
|
uint8_t command[3];
|
||||||
|
command[0] = avdtp_header(transaction_label, AVDTP_SINGLE_PACKET, AVDTP_GENERAL_REJECT_MSG);
|
||||||
|
command[1] = (uint8_t)identifier;
|
||||||
|
command[2] = category;
|
||||||
|
return l2cap_send(cid, command, sizeof(command));
|
||||||
|
}
|
||||||
|
|
||||||
static int avdtp_acceptor_send_response_reject(uint16_t cid, avdtp_signal_identifier_t identifier, uint8_t transaction_label){
|
static int avdtp_acceptor_send_response_reject(uint16_t cid, avdtp_signal_identifier_t identifier, uint8_t transaction_label){
|
||||||
uint8_t command[2];
|
uint8_t command[2];
|
||||||
@ -320,15 +349,27 @@ int avdtp_acceptor_stream_config_subsm_run(avdtp_connection_t * connection, avdt
|
|||||||
break;
|
break;
|
||||||
case AVDTP_ACCEPTOR_W2_ANSWER_OPEN_STREAM:
|
case AVDTP_ACCEPTOR_W2_ANSWER_OPEN_STREAM:
|
||||||
printf(" ACP: AVDTP_STREAM_ENDPOINT_W4_L2CAP_FOR_MEDIA_CONNECTED\n");
|
printf(" ACP: AVDTP_STREAM_ENDPOINT_W4_L2CAP_FOR_MEDIA_CONNECTED\n");
|
||||||
|
stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_STREAM_CONFIG_IDLE;
|
||||||
stream_endpoint->state = AVDTP_STREAM_ENDPOINT_W4_L2CAP_FOR_MEDIA_CONNECTED;
|
stream_endpoint->state = AVDTP_STREAM_ENDPOINT_W4_L2CAP_FOR_MEDIA_CONNECTED;
|
||||||
avdtp_acceptor_send_accept_response(stream_endpoint->connection->l2cap_signaling_cid, AVDTP_SI_OPEN, stream_endpoint->connection->acceptor_transaction_label);
|
avdtp_acceptor_send_accept_response(stream_endpoint->connection->l2cap_signaling_cid, AVDTP_SI_OPEN, stream_endpoint->connection->acceptor_transaction_label);
|
||||||
break;
|
break;
|
||||||
case AVDTP_ACCEPTOR_W2_ANSWER_START_STREAM:
|
case AVDTP_ACCEPTOR_W2_ANSWER_START_STREAM:
|
||||||
printf(" ACP: AVDTP_STREAM_ENDPOINT_STREAMING \n");
|
printf(" ACP: AVDTP_STREAM_ENDPOINT_STREAMING \n");
|
||||||
|
stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_STREAM_CONFIG_IDLE;
|
||||||
stream_endpoint->state = AVDTP_STREAM_ENDPOINT_STREAMING;
|
stream_endpoint->state = AVDTP_STREAM_ENDPOINT_STREAMING;
|
||||||
avdtp_acceptor_send_accept_response(stream_endpoint->connection->l2cap_signaling_cid, AVDTP_SI_START, stream_endpoint->connection->acceptor_transaction_label);
|
avdtp_acceptor_send_accept_response(stream_endpoint->connection->l2cap_signaling_cid, AVDTP_SI_START, stream_endpoint->connection->acceptor_transaction_label);
|
||||||
break;
|
break;
|
||||||
|
case AVDTP_ACCEPTOR_W2_ANSWER_RECONFIGURE:
|
||||||
|
printf(" ACP: DONE \n");
|
||||||
|
stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_STREAM_CONFIG_IDLE;
|
||||||
|
if (stream_endpoint->failed_reconfigure_service_category){
|
||||||
|
avdtp_acceptor_send_response_reject_service_category(stream_endpoint->connection->l2cap_signaling_cid, AVDTP_SI_RECONFIGURE,
|
||||||
|
stream_endpoint->failed_reconfigure_service_category, stream_endpoint->connection->acceptor_transaction_label);
|
||||||
|
stream_endpoint->failed_reconfigure_service_category = 0;
|
||||||
|
} else {
|
||||||
|
avdtp_acceptor_send_accept_response(stream_endpoint->connection->l2cap_signaling_cid, AVDTP_SI_RECONFIGURE, stream_endpoint->connection->acceptor_transaction_label);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
printf(" ACP: NOT IMPLEMENTED\n");
|
printf(" ACP: NOT IMPLEMENTED\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -352,6 +352,13 @@ static avdtp_stream_endpoint_t * get_avdtp_stream_endpoint_for_connection(avdtp_
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int avdtp_acceptor_send_accept_response(uint16_t cid, avdtp_signal_identifier_t identifier, uint8_t transaction_label){
|
||||||
|
uint8_t command[2];
|
||||||
|
command[0] = avdtp_header(transaction_label, AVDTP_SINGLE_PACKET, AVDTP_RESPONSE_ACCEPT_MSG);
|
||||||
|
command[1] = (uint8_t)identifier;
|
||||||
|
return l2cap_send(cid, command, sizeof(command));
|
||||||
|
}
|
||||||
|
|
||||||
static int avdtp_send_seps_response(uint16_t cid, uint8_t transaction_label, avdtp_stream_endpoint_t * endpoints){
|
static int avdtp_send_seps_response(uint16_t cid, uint8_t transaction_label, avdtp_stream_endpoint_t * endpoints){
|
||||||
uint8_t command[2+2*MAX_NUM_SEPS];
|
uint8_t command[2+2*MAX_NUM_SEPS];
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
@ -392,6 +399,13 @@ static void avdtp_sink_handle_can_send_now(avdtp_connection_t * connection, uint
|
|||||||
} else if (connection->wait_to_send_self){
|
} else if (connection->wait_to_send_self){
|
||||||
connection->wait_to_send_self = 0;
|
connection->wait_to_send_self = 0;
|
||||||
|
|
||||||
|
if (connection->confirm_suspend){
|
||||||
|
printf(" -> STREAMS SUSPENDED\n");
|
||||||
|
connection->confirm_suspend = 0;
|
||||||
|
avdtp_acceptor_send_accept_response(connection->l2cap_signaling_cid, AVDTP_SI_SUSPEND, connection->acceptor_transaction_label);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (connection->acceptor_connection_state){
|
switch (connection->acceptor_connection_state){
|
||||||
case AVDTP_SIGNALING_CONNECTION_ACCEPTOR_W2_ANSWER_DISCOVER_SEPS:
|
case AVDTP_SIGNALING_CONNECTION_ACCEPTOR_W2_ANSWER_DISCOVER_SEPS:
|
||||||
printf(" -> AVDTP_SIGNALING_CONNECTION_OPENED\n");
|
printf(" -> AVDTP_SIGNALING_CONNECTION_OPENED\n");
|
||||||
@ -483,6 +497,23 @@ static int handle_l2cap_data_packet_for_connection(avdtp_connection_t * connecti
|
|||||||
stream_endpoint = get_avdtp_stream_endpoint_for_active_seid(connection->query_seid);
|
stream_endpoint = get_avdtp_stream_endpoint_for_active_seid(connection->query_seid);
|
||||||
// printf(" handle_l2cap_data_packet_for_connection 2\n");
|
// printf(" handle_l2cap_data_packet_for_connection 2\n");
|
||||||
return handle_l2cap_data_packet_for_stream_endpoint(connection, stream_endpoint, packet, size);
|
return handle_l2cap_data_packet_for_stream_endpoint(connection, stream_endpoint, packet, size);
|
||||||
|
case AVDTP_SI_RECONFIGURE:
|
||||||
|
connection->query_seid = packet[2] >> 2;
|
||||||
|
stream_endpoint = get_avdtp_stream_endpoint_for_active_seid(connection->query_seid);
|
||||||
|
printf(" AVDTP_SI_RECONFIGURE handle_l2cap_data_packet_for_connection 2\n");
|
||||||
|
return handle_l2cap_data_packet_for_stream_endpoint(connection, stream_endpoint, packet, size);
|
||||||
|
|
||||||
|
case AVDTP_SI_SUSPEND:{
|
||||||
|
int i;
|
||||||
|
for (i=2; i<size; i++){
|
||||||
|
stream_endpoint = get_avdtp_stream_endpoint_for_active_seid(packet[i] >> 2);
|
||||||
|
if (!stream_endpoint) continue;
|
||||||
|
stream_endpoint->state = AVDTP_STREAM_ENDPOINT_OPENED;
|
||||||
|
}
|
||||||
|
connection->confirm_suspend = 1;
|
||||||
|
avdtp_sink_request_can_send_now_self(connection, connection->l2cap_signaling_cid);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
printf("AVDTP_CMD_MSG signal %d not implemented\n", signaling_header.signal_identifier);
|
printf("AVDTP_CMD_MSG signal %d not implemented\n", signaling_header.signal_identifier);
|
||||||
break;
|
break;
|
||||||
@ -503,7 +534,7 @@ static int handle_l2cap_data_packet_for_connection(avdtp_connection_t * connecti
|
|||||||
|
|
||||||
avdtp_sep_t sep;
|
avdtp_sep_t sep;
|
||||||
int i;
|
int i;
|
||||||
for (i = 2; i<size; i+=2){
|
for (i=2; i<size; i+=2){
|
||||||
sep.seid = packet[i] >> 2;
|
sep.seid = packet[i] >> 2;
|
||||||
if (sep.seid < 0x01 || sep.seid > 0x3E){
|
if (sep.seid < 0x01 || sep.seid > 0x3E){
|
||||||
printf("invalid sep id\n");
|
printf("invalid sep id\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user