From a7683aff7750346b142b1b3226c315ee319d05d4 Mon Sep 17 00:00:00 2001 From: emanuel Date: Mon, 2 May 2022 16:42:24 +0100 Subject: [PATCH] Forward TPMs to [applications] --- src/facilities.c | 1 + src/tpm.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/facilities.c b/src/facilities.c index 7173540..e164936 100644 --- a/src/facilities.c +++ b/src/facilities.c @@ -227,6 +227,7 @@ static int transport_indication(facilities_t *facilities, void* responder, void* case 7011: if (facilities->tolling.enabled) { tpm_recv(facilities, its_msg, security_socket, neighbour_cert, NULL); + fwd = true; } break; diff --git a/src/tpm.c b/src/tpm.c index fc6f793..db23778 100644 --- a/src/tpm.c +++ b/src/tpm.c @@ -1,8 +1,10 @@ #include "tpm.h" #include "facilities.h" +#include #include #include +#include #include #include #include @@ -42,6 +44,7 @@ int tpm_pay(void* fc, tolling_info_s* info, void* security_socket, uint8_t* neig TransportRequest_t* tr = NULL; SecurityRequest_t* sreq = NULL; SecurityReply_t* srep = NULL; + FacilitiesIndication_t* fi = NULL; TPM_t* tpm = NULL; const size_t buf_len = 2048; @@ -247,6 +250,23 @@ int tpm_pay(void* fc, tolling_info_s* info, void* security_socket, uint8_t* neig pthread_mutex_unlock(&facilities->id.lock); it2s_tender_db_add(facilities->logging.dbms, station_id, id, &facilities->epv, true, 117, NULL, tpm_uper, tpm_uper_len); } + + // send to [applications] + fi = calloc(1, sizeof(FacilitiesIndication_t)); + fi->present = FacilitiesIndication_PR_message; + fi->choice.message.id = id; + fi->choice.message.itsMessageType = 7011; + fi->choice.message.data.size = tpm_uper_len; + fi->choice.message.data.buf = malloc(tpm_uper_len); + memcpy(fi->choice.message.data.buf, tpm_uper, tpm_uper_len); + enc = oer_encode_to_buffer(&asn_DEF_FacilitiesIndication, NULL, fi, buf+1, buf_len-1); + if (enc.encoded == -1) { + syslog_err("[facilities] [tolling] error encoding FI TPM.request (%s)", enc.failed_type->name); + rv = 1; + goto cleanup; + } + it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message (TPM.request)"); + if (facilities->logging.recorder) { uint16_t buffer_len = 2048; uint8_t buffer[buffer_len]; @@ -269,6 +289,7 @@ cleanup: ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr); ASN_STRUCT_FREE(asn_DEF_SecurityRequest, sreq); ASN_STRUCT_FREE(asn_DEF_SecurityReply, srep); + ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi); return rv; } @@ -304,6 +325,7 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur TransportRequest_t* tr = NULL; SecurityRequest_t* sreq = NULL; SecurityReply_t* srep = NULL; + FacilitiesIndication_t* fi = NULL; TPM_t* tpm = NULL; if (tolling->protocol == TOLLING_PROTOCOL_SIMPLE) { @@ -555,6 +577,22 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur pthread_mutex_unlock(&facilities->id.lock); it2s_tender_db_add(facilities->logging.dbms, station_id, id, &facilities->epv, true, 117, NULL, tpm_uper, tpm_uper_len); } + + // send to [applications] + fi = calloc(1, sizeof(FacilitiesIndication_t)); + fi->present = FacilitiesIndication_PR_message; + fi->choice.message.id = id; + fi->choice.message.itsMessageType = 7011; + fi->choice.message.data.size = tpm_uper_len; + fi->choice.message.data.buf = malloc(tpm_uper_len); + memcpy(fi->choice.message.data.buf, tpm_uper, tpm_uper_len); + enc = oer_encode_to_buffer(&asn_DEF_FacilitiesIndication, NULL, fi, buf+1, buf_len-1); + if (enc.encoded == -1) { + syslog_err("[facilities] [tolling] error encoding FI TPM.reply (%s)", enc.failed_type->name); + goto cleanup; + } + + it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message (TPM.reply)"); if (facilities->logging.recorder) { uint16_t buffer_len = 2048; uint8_t buffer[buffer_len]; @@ -577,6 +615,7 @@ cleanup: ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr); ASN_STRUCT_FREE(asn_DEF_SecurityRequest, sreq); ASN_STRUCT_FREE(asn_DEF_SecurityReply, srep); + ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi); } static void veh_handle_recv(tolling_s* tolling, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour) {