1 /* 2 * Copyright (C) 2016 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 /* 39 * avrcp.h 40 * 41 * Audio/Video Remote Control Profile 42 * 43 */ 44 45 #ifndef __AVRCP_H 46 #define __AVRCP_H 47 48 #include <stdint.h> 49 #include "btstack_run_loop.h" 50 #include "btstack_linked_list.h" 51 52 #if defined __cplusplus 53 extern "C" { 54 #endif 55 56 #define BT_SIG_COMPANY_ID 0x001958 57 /* API_START */ 58 59 typedef enum { 60 AVRCP_CAPABILITY_ID_COMPANY = 0x02, 61 AVRCP_CAPABILITY_ID_EVENT = 0x03 62 } avrcp_capability_id_t; 63 64 typedef enum { 65 AVRCP_MEDIA_ATTR_TITLE = 1, 66 AVRCP_MEDIA_ATTR_ARTIST, 67 AVRCP_MEDIA_ATTR_ALBUM, 68 AVRCP_MEDIA_ATTR_TRACK, 69 AVRCP_MEDIA_ATTR_TOTAL_TRACKS, 70 AVRCP_MEDIA_ATTR_GENRE, 71 AVRCP_MEDIA_ATTR_SONG_LENGTH 72 } avrcp_media_attribute_id_t; 73 74 #define AVRCP_MEDIA_ATTR_COUNT 7 75 76 typedef enum { 77 AVRCP_PDU_ID_GET_CAPABILITIES = 0x10, 78 AVRCP_PDU_ID_GetCurrentPlayerApplicationSettingValue = 0x13, 79 AVRCP_PDU_ID_SetPlayerApplicationSettingValue = 0x14, 80 AVRCP_PDU_ID_GET_ELEMENT_ATTRIBUTES = 0x20, 81 AVRCP_PDU_ID_GET_PLAY_STATUS = 0x30, 82 AVRCP_PDU_ID_REGISTER_NOTIFICATION = 0x31, 83 AVRCP_PDU_ID_SET_ABSOLUTE_VOLUME = 0x50 84 } avrcp_pdu_id_t; 85 86 typedef enum { 87 AVRCP_NOTIFICATION_EVENT_PLAYBACK_STATUS_CHANGED = 0x01, // Change in playback status of the current track. 88 AVRCP_NOTIFICATION_EVENT_TRACK_CHANGED = 0x02, // Change of current track 89 AVRCP_NOTIFICATION_EVENT_TRACK_REACHED_END = 0x03, // Reached end of a track 90 AVRCP_NOTIFICATION_EVENT_TRACK_REACHED_START = 0x04, // Reached start of a track 91 AVRCP_NOTIFICATION_EVENT_PLAYBACK_POS_CHANGED = 0x05, // Change in playback position. Returned after the specified playback notification change notification interval 92 AVRCP_NOTIFICATION_EVENT_BATT_STATUS_CHANGED = 0x06, // Change in battery status 93 AVRCP_NOTIFICATION_EVENT_SYSTEM_STATUS_CHANGED = 0x07, // Change in system status 94 AVRCP_NOTIFICATION_EVENT_PLAYER_APPLICATION_SETTING_CHANGED = 0x08, // Change in player application setting 95 AVRCP_NOTIFICATION_EVENT_NOW_PLAYING_CONTENT_CHANGED = 0x09, // The content of the Now Playing list has changed, see 6.9.5. 96 AVRCP_NOTIFICATION_EVENT_AVAILABLE_PLAYERS_CHANGED = 0x0a, // The available players have changed, see 6.9.4. 97 AVRCP_NOTIFICATION_EVENT_ADDRESSED_PLAYER_CHANGED = 0x0b, // The Addressed Player has been changed, see 6.9.2. 98 AVRCP_NOTIFICATION_EVENT_UIDS_CHANGED = 0x0c, // The UIDs have changed, see 6.10.3.3. 99 AVRCP_NOTIFICATION_EVENT_VOLUME_CHANGED = 0x0d // The volume has been changed locally on the TG, see 6.13.3. 100 } avrcp_notification_event_id_t; 101 102 typedef enum { 103 AVRCP_CTYPE_CONTROL = 0, 104 AVRCP_CTYPE_STATUS, 105 AVRCP_CTYPE_SPECIFIC_INQUIRY, 106 AVRCP_CTYPE_NOTIFY, 107 AVRCP_CTYPE_GENERAL_INQUIRY, 108 AVRCP_CTYPE_RESERVED5, 109 AVRCP_CTYPE_RESERVED6, 110 AVRCP_CTYPE_RESERVED7, 111 AVRCP_CTYPE_RESPONSE_NOT_IMPLEMENTED = 8, 112 AVRCP_CTYPE_RESPONSE_ACCEPTED, 113 AVRCP_CTYPE_RESPONSE_REJECTED, 114 AVRCP_CTYPE_RESPONSE_IN_TRANSITION, // target state is in transition. A subsequent STATUS command, may result in the return of a STABLE status 115 AVRCP_CTYPE_RESPONSE_IMPLEMENTED_STABLE, 116 AVRCP_CTYPE_RESPONSE_CHANGED_STABLE, 117 AVRCP_CTYPE_RESPONSE_RESERVED, 118 AVRCP_CTYPE_RESPONSE_INTERIM // target is unable to respond with either ACCEPTED or REJECTED within 100 millisecond 119 } avrcp_command_type_t; 120 121 // control command response: accepted, rejected, interim 122 // status command response: not implemented, rejected, in transiiton, stable 123 // notify command response: not implemented, rejected, changed 124 typedef enum { 125 AVRCP_SUBUNIT_TYPE_MONITOR = 0, 126 AVRCP_SUBUNIT_TYPE_AUDIO = 1, 127 AVRCP_SUBUNIT_TYPE_PRINTER, 128 AVRCP_SUBUNIT_TYPE_DISC, 129 AVRCP_SUBUNIT_TYPE_TAPE_RECORDER_PLAYER, 130 AVRCP_SUBUNIT_TYPE_TUNER, 131 AVRCP_SUBUNIT_TYPE_CA, 132 AVRCP_SUBUNIT_TYPE_CAMERA, 133 AVRCP_SUBUNIT_TYPE_RESERVED, 134 AVRCP_SUBUNIT_TYPE_PANEL = 9, 135 AVRCP_SUBUNIT_TYPE_BULLETIN_BOARD, 136 AVRCP_SUBUNIT_TYPE_CAMERA_STORAGE, 137 AVRCP_SUBUNIT_TYPE_VENDOR_UNIQUE = 0x1C, 138 AVRCP_SUBUNIT_TYPE_RESERVED_FOR_ALL_SUBUNIT_TYPES, 139 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]. 140 // Further extension is possible when the value of extended_unit_type is FF16, in which case another byte will be added. 141 AVRCP_SUBUNIT_TYPE_UNIT = 0x1F 142 } avrcp_subunit_type_t; 143 144 typedef enum { 145 AVRCP_SUBUNIT_ID = 0, 146 AVRCP_SUBUNIT_ID_IGNORE = 7 147 } avrcp_subunit_id_t; 148 149 typedef enum { 150 AVRCP_CMD_OPCODE_VENDOR_DEPENDENT = 0x00, 151 // AVRCP_CMD_OPCODE_RESERVE = 0x01, 152 AVRCP_CMD_OPCODE_UNIT_INFO = 0x30, 153 // AVRCP_CMD_OPCODE_SUBUNIT_INFO = 0x31, 154 AVRCP_CMD_OPCODE_PASS_THROUGH = 0x7C, 155 // AVRCP_CMD_OPCODE_VERSION = 0xB0, 156 // AVRCP_CMD_OPCODE_POWER = 0xB2, 157 AVRCP_CMD_OPCODE_UNDEFINED = 0xFF 158 } avrcp_command_opcode_t; 159 160 typedef enum { 161 AVRCP_OPERATION_ID_SKIP = 0x3C, 162 AVRCP_OPERATION_ID_VOLUME_UP = 0x41, 163 AVRCP_OPERATION_ID_VOLUME_DOWN = 0x42, 164 AVRCP_OPERATION_ID_MUTE = 0x43, 165 166 AVRCP_OPERATION_ID_PLAY = 0x44, 167 AVRCP_OPERATION_ID_STOP = 0x45, 168 AVRCP_OPERATION_ID_PAUSE = 0x46, 169 AVRCP_OPERATION_ID_REWIND = 0x48, 170 AVRCP_OPERATION_ID_FAST_FORWARD = 0x49, 171 AVRCP_OPERATION_ID_FORWARD = 0x4B, 172 AVRCP_OPERATION_ID_BACKWARD = 0x4C, 173 AVRCP_OPERATION_ID_UNDEFINED = 0xFF 174 } avrcp_operation_id_t; 175 176 typedef enum { 177 AVCTP_CONNECTION_IDLE, 178 AVCTP_CONNECTION_W4_L2CAP_CONNECTED, 179 AVCTP_CONNECTION_OPENED, 180 AVCTP_W2_SEND_PRESS_COMMAND, 181 AVCTP_W2_SEND_RELEASE_COMMAND, 182 AVCTP_W4_STOP, 183 AVCTP_W2_SEND_COMMAND, 184 AVCTP_W2_RECEIVE_PRESS_RESPONSE, 185 AVCTP_W2_RECEIVE_RESPONSE 186 } avctp_connection_state_t; 187 188 typedef struct { 189 btstack_linked_item_t item; 190 bd_addr_t remote_addr; 191 uint16_t l2cap_signaling_cid; 192 193 avctp_connection_state_t state; 194 uint8_t wait_to_send; 195 196 // command 197 uint8_t transaction_label; 198 avrcp_command_opcode_t command_opcode; 199 avrcp_command_type_t command_type; 200 avrcp_subunit_type_t subunit_type; 201 avrcp_subunit_id_t subunit_id; 202 uint8_t cmd_operands[20]; 203 uint8_t cmd_operands_length; 204 btstack_timer_source_t press_and_hold_cmd_timer; 205 uint8_t continuous_fast_forward_cmd; 206 uint16_t notifications_enabled; 207 uint16_t notifications_to_register; 208 uint16_t notifications_to_deregister; 209 } avrcp_connection_t; 210 211 typedef enum { 212 AVRCP_PLAY_STATUS_STOPPED = 0x00, 213 AVRCP_PLAY_STATUS_PLAYING, 214 AVRCP_PLAY_STATUS_PAUSED, 215 AVRCP_PLAY_STATUS_FWD_SEEK, 216 AVRCP_PLAY_STATUS_REV_SEEK, 217 AVRCP_PLAY_STATUS_ERROR = 0xFF 218 } avrcp_play_status_t; 219 220 typedef enum { 221 AVRCP_SHUFFLE_MODE_INVALID, 222 AVRCP_SHUFFLE_MODE_OFF, 223 AVRCP_SHUFFLE_MODE_ALL_TRACKS, 224 AVRCP_SHUFFLE_MODE_GROUP 225 } avrcp_shuffle_mode_t; 226 227 typedef enum { 228 AVRCP_REPEAT_MODE_INVALID, 229 AVRCP_REPEAT_MODE_OFF, 230 AVRCP_REPEAT_MODE_SINGLE_TRACK, 231 AVRCP_REPEAT_MODE_ALL_TRACKS, 232 AVRCP_REPEAT_MODE_GROUP 233 } avrcp_repeat_mode_t; 234 235 /** 236 * @brief AVDTP Sink service record. 237 * @param service 238 * @param service_record_handle 239 * @param browsing 1 - supported, 0 - not supported 240 * @param supported_features 16-bit bitmap, see AVDTP_SINK_SF_* values in avdtp.h 241 * @param service_name 242 * @param service_provider_name 243 */ 244 void avrcp_controller_create_sdp_record(uint8_t * service, uint32_t service_record_handle, uint8_t browsing, uint16_t supported_features, const char * service_name, const char * service_provider_name); 245 246 /** 247 * @brief AVDTP Sink service record. 248 * @param service 249 * @param service_record_handle 250 * @param browsing 1 - supported, 0 - not supported 251 * @param supported_features 16-bit bitmap, see AVDTP_SINK_SF_* values in avdtp.h 252 * @param service_name 253 * @param service_provider_name 254 */ 255 void avrcp_target_create_sdp_record(uint8_t * service, uint32_t service_record_handle, uint8_t browsing, uint16_t supported_features, const char * service_name, const char * service_provider_name); 256 257 258 /** 259 * @brief Set up AVDTP Sink device. 260 */ 261 void avrcp_init(void); 262 263 /** 264 * @brief Register callback for the AVRCP Sink client. 265 * @param callback 266 */ 267 void avrcp_register_packet_handler(btstack_packet_handler_t callback); 268 269 /** 270 * @brief Connect to device with a Bluetooth address. 271 * @param bd_addr 272 * @param avrcp_cid 273 * @returns status 274 */ 275 uint8_t avrcp_connect(bd_addr_t bd_addr, uint16_t * avrcp_cid); 276 277 /** 278 * @brief Disconnect from AVRCP target 279 * @param avrcp_cid 280 * @returns status 281 */ 282 uint8_t avrcp_disconnect(uint16_t avrcp_cid); 283 284 /** 285 * @brief Unit info. 286 * @param avrcp_cid 287 * @returns status 288 */ 289 uint8_t avrcp_unit_info(uint16_t avrcp_cid); 290 291 /** 292 * @brief Get capabilities. 293 * @param avrcp_cid 294 * @returns status 295 */ 296 uint8_t avrcp_get_supported_company_ids(uint16_t avrcp_cid); 297 298 /** 299 * @brief Get supported Events. 300 * @param avrcp_cid 301 * @returns status 302 */ 303 uint8_t avrcp_get_supported_events(uint16_t avrcp_cid); 304 305 /** 306 * @brief Play. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 307 * @param avrcp_cid 308 * @returns status 309 */ 310 uint8_t avrcp_play(uint16_t avrcp_cid); 311 312 /** 313 * @brief Stop. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 314 * @param avrcp_cid 315 * @returns status 316 */ 317 uint8_t avrcp_stop(uint16_t avrcp_cid); 318 319 /** 320 * @brief Pause. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 321 * @param avrcp_cid 322 * @returns status 323 */ 324 uint8_t avrcp_pause(uint16_t avrcp_cid); 325 326 /** 327 * @brief Start Fast Forward. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 328 * @param avrcp_cid 329 * @returns status 330 */ 331 uint8_t avrcp_start_fast_forward(uint16_t avrcp_cid); 332 333 /** 334 * @brief Stop Fast Forward. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 335 * @param avrcp_cid 336 * @returns status 337 */ 338 uint8_t avrcp_stop_fast_forward(uint16_t avrcp_cid); 339 340 /** 341 * @brief Single step - fast forward. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 342 * @param avrcp_cid 343 * @returns status 344 */ 345 uint8_t avrcp_fast_forward(uint16_t avrcp_cid); 346 347 /** 348 * @brief Stop Rewind. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 349 * @param avrcp_cid 350 * @returns status 351 */ 352 uint8_t avrcp_start_rewind(uint16_t avrcp_cid); 353 354 /** 355 * @brief Stop Rewind. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 356 * @param avrcp_cid 357 * @returns status 358 */ 359 uint8_t avrcp_stop_rewind(uint16_t avrcp_cid); 360 361 /** 362 * @brief Single step rewind. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 363 * @param avrcp_cid 364 * @returns status 365 */ 366 uint8_t avrcp_rewind(uint16_t avrcp_cid); 367 368 /** 369 * @brief Forward. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 370 * @param avrcp_cid 371 * @returns status 372 */ 373 uint8_t avrcp_forward(uint16_t avrcp_cid); 374 375 /** 376 * @brief Backward. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 377 * @param avrcp_cid 378 * @returns status 379 */ 380 uint8_t avrcp_backward(uint16_t avrcp_cid); 381 382 383 /** 384 * @brief Get play status. Returns event of type AVRCP_SUBEVENT_PLAY_STATUS (length, position, play_status). 385 * If TG does not support SongLength And SongPosition on TG, then TG shall return 0xFFFFFFFF. 386 * @param avrcp_cid 387 * @returns status 388 */ 389 uint8_t avrcp_get_play_status(uint16_t avrcp_cid); 390 391 /** 392 * @brief Enable notification. Response via AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE. 393 * @param avrcp_cid 394 * @param event_id 395 * @returns status 396 */ 397 uint8_t avrcp_enable_notification(uint16_t avrcp_cid, avrcp_notification_event_id_t event_id); 398 399 /** 400 * @brief Disable notification. Response via AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE. 401 * @param avrcp_cid 402 * @param event_id 403 * @returns status 404 */ 405 uint8_t avrcp_disable_notification(uint16_t avrcp_cid, avrcp_notification_event_id_t event_id); 406 407 /** 408 * @brief Get info on now playing media. 409 * @param avrcp_cid 410 * @returns status 411 */ 412 uint8_t avrcp_get_now_playing_info(uint16_t avrcp_cid); 413 414 /** 415 * @brief Set absolute volume 0-127 (corresponds to 0-100%). Response via AVRCP_SUBEVENT_SET_ABSOLUTE_VOLUME_RESPONSE 416 * @param avrcp_cid 417 * @returns status 418 */ 419 uint8_t avrcp_set_absolute_volume(uint16_t avrcp_cid, uint8_t volume); 420 421 /** 422 * @brief Turns the volume to high. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 423 * @param avrcp_cid 424 * @returns status 425 */ 426 uint8_t avrcp_volume_up(uint16_t avrcp_cid); 427 428 /** 429 * @brief Turns the volume to low. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 430 * @param avrcp_cid 431 * @returns status 432 */ 433 uint8_t avrcp_volume_down(uint16_t avrcp_cid); 434 435 /** 436 * @brief Puts the sound out. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 437 * @param avrcp_cid 438 * @returns status 439 */ 440 uint8_t avrcp_mute(uint16_t avrcp_cid); 441 442 /** 443 * @brief Skip to next playing media. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 444 * @param avrcp_cid 445 * @returns status 446 */ 447 uint8_t avrcp_skip(uint16_t avrcp_cid); 448 449 /** 450 * @brief Query repeat and shuffle mode. Response via AVRCP_SUBEVENT_SHUFFLE_AND_REPEAT_MODE. 451 * @param avrcp_cid 452 * @returns status 453 */ 454 uint8_t avrcp_query_shuffle_and_repeat_modes(uint16_t avrcp_cid); 455 456 /** 457 * @brief Set shuffle mode. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 458 * @param avrcp_cid 459 * @returns status 460 */ 461 uint8_t avrcp_set_shuffle_mode(uint16_t avrcp_cid, avrcp_shuffle_mode_t mode); 462 463 /** 464 * @brief Set repeat mode. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 465 * @param avrcp_cid 466 * @returns status 467 */ 468 uint8_t avrcp_set_repeat_mode(uint16_t avrcp_cid, avrcp_repeat_mode_t mode); 469 470 const char * avrcp_subunit2str(uint16_t index); 471 const char * avrcp_event2str(uint16_t index); 472 const char * avrcp_operation2str(uint8_t index); 473 const char * avrcp_attribute2str(uint8_t index); 474 const char * avrcp_play_status2str(uint8_t index); 475 const char * avrcp_ctype2str(uint8_t index); 476 const char * avrcp_repeat2str(uint8_t index); 477 const char * avrcp_shuffle2str(uint8_t index); 478 479 /* API_END */ 480 #if defined __cplusplus 481 } 482 #endif 483 484 #endif // __AVRCP_H