Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
WifiSniffer.h
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/anakod/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * WifiSniffer.h
8  *
9  * Original code by Ray Burnette http://www.hackster.io/rayburne/projects
10  *
11  * Adapted for use with Sming March 2019 mikee47 <mike@sillyhouse.net>
12  *
13  * See ESP8266 non-OS SDK Version 3.0, section 3.11: Sniffer Related APIs
14  *
15  ****/
16 
17 #ifndef _SMING_CORE_WIFI_SNIFFER_H_
18 #define _SMING_CORE_WIFI_SNIFFER_H_
19 
20 #include "System.h"
21 #include "WVector.h"
22 
23 #define ETH_MAC_LEN 6
24 
28 struct BeaconInfo {
29  uint8_t bssid[ETH_MAC_LEN];
30  uint8_t ssid[33];
31  uint8_t ssid_len;
32  uint8_t channel;
33  int8_t err;
34  int8_t rssi;
35  uint8_t capa[2];
36 };
37 
41 struct ClientInfo {
42  uint8_t bssid[ETH_MAC_LEN];
43  uint8_t station[ETH_MAC_LEN];
44  uint8_t ap[ETH_MAC_LEN];
45  uint8_t channel;
46  int8_t err;
47  int8_t rssi;
48  uint16_t seq_n;
49 };
50 
54 class BeaconInfoList : public Vector<BeaconInfo>
55 {
56 public:
57  int indexOf(const uint8_t bssid[])
58  {
59  for(unsigned i = 0; i < count(); ++i) {
60  if(memcmp(elementAt(i).bssid, bssid, ETH_MAC_LEN) == 0) {
61  return i;
62  }
63  }
64 
65  return -1;
66  }
67 };
68 
72 class ClientInfoList : public Vector<ClientInfo>
73 {
74 public:
75  int indexOf(const uint8_t station[])
76  {
77  for(unsigned i = 0; i < count(); ++i) {
78  if(memcmp(elementAt(i).station, station, ETH_MAC_LEN) == 0) {
79  return i;
80  }
81  }
82 
83  return -1;
84  }
85 };
86 
87 typedef std::function<void(uint8_t* data, uint16_t length)> WifiSnifferCallback;
88 typedef std::function<void(const BeaconInfo& beacon)> WifiBeaconCallback;
89 typedef std::function<void(const ClientInfo& client)> WifiClientCallback;
90 
92 {
93 public:
95  void begin();
96 
98  void end();
99 
101  void onBeacon(WifiBeaconCallback callback)
102  {
103  beaconCallback = callback;
104  }
105 
107  void onClient(WifiClientCallback callback)
108  {
109  clientCallback = callback;
110  }
111 
115  void onSniff(WifiSnifferCallback callback)
116  {
117  snifferCallback = callback;
118  }
119 
123  void setChannel(unsigned channel)
124  {
125  wifi_set_channel(channel);
126  }
127 
129  unsigned getChannel()
130  {
131  return wifi_get_channel();
132  }
133 
134 private:
136  void onSystemReady() override;
137 
139  static void parseData(uint8_t* buf, uint16_t len);
140 
141  static WifiSnifferCallback snifferCallback;
142  static WifiBeaconCallback beaconCallback;
143  static WifiClientCallback clientCallback;
144 };
145 
146 #endif /* _SMING_CORE_WIFI_SNIFFER_H_ */
For applications to use to manage list of unique clients.
Definition: WifiSniffer.h:72
Decoded Wifi beacon (Access Point) information.
Definition: WifiSniffer.h:28
Definition: WifiSniffer.h:91
Definition: WVector.h:26
unsigned getChannel()
Get the current channel being listened on.
Definition: WifiSniffer.h:129
void onSniff(WifiSnifferCallback callback)
Register notification for all incoming data.
Definition: WifiSniffer.h:115
Decoded Wifi client information.
Definition: WifiSniffer.h:41
For applications to use to manage list of unique beacons.
Definition: WifiSniffer.h:54
void onBeacon(WifiBeaconCallback callback)
Register notification for beacon (AP) info.
Definition: WifiSniffer.h:101
void setChannel(unsigned channel)
Set the channel to listen on.
Definition: WifiSniffer.h:123
Definition: System.h:47
void onClient(WifiClientCallback callback)
Register notification for client info.
Definition: WifiSniffer.h:107