xref: /btstack/src/classic/avrcp.h (revision e9c5f44ee8add45f6cd4be8b6faa9e09a2804fcc)
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 #include "l2cap.h"
52 
53 #if defined __cplusplus
54 extern "C" {
55 #endif
56 
57 #define BT_SIG_COMPANY_ID 0x001958
58 #define AVRCP_MEDIA_ATTR_COUNT 7
59 #define AVRCP_MAX_ATTRIBUTTE_SIZE 100
60 #define AVRCP_ATTRIBUTE_HEADER_LEN  8
61 #define AVRCP_MAX_FOLDER_NAME_SIZE      20
62 
63 #define AVRCP_NO_TRACK_SELECTED_PLAYBACK_POSITION_CHANGED    0xFFFFFFFF
64 // #define AVRCP_NO_TRACK_SELECTED_TRACK_CHANGED                0xFFFFFFFFFFFFFFFF
65 
66 typedef enum {
67     AVRCP_STATUS_INVALID_COMMAND = 0,           // sent if TG received a PDU that it did not understand.
68     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.
69     AVRCP_STATUS_SPECIFIED_PARAMETER_NOT_FOUND, // sent if the parameter ID is understood, but content is wrong or corrupted.
70     AVRCP_STATUS_INTERNAL_ERROR,                // sent if there are error conditions not covered by a more specific error code.
71     AVRCP_STATUS_SUCCESS,                       // sent if the operation was successful.
72     AVRCP_STATUS_UID_CHANGED,                   // sent if the UIDs on the device have changed.
73     AVRCP_STATUS_RESERVED_6,
74     AVRCP_STATUS_INVALID_DIRECTION,             // The Direction parameter is invalid. Valid for command: Change Path
75     AVRCP_STATUS_NOT_A_DIRECTORY,               // The UID provided does not refer to a folder item. Valid for command: Change Path
76     AVRCP_STATUS_DOES_NOT_EXIST,                // The UID provided does not refer to any currently valid. Valid for command: Change Path, PlayItem, AddToNowPlaying, GetItemAttributes
77     AVRCP_STATUS_INVALID_SCOPE,                 // The scope parameter is invalid. Valid for command: GetFolderItems, PlayItem, AddToNowPlayer, GetItemAttributes,
78     AVRCP_STATUS_RANGE_OUT_OF_BOUNDS,           // The start of range provided is not valid. Valid for command: GetFolderItems
79     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
80     AVRCP_STATUS_MEDIA_IN_USE,                  // The media is not able to be used for this operation at this time. Valid for command: PlayItem, AddToNowPlaying
81     AVRCP_STATUS_NOW_PLAYING_LIST_FULL,         // No more items can be added to the Now Playing List. Valid for command: AddToNowPlaying
82     AVRCP_STATUS_SEARCH_NOT_SUPPORTED,          // The Browsed Media Player does not support search. Valid for command: Search
83     AVRCP_STATUS_SEARCH_IN_PROGRESS,            // A search operation is already in progress. Valid for command: Search
84     AVRCP_STATUS_INVALID_PLAYER_ID,             // The specified Player Id does not refer to a valid player. Valid for command: SetAddressedPlayer, SetBrowsedPlayer
85     AVRCP_STATUS_PLAYER_NOT_BROWSABLE,          // The Player Id supplied refers to a Media Player which does not support browsing. Valid for command: SetBrowsedPlayer
86     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
87     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
88     AVRCP_STATUS_NO_AVAILABLE_PLAYERS,
89     AVRCP_STATUS_ADDRESSED_PLAYER_CHANGED,       // Valid for command: Register Notification
90     AVRCP_STATUS_RESERVED                       // 0x17 - 0xFF
91 } avrcp_status_code_t;
92 
93 typedef enum {
94     AVRCP_SINGLE_PACKET= 0,
95     AVRCP_START_PACKET    ,
96     AVRCP_CONTINUE_PACKET ,
97     AVRCP_END_PACKET
98 } avrcp_packet_type_t;
99 
100 typedef enum {
101     AVRCP_COMMAND_FRAME = 0,
102     AVRCP_RESPONSE_FRAME
103 } avrcp_frame_type_t;
104 
105 
106 typedef enum {
107     AVRCP_CAPABILITY_ID_COMPANY = 0x02,
108     AVRCP_CAPABILITY_ID_EVENT = 0x03
109 } avrcp_capability_id_t;
110 
111 #define AVRCP_BROWSING_MAX_NUM_ATTR_IDS 8
112 typedef enum {
113     AVRCP_MEDIA_ATTR_ALL = 0x0000,
114     AVRCP_MEDIA_ATTR_TITLE,
115     AVRCP_MEDIA_ATTR_ARTIST,
116     AVRCP_MEDIA_ATTR_ALBUM,
117     AVRCP_MEDIA_ATTR_TRACK,
118     AVRCP_MEDIA_ATTR_TOTAL_NUM_ITEMS,
119     AVRCP_MEDIA_ATTR_GENRE,
120     AVRCP_MEDIA_ATTR_SONG_LENGTH_MS,
121     AVRCP_MEDIA_ATTR_DEFAULT_COVER_ART,
122     AVRCP_MEDIA_ATTR_NONE = 0x7FFF
123 } avrcp_media_attribute_id_t;
124 
125 typedef enum {
126     AVRCP_PDU_ID_GET_CAPABILITIES = 0x10,
127     AVRCP_PDU_ID_GetCurrentPlayerApplicationSettingValue = 0x13,
128     AVRCP_PDU_ID_SetPlayerApplicationSettingValue = 0x14,
129     AVRCP_PDU_ID_GET_ELEMENT_ATTRIBUTES = 0x20,
130     AVRCP_PDU_ID_GET_PLAY_STATUS = 0x30,
131     AVRCP_PDU_ID_REGISTER_NOTIFICATION = 0x31,
132     AVRCP_PDU_ID_REQUEST_CONTINUING_RESPONSE = 0x40,
133     AVRCP_PDU_ID_REQUEST_ABORT_CONTINUING_RESPONSE = 0x41,
134     AVRCP_PDU_ID_SET_ABSOLUTE_VOLUME = 0x50,
135     AVRCP_PDU_ID_SET_ADDRESSED_PLAYER = 0x60,
136     AVRCP_PDU_ID_SET_BROWSED_PLAYER = 0x70,
137     AVRCP_PDU_ID_GET_FOLDER_ITEMS = 0x71,
138     AVRCP_PDU_ID_CHANGE_PATH = 0x72,
139     AVRCP_PDU_ID_GET_ITEM_ATTRIBUTES = 0x73,
140     AVRCP_PDU_ID_PLAY_ITEM = 0x74,
141     AVRCP_PDU_ID_GET_TOTAL_NUMBER_OF_ITEMS = 0x75,
142     AVRCP_PDU_ID_SEARCH = 0x80,
143     AVRCP_PDU_ID_ADD_TO_NOW_PLAYING = 0x90,
144     AVRCP_PDU_ID_GENERAL_REJECT = 0xA0,
145 
146     AVRCP_PDU_ID_UNDEFINED = 0xFF
147 } avrcp_pdu_id_t;
148 
149 typedef enum {
150     AVRCP_NOTIFICATION_EVENT_PLAYBACK_STATUS_CHANGED = 0x01,            // Change in playback status of the current track.
151     AVRCP_NOTIFICATION_EVENT_TRACK_CHANGED = 0x02,                      // Change of current track
152     AVRCP_NOTIFICATION_EVENT_TRACK_REACHED_END = 0x03,                  // Reached end of a track
153     AVRCP_NOTIFICATION_EVENT_TRACK_REACHED_START = 0x04,                // Reached start of a track
154     AVRCP_NOTIFICATION_EVENT_PLAYBACK_POS_CHANGED = 0x05,               // Change in playback position. Returned after the specified playback notification change notification interval
155     AVRCP_NOTIFICATION_EVENT_BATT_STATUS_CHANGED = 0x06,                // Change in battery status
156     AVRCP_NOTIFICATION_EVENT_SYSTEM_STATUS_CHANGED = 0x07,              // Change in system status
157     AVRCP_NOTIFICATION_EVENT_PLAYER_APPLICATION_SETTING_CHANGED = 0x08, // Change in player application setting
158     AVRCP_NOTIFICATION_EVENT_NOW_PLAYING_CONTENT_CHANGED = 0x09,        // The content of the Now Playing list has changed, see 6.9.5.
159     AVRCP_NOTIFICATION_EVENT_AVAILABLE_PLAYERS_CHANGED = 0x0a,          // The available players have changed, see 6.9.4.
160     AVRCP_NOTIFICATION_EVENT_ADDRESSED_PLAYER_CHANGED = 0x0b,           // The Addressed Player has been changed, see 6.9.2.
161     AVRCP_NOTIFICATION_EVENT_UIDS_CHANGED = 0x0c,                       // The UIDs have changed, see 6.10.3.3.
162     AVRCP_NOTIFICATION_EVENT_VOLUME_CHANGED = 0x0d                      // The volume has been changed locally on the TG, see 6.13.3.
163 } avrcp_notification_event_id_t;
164 
165 // control command response: accepted, rejected, interim
166 // status  command response: not implemented, rejected, in transition, stable
167 // notify  command response: not implemented, rejected, changed
168 
169 typedef enum {
170     AVRCP_CTYPE_CONTROL = 0,
171     AVRCP_CTYPE_STATUS,
172     AVRCP_CTYPE_SPECIFIC_INQUIRY,
173     AVRCP_CTYPE_NOTIFY,
174     AVRCP_CTYPE_GENERAL_INQUIRY,
175     AVRCP_CTYPE_RESERVED5,
176     AVRCP_CTYPE_RESERVED6,
177     AVRCP_CTYPE_RESERVED7,
178     AVRCP_CTYPE_RESPONSE_NOT_IMPLEMENTED = 8,
179     AVRCP_CTYPE_RESPONSE_ACCEPTED,
180     AVRCP_CTYPE_RESPONSE_REJECTED,
181     AVRCP_CTYPE_RESPONSE_IN_TRANSITION, // target state is in transition. A subsequent STATUS command, may result in the return of a STABLE status
182     AVRCP_CTYPE_RESPONSE_IMPLEMENTED_STABLE,
183     AVRCP_CTYPE_RESPONSE_CHANGED_STABLE,
184     AVRCP_CTYPE_RESPONSE_RESERVED,
185     AVRCP_CTYPE_RESPONSE_INTERIM            // target is unable to respond with either ACCEPTED or REJECTED within 100 millisecond
186 } avrcp_command_type_t;
187 
188 typedef enum {
189     AVRCP_SUBUNIT_TYPE_MONITOR = 0,
190     AVRCP_SUBUNIT_TYPE_AUDIO = 1,
191     AVRCP_SUBUNIT_TYPE_PRINTER,
192     AVRCP_SUBUNIT_TYPE_DISC,
193     AVRCP_SUBUNIT_TYPE_TAPE_RECORDER_PLAYER,
194     AVRCP_SUBUNIT_TYPE_TUNER,
195     AVRCP_SUBUNIT_TYPE_CA,
196     AVRCP_SUBUNIT_TYPE_CAMERA,
197     AVRCP_SUBUNIT_TYPE_RESERVED,
198     AVRCP_SUBUNIT_TYPE_PANEL = 9,
199     AVRCP_SUBUNIT_TYPE_BULLETIN_BOARD,
200     AVRCP_SUBUNIT_TYPE_CAMERA_STORAGE,
201     AVRCP_SUBUNIT_TYPE_VENDOR_UNIQUE = 0x1C,
202     AVRCP_SUBUNIT_TYPE_RESERVED_FOR_ALL_SUBUNIT_TYPES,
203     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].
204                                               // Further extension is possible when the value of extended_unit_type is FF16, in which case another byte will be added.
205     AVRCP_SUBUNIT_TYPE_UNIT = 0x1F
206 } avrcp_subunit_type_t;
207 
208 typedef enum {
209     AVRCP_SUBUNIT_ID = 0,
210     AVRCP_SUBUNIT_ID_IGNORE = 7
211 } avrcp_subunit_id_t;
212 
213 typedef enum {
214     AVRCP_CMD_OPCODE_VENDOR_DEPENDENT = 0x00,
215     // AVRCP_CMD_OPCODE_RESERVE = 0x01,
216     AVRCP_CMD_OPCODE_UNIT_INFO = 0x30,
217     AVRCP_CMD_OPCODE_SUBUNIT_INFO = 0x31,
218     AVRCP_CMD_OPCODE_PASS_THROUGH = 0x7C,
219     // AVRCP_CMD_OPCODE_VERSION = 0xB0,
220     // AVRCP_CMD_OPCODE_POWER = 0xB2,
221     AVRCP_CMD_OPCODE_UNDEFINED = 0xFF
222 } avrcp_command_opcode_t;
223 
224 typedef enum {
225     AVRCP_OPERATION_ID_CHANNEL_UP = 0x30,
226     AVRCP_OPERATION_ID_CHANNEL_DOWN = 0x31,
227     AVRCP_OPERATION_ID_SELECT = 0x00,
228     AVRCP_OPERATION_ID_UP = 0x01,
229     AVRCP_OPERATION_ID_DOWN = 0x02,
230     AVRCP_OPERATION_ID_LEFT = 0x03,
231     AVRCP_OPERATION_ID_RIGHT = 0x04,
232     AVRCP_OPERATION_ID_ROOT_MENU = 0x09,
233 
234     AVRCP_OPERATION_ID_SKIP = 0x3C,
235     AVRCP_OPERATION_ID_VOLUME_UP = 0x41,
236     AVRCP_OPERATION_ID_VOLUME_DOWN = 0x42,
237     AVRCP_OPERATION_ID_MUTE = 0x43,
238 
239     AVRCP_OPERATION_ID_PLAY = 0x44,
240     AVRCP_OPERATION_ID_STOP = 0x45,
241     AVRCP_OPERATION_ID_PAUSE = 0x46,
242     AVRCP_OPERATION_ID_REWIND = 0x48,
243     AVRCP_OPERATION_ID_FAST_FORWARD = 0x49,
244     AVRCP_OPERATION_ID_FORWARD = 0x4B,
245     AVRCP_OPERATION_ID_BACKWARD = 0x4C,
246     AVRCP_OPERATION_ID_UNDEFINED = 0xFF
247 } avrcp_operation_id_t;
248 
249 typedef enum{
250     AVRCP_PLAYBACK_STATUS_STOPPED = 0x00,
251     AVRCP_PLAYBACK_STATUS_PLAYING,
252     AVRCP_PLAYBACK_STATUS_PAUSED,
253     AVRCP_PLAYBACK_STATUS_FWD_SEEK,
254     AVRCP_PLAYBACK_STATUS_REV_SEEK,
255     AVRCP_PLAYBACK_STATUS_ERROR = 0xFF
256 } avrcp_playback_status_t;
257 
258 typedef enum{
259     AVRCP_BATTERY_STATUS_NORMAL = 0x00, // Battery operation is in normal state
260     AVRCP_BATTERY_STATUS_WARNING,       // unable to operate soon. Is provided when the battery level is going down.
261     AVRCP_BATTERY_STATUS_CRITICAL,      // can not operate any more. Is provided when the battery level is going down.
262     AVRCP_BATTERY_STATUS_EXTERNAL,      // Plugged to external power supply
263     AVRCP_BATTERY_STATUS_FULL_CHARGE    // when the device is completely charged from the external power supply
264 } avrcp_battery_status_t;
265 
266 
267 typedef enum {
268     AVCTP_CONNECTION_IDLE,
269     AVCTP_CONNECTION_W4_SDP_QUERY_COMPLETE,
270     AVCTP_CONNECTION_W4_ERTM_CONFIGURATION,
271     AVCTP_CONNECTION_W4_L2CAP_CONNECTED,
272     AVCTP_CONNECTION_OPENED,
273     AVCTP_W2_SEND_PRESS_COMMAND,
274     AVCTP_W2_SEND_RELEASE_COMMAND,
275     AVCTP_W4_STOP,
276     AVCTP_W2_SEND_COMMAND,
277     AVCTP_W2_SEND_RESPONSE,
278     AVCTP_W2_RECEIVE_PRESS_RESPONSE,
279     AVCTP_W2_RECEIVE_RESPONSE,
280     AVCTP_W2_SEND_FRAGMENTED_COMMAND,
281 } avctp_connection_state_t;
282 
283 typedef enum {
284     AVRCP_BROWSING_MEDIA_PLAYER_LIST = 0x00,
285     AVRCP_BROWSING_MEDIA_PLAYER_VIRTUAL_FILESYSTEM,
286     AVRCP_BROWSING_SEARCH,
287     AVRCP_BROWSING_NOW_PLAYING
288 } avrcp_browsing_scope_t;
289 
290 typedef struct {
291     uint16_t len;
292     uint8_t  * value;
293 } avrcp_now_playing_info_item_t;
294 
295 typedef struct {
296     uint8_t track_id[8];
297     uint16_t track_nr;
298     char * title;
299     char * artist;
300     char * album;
301     char * genre;
302     uint32_t song_length_ms;
303     uint32_t song_position_ms;
304 } avrcp_track_t;
305 
306 typedef enum {
307     AVRCP_PARSER_GET_ATTRIBUTE_HEADER = 0,       // 8 bytes
308     AVRCP_PARSER_GET_ATTRIBUTE_VALUE,
309     AVRCP_PARSER_IGNORE_REST_OF_ATTRIBUTE_VALUE
310 } avrcp_parser_state_t;
311 
312 
313 #define AVRCP_BROWSING_ITEM_HEADER_LEN 3
314 
315 // BROWSING
316 typedef struct {
317     uint16_t l2cap_browsing_cid;
318 
319     avctp_connection_state_t state;
320     uint8_t  wait_to_send;
321     uint8_t  transaction_label;
322     // used for AVCTP fragmentation
323     uint8_t  num_packets;
324     uint16_t bytes_to_send;
325 
326     uint8_t *ertm_buffer;
327     uint32_t ertm_buffer_size;
328     l2cap_ertm_config_t ertm_config;
329 
330     // players
331     uint8_t  set_browsed_player_id;
332     uint16_t browsed_player_id;
333 
334     avrcp_browsing_scope_t  scope;
335     uint8_t  folder_uid[8]; // or media element
336     uint16_t uid_counter;
337 
338     // get folder item
339     uint8_t  get_folder_items;
340     uint32_t start_item;
341     uint32_t end_item;
342     uint32_t attr_bitmap;
343 
344     // item attrs
345     uint8_t get_item_attributes;
346 
347     // change_path
348     uint8_t  change_path;
349     uint8_t  direction;
350 
351     // search str
352     uint16_t search_str_len;
353     uint8_t  search_str[20];
354     uint8_t  search;
355 
356     // get_item_attributes
357     uint8_t  get_total_nr_items;
358     avrcp_browsing_scope_t get_total_nr_items_scope;
359 
360     avrcp_pdu_id_t pdu_id;
361     uint8_t browsing_status;
362     uint16_t num_items;
363 
364     avrcp_parser_state_t parser_state;
365     uint8_t  parser_attribute_header[AVRCP_BROWSING_ITEM_HEADER_LEN];
366     uint8_t  parser_attribute_header_pos;
367     uint8_t  parsed_attribute_value[AVRCP_MAX_ATTRIBUTTE_SIZE];
368     uint16_t parsed_attribute_value_len;
369     uint16_t parsed_attribute_value_offset;
370     uint8_t  parsed_num_attributes;
371 
372     // get folder items data
373     uint8_t * attr_list;
374     uint16_t attr_list_size;
375     // command
376     // uint8_t transaction_label;
377     avrcp_command_opcode_t command_opcode;
378     avrcp_command_type_t command_type;
379     avrcp_subunit_type_t subunit_type;
380     avrcp_subunit_id_t   subunit_id;
381     avrcp_packet_type_t  packet_type;
382     uint8_t cmd_operands[200];
383     uint8_t cmd_operands_length;
384 } avrcp_browsing_connection_t;
385 // BROWSING END
386 
387 typedef struct {
388     btstack_linked_item_t    item;
389     bd_addr_t remote_addr;
390     uint16_t l2cap_signaling_cid;
391     uint16_t l2cap_mtu;
392     uint16_t avrcp_cid;
393 
394     uint16_t avrcp_browsing_cid;
395     uint16_t browsing_l2cap_psm;
396     uint16_t browsing_version;
397 
398     avrcp_browsing_connection_t * browsing_connection;
399 
400     avctp_connection_state_t state;
401     uint8_t wait_to_send;
402 
403     // PID check
404     uint8_t reject_transport_header;
405     uint8_t transport_header;
406     uint16_t invalid_pid;
407 
408     // command
409     uint8_t transaction_label;
410     avrcp_command_opcode_t command_opcode;
411     avrcp_command_type_t command_type;
412     avrcp_subunit_type_t subunit_type;
413     avrcp_subunit_id_t   subunit_id;
414     avrcp_packet_type_t  packet_type;
415 
416     // regular commands
417     uint8_t cmd_operands[20];
418     uint8_t cmd_operands_length;
419 
420     // long/fragmented commands
421     const uint8_t * cmd_operands_fragmented_buffer;
422     uint16_t  cmd_operands_fragmented_pos;
423     uint16_t  cmd_operands_fragmented_len;
424 
425     btstack_timer_source_t press_and_hold_cmd_timer;
426     uint8_t  continuous_fast_forward_cmd;
427     uint16_t notifications_enabled;
428     uint16_t notifications_to_register;
429     uint16_t notifications_to_deregister;
430 
431     avrcp_subunit_type_t unit_type;
432     uint32_t company_id;
433     avrcp_subunit_type_t subunit_info_type;
434     const uint8_t * subunit_info_data;
435     uint16_t subunit_info_data_size;
436 
437     avrcp_now_playing_info_item_t now_playing_info[AVRCP_MEDIA_ATTR_COUNT];
438     uint8_t  track_id[8];
439     uint32_t song_length_ms;
440     uint32_t song_position_ms;
441     int total_tracks;
442     int track_nr;
443     uint8_t track_selected;
444     uint8_t track_changed;
445 
446     avrcp_playback_status_t playback_status;
447     uint8_t playback_status_changed;
448 
449     uint8_t playing_content_changed;
450 
451     avrcp_battery_status_t battery_status;
452     uint8_t battery_status_changed;
453     uint8_t volume_percentage;
454     uint8_t volume_percentage_changed;
455     uint8_t now_playing_info_response;
456     uint8_t now_playing_info_attr_bitmap;
457     uint8_t abort_continue_response;
458 
459     // used for fragmentation
460     avrcp_media_attribute_id_t next_attr_id;
461 
462     avrcp_parser_state_t parser_state;
463     uint8_t  parser_attribute_header[AVRCP_ATTRIBUTE_HEADER_LEN];
464     uint8_t  parser_attribute_header_pos;
465 
466     uint16_t list_size;
467     uint16_t list_offset;
468     uint8_t  attribute_value[AVRCP_MAX_ATTRIBUTTE_SIZE];
469     uint16_t attribute_value_len;
470     uint16_t attribute_value_offset;
471 
472     uint32_t attribute_id;
473 
474     uint8_t  num_attributes;
475     uint8_t  num_parsed_attributes;
476 
477     uint8_t addressed_player_changed;
478     uint16_t addressed_player_id;
479     uint16_t uid_counter;
480     // PTS requires definition of max num fragments
481     uint8_t max_num_fragments;
482     uint8_t num_received_fragments;
483 } avrcp_connection_t;
484 
485 typedef enum {
486     AVRCP_SHUFFLE_MODE_INVALID,
487     AVRCP_SHUFFLE_MODE_OFF,
488     AVRCP_SHUFFLE_MODE_ALL_TRACKS,
489     AVRCP_SHUFFLE_MODE_GROUP
490 } avrcp_shuffle_mode_t;
491 
492 typedef enum {
493     AVRCP_REPEAT_MODE_INVALID,
494     AVRCP_REPEAT_MODE_OFF,
495     AVRCP_REPEAT_MODE_SINGLE_TRACK,
496     AVRCP_REPEAT_MODE_ALL_TRACKS,
497     AVRCP_REPEAT_MODE_GROUP
498 } avrcp_repeat_mode_t;
499 
500 typedef enum{
501     AVRCP_CONTROLLER = 0,
502     AVRCP_TARGET
503 } avrcp_role_t;
504 
505 typedef enum {
506     RFC2978_CHARSET_MIB_UTF8 = 106
507 } rfc2978_charset_mib_enumid_t;
508 
509 typedef struct {
510     avrcp_role_t role;
511     btstack_linked_list_t connections;
512     btstack_packet_handler_t avrcp_callback;
513     btstack_packet_handler_t packet_handler;
514 
515     btstack_packet_handler_t browsing_avrcp_callback;
516     btstack_packet_handler_t browsing_packet_handler;
517 
518     // SDP query
519     uint8_t parse_sdp_record;
520     uint32_t record_id;
521     uint16_t avrcp_cid;
522     uint16_t avrcp_l2cap_psm;
523     uint16_t avrcp_version;
524 } avrcp_context_t;
525 
526 
527 const char * avrcp_subunit2str(uint16_t index);
528 const char * avrcp_event2str(uint16_t index);
529 const char * avrcp_operation2str(uint8_t index);
530 const char * avrcp_attribute2str(uint8_t index);
531 const char * avrcp_play_status2str(uint8_t index);
532 const char * avrcp_ctype2str(uint8_t index);
533 const char * avrcp_repeat2str(uint8_t index);
534 const char * avrcp_shuffle2str(uint8_t index);
535 
536 void avrcp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size, avrcp_context_t * context);
537 
538 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);
539 uint8_t avrcp_connect(bd_addr_t bd_addr, avrcp_context_t * context, uint16_t * avrcp_cid);
540 void avrcp_emit_connection_established(btstack_packet_handler_t callback, uint16_t avrcp_cid, bd_addr_t addr, uint8_t status);
541 void avrcp_emit_connection_closed(btstack_packet_handler_t callback, uint16_t avrcp_cid);
542 
543 uint8_t avrcp_cmd_opcode(uint8_t *packet, uint16_t size);
544 avrcp_connection_t * get_avrcp_connection_for_l2cap_signaling_cid(uint16_t l2cap_cid, avrcp_context_t * context);
545 avrcp_connection_t * get_avrcp_connection_for_avrcp_cid(uint16_t avrcp_cid, avrcp_context_t * context);
546 avrcp_connection_t * get_avrcp_connection_for_bd_addr(bd_addr_t addr, avrcp_context_t * context);
547 void avrcp_request_can_send_now(avrcp_connection_t * connection, uint16_t l2cap_cid);
548 uint16_t avrcp_get_next_cid(void);
549 
550 // SDP query
551 void avrcp_handle_sdp_client_query_result(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
552 
553 #if defined __cplusplus
554 }
555 #endif
556 
557 #endif // __AVRCP_H
558