CovidBracelet/src/ens/storage.h

73 lines
2.0 KiB
C
Raw Normal View History

2021-02-18 13:45:29 +01:00
#ifndef CONTACT_STORAGE_H
#define CONTACT_STORAGE_H
2021-01-26 16:14:58 +01:00
#include "../contacts.h" // Requires contact_t in contacts.h!
#include "../covid_types.h"
#include "sequencenumber.h"
2021-02-18 13:45:29 +01:00
typedef uint16_t storage_id_t;
2021-04-21 17:58:16 +02:00
// TODO lome: own datatype for storage
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;
} record_t;
2021-02-18 13:45:29 +01:00
typedef struct stored_contacts_information {
record_sequence_number_t oldest_contact;
2021-03-11 00:32:36 +01:00
record_sequence_number_t count;
2021-02-18 13:45:29 +01:00
} stored_contacts_information_t;
/**
* Initializes the contact storage component
* @return 0 for success
*/
int init_contact_storage();
/**
* Loads the contact with number sn into the destination struct
* @param dest
* @param sn
* @return 0 in case of success
*/
2021-04-21 17:58:16 +02:00
int load_contact(record_t* dest, record_sequence_number_t sn);
2021-02-18 13:45:29 +01:00
/**
* Stores the contact from src with number sn, increases latest sequence number
* @param sn
* @param src
* @return 0 in case of success
*/
2021-04-21 17:58:16 +02:00
int add_contact(record_t* src);
2021-02-18 13:45:29 +01:00
/**
* Deletes the contact from storage with number sn
* @param sn the sequence number to delete
* @return 0 in case of success
*/
int delete_contact(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
* TODO: How to handle if none is available?
* @return The amount of contacts, usually get_latest_sequence_number() - get_oldest_sequence_number()
2021-02-03 19:39:01 +01:00
*/
2021-02-18 13:45:29 +01:00
uint32_t get_num_contacts();
2021-02-01 23:17:48 +01:00
2021-03-11 00:32:36 +01:00
#endif