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

Commit 0f217667 authored by Ying Hsu's avatar Ying Hsu Committed by Automerger Merge Worker
Browse files

Merge "floss: hcidoc: Add Authenticated Payload Timeout Expired event" into...

Merge "floss: hcidoc: Add Authenticated Payload Timeout Expired event" into main am: 9297ffed am: d6c2eff1

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2737533



Change-Id: Iba1f9ff999b34fb5543be166cf55b3e19f9792eb
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 8f239f8b d6c2eff1
Loading
Loading
Loading
Loading
+40 −4
Original line number Original line Diff line number Diff line
@@ -7,16 +7,17 @@ use std::io::Write;
use crate::engine::{Rule, RuleGroup, Signal};
use crate::engine::{Rule, RuleGroup, Signal};
use crate::parser::{Packet, PacketChild};
use crate::parser::{Packet, PacketChild};
use bt_packets::hci::{
use bt_packets::hci::{
    Acl, AclCommandChild, Address, CommandChild, CommandStatus, ConnectionManagementCommandChild,
    Acl, AclCommandChild, Address, AuthenticatedPayloadTimeoutExpired, CommandChild, CommandStatus,
    DisconnectReason, ErrorCode, Event, EventChild, LeConnectionManagementCommandChild,
    ConnectionManagementCommandChild, DisconnectReason, ErrorCode, Event, EventChild,
    LeMetaEventChild, NumberOfCompletedPackets, OpCode, ScoConnectionCommandChild,
    LeConnectionManagementCommandChild, LeMetaEventChild, NumberOfCompletedPackets, OpCode,
    SecurityCommandChild, SubeventCode,
    ScoConnectionCommandChild, SecurityCommandChild, SubeventCode,
};
};


enum ConnectionSignal {
enum ConnectionSignal {
    LinkKeyMismatch, // Peer forgets the link key or it mismatches ours
    LinkKeyMismatch, // Peer forgets the link key or it mismatches ours
    NocpDisconnect,  // Peer is disconnected when NOCP packet isn't yet received
    NocpDisconnect,  // Peer is disconnected when NOCP packet isn't yet received
    NocpTimeout,     // Host doesn't receive NOCP packet 5 seconds after ACL is sent
    NocpTimeout,     // Host doesn't receive NOCP packet 5 seconds after ACL is sent
    ApteDisconnect,  // Host doesn't receive a packet with valid MIC for a while.
}
}


impl Into<&'static str> for ConnectionSignal {
impl Into<&'static str> for ConnectionSignal {
@@ -25,6 +26,7 @@ impl Into<&'static str> for ConnectionSignal {
            ConnectionSignal::LinkKeyMismatch => "LinkKeyMismatch",
            ConnectionSignal::LinkKeyMismatch => "LinkKeyMismatch",
            ConnectionSignal::NocpDisconnect => "Nocp",
            ConnectionSignal::NocpDisconnect => "Nocp",
            ConnectionSignal::NocpTimeout => "Nocp",
            ConnectionSignal::NocpTimeout => "Nocp",
            ConnectionSignal::ApteDisconnect => "AuthenticatedPayloadTimeoutExpired",
        }
        }
    }
    }
}
}
@@ -73,6 +75,9 @@ struct OddDisconnectionsRule {
    /// identify bursts.
    /// identify bursts.
    nocp_by_handle: HashMap<ConnectionHandle, NocpData>,
    nocp_by_handle: HashMap<ConnectionHandle, NocpData>,


    /// Number of |Authenticated Payload Timeout Expired| events hapened.
    apte_by_handle: HashMap<ConnectionHandle, u32>,

    /// Pre-defined signals discovered in the logs.
    /// Pre-defined signals discovered in the logs.
    signals: Vec<Signal>,
    signals: Vec<Signal>,


@@ -91,6 +96,7 @@ impl OddDisconnectionsRule {
            sco_connection_attempt: HashMap::new(),
            sco_connection_attempt: HashMap::new(),
            last_sco_connection_attempt: None,
            last_sco_connection_attempt: None,
            nocp_by_handle: HashMap::new(),
            nocp_by_handle: HashMap::new(),
            apte_by_handle: HashMap::new(),
            signals: vec![],
            signals: vec![],
            reportable: vec![],
            reportable: vec![],
        }
        }
@@ -315,6 +321,26 @@ impl OddDisconnectionsRule {


                // Remove nocp information for handles that were removed.
                // Remove nocp information for handles that were removed.
                self.nocp_by_handle.remove(&handle);
                self.nocp_by_handle.remove(&handle);

                // Check if auth payload timeout happened.
                match self.apte_by_handle.get_mut(&handle) {
                    Some(apte_count) => {
                        self.signals.push(Signal {
                            index: packet.index,
                            ts: packet.ts.clone(),
                            tag: ConnectionSignal::ApteDisconnect.into(),
                        });

                        self.reportable.push((
                            packet.ts,
                            format!("DisconnectionComplete with {} Authenticated Payload Timeout Expired (handle={})",
                            apte_count, handle)));
                    }
                    None => (),
                }

                // Remove apte information for handles that were removed.
                self.apte_by_handle.remove(&handle);
            }
            }


            EventChild::SynchronousConnectionComplete(scc) => {
            EventChild::SynchronousConnectionComplete(scc) => {
@@ -436,6 +462,11 @@ impl OddDisconnectionsRule {
        }
        }
    }
    }


    fn process_apte(&mut self, apte: &AuthenticatedPayloadTimeoutExpired, _packet: &Packet) {
        let handle = apte.get_connection_handle();
        *self.apte_by_handle.entry(handle).or_insert(0) += 1;
    }

    fn process_reset(&mut self) {
    fn process_reset(&mut self) {
        self.active_handles.clear();
        self.active_handles.clear();
        self.connection_attempt.clear();
        self.connection_attempt.clear();
@@ -445,6 +476,7 @@ impl OddDisconnectionsRule {
        self.sco_connection_attempt.clear();
        self.sco_connection_attempt.clear();
        self.last_sco_connection_attempt = None;
        self.last_sco_connection_attempt = None;
        self.nocp_by_handle.clear();
        self.nocp_by_handle.clear();
        self.apte_by_handle.clear();
    }
    }
}
}


@@ -518,6 +550,10 @@ impl Rule for OddDisconnectionsRule {
                    self.process_nocp(&nocp, packet);
                    self.process_nocp(&nocp, packet);
                }
                }


                EventChild::AuthenticatedPayloadTimeoutExpired(apte) => {
                    self.process_apte(&apte, packet);
                }

                // end hci event
                // end hci event
                _ => (),
                _ => (),
            },
            },
+1 −0
Original line number Original line Diff line number Diff line
@@ -113,6 +113,7 @@ bool is_valid_event_code(bluetooth::hci::EventCode event_code) {
      return true;
      return true;
    case bluetooth::hci::EventCode::VENDOR_SPECIFIC:
    case bluetooth::hci::EventCode::VENDOR_SPECIFIC:
    case bluetooth::hci::EventCode::LE_META_EVENT:  // Private to hci
    case bluetooth::hci::EventCode::LE_META_EVENT:  // Private to hci
    case bluetooth::hci::EventCode::AUTHENTICATED_PAYLOAD_TIMEOUT_EXPIRED:
      return false;
      return false;
  }
  }
  return false;
  return false;
+6 −0
Original line number Original line Diff line number Diff line
@@ -831,6 +831,7 @@ enum EventCode : 8 {
  REMOTE_HOST_SUPPORTED_FEATURES_NOTIFICATION = 0x3D,
  REMOTE_HOST_SUPPORTED_FEATURES_NOTIFICATION = 0x3D,
  LE_META_EVENT = 0x3e,
  LE_META_EVENT = 0x3e,
  NUMBER_OF_COMPLETED_DATA_BLOCKS = 0x48,
  NUMBER_OF_COMPLETED_DATA_BLOCKS = 0x48,
  AUTHENTICATED_PAYLOAD_TIMEOUT_EXPIRED = 0x57,
  VENDOR_SPECIFIC = 0xFF,
  VENDOR_SPECIFIC = 0xFF,
}
}


@@ -5803,6 +5804,11 @@ packet NumberOfCompletedDataBlocks : Event (event_code = NUMBER_OF_COMPLETED_DAT
  _payload_, // placeholder (unimplemented)
  _payload_, // placeholder (unimplemented)
}
}


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

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