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 58 typedef enum { 59 AVRCP_SINGLE_PACKET= 0, 60 AVRCP_START_PACKET , 61 AVRCP_CONTINUE_PACKET , 62 AVRCP_END_PACKET 63 } avrcp_packet_type_t; 64 65 typedef enum { 66 AVRCP_COMMAND_FRAME = 0, 67 AVRCP_RESPONSE_FRAME 68 } avrcp_frame_type_t; 69 70 71 typedef enum { 72 AVRCP_CAPABILITY_ID_COMPANY = 0x02, 73 AVRCP_CAPABILITY_ID_EVENT = 0x03 74 } avrcp_capability_id_t; 75 76 typedef enum { 77 AVRCP_MEDIA_ATTR_TITLE = 1, 78 AVRCP_MEDIA_ATTR_ARTIST, 79 AVRCP_MEDIA_ATTR_ALBUM, 80 AVRCP_MEDIA_ATTR_TRACK, 81 AVRCP_MEDIA_ATTR_TOTAL_TRACKS, 82 AVRCP_MEDIA_ATTR_GENRE, 83 AVRCP_MEDIA_ATTR_SONG_LENGTH 84 } avrcp_media_attribute_id_t; 85 86 #define AVRCP_MEDIA_ATTR_COUNT 7 87 88 typedef enum { 89 AVRCP_PDU_ID_GET_CAPABILITIES = 0x10, 90 AVRCP_PDU_ID_GetCurrentPlayerApplicationSettingValue = 0x13, 91 AVRCP_PDU_ID_SetPlayerApplicationSettingValue = 0x14, 92 AVRCP_PDU_ID_GET_ELEMENT_ATTRIBUTES = 0x20, 93 AVRCP_PDU_ID_GET_PLAY_STATUS = 0x30, 94 AVRCP_PDU_ID_REGISTER_NOTIFICATION = 0x31, 95 AVRCP_PDU_ID_SET_ABSOLUTE_VOLUME = 0x50 96 } avrcp_pdu_id_t; 97 98 typedef enum { 99 AVRCP_NOTIFICATION_EVENT_PLAYBACK_STATUS_CHANGED = 0x01, // Change in playback status of the current track. 100 AVRCP_NOTIFICATION_EVENT_TRACK_CHANGED = 0x02, // Change of current track 101 AVRCP_NOTIFICATION_EVENT_TRACK_REACHED_END = 0x03, // Reached end of a track 102 AVRCP_NOTIFICATION_EVENT_TRACK_REACHED_START = 0x04, // Reached start of a track 103 AVRCP_NOTIFICATION_EVENT_PLAYBACK_POS_CHANGED = 0x05, // Change in playback position. Returned after the specified playback notification change notification interval 104 AVRCP_NOTIFICATION_EVENT_BATT_STATUS_CHANGED = 0x06, // Change in battery status 105 AVRCP_NOTIFICATION_EVENT_SYSTEM_STATUS_CHANGED = 0x07, // Change in system status 106 AVRCP_NOTIFICATION_EVENT_PLAYER_APPLICATION_SETTING_CHANGED = 0x08, // Change in player application setting 107 AVRCP_NOTIFICATION_EVENT_NOW_PLAYING_CONTENT_CHANGED = 0x09, // The content of the Now Playing list has changed, see 6.9.5. 108 AVRCP_NOTIFICATION_EVENT_AVAILABLE_PLAYERS_CHANGED = 0x0a, // The available players have changed, see 6.9.4. 109 AVRCP_NOTIFICATION_EVENT_ADDRESSED_PLAYER_CHANGED = 0x0b, // The Addressed Player has been changed, see 6.9.2. 110 AVRCP_NOTIFICATION_EVENT_UIDS_CHANGED = 0x0c, // The UIDs have changed, see 6.10.3.3. 111 AVRCP_NOTIFICATION_EVENT_VOLUME_CHANGED = 0x0d // The volume has been changed locally on the TG, see 6.13.3. 112 } avrcp_notification_event_id_t; 113 114 typedef enum { 115 AVRCP_CTYPE_CONTROL = 0, 116 AVRCP_CTYPE_STATUS, 117 AVRCP_CTYPE_SPECIFIC_INQUIRY, 118 AVRCP_CTYPE_NOTIFY, 119 AVRCP_CTYPE_GENERAL_INQUIRY, 120 AVRCP_CTYPE_RESERVED5, 121 AVRCP_CTYPE_RESERVED6, 122 AVRCP_CTYPE_RESERVED7, 123 AVRCP_CTYPE_RESPONSE_NOT_IMPLEMENTED = 8, 124 AVRCP_CTYPE_RESPONSE_ACCEPTED, 125 AVRCP_CTYPE_RESPONSE_REJECTED, 126 AVRCP_CTYPE_RESPONSE_IN_TRANSITION, // target state is in transition. A subsequent STATUS command, may result in the return of a STABLE status 127 AVRCP_CTYPE_RESPONSE_IMPLEMENTED_STABLE, 128 AVRCP_CTYPE_RESPONSE_CHANGED_STABLE, 129 AVRCP_CTYPE_RESPONSE_RESERVED, 130 AVRCP_CTYPE_RESPONSE_INTERIM // target is unable to respond with either ACCEPTED or REJECTED within 100 millisecond 131 } avrcp_command_type_t; 132 133 // control command response: accepted, rejected, interim 134 // status command response: not implemented, rejected, in transiiton, stable 135 // notify command response: not implemented, rejected, changed 136 typedef enum { 137 AVRCP_SUBUNIT_TYPE_MONITOR = 0, 138 AVRCP_SUBUNIT_TYPE_AUDIO = 1, 139 AVRCP_SUBUNIT_TYPE_PRINTER, 140 AVRCP_SUBUNIT_TYPE_DISC, 141 AVRCP_SUBUNIT_TYPE_TAPE_RECORDER_PLAYER, 142 AVRCP_SUBUNIT_TYPE_TUNER, 143 AVRCP_SUBUNIT_TYPE_CA, 144 AVRCP_SUBUNIT_TYPE_CAMERA, 145 AVRCP_SUBUNIT_TYPE_RESERVED, 146 AVRCP_SUBUNIT_TYPE_PANEL = 9, 147 AVRCP_SUBUNIT_TYPE_BULLETIN_BOARD, 148 AVRCP_SUBUNIT_TYPE_CAMERA_STORAGE, 149 AVRCP_SUBUNIT_TYPE_VENDOR_UNIQUE = 0x1C, 150 AVRCP_SUBUNIT_TYPE_RESERVED_FOR_ALL_SUBUNIT_TYPES, 151 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]. 152 // Further extension is possible when the value of extended_unit_type is FF16, in which case another byte will be added. 153 AVRCP_SUBUNIT_TYPE_UNIT = 0x1F 154 } avrcp_subunit_type_t; 155 156 typedef enum { 157 AVRCP_SUBUNIT_ID = 0, 158 AVRCP_SUBUNIT_ID_IGNORE = 7 159 } avrcp_subunit_id_t; 160 161 typedef enum { 162 AVRCP_CMD_OPCODE_VENDOR_DEPENDENT = 0x00, 163 // AVRCP_CMD_OPCODE_RESERVE = 0x01, 164 AVRCP_CMD_OPCODE_UNIT_INFO = 0x30, 165 // AVRCP_CMD_OPCODE_SUBUNIT_INFO = 0x31, 166 AVRCP_CMD_OPCODE_PASS_THROUGH = 0x7C, 167 // AVRCP_CMD_OPCODE_VERSION = 0xB0, 168 // AVRCP_CMD_OPCODE_POWER = 0xB2, 169 AVRCP_CMD_OPCODE_UNDEFINED = 0xFF 170 } avrcp_command_opcode_t; 171 172 typedef enum { 173 AVRCP_OPERATION_ID_SKIP = 0x3C, 174 AVRCP_OPERATION_ID_VOLUME_UP = 0x41, 175 AVRCP_OPERATION_ID_VOLUME_DOWN = 0x42, 176 AVRCP_OPERATION_ID_MUTE = 0x43, 177 178 AVRCP_OPERATION_ID_PLAY = 0x44, 179 AVRCP_OPERATION_ID_STOP = 0x45, 180 AVRCP_OPERATION_ID_PAUSE = 0x46, 181 AVRCP_OPERATION_ID_REWIND = 0x48, 182 AVRCP_OPERATION_ID_FAST_FORWARD = 0x49, 183 AVRCP_OPERATION_ID_FORWARD = 0x4B, 184 AVRCP_OPERATION_ID_BACKWARD = 0x4C, 185 AVRCP_OPERATION_ID_UNDEFINED = 0xFF 186 } avrcp_operation_id_t; 187 188 typedef enum { 189 AVCTP_CONNECTION_IDLE, 190 AVCTP_SIGNALING_W4_SDP_QUERY_COMPLETE, 191 AVCTP_CONNECTION_W4_L2CAP_CONNECTED, 192 AVCTP_CONNECTION_OPENED, 193 AVCTP_W2_SEND_PRESS_COMMAND, 194 AVCTP_W2_SEND_RELEASE_COMMAND, 195 AVCTP_W4_STOP, 196 AVCTP_W2_SEND_COMMAND, 197 AVCTP_W2_RECEIVE_PRESS_RESPONSE, 198 AVCTP_W2_RECEIVE_RESPONSE 199 } avctp_connection_state_t; 200 201 typedef struct { 202 btstack_linked_item_t item; 203 bd_addr_t remote_addr; 204 uint16_t l2cap_signaling_cid; 205 uint16_t avrcp_cid; 206 207 avctp_connection_state_t state; 208 uint8_t wait_to_send; 209 210 // command 211 uint8_t transaction_label; 212 avrcp_command_opcode_t command_opcode; 213 avrcp_command_type_t command_type; 214 avrcp_subunit_type_t subunit_type; 215 avrcp_subunit_id_t subunit_id; 216 uint8_t cmd_operands[20]; 217 uint8_t cmd_operands_length; 218 btstack_timer_source_t press_and_hold_cmd_timer; 219 uint8_t continuous_fast_forward_cmd; 220 uint16_t notifications_enabled; 221 uint16_t notifications_to_register; 222 uint16_t notifications_to_deregister; 223 } avrcp_connection_t; 224 225 typedef enum { 226 AVRCP_PLAY_STATUS_STOPPED = 0x00, 227 AVRCP_PLAY_STATUS_PLAYING, 228 AVRCP_PLAY_STATUS_PAUSED, 229 AVRCP_PLAY_STATUS_FWD_SEEK, 230 AVRCP_PLAY_STATUS_REV_SEEK, 231 AVRCP_PLAY_STATUS_ERROR = 0xFF 232 } avrcp_play_status_t; 233 234 typedef enum { 235 AVRCP_SHUFFLE_MODE_INVALID, 236 AVRCP_SHUFFLE_MODE_OFF, 237 AVRCP_SHUFFLE_MODE_ALL_TRACKS, 238 AVRCP_SHUFFLE_MODE_GROUP 239 } avrcp_shuffle_mode_t; 240 241 typedef enum { 242 AVRCP_REPEAT_MODE_INVALID, 243 AVRCP_REPEAT_MODE_OFF, 244 AVRCP_REPEAT_MODE_SINGLE_TRACK, 245 AVRCP_REPEAT_MODE_ALL_TRACKS, 246 AVRCP_REPEAT_MODE_GROUP 247 } avrcp_repeat_mode_t; 248 249 typedef enum{ 250 AVRCP_CONTROLLER = 0, 251 AVRCP_TARGET 252 } avrcp_role_t; 253 254 typedef struct { 255 avrcp_role_t role; 256 btstack_linked_list_t connections; 257 btstack_packet_handler_t avrcp_callback; 258 btstack_packet_handler_t packet_handler; 259 260 // SDP query 261 uint16_t avrcp_cid; 262 uint16_t avrcp_l2cap_psm; 263 uint16_t avrcp_version; 264 uint16_t avrcp_browsing_l2cap_psm; 265 uint16_t avrcp_browsing_version; 266 uint8_t role_supported; 267 } avrcp_context_t; 268 269 const char * avrcp_subunit2str(uint16_t index); 270 const char * avrcp_event2str(uint16_t index); 271 const char * avrcp_operation2str(uint8_t index); 272 const char * avrcp_attribute2str(uint8_t index); 273 const char * avrcp_play_status2str(uint8_t index); 274 const char * avrcp_ctype2str(uint8_t index); 275 const char * avrcp_repeat2str(uint8_t index); 276 const char * avrcp_shuffle2str(uint8_t index); 277 278 void avrcp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size, avrcp_context_t * context); 279 280 void avrcp_create_sdp_record(uint8_t controller, uint8_t * service, uint32_t service_record_handle, uint8_t browsing, uint16_t supported_features, const char * service_name, const char * service_provider_name); 281 uint8_t avrcp_connect(bd_addr_t bd_addr, avrcp_context_t * context, uint16_t * avrcp_cid); 282 void avrcp_emit_connection_established(btstack_packet_handler_t callback, uint16_t avrcp_cid, bd_addr_t addr, uint8_t status); 283 void avrcp_emit_connection_closed(btstack_packet_handler_t callback, uint16_t avrcp_cid); 284 285 avrcp_connection_t * get_avrcp_connection_for_l2cap_signaling_cid(uint16_t l2cap_cid, avrcp_context_t * context); 286 avrcp_connection_t * get_avrcp_connection_for_avrcp_cid(uint16_t avrcp_cid, avrcp_context_t * context); 287 void avrcp_request_can_send_now(avrcp_connection_t * connection, uint16_t l2cap_cid); 288 289 #if defined __cplusplus 290 } 291 #endif 292 293 #endif // __AVRCP_H