121 lines
2.8 KiB
C
121 lines
2.8 KiB
C
#pragma once
|
|
|
|
#include <it2s-asn/etsi-its-v1/tpm/EI1_TPM.h>
|
|
#include <it2s-asn/etsi-its-v1/tpm/EI1_TollingPaymentInfo.h>
|
|
#include <it2s-tender/time.h>
|
|
#include <it2s-tender/queue.h>
|
|
#include <stdbool.h>
|
|
|
|
#define TOLLING_INFOS_MAX_LENGTH 16
|
|
#define TOLLING_PAYMENT_MIN_PERIOD_MS 40000
|
|
#define TOLLING_MAX_CONNS 64
|
|
#define TOLLING_CONN_TIMEOUT_MS 10000
|
|
#define TOLLING_RT_PERIOD_MS 400
|
|
#define TOLLING_RT_TIMEOUT_MS 10000
|
|
#define TOLLING_MAX_CLIENTS 256
|
|
#define TOLLING_CLIENT_LIFETIME_MS 300000
|
|
|
|
typedef enum TOLLING_PROTOCOL {
|
|
TOLLING_PROTOCOL_GN_SPKI,
|
|
TOLLING_PROTOCOL_GN_DPKI,
|
|
TOLLING_PROTOCOL_TLS,
|
|
TOLLING_PROTOCOL_TLS_GN,
|
|
TOLLING_PROTOCOL_TLS_SHS
|
|
} TOLLING_PROTOCOL_e;
|
|
|
|
typedef struct tolling_info {
|
|
uint64_t timestamp;
|
|
struct {
|
|
double (*polygon)[2]; /* (latitude, longitude) */
|
|
size_t polygon_len;
|
|
} zone;
|
|
EI1_TollingPaymentInfo_t* asn;
|
|
} tolling_info_t;
|
|
|
|
/**
|
|
* TLS connections
|
|
*/
|
|
typedef struct tlsc {
|
|
uint8_t ipv6[16];
|
|
uint16_t port;
|
|
uint64_t id;
|
|
uint64_t ts;
|
|
uint8_t state;
|
|
uint16_t nmsg;
|
|
} tlsc_t;
|
|
|
|
typedef struct toll_client {
|
|
uint32_t station_id;
|
|
uint64_t id;
|
|
uint64_t ts;
|
|
int8_t accepted;
|
|
} toll_client_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 {
|
|
toll_client_t* clients[TOLLING_MAX_CLIENTS];
|
|
uint16_t clients_len;
|
|
} rsu;
|
|
|
|
// OBU
|
|
struct {
|
|
bool active;
|
|
int8_t toll_type;
|
|
uint64_t nonce;
|
|
uint64_t client_id;
|
|
uint64_t tls_conn_id;
|
|
EI1_TPM_t* entry_proof;
|
|
|
|
uint64_t t_init;
|
|
|
|
// Retransmission
|
|
uint64_t rt_init;
|
|
uint64_t rt_t_trigger;
|
|
bool rt_on;
|
|
} obu;
|
|
} station;
|
|
|
|
struct {
|
|
tolling_info_t* z[TOLLING_INFOS_MAX_LENGTH];
|
|
uint8_t length;
|
|
} infos;
|
|
|
|
} tolling_t;
|
|
|
|
/**
|
|
* Initializes the main tolling struture
|
|
*/
|
|
int tolling_init(uint8_t station_type);
|
|
|
|
int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, uint8_t* dst_addr);
|
|
int tpm_recv(EI1_TPM_t* tpm_rx, void** security_socket, uint8_t* neighbour, uint8_t* src_addr);
|
|
int tpm_should_retransmit();
|
|
int tpm_is_inside_zone(tolling_info_t* ti);
|
|
|
|
tolling_info_t* tolling_info_new(EI1_TollingPaymentInfo_t* tpi);
|
|
void tolling_info_free(tolling_info_t* ti);
|
|
|
|
tlsc_t* tolling_tlsc_new(uint8_t ipv6[16], uint16_t port);
|
|
tlsc_t* tolling_tlsc_get(uint8_t ipv6[16], uint16_t port);
|
|
void tolling_tlsc_mgmt(itss_queue_t* tx_queue, void** security_socket);
|