it2s-itss-facilities/src/tpm.h

63 lines
1.4 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_s;
typedef struct tolling {
bool enabled;
TOLLING_PROTOCOL_e protocol;
// Vehicles
bool active;
uint64_t nonce;
uint64_t client_id;
uint64_t tz;
struct {
tolling_info_s* z[TOLLING_INFOS_MAX_LENGTH];
uint8_t length;
} infos;
// Security socket
void* security_socket;
} tolling_s;
/**
* 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_s* tolling, void* zmq_ctx, char* security_address);
int tpm_pay(void* fc, uint8_t* neighbour);
int tpm_recv(void* fc, TPM_t* tpm_rx, uint8_t* neighbour);
int tpm_is_inside_zone(void* fc, tolling_info_s* ti);
tolling_info_s* tolling_info_new(it2s_tender_epv_t* epv, TollingPaymentInfo_t* tpi);
void tolling_info_free(tolling_info_s* ti);