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_SIGNALING_W4_SDP_QUERY_COMPLETE, 179 AVCTP_CONNECTION_W4_L2CAP_CONNECTED, 180 AVCTP_CONNECTION_OPENED, 181 AVCTP_W2_SEND_PRESS_COMMAND, 182 AVCTP_W2_SEND_RELEASE_COMMAND, 183 AVCTP_W4_STOP, 184 AVCTP_W2_SEND_COMMAND, 185 AVCTP_W2_RECEIVE_PRESS_RESPONSE, 186 AVCTP_W2_RECEIVE_RESPONSE 187 } avctp_connection_state_t; 188 189 typedef struct { 190 btstack_linked_item_t item; 191 bd_addr_t remote_addr; 192 uint16_t l2cap_signaling_cid; 193 uint16_t avrcp_cid; 194 195 avctp_connection_state_t state; 196 uint8_t wait_to_send; 197 198 // command 199 uint8_t transaction_label; 200 avrcp_command_opcode_t command_opcode; 201 avrcp_command_type_t command_type; 202 avrcp_subunit_type_t subunit_type; 203 avrcp_subunit_id_t subunit_id; 204 uint8_t cmd_operands[20]; 205 uint8_t cmd_operands_length; 206 btstack_timer_source_t press_and_hold_cmd_timer; 207 uint8_t continuous_fast_forward_cmd; 208 uint16_t notifications_enabled; 209 uint16_t notifications_to_register; 210 uint16_t notifications_to_deregister; 211 } avrcp_connection_t; 212 213 typedef enum { 214 AVRCP_PLAY_STATUS_STOPPED = 0x00, 215 AVRCP_PLAY_STATUS_PLAYING, 216 AVRCP_PLAY_STATUS_PAUSED, 217 AVRCP_PLAY_STATUS_FWD_SEEK, 218 AVRCP_PLAY_STATUS_REV_SEEK, 219 AVRCP_PLAY_STATUS_ERROR = 0xFF 220 } avrcp_play_status_t; 221 222 typedef enum { 223 AVRCP_SHUFFLE_MODE_INVALID, 224 AVRCP_SHUFFLE_MODE_OFF, 225 AVRCP_SHUFFLE_MODE_ALL_TRACKS, 226 AVRCP_SHUFFLE_MODE_GROUP 227 } avrcp_shuffle_mode_t; 228 229 typedef enum { 230 AVRCP_REPEAT_MODE_INVALID, 231 AVRCP_REPEAT_MODE_OFF, 232 AVRCP_REPEAT_MODE_SINGLE_TRACK, 233 AVRCP_REPEAT_MODE_ALL_TRACKS, 234 AVRCP_REPEAT_MODE_GROUP 235 } avrcp_repeat_mode_t; 236 237 typedef enum{ 238 AVRCP_CONTROLLER = 0, 239 AVRCP_TARGET 240 } avrcp_role_t; 241 242 typedef struct { 243 avrcp_role_t role; 244 btstack_linked_list_t connections; 245 btstack_packet_handler_t avrcp_callback; 246 btstack_packet_handler_t packet_handler; 247 } avrcp_context_t; 248 249 typedef struct { 250 avrcp_connection_t * connection; 251 avrcp_context_t * avrcp_context; 252 uint16_t avrcp_l2cap_psm; 253 uint16_t avrcp_version; 254 uint8_t role_supported; 255 } avrcp_sdp_query_context_t; 256 257 258 /** 259 * @brief AVDTP Sink service record. 260 * @param service 261 * @param service_record_handle 262 * @param browsing 1 - supported, 0 - not supported 263 * @param supported_features 16-bit bitmap, see AVDTP_SINK_SF_* values in avdtp.h 264 * @param service_name 265 * @param service_provider_name 266 */ 267 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); 268 269 /** 270 * @brief AVDTP Sink service record. 271 * @param service 272 * @param service_record_handle 273 * @param browsing 1 - supported, 0 - not supported 274 * @param supported_features 16-bit bitmap, see AVDTP_SINK_SF_* values in avdtp.h 275 * @param service_name 276 * @param service_provider_name 277 */ 278 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); 279 280 281 /** 282 * @brief Set up AVDTP Sink device. 283 */ 284 void avrcp_controller_init(void); 285 286 /** 287 * @brief Register callback for the AVRCP Sink client. 288 * @param callback 289 */ 290 void avrcp_register_packet_handler(btstack_packet_handler_t callback); 291 292 /** 293 * @brief Connect to device with a Bluetooth address. 294 * @param bd_addr 295 * @param avrcp_cid 296 * @returns status 297 */ 298 299 300 uint8_t avrcp_connect(bd_addr_t bd_addr, avrcp_context_t * context, uint16_t * avrcp_cid); 301 uint8_t avrcp_controller_connect(bd_addr_t bd_addr, uint16_t * avrcp_cid); 302 303 /** 304 * @brief Disconnect from AVRCP target 305 * @param avrcp_cid 306 * @returns status 307 */ 308 uint8_t avrcp_disconnect(uint16_t avrcp_cid); 309 310 /** 311 * @brief Unit info. 312 * @param avrcp_cid 313 * @returns status 314 */ 315 uint8_t avrcp_unit_info(uint16_t avrcp_cid); 316 317 /** 318 * @brief Get capabilities. 319 * @param avrcp_cid 320 * @returns status 321 */ 322 uint8_t avrcp_get_supported_company_ids(uint16_t avrcp_cid); 323 324 /** 325 * @brief Get supported Events. 326 * @param avrcp_cid 327 * @returns status 328 */ 329 uint8_t avrcp_get_supported_events(uint16_t avrcp_cid); 330 331 /** 332 * @brief Play. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 333 * @param avrcp_cid 334 * @returns status 335 */ 336 uint8_t avrcp_play(uint16_t avrcp_cid); 337 338 /** 339 * @brief Stop. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 340 * @param avrcp_cid 341 * @returns status 342 */ 343 uint8_t avrcp_stop(uint16_t avrcp_cid); 344 345 /** 346 * @brief Pause. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 347 * @param avrcp_cid 348 * @returns status 349 */ 350 uint8_t avrcp_pause(uint16_t avrcp_cid); 351 352 /** 353 * @brief Start Fast Forward. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 354 * @param avrcp_cid 355 * @returns status 356 */ 357 uint8_t avrcp_start_fast_forward(uint16_t avrcp_cid); 358 359 /** 360 * @brief Stop Fast Forward. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 361 * @param avrcp_cid 362 * @returns status 363 */ 364 uint8_t avrcp_stop_fast_forward(uint16_t avrcp_cid); 365 366 /** 367 * @brief Single step - fast forward. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 368 * @param avrcp_cid 369 * @returns status 370 */ 371 uint8_t avrcp_fast_forward(uint16_t avrcp_cid); 372 373 /** 374 * @brief Stop Rewind. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 375 * @param avrcp_cid 376 * @returns status 377 */ 378 uint8_t avrcp_start_rewind(uint16_t avrcp_cid); 379 380 /** 381 * @brief Stop Rewind. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 382 * @param avrcp_cid 383 * @returns status 384 */ 385 uint8_t avrcp_stop_rewind(uint16_t avrcp_cid); 386 387 /** 388 * @brief Single step rewind. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 389 * @param avrcp_cid 390 * @returns status 391 */ 392 uint8_t avrcp_rewind(uint16_t avrcp_cid); 393 394 /** 395 * @brief Forward. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 396 * @param avrcp_cid 397 * @returns status 398 */ 399 uint8_t avrcp_forward(uint16_t avrcp_cid); 400 401 /** 402 * @brief Backward. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 403 * @param avrcp_cid 404 * @returns status 405 */ 406 uint8_t avrcp_backward(uint16_t avrcp_cid); 407 408 409 /** 410 * @brief Get play status. Returns event of type AVRCP_SUBEVENT_PLAY_STATUS (length, position, play_status). 411 * If TG does not support SongLength And SongPosition on TG, then TG shall return 0xFFFFFFFF. 412 * @param avrcp_cid 413 * @returns status 414 */ 415 uint8_t avrcp_get_play_status(uint16_t avrcp_cid); 416 417 /** 418 * @brief Enable notification. Response via AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE. 419 * @param avrcp_cid 420 * @param event_id 421 * @returns status 422 */ 423 uint8_t avrcp_enable_notification(uint16_t avrcp_cid, avrcp_notification_event_id_t event_id); 424 425 /** 426 * @brief Disable notification. Response via AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE. 427 * @param avrcp_cid 428 * @param event_id 429 * @returns status 430 */ 431 uint8_t avrcp_disable_notification(uint16_t avrcp_cid, avrcp_notification_event_id_t event_id); 432 433 /** 434 * @brief Get info on now playing media. 435 * @param avrcp_cid 436 * @returns status 437 */ 438 uint8_t avrcp_get_now_playing_info(uint16_t avrcp_cid); 439 440 /** 441 * @brief Set absolute volume 0-127 (corresponds to 0-100%). Response via AVRCP_SUBEVENT_SET_ABSOLUTE_VOLUME_RESPONSE 442 * @param avrcp_cid 443 * @returns status 444 */ 445 uint8_t avrcp_set_absolute_volume(uint16_t avrcp_cid, uint8_t volume); 446 447 /** 448 * @brief Turns the volume to high. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 449 * @param avrcp_cid 450 * @returns status 451 */ 452 uint8_t avrcp_volume_up(uint16_t avrcp_cid); 453 454 /** 455 * @brief Turns the volume to low. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 456 * @param avrcp_cid 457 * @returns status 458 */ 459 uint8_t avrcp_volume_down(uint16_t avrcp_cid); 460 461 /** 462 * @brief Puts the sound out. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 463 * @param avrcp_cid 464 * @returns status 465 */ 466 uint8_t avrcp_mute(uint16_t avrcp_cid); 467 468 /** 469 * @brief Skip to next playing media. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 470 * @param avrcp_cid 471 * @returns status 472 */ 473 uint8_t avrcp_skip(uint16_t avrcp_cid); 474 475 /** 476 * @brief Query repeat and shuffle mode. Response via AVRCP_SUBEVENT_SHUFFLE_AND_REPEAT_MODE. 477 * @param avrcp_cid 478 * @returns status 479 */ 480 uint8_t avrcp_query_shuffle_and_repeat_modes(uint16_t avrcp_cid); 481 482 /** 483 * @brief Set shuffle mode. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 484 * @param avrcp_cid 485 * @returns status 486 */ 487 uint8_t avrcp_set_shuffle_mode(uint16_t avrcp_cid, avrcp_shuffle_mode_t mode); 488 489 /** 490 * @brief Set repeat mode. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 491 * @param avrcp_cid 492 * @returns status 493 */ 494 uint8_t avrcp_set_repeat_mode(uint16_t avrcp_cid, avrcp_repeat_mode_t mode); 495 496 const char * avrcp_subunit2str(uint16_t index); 497 const char * avrcp_event2str(uint16_t index); 498 const char * avrcp_operation2str(uint8_t index); 499 const char * avrcp_attribute2str(uint8_t index); 500 const char * avrcp_play_status2str(uint8_t index); 501 const char * avrcp_ctype2str(uint8_t index); 502 const char * avrcp_repeat2str(uint8_t index); 503 const char * avrcp_shuffle2str(uint8_t index); 504 505 /* API_END */ 506 #if defined __cplusplus 507 } 508 #endif 509 510 #endif // __AVRCP_H