Hello ,
I'm using this code
https://www.hackster.io/rayburne/esp8266-mini-sniff-f6b93a
which is working ,
but now I want to make it "work" for me
and I'm trying to understand the function.h code
I want to do something like Friend Detector within this code
so when it found a known MAC - it will light a led (for example)
and I can't see to understand how to save the MAC of data I'm getting
what is the function that get ,and how do i save it
Does someone know?
this is the main code :
// by Ray Burnette 20161013 compiled on Linux 16.3 using Arduino 1.6.12
#include <ESP8266WiFi.h>
#include "functions.h"
#define disable 0
#define enable 1
// uint8_t channel = 1;
unsigned int channel = 1;
void setup() {
Serial.begin(57600);
Serial.printf("\n\nSDK version:%s\n\r", system_get_sdk_version());
Serial.println(F("ESP8266 mini-sniff by Ray Burnette http://www.hackster.io/rayburne/projects"));
Serial.println(F("Type: /-------MAC------/-----WiFi Access Point SSID-----/ /----MAC---/ Chnl RSSI"));
wifi_set_opmode(STATION_MODE); // Promiscuous works only with station mode
wifi_set_channel(channel);
wifi_promiscuous_enable(disable);
wifi_set_promiscuous_rx_cb(promisc_cb); // Set up promiscuous callback
wifi_promiscuous_enable(enable);
#define LIST_SIZE 3
uint8_t friendmac[LIST_SIZE][12] = {
{0x11, 0x11, 0x11, 0x11, 0x11, 0x11}
,{0x22, 0x22, 0x22, 0x22, 0x22, 0x22}
,{0xd0 , 0x11 , 0x56 , 0xb0 , 0xba , 0x9b}
};
String friendname[LIST_SIZE] = {
"Iphone 1 "
,"Friend 2"
, "Samsung A8"
};
}
void loop() {
channel = 1;
wifi_set_channel(channel);
while (true) {
nothing_new++; // Array is not finite, check bounds and adjust if required
if (nothing_new > 200) {
nothing_new = 0;
channel++;
if (channel == 15) break; // Only scan channels 1 to 14
wifi_set_channel(channel);
}
delay(1); // critical processing timeslice for NONOS SDK! No delay(0) yield()
// Press keyboard ENTER in console with NL active to repaint the screen
if ((Serial.available() > 0) && (Serial.read() == '\n')) {
Serial.println("\n-------------------------------------------------------------------------------------\n");
for (int u = 0; u < clients_known_count; u++) print_client(clients_known[u]);
for (int u = 0; u < aps_known_count; u++) print_beacon(aps_known[u]);
Serial.println("\n-------------------------------------------------------------------------------------\n");
}
}
}
this is the function.h
// This-->tab == "functions.h"
// Expose Espressif SDK functionality
extern "C" {
#include "user_interface.h"clients_known
typedef void (*freedom_outside_cb_t)(uint8 status);
int wifi_register_send_pkt_freedom_cb(freedom_outside_cb_t cb);
void wifi_unregister_send_pkt_freedom_cb(void);
int wifi_send_pkt_freedom(uint8 *buf, int len, bool sys_seq);
}
#include <ESP8266WiFi.h>
#include "./structures.h"
#define MAX_APS_TRACKED 100
#define MAX_CLIENTS_TRACKED 200
beaconinfo aps_known[MAX_APS_TRACKED]; // Array to save MACs of known APs
int aps_known_count = 0; // Number of known APs
int nothing_new = 0;
clientinfo clients_known[MAX_CLIENTS_TRACKED]; // Array to save MACs of known CLIENTs
int clients_known_count = 0; // Number of known CLIENTs
int register_beacon(beaconinfo beacon)
{
int known = 0; // Clear known flag
for (int u = 0; u < aps_known_count; u++)
{
if (! memcmp(aps_known[u].bssid, beacon.bssid, ETH_MAC_LEN)) {
known = 1;
break;
} // AP known => Set known flag
}
if (! known) // AP is NEW, copy MAC to array and return it
{
memcpy(&aps_known[aps_known_count], &beacon, sizeof(beacon));
aps_known_count++;
if ((unsigned int) aps_known_count >=
sizeof (aps_known) / sizeof (aps_known[0]) ) {
Serial.printf("exceeded max aps_known\n");
aps_known_count = 0;
}
}
return known;
}
int register_client(clientinfo ci)
{
int known = 0; // Clear known flag
for (int u = 0; u < clients_known_count; u++)
{
if (! memcmp(clients_known[u].station, ci.station, ETH_MAC_LEN)) {
known = 1;
break;
}
}
if (! known)
{
memcpy(&clients_known[clients_known_count], &ci, sizeof(ci));
clients_known_count++;
if ((unsigned int) clients_known_count >=
sizeof (clients_known) / sizeof (clients_known[0]) ) {
Serial.printf("exceeded max clients_known\n");
clients_known_count = 0;
}
}
return known;
}
void print_beacon(beaconinfo beacon)
{
if (beacon.err != 0) {
//Serial.printf("BEACON ERR: (%d) ", beacon.err);
} else {
Serial.printf("BEACON: <=============== [%32s] ", beacon.ssid);
for (int i = 0; i < 6; i++) Serial.printf("%02x", beacon.bssid[i]);
Serial.printf(" %2d", beacon.channel);
Serial.printf(" %4d\r\n", beacon.rssi);
}
}
void print_client(clientinfo ci)
{
int u = 0;
int known = 0; // Clear known flag
if (ci.err != 0) {
// nothing
} else {
Serial.printf("DEVICE: ");
for (int i = 0; i < 6; i++) Serial.printf("%02x", ci.station[i]);
Serial.printf(" ==> ");
for (u = 0; u < aps_known_count; u++)
{
if (! memcmp(aps_known[u].bssid, ci.bssid, ETH_MAC_LEN)) {
Serial.printf("[%32s]", aps_known[u].ssid);
known = 1; // AP known => Set known flag
break;
}
}
if (! known) {
Serial.printf(" Unknown/Malformed packet \r\n");
// for (int i = 0; i < 6; i++) Serial.printf("%02x", ci.bssid[i]);
} else {
Serial.printf("%2s", " ");
for (int i = 0; i < 6; i++) Serial.printf("%02x", ci.ap[i]);
Serial.printf(" %3d", aps_known[u].channel);
Serial.printf(" %4d\r\n", ci.rssi);
}
}
}
void promisc_cb(uint8_t *buf, uint16_t len)
{
int i = 0;
uint16_t seq_n_new = 0;
if (len == 12) {
struct RxControl *sniffer = (struct RxControl*) buf;
} else if (len == 128) {
struct sniffer_buf2 *sniffer = (struct sniffer_buf2*) buf;
struct beaconinfo beacon = parse_beacon(sniffer->buf, 112, sniffer->rx_ctrl.rssi);
if (register_beacon(beacon) == 0) {
print_beacon(beacon);
nothing_new = 0;
}
} else {
struct sniffer_buf *sniffer = (struct sniffer_buf*) buf;
//Is data or QOS?
if ((sniffer->buf[0] == 0x08) || (sniffer->buf[0] == 0x88)) {
struct clientinfo ci = parse_data(sniffer->buf, 36, sniffer->rx_ctrl.rssi, sniffer->rx_ctrl.channel);
if (memcmp(ci.bssid, ci.station, ETH_MAC_LEN)) {
if (register_client(ci) == 0) {
print_client(ci);
nothing_new = 0;
}
}
}
}
}
I have tried to use this line :
clients_known[u].station
but it doesn't work
Thanks ,