it2s-itss-facilities/src/tpm.h

71 lines
1.8 KiB
C

#pragma once
#include <tpm/TPM.h>
#include <tpm/TollingPaymentInfo.h>
#include <it2s-tender/time.h>
#include <stdbool.h>
#define TOLLING_INFOS_MAX_LENGTH 16
#define TOLLING_PAYMENT_MIN_PERIOD_MS 60000
typedef enum TOLLING_PROTOCOL {
TOLLING_PROTOCOL_SIMPLE,
TOLLING_PROTOCOL_TLS
} TOLLING_PROTOCOL_e;
typedef struct tolling_info {
uint64_t timestamp;
struct {
double (*polygon)[2]; /* (latitude, longitude) */
size_t polygon_len;
} zone;
TollingPaymentInfo_t* asn;
} tolling_info_t;
typedef struct tolling {
bool enabled;
TOLLING_PROTOCOL_e protocol;
union {
// RSU
struct {
uint64_t tls_conn_id;
} rsu;
// OBU
struct {
bool active;
int8_t toll_type;
uint64_t nonce;
uint64_t client_id;
uint64_t tls_conn_id;
TPM_t* entry_proof;
} obu;
} station;
uint64_t tz;
struct {
tolling_info_t* z[TOLLING_INFOS_MAX_LENGTH];
uint8_t length;
} infos;
} tolling_t;
/**
* Initializes the main tolling struture
*
* @param tolling The structure to initialize
* @param zmq_ctx The facilities ZMQ context
* @param security_address The security service ZMQ address
* @return Always successful
*/
int tolling_init(tolling_t* tolling, void* zmq_ctx, char* security_address, uint8_t station_type);
int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neighbour, uint8_t* dst_addr);
int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, uint8_t* src_addr);
int tpm_is_inside_zone(void* fc, tolling_info_t* ti);
tolling_info_t* tolling_info_new(it2s_tender_epv_t* epv, TollingPaymentInfo_t* tpi);
void tolling_info_free(tolling_info_t* ti);