From e00d7fc88cb380d33b894e65c1e71511f2a846cf Mon Sep 17 00:00:00 2001 From: emanuel Date: Mon, 10 Jan 2022 17:58:39 +0000 Subject: [PATCH] SAEM save neighbour sec ID --- src/facilities.c | 7 ++++++- src/sa.c | 9 +++++++-- src/sa.h | 4 +++- src/tpm.c | 13 ++++++++++++- src/tpm.h | 2 +- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/facilities.c b/src/facilities.c index fedafdb..a586667 100644 --- a/src/facilities.c +++ b/src/facilities.c @@ -198,7 +198,12 @@ static int transport_indication(facilities_t *facilities, void* responder, void* break; case Port_saem: - saem_check(facilities, &facilities->bulletin, its_msg); + saem_check( + facilities, + &facilities->bulletin, + its_msg, + tpi->choice.btp.gn.securityNeighbour ? tpi->choice.btp.gn.securityNeighbour->buf : NULL + ); break; case 7011: diff --git a/src/sa.c b/src/sa.c index 43df9ee..7b6065c 100644 --- a/src/sa.c +++ b/src/sa.c @@ -21,7 +21,7 @@ #define syslog_debug(msg, ...) #endif -SAEM_CODE_R saem_check(void* fc, bulletin_t* bulletin, SAEM_t* saem) { +SAEM_CODE_R saem_check(void* fc, bulletin_t* bulletin, SAEM_t* saem, uint8_t* neighbour) { facilities_t* facilities = (facilities_t*) fc; @@ -97,6 +97,11 @@ SAEM_CODE_R saem_check(void* fc, bulletin_t* bulletin, SAEM_t* saem) { } } + if (neighbour) { + bulletin->to_consume[bulletin->to_consume_len]->certificate_id = malloc(8); + memcpy(bulletin->to_consume[bulletin->to_consume_len]->certificate_id, neighbour, 8); + } + index = bulletin->to_consume_len; ++bulletin->to_consume_len; } @@ -343,7 +348,7 @@ void *sa_service(void *fc) { switch (facilities->tolling.protocol) { case TOLLING_PROTOCOL_SIMPLE: - tpm_pay(facilities); + tpm_pay(facilities, bulletin->to_consume[a]->certificate_id); ++bulletin->to_consume[a]->n_trigger; break; diff --git a/src/sa.h b/src/sa.h index f37169b..b251181 100644 --- a/src/sa.h +++ b/src/sa.h @@ -10,6 +10,8 @@ typedef struct announcement { uint8_t protocol_id; uint8_t traffic_class; + uint8_t* certificate_id; /* neighbour security-layer identity */ + struct { uint8_t ipv6_addr[16]; uint16_t port; @@ -46,6 +48,6 @@ typedef enum SAEM_CODE { void bulletin_init(bulletin_t* bulletin); -SAEM_CODE_R saem_check(void* fc, bulletin_t* bulletin, SAEM_t* saem); +SAEM_CODE_R saem_check(void* fc, bulletin_t* bulletin, SAEM_t* saem, uint8_t* neighbour); void* sa_service(void* fc); diff --git a/src/tpm.c b/src/tpm.c index c9032e7..6daf126 100644 --- a/src/tpm.c +++ b/src/tpm.c @@ -7,7 +7,7 @@ #include #include -int tpm_pay(void* fc) { +int tpm_pay(void* fc, uint8_t* neighbour) { int rv = 0; facilities_t* facilities = (facilities_t*) fc; @@ -112,6 +112,14 @@ int tpm_pay(void* fc) { tr->choice.packet.present = TransportPacketRequest_PR_btp; BTPPacketRequest_t* bpr = &tr->choice.packet.choice.btp; + bpr->gn.securityProfile.encrypt = true; + bpr->gn.securityProfile.sign = true; + + bpr->gn.securityNeighbour = calloc(1, sizeof(OCTET_STRING_t)); + bpr->gn.securityNeighbour->size = 8; + bpr->gn.securityNeighbour->buf = malloc(8); + memcpy(bpr->gn.securityNeighbour->buf, neighbour, 8); + bpr->data.size = tpm_uper_len; bpr->data.buf = malloc(tpm_uper_len); memcpy(bpr->data.buf, buf, tpm_uper_len); @@ -209,6 +217,9 @@ static void rsu_handle_recv(facilities_t* facilities, TollRequest_t* req, uint8_ tr->choice.packet.present = TransportPacketRequest_PR_btp; BTPPacketRequest_t* bpr = &tr->choice.packet.choice.btp; + bpr->gn.securityProfile.encrypt = true; + bpr->gn.securityProfile.sign = true; + bpr->data.size = tpm_uper_len; bpr->data.buf = malloc(tpm_uper_len); memcpy(bpr->data.buf, buf, tpm_uper_len); diff --git a/src/tpm.h b/src/tpm.h index e33bf64..8431afa 100644 --- a/src/tpm.h +++ b/src/tpm.h @@ -22,5 +22,5 @@ typedef struct tolling { } tolling_s; -int tpm_pay(void* fc); +int tpm_pay(void* fc, uint8_t* neighbour); int tpm_recv(void* fc, TPM_t* tpm_rx, uint8_t* neighbour);