CWA scanner minor modifications
This commit is contained in:
parent
c014824667
commit
2f0b3c8ef2
@ -9,7 +9,7 @@
|
||||
#include <map>
|
||||
|
||||
bool cwa_init(void);
|
||||
bool cwa_mac_add(uint8_t *);
|
||||
bool cwa_mac_add(uint16_t hashedmac);
|
||||
void cwa_clear(void);
|
||||
uint16_t cwa_report(void);
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
uint16_t get_salt(void);
|
||||
uint64_t macConvert(uint8_t *paddr);
|
||||
bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type);
|
||||
uint16_t mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type);
|
||||
void printKey(const char *name, const uint8_t *key, uint8_t len, bool lsb);
|
||||
|
||||
#endif
|
||||
|
@ -114,7 +114,9 @@ const char *btsig_gap_type(uint32_t gap_type) {
|
||||
// using IRAM_:ATTR here to speed up callback function
|
||||
IRAM_ATTR void gap_callback_handler(esp_gap_ble_cb_event_t event,
|
||||
esp_ble_gap_cb_param_t *param) {
|
||||
|
||||
esp_ble_gap_cb_param_t *p = (esp_ble_gap_cb_param_t *)param;
|
||||
uint16_t hashedmac = 0;
|
||||
|
||||
ESP_LOGV(TAG, "BT payload rcvd -> type: 0x%.2x -> %s", *p->scan_rst.ble_adv,
|
||||
btsig_gap_type(*p->scan_rst.ble_adv));
|
||||
@ -151,24 +153,20 @@ IRAM_ATTR void gap_callback_handler(esp_gap_ble_cb_event_t event,
|
||||
}
|
||||
|
||||
#if (VENDORFILTER)
|
||||
|
||||
if ((p->scan_rst.ble_addr_type == BLE_ADDR_TYPE_RANDOM) ||
|
||||
(p->scan_rst.ble_addr_type == BLE_ADDR_TYPE_RPA_RANDOM)) {
|
||||
ESP_LOGV(TAG, "BT device filtered");
|
||||
break;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// add this device and show new count total if it was not previously added
|
||||
mac_add((uint8_t *)p->scan_rst.bda, p->scan_rst.rssi, MAC_SNIFF_BLE);
|
||||
// hash and add this device and show new count total if it was not previously added
|
||||
hashedmac = mac_add((uint8_t *)p->scan_rst.bda, p->scan_rst.rssi, MAC_SNIFF_BLE);
|
||||
|
||||
#if (COUNT_ENS)
|
||||
// we can call the ens functions now using hashed max-value in mac_add()
|
||||
|
||||
// check for ens signature
|
||||
if (0 == strncmp((const char *)p->scan_rst.ble_adv, ensMagicBytes, 4)) {
|
||||
cwa_mac_add(p->scan_rst.bda);
|
||||
cwa_mac_add(hashedmac);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -15,10 +15,6 @@ static const char TAG[] = __FILE__;
|
||||
|
||||
#include "corona.h"
|
||||
|
||||
// taken from macsniff.cpp
|
||||
extern uint16_t salt;
|
||||
extern uint16_t hashedmac;
|
||||
|
||||
// When to forget old senders.
|
||||
#define FORGET_AFTER_MINUTES 2
|
||||
|
||||
@ -27,15 +23,16 @@ static std::map<uint16_t, unsigned long> cwaSeenNotifiers;
|
||||
|
||||
// Remove notifiers last seen over FORGET_AFTER_MINUTES ago.
|
||||
void cwa_clear() {
|
||||
ESP_LOGD(TAG, "CWA: forget old notifier: %d", cwaSeenNotifiers.size());
|
||||
|
||||
/*
|
||||
#ifdef SOME_FORM_OF_DEBUG
|
||||
|
||||
#ifdef SOME_FORM_OF_DEBUG
|
||||
ESP_LOGD(TAG, "CWA: forget old notifier: %d", cwaSeenNotifiers.size());
|
||||
for (auto const ¬ifier : cwaSeenNotifiers) {
|
||||
ESP_LOGD(TAG, "CWA forget <%X>", notifier.first);
|
||||
// }
|
||||
}
|
||||
#endif
|
||||
|
||||
*/
|
||||
|
||||
// clear everything, otherwise we would count the same device again, as in the
|
||||
@ -51,17 +48,10 @@ bool cwa_init(void) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// similar to mac_add(), found in macsniff.cpp
|
||||
// for comments pls. look into this function
|
||||
bool cwa_mac_add(uint8_t *paddr) {
|
||||
|
||||
// are we too early?
|
||||
if (!hashedmac)
|
||||
return false; // YES -> return
|
||||
// similar to mac_add(), found in macsniff.cpp, for comments look into this function
|
||||
bool cwa_mac_add(uint16_t hashedmac) {
|
||||
|
||||
bool added = false;
|
||||
ESP_LOGD(TAG, "Device address (bda): %02x:%02x:%02x:%02x:%02x:%02x",
|
||||
BT_BD_ADDR_HEX(paddr));
|
||||
|
||||
ESP_LOGD(TAG, "hashed ENS mac = %X, ENS count = %d (total=%d)", hashedmac,
|
||||
cwaSeenNotifiers.count(hashedmac), cwaSeenNotifiers.size());
|
||||
@ -69,12 +59,11 @@ bool cwa_mac_add(uint8_t *paddr) {
|
||||
|
||||
// Count only if this ENS MAC was not yet seen
|
||||
if (added) {
|
||||
cwaSeenNotifiers[hashedmac] = millis(); // last seen at ....
|
||||
ESP_LOGD(TAG, "added device with active ENS");
|
||||
}
|
||||
|
||||
cwaSeenNotifiers[hashedmac] = millis(); // last seen at ....
|
||||
|
||||
// True if MAC WiFi/BLE was new
|
||||
// True if ENS MAC was new
|
||||
return added;
|
||||
}
|
||||
|
||||
|
@ -10,9 +10,7 @@
|
||||
// Local logging tag
|
||||
static const char TAG[] = __FILE__;
|
||||
|
||||
// used here and in corona.cpp
|
||||
uint16_t salt = 0;
|
||||
uint16_t hashedmac = 0; // temporary buffer for generated hash value
|
||||
|
||||
uint16_t get_salt(void) {
|
||||
salt = (uint16_t)random(65536); // get new 16bit random for salting hashes
|
||||
@ -45,12 +43,13 @@ uint64_t macConvert(uint8_t *paddr) {
|
||||
return (__builtin_bswap64(*mac) >> 16);
|
||||
}
|
||||
|
||||
bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
|
||||
uint16_t mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
|
||||
|
||||
if (!salt) // ensure we have salt (appears after radio is turned on)
|
||||
return false;
|
||||
if (salt == 0) // ensure we have salt (appears after radio is turned on)
|
||||
return 0;
|
||||
|
||||
char buff[10]; // temporary buffer for printf
|
||||
uint16_t hashedmac = 0; // temporary buffer for generated hash value
|
||||
char buff[10]; // temporary buffer for printf
|
||||
bool added = false;
|
||||
int8_t beaconID; // beacon number in test monitor mode
|
||||
uint32_t *mac; // temporary buffer for shortened MAC
|
||||
@ -140,7 +139,7 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
|
||||
}
|
||||
#endif
|
||||
|
||||
// True if MAC WiFi/BLE was new
|
||||
return added; // function returns bool if a new and unique Wifi or BLE mac was
|
||||
// counted (true) or not (false)
|
||||
// if a new and unique Wifi or BLE mac was counted, returs hash of this mac,
|
||||
// else 0
|
||||
return hashedmac;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
// Corona Exposure Notification Service(ENS) counter
|
||||
#define COUNT_ENS 1 // count found number of devices which advertise Exposure Notification Service
|
||||
// set to 0 if you do not want to count these devices
|
||||
// set to 0 if you do not want to enable this function
|
||||
|
||||
// for additional sensors (added by some user)
|
||||
#define HAS_SENSOR_1 1 // set to 1 if you want to count CWAs
|
||||
|
Loading…
Reference in New Issue
Block a user