From 68e0291292822205544db5ed4e00589dd8c73f8d Mon Sep 17 00:00:00 2001 From: emanuel Date: Mon, 1 May 2023 21:16:54 +0100 Subject: [PATCH] Applicational extensions for EDM --- src/CMakeLists.txt | 1 - src/config.c | 2 ++ src/edm.c | 71 ++++++++++++++++++++++++++++++++++++++++++++-- src/edm.h | 47 ++++++------------------------ src/facilities.c | 10 +++---- src/facilities.h | 4 +++ src/requests.c | 57 +------------------------------------ src/requests.h | 1 - src/vcm.c | 32 +++++++++++++++++---- 9 files changed, 115 insertions(+), 110 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 651d0f7..be24d68 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,7 +32,6 @@ TARGET_LINK_LIBRARIES(it2s-itss-facilities -lit2s-asn-vcm -lit2s-asn-evcsnm -lit2s-asn-evrsrm - -lit2s-asn-verco -lit2s-tender -lit2s-obd -lm diff --git a/src/config.c b/src/config.c index edf0365..304d7d6 100644 --- a/src/config.c +++ b/src/config.c @@ -498,6 +498,8 @@ int facilities_config() { itss_epv_init(); + facilities.edm.enabled = true; + ManagementRequest_t* mreq = calloc(1, sizeof(ManagementRequest_t)); mreq->present = ManagementRequest_PR_attributes; mreq->choice.attributes.present = ManagementRequestAttributes_PR_get; diff --git a/src/edm.c b/src/edm.c index 285faf5..a7a815e 100644 --- a/src/edm.c +++ b/src/edm.c @@ -1,9 +1,74 @@ #include "edm.h" +#include "facilities.h" +#include +#include +#include + +int edm_encap(uint8_t* msg, uint16_t* msg_len, uint16_t msg_buf_len, int its_msg_type) { + edm_t* edm = &facilities.edm; + int rv = 0; + + FacilitiesIndication_t* fi = NULL; + FacilitiesResponse_t* fr = NULL; + + uint16_t b_len = 1380; + uint8_t b1[b_len], b2[b_len]; + + fi = calloc(1, sizeof(FacilitiesIndication_t)); + fi->present = FacilitiesIndication_PR_extension; + fi->choice.extension.data.size = *msg_len; + fi->choice.extension.data.buf = malloc(*msg_len); + memcpy(fi->choice.extension.data.buf, msg, *msg_len); + fi->choice.extension.itsMessageType = its_msg_type; + + b1[0] = ITSS_FACILITIES; + asn_enc_rval_t enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_FacilitiesIndication, fi, b1+1, b_len-1); + if (enc.encoded == -1) { + return 1; + } + + pthread_mutex_lock(&edm->lock); + itss_0send(edm->app_socket, b1, enc.encoded); + int rl = itss_0recv_rt(&edm->app_socket, b2, b_len, b1, enc.encoded+1, 1000); + if (rl == -1) { + rv = 1; + goto cleanup; + } + pthread_mutex_unlock(&edm->lock); + + asn_dec_rval_t dec = asn_decode(NULL, ATS_CANONICAL_OER, &asn_DEF_FacilitiesResponse, (void**) &fr, b2, rl); + if (dec.code != 0) { + rv = 1; + goto cleanup; + } + + if (fr->present != FacilitiesResponse_PR_extension || + fr->choice.extension.returnCode != 0) { + rv = 1; + goto cleanup; + } + + if (fr->choice.extension.extendedMsg.size > msg_buf_len) { + rv = 1; + goto cleanup; + } + + *msg_len = fr->choice.extension.extendedMsg.size; + memcpy(msg, fr->choice.extension.extendedMsg.buf, fr->choice.extension.extendedMsg.size); + +cleanup: + ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi); + ASN_STRUCT_FREE(asn_DEF_FacilitiesResponse, fr); + + return rv; +} + +int edm_decap(uint8_t* data, uint16_t data_len, int its_msg_type) { -int edm_encap(void* its_msg, int its_msg_type) { return 0; } -int edm_decap(uint8_t* data, uint16_t data_len) { - return 0; +void edm_init() { + facilities.edm.app_socket = itss_0connect(facilities.zmq.applications_address, ZMQ_REQ); + pthread_mutex_init(&facilities.edm.lock, NULL); } diff --git a/src/edm.h b/src/edm.h index 09f1742..d0be32f 100644 --- a/src/edm.h +++ b/src/edm.h @@ -1,47 +1,16 @@ #pragma once #include +#include +#include -#define EDM_VE_MAX_MSGS 16 -#define EDM_MAX_VES 16 - -typedef enum VE_MSG_TYPE { - iid, - hash -} VE_MSG_TYPE_e; - -/* - * event message - */ -typedef struct ve_msg { - VE_MSG_TYPE_e present; - union { - uint32_t iid; - uint8_t hash[32]; - } choice; -} ve_msg_t; - -/* - * event - */ -typedef struct ve { - uint32_t id; - - uint64_t t_init; - uint64_t t_la; - - ve_msg_t* ve_msgs[EDM_VE_MAX_MSGS]; - uint8_t ve_msgs_len; -} ve_t; - -/* - * event data manager - */ typedef struct edm { - ve_t* ves[EDM_MAX_VES]; - uint8_t ves_len; + bool enabled; + pthread_mutex_t lock; + void* app_socket; } edm_t; +int edm_encap(uint8_t* msg, uint16_t* msg_len, uint16_t msg_buf_len, int its_msg_type); +int edm_decap(uint8_t* data, uint16_t data_len, int its_msg_type); -int edm_encap(void* its_msg, int its_msg_type); -int edm_decap(uint8_t* data, uint16_t data_len); +void edm_init(); diff --git a/src/facilities.c b/src/facilities.c index d90f40c..e2aaed4 100644 --- a/src/facilities.c +++ b/src/facilities.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -141,10 +140,6 @@ static int facilities_request(void *responder, uint8_t *msg, uint32_t msg_len) { rv = facilities_request_chaininfo_set(responder, &fr->choice.data.choice.chainInfoSet); break; - case FacilitiesDataRequest_PR_veeInfo: - rv = facilities_request_veeinfo(responder, &fr->choice.data.choice.veeInfo); - break; - default: log_error("<- unrecognized FDR type received (%d)", fr->choice.data.present); facilities_request_result_rejected(responder); @@ -501,6 +496,11 @@ int main() { if (facilities.evm_args.activate) pthread_create(&facilities.evcsn_service, NULL, evcsn_service, NULL); + // EDM + if (facilities.edm.enabled) { + edm_init(); + } + security_socket = itss_0connect(facilities.zmq.security_address, ZMQ_REQ); uint8_t buffer[ITSS_SDU_MAX_LEN]; diff --git a/src/facilities.h b/src/facilities.h index 2722045..36273a3 100644 --- a/src/facilities.h +++ b/src/facilities.h @@ -13,6 +13,7 @@ #include "tpm.h" #include "vcm.h" #include "evm.h" +#include "edm.h" #include #include @@ -75,6 +76,9 @@ typedef struct facilities { // EVCSN evm_args_t evm_args; + // EDM + edm_t edm; + // Logging struct { bool recorder; diff --git a/src/requests.c b/src/requests.c index 1da7377..47c0ad3 100644 --- a/src/requests.c +++ b/src/requests.c @@ -1,12 +1,12 @@ #include "requests.h" +#include #include #include #include #include #include #include -#include #include #include #include @@ -98,15 +98,6 @@ int facilities_request_single_message(void *responder, FacilitiesMessageRequest_ bpr->destinationPort = Port_cpm; bpr->gn.packetTransportType = PacketTransportType_shb; bpr->gn.trafficClass = 2; - - break; - - case 2044: // VERCOe - its_msg_def = &asn_DEF_VERCOe; - its_msg = calloc(1, sizeof(VERCOe_t)); - bpr->destinationPort = 2044; - bpr->gn.packetTransportType = PacketTransportType_shb; - bpr->gn.trafficClass = 2; break; case ItsMessageType_evrsr: @@ -605,45 +596,6 @@ cleanup: return rv; } -int facilities_request_veeinfo(void *responder, VEEInfo_t *vi) { - int rv = 0; - - pthread_mutex_lock(&facilities.coordination.lock); - /* - facilities.coordination.chain.id = cis->idSet; - for (int i = 0; i < cis->linkSet.list.count; ++i) { - memcpy( - facilities.coordination.chain.links[i], - cis->linkSet.list.array[i]->buf, - cis->linkSet.list.array[i]->size); - } - facilities.coordination.chain.n_links = cis->linkSet.list.count; - */ - pthread_mutex_unlock(&facilities.coordination.lock); - - FacilitiesReply_t *frep = calloc(1, sizeof(FacilitiesReply_t)); - frep->present = FacilitiesReply_PR_data; - frep->choice.data.present = FacilitiesDataReply_PR_veeInfo; - frep->choice.data.choice.veeInfo = FacilitiesResultCode_accepted; - - uint8_t frep_oer[64]; - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesReply, NULL, frep, frep_oer, 64); - if (enc.encoded == -1) { - log_error("failed encoding FDResult (%s)", enc.failed_type->name); - facilities_request_result_rejected(responder); - rv = 1; - goto cleanup; - } - - itss_0send(responder, frep_oer, enc.encoded); - -cleanup: - ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, frep); - - return rv; -} - - int transport_indication_btp(BTPPacketIndication_t* bpi, void** security_socket) { int rv = 0; @@ -705,13 +657,6 @@ int transport_indication_btp(BTPPacketIndication_t* bpi, void** security_socket) its_msg_type = 43; break; - case 2044: /* VERCOe */ - its_msg_descriptor = &asn_DEF_VERCOe; - its_msg = calloc(1, sizeof(VERCOe_t)); - its_msg_type = 44; - fwd = true; - break; - case Port_poi: /* EVCSNM */ its_msg_descriptor = &asn_DEF_EvcsnPdu; its_msg = calloc(1, sizeof(EvcsnPdu_t)); diff --git a/src/requests.h b/src/requests.h index 729aa50..7fad584 100644 --- a/src/requests.h +++ b/src/requests.h @@ -13,7 +13,6 @@ int facilities_request_active_episodes(void* responder, FacilitiesRequest_t* fr) int facilities_request_attribute_types(void* responder, FacilitiesRequest_t* fr); int facilities_request_loaded_protected_zones(void* responder, FacilitiesRequest_t* fr); int facilities_request_chaininfo_set(void* responder, ChainInformationSet_t* cis); -int facilities_request_veeinfo(void* responder, VEEInfo_t* vi); int transport_indication_data(TransportDataIndication_t* tdi); int transport_indication_btp(BTPPacketIndication_t* bpi, void** security_socket); diff --git a/src/vcm.c b/src/vcm.c index 0ffd3b4..f34af61 100644 --- a/src/vcm.c +++ b/src/vcm.c @@ -79,14 +79,26 @@ static void tx_vcm(VCM_t* vcm) { log_error("[vc] VCM.reply encode failure (%s)", enc.failed_type->name); goto cleanup; } - ssize_t vcm_rep_len = (enc.encoded + 7) / 8; + uint16_t vcm_len = (enc.encoded + 7) / 8; tr = calloc(1, sizeof(TransportRequest_t)); tr->present = TransportRequest_PR_packet; tr->choice.packet.present = TransportPacketRequest_PR_btp; BTPPacketRequest_t* bpr = &tr->choice.packet.choice.btp; bpr->btpType = BTPType_btpB; - bpr->id = itss_id(buf, vcm_rep_len); + + if (facilities.edm.enabled && + vcm->vcm.maneuverContainer.present == ManeuverContainer_PR_vehicle && + vcm->vcm.maneuverContainer.choice.vehicle.negotiation + ) { + edm_encap(buf, &vcm_len, buf_len, 2043); + bpr->destinationPortInfo = calloc(1, sizeof(OCTET_STRING_t)); + bpr->destinationPortInfo->size = 2; + bpr->destinationPortInfo->buf = malloc(2); + *(uint16_t*)bpr->destinationPortInfo->buf = 0xed; + } + + bpr->id = itss_id(buf, vcm_len); bpr->gn.destinationAddress.buf = malloc(6); for (int i = 0; i < 6; ++i) { bpr->gn.destinationAddress.buf[i] = 0xff; @@ -95,9 +107,9 @@ static void tx_vcm(VCM_t* vcm) { bpr->gn.packetTransportType = PacketTransportType_shb; bpr->destinationPort = 2043; bpr->gn.trafficClass = 2; - bpr->data.buf = malloc(vcm_rep_len); - memcpy(bpr->data.buf, buf, vcm_rep_len); - bpr->data.size = vcm_rep_len; + bpr->data.buf = malloc(vcm_len); + memcpy(bpr->data.buf, buf, vcm_len); + bpr->data.size = vcm_len; buf[0] = 4; enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_TransportRequest, tr, buf+1, buf_len-1); if (enc.encoded == -1) { @@ -183,6 +195,7 @@ static void vcm_reject(VCM_t* vcm, mc_neighbour_s* neighbour) { vcm_rep->vcm.currentPosition.longitude = lon; asn_ulong2INTEGER(&vcm_rep->vcm.currentPosition.timestamp, now); + /* if (coordination->chain.enabled && coordination->chain.id) { vcm_rep->vcm.chain = calloc(1, sizeof(ChainInformation_t)); vcm_rep->vcm.chain->id = coordination->chain.id; @@ -199,6 +212,7 @@ static void vcm_reject(VCM_t* vcm, mc_neighbour_s* neighbour) { vcm_rep->vcm.chain->area->trees.list.array[q]->size = 4; } } + */ vcm_rep->vcm.maneuverContainer.present = ManeuverContainer_PR_vehicle; ManeuverVehicleContainer_t* mvc_rep = &vcm_rep->vcm.maneuverContainer.choice.vehicle; @@ -348,6 +362,7 @@ static bool commit() { mvc->negotiation->choice.commit.qp.choice.requesterId = coordination->session.requester->station_id; } + /* if (coordination->chain.enabled && coordination->chain.id) { vcm_com->vcm.chain = calloc(1, sizeof(ChainInformation_t)); vcm_com->vcm.chain->id = coordination->chain.id; @@ -364,6 +379,7 @@ static bool commit() { vcm_com->vcm.chain->area->trees.list.array[q]->size = 4; } } + */ tx_vcm(vcm_com); ASN_STRUCT_FREE(asn_DEF_VCM, vcm_com); @@ -495,6 +511,7 @@ static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) { vcm_rep->vcm.currentPosition.longitude = lon; asn_ulong2INTEGER(&vcm_rep->vcm.currentPosition.timestamp, now); + /* if (coordination->chain.enabled && coordination->chain.id && vcm->vcm.chain) { vcm_rep->vcm.chain = calloc(1, sizeof(ChainInformation_t)); vcm_rep->vcm.chain->id = coordination->chain.id; @@ -520,6 +537,7 @@ static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) { vcm_rep->vcm.chain->area->trees.list.array[q]->size = 4; } } + */ vcm_rep->vcm.maneuverContainer.present = ManeuverContainer_PR_vehicle; ManeuverVehicleContainer_t* mvc_rep = &vcm_rep->vcm.maneuverContainer.choice.vehicle; @@ -743,6 +761,7 @@ static int intersection_detected(VCM_t* vcm, mc_neighbour_s* neighbour) { vcm_req->vcm.currentPosition.longitude = lon; asn_ulong2INTEGER(&vcm_req->vcm.currentPosition.timestamp, now); + /* if (coordination->chain.enabled && coordination->chain.id) { vcm_req->vcm.chain = calloc(1, sizeof(ChainInformation_t)); vcm_req->vcm.chain->id = coordination->chain.id; @@ -759,6 +778,7 @@ static int intersection_detected(VCM_t* vcm, mc_neighbour_s* neighbour) { vcm_req->vcm.chain->area->trees.list.array[q]->size = 4; } } + */ vcm_req->vcm.maneuverContainer.present = ManeuverContainer_PR_vehicle; ManeuverVehicleContainer_t* mvc = &vcm_req->vcm.maneuverContainer.choice.vehicle; @@ -1052,6 +1072,7 @@ static int mk_vcm() { vcm->vcm.currentPosition.longitude = lon; asn_ulong2INTEGER(&vcm->vcm.currentPosition.timestamp, now); + /* if (coordination->chain.enabled && coordination->chain.id) { vcm->vcm.chain = calloc(1, sizeof(ChainInformation_t)); vcm->vcm.chain->id = coordination->chain.id; @@ -1068,6 +1089,7 @@ static int mk_vcm() { vcm->vcm.chain->area->trees.list.array[q]->size = 4; } } + */ if (facilities.station_type == StationType_roadSideUnit) { vcm->vcm.maneuverContainer.present = ManeuverContainer_PR_rsu;