I'm trying to write a program which creates hotspot. I'm using WlanHostedNetworkStartUsing
but it returns ERROR_INVALID_STATE
. And yet when I call WlanHostedNetworkInitSettings
it returns succsess. According to documemtation (last paragraph in Remarks section) it should to create a virtual wireless connection under Control Panel\Network and Internet\Network and Sharing Center but it doesn't.
I've searching a bit and found this:
When I run netsh wlan show drivers
it puts:
Driver : Intel(R) Dual Band Wireless-AC 3165
Vendor : Intel Corporation
Provider : Intel
Date : 07-Sep-16
Version : 19.20.0.6
INF file : ????
Type : Native Wi-Fi Driver
Radio types supported : 802.11b 802.11g 802.11n 802.11a 802.11ac
/ ...
Hosted network supported : No <--- Here
/ ...
So it says my wifi adapter doesn't wifi sharing at all (I have last drivers from HP site).
BUT when I try to create hotspot with Windows 10 builtin' tool it works.
The question: How could windows tool do it and how can I use this mechanism in my app?
Original 06/06/2018 comments here (see updates below):
Microsoft deprecated the WLAN HostedNetwork capability and it is NOT available for Win10 drivers. To use the old model in Win10 you must find and install drivers from 2015 (8.1 or possibly earlier depending on vendor).
The Win10 driver model changed the mechanism of HostedNetwork to be based on WiFi Direct, and took control away from app-developers and moved this feature to the kernel. There are some samples available if you dig around, that show how to use the modern-com (RT) UWP app libraries to configure a WiFi Direct HostedNetwork. It is a PITA, which was not explained by Microsoft, is not understood by most people commenting on this in the web, and which mostly looks like a two-step microsoft failure where product features were cut to make ship schedule and re-orgs among teams changed the ownership and plan for WiFi and hotspots. WiFi direct enables - theoretically - a simpler pairing and authentication model between devices. But the currently implementation involves bluetooth and therefore it is questionable other than support a limited mobile device WiFi 2.0 scenario. If you are working with headless devices or IoT device scenarios this is broken.
I've had to do a lot of work in this area. If you have a choice in WiFi hardware, I strongly recommend a hardware chipset that uses the Intel drivers (they are solid).
You may find this App store app helpful if your scenario allows for UX interaction. http://www.topuwp.com/windowsapps/wifi-direct-access-point/598084.html
====================
02/27/2020 Update to that story...
When Hosted network supported : No
then legacy hosted network support is not available on your adapter because you have WiFi Direct in Windows 10 etc. In which case you'll want to know and use this very sparsely commented on supported portion of WiFi Direct:
https://docs.microsoft.com/en-us/uwp/api/windows.networking.networkoperators.networkoperatortetheringmanager.createfromconnectionprofile
Command Line to HotSpot settings: start ms-settings:network-mobilehotspot
Article that talks about PowerShell programmatic access to the WinRT HotSpot APIs
enable Win10 inbuild hotspot by cmd/batch/powershell
KEYWORDS: "Virtual Wi-Fi", SoftAP, AdHoc IBSS, MobileHotSpot, netsh wlan HostedNetwork
====================
Which would not be complete without a working C++/WinRT
code sample as follows:
#include <winrt/Windows.Networking.Connectivity.h>
#include <winrt/Windows.Networking.NetworkOperators.h>
#include <winrt/Windows.Devices.WiFiDirect.h>
#include <winrt/Windows.Security.Credentials.h>
namespace winrt { // /ZW embed in :<winrt> when `Windows` is ambiguously defined
static void af_winrt_wifi_hotspot_test() {
// start ms-settings:network-mobilehotspot
init_apartment(); // apartment_type::multi_threaded
if (false /* play as you wish to test this all in simple c++ console app, I used clang */) {
auto publisher = Windows::Devices::WiFiDirect::WiFiDirectAdvertisementPublisher();
auto advertisement = publisher.Advertisement();
advertisement.ListenStateDiscoverability(Windows::Devices::WiFiDirect::WiFiDirectAdvertisementListenStateDiscoverability::Intensive);
advertisement.IsAutonomousGroupOwnerEnabled(true);
auto legacySettings = advertisement.LegacySettings();
legacySettings.IsEnabled(true);
legacySettings.Ssid(L"your-hotspot-name");
auto credential = Windows::Security::Credentials::PasswordCredential(); credential.Password(L"the-password!");
legacySettings.Passphrase(credential);
publisher.Start();
}
else {
auto connectionProfile{ Windows::Networking::Connectivity::NetworkInformation::GetInternetConnectionProfile() };
auto tetheringManager = Windows::Networking::NetworkOperators::NetworkOperatorTetheringManager::CreateFromConnectionProfile(connectionProfile);
auto credential = Windows::Security::Credentials::PasswordCredential(); credential.Password(L"the-password!");
auto conf = Windows::Networking::NetworkOperators::NetworkOperatorTetheringAccessPointConfiguration();
conf.Ssid(L"I-Own-You"); conf.Passphrase(credential.Password());
auto oldConf = tetheringManager.GetCurrentAccessPointConfiguration();
auto oldSsid = oldConf.Ssid(); auto oldPwd = oldConf.Passphrase();
tetheringManager.ConfigureAccessPointAsync(conf); // Sets new ssid/pwd here
switch (tetheringManager.TetheringOperationalState()) {
case Windows::Networking::NetworkOperators::TetheringOperationalState::Off: {
auto ioAsync = tetheringManager.StartTetheringAsync();
auto fResult = ioAsync.get();
}
break;
case Windows::Networking::NetworkOperators::TetheringOperationalState::On: {
// auto ioAsync = tetheringManager.StopTetheringAsync();
// auto fResult = ioAsync.get();
}
break;
case Windows::Networking::NetworkOperators::TetheringOperationalState::InTransition:
default:
break;
}
}
clear_factory_cache();
uninit_apartment();
}
}
Look here for older Microsoft Samples relating to WiFiDirectAdvertisementPublisher
:
WFD_GROUP_OWNER_PROFILE
profile is in this dir-path: C:\ProgramData\Microsoft\Wlansvc\Profiles\Interfaces\
So many articles on the web, so much confusion created by WiFi-Direct.
I've spent two whole days figuring it all out. Which, for my time, is a lot.
No excuse for Microsoft (where I use to work as an Architect) not having created a Blog about this very popular topic. Let alone simply having made netsh and Ad Hoc Wifi compat support, instead of leaving it so cryptic and confusing for devops, end-users, and developers.
-- enjoy David
The above is pretty concise, and exposes working c++/WinRT code for all scenarios.
[I now have this bundled in EdgeS: EdgeShell/EdgeScript/afm-scm toolset] []5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With