xref: /btstack/example/avrcp_browsing_client.c (revision fe10780b18ec8056cf6ad736d934e4493d6bd014)
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 #define BTSTACK_FILE__ "avrcp_browsing_client.c"
39 
40 /*
41  * avrcp_browsing_client.c
42  */
43 
44 // *****************************************************************************
45 /* EXAMPLE_START(avrcp_browsing_client): Browse media players and media information on a remote device.
46  *
47  * @text This example demonstrates how to use the AVRCP Controller Browsing service to
48  * browse madia players and media information on a remote AVRCP Source device.
49  *
50  * @test To test with a remote device, e.g. a mobile phone,
51  * pair from the remote device with the demo, then use the UI for browsing (tap
52  * SPACE on the console to show the available AVRCP commands).
53  *
54  */
55 // *****************************************************************************
56 
57 #include <stdint.h>
58 #include <inttypes.h>
59 #include <stdio.h>
60 #include <stdlib.h>
61 #include <string.h>
62 
63 #include "btstack.h"
64 
65 #ifdef HAVE_BTSTACK_STDIN
66 #include "btstack_stdin.h"
67 #endif
68 
69 #define AVRCP_BROWSING_ENABLED
70 
71 #define AVRCP_BROWSING_MAX_PLAYERS          10
72 #define AVRCP_BROWSING_MAX_FOLDERS          10
73 #define AVRCP_BROWSING_MAX_FOLDER_NAME_LEN  30
74 
75 #ifdef HAVE_BTSTACK_STDIN
76 // mac 2011: static bd_addr_t remote = {0x04, 0x0C, 0xCE, 0xE4, 0x85, 0xD3};
77 // pts: static bd_addr_t remote = {0x00, 0x1B, 0xDC, 0x08, 0x0A, 0xA5};
78 // mac 2013:
79 // static const char * device_addr_string = "84:38:35:65:d1:15";
80 // iPhone 5S: static const char * device_addr_string = "54:E4:3A:26:A2:39";
81 // phone 2013:
82 // static const char * device_addr_string = "B0:34:95:CB:97:C4";
83 
84 static const char * device_addr_string = "B0:34:95:CB:97:C4";
85 
86 static bd_addr_t device_addr;
87 #endif
88 
89 static uint16_t avrcp_cid = 0;
90 static uint8_t  avrcp_connected = 0;
91 
92 static uint16_t browsing_cid = 0;
93 static uint8_t  avrcp_browsing_connected = 0;
94 static uint8_t  sdp_avrcp_browsing_controller_service_buffer[200];
95 
96 static uint8_t browsing_query_active = 0;
97 static avrcp_media_item_context_t media_item_context;
98 
99 typedef struct {
100     uint16_t  charset;
101     uint8_t   depth;
102     uint16_t  name_len;
103     char      name[AVRCP_BROWSING_MAX_FOLDER_NAME_LEN];
104 } avrcp_browsing_root_folder_t;
105 
106 typedef struct {
107     uint8_t  uid[8];
108     uint16_t name_len;
109     char     name[AVRCP_BROWSING_MAX_FOLDER_NAME_LEN];
110 } avrcp_browsing_folders_t;
111 
112 static uint8_t  parent_folder_set = 0;
113 static uint8_t  parent_folder_uid[8];
114 static char     parent_folder_name[AVRCP_BROWSING_MAX_FOLDER_NAME_LEN];
115 static avrcp_browsing_folders_t folders[AVRCP_BROWSING_MAX_FOLDERS];
116 static int folder_index = -1;
117 static uint16_t players[AVRCP_BROWSING_MAX_PLAYERS];
118 static int player_index = -1;
119 static uint16_t browsing_uid_counter = 0;
120 
121 static btstack_packet_callback_registration_t hci_event_callback_registration;
122 
123 static uint8_t ertm_buffer[10000];
124 static l2cap_ertm_config_t ertm_config = {
125     1,  // ertm mandatory
126     2,  // max transmit, some tests require > 1
127     2000,
128     12000,
129     144,    // l2cap ertm mtu
130     4,
131     4,
132     0,      // No FCS
133 };
134 
135 
136 static inline int next_index(int * index, int max_value){
137     if ((*index) < max_value){
138         (*index)++;
139     } else {
140         (*index) = 0;
141     }
142     return (*index);
143 }
144 
145 static int next_folder_index(void){
146     return next_index(&folder_index, AVRCP_BROWSING_MAX_FOLDERS);
147 }
148 
149 static int next_player_index(void){
150     return next_index(&player_index, AVRCP_BROWSING_MAX_PLAYERS);
151 }
152 
153 
154 /* @section Main Application Setup
155  *
156  * @text The Listing MainConfiguration shows how to setup AVRCP Controller Browsing service.
157  * To announce AVRCP Controller Browsing service, you need to create corresponding
158  * SDP record and register it with the SDP service.
159  * You'll also need to register several packet handlers:
160  * - stdin_process callback - used to trigger AVRCP commands, such are get media players, playlists, albums, etc. Requires HAVE_BTSTACK_STDIN.
161  * - avrcp_browsing_controller_packet_handler - used to receive answers for AVRCP commands.
162  *
163  */
164 
165 /* LISTING_START(MainConfiguration): Setup Audio Sink and AVRCP Controller services */
166 static void avrcp_browsing_controller_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
167 #ifdef HAVE_BTSTACK_STDIN
168 static void stdin_process(char cmd);
169 #endif
170 
171 
172 int btstack_main(int argc, const char * argv[]);
173 int btstack_main(int argc, const char * argv[]){
174     (void)argc;
175     (void)argv;
176 
177     // Initialize L2CAP.
178     l2cap_init();
179 
180     // Initialize AVRCP service.
181     avrcp_init();
182     // Initialize AVRCP Controller.
183     avrcp_controller_init();
184 
185     // Initialize AVRCP Browsing Controller, HCI events will be sent to the AVRCP Controller callback.
186     avrcp_browsing_controller_init();
187     // // Register AVRCP for HCI events.
188     avrcp_browsing_controller_register_packet_handler(&avrcp_browsing_controller_packet_handler);
189 
190     // Initialize SDP.
191     sdp_init();
192 
193     // Create AVRCP service record and register it with SDP.
194     memset(sdp_avrcp_browsing_controller_service_buffer, 0, sizeof(sdp_avrcp_browsing_controller_service_buffer));
195 
196     uint16_t supported_features = (1 << AVRCP_CONTROLLER_SUPPORTED_FEATURE_CATEGORY_PLAYER_OR_RECORDER);
197 #ifdef AVRCP_BROWSING_ENABLED
198     supported_features |= (1 << AVRCP_CONTROLLER_SUPPORTED_FEATURE_BROWSING);
199 #endif
200     avrcp_controller_create_sdp_record(sdp_avrcp_browsing_controller_service_buffer, 0x10001, supported_features, NULL, NULL);
201     sdp_register_service(sdp_avrcp_browsing_controller_service_buffer);
202 
203     // Set local name with a template Bluetooth address, that will be automatically
204     // replaced with a actual address once it is available, i.e. when BTstack boots
205     // up and starts talking to a Bluetooth module.
206     gap_set_local_name("AVRCP Browsing Client 00:00:00:00:00:00");
207     gap_discoverable_control(1);
208     gap_set_class_of_device(0x200408);
209 
210     // Register for HCI events.
211     hci_event_callback_registration.callback = &avrcp_browsing_controller_packet_handler;
212     hci_add_event_handler(&hci_event_callback_registration);
213 
214     // Register for AVRCP events.
215     avrcp_controller_register_packet_handler(&avrcp_browsing_controller_packet_handler);
216 
217 
218 #ifdef HAVE_BTSTACK_STDIN
219     // Parse human readable Bluetooth address.
220     sscanf_bd_addr(device_addr_string, device_addr);
221     btstack_stdin_setup(stdin_process);
222 #endif
223     printf("Starting BTstack ...\n");
224     hci_power_control(HCI_POWER_ON);
225     return 0;
226 }
227 /* LISTING_END */
228 
229 static void avrcp_browsing_controller_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
230     UNUSED(channel);
231     int pos;
232 
233     switch(packet_type){
234         case AVRCP_BROWSING_DATA_PACKET:
235             pos = 0;
236             browsing_query_active = 1;
237             avrcp_browsing_item_type_t data_type = (avrcp_browsing_item_type_t)packet[pos++];
238             pos += 2; // length
239 
240             switch (data_type){
241                 case AVRCP_BROWSING_MEDIA_ROOT_FOLDER:{
242                     avrcp_browsing_root_folder_t root_folder;
243                     root_folder.charset = big_endian_read_16(packet, pos);
244                     pos += 2;
245                     root_folder.depth = packet[pos++];
246                     root_folder.name_len = big_endian_read_16(packet, pos);
247                     pos += 2;
248 
249                     memset(root_folder.name, 0, AVRCP_BROWSING_MAX_FOLDER_NAME_LEN);
250                     root_folder.name_len = btstack_min(big_endian_read_16(packet, pos), AVRCP_BROWSING_MAX_FOLDER_NAME_LEN - 1);
251                     memcpy(root_folder.name, packet+pos, root_folder.name_len);
252                     printf("Found root folder: name %s, depth %d \n", (char *)root_folder.name, root_folder.depth);
253                     break;
254                 }
255                 case AVRCP_BROWSING_MEDIA_PLAYER_ITEM:{
256                     printf("Received media player:  ");
257                     uint16_t player_id = big_endian_read_16(packet, pos);
258                     pos += 2;
259                     avrcp_browsing_media_player_major_type_t major_type = packet[pos++];
260                     avrcp_browsing_media_player_subtype_t subtype = big_endian_read_32(packet, pos);
261                     pos += 4;
262                     uint8_t status = packet[pos++];
263                     uint8_t feature_bitmask[16];
264                     memcpy(feature_bitmask, packet, 16);
265                     pos += 16;
266                     printf("player ID 0x%04x, major_type %d, subtype %d, status %d\n", player_id, major_type, subtype, status);
267                     players[next_player_index()] = player_id;
268                     break;
269                 }
270                 case AVRCP_BROWSING_FOLDER_ITEM:{
271                     int index = next_folder_index();
272                     // printf("Found folder [%d]: ", index);
273                     memcpy(folders[index].uid, packet+pos, 8);
274                     uint32_t folder_uid_high = big_endian_read_32(packet, pos);
275                     pos += 4;
276                     uint32_t folder_uid_low  = big_endian_read_32(packet, pos);
277                     pos += 4;
278                     avrcp_browsing_folder_type_t folder_type = packet[pos++];
279                     uint8_t  is_playable = packet[pos++];
280                     uint16_t charset = big_endian_read_16(packet, pos);
281                     pos += 2;
282                     uint16_t displayable_name_length = big_endian_read_16(packet, pos);
283                     pos += 2;
284 
285                     char value[AVRCP_BROWSING_MAX_FOLDER_NAME_LEN];
286 
287                     memset(value, 0, AVRCP_BROWSING_MAX_FOLDER_NAME_LEN);
288                     uint16_t value_len = btstack_min(displayable_name_length, AVRCP_BROWSING_MAX_FOLDER_NAME_LEN - 1);
289                     memcpy(value, packet+pos, value_len);
290 
291                     printf("UID 0x%08" PRIx32 "%08" PRIx32 ", type 0x%02x, is_playable %d, charset 0x%02x, name %s\n",
292                         folder_uid_high, folder_uid_low, folder_type, is_playable, charset, value);
293                     memcpy(folders[index].name, value, value_len);
294                     folders[index].name_len = value_len;
295                     break;
296                 }
297                 case AVRCP_BROWSING_MEDIA_ELEMENT_ITEM:{
298                     printf("Found media: ");
299 
300                     uint32_t media_uid_high = big_endian_read_32(packet, pos);
301                     pos += 4;
302                     uint32_t media_uid_low  = big_endian_read_32(packet, pos+4);
303                     pos += 4;
304                     avrcp_browsing_media_type_t media_type = packet[pos++];
305                     uint16_t charset = big_endian_read_16(packet, pos);
306                     pos += 2;
307                     uint16_t displayable_name_length = big_endian_read_16(packet, pos);
308                     pos += 2;
309                     pos += displayable_name_length;
310                     printf("Media UID: 0x%08" PRIx32 "%08" PRIx32 ", media_type 0x%02x, charset 0x%02x, displayable_name_length %d\n", media_uid_high, media_uid_low, media_type, charset, displayable_name_length);
311 
312                     uint8_t num_attributes = packet[pos++];
313                     printf("Num media attributes %d\n", num_attributes);
314 
315                     for (avrcp_media_item_iterator_init(&media_item_context, size-pos, packet+pos); avrcp_media_item_iterator_has_more(&media_item_context); avrcp_media_item_iterator_next(&media_item_context)){
316                         uint32_t attr_id            = avrcp_media_item_iterator_get_attr_id(&media_item_context);
317                         uint16_t attr_charset       = avrcp_media_item_iterator_get_attr_charset(&media_item_context);
318                         uint16_t attr_value_length  = avrcp_media_item_iterator_get_attr_value_len(&media_item_context);
319                         const uint8_t * attr_value  = avrcp_media_item_iterator_get_attr_value(&media_item_context);
320 
321                         printf("Attr ID 0x%08" PRIx32 ", charset %d, attr_value_length %d, value %s", attr_id, attr_charset, attr_value_length, attr_value);
322                     }
323                     break;
324                 }
325 
326                 default:
327                     log_error("AVRCP browsing: unknown browsable item type 0%02x", data_type);
328                     break;
329             }
330             break;
331         case HCI_EVENT_PACKET:
332             if (hci_event_packet_get_type(packet) != HCI_EVENT_AVRCP_META) return;
333             uint16_t local_cid;
334             uint8_t  status = 0xFF;
335             bd_addr_t address;
336 
337             if (packet[0] != HCI_EVENT_AVRCP_META) break;
338             switch (packet[2]){
339                 case AVRCP_SUBEVENT_CONNECTION_ESTABLISHED: {
340                     local_cid = avrcp_subevent_connection_established_get_avrcp_cid(packet);
341                     printf("AVRCP_SUBEVENT_CONNECTION_ESTABLISHED cid 0x%02x\n", local_cid);
342 
343                     if (avrcp_cid != 0 && avrcp_cid != local_cid) {
344                         printf("AVRCP Controller connection failed, expected 0x%02X l2cap cid, received 0x%02X\n", avrcp_cid, local_cid);
345                         return;
346                     }
347 
348                     status = avrcp_subevent_connection_established_get_status(packet);
349                     if (status != ERROR_CODE_SUCCESS){
350                         printf("AVRCP Controller connection failed: status 0x%02x\n", status);
351                         avrcp_cid = 0;
352                         return;
353                     }
354 
355                     avrcp_cid = local_cid;
356                     avrcp_connected = 1;
357                     avrcp_subevent_connection_established_get_bd_addr(packet, address);
358                     printf("AVRCP Controller connected.\n");
359                     return;
360                 }
361                 case AVRCP_SUBEVENT_CONNECTION_RELEASED:
362                     printf("AVRCP Controller Client released.\n");
363                     avrcp_cid = 0;
364                     avrcp_browsing_connected = 0;
365                     folder_index = 0;
366                     memset(folders, 0, sizeof(folders));
367                     return;
368 
369                 case AVRCP_SUBEVENT_INCOMING_BROWSING_CONNECTION:
370                     local_cid = avrcp_subevent_incoming_browsing_connection_get_browsing_cid(packet);
371                     printf("AVRCP_SUBEVENT_INCOMING_BROWSING_CONNECTION cid 0x%02x\n", local_cid);
372                     if (browsing_cid != 0 && browsing_cid != local_cid) {
373                         printf("AVRCP Browsing Client connection failed, expected 0x%02X l2cap cid, received 0x%02X\n", browsing_cid, local_cid);
374                         avrcp_browsing_controller_decline_incoming_connection(browsing_cid);
375                         return;
376                     }
377                     browsing_cid = local_cid;
378                     printf("AVRCP Browsing Client configure incoming connection, browsing cid 0x%02x\n", browsing_cid);
379                     avrcp_browsing_controller_configure_incoming_connection(browsing_cid, ertm_buffer, sizeof(ertm_buffer), &ertm_config);
380                     break;
381 
382                 case AVRCP_SUBEVENT_BROWSING_CONNECTION_ESTABLISHED: {
383                     local_cid = avrcp_subevent_browsing_connection_established_get_browsing_cid(packet);
384                     printf("AVRCP_SUBEVENT_BROWSING_CONNECTION_ESTABLISHED cid 0x%02x\n", local_cid);
385                     if (browsing_cid != 0 && browsing_cid != local_cid) {
386                         printf("AVRCP Browsing Client connection failed, expected 0x%02X l2cap cid, received 0x%02X\n", browsing_cid, local_cid);
387                         return;
388                     }
389 
390                     status = avrcp_subevent_browsing_connection_established_get_status(packet);
391                     if (status != ERROR_CODE_SUCCESS){
392                         printf("AVRCP Browsing Client connection failed: status 0x%02x\n", status);
393                         browsing_cid = 0;
394                         return;
395                     }
396 
397                     browsing_cid = local_cid;
398                     avrcp_browsing_connected = 1;
399                     avrcp_subevent_browsing_connection_established_get_bd_addr(packet, address);
400                     printf("AVRCP Browsing Client connected\n");
401                     return;
402                 }
403                 case AVRCP_SUBEVENT_BROWSING_CONNECTION_RELEASED:
404                     printf("AVRCP Browsing Controller released\n");
405                     browsing_cid = 0;
406                     avrcp_browsing_connected = 0;
407                     return;
408 
409                 case AVRCP_SUBEVENT_BROWSING_DONE:
410                     browsing_query_active = 0;
411                     browsing_uid_counter = 0;
412                     if (avrcp_subevent_browsing_done_get_browsing_status(packet) != AVRCP_BROWSING_ERROR_CODE_SUCCESS){
413                         printf("AVRCP Browsing query done with browsing status 0x%02x, bluetooth status 0x%02x.\n",
414                             avrcp_subevent_browsing_done_get_browsing_status(packet),
415                             avrcp_subevent_browsing_done_get_bluetooth_status(packet));
416                         break;
417                     }
418                     browsing_uid_counter = avrcp_subevent_browsing_done_get_uid_counter(packet);
419                     printf("DONE, browsing_uid_counter %d.\n", browsing_uid_counter);
420                     break;
421 
422                 default:
423                     break;
424             }
425             break;
426 
427         default:
428             break;
429     }
430 
431 }
432 
433 #ifdef HAVE_BTSTACK_STDIN
434 static void show_usage(void){
435     bd_addr_t      iut_address;
436     gap_local_bd_addr(iut_address);
437     printf("\n--- Bluetooth AVRCP Controller Connection Test Console %s ---\n", bd_addr_to_str(iut_address));
438     printf("c      - AVRCP create connection to addr %s\n", bd_addr_to_str(device_addr));
439     printf("C      - AVRCP disconnect\n");
440     printf("e      - AVRCP Browsing Controller create connection to addr %s\n", bd_addr_to_str(device_addr));
441     printf("E      - AVRCP Browsing Controller disconnect\n");
442 
443     printf("I      - Set first found player as addressed player\n");
444     printf("O      - Set first found player as browsed player\n");
445 
446     printf("p      - Get media players\n");
447     printf("Q      - Browse folders\n");
448     printf("P      - Go up one level\n");
449     printf("W      - Go down one level\n");
450     printf("T      - Browse media items\n");
451     printf("---\n");
452 }
453 #endif
454 
455 
456 #ifdef HAVE_BTSTACK_STDIN
457 static void stdin_process(char cmd){
458     uint8_t status = ERROR_CODE_SUCCESS;
459 
460     if (cmd != 'a' && cmd != 'A' && cmd != 'c' && cmd != 'C'){
461         if (browsing_query_active){
462             printf("Query active, try later!\n");
463             return;
464         }
465     }
466 
467     switch (cmd){
468         case 'c':
469             printf(" - Create AVRCP connection for control to addr %s.\n", bd_addr_to_str(device_addr));
470             status = avrcp_connect(device_addr, &avrcp_cid);
471             break;
472         case 'C':
473             if (avrcp_connected){
474                 printf(" - AVRCP disconnect from addr %s.\n", bd_addr_to_str(device_addr));
475                 status = avrcp_disconnect(avrcp_cid);
476                 break;
477             }
478             printf("AVRCP service already disconnected\n");
479             break;
480 
481         case 'e':
482             if (!avrcp_connected) {
483                 printf(" You must first create AVRCP connection for control to addr %s.\n", bd_addr_to_str(device_addr));
484                 break;
485             }
486             printf(" - Create AVRCP connection for browsing to addr %s.\n", bd_addr_to_str(device_addr));
487             status = avrcp_browsing_controller_connect(device_addr, ertm_buffer, sizeof(ertm_buffer), &ertm_config, &browsing_cid);
488             break;
489         case 'E':
490             if (avrcp_browsing_connected){
491                 printf(" - AVRCP Browsing Controller disconnect from addr %s.\n", bd_addr_to_str(device_addr));
492                 status = avrcp_browsing_controller_disconnect(browsing_cid);
493                 break;
494             }
495             printf("AVRCP Browsing Controller already disconnected\n");
496             break;
497         case '\n':
498         case '\r':
499             break;
500 
501         default:
502             if (!avrcp_browsing_connected){
503                 show_usage();
504                 printf("Please connect the AVRCP Browsing client\n");
505                 break;
506             }
507 
508             switch (cmd) {
509                 case 'I':
510                     if (player_index < 0) {
511                         printf("Get media players first\n");
512                         break;
513                     }
514                     printf("Set addressed player\n");
515                     status = avrcp_controller_set_addressed_player(avrcp_cid, players[0]);
516                     break;
517                 case 'O':
518                     if (player_index < 0) {
519                         printf("Get media players first\n");
520                         break;
521                     }
522                     printf("Set browsed player\n");
523                     status = avrcp_browsing_controller_set_browsed_player(browsing_cid, players[0]);
524                     break;
525                 case 'p':
526                     printf("AVRCP Browsing: get media players\n");
527                     player_index = -1;
528                     status = avrcp_browsing_controller_get_media_players(browsing_cid, 0, 0xFFFFFFFF, AVRCP_MEDIA_ATTR_ALL);
529                     break;
530                 case 'Q':
531                     printf("AVRCP Browsing: browse folders\n");
532                     folder_index = -1;
533                     status = avrcp_browsing_controller_browse_file_system(browsing_cid, 0, 0xFFFFFFFF, AVRCP_MEDIA_ATTR_ALL);
534                     break;
535                 case 'P':
536                     printf("AVRCP Browsing: browse media items\n");
537                     avrcp_browsing_controller_browse_media(browsing_cid, 0, 0xFFFFFFFF, AVRCP_MEDIA_ATTR_ALL);
538                     break;
539                 case 'W':
540                     printf("AVRCP Browsing: go up one level\n");
541                     status = avrcp_browsing_controller_go_up_one_level(browsing_cid);
542                     folder_index = -1;
543                     break;
544                 case 'T':
545                     if (folder_index < 0 && !parent_folder_set){
546                         printf("AVRCP Browsing: no folders available\n");
547                         break;
548                     }
549                     if (!parent_folder_set){
550                         parent_folder_set = 1;
551                         memcpy(parent_folder_name, folders[0].name, folders[0].name_len);
552                         memcpy(parent_folder_uid, folders[0].uid, 8);
553                     }
554                     printf("AVRCP Browsing: go down one level of %s\n", (char *)parent_folder_name);
555                     status = avrcp_browsing_controller_go_down_one_level(browsing_cid, parent_folder_uid);
556                     folder_index = -1;
557                     break;
558                 default:
559                     show_usage();
560                     break;
561             }
562             break;
563     }
564 
565     if (status != ERROR_CODE_SUCCESS){
566         printf("Could not perform command, status 0x%2x\n", status);
567     }
568 }
569 #endif
570 /* EXAMPLE_END */
571