commit
f1b7e10f85
12
build.py
12
build.py
@ -29,7 +29,7 @@ haldir = os.path.join (srcdir, "hal")
|
|||||||
halconfig = config.get("board", "halfile")
|
halconfig = config.get("board", "halfile")
|
||||||
halconfigfile = os.path.join (haldir, halconfig)
|
halconfigfile = os.path.join (haldir, halconfig)
|
||||||
if os.path.isfile(halconfigfile) and os.access(halconfigfile, os.R_OK):
|
if os.path.isfile(halconfigfile) and os.access(halconfigfile, os.R_OK):
|
||||||
print "Parsing hardware configuration from " + halconfigfile
|
print("Parsing hardware configuration from " + halconfigfile)
|
||||||
else:
|
else:
|
||||||
sys.exit("Missing file " + halconfigfile + ", please create it! Aborting.")
|
sys.exit("Missing file " + halconfigfile + ", please create it! Aborting.")
|
||||||
|
|
||||||
@ -37,21 +37,21 @@ else:
|
|||||||
lmicconfig = config.get("common", "lmicconfigfile")
|
lmicconfig = config.get("common", "lmicconfigfile")
|
||||||
lmicconfigfile = os.path.join (srcdir, lmicconfig)
|
lmicconfigfile = os.path.join (srcdir, lmicconfig)
|
||||||
if os.path.isfile(lmicconfigfile) and os.access(lmicconfigfile, os.R_OK):
|
if os.path.isfile(lmicconfigfile) and os.access(lmicconfigfile, os.R_OK):
|
||||||
print "Parsing LMIC configuration from " + lmicconfigfile
|
print("Parsing LMIC configuration from " + lmicconfigfile)
|
||||||
else:
|
else:
|
||||||
sys.exit("Missing file " + lmicconfigfile + ", please create it! Aborting.")
|
sys.exit("Missing file " + lmicconfigfile + ", please create it! Aborting.")
|
||||||
|
|
||||||
# check if lora key file is present in source directory
|
# check if lora key file is present in source directory
|
||||||
lorakeyfile = os.path.join (srcdir, config.get("common", "lorakeyfile"))
|
lorakeyfile = os.path.join (srcdir, config.get("common", "lorakeyfile"))
|
||||||
if os.path.isfile(lorakeyfile) and os.access(lorakeyfile, os.R_OK):
|
if os.path.isfile(lorakeyfile) and os.access(lorakeyfile, os.R_OK):
|
||||||
print "Parsing LORAWAN keys from " + lorakeyfile
|
print("Parsing LORAWAN keys from " + lorakeyfile)
|
||||||
else:
|
else:
|
||||||
sys.exit("Missing file " + lorakeyfile + ", please create it! Aborting.")
|
sys.exit("Missing file " + lorakeyfile + ", please create it! Aborting.")
|
||||||
|
|
||||||
# check if ota key file is present in source directory
|
# check if ota key file is present in source directory
|
||||||
otakeyfile = os.path.join (srcdir, config.get("common", "otakeyfile"))
|
otakeyfile = os.path.join (srcdir, config.get("common", "otakeyfile"))
|
||||||
if os.path.isfile(otakeyfile) and os.access(otakeyfile, os.R_OK):
|
if os.path.isfile(otakeyfile) and os.access(otakeyfile, os.R_OK):
|
||||||
print "Parsing OTA keys from " + otakeyfile
|
print("Parsing OTA keys from " + otakeyfile)
|
||||||
else:
|
else:
|
||||||
sys.exit("Missing file " + otakeyfile + ", please create it! Aborting.")
|
sys.exit("Missing file " + otakeyfile + ", please create it! Aborting.")
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ myboard = mykeys["board"]
|
|||||||
myuploadspeed = mykeys["upload_speed"]
|
myuploadspeed = mykeys["upload_speed"]
|
||||||
env.Replace(BOARD=myboard)
|
env.Replace(BOARD=myboard)
|
||||||
env.Replace(UPLOAD_SPEED=myuploadspeed)
|
env.Replace(UPLOAD_SPEED=myuploadspeed)
|
||||||
print '\033[94m' + "TARGET BOARD: " + myboard + " @ " + myuploadspeed + "bps" + '\033[0m'
|
print('\033[94m' + "TARGET BOARD: " + myboard + " @ " + myuploadspeed + "bps" + '\033[0m')
|
||||||
|
|
||||||
# parse ota key file
|
# parse ota key file
|
||||||
with open(otakeyfile) as myfile:
|
with open(otakeyfile) as myfile:
|
||||||
@ -136,4 +136,4 @@ def publish_bintray(source, target, env):
|
|||||||
# put build file name and upload command to platformio environment
|
# put build file name and upload command to platformio environment
|
||||||
env.Replace(
|
env.Replace(
|
||||||
PROGNAME="firmware_" + package + "_v%s" % version,
|
PROGNAME="firmware_" + package + "_v%s" % version,
|
||||||
UPLOADCMD=publish_bintray)
|
UPLOADCMD=publish_bintray)
|
||||||
|
@ -42,8 +42,8 @@
|
|||||||
#define SCREEN_MODE (0x80)
|
#define SCREEN_MODE (0x80)
|
||||||
|
|
||||||
// I2C bus access control
|
// I2C bus access control
|
||||||
#define I2C_MUTEX_LOCK() xSemaphoreTake(I2Caccess, pdMS_TO_TICKS(10)) == pdTRUE
|
#define I2C_MUTEX_LOCK() (xSemaphoreTake(I2Caccess, pdMS_TO_TICKS(2000)) == pdTRUE)
|
||||||
#define I2C_MUTEX_UNLOCK() xSemaphoreGive(I2Caccess)
|
#define I2C_MUTEX_UNLOCK() (xSemaphoreGive(I2Caccess))
|
||||||
|
|
||||||
// Struct holding devices's runtime configuration
|
// Struct holding devices's runtime configuration
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
#include "timekeeper.h"
|
#include "timekeeper.h"
|
||||||
|
|
||||||
void irqHandler(void *pvParameters);
|
void irqHandler(void *pvParameters);
|
||||||
int mask_user_IRQ();
|
void mask_user_IRQ();
|
||||||
int unmask_user_IRQ();
|
void unmask_user_IRQ();
|
||||||
|
|
||||||
#ifdef HAS_DISPLAY
|
#ifdef HAS_DISPLAY
|
||||||
void IRAM_ATTR DisplayIRQ();
|
void IRAM_ATTR DisplayIRQ();
|
||||||
|
@ -146,7 +146,7 @@ IRAM_ATTR void gap_callback_handler(esp_gap_ble_cb_event_t event,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if(VENDORFILTER)
|
#if (VENDORFILTER)
|
||||||
|
|
||||||
if ((p->scan_rst.ble_addr_type == BLE_ADDR_TYPE_RANDOM) ||
|
if ((p->scan_rst.ble_addr_type == BLE_ADDR_TYPE_RANDOM) ||
|
||||||
(p->scan_rst.ble_addr_type == BLE_ADDR_TYPE_RPA_RANDOM)) {
|
(p->scan_rst.ble_addr_type == BLE_ADDR_TYPE_RPA_RANDOM)) {
|
||||||
@ -162,6 +162,7 @@ IRAM_ATTR void gap_callback_handler(esp_gap_ble_cb_event_t event,
|
|||||||
/* to be improved in vendorfilter if:
|
/* to be improved in vendorfilter if:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// you can search for elements in the payload using the
|
// you can search for elements in the payload using the
|
||||||
// function esp_ble_resolve_adv_data()
|
// function esp_ble_resolve_adv_data()
|
||||||
//
|
//
|
||||||
@ -207,21 +208,21 @@ esp_err_t register_ble_callback(void) {
|
|||||||
ESP_ERROR_CHECK(esp_ble_gap_register_callback(&gap_callback_handler));
|
ESP_ERROR_CHECK(esp_ble_gap_register_callback(&gap_callback_handler));
|
||||||
|
|
||||||
static esp_ble_scan_params_t ble_scan_params = {
|
static esp_ble_scan_params_t ble_scan_params = {
|
||||||
.scan_type = BLE_SCAN_TYPE_PASSIVE,
|
.scan_type = BLE_SCAN_TYPE_PASSIVE,
|
||||||
.own_addr_type = BLE_ADDR_TYPE_RANDOM,
|
.own_addr_type = BLE_ADDR_TYPE_RANDOM,
|
||||||
|
|
||||||
#if(VENDORFILTER)
|
#if (VENDORFILTER)
|
||||||
.scan_filter_policy = BLE_SCAN_FILTER_ALLOW_WLIST_PRA_DIR,
|
.scan_filter_policy = BLE_SCAN_FILTER_ALLOW_WLIST_PRA_DIR,
|
||||||
// ADV_IND, ADV_NONCONN_IND, ADV_SCAN_IND packets are used for broadcasting
|
// ADV_IND, ADV_NONCONN_IND, ADV_SCAN_IND packets are used for broadcasting
|
||||||
// data in broadcast applications (e.g., Beacons), so we don't want them in
|
// data in broadcast applications (e.g., Beacons), so we don't want them in
|
||||||
// vendorfilter mode
|
// vendorfilter mode
|
||||||
#else
|
#else
|
||||||
.scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL,
|
.scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
.scan_interval =
|
.scan_interval =
|
||||||
(uint16_t)(cfg.blescantime * 10 / 0.625), // Time = N * 0.625 msec
|
(uint16_t)(cfg.blescantime * 10 / 0.625), // Time = N * 0.625 msec
|
||||||
.scan_window = (uint16_t)(BLESCANWINDOW / 0.625) // Time = N * 0.625 msec
|
.scan_window = (uint16_t)(BLESCANWINDOW / 0.625) // Time = N * 0.625 msec
|
||||||
};
|
};
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Set GAP scan parameters");
|
ESP_LOGI(TAG, "Set GAP scan parameters");
|
||||||
@ -234,12 +235,11 @@ esp_err_t register_ble_callback(void) {
|
|||||||
} // register_ble_callback
|
} // register_ble_callback
|
||||||
|
|
||||||
void start_BLEscan(void) {
|
void start_BLEscan(void) {
|
||||||
#if(BLECOUNTER)
|
#if (BLECOUNTER)
|
||||||
ESP_LOGI(TAG, "Initializing bluetooth scanner ...");
|
ESP_LOGI(TAG, "Initializing bluetooth scanner ...");
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_coex_preference_set(
|
ESP_ERROR_CHECK(esp_coex_preference_set(
|
||||||
(esp_coex_prefer_t)
|
ESP_COEX_PREFER_BALANCE)); // configure Wifi/BT coexist lib
|
||||||
ESP_COEX_PREFER_BALANCE)); // configure Wifi/BT coexist lib
|
|
||||||
|
|
||||||
// Initialize BT controller to allocate task and other resource.
|
// Initialize BT controller to allocate task and other resource.
|
||||||
btStart();
|
btStart();
|
||||||
@ -254,14 +254,14 @@ void start_BLEscan(void) {
|
|||||||
} // start_BLEscan
|
} // start_BLEscan
|
||||||
|
|
||||||
void stop_BLEscan(void) {
|
void stop_BLEscan(void) {
|
||||||
#if(BLECOUNTER)
|
#if (BLECOUNTER)
|
||||||
ESP_LOGI(TAG, "Shutting down bluetooth scanner ...");
|
ESP_LOGI(TAG, "Shutting down bluetooth scanner ...");
|
||||||
ESP_ERROR_CHECK(esp_ble_gap_register_callback(NULL));
|
ESP_ERROR_CHECK(esp_ble_gap_register_callback(NULL));
|
||||||
ESP_ERROR_CHECK(esp_bluedroid_disable());
|
ESP_ERROR_CHECK(esp_bluedroid_disable());
|
||||||
ESP_ERROR_CHECK(esp_bluedroid_deinit());
|
ESP_ERROR_CHECK(esp_bluedroid_deinit());
|
||||||
btStop(); // disable bt_controller
|
btStop(); // disable bt_controller
|
||||||
ESP_ERROR_CHECK(esp_coex_preference_set((
|
ESP_ERROR_CHECK(esp_coex_preference_set(
|
||||||
esp_coex_prefer_t)ESP_COEX_PREFER_WIFI)); // configure Wifi/BT coexist lib
|
ESP_COEX_PREFER_WIFI)); // configure Wifi/BT coexist lib
|
||||||
ESP_LOGI(TAG, "Bluetooth scanner stopped");
|
ESP_LOGI(TAG, "Bluetooth scanner stopped");
|
||||||
#endif // BLECOUNTER
|
#endif // BLECOUNTER
|
||||||
} // stop_BLEscan
|
} // stop_BLEscan
|
||||||
|
@ -62,8 +62,9 @@ void DisplayKey(const uint8_t *key, uint8_t len, bool lsb) {
|
|||||||
void init_display(const char *Productname, const char *Version) {
|
void init_display(const char *Productname, const char *Version) {
|
||||||
|
|
||||||
// block i2c bus access
|
// block i2c bus access
|
||||||
if (I2C_MUTEX_LOCK()) {
|
if (!I2C_MUTEX_LOCK())
|
||||||
|
ESP_LOGW(TAG, "[%0.3f] i2c mutex lock failed", millis() / 1000.0);
|
||||||
|
else {
|
||||||
// show startup screen
|
// show startup screen
|
||||||
uint8_t buf[32];
|
uint8_t buf[32];
|
||||||
u8x8.begin();
|
u8x8.begin();
|
||||||
@ -141,8 +142,9 @@ void refreshTheDisplay(bool nextPage) {
|
|||||||
myTZ.toLocal(now()); // note: call now() here *before* locking mutex!
|
myTZ.toLocal(now()); // note: call now() here *before* locking mutex!
|
||||||
|
|
||||||
// block i2c bus access
|
// block i2c bus access
|
||||||
if (I2C_MUTEX_LOCK()) {
|
if (!I2C_MUTEX_LOCK())
|
||||||
|
ESP_LOGW(TAG, "[%0.3f] i2c mutex lock failed", millis() / 1000.0);
|
||||||
|
else {
|
||||||
// set display on/off according to current device configuration
|
// set display on/off according to current device configuration
|
||||||
if (DisplayIsOn != cfg.screenon) {
|
if (DisplayIsOn != cfg.screenon) {
|
||||||
DisplayIsOn = cfg.screenon;
|
DisplayIsOn = cfg.screenon;
|
||||||
@ -165,7 +167,9 @@ void draw_page(time_t t, uint8_t page) {
|
|||||||
|
|
||||||
char timeState, buff[16];
|
char timeState, buff[16];
|
||||||
uint8_t msgWaiting;
|
uint8_t msgWaiting;
|
||||||
|
#if (HAS_GPS)
|
||||||
static bool wasnofix = true;
|
static bool wasnofix = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
// update counter (lines 0-1)
|
// update counter (lines 0-1)
|
||||||
snprintf(
|
snprintf(
|
||||||
|
@ -80,11 +80,12 @@ void IRAM_ATTR gps_storetime(gpsStatus_t &gps_store) {
|
|||||||
if (gps.time.isUpdated() && gps.date.isValid() && (gps.time.age() < 1000)) {
|
if (gps.time.isUpdated() && gps.date.isValid() && (gps.time.age() < 1000)) {
|
||||||
|
|
||||||
// nmea telegram serial delay compensation; not sure if we need this?
|
// nmea telegram serial delay compensation; not sure if we need this?
|
||||||
|
/*
|
||||||
if (gps.time.age() > nmea_txDelay_ms)
|
if (gps.time.age() > nmea_txDelay_ms)
|
||||||
gps_store.timedate.Second = gps.time.second() + 1;
|
gps_store.timedate.Second = gps.time.second() + 1;
|
||||||
else
|
else
|
||||||
gps_store.timedate.Second = gps.time.second();
|
gps_store.timedate.Second = gps.time.second();
|
||||||
|
*/
|
||||||
|
|
||||||
gps_store.timedate.Second = gps.time.second();
|
gps_store.timedate.Second = gps.time.second();
|
||||||
gps_store.timedate.Minute = gps.time.minute();
|
gps_store.timedate.Minute = gps.time.minute();
|
||||||
|
@ -53,8 +53,6 @@
|
|||||||
#define HAS_BUTTON (39) // on board button
|
#define HAS_BUTTON (39) // on board button
|
||||||
#define HAS_RGB_LED (0) // WS2812B RGB LED on GPIO0
|
#define HAS_RGB_LED (0) // WS2812B RGB LED on GPIO0
|
||||||
|
|
||||||
#define BOARD_HAS_PSRAM // use extra 4MB extern RAM
|
|
||||||
|
|
||||||
// GPS settings
|
// GPS settings
|
||||||
#define HAS_GPS 1 // use on board GPS
|
#define HAS_GPS 1 // use on board GPS
|
||||||
#define GPS_SERIAL 9600, SERIAL_8N1, GPIO_NUM_12, GPIO_NUM_15 // UBlox NEO 6M
|
#define GPS_SERIAL 9600, SERIAL_8N1, GPIO_NUM_12, GPIO_NUM_15 // UBlox NEO 6M
|
||||||
|
@ -119,18 +119,6 @@ void IRAM_ATTR GpsIRQ() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int mask_user_IRQ() {
|
void mask_user_IRQ() { xTaskNotify(irqHandlerTask, MASK_IRQ, eSetBits); }
|
||||||
// begin of time critical section: lock I2C bus to ensure accurate timing
|
|
||||||
if (I2C_MUTEX_LOCK()) {
|
|
||||||
xTaskNotify(irqHandlerTask, MASK_IRQ, eSetBits);
|
|
||||||
return 0;
|
|
||||||
} else
|
|
||||||
return 1; // failure
|
|
||||||
}
|
|
||||||
|
|
||||||
int unmask_user_IRQ() {
|
void unmask_user_IRQ() { xTaskNotify(irqHandlerTask, UNMASK_IRQ, eSetBits); }
|
||||||
// end of time critical section: release I2C bus
|
|
||||||
I2C_MUTEX_UNLOCK();
|
|
||||||
xTaskNotify(irqHandlerTask, UNMASK_IRQ, eSetBits);
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -306,7 +306,7 @@ void onEvent(ev_t ev) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case EV_TXSTART:
|
case EV_TXSTART:
|
||||||
if (!(LMIC.opmode & OP_JOINING))
|
if (!(LMIC.opmode & OP_JOINING)) {
|
||||||
#if (TIME_SYNC_LORASERVER)
|
#if (TIME_SYNC_LORASERVER)
|
||||||
// if last packet sent was a timesync request, store TX time
|
// if last packet sent was a timesync request, store TX time
|
||||||
if (LMIC.pendTxPort == TIMEPORT)
|
if (LMIC.pendTxPort == TIMEPORT)
|
||||||
@ -314,6 +314,7 @@ void onEvent(ev_t ev) {
|
|||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
strcpy_P(buff, PSTR("TX START"));
|
strcpy_P(buff, PSTR("TX START"));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EV_TXCANCELED:
|
case EV_TXCANCELED:
|
||||||
@ -506,9 +507,15 @@ void IRAM_ATTR user_request_network_time_callback(void *pVoidUserUTCTime,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// begin of time critical section: lock I2C bus to ensure accurate timing
|
// begin of time critical section
|
||||||
if (!mask_user_IRQ())
|
|
||||||
return; // failure
|
// lock I2C bus and application irq to ensure accurate timing
|
||||||
|
mask_user_IRQ();
|
||||||
|
if (!I2C_MUTEX_LOCK()) {
|
||||||
|
ESP_LOGW(TAG, "[%0.3f] Timesync handshake error: i2c bus locking failed",
|
||||||
|
millis() / 1000.0);
|
||||||
|
goto finish; // failure
|
||||||
|
}
|
||||||
|
|
||||||
// Update userUTCTime, considering the difference between the GPS and UTC
|
// Update userUTCTime, considering the difference between the GPS and UTC
|
||||||
// time, and the leap seconds until year 2019
|
// time, and the leap seconds until year 2019
|
||||||
@ -524,7 +531,9 @@ void IRAM_ATTR user_request_network_time_callback(void *pVoidUserUTCTime,
|
|||||||
// Update system time with time read from the network
|
// Update system time with time read from the network
|
||||||
setMyTime(*pUserUTCTime + requestDelaySec, 0);
|
setMyTime(*pUserUTCTime + requestDelaySec, 0);
|
||||||
|
|
||||||
// end of time critical section: release I2C bus
|
finish:
|
||||||
|
// end of time critical section: release I2C bus and app irq
|
||||||
|
I2C_MUTEX_UNLOCK();
|
||||||
unmask_user_IRQ();
|
unmask_user_IRQ();
|
||||||
|
|
||||||
} // user_request_network_time_callback
|
} // user_request_network_time_callback
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Basic Config
|
// Basic Config
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
#if(VENDORFILTER)
|
#if (VENDORFILTER)
|
||||||
#include "vendor_array.h"
|
#include "vendor_array.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -37,33 +37,35 @@ void printKey(const char *name, const uint8_t *key, uint8_t len, bool lsb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint64_t macConvert(uint8_t *paddr) {
|
uint64_t macConvert(uint8_t *paddr) {
|
||||||
return ((uint64_t)paddr[0]) | ((uint64_t)paddr[1] << 8) |
|
uint64_t *mac;
|
||||||
((uint64_t)paddr[2] << 16) | ((uint64_t)paddr[3] << 24) |
|
mac = (uint64_t *)paddr;
|
||||||
((uint64_t)paddr[4] << 32) | ((uint64_t)paddr[5] << 40);
|
return (__builtin_bswap64(*mac) >> 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
|
bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
|
||||||
|
|
||||||
char buff[16]; // temporary buffer for printf
|
if (!salt) // ensure we have salt (appears after radio is turned on)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
char buff[10]; // temporary buffer for printf
|
||||||
bool added = false;
|
bool added = false;
|
||||||
int8_t beaconID; // beacon number in test monitor mode
|
int8_t beaconID; // beacon number in test monitor mode
|
||||||
uint16_t hashedmac; // temporary buffer for generated hash value
|
uint16_t hashedmac; // temporary buffer for generated hash value
|
||||||
uint32_t addr2int; // temporary buffer for shortened MAC
|
uint32_t *mac; // temporary buffer for shortened MAC
|
||||||
#if(VENDORFILTER)
|
|
||||||
uint32_t vendor2int; // temporary buffer for Vendor OUI
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// only last 3 MAC Address bytes are used for MAC address anonymization
|
// only last 3 MAC Address bytes are used for MAC address anonymization
|
||||||
// but since it's uint32 we take 4 bytes to avoid 1st value to be 0
|
// but since it's uint32 we take 4 bytes to avoid 1st value to be 0.
|
||||||
addr2int = ((uint32_t)paddr[2]) | ((uint32_t)paddr[3] << 8) |
|
// this gets MAC in msb (= reverse) order, but doesn't matter for hashing it.
|
||||||
((uint32_t)paddr[4] << 16) | ((uint32_t)paddr[5] << 24);
|
mac = (uint32_t *)(paddr + 2);
|
||||||
|
|
||||||
|
#if (VENDORFILTER)
|
||||||
|
uint32_t *oui; // temporary buffer for vendor OUI
|
||||||
|
oui = (uint32_t *)paddr;
|
||||||
|
|
||||||
#if(VENDORFILTER)
|
|
||||||
vendor2int = ((uint32_t)paddr[2]) | ((uint32_t)paddr[1] << 8) |
|
|
||||||
((uint32_t)paddr[0] << 16);
|
|
||||||
// use OUI vendor filter list only on Wifi, not on BLE
|
// use OUI vendor filter list only on Wifi, not on BLE
|
||||||
if ((sniff_type == MAC_SNIFF_BLE) ||
|
if ((sniff_type == MAC_SNIFF_BLE) ||
|
||||||
std::find(vendors.begin(), vendors.end(), vendor2int) != vendors.end()) {
|
std::find(vendors.begin(), vendors.end(), __builtin_bswap32(*oui) >> 8) !=
|
||||||
|
vendors.end()) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// salt and hash MAC, and if new unique one, store identifier in container
|
// salt and hash MAC, and if new unique one, store identifier in container
|
||||||
@ -71,10 +73,9 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
|
|||||||
// https://en.wikipedia.org/wiki/MAC_Address_Anonymization
|
// https://en.wikipedia.org/wiki/MAC_Address_Anonymization
|
||||||
|
|
||||||
snprintf(buff, sizeof(buff), "%08X",
|
snprintf(buff, sizeof(buff), "%08X",
|
||||||
addr2int + (uint32_t)salt); // convert usigned 32-bit salted MAC
|
*mac + (uint32_t)salt); // convert unsigned 32-bit salted MAC
|
||||||
// to 8 digit hex string
|
// to 8 digit hex string
|
||||||
hashedmac = rokkit(&buff[3], 5); // hash MAC last string value, use 5 chars
|
hashedmac = rokkit(&buff[3], 5); // hash MAC 8 digit -> 5 digit
|
||||||
// to fit hash in uint16_t container
|
|
||||||
auto newmac = macs.insert(hashedmac); // add hashed MAC, if new unique
|
auto newmac = macs.insert(hashedmac); // add hashed MAC, if new unique
|
||||||
added = newmac.second ? true
|
added = newmac.second ? true
|
||||||
: false; // true if hashed MAC is unique in container
|
: false; // true if hashed MAC is unique in container
|
||||||
@ -88,7 +89,7 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
|
|||||||
blink_LED(COLOR_GREEN, 50);
|
blink_LED(COLOR_GREEN, 50);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#if(BLECOUNTER)
|
#if (BLECOUNTER)
|
||||||
else if (sniff_type == MAC_SNIFF_BLE) {
|
else if (sniff_type == MAC_SNIFF_BLE) {
|
||||||
macs_ble++; // increment BLE Macs counter
|
macs_ble++; // increment BLE Macs counter
|
||||||
#if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)
|
#if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)
|
||||||
@ -115,13 +116,14 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
|
|||||||
|
|
||||||
// Log scan result
|
// Log scan result
|
||||||
ESP_LOGV(TAG,
|
ESP_LOGV(TAG,
|
||||||
"%s %s RSSI %ddBi -> MAC %s -> Hash %04X -> WiFi:%d BLTH:%d -> "
|
"%s %s RSSI %ddBi -> salted MAC %s -> Hash %04X -> WiFi:%d "
|
||||||
|
"BLTH:%d -> "
|
||||||
"%d Bytes left",
|
"%d Bytes left",
|
||||||
added ? "new " : "known",
|
added ? "new " : "known",
|
||||||
sniff_type == MAC_SNIFF_WIFI ? "WiFi" : "BLTH", rssi, buff,
|
sniff_type == MAC_SNIFF_WIFI ? "WiFi" : "BLTH", rssi, buff,
|
||||||
hashedmac, macs_wifi, macs_ble, getFreeRAM());
|
hashedmac, macs_wifi, macs_ble, getFreeRAM());
|
||||||
|
|
||||||
#if(VENDORFILTER)
|
#if (VENDORFILTER)
|
||||||
} else {
|
} else {
|
||||||
// Very noisy
|
// Very noisy
|
||||||
// ESP_LOGD(TAG, "Filtered MAC %02X:%02X:%02X:%02X:%02X:%02X",
|
// ESP_LOGD(TAG, "Filtered MAC %02X:%02X:%02X:%02X:%02X:%02X",
|
||||||
|
@ -116,10 +116,9 @@ void setup() {
|
|||||||
|
|
||||||
// create some semaphores for syncing / mutexing tasks
|
// create some semaphores for syncing / mutexing tasks
|
||||||
I2Caccess = xSemaphoreCreateMutex(); // for access management of i2c bus
|
I2Caccess = xSemaphoreCreateMutex(); // for access management of i2c bus
|
||||||
if (I2Caccess)
|
assert(I2Caccess != NULL);
|
||||||
xSemaphoreGive(I2Caccess); // Flag the i2c bus available for use
|
|
||||||
|
|
||||||
// disable brownout detection
|
// disable brownout detection
|
||||||
#ifdef DISABLE_BROWNOUT
|
#ifdef DISABLE_BROWNOUT
|
||||||
// register with brownout is at address DR_REG_RTCCNTL_BASE + 0xd4
|
// register with brownout is at address DR_REG_RTCCNTL_BASE + 0xd4
|
||||||
(*((uint32_t volatile *)ETS_UNCACHED_ADDR((DR_REG_RTCCNTL_BASE + 0xd4)))) = 0;
|
(*((uint32_t volatile *)ETS_UNCACHED_ADDR((DR_REG_RTCCNTL_BASE + 0xd4)))) = 0;
|
||||||
@ -262,8 +261,8 @@ void setup() {
|
|||||||
// remove bluetooth stack to gain more free memory
|
// remove bluetooth stack to gain more free memory
|
||||||
btStop();
|
btStop();
|
||||||
ESP_ERROR_CHECK(esp_bt_mem_release(ESP_BT_MODE_BTDM));
|
ESP_ERROR_CHECK(esp_bt_mem_release(ESP_BT_MODE_BTDM));
|
||||||
ESP_ERROR_CHECK(esp_coex_preference_set((
|
ESP_ERROR_CHECK(esp_coex_preference_set(
|
||||||
esp_coex_prefer_t)ESP_COEX_PREFER_WIFI)); // configure Wifi/BT coexist lib
|
ESP_COEX_PREFER_WIFI)); // configure Wifi/BT coexist lib
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// initialize gps
|
// initialize gps
|
||||||
|
@ -64,7 +64,7 @@ void process_timesync_req(void *taskparameter) {
|
|||||||
|
|
||||||
// wait until we are joined if we are not
|
// wait until we are joined if we are not
|
||||||
while (!LMIC.devaddr) {
|
while (!LMIC.devaddr) {
|
||||||
vTaskDelay(5000);
|
vTaskDelay(3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// collect timestamp samples
|
// collect timestamp samples
|
||||||
@ -110,10 +110,10 @@ void process_timesync_req(void *taskparameter) {
|
|||||||
}
|
}
|
||||||
} // end of for loop to collect timestamp samples
|
} // end of for loop to collect timestamp samples
|
||||||
|
|
||||||
// begin of time critical section: lock app irq's and I2C bus
|
// lock I2C bus and application irq to ensure accurate timing
|
||||||
if (!mask_user_IRQ()) {
|
mask_user_IRQ();
|
||||||
ESP_LOGW(TAG,
|
if (!I2C_MUTEX_LOCK()) {
|
||||||
"[%0.3f] Timesync handshake error: irq / i2c masking failed",
|
ESP_LOGW(TAG, "[%0.3f] Timesync handshake error: i2c bus locking failed",
|
||||||
millis() / 1000.0);
|
millis() / 1000.0);
|
||||||
goto finish; // failure
|
goto finish; // failure
|
||||||
}
|
}
|
||||||
@ -135,10 +135,11 @@ void process_timesync_req(void *taskparameter) {
|
|||||||
|
|
||||||
setMyTime(time_to_set, time_to_set_fraction_msec);
|
setMyTime(time_to_set, time_to_set_fraction_msec);
|
||||||
|
|
||||||
// end of time critical section: release I2C bus and re-enable app irq's
|
finish:
|
||||||
|
// end of time critical section: release I2C bus and app irq
|
||||||
|
I2C_MUTEX_UNLOCK();
|
||||||
unmask_user_IRQ();
|
unmask_user_IRQ();
|
||||||
|
|
||||||
finish:
|
|
||||||
timeSyncPending = false;
|
timeSyncPending = false;
|
||||||
|
|
||||||
} // infinite while(1)
|
} // infinite while(1)
|
||||||
|
@ -57,8 +57,8 @@ void wifi_sniffer_init(void) {
|
|||||||
wificfg.nvs_enable = 0; // we don't need any wifi settings from NVRAM
|
wificfg.nvs_enable = 0; // we don't need any wifi settings from NVRAM
|
||||||
wificfg.wifi_task_core_id = 0; // we want wifi task running on core 0
|
wificfg.wifi_task_core_id = 0; // we want wifi task running on core 0
|
||||||
|
|
||||||
// wifi_promiscuous_filter_t filter = {
|
//wifi_promiscuous_filter_t filter = {
|
||||||
// .filter_mask = WIFI_PROMIS_FILTER_MASK_MGMT}; // only MGMT frames
|
// .filter_mask = WIFI_PROMIS_FILTER_MASK_MGMT}; // only MGMT frames
|
||||||
// .filter_mask = WIFI_PROMIS_FILTER_MASK_ALL}; // we use all frames
|
// .filter_mask = WIFI_PROMIS_FILTER_MASK_ALL}; // we use all frames
|
||||||
|
|
||||||
wifi_promiscuous_filter_t filter = {.filter_mask =
|
wifi_promiscuous_filter_t filter = {.filter_mask =
|
||||||
@ -73,7 +73,7 @@ void wifi_sniffer_init(void) {
|
|||||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL));
|
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL));
|
||||||
ESP_ERROR_CHECK(esp_wifi_stop());
|
ESP_ERROR_CHECK(esp_wifi_stop());
|
||||||
ESP_ERROR_CHECK(
|
ESP_ERROR_CHECK(
|
||||||
esp_wifi_set_promiscuous_filter(&filter)); // set MAC frame filter
|
esp_wifi_set_promiscuous_filter(&filter)); // set frame filter
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler));
|
ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler));
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_promiscuous(true)); // now switch on monitor mode
|
ESP_ERROR_CHECK(esp_wifi_set_promiscuous(true)); // now switch on monitor mode
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user