2021-02-18 13:45:29 +01:00
|
|
|
#ifndef CONTACT_STORAGE_H
|
|
|
|
#define CONTACT_STORAGE_H
|
2021-01-26 16:14:58 +01:00
|
|
|
|
2021-05-03 23:36:07 +02:00
|
|
|
#include <zephyr/types.h>
|
|
|
|
|
2022-05-25 20:26:38 +02:00
|
|
|
#include "covid_types.h"
|
2021-04-26 15:56:00 +02:00
|
|
|
#include "sequencenumber.h"
|
2021-02-18 13:45:29 +01:00
|
|
|
|
2021-05-03 23:36:07 +02:00
|
|
|
typedef uint64_t storage_id_t;
|
2021-02-18 13:45:29 +01:00
|
|
|
|
2021-04-21 17:58:16 +02:00
|
|
|
typedef struct record {
|
|
|
|
record_sequence_number_t sn; // TODO: Convert Sequence Number
|
|
|
|
uint32_t timestamp; // TODO: Seconds from january first 2000 (UTC+0)
|
|
|
|
rssi_t rssi; // TODO: Check correct
|
|
|
|
rolling_proximity_identifier_t rolling_proximity_identifier;
|
|
|
|
associated_encrypted_metadata_t associated_encrypted_metadata;
|
2021-05-17 19:16:47 +02:00
|
|
|
} __packed record_t;
|
2021-04-21 17:58:16 +02:00
|
|
|
|
2021-05-03 22:07:15 +02:00
|
|
|
typedef struct stored_records_information {
|
2021-02-18 13:45:29 +01:00
|
|
|
record_sequence_number_t oldest_contact;
|
2021-05-03 23:36:07 +02:00
|
|
|
uint32_t count;
|
2021-05-03 22:07:15 +02:00
|
|
|
} stored_records_information_t;
|
2021-02-18 13:45:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the contact storage component
|
2021-07-21 14:05:08 +02:00
|
|
|
* @param clean flag for indicating, if storage shall be init with clean state
|
|
|
|
*
|
2021-02-18 13:45:29 +01:00
|
|
|
* @return 0 for success
|
|
|
|
*/
|
2021-07-21 14:05:08 +02:00
|
|
|
int init_record_storage(bool clean);
|
2021-02-18 13:45:29 +01:00
|
|
|
|
2021-12-08 18:19:27 +01:00
|
|
|
/**
|
|
|
|
* Reset state of record storage.
|
|
|
|
*/
|
2021-12-10 13:51:56 +01:00
|
|
|
void reset_record_storage();
|
2021-12-08 18:19:27 +01:00
|
|
|
|
2021-02-18 13:45:29 +01:00
|
|
|
/**
|
2021-05-03 22:07:15 +02:00
|
|
|
* Loads the record with number sn into the destination struct
|
2021-02-18 13:45:29 +01:00
|
|
|
* @param dest
|
|
|
|
* @param sn
|
|
|
|
* @return 0 in case of success
|
|
|
|
*/
|
2021-05-03 22:07:15 +02:00
|
|
|
int load_record(record_t* dest, record_sequence_number_t sn);
|
2021-02-18 13:45:29 +01:00
|
|
|
|
|
|
|
/**
|
2021-05-03 22:07:15 +02:00
|
|
|
* Stores the record from src with number sn, increases latest sequence number
|
2021-02-18 13:45:29 +01:00
|
|
|
* @param sn
|
|
|
|
* @param src
|
|
|
|
* @return 0 in case of success
|
|
|
|
*/
|
2021-05-03 22:07:15 +02:00
|
|
|
int add_record(record_t* src);
|
2021-02-18 13:45:29 +01:00
|
|
|
|
|
|
|
/**
|
2021-05-03 22:07:15 +02:00
|
|
|
* Deletes the record from storage with number sn
|
2021-02-18 13:45:29 +01:00
|
|
|
* @param sn the sequence number to delete
|
|
|
|
* @return 0 in case of success
|
|
|
|
*/
|
2021-05-03 22:07:15 +02:00
|
|
|
int delete_record(record_sequence_number_t sn);
|
2021-02-01 23:17:48 +01:00
|
|
|
|
2021-01-26 16:14:58 +01:00
|
|
|
/**
|
2021-02-18 13:45:29 +01:00
|
|
|
* TODO: How to handle if none is available?
|
|
|
|
* @return The latest available sequence number (Caution: can actually be lower than the oldes in case of a
|
|
|
|
* wrap-around!)
|
2021-01-26 16:14:58 +01:00
|
|
|
*/
|
2021-02-18 13:45:29 +01:00
|
|
|
record_sequence_number_t get_latest_sequence_number();
|
2021-01-26 16:14:58 +01:00
|
|
|
|
2021-02-01 23:17:48 +01:00
|
|
|
/**
|
2021-02-18 13:45:29 +01:00
|
|
|
* TODO: How to handle if none is available?
|
|
|
|
* @return The oldest available sequence number
|
2021-02-01 23:17:48 +01:00
|
|
|
*/
|
2021-02-18 13:45:29 +01:00
|
|
|
record_sequence_number_t get_oldest_sequence_number();
|
2021-02-03 19:39:01 +01:00
|
|
|
|
|
|
|
/**
|
2021-02-18 13:45:29 +01:00
|
|
|
* @return The amount of contacts, usually get_latest_sequence_number() - get_oldest_sequence_number()
|
2021-02-03 19:39:01 +01:00
|
|
|
*/
|
2021-05-03 22:07:15 +02:00
|
|
|
uint32_t get_num_records();
|
2021-02-01 23:17:48 +01:00
|
|
|
|
2021-12-08 18:19:27 +01:00
|
|
|
int get_sequence_number_interval(record_sequence_number_t* oldest, record_sequence_number_t* latest);
|
2021-05-25 20:22:19 +02:00
|
|
|
|
2021-03-11 00:32:36 +01:00
|
|
|
#endif
|