• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (c) 2014 The Android Open Source Project
4  *  Copyright (C) 2009-2016 Broadcom Corporation
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at:
9  *
10  *  http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  ******************************************************************************/
19 
20 /*******************************************************************************
21  *
22  *  Filename:      btif_util.c
23  *
24  *  Description:   Miscellaneous helper functions
25  *
26  *
27  ******************************************************************************/
28 
29 #define LOG_TAG "bt_btif_util"
30 
31 #include "btif_util.h"
32 
33 #include <base/logging.h>
34 #include <ctype.h>
35 #include <netinet/in.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 
40 #include <hardware/bt_av.h>
41 
42 #include "avrc_defs.h"
43 #include "bt_common.h"
44 #include "bta_ag_api.h"
45 #include "bta_api.h"
46 #include "bta_av_api.h"
47 #include "bta_hd_api.h"
48 #include "bta_hf_client_api.h"
49 #include "bta_hh_api.h"
50 #include "bte.h"
51 #include "btif_common.h"
52 #include "btif_dm.h"
53 #include "btu.h"
54 
55 /*******************************************************************************
56  *  Constants & Macros
57  ******************************************************************************/
58 #define ISDIGIT(a) (((a) >= '0') && ((a) <= '9'))
59 #define ISXDIGIT(a)                                                    \
60   ((((a) >= '0') && ((a) <= '9')) || (((a) >= 'A') && ((a) <= 'F')) || \
61    (((a) >= 'a') && ((a) <= 'f')))
62 
63 /*******************************************************************************
64  *  Local type definitions
65  ******************************************************************************/
66 
67 /*******************************************************************************
68  *  Static variables
69  ******************************************************************************/
70 
71 /*******************************************************************************
72  *  Static functions
73  ******************************************************************************/
74 
75 /*******************************************************************************
76  *  Externs
77  ******************************************************************************/
78 
79 /*******************************************************************************
80  *  Functions
81  ******************************************************************************/
82 
83 /*****************************************************************************
84  *   Logging helper functions
85  ****************************************************************************/
86 
devclass2uint(DEV_CLASS dev_class)87 uint32_t devclass2uint(DEV_CLASS dev_class) {
88   uint32_t cod = 0;
89 
90   if (dev_class != NULL) {
91     /* if COD is 0, irrespective of the device type set it to Unclassified
92      * device */
93     cod = (dev_class[2]) | (dev_class[1] << 8) | (dev_class[0] << 16);
94   }
95   return cod;
96 }
uint2devclass(uint32_t cod,DEV_CLASS dev_class)97 void uint2devclass(uint32_t cod, DEV_CLASS dev_class) {
98   dev_class[2] = (uint8_t)cod;
99   dev_class[1] = (uint8_t)(cod >> 8);
100   dev_class[0] = (uint8_t)(cod >> 16);
101 }
102 
103 static const uint8_t sdp_base_uuid[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
104                                         0x10, 0x00, 0x80, 0x00, 0x00, 0x80,
105                                         0x5F, 0x9B, 0x34, 0xFB};
106 
uuid16_to_uuid128(uint16_t uuid16,bt_uuid_t * uuid128)107 void uuid16_to_uuid128(uint16_t uuid16, bt_uuid_t* uuid128) {
108   uint16_t uuid16_bo;
109   memset(uuid128, 0, sizeof(bt_uuid_t));
110 
111   memcpy(uuid128->uu, sdp_base_uuid, MAX_UUID_SIZE);
112   uuid16_bo = ntohs(uuid16);
113   memcpy(uuid128->uu + 2, &uuid16_bo, sizeof(uint16_t));
114 }
115 
string_to_uuid(const char * str,bt_uuid_t * p_uuid)116 bool string_to_uuid(const char* str, bt_uuid_t* p_uuid) {
117   CHECK(p_uuid);
118   if (str == NULL) return false;
119 
120   uint32_t uuid0, uuid4;
121   uint16_t uuid1, uuid2, uuid3, uuid5;
122 
123   int rc = sscanf(str, "%08x-%04hx-%04hx-%04hx-%08x%04hx", &uuid0, &uuid1,
124                   &uuid2, &uuid3, &uuid4, &uuid5);
125   if (rc != 6) return false;
126 
127   uuid0 = htonl(uuid0);
128   uuid1 = htons(uuid1);
129   uuid2 = htons(uuid2);
130   uuid3 = htons(uuid3);
131   uuid4 = htonl(uuid4);
132   uuid5 = htons(uuid5);
133 
134   memcpy(&(p_uuid->uu[0]), &uuid0, 4);
135   memcpy(&(p_uuid->uu[4]), &uuid1, 2);
136   memcpy(&(p_uuid->uu[6]), &uuid2, 2);
137   memcpy(&(p_uuid->uu[8]), &uuid3, 2);
138   memcpy(&(p_uuid->uu[10]), &uuid4, 4);
139   memcpy(&(p_uuid->uu[14]), &uuid5, 2);
140 
141   return true;
142 }
143 
uuid_to_string_legacy(bt_uuid_t * p_uuid,char * str,size_t str_len)144 void uuid_to_string_legacy(bt_uuid_t* p_uuid, char* str, size_t str_len) {
145   uint32_t uuid0, uuid4;
146   uint16_t uuid1, uuid2, uuid3, uuid5;
147 
148   memcpy(&uuid0, &(p_uuid->uu[0]), 4);
149   memcpy(&uuid1, &(p_uuid->uu[4]), 2);
150   memcpy(&uuid2, &(p_uuid->uu[6]), 2);
151   memcpy(&uuid3, &(p_uuid->uu[8]), 2);
152   memcpy(&uuid4, &(p_uuid->uu[10]), 4);
153   memcpy(&uuid5, &(p_uuid->uu[14]), 2);
154 
155   snprintf(str, str_len, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x", ntohl(uuid0),
156            ntohs(uuid1), ntohs(uuid2), ntohs(uuid3), ntohl(uuid4),
157            ntohs(uuid5));
158   return;
159 }
160 
161 /*****************************************************************************
162  *  Function        ascii_2_hex
163  *
164  *  Description     This function converts an ASCII string into HEX
165  *
166  *  Returns         the number of hex bytes filled.
167 */
ascii_2_hex(const char * p_ascii,int len,uint8_t * p_hex)168 int ascii_2_hex(const char* p_ascii, int len, uint8_t* p_hex) {
169   int x;
170   uint8_t c;
171 
172   for (x = 0; (x < len) && (*p_ascii); x++) {
173     if (ISDIGIT(*p_ascii))
174       c = (*p_ascii - '0') << 4;
175     else
176       c = (toupper(*p_ascii) - 'A' + 10) << 4;
177 
178     p_ascii++;
179     if (*p_ascii) {
180       if (ISDIGIT(*p_ascii))
181         c |= (*p_ascii - '0');
182       else
183         c |= (toupper(*p_ascii) - 'A' + 10);
184 
185       p_ascii++;
186     }
187     *p_hex++ = c;
188   }
189 
190   return (x);
191 }
192 
dump_dm_search_event(uint16_t event)193 const char* dump_dm_search_event(uint16_t event) {
194   switch (event) {
195     CASE_RETURN_STR(BTA_DM_INQ_RES_EVT)
196     CASE_RETURN_STR(BTA_DM_INQ_CMPL_EVT)
197     CASE_RETURN_STR(BTA_DM_DISC_RES_EVT)
198     CASE_RETURN_STR(BTA_DM_DISC_BLE_RES_EVT)
199     CASE_RETURN_STR(BTA_DM_DISC_CMPL_EVT)
200     CASE_RETURN_STR(BTA_DM_DI_DISC_CMPL_EVT)
201     CASE_RETURN_STR(BTA_DM_SEARCH_CANCEL_CMPL_EVT)
202 
203     default:
204       return "UNKNOWN MSG ID";
205   }
206 }
207 
dump_property_type(bt_property_type_t type)208 const char* dump_property_type(bt_property_type_t type) {
209   switch (type) {
210     CASE_RETURN_STR(BT_PROPERTY_BDNAME)
211     CASE_RETURN_STR(BT_PROPERTY_BDADDR)
212     CASE_RETURN_STR(BT_PROPERTY_UUIDS)
213     CASE_RETURN_STR(BT_PROPERTY_CLASS_OF_DEVICE)
214     CASE_RETURN_STR(BT_PROPERTY_TYPE_OF_DEVICE)
215     CASE_RETURN_STR(BT_PROPERTY_REMOTE_RSSI)
216     CASE_RETURN_STR(BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT)
217     CASE_RETURN_STR(BT_PROPERTY_ADAPTER_BONDED_DEVICES)
218     CASE_RETURN_STR(BT_PROPERTY_ADAPTER_SCAN_MODE)
219     CASE_RETURN_STR(BT_PROPERTY_REMOTE_FRIENDLY_NAME)
220 
221     default:
222       return "UNKNOWN PROPERTY ID";
223   }
224 }
225 
dump_dm_event(uint16_t event)226 const char* dump_dm_event(uint16_t event) {
227   switch (event) {
228     CASE_RETURN_STR(BTA_DM_ENABLE_EVT)
229     CASE_RETURN_STR(BTA_DM_DISABLE_EVT)
230     CASE_RETURN_STR(BTA_DM_PIN_REQ_EVT)
231     CASE_RETURN_STR(BTA_DM_AUTH_CMPL_EVT)
232     CASE_RETURN_STR(BTA_DM_AUTHORIZE_EVT)
233     CASE_RETURN_STR(BTA_DM_LINK_UP_EVT)
234     CASE_RETURN_STR(BTA_DM_LINK_DOWN_EVT)
235     CASE_RETURN_STR(BTA_DM_SIG_STRENGTH_EVT)
236     CASE_RETURN_STR(BTA_DM_BUSY_LEVEL_EVT)
237     CASE_RETURN_STR(BTA_DM_BOND_CANCEL_CMPL_EVT)
238     CASE_RETURN_STR(BTA_DM_SP_CFM_REQ_EVT)
239     CASE_RETURN_STR(BTA_DM_SP_KEY_NOTIF_EVT)
240     CASE_RETURN_STR(BTA_DM_SP_RMT_OOB_EVT)
241     CASE_RETURN_STR(BTA_DM_SP_KEYPRESS_EVT)
242     CASE_RETURN_STR(BTA_DM_ROLE_CHG_EVT)
243     CASE_RETURN_STR(BTA_DM_BLE_KEY_EVT)
244     CASE_RETURN_STR(BTA_DM_BLE_SEC_REQ_EVT)
245     CASE_RETURN_STR(BTA_DM_BLE_PASSKEY_NOTIF_EVT)
246     CASE_RETURN_STR(BTA_DM_BLE_PASSKEY_REQ_EVT)
247     CASE_RETURN_STR(BTA_DM_BLE_OOB_REQ_EVT)
248     CASE_RETURN_STR(BTA_DM_BLE_LOCAL_IR_EVT)
249     CASE_RETURN_STR(BTA_DM_BLE_LOCAL_ER_EVT)
250     CASE_RETURN_STR(BTA_DM_BLE_AUTH_CMPL_EVT)
251     CASE_RETURN_STR(BTA_DM_DEV_UNPAIRED_EVT)
252     CASE_RETURN_STR(BTA_DM_HW_ERROR_EVT)
253     CASE_RETURN_STR(BTA_DM_ENER_INFO_READ)
254 
255     default:
256       return "UNKNOWN DM EVENT";
257   }
258 }
259 
dump_hf_event(uint16_t event)260 const char* dump_hf_event(uint16_t event) {
261   switch (event) {
262     CASE_RETURN_STR(BTA_AG_ENABLE_EVT)
263     CASE_RETURN_STR(BTA_AG_REGISTER_EVT)
264     CASE_RETURN_STR(BTA_AG_OPEN_EVT)
265     CASE_RETURN_STR(BTA_AG_CLOSE_EVT)
266     CASE_RETURN_STR(BTA_AG_CONN_EVT)
267     CASE_RETURN_STR(BTA_AG_AUDIO_OPEN_EVT)
268     CASE_RETURN_STR(BTA_AG_AUDIO_CLOSE_EVT)
269     CASE_RETURN_STR(BTA_AG_SPK_EVT)
270     CASE_RETURN_STR(BTA_AG_MIC_EVT)
271     CASE_RETURN_STR(BTA_AG_AT_CKPD_EVT)
272     CASE_RETURN_STR(BTA_AG_DISABLE_EVT)
273     CASE_RETURN_STR(BTA_AG_WBS_EVT)
274     CASE_RETURN_STR(BTA_AG_AT_A_EVT)
275     CASE_RETURN_STR(BTA_AG_AT_D_EVT)
276     CASE_RETURN_STR(BTA_AG_AT_CHLD_EVT)
277     CASE_RETURN_STR(BTA_AG_AT_CHUP_EVT)
278     CASE_RETURN_STR(BTA_AG_AT_CIND_EVT)
279     CASE_RETURN_STR(BTA_AG_AT_VTS_EVT)
280     CASE_RETURN_STR(BTA_AG_AT_BINP_EVT)
281     CASE_RETURN_STR(BTA_AG_AT_BLDN_EVT)
282     CASE_RETURN_STR(BTA_AG_AT_BVRA_EVT)
283     CASE_RETURN_STR(BTA_AG_AT_NREC_EVT)
284     CASE_RETURN_STR(BTA_AG_AT_CNUM_EVT)
285     CASE_RETURN_STR(BTA_AG_AT_BTRH_EVT)
286     CASE_RETURN_STR(BTA_AG_AT_CLCC_EVT)
287     CASE_RETURN_STR(BTA_AG_AT_COPS_EVT)
288     CASE_RETURN_STR(BTA_AG_AT_UNAT_EVT)
289     CASE_RETURN_STR(BTA_AG_AT_CBC_EVT)
290     CASE_RETURN_STR(BTA_AG_AT_BAC_EVT)
291     CASE_RETURN_STR(BTA_AG_AT_BCS_EVT)
292     CASE_RETURN_STR(BTA_AG_AT_BIND_EVT)
293     CASE_RETURN_STR(BTA_AG_AT_BIEV_EVT)
294 
295     default:
296       return "UNKNOWN MSG ID";
297   }
298 }
299 
dump_hf_client_event(uint16_t event)300 const char* dump_hf_client_event(uint16_t event) {
301   switch (event) {
302     CASE_RETURN_STR(BTA_HF_CLIENT_ENABLE_EVT)
303     CASE_RETURN_STR(BTA_HF_CLIENT_REGISTER_EVT)
304     CASE_RETURN_STR(BTA_HF_CLIENT_OPEN_EVT)
305     CASE_RETURN_STR(BTA_HF_CLIENT_CLOSE_EVT)
306     CASE_RETURN_STR(BTA_HF_CLIENT_CONN_EVT)
307     CASE_RETURN_STR(BTA_HF_CLIENT_AUDIO_OPEN_EVT)
308     CASE_RETURN_STR(BTA_HF_CLIENT_AUDIO_MSBC_OPEN_EVT)
309     CASE_RETURN_STR(BTA_HF_CLIENT_AUDIO_CLOSE_EVT)
310     CASE_RETURN_STR(BTA_HF_CLIENT_SPK_EVT)
311     CASE_RETURN_STR(BTA_HF_CLIENT_MIC_EVT)
312     CASE_RETURN_STR(BTA_HF_CLIENT_DISABLE_EVT)
313     CASE_RETURN_STR(BTA_HF_CLIENT_IND_EVT)
314     CASE_RETURN_STR(BTA_HF_CLIENT_VOICE_REC_EVT)
315     CASE_RETURN_STR(BTA_HF_CLIENT_OPERATOR_NAME_EVT)
316     CASE_RETURN_STR(BTA_HF_CLIENT_CLIP_EVT)
317     CASE_RETURN_STR(BTA_HF_CLIENT_CCWA_EVT)
318     CASE_RETURN_STR(BTA_HF_CLIENT_AT_RESULT_EVT)
319     CASE_RETURN_STR(BTA_HF_CLIENT_CLCC_EVT)
320     CASE_RETURN_STR(BTA_HF_CLIENT_CNUM_EVT)
321     CASE_RETURN_STR(BTA_HF_CLIENT_BTRH_EVT)
322     CASE_RETURN_STR(BTA_HF_CLIENT_BSIR_EVT)
323     CASE_RETURN_STR(BTA_HF_CLIENT_BINP_EVT)
324     CASE_RETURN_STR(BTA_HF_CLIENT_RING_INDICATION)
325     default:
326       return "UNKNOWN MSG ID";
327   }
328 }
329 
dump_hh_event(uint16_t event)330 const char* dump_hh_event(uint16_t event) {
331   switch (event) {
332     CASE_RETURN_STR(BTA_HH_ENABLE_EVT)
333     CASE_RETURN_STR(BTA_HH_DISABLE_EVT)
334     CASE_RETURN_STR(BTA_HH_OPEN_EVT)
335     CASE_RETURN_STR(BTA_HH_CLOSE_EVT)
336     CASE_RETURN_STR(BTA_HH_GET_DSCP_EVT)
337     CASE_RETURN_STR(BTA_HH_GET_PROTO_EVT)
338     CASE_RETURN_STR(BTA_HH_GET_RPT_EVT)
339     CASE_RETURN_STR(BTA_HH_GET_IDLE_EVT)
340     CASE_RETURN_STR(BTA_HH_SET_PROTO_EVT)
341     CASE_RETURN_STR(BTA_HH_SET_RPT_EVT)
342     CASE_RETURN_STR(BTA_HH_SET_IDLE_EVT)
343     CASE_RETURN_STR(BTA_HH_VC_UNPLUG_EVT)
344     CASE_RETURN_STR(BTA_HH_ADD_DEV_EVT)
345     CASE_RETURN_STR(BTA_HH_RMV_DEV_EVT)
346     CASE_RETURN_STR(BTA_HH_API_ERR_EVT)
347     default:
348       return "UNKNOWN MSG ID";
349   }
350 }
351 
dump_hf_conn_state(uint16_t event)352 const char* dump_hf_conn_state(uint16_t event) {
353   switch (event) {
354     CASE_RETURN_STR(BTHF_CONNECTION_STATE_DISCONNECTED)
355     CASE_RETURN_STR(BTHF_CONNECTION_STATE_CONNECTING)
356     CASE_RETURN_STR(BTHF_CONNECTION_STATE_CONNECTED)
357     CASE_RETURN_STR(BTHF_CONNECTION_STATE_SLC_CONNECTED)
358     CASE_RETURN_STR(BTHF_CONNECTION_STATE_DISCONNECTING)
359     default:
360       return "UNKNOWN MSG ID";
361   }
362 }
363 
dump_hd_event(uint16_t event)364 const char* dump_hd_event(uint16_t event) {
365   switch (event) {
366     CASE_RETURN_STR(BTA_HD_ENABLE_EVT)
367     CASE_RETURN_STR(BTA_HD_DISABLE_EVT)
368     CASE_RETURN_STR(BTA_HD_REGISTER_APP_EVT)
369     CASE_RETURN_STR(BTA_HD_UNREGISTER_APP_EVT)
370     CASE_RETURN_STR(BTA_HD_OPEN_EVT)
371     CASE_RETURN_STR(BTA_HD_CLOSE_EVT)
372     CASE_RETURN_STR(BTA_HD_GET_REPORT_EVT)
373     CASE_RETURN_STR(BTA_HD_SET_REPORT_EVT)
374     CASE_RETURN_STR(BTA_HD_SET_PROTOCOL_EVT)
375     CASE_RETURN_STR(BTA_HD_INTR_DATA_EVT)
376     CASE_RETURN_STR(BTA_HD_VC_UNPLUG_EVT)
377     CASE_RETURN_STR(BTA_HD_CONN_STATE_EVT)
378     CASE_RETURN_STR(BTA_HD_API_ERR_EVT)
379     default:
380       return "UNKNOWN MSG ID";
381   }
382 }
383 
dump_hf_call_state(bthf_call_state_t call_state)384 const char* dump_hf_call_state(bthf_call_state_t call_state) {
385   switch (call_state) {
386     CASE_RETURN_STR(BTHF_CALL_STATE_IDLE)
387     CASE_RETURN_STR(BTHF_CALL_STATE_HELD)
388     CASE_RETURN_STR(BTHF_CALL_STATE_DIALING)
389     CASE_RETURN_STR(BTHF_CALL_STATE_ALERTING)
390     CASE_RETURN_STR(BTHF_CALL_STATE_INCOMING)
391     CASE_RETURN_STR(BTHF_CALL_STATE_WAITING)
392     CASE_RETURN_STR(BTHF_CALL_STATE_ACTIVE)
393     default:
394       return "UNKNOWN CALL STATE";
395   }
396 }
397 
dump_thread_evt(bt_cb_thread_evt evt)398 const char* dump_thread_evt(bt_cb_thread_evt evt) {
399   switch (evt) {
400     CASE_RETURN_STR(ASSOCIATE_JVM)
401     CASE_RETURN_STR(DISASSOCIATE_JVM)
402 
403     default:
404       return "unknown thread evt";
405   }
406 }
407 
dump_hf_audio_state(uint16_t event)408 const char* dump_hf_audio_state(uint16_t event) {
409   switch (event) {
410     CASE_RETURN_STR(BTHF_AUDIO_STATE_DISCONNECTED)
411     CASE_RETURN_STR(BTHF_AUDIO_STATE_CONNECTING)
412     CASE_RETURN_STR(BTHF_AUDIO_STATE_CONNECTED)
413     CASE_RETURN_STR(BTHF_AUDIO_STATE_DISCONNECTING)
414     default:
415       return "UNKNOWN MSG ID";
416   }
417 }
418 
dump_av_conn_state(uint16_t event)419 const char* dump_av_conn_state(uint16_t event) {
420   switch (event) {
421     CASE_RETURN_STR(BTAV_CONNECTION_STATE_DISCONNECTED)
422     CASE_RETURN_STR(BTAV_CONNECTION_STATE_CONNECTING)
423     CASE_RETURN_STR(BTAV_CONNECTION_STATE_CONNECTED)
424     CASE_RETURN_STR(BTAV_CONNECTION_STATE_DISCONNECTING)
425     default:
426       return "UNKNOWN MSG ID";
427   }
428 }
429 
dump_av_audio_state(uint16_t event)430 const char* dump_av_audio_state(uint16_t event) {
431   switch (event) {
432     CASE_RETURN_STR(BTAV_AUDIO_STATE_REMOTE_SUSPEND)
433     CASE_RETURN_STR(BTAV_AUDIO_STATE_STOPPED)
434     CASE_RETURN_STR(BTAV_AUDIO_STATE_STARTED)
435     default:
436       return "UNKNOWN MSG ID";
437   }
438 }
439 
dump_adapter_scan_mode(bt_scan_mode_t mode)440 const char* dump_adapter_scan_mode(bt_scan_mode_t mode) {
441   switch (mode) {
442     CASE_RETURN_STR(BT_SCAN_MODE_NONE)
443     CASE_RETURN_STR(BT_SCAN_MODE_CONNECTABLE)
444     CASE_RETURN_STR(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE)
445 
446     default:
447       return "unknown scan mode";
448   }
449 }
450 
dump_bt_status(bt_status_t status)451 const char* dump_bt_status(bt_status_t status) {
452   switch (status) {
453     CASE_RETURN_STR(BT_STATUS_SUCCESS)
454     CASE_RETURN_STR(BT_STATUS_FAIL)
455     CASE_RETURN_STR(BT_STATUS_NOT_READY)
456     CASE_RETURN_STR(BT_STATUS_NOMEM)
457     CASE_RETURN_STR(BT_STATUS_BUSY)
458     CASE_RETURN_STR(BT_STATUS_UNSUPPORTED)
459 
460     default:
461       return "unknown scan mode";
462   }
463 }
464 
dump_rc_event(uint8_t event)465 const char* dump_rc_event(uint8_t event) {
466   switch (event) {
467     CASE_RETURN_STR(BTA_AV_RC_OPEN_EVT)
468     CASE_RETURN_STR(BTA_AV_RC_CLOSE_EVT)
469     CASE_RETURN_STR(BTA_AV_RC_BROWSE_OPEN_EVT)
470     CASE_RETURN_STR(BTA_AV_RC_BROWSE_CLOSE_EVT)
471     CASE_RETURN_STR(BTA_AV_REMOTE_CMD_EVT)
472     CASE_RETURN_STR(BTA_AV_REMOTE_RSP_EVT)
473     CASE_RETURN_STR(BTA_AV_VENDOR_CMD_EVT)
474     CASE_RETURN_STR(BTA_AV_VENDOR_RSP_EVT)
475     CASE_RETURN_STR(BTA_AV_META_MSG_EVT)
476     CASE_RETURN_STR(BTA_AV_RC_FEAT_EVT)
477     default:
478       return "UNKNOWN_EVENT";
479   }
480 }
481 
dump_rc_notification_event_id(uint8_t event_id)482 const char* dump_rc_notification_event_id(uint8_t event_id) {
483   switch (event_id) {
484     CASE_RETURN_STR(AVRC_EVT_PLAY_STATUS_CHANGE)
485     CASE_RETURN_STR(AVRC_EVT_TRACK_CHANGE)
486     CASE_RETURN_STR(AVRC_EVT_TRACK_REACHED_END)
487     CASE_RETURN_STR(AVRC_EVT_TRACK_REACHED_START)
488     CASE_RETURN_STR(AVRC_EVT_PLAY_POS_CHANGED)
489     CASE_RETURN_STR(AVRC_EVT_BATTERY_STATUS_CHANGE)
490     CASE_RETURN_STR(AVRC_EVT_SYSTEM_STATUS_CHANGE)
491     CASE_RETURN_STR(AVRC_EVT_APP_SETTING_CHANGE)
492     CASE_RETURN_STR(AVRC_EVT_VOLUME_CHANGE)
493     CASE_RETURN_STR(AVRC_EVT_ADDR_PLAYER_CHANGE)
494     CASE_RETURN_STR(AVRC_EVT_AVAL_PLAYERS_CHANGE)
495     CASE_RETURN_STR(AVRC_EVT_NOW_PLAYING_CHANGE)
496     CASE_RETURN_STR(AVRC_EVT_UIDS_CHANGE)
497 
498     default:
499       return "Unhandled Event ID";
500   }
501 }
502 
dump_rc_pdu(uint8_t pdu)503 const char* dump_rc_pdu(uint8_t pdu) {
504   switch (pdu) {
505     CASE_RETURN_STR(AVRC_PDU_LIST_PLAYER_APP_ATTR)
506     CASE_RETURN_STR(AVRC_PDU_LIST_PLAYER_APP_VALUES)
507     CASE_RETURN_STR(AVRC_PDU_GET_CUR_PLAYER_APP_VALUE)
508     CASE_RETURN_STR(AVRC_PDU_SET_PLAYER_APP_VALUE)
509     CASE_RETURN_STR(AVRC_PDU_GET_PLAYER_APP_ATTR_TEXT)
510     CASE_RETURN_STR(AVRC_PDU_GET_PLAYER_APP_VALUE_TEXT)
511     CASE_RETURN_STR(AVRC_PDU_INFORM_DISPLAY_CHARSET)
512     CASE_RETURN_STR(AVRC_PDU_INFORM_BATTERY_STAT_OF_CT)
513     CASE_RETURN_STR(AVRC_PDU_GET_ELEMENT_ATTR)
514     CASE_RETURN_STR(AVRC_PDU_GET_PLAY_STATUS)
515     CASE_RETURN_STR(AVRC_PDU_REGISTER_NOTIFICATION)
516     CASE_RETURN_STR(AVRC_PDU_REQUEST_CONTINUATION_RSP)
517     CASE_RETURN_STR(AVRC_PDU_ABORT_CONTINUATION_RSP)
518     CASE_RETURN_STR(AVRC_PDU_SET_ABSOLUTE_VOLUME)
519     CASE_RETURN_STR(AVRC_PDU_SET_ADDRESSED_PLAYER)
520     CASE_RETURN_STR(AVRC_PDU_CHANGE_PATH)
521     CASE_RETURN_STR(AVRC_PDU_GET_CAPABILITIES)
522     CASE_RETURN_STR(AVRC_PDU_SET_BROWSED_PLAYER)
523     CASE_RETURN_STR(AVRC_PDU_GET_FOLDER_ITEMS)
524     CASE_RETURN_STR(AVRC_PDU_GET_ITEM_ATTRIBUTES)
525     CASE_RETURN_STR(AVRC_PDU_PLAY_ITEM)
526     CASE_RETURN_STR(AVRC_PDU_SEARCH)
527     CASE_RETURN_STR(AVRC_PDU_ADD_TO_NOW_PLAYING)
528     CASE_RETURN_STR(AVRC_PDU_GET_TOTAL_NUM_OF_ITEMS)
529     CASE_RETURN_STR(AVRC_PDU_GENERAL_REJECT)
530 
531     default:
532       return "Unknown PDU";
533   }
534 }
535