2020-07-11 12:11:34 +02:00
# esp-ena
2020-07-22 21:44:17 +02:00
Implementation of contact tracing with the Covid-19 Exposure Notification API by Apple and Google on an ESP32 (with [ESP-IDF ](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/index.html )).
2020-07-25 13:40:35 +02:00
More information about the Covid-19 Exposure Notification at [Apple ](https://www.apple.com/covid19/contacttracing/ ) and [Google ](https://www.google.com/covid19/exposurenotifications/ ). This is fully compatible with the official API and is meant for people without smartphone or without access to Apples/Googles implementation.
2020-07-11 12:11:34 +02:00
2020-07-25 13:33:03 +02:00
The main source (the Exposure Notification API) is a separate module in [**components/ena** ](components/ena ).
2020-07-22 21:44:17 +02:00
This implementation fully covers for the BLE part including the cryptography specifications needed (see Bluetooth Specifications and Cryptography Specifications documents in the links above):
2020-07-15 22:22:54 +02:00
* send beacons
* store TEKs on flash (last 14)
* receive beacons
* received beacons are stored after 5 minutes threshold (storage is limited, ~100k beacons can be stored)
2020-07-25 13:33:03 +02:00
* parse key export binaries as defined in [Exposure Key export file format and verification ](https://developers.google.com/android/exposure-notifications/exposure-key-file-format ) (big thanks to [nanopb ](https://github.com/nanopb/nanopb ) for making this easier than I thought!)
* calculating risks scores (after adding reported keys and storing exposure information)
2020-07-11 12:11:34 +02:00
2020-07-22 21:44:17 +02:00
Additional features for full ENA device
* RTC support with DS3231
* display support with SSD1306
* interface to
* set time
2020-07-25 13:33:03 +02:00
* show exposure status
2020-07-11 12:11:34 +02:00
Extensions planned:
2020-07-25 13:33:03 +02:00
* automatically receive key export from web (will test [Corona Warn App ](https://github.com/corona-warn-app ))
2020-07-11 12:11:34 +02:00
* send infected status (will test [Corona Warn App ](https://github.com/corona-warn-app ))
* battery support
* 3d print case
2020-07-25 13:33:03 +02:00
* interface to
* delete data
* report infection
2020-07-11 12:11:34 +02:00
Limitations/Problems
* storage only ~2.8mb available
* WiFi or other external connection needed for infections status (auto-connect to open WiFis?)
* obtaining accessibility
* all parameters (scanning time, thresholds etc.)
The following acronyms will be used in code and comments:
* *ENA* Exposure Notification Api
* *ENIN* ENIntervalNumber - timestamp with 10 minutes resolution
* *TEK* Temporary Exposure Key - personal secret key changed every 24h, published when infected
* *RPI* Rolling Proximity Identifier - send and received identifer changed every 10 minutes
* *AEM* Associated Encrypted Metadata - send and received metadata
2020-07-25 13:33:03 +02:00
Open questions/problems
* memory is really low with BLE and WiFi enabled, unzipping a Key Export not possible for now, maybe disable BLE service for download.
* service UUID is send reversed, RPI and AEM also send in reverse? Don't know BLE specification enough
2020-07-11 12:11:34 +02:00
## How to use
### Hardware Required
For now just an ESP32 is required. For full device later RTC (DS3231) and Display (SSD1306) will be required.
### Configure the project
```
idf.py menuconfig
```
required
* enable bluetooth (BLE)
* add partition-table for storage (currently hardcoded name "ena")
* mbedTLS enable HKDF
recommended
2020-07-15 22:32:51 +02:00
* BLE *Scan Duplicate* (By Device Address and Advertising Data)
2020-07-15 22:22:54 +02:00
debug options
* Log output set to Debug
2020-07-15 22:32:51 +02:00
* Exposure Notification API / Storage enable *Dump storage*
2020-07-11 12:11:34 +02:00
### Build and Flash
2020-07-11 17:33:47 +02:00
May flash partition table:
```
idf.py partition_table-flash
```
2020-07-11 12:11:34 +02:00
Build the project and flash it to the board, then run monitor tool to view serial output:
```
idf.py -p PORT flash monitor
```
(Replace PORT with the name of the serial port to use.)
(To exit the serial monitor, type ``Ctrl-]``.)
## Troubleshooting
Sometimes I get errors from BT-stack of ESP-IDF printed. Didn't affect functionality for now, but I also could not find out what it caused and what it means.
```
E (909164) BT_HCI: btu_hcif_hdl_command_complete opcode 0x2005 status 0xc
```
## Structure
2020-07-25 13:33:03 +02:00
The project is divided in different components. The main.c just wrap up all components. The Exposure Notification API is in **ena** module
2020-07-15 22:29:52 +02:00
### ena
2020-07-25 13:33:03 +02:00
The ena module contains the main functions of eps-ena with bluetooth scanning and adverting, storing data, handle beacons and check exposure.
2020-07-15 22:29:52 +02:00
* *ena-beacons* handles scanned data by storing temporary beacons, check for threshold and store beacons permanently
2020-07-11 12:11:34 +02:00
* *ena-crypto* covers cryptography part (key creation, encryption etc.)
2020-07-15 22:22:54 +02:00
* *ena-storage* storage part to store own TEKs and beacons
* *ena-bluetooth-scan* BLE scans for detecting other beacons
* *ena-bluetooth-advertise* BLE advertising to send own beacons
2020-07-25 13:33:03 +02:00
* *ena-exposure* decode Key Export, compare with stored beacons, calculate score and risk
2020-07-11 12:11:34 +02:00
* *ena* run all together and timing for scanning and advertising
2020-07-15 22:29:52 +02:00
2020-07-25 13:33:03 +02:00
### ena-cwa
Connection to german Exposure App ([Corona Warn App](https://github.com/corona-warn-app)) for download Key Export (and maybe later report infection).
2020-07-15 22:29:52 +02:00
### ena-interface
Adds interface functionality via touch pads for control and setup.
### i2c-main
Just start I2C driver for display and RTC.
2020-07-25 13:33:03 +02:00
### ds3231
I2C driver for a DS3231 RTC
2020-07-15 22:29:52 +02:00
### ssd1306
2020-07-25 13:33:03 +02:00
I2C driver for a SSD1306 display.
### nanopb
[Nanopb ](https://github.com/nanopb/nanopb ) for reading Protocol Buffers of Key Export. Including already generated Headers from *.proto files.
### miniz
2020-07-25 13:40:35 +02:00
[Miniz ](https://github.com/richgel999/miniz ) for unzipping Key Export (not successful for now due to memory limit)
## Demo
[Demo Video (early stage) ](https://twitter.com/Lurkars/status/1282223547579019264 )