xref: /btstack/src/classic/avrcp.h (revision f9f2075ceac5e9dc08e9abea437e43d733a3a0ea)
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 
50 #if defined __cplusplus
51 extern "C" {
52 #endif
53 
54 #define BT_SIG_COMPANY_ID 0x001958
55 /* API_START */
56 
57 typedef enum {
58     AVRCP_CAPABILITY_ID_COMPANY = 0x02,
59     AVRCP_CAPABILITY_ID_EVENT = 0x03
60 } avrcp_capability_id_t;
61 
62 typedef enum {
63     AVRCP_MEDIA_ATTR_TITLE = 1,
64     AVRCP_MEDIA_ATTR_ARTIST,
65     AVRCP_MEDIA_ATTR_ALBUM,
66     AVRCP_MEDIA_ATTR_TRACK,
67     AVRCP_MEDIA_ATTR_TOTAL_TRACKS,
68     AVRCP_MEDIA_ATTR_GENRE,
69     AVRCP_MEDIA_ATTR_SONG_LENGTH
70 } avrcp_media_attribute_id_t;
71 
72 #define AVRCP_MEDIA_ATTR_COUNT 7
73 
74 typedef enum {
75     AVRCP_PDU_ID_GET_CAPABILITIES = 0x10,
76     AVRCP_PDU_ID_GetCurrentPlayerApplicationSettingValue = 0x13,
77     AVRCP_PDU_ID_SetPlayerApplicationSettingValue = 0x14,
78     AVRCP_PDU_ID_GET_ELEMENT_ATTRIBUTES = 0x20,
79     AVRCP_PDU_ID_GET_PLAY_STATUS = 0x30,
80     AVRCP_PDU_ID_REGISTER_NOTIFICATION = 0x31,
81     AVRCP_PDU_ID_SET_ABSOLUTE_VOLUME = 0x50
82 } avrcp_pdu_id_t;
83 
84 typedef enum {
85     AVRCP_NOTIFICATION_EVENT_PLAYBACK_STATUS_CHANGED = 0x01,            // Change in playback status of the current track.
86     AVRCP_NOTIFICATION_EVENT_TRACK_CHANGED = 0x02,                      // Change of current track
87     AVRCP_NOTIFICATION_EVENT_TRACK_REACHED_END = 0x03,                  // Reached end of a track
88     AVRCP_NOTIFICATION_EVENT_TRACK_REACHED_START = 0x04,                // Reached start of a track
89     AVRCP_NOTIFICATION_EVENT_PLAYBACK_POS_CHANGED = 0x05,               // Change in playback position. Returned after the specified playback notification change notification interval
90     AVRCP_NOTIFICATION_EVENT_BATT_STATUS_CHANGED = 0x06,                // Change in battery status
91     AVRCP_NOTIFICATION_EVENT_SYSTEM_STATUS_CHANGED = 0x07,              // Change in system status
92     AVRCP_NOTIFICATION_EVENT_PLAYER_APPLICATION_SETTING_CHANGED = 0x08, // Change in player application setting
93     AVRCP_NOTIFICATION_EVENT_NOW_PLAYING_CONTENT_CHANGED = 0x09,        // The content of the Now Playing list has changed, see 6.9.5.
94     AVRCP_NOTIFICATION_EVENT_AVAILABLE_PLAYERS_CHANGED = 0x0a,          // The available players have changed, see 6.9.4.
95     AVRCP_NOTIFICATION_EVENT_ADDRESSED_PLAYER_CHANGED = 0x0b,           // The Addressed Player has been changed, see 6.9.2.
96     AVRCP_NOTIFICATION_EVENT_UIDS_CHANGED = 0x0c,                       // The UIDs have changed, see 6.10.3.3.
97     AVRCP_NOTIFICATION_EVENT_VOLUME_CHANGED = 0x0d                      // The volume has been changed locally on the TG, see 6.13.3.
98 } avrcp_notification_event_id_t;
99 
100 typedef enum {
101     AVRCP_CTYPE_CONTROL = 0,
102     AVRCP_CTYPE_STATUS,
103     AVRCP_CTYPE_SPECIFIC_INQUIRY,
104     AVRCP_CTYPE_NOTIFY,
105     AVRCP_CTYPE_GENERAL_INQUIRY,
106     AVRCP_CTYPE_RESERVED5,
107     AVRCP_CTYPE_RESERVED6,
108     AVRCP_CTYPE_RESERVED7,
109     AVRCP_CTYPE_RESPONSE_NOT_IMPLEMENTED = 8,
110     AVRCP_CTYPE_RESPONSE_ACCEPTED,
111     AVRCP_CTYPE_RESPONSE_REJECTED,
112     AVRCP_CTYPE_RESPONSE_IN_TRANSITION, // target state is in transition. A subsequent STATUS command, may result in the return of a STABLE status
113     AVRCP_CTYPE_RESPONSE_IMPLEMENTED_STABLE,
114     AVRCP_CTYPE_RESPONSE_CHANGED_STABLE,
115     AVRCP_CTYPE_RESPONSE_RESERVED,
116     AVRCP_CTYPE_RESPONSE_INTERIM            // target is unable to respond with either ACCEPTED or REJECTED within 100 millisecond
117 } avrcp_command_type_t;
118 
119 // control command response: accepted, rejected, interim
120 // status command response: not implemented, rejected, in transiiton, stable
121 // notify command response: not implemented, rejected, changed
122 typedef enum {
123     AVRCP_SUBUNIT_TYPE_MONITOR = 0,
124     AVRCP_SUBUNIT_TYPE_AUDIO = 1,
125     AVRCP_SUBUNIT_TYPE_PRINTER,
126     AVRCP_SUBUNIT_TYPE_DISC,
127     AVRCP_SUBUNIT_TYPE_TAPE_RECORDER_PLAYER,
128     AVRCP_SUBUNIT_TYPE_TUNER,
129     AVRCP_SUBUNIT_TYPE_CA,
130     AVRCP_SUBUNIT_TYPE_CAMERA,
131     AVRCP_SUBUNIT_TYPE_RESERVED,
132     AVRCP_SUBUNIT_TYPE_PANEL = 9,
133     AVRCP_SUBUNIT_TYPE_BULLETIN_BOARD,
134     AVRCP_SUBUNIT_TYPE_CAMERA_STORAGE,
135     AVRCP_SUBUNIT_TYPE_VENDOR_UNIQUE = 0x1C,
136     AVRCP_SUBUNIT_TYPE_RESERVED_FOR_ALL_SUBUNIT_TYPES,
137     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].
138                                               // Further extension is possible when the value of extended_unit_type is FF16, in which case another byte will be added.
139     AVRCP_SUBUNIT_TYPE_UNIT = 0x1F
140 } avrcp_subunit_type_t;
141 
142 typedef enum {
143     AVRCP_SUBUNIT_ID = 0,
144     AVRCP_SUBUNIT_ID_IGNORE = 7
145 } avrcp_subunit_id_t;
146 
147 typedef enum {
148     AVRCP_CMD_OPCODE_VENDOR_DEPENDENT = 0x00,
149     AVRCP_CMD_OPCODE_RESERVE = 0x01,
150     AVRCP_CMD_OPCODE_UNIT_INFO = 0x30,
151     AVRCP_CMD_OPCODE_SUBUNIT_INFO = 0x31,
152     AVRCP_CMD_OPCODE_PASS_THROUGH = 0x7C,
153     AVRCP_CMD_OPCODE_VERSION = 0xB0,
154     AVRCP_CMD_OPCODE_POWER = 0xB2
155 } avrcp_command_opcode_t;
156 
157 typedef enum {
158     AVRCP_OPERATION_ID_SKIP = 0x3C,
159     AVRCP_OPERATION_ID_VOLUME_UP = 0x41,
160     AVRCP_OPERATION_ID_VOLUME_DOWN = 0x42,
161     AVRCP_OPERATION_ID_MUTE = 0x43,
162 
163     AVRCP_OPERATION_ID_PLAY = 0x44,
164     AVRCP_OPERATION_ID_STOP = 0x45,
165     AVRCP_OPERATION_ID_PAUSE = 0x46,
166     AVRCP_OPERATION_ID_REWIND = 0x48,
167     AVRCP_OPERATION_ID_FAST_FORWARD = 0x49,
168     AVRCP_OPERATION_ID_FORWARD = 0x4B,
169     AVRCP_OPERATION_ID_BACKWARD = 0x4C
170 } avrcp_operation_id_t;
171 
172 typedef enum {
173     AVCTP_CONNECTION_IDLE,
174     AVCTP_CONNECTION_W4_L2CAP_CONNECTED,
175     AVCTP_CONNECTION_OPENED,
176     AVCTP_W2_SEND_PRESS_COMMAND,
177     AVCTP_W2_SEND_RELEASE_COMMAND,
178     AVCTP_W4_STOP,
179     AVCTP_W2_SEND_COMMAND,
180     AVCTP_W2_RECEIVE_PRESS_RESPONSE,
181     AVCTP_W2_RECEIVE_RESPONSE,
182     AVCTP_CONNECTION_W4_L2CAP_DISCONNECTED
183 } avctp_connection_state_t;
184 
185 typedef struct {
186     btstack_linked_item_t    item;
187     bd_addr_t remote_addr;
188     hci_con_handle_t con_handle;
189     uint16_t l2cap_signaling_cid;
190 
191     avctp_connection_state_t state;
192     uint8_t wait_to_send;
193 
194     // command
195     uint8_t transaction_label;
196     avrcp_command_opcode_t cmd_to_send;
197     avrcp_command_type_t command_type;
198     avrcp_subunit_type_t subunit_type;
199     avrcp_subunit_id_t   subunit_id;
200     uint8_t cmd_operands[20];
201     uint8_t cmd_operands_lenght;
202     btstack_timer_source_t press_and_hold_cmd_timer;
203 
204     uint16_t notifications_enabled;
205     uint16_t notifications_to_register;
206     uint16_t notifications_to_deregister;
207 
208     uint8_t disconnect;
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_OFF = 0x01,
222     AVRCP_SHUFFLE_MODE_ALL_TRACKS,
223     AVRCP_SHUFFLE_MODE_GROUP
224 } avrcp_shuffle_mode_t;
225 
226 typedef enum {
227     AVRCP_REPEAT_MODE_OFF = 0x01,
228     AVRCP_REPEAT_MODE_SINGLE_TRACK,
229     AVRCP_REPEAT_MODE_ALL_TRACKS,
230     AVRCP_REPEAT_MODE_GROUP
231 } avrcp_repeat_mode_t;
232 
233 /**
234  * @brief AVDTP Sink service record.
235  * @param service
236  * @param service_record_handle
237  * @param browsing  1 - supported, 0 - not supported
238  * @param supported_features 16-bit bitmap, see AVDTP_SINK_SF_* values in avdtp.h
239  * @param service_name
240  * @param service_provider_name
241  */
242 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);
243 
244 /**
245  * @brief AVDTP Sink service record.
246  * @param service
247  * @param service_record_handle
248  * @param browsing  1 - supported, 0 - not supported
249  * @param supported_features 16-bit bitmap, see AVDTP_SINK_SF_* values in avdtp.h
250  * @param service_name
251  * @param service_provider_name
252  */
253 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);
254 
255 
256 /**
257  * @brief Set up AVDTP Sink device.
258  */
259 void avrcp_init(void);
260 
261 /**
262  * @brief Register callback for the AVDTP Sink client.
263  * @param callback
264  */
265 void avrcp_register_packet_handler(btstack_packet_handler_t callback);
266 
267 /**
268  * @brief Connect to device with a bluetooth address.
269  * @param bd_addr
270  */
271 void avrcp_connect(bd_addr_t bd_addr);
272 void avrcp_disconnect(uint16_t con_handle);
273 /**
274  * @brief Unit info.
275  * @param con_handle
276  */
277 void avrcp_unit_info(uint16_t con_handle);
278 
279 /**
280  * @brief Get capabilities.
281  * @param con_handle
282  */
283 void avrcp_get_supported_company_ids(uint16_t con_handle);
284 void avrcp_get_supported_events(uint16_t con_handle);
285 
286 
287 /**
288  * @brief Play. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
289  * @param con_handle
290  */
291 void avrcp_play(uint16_t con_handle);
292 
293 /**
294  * @brief Stop. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
295  * @param con_handle
296  */
297 void avrcp_stop(uint16_t con_handle);
298 
299 /**
300  * @brief Pause. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
301  * @param con_handle
302  */
303 void avrcp_pause(uint16_t con_handle);
304 
305 /**
306  * @brief Fast forward. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
307  * @param con_handle
308  */
309 void avrcp_start_fast_forward(uint16_t con_handle);
310 void avrcp_stop_fast_forward(uint16_t con_handle);
311 
312 /**
313  * @brief Rewind. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
314  * @param con_handle
315  */
316 void avrcp_start_rewind(uint16_t con_handle);
317 void avrcp_stop_rewind(uint16_t con_handle);
318 
319 /**
320  * @brief Forward. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
321  * @param con_handle
322  */
323 void avrcp_forward(uint16_t con_handle);
324 
325 /**
326  * @brief Backward. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
327  * @param con_handle
328  */
329 void avrcp_backward(uint16_t con_handle);
330 
331 
332 /**
333  * @brief Get play status. Returns event of type AVRCP_SUBEVENT_PLAY_STATUS (length, position, play_status).
334  * If TG does not support SongLength And SongPosition on TG, then TG shall return 0xFFFFFFFF.
335  * @param con_handle
336  */
337 void avrcp_get_play_status(uint16_t con_handle);
338 
339 /**
340  * @brief Register notification. Response via AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE.
341  * @param con_handle
342  * @param event_id
343  */
344 void avrcp_enable_notification(uint16_t con_handle, avrcp_notification_event_id_t event_id);
345 void avrcp_disable_notification(uint16_t con_handle, avrcp_notification_event_id_t event_id);
346 
347 /**
348  * @brief Get info on now playing media.
349  * @param con_handle
350  */
351 void avrcp_get_now_playing_info(uint16_t con_handle);
352 
353 /**
354  * @brief Set absolute volume 0-127 (corresponds to 0-100%). Response via AVRCP_SUBEVENT_SET_ABSOLUTE_VOLUME_RESPONSE
355  * @param con_handle
356  */
357 void avrcp_set_absolute_volume(uint16_t con_handle, uint8_t volume);
358 
359 /**
360  * @brief Turns the volume to high. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
361  * @param con_handle
362  */
363 void avrcp_volume_up(uint16_t con_handle);
364 
365 /**
366  * @brief Turns the volume to low. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
367  * @param con_handle
368  */
369 void avrcp_volume_down(uint16_t con_handle);
370 
371 /**
372  * @brief Puts the sound out. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
373  * @param con_handle
374  */
375 void avrcp_mute(uint16_t con_handle);
376 
377 /**
378  * @brief Skip to next playing media. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
379  * @param con_handle
380  */
381 void avrcp_skip(uint16_t con_handle);
382 
383 /**
384  * @brief Query repeat and shuffle mode. Response via AVRCP_SUBEVENT_SHUFFLE_AND_REPEAT_MODE.
385  * @param con_handle
386  */
387 void avrcp_query_shuffle_and_repeat_modes(uint16_t con_handle);
388 
389 /**
390  * @brief Set shuffle mode. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
391  * @param con_handle
392  */
393 void avrcp_set_shuffle_mode(uint16_t con_handle, avrcp_shuffle_mode_t mode);
394 
395 /**
396  * @brief Set repeat mode. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
397  * @param con_handle
398  */
399 void avrcp_set_repeat_mode(uint16_t con_handle, avrcp_repeat_mode_t mode);
400 
401 const char * avrcp_subunit2str(uint16_t index);
402 const char * avrcp_event2str(uint16_t index);
403 const char * avrcp_operation2str(uint8_t index);
404 const char * avrcp_attribute2str(uint8_t index);
405 const char * avrcp_play_status2str(uint8_t index);
406 const char * avrcp_ctype2str(uint8_t index);
407 const char * avrcp_repeat2str(uint8_t index);
408 const char * avrcp_shuffle2str(uint8_t index);
409 
410 /* API_END */
411 #if defined __cplusplus
412 }
413 #endif
414 
415 #endif // __AVRCP_H