SAEM forwarding, documentation

This commit is contained in:
emanuel 2022-01-27 17:18:17 +00:00
parent e497628e7d
commit 5bd3925504
6 changed files with 64 additions and 13 deletions

View File

@ -140,6 +140,9 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
ssp_len = tpi->choice.btp.gn.securityPermissions->ssp.size; 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 // Manage message
switch (tpi->choice.btp.destinationPort) { switch (tpi->choice.btp.destinationPort) {
case Port_cam: case Port_cam:
@ -198,20 +201,17 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
break; break;
case Port_saem: case Port_saem:
saem_check( switch (saem_check(facilities, &facilities->bulletin, its_msg, neighbour_cert)) {
facilities, case SAEM_NEW:
&facilities->bulletin, fwd = true;
its_msg, break;
tpi->choice.btp.gn.securityNeighbour ? tpi->choice.btp.gn.securityNeighbour->buf : NULL default:
); break;
}
break; break;
case 7011: case 7011:
tpm_recv( tpm_recv(facilities, its_msg, neighbour_cert);
facilities,
its_msg,
tpi->choice.btp.gn.securityNeighbour ? tpi->choice.btp.gn.securityNeighbour->buf : NULL
);
break; break;
default: default:

15
src/mcm.c Normal file
View File

@ -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;
}

4
src/mcm.h Normal file
View File

@ -0,0 +1,4 @@
#pragma once
void* mc_service(void* fc);

View File

@ -53,6 +53,7 @@ SAEM_CODE_R saem_check(void* fc, bulletin_t* bulletin, SAEM_t* saem, uint8_t* ne
} }
if (index == -1) { if (index == -1) {
rv = SAEM_NEW;
if (bulletin->to_consume_len + 1 < MAX_ANNOUNCEMENTS_LEN) { 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]->its_aid = its_aid;
bulletin->to_consume[bulletin->to_consume_len]->station_id = saem->header.stationID; 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); pthread_mutex_unlock(&bulletin->lock);
return rv; return rv == SAEM_NEW ? SAEM_NEW : SAEM_OK;
} }
void bulletin_init(bulletin_t* bulletin) { 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]->present = ServiceInfoExt_PR_applicationDataSAM;
exts->list.array[2]->choice.applicationDataSAM.buf = malloc(1024); 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) { if (enc.encoded == -1) {
syslog_err("[facilities] [sa] failure to encode TollingPaymentInfo (%s)", enc.failed_type->name); syslog_err("[facilities] [sa] failure to encode TollingPaymentInfo (%s)", enc.failed_type->name);
rv = 1; rv = 1;

View File

@ -43,12 +43,34 @@ typedef struct bulletin {
typedef enum SAEM_CODE { typedef enum SAEM_CODE {
SAEM_OK, SAEM_OK,
SAEM_NEW,
SAEM_INVALID_HEADER_MESSAGE_ID, SAEM_INVALID_HEADER_MESSAGE_ID,
SAEM_INVALID_HEADER_VERSION SAEM_INVALID_HEADER_VERSION
} SAEM_CODE_R; } SAEM_CODE_R;
/**
* Initiaties bulletin, the main SA structure
*
* @param bulletin The structure to initialize
* @return Nothing
*/
void bulletin_init(bulletin_t* bulletin); 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); 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); void* sa_service(void* fc);

View File

@ -42,7 +42,16 @@ typedef struct tolling {
} tolling_s; } 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 tolling_init(tolling_s* tolling, void* zmq_ctx, char* security_address);
int tpm_pay(void* fc, uint8_t* neighbour); int tpm_pay(void* fc, uint8_t* neighbour);
int tpm_recv(void* fc, TPM_t* tpm_rx, 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); int tpm_is_inside_zone(void* fc, tolling_info_s* ti);