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