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