Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 74fdf687 authored by Charlie Boutier's avatar Charlie Boutier Committed by Android (Google) Code Review
Browse files

Merge changes from topic "update-rootcanal" into tm-qpr-dev

* changes:
  RootCanal: Remove unused devices
  Rootcanal: Increase encryption key size
  Use address type from config for le advertisement
  RootCanal: Fix LE advertising with legacy HCI commands
  [RootCanal] Add support for LinkPolicy and RoleChange in RootCanal
  Add support for cargo build of LMP
  Add libbt_packets build target without apex
  RootCanal: Fix typos in enhanced eSCO link commands parameter validation
  Export Bluetooth headers in libbt-rootcanal
  Make rootcanal package visible to tools/netsim
  RootCanal: Implement support for enhanced synchronous link commands
  RootCanal: Secure Connections controller support
  Add support for rewritting RssiWrapper packets in TestModel.
  RootCanal: Fix LMP accepted opcode definition
  RootCanal: Add a Baseband sniffer
  Allow toggling pcap logging on/off
  liblmp: Add tests from Bluetooth SIG LMP TestSuite
  RootCanal: Remove unused keys from controller_properties.json
  RootCanal: Set default HCI Version in device_properties to 5.3
  hci_packets.pdl: Add 5.3 version constants
  RootCanal: Add a readme
  RootCanal: Create OWNERS file
parents 20001982 7f6588dc
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ VALID_TARGETS = [
    'docs',  # Build Rust docs
    'main',  # Build the main C++ codebase
    'prepare',  # Prepare the output directory (gn gen + rust setup)
    'rootcanal',  # Build Rust targets for RootCanal
    'rust',  # Build only the rust components + copy artifacts to output dir
    'test',  # Run the unit tests
    'tools',  # Build the host tools (i.e. packetgen)
@@ -428,6 +429,11 @@ class HostBuild():
        """
        self._rust_build()

    def _target_rootcanal(self):
        """ Build rust artifacts for RootCanal in an already prepared environment.
        """
        self.run_command('rust', ['cargo', 'build'], cwd=os.path.join(self.platform_dir, 'bt/tools/rootcanal'), env=self.env)

    def _target_main(self):
        """ Build the main GN artifacts in an already prepared environment.
        """
@@ -442,6 +448,7 @@ class HostBuild():
            rust_test_cmd = rust_test_cmd + [self.args.test_name]

        self.run_command('test', rust_test_cmd, cwd=os.path.join(self.platform_dir, 'bt'), env=self.env)
        self.run_command('test', rust_test_cmd, cwd=os.path.join(self.platform_dir, 'bt/tools/rootcanal'), env=self.env)

        # Host tests second based on host test list
        for t in HOST_TESTS:
@@ -537,6 +544,8 @@ class HostBuild():
            self._target_prepare()
        elif self.target == 'tools':
            self._target_tools()
        elif self.target == 'rootcanal':
            self._target_rootcanal()
        elif self.target == 'rust':
            self._target_rust()
        elif self.target == 'docs':
+18 −0
Original line number Diff line number Diff line
@@ -632,6 +632,24 @@ rust_library {
    min_sdk_version: "30",
}

rust_library {
    name: "libbt_packets_nonapex",
    defaults: ["gd_rust_defaults"],
    crate_name: "bt_packets",
    srcs: ["rust/packets/lib.rs", ":BluetoothGeneratedPackets_rust"],
    edition: "2018",
    vendor_available : true,
    host_supported: true,
    proc_macros: ["libnum_derive"],
    rustlibs: [
        "libbytes",
        "libnum_traits",
        "libthiserror",
        "liblog_rust",
    ],
    min_sdk_version: "30",
}

rust_test_host {
    name: "libbt_packets_test",
    defaults: [
+49 −31
Original line number Diff line number Diff line
@@ -1168,6 +1168,26 @@ packet ReadLmpHandleComplete : CommandComplete (command_op_code = READ_LMP_HANDL
  _reserved_ : 32,
}

enum SynchronousPacketTypeBits : 16 {
  HV1_ALLOWED = 0x0001,
  HV2_ALLOWED = 0x0002,
  HV3_ALLOWED = 0x0004,
  EV3_ALLOWED = 0x0008,
  EV4_ALLOWED = 0x0010,
  EV5_ALLOWED = 0x0020,
  NO_2_EV3_ALLOWED = 0x0040,
  NO_3_EV3_ALLOWED = 0x0080,
  NO_2_EV5_ALLOWED = 0x0100,
  NO_3_EV5_ALLOWED = 0x0200,
}

enum RetransmissionEffort : 8 {
  NO_RETRANSMISSION = 0x00,
  OPTIMIZED_FOR_POWER = 0x01,
  OPTIMIZED_FOR_LINK_QUALITY = 0x02,
  DO_NOT_CARE = 0xFF,
}

packet SetupSynchronousConnection : ScoConnectionCommand (op_code = SETUP_SYNCHRONOUS_CONNECTION) {
  connection_handle : 12,
  _reserved_ : 4,
@@ -1176,8 +1196,8 @@ packet SetupSynchronousConnection : ScoConnectionCommand (op_code = SETUP_SYNCHR
  max_latency : 16, // 0-3 reserved, 0xFFFF = don't care
  voice_setting : 10,
  _reserved_ : 6,
  retransmission_effort : 8,
  packet_type : 16,
  retransmission_effort : RetransmissionEffort,
  packet_type : 16, // See SynchronousPacketTypeBits
}

packet SetupSynchronousConnectionStatus : CommandStatus (command_op_code = SETUP_SYNCHRONOUS_CONNECTION) {
@@ -1190,8 +1210,8 @@ packet AcceptSynchronousConnection : ScoConnectionCommand (op_code = ACCEPT_SYNC
  max_latency : 16, // 0-3 reserved, 0xFFFF = don't care
  voice_setting : 10,
  _reserved_ : 6,
  retransmission_effort : 8,
  packet_type : 16,
  retransmission_effort : RetransmissionEffort,
  packet_type : 16, // See SynchronousPacketTypeBits
}

packet AcceptSynchronousConnectionStatus : CommandStatus (command_op_code = ACCEPT_SYNCHRONOUS_CONNECTION) {
@@ -1342,34 +1362,14 @@ enum ScoDataPath : 8 {
  AUDIO_TEST_MODE = 0xFF,
}

enum SynchronousPacketTypeBits : 16 {
  HV1_ALLOWED = 0x0001,
  HV2_ALLOWED = 0x0002,
  HV3_ALLOWED = 0x0004,
  EV3_ALLOWED = 0x0008,
  EV4_ALLOWED = 0x0010,
  EV5_ALLOWED = 0x0020,
  NO_2_EV3_ALLOWED = 0x0040,
  NO_3_EV3_ALLOWED = 0x0080,
  NO_2_EV5_ALLOWED = 0x0100,
  NO_3_EV5_ALLOWED = 0x0200,
}

enum RetransmissionEffort : 8 {
  NO_RETRANSMISSION = 0x00,
  OPTIMIZED_FOR_POWER = 0x01,
  OPTIMIZED_FOR_LINK_QUALITY = 0x02,
  DO_NOT_CARE = 0xFF,
}

packet EnhancedSetupSynchronousConnection : ScoConnectionCommand (op_code = ENHANCED_SETUP_SYNCHRONOUS_CONNECTION) {
  connection_handle: 12,
  _reserved_ : 4,
  // Next two items
  // [0x00000000, 0xFFFFFFFE] Bandwidth in octets per second.
  // [0xFFFFFFFF]: Don't care
  transmit_bandwidth_octets_per_second : 32,
  receive_bandwidth_octets_per_second : 32,
  transmit_bandwidth : 32,
  receive_bandwidth : 32,
  transmit_coding_format : ScoCodingFormat,
  receive_coding_format : ScoCodingFormat,
  // Next two items
@@ -1379,8 +1379,8 @@ packet EnhancedSetupSynchronousConnection : ScoConnectionCommand (op_code = ENHA
  receive_codec_frame_size : 16,
  // Next two items
  // Host to Controller nominal data rate in octets per second.
  input_bandwidth_octets_per_second : 32,
  output_bandwidth_octets_per_second : 32,
  input_bandwidth : 32,
  output_bandwidth : 32,
  input_coding_format : ScoCodingFormat,
  output_coding_format : ScoCodingFormat,
  // Next two items
@@ -1407,11 +1407,15 @@ packet EnhancedSetupSynchronousConnection : ScoConnectionCommand (op_code = ENHA
  //     of the eSCO window, where the eSCO window is reserved slots plus the
  //     retransmission window
  // [0xFFFF]: don't care
  max_latency_ms: 16,
  packet_type : 16, // Or together SynchronousPacketTypeBits
  max_latency: 16,
  packet_type : 16, // See SynchronousPacketTypeBits
  retransmission_effort : RetransmissionEffort,
}

test EnhancedSetupSynchronousConnection {
  "\x3d\x04\x3b\x02\x00\x40\x1f\x00\x00\x40\x1f\x00\x00\x05\x00\x00\x00\x00\x05\x00\x00\x00\x00\x3c\x00\x3c\x00\x00\x7d\x00\x00\x00\x7d\x00\x00\x04\x00\x00\x00\x00\x04\x00\x00\x00\x00\x10\x00\x10\x00\x02\x02\x00\x00\x01\x01\x00\x00\x0d\x00\x88\x03\x02",
}

packet EnhancedSetupSynchronousConnectionStatus : CommandStatus (command_op_code = ENHANCED_SETUP_SYNCHRONOUS_CONNECTION) {
}

@@ -1460,7 +1464,7 @@ packet EnhancedAcceptSynchronousConnection : ScoConnectionCommand (op_code = ENH
  //     retransmission window
  // [0xFFFF]: don't care
  max_latency : 16,
  packet_type : 16, // Or together SynchronousPacketTypeBits
  packet_type : 16, // See SynchronousPacketTypeBits
  retransmission_effort : RetransmissionEffort,
}

@@ -2515,6 +2519,7 @@ enum HciVersion : 8 {
  V_5_0 = 0x09,
  V_5_1 = 0x0a,
  V_5_2 = 0x0b,
  V_5_3 = 0x0c,
}

enum LmpVersion : 8 {
@@ -2530,6 +2535,7 @@ enum LmpVersion : 8 {
  V_5_0 = 0x09,
  V_5_1 = 0x0a,
  V_5_2 = 0x0b,
  V_5_3 = 0x0c,
}

struct LocalVersionInformation {
@@ -5349,6 +5355,10 @@ packet SynchronousConnectionComplete : Event (event_code = SYNCHRONOUS_CONNECTIO
  air_mode : ScoAirMode,
}

test SynchronousConnectionComplete {
  "\x2c\x11\x00\x03\x00\x1d\xdf\xed\x2b\x1a\xf8\x02\x0c\x04\x3c\x00\x3c\x00\x03",
}

packet SynchronousConnectionChanged : Event (event_code = SYNCHRONOUS_CONNECTION_CHANGED) {
  status : ErrorCode,
  connection_handle : 12,
@@ -5442,6 +5452,10 @@ packet EnhancedFlush : Command (op_code = ENHANCED_FLUSH) {
  packet_type : FlushablePacketType,
}

test EnhancedFlush {
  "\x5f\x0c\x03\x02\x00\x00",
}

packet EnhancedFlushStatus : CommandStatus (command_op_code = ENHANCED_FLUSH) {
}

@@ -5450,6 +5464,10 @@ packet EnhancedFlushComplete : Event (event_code = ENHANCED_FLUSH_COMPLETE) {
  _reserved_ : 4,
}

test EnhancedFlushComplete {
  "\x39\x02\x02\x00",
}

packet UserPasskeyNotification : Event (event_code = USER_PASSKEY_NOTIFICATION) {
  bd_addr : Address,
  passkey : 20, // 0x00000-0xF423F (000000 - 999999)
+19 −2
Original line number Diff line number Diff line
@@ -18,8 +18,22 @@ use std::path::{Path, PathBuf};
use std::process::Command;

fn main() {
    let packets_prebuilt = match env::var("HCI_PACKETS_PREBUILT") {
        Ok(dir) => PathBuf::from(dir),
        Err(_) => PathBuf::from("hci_packets.rs"),
    };
    if Path::new(packets_prebuilt.as_os_str()).exists() {
        let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
        let outputted = out_dir.join("../../hci/hci_packets.rs");
        std::fs::copy(
            packets_prebuilt.as_os_str().to_str().unwrap(),
            out_dir.join(outputted.file_name().unwrap()).as_os_str().to_str().unwrap(),
        )
        .unwrap();
    } else {
        generate_packets();
    }
}

fn generate_packets() {
    let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
@@ -40,7 +54,10 @@ fn generate_packets() {
    };

    if !Path::new(packetgen.as_os_str()).exists() {
        panic!("Unable to locate bluetooth packet generator:{:?}", packetgen.as_os_str().to_str().unwrap());
        panic!(
            "Unable to locate bluetooth packet generator:{:?}",
            packetgen.as_os_str().to_str().unwrap()
        );
    }

    for i in 0..input_files.len() {
+3 −2
Original line number Diff line number Diff line
@@ -399,9 +399,10 @@ class BleAdvertiserInterfaceImpl : public BleAdvertiserInterface,
    config.enable_scan_request_notifications =
        static_cast<bluetooth::hci::Enable>(
            params.scan_request_notification_enable);

    // TODO set own_address_type based on address policy
    config.own_address_type = OwnAddressType::RANDOM_DEVICE_ADDRESS;
    if (params.own_address_type == 0) {
      config.own_address_type = OwnAddressType::PUBLIC_DEVICE_ADDRESS;
    }
  }
  std::map<uint8_t, GetAddressCallback> address_callbacks_;
};
Loading