Loading system/vendor_libs/test_vendor_lib/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ cc_library_static { "net/posix/posix_async_socket_server.cc", ":BluetoothPacketSources", ":BluetoothHciClassSources", ":BluetoothCryptoToolboxSources", ], cflags: [ "-Wall", Loading system/vendor_libs/test_vendor_lib/model/controller/dual_mode_controller.cc +3 −6 Original line number Diff line number Diff line Loading @@ -1998,16 +1998,13 @@ void DualModeController::LeAddDeviceToResolvingList(CommandView command) { gd_hci::LeSecurityCommandView::Create(command)); ASSERT(command_view.IsValid()); uint8_t addr_type = auto addr_type = static_cast<uint8_t>(command_view.GetPeerIdentityAddressType()); Address address = command_view.GetPeerIdentityAddress(); std::array<uint8_t, LinkLayerController::kIrk_size> peerIrk = command_view.GetPeerIrk(); std::array<uint8_t, LinkLayerController::kIrk_size> localIrk = command_view.GetLocalIrk(); auto status = link_layer_controller_.LeResolvingListAddDevice( address, addr_type, peerIrk, localIrk); address, addr_type, command_view.GetPeerIrk(), command_view.GetLocalIrk()); auto packet = bluetooth::hci::LeAddDeviceToResolvingListCompleteBuilder::Create( kNumCommandPackets, status); Loading system/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.cc +33 −14 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #include <hci/hci_packets.h> #include "crypto_toolbox/crypto_toolbox.h" #include "include/le_advertisement.h" #include "os/log.h" #include "packet/raw_builder.h" Loading Loading @@ -1143,6 +1144,19 @@ void LinkLayerController::IncomingKeypressNotificationPacket( } } static bool rpa_matches_irk( Address rpa, std::array<uint8_t, LinkLayerController::kIrkSize> irk) { // 1.3.2.3 Private device address resolution uint8_t hash[3] = {rpa.address[0], rpa.address[1], rpa.address[2]}; uint8_t prand[3] = {rpa.address[3], rpa.address[4], rpa.address[5]}; // generate X = E irk(R0, R1, R2) and R is random address 3 LSO auto x = bluetooth::crypto_toolbox::aes_128(irk, &prand[0], 3); // If the hashes match, this is the IRK return (memcmp(x.data(), &hash[0], 3) == 0); } void LinkLayerController::IncomingLeAdvertisementPacket( model::packets::LinkLayerPacketView incoming) { // TODO: Handle multiple advertisements per packet. Loading Loading @@ -1226,13 +1240,27 @@ void LinkLayerController::IncomingLeAdvertisementPacket( SendLeLinkLayerPacket(std::move(to_send)); } Address resolved_address = address; uint8_t resolved_address_type = static_cast<uint8_t>(address_type); bool resolved = false; for (const auto& entry : le_resolving_list_) { if (rpa_matches_irk(address, entry.peer_irk)) { resolved = true; resolved_address = entry.address; resolved_address_type = entry.address_type; } } // Connect if ((le_connect_ && le_peer_address_ == address && le_peer_address_type_ == static_cast<uint8_t>(address_type) && (adv_type == model::packets::AdvertisementType::ADV_IND || adv_type == model::packets::AdvertisementType::ADV_DIRECT_IND)) || (LeConnectListContainsDevice(address, static_cast<uint8_t>(address_type)))) { static_cast<uint8_t>(address_type))) || (resolved && LeConnectListContainsDevice( resolved_address, static_cast<uint8_t>(resolved_address_type)))) { if (!connections_.CreatePendingLeConnection(AddressWithType( address, static_cast<bluetooth::hci::AddressType>(address_type)))) { LOG_WARN( Loading Loading @@ -2772,25 +2800,16 @@ ErrorCode LinkLayerController::LeConnectListAddDevice(Address addr, } ErrorCode LinkLayerController::LeResolvingListAddDevice( Address addr, uint8_t addr_type, std::array<uint8_t, kIrk_size> peerIrk, std::array<uint8_t, kIrk_size> localIrk) { Address addr, uint8_t addr_type, std::array<uint8_t, kIrkSize> peerIrk, std::array<uint8_t, kIrkSize> localIrk) { if (ResolvingListBusy()) { return ErrorCode::COMMAND_DISALLOWED; } std::tuple<Address, uint8_t, std::array<uint8_t, kIrk_size>, std::array<uint8_t, kIrk_size>> new_tuple = std::make_tuple(addr, addr_type, peerIrk, localIrk); for (size_t i = 0; i < le_connect_list_.size(); i++) { auto curr = le_connect_list_[i]; if (std::get<0>(curr) == addr && std::get<1>(curr) == addr_type) { le_resolving_list_[i] = new_tuple; return ErrorCode::SUCCESS; } } if (LeResolvingListFull()) { return ErrorCode::MEMORY_CAPACITY_EXCEEDED; } le_resolving_list_.emplace_back(new_tuple); le_resolving_list_.emplace_back( ResolvingListEntry{addr, addr_type, peerIrk, localIrk}); return ErrorCode::SUCCESS; } Loading system/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.h +10 −6 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ using ::bluetooth::hci::OpCode; class LinkLayerController { public: static constexpr size_t kIrk_size = 16; static constexpr size_t kIrkSize = 16; LinkLayerController(const DeviceProperties& properties) : properties_(properties) {} ErrorCode SendCommandToRemoteByAddress( Loading Loading @@ -176,8 +176,8 @@ class LinkLayerController { bool ResolvingListBusy(); ErrorCode LeResolvingListClear(); ErrorCode LeResolvingListAddDevice(Address addr, uint8_t addr_type, std::array<uint8_t, kIrk_size> peerIrk, std::array<uint8_t, kIrk_size> localIrk); std::array<uint8_t, kIrkSize> peerIrk, std::array<uint8_t, kIrkSize> localIrk); ErrorCode LeResolvingListRemoveDevice(Address addr, uint8_t addr_type); bool LeResolvingListContainsDevice(Address addr, uint8_t addr_type); bool LeResolvingListFull(); Loading Loading @@ -445,9 +445,13 @@ class LinkLayerController { std::vector<uint8_t> le_event_mask_; std::vector<std::tuple<Address, uint8_t>> le_connect_list_; std::vector<std::tuple<Address, uint8_t, std::array<uint8_t, kIrk_size>, std::array<uint8_t, kIrk_size>>> le_resolving_list_; struct ResolvingListEntry { Address address; uint8_t address_type; std::array<uint8_t, kIrkSize> peer_irk; std::array<uint8_t, kIrkSize> local_irk; }; std::vector<ResolvingListEntry> le_resolving_list_; std::array<LeAdvertiser, 7> advertisers_; Loading Loading
system/vendor_libs/test_vendor_lib/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ cc_library_static { "net/posix/posix_async_socket_server.cc", ":BluetoothPacketSources", ":BluetoothHciClassSources", ":BluetoothCryptoToolboxSources", ], cflags: [ "-Wall", Loading
system/vendor_libs/test_vendor_lib/model/controller/dual_mode_controller.cc +3 −6 Original line number Diff line number Diff line Loading @@ -1998,16 +1998,13 @@ void DualModeController::LeAddDeviceToResolvingList(CommandView command) { gd_hci::LeSecurityCommandView::Create(command)); ASSERT(command_view.IsValid()); uint8_t addr_type = auto addr_type = static_cast<uint8_t>(command_view.GetPeerIdentityAddressType()); Address address = command_view.GetPeerIdentityAddress(); std::array<uint8_t, LinkLayerController::kIrk_size> peerIrk = command_view.GetPeerIrk(); std::array<uint8_t, LinkLayerController::kIrk_size> localIrk = command_view.GetLocalIrk(); auto status = link_layer_controller_.LeResolvingListAddDevice( address, addr_type, peerIrk, localIrk); address, addr_type, command_view.GetPeerIrk(), command_view.GetLocalIrk()); auto packet = bluetooth::hci::LeAddDeviceToResolvingListCompleteBuilder::Create( kNumCommandPackets, status); Loading
system/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.cc +33 −14 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #include <hci/hci_packets.h> #include "crypto_toolbox/crypto_toolbox.h" #include "include/le_advertisement.h" #include "os/log.h" #include "packet/raw_builder.h" Loading Loading @@ -1143,6 +1144,19 @@ void LinkLayerController::IncomingKeypressNotificationPacket( } } static bool rpa_matches_irk( Address rpa, std::array<uint8_t, LinkLayerController::kIrkSize> irk) { // 1.3.2.3 Private device address resolution uint8_t hash[3] = {rpa.address[0], rpa.address[1], rpa.address[2]}; uint8_t prand[3] = {rpa.address[3], rpa.address[4], rpa.address[5]}; // generate X = E irk(R0, R1, R2) and R is random address 3 LSO auto x = bluetooth::crypto_toolbox::aes_128(irk, &prand[0], 3); // If the hashes match, this is the IRK return (memcmp(x.data(), &hash[0], 3) == 0); } void LinkLayerController::IncomingLeAdvertisementPacket( model::packets::LinkLayerPacketView incoming) { // TODO: Handle multiple advertisements per packet. Loading Loading @@ -1226,13 +1240,27 @@ void LinkLayerController::IncomingLeAdvertisementPacket( SendLeLinkLayerPacket(std::move(to_send)); } Address resolved_address = address; uint8_t resolved_address_type = static_cast<uint8_t>(address_type); bool resolved = false; for (const auto& entry : le_resolving_list_) { if (rpa_matches_irk(address, entry.peer_irk)) { resolved = true; resolved_address = entry.address; resolved_address_type = entry.address_type; } } // Connect if ((le_connect_ && le_peer_address_ == address && le_peer_address_type_ == static_cast<uint8_t>(address_type) && (adv_type == model::packets::AdvertisementType::ADV_IND || adv_type == model::packets::AdvertisementType::ADV_DIRECT_IND)) || (LeConnectListContainsDevice(address, static_cast<uint8_t>(address_type)))) { static_cast<uint8_t>(address_type))) || (resolved && LeConnectListContainsDevice( resolved_address, static_cast<uint8_t>(resolved_address_type)))) { if (!connections_.CreatePendingLeConnection(AddressWithType( address, static_cast<bluetooth::hci::AddressType>(address_type)))) { LOG_WARN( Loading Loading @@ -2772,25 +2800,16 @@ ErrorCode LinkLayerController::LeConnectListAddDevice(Address addr, } ErrorCode LinkLayerController::LeResolvingListAddDevice( Address addr, uint8_t addr_type, std::array<uint8_t, kIrk_size> peerIrk, std::array<uint8_t, kIrk_size> localIrk) { Address addr, uint8_t addr_type, std::array<uint8_t, kIrkSize> peerIrk, std::array<uint8_t, kIrkSize> localIrk) { if (ResolvingListBusy()) { return ErrorCode::COMMAND_DISALLOWED; } std::tuple<Address, uint8_t, std::array<uint8_t, kIrk_size>, std::array<uint8_t, kIrk_size>> new_tuple = std::make_tuple(addr, addr_type, peerIrk, localIrk); for (size_t i = 0; i < le_connect_list_.size(); i++) { auto curr = le_connect_list_[i]; if (std::get<0>(curr) == addr && std::get<1>(curr) == addr_type) { le_resolving_list_[i] = new_tuple; return ErrorCode::SUCCESS; } } if (LeResolvingListFull()) { return ErrorCode::MEMORY_CAPACITY_EXCEEDED; } le_resolving_list_.emplace_back(new_tuple); le_resolving_list_.emplace_back( ResolvingListEntry{addr, addr_type, peerIrk, localIrk}); return ErrorCode::SUCCESS; } Loading
system/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.h +10 −6 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ using ::bluetooth::hci::OpCode; class LinkLayerController { public: static constexpr size_t kIrk_size = 16; static constexpr size_t kIrkSize = 16; LinkLayerController(const DeviceProperties& properties) : properties_(properties) {} ErrorCode SendCommandToRemoteByAddress( Loading Loading @@ -176,8 +176,8 @@ class LinkLayerController { bool ResolvingListBusy(); ErrorCode LeResolvingListClear(); ErrorCode LeResolvingListAddDevice(Address addr, uint8_t addr_type, std::array<uint8_t, kIrk_size> peerIrk, std::array<uint8_t, kIrk_size> localIrk); std::array<uint8_t, kIrkSize> peerIrk, std::array<uint8_t, kIrkSize> localIrk); ErrorCode LeResolvingListRemoveDevice(Address addr, uint8_t addr_type); bool LeResolvingListContainsDevice(Address addr, uint8_t addr_type); bool LeResolvingListFull(); Loading Loading @@ -445,9 +445,13 @@ class LinkLayerController { std::vector<uint8_t> le_event_mask_; std::vector<std::tuple<Address, uint8_t>> le_connect_list_; std::vector<std::tuple<Address, uint8_t, std::array<uint8_t, kIrk_size>, std::array<uint8_t, kIrk_size>>> le_resolving_list_; struct ResolvingListEntry { Address address; uint8_t address_type; std::array<uint8_t, kIrkSize> peer_irk; std::array<uint8_t, kIrkSize> local_irk; }; std::vector<ResolvingListEntry> le_resolving_list_; std::array<LeAdvertiser, 7> advertisers_; Loading