Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Second WiFi Direct connection fails #1399

Open
orineman opened this issue Nov 7, 2023 · 2 comments
Open

Second WiFi Direct connection fails #1399

orineman opened this issue Nov 7, 2023 · 2 comments
Labels

Comments

@orineman
Copy link

orineman commented Nov 7, 2023

Which sample are you reporting a bug in?

WiFiDirect

Describe the bug

Second connection to a give Windows computer running the sample fails.

To Reproduce
Steps to reproduce the behavior:

  1. Two computers running Windows 11 with WiFi Direct capability are required.
  2. The computers being used must not be paired - Use the Settings-Bluetooth & Devices > Devices "Remove device" option so the computers don't know about each other.
  3. Run the C# WiFi Direct sample on both computers.
  4. Use the sample to make a WiFi Direct connection.
  5. Close the other device on both computers.
  6. Attempt a second connection (this usually requires that you Stop /start advertisement on one machine and Stop/Start the watcher on the other machine or the other machine isn't found).
  7. The machine being connected to shows as "not paired", but you get this error displayed: "PairAsync failed, Status: AlreadyPaired".

Expected behavior

The connection should be successfuil.

Screenshots

image

Configuration

  • Language/architecture/flavor: C#
  • Windows platform and build number: Windows 11, various
  • Visual Studio version: Various, currently 17.7.4

Additional context

The sample relies on DeviceInformationPairing.IsPaired. It is false in this case. If however, you call CreateFromIdAsync() for the device and ask for "System.Devices.Aep.IsPaired", the "System.Devices.Aep.IsPaired" property will be true. Similarly for DeviceInformationPairing.CanPair and "System.Devices.Aep.CanPair". The documentation implies DeviceInformationPairing.IsPaired is derived from "System.Devices.Aep.IsPaired", whatever that means...

It should be noted that this is a problem on the Connector side only. The Advertiser side uses an additional function, IsAepPaired() to determine if pairing is necessary.

There are various ways of making the sample work should this be an OS "feature". Don't try to pair if CanPair is false seems to work. Probably better is to call CreateFromIdAsync() for the device and use the System.Devices.Aep.IsPaired/System.Devices.Aep.CanPair properties, if present. And finally, I suppose the AlreadyPaired error could be ignored!

@orineman orineman added the bug label Nov 7, 2023
@orineman
Copy link
Author

orineman commented Nov 7, 2023

I suppose I should add that if we believe the System.Devices.Aep.IsPaired property, then the "Unpaired" designation in the "Discovered Devices" list is incorrect.

Whether this turns out to be an OS bug or not, the sample should take account of this problem as anyone shipping product will have to use some kind of workaround for this problem.

@orineman
Copy link
Author

orineman commented Nov 8, 2023

So, if you ask for System.Devices.Aep.IsPaired in the list of properties passed to DeviceInformation.CreateWatcher(), then the System.Devices.Aep.IsPaired property is copied to DeviceInformation.IsPaired. Similarly for CanPair.

                string deviceSelector = WiFiDirectDevice.GetDeviceSelector(Utils.GetSelectedItemTag<WiFiDirectDeviceSelectorType>(cmbDeviceSelector));
                _deviceWatcher = DeviceInformation.CreateWatcher(deviceSelector,
                    new string[] {
                        "System.Devices.WiFiDirect.InformationElements",
                        "System.Devices.Aep.CanPair",
                        "System.Devices.Aep.IsPaired"
                    }
                );

I'd suggest this modification is made to the sample. It fixes both this issue and the misreporting of the pairing status in the Discovered Devices list.

I've not found any documentation of this 'feature'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant