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