• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 Google LLC
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 //     https://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 use bytes::Bytes;
16 
17 use netsim_proto::model::Chip as ProtoChip;
18 use netsim_proto::stats::NetsimRadioStats as ProtoRadioStats;
19 
20 pub type WirelessChipImpl = Box<dyn WirelessChip + Send + Sync>;
21 
22 // TODO: Factory trait to include start, stop, and add
23 /// WirelessChip is a trait that provides interface between the generic Chip
24 /// and Radio specific library (rootcanal, libslirp, pica).
25 pub trait WirelessChip {
26     /// This is the main entry for incoming host-to-controller packets
27     /// from virtual devices called by the transport module. The format of the
28     /// packet depends on the emulated chip kind:
29     /// * Bluetooth - packet is H4 HCI format
30     /// * Wi-Fi - packet is Radiotap format
31     /// * UWB - packet is UCI format
32     /// * NFC - packet is NCI format
handle_request(&self, packet: &Bytes)33     fn handle_request(&self, packet: &Bytes);
34 
35     /// Reset the internal state of the emulated chip for the virtual device.
36     /// The transmitted and received packet count will be set to 0 and the chip
37     /// shall be in the enabled state following a call to this function.
reset(&self)38     fn reset(&self);
39 
40     /// Return the Chip model protobuf from the emulated chip. This is part of
41     /// the Frontend API.
get(&self) -> ProtoChip42     fn get(&self) -> ProtoChip;
43 
44     /// Patch the state of the emulated chip. For example enable/disable the
45     /// chip's host-to-controller packet processing. This is part of the
46     /// Frontend API
patch(&self, chip: &ProtoChip)47     fn patch(&self, chip: &ProtoChip);
48 
49     /// Return the NetsimRadioStats protobuf from the emulated chip. This is
50     /// part of NetsimStats protobuf.
get_stats(&self, duration_secs: u64) -> Vec<ProtoRadioStats>51     fn get_stats(&self, duration_secs: u64) -> Vec<ProtoRadioStats>;
52 }
53 
54 // TODO(b/309529194):
55 // 1. Create Mock wireless adaptor, patch and get
56 // 2. Create Mock wireless adptor, patch and reset
57 #[cfg(test)]
58 mod tests {
59     #[test]
test_wireless_chip_new()60     fn test_wireless_chip_new() {
61         // TODO
62     }
63 }
64