xref: /btstack/src/classic/avrcp_browsing_target.c (revision 5d5682b540a258f388ba53e7bc02a284b2675a2c)
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 BLUEKITCHEN
24  * GMBH 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_target.c"
39 
40 #include <stdint.h>
41 #include <string.h>
42 #include <inttypes.h>
43 #include "classic/avrcp.h"
44 #include "classic/avrcp_browsing.h"
45 #include "classic/avrcp_browsing_target.h"
46 #include "classic/avrcp_target.h"
47 #include "classic/avrcp_controller.h"
48 
49 #include "bluetooth_sdp.h"
50 #include "btstack_debug.h"
51 #include "btstack_event.h"
52 
53 static void avrcp_browsing_target_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
54 
55 static int avrcp_browsing_target_handle_can_send_now(avrcp_browsing_connection_t * connection){
56     int pos = 0;
57 
58     // l2cap_reserve_packet_buffer();
59     // uint8_t * packet = l2cap_get_outgoing_buffer();
60     uint8_t packet[400];
61     connection->packet_type = AVRCP_SINGLE_PACKET;
62 
63     packet[pos++] = (connection->transaction_label << 4) | (connection->packet_type << 2) | (AVRCP_RESPONSE_FRAME << 1) | 0;
64     // Profile IDentifier (PID)
65     packet[pos++] = BLUETOOTH_SERVICE_CLASS_AV_REMOTE_CONTROL >> 8;
66     packet[pos++] = BLUETOOTH_SERVICE_CLASS_AV_REMOTE_CONTROL & 0x00FF;
67     (void)memcpy(packet + pos, connection->cmd_operands,
68                  connection->cmd_operands_length);
69 
70     pos += connection->cmd_operands_length;
71     connection->wait_to_send = false;
72     // return l2cap_send_prepared(connection->l2cap_browsing_cid, pos);
73     return l2cap_send(connection->l2cap_browsing_cid, packet, pos);
74 }
75 
76 
77 static uint8_t avrcp_browsing_target_response_general_reject(avrcp_browsing_connection_t * connection, avrcp_status_code_t status){
78     // AVRCP_CTYPE_RESPONSE_REJECTED
79     int pos = 0;
80     connection->cmd_operands[pos++] = AVRCP_PDU_ID_GENERAL_REJECT;
81     // connection->message_body[pos++] = 0;
82     // param length
83     big_endian_store_16(connection->cmd_operands, pos, 1);
84     pos += 2;
85     connection->cmd_operands[pos++] = status;
86     connection->cmd_operands_length = 4;
87     connection->state = AVCTP_W2_SEND_RESPONSE;
88     avrcp_browsing_request_can_send_now(connection, connection->l2cap_browsing_cid);
89     return ERROR_CODE_SUCCESS;
90 }
91 
92 static void avrcp_browsing_target_emit_get_folder_items(btstack_packet_handler_t callback, uint16_t browsing_cid, avrcp_browsing_connection_t * connection){
93     btstack_assert(callback != NULL);
94 
95     uint8_t event[18];
96     int pos = 0;
97     event[pos++] = HCI_EVENT_AVRCP_META;
98     event[pos++] = sizeof(event) - 2;
99     event[pos++] = AVRCP_SUBEVENT_BROWSING_GET_FOLDER_ITEMS;
100     little_endian_store_16(event, pos, browsing_cid);
101     pos += 2;
102     event[pos++] = connection->scope;
103     big_endian_store_32(event, pos, connection->start_item);
104     pos += 4;
105     big_endian_store_32(event, pos, connection->end_item);
106     pos += 4;
107     big_endian_store_32(event, pos, connection->attr_bitmap);
108     pos += 4;
109     (*callback)(HCI_EVENT_PACKET, 0, event, pos);
110 }
111 
112 static void avrcp_browsing_target_emit_get_total_num_items(btstack_packet_handler_t callback, uint16_t browsing_cid, avrcp_browsing_connection_t * connection){
113     btstack_assert(callback != NULL);
114 
115     uint8_t event[10];
116     int pos = 0;
117     event[pos++] = HCI_EVENT_AVRCP_META;
118     event[pos++] = sizeof(event) - 2;
119     event[pos++] = AVRCP_SUBEVENT_BROWSING_GET_TOTAL_NUM_ITEMS;
120     little_endian_store_16(event, pos, browsing_cid);
121     pos += 2;
122     event[pos++] = connection->scope;
123     (*callback)(HCI_EVENT_PACKET, 0, event, pos);
124 }
125 
126 static void avrcp_browsing_target_emit_set_browsed_player(btstack_packet_handler_t callback, uint16_t browsing_cid, uint16_t browsed_player_id){
127     btstack_assert(callback != NULL);
128 
129     uint8_t event[10];
130     int pos = 0;
131     event[pos++] = HCI_EVENT_AVRCP_META;
132     event[pos++] = sizeof(event) - 2;
133     event[pos++] = AVRCP_SUBEVENT_BROWSING_SET_BROWSED_PLAYER;
134     little_endian_store_16(event, pos, browsing_cid);
135     pos += 2;
136     little_endian_store_16(event, pos, browsed_player_id);
137     pos += 2;
138     (*callback)(HCI_EVENT_PACKET, 0, event, pos);
139 }
140 
141 static void avrcp_browsing_target_emit_change_path(btstack_packet_handler_t callback, uint16_t browsing_cid, uint16_t uid_counter, avrcp_browsing_direction_t direction, uint8_t * item_id){
142     btstack_assert(callback != NULL);
143 
144     uint8_t event[19];
145     int pos = 0;
146     event[pos++] = HCI_EVENT_AVRCP_META;
147     event[pos++] = sizeof(event) - 2;
148     event[pos++] = AVRCP_SUBEVENT_BROWSING_CHANGE_PATH;
149     little_endian_store_16(event, pos, browsing_cid);
150     pos += 2;
151     little_endian_store_16(event, pos, uid_counter);
152     pos += 2;
153     event[pos++] = direction;
154     memcpy(&event[pos], item_id, 8);
155     pos += 8;
156     (*callback)(HCI_EVENT_PACKET, 0, event, pos);
157 }
158 
159 
160 static void avrcp_browsing_target_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
161     UNUSED(size);
162     avrcp_browsing_connection_t * browsing_connection;
163     avrcp_browsing_direction_t direction;
164     uint16_t uid_counter;
165     uint8_t * item_id;
166 
167     switch (packet_type) {
168         case L2CAP_DATA_PACKET:{
169             browsing_connection = avrcp_get_browsing_connection_for_l2cap_cid_for_role(AVRCP_TARGET, channel);
170             if (!browsing_connection) break;
171             int pos = 0;
172             uint8_t transport_header = packet[pos++];
173             // Transaction label | Packet_type | C/R | IPID (1 == invalid profile identifier)
174             browsing_connection->transaction_label = transport_header >> 4;
175             avctp_packet_type_t avctp_packet_type = (avctp_packet_type_t)((transport_header & 0x0F) >> 2);
176             switch (avctp_packet_type){
177                 case AVCTP_SINGLE_PACKET:
178                 case AVCTP_START_PACKET:
179                     browsing_connection->subunit_type = packet[pos++] >> 2;
180                     browsing_connection->subunit_id = 0;
181                     browsing_connection->command_opcode = packet[pos++];
182                     browsing_connection->num_packets = 1;
183                     if (avctp_packet_type == AVCTP_START_PACKET){
184                         browsing_connection->num_packets = packet[pos++];
185                     }
186                     browsing_connection->pdu_id = packet[pos++];
187                     uint16_t parameter_length = big_endian_read_16(packet, pos);
188                     pos += 2;
189 
190                     switch(browsing_connection->pdu_id){
191                         case AVRCP_PDU_ID_GET_FOLDER_ITEMS:
192                             if (parameter_length < 10){
193                                 avrcp_browsing_target_response_general_reject(browsing_connection, AVRCP_STATUS_INVALID_COMMAND);
194                                 break;
195                             }
196 
197                             browsing_connection->scope = packet[pos++];
198                             browsing_connection->start_item = big_endian_read_32(packet, pos);
199                             pos += 4;
200                             browsing_connection->end_item = big_endian_read_32(packet, pos);
201                             pos += 4;
202                             uint8_t attr_count = packet[pos++];
203                             browsing_connection->attr_bitmap = 0;
204 
205                             while (attr_count){
206                                 uint32_t attr_id = big_endian_read_32(packet, pos);
207                                 pos += 4;
208                                 browsing_connection->attr_bitmap |= (1 << attr_id);
209                                 attr_count--;
210                             }
211                             avrcp_browsing_target_emit_get_folder_items(avrcp_target_context.browsing_avrcp_callback, channel, browsing_connection);
212                             break;
213 
214                         case AVRCP_PDU_ID_GET_TOTAL_NUMBER_OF_ITEMS:{
215                             // send total num items
216                             if (parameter_length != 1){
217                                 avrcp_browsing_target_response_general_reject(browsing_connection, AVRCP_STATUS_INVALID_SCOPE);
218                                 break;
219                             }
220 
221                             browsing_connection->scope = packet[pos++];
222                             avrcp_browsing_target_emit_get_total_num_items(avrcp_target_context.browsing_avrcp_callback, channel, browsing_connection);
223                             break;
224                         }
225                         case AVRCP_PDU_ID_SET_BROWSED_PLAYER:
226                             // player_id (2)
227                             if (parameter_length != 2){
228                                 avrcp_browsing_target_response_general_reject(browsing_connection, AVRCP_STATUS_INVALID_COMMAND);
229                                 break;
230                             }
231                             if ( (pos + 2) > size ){
232                                 avrcp_browsing_target_response_general_reject(browsing_connection, AVRCP_STATUS_INVALID_PLAYER_ID);
233                                 break;
234                             }
235                             avrcp_browsing_target_emit_set_browsed_player(avrcp_target_context.browsing_avrcp_callback, channel, big_endian_read_16(packet, pos));
236                             break;
237 
238                         case AVRCP_PDU_ID_CHANGE_PATH:
239                             // one level up or down in the virtual filesystem
240                             if (parameter_length != 11){
241                                 avrcp_browsing_target_response_general_reject(browsing_connection, AVRCP_STATUS_INVALID_COMMAND);
242                                 break;
243                             }
244                             uid_counter = big_endian_read_16(packet, pos);
245                             pos += 2;
246                             direction = (avrcp_browsing_direction_t)packet[pos++];
247 
248                             if (direction > AVRCP_BROWSING_DIRECTION_FOLDER_RFU){
249                                 avrcp_browsing_target_response_general_reject(browsing_connection, AVRCP_STATUS_INVALID_DIRECTION);
250                                 break;
251                             }
252                             item_id = &packet[pos];
253                             avrcp_browsing_target_emit_change_path(avrcp_target_context.browsing_avrcp_callback, channel, uid_counter, direction, item_id);
254                             break;
255 
256                         default:
257                             avrcp_browsing_target_response_general_reject(browsing_connection, AVRCP_STATUS_INVALID_COMMAND);
258                             log_info("not parsed pdu ID 0x%02x", browsing_connection->pdu_id);
259                             break;
260                     }
261                     browsing_connection->state = AVCTP_CONNECTION_OPENED;
262                     break;
263 
264                 default:
265                     break;
266             }
267             break;
268         }
269 
270         case HCI_EVENT_PACKET:
271             switch (hci_event_packet_get_type(packet)){
272                 case L2CAP_EVENT_CAN_SEND_NOW:
273                     browsing_connection = avrcp_get_browsing_connection_for_l2cap_cid_for_role(AVRCP_TARGET, channel);
274                     if (browsing_connection->state != AVCTP_W2_SEND_RESPONSE) return;
275                     browsing_connection->state = AVCTP_CONNECTION_OPENED;
276                     avrcp_browsing_target_handle_can_send_now(browsing_connection);
277                     break;
278                 default:
279                     break;
280             }
281             break;
282 
283         default:
284             break;
285     }
286 }
287 
288 void avrcp_browsing_target_init(void){
289     avrcp_target_context.browsing_packet_handler = avrcp_browsing_target_packet_handler;
290     avrcp_browsing_register_target_packet_handler(avrcp_browsing_target_packet_handler);
291 }
292 
293 void avrcp_browsing_target_deinit(void){
294     avrcp_controller_context.browsing_packet_handler = NULL;
295 }
296 
297 void avrcp_browsing_target_register_packet_handler(btstack_packet_handler_t callback){
298     btstack_assert(callback != NULL);
299     avrcp_target_context.browsing_avrcp_callback = callback;
300 }
301 
302 uint8_t avrcp_browsing_target_send_get_folder_items_response(uint16_t avrcp_browsing_cid, uint16_t uid_counter, uint8_t * attr_list, uint16_t attr_list_size, uint16_t num_items){
303     avrcp_connection_t * avrcp_connection = avrcp_get_connection_for_browsing_cid_for_role(AVRCP_TARGET, avrcp_browsing_cid);
304     if (!avrcp_connection){
305         log_error("Could not find an AVRCP Target connection for browsing_cid 0x%02x.", avrcp_browsing_cid);
306         return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
307     }
308 
309     avrcp_browsing_connection_t * connection = avrcp_connection->browsing_connection;
310     if (!connection){
311         log_info("Could not find a browsing connection.");
312         return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
313     }
314     if (connection->state != AVCTP_CONNECTION_OPENED){
315         return ERROR_CODE_COMMAND_DISALLOWED;
316     }
317 
318     // TODO: handle response to SetAddressedPlayer
319 
320     uint16_t pos = 0;
321     connection->cmd_operands[pos++] = AVRCP_PDU_ID_GET_FOLDER_ITEMS;
322     uint8_t param_length = 5;
323     uint8_t param_length_pos = pos;
324     pos += 2;
325 
326     avrcp_status_code_t status = AVRCP_STATUS_SUCCESS;
327     uint8_t status_pos = pos;
328     pos++;
329 
330     big_endian_store_16(connection->cmd_operands, pos, uid_counter);
331     pos += 2;
332 
333     // TODO: fragmentation
334     if (attr_list_size >  sizeof(connection->cmd_operands)){
335         connection->attr_list = attr_list;
336         connection->attr_list_size = attr_list_size;
337         log_info(" todo: list too big, invoke fragmentation");
338         return 1;
339     }
340 
341     uint16_t items_byte_len = 0;
342     if (connection->start_item < num_items) {
343         if (connection->end_item < num_items) {
344             items_byte_len =  connection->end_item - connection->start_item + 1;
345         } else {
346             items_byte_len = num_items - connection->start_item;
347         }
348 
349     } else {
350         big_endian_store_16(connection->cmd_operands, pos, 0);
351         pos += 2;
352     }
353     big_endian_store_16(connection->cmd_operands, pos, items_byte_len);
354     pos += 2;
355     param_length += items_byte_len;
356 
357     if (items_byte_len > 0){
358         (void)memcpy(&connection->cmd_operands[pos], attr_list, attr_list_size);
359         pos += attr_list_size;
360     } else {
361         status = AVRCP_STATUS_RANGE_OUT_OF_BOUNDS;
362     }
363 
364     big_endian_store_16(connection->cmd_operands, param_length_pos, param_length);
365     connection->cmd_operands[status_pos] = status;
366 
367     btstack_assert(pos <= 400);
368     connection->cmd_operands_length = pos;
369 
370     connection->state = AVCTP_W2_SEND_RESPONSE;
371     avrcp_browsing_request_can_send_now(connection, connection->l2cap_browsing_cid);
372     return ERROR_CODE_SUCCESS;
373 }
374 
375 uint8_t avrcp_browsing_target_send_change_path_response(uint16_t avrcp_browsing_cid, uint16_t uid_counter, avrcp_status_code_t status, uint32_t num_items){
376     avrcp_connection_t * avrcp_connection = avrcp_get_connection_for_browsing_cid_for_role(AVRCP_TARGET, avrcp_browsing_cid);
377     if (!avrcp_connection){
378         log_error("Could not find an AVRCP Target connection for browsing_cid 0x%02x.", avrcp_browsing_cid);
379         return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
380     }
381 
382     avrcp_browsing_connection_t * connection = avrcp_connection->browsing_connection;
383     if (!connection){
384         log_info("Could not find a browsing connection.");
385         return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
386     }
387     if (connection->state != AVCTP_CONNECTION_OPENED){
388         return ERROR_CODE_COMMAND_DISALLOWED;
389     }
390 
391     uint16_t pos = 0;
392     connection->cmd_operands[pos++] = AVRCP_PDU_ID_CHANGE_PATH;
393     // Param length
394     big_endian_store_16(connection->cmd_operands, pos, 5);
395     pos += 2;
396     connection->cmd_operands[pos++] = status;
397     big_endian_store_32(connection->cmd_operands, pos, num_items);
398 
399     connection->state = AVCTP_W2_SEND_RESPONSE;
400     avrcp_browsing_request_can_send_now(connection, connection->l2cap_browsing_cid);
401     return ERROR_CODE_SUCCESS;
402 }
403 
404 uint8_t avrcp_browsing_target_send_accept_set_browsed_player(uint16_t avrcp_browsing_cid, uint16_t uid_counter, uint16_t browsed_player_id, uint8_t * response, uint16_t response_size){
405     avrcp_connection_t * avrcp_connection = avrcp_get_connection_for_browsing_cid_for_role(AVRCP_TARGET, avrcp_browsing_cid);
406     if (!avrcp_connection){
407         log_error("Could not find an AVRCP Target connection for browsing_cid 0x%02x.", avrcp_browsing_cid);
408         return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
409     }
410 
411     avrcp_browsing_connection_t * connection = avrcp_connection->browsing_connection;
412     if (!connection){
413         log_info("Could not find a browsing connection.");
414         return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
415     }
416 
417     if (connection->state != AVCTP_CONNECTION_OPENED) {
418         log_info("Browsing connection wrong state.");
419         return ERROR_CODE_COMMAND_DISALLOWED;
420     }
421 
422     connection->browsed_player_id = browsed_player_id;
423 
424     uint16_t pos = 0;
425     connection->cmd_operands[pos++] = AVRCP_PDU_ID_SET_BROWSED_PLAYER;
426     big_endian_store_16(connection->cmd_operands, pos, response_size + 2 + 1); // uuid counter + status
427     pos += 2;
428 
429     connection->cmd_operands[pos++] = AVRCP_STATUS_SUCCESS;
430     big_endian_store_16(connection->cmd_operands, pos, uid_counter);
431     pos += 2;
432 
433     // TODO: fragmentation
434     if (response_size >  sizeof(connection->cmd_operands)){
435         connection->attr_list = response;
436         connection->attr_list_size = response_size;
437         log_info(" todo: list too big, invoke fragmentation");
438         return 1;
439     }
440 
441     (void)memcpy(&connection->cmd_operands[pos], response, response_size);
442     pos += response_size;
443 	btstack_assert(pos <= 255);
444     connection->cmd_operands_length = (uint8_t) pos;
445 
446     connection->state = AVCTP_W2_SEND_RESPONSE;
447     avrcp_browsing_request_can_send_now(connection, connection->l2cap_browsing_cid);
448     return ERROR_CODE_SUCCESS;
449 }
450 
451 uint8_t avrcp_browsing_target_send_reject_set_browsed_player(uint16_t avrcp_browsing_cid, avrcp_status_code_t status){
452     avrcp_connection_t * avrcp_connection = avrcp_get_connection_for_browsing_cid_for_role(AVRCP_TARGET, avrcp_browsing_cid);
453     if (!avrcp_connection){
454         log_error("Could not find an AVRCP Target connection for browsing_cid 0x%02x.", avrcp_browsing_cid);
455         return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
456     }
457 
458     avrcp_browsing_connection_t * connection = avrcp_connection->browsing_connection;
459     if (!connection){
460         log_info("Could not find a browsing connection.");
461         return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
462     }
463 
464     if (connection->state != AVCTP_CONNECTION_OPENED) {
465         log_info("Browsing connection wrong state.");
466         return ERROR_CODE_COMMAND_DISALLOWED;
467     }
468 
469     int pos = 0;
470     connection->cmd_operands[pos++] = AVRCP_PDU_ID_SET_BROWSED_PLAYER;
471     big_endian_store_16(connection->cmd_operands, pos, 1);
472     pos += 2;
473     connection->cmd_operands[pos++] = status;
474     connection->cmd_operands_length = pos;
475 
476     connection->state = AVCTP_W2_SEND_RESPONSE;
477     avrcp_browsing_request_can_send_now(connection, connection->l2cap_browsing_cid);
478     return ERROR_CODE_SUCCESS;
479 }
480 
481 uint8_t avrcp_browsing_target_send_get_total_num_items_response(uint16_t avrcp_browsing_cid, uint16_t uid_counter, uint32_t total_num_items){
482     avrcp_connection_t * avrcp_connection = avrcp_get_connection_for_browsing_cid_for_role(AVRCP_TARGET, avrcp_browsing_cid);
483     if (!avrcp_connection){
484         log_error("Could not find an AVRCP Target connection for browsing_cid 0x%02x.", avrcp_browsing_cid);
485         return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
486     }
487 
488     avrcp_browsing_connection_t * connection = avrcp_connection->browsing_connection;
489     if (!connection){
490         log_info("Could not find a browsing connection.");
491         return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
492     }
493 
494     if (connection->state != AVCTP_CONNECTION_OPENED) {
495         log_info("Browsing connection wrong state.");
496         return ERROR_CODE_COMMAND_DISALLOWED;
497     }
498 
499     int pos = 0;
500     connection->cmd_operands[pos++] = AVRCP_PDU_ID_GET_TOTAL_NUMBER_OF_ITEMS;
501     big_endian_store_16(connection->cmd_operands, pos, 7);
502     pos += 2;
503     connection->cmd_operands[pos++] = AVRCP_STATUS_SUCCESS;
504     big_endian_store_16(connection->cmd_operands, pos, uid_counter);
505     pos += 2;
506     big_endian_store_32(connection->cmd_operands, pos, total_num_items);
507     pos += 4;
508     connection->cmd_operands_length = pos;
509 
510     connection->state = AVCTP_W2_SEND_RESPONSE;
511     avrcp_browsing_request_can_send_now(connection, connection->l2cap_browsing_cid);
512     return ERROR_CODE_SUCCESS;
513 }
514 
515