Skip to content

Commit 6074941

Browse files
AdrianSoundyjosesimoes
authored andcommitted
Add Soft Access Point configuration for ESP32 (#91)
1 parent 14b7b56 commit 6074941

File tree

11 files changed

+599
-128
lines changed

11 files changed

+599
-128
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// Copyright (c) 2019 The nanoFramework project contributors
3+
// See LICENSE file in the project root for full license information.
4+
5+
namespace System.Net.NetworkInformation
6+
{
7+
/// <summary>
8+
/// Specifies the authentication used in a wireless network.
9+
/// </summary>
10+
public enum AuthenticationType : byte
11+
{
12+
/// <summary>
13+
/// No protocol.
14+
/// </summary>
15+
None = 0,
16+
17+
/// <summary>
18+
/// Extensible Authentication Protocol.
19+
/// </summary>
20+
EAP,
21+
22+
/// <summary>
23+
/// Protected Extensible Authentication Protocol.
24+
/// </summary>
25+
PEAP,
26+
27+
/// <summary>
28+
/// Microsoft Windows Connect Now protocol.
29+
/// </summary>
30+
WCN,
31+
32+
/// <summary>
33+
/// Open System authentication, for use with WEP encryption type.
34+
/// </summary>
35+
Open,
36+
37+
/// <summary>
38+
/// Shared Key authentication, for use with WEP encryption type.
39+
/// </summary>
40+
Shared,
41+
42+
/// <summary>
43+
/// Wired Equivalent Privacy protocol.
44+
/// </summary>
45+
WEP,
46+
47+
/// <summary>
48+
/// Wi-Fi Protected Access protocol.
49+
/// </summary>
50+
WPA,
51+
52+
/// <summary>
53+
/// Wi-Fi Protected Access 2 protocol.
54+
/// </summary>
55+
WPA2,
56+
}
57+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// Copyright (c) 2019 The nanoFramework project contributors
3+
// See LICENSE file in the project root for full license information.
4+
5+
namespace System.Net.NetworkInformation
6+
{
7+
/// <summary>
8+
/// Defines the available types of encryption for wireless networks.
9+
/// </summary>
10+
public enum EncryptionType : byte
11+
{
12+
/// <summary>
13+
/// No encryption.
14+
/// </summary>
15+
None = 0,
16+
17+
/// <summary>
18+
/// Wired Equivalent Privacy encryption.
19+
/// </summary>
20+
WEP,
21+
22+
/// <summary>
23+
/// Wireless Protected Access encryption.
24+
/// </summary>
25+
WPA,
26+
27+
/// <summary>
28+
/// Wireless Protected Access 2 encryption.
29+
/// </summary>
30+
WPA2,
31+
32+
/// <summary>
33+
/// Wireless Protected Access Pre-Shared Key encryption.
34+
/// </summary>
35+
WPA_PSK,
36+
37+
/// <summary>
38+
/// Wireless Protected Access 2 Pre-Shared Key encryption.
39+
/// </summary>
40+
WPA2_PSK,
41+
42+
/// <summary>
43+
/// Certificate encryption.
44+
/// </summary>
45+
Certificate,
46+
}
47+
}

source/nanoFramework.System.Net/NetworkInformation/NetworkChange.cs

Lines changed: 86 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ namespace System.Net.NetworkInformation
1313
/// </summary>
1414
public class NetworkAvailabilityEventArgs : EventArgs
1515
{
16-
private bool _isAvailable;
16+
#pragma warning disable IDE0032 // nanoFramework doesn't support auto-properties
17+
private readonly bool _isAvailable;
18+
#pragma warning disable IDE0032 // nanoFramework doesn't support auto-properties
1719

1820
internal NetworkAvailabilityEventArgs(bool isAvailable)
1921
{
@@ -23,28 +25,55 @@ internal NetworkAvailabilityEventArgs(bool isAvailable)
2325
/// <summary>
2426
/// Indicates whether the network is currently available.
2527
/// </summary>
26-
public bool IsAvailable
28+
public bool IsAvailable => _isAvailable;
29+
}
30+
31+
/// <summary>
32+
/// Contains argument values for network availability events.
33+
/// </summary>
34+
public class NetworkAPStationEventArgs : EventArgs
35+
{
36+
private readonly int _stationIndex;
37+
private readonly bool _isConnected;
38+
39+
internal NetworkAPStationEventArgs(bool isConnected, int StationIndex)
2740
{
28-
get
29-
{
30-
return _isAvailable;
31-
}
41+
_isConnected = isConnected;
42+
_stationIndex = StationIndex;
3243
}
44+
45+
/// <summary>
46+
/// Indicates whether the client has connected or disconnected.
47+
/// </summary>
48+
public bool IsConnected { get => _isConnected; }
49+
50+
/// <summary>
51+
/// Returns the Index of the connected Station.
52+
/// </summary>
53+
public int StationIndex { get => _stationIndex; }
3354
}
3455

56+
3557
/// <summary>
3658
/// Provides an event handler that is called when the network address changes.
3759
/// </summary>
3860
/// <param name="sender">Specifies the object that sent the network address changed event. </param>
3961
/// <param name="e">Contains the network address changed event arguments. </param>
40-
public delegate void NetworkAvailabilityChangedEventHandler(Object sender, NetworkAvailabilityEventArgs e);
62+
public delegate void NetworkAvailabilityChangedEventHandler(object sender, NetworkAvailabilityEventArgs e);
4163

4264
/// <summary>
4365
/// Indicates a change in the availability of the network.
4466
/// </summary>
4567
/// <param name="sender">Specifies the object that sent the network availability changed event. </param>
4668
/// <param name="e">Contains the network availability changed event arguments. </param>
47-
public delegate void NetworkAddressChangedEventHandler(Object sender, EventArgs e);
69+
public delegate void NetworkAddressChangedEventHandler(object sender, EventArgs e);
70+
71+
/// <summary>
72+
/// Indicates a change in the connected clients to Access Point.
73+
/// </summary>
74+
/// <param name="NetworkIndex">Specifies the index of network interface that sent the event. </param>
75+
/// <param name="e">Contains the network AP client changed event arguments. </param>
76+
public delegate void NetworkAPStationChangedEventHandler(int NetworkIndex, NetworkAPStationEventArgs e);
4877

4978
/// <summary>
5079
/// Contains information about changes in the availability and address of the network.
@@ -57,10 +86,11 @@ internal enum NetworkEventType : byte
5786
Invalid = 0,
5887
AvailabilityChanged = 1,
5988
AddressChanged = 2,
89+
APStationChanged = 3,
6090
}
6191

6292
[Flags]
63-
internal enum NetworkEventFlags : byte
93+
internal enum NetworkEvents : byte
6494
{
6595
NetworkAvailable = 0x1,
6696
}
@@ -69,30 +99,38 @@ internal class NetworkEvent : BaseEvent
6999
{
70100
public NetworkEventType EventType;
71101
public byte Flags;
102+
public ushort Index;
103+
public ushort Data;
72104
public DateTime Time;
73105
}
74106

75107
internal class NetworkChangeListener : IEventListener, IEventProcessor
76108
{
77109
public void InitializeForEventSource()
78110
{
111+
// Method intentionally left empty.
79112
}
80113

81114
public BaseEvent ProcessEvent(uint data1, uint data2, DateTime time)
82115
{
83116
NetworkEvent networkEvent = new NetworkEvent();
84117
networkEvent.EventType = (NetworkEventType)(data1 & 0xFF);
85118
networkEvent.Flags = (byte)((data1 >> 16) & 0xFF);
119+
120+
// Data2 - Low 8 bits are the Network interface index
121+
// Top 8 bits extra data ( i.e AP station index )
122+
networkEvent.Index = (ushort)(data2 & 0xff);
123+
networkEvent.Data = (ushort)(data2 >> 8);
86124
networkEvent.Time = time;
87125

88126
return networkEvent;
89127
}
90128

91129
public bool OnEvent(BaseEvent ev)
92130
{
93-
if (ev is NetworkEvent)
131+
if (ev is NetworkEvent myEvent)
94132
{
95-
NetworkChange.OnNetworkChangeCallback((NetworkEvent)ev);
133+
OnNetworkChangeCallback(myEvent);
96134
}
97135

98136
return true;
@@ -123,6 +161,18 @@ public bool OnEvent(BaseEvent ev)
123161
/// </remarks>
124162
public static event NetworkAvailabilityChangedEventHandler NetworkAvailabilityChanged;
125163

164+
/// <summary>
165+
/// Event occurs when a station connects or disconnects from Soft Access Point.
166+
/// </summary>
167+
/// <remarks>
168+
/// The NetworkChange class raises the NetworkAPStationChanged events when a client
169+
/// connects or disconnects from the Soft AP.
170+
///
171+
/// To have a NetworkChange object call an event-handling method when a NetworkAPStationChanged event occurs,
172+
/// you must associate the method with a NetworkAPStationChangedEventHandler delegate, and add this delegate to this event.
173+
/// </remarks>
174+
public static event NetworkAPStationChangedEventHandler NetworkAPStationChanged;
175+
126176
static NetworkChange()
127177
{
128178
NetworkChangeListener networkChangeListener = new NetworkChangeListener();
@@ -134,33 +184,41 @@ static NetworkChange()
134184

135185
internal static void OnNetworkChangeCallback(NetworkEvent networkEvent)
136186
{
187+
137188
switch (networkEvent.EventType)
138189
{
139190
case NetworkEventType.AvailabilityChanged:
191+
if (NetworkAvailabilityChanged != null)
140192
{
141-
if (NetworkAvailabilityChanged != null)
142-
{
143-
bool isAvailable = ((networkEvent.Flags & (byte)NetworkEventFlags.NetworkAvailable) != 0);
144-
NetworkAvailabilityEventArgs args = new NetworkAvailabilityEventArgs(isAvailable);
145-
146-
NetworkAvailabilityChanged(null, args);
147-
}
148-
break;
193+
bool isAvailable = ((networkEvent.Flags & (byte)NetworkEvents.NetworkAvailable) != 0);
194+
NetworkAvailabilityEventArgs args = new NetworkAvailabilityEventArgs(isAvailable);
195+
196+
NetworkAvailabilityChanged(networkEvent.Index, args);
149197
}
198+
break;
199+
150200
case NetworkEventType.AddressChanged:
201+
if (NetworkAddressChanged != null)
151202
{
152-
if (NetworkAddressChanged != null)
153-
{
154-
EventArgs args = new EventArgs();
155-
NetworkAddressChanged(null, args);
156-
}
157-
158-
break;
203+
EventArgs args = new EventArgs();
204+
NetworkAddressChanged(networkEvent.Index, args);
159205
}
160-
default:
206+
207+
break;
208+
209+
case NetworkEventType.APStationChanged:
210+
if (NetworkAPStationChanged != null)
161211
{
162-
break;
212+
bool isConnected = ((networkEvent.Flags & (byte)NetworkEvents.NetworkAvailable) != 0);
213+
214+
NetworkAPStationEventArgs args = new NetworkAPStationEventArgs(isConnected, networkEvent.Data);
215+
216+
NetworkAPStationChanged(networkEvent.Index, args);
163217
}
218+
break;
219+
220+
default:
221+
break;
164222
}
165223
}
166224
}

source/nanoFramework.System.Net/NetworkInformation/NetworkInterfaceType.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,11 @@ public enum NetworkInterfaceType
3232
/// The network interface uses a wireless LAN connection (IEEE 802.11 standard).
3333
/// </summary>
3434
Wireless80211 = 71,
35+
36+
/// <summary>
37+
/// The network interface uses a wireless Soft AP connection (IEEE 802.11 standard).
38+
/// </summary>
39+
WirelessAP = 72,
40+
3541
}
3642
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// Copyright (c) 2019 The nanoFramework project contributors
3+
// See LICENSE file in the project root for full license information.
4+
5+
namespace System.Net.NetworkInformation
6+
{
7+
/// <summary>
8+
/// Specifies the type of radio that the wireless network uses.
9+
/// </summary>
10+
public enum RadioType : byte
11+
{
12+
/// <summary>
13+
/// Not specified.
14+
/// </summary>
15+
NotSpecified = 0,
16+
17+
/// <summary>
18+
/// 802.11a-compatible radio.
19+
/// </summary>
20+
_802_11a = 1,
21+
22+
/// <summary>
23+
/// 802.11b-compatible radio.
24+
/// </summary>
25+
_802_11b = 2,
26+
27+
/// <summary>
28+
/// 802.11g-compatible radio.
29+
/// </summary>
30+
_802_11g = 4,
31+
32+
/// <summary>
33+
/// 802.11n-compatible radio.
34+
/// </summary>
35+
_802_11n = 8,
36+
}
37+
}

0 commit comments

Comments
 (0)