How are the HotspotAuthentication group of classes to be used
Currently, We have fewer documents on this. I have discuss with product team about this. I checked official code sample, it looks easy to understand. We use xml file to store hotspot configuration. And it contains ssid
encryption
protocol HotspotProfile
etc.
<CarrierProvisioning xmlns="http://www.microsoft.com/networking/CarrierControl/v1">
<Global>
<!-- Adjust the Carrier ID to fit your own ID. Refer to the MSDN documentation about Carrier ID's. -->
<CarrierId>{11111111-1111-1111-1111-111111111111}</CarrierId>
<!-- Adjust the Susbscriber ID. Refer to the MSDN documentation about Subscriber ID's. -->
<SubscriberId>1234567890</SubscriberId>
</Global>
<WLANProfiles>
<WLANProfile xmlns="http://www.microsoft.com/networking/CarrierControl/WLAN/v1">
<!-- Adjust the profile name to have a human readable network name. By default this equals the SSID. -->
<name>Contoso Wi-Fi</name>
<SSIDConfig>
<SSID>
<!-- Adjust the SSID name to fit the SSID of the hotspot. -->
<name>contosowifi</name>
</SSID>
</SSIDConfig>
<MSM>
<security>
<authEncryption>
<authentication>open</authentication>
<encryption>none</encryption>
<useOneX>false</useOneX>
</authEncryption>
<HotspotProfile xmlns="http://www.microsoft.com/networking/WLAN/HotspotProfile/v1">
<ExtAuth>
<!-- Adjust the extension ID to match the package family name of the application running the background task handler. -->
<ExtensionId>Microsoft.SDKSamples.HotspotAuthentication.CS_8wekyb3d8bbwe</ExtensionId>
</ExtAuth>
</HotspotProfile>
</security>
</MSM>
</WLANProfile>
</WLANProfiles>
</CarrierProvisioning>
And then, we call ProvisionFromXmlDocumentAsync
to load xml info and create hotspot.
private async void ProvisionButton_Click(object sender, RoutedEventArgs e)
{
ProvisionButton.IsEnabled = false;
// Open the installation folder
var installLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;
// Access the provisioning file
var provisioningFile = await installLocation.GetFileAsync("ProvisioningData.xml");
// Load with XML parser
var xmlDocument = await XmlDocument.LoadFromFileAsync(provisioningFile);
// Get raw XML
var provisioningXml = xmlDocument.GetXml();
// Create ProvisiongAgent Object
var provisioningAgent = new ProvisioningAgent();
try
{
// Create ProvisionFromXmlDocumentResults Object
var result = await provisioningAgent.ProvisionFromXmlDocumentAsync(provisioningXml);
if (result.AllElementsProvisioned)
{
rootPage.NotifyUser("Provisioning was successful", NotifyType.StatusMessage);
}
else
{
rootPage.NotifyUser("Provisioning result: " + result.ProvisionResultsXml, NotifyType.ErrorMessage);
}
}
catch (System.Exception ex)
{
// See https://learn.microsoft.com/en-us/uwp/api/windows.networking.networkoperators.provisioningagent.provisionfromxmldocumentasync
// for list of possible exceptions.
rootPage.NotifyUser($"Unable to provision: {ex}", NotifyType.ErrorMessage);
}
ProvisionButton.IsEnabled = true;
}
Please note, if you want to use HotspotAuthentication
in the uwp application, you need add networkConnectionManagerProvisioning
before. And the ExtensionId
is the app's package family name.
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp rescap"
.......
<rescap:Capability Name="networkConnectionManagerProvisioning"/>