Loading system/vendor_libs/test_vendor_lib/model/controller/le_advertiser.cc +8 −2 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ void LeAdvertiser::SetScanResponse(const std::vector<uint8_t>& data) { void LeAdvertiser::Enable() { enabled_ = true; last_le_advertisement_ = std::chrono::steady_clock::now() - interval_; num_events_ = 0; LOG_INFO("%s -> %s type = %hhx ad length %zu, scan length %zu", address_.ToString().c_str(), peer_address_.ToString().c_str(), type_, advertisement_.size(), scan_response_.size()); Loading @@ -86,11 +87,11 @@ void LeAdvertiser::Enable() { void LeAdvertiser::EnableExtended( std::chrono::steady_clock::duration duration) { last_le_advertisement_ = std::chrono::steady_clock::now(); Enable(); if (duration != std::chrono::milliseconds(0)) { ending_time_ = std::chrono::steady_clock::now() + duration; } enabled_ = true; extended_ = true; LOG_INFO("%s -> %s type = %hhx ad length %zu, scan length %zu", address_.ToString().c_str(), peer_address_.ToString().c_str(), type_, advertisement_.size(), scan_response_.size()); Loading @@ -100,6 +101,10 @@ void LeAdvertiser::Disable() { enabled_ = false; } bool LeAdvertiser::IsEnabled() const { return enabled_; } bool LeAdvertiser::IsExtended() const { return extended_; } uint8_t LeAdvertiser::GetNumAdvertisingEvents() const { return num_events_; } std::unique_ptr<model::packets::LeAdvertisementBuilder> LeAdvertiser::GetAdvertisement(std::chrono::steady_clock::time_point now) { if (!enabled_) { Loading @@ -116,6 +121,7 @@ LeAdvertiser::GetAdvertisement(std::chrono::steady_clock::time_point now) { } last_le_advertisement_ = now; num_events_ += (num_events_ < 255 ? 1 : 0); return model::packets::LeAdvertisementBuilder::Create( address_.GetAddress(), peer_address_.GetAddress(), static_cast<model::packets::AddressType>(address_.GetAddressType()), Loading system/vendor_libs/test_vendor_lib/model/controller/le_advertiser.h +6 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,10 @@ class LeAdvertiser { bool IsEnabled() const; bool IsExtended() const; uint8_t GetNumAdvertisingEvents() const; bluetooth::hci::AddressWithType GetAddress() const; private: Loading @@ -81,6 +85,8 @@ class LeAdvertiser { std::vector<uint8_t> scan_response_; std::chrono::steady_clock::duration interval_{}; std::chrono::steady_clock::time_point ending_time_{}; uint8_t num_events_{0}; bool extended_{false}; bool enabled_{false}; std::chrono::steady_clock::time_point last_le_advertisement_; }; Loading system/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.cc +28 −15 Original line number Diff line number Diff line Loading @@ -1298,7 +1298,7 @@ void LinkLayerController::IncomingLeAdvertisementPacket( } } void LinkLayerController::HandleLeConnection(AddressWithType address, uint16_t LinkLayerController::HandleLeConnection(AddressWithType address, AddressWithType own_address, uint8_t role, uint16_t connection_interval, Loading @@ -1309,16 +1309,17 @@ void LinkLayerController::HandleLeConnection(AddressWithType address, if (handle == kReservedHandle) { LOG_WARN("No pending connection for connection from %s", address.ToString().c_str()); return; return kReservedHandle; } if (properties_.IsUnmasked(EventCode::LE_META_EVENT)) { auto packet = bluetooth::hci::LeConnectionCompleteBuilder::Create( ErrorCode::SUCCESS, handle, static_cast<bluetooth::hci::Role>(role), address.GetAddressType(), address.GetAddress(), connection_interval, connection_latency, supervision_timeout, static_cast<bluetooth::hci::ClockAccuracy>(0x00)); if (properties_.IsUnmasked(EventCode::LE_META_EVENT)) { send_event_(std::move(packet)); } return handle; } void LinkLayerController::IncomingLeConnectPacket( Loading @@ -1340,11 +1341,13 @@ void LinkLayerController::IncomingLeConnectPacket( } bluetooth::hci::AddressWithType my_address{}; bool matched_advertiser = false; for (auto advertiser : advertisers_) { AddressWithType advertiser_address = advertiser.GetAddress(); size_t set = 0; for (size_t i = 0; i < advertisers_.size(); i++) { AddressWithType advertiser_address = advertisers_[i].GetAddress(); if (incoming.GetDestinationAddress() == advertiser_address.GetAddress()) { my_address = advertiser_address; matched_advertiser = true; set = i; } } Loading @@ -1354,7 +1357,7 @@ void LinkLayerController::IncomingLeConnectPacket( return; } HandleLeConnection( uint16_t handle = HandleLeConnection( AddressWithType( incoming.GetSourceAddress(), static_cast<bluetooth::hci::AddressType>(connect.GetAddressType())), Loading @@ -1368,6 +1371,16 @@ void LinkLayerController::IncomingLeConnectPacket( connect.GetLeConnectionSupervisionTimeout(), static_cast<uint8_t>(my_address.GetAddressType())); SendLeLinkLayerPacket(std::move(to_send)); if (advertisers_[set].IsExtended()) { uint8_t num_advertisements = advertisers_[set].GetNumAdvertisingEvents(); advertisers_[set].Disable(); if (properties_.GetLeEventSupported( bluetooth::hci::SubeventCode::ADVERTISING_SET_TERMINATED)) { send_event_(bluetooth::hci::LeAdvertisingSetTerminatedBuilder::Create( ErrorCode::SUCCESS, set, handle, num_advertisements)); } } } void LinkLayerController::IncomingLeConnectCompletePacket( Loading system/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.h +4 −4 Original line number Diff line number Diff line Loading @@ -162,7 +162,7 @@ class LinkLayerController { ErrorCode LeConnectionUpdate( bluetooth::hci::LeConnectionUpdateView connection_update_view); void HandleLeConnection(AddressWithType addr, AddressWithType own_addr, uint16_t HandleLeConnection(AddressWithType addr, AddressWithType own_addr, uint8_t role, uint16_t connection_interval, uint16_t connection_latency, uint16_t supervision_timeout); Loading Loading
system/vendor_libs/test_vendor_lib/model/controller/le_advertiser.cc +8 −2 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ void LeAdvertiser::SetScanResponse(const std::vector<uint8_t>& data) { void LeAdvertiser::Enable() { enabled_ = true; last_le_advertisement_ = std::chrono::steady_clock::now() - interval_; num_events_ = 0; LOG_INFO("%s -> %s type = %hhx ad length %zu, scan length %zu", address_.ToString().c_str(), peer_address_.ToString().c_str(), type_, advertisement_.size(), scan_response_.size()); Loading @@ -86,11 +87,11 @@ void LeAdvertiser::Enable() { void LeAdvertiser::EnableExtended( std::chrono::steady_clock::duration duration) { last_le_advertisement_ = std::chrono::steady_clock::now(); Enable(); if (duration != std::chrono::milliseconds(0)) { ending_time_ = std::chrono::steady_clock::now() + duration; } enabled_ = true; extended_ = true; LOG_INFO("%s -> %s type = %hhx ad length %zu, scan length %zu", address_.ToString().c_str(), peer_address_.ToString().c_str(), type_, advertisement_.size(), scan_response_.size()); Loading @@ -100,6 +101,10 @@ void LeAdvertiser::Disable() { enabled_ = false; } bool LeAdvertiser::IsEnabled() const { return enabled_; } bool LeAdvertiser::IsExtended() const { return extended_; } uint8_t LeAdvertiser::GetNumAdvertisingEvents() const { return num_events_; } std::unique_ptr<model::packets::LeAdvertisementBuilder> LeAdvertiser::GetAdvertisement(std::chrono::steady_clock::time_point now) { if (!enabled_) { Loading @@ -116,6 +121,7 @@ LeAdvertiser::GetAdvertisement(std::chrono::steady_clock::time_point now) { } last_le_advertisement_ = now; num_events_ += (num_events_ < 255 ? 1 : 0); return model::packets::LeAdvertisementBuilder::Create( address_.GetAddress(), peer_address_.GetAddress(), static_cast<model::packets::AddressType>(address_.GetAddressType()), Loading
system/vendor_libs/test_vendor_lib/model/controller/le_advertiser.h +6 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,10 @@ class LeAdvertiser { bool IsEnabled() const; bool IsExtended() const; uint8_t GetNumAdvertisingEvents() const; bluetooth::hci::AddressWithType GetAddress() const; private: Loading @@ -81,6 +85,8 @@ class LeAdvertiser { std::vector<uint8_t> scan_response_; std::chrono::steady_clock::duration interval_{}; std::chrono::steady_clock::time_point ending_time_{}; uint8_t num_events_{0}; bool extended_{false}; bool enabled_{false}; std::chrono::steady_clock::time_point last_le_advertisement_; }; Loading
system/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.cc +28 −15 Original line number Diff line number Diff line Loading @@ -1298,7 +1298,7 @@ void LinkLayerController::IncomingLeAdvertisementPacket( } } void LinkLayerController::HandleLeConnection(AddressWithType address, uint16_t LinkLayerController::HandleLeConnection(AddressWithType address, AddressWithType own_address, uint8_t role, uint16_t connection_interval, Loading @@ -1309,16 +1309,17 @@ void LinkLayerController::HandleLeConnection(AddressWithType address, if (handle == kReservedHandle) { LOG_WARN("No pending connection for connection from %s", address.ToString().c_str()); return; return kReservedHandle; } if (properties_.IsUnmasked(EventCode::LE_META_EVENT)) { auto packet = bluetooth::hci::LeConnectionCompleteBuilder::Create( ErrorCode::SUCCESS, handle, static_cast<bluetooth::hci::Role>(role), address.GetAddressType(), address.GetAddress(), connection_interval, connection_latency, supervision_timeout, static_cast<bluetooth::hci::ClockAccuracy>(0x00)); if (properties_.IsUnmasked(EventCode::LE_META_EVENT)) { send_event_(std::move(packet)); } return handle; } void LinkLayerController::IncomingLeConnectPacket( Loading @@ -1340,11 +1341,13 @@ void LinkLayerController::IncomingLeConnectPacket( } bluetooth::hci::AddressWithType my_address{}; bool matched_advertiser = false; for (auto advertiser : advertisers_) { AddressWithType advertiser_address = advertiser.GetAddress(); size_t set = 0; for (size_t i = 0; i < advertisers_.size(); i++) { AddressWithType advertiser_address = advertisers_[i].GetAddress(); if (incoming.GetDestinationAddress() == advertiser_address.GetAddress()) { my_address = advertiser_address; matched_advertiser = true; set = i; } } Loading @@ -1354,7 +1357,7 @@ void LinkLayerController::IncomingLeConnectPacket( return; } HandleLeConnection( uint16_t handle = HandleLeConnection( AddressWithType( incoming.GetSourceAddress(), static_cast<bluetooth::hci::AddressType>(connect.GetAddressType())), Loading @@ -1368,6 +1371,16 @@ void LinkLayerController::IncomingLeConnectPacket( connect.GetLeConnectionSupervisionTimeout(), static_cast<uint8_t>(my_address.GetAddressType())); SendLeLinkLayerPacket(std::move(to_send)); if (advertisers_[set].IsExtended()) { uint8_t num_advertisements = advertisers_[set].GetNumAdvertisingEvents(); advertisers_[set].Disable(); if (properties_.GetLeEventSupported( bluetooth::hci::SubeventCode::ADVERTISING_SET_TERMINATED)) { send_event_(bluetooth::hci::LeAdvertisingSetTerminatedBuilder::Create( ErrorCode::SUCCESS, set, handle, num_advertisements)); } } } void LinkLayerController::IncomingLeConnectCompletePacket( Loading
system/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.h +4 −4 Original line number Diff line number Diff line Loading @@ -162,7 +162,7 @@ class LinkLayerController { ErrorCode LeConnectionUpdate( bluetooth::hci::LeConnectionUpdateView connection_update_view); void HandleLeConnection(AddressWithType addr, AddressWithType own_addr, uint16_t HandleLeConnection(AddressWithType addr, AddressWithType own_addr, uint8_t role, uint16_t connection_interval, uint16_t connection_latency, uint16_t supervision_timeout); Loading