• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <cstdint>
23 #include <string>
24 
25 #include "stack/include/bt_dev_class.h"
26 #include "stack/include/bt_hdr.h"
27 #include "stack/include/hcidefs.h"
28 #include "stack/include/sdpdefs.h"
29 #include "types/raw_address.h"
30 
31 /* Structure returned with Vendor Specific Command complete callback */
32 typedef struct {
33   uint16_t opcode;
34   uint16_t param_len;
35   uint8_t* p_param_buf;
36 } tBTM_VSC_CMPL;
37 
38 /**************************************************
39  *  Device Control and General Callback Functions
40  **************************************************/
41 /* General callback function for notifying an application that a synchronous
42  * BTM function is complete. The pointer contains the address of any returned
43  * data.
44  */
45 typedef void(tBTM_CMPL_CB)(void* p1);
46 
47 /* VSC callback function for notifying an application that a synchronous
48  * BTM function is complete. The pointer contains the address of any returned
49  * data.
50  */
51 typedef void(tBTM_VSC_CMPL_CB)(tBTM_VSC_CMPL* p1);
52 
53 constexpr uint8_t PHY_LE_NO_PACKET = 0x00;
54 constexpr uint8_t PHY_LE_1M = 0x01;
55 constexpr uint8_t PHY_LE_2M = 0x02;
56 constexpr uint8_t PHY_LE_CODED = 0x04;
57 
58 constexpr uint8_t NO_ADI_PRESENT = 0xFF;
59 constexpr uint8_t TX_POWER_NOT_PRESENT = 0x7F;
60 
61 /******************
62  *  SCO Constants
63  ******************/
64 
65 /* Define an invalid SCO index and an invalid HCI handle */
66 #define BTM_INVALID_SCO_INDEX 0xFFFF
67 
68 #define BTM_SCO_LINK_ONLY_MASK \
69   (ESCO_PKT_TYPES_MASK_HV1 | ESCO_PKT_TYPES_MASK_HV2 | ESCO_PKT_TYPES_MASK_HV3)
70 
71 #define BTM_ESCO_LINK_ONLY_MASK \
72   (ESCO_PKT_TYPES_MASK_EV3 | ESCO_PKT_TYPES_MASK_EV4 | ESCO_PKT_TYPES_MASK_EV5)
73 
74 /***************
75  *  SCO Types
76  ***************/
77 #define BTM_LINK_TYPE_SCO HCI_LINK_TYPE_SCO
78 #define BTM_LINK_TYPE_ESCO HCI_LINK_TYPE_ESCO
79 typedef uint8_t tBTM_SCO_TYPE;
80 
81 /*******************
82  * SCO Codec Types
83  *******************/
84 // TODO(b/285458890) This should use common definitions
85 #define BTM_SCO_CODEC_NONE 0x0000
86 #define BTM_SCO_CODEC_CVSD 0x0001
87 #define BTM_SCO_CODEC_MSBC 0x0002
88 #define BTM_SCO_CODEC_LC3 0x0004
89 #define BTA_AG_SCO_APTX_SWB_SETTINGS_Q0_MASK 0x0008
90 #define BTA_AG_SCO_APTX_SWB_SETTINGS_Q1_MASK 0x0016
91 #define BTA_AG_SCO_APTX_SWB_SETTINGS_Q2_MASK 0x0032
92 #define BTA_AG_SCO_APTX_SWB_SETTINGS_Q3_MASK 0x0064
93 
94 /**
95  * enum value is defined based on HFP spec, Codec ID section
96  */
97 enum class tBTA_AG_UUID_CODEC : uint16_t {
98   BTA_AG_SCO_APTX_SWB_SETTINGS_Q0 = 0,
99   UUID_CODEC_NONE = 0,
100   UUID_CODEC_CVSD = 0x0001 /* CVSD */,
101   UUID_CODEC_MSBC = 0x0002 /* mSBC */,
102   UUID_CODEC_LC3 = 0x0003 /* LC3 */,
103 };
104 
105 typedef uint16_t tBTM_SCO_CODEC_TYPE;
106 
107 /***************************
108  *  SCO Callback Functions
109  ***************************/
110 typedef void(tBTM_SCO_CB)(uint16_t sco_inx);
111 
112 /***************
113  *  eSCO Types
114  ***************/
115 /* tBTM_ESCO_CBACK event types */
116 #define BTM_ESCO_CONN_REQ_EVT 2
117 typedef uint8_t tBTM_ESCO_EVT;
118 
119 /* Returned by BTM_ReadEScoLinkParms() */
120 struct tBTM_ESCO_DATA {
121   RawAddress bd_addr;
122   uint8_t link_type; /* BTM_LINK_TYPE_SCO or BTM_LINK_TYPE_ESCO */
123 };
124 
125 typedef struct {
126   uint16_t sco_inx;
127   RawAddress bd_addr;
128   DEV_CLASS dev_class;
129   tBTM_SCO_TYPE link_type;
130 } tBTM_ESCO_CONN_REQ_EVT_DATA;
131 
132 typedef union {
133   tBTM_ESCO_CONN_REQ_EVT_DATA conn_evt;
134 } tBTM_ESCO_EVT_DATA;
135 
136 /***************************
137  *  eSCO Callback Functions
138  ***************************/
139 typedef void(tBTM_ESCO_CBACK)(tBTM_ESCO_EVT event, tBTM_ESCO_EVT_DATA* p_data);
140 
141 /**************************
142  * SCO Types for Debugging and Testing
143  **************************/
144 
145 /* Define the structure for the WBS/SWB packet status dump.  */
146 typedef struct {
147   uint64_t begin_ts_raw_us;
148   uint64_t end_ts_raw_us;
149   std::string status_in_hex;
150   std::string status_in_binary;
151 } tBTM_SCO_PKT_STATUS_DATA;
152 
153 /* Returned by BTM_GetScoDebugDump */
154 typedef struct {
155   bool is_active;
156   uint16_t codec_id;
157   int total_num_decoded_frames;
158   double pkt_loss_ratio;
159   tBTM_SCO_PKT_STATUS_DATA latest_data;
160 } tBTM_SCO_DEBUG_DUMP;
161 
sco_codec_type_text(tBTM_SCO_CODEC_TYPE codec_type)162 inline std::string sco_codec_type_text(tBTM_SCO_CODEC_TYPE codec_type) {
163   switch (codec_type) {
164     case BTM_SCO_CODEC_CVSD:
165       return "CVSD";
166     case BTM_SCO_CODEC_MSBC:
167       return "MSBC";
168     case BTM_SCO_CODEC_LC3:
169       return "LC3";
170     default:
171       return "UNKNOWN";
172   }
173 }
174 
sco_codec_type_to_id(tBTM_SCO_CODEC_TYPE codec_type)175 inline uint16_t sco_codec_type_to_id(tBTM_SCO_CODEC_TYPE codec_type) {
176   switch (codec_type) {
177     case BTM_SCO_CODEC_CVSD:
178       return static_cast<std::underlying_type_t<tBTA_AG_UUID_CODEC>>(
179               tBTA_AG_UUID_CODEC::UUID_CODEC_CVSD);
180     case BTM_SCO_CODEC_MSBC:
181       return static_cast<std::underlying_type_t<tBTA_AG_UUID_CODEC>>(
182               tBTA_AG_UUID_CODEC::UUID_CODEC_MSBC);
183     case BTM_SCO_CODEC_LC3:
184       return static_cast<std::underlying_type_t<tBTA_AG_UUID_CODEC>>(
185               tBTA_AG_UUID_CODEC::UUID_CODEC_LC3);
186     default:
187       return 0;
188   }
189 }
190 
bta_ag_uuid_codec_text(const tBTA_AG_UUID_CODEC result)191 inline std::string bta_ag_uuid_codec_text(const tBTA_AG_UUID_CODEC result) {
192   switch (result) {
193     CASE_RETURN_TEXT(tBTA_AG_UUID_CODEC::UUID_CODEC_NONE);
194     CASE_RETURN_TEXT(tBTA_AG_UUID_CODEC::UUID_CODEC_CVSD);
195     CASE_RETURN_TEXT(tBTA_AG_UUID_CODEC::UUID_CODEC_MSBC);
196     CASE_RETURN_TEXT(tBTA_AG_UUID_CODEC::UUID_CODEC_LC3);
197     default:
198       return std::format("UNKNOWN Codec with id {}",
199                          static_cast<std::underlying_type_t<tBTA_AG_UUID_CODEC>>(result));
200   }
201 }
202 #endif  // BTM_API_TYPES_H
203