-
Notifications
You must be signed in to change notification settings - Fork 1
/
WirelessAP.cs
109 lines (91 loc) · 3.72 KB
/
WirelessAP.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Net.NetworkInformation;
namespace WiFiAP
{
public static class WirelessAP
{
/// <summary>
/// Disable the Soft AP for next restart.
/// </summary>
public static void Disable()
{
WirelessAPConfiguration wapconf = GetConfiguration();
wapconf.Options = WirelessAPConfiguration.ConfigurationOptions.None;
wapconf.SaveConfiguration();
}
/// <summary>
/// Set-up the Wireless AP settings, enable and save
/// </summary>
/// <returns>True if already set-up</returns>
public static bool Setup()
{
string SoftApIP = "192.168.4.1";
NetworkInterface ni = GetInterface();
WirelessAPConfiguration wapconf = GetConfiguration();
// Check if already Enabled and return true
if (wapconf.Options == (WirelessAPConfiguration.ConfigurationOptions.Enable |
WirelessAPConfiguration.ConfigurationOptions.AutoStart) &&
ni.IPv4Address == SoftApIP )
{
//attempt to enable DHCP on AP
//ni.EnableDhcp();
//wapconf.Options = (WirelessAPConfiguration.ConfigurationOptions)10;
return true;
}
// Set up IP address for Soft AP
ni.EnableStaticIPv4(SoftApIP, "255.255.255.0", SoftApIP);
// Set Options for Network Interface
//
// Enable - Enable the Soft AP ( Disable to reduce power )
// AutoStart - Start Soft AP when system boots.
// HiddenSSID- Hide the SSID
//
wapconf.Options = WirelessAPConfiguration.ConfigurationOptions.AutoStart |
WirelessAPConfiguration.ConfigurationOptions.Enable;
// Set the SSID for Access Point. If not set will use default "nano_xxxxxx"
//wapconf.Ssid = "MySsid";
// Maximum number of simultaneous connections, reserves memory for connections
wapconf.MaxConnections = 3;
// To set-up Access point with no Authentication
wapconf.Authentication = AuthenticationType.Open;
wapconf.Password = "";
// To set up Access point with no Authentication. Password minimum 8 chars.
//wapconf.Authentication = AuthenticationType.WPA2;
//wapconf.Password = "password";
// Save the configuration so on restart Access point will be running.
wapconf.SaveConfiguration();
return false;
}
/// <summary>
/// Find the Wireless AP configuration
/// </summary>
/// <returns>Wireless AP configuration or NUll if not available</returns>
public static WirelessAPConfiguration GetConfiguration()
{
NetworkInterface ni = GetInterface();
return WirelessAPConfiguration.GetAllWirelessAPConfigurations()[ni.SpecificConfigId];
}
public static NetworkInterface GetInterface()
{
NetworkInterface[] Interfaces = NetworkInterface.GetAllNetworkInterfaces();
// Find WirelessAP interface
foreach (NetworkInterface ni in Interfaces)
{
if (ni.NetworkInterfaceType == NetworkInterfaceType.WirelessAP)
{
return ni;
}
}
return null;
}
/// <summary>
/// Returns the IP address of the Soft AP
/// </summary>
/// <returns>IP address</returns>
public static string GetIP()
{
NetworkInterface ni = GetInterface();
return ni.IPv4Address;
}
}
}