1 /******************************************************************************
2  *
3  *  Copyright 1999-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #ifndef BTM_API_TYPES_H
20 #define BTM_API_TYPES_H
21 
22 #include <base/strings/stringprintf.h>
23 
24 #include <cstdint>
25 #include <string>
26 
27 #include "stack/include/bt_dev_class.h"
28 #include "stack/include/bt_hdr.h"
29 #include "stack/include/hcidefs.h"
30 #include "stack/include/sdpdefs.h"
31 #include "types/raw_address.h"
32 
33 /* Structure returned with Vendor Specific Command complete callback */
34 typedef struct {
35   uint16_t opcode;
36   uint16_t param_len;
37   uint8_t* p_param_buf;
38 } tBTM_VSC_CMPL;
39 
40 /**************************************************
41  *  Device Control and General Callback Functions
42  **************************************************/
43 /* General callback function for notifying an application that a synchronous
44  * BTM function is complete. The pointer contains the address of any returned
45  * data.
46  */
47 typedef void(tBTM_CMPL_CB)(void* p1);
48 
49 /* VSC callback function for notifying an application that a synchronous
50  * BTM function is complete. The pointer contains the address of any returned
51  * data.
52  */
53 typedef void(tBTM_VSC_CMPL_CB)(tBTM_VSC_CMPL* p1);
54 
55 constexpr uint8_t PHY_LE_NO_PACKET = 0x00;
56 constexpr uint8_t PHY_LE_1M = 0x01;
57 constexpr uint8_t PHY_LE_2M = 0x02;
58 constexpr uint8_t PHY_LE_CODED = 0x04;
59 
60 constexpr uint8_t NO_ADI_PRESENT = 0xFF;
61 constexpr uint8_t TX_POWER_NOT_PRESENT = 0x7F;
62 
63 /******************
64  *  SCO Constants
65  ******************/
66 
67 /* Define an invalid SCO index and an invalid HCI handle */
68 #define BTM_INVALID_SCO_INDEX 0xFFFF
69 
70 #define BTM_SCO_LINK_ONLY_MASK \
71   (ESCO_PKT_TYPES_MASK_HV1 | ESCO_PKT_TYPES_MASK_HV2 | ESCO_PKT_TYPES_MASK_HV3)
72 
73 #define BTM_ESCO_LINK_ONLY_MASK \
74   (ESCO_PKT_TYPES_MASK_EV3 | ESCO_PKT_TYPES_MASK_EV4 | ESCO_PKT_TYPES_MASK_EV5)
75 
76 /***************
77  *  SCO Types
78  ***************/
79 #define BTM_LINK_TYPE_SCO HCI_LINK_TYPE_SCO
80 #define BTM_LINK_TYPE_ESCO HCI_LINK_TYPE_ESCO
81 typedef uint8_t tBTM_SCO_TYPE;
82 
83 /*******************
84  * SCO Codec Types
85  *******************/
86 // TODO(b/285458890) This should use common definitions
87 #define BTM_SCO_CODEC_NONE 0x0000
88 #define BTM_SCO_CODEC_CVSD 0x0001
89 #define BTM_SCO_CODEC_MSBC 0x0002
90 #define BTM_SCO_CODEC_LC3 0x0004
91 #define BTA_AG_SCO_APTX_SWB_SETTINGS_Q0_MASK 0x0008
92 #define BTA_AG_SCO_APTX_SWB_SETTINGS_Q1_MASK 0x0016
93 #define BTA_AG_SCO_APTX_SWB_SETTINGS_Q2_MASK 0x0032
94 #define BTA_AG_SCO_APTX_SWB_SETTINGS_Q3_MASK 0x0064
95 typedef uint16_t tBTM_SCO_CODEC_TYPE;
96 
97 /***************************
98  *  SCO Callback Functions
99  ***************************/
100 typedef void(tBTM_SCO_CB)(uint16_t sco_inx);
101 
102 /***************
103  *  eSCO Types
104  ***************/
105 /* tBTM_ESCO_CBACK event types */
106 #define BTM_ESCO_CONN_REQ_EVT 2
107 typedef uint8_t tBTM_ESCO_EVT;
108 
109 /* Returned by BTM_ReadEScoLinkParms() */
110 struct tBTM_ESCO_DATA {
111   RawAddress bd_addr;
112   uint8_t link_type; /* BTM_LINK_TYPE_SCO or BTM_LINK_TYPE_ESCO */
113 };
114 
115 typedef struct {
116   uint16_t sco_inx;
117   RawAddress bd_addr;
118   DEV_CLASS dev_class;
119   tBTM_SCO_TYPE link_type;
120 } tBTM_ESCO_CONN_REQ_EVT_DATA;
121 
122 typedef union {
123   tBTM_ESCO_CONN_REQ_EVT_DATA conn_evt;
124 } tBTM_ESCO_EVT_DATA;
125 
126 /***************************
127  *  eSCO Callback Functions
128  ***************************/
129 typedef void(tBTM_ESCO_CBACK)(tBTM_ESCO_EVT event, tBTM_ESCO_EVT_DATA* p_data);
130 
131 /**************************
132  * SCO Types for Debugging and Testing
133  **************************/
134 
135 /* Define the structure for the WBS/SWB packet status dump.  */
136 typedef struct {
137   uint64_t begin_ts_raw_us;
138   uint64_t end_ts_raw_us;
139   std::string status_in_hex;
140   std::string status_in_binary;
141 } tBTM_SCO_PKT_STATUS_DATA;
142 
143 /* Returned by BTM_GetScoDebugDump */
144 typedef struct {
145   bool is_active;
146   uint16_t codec_id;
147   int total_num_decoded_frames;
148   double pkt_loss_ratio;
149   tBTM_SCO_PKT_STATUS_DATA latest_data;
150 } tBTM_SCO_DEBUG_DUMP;
151 
sco_codec_type_text(tBTM_SCO_CODEC_TYPE codec_type)152 inline std::string sco_codec_type_text(tBTM_SCO_CODEC_TYPE codec_type) {
153   switch (codec_type) {
154     case BTM_SCO_CODEC_CVSD:
155       return "CVSD";
156     case BTM_SCO_CODEC_MSBC:
157       return "MSBC";
158     case BTM_SCO_CODEC_LC3:
159       return "LC3";
160     default:
161       return "UNKNOWN";
162   }
163 }
164 
sco_codec_type_to_id(tBTM_SCO_CODEC_TYPE codec_type)165 inline uint16_t sco_codec_type_to_id(tBTM_SCO_CODEC_TYPE codec_type) {
166   switch (codec_type) {
167     case BTM_SCO_CODEC_CVSD:
168       return UUID_CODEC_CVSD;
169     case BTM_SCO_CODEC_MSBC:
170       return UUID_CODEC_MSBC;
171     case BTM_SCO_CODEC_LC3:
172       return UUID_CODEC_LC3;
173     default:
174       return 0;
175   }
176 }
177 #endif  // BTM_API_TYPES_H
178