1 /* 2 * Copyright (C) 2016 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 /* 39 * avrcp.h 40 * 41 * Audio/Video Remote Control Profile 42 * 43 */ 44 45 #ifndef __AVRCP_H 46 #define __AVRCP_H 47 48 #include <stdint.h> 49 #include "btstack_run_loop.h" 50 #include "btstack_linked_list.h" 51 52 #if defined __cplusplus 53 extern "C" { 54 #endif 55 56 #define BT_SIG_COMPANY_ID 0x001958 57 #define AVRCP_MEDIA_ATTR_COUNT 7 58 #define AVRCP_MAX_ATTRIBUTTE_SIZE 100 59 #define AVRCP_ATTRIBUTE_HEADER_LEN 8 60 #define AVRCP_MAX_FOLDER_NAME_SIZE 20 61 62 #define AVRCP_NO_TRACK_SELECTED_PLAYBACK_POSITION_CHANGED 0xFFFFFFFF 63 // #define AVRCP_NO_TRACK_SELECTED_TRACK_CHANGED 0xFFFFFFFFFFFFFFFF 64 65 typedef enum { 66 AVRCP_STATUS_INVALID_COMMAND = 0, // sent if TG received a PDU that it did not understand. 67 AVRCP_STATUS_INVALID_PARAMETER, // Sent if the TG received a PDU with a parameter ID that it did not understand, or, if there is only one parameter ID in the PDU. 68 AVRCP_STATUS_SPECIFIED_PARAMETER_NOT_FOUND, // sent if the parameter ID is understood, but content is wrong or corrupted. 69 AVRCP_STATUS_INTERNAL_ERROR, // sent if there are error conditions not covered by a more specific error code. 70 AVRCP_STATUS_SUCCESS, // sent if the operation was successful. 71 AVRCP_STATUS_UID_CHANGED, // sent if the UIDs on the device have changed. 72 AVRCP_STATUS_RESERVED_6, 73 AVRCP_STATUS_INVALID_DIRECTION, // The Direction parameter is invalid. Valid for command: Change Path 74 AVRCP_STATUS_NOT_A_DIRECTORY, // The UID provided does not refer to a folder item. Valid for command: Change Path 75 AVRCP_STATUS_DOES_NOT_EXIST, // The UID provided does not refer to any currently valid. Valid for command: Change Path, PlayItem, AddToNowPlaying, GetItemAttributes 76 AVRCP_STATUS_INVALID_SCOPE, // The scope parameter is invalid. Valid for command: GetFolderItems, PlayItem, AddToNowPlayer, GetItemAttributes, 77 AVRCP_STATUS_RANGE_OUT_OF_BOUNDS, // The start of range provided is not valid. Valid for command: GetFolderItems 78 AVRCP_STATUS_UID_IS_A_DIRECTORY, // The UID provided refers to a directory, which cannot be handled by this media player. Valid for command: PlayItem, AddToNowPlaying 79 AVRCP_STATUS_MEDIA_IN_USE, // The media is not able to be used for this operation at this time. Valid for command: PlayItem, AddToNowPlaying 80 AVRCP_STATUS_NOW_PLAYING_LIST_FULL, // No more items can be added to the Now Playing List. Valid for command: AddToNowPlaying 81 AVRCP_STATUS_SEARCH_NOT_SUPPORTED, // The Browsed Media Player does not support search. Valid for command: Search 82 AVRCP_STATUS_SEARCH_IN_PROGRESS, // A search operation is already in progress. Valid for command: Search 83 AVRCP_STATUS_INVALID_PLAYER_ID, // The specified Player Id does not refer to a valid player. Valid for command: SetAddressedPlayer, SetBrowsedPlayer 84 AVRCP_STATUS_PLAYER_NOT_BROWSABLE, // The Player Id supplied refers to a Media Player which does not support browsing. Valid for command: SetBrowsedPlayer 85 AVRCP_STATUS_PLAYER_NOT_ADDRESSED, // The Player Id supplied refers to a player which is not currently addressed, and the command is not able to be performed if the player is not set as addressed. Valid for command: Search SetBrowsedPlayer 86 AVRCP_STATUS_NO_VALID_SEARCH_RESULTS, // The Search result list does not contain valid entries, e.g. after being invalidated due to change of browsed player. Valid for command: GetFolderItems 87 AVRCP_STATUS_NO_AVAILABLE_PLAYERS, 88 AVRCP_STATUS_ADDRESSED_PLAYER_CHANGED, // Valid for command: Register Notification 89 AVRCP_STATUS_RESERVED // 0x17 - 0xFF 90 } avrcp_status_code_t; 91 92 typedef enum { 93 AVRCP_SINGLE_PACKET= 0, 94 AVRCP_START_PACKET , 95 AVRCP_CONTINUE_PACKET , 96 AVRCP_END_PACKET 97 } avrcp_packet_type_t; 98 99 typedef enum { 100 AVRCP_COMMAND_FRAME = 0, 101 AVRCP_RESPONSE_FRAME 102 } avrcp_frame_type_t; 103 104 105 typedef enum { 106 AVRCP_CAPABILITY_ID_COMPANY = 0x02, 107 AVRCP_CAPABILITY_ID_EVENT = 0x03 108 } avrcp_capability_id_t; 109 110 #define AVRCP_BROWSING_MAX_NUM_ATTR_IDS 8 111 typedef enum { 112 AVRCP_MEDIA_ATTR_ALL = 0x00000000, 113 AVRCP_MEDIA_ATTR_TITLE, 114 AVRCP_MEDIA_ATTR_ARTIST, 115 AVRCP_MEDIA_ATTR_ALBUM, 116 AVRCP_MEDIA_ATTR_TRACK, 117 AVRCP_MEDIA_ATTR_TOTAL_NUM_ITEMS, 118 AVRCP_MEDIA_ATTR_GENRE, 119 AVRCP_MEDIA_ATTR_SONG_LENGTH_MS, 120 AVRCP_MEDIA_ATTR_DEFAULT_COVER_ART, 121 AVRCP_MEDIA_ATTR_NONE = 0xFFFFFFFF 122 } avrcp_media_attribute_id_t; 123 124 typedef enum { 125 AVRCP_PDU_ID_GET_CAPABILITIES = 0x10, 126 AVRCP_PDU_ID_GetCurrentPlayerApplicationSettingValue = 0x13, 127 AVRCP_PDU_ID_SetPlayerApplicationSettingValue = 0x14, 128 AVRCP_PDU_ID_GET_ELEMENT_ATTRIBUTES = 0x20, 129 AVRCP_PDU_ID_GET_PLAY_STATUS = 0x30, 130 AVRCP_PDU_ID_REGISTER_NOTIFICATION = 0x31, 131 AVRCP_PDU_ID_REQUEST_CONTINUING_RESPONSE = 0x40, 132 AVRCP_PDU_ID_REQUEST_ABORT_CONTINUING_RESPONSE = 0x41, 133 AVRCP_PDU_ID_SET_ABSOLUTE_VOLUME = 0x50, 134 AVRCP_PDU_ID_SET_ADDRESSED_PLAYER = 0x60, 135 AVRCP_PDU_ID_SET_BROWSED_PLAYER = 0x70, 136 AVRCP_PDU_ID_GET_FOLDER_ITEMS = 0x71, 137 AVRCP_PDU_ID_CHANGE_PATH = 0x72, 138 AVRCP_PDU_ID_GET_ITEM_ATTRIBUTES = 0x73, 139 AVRCP_PDU_ID_PLAY_ITEM = 0x74, 140 AVRCP_PDU_ID_GET_TOTAL_NUMBER_OF_ITEMS = 0x75, 141 AVRCP_PDU_ID_SEARCH = 0x80, 142 AVRCP_PDU_ID_ADD_TO_NOW_PLAYING = 0x90, 143 AVRCP_PDU_ID_GENERAL_REJECT = 0xA0, 144 145 AVRCP_PDU_ID_UNDEFINED = 0xFF 146 } avrcp_pdu_id_t; 147 148 typedef enum { 149 AVRCP_NOTIFICATION_EVENT_PLAYBACK_STATUS_CHANGED = 0x01, // Change in playback status of the current track. 150 AVRCP_NOTIFICATION_EVENT_TRACK_CHANGED = 0x02, // Change of current track 151 AVRCP_NOTIFICATION_EVENT_TRACK_REACHED_END = 0x03, // Reached end of a track 152 AVRCP_NOTIFICATION_EVENT_TRACK_REACHED_START = 0x04, // Reached start of a track 153 AVRCP_NOTIFICATION_EVENT_PLAYBACK_POS_CHANGED = 0x05, // Change in playback position. Returned after the specified playback notification change notification interval 154 AVRCP_NOTIFICATION_EVENT_BATT_STATUS_CHANGED = 0x06, // Change in battery status 155 AVRCP_NOTIFICATION_EVENT_SYSTEM_STATUS_CHANGED = 0x07, // Change in system status 156 AVRCP_NOTIFICATION_EVENT_PLAYER_APPLICATION_SETTING_CHANGED = 0x08, // Change in player application setting 157 AVRCP_NOTIFICATION_EVENT_NOW_PLAYING_CONTENT_CHANGED = 0x09, // The content of the Now Playing list has changed, see 6.9.5. 158 AVRCP_NOTIFICATION_EVENT_AVAILABLE_PLAYERS_CHANGED = 0x0a, // The available players have changed, see 6.9.4. 159 AVRCP_NOTIFICATION_EVENT_ADDRESSED_PLAYER_CHANGED = 0x0b, // The Addressed Player has been changed, see 6.9.2. 160 AVRCP_NOTIFICATION_EVENT_UIDS_CHANGED = 0x0c, // The UIDs have changed, see 6.10.3.3. 161 AVRCP_NOTIFICATION_EVENT_VOLUME_CHANGED = 0x0d // The volume has been changed locally on the TG, see 6.13.3. 162 } avrcp_notification_event_id_t; 163 164 // control command response: accepted, rejected, interim 165 // status command response: not implemented, rejected, in transition, stable 166 // notify command response: not implemented, rejected, changed 167 168 typedef enum { 169 AVRCP_CTYPE_CONTROL = 0, 170 AVRCP_CTYPE_STATUS, 171 AVRCP_CTYPE_SPECIFIC_INQUIRY, 172 AVRCP_CTYPE_NOTIFY, 173 AVRCP_CTYPE_GENERAL_INQUIRY, 174 AVRCP_CTYPE_RESERVED5, 175 AVRCP_CTYPE_RESERVED6, 176 AVRCP_CTYPE_RESERVED7, 177 AVRCP_CTYPE_RESPONSE_NOT_IMPLEMENTED = 8, 178 AVRCP_CTYPE_RESPONSE_ACCEPTED, 179 AVRCP_CTYPE_RESPONSE_REJECTED, 180 AVRCP_CTYPE_RESPONSE_IN_TRANSITION, // target state is in transition. A subsequent STATUS command, may result in the return of a STABLE status 181 AVRCP_CTYPE_RESPONSE_IMPLEMENTED_STABLE, 182 AVRCP_CTYPE_RESPONSE_CHANGED_STABLE, 183 AVRCP_CTYPE_RESPONSE_RESERVED, 184 AVRCP_CTYPE_RESPONSE_INTERIM // target is unable to respond with either ACCEPTED or REJECTED within 100 millisecond 185 } avrcp_command_type_t; 186 187 typedef enum { 188 AVRCP_SUBUNIT_TYPE_MONITOR = 0, 189 AVRCP_SUBUNIT_TYPE_AUDIO = 1, 190 AVRCP_SUBUNIT_TYPE_PRINTER, 191 AVRCP_SUBUNIT_TYPE_DISC, 192 AVRCP_SUBUNIT_TYPE_TAPE_RECORDER_PLAYER, 193 AVRCP_SUBUNIT_TYPE_TUNER, 194 AVRCP_SUBUNIT_TYPE_CA, 195 AVRCP_SUBUNIT_TYPE_CAMERA, 196 AVRCP_SUBUNIT_TYPE_RESERVED, 197 AVRCP_SUBUNIT_TYPE_PANEL = 9, 198 AVRCP_SUBUNIT_TYPE_BULLETIN_BOARD, 199 AVRCP_SUBUNIT_TYPE_CAMERA_STORAGE, 200 AVRCP_SUBUNIT_TYPE_VENDOR_UNIQUE = 0x1C, 201 AVRCP_SUBUNIT_TYPE_RESERVED_FOR_ALL_SUBUNIT_TYPES, 202 AVRCP_SUBUNIT_TYPE_EXTENDED_TO_NEXT_BYTE, // The unit_type field may take value 1E16, which means that the field is extended to the following byte. In that case, an additional byte for extended_unit_type will be added immediately following operand[1]. 203 // Further extension is possible when the value of extended_unit_type is FF16, in which case another byte will be added. 204 AVRCP_SUBUNIT_TYPE_UNIT = 0x1F 205 } avrcp_subunit_type_t; 206 207 typedef enum { 208 AVRCP_SUBUNIT_ID = 0, 209 AVRCP_SUBUNIT_ID_IGNORE = 7 210 } avrcp_subunit_id_t; 211 212 typedef enum { 213 AVRCP_CMD_OPCODE_VENDOR_DEPENDENT = 0x00, 214 // AVRCP_CMD_OPCODE_RESERVE = 0x01, 215 AVRCP_CMD_OPCODE_UNIT_INFO = 0x30, 216 AVRCP_CMD_OPCODE_SUBUNIT_INFO = 0x31, 217 AVRCP_CMD_OPCODE_PASS_THROUGH = 0x7C, 218 // AVRCP_CMD_OPCODE_VERSION = 0xB0, 219 // AVRCP_CMD_OPCODE_POWER = 0xB2, 220 AVRCP_CMD_OPCODE_UNDEFINED = 0xFF 221 } avrcp_command_opcode_t; 222 223 typedef enum { 224 AVRCP_OPERATION_ID_CHANNEL_UP = 0x30, 225 AVRCP_OPERATION_ID_CHANNEL_DOWN = 0x31, 226 AVRCP_OPERATION_ID_SELECT = 0x00, 227 AVRCP_OPERATION_ID_UP = 0x01, 228 AVRCP_OPERATION_ID_DOWN = 0x02, 229 AVRCP_OPERATION_ID_LEFT = 0x03, 230 AVRCP_OPERATION_ID_RIGHT = 0x04, 231 AVRCP_OPERATION_ID_ROOT_MENU = 0x09, 232 233 AVRCP_OPERATION_ID_SKIP = 0x3C, 234 AVRCP_OPERATION_ID_VOLUME_UP = 0x41, 235 AVRCP_OPERATION_ID_VOLUME_DOWN = 0x42, 236 AVRCP_OPERATION_ID_MUTE = 0x43, 237 238 AVRCP_OPERATION_ID_PLAY = 0x44, 239 AVRCP_OPERATION_ID_STOP = 0x45, 240 AVRCP_OPERATION_ID_PAUSE = 0x46, 241 AVRCP_OPERATION_ID_REWIND = 0x48, 242 AVRCP_OPERATION_ID_FAST_FORWARD = 0x49, 243 AVRCP_OPERATION_ID_FORWARD = 0x4B, 244 AVRCP_OPERATION_ID_BACKWARD = 0x4C, 245 AVRCP_OPERATION_ID_UNDEFINED = 0xFF 246 } avrcp_operation_id_t; 247 248 typedef enum{ 249 AVRCP_PLAYBACK_STATUS_STOPPED = 0x00, 250 AVRCP_PLAYBACK_STATUS_PLAYING, 251 AVRCP_PLAYBACK_STATUS_PAUSED, 252 AVRCP_PLAYBACK_STATUS_FWD_SEEK, 253 AVRCP_PLAYBACK_STATUS_REV_SEEK, 254 AVRCP_PLAYBACK_STATUS_ERROR = 0xFF 255 } avrcp_playback_status_t; 256 257 typedef enum{ 258 AVRCP_BATTERY_STATUS_NORMAL = 0x00, // Battery operation is in normal state 259 AVRCP_BATTERY_STATUS_WARNING, // unable to operate soon. Is provided when the battery level is going down. 260 AVRCP_BATTERY_STATUS_CRITICAL, // can not operate any more. Is provided when the battery level is going down. 261 AVRCP_BATTERY_STATUS_EXTERNAL, // Plugged to external power supply 262 AVRCP_BATTERY_STATUS_FULL_CHARGE // when the device is completely charged from the external power supply 263 } avrcp_battery_status_t; 264 265 266 typedef enum { 267 AVCTP_CONNECTION_IDLE, 268 AVCTP_CONNECTION_W4_SDP_QUERY_COMPLETE, 269 AVCTP_CONNECTION_W4_ERTM_CONFIGURATION, 270 AVCTP_CONNECTION_W4_L2CAP_CONNECTED, 271 AVCTP_CONNECTION_OPENED, 272 AVCTP_W2_SEND_PRESS_COMMAND, 273 AVCTP_W2_SEND_RELEASE_COMMAND, 274 AVCTP_W4_STOP, 275 AVCTP_W2_SEND_COMMAND, 276 AVCTP_W2_SEND_RESPONSE, 277 AVCTP_W2_RECEIVE_PRESS_RESPONSE, 278 AVCTP_W2_RECEIVE_RESPONSE, 279 AVCTP_W2_SEND_FRAGMENTED_COMMAND, 280 } avctp_connection_state_t; 281 282 typedef enum { 283 AVRCP_BROWSING_MEDIA_PLAYER_LIST = 0x00, 284 AVRCP_BROWSING_MEDIA_PLAYER_VIRTUAL_FILESYSTEM, 285 AVRCP_BROWSING_SEARCH, 286 AVRCP_BROWSING_NOW_PLAYING 287 } avrcp_browsing_scope_t; 288 289 typedef struct { 290 uint16_t len; 291 uint8_t * value; 292 } avrcp_now_playing_info_item_t; 293 294 typedef struct { 295 uint8_t track_id[8]; 296 uint16_t track_nr; 297 char * title; 298 char * artist; 299 char * album; 300 char * genre; 301 uint32_t song_length_ms; 302 uint32_t song_position_ms; 303 } avrcp_track_t; 304 305 typedef enum { 306 AVRCP_PARSER_GET_ATTRIBUTE_HEADER = 0, // 8 bytes 307 AVRCP_PARSER_GET_ATTRIBUTE_VALUE, 308 AVRCP_PARSER_IGNORE_REST_OF_ATTRIBUTE_VALUE 309 } avrcp_parser_state_t; 310 311 312 #define AVRCP_BROWSING_ITEM_HEADER_LEN 3 313 314 // BROWSING 315 typedef struct { 316 uint16_t l2cap_browsing_cid; 317 318 avctp_connection_state_t state; 319 uint8_t wait_to_send; 320 uint8_t transaction_label; 321 // used for AVCTP fragmentation 322 uint8_t num_packets; 323 uint16_t bytes_to_send; 324 325 uint8_t *ertm_buffer; 326 uint32_t ertm_buffer_size; 327 l2cap_ertm_config_t ertm_config; 328 329 // players 330 uint8_t set_browsed_player_id; 331 uint16_t browsed_player_id; 332 333 avrcp_browsing_scope_t scope; 334 uint8_t folder_uid[8]; // or media element 335 uint16_t uid_counter; 336 337 // get folder item 338 uint8_t get_folder_items; 339 uint32_t start_item; 340 uint32_t end_item; 341 uint32_t attr_bitmap; 342 343 // item attrs 344 uint8_t get_item_attributes; 345 346 // change_path 347 uint8_t change_path; 348 uint8_t direction; 349 350 // search str 351 uint16_t search_str_len; 352 uint8_t search_str[20]; 353 uint8_t search; 354 355 // get_item_attributes 356 uint8_t get_total_nr_items; 357 avrcp_browsing_scope_t get_total_nr_items_scope; 358 359 avrcp_pdu_id_t pdu_id; 360 uint8_t browsing_status; 361 uint16_t num_items; 362 363 avrcp_parser_state_t parser_state; 364 uint8_t parser_attribute_header[AVRCP_BROWSING_ITEM_HEADER_LEN]; 365 uint8_t parser_attribute_header_pos; 366 uint8_t parsed_attribute_value[AVRCP_MAX_ATTRIBUTTE_SIZE]; 367 uint16_t parsed_attribute_value_len; 368 uint16_t parsed_attribute_value_offset; 369 uint8_t parsed_num_attributes; 370 371 // get folder items data 372 uint8_t * attr_list; 373 uint16_t attr_list_size; 374 // command 375 // uint8_t transaction_label; 376 avrcp_command_opcode_t command_opcode; 377 avrcp_command_type_t command_type; 378 avrcp_subunit_type_t subunit_type; 379 avrcp_subunit_id_t subunit_id; 380 avrcp_packet_type_t packet_type; 381 uint8_t cmd_operands[200]; 382 uint8_t cmd_operands_length; 383 } avrcp_browsing_connection_t; 384 // BROWSING END 385 386 typedef struct { 387 btstack_linked_item_t item; 388 bd_addr_t remote_addr; 389 uint16_t l2cap_signaling_cid; 390 uint16_t l2cap_mtu; 391 uint16_t avrcp_cid; 392 393 uint16_t avrcp_browsing_cid; 394 uint16_t browsing_l2cap_psm; 395 uint16_t browsing_version; 396 397 avrcp_browsing_connection_t * browsing_connection; 398 399 avctp_connection_state_t state; 400 uint8_t wait_to_send; 401 402 // PID check 403 uint8_t reject_transport_header; 404 uint8_t transport_header; 405 uint16_t invalid_pid; 406 407 // command 408 uint8_t transaction_label; 409 avrcp_command_opcode_t command_opcode; 410 avrcp_command_type_t command_type; 411 avrcp_subunit_type_t subunit_type; 412 avrcp_subunit_id_t subunit_id; 413 avrcp_packet_type_t packet_type; 414 415 // regular commands 416 uint8_t cmd_operands[20]; 417 uint8_t cmd_operands_length; 418 419 // long/fragmented commands 420 const uint8_t * cmd_operands_fragmented_buffer; 421 uint16_t cmd_operands_fragmented_pos; 422 uint16_t cmd_operands_fragmented_len; 423 424 btstack_timer_source_t press_and_hold_cmd_timer; 425 uint8_t continuous_fast_forward_cmd; 426 uint16_t notifications_enabled; 427 uint16_t notifications_to_register; 428 uint16_t notifications_to_deregister; 429 430 avrcp_subunit_type_t unit_type; 431 uint32_t company_id; 432 avrcp_subunit_type_t subunit_info_type; 433 const uint8_t * subunit_info_data; 434 uint16_t subunit_info_data_size; 435 436 avrcp_now_playing_info_item_t now_playing_info[AVRCP_MEDIA_ATTR_COUNT]; 437 uint8_t track_id[8]; 438 uint32_t song_length_ms; 439 uint32_t song_position_ms; 440 int total_tracks; 441 int track_nr; 442 uint8_t track_selected; 443 uint8_t track_changed; 444 445 avrcp_playback_status_t playback_status; 446 uint8_t playback_status_changed; 447 448 uint8_t playing_content_changed; 449 450 avrcp_battery_status_t battery_status; 451 uint8_t battery_status_changed; 452 uint8_t volume_percentage; 453 uint8_t volume_percentage_changed; 454 uint8_t now_playing_info_response; 455 uint8_t now_playing_info_attr_bitmap; 456 uint8_t abort_continue_response; 457 458 // used for fragmentation 459 avrcp_media_attribute_id_t next_attr_id; 460 461 avrcp_parser_state_t parser_state; 462 uint8_t parser_attribute_header[AVRCP_ATTRIBUTE_HEADER_LEN]; 463 uint8_t parser_attribute_header_pos; 464 465 uint16_t list_size; 466 uint16_t list_offset; 467 uint8_t attribute_value[AVRCP_MAX_ATTRIBUTTE_SIZE]; 468 uint16_t attribute_value_len; 469 uint16_t attribute_value_offset; 470 471 uint32_t attribute_id; 472 473 uint8_t num_attributes; 474 uint8_t num_parsed_attributes; 475 476 uint8_t addressed_player_changed; 477 uint16_t addressed_player_id; 478 uint16_t uid_counter; 479 // PTS requires definition of max num fragments 480 uint8_t max_num_fragments; 481 uint8_t num_received_fragments; 482 } avrcp_connection_t; 483 484 typedef enum { 485 AVRCP_SHUFFLE_MODE_INVALID, 486 AVRCP_SHUFFLE_MODE_OFF, 487 AVRCP_SHUFFLE_MODE_ALL_TRACKS, 488 AVRCP_SHUFFLE_MODE_GROUP 489 } avrcp_shuffle_mode_t; 490 491 typedef enum { 492 AVRCP_REPEAT_MODE_INVALID, 493 AVRCP_REPEAT_MODE_OFF, 494 AVRCP_REPEAT_MODE_SINGLE_TRACK, 495 AVRCP_REPEAT_MODE_ALL_TRACKS, 496 AVRCP_REPEAT_MODE_GROUP 497 } avrcp_repeat_mode_t; 498 499 typedef enum{ 500 AVRCP_CONTROLLER = 0, 501 AVRCP_TARGET 502 } avrcp_role_t; 503 504 typedef enum { 505 RFC2978_CHARSET_MIB_UTF8 = 106 506 } rfc2978_charset_mib_enumid_t; 507 508 typedef struct { 509 avrcp_role_t role; 510 btstack_linked_list_t connections; 511 btstack_packet_handler_t avrcp_callback; 512 btstack_packet_handler_t packet_handler; 513 514 btstack_packet_handler_t browsing_avrcp_callback; 515 btstack_packet_handler_t browsing_packet_handler; 516 517 // SDP query 518 uint8_t parse_sdp_record; 519 uint32_t record_id; 520 uint16_t avrcp_cid; 521 uint16_t avrcp_l2cap_psm; 522 uint16_t avrcp_version; 523 } avrcp_context_t; 524 525 526 const char * avrcp_subunit2str(uint16_t index); 527 const char * avrcp_event2str(uint16_t index); 528 const char * avrcp_operation2str(uint8_t index); 529 const char * avrcp_attribute2str(uint8_t index); 530 const char * avrcp_play_status2str(uint8_t index); 531 const char * avrcp_ctype2str(uint8_t index); 532 const char * avrcp_repeat2str(uint8_t index); 533 const char * avrcp_shuffle2str(uint8_t index); 534 535 void avrcp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size, avrcp_context_t * context); 536 537 void avrcp_create_sdp_record(uint8_t controller, uint8_t * service, uint32_t service_record_handle, uint8_t browsing, uint16_t supported_features, const char * service_name, const char * service_provider_name); 538 uint8_t avrcp_connect(bd_addr_t bd_addr, avrcp_context_t * context, uint16_t * avrcp_cid); 539 void avrcp_emit_connection_established(btstack_packet_handler_t callback, uint16_t avrcp_cid, bd_addr_t addr, uint8_t status); 540 void avrcp_emit_connection_closed(btstack_packet_handler_t callback, uint16_t avrcp_cid); 541 542 uint8_t avrcp_cmd_opcode(uint8_t *packet, uint16_t size); 543 avrcp_connection_t * get_avrcp_connection_for_l2cap_signaling_cid(uint16_t l2cap_cid, avrcp_context_t * context); 544 avrcp_connection_t * get_avrcp_connection_for_avrcp_cid(uint16_t avrcp_cid, avrcp_context_t * context); 545 avrcp_connection_t * get_avrcp_connection_for_bd_addr(bd_addr_t addr, avrcp_context_t * context); 546 void avrcp_request_can_send_now(avrcp_connection_t * connection, uint16_t l2cap_cid); 547 uint16_t avrcp_get_next_cid(void); 548 549 // SDP query 550 void avrcp_handle_sdp_client_query_result(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); 551 552 #if defined __cplusplus 553 } 554 #endif 555 556 #endif // __AVRCP_H 557