avrcp browsing target: send response to get total num of items; remove printf from library

This commit is contained in:
Milanka Ringwald 2018-04-26 23:29:29 +02:00
parent bd0f378ad2
commit e72b716b71
5 changed files with 96 additions and 29 deletions

View File

@ -588,8 +588,8 @@ static void avrcp_browsing_controller_packet_handler(uint8_t packet_type, uint16
case L2CAP_DATA_PACKET:{
browsing_connection = get_avrcp_browsing_connection_for_l2cap_cid(channel, &avrcp_controller_context);
if (!browsing_connection) break;
printf("received \n");
printf_hexdump(packet,size);
// printf("received \n");
// printf_hexdump(packet,size);
int pos = 0;
uint8_t transport_header = packet[pos++];
// Transaction label | Packet_type | C/R | IPID (1 == invalid profile identifier)
@ -636,7 +636,7 @@ static void avrcp_browsing_controller_packet_handler(uint8_t packet_type, uint16
case AVRCP_PDU_ID_GET_TOTAL_NUMBER_OF_ITEMS:{
uint32_t num_items = big_endian_read_32(packet, pos);
pos += 4;
printf("TODO: send event, uid_counter %d, num_items %d\n", browsing_connection->uid_counter, num_items);
// printf("TODO: send event, uid_counter %d, num_items %d\n", browsing_connection->uid_counter, num_items);
break;
}
case AVRCP_PDU_ID_SET_BROWSED_PLAYER:{
@ -687,7 +687,7 @@ static void avrcp_browsing_controller_packet_handler(uint8_t packet_type, uint16
browsing_connection->uid_counter = big_endian_read_16(packet, pos);
pos += 2;
uint32_t num_items = big_endian_read_32(packet, pos);
printf("TODO: send as event, search found %d items\n", num_items);
// printf("TODO: send as event, search found %d items\n", num_items);
break;
}
case AVRCP_PDU_ID_GET_ITEM_ATTRIBUTES:
@ -696,7 +696,7 @@ static void avrcp_browsing_controller_packet_handler(uint8_t packet_type, uint16
break;
default:
printf(" not parsed pdu ID 0x%02x\n", browsing_connection->pdu_id);
log_info(" not parsed pdu ID 0x%02x", browsing_connection->pdu_id);
break;
}
@ -839,7 +839,6 @@ static uint8_t avrcp_browsing_controller_get_folder_items(uint16_t avrcp_browsin
avrcp_browsing_connection_t * connection = avrcp_connection->browsing_connection;
if (connection->state != AVCTP_CONNECTION_OPENED) {
log_error("avrcp_browsing_controller_get_folder_items: connection in wrong state %d, expected %d.", connection->state, AVCTP_CONNECTION_OPENED);
printf("avrcp_browsing_controller_get_folder_items: : connection in wrong state %d, expected %d\n", connection->state, AVCTP_CONNECTION_OPENED);
return ERROR_CODE_COMMAND_DISALLOWED;
}
@ -914,7 +913,6 @@ uint8_t avrcp_browsing_controller_change_path(uint16_t avrcp_browsing_cid, uint8
log_error("avrcp_browsing_controller_change_path: no browsed player set.");
return ERROR_CODE_COMMAND_DISALLOWED;
}
printf(" send change path\n");
connection->change_path = 1;
connection->direction = direction;
memset(connection->folder_uid, 0, 8);

View File

@ -142,6 +142,19 @@ static void avrcp_browsing_target_emit_get_folder_items(btstack_packet_handler_t
(*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
static void avrcp_browsing_target_emit_get_total_num_items(btstack_packet_handler_t callback, uint16_t browsing_cid, avrcp_browsing_connection_t * connection){
if (!callback) return;
uint8_t event[10];
int pos = 0;
event[pos++] = HCI_EVENT_AVRCP_META;
event[pos++] = sizeof(event) - 2;
event[pos++] = AVRCP_SUBEVENT_BROWSING_GET_TOTAL_NUM_ITEMS;
little_endian_store_16(event, pos, browsing_cid);
pos += 2;
event[pos++] = connection->scope;
(*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
static void avrcp_emit_browsing_connection_established(btstack_packet_handler_t callback, uint16_t browsing_cid, bd_addr_t addr, uint8_t status){
if (!callback) return;
uint8_t event[12];
@ -314,14 +327,13 @@ static void avrcp_browsing_target_packet_handler(uint8_t packet_type, uint16_t c
case L2CAP_DATA_PACKET:{
browsing_connection = get_avrcp_browsing_connection_for_l2cap_cid(channel, &avrcp_target_context);
if (!browsing_connection) break;
printf_hexdump(packet,size);
// printf_hexdump(packet,size);
int pos = 0;
uint8_t transport_header = packet[pos++];
// Transaction label | Packet_type | C/R | IPID (1 == invalid profile identifier)
browsing_connection->transaction_label = transport_header >> 4;
avrcp_packet_type_t avctp_packet_type = (transport_header & 0x0F) >> 2;
printf("L2CAP_DATA_PACKET, transaction_label %d\n", browsing_connection->transaction_label);
// printf("L2CAP_DATA_PACKET, transaction_label %d\n", browsing_connection->transaction_label);
switch (avctp_packet_type){
case AVRCP_SINGLE_PACKET:
case AVRCP_START_PACKET:
@ -343,7 +355,7 @@ static void avrcp_browsing_target_packet_handler(uint8_t packet_type, uint16_t c
default:
break;
}
printf("pdu id 0x%2x\n", browsing_connection->pdu_id);
// printf("pdu id 0x%2x\n", browsing_connection->pdu_id);
// uint32_t i;
switch (avctp_packet_type){
case AVRCP_SINGLE_PACKET:
@ -365,12 +377,19 @@ static void avrcp_browsing_target_packet_handler(uint8_t packet_type, uint16_t c
attr_count--;
}
avrcp_browsing_target_emit_get_folder_items(avrcp_target_context.browsing_avrcp_callback, channel, browsing_connection);
break;
case AVRCP_PDU_ID_GET_TOTAL_NUMBER_OF_ITEMS:{
// send total num items
browsing_connection->scope = packet[pos++];
avrcp_browsing_target_emit_get_total_num_items(avrcp_target_context.browsing_avrcp_callback, channel, browsing_connection);
// uint32_t num_items = big_endian_read_32(packet, pos);
// pos += 4;
break;
}
default:
printf("send avrcp_browsing_target_response_general_reject\n");
// printf("send avrcp_browsing_target_response_general_reject\n");
avrcp_browsing_target_response_general_reject(browsing_connection, AVRCP_STATUS_INVALID_COMMAND);
printf(" not parsed pdu ID 0x%02x\n", browsing_connection->pdu_id);
log_info(" not parsed pdu ID 0x%02x", browsing_connection->pdu_id);
break;
}
browsing_connection->state = AVCTP_CONNECTION_OPENED;
@ -479,16 +498,15 @@ uint8_t avrcp_subevent_browsing_get_folder_items_response(uint16_t avrcp_browsin
return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
}
avrcp_browsing_connection_t * connection = avrcp_connection->browsing_connection;
if (!connection){
printf("avrcp_subevent_browsing_get_folder_items_response: could not find a connection.\n");
log_info("avrcp_subevent_browsing_get_folder_items_response: could not find a connection.");
return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
}
if (connection->state != AVCTP_CONNECTION_OPENED) return ERROR_CODE_COMMAND_DISALLOWED;
if (connection->state != AVCTP_CONNECTION_OPENED) {
printf("avrcp_subevent_browsing_get_folder_items_response: wrong state.\n");
log_info("avrcp_subevent_browsing_get_folder_items_response: wrong state.");
return ERROR_CODE_COMMAND_DISALLOWED;
}
int pos = 0;
@ -505,7 +523,7 @@ uint8_t avrcp_subevent_browsing_get_folder_items_response(uint16_t avrcp_browsin
if (attr_list_size > sizeof(connection->cmd_operands)){
connection->attr_list = attr_list;
connection->attr_list_size = attr_list_size;
printf(" todo: list too big, invoke fragmentation\n");
log_info(" todo: list too big, invoke fragmentation");
return 1;
}
memcpy(&connection->cmd_operands[pos], attr_list, attr_list_size);
@ -518,6 +536,45 @@ uint8_t avrcp_subevent_browsing_get_folder_items_response(uint16_t avrcp_browsin
return ERROR_CODE_SUCCESS;
}
uint8_t avrcp_subevent_browsing_get_total_num_items_response(uint16_t avrcp_browsing_cid, uint16_t uid_counter, uint32_t total_num_items){
avrcp_connection_t * avrcp_connection = get_avrcp_connection_for_browsing_cid(avrcp_browsing_cid, &avrcp_target_context);
if (!avrcp_connection){
log_error("avrcp_browsing_controller_disconnect: could not find a connection.");
return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
}
avrcp_browsing_connection_t * connection = avrcp_connection->browsing_connection;
if (!connection){
log_info("avrcp_subevent_browsing_get_folder_items_response: could not find a connection.");
return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
}
if (connection->state != AVCTP_CONNECTION_OPENED) return ERROR_CODE_COMMAND_DISALLOWED;
if (connection->state != AVCTP_CONNECTION_OPENED) {
log_info("avrcp_subevent_browsing_get_folder_items_response: wrong state.");
return ERROR_CODE_COMMAND_DISALLOWED;
}
int pos = 0;
connection->cmd_operands[pos++] = AVRCP_PDU_ID_GET_TOTAL_NUMBER_OF_ITEMS;
big_endian_store_16(connection->cmd_operands, pos, 7);
pos += 2;
connection->cmd_operands[pos++] = AVRCP_STATUS_SUCCESS;
big_endian_store_16(connection->cmd_operands, pos, uid_counter);
pos += 2;
big_endian_store_32(connection->cmd_operands, pos, total_num_items);
pos += 4;
connection->cmd_operands_length = pos;
// printf_hexdump(connection->cmd_operands, connection->cmd_operands_length);
connection->state = AVCTP_W2_SEND_RESPONSE;
avrcp_browsing_target_request_can_send_now(connection, connection->l2cap_browsing_cid);
return ERROR_CODE_SUCCESS;
}
/*
int pos = 0;
connection->cmd_operands[pos++] = AVRCP_PDU_ID_GENERAL_REJECT;

View File

@ -103,7 +103,7 @@ uint8_t avrcp_browsing_target_decline_incoming_connection(uint16_t avrcp_browsin
uint8_t avrcp_browsing_target_disconnect(uint16_t avrcp_browsing_cid);
uint8_t avrcp_subevent_browsing_get_folder_items_response(uint16_t browsing_cid, uint16_t uid_counter, uint8_t * attr_list, uint16_t attr_list_size);
uint8_t avrcp_subevent_browsing_get_total_num_items_response(uint16_t avrcp_browsing_cid, uint16_t uid_counter, uint32_t total_num_items);
/* API_END */
#if defined __cplusplus

View File

@ -400,7 +400,7 @@ static uint8_t avrcp_target_response_addressed_player_changed_interim(avrcp_conn
connection->subunit_type = subunit_type;
connection->subunit_id = subunit_id;
connection->command_opcode = opcode;
printf("avrcp_target_response_addressed_player_changed_interim \n");
// printf("avrcp_target_response_addressed_player_changed_interim \n");
// company id is 3 bytes long
int pos = connection->cmd_operands_length;
connection->cmd_operands[pos++] = pdu_id;
@ -702,7 +702,7 @@ uint8_t avrcp_target_addressed_player_changed(uint16_t avrcp_cid, uint16_t playe
return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
}
if (connection->notifications_enabled & (1 << AVRCP_NOTIFICATION_EVENT_ADDRESSED_PLAYER_CHANGED)) {
printf("send AVRCP_NOTIFICATION_EVENT_ADDRESSED_PLAYER_CHANGED\n");
// printf("send AVRCP_NOTIFICATION_EVENT_ADDRESSED_PLAYER_CHANGED\n");
// connection->addressed_player_changed = 1;
connection->uid_counter = uid_counter;
connection->addressed_player_id = player_id;
@ -828,7 +828,6 @@ static void avrcp_handle_l2cap_data_packet_for_signaling_connection(avrcp_connec
case AVRCP_OPERATION_ID_LEFT:
case AVRCP_OPERATION_ID_RIGHT:
case AVRCP_OPERATION_ID_ROOT_MENU:
printf("received op 0x%02x\n", operation_id);
avrcp_target_operation_accepted(connection->avrcp_cid, packet[6], packet[7], packet[8]);
avrcp_target_emit_operation(avrcp_target_context.avrcp_callback, connection->avrcp_cid, operation_id, packet[7], packet[8]);
break;
@ -852,7 +851,6 @@ static void avrcp_handle_l2cap_data_packet_for_signaling_connection(avrcp_connec
switch (pdu_id){
case AVRCP_PDU_ID_SET_ADDRESSED_PLAYER:{
if (length == 0){
printf(" reject id\n");
avrcp_target_response_reject(connection, subunit_type, subunit_id, opcode, pdu_id, AVRCP_STATUS_INVALID_PLAYER_ID);
break;
}
@ -955,7 +953,6 @@ static void avrcp_handle_l2cap_data_packet_for_signaling_connection(avrcp_connec
return;
case AVRCP_NOTIFICATION_EVENT_ADDRESSED_PLAYER_CHANGED:
connection->notifications_enabled |= event_mask;
printf("respond with interim AVRCP_NOTIFICATION_EVENT_ADDRESSED_PLAYER_CHANGED\n");
avrcp_target_response_addressed_player_changed_interim(connection, subunit_type, subunit_id, opcode, pdu_id);
return;
default:
@ -968,14 +965,14 @@ static void avrcp_handle_l2cap_data_packet_for_signaling_connection(avrcp_connec
uint16_t param_length = big_endian_read_16(pdu,2);
if (param_length != 1){
avrcp_target_response_reject(connection, subunit_type, subunit_id, opcode, pdu_id, AVRCP_STATUS_INVALID_COMMAND);
printf("param_length is %d != 1 \n", param_length);
// printf("param_length is %d != 1 \n", param_length);
break;
}
uint8_t absolute_volume = pdu[4];
if (absolute_volume > 0x7F){
avrcp_target_response_reject(connection, subunit_type, subunit_id, opcode, pdu_id, AVRCP_STATUS_INVALID_COMMAND);
printf("absolute_volume %d > 127 \n", absolute_volume);
// printf("absolute_volume %d > 127 \n", absolute_volume);
break;
}
connection->volume_percentage = absolute_volume;
@ -1093,7 +1090,6 @@ static void avrcp_target_reset_notification(avrcp_connection_t * connection, uin
log_error("avrcp tartget: could not find a connection.");
return;
}
printf("reset notification\n");
connection->notifications_enabled &= ~(1 << notification_id);
connection->command_opcode = AVRCP_CMD_OPCODE_VENDOR_DEPENDENT;

View File

@ -569,8 +569,24 @@ static void avrcp_target_packet_handler(uint8_t packet_type, uint16_t channel, u
avrcp_subevent_browsing_get_folder_items_response(browsing_cid, uid_counter, now_playing_list, sizeof(now_playing_list));
break;
}
printf(" AVRCP_SUBEVENT_BROWSING_GET_FOLDER_ITEMS \n");
break;
}
case AVRCP_SUBEVENT_BROWSING_GET_TOTAL_NUM_ITEMS:{
avrcp_browsing_scope_t scope = avrcp_subevent_browsing_get_folder_items_get_scope(packet);
uint32_t total_num_items = 0;
switch (scope){
case AVRCP_BROWSING_MEDIA_PLAYER_LIST:
total_num_items = big_endian_read_16(media_player_list, 0);
avrcp_subevent_browsing_get_total_num_items_response(browsing_cid, uid_counter, total_num_items);
break;
case AVRCP_BROWSING_MEDIA_PLAYER_VIRTUAL_FILESYSTEM:
total_num_items = big_endian_read_16(virtual_filesystem_list, 0);
avrcp_subevent_browsing_get_total_num_items_response(browsing_cid, uid_counter, total_num_items);
break;
default:
avrcp_subevent_browsing_get_total_num_items_response(browsing_cid, uid_counter, total_num_items);
break;
}
break;
}
case AVRCP_SUBEVENT_BROWSING_CONNECTION_RELEASED: