xref: /btstack/example/avrcp_browsing_client.c (revision 3c4cc6427fe05577c00b7d2593f58c7abcf9eab7)
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 Controller.
181     avrcp_controller_init();
182 
183         // Initialize AVRCP Browsing Controller, HCI events will be sent to the AVRCP Controller callback.
184     avrcp_browsing_controller_init();
185     // // Register AVRCP for HCI events.
186     avrcp_browsing_controller_register_packet_handler(&avrcp_browsing_controller_packet_handler);
187 
188     // Initialize SDP.
189     sdp_init();
190 
191     // Create AVRCP service record and register it with SDP.
192     memset(sdp_avrcp_browsing_controller_service_buffer, 0, sizeof(sdp_avrcp_browsing_controller_service_buffer));
193 
194     uint16_t supported_features = (1 << AVRCP_CONTROLLER_SUPPORTED_FEATURE_CATEGORY_PLAYER_OR_RECORDER);
195 #ifdef AVRCP_BROWSING_ENABLED
196     supported_features |= (1 << AVRCP_CONTROLLER_SUPPORTED_FEATURE_BROWSING);
197 #endif
198     avrcp_controller_create_sdp_record(sdp_avrcp_browsing_controller_service_buffer, 0x10001, supported_features, NULL, NULL);
199     sdp_register_service(sdp_avrcp_browsing_controller_service_buffer);
200 
201     // Set local name with a template Bluetooth address, that will be automatically
202     // replaced with a actual address once it is available, i.e. when BTstack boots
203     // up and starts talking to a Bluetooth module.
204     gap_set_local_name("AVRCP Browsing Client 00:00:00:00:00:00");
205     gap_discoverable_control(1);
206     gap_set_class_of_device(0x200408);
207 
208     // Register for HCI events.
209     hci_event_callback_registration.callback = &avrcp_browsing_controller_packet_handler;
210     hci_add_event_handler(&hci_event_callback_registration);
211 
212     // Register for AVRCP events.
213     avrcp_controller_register_packet_handler(&avrcp_browsing_controller_packet_handler);
214 
215 
216 #ifdef HAVE_BTSTACK_STDIN
217     // Parse human readable Bluetooth address.
218     sscanf_bd_addr(device_addr_string, device_addr);
219     btstack_stdin_setup(stdin_process);
220 #endif
221     printf("Starting BTstack ...\n");
222     hci_power_control(HCI_POWER_ON);
223     return 0;
224 }
225 /* LISTING_END */
226 
227 static void avrcp_browsing_controller_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
228     UNUSED(channel);
229     int pos;
230 
231     switch(packet_type){
232         case AVRCP_BROWSING_DATA_PACKET:
233             pos = 0;
234             browsing_query_active = 1;
235             avrcp_browsing_item_type_t data_type = (avrcp_browsing_item_type_t)packet[pos++];
236             pos += 2; // length
237 
238             switch (data_type){
239                 case AVRCP_BROWSING_MEDIA_ROOT_FOLDER:{
240                     avrcp_browsing_root_folder_t root_folder;
241                     root_folder.charset = big_endian_read_16(packet, pos);
242                     pos += 2;
243                     root_folder.depth = packet[pos++];
244                     root_folder.name_len = big_endian_read_16(packet, pos);
245                     pos += 2;
246 
247                     memset(root_folder.name, 0, AVRCP_BROWSING_MAX_FOLDER_NAME_LEN);
248                     root_folder.name_len = btstack_min(big_endian_read_16(packet, pos), AVRCP_BROWSING_MAX_FOLDER_NAME_LEN - 1);
249                     memcpy(root_folder.name, packet+pos, root_folder.name_len);
250                     printf("Found root folder: name %s, depth %d \n", (char *)root_folder.name, root_folder.depth);
251                     break;
252                 }
253                 case AVRCP_BROWSING_MEDIA_PLAYER_ITEM:{
254                     printf("Received media player:  ");
255                     uint16_t player_id = big_endian_read_16(packet, pos);
256                     pos += 2;
257                     avrcp_browsing_media_player_major_type_t major_type = packet[pos++];
258                     avrcp_browsing_media_player_subtype_t subtype = big_endian_read_32(packet, pos);
259                     pos += 4;
260                     uint8_t status = packet[pos++];
261                     uint8_t feature_bitmask[16];
262                     memcpy(feature_bitmask, packet, 16);
263                     pos += 16;
264                     printf("player ID 0x%04x, major_type %d, subtype %d, status %d\n", player_id, major_type, subtype, status);
265                     players[next_player_index()] = player_id;
266                     break;
267                 }
268                 case AVRCP_BROWSING_FOLDER_ITEM:{
269                     int index = next_folder_index();
270                     // printf("Found folder [%d]: ", index);
271                     memcpy(folders[index].uid, packet+pos, 8);
272                     uint32_t folder_uid_high = big_endian_read_32(packet, pos);
273                     pos += 4;
274                     uint32_t folder_uid_low  = big_endian_read_32(packet, pos);
275                     pos += 4;
276                     avrcp_browsing_folder_type_t folder_type = packet[pos++];
277                     uint8_t  is_playable = packet[pos++];
278                     uint16_t charset = big_endian_read_16(packet, pos);
279                     pos += 2;
280                     uint16_t displayable_name_length = big_endian_read_16(packet, pos);
281                     pos += 2;
282 
283                     char value[AVRCP_BROWSING_MAX_FOLDER_NAME_LEN];
284 
285                     memset(value, 0, AVRCP_BROWSING_MAX_FOLDER_NAME_LEN);
286                     uint16_t value_len = btstack_min(displayable_name_length, AVRCP_BROWSING_MAX_FOLDER_NAME_LEN - 1);
287                     memcpy(value, packet+pos, value_len);
288 
289                     printf("UID 0x%08" PRIx32 "%08" PRIx32 ", type 0x%02x, is_playable %d, charset 0x%02x, name %s\n",
290                         folder_uid_high, folder_uid_low, folder_type, is_playable, charset, value);
291                     memcpy(folders[index].name, value, value_len);
292                     folders[index].name_len = value_len;
293                     break;
294                 }
295                 case AVRCP_BROWSING_MEDIA_ELEMENT_ITEM:{
296                     printf("Found media: ");
297 
298                     uint32_t media_uid_high = big_endian_read_32(packet, pos);
299                     pos += 4;
300                     uint32_t media_uid_low  = big_endian_read_32(packet, pos+4);
301                     pos += 4;
302                     avrcp_browsing_media_type_t media_type = packet[pos++];
303                     uint16_t charset = big_endian_read_16(packet, pos);
304                     pos += 2;
305                     uint16_t displayable_name_length = big_endian_read_16(packet, pos);
306                     pos += 2;
307                     pos += displayable_name_length;
308                     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);
309 
310                     uint8_t num_attributes = packet[pos++];
311                     printf("Num media attributes %d\n", num_attributes);
312 
313                     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)){
314                         uint32_t attr_id            = avrcp_media_item_iterator_get_attr_id(&media_item_context);
315                         uint16_t attr_charset       = avrcp_media_item_iterator_get_attr_charset(&media_item_context);
316                         uint16_t attr_value_length  = avrcp_media_item_iterator_get_attr_value_len(&media_item_context);
317                         const uint8_t * attr_value  = avrcp_media_item_iterator_get_attr_value(&media_item_context);
318 
319                         printf("Attr ID 0x%08" PRIx32 ", charset %d, attr_value_length %d, value %s", attr_id, attr_charset, attr_value_length, attr_value);
320                     }
321                     break;
322                 }
323 
324                 default:
325                     log_error("AVRCP browsing: unknown browsable item type 0%02x", data_type);
326                     break;
327             }
328             break;
329         case HCI_EVENT_PACKET:
330             if (hci_event_packet_get_type(packet) != HCI_EVENT_AVRCP_META) return;
331             uint16_t local_cid;
332             uint8_t  status = 0xFF;
333             bd_addr_t address;
334 
335             if (packet[0] != HCI_EVENT_AVRCP_META) break;
336             switch (packet[2]){
337                 case AVRCP_SUBEVENT_CONNECTION_ESTABLISHED: {
338                     local_cid = avrcp_subevent_connection_established_get_avrcp_cid(packet);
339                     printf("AVRCP_SUBEVENT_CONNECTION_ESTABLISHED cid 0x%02x\n", local_cid);
340 
341                     if (avrcp_cid != 0 && avrcp_cid != local_cid) {
342                         printf("AVRCP Controller connection failed, expected 0x%02X l2cap cid, received 0x%02X\n", avrcp_cid, local_cid);
343                         return;
344                     }
345 
346                     status = avrcp_subevent_connection_established_get_status(packet);
347                     if (status != ERROR_CODE_SUCCESS){
348                         printf("AVRCP Controller connection failed: status 0x%02x\n", status);
349                         avrcp_cid = 0;
350                         return;
351                     }
352 
353                     avrcp_cid = local_cid;
354                     avrcp_connected = 1;
355                     avrcp_subevent_connection_established_get_bd_addr(packet, address);
356                     printf("AVRCP Controller connected.\n");
357                     return;
358                 }
359                 case AVRCP_SUBEVENT_CONNECTION_RELEASED:
360                     printf("AVRCP Controller Client released.\n");
361                     avrcp_cid = 0;
362                     avrcp_browsing_connected = 0;
363                     folder_index = 0;
364                     memset(folders, 0, sizeof(folders));
365                     return;
366 
367                 case AVRCP_SUBEVENT_INCOMING_BROWSING_CONNECTION:
368                     local_cid = avrcp_subevent_incoming_browsing_connection_get_browsing_cid(packet);
369                     printf("AVRCP_SUBEVENT_INCOMING_BROWSING_CONNECTION cid 0x%02x\n", local_cid);
370                     if (browsing_cid != 0 && browsing_cid != local_cid) {
371                         printf("AVRCP Browsing Client connection failed, expected 0x%02X l2cap cid, received 0x%02X\n", browsing_cid, local_cid);
372                         avrcp_browsing_controller_decline_incoming_connection(browsing_cid);
373                         return;
374                     }
375                     browsing_cid = local_cid;
376                     printf("AVRCP Browsing Client configure incoming connection, browsing cid 0x%02x\n", browsing_cid);
377                     avrcp_browsing_controller_configure_incoming_connection(browsing_cid, ertm_buffer, sizeof(ertm_buffer), &ertm_config);
378                     break;
379 
380                 case AVRCP_SUBEVENT_BROWSING_CONNECTION_ESTABLISHED: {
381                     local_cid = avrcp_subevent_browsing_connection_established_get_browsing_cid(packet);
382                     printf("AVRCP_SUBEVENT_BROWSING_CONNECTION_ESTABLISHED cid 0x%02x\n", local_cid);
383                     if (browsing_cid != 0 && browsing_cid != local_cid) {
384                         printf("AVRCP Browsing Client connection failed, expected 0x%02X l2cap cid, received 0x%02X\n", browsing_cid, local_cid);
385                         return;
386                     }
387 
388                     status = avrcp_subevent_browsing_connection_established_get_status(packet);
389                     if (status != ERROR_CODE_SUCCESS){
390                         printf("AVRCP Browsing Client connection failed: status 0x%02x\n", status);
391                         browsing_cid = 0;
392                         return;
393                     }
394 
395                     browsing_cid = local_cid;
396                     avrcp_browsing_connected = 1;
397                     avrcp_subevent_browsing_connection_established_get_bd_addr(packet, address);
398                     printf("AVRCP Browsing Client connected\n");
399                     return;
400                 }
401                 case AVRCP_SUBEVENT_BROWSING_CONNECTION_RELEASED:
402                     printf("AVRCP Browsing Controller released\n");
403                     browsing_cid = 0;
404                     avrcp_browsing_connected = 0;
405                     return;
406 
407                 case AVRCP_SUBEVENT_BROWSING_DONE:
408                     browsing_query_active = 0;
409                     browsing_uid_counter = 0;
410                     if (avrcp_subevent_browsing_done_get_browsing_status(packet) != AVRCP_BROWSING_ERROR_CODE_SUCCESS){
411                         printf("AVRCP Browsing query done with browsing status 0x%02x, bluetooth status 0x%02x.\n",
412                             avrcp_subevent_browsing_done_get_browsing_status(packet),
413                             avrcp_subevent_browsing_done_get_bluetooth_status(packet));
414                         break;
415                     }
416                     browsing_uid_counter = avrcp_subevent_browsing_done_get_uid_counter(packet);
417                     printf("DONE, browsing_uid_counter %d.\n", browsing_uid_counter);
418                     break;
419 
420                 default:
421                     break;
422             }
423             break;
424 
425         default:
426             break;
427     }
428 
429 }
430 
431 #ifdef HAVE_BTSTACK_STDIN
432 static void show_usage(void){
433     bd_addr_t      iut_address;
434     gap_local_bd_addr(iut_address);
435     printf("\n--- Bluetooth AVRCP Controller Connection Test Console %s ---\n", bd_addr_to_str(iut_address));
436     printf("c      - AVRCP Controller create connection to addr %s\n", bd_addr_to_str(device_addr));
437     printf("e      - AVRCP Browsing Controller create connection to addr %s\n", bd_addr_to_str(device_addr));
438     printf("E      - AVRCP Browsing Controller disconnect\n");
439     printf("C      - AVRCP Controller disconnect\n");
440 
441     printf("I      - Set first found player as addressed player\n");
442     printf("O      - Set first found player as browsed player\n");
443 
444     printf("p      - Get media players\n");
445     printf("Q      - Browse folders\n");
446     printf("P      - Go up one level\n");
447     printf("W      - Go down one level\n");
448     printf("T      - Browse media items\n");
449     printf("---\n");
450 }
451 #endif
452 
453 
454 #ifdef HAVE_BTSTACK_STDIN
455 static void stdin_process(char cmd){
456     uint8_t status = ERROR_CODE_SUCCESS;
457 
458     if (cmd != 'a' && cmd != 'A' && cmd != 'c' && cmd != 'C'){
459         if (browsing_query_active){
460             printf("Query active, try later!\n");
461             return;
462         }
463     }
464 
465     switch (cmd){
466         case 'c':
467             printf(" - Create AVRCP connection for control to addr %s.\n", bd_addr_to_str(device_addr));
468             status = avrcp_controller_connect(device_addr, &avrcp_cid);
469             break;
470         case 'C':
471             if (avrcp_connected){
472                 printf(" - AVRCP Controller disconnect from addr %s.\n", bd_addr_to_str(device_addr));
473                 status = avrcp_controller_disconnect(avrcp_cid);
474                 break;
475             }
476             printf("AVRCP Controller already disconnected\n");
477             break;
478 
479         case 'e':
480             if (!avrcp_connected) {
481                 printf(" You must first create AVRCP connection for control to addr %s.\n", bd_addr_to_str(device_addr));
482                 break;
483             }
484             printf(" - Create AVRCP connection for browsing to addr %s.\n", bd_addr_to_str(device_addr));
485             status = avrcp_browsing_controller_connect(device_addr, ertm_buffer, sizeof(ertm_buffer), &ertm_config, &browsing_cid);
486             break;
487         case 'E':
488             if (avrcp_browsing_connected){
489                 printf(" - AVRCP Browsing Controller disconnect from addr %s.\n", bd_addr_to_str(device_addr));
490                 status = avrcp_browsing_controller_disconnect(browsing_cid);
491                 break;
492             }
493             printf("AVRCP Browsing Controller already disconnected\n");
494             break;
495         case '\n':
496         case '\r':
497             break;
498 
499         default:
500             if (!avrcp_browsing_connected){
501                 show_usage();
502                 printf("Please connect the AVRCP Browsing client\n");
503                 break;
504             }
505 
506             switch (cmd) {
507                 case 'I':
508                     if (player_index < 0) {
509                         printf("Get media players first\n");
510                         break;
511                     }
512                     printf("Set addressed player\n");
513                     status = avrcp_controller_set_addressed_player(avrcp_cid, players[0]);
514                     break;
515                 case 'O':
516                     if (player_index < 0) {
517                         printf("Get media players first\n");
518                         break;
519                     }
520                     printf("Set browsed player\n");
521                     status = avrcp_browsing_controller_set_browsed_player(browsing_cid, players[0]);
522                     break;
523                 case 'p':
524                     printf("AVRCP Browsing: get media players\n");
525                     player_index = -1;
526                     status = avrcp_browsing_controller_get_media_players(browsing_cid, 0, 0xFFFFFFFF, AVRCP_MEDIA_ATTR_ALL);
527                     break;
528                 case 'Q':
529                     printf("AVRCP Browsing: browse folders\n");
530                     folder_index = -1;
531                     status = avrcp_browsing_controller_browse_file_system(browsing_cid, 0, 0xFFFFFFFF, AVRCP_MEDIA_ATTR_ALL);
532                     break;
533                 case 'P':
534                     printf("AVRCP Browsing: browse media items\n");
535                     avrcp_browsing_controller_browse_media(browsing_cid, 0, 0xFFFFFFFF, AVRCP_MEDIA_ATTR_ALL);
536                     break;
537                 case 'W':
538                     printf("AVRCP Browsing: go up one level\n");
539                     status = avrcp_browsing_controller_go_up_one_level(browsing_cid);
540                     folder_index = -1;
541                     break;
542                 case 'T':
543                     if (folder_index < 0 && !parent_folder_set){
544                         printf("AVRCP Browsing: no folders available\n");
545                         break;
546                     }
547                     if (!parent_folder_set){
548                         parent_folder_set = 1;
549                         memcpy(parent_folder_name, folders[0].name, folders[0].name_len);
550                         memcpy(parent_folder_uid, folders[0].uid, 8);
551                     }
552                     printf("AVRCP Browsing: go down one level of %s\n", (char *)parent_folder_name);
553                     status = avrcp_browsing_controller_go_down_one_level(browsing_cid, parent_folder_uid);
554                     folder_index = -1;
555                     break;
556                 default:
557                     show_usage();
558                     break;
559             }
560             break;
561     }
562 
563     if (status != ERROR_CODE_SUCCESS){
564         printf("Could not perform command, status 0x%2x\n", status);
565     }
566 }
567 #endif
568 /* EXAMPLE_END */
569