SecurityManagerChannel: Unit tests

Bug: 142341184
Test: atest --host -t bluetooth_test_gd:SecurityManagerChannelTest
Change-Id: I8c78039a5d1e0a3197f719fab837964707a98a2d
diff --git a/gd/hci/hci_packets.pdl b/gd/hci/hci_packets.pdl
index 255306c..0d9ee6d 100644
--- a/gd/hci/hci_packets.pdl
+++ b/gd/hci/hci_packets.pdl
@@ -3026,8 +3026,15 @@
   interval : 16, // 0x002 - 0xFFFE (1.25ms - 40.9s)
 }
 
+struct ZeroKeyAndAddress {
+  address : Address,
+  _fixed_ = 0 : 64,
+  _fixed_ = 0 : 64,
+}
+
 packet ReturnLinkKeys : EventPacket (event_code = RETURN_LINK_KEYS){
-  _payload_, // placeholder (unimplemented)
+  _count_(keys) : 8,
+  keys : ZeroKeyAndAddress[],
 }
 
 packet PinCodeRequest : EventPacket (event_code = PIN_CODE_REQUEST){
@@ -3038,8 +3045,20 @@
   bd_addr : Address,
 }
 
+enum KeyType : 8 {
+  COMBINATION = 0x00,
+  DEBUG_COMBINATION = 0x03,
+  UNAUTHENTICATED_P192 = 0x04,
+  AUTHENTICATED_P192 = 0x05,
+  CHANGED = 0x06,
+  UNAUTHENTICATED_P256 = 0x07,
+  AUTHENTICATED_P256 = 0x08,
+}
+
 packet LinkKeyNotification : EventPacket (event_code = LINK_KEY_NOTIFICATION){
-  _payload_, // placeholder (unimplemented)
+  bd_addr : Address,
+  link_key : 8[16],
+  key_type : KeyType,
 }
 
 packet LoopbackCommand : EventPacket (event_code = LOOPBACK_COMMAND){
diff --git a/gd/security/channel/security_manager_channel.cc b/gd/security/channel/security_manager_channel.cc
index 419386d..331bbec 100644
--- a/gd/security/channel/security_manager_channel.cc
+++ b/gd/security/channel/security_manager_channel.cc
@@ -39,7 +39,7 @@
   ASSERT_LOG(listener_ != nullptr, "No listener set!");
   std::shared_ptr<Device> device = nullptr;
   auto event = EventPacketView::Create(std::move(packet));
-  ASSERT_LOG(event.IsValid(), "Received invalid packet: %hhx", event.GetEventCode());
+  ASSERT_LOG(event.IsValid(), "Received invalid packet");
   const hci::EventCode code = event.GetEventCode();
   switch (code) {
     case hci::EventCode::CHANGE_CONNECTION_LINK_KEY_COMPLETE:
@@ -81,10 +81,10 @@
       listener_->OnRemoteOobDataRequest(device, hci::RemoteOobDataRequestView::Create(std::move(event)));
       break;
     case hci::EventCode::USER_PASSKEY_NOTIFICATION:
-      //      listener_->OnUserPasskeyNotification(device, <packet>);
+      listener_->OnUserPasskeyNotification(device, hci::UserPasskeyNotificationView::Create(std::move(event)));
       break;
     case hci::EventCode::KEYPRESS_NOTIFICATION:
-      //      listener_->OnSendKeypressNotification(device, <packet>);
+      listener_->OnKeypressNotification(device, hci::KeypressNotificationView::Create(std::move(event)));
       break;
     default:
       ASSERT_LOG(false, "Invalid packet received: %hhx", code);
diff --git a/gd/security/channel/security_manager_channel.h b/gd/security/channel/security_manager_channel.h
index 6a2b624..02d0357 100644
--- a/gd/security/channel/security_manager_channel.h
+++ b/gd/security/channel/security_manager_channel.h
@@ -55,6 +55,9 @@
   virtual void OnEncryptionKeyRefreshComplete(std::shared_ptr<hci::Device> device,
                                               hci::EncryptionKeyRefreshCompleteView packet) = 0;
   virtual void OnRemoteOobDataRequest(std::shared_ptr<hci::Device> device, hci::RemoteOobDataRequestView packet) = 0;
+  virtual void OnUserPasskeyNotification(std::shared_ptr<hci::Device> device,
+                                         hci::UserPasskeyNotificationView packet) = 0;
+  virtual void OnKeypressNotification(std::shared_ptr<hci::Device> device, hci::KeypressNotificationView packet) = 0;
 };
 
 /**
diff --git a/gd/security/channel/security_manager_channel_unittest.cc b/gd/security/channel/security_manager_channel_unittest.cc
index f346255..b111e7f 100644
--- a/gd/security/channel/security_manager_channel_unittest.cc
+++ b/gd/security/channel/security_manager_channel_unittest.cc
@@ -46,21 +46,6 @@
 
 static DeviceDatabase kDeviceDatabase;
 
-class TestPayloadBuilder : public PacketBuilder<kLittleEndian> {
- public:
-  ~TestPayloadBuilder() override = default;
-  size_t size() const override {
-    return 1;
-  }
-  void Serialize(BitInserter& inserter) const override {}
-  static std::unique_ptr<TestPayloadBuilder> Create() {
-    return std::unique_ptr<TestPayloadBuilder>(new TestPayloadBuilder());
-  }
-
- private:
-  TestPayloadBuilder() : PacketBuilder<kLittleEndian>(){};
-};
-
 class SecurityManagerChannelCallback : public ISecurityManagerChannelListener {
  public:
   // HCI
@@ -76,6 +61,8 @@
   bool receivedEncryptionChange = false;
   bool receivedEncryptionKeyRefreshComplete = false;
   bool receivedRemoteOobDataRequest = false;
+  bool receivedUserPasskeyNotification = false;
+  bool receivedKeypressNotification = false;
 
   void OnChangeConnectionLinkKeyComplete(std::shared_ptr<hci::Device> device,
                                          hci::ChangeConnectionLinkKeyCompleteView packet) {
@@ -126,6 +113,14 @@
     EXPECT_TRUE(packet.IsValid());
     receivedRemoteOobDataRequest = true;
   }
+  void OnUserPasskeyNotification(std::shared_ptr<hci::Device> device, hci::UserPasskeyNotificationView packet) {
+    EXPECT_TRUE(packet.IsValid());
+    receivedUserPasskeyNotification = true;
+  }
+  void OnKeypressNotification(std::shared_ptr<hci::Device> device, hci::KeypressNotificationView packet) {
+    EXPECT_TRUE(packet.IsValid());
+    receivedKeypressNotification = true;
+  }
 };
 
 class SecurityManagerChannelTest : public ::testing::Test {
@@ -216,59 +211,346 @@
   EXPECT_TRUE(callback_->receivedPinCodeRequest);
 }
 
-TEST_F(SecurityManagerChannelTest, send_pin_code_request_reply) {}
+TEST_F(SecurityManagerChannelTest, send_pin_code_request_reply) {
+  // Arrange
+  uint8_t pin_code_length = 6;
+  std::array<uint8_t, 16> pin_code = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5};
+  auto packet = hci::PinCodeRequestReplyBuilder::Create(device_->GetAddress(), pin_code_length, pin_code);
 
-TEST_F(SecurityManagerChannelTest, send_pin_code_request_neg_reply) {}
+  // Act
+  channel_->SendCommand(device_, std::move(packet));
+  auto last_command = std::move(hci_layer_->GetLastCommand()->command);
+  auto command_packet = GetPacketView(std::move(last_command));
+  hci::CommandPacketView packet_view = hci::CommandPacketView::Create(command_packet);
 
-TEST_F(SecurityManagerChannelTest, recv_user_passkey_notification) {}
+  // Assert
+  EXPECT_TRUE(packet_view.IsValid());
+  EXPECT_EQ(OpCode::PIN_CODE_REQUEST_REPLY, packet_view.GetOpCode());
+}
 
-TEST_F(SecurityManagerChannelTest, send_user_confirmation_request_reply) {}
+TEST_F(SecurityManagerChannelTest, send_pin_code_request_neg_reply) {
+  // Arrange
+  auto packet = hci::PinCodeRequestNegativeReplyBuilder::Create(device_->GetAddress());
 
-TEST_F(SecurityManagerChannelTest, send_user_confirmation_request_neg_reply) {}
+  // Act
+  channel_->SendCommand(device_, std::move(packet));
+  auto last_command = std::move(hci_layer_->GetLastCommand()->command);
+  auto command_packet = GetPacketView(std::move(last_command));
+  hci::CommandPacketView packet_view = hci::CommandPacketView::Create(command_packet);
 
-TEST_F(SecurityManagerChannelTest, recv_remote_oob_data_request) {}
+  // Assert
+  EXPECT_TRUE(packet_view.IsValid());
+  EXPECT_EQ(OpCode::PIN_CODE_REQUEST_NEGATIVE_REPLY, packet_view.GetOpCode());
+}
 
-TEST_F(SecurityManagerChannelTest, send_remote_oob_data_request_reply) {}
+TEST_F(SecurityManagerChannelTest, recv_user_passkey_notification) {
+  uint32_t passkey = 0x00;
+  hci_layer_->IncomingEvent(hci::UserPasskeyNotificationBuilder::Create(device_->GetAddress(), passkey));
+  EXPECT_TRUE(callback_->receivedUserPasskeyNotification);
+}
 
-TEST_F(SecurityManagerChannelTest, send_remote_oob_data_request_neg_reply) {}
+TEST_F(SecurityManagerChannelTest, send_user_confirmation_request_reply) {
+  // Arrange
+  auto packet = hci::UserConfirmationRequestReplyBuilder::Create(device_->GetAddress());
 
-TEST_F(SecurityManagerChannelTest, send_read_local_oob_data) {}
+  // Act
+  channel_->SendCommand(device_, std::move(packet));
+  auto last_command = std::move(hci_layer_->GetLastCommand()->command);
+  auto command_packet = GetPacketView(std::move(last_command));
+  hci::CommandPacketView packet_view = hci::CommandPacketView::Create(command_packet);
 
-TEST_F(SecurityManagerChannelTest, send_read_local_oob_extended_data) {}
+  // Assert
+  EXPECT_TRUE(packet_view.IsValid());
+  EXPECT_EQ(OpCode::USER_CONFIRMATION_REQUEST_REPLY, packet_view.GetOpCode());
+}
 
-TEST_F(SecurityManagerChannelTest, recv_link_key_request) {}
+TEST_F(SecurityManagerChannelTest, send_user_confirmation_request_neg_reply) {
+  // Arrange
+  auto packet = hci::UserConfirmationRequestNegativeReplyBuilder::Create(device_->GetAddress());
 
-TEST_F(SecurityManagerChannelTest, recv_link_key_notification) {}
+  // Act
+  channel_->SendCommand(device_, std::move(packet));
+  auto last_command = std::move(hci_layer_->GetLastCommand()->command);
+  auto command_packet = GetPacketView(std::move(last_command));
+  hci::CommandPacketView packet_view = hci::CommandPacketView::Create(command_packet);
 
-TEST_F(SecurityManagerChannelTest, recv_master_link_complete) {}
+  // Assert
+  EXPECT_TRUE(packet_view.IsValid());
+  EXPECT_EQ(OpCode::USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY, packet_view.GetOpCode());
+}
 
-TEST_F(SecurityManagerChannelTest, recv_change_connection_link_key_complete) {}
+TEST_F(SecurityManagerChannelTest, recv_remote_oob_data_request) {
+  hci_layer_->IncomingEvent(hci::RemoteOobDataRequestBuilder::Create(device_->GetAddress()));
+  EXPECT_TRUE(callback_->receivedRemoteOobDataRequest);
+}
 
-TEST_F(SecurityManagerChannelTest, recv_return_link_keys) {}
+TEST_F(SecurityManagerChannelTest, send_remote_oob_data_request_reply) {
+  // Arrange
+  std::array<uint8_t, 16> c = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5};
+  std::array<uint8_t, 16> r = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5};
+  auto packet = hci::RemoteOobDataRequestReplyBuilder::Create(device_->GetAddress(), c, r);
 
-TEST_F(SecurityManagerChannelTest, send_link_key_reply) {}
+  // Act
+  channel_->SendCommand(device_, std::move(packet));
+  auto last_command = std::move(hci_layer_->GetLastCommand()->command);
+  auto command_packet = GetPacketView(std::move(last_command));
+  hci::CommandPacketView packet_view = hci::CommandPacketView::Create(command_packet);
 
-TEST_F(SecurityManagerChannelTest, send_link_key_neg_reply) {}
+  // Assert
+  EXPECT_TRUE(packet_view.IsValid());
+  EXPECT_EQ(OpCode::REMOTE_OOB_DATA_REQUEST_REPLY, packet_view.GetOpCode());
+}
 
-TEST_F(SecurityManagerChannelTest, send_read_stored_link_key) {}
+TEST_F(SecurityManagerChannelTest, send_remote_oob_data_request_neg_reply) {
+  // Arrange
+  auto packet = hci::RemoteOobDataRequestNegativeReplyBuilder::Create(device_->GetAddress());
 
-TEST_F(SecurityManagerChannelTest, send_write_stored_link_key) {}
+  // Act
+  channel_->SendCommand(device_, std::move(packet));
+  auto last_command = std::move(hci_layer_->GetLastCommand()->command);
+  auto command_packet = GetPacketView(std::move(last_command));
+  hci::CommandPacketView packet_view = hci::CommandPacketView::Create(command_packet);
 
-TEST_F(SecurityManagerChannelTest, send_delete_stored_link_key) {}
+  // Assert
+  EXPECT_TRUE(packet_view.IsValid());
+  EXPECT_EQ(OpCode::REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY, packet_view.GetOpCode());
+}
 
-TEST_F(SecurityManagerChannelTest, recv_encryption_change) {}
+TEST_F(SecurityManagerChannelTest, send_read_local_oob_data) {
+  // Arrange
+  auto packet = hci::ReadLocalOobDataBuilder::Create();
 
-TEST_F(SecurityManagerChannelTest, send_refresh_encryption_key) {}
+  // Act
+  channel_->SendCommand(device_, std::move(packet));
+  auto last_command = std::move(hci_layer_->GetLastCommand()->command);
+  auto command_packet = GetPacketView(std::move(last_command));
+  hci::CommandPacketView packet_view = hci::CommandPacketView::Create(command_packet);
 
-TEST_F(SecurityManagerChannelTest, send_read_encryption_key_size) {}
+  // Assert
+  EXPECT_TRUE(packet_view.IsValid());
+  EXPECT_EQ(OpCode::READ_LOCAL_OOB_DATA, packet_view.GetOpCode());
+}
 
-TEST_F(SecurityManagerChannelTest, recv_simple_pairing_complete) {}
+TEST_F(SecurityManagerChannelTest, send_read_local_oob_extended_data) {
+  // Arrange
+  auto packet = hci::ReadLocalOobExtendedDataBuilder::Create();
 
-TEST_F(SecurityManagerChannelTest, send_read_simple_pairing_mode) {}
+  // Act
+  channel_->SendCommand(device_, std::move(packet));
+  auto last_command = std::move(hci_layer_->GetLastCommand()->command);
+  auto command_packet = GetPacketView(std::move(last_command));
+  hci::CommandPacketView packet_view = hci::CommandPacketView::Create(command_packet);
 
-TEST_F(SecurityManagerChannelTest, send_write_simple_pairing_mode) {}
+  // Assert
+  EXPECT_TRUE(packet_view.IsValid());
+  EXPECT_EQ(OpCode::READ_LOCAL_OOB_EXTENDED_DATA, packet_view.GetOpCode());
+}
 
-TEST_F(SecurityManagerChannelTest, send_keypress_notification) {}
+TEST_F(SecurityManagerChannelTest, recv_link_key_request) {
+  hci_layer_->IncomingEvent(hci::LinkKeyRequestBuilder::Create(device_->GetAddress()));
+  EXPECT_TRUE(callback_->receivedLinkKeyRequest);
+}
+
+TEST_F(SecurityManagerChannelTest, recv_link_key_notification) {
+  std::array<uint8_t, 16> link_key = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5};
+  hci_layer_->IncomingEvent(
+      hci::LinkKeyNotificationBuilder::Create(device_->GetAddress(), link_key, hci::KeyType::DEBUG_COMBINATION));
+  EXPECT_TRUE(callback_->receivedLinkKeyNotification);
+}
+
+TEST_F(SecurityManagerChannelTest, recv_master_link_key_complete) {
+  uint16_t connection_handle = 0x0;
+  hci_layer_->IncomingEvent(
+      hci::MasterLinkKeyCompleteBuilder::Create(hci::ErrorCode::SUCCESS, connection_handle, hci::KeyFlag::TEMPORARY));
+  EXPECT_TRUE(callback_->receivedMasterLinkKeyComplete);
+}
+
+TEST_F(SecurityManagerChannelTest, recv_change_connection_link_key_complete) {
+  uint16_t connection_handle = 0x0;
+  hci_layer_->IncomingEvent(
+      hci::ChangeConnectionLinkKeyCompleteBuilder::Create(hci::ErrorCode::SUCCESS, connection_handle));
+  EXPECT_TRUE(callback_->receivedChangeConnectionLinkKeyComplete);
+}
+
+TEST_F(SecurityManagerChannelTest, recv_return_link_keys) {
+  std::vector<hci::ZeroKeyAndAddress> keys;
+  hci_layer_->IncomingEvent(hci::ReturnLinkKeysBuilder::Create(keys));
+  EXPECT_TRUE(callback_->receivedReturnLinkKeys);
+}
+
+TEST_F(SecurityManagerChannelTest, send_link_key_request_reply) {
+  // Arrange
+  std::array<uint8_t, 16> link_key = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5};
+  auto packet = hci::LinkKeyRequestReplyBuilder::Create(device_->GetAddress(), link_key);
+
+  // Act
+  channel_->SendCommand(device_, std::move(packet));
+  auto last_command = std::move(hci_layer_->GetLastCommand()->command);
+  auto command_packet = GetPacketView(std::move(last_command));
+  hci::CommandPacketView packet_view = hci::CommandPacketView::Create(command_packet);
+
+  // Assert
+  EXPECT_TRUE(packet_view.IsValid());
+  EXPECT_EQ(OpCode::LINK_KEY_REQUEST_REPLY, packet_view.GetOpCode());
+}
+
+TEST_F(SecurityManagerChannelTest, send_link_key_request_neg_reply) {
+  // Arrange
+  auto packet = hci::LinkKeyRequestNegativeReplyBuilder::Create(device_->GetAddress());
+
+  // Act
+  channel_->SendCommand(device_, std::move(packet));
+  auto last_command = std::move(hci_layer_->GetLastCommand()->command);
+  auto command_packet = GetPacketView(std::move(last_command));
+  hci::CommandPacketView packet_view = hci::CommandPacketView::Create(command_packet);
+
+  // Assert
+  EXPECT_TRUE(packet_view.IsValid());
+  EXPECT_EQ(OpCode::LINK_KEY_REQUEST_NEGATIVE_REPLY, packet_view.GetOpCode());
+}
+
+TEST_F(SecurityManagerChannelTest, send_read_stored_link_key) {
+  // Arrange
+  auto packet = hci::ReadStoredLinkKeyBuilder::Create(device_->GetAddress(), hci::ReadStoredLinkKeyReadAllFlag::ALL);
+
+  // Act
+  channel_->SendCommand(device_, std::move(packet));
+  auto last_command = std::move(hci_layer_->GetLastCommand()->command);
+  auto command_packet = GetPacketView(std::move(last_command));
+  hci::CommandPacketView packet_view = hci::CommandPacketView::Create(command_packet);
+
+  // Assert
+  EXPECT_TRUE(packet_view.IsValid());
+  EXPECT_EQ(OpCode::READ_STORED_LINK_KEY, packet_view.GetOpCode());
+}
+
+TEST_F(SecurityManagerChannelTest, send_write_stored_link_key) {
+  // Arrange
+  std::vector<hci::KeyAndAddress> keys_to_write;
+  auto packet = hci::WriteStoredLinkKeyBuilder::Create(keys_to_write);
+
+  // Act
+  channel_->SendCommand(device_, std::move(packet));
+  auto last_command = std::move(hci_layer_->GetLastCommand()->command);
+  auto command_packet = GetPacketView(std::move(last_command));
+  hci::CommandPacketView packet_view = hci::CommandPacketView::Create(command_packet);
+
+  // Assert
+  EXPECT_TRUE(packet_view.IsValid());
+  EXPECT_EQ(OpCode::WRITE_STORED_LINK_KEY, packet_view.GetOpCode());
+}
+
+TEST_F(SecurityManagerChannelTest, send_delete_stored_link_key) {
+  // Arrange
+  auto packet =
+      hci::DeleteStoredLinkKeyBuilder::Create(device_->GetAddress(), hci::DeleteStoredLinkKeyDeleteAllFlag::ALL);
+
+  // Act
+  channel_->SendCommand(device_, std::move(packet));
+  auto last_command = std::move(hci_layer_->GetLastCommand()->command);
+  auto command_packet = GetPacketView(std::move(last_command));
+  hci::CommandPacketView packet_view = hci::CommandPacketView::Create(command_packet);
+
+  // Assert
+  EXPECT_TRUE(packet_view.IsValid());
+  EXPECT_EQ(OpCode::DELETE_STORED_LINK_KEY, packet_view.GetOpCode());
+}
+
+TEST_F(SecurityManagerChannelTest, recv_encryption_change) {
+  uint16_t connection_handle = 0x0;
+  hci_layer_->IncomingEvent(
+      hci::EncryptionChangeBuilder::Create(hci::ErrorCode::SUCCESS, connection_handle, hci::EncryptionEnabled::ON));
+  EXPECT_TRUE(callback_->receivedEncryptionChange);
+}
+
+TEST_F(SecurityManagerChannelTest, send_refresh_encryption_key) {
+  // Arrange
+  uint16_t connection_handle = 0x0;
+  auto packet = hci::RefreshEncryptionKeyBuilder::Create(connection_handle);
+
+  // Act
+  channel_->SendCommand(device_, std::move(packet));
+  auto last_command = std::move(hci_layer_->GetLastCommand()->command);
+  auto command_packet = GetPacketView(std::move(last_command));
+  hci::CommandPacketView packet_view = hci::CommandPacketView::Create(command_packet);
+
+  // Assert
+  EXPECT_TRUE(packet_view.IsValid());
+  EXPECT_EQ(OpCode::REFRESH_ENCRYPTION_KEY, packet_view.GetOpCode());
+}
+
+TEST_F(SecurityManagerChannelTest, send_read_encryption_key_size) {
+  // Arrange
+  uint16_t connection_handle = 0x0;
+  auto packet = hci::ReadEncryptionKeySizeBuilder::Create(connection_handle);
+
+  // Act
+  channel_->SendCommand(device_, std::move(packet));
+  auto last_command = std::move(hci_layer_->GetLastCommand()->command);
+  auto command_packet = GetPacketView(std::move(last_command));
+  hci::CommandPacketView packet_view = hci::CommandPacketView::Create(command_packet);
+
+  // Assert
+  EXPECT_TRUE(packet_view.IsValid());
+  EXPECT_EQ(OpCode::READ_ENCRYPTION_KEY_SIZE, packet_view.GetOpCode());
+}
+
+TEST_F(SecurityManagerChannelTest, recv_simple_pairing_complete) {
+  hci_layer_->IncomingEvent(hci::SimplePairingCompleteBuilder::Create(hci::ErrorCode::SUCCESS, device_->GetAddress()));
+  EXPECT_TRUE(callback_->receivedSimplePairingComplete);
+}
+
+TEST_F(SecurityManagerChannelTest, send_read_simple_pairing_mode) {
+  // Arrange
+  auto packet = hci::ReadSimplePairingModeBuilder::Create();
+
+  // Act
+  channel_->SendCommand(device_, std::move(packet));
+  auto last_command = std::move(hci_layer_->GetLastCommand()->command);
+  auto command_packet = GetPacketView(std::move(last_command));
+  hci::CommandPacketView packet_view = hci::CommandPacketView::Create(command_packet);
+
+  // Assert
+  EXPECT_TRUE(packet_view.IsValid());
+  EXPECT_EQ(OpCode::READ_SIMPLE_PAIRING_MODE, packet_view.GetOpCode());
+}
+
+TEST_F(SecurityManagerChannelTest, send_write_simple_pairing_mode) {
+  // Arrange
+  auto packet = hci::WriteSimplePairingModeBuilder::Create(hci::Enable::ENABLED);
+
+  // Act
+  channel_->SendCommand(device_, std::move(packet));
+  auto last_command = std::move(hci_layer_->GetLastCommand()->command);
+  auto command_packet = GetPacketView(std::move(last_command));
+  hci::CommandPacketView packet_view = hci::CommandPacketView::Create(command_packet);
+
+  // Assert
+  EXPECT_TRUE(packet_view.IsValid());
+  EXPECT_EQ(OpCode::WRITE_SIMPLE_PAIRING_MODE, packet_view.GetOpCode());
+}
+
+TEST_F(SecurityManagerChannelTest, recv_keypress_notification) {
+  hci_layer_->IncomingEvent(
+      hci::KeypressNotificationBuilder::Create(device_->GetAddress(), hci::KeypressNotificationType::ENTRY_COMPLETED));
+  EXPECT_TRUE(callback_->receivedKeypressNotification);
+}
+
+TEST_F(SecurityManagerChannelTest, send_keypress_notification) {
+  // Arrange
+  auto packet =
+      hci::SendKeypressNotificationBuilder::Create(device_->GetAddress(), hci::KeypressNotificationType::ENTRY_STARTED);
+
+  // Act
+  channel_->SendCommand(device_, std::move(packet));
+  auto last_command = std::move(hci_layer_->GetLastCommand()->command);
+  auto command_packet = GetPacketView(std::move(last_command));
+  hci::CommandPacketView packet_view = hci::CommandPacketView::Create(command_packet);
+
+  // Assert
+  EXPECT_TRUE(packet_view.IsValid());
+  EXPECT_EQ(OpCode::SEND_KEYPRESS_NOTIFICATION, packet_view.GetOpCode());
+}
 
 }  // namespace
 }  // namespace channel
diff --git a/gd/security/test/fake_hci_layer.h b/gd/security/test/fake_hci_layer.h
index 310a75c..84eff90 100644
--- a/gd/security/test/fake_hci_layer.h
+++ b/gd/security/test/fake_hci_layer.h
@@ -96,7 +96,7 @@
   void IncomingEvent(std::unique_ptr<EventPacketBuilder> event_builder) {
     auto packet = GetPacketView(std::move(event_builder));
     EventPacketView event = EventPacketView::Create(packet);
-    EXPECT_TRUE(event.IsValid());
+    ASSERT_TRUE(event.IsValid());
     EventCode event_code = event.GetEventCode();
     EXPECT_TRUE(registered_events_.find(event_code) != registered_events_.end());
     registered_events_[event_code].Run(event);