From d269a647dac5f8434a5eefd2ccc2dafdb5c0795d Mon Sep 17 00:00:00 2001 From: Jakub Pawlowski Date: Wed, 4 Sep 2024 21:56:25 +0200 Subject: Encryption Change V2 Bug: 365846652 Bug: 366018699 Test: mma -j32 Flag: encryption_change_v2 Change-Id: I387b0df153e7dcf7d02a460e182ef12523509a42 --- .../model/controller/link_layer_controller.cc | 18 +++++++++++++++--- tools/rootcanal/packets/hci_packets.pdl | 8 ++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'tools/rootcanal') diff --git a/tools/rootcanal/model/controller/link_layer_controller.cc b/tools/rootcanal/model/controller/link_layer_controller.cc index 047ea9c96e..e793ac16e3 100644 --- a/tools/rootcanal/model/controller/link_layer_controller.cc +++ b/tools/rootcanal/model/controller/link_layer_controller.cc @@ -83,8 +83,16 @@ AddressWithType PeerIdentityAddress(Address address, PeerAddressType peer_addres } bool LinkLayerController::IsEventUnmasked(EventCode event) const { - uint64_t bit = UINT64_C(1) << (static_cast(event) - 1); - return (event_mask_ & bit) != 0; + uint8_t evt = static_cast(event); + + if (evt <= 64) { + uint64_t bit = UINT64_C(1) << (evt - 1); + return (event_mask_ & bit) != 0; + } else { + evt -= 64; + uint64_t bit = UINT64_C(1) << (evt - 1); + return (event_mask_page_2_ & bit) != 0; + } } bool LinkLayerController::IsLeEventUnmasked(SubeventCode subevent) const { @@ -5638,7 +5646,11 @@ ErrorCode LinkLayerController::LeLongTermKeyRequestReply(uint16_t handle, } } else { connections_.Encrypt(handle); - if (IsEventUnmasked(EventCode::ENCRYPTION_CHANGE)) { + if (IsEventUnmasked(EventCode::ENCRYPTION_CHANGE_V2)) { + send_event_(bluetooth::hci::EncryptionChangeV2Builder::Create( + ErrorCode::SUCCESS, handle, bluetooth::hci::EncryptionEnabled::ON, + 0x10 /* key_size */)); + } else if (IsEventUnmasked(EventCode::ENCRYPTION_CHANGE)) { send_event_(bluetooth::hci::EncryptionChangeBuilder::Create( ErrorCode::SUCCESS, handle, bluetooth::hci::EncryptionEnabled::ON)); } diff --git a/tools/rootcanal/packets/hci_packets.pdl b/tools/rootcanal/packets/hci_packets.pdl index 2b404bdff1..6cb90fea7f 100644 --- a/tools/rootcanal/packets/hci_packets.pdl +++ b/tools/rootcanal/packets/hci_packets.pdl @@ -749,6 +749,7 @@ enum EventCode : 8 { REMOTE_HOST_SUPPORTED_FEATURES_NOTIFICATION = 0x3D, LE_META_EVENT = 0x3e, NUMBER_OF_COMPLETED_DATA_BLOCKS = 0x48, + ENCRYPTION_CHANGE_V2 = 0x59, VENDOR_SPECIFIC = 0xFF, } @@ -4767,6 +4768,13 @@ packet EncryptionChange : Event (event_code = ENCRYPTION_CHANGE) { encryption_enabled : EncryptionEnabled, } +packet EncryptionChangeV2 : Event (event_code = ENCRYPTION_CHANGE_V2) { + status : ErrorCode, + connection_handle : 12, + _reserved_ : 4, + encryption_enabled : EncryptionEnabled, + key_size : 8, +} packet ChangeConnectionLinkKeyComplete : Event (event_code = CHANGE_CONNECTION_LINK_KEY_COMPLETE) { status : ErrorCode, connection_handle : 12, -- cgit v1.2.3-59-g8ed1b