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 BLUEKITCHEN 24 * GMBH 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 * Audio/Video Remote Control Profile (AVRCP) 40 * 41 */ 42 43 #ifndef AVRCP_H 44 #define AVRCP_H 45 46 #include <stdint.h> 47 48 #include "btstack_bool.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 PSM_AVCTP_BROWSING 0x001b 58 59 #define AVRCP_BROWSING_ITEM_HEADER_LEN 3 60 #define AVRCP_BROWSING_MAX_NUM_ATTR_IDS 8 61 62 #define AVRCP_MAX_AV_C_MESSAGE_FRAME_SIZE 512 63 64 #define AVRCP_MAX_COMMAND_PARAMETER_LENGTH 11 65 #define BT_SIG_COMPANY_ID 0x001958 66 #define AVRCP_MEDIA_ATTR_COUNT 7 67 #define AVRCP_MAX_ATTRIBUTE_SIZE 130 68 #define AVRCP_ATTRIBUTE_HEADER_LEN 8 69 #define AVRCP_MAX_FOLDER_NAME_SIZE 20 70 71 #define AVRCP_NO_TRACK_SELECTED_PLAYBACK_POSITION_CHANGED 0xFFFFFFFF 72 73 #define AVRCP_FEATURE_MASK_CATEGORY_PLAYER_OR_RECORDER 0x0001u 74 #define AVRCP_FEATURE_MASK_CATEGORY_MONITOR_OR_AMPLIFIER 0x0002u 75 #define AVRCP_FEATURE_MASK_CATEGORY_TUNER 0x0004u 76 #define AVRCP_FEATURE_MASK_CATEGORY_MENU 0x0008u 77 #define AVRCP_FEATURE_MASK_PLAYER_APPLICATION_SETTINGS 0x0010u // AVRCP_FEATURE_MASK_CATEGORY_PLAYER_OR_RECORDER must be 1 for this feature to be set 78 #define AVRCP_FEATURE_MASK_GROUP_NAVIGATION 0x0020u // AVRCP_FEATURE_MASK_CATEGORY_PLAYER_OR_RECORDER must be 1 for this feature to be set 79 #define AVRCP_FEATURE_MASK_BROWSING 0x0040u 80 #define AVRCP_FEATURE_MASK_MULTIPLE_MEDIA_PLAYE_APPLICATIONS 0x0080u 81 82 typedef enum { 83 AVRCP_STATUS_INVALID_COMMAND = 0, // sent if TG received a PDU that it did not understand. 84 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. 85 AVRCP_STATUS_SPECIFIED_PARAMETER_NOT_FOUND, // sent if the parameter ID is understood, but content is wrong or corrupted. 86 AVRCP_STATUS_INTERNAL_ERROR, // sent if there are error conditions not covered by a more specific error code. 87 AVRCP_STATUS_SUCCESS, // sent if the operation was successful. 88 AVRCP_STATUS_UID_CHANGED, // sent if the UIDs on the device have changed. 89 AVRCP_STATUS_RESERVED_6, 90 AVRCP_STATUS_INVALID_DIRECTION, // The Direction parameter is invalid. Valid for command: Change Path 91 AVRCP_STATUS_NOT_A_DIRECTORY, // The UID provided does not refer to a folder item. Valid for command: Change Path 92 AVRCP_STATUS_DOES_NOT_EXIST, // The UID provided does not refer to any currently valid. Valid for command: Change Path, PlayItem, AddToNowPlaying, GetItemAttributes 93 AVRCP_STATUS_INVALID_SCOPE, // The scope parameter is invalid. Valid for command: GetFolderItems, PlayItem, AddToNowPlayer, GetItemAttributes, 94 AVRCP_STATUS_RANGE_OUT_OF_BOUNDS, // The start of range provided is not valid. Valid for command: GetFolderItems 95 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 96 AVRCP_STATUS_MEDIA_IN_USE, // The media is not able to be used for this operation at this time. Valid for command: PlayItem, AddToNowPlaying 97 AVRCP_STATUS_NOW_PLAYING_LIST_FULL, // No more items can be added to the Now Playing List. Valid for command: AddToNowPlaying 98 AVRCP_STATUS_SEARCH_NOT_SUPPORTED, // The Browsed Media Player does not support search. Valid for command: Search 99 AVRCP_STATUS_SEARCH_IN_PROGRESS, // A search operation is already in progress. Valid for command: Search 100 AVRCP_STATUS_INVALID_PLAYER_ID, // The specified Player Id does not refer to a valid player. Valid for command: SetAddressedPlayer, SetBrowsedPlayer 101 AVRCP_STATUS_PLAYER_NOT_BROWSABLE, // The Player Id supplied refers to a Media Player which does not support browsing. Valid for command: SetBrowsedPlayer 102 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 103 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 104 AVRCP_STATUS_NO_AVAILABLE_PLAYERS, 105 AVRCP_STATUS_ADDRESSED_PLAYER_CHANGED, // Valid for command: Register Notification 106 AVRCP_STATUS_RESERVED // 0x17 - 0xFF 107 } avrcp_status_code_t; 108 109 typedef enum { 110 AVRCP_SINGLE_PACKET= 0, 111 AVRCP_START_PACKET , 112 AVRCP_CONTINUE_PACKET , 113 AVRCP_END_PACKET 114 } avrcp_packet_type_t; 115 116 117 typedef enum { 118 AVCTP_SINGLE_PACKET= 0, 119 AVCTP_START_PACKET , 120 AVCTP_CONTINUE_PACKET , 121 AVCTP_END_PACKET 122 } avctp_packet_type_t; 123 124 typedef enum { 125 AVRCP_COMMAND_FRAME = 0, 126 AVRCP_RESPONSE_FRAME 127 } avrcp_frame_type_t; 128 129 130 typedef enum { 131 AVRCP_CAPABILITY_ID_COMPANY = 0x02, 132 AVRCP_CAPABILITY_ID_EVENT = 0x03 133 } avrcp_capability_id_t; 134 135 typedef enum { 136 AVRCP_MEDIA_ATTR_ALL = 0x0000, 137 AVRCP_MEDIA_ATTR_TITLE, 138 AVRCP_MEDIA_ATTR_ARTIST, 139 AVRCP_MEDIA_ATTR_ALBUM, 140 AVRCP_MEDIA_ATTR_TRACK, 141 AVRCP_MEDIA_ATTR_TOTAL_NUM_ITEMS, 142 AVRCP_MEDIA_ATTR_GENRE, 143 AVRCP_MEDIA_ATTR_SONG_LENGTH_MS, 144 AVRCP_MEDIA_ATTR_DEFAULT_COVER_ART, 145 AVRCP_MEDIA_ATTR_RESERVED = 0x0009, 146 AVRCP_MEDIA_ATTR_NONE = 0x7FFF 147 } avrcp_media_attribute_id_t; 148 149 typedef enum { 150 AVRCP_PDU_ID_GET_CAPABILITIES = 0x10, 151 AVRCP_PDU_ID_GET_CURRENT_PLAYER_APPLICATION_SETTING_VALUE = 0x13, 152 AVRCP_PDU_ID_SET_PLAYER_APPLICATION_SETTING_VALUE = 0x14, 153 AVRCP_PDU_ID_GET_ELEMENT_ATTRIBUTES = 0x20, 154 AVRCP_PDU_ID_GET_PLAY_STATUS = 0x30, 155 AVRCP_PDU_ID_REGISTER_NOTIFICATION = 0x31, 156 AVRCP_PDU_ID_REQUEST_CONTINUING_RESPONSE = 0x40, 157 AVRCP_PDU_ID_REQUEST_ABORT_CONTINUING_RESPONSE = 0x41, 158 AVRCP_PDU_ID_SET_ABSOLUTE_VOLUME = 0x50, 159 AVRCP_PDU_ID_SET_ADDRESSED_PLAYER = 0x60, 160 AVRCP_PDU_ID_SET_BROWSED_PLAYER = 0x70, 161 AVRCP_PDU_ID_GET_FOLDER_ITEMS = 0x71, 162 AVRCP_PDU_ID_CHANGE_PATH = 0x72, 163 AVRCP_PDU_ID_GET_ITEM_ATTRIBUTES = 0x73, 164 AVRCP_PDU_ID_PLAY_ITEM = 0x74, 165 AVRCP_PDU_ID_GET_TOTAL_NUMBER_OF_ITEMS = 0x75, 166 AVRCP_PDU_ID_SEARCH = 0x80, 167 AVRCP_PDU_ID_ADD_TO_NOW_PLAYING = 0x90, 168 AVRCP_PDU_ID_GENERAL_REJECT = 0xA0, 169 170 AVRCP_PDU_ID_UNDEFINED = 0xFF 171 } avrcp_pdu_id_t; 172 173 typedef enum { 174 AVRCP_NOTIFICATION_EVENT_NONE = 0, 175 AVRCP_NOTIFICATION_EVENT_FIRST_INDEX = 0x01, 176 AVRCP_NOTIFICATION_EVENT_PLAYBACK_STATUS_CHANGED = 0x01, // Change in playback status of the current track. 177 AVRCP_NOTIFICATION_EVENT_TRACK_CHANGED = 0x02, // Change of current track 178 AVRCP_NOTIFICATION_EVENT_TRACK_REACHED_END = 0x03, // Reached end of a track 179 AVRCP_NOTIFICATION_EVENT_TRACK_REACHED_START = 0x04, // Reached start of a track 180 AVRCP_NOTIFICATION_EVENT_PLAYBACK_POS_CHANGED = 0x05, // Change in playback position. Returned after the specified playback notification change notification interval 181 AVRCP_NOTIFICATION_EVENT_BATT_STATUS_CHANGED = 0x06, // Change in battery status 182 AVRCP_NOTIFICATION_EVENT_SYSTEM_STATUS_CHANGED = 0x07, // Change in system status 183 AVRCP_NOTIFICATION_EVENT_PLAYER_APPLICATION_SETTING_CHANGED = 0x08, // Change in player application setting 184 AVRCP_NOTIFICATION_EVENT_NOW_PLAYING_CONTENT_CHANGED = 0x09, // The content of the Now Playing list has changed, see 6.9.5. 185 AVRCP_NOTIFICATION_EVENT_AVAILABLE_PLAYERS_CHANGED = 0x0a, // The available players have changed, see 6.9.4. 186 AVRCP_NOTIFICATION_EVENT_ADDRESSED_PLAYER_CHANGED = 0x0b, // The Addressed Player has been changed, see 6.9.2. 187 AVRCP_NOTIFICATION_EVENT_UIDS_CHANGED = 0x0c, // The UIDs have changed, see 6.10.3.3. 188 AVRCP_NOTIFICATION_EVENT_VOLUME_CHANGED = 0x0d, // The volume has been changed locally on the TG, see 6.13.3. 189 AVRCP_NOTIFICATION_EVENT_MAX_VALUE = 0x0e, 190 AVRCP_NOTIFICATION_EVENT_LAST_INDEX = 0x0e 191 } avrcp_notification_event_id_t; 192 193 194 // control command response: accepted, rejected, interim 195 // status command response: not implemented, rejected, in transition, stable 196 // notify command response: not implemented, rejected, changed 197 198 typedef enum { 199 AVRCP_CTYPE_CONTROL = 0, 200 AVRCP_CTYPE_STATUS, 201 AVRCP_CTYPE_SPECIFIC_INQUIRY, 202 AVRCP_CTYPE_NOTIFY, 203 AVRCP_CTYPE_GENERAL_INQUIRY, 204 AVRCP_CTYPE_RESERVED5, 205 AVRCP_CTYPE_RESERVED6, 206 AVRCP_CTYPE_RESERVED7, 207 AVRCP_CTYPE_RESPONSE_NOT_IMPLEMENTED = 8, 208 AVRCP_CTYPE_RESPONSE_ACCEPTED, 209 AVRCP_CTYPE_RESPONSE_REJECTED, 210 AVRCP_CTYPE_RESPONSE_IN_TRANSITION, // target state is in transition. A subsequent STATUS command, may result in the return of a STABLE status 211 AVRCP_CTYPE_RESPONSE_IMPLEMENTED_STABLE, 212 AVRCP_CTYPE_RESPONSE_CHANGED_STABLE, 213 AVRCP_CTYPE_RESPONSE_RESERVED, 214 AVRCP_CTYPE_RESPONSE_INTERIM // target is unable to respond with either ACCEPTED or REJECTED within 100 millisecond 215 } avrcp_command_type_t; 216 217 typedef enum { 218 AVRCP_SUBUNIT_TYPE_MONITOR = 0, 219 AVRCP_SUBUNIT_TYPE_AUDIO = 1, 220 AVRCP_SUBUNIT_TYPE_PRINTER, 221 AVRCP_SUBUNIT_TYPE_DISC, 222 AVRCP_SUBUNIT_TYPE_TAPE_RECORDER_PLAYER, 223 AVRCP_SUBUNIT_TYPE_TUNER, 224 AVRCP_SUBUNIT_TYPE_CA, 225 AVRCP_SUBUNIT_TYPE_CAMERA, 226 AVRCP_SUBUNIT_TYPE_RESERVED, 227 AVRCP_SUBUNIT_TYPE_PANEL = 9, 228 AVRCP_SUBUNIT_TYPE_BULLETIN_BOARD, 229 AVRCP_SUBUNIT_TYPE_CAMERA_STORAGE, 230 AVRCP_SUBUNIT_TYPE_VENDOR_UNIQUE = 0x1C, 231 AVRCP_SUBUNIT_TYPE_RESERVED_FOR_ALL_SUBUNIT_TYPES, 232 AVRCP_SUBUNIT_TYPE_EXTENDED_TO_NEXT_BYTE, // The target_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]. 233 // Further extension is possible when the value of extended_unit_type is FF16, in which case another byte will be added. 234 AVRCP_SUBUNIT_TYPE_UNIT = 0x1F 235 } avrcp_subunit_type_t; 236 237 typedef enum { 238 AVRCP_SUBUNIT_ID = 0, 239 AVRCP_SUBUNIT_ID_IGNORE = 7 240 } avrcp_subunit_id_t; 241 242 typedef enum { 243 AVRCP_CMD_OPCODE_VENDOR_DEPENDENT = 0x00, 244 // AVRCP_CMD_OPCODE_RESERVE = 0x01, 245 AVRCP_CMD_OPCODE_UNIT_INFO = 0x30, 246 AVRCP_CMD_OPCODE_SUBUNIT_INFO = 0x31, 247 AVRCP_CMD_OPCODE_PASS_THROUGH = 0x7C, 248 // AVRCP_CMD_OPCODE_VERSION = 0xB0, 249 // AVRCP_CMD_OPCODE_POWER = 0xB2, 250 AVRCP_CMD_OPCODE_UNDEFINED = 0xFF 251 } avrcp_command_opcode_t; 252 253 // See "AVC-Panel Subunit.pdf", Chapter 9.4 "PASS THROUGH control command" 254 // Using subset defined in "AVRCP_v1.6.3.pdf", Chapter 4.6.1 "Support Level in TG" 255 256 typedef enum { 257 AVRCP_GROUP_OPERATION_ID_GOTO_NEXT = 0x00, 258 AVRCP_GROUP_OPERATION_ID_GOTO_PREVIOUS = 0x01 259 } avrcp_group_operation_id_t; 260 261 typedef enum { 262 AVRCP_OPERATION_ID_SELECT = 0x00, // Next Group 263 AVRCP_OPERATION_ID_UP = 0x01, // Previous Group 264 AVRCP_OPERATION_ID_DOWN = 0x02, 265 AVRCP_OPERATION_ID_LEFT = 0x03, 266 AVRCP_OPERATION_ID_RIGHT = 0x04, 267 AVRCP_OPERATION_ID_RIGHT_UP = 0x05, 268 AVRCP_OPERATION_ID_RIGHT_DOWN = 0x06, 269 AVRCP_OPERATION_ID_LEFT_UP = 0x07, 270 AVRCP_OPERATION_ID_LEFT_DOWN = 0x08, 271 AVRCP_OPERATION_ID_ROOT_MENU = 0x09, 272 AVRCP_OPERATION_ID_SETUP_MENU = 0x0A, 273 AVRCP_OPERATION_ID_CONTENTS_MENU = 0x0B, 274 AVRCP_OPERATION_ID_FAVORITE_MENU = 0x0C, 275 AVRCP_OPERATION_ID_EXIT = 0x0D, 276 AVRCP_OPERATION_ID_RESERVED_1 = 0x0E, 277 278 AVRCP_OPERATION_ID_0 = 0x20, 279 AVRCP_OPERATION_ID_1 = 0x21, 280 AVRCP_OPERATION_ID_2 = 0x22, 281 AVRCP_OPERATION_ID_3 = 0x23, 282 AVRCP_OPERATION_ID_4 = 0x24, 283 AVRCP_OPERATION_ID_5 = 0x25, 284 AVRCP_OPERATION_ID_6 = 0x26, 285 AVRCP_OPERATION_ID_7 = 0x27, 286 AVRCP_OPERATION_ID_8 = 0x28, 287 AVRCP_OPERATION_ID_9 = 0x29, 288 AVRCP_OPERATION_ID_DOT = 0x2A, 289 AVRCP_OPERATION_ID_ENTER = 0x2B, 290 AVRCP_OPERATION_ID_CLEAR = 0x2C, 291 AVRCP_OPERATION_ID_RESERVED_2 = 0x2D, 292 293 AVRCP_OPERATION_ID_CHANNEL_UP = 0x30, 294 AVRCP_OPERATION_ID_CHANNEL_DOWN = 0x31, 295 AVRCP_OPERATION_ID_PREVIOUS_CHANNEL = 0x32, 296 AVRCP_OPERATION_ID_SOUND_SELECT = 0x33, 297 AVRCP_OPERATION_ID_INPUT_SELECT = 0x34, 298 AVRCP_OPERATION_ID_DISPLAY_INFORMATION = 0x35, 299 AVRCP_OPERATION_ID_HELP = 0x36, 300 AVRCP_OPERATION_ID_PAGE_UP = 0x37, 301 AVRCP_OPERATION_ID_PAGE_DOWN = 0x38, 302 AVRCP_OPERATION_ID_RESERVED_3 = 0x39, 303 304 AVRCP_OPERATION_ID_SKIP = 0x3C, 305 306 AVRCP_OPERATION_ID_POWER = 0x40, 307 AVRCP_OPERATION_ID_VOLUME_UP = 0x41, 308 AVRCP_OPERATION_ID_VOLUME_DOWN = 0x42, 309 AVRCP_OPERATION_ID_MUTE = 0x43, 310 AVRCP_OPERATION_ID_PLAY = 0x44, 311 AVRCP_OPERATION_ID_STOP = 0x45, 312 AVRCP_OPERATION_ID_PAUSE = 0x46, 313 AVRCP_OPERATION_ID_RECORD = 0x47, 314 AVRCP_OPERATION_ID_REWIND = 0x48, 315 AVRCP_OPERATION_ID_FAST_FORWARD = 0x49, 316 AVRCP_OPERATION_ID_EJECT = 0x4A, 317 AVRCP_OPERATION_ID_FORWARD = 0x4B, 318 AVRCP_OPERATION_ID_BACKWARD = 0x4C, 319 AVRCP_OPERATION_ID_RESERVED_4 = 0x4D, 320 321 AVRCP_OPERATION_ID_ANGLE = 0x50, 322 AVRCP_OPERATION_ID_SUBPICTURE = 0x51, 323 AVRCP_OPERATION_ID_RESERVED_5 = 0x52, 324 325 AVRCP_OPERATION_ID_F1 = 0x71, 326 AVRCP_OPERATION_ID_F2 = 0x72, 327 AVRCP_OPERATION_ID_F3 = 0x73, 328 AVRCP_OPERATION_ID_F4 = 0x74, 329 AVRCP_OPERATION_ID_F5 = 0x75, 330 AVRCP_OPERATION_ID_RESERVED_6 = 0x76, 331 332 AVRCP_OPERATION_ID_VENDOR_UNIQUE = 0x7E, 333 AVRCP_OPERATION_ID_RESERVED_7 = 0x7F 334 } avrcp_operation_id_t; 335 336 typedef enum{ 337 AVRCP_PLAYBACK_STATUS_STOPPED = 0x00, 338 AVRCP_PLAYBACK_STATUS_PLAYING, 339 AVRCP_PLAYBACK_STATUS_PAUSED, 340 AVRCP_PLAYBACK_STATUS_FWD_SEEK, 341 AVRCP_PLAYBACK_STATUS_REV_SEEK, 342 AVRCP_PLAYBACK_STATUS_ERROR = 0xFF 343 } avrcp_playback_status_t; 344 345 typedef enum { 346 AVRCP_BATTERY_STATUS_NORMAL = 0x00, // Battery operation is in normal state 347 AVRCP_BATTERY_STATUS_WARNING, // unable to operate soon. Is provided when the battery level is going down. 348 AVRCP_BATTERY_STATUS_CRITICAL, // can not operate any more. Is provided when the battery level is going down. 349 AVRCP_BATTERY_STATUS_EXTERNAL, // Plugged to external power supply 350 AVRCP_BATTERY_STATUS_FULL_CHARGE // when the device is completely charged from the external power supply 351 } avrcp_battery_status_t; 352 353 typedef enum { 354 AVRCP_SYSTEM_STATUS_POWER_ON = 0x00, 355 AVRCP_SYSTEM_STATUS_POWER_OFF, 356 AVRCP_SYSTEM_STATUS_UNPLUGGED 357 } avrcp_system_status_t; 358 359 typedef enum { 360 AVRCP_PLAYER_APPLICATION_SETTING_ATTRIBUTE_ID_ILLEGAL = 0x00, // ValueIDs with descriptions: 361 AVRCP_PLAYER_APPLICATION_SETTING_ATTRIBUTE_ID_EQUALIZER_STATUS, // 1 - off, 2 - on 362 AVRCP_PLAYER_APPLICATION_SETTING_ATTRIBUTE_ID_REPEAT_MODE_STATUS, // 1 - off, 2 - single track repeat, 3 - all tracks repeat, 4 - group repeat 363 AVRCP_PLAYER_APPLICATION_SETTING_ATTRIBUTE_ID_SHUFFLE_STATUS, // 1 - off, 2 - all tracks shuffle , 3 - group shuffle 364 AVRCP_PLAYER_APPLICATION_SETTING_ATTRIBUTE_ID_SCAN_STATUS // 1 - off, 2 - all tracks scan , 3 - group scan 365 } avrcp_player_application_setting_attribute_id_t; 366 367 typedef enum { 368 AVCTP_CONNECTION_IDLE, 369 AVCTP_CONNECTION_W4_SDP_QUERY_COMPLETE, 370 AVCTP_CONNECTION_W4_ERTM_CONFIGURATION, 371 AVCTP_CONNECTION_W2_L2CAP_CONNECT, 372 AVCTP_CONNECTION_W4_L2CAP_CONNECTED, 373 AVCTP_CONNECTION_W2_L2CAP_RETRY, 374 AVCTP_CONNECTION_OPENED, 375 AVCTP_W2_SEND_PRESS_COMMAND, 376 AVCTP_W2_SEND_RELEASE_COMMAND, 377 AVCTP_W4_STOP, 378 AVCTP_W2_SEND_COMMAND, 379 AVCTP_W2_SEND_RESPONSE, 380 AVCTP_W2_RECEIVE_PRESS_RESPONSE, 381 AVCTP_W2_RECEIVE_RESPONSE, 382 AVCTP_W2_SEND_GET_ELEMENT_ATTRIBUTES_REQUEST, 383 //AVCTP_W2_SEND_AVCTP_FRAGMENTED_MESSAGE 384 } avctp_connection_state_t; 385 386 typedef struct { 387 uint16_t len; 388 uint8_t * value; 389 } avrcp_now_playing_info_item_t; 390 391 typedef struct { 392 uint8_t track_id[8]; 393 uint16_t track_nr; 394 char * title; 395 char * artist; 396 char * album; 397 char * genre; 398 uint32_t song_length_ms; 399 uint32_t song_position_ms; 400 } avrcp_track_t; 401 402 typedef enum { 403 AVRCP_PARSER_GET_ATTRIBUTE_HEADER = 0, // 8 bytes 404 AVRCP_PARSER_GET_ATTRIBUTE_VALUE, 405 AVRCP_PARSER_IGNORE_REST_OF_ATTRIBUTE_VALUE 406 } avrcp_parser_state_t; 407 408 typedef enum{ 409 AVRCP_CONTROLLER = 0, 410 AVRCP_TARGET 411 } avrcp_role_t; 412 413 typedef enum { 414 AVRCP_SHUFFLE_MODE_INVALID, 415 AVRCP_SHUFFLE_MODE_OFF, 416 AVRCP_SHUFFLE_MODE_ALL_TRACKS, 417 AVRCP_SHUFFLE_MODE_GROUP 418 } avrcp_shuffle_mode_t; 419 420 typedef enum { 421 AVRCP_REPEAT_MODE_INVALID, 422 AVRCP_REPEAT_MODE_OFF, 423 AVRCP_REPEAT_MODE_SINGLE_TRACK, 424 AVRCP_REPEAT_MODE_ALL_TRACKS, 425 AVRCP_REPEAT_MODE_GROUP 426 } avrcp_repeat_mode_t; 427 428 typedef enum { 429 RFC2978_CHARSET_MIB_UTF8 = 106 430 } rfc2978_charset_mib_enumid_t; 431 432 typedef enum { 433 AVRCP_BROWSING_MEDIA_PLAYER_LIST = 0x00, 434 AVRCP_BROWSING_MEDIA_PLAYER_VIRTUAL_FILESYSTEM, 435 AVRCP_BROWSING_SEARCH, 436 AVRCP_BROWSING_NOW_PLAYING 437 } avrcp_browsing_scope_t; 438 439 typedef enum{ 440 AVRCP_REMOTE_CAPABILITIES_NONE = 0, 441 AVRCP_REMOTE_CAPABILITIES_W4_QUERY_RESULT, 442 AVRCP_REMOTE_CAPABILITIES_KNOWN 443 } avrcp_remote_capabilities_state_t; 444 445 446 // BROWSING 447 typedef struct { 448 uint16_t l2cap_browsing_cid; 449 450 avctp_connection_state_t state; 451 bool wait_to_send; 452 uint8_t transaction_label; 453 // used for fragmentation 454 uint8_t num_packets; 455 uint16_t bytes_to_send; 456 457 uint8_t *ertm_buffer; 458 uint32_t ertm_buffer_size; 459 l2cap_ertm_config_t ertm_config; 460 461 // players 462 uint8_t set_browsed_player_id; 463 uint16_t browsed_player_id; 464 465 avrcp_browsing_scope_t scope; 466 uint8_t folder_uid[8]; // or media element 467 uint16_t uid_counter; 468 469 // get folder item 470 uint8_t get_folder_items; 471 uint32_t start_item; 472 uint32_t end_item; 473 uint32_t attr_bitmap; 474 475 // item attrs 476 uint8_t get_item_attributes; 477 478 // change_path 479 uint8_t change_path; 480 uint8_t direction; 481 482 // search str 483 uint16_t search_str_len; 484 uint8_t search_str[20]; 485 uint8_t search; 486 487 // get_item_attributes 488 uint8_t get_total_nr_items; 489 avrcp_browsing_scope_t get_total_nr_items_scope; 490 491 avrcp_pdu_id_t pdu_id; 492 uint8_t browsing_status; 493 uint16_t num_items; 494 495 avrcp_parser_state_t parser_state; 496 uint8_t parser_attribute_header[AVRCP_BROWSING_ITEM_HEADER_LEN]; 497 uint8_t parser_attribute_header_pos; 498 uint8_t parsed_attribute_value[AVRCP_MAX_ATTRIBUTE_SIZE]; 499 uint16_t parsed_attribute_value_len; 500 uint16_t parsed_attribute_value_offset; 501 uint8_t parsed_num_attributes; 502 503 // get folder items data 504 uint8_t * attr_list; 505 uint16_t attr_list_size; 506 // command 507 // uint8_t transaction_label; 508 avrcp_command_opcode_t command_opcode; 509 avrcp_command_type_t command_type; 510 avrcp_subunit_type_t subunit_type; 511 avrcp_subunit_id_t subunit_id; 512 avrcp_packet_type_t packet_type; 513 uint8_t cmd_operands[200]; 514 uint8_t cmd_operands_length; 515 516 bool incoming_declined; 517 } avrcp_browsing_connection_t; 518 519 typedef struct { 520 btstack_linked_item_t item; 521 522 avrcp_role_t role; 523 bd_addr_t remote_addr; 524 hci_con_handle_t con_handle; 525 526 uint16_t l2cap_signaling_cid; 527 uint16_t l2cap_mtu; 528 uint16_t avrcp_cid; 529 uint16_t avrcp_browsing_cid; 530 531 bool incoming_declined; 532 533 bool trigger_sdp_query; 534 535 // SDP results 536 uint16_t avrcp_l2cap_psm; 537 uint16_t browsing_l2cap_psm; 538 uint16_t browsing_version; 539 #ifdef ENABLE_AVRCP_COVER_ART 540 uint16_t cover_art_psm; 541 #endif 542 543 avrcp_browsing_connection_t * browsing_connection; 544 545 avctp_connection_state_t state; 546 bool wait_to_send; 547 548 549 // transaction id 550 uint8_t transaction_id_counter; 551 552 btstack_timer_source_t retry_timer; 553 554 // AVCTP header 555 uint8_t transaction_id; 556 avctp_packet_type_t avctp_packet_type; 557 // AVRCP header 558 avrcp_packet_type_t avrcp_packet_type; 559 uint16_t avrcp_frame_bytes_sent; 560 avrcp_subunit_type_t subunit_type; 561 avrcp_subunit_id_t subunit_id; 562 uint32_t company_id; 563 // message (command and response) header 564 avrcp_pdu_id_t pdu_id; 565 avrcp_command_opcode_t command_opcode; 566 avrcp_command_type_t command_type; 567 // needed for PASS_THROUGH 568 avrcp_operation_id_t operation_id; 569 570 uint16_t notifications_enabled; 571 uint16_t notifications_supported_by_target; 572 573 // message data, used for responses and commands that fit into a single AVCTP packet 574 uint8_t message_body[AVRCP_MAX_COMMAND_PARAMETER_LENGTH]; 575 576 // pointer to command and response data 577 uint8_t * data; 578 uint16_t data_len; 579 580 // used for fragmentation 581 uint16_t data_offset; 582 avrcp_media_attribute_id_t next_attr_id; 583 584 // used for parser in controller, and for fragmentation in target 585 uint8_t attribute_value[AVRCP_MAX_ATTRIBUTE_SIZE]; 586 uint16_t attribute_value_len; 587 uint16_t attribute_value_offset; 588 589 // controller only 590 // parser 591 avrcp_parser_state_t parser_state; 592 uint8_t parser_attribute_header[AVRCP_ATTRIBUTE_HEADER_LEN]; 593 uint8_t parser_attribute_header_pos; 594 uint16_t list_size; 595 uint16_t list_offset; 596 597 // limit number of pending commands to transaction id window size 598 uint8_t controller_last_confirmed_transaction_id; 599 600 btstack_timer_source_t controller_press_and_hold_cmd_timer; 601 bool controller_press_and_hold_cmd_active; 602 bool controller_press_and_hold_cmd_release; 603 604 avrcp_remote_capabilities_state_t remote_capabilities_state; 605 bool controller_notifications_supported_by_target_suppress_emit_result; 606 uint16_t controller_initial_status_reported; 607 uint16_t controller_notifications_to_register; 608 uint16_t controller_notifications_to_deregister; 609 610 // used for avrcp_controller_get_element_attributes 611 uint16_t controller_element_attributes; 612 613 // PTS requires definition of max num fragments 614 uint8_t controller_max_num_fragments; 615 uint8_t controller_num_received_fragments; 616 617 // target only 618 // PID check 619 bool target_reject_transport_header; 620 uint16_t target_invalid_pid; 621 622 uint8_t target_notifications_transaction_label[AVRCP_NOTIFICATION_EVENT_MAX_VALUE + 1]; 623 624 avrcp_subunit_type_t target_unit_type; 625 avrcp_subunit_type_t target_subunit_info_type; 626 const uint8_t * target_subunit_info_data; 627 uint16_t target_subunit_info_data_size; 628 629 const uint32_t * target_supported_companies; 630 uint8_t target_supported_companies_num; 631 632 bool target_addressed_player_changed; 633 uint16_t target_addressed_player_id; 634 uint16_t target_uid_counter; 635 636 bool target_accept_response; 637 638 bool target_now_playing_info_response; 639 bool target_abort_continue_response; 640 bool target_continue_response; 641 uint8_t target_now_playing_info_attr_bitmap; 642 643 bool target_playback_status_changed; 644 avrcp_playback_status_t target_playback_status; 645 646 bool target_battery_status_changed; 647 avrcp_battery_status_t target_battery_status; 648 649 bool target_notify_absolute_volume_changed; 650 uint8_t target_absolute_volume; 651 652 bool target_playing_content_changed; 653 bool target_track_selected; 654 bool target_track_changed; 655 avrcp_now_playing_info_item_t target_now_playing_info[AVRCP_MEDIA_ATTR_COUNT]; 656 uint8_t target_track_id[8]; 657 uint32_t target_song_length_ms; 658 uint32_t target_song_position_ms; 659 uint32_t target_total_tracks; 660 uint32_t target_track_nr; 661 662 #ifdef ENABLE_AVCTP_FRAGMENTATION 663 uint16_t avctp_reassembly_size; 664 uint8_t avctp_reassembly_buffer[200]; 665 #endif 666 667 } avrcp_connection_t; 668 669 typedef struct { 670 avrcp_role_t role; 671 btstack_packet_handler_t avrcp_callback; 672 btstack_packet_handler_t packet_handler; 673 674 bool (*set_addressed_player_callback)(uint16_t player_id); 675 676 btstack_packet_handler_t browsing_avrcp_callback; 677 btstack_packet_handler_t browsing_packet_handler; 678 } avrcp_context_t; 679 680 681 const char * avrcp_subunit2str(uint16_t index); 682 const char * avrcp_event2str(uint16_t index); 683 const char * avrcp_operation2str(uint8_t index); 684 const char * avrcp_attribute2str(uint8_t index); 685 const char * avrcp_play_status2str(uint8_t index); 686 const char * avrcp_ctype2str(uint8_t index); 687 const char * avrcp_repeat2str(uint8_t index); 688 const char * avrcp_shuffle2str(uint8_t index); 689 const char * avrcp_notification2str(avrcp_notification_event_id_t index); 690 691 avctp_packet_type_t avctp_get_packet_type(avrcp_connection_t * connection, uint16_t * max_payload_size); 692 avrcp_packet_type_t avrcp_get_packet_type(avrcp_connection_t * connection); 693 uint16_t avctp_get_num_bytes_for_header(avctp_packet_type_t avctp_packet_type); 694 uint16_t avrcp_get_num_bytes_for_header(avrcp_command_opcode_t command_opcode, avctp_packet_type_t avctp_packet_type); 695 696 void avrcp_register_controller_packet_handler(btstack_packet_handler_t avrcp_controller_packet_handler); 697 void avrcp_register_target_packet_handler(btstack_packet_handler_t avrcp_target_packet_handler); 698 699 void avrcp_register_browsing_sdp_query_complete_handler(void (*callback)(avrcp_connection_t * connection, uint8_t status)); 700 void avrcp_register_cover_art_sdp_query_complete_handler(void (*callback)(avrcp_connection_t * connection, uint8_t status)); 701 702 uint8_t avrcp_cmd_opcode(uint8_t *packet, uint16_t size); 703 704 avrcp_connection_t * avrcp_get_connection_for_l2cap_signaling_cid_for_role(avrcp_role_t role, uint16_t l2cap_cid); 705 avrcp_connection_t * avrcp_get_connection_for_avrcp_cid_for_role(avrcp_role_t role, uint16_t avrcp_cid); 706 avrcp_connection_t * avrcp_get_connection_for_bd_addr_for_role(avrcp_role_t role, bd_addr_t addr); 707 708 avrcp_connection_t * avrcp_get_connection_for_browsing_cid_for_role(avrcp_role_t role, uint16_t browsing_cid); 709 avrcp_connection_t * avrcp_get_connection_for_browsing_l2cap_cid_for_role(avrcp_role_t role, uint16_t browsing_l2cap_cid); 710 avrcp_browsing_connection_t * avrcp_get_browsing_connection_for_l2cap_cid_for_role(avrcp_role_t role, uint16_t l2cap_cid); 711 712 void avrcp_request_can_send_now(avrcp_connection_t * connection, uint16_t l2cap_cid); 713 uint16_t avrcp_get_next_cid(avrcp_role_t role); 714 btstack_linked_list_t avrcp_get_connections(void); 715 716 uint16_t avrcp_sdp_query_browsing_l2cap_psm(void); 717 void avrcp_handle_sdp_client_query_attribute_value(uint8_t *packet); 718 avrcp_connection_t * get_avrcp_connection_for_browsing_cid_for_role(avrcp_role_t role, uint16_t browsing_cid); 719 avrcp_connection_t * get_avrcp_connection_for_browsing_l2cap_cid_for_role(avrcp_role_t role, uint16_t browsing_l2cap_cid); 720 avrcp_browsing_connection_t * get_avrcp_browsing_connection_for_l2cap_cid_for_role(avrcp_role_t role, uint16_t l2cap_cid); 721 // SDP query 722 void avrcp_create_sdp_record(bool 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); 723 void avrcp_trigger_sdp_query(avrcp_connection_t *connection_controller, avrcp_connection_t *connection_target); 724 725 726 /* API_START */ 727 728 /** 729 * @brief Set up AVRCP service 730 */ 731 void avrcp_init(void); 732 733 /** 734 * @brief Register callback for the AVRCP Controller client. 735 * @param callback 736 */ 737 void avrcp_register_packet_handler(btstack_packet_handler_t callback); 738 739 /** 740 * @brief Connect to AVRCP service on a remote device, emits AVRCP_SUBEVENT_CONNECTION_ESTABLISHED with status 741 * @param remote_addr 742 * @param avrcp_cid outgoing parameter, valid if status == ERROR_CODE_SUCCESS 743 * @return status 744 */ 745 uint8_t avrcp_connect(bd_addr_t remote_addr, uint16_t * avrcp_cid); 746 747 /** 748 * @brief Disconnect from AVRCP service 749 * @param avrcp_cid 750 * @return status 751 */ 752 uint8_t avrcp_disconnect(uint16_t avrcp_cid); 753 754 /** 755 * @brief De-Init AVRCP 756 */ 757 void avrcp_deinit(void); 758 759 /* API_END */ 760 761 #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION 762 void avrcp_init_fuzz(void); 763 void avrcp_packet_handler_fuzz(uint8_t *packet, uint16_t size); 764 #endif 765 766 767 #if defined __cplusplus 768 } 769 #endif 770 771 #endif // AVRCP_H 772