WlanHostedNetworkStartUsing 或 Windows 10 内置移动热点的工作原理 [英] WlanHostedNetworkStartUsing or how windows 10 builtin mobile hotspot works

查看:90
本文介绍了WlanHostedNetworkStartUsing 或 Windows 10 内置移动热点的工作原理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个创建热点的程序.我正在使用 WlanHostedNetworkStartUsing 但它返回 ERROR_INVALID_STATE.然而,当我调用 WlanHostedNetworkInitSettings 时,它返回成功.根据

问题:windows 工具如何做到这一点以及我如何在我的应用中使用这种机制?

解决方案

2018 年 6 月 6 日的原始评论(见下面的更新):

Microsoft 弃用了 WLAN HostedNetwork 功能,但它不是适用于 Win10 驱动程序.要在 Win10 中使用旧模型,您必须查找并安装 2015 年的驱动程序(8.1 或更早版本,具体取决于供应商).

Win10驱动模型将HostedNetwork的机制改为基于 WiFi Direct,并从应用程序开发人员和将此功能移至内核.有一些样品可用,如果你四处挖掘,展示如何使用现代 com (RT) UWP 应用程序库来配置 WiFi Direct HostedNetwork.这是一个皮塔饼,微软没有解释,大多数人不理解在网络上对此发表评论,并且主要看起来像两步微软在产品功能被削减以出货的失败团队之间的日程安排和重组改变了所有权和计划WiFi和热点.WiFi直接启用 - 理论上 - 更简单设备之间的配对和身份验证模型.但目前实施涉及蓝牙,因此值得怀疑除了支持有限的移动设备 WiFi 2.0 场景.如果你正在使用无头设备或物联网设备方案,这是坏了.

我不得不在这方面做很多工作.如果你有选择WiFi 硬件,我强烈推荐使用英特尔驱动程序(它们是可靠的).

如果您的场景允许 UX,您可能会发现此 App Store 应用程序很有帮助相互作用.

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:

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

这篇关于WlanHostedNetworkStartUsing 或 Windows 10 内置移动热点的工作原理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆