added Exposure code, DS3231, SSD1306, interfaces, started with protocol buffers impl.

This commit is contained in:
Lurkars
2020-07-22 21:44:17 +02:00
parent 04f7e8e1d6
commit 4ba1352a05
38 changed files with 5800 additions and 178 deletions
+6 -1
View File
@@ -5,10 +5,15 @@ idf_component_register(
"ena-bluetooth-advertise.c"
"ena-bluetooth-scan.c"
"ena-crypto.c"
"ena-exposure.c"
"ena-storage.c"
INCLUDE_DIRS "include"
PRIV_REQUIRES
PRIV_REQUIRES
spi_flash
mbedtls
bt
nanopb
EMBED_FILES
"test/export.bin"
"test/export.sig"
)
+13
View File
@@ -14,6 +14,12 @@ menu "Exposure Notification API"
help
Defines the maximum number of TEKs to be stored. (Default 14 [14 * 144 => 14 days])
config ENA_STORAGE_EXPOSURE_INFORMATION_MAX
int "Max. exporure information"
default 500
help
Defines the maximum number of exposure information to be stored. (Default 500)
config ENA_STORAGE_TEMP_BEACONS_MAX
int "Max. temporary beacons"
default 1000
@@ -81,5 +87,12 @@ menu "Exposure Notification API"
Defines the TEK rolling period in 10 minute steps. (Default 144 => 24 hours)
endmenu
menu "Miscellaneous"
config ENA_RAM
int "ENA RAM"
default 100000
help
RAM required for main task. (Default 100 KB)
endmenu
endmenu
+10 -20
View File
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <string.h>
#include <time.h>
#include "esp_log.h"
@@ -21,17 +22,7 @@
#include "ena-beacons.h"
static uint32_t temp_beacons_count = 0;
static ena_temp_beacon_t temp_beacons[ENA_STORAGE_TEMP_BEACONS_MAX];
ena_beacon_t ena_beacons_convert(ena_temp_beacon_t temp_beacon)
{
ena_beacon_t beacon;
memcpy(beacon.rpi, temp_beacon.rpi, ENA_KEY_LENGTH);
memcpy(beacon.aem, temp_beacon.aem, ENA_AEM_METADATA_LENGTH);
beacon.timestamp = temp_beacon.timestamp_last;
beacon.rssi = temp_beacon.rssi;
return beacon;
}
static ena_beacon_t temp_beacons[ENA_STORAGE_TEMP_BEACONS_MAX];
int ena_get_temp_beacon_index(uint8_t *rpi, uint8_t *aem)
{
@@ -55,8 +46,7 @@ void ena_beacons_temp_refresh(uint32_t unix_timestamp)
{
ESP_LOGD(ENA_BEACON_LOG, "create beacon after treshold");
ESP_LOG_BUFFER_HEXDUMP(ENA_BEACON_LOG, temp_beacons[i].rpi, ENA_KEY_LENGTH, ESP_LOG_DEBUG);
ena_beacon_t beacon = ena_beacons_convert(temp_beacons[i]);
ena_storage_add_beacon(&beacon);
ena_storage_add_beacon(&temp_beacons[i]);
ena_storage_remove_temp_beacon(i);
}
else
@@ -77,7 +67,8 @@ void ena_beacons_temp_refresh(uint32_t unix_timestamp)
#if (CONFIG_ENA_STORAGE_DUMP)
// DEBUG dump
ena_storage_dump_tek();
ena_storage_dump_teks();
ena_storage_dump_exposure_information();
ena_storage_dump_temp_beacons();
ena_storage_dump_beacons();
#endif
@@ -86,7 +77,6 @@ void ena_beacons_temp_refresh(uint32_t unix_timestamp)
void ena_beacon(uint32_t unix_timestamp, uint8_t *rpi, uint8_t *aem, int rssi)
{
uint32_t beacon_index = ena_get_temp_beacon_index(rpi, aem);
if (beacon_index == -1)
{
temp_beacons[temp_beacons_count].timestamp_first = unix_timestamp;
@@ -95,8 +85,7 @@ void ena_beacon(uint32_t unix_timestamp, uint8_t *rpi, uint8_t *aem, int rssi)
temp_beacons[temp_beacons_count].rssi = rssi;
temp_beacons[temp_beacons_count].timestamp_last = unix_timestamp;
beacon_index = ena_storage_add_temp_beacon(&temp_beacons[temp_beacons_count]);
ESP_LOGD(ENA_BEACON_LOG, "New temporary beacon at %d with timestamp %u", temp_beacons_count, unix_timestamp);
ESP_LOGD(ENA_BEACON_LOG, "new temporary beacon %d at %u", temp_beacons_count, unix_timestamp);
ESP_LOG_BUFFER_HEX_LEVEL(ENA_BEACON_LOG, rpi, ENA_KEY_LENGTH, ESP_LOG_DEBUG);
ESP_LOG_BUFFER_HEX_LEVEL(ENA_BEACON_LOG, aem, ENA_AEM_METADATA_LENGTH, ESP_LOG_DEBUG);
ESP_LOGD(ENA_BEACON_LOG, "RSSI %d", rssi);
@@ -111,9 +100,10 @@ void ena_beacon(uint32_t unix_timestamp, uint8_t *rpi, uint8_t *aem, int rssi)
{
temp_beacons[beacon_index].rssi = (temp_beacons[beacon_index].rssi + rssi) / 2;
temp_beacons[beacon_index].timestamp_last = unix_timestamp;
ESP_LOGD(ENA_BEACON_LOG, "New Timestamp for temporary beacon %d: %u", beacon_index, unix_timestamp);
ESP_LOG_BUFFER_HEX_LEVEL(ENA_BEACON_LOG, rpi, ENA_KEY_LENGTH, ESP_LOG_DEBUG);
ESP_LOG_BUFFER_HEX_LEVEL(ENA_BEACON_LOG, aem, ENA_AEM_METADATA_LENGTH, ESP_LOG_DEBUG);
ESP_LOGD(ENA_BEACON_LOG, "update temporary beacon %d at %u", beacon_index, unix_timestamp);
ESP_LOG_BUFFER_HEX_LEVEL(ENA_BEACON_LOG, temp_beacons[beacon_index].rpi, ENA_KEY_LENGTH, ESP_LOG_DEBUG);
ESP_LOG_BUFFER_HEX_LEVEL(ENA_BEACON_LOG, temp_beacons[beacon_index].aem, ENA_AEM_METADATA_LENGTH, ESP_LOG_DEBUG);
ESP_LOGD(ENA_BEACON_LOG, "RSSI %d", temp_beacons[beacon_index].rssi);
ena_storage_set_temp_beacon(temp_beacons_count, &temp_beacons[temp_beacons_count]);
}
}
+280
View File
@@ -0,0 +1,280 @@
// Copyright 2020 Lukas Haubaum
//
// Licensed under the GNU Affero General Public License, Version 3;
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.gnu.org/licenses/agpl-3.0.html
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <string.h>
#include <time.h>
#include <limits.h>
#include "esp_log.h"
#include "ena-crypto.h"
#include "ena-storage.h"
#include "ena-beacons.h"
#include "ena-exposure.h"
static ena_exposure_config_t DEFAULT_ENA_EXPOSURE_CONFIG = {
// transmission_risk_values
{
MINIMAL, // UNKNOWN
LOW, // CONFIRMED_TEST_LOW
MEDIUM, // CONFIRMED_TEST_STANDARD
HIGH, // CONFIRMED_TEST_HIGH
VERY_HIGH, // CONFIRMED_CLINICAL_DIAGNOSIS
VERY_LOW, // SELF_REPORT
ZERO, // NEGATIVE
MINIMAL // RECURSIVE
},
// duration_risk_values
{
MINIMAL, // D = 0 min
MINIMAL, // D <= 5 min
MEDIUM, // D <= 10 min
VERY_HIGH, // D <= 15 min
VERY_HIGH, // D <= 20 min
MAXIMUM, // D <= 25 min
MAXIMUM, // D <= 30 min
MAXIMUM // D > 30 min
},
// days_risk_values
{
MINIMAL, // >= 14 days
VERY_LOW, // 12-13 days
VERY_LOW, // 10-11 days
MEDIUM, // 8-9 days
HIGH, // 6-7 days
MAXIMUM, // 4-5 days
MAXIMUM, // 2-3 days
MAXIMUM // 0-1 days
},
// attenuation_risk_values
{
MINIMAL, // A > 73 dB
MINIMAL, // 73 >= A > 63
MINIMAL, // 63 >= A > 61
MAXIMUM, // 51 >= A > 33
MAXIMUM, // 33 >= A > 27
MAXIMUM, // 27 >= A > 15
MAXIMUM, // 15 >= A > 10
MAXIMUM // A <= 10
},
};
static const char kFileHeader[] = "EK Export v1 ";
static size_t kFileHeaderSize = sizeof(kFileHeader) - 1;
extern const uint8_t export_bin_start[] asm("_binary_export_bin_start");
extern const uint8_t export_bin_end[] asm("_binary_export_bin_end");
void ena_exposure_keyfiletest(void)
{
ESP_LOG_BUFFER_HEXDUMP(ENA_EXPOSURE_LOG, export_bin_start, (export_bin_end - export_bin_start), ESP_LOG_INFO);
}
void ena_exposure_check(ena_tek_reported_t tek_reported)
{
bool match = false;
ena_beacon_t beacon;
ena_exposure_information_t exposure_info;
exposure_info.duration_minutes = 0;
exposure_info.min_attenuation = INT_MAX;
exposure_info.typical_attenuation = 0;
exposure_info.report_type = tek_reported.report_type;
uint8_t rpi[ENA_KEY_LENGTH];
uint8_t rpik[ENA_KEY_LENGTH];
ena_crypto_rpik(rpik, tek_reported.key_data);
uint32_t beacons_count = ena_storage_beacons_count();
for (int i = 0; i < tek_reported.rolling_period; i++)
{
ena_crypto_rpi(rpi, rpik, tek_reported.rolling_start_interval_number + i);
for (int y = 0; y < beacons_count; y++)
{
ena_storage_get_beacon(y, &beacon);
if (memcmp(beacon.rpi, rpi, sizeof(ENA_KEY_LENGTH)) == 0)
{
match = true;
exposure_info.day = tek_reported.rolling_start_interval_number * ENA_TIME_WINDOW;
exposure_info.duration_minutes += (ENA_BEACON_TRESHOLD / 60);
exposure_info.typical_attenuation = (exposure_info.typical_attenuation + beacon.rssi) / 2;
if (beacon.rssi < exposure_info.min_attenuation)
{
exposure_info.min_attenuation = beacon.rssi;
}
}
}
}
if (match)
{
ena_storage_add_exposure_information(&exposure_info);
}
}
int ena_exposure_risk_score(ena_exposure_config_t *config, ena_exposure_parameter_t params)
{
int score = 1;
score *= config->transmission_risk_values[params.report_type];
// calc duration level
int duration_level = MINUTES_0;
if (params.duration > 0)
{
if (params.duration <= 5)
{
duration_level = MINUTES_5;
}
else if (params.duration <= 10)
{
duration_level = MINUTES_10;
}
if (params.duration <= 15)
{
duration_level = MINUTES_15;
}
if (params.duration <= 20)
{
duration_level = MINUTES_20;
}
if (params.duration <= 25)
{
duration_level = MINUTES_25;
}
if (params.duration <= 30)
{
duration_level = MINUTES_30;
}
else
{
duration_level = MINUTES_LONGER;
}
}
score *= config->duration_risk_values[duration_level];
// calc days level
int days_level = DAYS_14;
if (params.days < 2)
{
days_level = DAYS_0;
}
else if (params.days < 4)
{
days_level = DAYS_3;
}
else if (params.days < 6)
{
days_level = DAYS_5;
}
else if (params.days < 8)
{
days_level = DAYS_7;
}
else if (params.days < 10)
{
days_level = DAYS_9;
}
else if (params.days < 12)
{
days_level = DAYS_11;
}
else if (params.days < 14)
{
days_level = DAYS_13;
}
score *= config->days_risk_values[days_level];
// calc attenuation level
int attenuation_level = ATTENUATION_73;
if (params.attenuation <= 10)
{
attenuation_level = ATTENUATION_LOWER;
}
else if (params.attenuation <= 15)
{
attenuation_level = ATTENUATION_10;
}
else if (params.attenuation <= 27)
{
attenuation_level = ATTENUATION_15;
}
else if (params.attenuation <= 33)
{
attenuation_level = ATTENUATION_27;
}
else if (params.attenuation <= 51)
{
attenuation_level = ATTENUATION_33;
}
else if (params.attenuation <= 63)
{
attenuation_level = ATTENUATION_51;
}
else if (params.attenuation <= 73)
{
attenuation_level = ATTENUATION_63;
}
score *= config->attenuation_risk_values[attenuation_level];
if (score > 255)
{
score = 255;
}
return score;
}
void ena_exposure_summary(ena_exposure_config_t *config, ena_exposure_summary_t *summary)
{
uint32_t count = ena_storage_exposure_information_count();
uint32_t current_time = (uint32_t)time(NULL);
summary->days_since_last_exposure = INT_MAX;
summary->max_risk_score = 0;
summary->risk_score_sum = 0;
summary->num_exposures = count;
if (count == 0)
{
summary->days_since_last_exposure = -1;
}
ena_exposure_information_t exposure_info;
ena_exposure_parameter_t params;
for (int i = 0; i < count; i++)
{
ena_storage_get_exposure_information(i, &exposure_info);
params.days = (current_time - exposure_info.day) / (60 * 60 * 24); // difference in days
if (params.days < summary->days_since_last_exposure)
{
summary->days_since_last_exposure = params.days;
}
params.duration = exposure_info.duration_minutes;
params.attenuation = exposure_info.typical_attenuation;
int score = ena_exposure_risk_score(config, params);
if (score > summary->max_risk_score)
{
summary->max_risk_score = score;
}
summary->risk_score_sum += score;
}
ena_exposure_keyfiletest();
}
ena_exposure_config_t *ena_exposure_default_config(void)
{
return &DEFAULT_ENA_EXPOSURE_CONFIG;
}
+89 -64
View File
@@ -24,14 +24,15 @@
const int ENA_STORAGE_TEK_COUNT_ADDRESS = (ENA_STORAGE_START_ADDRESS); // starting address for TEK COUNT
const int ENA_STORAGE_TEK_START_ADDRESS = (ENA_STORAGE_TEK_COUNT_ADDRESS + sizeof(uint32_t));
const int ENA_STORAGE_TEMP_BEACONS_COUNT_ADDRESS = (ENA_STORAGE_TEK_START_ADDRESS + sizeof(ena_tek_t) * ENA_STORAGE_TEK_MAX);
const int ENA_STORAGE_EXPOSURE_INFORMATION_COUNT_ADDRESS = (ENA_STORAGE_TEK_START_ADDRESS + sizeof(ena_tek_t) * ENA_STORAGE_TEK_MAX);
const int ENA_STORAGE_EXPOSURE_INFORMATION_START_ADDRESS = (ENA_STORAGE_EXPOSURE_INFORMATION_COUNT_ADDRESS + sizeof(uint32_t));
const int ENA_STORAGE_TEMP_BEACONS_COUNT_ADDRESS = (ENA_STORAGE_EXPOSURE_INFORMATION_COUNT_ADDRESS + sizeof(ena_exposure_information_t) * ENA_STORAGE_EXPOSURE_INFORMATION_MAX);
const int ENA_STORAGE_TEMP_BEACONS_START_ADDRESS = (ENA_STORAGE_TEMP_BEACONS_COUNT_ADDRESS + sizeof(uint32_t));
const int ENA_STORAGE_BEACONS_COUNT_ADDRESS = (ENA_STORAGE_TEMP_BEACONS_START_ADDRESS + sizeof(ena_temp_beacon_t) * ENA_STORAGE_TEMP_BEACONS_MAX);
const int ENA_STORAGE_BEACONS_COUNT_ADDRESS = (ENA_STORAGE_TEMP_BEACONS_START_ADDRESS + sizeof(ena_beacon_t) * ENA_STORAGE_TEMP_BEACONS_MAX);
const int ENA_STORAGE_BEACONS_START_ADDRESS = (ENA_STORAGE_BEACONS_COUNT_ADDRESS + sizeof(uint32_t));
void ena_storage_read(size_t address, void *data, size_t size)
{
ESP_LOGD(ENA_STORAGE_LOG, "START ena_storage_read");
const esp_partition_t *partition = esp_partition_find_first(
ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, ENA_STORAGE_PARTITION_NAME);
assert(partition);
@@ -39,12 +40,10 @@ void ena_storage_read(size_t address, void *data, size_t size)
vTaskDelay(1);
ESP_LOGD(ENA_STORAGE_LOG, "read data at %u", address);
ESP_LOG_BUFFER_HEXDUMP(ENA_STORAGE_LOG, data, size, ESP_LOG_DEBUG);
ESP_LOGD(ENA_STORAGE_LOG, "END ena_storage_read");
}
void ena_storage_write(size_t address, void *data, size_t size)
{
ESP_LOGD(ENA_STORAGE_LOG, "START ena_storage_write");
const int block_num = address / BLOCK_SIZE;
// check for overflow
if (address + size <= (block_num + 1) * BLOCK_SIZE)
@@ -90,13 +89,10 @@ void ena_storage_write(size_t address, void *data, size_t size)
ena_storage_write(block2_address, data2, data2_size);
free(data2);
}
ESP_LOGD(ENA_STORAGE_LOG, "END ena_storage_write");
}
void ena_storage_shift_delete(size_t address, size_t end_address, size_t size)
{
ESP_LOGD(ENA_STORAGE_LOG, "START ena_storage_shift_delete");
int block_num_start = address / BLOCK_SIZE;
// check for overflow
if (address + size <= (block_num_start + 1) * BLOCK_SIZE)
@@ -146,12 +142,10 @@ void ena_storage_shift_delete(size_t address, size_t end_address, size_t size)
ena_storage_shift_delete(block1_address, block2_address, data1_size);
ena_storage_shift_delete(block2_address, end_address - data1_size, data2_size);
}
ESP_LOGD(ENA_STORAGE_LOG, "END ena_storage_shift_delete");
}
uint32_t ena_storage_read_last_tek(ena_tek_t *tek)
{
ESP_LOGD(ENA_STORAGE_LOG, "START ena_storage_read_tek");
uint32_t tek_count = 0;
ena_storage_read(ENA_STORAGE_TEK_COUNT_ADDRESS, &tek_count, sizeof(uint32_t));
if (tek_count < 1)
@@ -163,14 +157,11 @@ uint32_t ena_storage_read_last_tek(ena_tek_t *tek)
ESP_LOGD(ENA_STORAGE_LOG, "read last tek %u:", tek->enin);
ESP_LOG_BUFFER_HEXDUMP(ENA_STORAGE_LOG, tek->key_data, ENA_KEY_LENGTH, ESP_LOG_DEBUG);
ESP_LOGD(ENA_STORAGE_LOG, "END ena_storage_read_tek");
return tek_count;
}
void ena_storage_write_tek(ena_tek_t *tek)
{
ESP_LOGD(ENA_STORAGE_LOG, "START ena_storage_write_tek");
uint32_t tek_count = 0;
ena_storage_read(ENA_STORAGE_TEK_COUNT_ADDRESS, &tek_count, sizeof(uint32_t));
uint8_t index = (tek_count % ENA_STORAGE_TEK_MAX);
@@ -181,33 +172,49 @@ void ena_storage_write_tek(ena_tek_t *tek)
ESP_LOGD(ENA_STORAGE_LOG, "write tek: ENIN %u", tek->enin);
ESP_LOG_BUFFER_HEXDUMP(ENA_STORAGE_LOG, tek->key_data, ENA_KEY_LENGTH, ESP_LOG_DEBUG);
ESP_LOGD(ENA_STORAGE_LOG, "END ena_storage_write_tek");
}
uint32_t ena_storage_exposure_information_count(void)
{
uint32_t count = 0;
ena_storage_read(ENA_STORAGE_EXPOSURE_INFORMATION_COUNT_ADDRESS, &count, sizeof(uint32_t));
ESP_LOGD(ENA_STORAGE_LOG, "read exposure information count: %u", count);
return count;
}
void ena_storage_get_exposure_information(uint32_t index, ena_exposure_information_t *exposure_info)
{
ena_storage_read(ENA_STORAGE_EXPOSURE_INFORMATION_START_ADDRESS + index * sizeof(ena_exposure_information_t), exposure_info, sizeof(ena_exposure_information_t));
ESP_LOGD(ENA_STORAGE_LOG, "read exporuse information: day %u, duration %d", exposure_info->day, exposure_info->duration_minutes);
}
void ena_storage_add_exposure_information(ena_exposure_information_t *exposure_info)
{
uint32_t count = ena_storage_exposure_information_count();
ena_storage_write(ENA_STORAGE_EXPOSURE_INFORMATION_START_ADDRESS + count * sizeof(ena_exposure_information_t), exposure_info, sizeof(ena_exposure_information_t));
count++;
ena_storage_write(ENA_STORAGE_EXPOSURE_INFORMATION_COUNT_ADDRESS, &count, sizeof(uint32_t));
ESP_LOGD(ENA_STORAGE_LOG, "write exposure info: day %u, duration %d", exposure_info->day, exposure_info->duration_minutes);
}
uint32_t ena_storage_temp_beacons_count(void)
{
ESP_LOGD(ENA_STORAGE_LOG, "START ena_storage_temp_beacons_count");
uint32_t count = 0;
ena_storage_read(ENA_STORAGE_TEMP_BEACONS_COUNT_ADDRESS, &count, sizeof(uint32_t));
ESP_LOGD(ENA_STORAGE_LOG, "read temp contancts count: %u", count);
ESP_LOGD(ENA_STORAGE_LOG, "END ena_storage_temp_beacons_count");
ESP_LOGD(ENA_STORAGE_LOG, "read temp beacons count: %u", count);
return count;
}
void ena_storage_get_temp_beacon(uint32_t index, ena_temp_beacon_t *beacon)
void ena_storage_get_temp_beacon(uint32_t index, ena_beacon_t *beacon)
{
ESP_LOGD(ENA_STORAGE_LOG, "START ena_storage_read_temp_beacon");
ena_storage_read(ENA_STORAGE_TEMP_BEACONS_START_ADDRESS + index * sizeof(ena_temp_beacon_t), beacon, sizeof(ena_temp_beacon_t));
ena_storage_read(ENA_STORAGE_TEMP_BEACONS_START_ADDRESS + index * sizeof(ena_beacon_t), beacon, sizeof(ena_beacon_t));
ESP_LOGD(ENA_STORAGE_LOG, "read temp beacon: first %u, last %u and rssi %d", beacon->timestamp_first, beacon->timestamp_last, beacon->rssi);
ESP_LOG_BUFFER_HEXDUMP(ENA_STORAGE_LOG, beacon->rpi, ENA_KEY_LENGTH, ESP_LOG_DEBUG);
ESP_LOG_BUFFER_HEXDUMP(ENA_STORAGE_LOG, beacon->aem, ENA_AEM_METADATA_LENGTH, ESP_LOG_DEBUG);
ESP_LOGD(ENA_STORAGE_LOG, "END ena_storage_read_temp_beacon");
}
uint32_t ena_storage_add_temp_beacon(ena_temp_beacon_t *beacon)
uint32_t ena_storage_add_temp_beacon(ena_beacon_t *beacon)
{
ESP_LOGD(ENA_STORAGE_LOG, "START ena_storage_add_temp_beacon");
uint32_t count = ena_storage_temp_beacons_count();
// overwrite older temporary beacons?!
uint8_t index = count % ENA_STORAGE_TEMP_BEACONS_MAX;
@@ -217,73 +224,60 @@ uint32_t ena_storage_add_temp_beacon(ena_temp_beacon_t *beacon)
ESP_LOG_BUFFER_HEXDUMP(ENA_STORAGE_LOG, beacon->aem, ENA_AEM_METADATA_LENGTH, ESP_LOG_DEBUG);
count++;
ena_storage_write(ENA_STORAGE_TEMP_BEACONS_COUNT_ADDRESS, &count, sizeof(uint32_t));
ESP_LOGD(ENA_STORAGE_LOG, "END ena_storage_add_temp_beacon");
return count - 1;
}
void ena_storage_set_temp_beacon(uint32_t index, ena_temp_beacon_t *beacon)
void ena_storage_set_temp_beacon(uint32_t index, ena_beacon_t *beacon)
{
ESP_LOGD(ENA_STORAGE_LOG, "START ena_storage_set_temp_beacon");
ena_storage_write(ENA_STORAGE_TEMP_BEACONS_START_ADDRESS + index * sizeof(ena_temp_beacon_t), beacon, sizeof(ena_temp_beacon_t));
ena_storage_write(ENA_STORAGE_TEMP_BEACONS_START_ADDRESS + index * sizeof(ena_beacon_t), beacon, sizeof(ena_beacon_t));
ESP_LOGD(ENA_STORAGE_LOG, "set temp beacon at %u: first %u, last %u and rssi %d", index, beacon->timestamp_first, beacon->timestamp_last, beacon->rssi);
ESP_LOG_BUFFER_HEXDUMP(ENA_STORAGE_LOG, beacon->rpi, ENA_KEY_LENGTH, ESP_LOG_DEBUG);
ESP_LOG_BUFFER_HEXDUMP(ENA_STORAGE_LOG, beacon->aem, ENA_AEM_METADATA_LENGTH, ESP_LOG_DEBUG);
ESP_LOGD(ENA_STORAGE_LOG, "END ena_storage_set_temp_beacon");
}
void ena_storage_remove_temp_beacon(uint32_t index)
{
ESP_LOGD(ENA_STORAGE_LOG, "START ena_storage_remove_temp_beacon");
uint32_t count = ena_storage_temp_beacons_count();
size_t address_from = ENA_STORAGE_TEMP_BEACONS_START_ADDRESS + index * sizeof(ena_temp_beacon_t);
size_t address_to = ENA_STORAGE_TEMP_BEACONS_START_ADDRESS + count * sizeof(ena_temp_beacon_t);
size_t address_from = ENA_STORAGE_TEMP_BEACONS_START_ADDRESS + index * sizeof(ena_beacon_t);
size_t address_to = ENA_STORAGE_TEMP_BEACONS_START_ADDRESS + count * sizeof(ena_beacon_t);
ena_storage_shift_delete(address_from, address_to, sizeof(ena_temp_beacon_t));
ena_storage_shift_delete(address_from, address_to, sizeof(ena_beacon_t));
count--;
ena_storage_write(ENA_STORAGE_TEMP_BEACONS_COUNT_ADDRESS, &count, sizeof(uint32_t));
ESP_LOGD(ENA_STORAGE_LOG, "remove temp beacon: %u", index);
ESP_LOGD(ENA_STORAGE_LOG, "END ena_storage_remove_temp_beacon");
}
uint32_t ena_storage_beacons_count(void)
{
ESP_LOGD(ENA_STORAGE_LOG, "START ena_storage_beacons_count");
uint32_t count = 0;
ena_storage_read(ENA_STORAGE_BEACONS_COUNT_ADDRESS, &count, sizeof(uint32_t));
ESP_LOGD(ENA_STORAGE_LOG, "read contancts count: %u", count);
ESP_LOGD(ENA_STORAGE_LOG, "END ena_storage_beacons_count");
return count;
}
void ena_storage_get_beacon(uint32_t index, ena_beacon_t *beacon)
{
ESP_LOGD(ENA_STORAGE_LOG, "START ena_storage_read_beacon");
ena_storage_read(ENA_STORAGE_BEACONS_START_ADDRESS + index * sizeof(ena_beacon_t), beacon, sizeof(ena_beacon_t));
ESP_LOGD(ENA_STORAGE_LOG, "read beacon: timestamp %u and rssi %d", beacon->timestamp, beacon->rssi);
ESP_LOGD(ENA_STORAGE_LOG, "read beacon: first %u, last %u and rssi %d", beacon->timestamp_first, beacon->timestamp_last, beacon->rssi);
ESP_LOG_BUFFER_HEXDUMP(ENA_STORAGE_LOG, beacon->rpi, ENA_KEY_LENGTH, ESP_LOG_DEBUG);
ESP_LOG_BUFFER_HEXDUMP(ENA_STORAGE_LOG, beacon->aem, ENA_AEM_METADATA_LENGTH, ESP_LOG_DEBUG);
ESP_LOGD(ENA_STORAGE_LOG, "END ena_storage_read_beacon");
}
void ena_storage_add_beacon(ena_beacon_t *beacon)
{
ESP_LOGD(ENA_STORAGE_LOG, "START ena_storage_write_beacon");
ESP_LOG_BUFFER_HEXDUMP(ENA_STORAGE_LOG, beacon->rpi, ENA_KEY_LENGTH, ESP_LOG_DEBUG);
uint32_t count = ena_storage_beacons_count();
ena_storage_write(ENA_STORAGE_BEACONS_START_ADDRESS + count * sizeof(ena_beacon_t), beacon, sizeof(ena_beacon_t));
count++;
ena_storage_write(ENA_STORAGE_BEACONS_COUNT_ADDRESS, &count, sizeof(uint32_t));
ESP_LOGD(ENA_STORAGE_LOG, "write beacon: timestamp %u and rssi %d", beacon->timestamp, beacon->rssi);
ESP_LOGD(ENA_STORAGE_LOG, "write beacon: first %u, last %u and rssi %d", beacon->timestamp_first, beacon->timestamp_last, beacon->rssi);
ESP_LOG_BUFFER_HEXDUMP(ENA_STORAGE_LOG, beacon->rpi, ENA_KEY_LENGTH, ESP_LOG_DEBUG);
ESP_LOG_BUFFER_HEXDUMP(ENA_STORAGE_LOG, beacon->aem, ENA_AEM_METADATA_LENGTH, ESP_LOG_DEBUG);
ESP_LOGD(ENA_STORAGE_LOG, "END ena_storage_write_beacon");
}
void ena_storage_erase(void)
{
ESP_LOGD(ENA_STORAGE_LOG, "START ena_storage_erase");
const esp_partition_t *partition = esp_partition_find_first(
ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, ENA_STORAGE_PARTITION_NAME);
assert(partition);
@@ -292,23 +286,20 @@ void ena_storage_erase(void)
uint32_t count = 0;
ena_storage_write(ENA_STORAGE_TEK_COUNT_ADDRESS, &count, sizeof(uint32_t));
ena_storage_write(ENA_STORAGE_EXPOSURE_INFORMATION_COUNT_ADDRESS, &count, sizeof(uint32_t));
ena_storage_write(ENA_STORAGE_TEMP_BEACONS_COUNT_ADDRESS, &count, sizeof(uint32_t));
ena_storage_write(ENA_STORAGE_BEACONS_COUNT_ADDRESS, &count, sizeof(uint32_t));
ESP_LOGD(ENA_STORAGE_LOG, "END ena_storage_erase");
}
void ena_storage_erase_tek(void)
{
uint32_t count = 0;
ena_storage_read(ENA_STORAGE_TEK_COUNT_ADDRESS, &count, sizeof(uint32_t));
uint32_t stored = ENA_STORAGE_TEK_MAX;
ESP_LOGD(ENA_STORAGE_LOG, "START ena_storage_erase_teks");
uint32_t tek_count = 0;
ena_storage_read(ENA_STORAGE_TEK_COUNT_ADDRESS, &tek_count, sizeof(uint32_t));
uint8_t stored = ENA_STORAGE_TEK_MAX;
if (tek_count < ENA_STORAGE_TEK_MAX)
if (count < ENA_STORAGE_TEK_MAX)
{
stored = tek_count;
stored = count;
}
size_t size = sizeof(uint32_t) + stored * sizeof(ena_tek_t);
@@ -316,12 +307,27 @@ void ena_storage_erase_tek(void)
ena_storage_write(ENA_STORAGE_TEK_COUNT_ADDRESS, zeros, size);
free(zeros);
ESP_LOGI(ENA_STORAGE_LOG, "erased %d teks (size %u at %u)", stored, size, ENA_STORAGE_TEK_COUNT_ADDRESS);
ESP_LOGD(ENA_STORAGE_LOG, "END ena_storage_erase_teks");
}
void ena_storage_erase_exposure_information(void)
{
uint32_t count = ena_storage_exposure_information_count();
uint32_t stored = ENA_STORAGE_EXPOSURE_INFORMATION_MAX;
if (count < ENA_STORAGE_EXPOSURE_INFORMATION_MAX)
{
stored = count;
}
size_t size = sizeof(uint32_t) + stored * sizeof(ena_exposure_information_t);
uint8_t *zeros = calloc(size, sizeof(uint8_t));
ena_storage_write(ENA_STORAGE_EXPOSURE_INFORMATION_COUNT_ADDRESS, zeros, size);
free(zeros);
ESP_LOGI(ENA_STORAGE_LOG, "erased %d exposure information (size %u at %u)", stored, size, ENA_STORAGE_EXPOSURE_INFORMATION_COUNT_ADDRESS);
}
void ena_storage_erase_temporary_beacon(void)
{
ESP_LOGD(ENA_STORAGE_LOG, "START ena_storage_erase_temporary_beacons");
uint32_t beacon_count = 0;
ena_storage_read(ENA_STORAGE_TEMP_BEACONS_COUNT_ADDRESS, &beacon_count, sizeof(uint32_t));
uint32_t stored = ENA_STORAGE_TEMP_BEACONS_MAX;
@@ -331,18 +337,16 @@ void ena_storage_erase_temporary_beacon(void)
stored = beacon_count;
}
size_t size = sizeof(uint32_t) + stored * sizeof(ena_temp_beacon_t);
size_t size = sizeof(uint32_t) + stored * sizeof(ena_beacon_t);
uint8_t *zeros = calloc(size, sizeof(uint8_t));
ena_storage_write(ENA_STORAGE_TEMP_BEACONS_COUNT_ADDRESS, zeros, size);
free(zeros);
ESP_LOGI(ENA_STORAGE_LOG, "erased %d temporary beacons (size %u at %u)", stored, size, ENA_STORAGE_TEMP_BEACONS_COUNT_ADDRESS);
ESP_LOGD(ENA_STORAGE_LOG, "END ena_storage_erase_temporary_beacons");
}
void ena_storage_erase_beacon(void)
{
ESP_LOGD(ENA_STORAGE_LOG, "START ena_storage_erase_beacon");
uint32_t beacon_count = 0;
ena_storage_read(ENA_STORAGE_BEACONS_COUNT_ADDRESS, &beacon_count, sizeof(uint32_t));
@@ -352,7 +356,6 @@ void ena_storage_erase_beacon(void)
free(zeros);
ESP_LOGI(ENA_STORAGE_LOG, "erased %d beacons (size %u at %u)", beacon_count, size, ENA_STORAGE_BEACONS_COUNT_ADDRESS);
ESP_LOGD(ENA_STORAGE_LOG, "END ena_storage_erase_beacon");
}
void ena_storage_dump_hash_array(uint8_t *data, size_t size)
@@ -370,12 +373,12 @@ void ena_storage_dump_hash_array(uint8_t *data, size_t size)
}
}
void ena_storage_dump_tek(void)
void ena_storage_dump_teks(void)
{
ena_tek_t tek;
uint32_t tek_count = 0;
ena_storage_read(ENA_STORAGE_TEK_COUNT_ADDRESS, &tek_count, sizeof(uint32_t));
uint8_t stored = ENA_STORAGE_TEK_MAX;
uint32_t stored = ENA_STORAGE_TEK_MAX;
if (tek_count < ENA_STORAGE_TEK_MAX)
{
@@ -395,9 +398,31 @@ void ena_storage_dump_tek(void)
}
}
void ena_storage_dump_exposure_information(void)
{
ena_exposure_information_t exposure_info;
uint32_t exposure_information_count = ena_storage_exposure_information_count();
uint32_t stored = ENA_STORAGE_EXPOSURE_INFORMATION_MAX;
if (exposure_information_count < ENA_STORAGE_EXPOSURE_INFORMATION_MAX)
{
stored = exposure_information_count;
}
ESP_LOGD(ENA_STORAGE_LOG, "%u exposure information (%u stored)\n", exposure_information_count, stored);
printf("#,day,typical_attenuation,min_attenuation,duration_minutes,report_type\n");
for (int i = 0; i < stored; i++)
{
size_t address = ENA_STORAGE_EXPOSURE_INFORMATION_START_ADDRESS + i * sizeof(ena_exposure_information_t);
ena_storage_read(address, &exposure_info, sizeof(ena_exposure_information_t));
printf("%d,%u,%d,%d,%d,%d\n", i, exposure_info.day, exposure_info.typical_attenuation, exposure_info.min_attenuation, exposure_info.duration_minutes, exposure_info.report_type);
}
}
void ena_storage_dump_temp_beacons(void)
{
ena_temp_beacon_t beacon;
ena_beacon_t beacon;
uint32_t beacon_count = 0;
ena_storage_read(ENA_STORAGE_TEMP_BEACONS_COUNT_ADDRESS, &beacon_count, sizeof(uint32_t));
uint32_t stored = ENA_STORAGE_TEMP_BEACONS_MAX;
@@ -426,11 +451,11 @@ void ena_storage_dump_beacons(void)
uint32_t beacon_count = 0;
ena_storage_read(ENA_STORAGE_BEACONS_COUNT_ADDRESS, &beacon_count, sizeof(uint32_t));
ESP_LOGD(ENA_STORAGE_LOG, "%u beacons\n", beacon_count);
printf("#,timestamp,rpi,aem,rssi\n");
printf("#,timestamp_first,timestamp_last,rpi,aem,rssi\n");
for (int i = 0; i < beacon_count; i++)
{
ena_storage_get_beacon(i, &beacon);
printf("%d,%u,", i, beacon.timestamp);
printf("%d,%u,%u,", i, beacon.timestamp_first, beacon.timestamp_last);
ena_storage_dump_hash_array(beacon.rpi, ENA_KEY_LENGTH);
printf(",");
ena_storage_dump_hash_array(beacon.aem, ENA_AEM_METADATA_LENGTH);
+5 -4
View File
@@ -49,8 +49,8 @@ void ena_next_rpi_timestamp(uint32_t timestamp)
void ena_run(void *pvParameter)
{
uint32_t unix_timestamp = 0;
uint32_t current_enin = 0;
static uint32_t unix_timestamp = 0;
static uint32_t current_enin = 0;
while (1)
{
unix_timestamp = (uint32_t)time(NULL);
@@ -97,6 +97,7 @@ void ena_start(void)
#if (CONFIG_ENA_STORAGE_ERASE)
ena_storage_erase();
#endif
// init NVS for BLE
esp_err_t ret;
ret = nvs_flash_init();
@@ -146,7 +147,7 @@ void ena_start(void)
ena_crypto_init();
uint32_t unix_timestamp = (uint32_t)time(NULL);
uint32_t current_enin = ena_crypto_enin(unix_timestamp);
uint32_t tek_count = ena_storage_read_last_tek(&last_tek);
@@ -172,5 +173,5 @@ void ena_start(void)
ena_bluetooth_scan_start(ENA_SCANNING_TIME);
// what is a good stack size here?
xTaskCreate(&ena_run, "ena_run", configMINIMAL_STACK_SIZE * 8, NULL, 5, NULL);
xTaskCreate(&ena_run, "ena_run", ENA_RAM, NULL, 5, NULL);
}
+177
View File
@@ -0,0 +1,177 @@
// Copyright 2020 Lukas Haubaum
//
// Licensed under the GNU Affero General Public License, Version 3;
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.gnu.org/licenses/agpl-3.0.html
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _ena_EXPOSURE_H_
#define _ena_EXPOSURE_H_
#include <stdio.h>
#include "ena-crypto.h"
#define ENA_EXPOSURE_LOG "ESP-ENA-exposure" // TAG for Logging
/**
* @brief report type
*/
typedef enum
{
UNKNOWN = 0,
CONFIRMED_TEST_LOW = 1,
CONFIRMED_TEST_STANDARD = 2,
CONFIRMED_TEST_HIGH = 3,
CONFIRMED_CLINICAL_DIAGNOSIS = 4,
SELF_REPORT = 5,
NEGATIVE = 6,
RECURSIVE = 7,
} ena_report_type_t;
/**
* @brief duration risk
*/
typedef enum
{
MINUTES_0 = 0, // D = 0 min
MINUTES_5 = 1, // D <= 5 min
MINUTES_10 = 2, // D <= 10 min
MINUTES_15 = 3, // D <= 15 min
MINUTES_20 = 4, // D <= 20 min
MINUTES_25 = 5, // D <= 25 min
MINUTES_30 = 6, // D <= 30 min
MINUTES_LONGER = 7, // D > 30 min
} ena_duration_risk_t;
/**
* @brief day risk
*/
typedef enum
{
DAYS_14 = 0, // >= 14 days
DAYS_13 = 1, // 12-13 days
DAYS_11 = 2, // 10-11 days
DAYS_9 = 3, // 8-9 days
DAYS_7 = 4, // 6-7 days
DAYS_5 = 5, // 4-5 days
DAYS_3 = 6, // 2-3 days
DAYS_0 = 7, // 0-1 days
} ena_day_risk_t;
/**
* @brief attenuation risk
*/
typedef enum
{
ATTENUATION_73 = 0, // A > 73 dB
ATTENUATION_63 = 1, // 73 >= A > 63
ATTENUATION_51 = 2, // 63 >= A > 61
ATTENUATION_33 = 3, // 51 >= A > 33
ATTENUATION_27 = 4, // 33 >= A > 27
ATTENUATION_15 = 5, // 27 >= A > 15
ATTENUATION_10 = 6, // 15 >= A > 10
ATTENUATION_LOWER = 7, // A <= 10
} ena_attenuation_risk_t;
/**
* @brief risk level from 0-8
*/
typedef enum
{
ZERO = 0,
MINIMAL = 1,
VERY_LOW = 2,
LOW = 3,
MEDIUM = 4,
INCREASED = 5,
HIGH = 6,
VERY_HIGH = 7,
MAXIMUM = 8,
} ena_risk_level_t;
/**
* @brief structure for exposure configuration
*
* The exposure configuration is used to calculate the risk score.
*/
typedef struct __attribute__((__packed__))
{
uint8_t transmission_risk_values[8];
uint8_t duration_risk_values[8];
uint8_t days_risk_values[8];
uint8_t attenuation_risk_values[8];
} ena_exposure_config_t;
/**
* @brief structure for exposure parameter
*
* These parameter are obtained from an exposure information to calculate the risk score.
*/
typedef struct __attribute__((__packed__))
{
ena_report_type_t report_type;
int days;
int duration;
int attenuation;
} ena_exposure_parameter_t;
/**
* @brief structure for exposure summary
*
* This represents the current state of all exposures.
*/
typedef struct __attribute__((__packed__))
{
int days_since_last_exposure; // Number of days since the most recent exposure.
int num_exposures; // Number of all exposure information
int max_risk_score; // max. risk score of all exposure information
int risk_score_sum; // sum of all risk_scores
} ena_exposure_summary_t;
/**
* @brief structure for a reported TEK
*/
typedef struct __attribute__((__packed__))
{
uint8_t key_data[ENA_KEY_LENGTH]; // Key of infected user
uint32_t rolling_start_interval_number; // The interval number since epoch for which a key starts
uint8_t rolling_period; // Increments of 10 minutes describing how long a key is valid
ena_report_type_t report_type; // Type of diagnosis associated with a key.
uint32_t days_since_onset_of_symptoms; // Number of days elapsed between symptom onset and the TEK being used. E.g. 2 means TEK is 2 days after onset of symptoms.
} ena_tek_reported_t;
/**
* @brief check for exposure for a reported tek and store exposure information on finding
*
* @param[in] tek_reported the reported tek to check
*/
void ena_exposure_check(ena_tek_reported_t tek_reported);
/**
* @brief calculate risk score
*
* @param[in] config the exposure configuration used for calculating score
* @param[in] params the exposure parameter to calculate with
*/
int ena_exposure_risk_score(ena_exposure_config_t *config, ena_exposure_parameter_t params);
/**
* @brief returns the current exposure summary
*
* @param[in] config the exposure configuration used for calculating scores
* @param[out] summary pointer to exposure summary to write to
*/
void ena_exposure_summary(ena_exposure_config_t *config, ena_exposure_summary_t *summary);
/**
* @brief return a default exposure configuration
*/
ena_exposure_config_t *ena_exposure_default_config(void);
#endif
+60 -18
View File
@@ -16,11 +16,12 @@
#include "ena-crypto.h"
#define ENA_STORAGE_LOG "ESP-ENA-storage" // TAG for Logging
#define ENA_STORAGE_PARTITION_NAME (CONFIG_ENA_STORAGE_PARTITION_NAME) // name of partition to use for storing
#define ENA_STORAGE_START_ADDRESS (CONFIG_ENA_STORAGE_START_ADDRESS) // start address of storage
#define ENA_STORAGE_TEK_MAX (CONFIG_ENA_STORAGE_TEK_MAX) // Period of storing TEKs // length of a stored beacon -> RPI keysize + AEM size + 4 Bytes for ENIN + 4 Bytes for RSSI
#define ENA_STORAGE_TEMP_BEACONS_MAX (CONFIG_ENA_STORAGE_TEMP_BEACONS_MAX) // Maximum number of temporary stored beacons
#define ENA_STORAGE_LOG "ESP-ENA-storage" // TAG for Logging
#define ENA_STORAGE_PARTITION_NAME (CONFIG_ENA_STORAGE_PARTITION_NAME) // name of partition to use for storing
#define ENA_STORAGE_START_ADDRESS (CONFIG_ENA_STORAGE_START_ADDRESS) // start address of storage
#define ENA_STORAGE_TEK_MAX (CONFIG_ENA_STORAGE_TEK_MAX) // Period of storing TEKs // length of a stored beacon -> RPI keysize + AEM size + 4 Bytes for ENIN + 4 Bytes for RSSI
#define ENA_STORAGE_TEMP_BEACONS_MAX (CONFIG_ENA_STORAGE_TEMP_BEACONS_MAX) // Maximum number of temporary stored beacons // length of a stored beacon -> RPI keysize + AEM size + 4 Bytes for ENIN + 4 Bytes for RSSI
#define ENA_STORAGE_EXPOSURE_INFORMATION_MAX (CONFIG_ENA_STORAGE_EXPOSURE_INFORMATION_MAX) // Maximum number of stored exposure information
/**
* @brief structure for TEK
@@ -33,7 +34,7 @@ typedef struct __attribute__((__packed__))
} ena_tek_t;
/**
* @brief sturcture for storing a temporary beacon
* @brief sturcture for storing a beacons
*/
typedef struct __attribute__((__packed__))
{
@@ -42,18 +43,19 @@ typedef struct __attribute__((__packed__))
uint32_t timestamp_first; // timestamp of first recognition
uint32_t timestamp_last; // timestamp of last recognition
int rssi; // average measured RSSI
} ena_temp_beacon_t;
} ena_beacon_t;
/**
* @brief sturcture for permanently storing a beacon after threshold reached
* @brief structure for storing a Exposure Information (combined ExposureInformation, ExposureWindow and ScanInstance from Google API >= 1.5)
*/
typedef struct __attribute__((__packed__))
{
uint8_t rpi[ENA_KEY_LENGTH]; // received RPI of beacon
uint8_t aem[ENA_AEM_METADATA_LENGTH]; // received AEM of beacon
uint32_t timestamp; // timestamp of last recognition
int rssi; // average measured RSSI
} ena_beacon_t;
uint32_t day; // Day of the exposure, using UTC, encapsulated as the time of the beginning of that day.
int typical_attenuation; // Aggregation of the attenuations of all of a given diagnosis key's beacons received during the scan, in dB.
int min_attenuation; // Minimum attenuation of all of a given diagnosis key's beacons received during the scan, in dB.
int duration_minutes; //The duration of the exposure in minutes.
int report_type; // Type of diagnosis associated with a key.
} ena_exposure_information_t;
/**
* @brief read bytes at given address
@@ -101,6 +103,29 @@ uint32_t ena_storage_read_last_tek(ena_tek_t *tek);
*/
void ena_storage_write_tek(ena_tek_t *tek);
/**
* @brief get number of stored exposure information
*
* @return
* total number of exposure information stored
*/
uint32_t ena_storage_exposure_information_count(void);
/**
* @brief get exposure information at given index
*
* @param[in] index the index of the exposure information to read
* @param[out] exposure_info pointer to exposure information to write to
*/
void ena_storage_get_exposure_information(uint32_t index, ena_exposure_information_t *exposure_info);
/**
* @brief store exposure information
*
* @param[in] exposure_info new exposure information to store
*/
void ena_storage_add_exposure_information(ena_exposure_information_t *exposure_info);
/**
* @brief get number of stored temporary beacons
*
@@ -113,9 +138,9 @@ uint32_t ena_storage_temp_beacons_count(void);
* @brief get temporary beacon at given index
*
* @param[in] index the index of the temporary beacon to read
* @param[out] beacon pointer to temporary to write to
* @param[out] beacon pointer to temporary beacon to write to
*/
void ena_storage_get_temp_beacon(uint32_t index, ena_temp_beacon_t *beacon);
void ena_storage_get_temp_beacon(uint32_t index, ena_beacon_t *beacon);
/**
* @brief store temporary beacon
@@ -125,7 +150,7 @@ void ena_storage_get_temp_beacon(uint32_t index, ena_temp_beacon_t *beacon);
* @return
* index of new stored beacon
*/
uint32_t ena_storage_add_temp_beacon(ena_temp_beacon_t *beacon);
uint32_t ena_storage_add_temp_beacon(ena_beacon_t *beacon);
/**
* @brief store temporary beacon at given index
@@ -133,7 +158,7 @@ uint32_t ena_storage_add_temp_beacon(ena_temp_beacon_t *beacon);
* @param[in] index the index of the temporary beacon to overwrite
* @param[in] beacon temporary beacon to store
*/
void ena_storage_set_temp_beacon(uint32_t index, ena_temp_beacon_t *beacon);
void ena_storage_set_temp_beacon(uint32_t index, ena_beacon_t *beacon);
/**
* @brief remove temporary beacon at given index
@@ -180,6 +205,14 @@ void ena_storage_erase(void);
*/
void ena_storage_erase_tek(void);
/**
* @brief erase all stored exposure information
*
* This function deletes all stored exposure information and resets counter to zero.
*/
void ena_storage_erase_exposure_information(void);
/**
* @brief erase all stored temporary beacons
*
@@ -200,7 +233,16 @@ void ena_storage_erase_beacon(void);
* This function prints all stored TEKs to serial output in
* the following CSV format: #,enin,tek
*/
void ena_storage_dump_tek(void);
void ena_storage_dump_teks(void);
/**
* @brief dump all stored exposure information to serial output
*
* This function prints all stored exposure information to serial output in
* the following CSV format: #,day,typical_attenuation,min_attenuation,duration_minutes,report_type
*/
void ena_storage_dump_exposure_information(void);
/**
* @brief dump all stored temporary beacons to serial output
+1
View File
@@ -15,6 +15,7 @@
#define _ena_H_
#define ENA_LOG "ESP-ENA" // TAG for Logging
#define ENA_RAM (CONFIG_ENA_RAM) // change advertising payload and therefore the BT address
#define ENA_BT_ROTATION_TIMEOUT_INTERVAL (CONFIG_ENA_BT_ROTATION_TIMEOUT_INTERVAL) // change advertising payload and therefore the BT address
#define ENA_BT_RANDOMIZE_ROTATION_TIMEOUT_INTERVAL (CONFIG_ENA_BT_RANDOMIZE_ROTATION_TIMEOUT_INTERVAL) // random intervall change for BT address change
Binary file not shown.
Binary file not shown.