5

I'm currently developing an application where I need to create a link (read: WiFi link) between a desktop app (on Windows 10) and a tablet (Android, but it is irrelevant). Workflow: Push button -> elevate privileges if required -> Create hosted network-like WiFi network -> Allow device to connect providing a SSID/password/dynamic IP address...

Previously, I used a system call to netsh (running the app with elevated privileges) to create a hosted network. Now it seems it is less and less possible to proceed this way (example: on the same computer, it worked on Win 7 but it no longer works on Win 10). It seems to be a driver problem because it still works with an external USB antenna but not with the internal antenna. Any way, I don't want to go further with this solution.

My goal: to be able to do this programmatically using an API. I saw a lot of discussions about WiFi Direct vs Hosted Network and it seems that Hosted Network is a vanishing technology while WiFi Direct has a brilliant future??? I don't know.

I found WiFi Direct API but they look Universal Windows (UWP) oriented while I want to be able to use them in a simple C# app. This post shows how to hack the system and use the API with a simple C# console app. So far, so good, it worked.

In order to have a simple use, I used the API in Legacy mode, giving a SSID and a password in such a way my tablet see a network. WiFiDirectAdvertisementPublisherAdvertisement.LegacySettings.IsEnabled = true; The connection is very fast and everything is good.

Where it fails is that I use a streamer (something like splashtop) and it disconnects after 1-2 minutes (the streamer disconnects, not the WiFi). On the opposite, if I simply go to the "Wireless Access Point" form in Windows settings and activate it, the communication holds for more than 24 hours (and it's still running now without flaw). So, the problem is not with the streamer, neither the WiFi device hardware/driver. My first idea is that there is a WiFi Direct setting that is badly set to sustain a streaming data flow.

Going with that I'm unable to find doc on the web. The Microsoft Wlanapi.dll documentation is so-so... and I still don't know if I must focus to WiFi Direct (really?) or stick to Hosted Network because it proved it works fine?

Here is my code that works fine to maintain a WiFi link but that makes the streamer to disconnect shortly:

using System;
using Windows.Devices.WiFiDirect;
using Windows.Security.Credentials;

namespace WFDcs_1
{
    class Program
    {
        private WiFiDirectAdvertisementPublisher mPublisher = null;
        private bool mConnected = false;

        static void Main(string[] args)
        {
            Program zeProgram = new Program(args);
        }

        Program(string[] args)
        {
            StartAdvertisement(WiFiDirectAdvertisementListenStateDiscoverability.Normal);

            Console.WriteLine("Hit a key to quit...");
            Console.ReadKey();
        }

        void StopAdvertisement()
        {
            if (mConnected)
            {
                mPublisher.Stop();
                mPublisher.StatusChanged -= OnStatusChanged;
            }
        }

        void StartAdvertisement(WiFiDirectAdvertisementListenStateDiscoverability discoverability)
        {
            if ( mPublisher == null )
            {
                mPublisher = new WiFiDirectAdvertisementPublisher();
            }

            mPublisher.StatusChanged += OnStatusChanged;
            mPublisher.Advertisement.IsAutonomousGroupOwnerEnabled = true;
            mPublisher.Advertisement.LegacySettings.IsEnabled = true;
            mPublisher.Advertisement.LegacySettings.Ssid = "MyGloriousSSID";

            PasswordCredential lCred = new PasswordCredential();
            lCred.Password = "test1234";

            mPublisher.Advertisement.LegacySettings.Passphrase = lCred;

            mPublisher.Advertisement.ListenStateDiscoverability = discoverability;
            mPublisher.Start();
        }

        void OnStatusChanged(WiFiDirectAdvertisementPublisher sender, WiFiDirectAdvertisementPublisherStatusChangedEventArgs statusEventArgs)
        {
            // *** 1 ***
            Console.WriteLine("OnStatusChanged(...): New connection status: {0}", statusEventArgs.Status.ToString());
        }
    }
}

I would appreciate some reference to tutorials, examples, hints, whatever that could help me. Thank you!

5
  • In fact you can use both APIs (HostedNetwork or WiFiDirect) but should know that not all WiFi Adapters support Hosted Network and/or WiFiDirect. WiFi Adapter may support only Hosted Network or only WiFi Direct. So your application must support both. Th eother problem is that Hosted Network and WiFi Direct in SoftAP mode (legacy) creates Virtual AP on your PC. Instead of that WiFiDirect creates somple point-ot-point connection with much better features and productivity. You can take a look on our WiFi Framework that supports WiFi Direct and Hosted Network (btframework.com) Commented Mar 12, 2019 at 12:23
  • Are there some settings that can be set (else than SSID/pwd)? MS doc is very poor for these APIs...
    – dom_beau
    Commented Mar 12, 2019 at 19:12
  • Depending on what you need. For AdHock (Hosted Network) only SSID and PWD can be set. Because it appears as Access Point. The same is true for WiFiDirect Legacy SoftAP mode. However, normal WiFiDirect allows to provide lot of settings: authetnication methods, Group Owner, Group ID, supported services and others. Commented Mar 12, 2019 at 19:37
  • Actually, as I wrote, my streamer disconnect after some time with WiFi Direct but not with Hosted Network. I cannot start Hosted Network, so I want to use WiFi Direct. Do some tutorials and/or examples exist for these APIs?
    – dom_beau
    Commented Mar 12, 2019 at 19:40
  • Here is complete demo apps: github.com/Microsoft/Windows-universal-samples/tree/master/… Commented Mar 12, 2019 at 19:44

1 Answer 1

1

After looking to example refered to by Mike Petrichenko, I finaly found this link: (native c++ example to download) in this page. It makes use of WiFiDirect in legacy mode to simulate a hosted network. It uses WRL. No *.vcxproj file to hack, no "strange" library to link to. Also there are some more or less useful explanations here. Exactly what I wanted.

I must say that this information was not easy to find...

1
  • The key phrase is "Wi-Fi Direct Legacy AP Mode" which is the name for Wi-Fi Direct supporting the 'soft AP' mechanism. The utilities pointed to here allow you to enable this for mode any Wi-Fi device and driver which supports Wi-Fi Direct (most do). No need for the deprecated "Hosted Network" support which has been removed from many updated drivers.
    – Govert
    Commented Oct 2, 2020 at 16:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.