diff --git a/src/facilities.c b/src/facilities.c index d7bd0b7..04f923e 100644 --- a/src/facilities.c +++ b/src/facilities.c @@ -140,6 +140,9 @@ static int transport_indication(facilities_t *facilities, void* responder, void* ssp_len = tpi->choice.btp.gn.securityPermissions->ssp.size; } + // Get neighbour certificate ID + uint8_t* neighbour_cert = tpi->choice.btp.gn.securityNeighbour ? tpi->choice.btp.gn.securityNeighbour->buf : NULL; + // Manage message switch (tpi->choice.btp.destinationPort) { case Port_cam: @@ -198,20 +201,17 @@ static int transport_indication(facilities_t *facilities, void* responder, void* break; case Port_saem: - saem_check( - facilities, - &facilities->bulletin, - its_msg, - tpi->choice.btp.gn.securityNeighbour ? tpi->choice.btp.gn.securityNeighbour->buf : NULL - ); + switch (saem_check(facilities, &facilities->bulletin, its_msg, neighbour_cert)) { + case SAEM_NEW: + fwd = true; + break; + default: + break; + } break; case 7011: - tpm_recv( - facilities, - its_msg, - tpi->choice.btp.gn.securityNeighbour ? tpi->choice.btp.gn.securityNeighbour->buf : NULL - ); + tpm_recv(facilities, its_msg, neighbour_cert); break; default: diff --git a/src/mcm.c b/src/mcm.c new file mode 100644 index 0000000..bc2f685 --- /dev/null +++ b/src/mcm.c @@ -0,0 +1,15 @@ +#include "mcm.h" +#include "facilities.h" + + +void* mc_service(void* fc) { + + facilities_t* facilities = (facilities_t*) fc; + + while (!facilities->exit) { + + usleep(50*1000); + } + + return NULL; +} diff --git a/src/mcm.h b/src/mcm.h new file mode 100644 index 0000000..7208d8d --- /dev/null +++ b/src/mcm.h @@ -0,0 +1,4 @@ +#pragma once + + +void* mc_service(void* fc); diff --git a/src/saem.c b/src/saem.c index d454a6d..394a6f2 100644 --- a/src/saem.c +++ b/src/saem.c @@ -53,6 +53,7 @@ SAEM_CODE_R saem_check(void* fc, bulletin_t* bulletin, SAEM_t* saem, uint8_t* ne } if (index == -1) { + rv = SAEM_NEW; if (bulletin->to_consume_len + 1 < MAX_ANNOUNCEMENTS_LEN) { bulletin->to_consume[bulletin->to_consume_len]->its_aid = its_aid; bulletin->to_consume[bulletin->to_consume_len]->station_id = saem->header.stationID; @@ -134,7 +135,7 @@ SAEM_CODE_R saem_check(void* fc, bulletin_t* bulletin, SAEM_t* saem, uint8_t* ne pthread_mutex_unlock(&bulletin->lock); - return rv; + return rv == SAEM_NEW ? SAEM_NEW : SAEM_OK; } void bulletin_init(bulletin_t* bulletin) { @@ -206,7 +207,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); - enc = uper_encode_to_buffer(&asn_DEF_TollingPaymentInfo, NULL, facilities->tolling.infos.z[0], exts->list.array[2]->choice.applicationDataSAM.buf, 1024); + enc = uper_encode_to_buffer(&asn_DEF_TollingPaymentInfo, NULL, facilities->tolling.infos.z[0]->asn, 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; diff --git a/src/saem.h b/src/saem.h index 36c03b6..0de7013 100644 --- a/src/saem.h +++ b/src/saem.h @@ -43,12 +43,34 @@ typedef struct bulletin { typedef enum SAEM_CODE { SAEM_OK, + SAEM_NEW, SAEM_INVALID_HEADER_MESSAGE_ID, SAEM_INVALID_HEADER_VERSION } SAEM_CODE_R; +/** + * Initiaties bulletin, the main SA structure + * + * @param bulletin The structure to initialize + * @return Nothing + */ void bulletin_init(bulletin_t* bulletin); +/** + * Checks SAEM, saves advertisements + * + * @param fc The main facilities structure + * @param bulletin The main SA structure + * @param saem The SAEM message to check + * @param neighbour The certificate used by the neighbour, for encryption + * @return SAEM_CODE + */ SAEM_CODE_R saem_check(void* fc, bulletin_t* bulletin, SAEM_t* saem, uint8_t* neighbour); +/** + * The main SA function, run as a thread + * + * @param The main facilities structure + * @return NULL + */ void* sa_service(void* fc); diff --git a/src/tpm.h b/src/tpm.h index 6213eb6..43acc6b 100644 --- a/src/tpm.h +++ b/src/tpm.h @@ -42,7 +42,16 @@ typedef struct tolling { } 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);