aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-12-15 00:44:58 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-12-15 00:44:58 +0000
commit528856fb70411b5f0e41a4094236e7a978459ceb (patch)
tree468215b8bacfc9418c5c80bf7e11ec13cfb1b043
parent5658c3db12895bca6fa218737ee2933a6d615ac1 (diff)
parent8636f343484c7cd7c055835c56f14e4e0ef05959 (diff)
downloadnetsim-android14-qpr2-s3-release.tar.gz
Change-Id: Ib59b0e17955c059929b02d4fd20756b1b840254a
-rw-r--r--proto/netsim/config.proto12
-rw-r--r--rust/daemon/src/echip/bluetooth.rs8
-rw-r--r--rust/daemon/src/ffi.rs2
-rw-r--r--rust/daemon/src/rust_main.rs25
-rw-r--r--rust/proto/src/config.rs202
-rw-r--r--src/hci/bluetooth_facade.cc8
-rw-r--r--src/hci/bluetooth_facade.h2
7 files changed, 219 insertions, 40 deletions
diff --git a/proto/netsim/config.proto b/proto/netsim/config.proto
index cb27ba1..e48ba87 100644
--- a/proto/netsim/config.proto
+++ b/proto/netsim/config.proto
@@ -54,11 +54,19 @@ message WiFi {
message Bluetooth {
optional rootcanal.configuration.Controller properties = 1;
- optional bool address_reuse = 2;
+ // default is False
+ optional bool disable_address_reuse = 2;
+ // default is False
+ optional bool test_beacons = 3;
+}
+
+message Capture {
+ optional bool enabled = 1;
}
message Config {
// Major sections
Bluetooth bluetooth = 1;
WiFi wifi = 2;
-} \ No newline at end of file
+ Capture capture = 3;
+}
diff --git a/rust/daemon/src/echip/bluetooth.rs b/rust/daemon/src/echip/bluetooth.rs
index 1661128..96b130c 100644
--- a/rust/daemon/src/echip/bluetooth.rs
+++ b/rust/daemon/src/echip/bluetooth.rs
@@ -115,13 +115,9 @@ pub fn new(create_params: &CreateParams, chip_id: ChipIdentifier) -> SharedEmula
}
/// Starts the Bluetooth service.
-pub fn bluetooth_start(
- config: &MessageField<BluetoothConfig>,
- instance_num: u16,
- disable_address_reuse: bool,
-) {
+pub fn bluetooth_start(config: &MessageField<BluetoothConfig>, instance_num: u16) {
let proto_bytes = config.as_ref().unwrap_or_default().write_to_bytes().unwrap();
- ffi_bluetooth::bluetooth_start(&proto_bytes, instance_num, disable_address_reuse);
+ ffi_bluetooth::bluetooth_start(&proto_bytes, instance_num);
}
/// Stops the Bluetooth service.
diff --git a/rust/daemon/src/ffi.rs b/rust/daemon/src/ffi.rs
index 19763f2..5a06c13 100644
--- a/rust/daemon/src/ffi.rs
+++ b/rust/daemon/src/ffi.rs
@@ -218,7 +218,7 @@ pub mod ffi_bluetooth {
#[rust_name = bluetooth_start]
#[namespace = "netsim::hci::facade"]
- pub fn Start(proto_bytes: &[u8], instance_num: u16, disable_address_reuse: bool);
+ pub fn Start(proto_bytes: &[u8], instance_num: u16);
#[rust_name = bluetooth_stop]
#[namespace = "netsim::hci::facade"]
diff --git a/rust/daemon/src/rust_main.rs b/rust/daemon/src/rust_main.rs
index dd90764..fbda552 100644
--- a/rust/daemon/src/rust_main.rs
+++ b/rust/daemon/src/rust_main.rs
@@ -191,7 +191,7 @@ fn run_netsimd_primary(args: NetsimdArgs) {
fd_startup_str,
args.no_cli_ui,
args.no_web_ui,
- args.pcap,
+ config.capture.enabled == Some(true) || args.pcap,
hci_port,
instance_num,
args.dev,
@@ -220,18 +220,27 @@ fn run_netsimd_primary(args: NetsimdArgs) {
spawn_shutdown_publisher(device_events_rx);
}
+ // Command line over-rides config file
+ if args.disable_address_reuse {
+ if let Some(v) = config.bluetooth.as_mut().unwrap().disable_address_reuse.as_mut() {
+ *v = true;
+ }
+ }
+
// Start radio facades
- echip::bluetooth::bluetooth_start(&config.bluetooth, instance_num, args.disable_address_reuse);
+ echip::bluetooth::bluetooth_start(&config.bluetooth, instance_num);
echip::wifi::wifi_start(&config.wifi);
// Maybe create test beacons, default true for cuttlefish
// TODO: remove default for cuttlefish by adding flag to tests
- if match (args.test_beacons, args.no_test_beacons) {
- (true, false) => true,
- (false, true) => false,
- (false, false) => cfg!(feature = "cuttlefish"),
- (true, true) => panic!("unexpected flag combination"),
- } {
+ if config.bluetooth.test_beacons == Some(true)
+ || match (args.test_beacons, args.no_test_beacons) {
+ (true, false) => true,
+ (false, true) => false,
+ (false, false) => cfg!(feature = "cuttlefish"),
+ (true, true) => panic!("unexpected flag combination"),
+ }
+ {
new_test_beacon(1, 1000);
new_test_beacon(2, 1000);
}
diff --git a/rust/proto/src/config.rs b/rust/proto/src/config.rs
index eefe931..8c37c32 100644
--- a/rust/proto/src/config.rs
+++ b/rust/proto/src/config.rs
@@ -723,8 +723,10 @@ pub struct Bluetooth {
// message fields
// @@protoc_insertion_point(field:netsim.config.Bluetooth.properties)
pub properties: ::protobuf::MessageField<super::configuration::Controller>,
- // @@protoc_insertion_point(field:netsim.config.Bluetooth.address_reuse)
- pub address_reuse: ::std::option::Option<bool>,
+ // @@protoc_insertion_point(field:netsim.config.Bluetooth.disable_address_reuse)
+ pub disable_address_reuse: ::std::option::Option<bool>,
+ // @@protoc_insertion_point(field:netsim.config.Bluetooth.test_beacons)
+ pub test_beacons: ::std::option::Option<bool>,
// special fields
// @@protoc_insertion_point(special_field:netsim.config.Bluetooth.special_fields)
pub special_fields: ::protobuf::SpecialFields,
@@ -742,7 +744,7 @@ impl Bluetooth {
}
fn generated_message_descriptor_data() -> ::protobuf::reflect::GeneratedMessageDescriptorData {
- let mut fields = ::std::vec::Vec::with_capacity(2);
+ let mut fields = ::std::vec::Vec::with_capacity(3);
let mut oneofs = ::std::vec::Vec::with_capacity(0);
fields.push(::protobuf::reflect::rt::v2::make_message_field_accessor::<_, super::configuration::Controller>(
"properties",
@@ -750,9 +752,14 @@ impl Bluetooth {
|m: &mut Bluetooth| { &mut m.properties },
));
fields.push(::protobuf::reflect::rt::v2::make_option_accessor::<_, _>(
- "address_reuse",
- |m: &Bluetooth| { &m.address_reuse },
- |m: &mut Bluetooth| { &mut m.address_reuse },
+ "disable_address_reuse",
+ |m: &Bluetooth| { &m.disable_address_reuse },
+ |m: &mut Bluetooth| { &mut m.disable_address_reuse },
+ ));
+ fields.push(::protobuf::reflect::rt::v2::make_option_accessor::<_, _>(
+ "test_beacons",
+ |m: &Bluetooth| { &m.test_beacons },
+ |m: &mut Bluetooth| { &mut m.test_beacons },
));
::protobuf::reflect::GeneratedMessageDescriptorData::new_2::<Bluetooth>(
"Bluetooth",
@@ -776,7 +783,10 @@ impl ::protobuf::Message for Bluetooth {
::protobuf::rt::read_singular_message_into_field(is, &mut self.properties)?;
},
16 => {
- self.address_reuse = ::std::option::Option::Some(is.read_bool()?);
+ self.disable_address_reuse = ::std::option::Option::Some(is.read_bool()?);
+ },
+ 24 => {
+ self.test_beacons = ::std::option::Option::Some(is.read_bool()?);
},
tag => {
::protobuf::rt::read_unknown_or_skip_group(tag, is, self.special_fields.mut_unknown_fields())?;
@@ -794,7 +804,10 @@ impl ::protobuf::Message for Bluetooth {
let len = v.compute_size();
my_size += 1 + ::protobuf::rt::compute_raw_varint64_size(len) + len;
}
- if let Some(v) = self.address_reuse {
+ if let Some(v) = self.disable_address_reuse {
+ my_size += 1 + 1;
+ }
+ if let Some(v) = self.test_beacons {
my_size += 1 + 1;
}
my_size += ::protobuf::rt::unknown_fields_size(self.special_fields.unknown_fields());
@@ -806,9 +819,12 @@ impl ::protobuf::Message for Bluetooth {
if let Some(v) = self.properties.as_ref() {
::protobuf::rt::write_message_field_with_cached_size(1, v, os)?;
}
- if let Some(v) = self.address_reuse {
+ if let Some(v) = self.disable_address_reuse {
os.write_bool(2, v)?;
}
+ if let Some(v) = self.test_beacons {
+ os.write_bool(3, v)?;
+ }
os.write_unknown_fields(self.special_fields.unknown_fields())?;
::std::result::Result::Ok(())
}
@@ -827,14 +843,16 @@ impl ::protobuf::Message for Bluetooth {
fn clear(&mut self) {
self.properties.clear();
- self.address_reuse = ::std::option::Option::None;
+ self.disable_address_reuse = ::std::option::Option::None;
+ self.test_beacons = ::std::option::Option::None;
self.special_fields.clear();
}
fn default_instance() -> &'static Bluetooth {
static instance: Bluetooth = Bluetooth {
properties: ::protobuf::MessageField::none(),
- address_reuse: ::std::option::Option::None,
+ disable_address_reuse: ::std::option::Option::None,
+ test_beacons: ::std::option::Option::None,
special_fields: ::protobuf::SpecialFields::new(),
};
&instance
@@ -859,6 +877,128 @@ impl ::protobuf::reflect::ProtobufValue for Bluetooth {
}
#[derive(PartialEq,Clone,Default,Debug)]
+// @@protoc_insertion_point(message:netsim.config.Capture)
+pub struct Capture {
+ // message fields
+ // @@protoc_insertion_point(field:netsim.config.Capture.enabled)
+ pub enabled: ::std::option::Option<bool>,
+ // special fields
+ // @@protoc_insertion_point(special_field:netsim.config.Capture.special_fields)
+ pub special_fields: ::protobuf::SpecialFields,
+}
+
+impl<'a> ::std::default::Default for &'a Capture {
+ fn default() -> &'a Capture {
+ <Capture as ::protobuf::Message>::default_instance()
+ }
+}
+
+impl Capture {
+ pub fn new() -> Capture {
+ ::std::default::Default::default()
+ }
+
+ fn generated_message_descriptor_data() -> ::protobuf::reflect::GeneratedMessageDescriptorData {
+ let mut fields = ::std::vec::Vec::with_capacity(1);
+ let mut oneofs = ::std::vec::Vec::with_capacity(0);
+ fields.push(::protobuf::reflect::rt::v2::make_option_accessor::<_, _>(
+ "enabled",
+ |m: &Capture| { &m.enabled },
+ |m: &mut Capture| { &mut m.enabled },
+ ));
+ ::protobuf::reflect::GeneratedMessageDescriptorData::new_2::<Capture>(
+ "Capture",
+ fields,
+ oneofs,
+ )
+ }
+}
+
+impl ::protobuf::Message for Capture {
+ const NAME: &'static str = "Capture";
+
+ fn is_initialized(&self) -> bool {
+ true
+ }
+
+ fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::Result<()> {
+ while let Some(tag) = is.read_raw_tag_or_eof()? {
+ match tag {
+ 8 => {
+ self.enabled = ::std::option::Option::Some(is.read_bool()?);
+ },
+ tag => {
+ ::protobuf::rt::read_unknown_or_skip_group(tag, is, self.special_fields.mut_unknown_fields())?;
+ },
+ };
+ }
+ ::std::result::Result::Ok(())
+ }
+
+ // Compute sizes of nested messages
+ #[allow(unused_variables)]
+ fn compute_size(&self) -> u64 {
+ let mut my_size = 0;
+ if let Some(v) = self.enabled {
+ my_size += 1 + 1;
+ }
+ my_size += ::protobuf::rt::unknown_fields_size(self.special_fields.unknown_fields());
+ self.special_fields.cached_size().set(my_size as u32);
+ my_size
+ }
+
+ fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::Result<()> {
+ if let Some(v) = self.enabled {
+ os.write_bool(1, v)?;
+ }
+ os.write_unknown_fields(self.special_fields.unknown_fields())?;
+ ::std::result::Result::Ok(())
+ }
+
+ fn special_fields(&self) -> &::protobuf::SpecialFields {
+ &self.special_fields
+ }
+
+ fn mut_special_fields(&mut self) -> &mut ::protobuf::SpecialFields {
+ &mut self.special_fields
+ }
+
+ fn new() -> Capture {
+ Capture::new()
+ }
+
+ fn clear(&mut self) {
+ self.enabled = ::std::option::Option::None;
+ self.special_fields.clear();
+ }
+
+ fn default_instance() -> &'static Capture {
+ static instance: Capture = Capture {
+ enabled: ::std::option::Option::None,
+ special_fields: ::protobuf::SpecialFields::new(),
+ };
+ &instance
+ }
+}
+
+impl ::protobuf::MessageFull for Capture {
+ fn descriptor() -> ::protobuf::reflect::MessageDescriptor {
+ static descriptor: ::protobuf::rt::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::Lazy::new();
+ descriptor.get(|| file_descriptor().message_by_package_relative_name("Capture").unwrap()).clone()
+ }
+}
+
+impl ::std::fmt::Display for Capture {
+ fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
+ ::protobuf::text_format::fmt(self, f)
+ }
+}
+
+impl ::protobuf::reflect::ProtobufValue for Capture {
+ type RuntimeType = ::protobuf::reflect::rt::RuntimeTypeMessage<Self>;
+}
+
+#[derive(PartialEq,Clone,Default,Debug)]
// @@protoc_insertion_point(message:netsim.config.Config)
pub struct Config {
// message fields
@@ -866,6 +1006,8 @@ pub struct Config {
pub bluetooth: ::protobuf::MessageField<Bluetooth>,
// @@protoc_insertion_point(field:netsim.config.Config.wifi)
pub wifi: ::protobuf::MessageField<WiFi>,
+ // @@protoc_insertion_point(field:netsim.config.Config.capture)
+ pub capture: ::protobuf::MessageField<Capture>,
// special fields
// @@protoc_insertion_point(special_field:netsim.config.Config.special_fields)
pub special_fields: ::protobuf::SpecialFields,
@@ -883,7 +1025,7 @@ impl Config {
}
fn generated_message_descriptor_data() -> ::protobuf::reflect::GeneratedMessageDescriptorData {
- let mut fields = ::std::vec::Vec::with_capacity(2);
+ let mut fields = ::std::vec::Vec::with_capacity(3);
let mut oneofs = ::std::vec::Vec::with_capacity(0);
fields.push(::protobuf::reflect::rt::v2::make_message_field_accessor::<_, Bluetooth>(
"bluetooth",
@@ -895,6 +1037,11 @@ impl Config {
|m: &Config| { &m.wifi },
|m: &mut Config| { &mut m.wifi },
));
+ fields.push(::protobuf::reflect::rt::v2::make_message_field_accessor::<_, Capture>(
+ "capture",
+ |m: &Config| { &m.capture },
+ |m: &mut Config| { &mut m.capture },
+ ));
::protobuf::reflect::GeneratedMessageDescriptorData::new_2::<Config>(
"Config",
fields,
@@ -919,6 +1066,9 @@ impl ::protobuf::Message for Config {
18 => {
::protobuf::rt::read_singular_message_into_field(is, &mut self.wifi)?;
},
+ 26 => {
+ ::protobuf::rt::read_singular_message_into_field(is, &mut self.capture)?;
+ },
tag => {
::protobuf::rt::read_unknown_or_skip_group(tag, is, self.special_fields.mut_unknown_fields())?;
},
@@ -939,6 +1089,10 @@ impl ::protobuf::Message for Config {
let len = v.compute_size();
my_size += 1 + ::protobuf::rt::compute_raw_varint64_size(len) + len;
}
+ if let Some(v) = self.capture.as_ref() {
+ let len = v.compute_size();
+ my_size += 1 + ::protobuf::rt::compute_raw_varint64_size(len) + len;
+ }
my_size += ::protobuf::rt::unknown_fields_size(self.special_fields.unknown_fields());
self.special_fields.cached_size().set(my_size as u32);
my_size
@@ -951,6 +1105,9 @@ impl ::protobuf::Message for Config {
if let Some(v) = self.wifi.as_ref() {
::protobuf::rt::write_message_field_with_cached_size(2, v, os)?;
}
+ if let Some(v) = self.capture.as_ref() {
+ ::protobuf::rt::write_message_field_with_cached_size(3, v, os)?;
+ }
os.write_unknown_fields(self.special_fields.unknown_fields())?;
::std::result::Result::Ok(())
}
@@ -970,6 +1127,7 @@ impl ::protobuf::Message for Config {
fn clear(&mut self) {
self.bluetooth.clear();
self.wifi.clear();
+ self.capture.clear();
self.special_fields.clear();
}
@@ -977,6 +1135,7 @@ impl ::protobuf::Message for Config {
static instance: Config = Config {
bluetooth: ::protobuf::MessageField::none(),
wifi: ::protobuf::MessageField::none(),
+ capture: ::protobuf::MessageField::none(),
special_fields: ::protobuf::SpecialFields::new(),
};
&instance
@@ -1020,13 +1179,17 @@ static file_descriptor_proto_data: &'static [u8] = b"\
\x18\x03\x20\x01(\tR\x06passwdB\x0b\n\t_disabled\"\x90\x01\n\x04WiFi\x12\
@\n\rslirp_options\x18\x01\x20\x01(\x0b2\x1b.netsim.config.SlirpOptionsR\
\x0cslirpOptions\x12F\n\x0fhostapd_options\x18\x02\x20\x01(\x0b2\x1d.net\
- sim.config.HostapdOptionsR\x0ehostapdOptions\"\xa0\x01\n\tBluetooth\x12H\
+ sim.config.HostapdOptionsR\x0ehostapdOptions\"\xf0\x01\n\tBluetooth\x12H\
\n\nproperties\x18\x01\x20\x01(\x0b2#.rootcanal.configuration.Controller\
- H\0R\nproperties\x88\x01\x01\x12(\n\raddress_reuse\x18\x02\x20\x01(\x08H\
- \x01R\x0caddressReuse\x88\x01\x01B\r\n\x0b_propertiesB\x10\n\x0e_address\
- _reuse\"i\n\x06Config\x126\n\tbluetooth\x18\x01\x20\x01(\x0b2\x18.netsim\
- .config.BluetoothR\tbluetooth\x12'\n\x04wifi\x18\x02\x20\x01(\x0b2\x13.n\
- etsim.config.WiFiR\x04wifib\x06proto3\
+ H\0R\nproperties\x88\x01\x01\x127\n\x15disable_address_reuse\x18\x02\x20\
+ \x01(\x08H\x01R\x13disableAddressReuse\x88\x01\x01\x12&\n\x0ctest_beacon\
+ s\x18\x03\x20\x01(\x08H\x02R\x0btestBeacons\x88\x01\x01B\r\n\x0b_propert\
+ iesB\x18\n\x16_disable_address_reuseB\x0f\n\r_test_beacons\"4\n\x07Captu\
+ re\x12\x1d\n\x07enabled\x18\x01\x20\x01(\x08H\0R\x07enabled\x88\x01\x01B\
+ \n\n\x08_enabled\"\x9b\x01\n\x06Config\x126\n\tbluetooth\x18\x01\x20\x01\
+ (\x0b2\x18.netsim.config.BluetoothR\tbluetooth\x12'\n\x04wifi\x18\x02\
+ \x20\x01(\x0b2\x13.netsim.config.WiFiR\x04wifi\x120\n\x07capture\x18\x03\
+ \x20\x01(\x0b2\x16.netsim.config.CaptureR\x07captureb\x06proto3\
";
/// `FileDescriptorProto` object which was a source for this generated file
@@ -1045,11 +1208,12 @@ pub fn file_descriptor() -> &'static ::protobuf::reflect::FileDescriptor {
let generated_file_descriptor = generated_file_descriptor_lazy.get(|| {
let mut deps = ::std::vec::Vec::with_capacity(1);
deps.push(super::configuration::file_descriptor().clone());
- let mut messages = ::std::vec::Vec::with_capacity(5);
+ let mut messages = ::std::vec::Vec::with_capacity(6);
messages.push(SlirpOptions::generated_message_descriptor_data());
messages.push(HostapdOptions::generated_message_descriptor_data());
messages.push(WiFi::generated_message_descriptor_data());
messages.push(Bluetooth::generated_message_descriptor_data());
+ messages.push(Capture::generated_message_descriptor_data());
messages.push(Config::generated_message_descriptor_data());
let mut enums = ::std::vec::Vec::with_capacity(0);
::protobuf::reflect::GeneratedFileDescriptor::new_generated(
diff --git a/src/hci/bluetooth_facade.cc b/src/hci/bluetooth_facade.cc
index 7195f46..5b25399 100644
--- a/src/hci/bluetooth_facade.cc
+++ b/src/hci/bluetooth_facade.cc
@@ -198,7 +198,7 @@ void SetUpTestChannel(uint16_t instance_num) {
// Initialize the rootcanal library.
void Start(const rust::Slice<::std::uint8_t const> proto_bytes,
- uint16_t instance_num, bool disable_address_reuse) {
+ uint16_t instance_num) {
if (gStarted) return;
// output is to a file, so no color wanted
@@ -238,8 +238,10 @@ void Start(const rust::Slice<::std::uint8_t const> proto_bytes,
rootcanal::Phy::Type /* phy_type */) { return nullptr; });
// Disable Address Reuse if '--disable_address_reuse' flag is true
- // TODO: once config files are active, use the value from config proto
- gTestModel->SetReuseDeviceAddresses(!disable_address_reuse);
+ // Enable Address Reuse if 'address_reuse' is true
+ if (config.has_disable_address_reuse()) {
+ gTestModel->SetReuseDeviceAddresses(!config.disable_address_reuse());
+ }
// NOTE: 0:BR_EDR, 1:LOW_ENERGY. The order is used by bluetooth CTS.
phy_classic_index_ = gTestModel->AddPhy(rootcanal::Phy::Type::BR_EDR);
diff --git a/src/hci/bluetooth_facade.h b/src/hci/bluetooth_facade.h
index bb84e0d..fa6c730 100644
--- a/src/hci/bluetooth_facade.h
+++ b/src/hci/bluetooth_facade.h
@@ -51,7 +51,7 @@ void SetRustDeviceAddress(
void RemoveRustDevice(uint32_t rootcanal_id);
void Start(const rust::Slice<::std::uint8_t const> proto_bytes,
- uint16_t instance_num, bool disable_address_reuse);
+ uint16_t instance_num);
void Stop();
// Cxx functions for rust ffi.