1 /*
2 * Copyright 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #pragma once
18
19 #include <stdint.h>
20
21 #include <vector>
22
23 #include "device/include/esco_parameters.h"
24 #include "internal_include/bt_target.h"
25 #include "raw_address.h"
26
27 // Used by the Bluetooth stack to get WBS supported and codec, or notify SCO
28 // connection change to lower layer (kernel) when SCO-over-HCI is used. So far
29 // ChromeOS uses SCO-over-HCI; usually Android phone uses hardware SCO route so
30 // it doesn't apply here.
31 namespace hfp_hal_interface {
32 enum codec : uint64_t {
33 CVSD = 1 << 0,
34 MSBC_TRANSPARENT = 1 << 1,
35 MSBC = 1 << 2,
36 LC3 = 1 << 3,
37 };
38
39 struct bt_codec {
40 codec codec;
41 uint8_t data_path;
42 std::vector<uint8_t> data;
43 };
44
45 struct bt_codecs {
46 bool offload_capable;
47 std::vector<bt_codec> codecs;
48 };
49
50 // Use default packet size for codec if this value is given.
51 constexpr size_t kDefaultPacketSize = 0;
52
esco_coding_to_codec(esco_coding_format_t esco_coding)53 constexpr inline int esco_coding_to_codec(esco_coding_format_t esco_coding) {
54 switch (esco_coding) {
55 case ESCO_CODING_FORMAT_TRANSPNT:
56 return codec::MSBC_TRANSPARENT;
57 case ESCO_CODING_FORMAT_MSBC:
58 return codec::MSBC;
59 case ESCO_CODING_FORMAT_LC3:
60 return codec::LC3;
61
62 // Default to CVSD encoding if unknown format.
63 case ESCO_CODING_FORMAT_CVSD:
64 default:
65 return codec::CVSD;
66 }
67 }
68
69 // Initialize the SCO HFP HAL module
70 void init();
71
72 // Check if specified coding format is supported by the adapter.
73 bool is_coding_format_supported(esco_coding_format_t coding_format);
74
75 // Check if wideband speech is supported on local device.
76 bool get_wbs_supported();
77
78 // Check if super wideband speech is supported on local device.
79 bool get_swb_supported();
80
81 // Checks the details of the codecs (specified as a bitmask of enum codec).
82 bt_codecs get_codec_capabilities(uint64_t codecs);
83
84 // Check if hardware offload is supported.
85 bool get_offload_supported();
86
87 // Check if hardware offload is enabled.
88 bool get_offload_enabled();
89
90 // Set offload enable/disable.
91 bool enable_offload(bool enable);
92
93 // Notify the codec datapath to lower layer for offload mode.
94 void set_codec_datapath(int codec_uuid);
95
96 // Get the maximum supported packet size from the lower layer.
97 size_t get_packet_size(int codec);
98
99 // Notify the lower layer about SCO connection change.
100 void notify_sco_connection_change(RawAddress device, bool is_connected,
101 int codec);
102
103 // Update eSCO parameters
104 void update_esco_parameters(enh_esco_params_t* p_parms);
105 } // namespace hfp_hal_interface
106