WifiEvents.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * WifiEvents.h
8  *
9  * Created on: 19 ????. 2016 ?.
10  * Author: shurik
11  *
12  ****/
13 
14 #pragma once
15 
16 #include <WString.h>
17 #include <IpAddress.h>
18 #include <MacAddress.h>
19 #include <Delegate.h>
20 #include "BssInfo.h"
21 
44 #define WIFI_DISCONNECT_REASON_CODES_MAP(XX) \
45  XX(UNSPECIFIED, 1, "Unspecified") \
46  XX(AUTH_EXPIRE, 2, "AUTH expired") \
47  XX(AUTH_LEAVE, 3, "Sending STA is leaving, or has left") \
48  XX(ASSOC_EXPIRE, 4, "Disassociated: inactivity") \
49  XX(ASSOC_TOOMANY, 5, "Disassociated: too many clients)") \
50  XX(NOT_AUTHED, 6, "Class 2 frame received from non-authenticated STA") \
51  XX(NOT_ASSOCED, 7, "Class 3 frame received from non-authenticated STA") \
52  XX(ASSOC_LEAVE, 8, "Disassociated: STA is leaving, or has left") \
53  XX(ASSOC_NOT_AUTHED, 9, "Disassociated: STA not authenticated") \
54  XX(DISASSOC_PWRCAP_BAD, 10, "Disassociated: power capability unacceptable") \
55  XX(DISASSOC_SUPCHAN_BAD, 11, "Disassociated: supported channels unacceptable") \
56  XX(IE_INVALID, 13, "Invalid IE") \
57  XX(MIC_FAILURE, 14, "Message Integrity failure") \
58  XX(4WAY_HANDSHAKE_TIMEOUT, 15, "4-way Handshake timeout") \
59  XX(GROUP_KEY_UPDATE_TIMEOUT, 16, "Group Key Handshake timeout") \
60  XX(IE_IN_4WAY_DIFFERS, 17, "4-way Handshake Information Differs") \
61  XX(GROUP_CIPHER_INVALID, 18, "Invalid group cypher") \
62  XX(PAIRWISE_CIPHER_INVALID, 19, "Invalid pairwise cypher") \
63  XX(AKMP_INVALID, 20, "Invalid AKMP") \
64  XX(UNSUPP_RSN_IE_VERSION, 21, "Unsupported RSN IE Version") \
65  XX(INVALID_RSN_IE_CAP, 22, "Invalid RSN IE capabilities") \
66  XX(802_1X_AUTH_FAILED, 23, "IEEE 802.1X authentication failed") \
67  XX(CIPHER_SUITE_REJECTED, 24, "Cipher suite rejected (security policy)") \
68  XX(BEACON_TIMEOUT, 200, "Beacon Timeout") \
69  XX(NO_AP_FOUND, 201, "No AP found") \
70  XX(AUTH_FAIL, 202, "Authentication failure") \
71  XX(ASSOC_FAIL, 203, "Association failure") \
72  XX(HANDSHAKE_TIMEOUT, 204, "Handshake timeout") \
73  XX(CONNECTION_FAIL, 205, "Connection failure")
74 
80 #define XX(tag, code, desc) WIFI_DISCONNECT_REASON_##tag = code,
82 #undef XX
83 };
84 
94 
109 
118 
131 
139 
147 
156 
160 {
161 public:
165  void onStationConnect(StationConnectDelegate delegateFunction)
166  {
167  onSTAConnect = delegateFunction;
168  }
169 
173  void onStationDisconnect(StationDisconnectDelegate delegateFunction)
174  {
175  onSTADisconnect = delegateFunction;
176  }
177 
182 
187 
191  void onStationAuthModeChange(StationAuthModeChangeDelegate delegateFunction)
192  {
193  onSTAAuthModeChange = delegateFunction;
194  }
195 
199  void onStationGotIP(StationGotIPDelegate delegateFunction)
200  {
201  onSTAGotIP = delegateFunction;
202  }
203 
207  void onAccessPointConnect(AccessPointConnectDelegate delegateFunction)
208  {
209  onSOFTAPConnect = delegateFunction;
210  }
211 
215  void onAccessPointDisconnect(AccessPointDisconnectDelegate delegateFunction)
216  {
217  onSOFTAPDisconnect = delegateFunction;
218  }
219 
223  void onAccessPointProbeReqRecved(AccessPointProbeReqRecvedDelegate delegateFunction)
224  {
225  onSOFTAPProbeReqRecved = delegateFunction;
226  }
227 
228 protected:
229  StationConnectDelegate onSTAConnect = nullptr;
230  StationDisconnectDelegate onSTADisconnect = nullptr;
231  StationAuthModeChangeDelegate onSTAAuthModeChange = nullptr;
232  StationGotIPDelegate onSTAGotIP = nullptr;
233  AccessPointConnectDelegate onSOFTAPConnect = nullptr;
234  AccessPointDisconnectDelegate onSOFTAPDisconnect = nullptr;
235  AccessPointProbeReqRecvedDelegate onSOFTAPProbeReqRecved = nullptr;
236 };
237 
242 
void onStationAuthModeChange(StationAuthModeChangeDelegate delegateFunction)
Set callback for &#39;station authorisation mode change&#39; event.
Definition: WifiEvents.h:191
#define WIFI_DISCONNECT_REASON_CODES_MAP(XX)
Common set of reason codes to IEEE 802.11-2007.
Definition: WifiEvents.h:44
StationGotIPDelegate onSTAGotIP
Definition: WifiEvents.h:232
Delegate< void(const String &ssid, MacAddress bssid, uint8_t channel)> StationConnectDelegate
Delegate type for &#39;station connected&#39; event.
Definition: WifiEvents.h:93
Delegate< void(MacAddress mac, uint16_t aid)> AccessPointConnectDelegate
Delegate type for &#39;Access Point Connect&#39; event.
Definition: WifiEvents.h:138
Delegate< void(const String &ssid, MacAddress bssid, WifiDisconnectReason reason)> StationDisconnectDelegate
Delegate type for &#39;station disconnected&#39; event.
Definition: WifiEvents.h:108
StationConnectDelegate onSTAConnect
Definition: WifiEvents.h:229
WiFi events class.
Definition: WifiEvents.h:159
Delegate< void(int rssi, MacAddress mac)> AccessPointProbeReqRecvedDelegate
Delegate type for &#39;Access Point Probe Request Received&#39; event.
Definition: WifiEvents.h:155
void onStationConnect(StationConnectDelegate delegateFunction)
Set callback for &#39;station connected&#39; event.
Definition: WifiEvents.h:165
void onAccessPointProbeReqRecved(AccessPointProbeReqRecvedDelegate delegateFunction)
Set callback for &#39;access point probe request received&#39; event.
Definition: WifiEvents.h:223
WifiDisconnectReason
Reason codes for WiFi station disconnection.
Definition: WifiEvents.h:79
The String class.
Definition: WString.h:136
Delegate< void(WifiAuthMode oldMode, WifiAuthMode newMode)> StationAuthModeChangeDelegate
Delegate type for &#39;station authorisation mode changed&#39; event.
Definition: WifiEvents.h:117
#define XX(tag, code, desc)
Definition: WifiEvents.h:80
Delegate< void(MacAddress mac, uint16_t aid)> AccessPointDisconnectDelegate
Delegate type for &#39;Access Point Disconnect&#39; event.
Definition: WifiEvents.h:146
void onAccessPointConnect(AccessPointConnectDelegate delegateFunction)
Set callback for &#39;access point client connected&#39; event.
Definition: WifiEvents.h:207
AccessPointProbeReqRecvedDelegate onSOFTAPProbeReqRecved
Definition: WifiEvents.h:235
WifiEventsClass & WifiEvents
Global reference to architecture-specific implementation.
AccessPointConnectDelegate onSOFTAPConnect
Definition: WifiEvents.h:233
static String getDisconnectReasonName(WifiDisconnectReason reason)
Get short name for disconnection reason.
StationDisconnectDelegate onSTADisconnect
Definition: WifiEvents.h:230
AccessPointDisconnectDelegate onSOFTAPDisconnect
Definition: WifiEvents.h:234
void onAccessPointDisconnect(AccessPointDisconnectDelegate delegateFunction)
Set callback for &#39;access point client disconnected&#39; event.
Definition: WifiEvents.h:215
void onStationDisconnect(StationDisconnectDelegate delegateFunction)
Set callback for &#39;station disconnected&#39; event.
Definition: WifiEvents.h:173
void onStationGotIP(StationGotIPDelegate delegateFunction)
Set callback for &#39;station connected with IP address&#39; event.
Definition: WifiEvents.h:199
static String getDisconnectReasonDesc(WifiDisconnectReason reason)
Get descriptive explanation for disconnect reason.
Delegate< void(IpAddress ip, IpAddress netmask, IpAddress gateway)> StationGotIPDelegate
Delegate type for &#39;station got IP address&#39; event.
Definition: WifiEvents.h:130
StationAuthModeChangeDelegate onSTAAuthModeChange
Definition: WifiEvents.h:231