Skip to content

Commit b5340f8

Browse files
Steven WhiteSteven White
authored andcommitted
Merged PR 21075: Partially done; will complete it next
Partially done; will complete it next
1 parent 04f49ea commit b5340f8

14 files changed

Lines changed: 489 additions & 0 deletions
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
-api-id: M:Windows.Networking.NetworkOperators.NetworkOperatorTetheringManager.StartTetheringAsync(Windows.Networking.NetworkOperators.NetworkOperatorTetheringSessionAccessPointConfiguration)
3+
-api-type: winrt method
4+
---
5+
6+
# Windows.Networking.NetworkOperators.NetworkOperatorTetheringManager.StartTetheringAsync(Windows.Networking.NetworkOperators.NetworkOperatorTetheringSessionAccessPointConfiguration)
7+
8+
<!--
9+
public Windows.Foundation.IAsyncOperation<Windows.Networking.NetworkOperators.NetworkOperatorTetheringOperationResult> StartTetheringAsync (Windows.Networking.NetworkOperators.NetworkOperatorTetheringSessionAccessPointConfiguration configuration);
10+
-->
11+
12+
13+
## -description
14+
15+
Allows you to start a tethering session without having to pre-configure it via [ConfigureAccessPointAsync](./networkoperatortetheringmanager_configureaccesspointasync_1399951422.md). The configuration passed as a parameter is valid only for the current session, and will be lost once the session has ended.
16+
17+
Starting a new session via this overload of **StartTetheringAsync** also allows you to configure per-session-only parameters that can't be persistently set via **ConfigureAccessPointAsync**. Parameters that *can* be persisted are the network SSID, the network password, the network wireless frequency band, and the network authentication algorithm.
18+
19+
## -parameters
20+
21+
### -param configuration
22+
23+
## -returns
24+
25+
## -remarks
26+
27+
## -see-also
28+
29+
## -examples
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
---
2+
-api-id: T:Windows.Networking.NetworkOperators.NetworkOperatorTetheringSessionAccessPointConfiguration
3+
-api-type: winrt class
4+
---
5+
6+
# Windows.Networking.NetworkOperators.NetworkOperatorTetheringSessionAccessPointConfiguration
7+
8+
<!--
9+
public sealed class NetworkOperatorTetheringSessionAccessPointConfiguration
10+
-->
11+
12+
13+
## -description
14+
15+
Represents a per-session tethering configuration.
16+
17+
**NetworkOperatorTetheringSessionAccessPointConfiguration** contains the same fields and helper methods as [NetworkOperatorTetheringAccessPointConfiguration](./networkoperatortetheringaccesspointconfiguration.md) does, with several additions.
18+
19+
## -remarks
20+
21+
The purpose of this class is to specify the per-session tethering configuration when starting the tethering session via [StartTetheringAsync](./networkoperatortetheringmanager_starttetheringasync_1060696031.md). The additional members of this per-session-only class are typically values that aren't currently configurable by users via Windows **Settings**.
22+
23+
## -see-also
24+
25+
## -examples
26+
27+
```csharp
28+
using System;
29+
using System.Threading.Tasks;
30+
using Windows.Foundation.Metadata;
31+
using Windows.Networking.NetworkOperators;
32+
using Windows.Networking.Connectivity;
33+
34+
namespace TetheringApiDemoApp
35+
{
36+
static class TetheringApiDemoClass
37+
{
38+
// Sample desired per-session access point configuration values.
39+
private const string DesiredSsid = "DemoSsid";
40+
41+
private const string DesiredPassphrase = "DemoPassphrase";
42+
43+
private const TetheringWiFiBand DesiredBand =
44+
TetheringWiFiBand.SixGigahertz;
45+
46+
private const TetheringWiFiAuthenticationKind DesiredAuthenticationKind =
47+
TetheringWiFiAuthenticationKind.Wpa3;
48+
49+
private const TetheringWiFiPerformancePriority DesiredPerformancePriority =
50+
TetheringWiFiPerformancePriority.TetheringOverStation;
51+
52+
public static void VerifyPerSessionTetheringApiSupport()
53+
{
54+
if (!ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 17))
55+
{
56+
throw new InvalidOperationException(
57+
"This OS doesn't support per-session tethering configurations.");
58+
}
59+
}
60+
61+
public static NetworkOperatorTetheringManager GetTetheringManagerForCurrentConnection()
62+
{
63+
// Get the connection profile associated with the internet connection currently used by the local machine.
64+
ConnectionProfile currentConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
65+
66+
if (currentConnectionProfile == null)
67+
{
68+
throw new InvalidOperationException("Machine isn't connected to the internet.");
69+
}
70+
71+
TetheringCapability tetheringCapability =
72+
NetworkOperatorTetheringManager.GetTetheringCapabilityFromConnectionProfile(currentConnectionProfile);
73+
74+
if (tetheringCapability != TetheringCapability.Enabled)
75+
{
76+
throw new InvalidOperationException(
77+
$"Tethering is disabled on this machine. Reason code: {tetheringCapability}.");
78+
}
79+
80+
return NetworkOperatorTetheringManager.CreateFromConnectionProfile(currentConnectionProfile);
81+
}
82+
83+
public static async Task<NetworkOperatorTetheringSessionAccessPointConfiguration>
84+
SetUpSessionConfigurationAsync(NetworkOperatorTetheringManager tetheringManager)
85+
{
86+
NetworkOperatorTetheringSessionAccessPointConfiguration sessionConfiguration =
87+
new NetworkOperatorTetheringSessionAccessPointConfiguration();
88+
89+
sessionConfiguration.Ssid = DesiredSsid;
90+
sessionConfiguration.Passphrase = DesiredPassphrase;
91+
92+
if (await sessionConfiguration.IsBandSupportedAsync(DesiredBand))
93+
{
94+
sessionConfiguration.Band = DesiredBand;
95+
}
96+
else
97+
{
98+
throw new InvalidOperationException("Desired band isn't supported.");
99+
}
100+
101+
if (await sessionConfiguration.IsAuthenticationKindSupportedAsync(DesiredAuthenticationKind))
102+
{
103+
sessionConfiguration.AuthenticationKind = DesiredAuthenticationKind;
104+
}
105+
else
106+
{
107+
throw new InvalidOperationException("Desired authentication kind isn't supported.");
108+
}
109+
110+
sessionConfiguration.PerformancePriority = DesiredPerformancePriority;
111+
112+
return sessionConfiguration;
113+
}
114+
115+
public static async Task StartTetheringSessionAsync(
116+
NetworkOperatorTetheringManager tetheringManager,
117+
NetworkOperatorTetheringSessionAccessPointConfiguration sessionConfiguration)
118+
{
119+
TetheringOperationStatus operationResult =
120+
await tetheringManager.StartTetheringAsync(sessionConfiguration);
121+
122+
if (operationResult.Status == TetheringOperationStatus.Success)
123+
{
124+
Console.WriteLine("Tethering started successfully.");
125+
}
126+
else if (operationResult.Status == TetheringOperationStatus.AlreadyOn)
127+
{
128+
// Custom error message for AlreadyOn status.
129+
Console.WriteLine("Tethering is already on.");
130+
}
131+
else if (operationResult.Status == TetheringOperationStatus.RadioRestriction)
132+
{
133+
// Custom error message for RadioRestriction status.
134+
Console.WriteLine(
135+
"Can't start tethering at 6 GHz due to radio restrictions (2x2 + dual radio).");
136+
}
137+
else if (operationResult.Status == TetheringOperationStatus.BandInterference)
138+
{
139+
// Custom error message for BandInterference status.
140+
Console.WriteLine(
141+
"Can't start tethering at 6 GHz because a 5 GHz connection interferes.");
142+
}
143+
else
144+
{
145+
// Generic error message for all other statuses.
146+
Console.WriteLine(
147+
$"Failed to start tethering: {operationResult.AdditionalErrorMessage}.");
148+
}
149+
}
150+
151+
public static async Task Main()
152+
{
153+
try
154+
{
155+
VerifyPerSessionTetheringApiSupport();
156+
157+
NetworkOperatorTetheringManager tetheringManager = GetTetheringManagerForCurrentConnection();
158+
159+
NetworkOperatorTetheringSessionAccessPointConfiguration sessionConfiguration =
160+
await SetUpSessionConfigurationAsync(tetheringManager);
161+
162+
await StartTetheringSessionAsync(tetheringManager, sessionConfiguration);
163+
}
164+
catch (InvalidOperationException ex)
165+
{
166+
Console.WriteLine($"Failed to initialize tethering configuration: {ex.Message}.");
167+
}
168+
catch (Exception ex)
169+
{
170+
Console.WriteLine($"Unexpected error: {ex.Message}.");
171+
}
172+
}
173+
}
174+
}
175+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
-api-id: P:Windows.Networking.NetworkOperators.NetworkOperatorTetheringSessionAccessPointConfiguration.AuthenticationKind
3+
-api-type: winrt property
4+
---
5+
6+
# Windows.Networking.NetworkOperators.NetworkOperatorTetheringSessionAccessPointConfiguration.AuthenticationKind
7+
8+
<!--
9+
public Windows.Networking.NetworkOperators.TetheringWiFiAuthenticationKind AuthenticationKind { get; set; }
10+
-->
11+
12+
13+
## -description
14+
15+
## -property-value
16+
17+
## -remarks
18+
19+
## -see-also
20+
21+
## -examples
22+
23+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
-api-id: P:Windows.Networking.NetworkOperators.NetworkOperatorTetheringSessionAccessPointConfiguration.Band
3+
-api-type: winrt property
4+
---
5+
6+
# Windows.Networking.NetworkOperators.NetworkOperatorTetheringSessionAccessPointConfiguration.Band
7+
8+
<!--
9+
public Windows.Networking.NetworkOperators.TetheringWiFiBand Band { get; set; }
10+
-->
11+
12+
13+
## -description
14+
15+
## -property-value
16+
17+
## -remarks
18+
19+
## -see-also
20+
21+
## -examples
22+
23+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
-api-id: M:Windows.Networking.NetworkOperators.NetworkOperatorTetheringSessionAccessPointConfiguration.IsAuthenticationKindSupported(Windows.Networking.NetworkOperators.TetheringWiFiAuthenticationKind)
3+
-api-type: winrt method
4+
---
5+
6+
# Windows.Networking.NetworkOperators.NetworkOperatorTetheringSessionAccessPointConfiguration.IsAuthenticationKindSupported(Windows.Networking.NetworkOperators.TetheringWiFiAuthenticationKind)
7+
8+
<!--
9+
public bool IsAuthenticationKindSupported (Windows.Networking.NetworkOperators.TetheringWiFiAuthenticationKind authenticationKind);
10+
-->
11+
12+
13+
## -description
14+
15+
## -parameters
16+
17+
### -param authenticationKind
18+
19+
## -returns
20+
21+
## -remarks
22+
23+
## -see-also
24+
25+
## -examples
26+
27+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
-api-id: M:Windows.Networking.NetworkOperators.NetworkOperatorTetheringSessionAccessPointConfiguration.IsAuthenticationKindSupportedAsync(Windows.Networking.NetworkOperators.TetheringWiFiAuthenticationKind)
3+
-api-type: winrt method
4+
---
5+
6+
# Windows.Networking.NetworkOperators.NetworkOperatorTetheringSessionAccessPointConfiguration.IsAuthenticationKindSupportedAsync(Windows.Networking.NetworkOperators.TetheringWiFiAuthenticationKind)
7+
8+
<!--
9+
public Windows.Foundation.IAsyncOperation<bool> IsAuthenticationKindSupportedAsync (Windows.Networking.NetworkOperators.TetheringWiFiAuthenticationKind authenticationKind);
10+
-->
11+
12+
13+
## -description
14+
15+
## -parameters
16+
17+
### -param authenticationKind
18+
19+
## -returns
20+
21+
## -remarks
22+
23+
## -see-also
24+
25+
## -examples
26+
27+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
-api-id: M:Windows.Networking.NetworkOperators.NetworkOperatorTetheringSessionAccessPointConfiguration.IsBandSupported(Windows.Networking.NetworkOperators.TetheringWiFiBand)
3+
-api-type: winrt method
4+
---
5+
6+
# Windows.Networking.NetworkOperators.NetworkOperatorTetheringSessionAccessPointConfiguration.IsBandSupported(Windows.Networking.NetworkOperators.TetheringWiFiBand)
7+
8+
<!--
9+
public bool IsBandSupported (Windows.Networking.NetworkOperators.TetheringWiFiBand band);
10+
-->
11+
12+
13+
## -description
14+
15+
## -parameters
16+
17+
### -param band
18+
19+
## -returns
20+
21+
## -remarks
22+
23+
## -see-also
24+
25+
## -examples
26+
27+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
-api-id: M:Windows.Networking.NetworkOperators.NetworkOperatorTetheringSessionAccessPointConfiguration.IsBandSupportedAsync(Windows.Networking.NetworkOperators.TetheringWiFiBand)
3+
-api-type: winrt method
4+
---
5+
6+
# Windows.Networking.NetworkOperators.NetworkOperatorTetheringSessionAccessPointConfiguration.IsBandSupportedAsync(Windows.Networking.NetworkOperators.TetheringWiFiBand)
7+
8+
<!--
9+
public Windows.Foundation.IAsyncOperation<bool> IsBandSupportedAsync (Windows.Networking.NetworkOperators.TetheringWiFiBand band);
10+
-->
11+
12+
13+
## -description
14+
15+
## -parameters
16+
17+
### -param band
18+
19+
## -returns
20+
21+
## -remarks
22+
23+
## -see-also
24+
25+
## -examples
26+
27+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
-api-id: M:Windows.Networking.NetworkOperators.NetworkOperatorTetheringSessionAccessPointConfiguration.#ctor
3+
-api-type: winrt constructor
4+
---
5+
6+
# Windows.Networking.NetworkOperators.NetworkOperatorTetheringSessionAccessPointConfiguration.#ctor
7+
8+
<!--
9+
public NetworkOperatorTetheringSessionAccessPointConfiguration ();
10+
-->
11+
12+
13+
## -description
14+
15+
## -remarks
16+
17+
## -see-also
18+
19+
## -examples
20+
21+

0 commit comments

Comments
 (0)