code sanitization (volatiles check)

This commit is contained in:
Klaus K Wilting 2018-09-23 22:12:10 +02:00
parent d4d6a7ea07
commit 8985ee3603
12 changed files with 34 additions and 34 deletions

View File

@ -48,7 +48,7 @@ void doHousekeeping() {
esp_get_minimum_free_heap_size(), ESP.getFreeHeap());
SendData(COUNTERPORT); // send data before clearing counters
reset_counters(); // clear macs container and reset all counters
reset_salt(); // get new salt for salting hashes
get_salt(); // get new salt for salting hashes
if (esp_get_minimum_free_heap_size() <= MEM_LOW) // check again
esp_restart(); // memory leak, reset device

View File

@ -13,7 +13,7 @@ const char lora_datarate[] = {"1211100908077BFSNA"};
const char lora_datarate[] = {"100908078CNA121110090807"};
#endif
uint8_t DisplayState = 0;
uint8_t volatile DisplayState = 0;
// helper function, prints a hex key on display
void DisplayKey(const uint8_t *key, uint8_t len, bool lsb) {

View File

@ -3,7 +3,7 @@
#include <U8x8lib.h>
extern uint8_t DisplayState;
extern uint8_t volatile DisplayState;
extern HAS_DISPLAY u8x8;
void init_display(const char *Productname, const char *Version);

View File

@ -41,12 +41,13 @@ typedef struct {
// global variables
extern configData_t cfg; // current device configuration
extern char display_line6[], display_line7[]; // screen buffers
extern uint8_t channel; // wifi channel rotation counter
extern uint16_t macs_total, macs_wifi, macs_ble, batt_voltage; // display values
extern uint8_t volatile channel; // wifi channel rotation counter
extern uint16_t volatile macs_total, macs_wifi, macs_ble,
batt_voltage; // display values
extern std::set<uint16_t> macs; // temp storage for MACs
extern hw_timer_t *channelSwitch, *sendCycle;
extern portMUX_TYPE timerMux;
extern volatile int SendCycleTimerIRQ, HomeCycleIRQ, DisplayTimerIRQ,
extern volatile uint8_t SendCycleTimerIRQ, HomeCycleIRQ, DisplayTimerIRQ,
ChannelTimerIRQ, ButtonPressedIRQ;
extern std::array<uint64_t, 0xff>::iterator it;

View File

@ -11,8 +11,8 @@ static const char TAG[] = "main";
uint16_t salt;
uint16_t reset_salt(void) {
salt = random(65536); // get new 16bit random for salting hashes
uint16_t get_salt(void) {
salt = (uint16_t)random(65536); // get new 16bit random for salting hashes
return salt;
}
@ -71,8 +71,8 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
// https://en.wikipedia.org/wiki/MAC_Address_Anonymization
snprintf(buff, sizeof(buff), "%08X",
addr2int + (uint32_t)salt); // convert usigned 32-bit salted MAC to
// 8 digit hex string
addr2int + (uint32_t)salt); // convert usigned 32-bit salted MAC
// to 8 digit hex string
hashedmac = rokkit(&buff[3], 5); // hash MAC last string value, use 5 chars
// to fit hash in uint16_t container
auto newmac = macs.insert(hashedmac); // add hashed MAC, if new unique
@ -81,7 +81,6 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
// Count only if MAC was not yet seen
if (added) {
// increment counter and one blink led
if (sniff_type == MAC_SNIFF_WIFI) {
macs_wifi++; // increment Wifi MACs counter

View File

@ -12,7 +12,7 @@
#define MAC_SNIFF_WIFI 0
#define MAC_SNIFF_BLE 1
uint16_t reset_salt(void);
uint16_t get_salt(void);
uint64_t macConvert(uint8_t *paddr);
bool 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);

View File

@ -47,16 +47,16 @@ ESP32 hardware timers
configData_t cfg; // struct holds current device configuration
char display_line6[16], display_line7[16]; // display buffers
uint8_t channel = 0; // channel rotation counter
uint16_t macs_total = 0, macs_wifi = 0, macs_ble = 0,
uint8_t volatile channel = 0; // channel rotation counter
uint16_t volatile macs_total = 0, macs_wifi = 0, macs_ble = 0,
batt_voltage = 0; // globals for display
// hardware timer for cyclic tasks
hw_timer_t *channelSwitch, *displaytimer, *sendCycle, *homeCycle;
// this variables will be changed in the ISR, and read in main loop
volatile int ButtonPressedIRQ = 0, ChannelTimerIRQ = 0, SendCycleTimerIRQ = 0,
DisplayTimerIRQ = 0, HomeCycleIRQ = 0;
uint8_t volatile ButtonPressedIRQ = 0, ChannelTimerIRQ = 0,
SendCycleTimerIRQ = 0, DisplayTimerIRQ = 0, HomeCycleIRQ = 0;
TaskHandle_t StateTask = NULL;
@ -96,7 +96,7 @@ void setup() {
// disable brownout detection
#ifdef DISABLE_BROWNOUT
// register with brownout is at address DR_REG_RTCCNTL_BASE + 0xd4
(*((volatile uint32_t *)ETS_UNCACHED_ADDR((DR_REG_RTCCNTL_BASE + 0xd4)))) = 0;
(*((uint32_t volatile *)ETS_UNCACHED_ADDR((DR_REG_RTCCNTL_BASE + 0xd4)))) = 0;
#endif
// setup debug output or silence device
@ -329,7 +329,7 @@ void setup() {
// initialize salt value using esp_random() called by random() in
// arduino-esp32 core. Note: do this *after* wifi has started, since
// function gets it's seed from RF noise
reset_salt(); // get new 16bit for salting hashes
get_salt(); // get new 16bit for salting hashes
// start state machine
ESP_LOGI(TAG, "Starting Statemachine...");

View File

@ -29,8 +29,8 @@ const int port = 443;
const uint32_t RESPONSE_TIMEOUT_MS = 5000;
// Variables to validate firmware content
volatile int contentLength = 0;
volatile bool isValidContentType = false;
int volatile contentLength = 0;
bool volatile isValidContentType = false;
// Local logging tag
static const char TAG[] = "main";

View File

@ -18,7 +18,7 @@ void set_reset(uint8_t val[]) {
case 1: // reset MAC counter
ESP_LOGI(TAG, "Remote command: reset MAC counter");
reset_counters(); // clear macs
reset_salt(); // get new salt
get_salt(); // get new salt
sprintf(display_line6, "Reset counter");
break;
case 2: // reset device to factory settings

View File

@ -29,7 +29,7 @@ void SendData(uint8_t port) {
// clear counter if not in cumulative counter mode
if ((port == COUNTERPORT) && (cfg.countermode != 1)) {
reset_counters(); // clear macs container and reset all counters
reset_salt(); // get new salt for salting hashes
get_salt(); // get new salt for salting hashes
ESP_LOGI(TAG, "Counter cleared");
}
} // SendData

View File

@ -44,15 +44,15 @@ void wifi_sniffer_init(void) {
}
// Wifi channel rotation
void switchWifiChannel(uint8_t &ch) {
void switchWifiChannel(uint8_t volatile &ch) {
portENTER_CRITICAL(&timerMux);
ChannelTimerIRQ = 0;
portEXIT_CRITICAL(&timerMux);
// rotates variable channel 1..WIFI_CHANNEL_MAX
ch = (ch % WIFI_CHANNEL_MAX) + 1;
esp_wifi_set_channel(ch, WIFI_SECOND_CHAN_NONE);
ESP_LOGD(TAG, "Wifi set channel %d", &ch);
}
ESP_LOGD(TAG, "Wifi set channel %d", ch);
}
// IRQ handler
void IRAM_ATTR ChannelSwitchIRQ() {

View File

@ -28,6 +28,6 @@ typedef struct {
void wifi_sniffer_init(void);
void wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type);
void ChannelSwitchIRQ(void);
void switchWifiChannel(uint8_t &ch);
void switchWifiChannel(uint8_t volatile &ch);
#endif