mirror of
https://github.com/Lurkars/esp-ena.git
synced 2026-05-08 20:10:37 +02:00
added Exposure code, DS3231, SSD1306, interfaces, started with protocol buffers impl.
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user