diff --git a/connections/implementation/offline_frames.cc b/connections/implementation/offline_frames.cc index 246d3377..a6a240fd 100644 --- a/connections/implementation/offline_frames.cc +++ b/connections/implementation/offline_frames.cc @@ -19,7 +19,6 @@ #include #include -#include "absl/strings/str_cat.h" #include "connections/connection_options.h" #include "connections/implementation/flags/nearby_connections_feature_flags.h" #include "connections/implementation/internal_payload.h" @@ -30,6 +29,7 @@ #include "internal/flags/nearby_flags.h" #include "internal/platform/byte_array.h" #include "internal/platform/exception.h" +#include "internal/platform/implementation/wifi_utils.h" #include "internal/platform/logging.h" #include "internal/platform/mac_address.h" @@ -283,16 +283,6 @@ ByteArray ForBwuWifiHotspotPathAvailable( ByteArray ForBwuWifiLanPathAvailable( const std::vector& ip_addresses, std::int32_t port) { - // For compatibility with Android versions, only use IPv4 address. - // IPv4 addresses are always at the end of the list. - std::string ip_address = ip_addresses.back(); - if (ip_address.size() != 4) { - return {}; - } - VLOG(1) << "WifiLanBwuPath retrieved WIFI_LAN credentials. IP addr: " - << absl::Hex(ip_address[0]) << "." << absl::Hex(ip_address[1]) << "." - << absl::Hex(ip_address[2]) << "." << absl::Hex(ip_address[3]) - << ", Port: " << port; OfflineFrame frame; frame.set_version(OfflineFrame::V1); @@ -305,9 +295,21 @@ ByteArray ForBwuWifiLanPathAvailable( upgrade_path_info->set_medium(UpgradePathInfo::WIFI_LAN); upgrade_path_info->set_supports_client_introduction_ack(true); auto* wifi_lan_socket = upgrade_path_info->mutable_wifi_lan_socket(); - wifi_lan_socket->set_ip_address(ip_address); - wifi_lan_socket->set_wifi_port(port); - + // For compatibility with Android versions, only use IPv4 address. + // IPv4 addresses are always at the end of the list. + std::string ip_address = ip_addresses.back(); + if (ip_address.size() == 4) { + wifi_lan_socket->set_ip_address(ip_address); + wifi_lan_socket->set_wifi_port(port); + } + for (const auto& address : ip_addresses) { + auto* address_candidate = wifi_lan_socket->add_address_candidates(); + std::string ip_address = std::string(address.begin(), address.end()); + address_candidate->set_ip_address(ip_address); + address_candidate->set_port(port); + VLOG(1) << "ForBwuWifiLanPathAvailable: " + << WifiUtils::GetHumanReadableIpAddress(ip_address) << ":" << port; + } return ToBytes(std::move(frame)); } diff --git a/connections/implementation/offline_frames_test.cc b/connections/implementation/offline_frames_test.cc index 936e9547..3c4945b9 100644 --- a/connections/implementation/offline_frames_test.cc +++ b/connections/implementation/offline_frames_test.cc @@ -441,12 +441,28 @@ TEST(OfflineFramesTest, CanGenerateBwuWifiLanPathAvailable) { event_type: UPGRADE_PATH_AVAILABLE upgrade_path_info: < medium: WIFI_LAN - wifi_lan_socket: < ip_address: "\x01\x02\x03\x04" wifi_port: 1234 > + wifi_lan_socket: < + ip_address: "\x01\x02\x03\x04" + wifi_port: 1234 + address_candidates: < + ip_address: "\x2a\x00\x79\xe0\x2e\x87\x00\x06\xb7\x28\x67\x45\x7a\xdd\x01\x53" + port: 1234 + > + address_candidates: < + ip_address: "\001\002\003\004" + port: 1234 + > + > supports_client_introduction_ack: true > > >)pb"; - ByteArray bytes = ForBwuWifiLanPathAvailable({"\x01\x02\x03\x04"}, 1234); + ByteArray bytes = ForBwuWifiLanPathAvailable( + {std::string( + "\x2a\x00\x79\xe0\x2e\x87\x00\x06\xb7\x28\x67\x45\x7a\xdd\x01\x53", + 16), + "\x01\x02\x03\x04"}, + 1234); auto response = FromBytes(bytes); ASSERT_TRUE(response.ok()); OfflineFrame message = response.result(); diff --git a/internal/platform/flags/nearby_platform_feature_flags.h b/internal/platform/flags/nearby_platform_feature_flags.h index a91c2f32..b760aa4b 100644 --- a/internal/platform/flags/nearby_platform_feature_flags.h +++ b/internal/platform/flags/nearby_platform_feature_flags.h @@ -73,10 +73,14 @@ constexpr auto kEnableIpv6DualStack = constexpr auto kEnableMdnsIpv6 = flags::Flag(kConfigPackage, "45735181", false); - // Enable/Disable new Bluetooth refactor +// Enable/Disable new Bluetooth refactor constexpr auto kEnableNewBluetoothRefactor = flags::Flag(kConfigPackage, "45615156", false); +// Enable/Disable use of address candidates for WifiLan upgrade in Windows. +constexpr auto kEnableWifiLanAddressCandidates = + flags::Flag(kConfigPackage, "45739995", false); + // The send buffer size of blocking socket constexpr auto kSocketSendBufferSize = flags::Flag(kConfigPackage, "45673785", 524288); diff --git a/internal/platform/implementation/windows/wifi_lan_medium.cc b/internal/platform/implementation/windows/wifi_lan_medium.cc index 035593ff..717a1977 100644 --- a/internal/platform/implementation/windows/wifi_lan_medium.cc +++ b/internal/platform/implementation/windows/wifi_lan_medium.cc @@ -765,10 +765,15 @@ std::vector WifiLanMedium::GetUpgradeAddressCandidates( 4)); } } - // Append v4 addresses to the end of the list. - ip_addresses.insert(ip_addresses.end(), ipv4_addresses.begin(), - ipv4_addresses.end()); - return ip_addresses; + if (NearbyFlags::GetInstance().GetBoolFlag( + platform::config_package_nearby::nearby_platform_feature:: + kEnableWifiLanAddressCandidates)) { + // Append v4 addresses to the end of the list. + ip_addresses.insert(ip_addresses.end(), ipv4_addresses.begin(), + ipv4_addresses.end()); + return ip_addresses; + } + return { ip_addresses.back() }; } } // namespace nearby::windows