1 /*
2  * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /******************************************************************************
8  *
9  *  This is the AVRC call-out function implementation for  BTC.
10  *
11  ******************************************************************************/
12 
13 /*****************************************************************************
14  *
15  *  Filename:      bta_avrc_co.c
16  *
17  *  Description:   Bluetooth AVRC implementation
18  *
19  *****************************************************************************/
20 
21 #include <stdint.h>
22 #include "common/bt_target.h"
23 #include "bta/bta_sys.h"
24 #include "bta/bta_av_api.h"
25 #include "btc_avrc.h"
26 
27 #if BTC_AV_INCLUDED
28 /*******************************************************************************
29  **
30  ** Function         bta_avrc_co_cmd_allowed
31  **
32  ** Description      Check if local AVRCP TG configuration supports a specific
33  **                  PASSTHROUGH command with the given operation_id
34  **
35  ** Returns          TRUE if operation_id is supported, FALSE otherwise
36  **
37  *******************************************************************************/
bta_avrc_co_cmd_allowed(tBTA_AV_RC rc_id)38 BOOLEAN bta_avrc_co_cmd_allowed(tBTA_AV_RC rc_id)
39 {
40     if (rc_id >= BTA_AV_VENDOR) {
41         return FALSE;
42     }
43     const uint16_t *rc_cmd = btc_avrc_tg_get_supported_command();
44     if (rc_cmd[rc_id >> 4] & ((uint16_t)1 << (rc_id & 0x0F))) {
45         return TRUE;
46     } else {
47         return FALSE;
48     }
49 }
50 
51 /*******************************************************************************
52  **
53  ** Function         bta_avrc_co_rn_evt_cap
54  **
55  ** Description      get the event notifcation capabilities on AVRCP target
56  **
57  ** Returns          number of event_ids supported
58  **
59  *******************************************************************************/
bta_avrc_co_rn_evt_cap(UINT8 * event_ids)60 UINT8 bta_avrc_co_rn_evt_cap(UINT8 *event_ids)
61 {
62     if (event_ids == 0) {
63         return 0;
64     }
65 
66     UINT16 event_bits = btc_avrc_tg_get_rn_supported_evt();
67     UINT8 count = 0;
68     for (UINT8 i = 0; i < 16; ++i, event_bits >>= 1) {
69         if (event_bits & 0x01) {
70             event_ids[count++] = i;
71         }
72     }
73     return count;
74 }
75 
76 /*******************************************************************************
77  **
78  ** Function         bta_avrc_co_evt_supported
79  **
80  ** Description      Check if local AVRCP TG configuration supports the given
81  **                  event_id
82  **
83  ** Returns          TRUE if operation_id is supported, FALSE otherwise
84  **
85  *******************************************************************************/
bta_avrc_co_rn_evt_supported(UINT8 event_id)86 BOOLEAN bta_avrc_co_rn_evt_supported(UINT8 event_id)
87 {
88     return btc_avrc_tg_rn_evt_supported(event_id) ?
89            TRUE : FALSE;
90 }
91 
92 /* the call out functions for AVRC */
93 tBTA_AVRC_CO_FUNCTS bta_avrc_cos = {
94     bta_avrc_co_cmd_allowed,
95     bta_avrc_co_rn_evt_cap,
96     bta_avrc_co_rn_evt_supported,
97 };
98 
99 #endif /* #if BTC_AV_INCLUDED */
100