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 #include <cstdint>
19 #include <memory>
20 #include <string>
21 
22 #include "hci/address.h"
23 #include "hci/rust_device.h"
24 #include "netsim/model.pb.h"
25 #include "rust/cxx.h"
26 
27 /** Manages the bluetooth chip emulation provided by the root canal library.
28  *
29  * Owns the TestModel, setup, and manages the packet flow into and out of
30  * rootcanal.
31  */
32 
33 namespace netsim::hci::facade {
34 // Use forward declaration instead of including "netsim-cxx/src/lib.rs.h".
35 struct DynRustBluetoothChipCallbacks;
36 struct AddRustDeviceResult;
37 
38 void Reset(uint32_t);
39 void Remove(uint32_t);
40 model::Chip::Bluetooth Get(uint32_t);
41 uint32_t Add(uint32_t chip_id, const std::string &address_string,
42              const rust::Slice<::std::uint8_t const> controller_proto_bytes);
43 
44 rust::Box<AddRustDeviceResult> AddRustDevice(
45     uint32_t chip_id, rust::Box<DynRustBluetoothChipCallbacks> callbacks,
46     const std::string &type, const std::string &address);
47 void SetRustDeviceAddress(
48     uint32_t rootcanal_id,
49     std::array<uint8_t, rootcanal::Address::kLength> address);
50 void RemoveRustDevice(uint32_t rootcanal_id);
51 
52 void Start(const rust::Slice<::std::uint8_t const> proto_bytes,
53            uint16_t instance_num);
54 void Stop();
55 
56 void AddDeviceToPhy(uint32_t rootcanal_id, bool isLowEnergy);
57 void RemoveDeviceFromPhy(uint32_t rootcanal_id, bool isLowEnergy);
58 
59 // Cxx functions for rust ffi.
60 rust::Vec<::std::uint8_t> GetCxx(uint32_t id);
61 
62 }  // namespace netsim::hci::facade
63