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