Tolling zones in SAEM
This commit is contained in:
parent
e00d7fc88c
commit
b253e3de6c
|
|
@ -7,7 +7,7 @@ ADD_EXECUTABLE(it2s-itss-facilities
|
|||
requests.c
|
||||
facilities.c
|
||||
cpm.c
|
||||
sa.c
|
||||
saem.c
|
||||
tpm.c
|
||||
)
|
||||
|
||||
|
|
|
|||
51
src/config.c
51
src/config.c
|
|
@ -10,6 +10,7 @@
|
|||
#include <it2s-config.h>
|
||||
#include <dirent.h>
|
||||
#include <camv2/ProtectedCommunicationZone.h>
|
||||
#include <tpm/TollingPaymentInfo.h>
|
||||
#include <zmq.h>
|
||||
|
||||
#include <itss-management/ManagementRequest.h>
|
||||
|
|
@ -363,6 +364,56 @@ int facilities_config(void* facilities_s) {
|
|||
}
|
||||
}
|
||||
|
||||
// TZ
|
||||
if (facilities->station_type == 15) {
|
||||
|
||||
int i = 0;
|
||||
|
||||
DIR *d = opendir(config->facilities.tpm.tis_path);
|
||||
struct dirent *dir;
|
||||
char file[256];
|
||||
char ti_xml[2048];
|
||||
if (d) {
|
||||
while ((dir = readdir(d)) != NULL && i < TOLLING_INFOS_MAX_LENGTH) {
|
||||
if (dir->d_name[0] == '.') continue;
|
||||
sprintf(file, "%s/%s", config->facilities.tpm.tis_path, dir->d_name);
|
||||
FILE *fp = fopen(file, "r");
|
||||
if (!fp) continue;
|
||||
fseek(fp, 0, SEEK_END);
|
||||
uint16_t size = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
if (!size) {
|
||||
fclose(fp);
|
||||
continue;
|
||||
}
|
||||
if (!fread(ti_xml, 1, size, fp)) {
|
||||
fclose(fp);
|
||||
continue;
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
TollingPaymentInfo_t *ti = calloc(1, sizeof(TollingPaymentInfo_t));
|
||||
|
||||
asn_dec_rval_t dec = xer_decode(NULL, &asn_DEF_TollingPaymentInfo, (void**) &ti, ti_xml, size);
|
||||
if (!dec.code) {
|
||||
facilities->tolling.infos.z[i] = ti;
|
||||
++facilities->tolling.infos.length;
|
||||
++i;
|
||||
syslog_debug("[facilities] [config] loaded tolling info @ (%ld, %ld) with %d payment option(s)",
|
||||
ti->zone.latitude,
|
||||
ti->zone.longitude,
|
||||
(ti->fiatInfos ? ti->fiatInfos->list.count : 0) + (ti->ledgerInfos ? ti->ledgerInfos->list.count : 0)
|
||||
);
|
||||
} else {
|
||||
syslog_err("[facilities] [config] failure to decode tolling info '%s'", dir->d_name);
|
||||
ASN_STRUCT_FREE(asn_DEF_TollingPaymentInfo, ti);
|
||||
}
|
||||
|
||||
}
|
||||
closedir(d);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_init(&facilities->epv.space.lock, NULL);
|
||||
pthread_mutex_init(&facilities->epv.time.lock, NULL);
|
||||
facilities->epv.time.resolution = TIME_MILLISECONDS;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#include "infrastructure.h"
|
||||
#include "requests.h"
|
||||
#include "cpm.h"
|
||||
#include "sa.h"
|
||||
#include "saem.h"
|
||||
|
||||
#include <itss-networking/NetworkingIndication.h>
|
||||
#include <itss-transport/TransportRequest.h>
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
#include "infrastructure.h"
|
||||
#include "queue.h"
|
||||
#include "cpm.h"
|
||||
#include "sa.h"
|
||||
#include "saem.h"
|
||||
#include "tpm.h"
|
||||
|
||||
#include <it2s-tender/epv.h>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "sa.h"
|
||||
#include "saem.h"
|
||||
#include "facilities.h"
|
||||
#include "infrastructure.h"
|
||||
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
#include <itss-transport/TransportRequest.h>
|
||||
#include <itss-security/SecurityRequest.h>
|
||||
#include <itss-security/SecurityReply.h>
|
||||
#include <saem/asn_application.h>
|
||||
#include <saem/per_encoder.h>
|
||||
#include <tpm/TollingPaymentInfo.h>
|
||||
#include <saem/SAEM.h>
|
||||
|
|
@ -137,7 +138,11 @@ void bulletin_init(bulletin_t* bulletin) {
|
|||
int mk_saem(facilities_t* facilities, uint8_t* b_saem, uint32_t* b_saem_len) {
|
||||
int rv = 0;
|
||||
|
||||
TollingPaymentInfo_t* tpi = NULL;
|
||||
// Check tolling advertisements
|
||||
if (!facilities->tolling.infos.length) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
asn_enc_rval_t enc;
|
||||
|
||||
SAEM_t* saem = calloc(1, sizeof(SAEM_t));
|
||||
|
|
@ -174,6 +179,7 @@ int mk_saem(facilities_t* facilities, uint8_t* b_saem, uint32_t* b_saem_len) {
|
|||
|
||||
exts->list.array[0] = calloc(1, sizeof(ServiceInfoExt_t));
|
||||
exts->list.array[0]->present = ServiceInfoExt_PR_providerServiceContext;
|
||||
|
||||
char ctx_s[] = "tolling:simple";
|
||||
exts->list.array[0]->choice.providerServiceContext.size = strlen(ctx_s);
|
||||
exts->list.array[0]->choice.providerServiceContext.buf = malloc(strlen(ctx_s));
|
||||
|
|
@ -187,17 +193,7 @@ int mk_saem(facilities_t* facilities, uint8_t* b_saem, uint32_t* b_saem_len) {
|
|||
exts->list.array[2]->present = ServiceInfoExt_PR_applicationDataSAM;
|
||||
exts->list.array[2]->choice.applicationDataSAM.buf = malloc(1024);
|
||||
|
||||
if (tpi) ASN_STRUCT_FREE(asn_DEF_TollingPaymentInfo, tpi);
|
||||
tpi = calloc(1, sizeof(TollingPaymentInfo_t));
|
||||
tpi->fiatInfos = calloc(1, sizeof(FiatInfos_t));
|
||||
tpi->fiatInfos->list.count = 1;
|
||||
tpi->fiatInfos->list.size = 1 * sizeof(void*);
|
||||
tpi->fiatInfos->list.array = malloc(1 * sizeof(void*));
|
||||
tpi->fiatInfos->list.array[0] = calloc(1, sizeof(FiatInfo_t));
|
||||
tpi->fiatInfos->list.array[0]->value = 350;
|
||||
tpi->fiatInfos->list.array[0]->fiatId = FiatId_eur;
|
||||
|
||||
enc = uper_encode_to_buffer(&asn_DEF_TollingPaymentInfo, NULL, tpi, exts->list.array[2]->choice.applicationDataSAM.buf, 1024);
|
||||
enc = uper_encode_to_buffer(&asn_DEF_TollingPaymentInfo, NULL, facilities->tolling.infos.z[0], exts->list.array[2]->choice.applicationDataSAM.buf, 1024);
|
||||
if (enc.encoded == -1) {
|
||||
syslog_err("[facilities] [sa] failure to encode TollingPaymentInfo (%s)", enc.failed_type->name);
|
||||
rv = 1;
|
||||
|
|
@ -233,17 +229,7 @@ int mk_saem(facilities_t* facilities, uint8_t* b_saem, uint32_t* b_saem_len) {
|
|||
exts->list.array[3]->present = ServiceInfoExt_PR_applicationDataSAM;
|
||||
exts->list.array[3]->choice.applicationDataSAM.buf = malloc(1024);
|
||||
|
||||
if (tpi) ASN_STRUCT_FREE(asn_DEF_TollingPaymentInfo, tpi);
|
||||
tpi = calloc(1, sizeof(TollingPaymentInfo_t));
|
||||
tpi->fiatInfos = calloc(1, sizeof(FiatInfos_t));
|
||||
tpi->fiatInfos->list.count = 1;
|
||||
tpi->fiatInfos->list.size = 1 * sizeof(void*);
|
||||
tpi->fiatInfos->list.array = malloc(1 * sizeof(void*));
|
||||
tpi->fiatInfos->list.array[0] = calloc(1, sizeof(FiatInfo_t));
|
||||
tpi->fiatInfos->list.array[0]->value = 350;
|
||||
tpi->fiatInfos->list.array[0]->fiatId = FiatId_eur;
|
||||
|
||||
enc = uper_encode_to_buffer(&asn_DEF_TollingPaymentInfo, NULL, tpi, exts->list.array[3]->choice.applicationDataSAM.buf, 1024);
|
||||
enc = uper_encode_to_buffer(&asn_DEF_TollingPaymentInfo, NULL, facilities->tolling.infos.z[0], exts->list.array[3]->choice.applicationDataSAM.buf, 1024);
|
||||
if (enc.encoded == -1) {
|
||||
syslog_err("[facilities] [sa] failure to encode TollingPaymentInfo (%s)", enc.failed_type->name);
|
||||
rv = 1;
|
||||
|
|
@ -267,7 +253,6 @@ int mk_saem(facilities_t* facilities, uint8_t* b_saem, uint32_t* b_saem_len) {
|
|||
|
||||
cleanup:
|
||||
ASN_STRUCT_FREE(asn_DEF_SAEM, saem);
|
||||
ASN_STRUCT_FREE(asn_DEF_TollingPaymentInfo, tpi);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <tpm/TPM.h>
|
||||
#include <tpm/TollingPaymentInfo.h>
|
||||
#include <it2s-tender/time.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define TOLLING_INFOS_MAX_LENGTH 16
|
||||
|
||||
typedef enum TOLLING_PROTOCOL {
|
||||
TOLLING_PROTOCOL_SIMPLE,
|
||||
TOLLING_PROTOCOL_TLS
|
||||
|
|
@ -20,6 +23,11 @@ typedef struct tolling {
|
|||
|
||||
uint64_t tz;
|
||||
|
||||
struct {
|
||||
TollingPaymentInfo_t* z[TOLLING_INFOS_MAX_LENGTH];
|
||||
uint8_t length;
|
||||
} infos;
|
||||
|
||||
} tolling_s;
|
||||
|
||||
int tpm_pay(void* fc, uint8_t* neighbour);
|
||||
|
|
|
|||
Loading…
Reference in New Issue