rename interface component, update docs, added cleanup of old beacons

This commit is contained in:
Lurkars
2020-07-27 16:54:51 +02:00
parent 7dacb93369
commit 4e696f2fb4
30 changed files with 484 additions and 333 deletions
+78 -74
View File
@@ -1,90 +1,94 @@
menu "Exposure Notification API"
menu "Storage"
config ENA_STORAGE_DUMP
bool "Dump storage"
default false
help
Dump storage (stored TEKs, temp. beacons and perm. beacons) to serial output after scan.
config ENA_STORAGE_TEK_MAX
int "Max. TEKs"
default 14
help
Defines the maximum number of TEKs to be stored. (Default 14 [14 * 144 => 14 days])
menu "Storage"
config ENA_STORAGE_DUMP
bool "Dump storage"
default false
help
Dump storage (stored TEKs, temp. beacons and perm. beacons) to serial output after scan.
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_TEK_MAX
int "Max. TEKs"
default 14
help
Defines the maximum number of TEKs to be stored. (Default 14 [14 * 144 => 14 days])
config ENA_STORAGE_TEMP_BEACONS_MAX
int "Max. temporary beacons"
default 1000
help
Defines the maximum number of temporary beacons to be stored. (Default 1000)
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_START_ADDRESS
int "Storage start address"
default 0
help
Defines the start address on partition. (Default 0)
config ENA_STORAGE_TEMP_BEACONS_MAX
int "Max. temporary beacons"
default 1000
help
Defines the maximum number of temporary beacons to be stored. (Default 1000)
config ENA_STORAGE_PARTITION_NAME
string "Partition name"
default "ena"
help
Name of the partition used for storage. (Default "ena", see partitions.csv)
config ENA_STORAGE_START_ADDRESS
int "Storage start address"
default 0
help
Defines the start address on partition. (Default 0)
config ENA_STORAGE_ERASE
bool "Erase storage (!)"
default false
help
Erases the complete(!) partition on startup and reset counters.
config ENA_STORAGE_PARTITION_NAME
string "Partition name"
default "ena"
help
Name of the partition used for storage. (Default "ena", see partitions.csv)
endmenu
menu "Scanning"
config ENA_BEACON_TRESHOLD
int "Contact threshold"
default 300
help
Threshold in seconds after a received beacon is stored permanently. (Default 5 minutes)
config ENA_STORAGE_ERASE
bool "Erase storage (!)"
default false
help
Erases the complete(!) partition on startup and reset counters.
config ENA_SCANNING_TIME
int "Scanning time"
default 30
help
Time in seconds how long a scan should run. (Default 30 seconds)
endmenu
config ENA_SCANNING_INTERVAL
int "Scanning interval"
default 300
help
Interval in seconds for the next scan to happen. (Default 5 minutes)
endmenu
menu "Scanning"
config ENA_BEACON_TRESHOLD
int "Contact threshold"
default 300
help
Threshold in seconds after a received beacon is stored permanently. (Default 5 minutes)
menu "Advertising"
config ENA_BEACON_CLEANUP_TRESHOLD
int "Clean-Up threshold"
default 14
help
Threshold in days after stored beacons to be removed.
config ENA_BT_ROTATION_TIMEOUT_INTERVAL
int "Rotation timeout interval"
default 900
help
Base rotation timeout interval in seconds for changing BT address and therefore the advertised beacon. (Default 5 minutes)
config ENA_SCANNING_TIME
int "Scanning time"
default 30
help
Time in seconds how long a scan should run. (Default 30 seconds)
config ENA_BT_RANDOMIZE_ROTATION_TIMEOUT_INTERVAL
int "Randomize rotation timeout interval"
default 150
help
Range in seconds for randomize the rotation timeout interval. (Default +/- ~2.5 minutes)
config ENA_SCANNING_INTERVAL
int "Scanning interval"
default 300
help
Interval in seconds for the next scan to happen. (Default 5 minutes)
endmenu
config ENA_TEK_ROLLING_PERIOD
int "TEK rolling period"
default 144
help
Defines the TEK rolling period in 10 minute steps. (Default 144 => 24 hours)
endmenu
menu "Advertising"
config ENA_BT_ROTATION_TIMEOUT_INTERVAL
int "Rotation timeout interval"
default 900
help
Base rotation timeout interval in seconds for BT address change & therefore the advertised beacon.(Default 5 minutes)
config ENA_BT_RANDOMIZE_ROTATION_TIMEOUT_INTERVAL
int "Randomize rotation timeout interval"
default 150
help
Range in seconds for randomize the rotation timeout interval. (Default +/- ~2.5 minutes)
config ENA_TEK_ROLLING_PERIOD
int "TEK rolling period"
default 144
help
Defines the TEK rolling period in 10 minute steps. (Default 144 => 24 hours)
endmenu
endmenu
+14
View File
@@ -74,6 +74,20 @@ void ena_beacons_temp_refresh(uint32_t unix_timestamp)
#endif
}
void ena_beacons_cleanup(uint32_t unix_timestamp)
{
uint32_t count = ena_storage_beacons_count();
ena_beacon_t beacon;
for (int i = count - 1; i >= 0; i--)
{
ena_storage_get_beacon(i, &beacon);
if (((unix_timestamp - beacon.timestamp_last) / (60 * 60 * 24)) > ENA_BEACON_CLEANUP_TRESHOLD)
{
ena_storage_remove_beacon(i);
}
}
}
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);
+13
View File
@@ -276,6 +276,19 @@ void ena_storage_add_beacon(ena_beacon_t *beacon)
ESP_LOG_BUFFER_HEXDUMP(ENA_STORAGE_LOG, beacon->aem, ENA_AEM_METADATA_LENGTH, ESP_LOG_DEBUG);
}
void ena_storage_remove_beacon(uint32_t index)
{
uint32_t count = ena_storage_beacons_count();
size_t address_from = ENA_STORAGE_BEACONS_START_ADDRESS + index * sizeof(ena_beacon_t);
size_t address_to = ENA_STORAGE_BEACONS_START_ADDRESS + count * sizeof(ena_beacon_t);
ena_storage_shift_delete(address_from, address_to, sizeof(ena_beacon_t));
count--;
ena_storage_write(ENA_STORAGE_BEACONS_COUNT_ADDRESS, &count, sizeof(uint32_t));
ESP_LOGD(ENA_STORAGE_LOG, "remove beacon: %u", index);
}
void ena_storage_erase(void)
{
const esp_partition_t *partition = esp_partition_find_first(
+3
View File
@@ -26,6 +26,7 @@
#include "ena-storage.h"
#include "ena-bluetooth-scan.h"
#include "ena-bluetooth-advertise.h"
#include "ena-beacons.h"
#include "ena.h"
@@ -56,6 +57,8 @@ void ena_run(void)
// validity only to next day 00:00
last_tek.rolling_period = ENA_TEK_ROLLING_PERIOD - (last_tek.enin % ENA_TEK_ROLLING_PERIOD);
ena_storage_write_tek(&last_tek);
// clean up old beacons
ena_beacons_cleanup(unix_timestamp);
}
// change RPI
+20 -3
View File
@@ -11,11 +11,18 @@
// 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.
/**
* @file
*
* @brief handles scanned data by storing temporary beacons, check for threshold and store beacons permanently
*
*/
#ifndef _ena_BEACON_H_
#define _ena_BEACON_H_
#define ENA_BEACON_LOG "ESP-ENA-beacon" // TAG for Logging
#define ENA_BEACON_TRESHOLD (CONFIG_ENA_BEACON_TRESHOLD) // meet for longer than 5 minutes
#define ENA_BEACON_LOG "ESP-ENA-beacon" // TAG for Logging
#define ENA_BEACON_TRESHOLD (CONFIG_ENA_BEACON_TRESHOLD) // meet for longer than 5 minutes
#define ENA_BEACON_CLEANUP_TRESHOLD (CONFIG_ENA_BEACON_CLEANUP_TRESHOLD) // threshold (in days) for stored beacons to be removed
/**
* @brief check temporary beacon for threshold or expiring
@@ -23,11 +30,21 @@
* This function checks all current temporary beacons if the contact threshold is
* reached or if the temporary contact can be discarded.
*
* @param[in] unix_timestamp current time as UNIX timestamp to compate
* @param[in] unix_timestamp current time as UNIX timestamp to compare
*
*/
void ena_beacons_temp_refresh(uint32_t unix_timestamp);
/**
* @brief check stored beacons to expire
*
* This function checks for all stored beacons if the last timestamp is over a threshold to remove the beacon.
*
* @param[in] unix_timestamp current time as UNIX timestamp to compate
*
*/
void ena_beacons_cleanup(uint32_t unix_timestamp);
/**
* @brief handle new beacon received from a BLE scan
*
@@ -11,6 +11,12 @@
// 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.
/**
* @file
*
* @brief BLE advertising to send own beacons
*
*/
#ifndef _ena_BLUETOOTH_ADVERTISE_H_
#define _ena_BLUETOOTH_ADVERTISE_H_
@@ -11,6 +11,12 @@
// 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.
/**
* @file
*
* @brief BLE scans for detecting other beacons
*
*/
#ifndef _ena_BLUETOOTH_SCAN_H_
#define _ena_BLUETOOTH_SCAN_H_
+6
View File
@@ -11,6 +11,12 @@
// 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.
/**
* @file
*
* @brief covers cryptography part (key creation, encryption etc.)
*
*/
#ifndef _ena_CRYPTO_H_
#define _ena_CRYPTO_H_
+6
View File
@@ -11,6 +11,12 @@
// 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.
/**
* @file
*
* @brief decode Exposure Key export, compare with stored beacons, calculate score and risk
*
*/
#ifndef _ena_EXPOSURE_H_
#define _ena_EXPOSURE_H_
+13
View File
@@ -11,6 +11,12 @@
// 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.
/**
* @file
*
* @brief storage part to store own TEKs and beacons
*
*/
#ifndef _ena_STORAGE_H_
#define _ena_STORAGE_H_
@@ -190,6 +196,13 @@ void ena_storage_get_beacon(uint32_t index, ena_beacon_t *beacon);
*/
void ena_storage_add_beacon(ena_beacon_t *beacon);
/**
* @brief remove beacon at given index
*
* @param[in] index the index of the beacon to remove
*/
void ena_storage_remove_beacon(uint32_t index);
/**
* @brief erase the storage
*
+6
View File
@@ -11,6 +11,12 @@
// 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.
/**
* @file
*
* @brief run all other ena parts together to time scanning, advertising and exposure checks
*
*/
#ifndef _ena_H_
#define _ena_H_