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

Commit edef9b9c authored by Archie Pusaka's avatar Archie Pusaka Committed by Gerrit Code Review
Browse files

Merge changes I0ede46f8,Iaeb06fa4,Ic8f8860a,Id93d52a5 into main

* changes:
  Hcidoc: Use hci_packets.pdl in rootcanal
  RootCanal: Add Authenticated Payload Timeout Expired event
  Hcidoc: Add disconnection initiator information
  Hcidoc: Print cid info
parents 246f0bb8 b309d99f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ fn generate_packets() {
    );

    let out_file = File::create(out_dir.join("hci_packets.rs")).unwrap();
    let in_file = PathBuf::from("../../../system/pdl/hci/hci_packets.pdl");
    let in_file = PathBuf::from("../../../tools/rootcanal/packets/hci_packets.pdl");

    println!("cargo:rerun-if-changed={}", in_file.display());
    let output = Command::new("pdlc")
+42 −0
Original line number Diff line number Diff line
@@ -36,4 +36,46 @@ pub mod hci {
            bytes[0..6].try_into().unwrap()
        }
    }

    pub struct GapData {
        pub data_type: GapDataType,
        pub data: Vec<u8>,
    }

    impl GapData {
        pub fn parse(bytes: &[u8]) -> std::result::Result<Self, String> {
            // In case of parsing EIR, we can get normal data, or all zeroes. Normal data always
            // have at least 2 bytes: one for the length, and another for the type. Therefore we
            // can terminate early if the data has less than 2 bytes.
            if (bytes.len() == 0) {
                return Err("no data to parse".to_string());
            } else if (bytes.len() == 1) {
                if (bytes[0] != 0) {
                    return Err(format!("can't parse 1 byte of data: {}", bytes[0]));
                }
                return Ok(GapData { data_type: GapDataType::Invalid, data: vec![] });
            }

            let mut data_size = bytes[0] as usize;
            if (data_size == 0) {
                // Data size already include the data_type, so size = 0 is possible only when
                // parsing EIR, where all data are zeroes. Here we just assume that assumption is
                // correct, and don't really check all the elements.
                return Ok(GapData { data_type: GapDataType::Invalid, data: bytes[2..].to_vec() });
            }

            if (data_size > bytes.len() - 1) {
                return Err(format!(
                    "size {} is bigger than remaining length {}",
                    data_size,
                    bytes.len() - 1
                ));
            }
            let data_type = match GapDataType::try_from(bytes[1]) {
                Ok(data_type) => Ok(data_type),
                Err(_) => Err(format!("can't parse data type {}", bytes[1])),
            }?;
            return Ok(GapData { data_type, data: bytes[2..(data_size + 1)].to_vec() });
        }
    }
}
+95 −137
Original line number Diff line number Diff line
@@ -8,11 +8,9 @@ use std::slice::Iter;
use crate::engine::{Rule, RuleGroup, Signal};
use crate::parser::{Packet, PacketChild};
use hcidoc_packets::hci::{
    Acl, AclCommandChild, Address, AuthenticatedPayloadTimeoutExpired, CommandChild,
    ConnectionManagementCommandChild, DisconnectReason, Enable, ErrorCode, EventChild,
    InitiatorFilterPolicy, LeConnectionManagementCommandChild, LeMetaEventChild,
    LeSecurityCommandChild, NumberOfCompletedPackets, OpCode, ScoConnectionCommandChild,
    SecurityCommandChild,
    Acl, Address, AuthenticatedPayloadTimeoutExpired, CommandChild, DisconnectReason, Enable,
    ErrorCode, EventChild, InitiatorFilterPolicy, LeMetaEventChild, NumberOfCompletedPackets,
    OpCode,
};

enum ConnectionSignal {
@@ -626,100 +624,77 @@ impl Rule for OddDisconnectionsRule {
    fn process(&mut self, packet: &Packet) {
        match &packet.inner {
            PacketChild::HciCommand(cmd) => match cmd.specialize() {
                CommandChild::AclCommand(aclpkt) => match aclpkt.specialize() {
                    AclCommandChild::ConnectionManagementCommand(conn) => match conn.specialize() {
                        ConnectionManagementCommandChild::CreateConnection(cc) => {
                CommandChild::CreateConnection(cc) => {
                    self.process_classic_connection(cc.get_bd_addr(), packet);
                }
                        ConnectionManagementCommandChild::AcceptConnectionRequest(ac) => {
                CommandChild::AcceptConnectionRequest(ac) => {
                    self.process_classic_connection(ac.get_bd_addr(), packet);
                }
                        ConnectionManagementCommandChild::ReadRemoteSupportedFeatures(rrsf) => {
                CommandChild::ReadRemoteSupportedFeatures(rrsf) => {
                    self.process_remote_feat_cmd(
                        PendingRemoteFeature::Supported,
                        &rrsf.get_connection_handle(),
                        packet,
                    );
                }
                        ConnectionManagementCommandChild::ReadRemoteExtendedFeatures(rref) => {
                CommandChild::ReadRemoteExtendedFeatures(rref) => {
                    self.process_remote_feat_cmd(
                        PendingRemoteFeature::Extended,
                        &rref.get_connection_handle(),
                        packet,
                    );
                }
                        // End ConnectionManagementCommand.specialize()
                        _ => {}
                    },
                    AclCommandChild::ScoConnectionCommand(sco_con) => match sco_con.specialize() {
                        ScoConnectionCommandChild::SetupSynchronousConnection(ssc) => {
                            let address =
                                self.convert_sco_handle_to_address(ssc.get_connection_handle());
                CommandChild::SetupSynchronousConnection(ssc) => {
                    let address = self.convert_sco_handle_to_address(ssc.get_connection_handle());
                    self.process_sync_connection(address, packet);
                }
                        ScoConnectionCommandChild::EnhancedSetupSynchronousConnection(esc) => {
                            let address =
                                self.convert_sco_handle_to_address(esc.get_connection_handle());
                CommandChild::EnhancedSetupSynchronousConnection(esc) => {
                    let address = self.convert_sco_handle_to_address(esc.get_connection_handle());
                    self.process_sync_connection(address, packet);
                }
                        ScoConnectionCommandChild::AcceptSynchronousConnection(asc) => {
                CommandChild::AcceptSynchronousConnection(asc) => {
                    self.process_sync_connection(asc.get_bd_addr(), packet);
                }
                        ScoConnectionCommandChild::EnhancedAcceptSynchronousConnection(easc) => {
                CommandChild::EnhancedAcceptSynchronousConnection(easc) => {
                    self.process_sync_connection(easc.get_bd_addr(), packet);
                }
                        // End ScoConnectionCommand.specialize()
                        _ => {}
                    },
                    AclCommandChild::LeConnectionManagementCommand(le_conn) => match le_conn
                        .specialize()
                    {
                        LeConnectionManagementCommandChild::LeCreateConnection(lcc) => {
                CommandChild::LeCreateConnection(lcc) => {
                    self.process_le_create_connection(
                        lcc.get_peer_address(),
                        lcc.get_initiator_filter_policy(),
                        packet,
                    );
                }
                        LeConnectionManagementCommandChild::LeExtendedCreateConnection(lecc) => {
                CommandChild::LeExtendedCreateConnection(lecc) => {
                    self.process_le_create_connection(
                        lecc.get_peer_address(),
                        lecc.get_initiator_filter_policy(),
                        packet,
                    );
                }
                        LeConnectionManagementCommandChild::LeAddDeviceToFilterAcceptList(laac) => {
                CommandChild::LeAddDeviceToFilterAcceptList(laac) => {
                    self.process_add_accept_list(laac.get_address(), packet);
                }
                        LeConnectionManagementCommandChild::LeRemoveDeviceFromFilterAcceptList(
                            lrac,
                        ) => {
                CommandChild::LeRemoveDeviceFromFilterAcceptList(lrac) => {
                    self.process_remove_accept_list(lrac.get_address(), packet);
                }
                        LeConnectionManagementCommandChild::LeClearFilterAcceptList(_lcac) => {
                CommandChild::LeClearFilterAcceptList(_lcac) => {
                    self.process_clear_accept_list(packet);
                }
                        LeConnectionManagementCommandChild::LeReadRemoteFeatures(lrrf) => {
                CommandChild::LeReadRemoteFeatures(lrrf) => {
                    self.process_remote_feat_cmd(
                        PendingRemoteFeature::Le,
                        &lrrf.get_connection_handle(),
                        packet,
                    );
                }
                        // End LeConnectionManagementCommand.specialize()
                        _ => {}
                    },
                    AclCommandChild::Disconnect(dc_conn) => {
                CommandChild::Disconnect(dc_conn) => {
                    self.process_disconnect_cmd(
                        dc_conn.get_reason(),
                        dc_conn.get_connection_handle(),
                        packet,
                    );
                }

                    // End AclCommand.specialize()
                    _ => (),
                },
                CommandChild::Reset(_) => {
                    self.process_reset();
                }
@@ -754,6 +729,7 @@ impl Rule for OddDisconnectionsRule {
                EventChild::NumberOfCompletedPackets(nocp) => {
                    self.process_nocp(&nocp, packet);
                }

                EventChild::AuthenticatedPayloadTimeoutExpired(apte) => {
                    self.process_apte(&apte, packet);
                }
@@ -1008,11 +984,10 @@ impl Rule for LinkKeyMismatchRule {
            },

            PacketChild::HciCommand(cmd) => match cmd.specialize() {
                CommandChild::AclCommand(cmd) => match cmd.specialize() {
                // Have an arm for Disconnect since sometimes we don't receive disconnect
                // event when powering off. However, no need to actually match the reason
                // since we just clean the handle in both cases.
                    AclCommandChild::Disconnect(cmd) => {
                CommandChild::Disconnect(cmd) => {
                    self.process_handle_auth(
                        ErrorCode::Success,
                        cmd.get_connection_handle(),
@@ -1020,32 +995,15 @@ impl Rule for LinkKeyMismatchRule {
                    );
                    self.handles.remove(&cmd.get_connection_handle());
                }

                    // CommandChild::AclCommand(cmd).specialize()
                    _ => {}
                },

                CommandChild::SecurityCommand(cmd) => match cmd.specialize() {
                    SecurityCommandChild::LinkKeyRequestReply(cmd) => {
                CommandChild::LinkKeyRequestReply(cmd) => {
                    self.process_reply_link_key(cmd.get_bd_addr(), true);
                }
                    SecurityCommandChild::LinkKeyRequestNegativeReply(cmd) => {
                CommandChild::LinkKeyRequestNegativeReply(cmd) => {
                    self.process_reply_link_key(cmd.get_bd_addr(), false);
                }

                    // CommandChild::SecurityCommand(cmd).specialize()
                    _ => {}
                },

                CommandChild::LeSecurityCommand(cmd) => match cmd.specialize() {
                    LeSecurityCommandChild::LeStartEncryption(cmd) => {
                CommandChild::LeStartEncryption(cmd) => {
                    self.pending_le_encrypt.insert(cmd.get_connection_handle());
                }

                    // CommandChild::LeSecurityCommand(cmd).specialize()
                    _ => {}
                },

                CommandChild::Reset(_) => {
                    self.process_reset();
                }
+162 −108

File changed.

Preview size limit exceeded, changes collapsed.

+6 −0
Original line number Diff line number Diff line
@@ -749,6 +749,7 @@ enum EventCode : 8 {
  REMOTE_HOST_SUPPORTED_FEATURES_NOTIFICATION = 0x3D,
  LE_META_EVENT = 0x3e,
  NUMBER_OF_COMPLETED_DATA_BLOCKS = 0x48,
  AUTHENTICATED_PAYLOAD_TIMEOUT_EXPIRED = 0x57,
  ENCRYPTION_CHANGE_V2 = 0x59,
  VENDOR_SPECIFIC = 0xFF,
}
@@ -5134,6 +5135,11 @@ packet NumberOfCompletedDataBlocks : Event (event_code = NUMBER_OF_COMPLETED_DAT
  _payload_, // placeholder (unimplemented)
}

packet AuthenticatedPayloadTimeoutExpired : Event (event_code = AUTHENTICATED_PAYLOAD_TIMEOUT_EXPIRED) {
  connection_handle : 12,
  _reserved_ : 4,
}

// LE Events
packet LeConnectionComplete : LeMetaEvent (subevent_code = CONNECTION_COMPLETE) {
  status : ErrorCode,