diff --git a/connections/implementation/offline_frames_validator.cc b/connections/implementation/offline_frames_validator.cc index d388d6eb..c42cd4a3 100644 --- a/connections/implementation/offline_frames_validator.cc +++ b/connections/implementation/offline_frames_validator.cc @@ -61,8 +61,13 @@ constexpr absl::string_view kWifiDirectSsidPatternString{ constexpr int kWifiDirectSsidMaxLength = 32; constexpr int kWifiPasswordSsidMinLength = 8; constexpr int kWifiPasswordSsidMaxLength = 64; -// We may use Push Button for WPS, so no pin is required, the min length should -// be 0. +// For Windows Wifi Direct based on WinRT Windows.Devices.WiFiDirect, user can't +// choose pin when pairing with the other device. Instead, When GO is created, a +// pin is created by OS. But at this stage, BWU has already sent device name as +// credential to GC for connection. Current BWU design has no way to send second +// ForBwuWifiDirectPathAvailable frame with pin as crdential to GC. To avoid +// major change in BWU structure, we decided to use ConfirmOnly(Push Button) for +// WPS, so no pin is required, the min length should be 0. constexpr int kWifiDirectPinMinLength = 0; constexpr int kWifiDirectPinMaxLength = 16; diff --git a/internal/platform/implementation/windows/wifi_direct.h b/internal/platform/implementation/windows/wifi_direct.h index 399b3f5d..982fa6ba 100644 --- a/internal/platform/implementation/windows/wifi_direct.h +++ b/internal/platform/implementation/windows/wifi_direct.h @@ -274,7 +274,7 @@ class WifiDirectMedium : public api::WifiDirectMedium { bool IsIdle() { return medium_status_ == kMediumStatusIdle; } // Advertiser is accepting connection on server socket bool IsAccepting() { return (medium_status_ & kMediumStatusAccepting) != 0; } - // GO is starated and sending beacon + // GO is started and sending beacon bool IsBeaconing() { return (medium_status_ & kMediumStatusBeaconing) != 0; } // GC is connecting to the GO bool IsConnecting() { diff --git a/internal/platform/implementation/windows/wifi_direct_medium.cc b/internal/platform/implementation/windows/wifi_direct_medium.cc index dac7d1a5..7adc12eb 100644 --- a/internal/platform/implementation/windows/wifi_direct_medium.cc +++ b/internal/platform/implementation/windows/wifi_direct_medium.cc @@ -44,8 +44,10 @@ namespace nearby::windows { namespace { -constexpr int kWaitingForConnectionTimeoutSeconds = 60; // seconds -constexpr int kWaitingForRePair = 3; // seconds +constexpr absl::Duration kServiceConnectionTimeout = absl::Seconds(60); +constexpr absl::Duration kWaitingForRePair = absl::Seconds(3); +constexpr absl::Duration kWaitForGOServerStart = absl::Milliseconds(500); +constexpr absl::Duration kConnectTimeout = absl::Seconds(30); } // namespace WifiDirectDeviceDiscovered::WifiDirectDeviceDiscovered( @@ -135,7 +137,7 @@ std::unique_ptr WifiDirectMedium::ConnectToService( LOG(INFO) << "Connect to service "; // In the test, GO server takes longer to started, so wait for 500ms before // trying to connect to the service. - absl::SleepFor(absl::Milliseconds(500)); + absl::SleepFor(kWaitForGOServerStart); for (int i = 0; i < wifi_direct_max_connection_retries; ++i) { auto wifi_direct_socket = std::make_unique(); @@ -200,8 +202,8 @@ std::unique_ptr WifiDirectMedium::ListenForService( if (ip_address_local_.empty()) { if (server_socket_ptr_) { LOG(INFO) << "Waiting for IP address is ready."; - is_ip_address_ready_.WaitWithTimeout( - &mutex_, absl::Seconds(kWaitingForConnectionTimeoutSeconds)); + is_ip_address_ready_.WaitWithTimeout(&mutex_, + kServiceConnectionTimeout); if (!server_socket_ptr_) { LOG(WARNING) << "Server socket was closed before IP address is ready."; @@ -459,8 +461,8 @@ fire_and_forget WifiDirectMedium::OnConnectionRequested( unpairing_result.Status() == DeviceUnpairingResultStatus::AlreadyUnpaired) { LOG(INFO) << "GO Unpaired GC, Re-pair"; - // Wait for kWaitingForRePair seconds to allow WiFi driver to stabilize. - absl::SleepFor(absl::Seconds(kWaitingForRePair)); + // Wait for kWaitingForRePair to allow WiFi driver to stabilize. + absl::SleepFor(kWaitingForRePair); // Refresh device info after unpairing. DeviceInformation refreshed_device_info = DeviceInformation::CreateFromIdAsync(device_id).get(); @@ -642,8 +644,9 @@ bool WifiDirectMedium::ConnectWifiDirect( } } - LOG(INFO) << "Started to discover and wait 30s for connection."; - connection_latch_->Await(absl::Seconds(30)); + LOG(INFO) << "Started to discover and wait " << kConnectTimeout + << " for connection."; + connection_latch_->Await(kConnectTimeout); { absl::MutexLock lock(mutex_); if (IsConnected()) { @@ -777,10 +780,9 @@ fire_and_forget WifiDirectMedium::Watcher_DeviceAdded( if (unpairing_result.Status() == DeviceUnpairingResultStatus::Unpaired || unpairing_result.Status() == DeviceUnpairingResultStatus::AlreadyUnpaired) { - // Wait kWaitingForRePair seconds for the device stabilize before - // re-pairing. This may avoid the possible contention problems in Intel - // WiFi driver. - absl::SleepFor(absl::Seconds(kWaitingForRePair)); + // Wait kWaitingForRePair for the device stabilize before re-pairing. + // This may avoid the possible contention problems in Intel WiFi driver. + absl::SleepFor(kWaitingForRePair); DeviceInformation refreshed_device_info = DeviceInformation::CreateFromIdAsync(device_id).get(); is_paired = RequestPairDeviceAsync(refreshed_device_info.Pairing(), 1,