1 // Copyright 2023 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "hci/rust_device.h"
16
17 #include <cstdint>
18
19 #include "netsim-daemon/src/ffi.rs.h"
20 #include "packets/link_layer_packets.h"
21 #include "phy.h"
22 #include "rust/cxx.h"
23
24 namespace netsim::hci::facade {
Tick()25 void RustDevice::Tick() { ::netsim::hci::facade::Tick(*callbacks_); }
26
ReceiveLinkLayerPacket(::model::packets::LinkLayerPacketView packet,rootcanal::Phy::Type type,int8_t rssi)27 void RustDevice::ReceiveLinkLayerPacket(
28 ::model::packets::LinkLayerPacketView packet, rootcanal::Phy::Type type,
29 int8_t rssi) {
30 auto packet_vec = packet.bytes().bytes();
31 auto slice = rust::Slice<const uint8_t>(packet_vec.data(), packet_vec.size());
32
33 ::netsim::hci::facade::ReceiveLinkLayerPacket(
34 *callbacks_, packet.GetSourceAddress().ToString(),
35 packet.GetDestinationAddress().ToString(),
36 static_cast<int8_t>(packet.GetType()), slice);
37 }
38
SendLinkLayerLePacket(const rust::Slice<const uint8_t> packet,int8_t tx_power) const39 void RustBluetoothChip::SendLinkLayerLePacket(
40 const rust::Slice<const uint8_t> packet, int8_t tx_power) const {
41 std::vector<uint8_t> buffer(packet.begin(), packet.end());
42 rust_device->SendLinkLayerPacket(buffer, rootcanal::Phy::Type::LOW_ENERGY,
43 tx_power);
44 }
45 } // namespace netsim::hci::facade
46