1 /*
2  * Copyright 2020 HIMSA II K/S - www.himsa.com.
3  * Represented by EHIMA - www.ehima.com
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 #include "mock_hcic_layer.h"
19 
20 static hcic::MockHcicInterface* hcic_interface = nullptr;
21 
SetMockHcicInterface(MockHcicInterface * interface)22 void hcic::SetMockHcicInterface(MockHcicInterface* interface) {
23   hcic_interface = interface;
24 }
25 
btsnd_hcic_set_cig_params(uint8_t cig_id,uint32_t sdu_itv_mtos,uint32_t sdu_itv_stom,uint8_t sca,uint8_t packing,uint8_t framing,uint16_t max_trans_lat_stom,uint16_t max_trans_lat_mtos,uint8_t cis_cnt,const EXT_CIS_CFG * cis_cfg,base::OnceCallback<void (uint8_t *,uint16_t)> cb)26 void btsnd_hcic_set_cig_params(
27     uint8_t cig_id, uint32_t sdu_itv_mtos, uint32_t sdu_itv_stom, uint8_t sca,
28     uint8_t packing, uint8_t framing, uint16_t max_trans_lat_stom,
29     uint16_t max_trans_lat_mtos, uint8_t cis_cnt, const EXT_CIS_CFG* cis_cfg,
30     base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
31   struct bluetooth::hci::iso_manager::cig_create_params cig_params = {
32       .sdu_itv_mtos = sdu_itv_mtos,
33       .sdu_itv_stom = sdu_itv_stom,
34       .sca = sca,
35       .packing = packing,
36       .framing = framing,
37       .max_trans_lat_stom = max_trans_lat_stom,
38       .max_trans_lat_mtos = max_trans_lat_mtos,
39       .cis_cfgs = std::vector(cis_cfg, cis_cfg + cis_cnt),
40   };
41   hcic_interface->SetCigParams(cig_id, std::move(cig_params), std::move(cb));
42 }
43 
btsnd_hcic_remove_cig(uint8_t cig_id,base::OnceCallback<void (uint8_t *,uint16_t)> cb)44 void btsnd_hcic_remove_cig(uint8_t cig_id,
45                            base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
46   hcic_interface->RemoveCig(cig_id, std::move(cb));
47 }
48 
btsnd_hcic_create_cis(uint8_t num_cis,const EXT_CIS_CREATE_CFG * cis_cfg,base::OnceCallback<void (uint8_t *,uint16_t)> cb)49 void btsnd_hcic_create_cis(uint8_t num_cis, const EXT_CIS_CREATE_CFG* cis_cfg,
50                            base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
51   hcic_interface->CreateCis(num_cis, cis_cfg, std::move(cb));
52 }
53 
btsnd_hcic_disconnect(uint16_t handle,uint8_t reason)54 static void btsnd_hcic_disconnect(uint16_t handle, uint8_t reason) {
55   hcic_interface->Disconnect(handle, reason);
56 }
57 
btsnd_hcic_setup_iso_data_path(uint16_t iso_handle,uint8_t data_path_dir,uint8_t data_path_id,uint8_t codec_id_format,uint16_t codec_id_company,uint16_t codec_id_vendor,uint32_t controller_delay,std::vector<uint8_t> codec_conf,base::OnceCallback<void (uint8_t *,uint16_t)> cb)58 void btsnd_hcic_setup_iso_data_path(
59     uint16_t iso_handle, uint8_t data_path_dir, uint8_t data_path_id,
60     uint8_t codec_id_format, uint16_t codec_id_company,
61     uint16_t codec_id_vendor, uint32_t controller_delay,
62     std::vector<uint8_t> codec_conf,
63     base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
64   hcic_interface->SetupIsoDataPath(iso_handle, data_path_dir, data_path_id,
65                                    codec_id_format, codec_id_company,
66                                    codec_id_vendor, controller_delay,
67                                    std::move(codec_conf), std::move(cb));
68 }
69 
btsnd_hcic_remove_iso_data_path(uint16_t iso_handle,uint8_t data_path_dir,base::OnceCallback<void (uint8_t *,uint16_t)> cb)70 void btsnd_hcic_remove_iso_data_path(
71     uint16_t iso_handle, uint8_t data_path_dir,
72     base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
73   hcic_interface->RemoveIsoDataPath(iso_handle, data_path_dir, std::move(cb));
74 }
75 
btsnd_hcic_read_iso_link_quality(uint16_t iso_handle,base::OnceCallback<void (uint8_t *,uint16_t)> cb)76 void btsnd_hcic_read_iso_link_quality(
77     uint16_t iso_handle, base::OnceCallback<void(uint8_t*, uint16_t)> cb) {
78   hcic_interface->ReadIsoLinkQuality(iso_handle, std::move(cb));
79 }
80 
btsnd_hcic_create_big(uint8_t big_handle,uint8_t adv_handle,uint8_t num_bis,uint32_t sdu_itv,uint16_t max_sdu_size,uint16_t transport_latency,uint8_t rtn,uint8_t phy,uint8_t packing,uint8_t framing,uint8_t enc,std::array<uint8_t,16> bcst_code)81 void btsnd_hcic_create_big(uint8_t big_handle, uint8_t adv_handle,
82                            uint8_t num_bis, uint32_t sdu_itv,
83                            uint16_t max_sdu_size, uint16_t transport_latency,
84                            uint8_t rtn, uint8_t phy, uint8_t packing,
85                            uint8_t framing, uint8_t enc,
86                            std::array<uint8_t, 16> bcst_code) {
87   struct bluetooth::hci::iso_manager::big_create_params big_params = {
88       .adv_handle = adv_handle,
89       .num_bis = num_bis,
90       .sdu_itv = sdu_itv,
91       .max_sdu_size = max_sdu_size,
92       .max_transport_latency = transport_latency,
93       .rtn = rtn,
94       .phy = phy,
95       .packing = packing,
96       .framing = framing,
97       .enc = enc,
98       .enc_code = std::move(bcst_code),
99   };
100   hcic_interface->CreateBig(big_handle, std::move(big_params));
101 }
102 
btsnd_hcic_term_big(uint8_t big_handle,uint8_t reason)103 void btsnd_hcic_term_big(uint8_t big_handle, uint8_t reason) {
104   hcic_interface->TerminateBig(big_handle, reason);
105 }
106 
107 bluetooth::legacy::hci::Interface interface_ = {
108     .Disconnect = btsnd_hcic_disconnect,
109 };
110 
111 const bluetooth::legacy::hci::Interface&
GetInterface()112 bluetooth::legacy::hci::GetInterface() {
113   return interface_;
114 }
115