1 /******************************************************************************
2  *
3  *  This is the AVRC call-out function implementation for  BTC.
4  *
5  ******************************************************************************/
6 // Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 
12 //     http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
19 
20 /*****************************************************************************
21  *
22  *  Filename:      bta_avrc_co.c
23  *
24  *  Description:   Bluetooth AVRC implementation
25  *
26  *****************************************************************************/
27 
28 #include <stdint.h>
29 #include "common/bt_target.h"
30 #include "bta/bta_sys.h"
31 #include "bta/bta_av_api.h"
32 #include "btc_avrc.h"
33 
34 #if BTC_AV_INCLUDED
35 /*******************************************************************************
36  **
37  ** Function         bta_avrc_co_cmd_allowed
38  **
39  ** Description      Check if local AVRCP TG configuration supports a specific
40  **                  PASSTHROUGH command with the given operation_id
41  **
42  ** Returns          TRUE if operation_id is supported, FALSE otherwise
43  **
44  *******************************************************************************/
bta_avrc_co_cmd_allowed(tBTA_AV_RC rc_id)45 BOOLEAN bta_avrc_co_cmd_allowed(tBTA_AV_RC rc_id)
46 {
47     if (rc_id >= BTA_AV_VENDOR) {
48         return FALSE;
49     }
50     const uint16_t *rc_cmd = btc_avrc_tg_get_supported_command();
51     if (rc_cmd[rc_id >> 4] & ((uint16_t)1 << (rc_id & 0x0F))) {
52         return TRUE;
53     } else {
54         return FALSE;
55     }
56 }
57 
58 /*******************************************************************************
59  **
60  ** Function         bta_avrc_co_rn_evt_cap
61  **
62  ** Description      get the event notifcation capabilities on AVRCP target
63  **
64  ** Returns          number of event_ids supported
65  **
66  *******************************************************************************/
bta_avrc_co_rn_evt_cap(UINT8 * event_ids)67 UINT8 bta_avrc_co_rn_evt_cap(UINT8 *event_ids)
68 {
69     if (event_ids == 0) {
70         return 0;
71     }
72 
73     UINT16 event_bits = btc_avrc_tg_get_rn_supported_evt();
74     UINT8 count = 0;
75     for (UINT8 i = 0; i < 16; ++i, event_bits >>= 1) {
76         if (event_bits & 0x01) {
77             event_ids[count++] = i;
78         }
79     }
80     return count;
81 }
82 
83 /*******************************************************************************
84  **
85  ** Function         bta_avrc_co_evt_supported
86  **
87  ** Description      Check if local AVRCP TG configuration supports the given
88  **                  event_id
89  **
90  ** Returns          TRUE if operation_id is supported, FALSE otherwise
91  **
92  *******************************************************************************/
bta_avrc_co_rn_evt_supported(UINT8 event_id)93 BOOLEAN bta_avrc_co_rn_evt_supported(UINT8 event_id)
94 {
95     return btc_avrc_tg_rn_evt_supported(event_id) ?
96            TRUE : FALSE;
97 }
98 
99 /* the call out functions for AVRC */
100 tBTA_AVRC_CO_FUNCTS bta_avrc_cos = {
101     bta_avrc_co_cmd_allowed,
102     bta_avrc_co_rn_evt_cap,
103     bta_avrc_co_rn_evt_supported,
104 };
105 
106 #endif /* #if BTC_AV_INCLUDED */
107