SecurityManager: Classic Pairing Handler
- Plumbing for driving pairing handler and foundation for Classic Pairing Logic
- Implement JustWorks Association models and unit tests
Bug: 144374435 144376172
Test: atest --host -t bluetooth_test_gd:ClassicPairingHandlerTest
Change-Id: Ie88956602e14567f32eaa0f6ca397521d398e1ab
diff --git a/gd/security/channel/security_manager_channel_unittest.cc b/gd/security/channel/security_manager_channel_unittest.cc
index b111e7f..ee12b92 100644
--- a/gd/security/channel/security_manager_channel_unittest.cc
+++ b/gd/security/channel/security_manager_channel_unittest.cc
@@ -1,4 +1,4 @@
-/******************************************************************************
+/*
*
* Copyright 2019 The Android Open Source Project
*
@@ -14,13 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- ******************************************************************************/
+ */
#include "security_manager_channel.h"
#include <gtest/gtest.h>
-#include "hci/device.h"
-#include "hci/device_database.h"
#include "hci/hci_packets.h"
#include "packet/raw_builder.h"
#include "security/smp_packets.h"
@@ -32,10 +30,9 @@
namespace {
using bluetooth::security::channel::SecurityManagerChannel;
+using hci::Address;
using hci::AuthenticationRequirements;
using hci::CommandCompleteBuilder;
-using hci::Device;
-using hci::DeviceDatabase;
using hci::IoCapabilityRequestReplyBuilder;
using hci::IoCapabilityRequestView;
using hci::OobDataPresent;
@@ -44,8 +41,6 @@
using os::Thread;
using packet::RawBuilder;
-static DeviceDatabase kDeviceDatabase;
-
class SecurityManagerChannelCallback : public ISecurityManagerChannelListener {
public:
// HCI
@@ -62,71 +57,138 @@
bool receivedEncryptionKeyRefreshComplete = false;
bool receivedRemoteOobDataRequest = false;
bool receivedUserPasskeyNotification = false;
+ bool receivedUserPasskeyRequest = false;
bool receivedKeypressNotification = false;
+ bool receivedUserConfirmationRequest = false;
- void OnChangeConnectionLinkKeyComplete(std::shared_ptr<hci::Device> device,
- hci::ChangeConnectionLinkKeyCompleteView packet) {
- EXPECT_TRUE(packet.IsValid());
+ void OnReceive(hci::AddressWithType device, hci::ChangeConnectionLinkKeyCompleteView packet) {
+ ASSERT_TRUE(packet.IsValid());
receivedChangeConnectionLinkKeyComplete = true;
}
- void OnMasterLinkKeyComplete(std::shared_ptr<hci::Device> device, hci::MasterLinkKeyCompleteView packet) {
- EXPECT_TRUE(packet.IsValid());
+ void OnReceive(hci::AddressWithType device, hci::MasterLinkKeyCompleteView packet) {
+ ASSERT_TRUE(packet.IsValid());
receivedMasterLinkKeyComplete = true;
}
- void OnPinCodeRequest(std::shared_ptr<hci::Device> device, hci::PinCodeRequestView packet) {
- EXPECT_TRUE(packet.IsValid());
+ void OnReceive(hci::AddressWithType device, hci::PinCodeRequestView packet) {
+ ASSERT_TRUE(packet.IsValid());
receivedPinCodeRequest = true;
}
- void OnLinkKeyRequest(std::shared_ptr<hci::Device> device, hci::LinkKeyRequestView packet) {
- EXPECT_TRUE(packet.IsValid());
+ void OnReceive(hci::AddressWithType device, hci::LinkKeyRequestView packet) {
+ ASSERT_TRUE(packet.IsValid());
receivedLinkKeyRequest = true;
}
- void OnLinkKeyNotification(std::shared_ptr<hci::Device> device, hci::LinkKeyNotificationView packet) {
- EXPECT_TRUE(packet.IsValid());
+ void OnReceive(hci::AddressWithType device, hci::LinkKeyNotificationView packet) {
+ ASSERT_TRUE(packet.IsValid());
receivedLinkKeyNotification = true;
}
- void OnIoCapabilityRequest(std::shared_ptr<Device> device, hci::IoCapabilityRequestView packet) {
- EXPECT_TRUE(packet.IsValid());
+ void OnReceive(hci::AddressWithType device, hci::IoCapabilityRequestView packet) {
+ ASSERT_TRUE(packet.IsValid());
receivedIoCapabilityRequest = true;
}
- void OnIoCapabilityResponse(std::shared_ptr<Device> device, hci::IoCapabilityResponseView packet) {
- EXPECT_TRUE(packet.IsValid());
+ void OnReceive(hci::AddressWithType device, hci::IoCapabilityResponseView packet) {
+ ASSERT_TRUE(packet.IsValid());
receivedIoCapabilityResponse = true;
}
- void OnSimplePairingComplete(std::shared_ptr<Device> device, hci::SimplePairingCompleteView packet) {
- EXPECT_TRUE(packet.IsValid());
+ void OnReceive(hci::AddressWithType device, hci::SimplePairingCompleteView packet) {
+ ASSERT_TRUE(packet.IsValid());
receivedSimplePairingComplete = true;
}
- void OnReturnLinkKeys(std::shared_ptr<Device> device, hci::ReturnLinkKeysView packet) {
- EXPECT_TRUE(packet.IsValid());
+ void OnReceive(hci::AddressWithType device, hci::ReturnLinkKeysView packet) {
+ ASSERT_TRUE(packet.IsValid());
receivedReturnLinkKeys = true;
}
- void OnEncryptionChange(std::shared_ptr<Device> device, hci::EncryptionChangeView packet) {
- EXPECT_TRUE(packet.IsValid());
+ void OnReceive(hci::AddressWithType device, hci::EncryptionChangeView packet) {
+ ASSERT_TRUE(packet.IsValid());
receivedEncryptionChange = true;
}
- void OnEncryptionKeyRefreshComplete(std::shared_ptr<Device> device, hci::EncryptionKeyRefreshCompleteView packet) {
- EXPECT_TRUE(packet.IsValid());
+ void OnReceive(hci::AddressWithType device, hci::EncryptionKeyRefreshCompleteView packet) {
+ ASSERT_TRUE(packet.IsValid());
receivedEncryptionKeyRefreshComplete = true;
}
- void OnRemoteOobDataRequest(std::shared_ptr<Device> device, hci::RemoteOobDataRequestView packet) {
- EXPECT_TRUE(packet.IsValid());
+ void OnReceive(hci::AddressWithType device, hci::RemoteOobDataRequestView packet) {
+ ASSERT_TRUE(packet.IsValid());
receivedRemoteOobDataRequest = true;
}
- void OnUserPasskeyNotification(std::shared_ptr<hci::Device> device, hci::UserPasskeyNotificationView packet) {
- EXPECT_TRUE(packet.IsValid());
+ void OnReceive(hci::AddressWithType device, hci::UserPasskeyNotificationView packet) {
+ ASSERT_TRUE(packet.IsValid());
receivedUserPasskeyNotification = true;
}
- void OnKeypressNotification(std::shared_ptr<hci::Device> device, hci::KeypressNotificationView packet) {
- EXPECT_TRUE(packet.IsValid());
+ void OnReceive(hci::AddressWithType device, hci::KeypressNotificationView packet) {
+ ASSERT_TRUE(packet.IsValid());
receivedKeypressNotification = true;
}
+ void OnReceive(hci::AddressWithType device, hci::UserConfirmationRequestView packet) {
+ ASSERT_TRUE(packet.IsValid());
+ receivedUserConfirmationRequest = true;
+ }
+ void OnReceive(hci::AddressWithType device, hci::UserPasskeyRequestView packet) {
+ ASSERT_TRUE(packet.IsValid());
+ receivedUserPasskeyRequest = true;
+ }
+
+ void OnHciEventReceived(EventPacketView packet) override {
+ auto event = EventPacketView::Create(packet);
+ ASSERT_LOG(event.IsValid(), "Received invalid packet");
+ const hci::EventCode code = event.GetEventCode();
+ switch (code) {
+ case hci::EventCode::CHANGE_CONNECTION_LINK_KEY_COMPLETE:
+ OnReceive(hci::AddressWithType(), hci::ChangeConnectionLinkKeyCompleteView::Create(event));
+ break;
+ case hci::EventCode::MASTER_LINK_KEY_COMPLETE:
+ OnReceive(hci::AddressWithType(), hci::MasterLinkKeyCompleteView::Create(event));
+ break;
+ case hci::EventCode::PIN_CODE_REQUEST:
+ OnReceive(hci::AddressWithType(), hci::PinCodeRequestView::Create(event));
+ break;
+ case hci::EventCode::LINK_KEY_REQUEST:
+ OnReceive(hci::AddressWithType(), hci::LinkKeyRequestView::Create(event));
+ break;
+ case hci::EventCode::LINK_KEY_NOTIFICATION:
+ OnReceive(hci::AddressWithType(), hci::LinkKeyNotificationView::Create(event));
+ break;
+ case hci::EventCode::IO_CAPABILITY_REQUEST:
+ OnReceive(hci::AddressWithType(), hci::IoCapabilityRequestView::Create(event));
+ break;
+ case hci::EventCode::IO_CAPABILITY_RESPONSE:
+ OnReceive(hci::AddressWithType(), hci::IoCapabilityResponseView::Create(event));
+ break;
+ case hci::EventCode::SIMPLE_PAIRING_COMPLETE:
+ OnReceive(hci::AddressWithType(), hci::SimplePairingCompleteView::Create(event));
+ break;
+ case hci::EventCode::RETURN_LINK_KEYS:
+ OnReceive(hci::AddressWithType(), hci::ReturnLinkKeysView::Create(event));
+ break;
+ case hci::EventCode::ENCRYPTION_CHANGE:
+ OnReceive(hci::AddressWithType(), hci::EncryptionChangeView::Create(event));
+ break;
+ case hci::EventCode::ENCRYPTION_KEY_REFRESH_COMPLETE:
+ OnReceive(hci::AddressWithType(), hci::EncryptionKeyRefreshCompleteView::Create(event));
+ break;
+ case hci::EventCode::REMOTE_OOB_DATA_REQUEST:
+ OnReceive(hci::AddressWithType(), hci::RemoteOobDataRequestView::Create(event));
+ break;
+ case hci::EventCode::USER_PASSKEY_NOTIFICATION:
+ OnReceive(hci::AddressWithType(), hci::UserPasskeyNotificationView::Create(event));
+ break;
+ case hci::EventCode::KEYPRESS_NOTIFICATION:
+ OnReceive(hci::AddressWithType(), hci::KeypressNotificationView::Create(event));
+ break;
+ case hci::EventCode::USER_CONFIRMATION_REQUEST:
+ OnReceive(hci::AddressWithType(), hci::UserConfirmationRequestView::Create(event));
+ break;
+ case hci::EventCode::USER_PASSKEY_REQUEST:
+ OnReceive(hci::AddressWithType(), hci::UserPasskeyRequestView::Create(event));
+ break;
+ default:
+ ASSERT_LOG(false, "Cannot handle received packet: %s", hci::EventCodeText(code).c_str());
+ break;
+ }
+ }
};
class SecurityManagerChannelTest : public ::testing::Test {
protected:
void SetUp() override {
- device_ = kDeviceDatabase.CreateClassicDevice(hci::Address({0x01, 0x02, 0x03, 0x04, 0x05, 0x06}));
handler_ = new Handler(&thread_);
callback_ = new SecurityManagerChannelCallback();
hci_layer_ = new FakeHciLayer();
@@ -152,14 +214,14 @@
FakeHciLayer* hci_layer_ = nullptr;
SecurityManagerChannel* channel_ = nullptr;
SecurityManagerChannelCallback* callback_ = nullptr;
- std::shared_ptr<Device> device_ = nullptr;
+ hci::AddressWithType device_;
};
TEST_F(SecurityManagerChannelTest, setup_teardown) {}
TEST_F(SecurityManagerChannelTest, recv_io_cap_request) {
- hci_layer_->IncomingEvent(hci::IoCapabilityRequestBuilder::Create(device_->GetAddress()));
- EXPECT_TRUE(callback_->receivedIoCapabilityRequest);
+ hci_layer_->IncomingEvent(hci::IoCapabilityRequestBuilder::Create(device_.GetAddress()));
+ ASSERT_TRUE(callback_->receivedIoCapabilityRequest);
}
TEST_F(SecurityManagerChannelTest, send_io_cap_request_reply) {
@@ -167,153 +229,159 @@
hci::IoCapability io_capability = (hci::IoCapability)0x00;
OobDataPresent oob_present = (OobDataPresent)0x00;
AuthenticationRequirements authentication_requirements = (AuthenticationRequirements)0x00;
- auto packet = hci::IoCapabilityRequestReplyBuilder::Create(device_->GetAddress(), io_capability, oob_present,
+ auto packet = hci::IoCapabilityRequestReplyBuilder::Create(device_.GetAddress(), io_capability, oob_present,
authentication_requirements);
// Act
- channel_->SendCommand(device_, std::move(packet));
+ channel_->SendCommand(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::IO_CAPABILITY_REQUEST_REPLY, packet_view.GetOpCode());
+ ASSERT_TRUE(packet_view.IsValid());
+ ASSERT_EQ(OpCode::IO_CAPABILITY_REQUEST_REPLY, packet_view.GetOpCode());
}
TEST_F(SecurityManagerChannelTest, send_io_cap_request_neg_reply) {
// Arrange
auto packet =
- hci::IoCapabilityRequestNegativeReplyBuilder::Create(device_->GetAddress(), hci::ErrorCode::COMMAND_DISALLOWED);
+ hci::IoCapabilityRequestNegativeReplyBuilder::Create(device_.GetAddress(), hci::ErrorCode::COMMAND_DISALLOWED);
// Act
- channel_->SendCommand(device_, std::move(packet));
+ channel_->SendCommand(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::IO_CAPABILITY_REQUEST_NEGATIVE_REPLY, packet_view.GetOpCode());
+ ASSERT_TRUE(packet_view.IsValid());
+ ASSERT_EQ(OpCode::IO_CAPABILITY_REQUEST_NEGATIVE_REPLY, packet_view.GetOpCode());
}
TEST_F(SecurityManagerChannelTest, recv_io_cap_response) {
hci::IoCapability io_capability = (hci::IoCapability)0x00;
OobDataPresent oob_present = (OobDataPresent)0x00;
AuthenticationRequirements authentication_requirements = (AuthenticationRequirements)0x00;
- hci_layer_->IncomingEvent(hci::IoCapabilityResponseBuilder::Create(device_->GetAddress(), io_capability, oob_present,
+ hci_layer_->IncomingEvent(hci::IoCapabilityResponseBuilder::Create(device_.GetAddress(), io_capability, oob_present,
authentication_requirements));
- EXPECT_TRUE(callback_->receivedIoCapabilityResponse);
+ ASSERT_TRUE(callback_->receivedIoCapabilityResponse);
}
TEST_F(SecurityManagerChannelTest, recv_pin_code_request) {
- hci_layer_->IncomingEvent(hci::PinCodeRequestBuilder::Create(device_->GetAddress()));
- EXPECT_TRUE(callback_->receivedPinCodeRequest);
+ hci_layer_->IncomingEvent(hci::PinCodeRequestBuilder::Create(device_.GetAddress()));
+ ASSERT_TRUE(callback_->receivedPinCodeRequest);
}
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);
+ auto packet = hci::PinCodeRequestReplyBuilder::Create(device_.GetAddress(), pin_code_length, pin_code);
// Act
- channel_->SendCommand(device_, std::move(packet));
+ channel_->SendCommand(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::PIN_CODE_REQUEST_REPLY, packet_view.GetOpCode());
+ ASSERT_TRUE(packet_view.IsValid());
+ ASSERT_EQ(OpCode::PIN_CODE_REQUEST_REPLY, packet_view.GetOpCode());
}
TEST_F(SecurityManagerChannelTest, send_pin_code_request_neg_reply) {
// Arrange
- auto packet = hci::PinCodeRequestNegativeReplyBuilder::Create(device_->GetAddress());
+ auto packet = hci::PinCodeRequestNegativeReplyBuilder::Create(device_.GetAddress());
// Act
- channel_->SendCommand(device_, std::move(packet));
+ channel_->SendCommand(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::PIN_CODE_REQUEST_NEGATIVE_REPLY, packet_view.GetOpCode());
+ ASSERT_TRUE(packet_view.IsValid());
+ ASSERT_EQ(OpCode::PIN_CODE_REQUEST_NEGATIVE_REPLY, packet_view.GetOpCode());
}
TEST_F(SecurityManagerChannelTest, recv_user_passkey_notification) {
uint32_t passkey = 0x00;
- hci_layer_->IncomingEvent(hci::UserPasskeyNotificationBuilder::Create(device_->GetAddress(), passkey));
- EXPECT_TRUE(callback_->receivedUserPasskeyNotification);
+ hci_layer_->IncomingEvent(hci::UserPasskeyNotificationBuilder::Create(device_.GetAddress(), passkey));
+ ASSERT_TRUE(callback_->receivedUserPasskeyNotification);
+}
+
+TEST_F(SecurityManagerChannelTest, recv_user_confirmation_request) {
+ uint32_t numeric_value = 0x0;
+ hci_layer_->IncomingEvent(hci::UserConfirmationRequestBuilder::Create(device_.GetAddress(), numeric_value));
+ ASSERT_TRUE(callback_->receivedUserConfirmationRequest);
}
TEST_F(SecurityManagerChannelTest, send_user_confirmation_request_reply) {
// Arrange
- auto packet = hci::UserConfirmationRequestReplyBuilder::Create(device_->GetAddress());
+ auto packet = hci::UserConfirmationRequestReplyBuilder::Create(device_.GetAddress());
// Act
- channel_->SendCommand(device_, std::move(packet));
+ channel_->SendCommand(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::USER_CONFIRMATION_REQUEST_REPLY, packet_view.GetOpCode());
+ ASSERT_TRUE(packet_view.IsValid());
+ ASSERT_EQ(OpCode::USER_CONFIRMATION_REQUEST_REPLY, packet_view.GetOpCode());
}
-TEST_F(SecurityManagerChannelTest, send_user_confirmation_request_neg_reply) {
+TEST_F(SecurityManagerChannelTest, send_user_confirmation_request_negative_reply) {
// Arrange
- auto packet = hci::UserConfirmationRequestNegativeReplyBuilder::Create(device_->GetAddress());
+ auto packet = hci::UserConfirmationRequestNegativeReplyBuilder::Create(device_.GetAddress());
// Act
- channel_->SendCommand(device_, std::move(packet));
+ channel_->SendCommand(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::USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY, packet_view.GetOpCode());
+ ASSERT_TRUE(packet_view.IsValid());
+ ASSERT_EQ(OpCode::USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY, packet_view.GetOpCode());
}
TEST_F(SecurityManagerChannelTest, recv_remote_oob_data_request) {
- hci_layer_->IncomingEvent(hci::RemoteOobDataRequestBuilder::Create(device_->GetAddress()));
- EXPECT_TRUE(callback_->receivedRemoteOobDataRequest);
+ hci_layer_->IncomingEvent(hci::RemoteOobDataRequestBuilder::Create(device_.GetAddress()));
+ ASSERT_TRUE(callback_->receivedRemoteOobDataRequest);
}
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);
+ auto packet = hci::RemoteOobDataRequestReplyBuilder::Create(device_.GetAddress(), c, r);
// Act
- channel_->SendCommand(device_, std::move(packet));
+ channel_->SendCommand(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::REMOTE_OOB_DATA_REQUEST_REPLY, packet_view.GetOpCode());
+ ASSERT_TRUE(packet_view.IsValid());
+ ASSERT_EQ(OpCode::REMOTE_OOB_DATA_REQUEST_REPLY, packet_view.GetOpCode());
}
TEST_F(SecurityManagerChannelTest, send_remote_oob_data_request_neg_reply) {
// Arrange
- auto packet = hci::RemoteOobDataRequestNegativeReplyBuilder::Create(device_->GetAddress());
+ auto packet = hci::RemoteOobDataRequestNegativeReplyBuilder::Create(device_.GetAddress());
// Act
- channel_->SendCommand(device_, std::move(packet));
+ channel_->SendCommand(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::REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY, packet_view.GetOpCode());
+ ASSERT_TRUE(packet_view.IsValid());
+ ASSERT_EQ(OpCode::REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY, packet_view.GetOpCode());
}
TEST_F(SecurityManagerChannelTest, send_read_local_oob_data) {
@@ -321,14 +389,14 @@
auto packet = hci::ReadLocalOobDataBuilder::Create();
// Act
- channel_->SendCommand(device_, std::move(packet));
+ channel_->SendCommand(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_LOCAL_OOB_DATA, packet_view.GetOpCode());
+ ASSERT_TRUE(packet_view.IsValid());
+ ASSERT_EQ(OpCode::READ_LOCAL_OOB_DATA, packet_view.GetOpCode());
}
TEST_F(SecurityManagerChannelTest, send_read_local_oob_extended_data) {
@@ -336,92 +404,92 @@
auto packet = hci::ReadLocalOobExtendedDataBuilder::Create();
// Act
- channel_->SendCommand(device_, std::move(packet));
+ channel_->SendCommand(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_LOCAL_OOB_EXTENDED_DATA, packet_view.GetOpCode());
+ ASSERT_TRUE(packet_view.IsValid());
+ ASSERT_EQ(OpCode::READ_LOCAL_OOB_EXTENDED_DATA, packet_view.GetOpCode());
}
TEST_F(SecurityManagerChannelTest, recv_link_key_request) {
- hci_layer_->IncomingEvent(hci::LinkKeyRequestBuilder::Create(device_->GetAddress()));
- EXPECT_TRUE(callback_->receivedLinkKeyRequest);
+ hci_layer_->IncomingEvent(hci::LinkKeyRequestBuilder::Create(device_.GetAddress()));
+ ASSERT_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);
+ hci::LinkKeyNotificationBuilder::Create(device_.GetAddress(), link_key, hci::KeyType::DEBUG_COMBINATION));
+ ASSERT_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);
+ ASSERT_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);
+ ASSERT_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);
+ ASSERT_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);
+ auto packet = hci::LinkKeyRequestReplyBuilder::Create(device_.GetAddress(), link_key);
// Act
- channel_->SendCommand(device_, std::move(packet));
+ channel_->SendCommand(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());
+ ASSERT_TRUE(packet_view.IsValid());
+ ASSERT_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());
+ auto packet = hci::LinkKeyRequestNegativeReplyBuilder::Create(device_.GetAddress());
// Act
- channel_->SendCommand(device_, std::move(packet));
+ channel_->SendCommand(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());
+ ASSERT_TRUE(packet_view.IsValid());
+ ASSERT_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);
+ auto packet = hci::ReadStoredLinkKeyBuilder::Create(device_.GetAddress(), hci::ReadStoredLinkKeyReadAllFlag::ALL);
// Act
- channel_->SendCommand(device_, std::move(packet));
+ channel_->SendCommand(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());
+ ASSERT_TRUE(packet_view.IsValid());
+ ASSERT_EQ(OpCode::READ_STORED_LINK_KEY, packet_view.GetOpCode());
}
TEST_F(SecurityManagerChannelTest, send_write_stored_link_key) {
@@ -430,37 +498,44 @@
auto packet = hci::WriteStoredLinkKeyBuilder::Create(keys_to_write);
// Act
- channel_->SendCommand(device_, std::move(packet));
+ channel_->SendCommand(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());
+ ASSERT_TRUE(packet_view.IsValid());
+ ASSERT_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);
+ hci::DeleteStoredLinkKeyBuilder::Create(device_.GetAddress(), hci::DeleteStoredLinkKeyDeleteAllFlag::ALL);
// Act
- channel_->SendCommand(device_, std::move(packet));
+ channel_->SendCommand(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());
+ ASSERT_TRUE(packet_view.IsValid());
+ ASSERT_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);
+ ASSERT_TRUE(callback_->receivedEncryptionChange);
+}
+
+TEST_F(SecurityManagerChannelTest, recv_encryption_key_refresh) {
+ uint16_t connection_handle = 0x0;
+ hci_layer_->IncomingEvent(
+ hci::EncryptionKeyRefreshCompleteBuilder::Create(hci::ErrorCode::SUCCESS, connection_handle));
+ ASSERT_TRUE(callback_->receivedEncryptionKeyRefreshComplete);
}
TEST_F(SecurityManagerChannelTest, send_refresh_encryption_key) {
@@ -469,14 +544,14 @@
auto packet = hci::RefreshEncryptionKeyBuilder::Create(connection_handle);
// Act
- channel_->SendCommand(device_, std::move(packet));
+ channel_->SendCommand(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());
+ ASSERT_TRUE(packet_view.IsValid());
+ ASSERT_EQ(OpCode::REFRESH_ENCRYPTION_KEY, packet_view.GetOpCode());
}
TEST_F(SecurityManagerChannelTest, send_read_encryption_key_size) {
@@ -485,19 +560,19 @@
auto packet = hci::ReadEncryptionKeySizeBuilder::Create(connection_handle);
// Act
- channel_->SendCommand(device_, std::move(packet));
+ channel_->SendCommand(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());
+ ASSERT_TRUE(packet_view.IsValid());
+ ASSERT_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);
+ hci_layer_->IncomingEvent(hci::SimplePairingCompleteBuilder::Create(hci::ErrorCode::SUCCESS, device_.GetAddress()));
+ ASSERT_TRUE(callback_->receivedSimplePairingComplete);
}
TEST_F(SecurityManagerChannelTest, send_read_simple_pairing_mode) {
@@ -505,14 +580,14 @@
auto packet = hci::ReadSimplePairingModeBuilder::Create();
// Act
- channel_->SendCommand(device_, std::move(packet));
+ channel_->SendCommand(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());
+ ASSERT_TRUE(packet_view.IsValid());
+ ASSERT_EQ(OpCode::READ_SIMPLE_PAIRING_MODE, packet_view.GetOpCode());
}
TEST_F(SecurityManagerChannelTest, send_write_simple_pairing_mode) {
@@ -520,36 +595,41 @@
auto packet = hci::WriteSimplePairingModeBuilder::Create(hci::Enable::ENABLED);
// Act
- channel_->SendCommand(device_, std::move(packet));
+ channel_->SendCommand(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());
+ ASSERT_TRUE(packet_view.IsValid());
+ ASSERT_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);
+ hci::KeypressNotificationBuilder::Create(device_.GetAddress(), hci::KeypressNotificationType::ENTRY_COMPLETED));
+ ASSERT_TRUE(callback_->receivedKeypressNotification);
}
TEST_F(SecurityManagerChannelTest, send_keypress_notification) {
// Arrange
auto packet =
- hci::SendKeypressNotificationBuilder::Create(device_->GetAddress(), hci::KeypressNotificationType::ENTRY_STARTED);
+ hci::SendKeypressNotificationBuilder::Create(device_.GetAddress(), hci::KeypressNotificationType::ENTRY_STARTED);
// Act
- channel_->SendCommand(device_, std::move(packet));
+ channel_->SendCommand(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());
+ ASSERT_TRUE(packet_view.IsValid());
+ ASSERT_EQ(OpCode::SEND_KEYPRESS_NOTIFICATION, packet_view.GetOpCode());
+}
+
+TEST_F(SecurityManagerChannelTest, recv_user_passkey_request) {
+ hci_layer_->IncomingEvent(hci::UserPasskeyRequestBuilder::Create(device_.GetAddress()));
+ ASSERT_TRUE(callback_->receivedUserPasskeyRequest);
}
} // namespace