#pragma once #include #include #include #include #include #define TOLLING_INFOS_MAX_LENGTH 16 #define TOLLING_PAYMENT_MIN_PERIOD_MS 60000 #define TOLLING_MAX_CONNS 64 #define TOLLING_CONN_TIMEOUT_MS 10000 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; /** * TLS connections */ typedef struct tlsc { uint8_t ipv6[16]; uint16_t port; uint64_t id; uint64_t ts; } tlsc_t; typedef struct tolling { bool enabled; pthread_mutex_t lock; struct { TOLLING_PROTOCOL_e p; union { // Simple struct { } simple; // TLS struct { tlsc_t* tls_conns[TOLLING_MAX_CONNS]; uint8_t n_tlsc; } tls; } c; } protocol; union { // RSU struct { } 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); tlsc_t* tolling_tlsc_new(tolling_t* tolling, it2s_tender_epv_t* epv, uint8_t ipv6[16], uint16_t port); tlsc_t* tolling_tlsc_get(tolling_t* tolling, it2s_tender_epv_t* epv, uint8_t ipv6[16], uint16_t port); void tolling_tlsc_mgmt(tolling_t* tolling, it2s_tender_epv_t* epv, it2s_tender_queue_t* tx_queue, void* security_socket);