From afeeb9d18602aa0b9c7aec24fbf594b543756e06 Mon Sep 17 00:00:00 2001 From: emanuel Date: Thu, 25 Jan 2024 15:20:06 +0000 Subject: [PATCH] Prefixed ASN.1 types --- src/CMakeLists.txt | 28 +-- src/cam.c | 192 ++++++++++---------- src/cam.h | 8 +- src/config.c | 74 ++++---- src/cpm.c | 96 +++++----- src/cpm.h | 2 +- src/denm.c | 30 +-- src/denm.h | 6 +- src/edm.c | 22 +-- src/evm.c | 176 +++++++++--------- src/evm.h | 22 +-- src/facilities.c | 102 +++++------ src/indications.c | 26 +-- src/indications.h | 4 +- src/infrastructure.c | 72 ++++---- src/infrastructure.h | 4 +- src/requests.c | 419 +++++++++++++++++++++--------------------- src/requests.h | 16 +- src/saem.c | 102 +++++------ src/saem.h | 4 +- src/tpm.c | 422 +++++++++++++++++++++---------------------- src/tpm.h | 12 +- src/vcm.c | 200 ++++++++++---------- src/vcm.h | 6 +- 24 files changed, 1023 insertions(+), 1022 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 61091e1..bdf19ef 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,22 +15,24 @@ ADD_EXECUTABLE(it2s-itss-facilities ) TARGET_LINK_LIBRARIES(it2s-itss-facilities - -lit2s-asn-itss-facilities - -lit2s-asn-itss-security - -lit2s-asn-itss-management - -lit2s-asn-itss-networking + -lit2s-asn-etsi-its-sdu-itss-facilities + -lit2s-asn-etsi-its-sdu-itss-security + -lit2s-asn-etsi-its-sdu-itss-management + -lit2s-asn-etsi-its-sdu-itss-networking + -lit2s-asn-etsi-its-sdu-cdd-1.3.1 -lzmq -lpthread -lit2s-config-etsi-its - -lit2s-asn-camv2 - -lit2s-asn-ivim - -lit2s-asn-denmv2 - -lit2s-asn-cpm - -lit2s-asn-saem - -lit2s-asn-tpm - -lit2s-asn-vcm - -lit2s-asn-evcsnm - -lit2s-asn-evrsrm + -lit2s-asn-etsi-its-v1-cdd-1.3.1 + -lit2s-asn-etsi-its-v1-cam + -lit2s-asn-etsi-its-v1-ivim + -lit2s-asn-etsi-its-v1-denm + -lit2s-asn-etsi-its-v1-cpm + -lit2s-asn-etsi-its-v1-saem + -lit2s-asn-etsi-its-v1-tpm + -lit2s-asn-etsi-its-v1-vcm + -lit2s-asn-etsi-its-v1-evcsnm + -lit2s-asn-etsi-its-v1-evrsrm -lit2s-tender -lm -lrt diff --git a/src/cam.c b/src/cam.c index b671919..79250c6 100644 --- a/src/cam.c +++ b/src/cam.c @@ -1,10 +1,10 @@ #include "cam.h" #include "facilities.h" -#include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -161,22 +161,22 @@ static int mk_cam(uint8_t *cam_oer, uint16_t *cam_len) { lightship_t* lightship = &facilities.lightship; - CAM_t *cam = calloc(1, sizeof(CAM_t)); + EI1_CAM_t *cam = calloc(1, sizeof(EI1_CAM_t)); cam->header.protocolVersion = 2; - cam->header.messageID = messageID_cam; + cam->header.messageID = EI1_messageID_cam; pthread_mutex_lock(&facilities.id.lock); cam->header.stationID = facilities.id.station_id; pthread_mutex_unlock(&facilities.id.lock); cam->cam.camParameters.basicContainer.stationType = facilities.station_type; - BasicContainer_t* bc = &cam->cam.camParameters.basicContainer; + EI1_BasicContainer_t* bc = &cam->cam.camParameters.basicContainer; uint64_t now = itss_time_get(); pthread_mutex_lock(&lightship->lock); - if (facilities.station_type != StationType_roadSideUnit) { + if (facilities.station_type != EI1_StationType_roadSideUnit) { cam->cam.generationDeltaTime = now % 65536; itss_space_lock(); @@ -190,8 +190,8 @@ static int mk_cam(uint8_t *cam_oer, uint16_t *cam_len) { uint16_t lat_conf = epv.space.latitude_conf; uint16_t lon_conf = epv.space.longitude_conf; - cam->cam.camParameters.highFrequencyContainer.present = HighFrequencyContainer_PR_basicVehicleContainerHighFrequency; - BasicVehicleContainerHighFrequency_t* bvc_hf = &cam->cam.camParameters.highFrequencyContainer.choice.basicVehicleContainerHighFrequency; + cam->cam.camParameters.highFrequencyContainer.present = EI1_HighFrequencyContainer_PR_basicVehicleContainerHighFrequency; + EI1_BasicVehicleContainerHighFrequency_t* bvc_hf = &cam->cam.camParameters.highFrequencyContainer.choice.basicVehicleContainerHighFrequency; // Set speed bvc_hf->speed.speedValue = epv.space.speed; @@ -215,15 +215,15 @@ static int mk_cam(uint8_t *cam_oer, uint16_t *cam_len) { bvc_hf->vehicleWidth = facilities.vehicle.width; bvc_hf->vehicleLength.vehicleLengthValue = facilities.vehicle.length; - bvc_hf->vehicleLength.vehicleLengthConfidenceIndication = VehicleLengthConfidenceIndication_unavailable; - bvc_hf->longitudinalAcceleration.longitudinalAccelerationValue = LongitudinalAccelerationValue_unavailable; - bvc_hf->longitudinalAcceleration.longitudinalAccelerationConfidence = AccelerationConfidence_unavailable; + bvc_hf->vehicleLength.vehicleLengthConfidenceIndication = EI1_VehicleLengthConfidenceIndication_unavailable; + bvc_hf->longitudinalAcceleration.longitudinalAccelerationValue = EI1_LongitudinalAccelerationValue_unavailable; + bvc_hf->longitudinalAcceleration.longitudinalAccelerationConfidence = EI1_AccelerationConfidence_unavailable; - bvc_hf->driveDirection = DriveDirection_unavailable; - bvc_hf->curvature.curvatureValue = CurvatureValue_unavailable; - bvc_hf->curvature.curvatureConfidence = CurvatureConfidence_unavailable; - bvc_hf->yawRate.yawRateValue = YawRateValue_unavailable; - bvc_hf->yawRate.yawRateConfidence = YawRateConfidence_unavailable; + bvc_hf->driveDirection = EI1_DriveDirection_unavailable; + bvc_hf->curvature.curvatureValue = EI1_CurvatureValue_unavailable; + bvc_hf->curvature.curvatureConfidence = EI1_CurvatureConfidence_unavailable; + bvc_hf->yawRate.yawRateValue = EI1_YawRateValue_unavailable; + bvc_hf->yawRate.yawRateConfidence = EI1_YawRateConfidence_unavailable; /* // Save current values @@ -260,72 +260,72 @@ static int mk_cam(uint8_t *cam_oer, uint16_t *cam_len) { else if (long_a < -160) long_a = -160; bvc_hf->longitudinalAcceleration.longitudinalAccelerationValue = long_a; - bvc_hf->longitudinalAcceleration.longitudinalAccelerationConfidence = AccelerationConfidence_unavailable; + bvc_hf->longitudinalAcceleration.longitudinalAccelerationConfidence = EI1_AccelerationConfidence_unavailable; } else { - bvc_hf->longitudinalAcceleration.longitudinalAccelerationValue = LongitudinalAccelerationValue_unavailable; - bvc_hf->longitudinalAcceleration.longitudinalAccelerationConfidence = AccelerationConfidence_unavailable; + bvc_hf->longitudinalAcceleration.longitudinalAccelerationValue = EI1_LongitudinalAccelerationValue_unavailable; + bvc_hf->longitudinalAcceleration.longitudinalAccelerationConfidence = EI1_AccelerationConfidence_unavailable; } // Low frequency container if (now > lightship->t_last_cam_lfc + 500) { - cam->cam.camParameters.lowFrequencyContainer = calloc(1, sizeof(LowFrequencyContainer_t)); + cam->cam.camParameters.lowFrequencyContainer = calloc(1, sizeof(EI1_LowFrequencyContainer_t)); - cam->cam.camParameters.lowFrequencyContainer->present = LowFrequencyContainer_PR_basicVehicleContainerLowFrequency; + cam->cam.camParameters.lowFrequencyContainer->present = EI1_LowFrequencyContainer_PR_basicVehicleContainerLowFrequency; - BasicVehicleContainerLowFrequency_t* bvc_lf = &cam->cam.camParameters.lowFrequencyContainer->choice.basicVehicleContainerLowFrequency; + EI1_BasicVehicleContainerLowFrequency_t* bvc_lf = &cam->cam.camParameters.lowFrequencyContainer->choice.basicVehicleContainerLowFrequency; - PathHistory_t* ph = &cam->cam.camParameters.lowFrequencyContainer->choice.basicVehicleContainerLowFrequency.pathHistory; + EI1_PathHistory_t* ph = &cam->cam.camParameters.lowFrequencyContainer->choice.basicVehicleContainerLowFrequency.pathHistory; if (lightship->path_history_len != 0) { ph->list.array = malloc((lightship->path_history_len) * sizeof(void*)); ph->list.count = lightship->path_history_len; ph->list.size = (lightship->path_history_len) * sizeof(void*); - ph->list.array[0] = calloc(1,sizeof(PathPoint_t)); + ph->list.array[0] = calloc(1,sizeof(EI1_PathPoint_t)); - if (lightship->path_history[0]->alt != AltitudeValue_unavailable && pn.alt != AltitudeValue_unavailable) { + if (lightship->path_history[0]->alt != EI1_AltitudeValue_unavailable && pn.alt != EI1_AltitudeValue_unavailable) { ph->list.array[0]->pathPosition.deltaAltitude = lightship->path_history[0]->alt - pn.alt; } else { - ph->list.array[0]->pathPosition.deltaAltitude = DeltaAltitude_unavailable; + ph->list.array[0]->pathPosition.deltaAltitude = EI1_DeltaAltitude_unavailable; } - if (lightship->path_history[0]->lat != Latitude_unavailable && pn.lat != Latitude_unavailable) { + if (lightship->path_history[0]->lat != EI1_Latitude_unavailable && pn.lat != EI1_Latitude_unavailable) { ph->list.array[0]->pathPosition.deltaLatitude = lightship->path_history[0]->lat - pn.lat; } else { - ph->list.array[0]->pathPosition.deltaLatitude = DeltaLatitude_unavailable; + ph->list.array[0]->pathPosition.deltaLatitude = EI1_DeltaLatitude_unavailable; } - if (lightship->path_history[0]->lon != Longitude_unavailable && pn.lon != Longitude_unavailable) { + if (lightship->path_history[0]->lon != EI1_Longitude_unavailable && pn.lon != EI1_Longitude_unavailable) { ph->list.array[0]->pathPosition.deltaLongitude = lightship->path_history[0]->lon - pn.lon; } else { - ph->list.array[0]->pathPosition.deltaLongitude = DeltaLongitude_unavailable; + ph->list.array[0]->pathPosition.deltaLongitude = EI1_DeltaLongitude_unavailable; } - ph->list.array[0]->pathDeltaTime = calloc(1,sizeof(PathDeltaTime_t)); + ph->list.array[0]->pathDeltaTime = calloc(1,sizeof(EI1_PathDeltaTime_t)); *ph->list.array[0]->pathDeltaTime = (pn.ts - lightship->path_history[0]->ts)/10; for (int i = 1; i < lightship->path_history_len; ++i) { - ph->list.array[i] = calloc(1,sizeof(PathPoint_t)); + ph->list.array[i] = calloc(1,sizeof(EI1_PathPoint_t)); - if (lightship->path_history[i]->alt != AltitudeValue_unavailable && lightship->path_history[i-1]->alt != AltitudeValue_unavailable) { + if (lightship->path_history[i]->alt != EI1_AltitudeValue_unavailable && lightship->path_history[i-1]->alt != EI1_AltitudeValue_unavailable) { ph->list.array[i]->pathPosition.deltaAltitude = lightship->path_history[i]->alt - lightship->path_history[i-1]->alt; } else { - ph->list.array[i]->pathPosition.deltaAltitude = DeltaAltitude_unavailable; + ph->list.array[i]->pathPosition.deltaAltitude = EI1_DeltaAltitude_unavailable; } - if (lightship->path_history[i]->lat != Latitude_unavailable && lightship->path_history[i-1]->lat != Latitude_unavailable) { + if (lightship->path_history[i]->lat != EI1_Latitude_unavailable && lightship->path_history[i-1]->lat != EI1_Latitude_unavailable) { ph->list.array[i]->pathPosition.deltaLatitude = lightship->path_history[i]->lat - lightship->path_history[i-1]->lat; } else { - ph->list.array[i]->pathPosition.deltaLatitude = DeltaLatitude_unavailable; + ph->list.array[i]->pathPosition.deltaLatitude = EI1_DeltaLatitude_unavailable; } - if (lightship->path_history[i]->lon != Longitude_unavailable && lightship->path_history[i-1]->lon != Longitude_unavailable) { + if (lightship->path_history[i]->lon != EI1_Longitude_unavailable && lightship->path_history[i-1]->lon != EI1_Longitude_unavailable) { ph->list.array[i]->pathPosition.deltaLongitude = lightship->path_history[i]->lon - lightship->path_history[i-1]->lon; } else { - ph->list.array[i]->pathPosition.deltaLongitude = DeltaLongitude_unavailable; + ph->list.array[i]->pathPosition.deltaLongitude = EI1_DeltaLongitude_unavailable; } - ph->list.array[i]->pathDeltaTime = calloc(1,sizeof(PathDeltaTime_t)); + ph->list.array[i]->pathDeltaTime = calloc(1,sizeof(EI1_PathDeltaTime_t)); *ph->list.array[i]->pathDeltaTime = (lightship->path_history[i-1]->ts - lightship->path_history[i]->ts)/10; } } @@ -346,21 +346,21 @@ static int mk_cam(uint8_t *cam_oer, uint16_t *cam_len) { // Set GPS coordinates bc->referencePosition.latitude = epv.space.latitude; bc->referencePosition.longitude = epv.space.longitude; - bc->referencePosition.positionConfidenceEllipse.semiMinorConfidence = SemiAxisLength_unavailable; - bc->referencePosition.positionConfidenceEllipse.semiMajorConfidence = SemiAxisLength_unavailable; - bc->referencePosition.positionConfidenceEllipse.semiMajorOrientation = HeadingValue_unavailable; + bc->referencePosition.positionConfidenceEllipse.semiMinorConfidence = EI1_SemiAxisLength_unavailable; + bc->referencePosition.positionConfidenceEllipse.semiMajorConfidence = EI1_SemiAxisLength_unavailable; + bc->referencePosition.positionConfidenceEllipse.semiMajorOrientation = EI1_HeadingValue_unavailable; itss_space_unlock(); - cam->cam.camParameters.highFrequencyContainer.present = HighFrequencyContainer_PR_rsuContainerHighFrequency; + cam->cam.camParameters.highFrequencyContainer.present = EI1_HighFrequencyContainer_PR_rsuContainerHighFrequency; if (lightship->protected_zones.pz_len > 0) { - cam->cam.camParameters.highFrequencyContainer.choice.rsuContainerHighFrequency.protectedCommunicationZonesRSU = calloc(1, sizeof(ProtectedCommunicationZonesRSU_t)); - ProtectedCommunicationZonesRSU_t *pzs = cam->cam.camParameters.highFrequencyContainer.choice.rsuContainerHighFrequency.protectedCommunicationZonesRSU; + cam->cam.camParameters.highFrequencyContainer.choice.rsuContainerHighFrequency.protectedCommunicationZonesRSU = calloc(1, sizeof(EI1_ProtectedCommunicationZonesRSU_t)); + EI1_ProtectedCommunicationZonesRSU_t *pzs = cam->cam.camParameters.highFrequencyContainer.choice.rsuContainerHighFrequency.protectedCommunicationZonesRSU; pzs->list.count = lightship->protected_zones.pz_len; pzs->list.size = lightship->protected_zones.pz_len * sizeof(void*); pzs->list.array = malloc(lightship->protected_zones.pz_len * sizeof(void*)); for (int i = 0; i < lightship->protected_zones.pz_len; ++i) { - pzs->list.array[i] = calloc(1, sizeof(ProtectedCommunicationZone_t)); + pzs->list.array[i] = calloc(1, sizeof(EI1_ProtectedCommunicationZone_t)); pzs->list.array[i]->protectedZoneLatitude = lightship->protected_zones.pz[i]->protectedZoneLatitude; pzs->list.array[i]->protectedZoneLongitude = lightship->protected_zones.pz[i]->protectedZoneLongitude; pzs->list.array[i]->protectedZoneType = lightship->protected_zones.pz[i]->protectedZoneType; @@ -385,7 +385,7 @@ static int mk_cam(uint8_t *cam_oer, uint16_t *cam_len) { pthread_mutex_unlock(&lightship->lock); - asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_CAM, NULL, cam, cam_oer, 512); + asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_EI1_CAM, NULL, cam, cam_oer, 512); if (enc.encoded == -1) { log_error("[ca] failed encoding CAM (%s)", enc.failed_type->name); rv = 1; @@ -394,7 +394,7 @@ static int mk_cam(uint8_t *cam_oer, uint16_t *cam_len) { *cam_len = (enc.encoded + 7) / 8; cleanup: - ASN_STRUCT_FREE(asn_DEF_CAM, cam); + ASN_STRUCT_FREE(asn_DEF_EI1_CAM, cam); return rv; } @@ -420,7 +420,7 @@ int lightship_check() { pthread_mutex_lock(&lightship->lock); - if (lightship->type == StationType_roadSideUnit) { // RSU + if (lightship->type == EI1_StationType_roadSideUnit) { // RSU if (lightship->is_vehicle_near && now > lightship->next_cam_min) { rv = 1; } @@ -459,7 +459,7 @@ int lightship_check() { if (lightship->protected_zones.pz[i]->expiryTime) { asn_INTEGER2ulong(lightship->protected_zones.pz[i]->expiryTime, (unsigned long long*) &expiry); if (now >= expiry) { - ASN_STRUCT_FREE(asn_DEF_ProtectedCommunicationZone, lightship->protected_zones.pz[i]); + ASN_STRUCT_FREE(asn_DEF_EI1_ProtectedCommunicationZone, lightship->protected_zones.pz[i]); for (int j = i; j < lightship->protected_zones.pz_len - 1; ++j) { lightship->protected_zones.pz[j] = lightship->protected_zones.pz[j+1]; } @@ -483,7 +483,7 @@ void lightship_reset_timer() { pthread_mutex_lock(&lightship->lock); - if (lightship->type != StationType_roadSideUnit) { // Vehicle + if (lightship->type != EI1_StationType_roadSideUnit) { // Vehicle lightship->next_cam_max = now + lightship->vehicle_gen_max; lightship->next_cam_min = now + lightship->vehicle_gen_min; } else { // RSU @@ -496,7 +496,7 @@ void lightship_reset_timer() { pthread_mutex_unlock(&lightship->lock); } -enum CAM_CHECK_R check_cam(BTPPacketIndication_t *bpi, CAM_t* cam, uint8_t* ssp, uint32_t ssp_len) { +enum CAM_CHECK_R check_cam(EIS_BTPPacketIndication_t *bpi, EI1_CAM_t* cam, uint8_t* ssp, uint32_t ssp_len) { int rv = 0; lightship_t* lightship = &facilities.lightship; @@ -504,7 +504,7 @@ enum CAM_CHECK_R check_cam(BTPPacketIndication_t *bpi, CAM_t* cam, uint8_t* ssp, // Check permissions if (ssp) { - if (cam->cam.camParameters.highFrequencyContainer.present == HighFrequencyContainer_PR_rsuContainerHighFrequency && + if (cam->cam.camParameters.highFrequencyContainer.present == EI1_HighFrequencyContainer_PR_rsuContainerHighFrequency && cam->cam.camParameters.highFrequencyContainer.choice.rsuContainerHighFrequency.protectedCommunicationZonesRSU) { if (!permissions_check(CID_PROTECTED_ZONES, ssp, ssp_len)) { rv = CAM_BAD_PERMISSIONS; @@ -514,30 +514,30 @@ enum CAM_CHECK_R check_cam(BTPPacketIndication_t *bpi, CAM_t* cam, uint8_t* ssp, } if (cam->cam.camParameters.specialVehicleContainer) { switch (cam->cam.camParameters.specialVehicleContainer->present) { - case SpecialVehicleContainer_PR_NOTHING: + case EI1_SpecialVehicleContainer_PR_NOTHING: break; - case SpecialVehicleContainer_PR_publicTransportContainer: + case EI1_SpecialVehicleContainer_PR_publicTransportContainer: if (!permissions_check(CID_PUBLIC_TRANSPORT, ssp, ssp_len)) { rv = CAM_BAD_PERMISSIONS; log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_PUBLIC_TRANSPORT].container); return rv; } break; - case SpecialVehicleContainer_PR_specialTransportContainer: + case EI1_SpecialVehicleContainer_PR_specialTransportContainer: if (!permissions_check(CID_SPECIAL_TRANSPORT, ssp, ssp_len)) { rv = CAM_BAD_PERMISSIONS; log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_SPECIAL_TRANSPORT].container); return rv; } break; - case SpecialVehicleContainer_PR_dangerousGoodsContainer: + case EI1_SpecialVehicleContainer_PR_dangerousGoodsContainer: if (!permissions_check(CID_DANGEROUS_GOODS, ssp, ssp_len)) { rv = CAM_BAD_PERMISSIONS; log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_DANGEROUS_GOODS].container); return rv; } break; - case SpecialVehicleContainer_PR_roadWorksContainerBasic: + case EI1_SpecialVehicleContainer_PR_roadWorksContainerBasic: if (!permissions_check(CID_ROADWORK, ssp, ssp_len)) { rv = CAM_BAD_PERMISSIONS; log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_ROADWORK].container); @@ -551,14 +551,14 @@ enum CAM_CHECK_R check_cam(BTPPacketIndication_t *bpi, CAM_t* cam, uint8_t* ssp, } } break; - case SpecialVehicleContainer_PR_rescueContainer: + case EI1_SpecialVehicleContainer_PR_rescueContainer: if (!permissions_check(CID_RESCUE, ssp, ssp_len)) { rv = CAM_BAD_PERMISSIONS; log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_RESCUE].container); return rv; } break; - case SpecialVehicleContainer_PR_emergencyContainer: + case EI1_SpecialVehicleContainer_PR_emergencyContainer: if (!permissions_check(CID_EMERGENCY, ssp, ssp_len)) { rv = CAM_BAD_PERMISSIONS; log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_EMERGENCY].container); @@ -584,7 +584,7 @@ enum CAM_CHECK_R check_cam(BTPPacketIndication_t *bpi, CAM_t* cam, uint8_t* ssp, } } break; - case SpecialVehicleContainer_PR_safetyCarContainer: + case EI1_SpecialVehicleContainer_PR_safetyCarContainer: if (!permissions_check(CID_SAFETY_CAR, ssp, ssp_len)) { rv = CAM_BAD_PERMISSIONS; log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_SAFETY_CAR].container); @@ -592,14 +592,14 @@ enum CAM_CHECK_R check_cam(BTPPacketIndication_t *bpi, CAM_t* cam, uint8_t* ssp, } if (cam->cam.camParameters.specialVehicleContainer->choice.safetyCarContainer.trafficRule) { switch (*cam->cam.camParameters.specialVehicleContainer->choice.safetyCarContainer.trafficRule) { - case TrafficRule_noPassing: + case EI1_TrafficRule_noPassing: if (!permissions_check(CID_NO_PASSING, ssp, ssp_len)) { rv = CAM_BAD_PERMISSIONS; log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_NO_PASSING].container); return rv; } break; - case TrafficRule_noPassingForTrucks: + case EI1_TrafficRule_noPassingForTrucks: if (!permissions_check(CID_NO_PASSING_FOR_TRUCKS, ssp, ssp_len)) { rv = CAM_BAD_PERMISSIONS; log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_NO_PASSING_FOR_TRUCKS].container); @@ -624,17 +624,17 @@ enum CAM_CHECK_R check_cam(BTPPacketIndication_t *bpi, CAM_t* cam, uint8_t* ssp, } pthread_mutex_lock(&lightship->lock); - if (lightship->type == StationType_roadSideUnit) { + if (lightship->type == EI1_StationType_roadSideUnit) { // Send CAMs if vehicles nearby - if (bpi->stationType != StationType_roadSideUnit && bpi->isNeighbour) { + if (bpi->stationType != EI1_StationType_roadSideUnit && bpi->isNeighbour) { lightship->t_last_vehicle = now; lightship->is_vehicle_near = true; } } else { // Protected zones - if (cam->cam.camParameters.basicContainer.stationType == StationType_roadSideUnit && + if (cam->cam.camParameters.basicContainer.stationType == EI1_StationType_roadSideUnit && cam->cam.camParameters.highFrequencyContainer.choice.rsuContainerHighFrequency.protectedCommunicationZonesRSU) { - ProtectedCommunicationZonesRSU_t *pzs = cam->cam.camParameters.highFrequencyContainer.choice.rsuContainerHighFrequency.protectedCommunicationZonesRSU; + EI1_ProtectedCommunicationZonesRSU_t *pzs = cam->cam.camParameters.highFrequencyContainer.choice.rsuContainerHighFrequency.protectedCommunicationZonesRSU; if (pzs->list.count > 0 && pzs->list.count + lightship->protected_zones.pz_len < 255) { bool new_pz = false; @@ -652,7 +652,7 @@ enum CAM_CHECK_R check_cam(BTPPacketIndication_t *bpi, CAM_t* cam, uint8_t* ssp, new_pz = true; - lightship->protected_zones.pz[lightship->protected_zones.pz_len] = calloc(1, sizeof(ProtectedCommunicationZone_t)); + lightship->protected_zones.pz[lightship->protected_zones.pz_len] = calloc(1, sizeof(EI1_ProtectedCommunicationZone_t)); lightship->protected_zones.pz[lightship->protected_zones.pz_len]->protectedZoneLatitude = pzs->list.array[k]->protectedZoneLatitude; lightship->protected_zones.pz[lightship->protected_zones.pz_len]->protectedZoneLongitude = pzs->list.array[k]->protectedZoneLongitude; lightship->protected_zones.pz[lightship->protected_zones.pz_len]->protectedZoneType = pzs->list.array[k]->protectedZoneType; @@ -676,20 +676,20 @@ enum CAM_CHECK_R check_cam(BTPPacketIndication_t *bpi, CAM_t* cam, uint8_t* ssp, // Inform [management] if (new_pz) { uint8_t b_oer[512]; - ManagementRequest_t* mreq = calloc(1, sizeof(ManagementRequest_t)); - mreq->present = ManagementRequest_PR_attributes; - mreq->choice.attributes.present = ManagementRequestAttributes_PR_set; - mreq->choice.attributes.choice.set.protectedZones = calloc(1, sizeof(struct protectedZones)); + EIS_ManagementRequest_t* mreq = calloc(1, sizeof(EIS_ManagementRequest_t)); + mreq->present = EIS_ManagementRequest_PR_attributes; + mreq->choice.attributes.present = EIS_ManagementRequestAttributes_PR_set; + mreq->choice.attributes.choice.set.protectedZones = calloc(1, sizeof(struct EIS_protectedZones)); mreq->choice.attributes.choice.set.protectedZones->list.count = lightship->protected_zones.pz_len; mreq->choice.attributes.choice.set.protectedZones->list.size = lightship->protected_zones.pz_len * sizeof(void*); mreq->choice.attributes.choice.set.protectedZones->list.array = calloc(lightship->protected_zones.pz_len, sizeof(void*)); for (int p = 0; p < lightship->protected_zones.pz_len; ++p) { - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_ProtectedCommunicationZone, NULL, lightship->protected_zones.pz[p], b_oer, 512); - oer_decode(NULL, &asn_DEF_ProtectedCommunicationZone, (void**) &mreq->choice.attributes.choice.set.protectedZones->list.array[p], b_oer, enc.encoded); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_ProtectedCommunicationZone, NULL, lightship->protected_zones.pz[p], b_oer, 512); + oer_decode(NULL, &asn_DEF_EIS_ProtectedCommunicationZone, (void**) &mreq->choice.attributes.choice.set.protectedZones->list.array[p], b_oer, enc.encoded); } - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_ManagementRequest, NULL, mreq, b_oer, 512); - ASN_STRUCT_FREE(asn_DEF_ManagementRequest, mreq); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_ManagementRequest, NULL, mreq, b_oer, 512); + ASN_STRUCT_FREE(asn_DEF_EIS_ManagementRequest, mreq); void* management_socket = itss_0connect(facilities.zmq.management_address, ZMQ_REQ); itss_0send(management_socket, b_oer, enc.encoded); log_debug("[ca]-> sending MReq.attributes.set.protectedZones to ->[management]"); @@ -739,23 +739,23 @@ static int check_pz() { void* ca_service() { int rv = 0; - NetworkingRequest_t* nr = calloc(1, sizeof(NetworkingRequest_t)); - nr->present = NetworkingRequest_PR_packet; - NetworkingPacketRequest_t* npr = &nr->choice.packet; + EIS_NetworkingRequest_t* nr = calloc(1, sizeof(EIS_NetworkingRequest_t)); + nr->present = EIS_NetworkingRequest_PR_packet; + EIS_NetworkingPacketRequest_t* npr = &nr->choice.packet; - npr->network.present = NetworkingPacketRequestNW_PR_gn; + npr->network.present = EIS_NetworkingPacketRequestNW_PR_gn; npr->network.choice.gn.trafficClass = 2; npr->network.choice.gn.destinationAddress.buf = malloc(6); for (int i = 0; i < 6; ++i) { npr->network.choice.gn.destinationAddress.buf[i] = 0xff; } npr->network.choice.gn.destinationAddress.size = 6; - npr->network.choice.gn.packetTransportType = PacketTransportType_shb; + npr->network.choice.gn.packetTransportType = EIS_PacketTransportType_shb; npr->network.choice.gn.securityProfile.sign = true; - npr->transport.present = NetworkingPacketRequestTP_PR_btp; - npr->transport.choice.btp.btpType = BTPType_btpB; - npr->transport.choice.btp.destinationPort = Port_cam; + npr->transport.present = EIS_NetworkingPacketRequestTP_PR_btp; + npr->transport.choice.btp.btpType = EIS_BTPType_btpB; + npr->transport.choice.btp.destinationPort = EIS_Port_cam; if (facilities.edm.enabled) { npr->transport.choice.btp.destinationPortInfo = calloc(1, sizeof(OCTET_STRING_t)); npr->transport.choice.btp.destinationPortInfo->size = 2; @@ -768,10 +768,10 @@ void* ca_service() { // Fill header for FacilitiesIndication and FacilitiesMessageIndication structs - FacilitiesIndication_t* fi = calloc(1,sizeof(FacilitiesIndication_t)); - fi->present = FacilitiesIndication_PR_message; - FacilitiesMessageIndication_t* fmi = &fi->choice.message; - fmi->itsMessageType = ItsMessageType_cam; + EIS_FacilitiesIndication_t* fi = calloc(1,sizeof(EIS_FacilitiesIndication_t)); + fi->present = EIS_FacilitiesIndication_PR_message; + EIS_FacilitiesMessageIndication_t* fmi = &fi->choice.message; + fmi->itsMessageType = EIS_ItsMessageType_cam; fmi->data.buf = malloc(buf_len); uint8_t nr_oer[buf_len]; @@ -788,7 +788,7 @@ void* ca_service() { } if (facilities.edm.enabled) { - edm_encap(npr->data.buf, (uint16_t*) &npr->data.size, buf_len, Port_cam); + edm_encap(npr->data.buf, (uint16_t*) &npr->data.size, buf_len, EIS_Port_cam); } memcpy(fmi->data.buf, npr->data.buf, npr->data.size); @@ -802,13 +802,13 @@ void* ca_service() { npr->id = id; fmi->id = id; - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_NetworkingRequest, NULL, nr, nr_oer+1, 1023); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_NetworkingRequest, NULL, nr, nr_oer+1, 1023); if (enc.encoded == -1) { log_error("encoding TR for cam failed"); continue; } - asn_enc_rval_t enc_fdi = oer_encode_to_buffer(&asn_DEF_FacilitiesIndication, NULL, fi, fi_oer+1, 1023); + asn_enc_rval_t enc_fdi = oer_encode_to_buffer(&asn_DEF_EIS_FacilitiesIndication, NULL, fi, fi_oer+1, 1023); if(enc_fdi.encoded == -1){ log_error("encoding FI for cam failed"); continue; @@ -825,7 +825,7 @@ void* ca_service() { pthread_mutex_lock(&facilities.id.lock); uint32_t station_id = facilities.id.station_id; pthread_mutex_unlock(&facilities.id.lock); - itss_db_add(facilities.logging.dbms, station_id, npr->id, true, messageID_cam, NULL, npr->data.buf, npr->data.size); + itss_db_add(facilities.logging.dbms, station_id, npr->id, true, EI1_messageID_cam, NULL, npr->data.buf, npr->data.size); } if (facilities.logging.recorder) { @@ -848,8 +848,8 @@ void* ca_service() { } - ASN_STRUCT_FREE(asn_DEF_NetworkingRequest, nr); - ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi); + ASN_STRUCT_FREE(asn_DEF_EIS_NetworkingRequest, nr); + ASN_STRUCT_FREE(asn_DEF_EIS_FacilitiesIndication, fi); return NULL; } diff --git a/src/cam.h b/src/cam.h index afd63ba..71b770d 100644 --- a/src/cam.h +++ b/src/cam.h @@ -6,8 +6,8 @@ #include #include -#include -#include +#include +#include #include @@ -84,7 +84,7 @@ typedef struct lightship { uint32_t rsu_vehicle_permanence; struct { - ProtectedCommunicationZone_t ** pz; + EI1_ProtectedCommunicationZone_t ** pz; uint16_t pz_len; } protected_zones; @@ -116,7 +116,7 @@ void lightship_reset_timer(); * * @return A CAM check code */ -enum CAM_CHECK_R check_cam(BTPPacketIndication_t* bpi, CAM_t* cam,uint8_t* ssp, uint32_t ssp_len); +enum CAM_CHECK_R check_cam(EIS_BTPPacketIndication_t* bpi, EI1_CAM_t* cam,uint8_t* ssp, uint32_t ssp_len); /* * @brief Main CA service diff --git a/src/config.c b/src/config.c index e6aef44..14d5997 100644 --- a/src/config.c +++ b/src/config.c @@ -12,16 +12,16 @@ #include #include #include -#include -#include +#include +#include #include #include -#include -#include -#include -#include +#include +#include +#include +#include static int fetch_target_address(char** addresses, uint16_t addresses_len) { int index = -1; @@ -239,20 +239,20 @@ int facilities_config() { if (facilities.id.change.random) { // Ask [security] for station id - SecurityRequest_t* sREQ = calloc(1, sizeof(SecurityRequest_t)); - SecurityReply_t* sREP = NULL; + EIS_SecurityRequest_t* sREQ = calloc(1, sizeof(EIS_SecurityRequest_t)); + EIS_SecurityReply_t* sREP = NULL; - sREQ->present = SecurityRequest_PR_ids; + sREQ->present = EIS_SecurityRequest_PR_ids; sREQ->choice.ids.list.count = 2; sREQ->choice.ids.list.size = 2*sizeof(void*); sREQ->choice.ids.list.array = malloc(2*sizeof(void*)); - sREQ->choice.ids.list.array[0] = calloc(1, sizeof(SecurityIdType_t)); - *sREQ->choice.ids.list.array[0] = SecurityIdType_stationId; - sREQ->choice.ids.list.array[1] = calloc(1, sizeof(SecurityIdType_t)); - *sREQ->choice.ids.list.array[1] = SecurityIdType_ipv6Address; + sREQ->choice.ids.list.array[0] = calloc(1, sizeof(EIS_SecurityIdType_t)); + *sREQ->choice.ids.list.array[0] = EIS_SecurityIdType_stationId; + sREQ->choice.ids.list.array[1] = calloc(1, sizeof(EIS_SecurityIdType_t)); + *sREQ->choice.ids.list.array[1] = EIS_SecurityIdType_ipv6Address; uint8_t b_tx[256], b_rx[256]; - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sREQ, b_tx, 256); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityRequest, NULL, sREQ, b_tx, 256); void* ss = itss_0connect(facilities.zmq.security_address, ZMQ_REQ); itss_0send(ss, b_tx, enc.encoded); @@ -263,19 +263,19 @@ int facilities_config() { goto cleanup; } - asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &sREP, b_rx, 256); + asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_EIS_SecurityReply, (void**) &sREP, b_rx, 256); - if (sREP->returnCode == SecurityReplyReturnCode_rejected) { + if (sREP->returnCode == EIS_SecurityReplyReturnCode_rejected) { // TODO handle it goto cleanup; } for (int i = 0; i < sREP->data->choice.ids.list.count; ++i) { switch (sREP->data->choice.ids.list.array[i]->present) { - case SecurityId_PR_stationId: + case EIS_SecurityId_PR_stationId: facilities.id.station_id = sREP->data->choice.ids.list.array[i]->choice.stationId; break; - case SecurityId_PR_ipv6Address: + case EIS_SecurityId_PR_ipv6Address: memcpy(facilities.id.ipv6_addr, sREP->data->choice.ids.list.array[i]->choice.ipv6Address.buf, 16); break; default: @@ -283,8 +283,8 @@ int facilities_config() { } } - ASN_STRUCT_FREE(asn_DEF_SecurityRequest, sREQ); - ASN_STRUCT_FREE(asn_DEF_SecurityReply, sREP); + ASN_STRUCT_FREE(asn_DEF_EIS_SecurityRequest, sREQ); + ASN_STRUCT_FREE(asn_DEF_EIS_SecurityReply, sREP); } else { facilities.id.station_id = itss_cfg->security.identity.station_id; @@ -414,17 +414,17 @@ int facilities_config() { } fclose(fp); - ProtectedCommunicationZone_t *zone = calloc(1, sizeof(ProtectedCommunicationZone_t)); + EIS_ProtectedCommunicationZone_t *zone = calloc(1, sizeof(EIS_ProtectedCommunicationZone_t)); - asn_dec_rval_t dec = xer_decode(NULL, &asn_DEF_ProtectedCommunicationZone, (void**) &zone, pz_xml, size); + asn_dec_rval_t dec = xer_decode(NULL, &asn_DEF_EIS_ProtectedCommunicationZone, (void**) &zone, pz_xml, size); if (!dec.code) { - facilities.lightship.protected_zones.pz[i] = zone; + facilities.lightship.protected_zones.pz[i] = (EI1_ProtectedCommunicationZone_t*)zone; ++facilities.lightship.protected_zones.pz_len; ++i; log_debug("[config] loaded protection zone @ (%lld, %lld)", zone->protectedZoneLatitude, zone->protectedZoneLongitude); } else { log_error("[config] failure to decode protection zone '%s'", dir->d_name); - ASN_STRUCT_FREE(asn_DEF_ProtectedCommunicationZone, zone); + ASN_STRUCT_FREE(asn_DEF_EIS_ProtectedCommunicationZone, zone); } } @@ -460,9 +460,9 @@ int facilities_config() { } fclose(fp); - TollingPaymentInfo_t *ti = calloc(1, sizeof(TollingPaymentInfo_t)); + EI1_TollingPaymentInfo_t *ti = calloc(1, sizeof(EI1_TollingPaymentInfo_t)); - asn_dec_rval_t dec = xer_decode(NULL, &asn_DEF_TollingPaymentInfo, (void**) &ti, ti_xml, size); + asn_dec_rval_t dec = xer_decode(NULL, &asn_DEF_EI1_TollingPaymentInfo, (void**) &ti, ti_xml, size); if (!dec.code) { facilities.tolling.infos.z[i] = calloc(1, sizeof(tolling_info_t)); facilities.tolling.infos.z[i]->asn = ti; @@ -470,11 +470,11 @@ int facilities_config() { ++i; log_debug("[config] loaded tolling info | id:%lld type:%s", ti->id, - ti->tollType==TollType_entry ? "entry": ti->tollType==TollType_exit ? "exit": "single" + ti->tollType==EI1_TollType_entry ? "entry": ti->tollType==EI1_TollType_exit ? "exit": "single" ); } else { log_error("[config] failure to decode tolling info '%s'", dir->d_name); - ASN_STRUCT_FREE(asn_DEF_TollingPaymentInfo, ti); + ASN_STRUCT_FREE(asn_DEF_EI1_TollingPaymentInfo, ti); } } @@ -486,9 +486,9 @@ int facilities_config() { facilities.edm.enabled = itss_cfg->applications.extensions.enabled; - ManagementRequest_t* mreq = calloc(1, sizeof(ManagementRequest_t)); - mreq->present = ManagementRequest_PR_attributes; - mreq->choice.attributes.present = ManagementRequestAttributes_PR_get; + EIS_ManagementRequest_t* mreq = calloc(1, sizeof(EIS_ManagementRequest_t)); + mreq->present = EIS_ManagementRequest_PR_attributes; + mreq->choice.attributes.present = EIS_ManagementRequestAttributes_PR_get; mreq->choice.attributes.choice.get.coordinates = 1; mreq->choice.attributes.choice.get.altitude = 1; mreq->choice.attributes.choice.get.heading = 1; @@ -501,7 +501,7 @@ int facilities_config() { mreq->choice.attributes.choice.get.trajectory = etsi_its_cfg->facilities.mcm.activate; void* management_socket = itss_0connect(facilities.zmq.management_address, ZMQ_REQ); uint8_t b_tx[256], b_rx[256]; - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_ManagementRequest, NULL, mreq, b_tx, 256); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_ManagementRequest, NULL, mreq, b_tx, 256); itss_0send(management_socket, b_tx, enc.encoded); int rl = itss_0recv_rt(&management_socket, b_rx, 256, b_tx, 256, -1); @@ -511,10 +511,10 @@ int facilities_config() { goto cleanup; } - ManagementReply_t* mrep = calloc(1, sizeof(ManagementReply_t)); - oer_decode(NULL, &asn_DEF_ManagementReply, (void**) &mrep, b_rx, 256); + EIS_ManagementReply_t* mrep = calloc(1, sizeof(EIS_ManagementReply_t)); + oer_decode(NULL, &asn_DEF_EIS_ManagementReply, (void**) &mrep, b_rx, 256); long lat, lon, alt, alt_conf; - if (mrep->returnCode == ManagementReplyReturnCode_accepted && + if (mrep->returnCode == EIS_ManagementReplyReturnCode_accepted && mrep->data && mrep->data->choice.attributes.coordinates && mrep->data->choice.attributes.altitude && @@ -557,8 +557,8 @@ int facilities_config() { rv = 1; goto cleanup; } - ASN_STRUCT_FREE(asn_DEF_ManagementRequest, mreq); - ASN_STRUCT_FREE(asn_DEF_ManagementReply, mrep); + ASN_STRUCT_FREE(asn_DEF_EIS_ManagementRequest, mreq); + ASN_STRUCT_FREE(asn_DEF_EIS_ManagementReply, mrep); if (etsi_its_cfg->facilities.saem.activate) { // TODO handle various services facilities.bulletin.to_provide_len = 1; diff --git a/src/cpm.c b/src/cpm.c index 7f27963..729457c 100644 --- a/src/cpm.c +++ b/src/cpm.c @@ -1,12 +1,12 @@ #include "cpm.h" #include "facilities.h" -#include -#include +#include +#include #include #include #include -#include +#include #include #include @@ -479,9 +479,9 @@ long rotate_y(long x, long y) { return (long)(x * roadRotationSin + y * roadRotationCos); } -static void set_values(int i, int j, uint64_t timestamp, CPM_t* cpm_tx, long history_list[NOF_OBJECTS][4], int valid_array[], uint64_t history_timestamp[]){ +static void set_values(int i, int j, uint64_t timestamp, EI1_CPM_t* cpm_tx, long history_list[NOF_OBJECTS][4], int valid_array[], uint64_t history_timestamp[]){ /* Fill CPM */ - cpm_tx->cpm.cpmParameters.perceivedObjectContainer->list.array[j] = calloc(1, sizeof(PerceivedObject_t)); + cpm_tx->cpm.cpmParameters.perceivedObjectContainer->list.array[j] = calloc(1, sizeof(EI1_PerceivedObject_t)); cpm_tx->cpm.cpmParameters.perceivedObjectContainer->list.array[j]->objectID = (long)as_objects[i].u8_objectID; cpm_tx->cpm.cpmParameters.perceivedObjectContainer->list.array[j]->timeOfMeasurement = 0; //Sem informaƧao do radar cpm_tx->cpm.cpmParameters.perceivedObjectContainer->list.array[j]->objectConfidence = 95; @@ -497,46 +497,46 @@ static void set_values(int i, int j, uint64_t timestamp, CPM_t* cpm_tx, long his cpm_tx->cpm.cpmParameters.perceivedObjectContainer->list.array[j]->ySpeed.value = rotate_y( (long)as_objects[i].f_xSpeed * 100, (long)as_objects[i].f_ySpeed * 100); cpm_tx->cpm.cpmParameters.perceivedObjectContainer->list.array[j]->ySpeed.confidence = 40; - cpm_tx->cpm.cpmParameters.perceivedObjectContainer->list.array[j]->objectRefPoint = ObjectRefPoint_bottomMid; + cpm_tx->cpm.cpmParameters.perceivedObjectContainer->list.array[j]->objectRefPoint = EI1_ObjectRefPoint_bottomMid; /* Detected Object Class*/ - cpm_tx->cpm.cpmParameters.perceivedObjectContainer->list.array[j]->classification = calloc(1, sizeof(ObjectClassDescription_t)); - ObjectClassDescription_t *class = cpm_tx->cpm.cpmParameters.perceivedObjectContainer->list.array[j]->classification; + cpm_tx->cpm.cpmParameters.perceivedObjectContainer->list.array[j]->classification = calloc(1, sizeof(EI1_ObjectClassDescription_t)); + EI1_ObjectClassDescription_t *class = cpm_tx->cpm.cpmParameters.perceivedObjectContainer->list.array[j]->classification; class->list.size = 1 * sizeof(void*); class->list.array = malloc(1* sizeof(void*)); class->list.count = 1; - class->list.array[0] = calloc(1, sizeof(ObjectClass_t)); + class->list.array[0] = calloc(1, sizeof(EI1_ObjectClass_t)); class->list.array[0]->confidence = 0; int obj_len = (int)(as_objects[i].f_objectLength*10); if (obj_len == 10) { - class->list.array[0]->Class.present = class_PR_person; + class->list.array[0]->Class.present = EI1_class_PR_person; class->list.array[0]->Class.choice.person.type = 1; // pedestrian class->list.array[0]->Class.choice.person.confidence = 0; } else if (obj_len == 16) { - class->list.array[0]->Class.present = class_PR_person; + class->list.array[0]->Class.present = EI1_class_PR_person; class->list.array[0]->Class.choice.person.type = 3; // cyclist class->list.array[0]->Class.choice.person.confidence = 0; } else if (obj_len == 26) { - class->list.array[0]->Class.present = class_PR_vehicle; + class->list.array[0]->Class.present = EI1_class_PR_vehicle; class->list.array[0]->Class.choice.vehicle.type = 2; // motorcycle class->list.array[0]->Class.choice.vehicle.confidence = 0; } else if (obj_len >= 46 && obj_len <= 54) { - class->list.array[0]->Class.present = class_PR_vehicle; + class->list.array[0]->Class.present = EI1_class_PR_vehicle; class->list.array[0]->Class.choice.vehicle.type = 3; // passenger car class->list.array[0]->Class.choice.vehicle.confidence = 0; } else if (obj_len >= 56 && obj_len <= 88) { - class->list.array[0]->Class.present = class_PR_vehicle; + class->list.array[0]->Class.present = EI1_class_PR_vehicle; class->list.array[0]->Class.choice.vehicle.type = 5; // light truck class->list.array[0]->Class.choice.vehicle.confidence = 0; } else if (obj_len >= 90) { - class->list.array[0]->Class.present = class_PR_vehicle; + class->list.array[0]->Class.present = EI1_class_PR_vehicle; class->list.array[0]->Class.choice.vehicle.type = 6; // heavy truck class->list.array[0]->Class.choice.vehicle.confidence = 0; } else { - class->list.array[0]->Class.present = class_PR_other; + class->list.array[0]->Class.present = EI1_class_PR_other; class->list.array[0]->Class.choice.other.type = 0; // unknown class->list.array[0]->Class.choice.other.confidence = 0; } @@ -554,7 +554,7 @@ static void set_values(int i, int j, uint64_t timestamp, CPM_t* cpm_tx, long his static int mk_cpm(uint8_t *bdr_oer, uint32_t *bdr_len, uint8_t *fdi_oer, uint32_t *fdi_len, long history_list[NOF_OBJECTS][4], int valid_array[], uint64_t history_timestamp[]) { /* Variables */ - CPM_t* cpm_tx = calloc(1, sizeof(CPM_t)); + EI1_CPM_t* cpm_tx = calloc(1, sizeof(EI1_CPM_t)); long euclidian_dist, abs_speed, abs_speed_hist, angle, angle_hist, angle_diff; int j = 0, rv = 0; @@ -579,41 +579,41 @@ static int mk_cpm(uint8_t *bdr_oer, uint32_t *bdr_len, uint8_t *fdi_oer, uint32_ itss_space_unlock(); cpm_tx->cpm.generationDeltaTime = generationDeltaTime; - cpm_tx->cpm.cpmParameters.managementContainer.stationType = StationType_roadSideUnit; + cpm_tx->cpm.cpmParameters.managementContainer.stationType = EI1_StationType_roadSideUnit; cpm_tx->cpm.cpmParameters.managementContainer.referencePosition.latitude = lat; cpm_tx->cpm.cpmParameters.managementContainer.referencePosition.longitude = lon; cpm_tx->cpm.cpmParameters.managementContainer.referencePosition.positionConfidenceEllipse.semiMajorConfidence = 100; // TODO cpm_tx->cpm.cpmParameters.managementContainer.referencePosition.positionConfidenceEllipse.semiMinorConfidence = 100; // TODO - cpm_tx->cpm.cpmParameters.managementContainer.referencePosition.positionConfidenceEllipse.semiMajorOrientation = HeadingValue_wgs84North; // TODO + cpm_tx->cpm.cpmParameters.managementContainer.referencePosition.positionConfidenceEllipse.semiMajorOrientation = EI1_HeadingValue_wgs84North; // TODO cpm_tx->cpm.cpmParameters.managementContainer.referencePosition.altitude.altitudeValue = alt; cpm_tx->cpm.cpmParameters.managementContainer.referencePosition.altitude.altitudeConfidence = alt_conf; if(dissemination_check(0) == 1){ /* Sensor Information Container Inclusion Management */ - cpm_tx->cpm.cpmParameters.sensorInformationContainer = calloc(1, sizeof(SensorInformationContainer_t)); + cpm_tx->cpm.cpmParameters.sensorInformationContainer = calloc(1, sizeof(EI1_SensorInformationContainer_t)); cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.count = 1; cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.size = 1; - cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array = calloc(1, sizeof(SensorInformation_t)); - cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array[0] = calloc(1, sizeof(SensorInformation_t)); + cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array = calloc(1, sizeof(EI1_SensorInformation_t)); + cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array[0] = calloc(1, sizeof(EI1_SensorInformation_t)); cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array[0]->sensorID = 0; - cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array[0]->type = SensorType_radar; - cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array[0]->detectionArea.present = DetectionArea_PR_stationarySensorRadial; + cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array[0]->type = EI1_SensorType_radar; + cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array[0]->detectionArea.present = EI1_DetectionArea_PR_stationarySensorRadial; cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array[0]->detectionArea.choice.stationarySensorRadial.range = 3400; cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array[0]->detectionArea.choice.stationarySensorRadial.stationaryHorizontalOpeningAngleStart = facilities.dissemination.opening_angle_start; cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array[0]->detectionArea.choice.stationarySensorRadial.stationaryHorizontalOpeningAngleEnd = facilities.dissemination.opening_angle_end; - cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array[0]->detectionArea.choice.stationarySensorRadial.verticalOpeningAngleStart = calloc(1, sizeof(CartesianAngleValue_t)); + cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array[0]->detectionArea.choice.stationarySensorRadial.verticalOpeningAngleStart = calloc(1, sizeof(EI1_CartesianAngleValue_t)); (*cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array[0]->detectionArea.choice.stationarySensorRadial.verticalOpeningAngleStart) = 1730; - cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array[0]->detectionArea.choice.stationarySensorRadial.verticalOpeningAngleEnd = calloc(1, sizeof(CartesianAngleValue_t)); + cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array[0]->detectionArea.choice.stationarySensorRadial.verticalOpeningAngleEnd = calloc(1, sizeof(EI1_CartesianAngleValue_t)); (*cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array[0]->detectionArea.choice.stationarySensorRadial.verticalOpeningAngleEnd) = 1890; - cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array[0]->detectionArea.choice.stationarySensorRadial.sensorHeight = calloc(1, sizeof(SensorHeight_t)); + cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array[0]->detectionArea.choice.stationarySensorRadial.sensorHeight = calloc(1, sizeof(EI1_SensorHeight_t)); (*cpm_tx->cpm.cpmParameters.sensorInformationContainer->list.array[0]->detectionArea.choice.stationarySensorRadial.sensorHeight) = 600; dissemination_reset_timer(0); } if (s_objectControl.u8_numberOfObjects > 0) { - cpm_tx->cpm.cpmParameters.perceivedObjectContainer = calloc(1, sizeof(PerceivedObjectContainer_t)); - cpm_tx->cpm.cpmParameters.perceivedObjectContainer->list.array = calloc(s_objectControl.u8_numberOfObjects,sizeof(PerceivedObject_t*)); + cpm_tx->cpm.cpmParameters.perceivedObjectContainer = calloc(1, sizeof(EI1_PerceivedObjectContainer_t)); + cpm_tx->cpm.cpmParameters.perceivedObjectContainer->list.array = calloc(s_objectControl.u8_numberOfObjects,sizeof(EI1_PerceivedObject_t*)); cpm_tx->cpm.cpmParameters.perceivedObjectContainer->list.count = s_objectControl.u8_numberOfObjects; @@ -663,7 +663,7 @@ static int mk_cpm(uint8_t *bdr_oer, uint32_t *bdr_len, uint8_t *fdi_oer, uint32_ //BDR memset(bdr_oer, 0, 1500); - asn_enc_rval_t retval_enc_bdr = uper_encode_to_buffer(&asn_DEF_CPM, NULL, cpm_tx, bdr_oer, 1500); + asn_enc_rval_t retval_enc_bdr = uper_encode_to_buffer(&asn_DEF_EI1_CPM, NULL, cpm_tx, bdr_oer, 1500); if (retval_enc_bdr.encoded == -1) { log_error("[cp] failed encoding CPM (%s)", retval_enc_bdr.failed_type->name); rv = 1; @@ -674,7 +674,7 @@ static int mk_cpm(uint8_t *bdr_oer, uint32_t *bdr_len, uint8_t *fdi_oer, uint32_ //FDI memset(fdi_oer, 0, 1500); - asn_enc_rval_t retval_enc_fdi = uper_encode_to_buffer(&asn_DEF_CPM, NULL, cpm_tx, fdi_oer, 1500); + asn_enc_rval_t retval_enc_fdi = uper_encode_to_buffer(&asn_DEF_EI1_CPM, NULL, cpm_tx, fdi_oer, 1500); if (retval_enc_fdi.encoded == -1) { log_error("[cp] failed encoding CPM (%s)", retval_enc_fdi.failed_type->name); rv = 1; @@ -684,7 +684,7 @@ static int mk_cpm(uint8_t *bdr_oer, uint32_t *bdr_len, uint8_t *fdi_oer, uint32_ *fdi_len = ((retval_enc_fdi.encoded + 7) / 8); cleanup: - ASN_STRUCT_FREE(asn_DEF_CPM, cpm_tx); + ASN_STRUCT_FREE(asn_DEF_EI1_CPM, cpm_tx); return rv; } @@ -708,27 +708,27 @@ void *cp_service(){ tr_oer[0] = 4; //Facilities fi_oer[0] = 4; - NetworkingRequest_t* nr = calloc(1, sizeof(NetworkingRequest_t)); - nr->present = NetworkingRequest_PR_packet; - NetworkingPacketRequest_t* npr = &nr->choice.packet; + EIS_NetworkingRequest_t* nr = calloc(1, sizeof(EIS_NetworkingRequest_t)); + nr->present = EIS_NetworkingRequest_PR_packet; + EIS_NetworkingPacketRequest_t* npr = &nr->choice.packet; - npr->network.present = NetworkingPacketRequestNW_PR_gn; + npr->network.present = EIS_NetworkingPacketRequestNW_PR_gn; npr->network.choice.gn.trafficClass = 2; npr->network.choice.gn.destinationAddress.buf = malloc(6); for (int i = 0; i < 6; ++i) { npr->network.choice.gn.destinationAddress.buf[i] = 0xff; } npr->network.choice.gn.destinationAddress.size = 6; - npr->network.choice.gn.packetTransportType = PacketTransportType_shb; + npr->network.choice.gn.packetTransportType = EIS_PacketTransportType_shb; npr->network.choice.gn.securityProfile.sign = true; - npr->transport.present = NetworkingPacketRequestTP_PR_btp; - npr->transport.choice.btp.btpType = BTPType_btpB; - npr->transport.choice.btp.destinationPort = Port_cpm; + npr->transport.present = EIS_NetworkingPacketRequestTP_PR_btp; + npr->transport.choice.btp.btpType = EIS_BTPType_btpB; + npr->transport.choice.btp.destinationPort = EIS_Port_cpm; - FacilitiesIndication_t* fi = calloc(1, sizeof(FacilitiesIndication_t)); - fi->present = FacilitiesIndication_PR_message; - FacilitiesMessageIndication_t* fmi = &fi->choice.message; + EIS_FacilitiesIndication_t* fi = calloc(1, sizeof(EIS_FacilitiesIndication_t)); + fi->present = EIS_FacilitiesIndication_PR_message; + EIS_FacilitiesMessageIndication_t* fmi = &fi->choice.message; roadRotationSin = sin(((facilities.dissemination.radar_rotation + 90.0) * PI) / 180); roadRotationCos = cos(((facilities.dissemination.radar_rotation + 90.0) * PI) / 180); @@ -737,7 +737,7 @@ void *cp_service(){ npr->data.buf = malloc(1500); //CPM Data to be sent to the Networking layer /*--- Fill mandatory Facilities Message Indication parameters ---*/ - fmi->itsMessageType = ItsMessageType_cpm; + fmi->itsMessageType = EIS_ItsMessageType_cpm; fmi->data.buf = malloc(1500); /* Creating sockets and waiting for radar to connect*/ @@ -768,14 +768,14 @@ void *cp_service(){ fmi->id = id; /* Encode NetworkingRequest */ - asn_enc_rval_t enc_tdr = oer_encode_to_buffer(&asn_DEF_NetworkingRequest, NULL, nr, tr_oer+1, 2047); + asn_enc_rval_t enc_tdr = oer_encode_to_buffer(&asn_DEF_EIS_NetworkingRequest, NULL, nr, tr_oer+1, 2047); if(enc_tdr.encoded == -1){ log_error("encoding TR for cpm failed"); continue; } /* Encode FacilitiesIndication */ - asn_enc_rval_t enc_fdi = oer_encode_to_buffer(&asn_DEF_FacilitiesIndication, NULL, fi, fi_oer+1, 2047); + asn_enc_rval_t enc_fdi = oer_encode_to_buffer(&asn_DEF_EIS_FacilitiesIndication, NULL, fi, fi_oer+1, 2047); if(enc_fdi.encoded == -1){ log_error("encoding FI for cpm failed"); continue; @@ -820,8 +820,8 @@ void *cp_service(){ } } - ASN_STRUCT_FREE(asn_DEF_NetworkingRequest, nr); - ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi); + ASN_STRUCT_FREE(asn_DEF_EIS_NetworkingRequest, nr); + ASN_STRUCT_FREE(asn_DEF_EIS_FacilitiesIndication, fi); /* Close sockets */ if(facilities.dissemination.tmc_connect) diff --git a/src/cpm.h b/src/cpm.h index fcd78f9..e14e931 100644 --- a/src/cpm.h +++ b/src/cpm.h @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/denm.c b/src/denm.c index 4695f69..be33573 100644 --- a/src/denm.c +++ b/src/denm.c @@ -67,7 +67,7 @@ static int permissions_check(int cause_code, uint8_t* permissions, uint8_t permi } -static enum EVENT_CHECK_R event_check(DENM_t *denm, uint8_t* ssp, uint32_t ssp_len) { +static enum EVENT_CHECK_R event_check(EI1_DENM_t *denm, uint8_t* ssp, uint32_t ssp_len) { int rv = 0; den_t* den = &facilities.den; @@ -155,7 +155,7 @@ static enum EVENT_CHECK_R event_check(DENM_t *denm, uint8_t* ssp, uint32_t ssp_l return EVENT_NEW; } -static int event_add(DENM_t *denm, uint64_t* id) { +static int event_add(EI1_DENM_t *denm, uint64_t* id) { den_t* den = &facilities.den; uint64_t now = itss_time_get(); @@ -226,7 +226,7 @@ static int event_add(DENM_t *denm, uint64_t* id) { else return 0; // Event added to db } -static int event_update(DENM_t *denm, uint64_t* id) { +static int event_update(EI1_DENM_t *denm, uint64_t* id) { den_t* den = &facilities.den; uint64_t now = itss_time_get(); @@ -300,7 +300,7 @@ static int event_update(DENM_t *denm, uint64_t* id) { den->events[index]->latitude = denm->denm.management.eventPosition.latitude; den->events[index]->longitude = denm->denm.management.eventPosition.longitude; - ASN_STRUCT_FREE(asn_DEF_DENM, den->events[index]->denm); + ASN_STRUCT_FREE(asn_DEF_EI1_DENM, den->events[index]->denm); den->events[index]->denm = denm; } @@ -310,30 +310,30 @@ static int event_update(DENM_t *denm, uint64_t* id) { else return 0; // Event updated } -enum EVENT_CHECK_R event_manage(DENM_t *denm, uint64_t* id, uint8_t* ssp, uint32_t ssp_len) { +enum EVENT_CHECK_R event_manage(EI1_DENM_t *denm, uint64_t* id, uint8_t* ssp, uint32_t ssp_len) { int rv = 0; switch (rv = event_check(denm, ssp, ssp_len)) { case EVENT_NEW: log_debug("[den] new event received"); if (event_add(denm, id)) { log_debug("[den] failed adding event, max events reached"); - ASN_STRUCT_FREE(asn_DEF_DENM, denm); + ASN_STRUCT_FREE(asn_DEF_EI1_DENM, denm); rv = -1; } break; case EVENT_INVALID: log_debug("[den] invalid event received, ignoring"); - ASN_STRUCT_FREE(asn_DEF_DENM, denm); + ASN_STRUCT_FREE(asn_DEF_EI1_DENM, denm); break; case EVENT_PASSED: log_debug("[den] old event received, ignoring"); - ASN_STRUCT_FREE(asn_DEF_DENM, denm); + ASN_STRUCT_FREE(asn_DEF_EI1_DENM, denm); break; case EVENT_CANCELLATION: log_debug("[den] event cancellation received"); if (event_update(denm, id)) { log_debug("[den] failed cancelling event, event not found"); - ASN_STRUCT_FREE(asn_DEF_DENM, denm); + ASN_STRUCT_FREE(asn_DEF_EI1_DENM, denm); rv = EVENT_NUMBER_EXCEEDED; } break; @@ -341,7 +341,7 @@ enum EVENT_CHECK_R event_manage(DENM_t *denm, uint64_t* id, uint8_t* ssp, uint32 log_debug("[den] event negation received"); if (event_update(denm, id)) { log_debug("[den] failed negating event, event not found"); - ASN_STRUCT_FREE(asn_DEF_DENM, denm); + ASN_STRUCT_FREE(asn_DEF_EI1_DENM, denm); rv = EVENT_NUMBER_EXCEEDED; } break; @@ -349,21 +349,21 @@ enum EVENT_CHECK_R event_manage(DENM_t *denm, uint64_t* id, uint8_t* ssp, uint32 log_debug("[den] event update received"); if (event_update(denm, id)) { log_debug("[den] failed updating event, event not found"); - ASN_STRUCT_FREE(asn_DEF_DENM, denm); + ASN_STRUCT_FREE(asn_DEF_EI1_DENM, denm); rv = EVENT_NUMBER_EXCEEDED; } break; case EVENT_REPEATED: log_debug("[den] repeated event received or referenceTime doesn't allow an update, ignoring"); - ASN_STRUCT_FREE(asn_DEF_DENM, denm); + ASN_STRUCT_FREE(asn_DEF_EI1_DENM, denm); break; case EVENT_NUMBER_EXCEEDED: log_debug("[den] max events reached, ignoring"); - ASN_STRUCT_FREE(asn_DEF_DENM, denm); + ASN_STRUCT_FREE(asn_DEF_EI1_DENM, denm); break; case EVENT_BAD_PERMISSIONS: log_debug("[den] permisisons check failed for the received event, ignoring"); - ASN_STRUCT_FREE(asn_DEF_DENM, denm); + ASN_STRUCT_FREE(asn_DEF_EI1_DENM, denm); break; } return rv; @@ -398,7 +398,7 @@ void* den_service() { log_debug("[den] removed event %d (expiration)", i); den->events[i]->enabled = false; - ASN_STRUCT_FREE(asn_DEF_DENM, den->events[i]->denm); + ASN_STRUCT_FREE(asn_DEF_EI1_DENM, den->events[i]->denm); switch (den->events[i]->state) { case EVENT_ACTIVE: --den->n_active_events; diff --git a/src/denm.h b/src/denm.h index d817d53..b7de1fe 100644 --- a/src/denm.h +++ b/src/denm.h @@ -2,7 +2,7 @@ #define FACILITIES_DENM_H #include -#include +#include #include #include @@ -16,7 +16,7 @@ enum EVENT_STATE { typedef struct event { uint64_t id; - DENM_t *denm; + EI1_DENM_t *denm; uint32_t station_id; uint32_t sn; uint64_t detection_time; @@ -67,7 +67,7 @@ typedef struct cc_ssp_bm { * @param ssp permissions * @return 0 if event OK, 1 if event NOK */ -enum EVENT_CHECK_R event_manage(DENM_t* denm, uint64_t* id, uint8_t* ssp, uint32_t ssp_len); +enum EVENT_CHECK_R event_manage(EI1_DENM_t* denm, uint64_t* id, uint8_t* ssp, uint32_t ssp_len); int den_init(); void* den_service(); diff --git a/src/edm.c b/src/edm.c index 2cd0bed..40bd42a 100644 --- a/src/edm.c +++ b/src/edm.c @@ -1,28 +1,28 @@ #include "edm.h" #include "facilities.h" -#include -#include +#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; + EIS_FacilitiesIndication_t* fi = NULL; + EIS_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 = calloc(1, sizeof(EIS_FacilitiesIndication_t)); + fi->present = EIS_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); + asn_enc_rval_t enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_EIS_FacilitiesIndication, fi, b1+1, b_len-1); if (enc.encoded == -1) { return 1; } @@ -39,13 +39,13 @@ int edm_encap(uint8_t* msg, uint16_t* msg_len, uint16_t msg_buf_len, int its_msg } pthread_mutex_unlock(&edm->lock); - asn_dec_rval_t dec = asn_decode(NULL, ATS_CANONICAL_OER, &asn_DEF_FacilitiesResponse, (void**) &fr, b2, rl); + asn_dec_rval_t dec = asn_decode(NULL, ATS_CANONICAL_OER, &asn_DEF_EIS_FacilitiesResponse, (void**) &fr, b2, rl); if (dec.code != 0) { rv = 1; goto cleanup; } - if (fr->present != FacilitiesResponse_PR_extension || + if (fr->present != EIS_FacilitiesResponse_PR_extension || fr->choice.extension.returnCode != 0) { rv = 1; goto cleanup; @@ -62,8 +62,8 @@ int edm_encap(uint8_t* msg, uint16_t* msg_len, uint16_t msg_buf_len, int its_msg log_debug("[edm] request took %ld us", itss_ts_get(TIME_MICROSECONDS) - t_init); cleanup: - ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi); - ASN_STRUCT_FREE(asn_DEF_FacilitiesResponse, fr); + ASN_STRUCT_FREE(asn_DEF_EIS_FacilitiesIndication, fi); + ASN_STRUCT_FREE(asn_DEF_EIS_FacilitiesResponse, fr); return rv; } diff --git a/src/evm.c b/src/evm.c index df6ea25..b87fce2 100644 --- a/src/evm.c +++ b/src/evm.c @@ -2,10 +2,10 @@ #include "facilities.h" #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include @@ -38,7 +38,7 @@ static int mk_evcsnm(uint8_t *evcsnm_oer, uint32_t *evcsnm_len) { int rv = 0; int shm_fd, shm_valid = 0; - EvcsnPdu_t *evcsnm = calloc(1, sizeof(EvcsnPdu_t)); + EI1_EvcsnPdu_t *evcsnm = calloc(1, sizeof(EI1_EvcsnPdu_t)); evcsnm->header.protocolVersion = 2; evcsnm->header.messageID = 1; pthread_mutex_lock(&facilities.id.lock); @@ -54,8 +54,8 @@ static int mk_evcsnm(uint8_t *evcsnm_oer, uint32_t *evcsnm_len) { evcsnm->evcsn.evcsnData.chargingStationsData.list.array = calloc(1, sizeof(void *)); evcsnm->evcsn.evcsnData.chargingStationsData.list.count = 1; evcsnm->evcsn.evcsnData.chargingStationsData.list.size = sizeof(void *) * 1; - evcsnm->evcsn.evcsnData.chargingStationsData.list.array[0] = calloc(1, sizeof(struct ItsChargingStationData)); - struct ItsChargingStationData *cs0 = evcsnm->evcsn.evcsnData.chargingStationsData.list.array[0]; + evcsnm->evcsn.evcsnData.chargingStationsData.list.array[0] = calloc(1, sizeof(struct EI1_ItsChargingStationData)); + struct EI1_ItsChargingStationData *cs0 = evcsnm->evcsn.evcsnData.chargingStationsData.list.array[0]; cs0->chargingStationID = 0; itss_space_lock(); itss_space_get(); @@ -63,9 +63,9 @@ static int mk_evcsnm(uint8_t *evcsnm_oer, uint32_t *evcsnm_len) { cs0->chargingStationLocation.longitude = -86628610; cs0->chargingStationLocation.altitude.altitudeValue = epv.space.altitude; cs0->chargingStationLocation.altitude.altitudeConfidence = epv.space.altitude_conf; - cs0->chargingStationLocation.positionConfidenceEllipse.semiMajorConfidence = SemiAxisLength_unavailable; - cs0->chargingStationLocation.positionConfidenceEllipse.semiMinorConfidence = SemiAxisLength_unavailable; - cs0->chargingStationLocation.positionConfidenceEllipse.semiMajorOrientation = HeadingValue_unavailable; + cs0->chargingStationLocation.positionConfidenceEllipse.semiMajorConfidence = EI1_SemiAxisLength_unavailable; + cs0->chargingStationLocation.positionConfidenceEllipse.semiMinorConfidence = EI1_SemiAxisLength_unavailable; + cs0->chargingStationLocation.positionConfidenceEllipse.semiMajorOrientation = EI1_HeadingValue_unavailable; cs0->accessibility = *create_utf8_from_string("Free Access", strlen("Free Access")); cs0->pricing = *create_utf8_from_string(".15 €/kWh", strlen(".15 €/kWh")); cs0->openingDaysHours = *create_utf8_from_string("Always", strlen("Always")); @@ -74,8 +74,8 @@ static int mk_evcsnm(uint8_t *evcsnm_oer, uint32_t *evcsnm_len) { cs0->chargingSpotsAvailable.list.array = calloc(1, sizeof(void *)); cs0->chargingSpotsAvailable.list.count = 1; cs0->chargingSpotsAvailable.list.size = sizeof(void *) * 1; - cs0->chargingSpotsAvailable.list.array[0] = calloc(1, sizeof(struct ItsChargingSpotDataElements)); - struct ItsChargingSpotDataElements *cs_elem0 = cs0->chargingSpotsAvailable.list.array[0]; + cs0->chargingSpotsAvailable.list.array[0] = calloc(1, sizeof(struct EI1_ItsChargingSpotDataElements)); + struct EI1_ItsChargingSpotDataElements *cs_elem0 = cs0->chargingSpotsAvailable.list.array[0]; cs_elem0->energyAvailability = *create_utf8_from_string("Max: 30kW", strlen("Max: 30kW")); cs_elem0->type.buf = calloc(1, sizeof(uint8_t)); cs_elem0->type.size = 1; @@ -85,14 +85,14 @@ static int mk_evcsnm(uint8_t *evcsnm_oer, uint32_t *evcsnm_len) { cs_elem0->typeOfReceptacle.size = 1; cs_elem0->typeOfReceptacle.bits_unused = 0; cs_elem0->typeOfReceptacle.buf[0] = 0x0D; - cs_elem0->parkingPlacesData = calloc(1, sizeof(struct ParkingPlacesData)); + cs_elem0->parkingPlacesData = calloc(1, sizeof(struct EI1_ParkingPlacesData)); cs_elem0->parkingPlacesData->list.array = calloc(2, sizeof(void *)); cs_elem0->parkingPlacesData->list.count = 2; cs_elem0->parkingPlacesData->list.size = sizeof(void *) * 2; // As requested onnly 2 parking places are available for (int parckingPlaceIndex = 0; parckingPlaceIndex < 2; parckingPlaceIndex++) { - cs_elem0->parkingPlacesData->list.array[parckingPlaceIndex] = calloc(1, sizeof(struct SpotAvailability)); - struct SpotAvailability *spot = cs_elem0->parkingPlacesData->list.array[parckingPlaceIndex]; + cs_elem0->parkingPlacesData->list.array[parckingPlaceIndex] = calloc(1, sizeof(struct EI1_SpotAvailability)); + struct EI1_SpotAvailability *spot = cs_elem0->parkingPlacesData->list.array[parckingPlaceIndex]; spot->maxWaitingTimeMinutes = 0; spot->blocking = 1; } @@ -101,7 +101,7 @@ static int mk_evcsnm(uint8_t *evcsnm_oer, uint32_t *evcsnm_len) { //{ // } - asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_EvcsnPdu, NULL, evcsnm, evcsnm_oer, 512); + asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_EI1_EvcsnPdu, NULL, evcsnm, evcsnm_oer, 512); if (enc.encoded == -1) { log_error("[ev] failed encoding evcsnm (%s)", enc.failed_type->name); rv = 1; @@ -110,64 +110,64 @@ static int mk_evcsnm(uint8_t *evcsnm_oer, uint32_t *evcsnm_len) { *evcsnm_len = (enc.encoded + 7) / 8; cleanup: - ASN_STRUCT_FREE(asn_DEF_EvcsnPdu, evcsnm); + ASN_STRUCT_FREE(asn_DEF_EI1_EvcsnPdu, evcsnm); return rv; } static uint64_t pre_reservation_id = 1; static uint64_t reservation_id = 1; -int evrsrm_recv(EV_RSR_t *evrsr_request) { +int evrsrm_recv(EI1_EV_RSR_t *evrsr_request) { int rv = 0; - NetworkingRequest_t* nr = calloc(1, sizeof(NetworkingRequest_t)); - nr->present = NetworkingRequest_PR_packet; - NetworkingPacketRequest_t* npr = &nr->choice.packet; + EIS_NetworkingRequest_t* nr = calloc(1, sizeof(EIS_NetworkingRequest_t)); + nr->present = EIS_NetworkingRequest_PR_packet; + EIS_NetworkingPacketRequest_t* npr = &nr->choice.packet; - npr->network.present = NetworkingPacketRequestNW_PR_gn; + npr->network.present = EIS_NetworkingPacketRequestNW_PR_gn; npr->network.choice.gn.trafficClass = 2; npr->network.choice.gn.destinationAddress.buf = malloc(6); for (int i = 0; i < 6; ++i) { npr->network.choice.gn.destinationAddress.buf[i] = 0xff; } npr->network.choice.gn.destinationAddress.size = 6; - npr->network.choice.gn.packetTransportType = PacketTransportType_shb; + npr->network.choice.gn.packetTransportType = EIS_PacketTransportType_shb; npr->network.choice.gn.securityProfile.sign = true; - npr->transport.present = NetworkingPacketRequestTP_PR_btp; - npr->transport.choice.btp.btpType = BTPType_btpB; - npr->transport.choice.btp.destinationPort = Port_evrsr; + npr->transport.present = EIS_NetworkingPacketRequestTP_PR_btp; + npr->transport.choice.btp.btpType = EIS_BTPType_btpB; + npr->transport.choice.btp.destinationPort = EIS_Port_evrsr; npr->data.buf = malloc(512); // Fill header for FacilitiesIndication and FacilitiesMessageIndication structs - FacilitiesIndication_t *fi = calloc(1, sizeof(FacilitiesIndication_t)); - fi->present = FacilitiesIndication_PR_message; - FacilitiesMessageIndication_t *fmi = &fi->choice.message; - fmi->itsMessageType = ItsMessageType_evrsr; + EIS_FacilitiesIndication_t *fi = calloc(1, sizeof(EIS_FacilitiesIndication_t)); + fi->present = EIS_FacilitiesIndication_PR_message; + EIS_FacilitiesMessageIndication_t *fmi = &fi->choice.message; + fmi->itsMessageType = EIS_ItsMessageType_evrsr; fmi->data.buf = malloc(512); uint8_t tr_oer[1024]; uint8_t fi_oer[1024]; tr_oer[0] = 4; // Facilities fi_oer[0] = 4; - if (!(evrsr_request->messageBody.present == EV_RSR_MessageBody_PR_preReservationRequestMessage || - evrsr_request->messageBody.present == EV_RSR_MessageBody_PR_reservationRequestMessage || - evrsr_request->messageBody.present == EV_RSR_MessageBody_PR_cancellationRequestMessage || - evrsr_request->messageBody.present == EV_RSR_MessageBody_PR_updateRequestMessage)) { + if (!(evrsr_request->messageBody.present == EI1_EV_RSR_MessageBody_PR_preReservationRequestMessage || + evrsr_request->messageBody.present == EI1_EV_RSR_MessageBody_PR_reservationRequestMessage || + evrsr_request->messageBody.present == EI1_EV_RSR_MessageBody_PR_cancellationRequestMessage || + evrsr_request->messageBody.present == EI1_EV_RSR_MessageBody_PR_updateRequestMessage)) { rv = 1; goto cleanup; } int evrsr_response; - if (evrsr_request->messageBody.present == EV_RSR_MessageBody_PR_preReservationRequestMessage) + if (evrsr_request->messageBody.present == EI1_EV_RSR_MessageBody_PR_preReservationRequestMessage) evrsr_response = evrsrm_pre_reservation_response(npr->data.buf, (uint32_t *)&npr->data.size); - else if (evrsr_request->messageBody.present == EV_RSR_MessageBody_PR_reservationRequestMessage) + else if (evrsr_request->messageBody.present == EI1_EV_RSR_MessageBody_PR_reservationRequestMessage) evrsr_response = evrsrm_reservation_response(evrsr_request, npr->data.buf, (uint32_t *)&npr->data.size); - else if (evrsr_request->messageBody.present == EV_RSR_MessageBody_PR_cancellationRequestMessage) + else if (evrsr_request->messageBody.present == EI1_EV_RSR_MessageBody_PR_cancellationRequestMessage) evrsr_response = evrsrm_cancellation_response(evrsr_request, npr->data.buf, (uint32_t *)&npr->data.size); - else if (evrsr_request->messageBody.present == EV_RSR_MessageBody_PR_updateRequestMessage) + else if (evrsr_request->messageBody.present == EI1_EV_RSR_MessageBody_PR_updateRequestMessage) evrsr_response = evrsrm_update_response(evrsr_request, npr->data.buf, (uint32_t *)&npr->data.size); if (evrsr_response != 0) { rv = 1; @@ -180,14 +180,14 @@ int evrsrm_recv(EV_RSR_t *evrsr_request) { npr->id = id; fmi->id = id; - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_NetworkingRequest, NULL, nr, tr_oer + 1, 1023); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_NetworkingRequest, NULL, nr, tr_oer + 1, 1023); if (enc.encoded == -1) { log_error("[ev] failed encoding transport request (%s)", enc.failed_type->name); rv = 1; goto cleanup; } - asn_enc_rval_t enc_fdi = oer_encode_to_buffer(&asn_DEF_FacilitiesIndication, NULL, fi, fi_oer + 1, 1023); + asn_enc_rval_t enc_fdi = oer_encode_to_buffer(&asn_DEF_EIS_FacilitiesIndication, NULL, fi, fi_oer + 1, 1023); if (enc_fdi.encoded == -1) { log_error("[ev] encoding FI for evrsrm failed"); rv = 1; @@ -202,23 +202,23 @@ cleanup: return rv; } -static int evrsrm_cancellation_response(EV_RSR_t *evrsrm_request, uint8_t *evrsrm_oer, uint32_t *evrsrm_len){ +static int evrsrm_cancellation_response(EI1_EV_RSR_t *evrsrm_request, uint8_t *evrsrm_oer, uint32_t *evrsrm_len){ int rv = 0; - EV_RSR_t *evrsr_response = calloc(1, sizeof(EV_RSR_t)); + EI1_EV_RSR_t *evrsr_response = calloc(1, sizeof(EI1_EV_RSR_t)); evrsr_response->header.protocolVersion = 1; evrsr_response->header.messageID = 7; pthread_mutex_lock(&facilities.id.lock); evrsr_response->header.stationID = facilities.id.station_id; pthread_mutex_unlock(&facilities.id.lock); - evrsr_response->messageBody.present = EV_RSR_MessageBody_PR_cancellationResponseMessage; - CancellationResponseMessage_t *evrsr_cancellation_response = &evrsr_response->messageBody.choice.cancellationResponseMessage; + evrsr_response->messageBody.present = EI1_EV_RSR_MessageBody_PR_cancellationResponseMessage; + EI1_CancellationResponseMessage_t *evrsr_cancellation_response = &evrsr_response->messageBody.choice.cancellationResponseMessage; evrsr_cancellation_response->reservation_ID.buf = calloc(8, sizeof(uint8_t)); evrsr_cancellation_response->reservation_ID.size = 8; memccpy(evrsr_cancellation_response->reservation_ID.buf, evrsrm_request->messageBody.choice.cancellationRequestMessage.reservation_ID.buf, 0, 8); - evrsr_cancellation_response->cancellationResponseCode = CancellationResponseCode_ok; + evrsr_cancellation_response->cancellationResponseCode = EI1_CancellationResponseCode_ok; - asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_EV_RSR, NULL, evrsr_response, evrsrm_oer, 512); + asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_EI1_EV_RSR, NULL, evrsr_response, evrsrm_oer, 512); if (enc.encoded == -1) { log_error("[ev] failed encoding evrsrm cancellation response (%s)", enc.failed_type->name); rv = 1; @@ -226,27 +226,27 @@ static int evrsrm_cancellation_response(EV_RSR_t *evrsrm_request, uint8_t *evrsr } *evrsrm_len = (enc.encoded + 7) / 8; cleanup: - ASN_STRUCT_FREE(asn_DEF_EV_RSR, evrsr_response); + ASN_STRUCT_FREE(asn_DEF_EI1_EV_RSR, evrsr_response); return rv; } -static int evrsrm_update_response(EV_RSR_t *evrsrm_request, uint8_t *evrsrm_oer, uint32_t *evrsrm_len){ +static int evrsrm_update_response(EI1_EV_RSR_t *evrsrm_request, uint8_t *evrsrm_oer, uint32_t *evrsrm_len){ int rv = 0; - EV_RSR_t *evrsr_response = calloc(1, sizeof(EV_RSR_t)); + EI1_EV_RSR_t *evrsr_response = calloc(1, sizeof(EI1_EV_RSR_t)); evrsr_response->header.protocolVersion = 1; evrsr_response->header.messageID = 7; pthread_mutex_lock(&facilities.id.lock); evrsr_response->header.stationID = facilities.id.station_id; pthread_mutex_unlock(&facilities.id.lock); - evrsr_response->messageBody.present = EV_RSR_MessageBody_PR_updateResponseMessage; - UpdateResponseMessage_t *evrsr_update_response = &evrsr_response->messageBody.choice.updateResponseMessage; + evrsr_response->messageBody.present = EI1_EV_RSR_MessageBody_PR_updateResponseMessage; + EI1_UpdateResponseMessage_t *evrsr_update_response = &evrsr_response->messageBody.choice.updateResponseMessage; evrsr_update_response->reservation_ID.buf = calloc(8, sizeof(uint8_t)); evrsr_update_response->reservation_ID.size = 8; memccpy(evrsr_update_response->reservation_ID.buf, evrsrm_request->messageBody.choice.updateRequestMessage.reservation_ID.buf, 0, 8); - evrsr_update_response->updateResponseCode = UpdateResponseCode_ok; + evrsr_update_response->updateResponseCode = EI1_UpdateResponseCode_ok; - asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_EV_RSR, NULL, evrsr_response, evrsrm_oer, 512); + asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_EI1_EV_RSR, NULL, evrsr_response, evrsrm_oer, 512); if (enc.encoded == -1) { log_error("[ev] failed encoding evrsrm update response (%s)", enc.failed_type->name); rv = 1; @@ -254,26 +254,26 @@ static int evrsrm_update_response(EV_RSR_t *evrsrm_request, uint8_t *evrsrm_oer, } *evrsrm_len = (enc.encoded + 7) / 8; cleanup: - ASN_STRUCT_FREE(asn_DEF_EV_RSR, evrsr_response); + ASN_STRUCT_FREE(asn_DEF_EI1_EV_RSR, evrsr_response); return rv; } -static int evrsrm_reservation_response(EV_RSR_t *evrsrm_request, uint8_t *evrsrm_oer, uint32_t *evrsrm_len) { +static int evrsrm_reservation_response(EI1_EV_RSR_t *evrsrm_request, uint8_t *evrsrm_oer, uint32_t *evrsrm_len) { int rv = 0; - EV_RSR_t *evrsr_response = calloc(1, sizeof(EV_RSR_t)); + EI1_EV_RSR_t *evrsr_response = calloc(1, sizeof(EI1_EV_RSR_t)); evrsr_response->header.protocolVersion = 1; evrsr_response->header.messageID = 7; pthread_mutex_lock(&facilities.id.lock); evrsr_response->header.stationID = facilities.id.station_id; pthread_mutex_unlock(&facilities.id.lock); - evrsr_response->messageBody.present = EV_RSR_MessageBody_PR_reservationResponseMessage; + evrsr_response->messageBody.present = EI1_EV_RSR_MessageBody_PR_reservationResponseMessage; - ReservationResponseMessage_t *response = &evrsr_response->messageBody.choice.reservationResponseMessage; + EI1_ReservationResponseMessage_t *response = &evrsr_response->messageBody.choice.reservationResponseMessage; // Assumes the pre reservation was successful - response->reservationResponseCode = ReservationResponseCode_ok; + response->reservationResponseCode = EI1_ReservationResponseCode_ok; - response->reservation_ID = calloc(1, sizeof(Reservation_ID_t)); + response->reservation_ID = calloc(1, sizeof(EI1_Reservation_ID_t)); response->reservation_ID->buf = calloc(8, sizeof(uint8_t)); response->reservation_ID->size = 8; response->reservation_ID->buf[0] = '0' + reservation_id / 10000000; @@ -285,7 +285,7 @@ static int evrsrm_reservation_response(EV_RSR_t *evrsrm_request, uint8_t *evrsrm response->reservation_ID->buf[6] = '0' + (reservation_id / 10) % 10; response->reservation_ID->buf[7] = '0' + reservation_id % 10; - response->reservation_Password = calloc(1, sizeof(Reservation_Password_t)); + response->reservation_Password = calloc(1, sizeof(EI1_Reservation_Password_t)); response->reservation_Password->buf = calloc(8, sizeof(uint8_t)); response->reservation_Password->size = 8; response->reservation_Password->buf[0] = 'i'; @@ -300,7 +300,7 @@ static int evrsrm_reservation_response(EV_RSR_t *evrsrm_request, uint8_t *evrsrm response->expirationTime = evrsrm_request->messageBody.choice.reservationRequestMessage.arrivalTime; response->expirationTime += 15 * 60 * 1000; // 15 minutes - asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_EV_RSR, NULL, evrsr_response, evrsrm_oer, 512); + asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_EI1_EV_RSR, NULL, evrsr_response, evrsrm_oer, 512); if (enc.encoded == -1) { log_error("[ev] failed encoding evrsrm reservation response (%s)", enc.failed_type->name); rv = 1; @@ -310,20 +310,20 @@ static int evrsrm_reservation_response(EV_RSR_t *evrsrm_request, uint8_t *evrsrm reservation_id++; cleanup: - ASN_STRUCT_FREE(asn_DEF_EV_RSR, evrsr_response); + ASN_STRUCT_FREE(asn_DEF_EI1_EV_RSR, evrsr_response); return rv; } static int evrsrm_pre_reservation_response(uint8_t *evrsrm_oer, uint32_t *evrsrm_len) { int rv = 0; - EV_RSR_t *evrsr_response = calloc(1, sizeof(EV_RSR_t)); + EI1_EV_RSR_t *evrsr_response = calloc(1, sizeof(EI1_EV_RSR_t)); evrsr_response->header.protocolVersion = 1; evrsr_response->header.messageID = 7; pthread_mutex_lock(&facilities.id.lock); evrsr_response->header.stationID = facilities.id.station_id; pthread_mutex_unlock(&facilities.id.lock); - evrsr_response->messageBody.present = EV_RSR_MessageBody_PR_preReservationResponseMessage; + evrsr_response->messageBody.present = EI1_EV_RSR_MessageBody_PR_preReservationResponseMessage; - PreReservationResponseMessage_t *response = &evrsr_response->messageBody.choice.preReservationResponseMessage; + EI1_PreReservationResponseMessage_t *response = &evrsr_response->messageBody.choice.preReservationResponseMessage; response->preReservation_ID.buf = calloc(8, sizeof(uint8_t)); response->preReservation_ID.size = 8; response->preReservation_ID.buf[0] = '0' + (pre_reservation_id / 10000000); @@ -343,7 +343,7 @@ static int evrsrm_pre_reservation_response(uint8_t *evrsrm_oer, uint32_t *evrsrm response->supportedPaymentTypes.buf[0] = 0x00; response->preReservationExpirationTime = 0; - asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_EV_RSR, NULL, evrsr_response, evrsrm_oer, 512); + asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_EI1_EV_RSR, NULL, evrsr_response, evrsrm_oer, 512); if (enc.encoded == -1) { log_error("[ev] failed encoding evrsrm pre reservation response (%s)", enc.failed_type->name); rv = 1; @@ -353,56 +353,56 @@ static int evrsrm_pre_reservation_response(uint8_t *evrsrm_oer, uint32_t *evrsrm pre_reservation_id++; cleanup: - ASN_STRUCT_FREE(asn_DEF_EV_RSR, evrsr_response); + ASN_STRUCT_FREE(asn_DEF_EI1_EV_RSR, evrsr_response); return rv; } -int evcsnm_check(EvcsnPdu_t *evcsnm) { +int evcsnm_check(EI1_EvcsnPdu_t *evcsnm) { return 0; } -int evrsrm_check(EV_RSR_t *evrsrm) { +int evrsrm_check(EI1_EV_RSR_t *evrsrm) { return 0; } -enum EVM_CHECK_R check_evcsnm(BTPPacketIndication_t *bpi, EvcsnPdu_t *evcsnm, uint8_t *ssp, uint32_t ssp_len) { +enum EVM_CHECK_R check_evcsnm(EIS_BTPPacketIndication_t *bpi, EI1_EvcsnPdu_t *evcsnm, uint8_t *ssp, uint32_t ssp_len) { return 0; } -enum EVM_CHECK_R check_evrsrm(BTPPacketIndication_t *bpi, EV_RSR_t *evrsrm, uint8_t *ssp, uint32_t ssp_len) { +enum EVM_CHECK_R check_evrsrm(EIS_BTPPacketIndication_t *bpi, EI1_EV_RSR_t *evrsrm, uint8_t *ssp, uint32_t ssp_len) { return 0; } void *evcsn_service() { int rv = 0; - NetworkingRequest_t* nr = calloc(1, sizeof(NetworkingRequest_t)); - nr->present = NetworkingRequest_PR_packet; - NetworkingPacketRequest_t* npr = &nr->choice.packet; + EIS_NetworkingRequest_t* nr = calloc(1, sizeof(EIS_NetworkingRequest_t)); + nr->present = EIS_NetworkingRequest_PR_packet; + EIS_NetworkingPacketRequest_t* npr = &nr->choice.packet; - npr->network.present = NetworkingPacketRequestNW_PR_gn; + npr->network.present = EIS_NetworkingPacketRequestNW_PR_gn; npr->network.choice.gn.trafficClass = 2; npr->network.choice.gn.destinationAddress.buf = malloc(6); for (int i = 0; i < 6; ++i) { npr->network.choice.gn.destinationAddress.buf[i] = 0xff; } npr->network.choice.gn.destinationAddress.size = 6; - npr->network.choice.gn.packetTransportType = PacketTransportType_shb; + npr->network.choice.gn.packetTransportType = EIS_PacketTransportType_shb; npr->network.choice.gn.securityProfile.sign = true; - npr->transport.present = NetworkingPacketRequestTP_PR_btp; - npr->transport.choice.btp.btpType = BTPType_btpB; - npr->transport.choice.btp.destinationPort = Port_poi; + npr->transport.present = EIS_NetworkingPacketRequestTP_PR_btp; + npr->transport.choice.btp.btpType = EIS_BTPType_btpB; + npr->transport.choice.btp.destinationPort = EIS_Port_poi; npr->data.buf = malloc(512); // Fill header for FacilitiesIndication and FacilitiesMessageIndication structs - FacilitiesIndication_t *fi = calloc(1, sizeof(FacilitiesIndication_t)); - fi->present = FacilitiesIndication_PR_message; - FacilitiesMessageIndication_t *fmi = &fi->choice.message; - fmi->itsMessageType = ItsMessageType_poi; + EIS_FacilitiesIndication_t *fi = calloc(1, sizeof(EIS_FacilitiesIndication_t)); + fi->present = EIS_FacilitiesIndication_PR_message; + EIS_FacilitiesMessageIndication_t *fmi = &fi->choice.message; + fmi->itsMessageType = EIS_ItsMessageType_poi; fmi->data.buf = malloc(512); uint8_t tr_oer[1024]; @@ -423,13 +423,13 @@ void *evcsn_service() { npr->id = id; fmi->id = id; - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_NetworkingRequest, NULL, nr, tr_oer + 1, 1023); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_NetworkingRequest, NULL, nr, tr_oer + 1, 1023); if (enc.encoded == -1) { log_error("encoding TR for evcsnm failed"); continue; } - asn_enc_rval_t enc_fdi = oer_encode_to_buffer(&asn_DEF_FacilitiesIndication, NULL, fi, fi_oer + 1, 1023); + asn_enc_rval_t enc_fdi = oer_encode_to_buffer(&asn_DEF_EIS_FacilitiesIndication, NULL, fi, fi_oer + 1, 1023); if (enc_fdi.encoded == -1) { log_error("encoding FI for evcsnm failed"); continue; @@ -444,7 +444,7 @@ void *evcsn_service() { pthread_mutex_lock(&facilities.id.lock); uint32_t station_id = facilities.id.station_id; pthread_mutex_unlock(&facilities.id.lock); - itss_db_add(facilities.logging.dbms, station_id, npr->id, true, messageID_evcsn, NULL, npr->data.buf, npr->data.size); + itss_db_add(facilities.logging.dbms, station_id, npr->id, true, EI1_messageID_evcsn, NULL, npr->data.buf, npr->data.size); } if (facilities.logging.recorder) { @@ -466,7 +466,7 @@ void *evcsn_service() { } } - ASN_STRUCT_FREE(asn_DEF_NetworkingRequest, nr); + ASN_STRUCT_FREE(asn_DEF_EIS_NetworkingRequest, nr); return NULL; } diff --git a/src/evm.h b/src/evm.h index eee40dc..b818b68 100644 --- a/src/evm.h +++ b/src/evm.h @@ -1,15 +1,15 @@ #ifndef FACILITIES_EVM_H #define FACILITIES_EVM_H -#include -#include +#include +#include #include #include #include #include #include -#include +#include enum EVM_CHECK_R { EVM_OK, @@ -22,14 +22,14 @@ enum EVM_CHECK_R { * * @return A EVM check code */ -enum EVM_CHECK_R check_evcsnm(BTPPacketIndication_t *bpi, EvcsnPdu_t *evcsnm, uint8_t *ssp, uint32_t ssp_len); +enum EVM_CHECK_R check_evcsnm(EIS_BTPPacketIndication_t *bpi, EI1_EvcsnPdu_t *evcsnm, uint8_t *ssp, uint32_t ssp_len); /* * @brief Analyzes a received EVRSRM * * @return A EVM check code */ -enum EVM_CHECK_R check_evrsrm(BTPPacketIndication_t *bpi, EV_RSR_t *evrsrm, uint8_t *ssp, uint32_t ssp_len); +enum EVM_CHECK_R check_evrsrm(EIS_BTPPacketIndication_t *bpi, EI1_EV_RSR_t *evrsrm, uint8_t *ssp, uint32_t ssp_len); /* * @brief Main CA service @@ -44,7 +44,7 @@ void *evcsn_service(); * * @return 0 on success, 1 otherwise */ -int evrsrm_recv(EV_RSR_t *evrsr_request); +int evrsrm_recv(EI1_EV_RSR_t *evrsr_request); /** * @brief Creates a pre reservation response. @@ -64,7 +64,7 @@ static int evrsrm_pre_reservation_response(uint8_t *evrsrm_oer, uint32_t *evrsrm * @return The reservation response */ -static int evrsrm_reservation_response(EV_RSR_t *evrsrm_request, uint8_t *evrsrm_oer, uint32_t *evrsrm_len); +static int evrsrm_reservation_response(EI1_EV_RSR_t *evrsrm_request, uint8_t *evrsrm_oer, uint32_t *evrsrm_len); /** * @brief Creates a reservation cancellation response. @@ -74,7 +74,7 @@ static int evrsrm_reservation_response(EV_RSR_t *evrsrm_request, uint8_t *evrsrm * @return The reservation response */ -static int evrsrm_cancellation_response(EV_RSR_t *evrsrm_request, uint8_t *evrsrm_oer, uint32_t *evrsrm_len); +static int evrsrm_cancellation_response(EI1_EV_RSR_t *evrsrm_request, uint8_t *evrsrm_oer, uint32_t *evrsrm_len); /** * @brief Creates a reservation update response. @@ -84,7 +84,7 @@ static int evrsrm_cancellation_response(EV_RSR_t *evrsrm_request, uint8_t *evrsr * @return The reservation response */ -static int evrsrm_update_response(EV_RSR_t *evrsrm_request, uint8_t *evrsrm_oer, uint32_t *evrsrm_len); +static int evrsrm_update_response(EI1_EV_RSR_t *evrsrm_request, uint8_t *evrsrm_oer, uint32_t *evrsrm_len); /** @@ -93,14 +93,14 @@ static int evrsrm_update_response(EV_RSR_t *evrsrm_request, uint8_t *evrsrm_oer, * @return 0 on success, other value otherwise */ -int evcsnm_check(EvcsnPdu_t *evcsnm); +int evcsnm_check(EI1_EvcsnPdu_t *evcsnm); /** * Analyses a evrsrm * @param evrsrm The evrsrm to be analyzed * @return 0 on success, other value otherwise */ -int evrsrm_check(EV_RSR_t *evrsrm); +int evrsrm_check(EI1_EV_RSR_t *evrsrm); typedef struct evm_args { bool activate; diff --git a/src/facilities.c b/src/facilities.c index b8b1028..7f7a436 100644 --- a/src/facilities.c +++ b/src/facilities.c @@ -1,22 +1,22 @@ #include "facilities.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -48,9 +48,9 @@ static int networking_indication(void *responder, void **security_socket, uint8_ uint8_t code = 0; bool stored = false; - NetworkingIndication_t *ni = calloc(1, sizeof(NetworkingIndication_t)); + EIS_NetworkingIndication_t *ni = calloc(1, sizeof(EIS_NetworkingIndication_t)); - asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_NetworkingIndication, (void **)&ni, msg, msg_len); + asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_EIS_NetworkingIndication, (void **)&ni, msg, msg_len); if (dec.code) { log_error("<- invalid TI received"); rv = 1; @@ -62,10 +62,10 @@ static int networking_indication(void *responder, void **security_socket, uint8_ itss_0send(responder, &code, 1); switch (ni->present) { - case NetworkingIndication_PR_packet: + case EIS_NetworkingIndication_PR_packet: networking_packet_indication(&ni->choice.packet, security_socket); break; - case NetworkingIndication_PR_data: + case EIS_NetworkingIndication_PR_data: networking_data_indication(&ni->choice.data, security_socket); goto cleanup; default: @@ -75,7 +75,7 @@ static int networking_indication(void *responder, void **security_socket, uint8_ } cleanup: - ASN_STRUCT_FREE(asn_DEF_NetworkingIndication, ni); + ASN_STRUCT_FREE(asn_DEF_EIS_NetworkingIndication, ni); return rv; } @@ -83,9 +83,9 @@ cleanup: static int facilities_request(void *responder, uint8_t *msg, uint32_t msg_len) { int rv = 0; - FacilitiesRequest_t *fr = calloc(1, sizeof(FacilitiesRequest_t)); + EIS_FacilitiesRequest_t *fr = calloc(1, sizeof(EIS_FacilitiesRequest_t)); - asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_FacilitiesRequest, (void **)&fr, msg, msg_len); + asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_EIS_FacilitiesRequest, (void **)&fr, msg, msg_len); if (dec.code) { log_error("<- invalid FR received"); facilities_request_result_rejected(responder); @@ -94,25 +94,25 @@ static int facilities_request(void *responder, uint8_t *msg, uint32_t msg_len) { } switch (fr->present) { - case FacilitiesRequest_PR_message: + case EIS_FacilitiesRequest_PR_message: rv = facilities_request_single_message(responder, &fr->choice.message); break; - case FacilitiesRequest_PR_data: + case EIS_FacilitiesRequest_PR_data: switch (fr->choice.data.present) { - case FacilitiesDataRequest_PR_activeEpisodes: + case EIS_FacilitiesDataRequest_PR_activeEpisodes: rv = facilities_request_active_episodes(responder, fr); break; - case FacilitiesDataRequest_PR_attributeTypes: + case EIS_FacilitiesDataRequest_PR_attributeTypes: rv = facilities_request_attribute_types(responder, fr); break; - case FacilitiesDataRequest_PR_loadedProtectionZones: + case EIS_FacilitiesDataRequest_PR_loadedProtectionZones: rv = facilities_request_loaded_protected_zones(responder, fr); break; - case FacilitiesDataRequest_PR_chainInfoSet: + case EIS_FacilitiesDataRequest_PR_chainInfoSet: rv = facilities_request_chaininfo_set(responder, &fr->choice.data.choice.chainInfoSet); break; @@ -132,7 +132,7 @@ static int facilities_request(void *responder, uint8_t *msg, uint32_t msg_len) { } cleanup: - ASN_STRUCT_FREE(asn_DEF_FacilitiesRequest, fr); + ASN_STRUCT_FREE(asn_DEF_EIS_FacilitiesRequest, fr); return rv; } @@ -140,14 +140,14 @@ cleanup: static int security_indication(void *responder_secured, uint8_t *msg, uint32_t msg_len) { int rv = 0; - SecurityIndication_t *si = calloc(1, sizeof(SecurityIndication_t)); - SecurityResponse_t *sr = calloc(1, sizeof(SecurityResponse_t)); + EIS_SecurityIndication_t *si = calloc(1, sizeof(EIS_SecurityIndication_t)); + EIS_SecurityResponse_t *sr = calloc(1, sizeof(EIS_SecurityResponse_t)); uint8_t buffer[64]; asn_enc_rval_t enc; - asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_SecurityIndication, (void **)&si, msg, msg_len); + asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_EIS_SecurityIndication, (void **)&si, msg, msg_len); if (dec.code) { log_error("<- invalid SIndication received"); rv = 1; @@ -163,8 +163,8 @@ static int security_indication(void *responder_secured, uint8_t *msg, uint32_t m } if (facilities.id.change.stage == ID_CHANGE_PREPARE && - si->choice.idChangeEvent.command != SecurityIdChangeEventType_commit && - si->choice.idChangeEvent.command != SecurityIdChangeEventType_abort) { + si->choice.idChangeEvent.command != EIS_SecurityIdChangeEventType_commit && + si->choice.idChangeEvent.command != EIS_SecurityIdChangeEventType_abort) { pthread_mutex_unlock(&facilities.id.change.lock); log_debug("current identity change state is prepare, but received identity change command is not commit nor abort"); rv = 1; @@ -174,7 +174,7 @@ static int security_indication(void *responder_secured, uint8_t *msg, uint32_t m bool id_changed = false; switch (si->choice.idChangeEvent.command) { - case SecurityIdChangeEventType_prepare: + case EIS_SecurityIdChangeEventType_prepare: facilities.id.change.stage = ID_CHANGE_PREPARE; @@ -182,7 +182,7 @@ static int security_indication(void *responder_secured, uint8_t *msg, uint32_t m pthread_mutex_lock(&facilities.lightship.lock); break; - case SecurityIdChangeEventType_commit:; + case EIS_SecurityIdChangeEventType_commit:; facilities.id.change.stage = ID_CHANGE_COMMIT; // Reset lightship @@ -201,10 +201,10 @@ static int security_indication(void *responder_secured, uint8_t *msg, uint32_t m // Change Station ID for (int i = 0; i < si->choice.idChangeEvent.ids.list.count; ++i) { switch (si->choice.idChangeEvent.ids.list.array[i]->present) { - case SecurityId_PR_stationId: + case EIS_SecurityId_PR_stationId: facilities.id.station_id = si->choice.idChangeEvent.ids.list.array[i]->choice.stationId; break; - case SecurityId_PR_ipv6Address: + case EIS_SecurityId_PR_ipv6Address: memcpy(facilities.id.ipv6_addr, si->choice.idChangeEvent.ids.list.array[i]->choice.ipv6Address.buf, 16); break; default: @@ -220,7 +220,7 @@ static int security_indication(void *responder_secured, uint8_t *msg, uint32_t m break; - case SecurityIdChangeEventType_abort: + case EIS_SecurityIdChangeEventType_abort: pthread_mutex_unlock(&facilities.id.lock); pthread_mutex_unlock(&facilities.lightship.lock); @@ -234,24 +234,24 @@ static int security_indication(void *responder_secured, uint8_t *msg, uint32_t m goto cleanup; } - sr->present = SecurityResponse_PR_idChangeEvent; + sr->present = EIS_SecurityResponse_PR_idChangeEvent; sr->choice.idChangeEvent.returnCode = 0; - enc = oer_encode_to_buffer(&asn_DEF_SecurityResponse, NULL, sr, buffer, 64); + enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityResponse, NULL, sr, buffer, 64); itss_0send(responder_secured, buffer, enc.encoded); pthread_mutex_unlock(&facilities.id.change.lock); cleanup: if (rv) { - sr->present = SecurityResponse_PR_idChangeEvent; + sr->present = EIS_SecurityResponse_PR_idChangeEvent; sr->choice.idChangeEvent.returnCode = 1; - enc = oer_encode_to_buffer(&asn_DEF_SecurityResponse, NULL, sr, buffer, 64); + enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityResponse, NULL, sr, buffer, 64); itss_0send(responder_secured, buffer, enc.encoded); } pthread_mutex_unlock(&facilities.id.change.lock); - ASN_STRUCT_FREE(asn_DEF_SecurityResponse, sr); - ASN_STRUCT_FREE(asn_DEF_SecurityIndication, si); + ASN_STRUCT_FREE(asn_DEF_EIS_SecurityResponse, sr); + ASN_STRUCT_FREE(asn_DEF_EIS_SecurityIndication, si); return rv; } @@ -262,9 +262,9 @@ static int management_indication(void *responder, uint8_t *msg, uint32_t msg_len uint8_t code = 0; - ManagementIndication_t *mi = calloc(1, sizeof(ManagementIndication_t)); + EIS_ManagementIndication_t *mi = calloc(1, sizeof(EIS_ManagementIndication_t)); - asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_ManagementIndication, (void **)&mi, msg, msg_len); + asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_EIS_ManagementIndication, (void **)&mi, msg, msg_len); if (dec.code) { rv = 1; code = 1; @@ -273,7 +273,7 @@ static int management_indication(void *responder, uint8_t *msg, uint32_t msg_len } itss_0send(responder, &code, 1); - if (mi->present == ManagementIndication_PR_attributes) { + if (mi->present == EIS_ManagementIndication_PR_attributes) { itss_space_lock(); epv.space.latitude = mi->choice.attributes.coordinates.latitude; epv.space.latitude_conf = mi->choice.attributes.coordinates.latitudeConfidence; @@ -305,7 +305,7 @@ static int management_indication(void *responder, uint8_t *msg, uint32_t msg_len } cleanup: - ASN_STRUCT_FREE(asn_DEF_ManagementIndication, mi); + ASN_STRUCT_FREE(asn_DEF_EIS_ManagementIndication, mi); return rv; } diff --git a/src/indications.c b/src/indications.c index 89acf26..9887240 100644 --- a/src/indications.c +++ b/src/indications.c @@ -1,14 +1,14 @@ #include "indications.h" -#include -#include +#include +#include #include -static void tcp_conn_reset(TCPConnRSTInfo_t* cri, void** security_socket) { +static void tcp_conn_reset(EIS_TCPConnRSTInfo_t* cri, void** security_socket) { if (cri->destinationAddress.size != 16) return; - SecurityRequest_t* sreq = NULL; + EIS_SecurityRequest_t* sreq = NULL; // Reset tolling, tls tolling_t* tolling = &facilities.tolling; @@ -20,13 +20,13 @@ static void tcp_conn_reset(TCPConnRSTInfo_t* cri, void** security_socket) { ) { for (int i = 0; i < bulletin->to_consume_len; ++i) { if (!memcmp(bulletin->to_consume[i]->endpoint.ipv6_addr, cri->destinationAddress.buf, 16)) { - sreq = calloc(1, sizeof(SecurityRequest_t)); - sreq->present = SecurityRequest_PR_tlsReset; + sreq = calloc(1, sizeof(EIS_SecurityRequest_t)); + sreq->present = EIS_SecurityRequest_PR_tlsReset; sreq->choice.tlsReset.connId = tolling->station.obu.tls_conn_id; uint8_t b_s[64], b_r[64]; b_s[0] = 4; - asn_enc_rval_t enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_SecurityRequest, sreq, b_s+1, 63); + asn_enc_rval_t enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_EIS_SecurityRequest, sreq, b_s+1, 63); if (enc.encoded == -1) { log_error("[facilities] SecurityRequest.tlsReset encoding failed"); } @@ -40,18 +40,18 @@ static void tcp_conn_reset(TCPConnRSTInfo_t* cri, void** security_socket) { } - ASN_STRUCT_FREE(asn_DEF_SecurityRequest, sreq); + ASN_STRUCT_FREE(asn_DEF_EIS_SecurityRequest, sreq); } -int networking_data_indication(NetworkingDataIndication_t* ndi, void** security_socket) { +int networking_data_indication(EIS_NetworkingDataIndication_t* ndi, void** security_socket) { int rv = 0; switch (ndi->present) { - case NetworkingDataIndication_PR_transport: + case EIS_NetworkingDataIndication_PR_transport: switch (ndi->choice.transport.present) { - case NetworkingDataIndicationTP_PR_tcp: + case EIS_NetworkingDataIndicationTP_PR_tcp: switch (ndi->choice.transport.choice.tcp.present) { - case TCPDataIndication_PR_connInfoReset: + case EIS_TCPDataIndication_PR_connInfoReset: tcp_conn_reset(&ndi->choice.transport.choice.tcp.choice.connInfoReset, security_socket); break; default: @@ -64,7 +64,7 @@ int networking_data_indication(NetworkingDataIndication_t* ndi, void** security_ goto cleanup; } break; - case NetworkingDataIndication_PR_network: + case EIS_NetworkingDataIndication_PR_network: if (ndi->choice.network.mobileNeighbour && *ndi->choice.network.mobileNeighbour) { pthread_mutex_lock(&facilities.lightship.lock); diff --git a/src/indications.h b/src/indications.h index 0987e38..1e92f4e 100644 --- a/src/indications.h +++ b/src/indications.h @@ -1,6 +1,6 @@ #pragma once #include "facilities.h" -#include +#include -int networking_data_indication(NetworkingDataIndication_t* tpi, void** security_socket); +int networking_data_indication(EIS_NetworkingDataIndication_t* tpi, void** security_socket); diff --git a/src/infrastructure.c b/src/infrastructure.c index 01c8d01..48e9189 100644 --- a/src/infrastructure.c +++ b/src/infrastructure.c @@ -6,9 +6,9 @@ #include #include -#include +#include -const ivi_diid_ssp_bm_t DIID_SSP_BM_MAP[] = { +static const ivi_diid_ssp_bm_t DIID_SSP_BM_MAP[] = { {"Vienna Convention Code for road sign", IVI_DIID_ViennaCodeConvention, 0x800000}, {"ISO 14823 traffic sign pictogram (danger/warning)", IVI_DIID_TrafficSignPictogramDangerWarning, 0x400000}, {"ISO 14823 traffic sign pictogram (regulatory)", IVI_DIID_TrafficSignPictogramRegulatory, 0x200000}, @@ -25,7 +25,7 @@ const ivi_diid_ssp_bm_t DIID_SSP_BM_MAP[] = { }; static int permissions_check(int diid, uint8_t* permissions, uint8_t permissions_len) { - /* IVIM SSP scheme + /* EI1_IVIM SSP scheme * * byte | description * --------------------------------- @@ -71,7 +71,7 @@ static enum SERVICE_EVAL_R service_check(enum SERVICE_TYPE type, void* its_msg, return -1; } - IVIM_t* ivim = (IVIM_t*) its_msg; + EI1_IVIM_t* ivim = (EI1_IVIM_t*) its_msg; uint64_t timestamp, valid_to, valid_from; if (!ivim->ivi.mandatory.timeStamp) { @@ -103,46 +103,46 @@ static enum SERVICE_EVAL_R service_check(enum SERVICE_TYPE type, void* its_msg, if (ivim->ivi.optional) { for (int i = 0; i < ivim->ivi.optional->list.count; ++i) { switch (ivim->ivi.optional->list.array[i]->present) { - case IviContainer_PR_giv: + case EI1_IviContainer_PR_giv: ; - GeneralIviContainer_t* giv = &ivim->ivi.optional->list.array[i]->choice.giv; + EI1_GeneralIviContainer_t* giv = &ivim->ivi.optional->list.array[i]->choice.giv; for (int j = 0; j < giv->list.count; ++j) { - GicPart_t* gicp = giv->list.array[j]; + EI1_GicPart_t* gicp = giv->list.array[j]; for (int k = 0; k < gicp->roadSignCodes.list.count; ++k) { - struct RSCode__code* code = &gicp->roadSignCodes.list.array[k]->code; + struct EI1_RSCode__code* code = &gicp->roadSignCodes.list.array[k]->code; switch (code->present) { - case RSCode__code_PR_viennaConvention: + case EI1_RSCode__code_PR_viennaConvention: if (!permissions_check(IVI_DIID_ViennaCodeConvention, ssp, ssp_len)) {return SERVICE_BAD_PERMISSIONS;} break; - case RSCode__code_PR_iso14823: + case EI1_RSCode__code_PR_iso14823: switch (code->choice.iso14823.pictogramCode.serviceCategoryCode.present) { - case ISO14823Code__pictogramCode__serviceCategoryCode_PR_trafficSignPictogram: + case EI1_ISO14823Code__pictogramCode__serviceCategoryCode_PR_trafficSignPictogram: switch (code->choice.iso14823.pictogramCode.serviceCategoryCode.choice.trafficSignPictogram) { - case ISO14823Code__pictogramCode__serviceCategoryCode__trafficSignPictogram_dangerWarning: + case EI1_ISO14823Code__pictogramCode__serviceCategoryCode__trafficSignPictogram_dangerWarning: if (!permissions_check(IVI_DIID_TrafficSignPictogramDangerWarning, ssp, ssp_len)) {return SERVICE_BAD_PERMISSIONS;} break; - case ISO14823Code__pictogramCode__serviceCategoryCode__trafficSignPictogram_regulatory: + case EI1_ISO14823Code__pictogramCode__serviceCategoryCode__trafficSignPictogram_regulatory: if (!permissions_check(IVI_DIID_TrafficSignPictogramRegulatory, ssp, ssp_len)) {return SERVICE_BAD_PERMISSIONS;} break; - case ISO14823Code__pictogramCode__serviceCategoryCode__trafficSignPictogram_informative: + case EI1_ISO14823Code__pictogramCode__serviceCategoryCode__trafficSignPictogram_informative: if (!permissions_check(IVI_DIID_TrafficSignPictogramInformative, ssp, ssp_len)) {return SERVICE_BAD_PERMISSIONS;} break; } break; - case ISO14823Code__pictogramCode__serviceCategoryCode_PR_publicFacilitiesPictogram: + case EI1_ISO14823Code__pictogramCode__serviceCategoryCode_PR_publicFacilitiesPictogram: if (!permissions_check(IVI_DIID_ServiceCategoryCodePublicFacilitiesPictogram, ssp, ssp_len)) {return SERVICE_BAD_PERMISSIONS;} break; - case ISO14823Code__pictogramCode__serviceCategoryCode_PR_ambientOrRoadConditionPictogram: + case EI1_ISO14823Code__pictogramCode__serviceCategoryCode_PR_ambientOrRoadConditionPictogram: switch (code->choice.iso14823.pictogramCode.serviceCategoryCode.choice.ambientOrRoadConditionPictogram) { - case ISO14823Code__pictogramCode__serviceCategoryCode__ambientOrRoadConditionPictogram_ambientCondition: + case EI1_ISO14823Code__pictogramCode__serviceCategoryCode__ambientOrRoadConditionPictogram_ambientCondition: if (!permissions_check(IVI_DIID_ServiceCategoryCodeAmbientOrRoadConditionPictogramAmbientCondition, ssp, ssp_len)) {return SERVICE_BAD_PERMISSIONS;} break; - case ISO14823Code__pictogramCode__serviceCategoryCode__ambientOrRoadConditionPictogram_roadCondition: + case EI1_ISO14823Code__pictogramCode__serviceCategoryCode__ambientOrRoadConditionPictogram_roadCondition: if (!permissions_check(IVI_DIID_ServiceCategoryCodeAmbientOrRoadConditionPictogramRoadCondition, ssp, ssp_len)) {return SERVICE_BAD_PERMISSIONS;} break; } @@ -152,7 +152,7 @@ static enum SERVICE_EVAL_R service_check(enum SERVICE_TYPE type, void* its_msg, } break; - case RSCode__code_PR_itisCodes: + case EI1_RSCode__code_PR_itisCodes: if (!permissions_check(IVI_DIID_itisCodes, ssp, ssp_len)) {return SERVICE_BAD_PERMISSIONS;} break; @@ -168,15 +168,15 @@ static enum SERVICE_EVAL_R service_check(enum SERVICE_TYPE type, void* its_msg, } // end giv list for break; - case IviContainer_PR_rcc: + case EI1_IviContainer_PR_rcc: if (!permissions_check(IVI_DIID_rcc, ssp, ssp_len)) {return SERVICE_BAD_PERMISSIONS;} break; - case IviContainer_PR_tc: + case EI1_IviContainer_PR_tc: if (!permissions_check(IVI_DIID_tc, ssp, ssp_len)) {return SERVICE_BAD_PERMISSIONS;} break; - case IviContainer_PR_lac: + case EI1_IviContainer_PR_lac: if (!permissions_check(IVI_DIID_lac, ssp, ssp_len)) {return SERVICE_BAD_PERMISSIONS;} break; @@ -188,7 +188,7 @@ static enum SERVICE_EVAL_R service_check(enum SERVICE_TYPE type, void* its_msg, } // end optional list for } // end optional if - if (ivim->ivi.mandatory.iviStatus == IviStatus_negation) { + if (ivim->ivi.mandatory.iviStatus == EI1_IviStatus_negation) { if (!permissions_check(IVI_DIID_StatusNegation, ssp, ssp_len)) {return SERVICE_BAD_PERMISSIONS;} } } // end parameters check @@ -262,7 +262,7 @@ static int service_add(enum SERVICE_TYPE type, void* its_msg, uint64_t* id) { return -1; } - IVIM_t* ivim = (IVIM_t*) its_msg; + EI1_IVIM_t* ivim = (EI1_IVIM_t*) its_msg; uint64_t now = itss_time_get(); @@ -350,7 +350,7 @@ static int service_update(enum SERVICE_TYPE type, void* its_msg, uint64_t* id) { return -1; } - IVIM_t* ivim = (IVIM_t*) its_msg; + EI1_IVIM_t* ivim = (EI1_IVIM_t*) its_msg; uint64_t now = itss_time_get(); @@ -438,7 +438,7 @@ static int service_update(enum SERVICE_TYPE type, void* its_msg, uint64_t* id) { infrastructure->services[index]->valid_to = now + 600 * 1000; } - ASN_STRUCT_FREE(asn_DEF_IVIM, infrastructure->services[index]->ivim); + ASN_STRUCT_FREE(asn_DEF_EI1_IVIM, infrastructure->services[index]->ivim); infrastructure->services[index]->ivim = ivim; } @@ -459,23 +459,23 @@ enum SERVICE_EVAL_R service_eval(enum SERVICE_TYPE type, void* its_msg, uint64_t log_debug("[infrastructure] new service received"); if (service_add(type, its_msg, id)) { log_debug("[infrastructure] failed adding service, max services reached"); - ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg); + ASN_STRUCT_FREE(asn_DEF_EI1_IVIM, its_msg); rv = -1; } break; case SERVICE_INVALID: log_debug("[infrastructure] invalid service received, ignoring"); - ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg); + ASN_STRUCT_FREE(asn_DEF_EI1_IVIM, its_msg); break; case SERVICE_PASSED: log_debug("[infrastructure] old service received, ignoring"); - ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg); + ASN_STRUCT_FREE(asn_DEF_EI1_IVIM, its_msg); break; case SERVICE_CANCELLATION: log_debug("[infrastructure] service cancellation received"); if (service_update(type, its_msg, id)) { log_debug("[infrastructure] failed cancelling service, event not found"); - ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg); + ASN_STRUCT_FREE(asn_DEF_EI1_IVIM, its_msg); rv = -1; } break; @@ -483,7 +483,7 @@ enum SERVICE_EVAL_R service_eval(enum SERVICE_TYPE type, void* its_msg, uint64_t log_debug("[infrastructure] service negation received"); if (service_update(type, its_msg, id)) { log_debug("[infrastructure] failed negating service, service not found"); - ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg); + ASN_STRUCT_FREE(asn_DEF_EI1_IVIM, its_msg); rv = -1; } break; @@ -491,21 +491,21 @@ enum SERVICE_EVAL_R service_eval(enum SERVICE_TYPE type, void* its_msg, uint64_t log_debug("[infrastructure] service update received"); if (service_update(type, its_msg, id)) { log_debug("[infrastructure] failed updating service, service not found"); - ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg); + ASN_STRUCT_FREE(asn_DEF_EI1_IVIM, its_msg); rv = -1; } break; case SERVICE_REPEATED: log_debug("[infrastructure] repeated service received or timeStamp doesn't allow an update, ignoring"); - ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg); + ASN_STRUCT_FREE(asn_DEF_EI1_IVIM, its_msg); break; case SERVICE_NUMBER_EXCEEDED: log_debug("[infrastructure] max services reached, ignoring"); - ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg); + ASN_STRUCT_FREE(asn_DEF_EI1_IVIM, its_msg); break; case SERVICE_BAD_PERMISSIONS: log_debug("[infrastructure] invalid service permissions, ignoring"); - ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg); + ASN_STRUCT_FREE(asn_DEF_EI1_IVIM, its_msg); break; } return rv; @@ -542,7 +542,7 @@ void* infrastructure_service() { log_debug("[infrastructure] removed service %d (expiration)", i); infrastructure->services[i]->enabled = false; - ASN_STRUCT_FREE(asn_DEF_IVIM, infrastructure->services[i]->ivim); + ASN_STRUCT_FREE(asn_DEF_EI1_IVIM, infrastructure->services[i]->ivim); switch (infrastructure->services[i]->state) { case SERVICE_ACTIVE: --infrastructure->n_active_services; diff --git a/src/infrastructure.h b/src/infrastructure.h index b75f069..1dbd69d 100644 --- a/src/infrastructure.h +++ b/src/infrastructure.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include #include @@ -49,7 +49,7 @@ typedef struct service { uint32_t station_id; enum SERVICE_STATE state; - IVIM_t *ivim; + EI1_IVIM_t *ivim; uint64_t ivi_id_number; uint64_t timestamp; uint64_t valid_from; diff --git a/src/requests.c b/src/requests.c index 12badb4..c22f232 100644 --- a/src/requests.c +++ b/src/requests.c @@ -1,12 +1,11 @@ #include "requests.h" -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -22,11 +21,11 @@ #include "tpm.h" static void fwd_to_apps(uint8_t* msg, uint16_t msg_len, int its_msg_type, uint32_t iid) { - FacilitiesIndication_t* fi = NULL; + EIS_FacilitiesIndication_t* fi = NULL; - fi = calloc(1, sizeof(FacilitiesIndication_t)); - fi->present = FacilitiesIndication_PR_message; - FacilitiesMessageIndication_t *fmi = &fi->choice.message; + fi = calloc(1, sizeof(EIS_FacilitiesIndication_t)); + fi->present = EIS_FacilitiesIndication_PR_message; + EIS_FacilitiesMessageIndication_t *fmi = &fi->choice.message; fmi->id = iid; @@ -38,7 +37,7 @@ static void fwd_to_apps(uint8_t* msg, uint16_t msg_len, int its_msg_type, uint32 uint8_t buffer[ITSS_SDU_MAX_LEN]; buffer[0] = 4; // Facilities - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesIndication, NULL, fi, buffer + 1, ITSS_SDU_MAX_LEN - 1); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_FacilitiesIndication, NULL, fi, buffer + 1, ITSS_SDU_MAX_LEN - 1); log_debug("-> FI.message ->[applications] | id:%08x size:%dB", (uint32_t)iid, enc.encoded+1); @@ -50,45 +49,45 @@ static void fwd_to_apps(uint8_t* msg, uint16_t msg_len, int its_msg_type, uint32 (uint32_t)iid, enc.encoded+1); } - ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi); + ASN_STRUCT_FREE(asn_DEF_EIS_FacilitiesIndication, fi); } int facilities_request_result_accepted(void *responder) { int rv = 0; - FacilitiesReply_t *fr = calloc(1, sizeof(FacilitiesReply_t)); - fr->present = FacilitiesReply_PR_message; + EIS_FacilitiesReply_t *fr = calloc(1, sizeof(EIS_FacilitiesReply_t)); + fr->present = EIS_FacilitiesReply_PR_message; fr->choice.message.returnCode = 0; uint8_t fr_oer[32]; - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesReply, NULL, fr, fr_oer, 32); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_FacilitiesReply, NULL, fr, fr_oer, 32); itss_0send(responder, fr_oer, enc.encoded); - ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, fr); + ASN_STRUCT_FREE(asn_DEF_EIS_FacilitiesReply, fr); return rv; } int facilities_request_result_rejected(void *responder) { int rv = 0; - FacilitiesReply_t *fr = calloc(1, sizeof(FacilitiesReply_t)); - fr->present = FacilitiesReply_PR_message; + EIS_FacilitiesReply_t *fr = calloc(1, sizeof(EIS_FacilitiesReply_t)); + fr->present = EIS_FacilitiesReply_PR_message; fr->choice.message.returnCode = 1; uint8_t fr_oer[32]; - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesReply, NULL, fr, fr_oer, 32); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_FacilitiesReply, NULL, fr, fr_oer, 32); itss_0send(responder, fr_oer, enc.encoded); - ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, fr); + ASN_STRUCT_FREE(asn_DEF_EIS_FacilitiesReply, fr); return rv; } -int facilities_request_single_message(void *responder, FacilitiesMessageRequest_t *frm) { +int facilities_request_single_message(void *responder, EIS_FacilitiesMessageRequest_t *frm) { int rv = 0; - NetworkingRequest_t* nr = calloc(1, sizeof(NetworkingRequest_t)); - nr->present = NetworkingRequest_PR_packet; - NetworkingPacketRequest_t* npr = &nr->choice.packet; - npr->network.present = NetworkingPacketRequestNW_PR_gn; - npr->transport.present = NetworkingPacketRequestTP_PR_btp; + EIS_NetworkingRequest_t* nr = calloc(1, sizeof(EIS_NetworkingRequest_t)); + nr->present = EIS_NetworkingRequest_PR_packet; + EIS_NetworkingPacketRequest_t* npr = &nr->choice.packet; + npr->network.present = EIS_NetworkingPacketRequestNW_PR_gn; + npr->transport.present = EIS_NetworkingPacketRequestTP_PR_btp; void *its_msg = NULL; asn_TYPE_descriptor_t *its_msg_def = NULL; @@ -100,44 +99,44 @@ int facilities_request_single_message(void *responder, FacilitiesMessageRequest_ uint64_t transmission_start = 0; switch (frm->itsMessageType) { - case ItsMessageType_cam: - its_msg_def = &asn_DEF_CAM; - its_msg = calloc(1, sizeof(CAM_t)); - npr->transport.choice.btp.destinationPort = Port_cam; - npr->network.choice.gn.packetTransportType = PacketTransportType_shb; + case EIS_ItsMessageType_cam: + its_msg_def = &asn_DEF_EI1_CAM; + its_msg = calloc(1, sizeof(EI1_CAM_t)); + npr->transport.choice.btp.destinationPort = EIS_Port_cam; + npr->network.choice.gn.packetTransportType = EIS_PacketTransportType_shb; npr->network.choice.gn.trafficClass = 1; break; - case ItsMessageType_denm: - its_msg_def = &asn_DEF_DENM; - its_msg = calloc(1, sizeof(DENM_t)); - npr->transport.choice.btp.destinationPort = Port_denm; - npr->network.choice.gn.packetTransportType = PacketTransportType_gbc; + case EIS_ItsMessageType_denm: + its_msg_def = &asn_DEF_EI1_DENM; + its_msg = calloc(1, sizeof(EI1_DENM_t)); + npr->transport.choice.btp.destinationPort = EIS_Port_denm; + npr->network.choice.gn.packetTransportType = EIS_PacketTransportType_gbc; npr->network.choice.gn.trafficClass = 2; break; - case ItsMessageType_ivim: - its_msg_def = &asn_DEF_IVIM; - its_msg = calloc(1, sizeof(IVIM_t)); - npr->transport.choice.btp.destinationPort = Port_ivim; - npr->network.choice.gn.packetTransportType = PacketTransportType_shb; + case EIS_ItsMessageType_ivim: + its_msg_def = &asn_DEF_EI1_IVIM; + its_msg = calloc(1, sizeof(EI1_IVIM_t)); + npr->transport.choice.btp.destinationPort = EIS_Port_ivim; + npr->network.choice.gn.packetTransportType = EIS_PacketTransportType_shb; npr->network.choice.gn.trafficClass = 1; break; - case ItsMessageType_cpm: - its_msg_def = &asn_DEF_CPM; - its_msg = calloc(1, sizeof(CPM_t)); - npr->transport.choice.btp.destinationPort = Port_cpm; - npr->network.choice.gn.packetTransportType = PacketTransportType_shb; + case EIS_ItsMessageType_cpm: + its_msg_def = &asn_DEF_EI1_CPM; + its_msg = calloc(1, sizeof(EI1_CPM_t)); + npr->transport.choice.btp.destinationPort = EIS_Port_cpm; + npr->network.choice.gn.packetTransportType = EIS_PacketTransportType_shb; npr->network.choice.gn.trafficClass = 2; break; - case ItsMessageType_evrsr: - its_msg_def = &asn_DEF_EV_RSR; - its_msg = calloc(1, sizeof(EV_RSR_t)); - npr->transport.choice.btp.destinationPort = Port_evrsr; - npr->network.choice.gn.packetTransportType = PacketTransportType_shb; + case EIS_ItsMessageType_evrsr: + its_msg_def = &asn_DEF_EI1_EV_RSR; + its_msg = calloc(1, sizeof(EI1_EV_RSR_t)); + npr->transport.choice.btp.destinationPort = EIS_Port_evrsr; + npr->network.choice.gn.packetTransportType = EIS_PacketTransportType_shb; npr->network.choice.gn.trafficClass = 1; break; @@ -166,7 +165,7 @@ int facilities_request_single_message(void *responder, FacilitiesMessageRequest_ bool is_update = false; int managed_msg = false; - if (frm->itsMessageType == ItsMessageType_denm) { + if (frm->itsMessageType == EIS_ItsMessageType_denm) { managed_msg = true; uint8_t event_type = event_manage(its_msg, &id, NULL, 0); @@ -188,21 +187,21 @@ int facilities_request_single_message(void *responder, FacilitiesMessageRequest_ if (fwd) { // set stationID pthread_mutex_lock(&facilities.id.lock); - ((DENM_t *)its_msg)->header.stationID = facilities.id.station_id; + ((EI1_DENM_t *)its_msg)->header.stationID = facilities.id.station_id; pthread_mutex_unlock(&facilities.id.lock); // Set only one trace if (facilities.station_type != 15) { pthread_mutex_lock(&facilities.lightship.lock); if (facilities.lightship.path_history_len > 0) { - if (!((DENM_t *)its_msg)->denm.location) { - ((DENM_t *)its_msg)->denm.location = calloc(1, sizeof(LocationContainer_t)); + if (!((EI1_DENM_t *)its_msg)->denm.location) { + ((EI1_DENM_t *)its_msg)->denm.location = calloc(1, sizeof(EI1_LocationContainer_t)); } - ((DENM_t *)its_msg)->denm.location->traces.list.count = 1; - ((DENM_t *)its_msg)->denm.location->traces.list.size = 1 * sizeof(void *); - ((DENM_t *)its_msg)->denm.location->traces.list.array = malloc(1 * sizeof(void *)); - ((DENM_t *)its_msg)->denm.location->traces.list.array[0] = calloc(1, sizeof(PathHistory_t)); - PathHistory_t *ph = ((DENM_t *)its_msg)->denm.location->traces.list.array[0]; + ((EI1_DENM_t *)its_msg)->denm.location->traces.list.count = 1; + ((EI1_DENM_t *)its_msg)->denm.location->traces.list.size = 1 * sizeof(void *); + ((EI1_DENM_t *)its_msg)->denm.location->traces.list.array = malloc(1 * sizeof(void *)); + ((EI1_DENM_t *)its_msg)->denm.location->traces.list.array[0] = calloc(1, sizeof(EI1_PathHistory_t)); + EI1_PathHistory_t *ph = ((EI1_DENM_t *)its_msg)->denm.location->traces.list.array[0]; pos_point_t **path_history = facilities.lightship.path_history; uint16_t path_history_len = facilities.lightship.path_history_len; @@ -211,53 +210,53 @@ int facilities_request_single_message(void *responder, FacilitiesMessageRequest_ ph->list.count = path_history_len; ph->list.size = (path_history_len) * sizeof(void *); - ph->list.array[0] = calloc(1, sizeof(PathPoint_t)); + ph->list.array[0] = calloc(1, sizeof(EI1_PathPoint_t)); itss_space_lock(); - if (path_history[0]->alt != AltitudeValue_unavailable && epv.space.altitude != AltitudeValue_unavailable) { + if (path_history[0]->alt != EI1_AltitudeValue_unavailable && epv.space.altitude != EI1_AltitudeValue_unavailable) { ph->list.array[0]->pathPosition.deltaAltitude = path_history[0]->alt - epv.space.altitude; } else { - ph->list.array[0]->pathPosition.deltaAltitude = DeltaAltitude_unavailable; + ph->list.array[0]->pathPosition.deltaAltitude = EI1_DeltaAltitude_unavailable; } - if (path_history[0]->lat != Latitude_unavailable && epv.space.latitude != Latitude_unavailable) { + if (path_history[0]->lat != EI1_Latitude_unavailable && epv.space.latitude != EI1_Latitude_unavailable) { ph->list.array[0]->pathPosition.deltaLatitude = path_history[0]->lat - epv.space.latitude; } else { - ph->list.array[0]->pathPosition.deltaLatitude = DeltaLatitude_unavailable; + ph->list.array[0]->pathPosition.deltaLatitude = EI1_DeltaLatitude_unavailable; } - if (path_history[0]->lon != Longitude_unavailable && epv.space.longitude != Longitude_unavailable) { + if (path_history[0]->lon != EI1_Longitude_unavailable && epv.space.longitude != EI1_Longitude_unavailable) { ph->list.array[0]->pathPosition.deltaLongitude = path_history[0]->lon - epv.space.longitude; } else { - ph->list.array[0]->pathPosition.deltaLongitude = DeltaLongitude_unavailable; + ph->list.array[0]->pathPosition.deltaLongitude = EI1_DeltaLongitude_unavailable; } itss_space_unlock(); - ph->list.array[0]->pathDeltaTime = calloc(1, sizeof(PathDeltaTime_t)); + ph->list.array[0]->pathDeltaTime = calloc(1, sizeof(EI1_PathDeltaTime_t)); *ph->list.array[0]->pathDeltaTime = (itss_time_get() - path_history[0]->ts) / 10; for (int i = 1; i < path_history_len; ++i) { - ph->list.array[i] = calloc(1, sizeof(PathPoint_t)); + ph->list.array[i] = calloc(1, sizeof(EI1_PathPoint_t)); - if (path_history[i]->alt != AltitudeValue_unavailable && path_history[i - 1]->alt != AltitudeValue_unavailable) { + if (path_history[i]->alt != EI1_AltitudeValue_unavailable && path_history[i - 1]->alt != EI1_AltitudeValue_unavailable) { ph->list.array[i]->pathPosition.deltaAltitude = path_history[i]->alt - path_history[i - 1]->alt; } else { - ph->list.array[i]->pathPosition.deltaAltitude = DeltaAltitude_unavailable; + ph->list.array[i]->pathPosition.deltaAltitude = EI1_DeltaAltitude_unavailable; } - if (path_history[i]->lat != Latitude_unavailable && path_history[i - 1]->lat != Latitude_unavailable) { + if (path_history[i]->lat != EI1_Latitude_unavailable && path_history[i - 1]->lat != EI1_Latitude_unavailable) { ph->list.array[i]->pathPosition.deltaLatitude = path_history[i]->lat - path_history[i - 1]->lat; } else { - ph->list.array[i]->pathPosition.deltaLatitude = DeltaLatitude_unavailable; + ph->list.array[i]->pathPosition.deltaLatitude = EI1_DeltaLatitude_unavailable; } - if (path_history[i]->lon != Longitude_unavailable && path_history[i - 1]->lon != Longitude_unavailable) { + if (path_history[i]->lon != EI1_Longitude_unavailable && path_history[i - 1]->lon != EI1_Longitude_unavailable) { ph->list.array[i]->pathPosition.deltaLongitude = path_history[i]->lon - path_history[i - 1]->lon; } else { - ph->list.array[i]->pathPosition.deltaLongitude = DeltaLongitude_unavailable; + ph->list.array[i]->pathPosition.deltaLongitude = EI1_DeltaLongitude_unavailable; } - ph->list.array[i]->pathDeltaTime = calloc(1, sizeof(PathDeltaTime_t)); + ph->list.array[i]->pathDeltaTime = calloc(1, sizeof(EI1_PathDeltaTime_t)); *ph->list.array[i]->pathDeltaTime = (path_history[i - 1]->ts - path_history[i]->ts) / 10; } } @@ -265,17 +264,17 @@ int facilities_request_single_message(void *responder, FacilitiesMessageRequest_ } // get, set retransmission, duration - if (((DENM_t *)its_msg)->denm.management.transmissionInterval) { - transmission_interval = *((uint32_t *)((DENM_t *)its_msg)->denm.management.transmissionInterval); + if (((EI1_DENM_t *)its_msg)->denm.management.transmissionInterval) { + transmission_interval = *((uint32_t *)((EI1_DENM_t *)its_msg)->denm.management.transmissionInterval); - if (((DENM_t *)its_msg)->denm.management.validityDuration) { - transmission_duration = *((uint32_t *)((DENM_t *)its_msg)->denm.management.validityDuration) * 1000; + if (((EI1_DENM_t *)its_msg)->denm.management.validityDuration) { + transmission_duration = *((uint32_t *)((EI1_DENM_t *)its_msg)->denm.management.validityDuration) * 1000; } else { transmission_duration = 600 * 1000; } } } - } else if (frm->itsMessageType == ItsMessageType_ivim) { + } else if (frm->itsMessageType == EIS_ItsMessageType_ivim) { managed_msg = true; uint8_t service_type = service_eval(SERVICE_IVI, its_msg, &id, NULL, 0); @@ -296,23 +295,23 @@ int facilities_request_single_message(void *responder, FacilitiesMessageRequest_ if (fwd) { uint64_t valid_to, valid_from; - if (!((IVIM_t *)its_msg)->ivi.mandatory.validFrom) { + if (!((EI1_IVIM_t *)its_msg)->ivi.mandatory.validFrom) { valid_from = itss_time_get(); } else { - asn_INTEGER2ulong((INTEGER_t *)((IVIM_t *)its_msg)->ivi.mandatory.validFrom, (unsigned long long *)&valid_from); + asn_INTEGER2ulong((INTEGER_t *)((EI1_IVIM_t *)its_msg)->ivi.mandatory.validFrom, (unsigned long long *)&valid_from); } - if (!((IVIM_t *)its_msg)->ivi.mandatory.validTo) { + if (!((EI1_IVIM_t *)its_msg)->ivi.mandatory.validTo) { valid_to = valid_from + facilities.infrastructure.default_service_duration; } else { - asn_INTEGER2ulong((INTEGER_t *)((IVIM_t *)its_msg)->ivi.mandatory.validTo, (unsigned long long *)&valid_to); + asn_INTEGER2ulong((INTEGER_t *)((EI1_IVIM_t *)its_msg)->ivi.mandatory.validTo, (unsigned long long *)&valid_to); } transmission_start = valid_from; transmission_interval = facilities.infrastructure.replay_interval; transmission_duration = valid_to - valid_from; } - } else if (frm->itsMessageType == ItsMessageType_evrsr) { + } else if (frm->itsMessageType == EIS_ItsMessageType_evrsr) { managed_msg = true; } if (!facilities.replay) { @@ -325,7 +324,7 @@ int facilities_request_single_message(void *responder, FacilitiesMessageRequest_ // Forward message to [networking] if (fwd) { - npr->transport.choice.btp.btpType = BTPType_btpB; + npr->transport.choice.btp.btpType = EIS_BTPType_btpB; npr->id = id; @@ -367,7 +366,7 @@ int facilities_request_single_message(void *responder, FacilitiesMessageRequest_ uint8_t tr_oer[2048]; tr_oer[0] = 4; // [facilities] service id - enc = oer_encode_to_buffer(&asn_DEF_NetworkingRequest, NULL, nr, tr_oer + 1, 2047); + enc = oer_encode_to_buffer(&asn_DEF_EIS_NetworkingRequest, NULL, nr, tr_oer + 1, 2047); if (enc.encoded == -1) { log_error("failed encoding TR (%s)", enc.failed_type->name); rv = 1; @@ -398,19 +397,19 @@ int facilities_request_single_message(void *responder, FacilitiesMessageRequest_ cleanup: if (its_msg_def && !managed_msg) ASN_STRUCT_FREE(*its_msg_def, its_msg); - ASN_STRUCT_FREE(asn_DEF_NetworkingRequest, nr); + ASN_STRUCT_FREE(asn_DEF_EIS_NetworkingRequest, nr); return rv; } -int facilities_request_active_episodes(void *responder, FacilitiesRequest_t *freq) { +int facilities_request_active_episodes(void *responder, EIS_FacilitiesRequest_t *freq) { int rv = 0; - FacilitiesReply_t *frep = calloc(1, sizeof(FacilitiesReply_t)); + EIS_FacilitiesReply_t *frep = calloc(1, sizeof(EIS_FacilitiesReply_t)); uint8_t *frep_oer = NULL; - frep->present = FacilitiesReply_PR_data; - frep->choice.data.present = FacilitiesDataReply_PR_episodes; + frep->present = EIS_FacilitiesReply_PR_data; + frep->choice.data.present = EIS_FacilitiesDataReply_PR_episodes; pthread_mutex_lock(&facilities.den.lock); pthread_mutex_lock(&facilities.infrastructure.lock); @@ -422,10 +421,10 @@ int facilities_request_active_episodes(void *responder, FacilitiesRequest_t *fre for (int e = 0; e < freq->choice.data.choice.activeEpisodes.list.count; ++e) { switch (*freq->choice.data.choice.activeEpisodes.list.array[e]) { - case EpisodeType_denm: + case EIS_EpisodeType_denm: na += nae; break; - case EpisodeType_ivim: + case EIS_EpisodeType_ivim: na += nas; break; } @@ -437,13 +436,13 @@ int facilities_request_active_episodes(void *responder, FacilitiesRequest_t *fre for (int e = 0, j = 0; e < freq->choice.data.choice.activeEpisodes.list.count; ++e) { switch (*freq->choice.data.choice.activeEpisodes.list.array[e]) { - case EpisodeType_denm: + case EIS_EpisodeType_denm: for (int i = 0, n = 0; n < nae; ++i) { if (facilities.den.events[i]->enabled && facilities.den.events[i]->state == EVENT_ACTIVE) { - frep->choice.data.choice.episodes.list.array[j] = calloc(1, sizeof(ItsMessage_t)); - frep->choice.data.choice.episodes.list.array[j]->itsMessageType = ItsMessageType_denm; + frep->choice.data.choice.episodes.list.array[j] = calloc(1, sizeof(EIS_ItsMessage_t)); + frep->choice.data.choice.episodes.list.array[j]->itsMessageType = EIS_ItsMessageType_denm; frep->choice.data.choice.episodes.list.array[j]->data.buf = malloc(2048); - asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_DENM, NULL, facilities.den.events[i]->denm, frep->choice.data.choice.episodes.list.array[j]->data.buf, 2048); + asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_EI1_DENM, NULL, facilities.den.events[i]->denm, frep->choice.data.choice.episodes.list.array[j]->data.buf, 2048); if (enc.encoded == -1) { /* encoding shouldn't fail as all saved DENMs are structurally valid */ log_error("failed encoding DENM for FDResult (%s)", enc.failed_type->name); frep->choice.data.choice.episodes.list.array[j]->data.size = 0; @@ -455,13 +454,13 @@ int facilities_request_active_episodes(void *responder, FacilitiesRequest_t *fre } } break; - case EpisodeType_ivim: + case EIS_EpisodeType_ivim: for (int i = 0, n = 0; n < nas; ++i) { if (facilities.infrastructure.services[i]->enabled && facilities.infrastructure.services[i]->state == SERVICE_ACTIVE) { - frep->choice.data.choice.episodes.list.array[j] = calloc(1, sizeof(ItsMessage_t)); - frep->choice.data.choice.episodes.list.array[j]->itsMessageType = ItsMessageType_ivim; + frep->choice.data.choice.episodes.list.array[j] = calloc(1, sizeof(EIS_ItsMessage_t)); + frep->choice.data.choice.episodes.list.array[j]->itsMessageType = EIS_ItsMessageType_ivim; frep->choice.data.choice.episodes.list.array[j]->data.buf = malloc(2048); - asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_IVIM, NULL, facilities.infrastructure.services[i]->ivim, frep->choice.data.choice.episodes.list.array[j]->data.buf, 2048); + asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_EI1_IVIM, NULL, facilities.infrastructure.services[i]->ivim, frep->choice.data.choice.episodes.list.array[j]->data.buf, 2048); if (enc.encoded == -1) { /* encoding shouldn't fail as all saved DENMs are structurally valid */ log_error("failed encoding IVIM for FDResult (%s)", enc.failed_type->name); frep->choice.data.choice.episodes.list.array[j]->data.size = 0; @@ -488,7 +487,7 @@ int facilities_request_active_episodes(void *responder, FacilitiesRequest_t *fre pthread_mutex_unlock(&facilities.infrastructure.lock); frep_oer = malloc(32768); - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesReply, NULL, frep, frep_oer, 32768); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_FacilitiesReply, NULL, frep, frep_oer, 32768); if (enc.encoded == -1) { log_error("failed encoding FReply (%s)", enc.failed_type->name); @@ -501,26 +500,26 @@ int facilities_request_active_episodes(void *responder, FacilitiesRequest_t *fre cleanup: free(frep_oer); - ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, frep); + ASN_STRUCT_FREE(asn_DEF_EIS_FacilitiesReply, frep); return rv; } -int facilities_request_attribute_types(void *responder, FacilitiesRequest_t *freq) { +int facilities_request_attribute_types(void *responder, EIS_FacilitiesRequest_t *freq) { int rv = 0; - FacilitiesReply_t *frep = calloc(1, sizeof(FacilitiesReply_t)); - frep->present = FacilitiesReply_PR_data; + EIS_FacilitiesReply_t *frep = calloc(1, sizeof(EIS_FacilitiesReply_t)); + frep->present = EIS_FacilitiesReply_PR_data; int nra = freq->choice.data.choice.attributeTypes.list.count; - frep->choice.data.present = FacilitiesDataReply_PR_attributes; + frep->choice.data.present = EIS_FacilitiesDataReply_PR_attributes; frep->choice.data.choice.attributes.list.count = nra; frep->choice.data.choice.attributes.list.size = sizeof(void *) * nra; frep->choice.data.choice.attributes.list.array = malloc(sizeof(void *) * nra); for (int j = 0; j < nra; ++j) { switch (*freq->choice.data.choice.attributeTypes.list.array[j]) { - case FacilitiesAttributeType_stationId: - frep->choice.data.choice.attributes.list.array[j] = calloc(1, sizeof(FacilitiesAttribute_t)); + case EIS_FacilitiesAttributeType_stationId: + frep->choice.data.choice.attributes.list.array[j] = calloc(1, sizeof(EIS_FacilitiesAttribute_t)); frep->choice.data.choice.attributes.list.array[j]->data.size = 8; frep->choice.data.choice.attributes.list.array[j]->data.buf = malloc(8); pthread_mutex_lock(&facilities.id.lock); @@ -536,7 +535,7 @@ int facilities_request_attribute_types(void *responder, FacilitiesRequest_t *fre } } uint8_t frep_oer[256]; - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesReply, NULL, frep, frep_oer, 256); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_FacilitiesReply, NULL, frep, frep_oer, 256); if (enc.encoded == -1) { log_error("failed encoding FReply (%s)", enc.failed_type->name); facilities_request_result_rejected(responder); @@ -547,18 +546,18 @@ int facilities_request_attribute_types(void *responder, FacilitiesRequest_t *fre itss_0send(responder, frep_oer, enc.encoded); cleanup: - ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, frep); + ASN_STRUCT_FREE(asn_DEF_EIS_FacilitiesReply, frep); return rv; } -int facilities_request_loaded_protected_zones(void *responder, FacilitiesRequest_t *freq) { +int facilities_request_loaded_protected_zones(void *responder, EIS_FacilitiesRequest_t *freq) { int rv = 0; - FacilitiesReply_t *frep = calloc(1, sizeof(FacilitiesReply_t)); + EIS_FacilitiesReply_t *frep = calloc(1, sizeof(EIS_FacilitiesReply_t)); - frep->present = FacilitiesReply_PR_data; - frep->choice.data.present = FacilitiesDataReply_PR_protectedCommunicationZones; + frep->present = EIS_FacilitiesReply_PR_data; + frep->choice.data.present = EIS_FacilitiesDataReply_PR_protectedCommunicationZones; pthread_mutex_lock(&facilities.lightship.lock); @@ -568,15 +567,15 @@ int facilities_request_loaded_protected_zones(void *responder, FacilitiesRequest uint8_t buf[256]; for (int z = 0; z < facilities.lightship.protected_zones.pz_len; ++z) { - frep->choice.data.choice.protectedCommunicationZones.list.array[z] = calloc(1, sizeof(ProtectedCommunicationZone_t)); - asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_ProtectedCommunicationZone, NULL, facilities.lightship.protected_zones.pz[z], buf, 256); - uper_decode_complete(NULL, &asn_DEF_ProtectedCommunicationZone, (void **)&frep->choice.data.choice.protectedCommunicationZones.list.array[z], buf, (enc.encoded + 7) / 8); + frep->choice.data.choice.protectedCommunicationZones.list.array[z] = calloc(1, sizeof(EIS_ProtectedCommunicationZone_t)); + asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_EIS_ProtectedCommunicationZone, NULL, facilities.lightship.protected_zones.pz[z], buf, 256); + uper_decode_complete(NULL, &asn_DEF_EIS_ProtectedCommunicationZone, (void **)&frep->choice.data.choice.protectedCommunicationZones.list.array[z], buf, (enc.encoded + 7) / 8); } pthread_mutex_unlock(&facilities.lightship.lock); uint8_t frep_oer[1024]; - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesReply, NULL, frep, frep_oer, 1024); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_FacilitiesReply, NULL, frep, frep_oer, 1024); if (enc.encoded == -1) { log_error("failed encoding FDResult (%s)", enc.failed_type->name); facilities_request_result_rejected(responder); @@ -587,12 +586,12 @@ int facilities_request_loaded_protected_zones(void *responder, FacilitiesRequest itss_0send(responder, frep_oer, enc.encoded); cleanup: - ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, frep); + ASN_STRUCT_FREE(asn_DEF_EIS_FacilitiesReply, frep); return rv; } -int facilities_request_chaininfo_set(void *responder, ChainInformationSet_t *cis) { +int facilities_request_chaininfo_set(void *responder, EIS_ChainInformationSet_t *cis) { int rv = 0; pthread_mutex_lock(&facilities.coordination.lock); @@ -607,13 +606,13 @@ int facilities_request_chaininfo_set(void *responder, ChainInformationSet_t *cis // TODO region 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_chainInfoSet; - frep->choice.data.choice.chainInfoSet = FacilitiesResultCode_accepted; + EIS_FacilitiesReply_t *frep = calloc(1, sizeof(EIS_FacilitiesReply_t)); + frep->present = EIS_FacilitiesReply_PR_data; + frep->choice.data.present = EIS_FacilitiesDataReply_PR_chainInfoSet; + frep->choice.data.choice.chainInfoSet = EIS_FacilitiesResultCode_accepted; uint8_t frep_oer[1024]; - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesReply, NULL, frep, frep_oer, 1024); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_FacilitiesReply, NULL, frep, frep_oer, 1024); if (enc.encoded == -1) { log_error("failed encoding FDResult (%s)", enc.failed_type->name); facilities_request_result_rejected(responder); @@ -624,17 +623,17 @@ int facilities_request_chaininfo_set(void *responder, ChainInformationSet_t *cis itss_0send(responder, frep_oer, enc.encoded); cleanup: - ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, frep); + ASN_STRUCT_FREE(asn_DEF_EIS_FacilitiesReply, frep); return rv; } -static int networking_packet_indication_btp(NetworkingPacketIndication_t* npi, void** security_socket) { +static int networking_packet_indication_btp(EIS_NetworkingPacketIndication_t* npi, void** security_socket) { int rv = 0; - BTPPacketIndication_t* bpi = &npi->transport.choice.btp; + EIS_BTPPacketIndication_t* bpi = &npi->transport.choice.btp; - FacilitiesIndication_t *fi = NULL; + EIS_FacilitiesIndication_t *fi = NULL; asn_TYPE_descriptor_t *its_msg_descriptor = NULL; void *its_msg = NULL; @@ -650,58 +649,58 @@ static int networking_packet_indication_btp(NetworkingPacketIndication_t* npi, v // Parse message switch (bpi->destinationPort) { - case Port_cam: - its_msg_descriptor = &asn_DEF_CAM; - its_msg = calloc(1, sizeof(CAM_t)); - its_msg_type = messageID_cam; + case EIS_Port_cam: + its_msg_descriptor = &asn_DEF_EI1_CAM; + its_msg = calloc(1, sizeof(EI1_CAM_t)); + its_msg_type = EI1_messageID_cam; break; - case Port_denm: - its_msg_descriptor = &asn_DEF_DENM; - its_msg = calloc(1, sizeof(DENM_t)); - its_msg_type = messageID_denm; + case EIS_Port_denm: + its_msg_descriptor = &asn_DEF_EI1_DENM; + its_msg = calloc(1, sizeof(EI1_DENM_t)); + its_msg_type = EI1_messageID_denm; break; - case Port_ivim: - its_msg_descriptor = &asn_DEF_IVIM; - its_msg = calloc(1, sizeof(IVIM_t)); - its_msg_type = messageID_ivim; + case EIS_Port_ivim: + its_msg_descriptor = &asn_DEF_EI1_IVIM; + its_msg = calloc(1, sizeof(EI1_IVIM_t)); + its_msg_type = EI1_messageID_ivim; break; - case Port_cpm: - its_msg_descriptor = &asn_DEF_CPM; - its_msg = calloc(1, sizeof(CPM_t)); + case EIS_Port_cpm: + its_msg_descriptor = &asn_DEF_EI1_CPM; + its_msg = calloc(1, sizeof(EI1_CPM_t)); its_msg_type = 14; break; - case Port_saem: - its_msg_descriptor = &asn_DEF_SAEM; - its_msg = calloc(1, sizeof(SAEM_t)); - its_msg_type = messageID_saem; + case EIS_Port_saem: + its_msg_descriptor = &asn_DEF_EI1_SAEM; + its_msg = calloc(1, sizeof(EI1_SAEM_t)); + its_msg_type = EI1_messageID_saem; break; case 7011: /* tolling */ - its_msg_descriptor = &asn_DEF_TPM; - its_msg = calloc(1, sizeof(TPM_t)); + its_msg_descriptor = &asn_DEF_EI1_TPM; + its_msg = calloc(1, sizeof(EI1_TPM_t)); its_msg_type = 117; break; case 2043: /* maneuvers */ - its_msg_descriptor = &asn_DEF_VCM; - its_msg = calloc(1, sizeof(VCM_t)); + its_msg_descriptor = &asn_DEF_EI1_VCM; + its_msg = calloc(1, sizeof(EI1_VCM_t)); its_msg_type = 43; break; - case Port_poi: /* EVCSNM */ - its_msg_descriptor = &asn_DEF_EvcsnPdu; - its_msg = calloc(1, sizeof(EvcsnPdu_t)); - its_msg_type = messageID_evcsn; + case EIS_Port_poi: /* EVCSNM */ + its_msg_descriptor = &asn_DEF_EI1_EvcsnPdu; + its_msg = calloc(1, sizeof(EI1_EvcsnPdu_t)); + its_msg_type = EI1_messageID_evcsn; break; - case Port_evrsr: /* EVRSRM */ - its_msg_descriptor = &asn_DEF_EV_RSR; - its_msg = calloc(1, sizeof(EV_RSR_t)); - its_msg_type = messageID_evcsn; + case EIS_Port_evrsr: /* EVRSRM */ + its_msg_descriptor = &asn_DEF_EI1_EV_RSR; + its_msg = calloc(1, sizeof(EI1_EV_RSR_t)); + its_msg_type = EI1_messageID_evcsn; break; default: @@ -722,7 +721,7 @@ static int networking_packet_indication_btp(NetworkingPacketIndication_t* npi, v uint8_t* neighbour_cert = NULL; switch (npi->network.present) { - case NetworkingPacketRequestNW_PR_gn: + case EIS_NetworkingPacketRequestNW_PR_gn: if (npi->network.choice.gn.securityPermissions) { ssp = npi->network.choice.gn.securityPermissions->ssp.buf; ssp_len = npi->network.choice.gn.securityPermissions->ssp.size; @@ -731,7 +730,7 @@ static int networking_packet_indication_btp(NetworkingPacketIndication_t* npi, v neighbour_cert = npi->network.choice.gn.securityNeighbour->buf; } break; - case NetworkingPacketRequestNW_PR_gn6a: + case EIS_NetworkingPacketRequestNW_PR_gn6a: if (npi->network.choice.gn6a.gn.securityPermissions) { ssp = npi->network.choice.gn6a.gn.securityPermissions->ssp.buf; ssp_len = npi->network.choice.gn6a.gn.securityPermissions->ssp.size; @@ -746,7 +745,7 @@ static int networking_packet_indication_btp(NetworkingPacketIndication_t* npi, v // Manage message switch (bpi->destinationPort) { - case Port_cam: + case EIS_Port_cam: switch (check_cam(bpi, its_msg, ssp, ssp_len)) { case CAM_OK: fwd = true; @@ -758,7 +757,7 @@ static int networking_packet_indication_btp(NetworkingPacketIndication_t* npi, v } break; - case Port_denm: + case EIS_Port_denm: #ifdef DEBUG uint8_t *xml_denm = malloc(32768); asn_enc_rval_t rve = xer_encode_to_buffer(xml_denm, 32768, 0x02, &asn_DEF_DENM, its_msg); @@ -782,7 +781,7 @@ static int networking_packet_indication_btp(NetworkingPacketIndication_t* npi, v } break; - case Port_ivim: + case EIS_Port_ivim: stored = true; switch (service_eval(SERVICE_IVI, its_msg, &id, ssp, ssp_len)) { case SERVICE_NEW: @@ -801,7 +800,7 @@ static int networking_packet_indication_btp(NetworkingPacketIndication_t* npi, v } break; - case Port_saem: + case EIS_Port_saem: switch (saem_check(its_msg, neighbour_cert)) { case SAEM_NEW: fwd = true; @@ -831,18 +830,18 @@ static int networking_packet_indication_btp(NetworkingPacketIndication_t* npi, v } break; - case Port_poi: + case EIS_Port_poi: if (facilities.evm_args.activate) { evcsnm_check(its_msg); fwd = true; } break; - case Port_evrsr: + case EIS_Port_evrsr: if (facilities.evm_args.activate) { evrsrm_check(its_msg); fwd = true; - EV_RSR_t *evrsr_request = (EV_RSR_t *)its_msg; + EI1_EV_RSR_t *evrsr_request = (EI1_EV_RSR_t *)its_msg; evrsrm_recv(evrsr_request); } break; @@ -882,29 +881,29 @@ cleanup: if (its_msg && !stored) { ASN_STRUCT_FREE(*its_msg_descriptor, its_msg); } - ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi); + ASN_STRUCT_FREE(asn_DEF_EIS_FacilitiesIndication, fi); return rv; } -static int networking_packet_indication_tcp(NetworkingPacketIndication_t* npi, void** security_socket) { +static int networking_packet_indication_tcp(EIS_NetworkingPacketIndication_t* npi, void** security_socket) { int rv = 0; - TCPPacketIndication_t* tpi = &npi->transport.choice.tcp; + EIS_TCPPacketIndication_t* tpi = &npi->transport.choice.tcp; uint16_t buf_len = 2048; uint8_t buf[buf_len]; - SecurityRequest_t* sreq = NULL; - SecurityReply_t* srep = NULL; - NetworkingRequest_t* nr = NULL; - FacilitiesIndication_t* fi = NULL; + EIS_SecurityRequest_t* sreq = NULL; + EIS_SecurityReply_t* srep = NULL; + EIS_NetworkingRequest_t* nr = NULL; + EIS_FacilitiesIndication_t* fi = NULL; void* its_msg = NULL; - sreq = calloc(1, sizeof(SecurityRequest_t)); - sreq->present = SecurityRequest_PR_tlsRecv; + sreq = calloc(1, sizeof(EIS_SecurityRequest_t)); + sreq->present = EIS_SecurityRequest_PR_tlsRecv; sreq->choice.tlsRecv.data.size = npi->data.size; sreq->choice.tlsRecv.data.buf = malloc(npi->data.size); memcpy(sreq->choice.tlsRecv.data.buf, npi->data.buf, npi->data.size); @@ -924,27 +923,27 @@ static int networking_packet_indication_tcp(NetworkingPacketIndication_t* npi, v uint8_t b_tx[2048], b_rx[2048]; b_tx[0] = 4; - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, b_tx + 1, 2047); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityRequest, NULL, sreq, b_tx + 1, 2047); log_debug("->[security] SecurityRequest.tlsRecv (%ldB)", enc.encoded + 1); itss_0send(*security_socket, b_tx, enc.encoded + 1); int32_t rl = itss_0recv_rt(security_socket, b_rx, 2048, b_tx, enc.encoded + 1, 1000); log_debug("<-[security] SecurityReply.tlsRecv (%dB)", rl); - if (oer_decode(NULL, &asn_DEF_SecurityReply, (void **)&srep, b_rx, rl).code) { + if (oer_decode(NULL, &asn_DEF_EIS_SecurityReply, (void **)&srep, b_rx, rl).code) { log_error("SecurityReply.tlsRecv decode failure"); rv = 1; goto cleanup; } - if (srep->returnCode == SecurityReplyReturnCode_rejected) { + if (srep->returnCode == EIS_SecurityReplyReturnCode_rejected) { log_error("SecurityReply.tlsRecv rejected"); - SecurityRequest_t *sREQ = calloc(1, sizeof(SecurityRequest_t)); - sREQ->present = SecurityRequest_PR_tlsShutdown; + EIS_SecurityRequest_t *sREQ = calloc(1, sizeof(EIS_SecurityRequest_t)); + sREQ->present = EIS_SecurityRequest_PR_tlsShutdown; sREQ->choice.tlsShutdown.connId = id; b_tx[0] = 4; - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sREQ, b_tx + 1, 2047); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityRequest, NULL, sREQ, b_tx + 1, 2047); log_debug("->[security] SecurityRequest.tlsShutdown (%ldB)", enc.encoded + 1); itss_0send(*security_socket, b_tx, enc.encoded + 1); int32_t rl = itss_0recv_rt(security_socket, b_rx, 2048, b_tx, enc.encoded + 1, 1000); @@ -958,17 +957,17 @@ static int networking_packet_indication_tcp(NetworkingPacketIndication_t* npi, v // Forward to [networking] if (srep->data->choice.tlsRecv.state != 1) { - nr = calloc(1, sizeof(NetworkingRequest_t)); - nr->present = NetworkingRequest_PR_packet; - NetworkingPacketRequest_t* npr = &nr->choice.packet; - npr->transport.present = NetworkingPacketRequestTP_PR_tcp; - npr->network.present = NetworkingPacketRequestNW_PR_gn; + nr = calloc(1, sizeof(EIS_NetworkingRequest_t)); + nr->present = EIS_NetworkingRequest_PR_packet; + EIS_NetworkingPacketRequest_t* npr = &nr->choice.packet; + npr->transport.present = EIS_NetworkingPacketRequestTP_PR_tcp; + npr->network.present = EIS_NetworkingPacketRequestNW_PR_gn; npr->data.size = srep->data->choice.tlsRecv.data.size; npr->data.buf = malloc(srep->data->choice.tlsRecv.data.size); memcpy(npr->data.buf, srep->data->choice.tlsRecv.data.buf, srep->data->choice.tlsRecv.data.size); - npr->transport.present = NetworkingPacketRequestTP_PR_tcp; + npr->transport.present = EIS_NetworkingPacketRequestTP_PR_tcp; npr->transport.choice.tcp.sourcePort = tpi->destinationPort; npr->transport.choice.tcp.destinationPort = tpi->sourcePort; @@ -981,8 +980,8 @@ static int networking_packet_indication_tcp(NetworkingPacketIndication_t* npi, v if (facilities.tolling.protocol.p == TOLLING_PROTOCOL_TLS_GN || (facilities.tolling.protocol.p == TOLLING_PROTOCOL_TLS_SHS && tlsc->nmsg < 2)) { - npr->network.present = NetworkingPacketRequestNW_PR_gn6a; - npr->network.choice.gn6a.gn.packetTransportType = PacketTransportType_shb; + npr->network.present = EIS_NetworkingPacketRequestNW_PR_gn6a; + npr->network.choice.gn6a.gn.packetTransportType = EIS_PacketTransportType_shb; npr->network.choice.gn6a.gn.destinationAddress.buf = calloc(1, 6); npr->network.choice.gn6a.gn.destinationAddress.size = 6; npr->network.choice.gn6a.gn.securityProfile.encrypt = false; @@ -992,7 +991,7 @@ static int networking_packet_indication_tcp(NetworkingPacketIndication_t* npi, v npr->network.choice.gn6a.ip.destinationAddress.size = 16; memcpy(npr->network.choice.gn6a.ip.destinationAddress.buf, tpi->sourceAddress->buf, 16); } else { - npr->network.present = NetworkingPacketRequestNW_PR_ip; + npr->network.present = EIS_NetworkingPacketRequestNW_PR_ip; npr->network.choice.ip.destinationAddress.buf = malloc(16); npr->network.choice.ip.destinationAddress.size = 16; memcpy(npr->network.choice.ip.destinationAddress.buf, tpi->sourceAddress->buf, 16); @@ -1001,7 +1000,7 @@ static int networking_packet_indication_tcp(NetworkingPacketIndication_t* npi, v npr->id = itss_id(npr->data.buf, npr->data.size); buf[0] = 4; - enc = oer_encode_to_buffer(&asn_DEF_NetworkingRequest, NULL, nr, buf + 1, buf_len - 1); + enc = oer_encode_to_buffer(&asn_DEF_EIS_NetworkingRequest, NULL, nr, buf + 1, buf_len - 1); if (enc.encoded == -1) { log_error("NR encoding error (%s)", enc.failed_type->name); rv = 1; @@ -1011,7 +1010,7 @@ static int networking_packet_indication_tcp(NetworkingPacketIndication_t* npi, v itss_queue_send(facilities.tx_queue, buf, enc.encoded + 1, ITSS_NETWORKING, npr->id, "NR.packet.tcp"); } else { if (facilities.tolling.enabled && srep->data->choice.tlsRecv.data.size) { - asn_dec_rval_t dec = uper_decode_complete(NULL, &asn_DEF_TPM, (void **)&its_msg, srep->data->choice.tlsRecv.data.buf, srep->data->choice.tlsRecv.data.size); + asn_dec_rval_t dec = uper_decode_complete(NULL, &asn_DEF_EI1_TPM, (void **)&its_msg, srep->data->choice.tlsRecv.data.buf, srep->data->choice.tlsRecv.data.size); if (dec.code) { log_debug("<- invalid TPM received"); rv = 1; @@ -1021,9 +1020,9 @@ static int networking_packet_indication_tcp(NetworkingPacketIndication_t* npi, v tpm_recv(its_msg, security_socket, NULL, tpi->sourceAddress->buf); // Fwd to [applications] - fi = calloc(1, sizeof(FacilitiesIndication_t)); - fi->present = FacilitiesIndication_PR_message; - FacilitiesMessageIndication_t *fmi = &fi->choice.message; + fi = calloc(1, sizeof(EIS_FacilitiesIndication_t)); + fi->present = EIS_FacilitiesIndication_PR_message; + EIS_FacilitiesMessageIndication_t *fmi = &fi->choice.message; fmi->id = id; @@ -1035,7 +1034,7 @@ static int networking_packet_indication_tcp(NetworkingPacketIndication_t* npi, v uint8_t buffer[ITSS_SDU_MAX_LEN]; buffer[0] = 4; // Facilities - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesIndication, NULL, fi, buffer + 1, ITSS_SDU_MAX_LEN - 1); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_FacilitiesIndication, NULL, fi, buffer + 1, ITSS_SDU_MAX_LEN - 1); itss_queue_send(facilities.tx_queue, buffer, enc.encoded + 1, ITSS_APPLICATIONS, id, "FI.message"); @@ -1065,23 +1064,23 @@ static int networking_packet_indication_tcp(NetworkingPacketIndication_t* npi, v } cleanup: - ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi); - ASN_STRUCT_FREE(asn_DEF_SecurityRequest, sreq); - ASN_STRUCT_FREE(asn_DEF_SecurityReply, srep); - ASN_STRUCT_FREE(asn_DEF_NetworkingRequest, nr); + ASN_STRUCT_FREE(asn_DEF_EIS_FacilitiesIndication, fi); + ASN_STRUCT_FREE(asn_DEF_EIS_SecurityRequest, sreq); + ASN_STRUCT_FREE(asn_DEF_EIS_SecurityReply, srep); + ASN_STRUCT_FREE(asn_DEF_EIS_NetworkingRequest, nr); return rv; } -int networking_packet_indication(NetworkingPacketIndication_t* npi, void** security_socket) { +int networking_packet_indication(EIS_NetworkingPacketIndication_t* npi, void** security_socket) { int rv = 0; switch (npi->transport.present) { - case NetworkingPacketIndicationTP_PR_btp: + case EIS_NetworkingPacketIndicationTP_PR_btp: networking_packet_indication_btp(npi, security_socket); break; - case NetworkingPacketIndicationTP_PR_tcp: + case EIS_NetworkingPacketIndicationTP_PR_tcp: networking_packet_indication_tcp(npi, security_socket); break; default: diff --git a/src/requests.h b/src/requests.h index c257d57..dff416b 100644 --- a/src/requests.h +++ b/src/requests.h @@ -2,18 +2,18 @@ #define FACILITIES_REQUESTS #include "facilities.h" -#include -#include +#include +#include int facilities_request_result_accepted(void* responder); int facilities_request_result_rejected(void* responder); -int facilities_request_single_message(void* responder, FacilitiesMessageRequest_t* frm); -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_single_message(void* responder, EIS_FacilitiesMessageRequest_t* frm); +int facilities_request_active_episodes(void* responder, EIS_FacilitiesRequest_t* fr); +int facilities_request_attribute_types(void* responder, EIS_FacilitiesRequest_t* fr); +int facilities_request_loaded_protected_zones(void* responder, EIS_FacilitiesRequest_t* fr); +int facilities_request_chaininfo_set(void* responder, EIS_ChainInformationSet_t* cis); -int networking_packet_indication(NetworkingPacketIndication_t* npi, void** security_socket); +int networking_packet_indication(EIS_NetworkingPacketIndication_t* npi, void** security_socket); #endif diff --git a/src/saem.c b/src/saem.c index 023a943..d163e02 100644 --- a/src/saem.c +++ b/src/saem.c @@ -8,21 +8,21 @@ #include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include -SAEM_CODE_R saem_check(SAEM_t* saem, uint8_t* neighbour) { +SAEM_CODE_R saem_check(EI1_SAEM_t* saem, uint8_t* neighbour) { int rv = 0; bulletin_t* bulletin = &facilities.bulletin; - if (saem->header.messageID != messageID_saem) { + if (saem->header.messageID != EI1_messageID_saem) { return SAEM_INVALID_HEADER_MESSAGE_ID; } @@ -38,7 +38,7 @@ SAEM_CODE_R saem_check(SAEM_t* saem, uint8_t* neighbour) { if (saem->sam.body.serviceInfos) { for (int i = 0; i < saem->sam.body.serviceInfos->list.count; ++i) { - ServiceInfo_t* si = saem->sam.body.serviceInfos->list.array[i]; + EI1_ServiceInfo_t* si = saem->sam.body.serviceInfos->list.array[i]; uint16_t its_aid = si->serviceID; @@ -48,7 +48,7 @@ SAEM_CODE_R saem_check(SAEM_t* saem, uint8_t* neighbour) { for (int e = 0; e < si->chOptions.extensions->list.count; ++e) { switch (si->chOptions.extensions->list.array[e]->present) { - case ServiceInfoExt_PR_providerServiceContext: + case EI1_ServiceInfoExt_PR_providerServiceContext: bulletin->to_consume[bulletin->to_consume_len]->info.context_len = si->chOptions.extensions->list.array[e]->choice.providerServiceContext.size; bulletin->to_consume[bulletin->to_consume_len]->info.context = malloc(si->chOptions.extensions->list.array[e]->choice.providerServiceContext.size); memcpy(bulletin->to_consume[bulletin->to_consume_len]->info.context, @@ -57,7 +57,7 @@ SAEM_CODE_R saem_check(SAEM_t* saem, uint8_t* neighbour) { ); break; - case ServiceInfoExt_PR_applicationDataSAM: + case EI1_ServiceInfoExt_PR_applicationDataSAM: bulletin->to_consume[bulletin->to_consume_len]->info.data_len = si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.size; bulletin->to_consume[bulletin->to_consume_len]->info.data = malloc(si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.size); memcpy(bulletin->to_consume[bulletin->to_consume_len]->info.data, @@ -68,10 +68,10 @@ SAEM_CODE_R saem_check(SAEM_t* saem, uint8_t* neighbour) { switch (its_aid) { case SAID_ETC: if (facilities.station_type != 15 && facilities.tolling.infos.length < TOLLING_INFOS_MAX_LENGTH) { - TollingPaymentInfo_t* tpi = NULL; + EI1_TollingPaymentInfo_t* tpi = NULL; asn_dec_rval_t dec = uper_decode_complete( NULL, - &asn_DEF_TollingPaymentInfo, + &asn_DEF_EI1_TollingPaymentInfo, (void**) &tpi, si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.buf, si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.size @@ -93,7 +93,7 @@ SAEM_CODE_R saem_check(SAEM_t* saem, uint8_t* neighbour) { new_announcement = true; } } else { - ASN_STRUCT_FREE(asn_DEF_TollingPaymentInfo, tpi); + ASN_STRUCT_FREE(asn_DEF_EI1_TollingPaymentInfo, tpi); } } break; @@ -104,11 +104,11 @@ SAEM_CODE_R saem_check(SAEM_t* saem, uint8_t* neighbour) { } break; - case ServiceInfoExt_PR_addressIPv6: + case EI1_ServiceInfoExt_PR_addressIPv6: memcpy(bulletin->to_consume[bulletin->to_consume_len]->endpoint.ipv6_addr, si->chOptions.extensions->list.array[e]->choice.addressIPv6.buf, 16); break; - case ServiceInfoExt_PR_servicePort: + case EI1_ServiceInfoExt_PR_servicePort: bulletin->to_consume[bulletin->to_consume_len]->endpoint.port = si->chOptions.extensions->list.array[e]->choice.servicePort; break; @@ -175,11 +175,11 @@ static int mk_saem(uint8_t* b_saem, uint32_t* b_saem_len) { asn_enc_rval_t enc; - SAEM_t* saem = calloc(1, sizeof(SAEM_t)); + EI1_SAEM_t* saem = calloc(1, sizeof(EI1_SAEM_t)); /* header */ saem->header.protocolVersion = 1; - saem->header.messageID = messageID_saem; + saem->header.messageID = EI1_messageID_saem; pthread_mutex_lock(&facilities.id.lock); saem->header.stationID = facilities.id.station_id; @@ -187,7 +187,7 @@ static int mk_saem(uint8_t* b_saem, uint32_t* b_saem_len) { /* sam */ saem->sam.version = 0; - saem->sam.body.serviceInfos = calloc(1, sizeof(ServiceInfos_t)); + saem->sam.body.serviceInfos = calloc(1, sizeof(EI1_ServiceInfos_t)); saem->sam.body.serviceInfos->list.count = facilities.tolling.infos.length; // + facilities.evcsn.infos.length; saem->sam.body.serviceInfos->list.size = facilities.tolling.infos.length * sizeof(void*); // + facilities.evcsn.infos.length * sizeof(void*); saem->sam.body.serviceInfos->list.array = malloc(facilities.tolling.infos.length * sizeof(void*)); // + facilities.evcsn.infos.length * sizeof(void*); @@ -195,12 +195,12 @@ static int mk_saem(uint8_t* b_saem, uint32_t* b_saem_len) { uint8_t buf[1024]; int i; for (i = 0; i < facilities.tolling.infos.length; ++i) { - saem->sam.body.serviceInfos->list.array[i] = calloc(1, sizeof(ServiceInfo_t)); + saem->sam.body.serviceInfos->list.array[i] = calloc(1, sizeof(EI1_ServiceInfo_t)); saem->sam.body.serviceInfos->list.array[i]->serviceID = SAID_ETC; - saem->sam.body.serviceInfos->list.array[i]->chOptions.extensions = calloc(1, sizeof(ServiceInfoExts_t)); + saem->sam.body.serviceInfos->list.array[i]->chOptions.extensions = calloc(1, sizeof(EI1_ServiceInfoExts_t)); - ServiceInfoExts_t* exts = saem->sam.body.serviceInfos->list.array[i]->chOptions.extensions; + EI1_ServiceInfoExts_t* exts = saem->sam.body.serviceInfos->list.array[i]->chOptions.extensions; switch (facilities.tolling.protocol.p) { case TOLLING_PROTOCOL_GN_SPKI: @@ -209,23 +209,23 @@ static int mk_saem(uint8_t* b_saem, uint32_t* b_saem_len) { exts->list.size = 3 * sizeof(void*); exts->list.array = malloc(3 * sizeof(void*)); - exts->list.array[0] = calloc(1, sizeof(ServiceInfoExt_t)); - exts->list.array[0]->present = ServiceInfoExt_PR_providerServiceContext; + exts->list.array[0] = calloc(1, sizeof(EI1_ServiceInfoExt_t)); + exts->list.array[0]->present = EI1_ServiceInfoExt_PR_providerServiceContext; char ctx_s[] = "tolling:gn"; exts->list.array[0]->choice.providerServiceContext.size = strlen(ctx_s); exts->list.array[0]->choice.providerServiceContext.buf = malloc(strlen(ctx_s)); memcpy(exts->list.array[0]->choice.providerServiceContext.buf, ctx_s, strlen(ctx_s)); - exts->list.array[1] = calloc(1, sizeof(ServiceInfoExt_t)); - exts->list.array[1]->present = ServiceInfoExt_PR_servicePort; + exts->list.array[1] = calloc(1, sizeof(EI1_ServiceInfoExt_t)); + exts->list.array[1]->present = EI1_ServiceInfoExt_PR_servicePort; exts->list.array[1]->choice.servicePort = 7011; - exts->list.array[2] = calloc(1, sizeof(ServiceInfoExt_t)); - exts->list.array[2]->present = ServiceInfoExt_PR_applicationDataSAM; + exts->list.array[2] = calloc(1, sizeof(EI1_ServiceInfoExt_t)); + exts->list.array[2]->present = EI1_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[i]->asn, exts->list.array[2]->choice.applicationDataSAM.buf, 1024); + enc = uper_encode_to_buffer(&asn_DEF_EI1_TollingPaymentInfo, NULL, facilities.tolling.infos.z[i]->asn, exts->list.array[2]->choice.applicationDataSAM.buf, 1024); if (enc.encoded == -1) { log_error("[sa] failure to encode TollingPaymentInfo (%s)", enc.failed_type->name); rv = 1; @@ -242,28 +242,28 @@ static int mk_saem(uint8_t* b_saem, uint32_t* b_saem_len) { exts->list.size = 4 * sizeof(void*); exts->list.array = malloc(4 * sizeof(void*)); - exts->list.array[0] = calloc(1, sizeof(ServiceInfoExt_t)); - exts->list.array[0]->present = ServiceInfoExt_PR_providerServiceContext; + exts->list.array[0] = calloc(1, sizeof(EI1_ServiceInfoExt_t)); + exts->list.array[0]->present = EI1_ServiceInfoExt_PR_providerServiceContext; char ctx_t[] = "tolling:tls"; exts->list.array[0]->choice.providerServiceContext.size = strlen(ctx_t); exts->list.array[0]->choice.providerServiceContext.buf = malloc(strlen(ctx_t)); memcpy(exts->list.array[0]->choice.providerServiceContext.buf, ctx_t, strlen(ctx_t)); - exts->list.array[1] = calloc(1, sizeof(ServiceInfoExt_t)); - exts->list.array[1]->present = ServiceInfoExt_PR_addressIPv6; + exts->list.array[1] = calloc(1, sizeof(EI1_ServiceInfoExt_t)); + exts->list.array[1]->present = EI1_ServiceInfoExt_PR_addressIPv6; exts->list.array[1]->choice.addressIPv6.size = 16; exts->list.array[1]->choice.addressIPv6.buf = malloc(16); memcpy(exts->list.array[1]->choice.addressIPv6.buf, facilities.id.ipv6_addr, 16); - exts->list.array[2] = calloc(1, sizeof(ServiceInfoExt_t)); - exts->list.array[2]->present = ServiceInfoExt_PR_servicePort; + exts->list.array[2] = calloc(1, sizeof(EI1_ServiceInfoExt_t)); + exts->list.array[2]->present = EI1_ServiceInfoExt_PR_servicePort; exts->list.array[2]->choice.servicePort = 7011; - exts->list.array[3] = calloc(1, sizeof(ServiceInfoExt_t)); - exts->list.array[3]->present = ServiceInfoExt_PR_applicationDataSAM; + exts->list.array[3] = calloc(1, sizeof(EI1_ServiceInfoExt_t)); + exts->list.array[3]->present = EI1_ServiceInfoExt_PR_applicationDataSAM; exts->list.array[3]->choice.applicationDataSAM.buf = malloc(1024); - enc = uper_encode_to_buffer(&asn_DEF_TollingPaymentInfo, NULL, facilities.tolling.infos.z[i]->asn, exts->list.array[3]->choice.applicationDataSAM.buf, 1024); + enc = uper_encode_to_buffer(&asn_DEF_EI1_TollingPaymentInfo, NULL, facilities.tolling.infos.z[i]->asn, exts->list.array[3]->choice.applicationDataSAM.buf, 1024); if (enc.encoded == -1) { log_error("[sa] failure to encode TollingPaymentInfo (%s)", enc.failed_type->name); rv = 1; @@ -276,14 +276,14 @@ static int mk_saem(uint8_t* b_saem, uint32_t* b_saem_len) { } for (int j = 0; j < 0/* + facilities.evcsn.infos.length */; ++j) { - saem->sam.body.serviceInfos->list.array[i+j] = calloc(1, sizeof(ServiceInfo_t)); + saem->sam.body.serviceInfos->list.array[i+j] = calloc(1, sizeof(EI1_ServiceInfo_t)); saem->sam.body.serviceInfos->list.array[i+j]->serviceID = SAID_EVCSN; // TODO } pthread_mutex_unlock(&facilities.id.lock); - enc = asn_encode_to_buffer(NULL, ATS_UNALIGNED_CANONICAL_PER, &asn_DEF_SAEM, saem, b_saem, *b_saem_len); + enc = asn_encode_to_buffer(NULL, ATS_UNALIGNED_CANONICAL_PER, &asn_DEF_EI1_SAEM, saem, b_saem, *b_saem_len); if (enc.encoded == -1) { log_error("[sa] failure to encode SAEM (%s)", enc.failed_type->name); rv = 1; @@ -292,7 +292,7 @@ static int mk_saem(uint8_t* b_saem, uint32_t* b_saem_len) { *b_saem_len = enc.encoded; cleanup: - ASN_STRUCT_FREE(asn_DEF_SAEM, saem); + ASN_STRUCT_FREE(asn_DEF_EI1_SAEM, saem); return rv; } @@ -301,23 +301,23 @@ void *sa_service() { pthread_mutex_init(&facilities.bulletin.lock, NULL); - NetworkingRequest_t* nr = calloc(1, sizeof(NetworkingRequest_t)); - nr->present = NetworkingRequest_PR_packet; - NetworkingPacketRequest_t* npr = &nr->choice.packet; + EIS_NetworkingRequest_t* nr = calloc(1, sizeof(EIS_NetworkingRequest_t)); + nr->present = EIS_NetworkingRequest_PR_packet; + EIS_NetworkingPacketRequest_t* npr = &nr->choice.packet; - npr->network.present = NetworkingPacketRequestNW_PR_gn; + npr->network.present = EIS_NetworkingPacketRequestNW_PR_gn; npr->network.choice.gn.trafficClass = 2; npr->network.choice.gn.destinationAddress.buf = malloc(6); for (int i = 0; i < 6; ++i) { npr->network.choice.gn.destinationAddress.buf[i] = 0xff; } npr->network.choice.gn.destinationAddress.size = 6; - npr->network.choice.gn.packetTransportType = PacketTransportType_shb; + npr->network.choice.gn.packetTransportType = EIS_PacketTransportType_shb; npr->network.choice.gn.securityProfile.sign = true; - npr->transport.present = NetworkingPacketRequestTP_PR_btp; - npr->transport.choice.btp.btpType = BTPType_btpB; - npr->transport.choice.btp.destinationPort = Port_saem; + npr->transport.present = EIS_NetworkingPacketRequestTP_PR_btp; + npr->transport.choice.btp.btpType = EIS_BTPType_btpB; + npr->transport.choice.btp.destinationPort = EIS_Port_saem; bulletin_t* bulletin = &facilities.bulletin; @@ -343,7 +343,7 @@ void *sa_service() { npr->id = itss_id(npr->data.buf, npr->data.size); - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_NetworkingRequest, NULL, nr, tr_oer+1, 1023); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_NetworkingRequest, NULL, nr, tr_oer+1, 1023); if (enc.encoded == -1) { log_error("encoding TR for SAEM failed"); continue; @@ -354,7 +354,7 @@ void *sa_service() { pthread_mutex_lock(&facilities.id.lock); uint32_t station_id = facilities.id.station_id; pthread_mutex_unlock(&facilities.id.lock); - itss_db_add(facilities.logging.dbms, station_id, npr->id, true, messageID_saem, NULL, npr->data.buf, npr->data.size); + itss_db_add(facilities.logging.dbms, station_id, npr->id, true, EI1_messageID_saem, NULL, npr->data.buf, npr->data.size); } if (facilities.logging.recorder) { uint16_t buffer_len = 2048; @@ -438,7 +438,7 @@ void *sa_service() { usleep(sleep_ms*1000); } - ASN_STRUCT_FREE(asn_DEF_NetworkingRequest, nr); + ASN_STRUCT_FREE(asn_DEF_EIS_NetworkingRequest, nr); itss_0close(security_socket); diff --git a/src/saem.h b/src/saem.h index bf2220a..57e1f8d 100644 --- a/src/saem.h +++ b/src/saem.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #define MAX_ANNOUNCEMENTS_LEN 32 @@ -69,7 +69,7 @@ void bulletin_init(); * @param neighbour The certificate used by the neighbour, for encryption * @return SAEM_CODE */ -SAEM_CODE_R saem_check(SAEM_t* saem, uint8_t* neighbour); +SAEM_CODE_R saem_check(EI1_SAEM_t* saem, uint8_t* neighbour); /** * The main SA function, run as a thread diff --git a/src/tpm.c b/src/tpm.c index 0ff7c49..cad2d54 100644 --- a/src/tpm.c +++ b/src/tpm.c @@ -3,11 +3,11 @@ #include "edm.h" #include -#include -#include -#include +#include +#include +#include #include -#include +#include #include #include #include @@ -77,11 +77,11 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui return rv; } - TPM_t* tpm = NULL; - NetworkingRequest_t* nr = NULL; - SecurityRequest_t* sreq = NULL; - SecurityReply_t* srep = NULL; - FacilitiesIndication_t* fi = NULL; + EI1_TPM_t* tpm = NULL; + EIS_NetworkingRequest_t* nr = NULL; + EIS_SecurityRequest_t* sreq = NULL; + EIS_SecurityReply_t* srep = NULL; + EIS_FacilitiesIndication_t* fi = NULL; pthread_mutex_lock(&tolling->lock); @@ -92,7 +92,7 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui log_info("[tolling] issuing toll %s.request | client: %lld nonce: %lld", tts(info->asn->tollType), tolling->station.obu.client_id, tolling->station.obu.nonce); // TPM - tpm = calloc(1, sizeof(TPM_t)); + tpm = calloc(1, sizeof(EI1_TPM_t)); tpm->header.messageID = 117; tpm->header.protocolVersion = 0; @@ -100,7 +100,7 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui tpm->header.stationID = facilities.id.station_id; pthread_mutex_unlock(&facilities.id.lock); - tpm->tpm = calloc(1, sizeof(TollingPaymentMessage_t)); + tpm->tpm = calloc(1, sizeof(EI1_TollingPaymentMessage_t)); // timestamp asn_ulong2INTEGER(&tpm->tpm->timestamp, itss_time_get()); @@ -128,55 +128,55 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui tpm->tpm->referencePosition.positionConfidenceEllipse.semiMajorOrientation = 900; } - tpm->tpm->tollingType = calloc(1, sizeof(TollingType_t)); - TollingType_t* type = tpm->tpm->tollingType; + tpm->tpm->tollingType = calloc(1, sizeof(EI1_TollingType_t)); + EI1_TollingType_t* type = tpm->tpm->tollingType; switch (info->asn->tollType) { - case TollType_entry: + case EI1_TollType_entry: if (tolling->station.obu.toll_type != -1 && !tolling->station.obu.rt_on) { log_error("[tolling] trying to issue entry.request but current tolling state is %s - resetting", tts(tolling->station.obu.toll_type)); tolling->station.obu.toll_type = -1; tolling->station.obu.active = false; - ASN_STRUCT_FREE(asn_DEF_TPM, tolling->station.obu.entry_proof); + ASN_STRUCT_FREE(asn_DEF_EI1_TPM, tolling->station.obu.entry_proof); tolling->station.obu.entry_proof = NULL; } - type->present = TollingType_PR_entry; - type->choice.entry.present = TollingEntry_PR_request; + type->present = EI1_TollingType_PR_entry; + type->choice.entry.present = EI1_TollingEntry_PR_request; type->choice.entry.choice.request.clientId = tolling->station.obu.client_id; type->choice.entry.choice.request.infoId = info->asn->id; type->choice.entry.choice.request.transactionNonce = tolling->station.obu.nonce; break; - case TollType_exit: - type->present = TollingType_PR_exit; - type->choice.exit = calloc(1, sizeof(TollingExit_t)); - type->choice.exit->present = TollingExit_PR_request; - type->choice.exit->choice.request = calloc(1, sizeof(TollingExitRequest_t)); + case EI1_TollType_exit: + type->present = EI1_TollingType_PR_exit; + type->choice.exit = calloc(1, sizeof(EI1_TollingExit_t)); + type->choice.exit->present = EI1_TollingExit_PR_request; + type->choice.exit->choice.request = calloc(1, sizeof(EI1_TollingExitRequest_t)); type->choice.exit->choice.request->clientId = tolling->station.obu.client_id; type->choice.exit->choice.request->infoId = info->asn->id; type->choice.exit->choice.request->transactionNonce = tolling->station.obu.nonce; - if (tolling->station.obu.toll_type != TollingType_PR_entry && + if (tolling->station.obu.toll_type != EI1_TollingType_PR_entry && !tolling->station.obu.rt_on) { log_error("[tolling] trying to issue exit.request but current tolling state is %s - will not provide entry proof", tts(tolling->station.obu.toll_type)); } else { uint8_t b_tep[1024]; - asn_enc_rval_t e_tep = uper_encode_to_buffer(&asn_DEF_TPM, NULL, tolling->station.obu.entry_proof, b_tep, 1024); + asn_enc_rval_t e_tep = uper_encode_to_buffer(&asn_DEF_EI1_TPM, NULL, tolling->station.obu.entry_proof, b_tep, 1024); if (e_tep.encoded == -1) { log_error("[tolling] error encoding TPM entry proof (%s)", e_tep.failed_type->name); - ASN_STRUCT_FREE(asn_DEF_TPM, tolling->station.obu.entry_proof); + ASN_STRUCT_FREE(asn_DEF_EI1_TPM, tolling->station.obu.entry_proof); tolling->station.obu.entry_proof = NULL; rv = 1; goto cleanup; } - uper_decode_complete(NULL, &asn_DEF_TPM, (void**) &type->choice.exit->choice.request->entryProof, b_tep, (e_tep.encoded+7)/8); + uper_decode_complete(NULL, &asn_DEF_EI1_TPM, (void**) &type->choice.exit->choice.request->entryProof, b_tep, (e_tep.encoded+7)/8); } break; - case TollType_single: + case EI1_TollType_single: if (tolling->station.obu.toll_type != -1 && !tolling->station.obu.rt_on) { log_error("[tolling] trying to issue single.request but current tolling state is %s", @@ -184,8 +184,8 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui rv = 1; goto cleanup; } - type->present = TollingType_PR_single; - type->choice.single.present = TollingSingle_PR_request; + type->present = EI1_TollingType_PR_single; + type->choice.single.present = EI1_TollingSingle_PR_request; type->choice.single.choice.request.clientId = tolling->station.obu.client_id; type->choice.single.choice.request.infoId = info->asn->id; type->choice.single.choice.request.transactionNonce = tolling->station.obu.nonce; @@ -196,7 +196,7 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui // Encode TollingPaymentMessage - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TollingPaymentMessage, NULL, tpm->tpm, buf1, buf_len); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EI1_TollingPaymentMessage, NULL, tpm->tpm, buf1, buf_len); if (enc.encoded == -1) { log_error("[tolling] error encoding TollingPaymentMessage (%s)", enc.failed_type->name); rv = 1; @@ -205,32 +205,32 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui if (tolling->protocol.p == TOLLING_PROTOCOL_GN_DPKI) { // Sign - sreq = calloc(1, sizeof(SecurityRequest_t)); - sreq->present = SecurityRequest_PR_sign; + sreq = calloc(1, sizeof(EIS_SecurityRequest_t)); + sreq->present = EIS_SecurityRequest_PR_sign; sreq->choice.sign.data.size = enc.encoded; sreq->choice.sign.data.buf = malloc(enc.encoded); memcpy(sreq->choice.sign.data.buf, buf1, enc.encoded); buf2[0] = 4; - enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf2+1, 2047); + enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityRequest, NULL, sreq, buf2+1, 2047); log_debug("->[security] SecurityRequest.sign (%ldB)", enc.encoded+1); itss_0send(*security_socket, buf2, enc.encoded+1); int32_t rl = itss_0recv_rt(security_socket, buf1, buf_len, buf2, enc.encoded+1, 1000); log_debug("<-[security] SecurityReply.sign (%dB)", rl); - if (oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf1, rl).code) { + if (oer_decode(NULL, &asn_DEF_EIS_SecurityReply, (void**) &srep, buf1, rl).code) { log_error("SecurityReply.sign decode failure"); rv = 1; goto cleanup; } - if (srep->returnCode == SecurityReplyReturnCode_rejected) { + if (srep->returnCode == EIS_SecurityReplyReturnCode_rejected) { log_error("SecurityReply.sign rejected"); rv = 1; goto cleanup; } - tpm->tpmSignature = calloc(1, sizeof(TpmSignature_t)); + tpm->tpmSignature = calloc(1, sizeof(EI1_TpmSignature_t)); tpm->tpmSignature->r.size = srep->data->choice.sign.r.size; tpm->tpmSignature->r.buf = malloc(srep->data->choice.sign.r.size); memcpy(tpm->tpmSignature->r.buf, srep->data->choice.sign.r.buf, srep->data->choice.sign.r.size); @@ -244,7 +244,7 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui } // Encode TPM - enc = uper_encode_to_buffer(&asn_DEF_TPM, NULL, tpm, tpm_uper, buf_len); + enc = uper_encode_to_buffer(&asn_DEF_EI1_TPM, NULL, tpm, tpm_uper, buf_len); if (enc.encoded == -1) { log_error("[tolling] error encoding TPM.request (%s)", enc.failed_type->name); rv = 1; @@ -257,17 +257,17 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui } // [transport] request (TR) - nr = calloc(1, sizeof(NetworkingRequest_t)); - nr->present = NetworkingRequest_PR_packet; - NetworkingPacketRequest_t* npr = &nr->choice.packet; + nr = calloc(1, sizeof(EIS_NetworkingRequest_t)); + nr->present = EIS_NetworkingRequest_PR_packet; + EIS_NetworkingPacketRequest_t* npr = &nr->choice.packet; uint64_t id = 0; switch (facilities.tolling.protocol.p) { case TOLLING_PROTOCOL_GN_SPKI: case TOLLING_PROTOCOL_GN_DPKI: - npr->transport.present = NetworkingPacketRequestTP_PR_btp; - npr->network.present = NetworkingPacketRequestNW_PR_gn; + npr->transport.present = EIS_NetworkingPacketRequestTP_PR_btp; + npr->network.present = EIS_NetworkingPacketRequestNW_PR_gn; npr->network.choice.gn.securityProfile.encrypt = true; npr->network.choice.gn.securityProfile.sign = true; @@ -285,21 +285,21 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui id = npr->id; npr->transport.choice.btp.destinationPort = 7011; - npr->transport.choice.btp.btpType = BTPType_btpB; + npr->transport.choice.btp.btpType = EIS_BTPType_btpB; npr->network.choice.gn.destinationAddress.buf = malloc(6); for (int i = 0; i < 6; ++i) { npr->network.choice.gn.destinationAddress.buf[i] = 0xff; } npr->network.choice.gn.destinationAddress.size = 6; npr->network.choice.gn.trafficClass = 2; - npr->network.choice.gn.packetTransportType = PacketTransportType_shb; + npr->network.choice.gn.packetTransportType = EIS_PacketTransportType_shb; break; case TOLLING_PROTOCOL_TLS: case TOLLING_PROTOCOL_TLS_GN: case TOLLING_PROTOCOL_TLS_SHS: - sreq = calloc(1, sizeof(SecurityRequest_t)); - sreq->present = SecurityRequest_PR_tlsSend; + sreq = calloc(1, sizeof(EIS_SecurityRequest_t)); + sreq->present = EIS_SecurityRequest_PR_tlsSend; sreq->choice.tlsSend.data.buf = malloc(tpm_uper_len); sreq->choice.tlsSend.data.size = tpm_uper_len; memcpy(sreq->choice.tlsSend.data.buf, tpm_uper, tpm_uper_len); @@ -315,7 +315,7 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui sreq->choice.tlsSend.connId = id; buf1[0] = 4; - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf1+1, buf_len-1); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityRequest, NULL, sreq, buf1+1, buf_len-1); log_debug("[tolling]-> SecurityRequest.tlsSend ->[security] | size:%ldB", enc.encoded); itss_0send(*security_socket, buf1, enc.encoded+1); @@ -327,20 +327,20 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui } log_debug("[tolling]<- SecurityReply.tlsSend <-[security] | size:%dB", rc); - SecurityReply_t* srep = NULL; - asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf2, buf_len); + EIS_SecurityReply_t* srep = NULL; + asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_EIS_SecurityReply, (void**) &srep, buf2, buf_len); if (dec.code || - srep->returnCode != SecurityReplyReturnCode_accepted || + srep->returnCode != EIS_SecurityReplyReturnCode_accepted || !srep->data || - srep->data->present != SecurityReplyData_PR_tlsSend) { + srep->data->present != EIS_SecurityReplyData_PR_tlsSend) { log_error("[tolling]<- SecurityReply.tlsSend rejected"); rv = 1; goto cleanup; } // TR TCP - npr->transport.present = NetworkingPacketRequestTP_PR_tcp; + npr->transport.present = EIS_NetworkingPacketRequestTP_PR_tcp; npr->id = id; @@ -357,8 +357,8 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui if (tolling->protocol.p == TOLLING_PROTOCOL_TLS_GN || tolling->protocol.p == TOLLING_PROTOCOL_TLS_SHS) { - npr->network.present = NetworkingPacketRequestNW_PR_gn6a; - npr->network.choice.gn6a.gn.packetTransportType = PacketTransportType_shb; + npr->network.present = EIS_NetworkingPacketRequestNW_PR_gn6a; + npr->network.choice.gn6a.gn.packetTransportType = EIS_PacketTransportType_shb; npr->network.choice.gn6a.gn.destinationAddress.buf = calloc(1, 6); npr->network.choice.gn6a.gn.destinationAddress.size = 6; npr->network.choice.gn6a.gn.securityProfile.encrypt = false; @@ -368,7 +368,7 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui npr->network.choice.gn6a.ip.destinationAddress.size = 16; memcpy(npr->network.choice.gn6a.ip.destinationAddress.buf, dst_addr, 16); } else { - npr->network.present = NetworkingPacketRequestNW_PR_ip; + npr->network.present = EIS_NetworkingPacketRequestNW_PR_ip; npr->network.choice.ip.destinationAddress.buf = malloc(16); npr->network.choice.ip.destinationAddress.size = 16; memcpy(npr->network.choice.ip.destinationAddress.buf, dst_addr, 16); @@ -378,7 +378,7 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui // encode TR buf1[0] = 4; - enc = oer_encode_to_buffer(&asn_DEF_NetworkingRequest, NULL, nr, buf1+1, buf_len-1); + enc = oer_encode_to_buffer(&asn_DEF_EIS_NetworkingRequest, NULL, nr, buf1+1, buf_len-1); if (enc.encoded == -1) { log_error("[tolling] error encoding TR TPM.request (%s)", enc.failed_type->name); rv = 1; @@ -406,14 +406,14 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui } // send to [applications] - fi = calloc(1, sizeof(FacilitiesIndication_t)); - fi->present = FacilitiesIndication_PR_message; + fi = calloc(1, sizeof(EIS_FacilitiesIndication_t)); + fi->present = EIS_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, buf1+1, buf_len-1); + enc = oer_encode_to_buffer(&asn_DEF_EIS_FacilitiesIndication, NULL, fi, buf1+1, buf_len-1); if (enc.encoded == -1) { log_error("[tolling] error encoding FI TPM.request (%s)", enc.failed_type->name); rv = 1; @@ -440,16 +440,16 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui cleanup: pthread_mutex_unlock(&tolling->lock); - ASN_STRUCT_FREE(asn_DEF_TPM, tpm); - ASN_STRUCT_FREE(asn_DEF_NetworkingRequest, nr); - ASN_STRUCT_FREE(asn_DEF_SecurityRequest, sreq); - ASN_STRUCT_FREE(asn_DEF_SecurityReply, srep); - ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi); + ASN_STRUCT_FREE(asn_DEF_EI1_TPM, tpm); + ASN_STRUCT_FREE(asn_DEF_EIS_NetworkingRequest, nr); + ASN_STRUCT_FREE(asn_DEF_EIS_SecurityRequest, sreq); + ASN_STRUCT_FREE(asn_DEF_EIS_SecurityReply, srep); + ASN_STRUCT_FREE(asn_DEF_EIS_FacilitiesIndication, fi); return rv; } -static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neighbour, uint8_t* src_addr) { +static int rsu_handle_recv(EI1_TPM_t* tpm_rx, void** security_socket, uint8_t* neighbour, uint8_t* src_addr) { int rv = 0; @@ -458,21 +458,21 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh return 1; } - TollingType_t* type_rx = tpm_rx->tpm->tollingType; + EI1_TollingType_t* type_rx = tpm_rx->tpm->tollingType; uint64_t client_id, nonce, info_id; const uint32_t buf_len = 1800; uint8_t buf1[buf_len], buf2[buf_len]; uint8_t tpm_uper[buf_len]; - SecurityRequest_t* sreq = NULL; - SecurityReply_t* srep = NULL; + EIS_SecurityRequest_t* sreq = NULL; + EIS_SecurityReply_t* srep = NULL; tolling_t* tolling = &facilities.tolling; switch (type_rx->present) { - case TollingType_PR_entry: - if (type_rx->choice.entry.present != TollingEntry_PR_request) { + case EI1_TollingType_PR_entry: + if (type_rx->choice.entry.present != EI1_TollingEntry_PR_request) { log_error("[tolling] received TPM.entry is not request"); return 1; } @@ -481,9 +481,9 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh info_id = type_rx->choice.entry.choice.request.infoId; break; - case TollingType_PR_exit: + case EI1_TollingType_PR_exit: if (!type_rx->choice.exit || - type_rx->choice.exit->present != TollingExit_PR_request || + type_rx->choice.exit->present != EI1_TollingExit_PR_request || !type_rx->choice.exit->choice.request ) { log_error("[tolling] received TPM.exit is not request"); @@ -502,7 +502,7 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh return 1; } - TPM_t* ep = (TPM_t*) type_rx->choice.exit->choice.request->entryProof; + EI1_TPM_t* ep = (EI1_TPM_t*) type_rx->choice.exit->choice.request->entryProof; if (!ep->tpmSignature) { log_error("[tolling] received TPM.exit.request.entryProof does not contain signature");; @@ -510,7 +510,7 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh } // Encode TollingPaymentMessage - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TollingPaymentMessage, NULL, ep->tpm, buf1, buf_len); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EI1_TollingPaymentMessage, NULL, ep->tpm, buf1, buf_len); if (enc.encoded == -1) { log_error("[tolling] error encoding TollingPaymentMessage (%s)", enc.failed_type->name); rv = 1; @@ -518,8 +518,8 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh } // Verify - sreq = calloc(1, sizeof(SecurityRequest_t)); - sreq->present = SecurityRequest_PR_verify; + sreq = calloc(1, sizeof(EIS_SecurityRequest_t)); + sreq->present = EIS_SecurityRequest_PR_verify; // message sreq->choice.verify.message.size = enc.encoded; sreq->choice.verify.message.buf = malloc(enc.encoded); @@ -541,39 +541,39 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh sreq->choice.verify.type = ep->tpmSignature->type; buf1[0] = 4; - enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf1+1, buf_len-1); + enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityRequest, NULL, sreq, buf1+1, buf_len-1); log_debug("->[security] SecurityRequest.verify (%ldB)", enc.encoded+1); itss_0send(*security_socket, buf1, enc.encoded+1); int32_t rl = itss_0recv_rt(security_socket, buf2, buf_len, buf1, enc.encoded+1, 1000); log_debug("<-[security] SecurityReply.verify (%dB)", rl); - if (oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf2, rl).code) { + if (oer_decode(NULL, &asn_DEF_EIS_SecurityReply, (void**) &srep, buf2, rl).code) { log_error("SecurityReply.verify decode failure"); rv = 1; goto cleanup; } - if (srep->returnCode == SecurityReplyReturnCode_rejected) { + if (srep->returnCode == EIS_SecurityReplyReturnCode_rejected) { log_error("SecurityReply.verify rejected"); rv = 1; goto cleanup; } - if (srep->data->choice.verify.report != SecurityVerifyConfirmCode_success) { + if (srep->data->choice.verify.report != EIS_SecurityVerifyConfirmCode_success) { log_debug("entry proof signature verify failed"); rv = 1; goto cleanup; } - ASN_STRUCT_FREE(asn_DEF_SecurityRequest, sreq); - ASN_STRUCT_FREE(asn_DEF_SecurityReply, srep); + ASN_STRUCT_FREE(asn_DEF_EIS_SecurityRequest, sreq); + ASN_STRUCT_FREE(asn_DEF_EIS_SecurityReply, srep); sreq = NULL; srep = NULL; } break; - case TollingType_PR_single: - if (type_rx->choice.single.present != TollingSingle_PR_request) { + case EI1_TollingType_PR_single: + if (type_rx->choice.single.present != EI1_TollingSingle_PR_request) { log_error("[tolling] received TPM.single is not request"); return 1; } @@ -613,9 +613,9 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh asn_enc_rval_t enc; - NetworkingRequest_t* nr = NULL; - FacilitiesIndication_t* fi = NULL; - TPM_t* tpm = NULL; + EIS_NetworkingRequest_t* nr = NULL; + EIS_FacilitiesIndication_t* fi = NULL; + EI1_TPM_t* tpm = NULL; if (tolling->protocol.p == TOLLING_PROTOCOL_GN_DPKI) { @@ -626,7 +626,7 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh } // Encode TollingPaymentMessage - enc = oer_encode_to_buffer(&asn_DEF_TollingPaymentMessage, NULL, tpm_rx->tpm, buf1, buf_len); + enc = oer_encode_to_buffer(&asn_DEF_EI1_TollingPaymentMessage, NULL, tpm_rx->tpm, buf1, buf_len); if (enc.encoded == -1) { log_error("[tolling] error encoding TollingPaymentMessage (%s)", enc.failed_type->name); rv = 1; @@ -634,8 +634,8 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh } // Verify - sreq = calloc(1, sizeof(SecurityRequest_t)); - sreq->present = SecurityRequest_PR_verify; + sreq = calloc(1, sizeof(EIS_SecurityRequest_t)); + sreq->present = EIS_SecurityRequest_PR_verify; // message sreq->choice.verify.message.size = enc.encoded; sreq->choice.verify.message.buf = malloc(enc.encoded); @@ -657,39 +657,39 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh sreq->choice.verify.type = tpm_rx->tpmSignature->type; buf1[0] = 4; - enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf1+1, buf_len-1); + enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityRequest, NULL, sreq, buf1+1, buf_len-1); log_debug("->[security] SecurityRequest.verify (%ldB)", enc.encoded+1); itss_0send(*security_socket, buf1, enc.encoded+1); int32_t rl = itss_0recv_rt(security_socket, buf2, buf_len, buf1, enc.encoded+1, 1000); log_debug("<-[security] SecurityReply.verify (%dB)", rl); - if (oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf2, rl).code) { + if (oer_decode(NULL, &asn_DEF_EIS_SecurityReply, (void**) &srep, buf2, rl).code) { log_error("SecurityReply.verify decode failure"); rv = 1; goto cleanup; } - if (srep->returnCode == SecurityReplyReturnCode_rejected) { + if (srep->returnCode == EIS_SecurityReplyReturnCode_rejected) { log_error("SecurityReply.verify rejected"); rv = 1; goto cleanup; } - if (srep->data->choice.verify.report != SecurityVerifyConfirmCode_success) { + if (srep->data->choice.verify.report != EIS_SecurityVerifyConfirmCode_success) { log_debug("signature verify failed"); rv = 1; goto cleanup; } - ASN_STRUCT_FREE(asn_DEF_SecurityRequest, sreq); - ASN_STRUCT_FREE(asn_DEF_SecurityReply, srep); + ASN_STRUCT_FREE(asn_DEF_EIS_SecurityRequest, sreq); + ASN_STRUCT_FREE(asn_DEF_EIS_SecurityReply, srep); sreq = NULL; srep = NULL; } // TPM - tpm = calloc(1, sizeof(TPM_t)); + tpm = calloc(1, sizeof(EI1_TPM_t)); tpm->header.messageID = 117; tpm->header.protocolVersion = 0; @@ -697,7 +697,7 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh tpm->header.stationID = facilities.id.station_id; pthread_mutex_unlock(&facilities.id.lock); - tpm->tpm = calloc(1, sizeof(TollingPaymentMessage_t)); + tpm->tpm = calloc(1, sizeof(EI1_TollingPaymentMessage_t)); // timestamp asn_ulong2INTEGER(&tpm->tpm->timestamp, itss_time_get()); @@ -760,38 +760,38 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh client->accepted = -1; } - uint8_t confirmation_code = TollingConfirmationCode_rejected; + uint8_t confirmation_code = EI1_TollingConfirmationCode_rejected; if (itss_time_get() > client->ts + TOLLING_PAYMENT_MIN_PERIOD_MS || client->accepted == -1) { - confirmation_code = TollingConfirmationCode_accepted; + confirmation_code = EI1_TollingConfirmationCode_accepted; client->accepted = true; } else if (client->accepted && itss_time_get() < client->ts + TOLLING_PAYMENT_MIN_PERIOD_MS) { - confirmation_code = TollingConfirmationCode_alreadyAccepted; + confirmation_code = EI1_TollingConfirmationCode_alreadyAccepted; } - tpm->tpm->tollingType = calloc(1, sizeof(TollingType_t)); + tpm->tpm->tollingType = calloc(1, sizeof(EI1_TollingType_t)); switch (tpm_rx->tpm->tollingType->present) { - case TollingType_PR_entry: - tpm->tpm->tollingType->present = TollingType_PR_entry; - tpm->tpm->tollingType->choice.entry.present = TollingEntry_PR_reply; + case EI1_TollingType_PR_entry: + tpm->tpm->tollingType->present = EI1_TollingType_PR_entry; + tpm->tpm->tollingType->choice.entry.present = EI1_TollingEntry_PR_reply; tpm->tpm->tollingType->choice.entry.choice.reply.clientId = client_id; tpm->tpm->tollingType->choice.entry.choice.reply.infoId = info_id; tpm->tpm->tollingType->choice.entry.choice.reply.transactionNonce = nonce; tpm->tpm->tollingType->choice.entry.choice.reply.confirmationCode = confirmation_code; break; - case TollingType_PR_exit: - tpm->tpm->tollingType->present = TollingType_PR_exit; - tpm->tpm->tollingType->choice.exit = calloc(1, sizeof(TollingExit_t)); - tpm->tpm->tollingType->choice.exit->present = TollingExit_PR_reply; + case EI1_TollingType_PR_exit: + tpm->tpm->tollingType->present = EI1_TollingType_PR_exit; + tpm->tpm->tollingType->choice.exit = calloc(1, sizeof(EI1_TollingExit_t)); + tpm->tpm->tollingType->choice.exit->present = EI1_TollingExit_PR_reply; tpm->tpm->tollingType->choice.exit->choice.reply.clientId = client_id; tpm->tpm->tollingType->choice.exit->choice.reply.infoId = info_id; tpm->tpm->tollingType->choice.exit->choice.reply.transactionNonce = nonce; tpm->tpm->tollingType->choice.exit->choice.reply.confirmationCode = confirmation_code; break; - case TollingType_PR_single: - tpm->tpm->tollingType->present = TollingType_PR_single; - tpm->tpm->tollingType->choice.single.present = TollingSingle_PR_reply; + case EI1_TollingType_PR_single: + tpm->tpm->tollingType->present = EI1_TollingType_PR_single; + tpm->tpm->tollingType->choice.single.present = EI1_TollingSingle_PR_reply; tpm->tpm->tollingType->choice.single.choice.reply.clientId = client_id; tpm->tpm->tollingType->choice.single.choice.reply.infoId = info_id; tpm->tpm->tollingType->choice.single.choice.reply.transactionNonce = nonce; @@ -804,7 +804,7 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh // TODO check clientId // Encode TollingPaymentMessage - enc = oer_encode_to_buffer(&asn_DEF_TollingPaymentMessage, NULL, tpm->tpm, buf1, buf_len); + enc = oer_encode_to_buffer(&asn_DEF_EI1_TollingPaymentMessage, NULL, tpm->tpm, buf1, buf_len); if (enc.encoded == -1) { log_error("[tolling] error encoding TollingPaymentMessage (%s)", enc.failed_type->name); rv = 1; @@ -813,14 +813,14 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh if (tolling->protocol.p == TOLLING_PROTOCOL_GN_DPKI) { // Sign - sreq = calloc(1, sizeof(SecurityRequest_t)); - sreq->present = SecurityRequest_PR_sign; + sreq = calloc(1, sizeof(EIS_SecurityRequest_t)); + sreq->present = EIS_SecurityRequest_PR_sign; sreq->choice.sign.data.size = enc.encoded; sreq->choice.sign.data.buf = malloc(enc.encoded); memcpy(sreq->choice.sign.data.buf, buf1, enc.encoded); buf1[0] = 4; - enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf1+1, buf_len-1); + enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityRequest, NULL, sreq, buf1+1, buf_len-1); if (enc.encoded == -1) { log_error("[tolling] error encoding SecurityRequest (%s)", enc.failed_type->name); rv = 1; @@ -831,19 +831,19 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh int rc = itss_0recv_rt(security_socket, buf2, buf_len, buf1, enc.encoded+1, 1000); log_debug("<-[security] SecurityReply.sign (%dB)", rc); - if (oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf2, rc).code) { + if (oer_decode(NULL, &asn_DEF_EIS_SecurityReply, (void**) &srep, buf2, rc).code) { log_error("SecurityReply.sign decode failure"); rv = 1; goto cleanup; } - if (srep->returnCode == SecurityReplyReturnCode_rejected) { + if (srep->returnCode == EIS_SecurityReplyReturnCode_rejected) { log_error("SecurityReply.sign rejected"); rv = 1; goto cleanup; } - tpm->tpmSignature = calloc(1, sizeof(TpmSignature_t)); + tpm->tpmSignature = calloc(1, sizeof(EI1_TpmSignature_t)); tpm->tpmSignature->r.size = srep->data->choice.sign.r.size; tpm->tpmSignature->r.buf = malloc(srep->data->choice.sign.r.size); memcpy(tpm->tpmSignature->r.buf, srep->data->choice.sign.r.buf, srep->data->choice.sign.r.size); @@ -855,14 +855,14 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh memcpy(tpm->tpmSignature->signer.buf, srep->data->choice.sign.signer.buf, srep->data->choice.sign.signer.size); tpm->tpmSignature->type = srep->data->choice.sign.type; - ASN_STRUCT_FREE(asn_DEF_SecurityRequest, sreq); - ASN_STRUCT_FREE(asn_DEF_SecurityReply, srep); + ASN_STRUCT_FREE(asn_DEF_EIS_SecurityRequest, sreq); + ASN_STRUCT_FREE(asn_DEF_EIS_SecurityReply, srep); sreq = NULL; srep = NULL; } // encode TPM - enc = uper_encode_to_buffer(&asn_DEF_TPM, NULL, tpm, tpm_uper, buf_len); + enc = uper_encode_to_buffer(&asn_DEF_EI1_TPM, NULL, tpm, tpm_uper, buf_len); if (enc.encoded == -1) { log_error("[tolling] error encoding TPM.reply (%s)", enc.failed_type->name); rv = 1; @@ -876,16 +876,16 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh uint64_t id = 0; - nr = calloc(1, sizeof(NetworkingRequest_t)); - nr->present = NetworkingRequest_PR_packet; - NetworkingPacketRequest_t* npr = &nr->choice.packet; + nr = calloc(1, sizeof(EIS_NetworkingRequest_t)); + nr->present = EIS_NetworkingRequest_PR_packet; + EIS_NetworkingPacketRequest_t* npr = &nr->choice.packet; // [transport] request (TR) switch (tolling->protocol.p) { case TOLLING_PROTOCOL_GN_SPKI: case TOLLING_PROTOCOL_GN_DPKI: - npr->transport.present = NetworkingPacketRequestTP_PR_btp; - npr->network.present = NetworkingPacketRequestNW_PR_gn; + npr->transport.present = EIS_NetworkingPacketRequestTP_PR_btp; + npr->network.present = EIS_NetworkingPacketRequestNW_PR_gn; npr->network.choice.gn.securityProfile.encrypt = true; npr->network.choice.gn.securityProfile.sign = true; @@ -903,14 +903,14 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh id = npr->id; npr->transport.choice.btp.destinationPort = 7011; - npr->transport.choice.btp.btpType = BTPType_btpB; + npr->transport.choice.btp.btpType = EIS_BTPType_btpB; npr->network.choice.gn.destinationAddress.buf = malloc(6); for (int i = 0; i < 6; ++i) { npr->network.choice.gn.destinationAddress.buf[i] = 0xff; } npr->network.choice.gn.destinationAddress.size = 6; npr->network.choice.gn.trafficClass = 2; - npr->network.choice.gn.packetTransportType = PacketTransportType_shb; + npr->network.choice.gn.packetTransportType = EIS_PacketTransportType_shb; if (neighbour) { /* neighbour ID for [security] encryption */ @@ -924,8 +924,8 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh case TOLLING_PROTOCOL_TLS: case TOLLING_PROTOCOL_TLS_GN: case TOLLING_PROTOCOL_TLS_SHS: - sreq = calloc(1, sizeof(SecurityRequest_t)); - sreq->present = SecurityRequest_PR_tlsSend; + sreq = calloc(1, sizeof(EIS_SecurityRequest_t)); + sreq->present = EIS_SecurityRequest_PR_tlsSend; sreq->choice.tlsSend.data.buf = malloc(tpm_uper_len); sreq->choice.tlsSend.data.size = tpm_uper_len; memcpy(sreq->choice.tlsSend.data.buf, tpm_uper, tpm_uper_len); @@ -941,7 +941,7 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh sreq->choice.tlsSend.connId = id; buf1[0] = 4; - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf1+1, buf_len-1); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityRequest, NULL, sreq, buf1+1, buf_len-1); log_debug("[tolling]-> SecurityRequest.tlsSend ->[security] | size:%ldB", enc.encoded); itss_0send(*security_socket, buf1, enc.encoded+1); @@ -953,19 +953,19 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh } log_debug("[tolling]<- SecurityReply.tlsSend <-[security] | size:%dB", rc); - asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf2, rc); + asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_EIS_SecurityReply, (void**) &srep, buf2, rc); if (dec.code || - srep->returnCode != SecurityReplyReturnCode_accepted || + srep->returnCode != EIS_SecurityReplyReturnCode_accepted || !srep->data || - srep->data->present != SecurityReplyData_PR_tlsSend) { + srep->data->present != EIS_SecurityReplyData_PR_tlsSend) { log_error("[tolling]<- SecurityReply.tlsSend rejected"); rv = 1; goto cleanup; } // TR TCP - npr->transport.present = NetworkingPacketRequestTP_PR_tcp; + npr->transport.present = EIS_NetworkingPacketRequestTP_PR_tcp; npr->id = id; @@ -981,8 +981,8 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh memcpy(npr->data.buf, srep->data->choice.tlsSend.data.buf, srep->data->choice.tlsSend.data.size); if (tolling->protocol.p == TOLLING_PROTOCOL_TLS_GN) { - npr->network.present = NetworkingPacketRequestNW_PR_gn6a; - npr->network.choice.gn6a.gn.packetTransportType = PacketTransportType_shb; + npr->network.present = EIS_NetworkingPacketRequestNW_PR_gn6a; + npr->network.choice.gn6a.gn.packetTransportType = EIS_PacketTransportType_shb; npr->network.choice.gn6a.gn.destinationAddress.buf = calloc(1, 6); npr->network.choice.gn6a.gn.destinationAddress.size = 6; npr->network.choice.gn6a.gn.securityProfile.encrypt = false; @@ -992,7 +992,7 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh npr->network.choice.gn6a.ip.destinationAddress.size = 16; memcpy(npr->network.choice.gn6a.ip.destinationAddress.buf, src_addr, 16); } else { - npr->network.present = NetworkingPacketRequestNW_PR_ip; + npr->network.present = EIS_NetworkingPacketRequestNW_PR_ip; npr->network.choice.ip.destinationAddress.buf = malloc(16); npr->network.choice.ip.destinationAddress.size = 16; memcpy(npr->network.choice.ip.destinationAddress.buf, src_addr, 16); @@ -1003,7 +1003,7 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh // encode TR buf1[0] = 4; - enc = oer_encode_to_buffer(&asn_DEF_NetworkingRequest, NULL, nr, buf1+1, buf_len-1); + enc = oer_encode_to_buffer(&asn_DEF_EIS_NetworkingRequest, NULL, nr, buf1+1, buf_len-1); if (enc.encoded == -1) { log_error("[tolling] error encoding TR TPM.reply (%s)", enc.failed_type->name); rv = 1; @@ -1022,14 +1022,14 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh } // send to [applications] - fi = calloc(1, sizeof(FacilitiesIndication_t)); - fi->present = FacilitiesIndication_PR_message; + fi = calloc(1, sizeof(EIS_FacilitiesIndication_t)); + fi->present = EIS_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, buf1+1, buf_len-1); + enc = oer_encode_to_buffer(&asn_DEF_EIS_FacilitiesIndication, NULL, fi, buf1+1, buf_len-1); if (enc.encoded == -1) { log_error("[tolling] error encoding FI TPM.reply (%s)", enc.failed_type->name); rv = 1; @@ -1055,16 +1055,16 @@ static int rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neigh } cleanup: - ASN_STRUCT_FREE(asn_DEF_TPM, tpm); - ASN_STRUCT_FREE(asn_DEF_NetworkingRequest, nr); - ASN_STRUCT_FREE(asn_DEF_SecurityRequest, sreq); - ASN_STRUCT_FREE(asn_DEF_SecurityReply, srep); - ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi); + ASN_STRUCT_FREE(asn_DEF_EI1_TPM, tpm); + ASN_STRUCT_FREE(asn_DEF_EIS_NetworkingRequest, nr); + ASN_STRUCT_FREE(asn_DEF_EIS_SecurityRequest, sreq); + ASN_STRUCT_FREE(asn_DEF_EIS_SecurityReply, srep); + ASN_STRUCT_FREE(asn_DEF_EIS_FacilitiesIndication, fi); return rv; } -static int veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void** security_socket, itss_queue_t* tx_queue, uint8_t* neighbour, uint8_t* src_addr) { +static int veh_handle_recv(tolling_t* tolling, EI1_TPM_t* tpm_rx, void** security_socket, itss_queue_t* tx_queue, uint8_t* neighbour, uint8_t* src_addr) { int rv = 0; if (!tpm_rx->tpm->tollingType) { @@ -1072,27 +1072,27 @@ static int veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void** security_so return 1; } - TollingType_t* type_rx = tpm_rx->tpm->tollingType; + EI1_TollingType_t* type_rx = tpm_rx->tpm->tollingType; uint64_t client_id, nonce, info_id; int confirmation_code; - SecurityRequest_t* sreq = NULL; - SecurityReply_t* srep = NULL; - NetworkingRequest_t* tr = NULL; + EIS_SecurityRequest_t* sreq = NULL; + EIS_SecurityReply_t* srep = NULL; + EIS_NetworkingRequest_t* tr = NULL; const uint16_t buf_len = 2048; uint8_t buf1[buf_len], buf2[buf_len]; switch (type_rx->present) { - case TollingType_PR_entry: - if (type_rx->choice.entry.present != TollingEntry_PR_reply) { + case EI1_TollingType_PR_entry: + if (type_rx->choice.entry.present != EI1_TollingEntry_PR_reply) { log_error("[tolling] received TPM.entry is not reply"); return 1; } - if (tolling->station.obu.toll_type != TollingType_PR_entry) { + if (tolling->station.obu.toll_type != EI1_TollingType_PR_entry) { log_error("[tolling] received TPM toll (%d) is not expected toll type (%d)", - TollingType_PR_entry, tolling->station.obu.toll_type); + EI1_TollingType_PR_entry, tolling->station.obu.toll_type); } client_id = type_rx->choice.entry.choice.reply.clientId; nonce = type_rx->choice.entry.choice.reply.transactionNonce; @@ -1100,24 +1100,24 @@ static int veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void** security_so confirmation_code = type_rx->choice.entry.choice.reply.confirmationCode; uint8_t b_tep[2048]; - asn_enc_rval_t e_tep = uper_encode_to_buffer(&asn_DEF_TPM, NULL, tpm_rx, b_tep, 2048); + asn_enc_rval_t e_tep = uper_encode_to_buffer(&asn_DEF_EI1_TPM, NULL, tpm_rx, b_tep, 2048); if (e_tep.encoded == -1) { log_error("[tolling] error encoding received TPM as entry proof"); return 1; } - uper_decode_complete(NULL, &asn_DEF_TPM, (void**) &tolling->station.obu.entry_proof, b_tep, (e_tep.encoded+7)/8); + uper_decode_complete(NULL, &asn_DEF_EI1_TPM, (void**) &tolling->station.obu.entry_proof, b_tep, (e_tep.encoded+7)/8); break; - case TollingType_PR_exit: + case EI1_TollingType_PR_exit: if (!type_rx->choice.exit || - type_rx->choice.exit->present != TollingExit_PR_reply + type_rx->choice.exit->present != EI1_TollingExit_PR_reply ) { log_error("[tolling] received TPM.exit is not reply"); return 1; } - if (tolling->station.obu.toll_type != TollingType_PR_exit) { + if (tolling->station.obu.toll_type != EI1_TollingType_PR_exit) { log_error("[tolling] received TPM toll (%d) is not expected toll type (%d)", - TollingType_PR_exit, tolling->station.obu.toll_type); + EI1_TollingType_PR_exit, tolling->station.obu.toll_type); return 1; } client_id = type_rx->choice.exit->choice.reply.clientId; @@ -1126,14 +1126,14 @@ static int veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void** security_so confirmation_code = type_rx->choice.exit->choice.reply.confirmationCode; break; - case TollingType_PR_single: - if (type_rx->choice.single.present != TollingSingle_PR_reply) { + case EI1_TollingType_PR_single: + if (type_rx->choice.single.present != EI1_TollingSingle_PR_reply) { log_error("[tolling] received TPM.single is not reply"); return 1; } - if (tolling->station.obu.toll_type != TollingType_PR_single) { + if (tolling->station.obu.toll_type != EI1_TollingType_PR_single) { log_error("[tolling] received TPM type (%d) is not expected toll type (%d)", - TollingType_PR_single, tolling->station.obu.toll_type); + EI1_TollingType_PR_single, tolling->station.obu.toll_type); } client_id = type_rx->choice.single.choice.reply.clientId; nonce = type_rx->choice.single.choice.reply.transactionNonce; @@ -1158,7 +1158,7 @@ static int veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void** security_so // Encode TollingPaymentMessage - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TollingPaymentMessage, NULL, tpm_rx->tpm, buf1, buf_len); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EI1_TollingPaymentMessage, NULL, tpm_rx->tpm, buf1, buf_len); if (enc.encoded == -1) { log_error("[tolling] error encoding TollingPaymentMessage (%s)", enc.failed_type->name); rv = 1; @@ -1168,8 +1168,8 @@ static int veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void** security_so bool accepted = true; if (tolling->protocol.p == TOLLING_PROTOCOL_GN_DPKI) { // Verify - sreq = calloc(1, sizeof(SecurityRequest_t)); - sreq->present = SecurityRequest_PR_verify; + sreq = calloc(1, sizeof(EIS_SecurityRequest_t)); + sreq->present = EIS_SecurityRequest_PR_verify; // message sreq->choice.verify.message.size = enc.encoded; sreq->choice.verify.message.buf = malloc(enc.encoded); @@ -1190,47 +1190,47 @@ static int veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void** security_so sreq->choice.verify.type = tpm_rx->tpmSignature->type; buf1[0] = 4; - enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf1+1, 2047); + enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityRequest, NULL, sreq, buf1+1, 2047); log_debug("->[security] SecurityRequest.verify (%ldB)", enc.encoded+1); itss_0send(*security_socket, buf1, enc.encoded+1); int32_t rl = itss_0recv_rt(security_socket, buf2, buf_len, buf1, enc.encoded+1, 1000); log_debug("<-[security] SecurityReply.verify (%dB)", rl); - if (oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf2, rl).code) { + if (oer_decode(NULL, &asn_DEF_EIS_SecurityReply, (void**) &srep, buf2, rl).code) { log_error("SecurityReply.verify decode failure"); rv = 1; goto cleanup; } - if (srep->returnCode == SecurityReplyReturnCode_rejected) { + if (srep->returnCode == EIS_SecurityReplyReturnCode_rejected) { log_error("SecurityReply.verify rejected"); rv = 1; goto cleanup; } - if (srep->data->choice.verify.report != SecurityVerifyConfirmCode_success) { + if (srep->data->choice.verify.report != EIS_SecurityVerifyConfirmCode_success) { log_debug("signature verify failed"); rv = 1; goto cleanup; } - accepted = confirmation_code == TollingConfirmationCode_accepted || confirmation_code == TollingConfirmationCode_alreadyAccepted; + accepted = confirmation_code == EI1_TollingConfirmationCode_accepted || confirmation_code == EI1_TollingConfirmationCode_alreadyAccepted; } switch (type_rx->present) { - case TollingType_PR_entry: + case EI1_TollingType_PR_entry: log_info("[tolling] received entry.reply | client: %lld nonce: %lld accepted: %s", (long long) tolling->station.obu.client_id, tolling->station.obu.nonce, accepted ? "yes" : "no"); break; - case TollingType_PR_exit: + case EI1_TollingType_PR_exit: log_info("[tolling] received exit.reply | client: %lld nonce: %lld accepted: %s", (long long) tolling->station.obu.client_id, tolling->station.obu.nonce, accepted ? "yes" : "no"); tolling->station.obu.toll_type = -1; tolling->station.obu.active = false; - ASN_STRUCT_FREE(asn_DEF_TPM, tolling->station.obu.entry_proof); + ASN_STRUCT_FREE(asn_DEF_EI1_TPM, tolling->station.obu.entry_proof); tolling->station.obu.entry_proof = NULL; break; - case TollingType_PR_single: + case EI1_TollingType_PR_single: log_info("[tolling] received single.reply | client: %lld nonce: %lld accepted: %s", (long long) tolling->station.obu.client_id, tolling->station.obu.nonce, accepted ? "yes" : "no"); tolling->station.obu.toll_type = -1; tolling->station.obu.active = false; @@ -1246,22 +1246,22 @@ static int veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void** security_so tolling->protocol.p == TOLLING_PROTOCOL_TLS_SHS) { tlsc_t* tlsc = tolling_tlsc_get(src_addr, 7011); if (tlsc) { - sreq = calloc(1, sizeof(SecurityRequest_t)); - sreq->present = SecurityRequest_PR_tlsClose; + sreq = calloc(1, sizeof(EIS_SecurityRequest_t)); + sreq->present = EIS_SecurityRequest_PR_tlsClose; sreq->choice.tlsClose.connId = tlsc->id; buf1[0] = 4; - enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf1+1, buf_len-1); + enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityRequest, NULL, sreq, buf1+1, buf_len-1); log_debug("->[security] SecurityRequest.tlsClose (%ldB)", enc.encoded+1); itss_0send(*security_socket, buf1, enc.encoded+1); int32_t rl = itss_0recv_rt(security_socket, buf2, buf_len, buf1, enc.encoded+1, 1000); log_debug("<-[security] SecurityReply.tlsClose (%dB)", rl); uint32_t id = rand(); - tr = calloc(1, sizeof(NetworkingRequest_t)); - tr->present = NetworkingRequest_PR_data; - tr->choice.data.present = NetworkingDataRequest_PR_tcp; - tr->choice.data.choice.tcp.present = TCPDataRequest_PR_connCloseReq; + tr = calloc(1, sizeof(EIS_NetworkingRequest_t)); + tr->present = EIS_NetworkingRequest_PR_data; + tr->choice.data.present = EIS_NetworkingDataRequest_PR_tcp; + tr->choice.data.choice.tcp.present = EIS_TCPDataRequest_PR_connCloseReq; tr->choice.data.choice.tcp.choice.connCloseReq.closeByPeer = false; tr->choice.data.choice.tcp.choice.connCloseReq.destinationPort = 7011; tr->choice.data.choice.tcp.choice.connCloseReq.destinationAddress.size = 16; @@ -1270,7 +1270,7 @@ static int veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void** security_so tr->choice.data.choice.tcp.choice.connCloseReq.id = id; buf1[0] = 4; - enc = oer_encode_to_buffer(&asn_DEF_NetworkingRequest, NULL, tr, buf1+1, buf_len-1); + enc = oer_encode_to_buffer(&asn_DEF_EIS_NetworkingRequest, NULL, tr, buf1+1, buf_len-1); itss_queue_send(tx_queue, buf1, enc.encoded+1, ITSS_NETWORKING, id, "NR.data.tcp.connClose"); free(tlsc); @@ -1290,13 +1290,13 @@ static int veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void** security_so cleanup: - ASN_STRUCT_FREE(asn_DEF_SecurityRequest, sreq); - ASN_STRUCT_FREE(asn_DEF_SecurityReply, srep); + ASN_STRUCT_FREE(asn_DEF_EIS_SecurityRequest, sreq); + ASN_STRUCT_FREE(asn_DEF_EIS_SecurityReply, srep); return rv; } -int tpm_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neighbour, uint8_t* src_addr) { +int tpm_recv(EI1_TPM_t* tpm_rx, void** security_socket, uint8_t* neighbour, uint8_t* src_addr) { tolling_t* tolling = &facilities.tolling; @@ -1319,16 +1319,16 @@ int tpm_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neighbour, uint8_t* switch (tpm_rx->tpm->tollingType->present) { // Entry - case TollingType_PR_entry: + case EI1_TollingType_PR_entry: switch (tpm_rx->tpm->tollingType->choice.entry.present) { - case TollingSingle_PR_request: + case EI1_TollingSingle_PR_request: if (facilities.station_type != 15) { log_debug("[tolling] received TPM.entry.request, ignoring"); goto cleanup; } rsu_handle_recv(tpm_rx, security_socket, neighbour, src_addr); break; - case TollingSingle_PR_reply: + case EI1_TollingSingle_PR_reply: if (facilities.station_type == 15) { log_debug("[tolling] received TPM.entry.reply, ignoring"); goto cleanup; @@ -1345,19 +1345,19 @@ int tpm_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neighbour, uint8_t* } break; // Exit - case TollingType_PR_exit: + case EI1_TollingType_PR_exit: if (!tpm_rx->tpm->tollingType->choice.exit) { return 1; } switch (tpm_rx->tpm->tollingType->choice.exit->present) { - case TollingSingle_PR_request: + case EI1_TollingSingle_PR_request: if (facilities.station_type != 15) { log_debug("[tolling] received TPM.exit.request, ignoring"); goto cleanup; } rsu_handle_recv(tpm_rx, security_socket, neighbour, src_addr); break; - case TollingSingle_PR_reply: + case EI1_TollingSingle_PR_reply: if (facilities.station_type == 15) { log_debug("[tolling] received TPM.exit.reply, ignoring"); goto cleanup; @@ -1374,16 +1374,16 @@ int tpm_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neighbour, uint8_t* } break; // Single - case TollingType_PR_single: + case EI1_TollingType_PR_single: switch (tpm_rx->tpm->tollingType->choice.single.present) { - case TollingSingle_PR_request: + case EI1_TollingSingle_PR_request: if (facilities.station_type != 15) { log_debug("[tolling] received TPM.single.request, ignoring"); goto cleanup; } rsu_handle_recv(tpm_rx, security_socket, neighbour, src_addr); break; - case TollingSingle_PR_reply: + case EI1_TollingSingle_PR_reply: if (facilities.station_type == 15) { log_debug("[tolling] received TPM.single.reply, ignoring"); goto cleanup; @@ -1427,7 +1427,7 @@ int tolling_init(uint8_t station_type) { return 0; } -tolling_info_t* tolling_info_new(TollingPaymentInfo_t* tpi) { +tolling_info_t* tolling_info_new(EI1_TollingPaymentInfo_t* tpi) { tolling_info_t* ti = calloc(1, sizeof(tolling_info_t)); ti->timestamp = itss_time_get(); @@ -1445,7 +1445,7 @@ tolling_info_t* tolling_info_new(TollingPaymentInfo_t* tpi) { } void tolling_info_free(tolling_info_t* ti) { - ASN_STRUCT_FREE(asn_DEF_TollingPaymentInfo, ti->asn); + ASN_STRUCT_FREE(asn_DEF_EI1_TollingPaymentInfo, ti->asn); free(ti->zone.polygon); free(ti); } @@ -1493,28 +1493,28 @@ void tolling_tlsc_mgmt(itss_queue_t* tx_queue, void** security_socket) { for (int i = 0; i < tolling->protocol.c.tls.n_tlsc; ++i) { tlsc_t* tlsc = tolling->protocol.c.tls.tls_conns[i]; if (tlsc->ts + TOLLING_CONN_TIMEOUT_MS < now) { - SecurityRequest_t* sreq = NULL; - NetworkingRequest_t* tr = NULL; + EIS_SecurityRequest_t* sreq = NULL; + EIS_NetworkingRequest_t* tr = NULL; const uint32_t buf_len = 1024; uint8_t buf1[buf_len], buf2[buf_len]; log_debug("[tolling] closing TCP/TLS connection"); - sreq = calloc(1, sizeof(SecurityRequest_t)); - sreq->present = SecurityRequest_PR_tlsClose; + sreq = calloc(1, sizeof(EIS_SecurityRequest_t)); + sreq->present = EIS_SecurityRequest_PR_tlsClose; sreq->choice.tlsClose.connId = tlsc->id; buf1[0] = 4; - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf1+1, buf_len-1); + asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_EIS_SecurityRequest, NULL, sreq, buf1+1, buf_len-1); log_debug("->[security] SecurityRequest.tlsClose (%ldB)", enc.encoded+1); itss_0send(*security_socket, buf1, enc.encoded+1); int32_t rl = itss_0recv_rt(security_socket, buf2, buf_len, buf1, enc.encoded+1, 1000); log_debug("<-[security] SecurityReply.tlsClose (%dB)", rl); uint64_t id = rand() + 1; - tr = calloc(1, sizeof(NetworkingRequest_t)); - tr->present = NetworkingRequest_PR_data; - tr->choice.data.present = NetworkingDataRequest_PR_tcp; - tr->choice.data.choice.tcp.present = TCPDataRequest_PR_connCloseReq; + tr = calloc(1, sizeof(EIS_NetworkingRequest_t)); + tr->present = EIS_NetworkingRequest_PR_data; + tr->choice.data.present = EIS_NetworkingDataRequest_PR_tcp; + tr->choice.data.choice.tcp.present = EIS_TCPDataRequest_PR_connCloseReq; tr->choice.data.choice.tcp.choice.connCloseReq.closeByPeer = false; tr->choice.data.choice.tcp.choice.connCloseReq.destinationPort = 7011; tr->choice.data.choice.tcp.choice.connCloseReq.destinationAddress.size = 16; @@ -1523,7 +1523,7 @@ void tolling_tlsc_mgmt(itss_queue_t* tx_queue, void** security_socket) { tr->choice.data.choice.tcp.choice.connCloseReq.id = id; buf1[0] = 4; - enc = oer_encode_to_buffer(&asn_DEF_NetworkingRequest, NULL, tr, buf1+1, buf_len-1); + enc = oer_encode_to_buffer(&asn_DEF_EIS_NetworkingRequest, NULL, tr, buf1+1, buf_len-1); itss_queue_send(tx_queue, buf1, enc.encoded+1, ITSS_NETWORKING, id, "NR.data.tcp.connClose"); free(tlsc); diff --git a/src/tpm.h b/src/tpm.h index 05c3936..4236b7a 100644 --- a/src/tpm.h +++ b/src/tpm.h @@ -1,7 +1,7 @@ #pragma once -#include -#include +#include +#include #include #include #include @@ -29,7 +29,7 @@ typedef struct tolling_info { double (*polygon)[2]; /* (latitude, longitude) */ size_t polygon_len; } zone; - TollingPaymentInfo_t* asn; + EI1_TollingPaymentInfo_t* asn; } tolling_info_t; /** @@ -84,7 +84,7 @@ typedef struct tolling { uint64_t nonce; uint64_t client_id; uint64_t tls_conn_id; - TPM_t* entry_proof; + EI1_TPM_t* entry_proof; uint64_t t_init; @@ -108,11 +108,11 @@ typedef struct tolling { int tolling_init(uint8_t station_type); int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, uint8_t* dst_addr); -int tpm_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neighbour, uint8_t* src_addr); +int tpm_recv(EI1_TPM_t* tpm_rx, void** security_socket, uint8_t* neighbour, uint8_t* src_addr); int tpm_should_retransmit(); int tpm_is_inside_zone(tolling_info_t* ti); -tolling_info_t* tolling_info_new(TollingPaymentInfo_t* tpi); +tolling_info_t* tolling_info_new(EI1_TollingPaymentInfo_t* tpi); void tolling_info_free(tolling_info_t* ti); tlsc_t* tolling_tlsc_new(uint8_t ipv6[16], uint16_t port); diff --git a/src/vcm.c b/src/vcm.c index 35f7678..e20b0f8 100644 --- a/src/vcm.c +++ b/src/vcm.c @@ -7,10 +7,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include @@ -73,38 +73,38 @@ static mc_neighbour_s* get_neighbour(uint32_t station_id) { } -static void tx_vcm(VCM_t* vcm) { +static void tx_vcm(EI1_VCM_t* vcm) { const uint16_t buf_len = 2048; uint8_t buf[buf_len]; - NetworkingRequest_t* nr = NULL; - FacilitiesIndication_t* fi = NULL; - asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_VCM, NULL, vcm, buf, buf_len); + EIS_NetworkingRequest_t* nr = NULL; + EIS_FacilitiesIndication_t* fi = NULL; + asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_EI1_VCM, NULL, vcm, buf, buf_len); if (enc.encoded == -1) { log_error("[vc] VCM encode failure (%s)", enc.failed_type->name); goto cleanup; } uint16_t vcm_len = (enc.encoded + 7) / 8; - nr = calloc(1, sizeof(NetworkingRequest_t)); - nr->present = NetworkingRequest_PR_packet; - NetworkingPacketRequest_t* npr = &nr->choice.packet; + nr = calloc(1, sizeof(EIS_NetworkingRequest_t)); + nr->present = EIS_NetworkingRequest_PR_packet; + EIS_NetworkingPacketRequest_t* npr = &nr->choice.packet; - npr->network.present = NetworkingPacketRequestNW_PR_gn; + npr->network.present = EIS_NetworkingPacketRequestNW_PR_gn; npr->network.choice.gn.trafficClass = 2; npr->network.choice.gn.destinationAddress.buf = malloc(6); for (int i = 0; i < 6; ++i) { npr->network.choice.gn.destinationAddress.buf[i] = 0xff; } npr->network.choice.gn.destinationAddress.size = 6; - npr->network.choice.gn.packetTransportType = PacketTransportType_shb; + npr->network.choice.gn.packetTransportType = EIS_PacketTransportType_shb; npr->network.choice.gn.securityProfile.sign = true; - npr->transport.present = NetworkingPacketRequestTP_PR_btp; - npr->transport.choice.btp.btpType = BTPType_btpB; + npr->transport.present = EIS_NetworkingPacketRequestTP_PR_btp; + npr->transport.choice.btp.btpType = EIS_BTPType_btpB; npr->transport.choice.btp.destinationPort = 2043; if (facilities.edm.enabled && - vcm->vcm.maneuverContainer.present == ManeuverContainer_PR_vehicle && + vcm->vcm.maneuverContainer.present == EI1_ManeuverContainer_PR_vehicle && vcm->vcm.maneuverContainer.choice.vehicle.negotiation ) { edm_encap(buf, &vcm_len, buf_len, 2043); @@ -119,7 +119,7 @@ static void tx_vcm(VCM_t* vcm) { memcpy(npr->data.buf, buf, vcm_len); npr->data.size = vcm_len; buf[0] = 4; - enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_NetworkingRequest, nr, buf+1, buf_len-1); + enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_EIS_NetworkingRequest, nr, buf+1, buf_len-1); if (enc.encoded == -1) { log_error("[vc] NR VCM.reply encode failure (%s)", enc.failed_type->name); goto cleanup; @@ -127,15 +127,15 @@ static void tx_vcm(VCM_t* vcm) { itss_queue_send(facilities.tx_queue, buf, enc.encoded+1, ITSS_NETWORKING, npr->id, "NR.packet.btp"); - fi = calloc(1, sizeof(FacilitiesIndication_t)); - fi->present = FacilitiesIndication_PR_message; + fi = calloc(1, sizeof(EIS_FacilitiesIndication_t)); + fi->present = EIS_FacilitiesIndication_PR_message; fi->choice.message.id = npr->id; fi->choice.message.itsMessageType = 2043; fi->choice.message.data.size = npr->data.size; fi->choice.message.data.buf = malloc(npr->data.size); memcpy(fi->choice.message.data.buf, npr->data.buf, npr->data.size); buf[0] = 4; - enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_FacilitiesIndication, fi, buf+1, buf_len-1); + enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_EIS_FacilitiesIndication, fi, buf+1, buf_len-1); if (enc.encoded == -1) { log_error("[vc] TR VCM.reply encode failure (%s)", enc.failed_type->name); goto cleanup; @@ -163,11 +163,11 @@ static void tx_vcm(VCM_t* vcm) { } cleanup: - ASN_STRUCT_FREE(asn_DEF_NetworkingRequest, nr); - ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi); + ASN_STRUCT_FREE(asn_DEF_EIS_NetworkingRequest, nr); + ASN_STRUCT_FREE(asn_DEF_EIS_FacilitiesIndication, fi); } -static void vcm_reject(VCM_t* vcm, mc_neighbour_s* neighbour) { +static void vcm_reject(EI1_VCM_t* vcm, mc_neighbour_s* neighbour) { coordination_t* coordination = &facilities.coordination; @@ -191,9 +191,9 @@ static void vcm_reject(VCM_t* vcm, mc_neighbour_s* neighbour) { itss_st_t trajectoryA[TRAJECTORY_MAX_LEN+1]; /* ego trajectory */ ssize_t trajectoryA_len = 0; - NetworkingRequest_t* tr = NULL; - FacilitiesIndication_t* fi = NULL; - VCM_t* vcm_rep = calloc(1, sizeof(VCM_t)); + EIS_NetworkingRequest_t* tr = NULL; + EIS_FacilitiesIndication_t* fi = NULL; + EI1_VCM_t* vcm_rep = calloc(1, sizeof(EI1_VCM_t)); int rv = 0; const uint16_t buf_len = 2048; @@ -226,8 +226,8 @@ static void vcm_reject(VCM_t* vcm, mc_neighbour_s* neighbour) { } */ - vcm_rep->vcm.maneuverContainer.present = ManeuverContainer_PR_vehicle; - ManeuverVehicleContainer_t* mvc_rep = &vcm_rep->vcm.maneuverContainer.choice.vehicle; + vcm_rep->vcm.maneuverContainer.present = EI1_ManeuverContainer_PR_vehicle; + EI1_ManeuverVehicleContainer_t* mvc_rep = &vcm_rep->vcm.maneuverContainer.choice.vehicle; mvc_rep->heading.headingValue = heading; mvc_rep->heading.headingConfidence = heading_conf; @@ -251,14 +251,14 @@ static void vcm_reject(VCM_t* vcm, mc_neighbour_s* neighbour) { mvc_rep->plannedTrajectory.list.size = (trajectoryA_len - 1) * sizeof(void*); mvc_rep->plannedTrajectory.list.array = malloc((trajectoryA_len - 1) * sizeof(void*)); for (int i = 0; i < trajectoryA_len - 1; ++i) { - mvc_rep->plannedTrajectory.list.array[i] = calloc(1, sizeof(STPoint_t)); + mvc_rep->plannedTrajectory.list.array[i] = calloc(1, sizeof(EI1_STPoint_t)); mvc_rep->plannedTrajectory.list.array[i]->deltaLatitude = trajectoryA[i+1].latitude - trajectoryA[i].latitude; mvc_rep->plannedTrajectory.list.array[i]->deltaLongitude = trajectoryA[i+1].longitude - trajectoryA[i].longitude; mvc_rep->plannedTrajectory.list.array[i]->deltaTime = trajectoryA[i+1].timestamp - trajectoryA[i].timestamp; } - mvc_rep->negotiation = calloc(1, sizeof(CoordinationNegotiation_t)); - mvc_rep->negotiation->present = CoordinationNegotiation_PR_reply; + mvc_rep->negotiation = calloc(1, sizeof(EI1_CoordinationNegotiation_t)); + mvc_rep->negotiation->present = EI1_CoordinationNegotiation_PR_reply; mvc_rep->negotiation->choice.reply.acceptedTrajectoriesIds.list.count = 0; mvc_rep->negotiation->choice.reply.acceptedTrajectoriesIds.list.size = 0; mvc_rep->negotiation->choice.reply.acceptedTrajectoriesIds.list.array = NULL; @@ -268,7 +268,7 @@ static void vcm_reject(VCM_t* vcm, mc_neighbour_s* neighbour) { tx_vcm(vcm_rep); cleanup: - ASN_STRUCT_FREE(asn_DEF_VCM, vcm_rep); + ASN_STRUCT_FREE(asn_DEF_EI1_VCM, vcm_rep); } static bool is_maneuver_approved() { @@ -288,7 +288,7 @@ static bool is_maneuver_approved() { static void session_cleanup() { coordination_t* coordination = &facilities.coordination; - ASN_STRUCT_FREE(asn_DEF_VCM, coordination->session.own_req); + ASN_STRUCT_FREE(asn_DEF_EI1_VCM, coordination->session.own_req); coordination->session.own_req = NULL; coordination->session.ts = itss_time_get(); coordination->session.nonce = 0; @@ -315,7 +315,7 @@ static bool commit() { log_debug("[vc] issuing COMMIT - session %d", coordination->session.nonce); - VCM_t* vcm_com = calloc(1, sizeof(VCM_t)); + EI1_VCM_t* vcm_com = calloc(1, sizeof(EI1_VCM_t)); vcm_com->header.messageID = 43; vcm_com->header.protocolVersion = 1; pthread_mutex_lock(&facilities.id.lock); @@ -338,8 +338,8 @@ static bool commit() { uint64_t now = itss_time_get(); asn_ulong2INTEGER(&vcm_com->vcm.currentPosition.timestamp, now); - vcm_com->vcm.maneuverContainer.present = ManeuverContainer_PR_vehicle; - ManeuverVehicleContainer_t* mvc = &vcm_com->vcm.maneuverContainer.choice.vehicle; + vcm_com->vcm.maneuverContainer.present = EI1_ManeuverContainer_PR_vehicle; + EI1_ManeuverVehicleContainer_t* mvc = &vcm_com->vcm.maneuverContainer.choice.vehicle; mvc->heading.headingValue = heading; mvc->heading.headingConfidence = heading_conf; @@ -365,20 +365,20 @@ static bool commit() { mvc->plannedTrajectory.list.size = (trajectoryA_len - 1) * sizeof(void*); mvc->plannedTrajectory.list.array = malloc((trajectoryA_len - 1) * sizeof(void*)); for (int i = 0; i < trajectoryA_len - 1; ++i) { - mvc->plannedTrajectory.list.array[i] = calloc(1, sizeof(STPoint_t)); + mvc->plannedTrajectory.list.array[i] = calloc(1, sizeof(EI1_STPoint_t)); mvc->plannedTrajectory.list.array[i]->deltaLatitude = trajectoryA[i+1].latitude - trajectoryA[i].latitude; mvc->plannedTrajectory.list.array[i]->deltaLongitude = trajectoryA[i+1].longitude - trajectoryA[i].longitude; mvc->plannedTrajectory.list.array[i]->deltaTime = trajectoryA[i+1].timestamp - trajectoryA[i].timestamp; } - mvc->negotiation = calloc(1, sizeof(CoordinationNegotiation_t)); - mvc->negotiation->present = CoordinationNegotiation_PR_commit; + mvc->negotiation = calloc(1, sizeof(EI1_CoordinationNegotiation_t)); + mvc->negotiation->present = EI1_CoordinationNegotiation_PR_commit; mvc->negotiation->choice.commit.nonce = coordination->session.nonce; if (coordination->session.own_req) { - mvc->negotiation->choice.commit.qp.present = CoordinationCommitQP_PR_acceptedTrajectoryId; + mvc->negotiation->choice.commit.qp.present = EI1_CoordinationCommitQP_PR_acceptedTrajectoryId; mvc->negotiation->choice.commit.qp.choice.acceptedTrajectoryId = 0; } else { - mvc->negotiation->choice.commit.qp.present = CoordinationCommitQP_PR_requesterId; + mvc->negotiation->choice.commit.qp.present = EI1_CoordinationCommitQP_PR_requesterId; mvc->negotiation->choice.commit.qp.choice.requesterId = coordination->session.requester->station_id; } @@ -402,7 +402,7 @@ static bool commit() { */ tx_vcm(vcm_com); - ASN_STRUCT_FREE(asn_DEF_VCM, vcm_com); + ASN_STRUCT_FREE(asn_DEF_EI1_VCM, vcm_com); session_cleanup(); @@ -410,7 +410,7 @@ static bool commit() { }; -static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) { +static int vcm_check_handle_request(EI1_VCM_t* vcm, mc_neighbour_s* neighbour) { int rv = 0; coordination_t* coordination = &facilities.coordination; @@ -423,7 +423,7 @@ static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) { // Is request for me? - CoordinationRequest_t* request = &vcm->vcm.maneuverContainer.choice.vehicle.negotiation->choice.request; + EI1_CoordinationRequest_t* request = &vcm->vcm.maneuverContainer.choice.vehicle.negotiation->choice.request; bool is_req4me = false; for (int i = 0; i < request->desiredTrajectories.list.count && !is_req4me; ++i) { for (int j = 0; j < request->desiredTrajectories.list.array[i]->affectingStations.list.count; ++j) { @@ -455,7 +455,7 @@ static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) { // Change speed // Just check who is closer to mid trajectory point, if ego is closer, accelerate // TODO a real trajectory analysis - STDeltaTrajectory_t* stdt = &request->desiredTrajectories.list.array[0]->trajectory; + EI1_STDeltaTrajectory_t* stdt = &request->desiredTrajectories.list.array[0]->trajectory; itss_st_t* trj = calloc(stdt->list.count/2 + 1, sizeof(itss_st_t)); trj[0].latitude = vcm->vcm.currentPosition.latitude; trj[0].longitude = vcm->vcm.currentPosition.longitude; @@ -489,16 +489,16 @@ static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) { ); free(trj); - ManagementRequest_t* mreq = calloc(1, sizeof(ManagementRequest_t)); - mreq->present = ManagementRequest_PR_attributes; - mreq->choice.attributes.present = ManagementRequestAttributes_PR_set; - mreq->choice.attributes.choice.set.speed = calloc(1, sizeof(ManagementSpeedSet_t)); - ManagementSpeedSet_t* mgss = mreq->choice.attributes.choice.set.speed; + EIS_ManagementRequest_t* mreq = calloc(1, sizeof(EIS_ManagementRequest_t)); + mreq->present = EIS_ManagementRequest_PR_attributes; + mreq->choice.attributes.present = EIS_ManagementRequestAttributes_PR_set; + mreq->choice.attributes.choice.set.speed = calloc(1, sizeof(EIS_ManagementSpeedSet_t)); + EIS_ManagementSpeedSet_t* mgss = mreq->choice.attributes.choice.set.speed; mgss->rate = 5; /* km/h/s */ mgss->temporary = true; /* go back to original speed after a while */ - mgss->type.present = ManagementSpeedSetType_PR_diff; /* differential change set */ + mgss->type.present = EIS_ManagementSpeedSetType_PR_diff; /* differential change set */ mgss->type.choice.diff = (dreq > dego) ? 10 : -10; /* % */ - asn_enc_rval_t enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_ManagementRequest, mreq, buf1, buf_len); + asn_enc_rval_t enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_EIS_ManagementRequest, mreq, buf1, buf_len); if (enc.encoded == -1) { log_error("[vc] failed to encode MReq.speedSet (%s)", enc.failed_type->name); } @@ -506,12 +506,12 @@ static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) { if (itss_0recv_rt(&coordination->mgmt_socket, buf2, buf_len, buf1, enc.encoded, 500) == -1) { log_error("[vc]-> MReq.speedSet ->[management] "); } - ASN_STRUCT_FREE(asn_DEF_ManagementRequest, mreq); + ASN_STRUCT_FREE(asn_DEF_EIS_ManagementRequest, mreq); // Respond - VCM_t* vcm_rep = NULL; - NetworkingRequest_t* tr = NULL; - FacilitiesIndication_t* fi = NULL; + EI1_VCM_t* vcm_rep = NULL; + EIS_NetworkingRequest_t* tr = NULL; + EIS_FacilitiesIndication_t* fi = NULL; itss_st_t trajectoryA[TRAJECTORY_MAX_LEN+1]; /* ego trajectory */ @@ -525,7 +525,7 @@ static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) { coordination->session.requester = neighbour; coordination->session.t_init = now; - vcm_rep = calloc(1, sizeof(VCM_t)); + vcm_rep = calloc(1, sizeof(EI1_VCM_t)); vcm_rep->header.messageID = 43; vcm_rep->header.protocolVersion = 1; @@ -563,8 +563,8 @@ static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) { } */ - vcm_rep->vcm.maneuverContainer.present = ManeuverContainer_PR_vehicle; - ManeuverVehicleContainer_t* mvc_rep = &vcm_rep->vcm.maneuverContainer.choice.vehicle; + vcm_rep->vcm.maneuverContainer.present = EI1_ManeuverContainer_PR_vehicle; + EI1_ManeuverVehicleContainer_t* mvc_rep = &vcm_rep->vcm.maneuverContainer.choice.vehicle; mvc_rep->heading.headingValue = heading; mvc_rep->heading.headingConfidence = heading_conf; @@ -588,7 +588,7 @@ static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) { mvc_rep->plannedTrajectory.list.size = (trajectoryA_len - 1) * sizeof(void*); mvc_rep->plannedTrajectory.list.array = malloc((trajectoryA_len - 1) * sizeof(void*)); for (int i = 0; i < trajectoryA_len - 1; ++i) { - mvc_rep->plannedTrajectory.list.array[i] = calloc(1, sizeof(STPoint_t)); + mvc_rep->plannedTrajectory.list.array[i] = calloc(1, sizeof(EI1_STPoint_t)); mvc_rep->plannedTrajectory.list.array[i]->deltaLatitude = trajectoryA[i+1].latitude - trajectoryA[i].latitude; mvc_rep->plannedTrajectory.list.array[i]->deltaLongitude = trajectoryA[i+1].longitude - trajectoryA[i].longitude; mvc_rep->plannedTrajectory.list.array[i]->deltaTime = trajectoryA[i+1].timestamp - trajectoryA[i].timestamp; @@ -600,12 +600,12 @@ static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) { rv = 1; goto cleanup; } - ProposedTrajectory_t* pt = request->desiredTrajectories.list.array[0]; + EI1_ProposedTrajectory_t* pt = request->desiredTrajectories.list.array[0]; // TODO check if vehicles are really going to intersect - mvc_rep->negotiation = calloc(1, sizeof(CoordinationNegotiation_t)); - mvc_rep->negotiation->present = CoordinationNegotiation_PR_reply; + mvc_rep->negotiation = calloc(1, sizeof(EI1_CoordinationNegotiation_t)); + mvc_rep->negotiation->present = EI1_CoordinationNegotiation_PR_reply; mvc_rep->negotiation->choice.reply.acceptedTrajectoriesIds.list.count = 1; mvc_rep->negotiation->choice.reply.acceptedTrajectoriesIds.list.size = sizeof(void*); mvc_rep->negotiation->choice.reply.acceptedTrajectoriesIds.list.array = malloc(1*sizeof(void*)); @@ -634,16 +634,16 @@ static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) { } cleanup: - ASN_STRUCT_FREE(asn_DEF_VCM, vcm_rep); + ASN_STRUCT_FREE(asn_DEF_EI1_VCM, vcm_rep); return rv; } -static int vcm_check_handle_reply(VCM_t* vcm, mc_neighbour_s* neighbour) { +static int vcm_check_handle_reply(EI1_VCM_t* vcm, mc_neighbour_s* neighbour) { int rv = 0; coordination_t* coordination = &facilities.coordination; - CoordinationReply_t* reply = &vcm->vcm.maneuverContainer.choice.vehicle.negotiation->choice.reply; + EI1_CoordinationReply_t* reply = &vcm->vcm.maneuverContainer.choice.vehicle.negotiation->choice.reply; if (reply->nonce != coordination->session.nonce) { return 1; @@ -738,15 +738,15 @@ static int vcm_check_handle_reply(VCM_t* vcm, mc_neighbour_s* neighbour) { return rv; } -static int intersection_detected(VCM_t* vcm, mc_neighbour_s* neighbour) { +static int intersection_detected(EI1_VCM_t* vcm, mc_neighbour_s* neighbour) { int rv = 0; coordination_t* coordination = &facilities.coordination; - VCM_t* vcm_req = NULL; - NetworkingRequest_t* tr = NULL; - FacilitiesIndication_t* fi = NULL; + EI1_VCM_t* vcm_req = NULL; + EIS_NetworkingRequest_t* tr = NULL; + EIS_FacilitiesIndication_t* fi = NULL; const ssize_t buf_len = 1024; uint8_t buf[buf_len]; @@ -779,7 +779,7 @@ static int intersection_detected(VCM_t* vcm, mc_neighbour_s* neighbour) { ++trajectoryA_len; // Initiate conflict resolution - vcm_req = calloc(1, sizeof(VCM_t)); + vcm_req = calloc(1, sizeof(EI1_VCM_t)); vcm_req->header.messageID = 43; vcm_req->header.protocolVersion = 1; @@ -810,8 +810,8 @@ static int intersection_detected(VCM_t* vcm, mc_neighbour_s* neighbour) { } */ - vcm_req->vcm.maneuverContainer.present = ManeuverContainer_PR_vehicle; - ManeuverVehicleContainer_t* mvc = &vcm_req->vcm.maneuverContainer.choice.vehicle; + vcm_req->vcm.maneuverContainer.present = EI1_ManeuverContainer_PR_vehicle; + EI1_ManeuverVehicleContainer_t* mvc = &vcm_req->vcm.maneuverContainer.choice.vehicle; mvc->heading.headingValue = heading; mvc->heading.headingConfidence = heading_conf; @@ -825,20 +825,20 @@ static int intersection_detected(VCM_t* vcm, mc_neighbour_s* neighbour) { mvc->plannedTrajectory.list.size = (trajectoryA_len - 1) * sizeof(void*); mvc->plannedTrajectory.list.array = malloc((trajectoryA_len - 1) * sizeof(void*)); for (int i = 0; i < trajectoryA_len - 1; ++i) { - mvc->plannedTrajectory.list.array[i] = calloc(1, sizeof(STPoint_t)); + mvc->plannedTrajectory.list.array[i] = calloc(1, sizeof(EI1_STPoint_t)); mvc->plannedTrajectory.list.array[i]->deltaLatitude = trajectoryA[i+1].latitude - trajectoryA[i].latitude; mvc->plannedTrajectory.list.array[i]->deltaLongitude = trajectoryA[i+1].longitude - trajectoryA[i].longitude; mvc->plannedTrajectory.list.array[i]->deltaTime = trajectoryA[i+1].timestamp - trajectoryA[i].timestamp; } // Desired trajectory - mvc->negotiation = calloc(1, sizeof(CoordinationNegotiation_t)); - mvc->negotiation->present = CoordinationNegotiation_PR_request; + mvc->negotiation = calloc(1, sizeof(EI1_CoordinationNegotiation_t)); + mvc->negotiation->present = EI1_CoordinationNegotiation_PR_request; mvc->negotiation->choice.request.desiredTrajectories.list.count = 1; mvc->negotiation->choice.request.desiredTrajectories.list.size = sizeof(void*); mvc->negotiation->choice.request.desiredTrajectories.list.array = malloc(1*sizeof(void*)); - mvc->negotiation->choice.request.desiredTrajectories.list.array[0] = calloc(1,sizeof(ProposedTrajectory_t)); - ProposedTrajectory_t* pt = mvc->negotiation->choice.request.desiredTrajectories.list.array[0]; + mvc->negotiation->choice.request.desiredTrajectories.list.array[0] = calloc(1,sizeof(EI1_ProposedTrajectory_t)); + EI1_ProposedTrajectory_t* pt = mvc->negotiation->choice.request.desiredTrajectories.list.array[0]; mvc->negotiation->choice.request.requesterId = vcm->header.stationID; mvc->negotiation->choice.request.nonce = rand(); coordination->session.nonce = mvc->negotiation->choice.request.nonce; @@ -847,7 +847,7 @@ static int intersection_detected(VCM_t* vcm, mc_neighbour_s* neighbour) { pt->trajectory.list.size = sizeof(void*) * (trajectoryA_len - 1); pt->trajectory.list.array = malloc(sizeof(void*) * (trajectoryA_len - 1)); for (int i = 0; i < trajectoryA_len - 1; ++i) { - pt->trajectory.list.array[i] = calloc(1, sizeof(STPoint_t)); + pt->trajectory.list.array[i] = calloc(1, sizeof(EI1_STPoint_t)); pt->trajectory.list.array[i]->deltaLatitude = trajectoryA[i+1].latitude - trajectoryA[i].latitude; pt->trajectory.list.array[i]->deltaLongitude = trajectoryA[i+1].longitude - trajectoryA[i].longitude; pt->trajectory.list.array[i]->deltaTime = trajectoryA[i+1].timestamp - trajectoryA[i].timestamp; @@ -915,9 +915,9 @@ static int intersection_detected(VCM_t* vcm, mc_neighbour_s* neighbour) { return rv; } -static void intersection_check(VCM_t* vcm, mc_neighbour_s* neighbour) { +static void intersection_check(EI1_VCM_t* vcm, mc_neighbour_s* neighbour) { - ManeuverVehicleContainer_t* mvc = &vcm->vcm.maneuverContainer.choice.vehicle; + EI1_ManeuverVehicleContainer_t* mvc = &vcm->vcm.maneuverContainer.choice.vehicle; itss_st_t trajectoryA[TRAJECTORY_MAX_LEN+1]; /* ego trajectory */ itss_st_t trajectoryB[TRAJECTORY_MAX_LEN+1]; /* neighbour trajectory */ @@ -979,7 +979,7 @@ static void intersection_check(VCM_t* vcm, mc_neighbour_s* neighbour) { } } -static int vcm_check_handle_commit(VCM_t* vcm, mc_neighbour_s* neighbour) { +static int vcm_check_handle_commit(EI1_VCM_t* vcm, mc_neighbour_s* neighbour) { coordination_t* coordination = &facilities.coordination; if (vcm->vcm.maneuverContainer.choice.vehicle.negotiation->choice.commit.nonce != coordination->session.nonce) { @@ -1007,7 +1007,7 @@ static bool in_maneuver() { return true; } -int vcm_check(VCM_t* vcm) { +int vcm_check(EI1_VCM_t* vcm) { coordination_t* coordination = &facilities.coordination; int rv = 0; @@ -1019,20 +1019,20 @@ int vcm_check(VCM_t* vcm) { mc_neighbour_s* neighbour = get_neighbour(vcm->header.stationID); switch (vcm->vcm.maneuverContainer.present) { - case ManeuverContainer_PR_vehicle: + case EI1_ManeuverContainer_PR_vehicle: ; - ManeuverVehicleContainer_t* mvc = &vcm->vcm.maneuverContainer.choice.vehicle; + EI1_ManeuverVehicleContainer_t* mvc = &vcm->vcm.maneuverContainer.choice.vehicle; if (mvc->negotiation) { switch (mvc->negotiation->present) { - case CoordinationNegotiation_PR_request: + case EI1_CoordinationNegotiation_PR_request: vcm_check_handle_request(vcm, neighbour); break; - case CoordinationNegotiation_PR_reply: + case EI1_CoordinationNegotiation_PR_reply: vcm_check_handle_reply(vcm, neighbour); break; - case CoordinationNegotiation_PR_commit: + case EI1_CoordinationNegotiation_PR_commit: vcm_check_handle_commit(vcm, neighbour); break; @@ -1044,7 +1044,7 @@ int vcm_check(VCM_t* vcm) { log_debug("[vc] ignoring VCM from %d - currently in maneuver", vcm->header.stationID); } else { if (coordination->session.own_req) { /* clear previous request if exists */ - ASN_STRUCT_FREE(asn_DEF_VCM, coordination->session.own_req); + ASN_STRUCT_FREE(asn_DEF_EI1_VCM, coordination->session.own_req); coordination->session.own_req = NULL; coordination->session.ts = now; memset(coordination->session.affs, 0, sizeof(coordination->session.affs)); @@ -1058,7 +1058,7 @@ int vcm_check(VCM_t* vcm) { } } break; - case ManeuverContainer_PR_rsu: + case EI1_ManeuverContainer_PR_rsu: break; default: log_debug("[vc] received VCM contains unrecognized ManeuverContainer type"); @@ -1078,7 +1078,7 @@ static int mk_vcm() { itss_st_t trajectory[TRAJECTORY_MAX_LEN]; - VCM_t* vcm = calloc(1, sizeof(VCM_t)); + EI1_VCM_t* vcm = calloc(1, sizeof(EI1_VCM_t)); vcm->header.messageID = 43; vcm->header.protocolVersion = 1; @@ -1127,13 +1127,13 @@ static int mk_vcm() { } */ - if (facilities.station_type == StationType_roadSideUnit) { - vcm->vcm.maneuverContainer.present = ManeuverContainer_PR_rsu; - ManeuverRSUContainer_t* mrc = &vcm->vcm.maneuverContainer.choice.rsu; + if (facilities.station_type == EI1_StationType_roadSideUnit) { + vcm->vcm.maneuverContainer.present = EI1_ManeuverContainer_PR_rsu; + EI1_ManeuverRSUContainer_t* mrc = &vcm->vcm.maneuverContainer.choice.rsu; mrc->recommendedTrajectories = NULL; // TODO } else { - vcm->vcm.maneuverContainer.present = ManeuverContainer_PR_vehicle; - ManeuverVehicleContainer_t* mvc = &vcm->vcm.maneuverContainer.choice.vehicle; + vcm->vcm.maneuverContainer.present = EI1_ManeuverContainer_PR_vehicle; + EI1_ManeuverVehicleContainer_t* mvc = &vcm->vcm.maneuverContainer.choice.vehicle; mvc->heading.headingValue = heading; mvc->heading.headingConfidence = heading_conf; // Vehicle Dimensions @@ -1144,12 +1144,12 @@ static int mk_vcm() { mvc->plannedTrajectory.list.count = trajectory_len; mvc->plannedTrajectory.list.size = trajectory_len * sizeof(void*); mvc->plannedTrajectory.list.array = malloc(trajectory_len * sizeof(void*)); - mvc->plannedTrajectory.list.array[0] = calloc(1, sizeof(STPoint_t)); + mvc->plannedTrajectory.list.array[0] = calloc(1, sizeof(EI1_STPoint_t)); mvc->plannedTrajectory.list.array[0]->deltaLatitude = trajectory[0].latitude - lat; mvc->plannedTrajectory.list.array[0]->deltaLongitude = trajectory[0].longitude - lon; mvc->plannedTrajectory.list.array[0]->deltaTime = trajectory[0].timestamp - now; for (int i = 1; i < trajectory_len; ++i) { - mvc->plannedTrajectory.list.array[i] = calloc(1, sizeof(STPoint_t)); + mvc->plannedTrajectory.list.array[i] = calloc(1, sizeof(EI1_STPoint_t)); mvc->plannedTrajectory.list.array[i]->deltaLatitude = trajectory[i].latitude - trajectory[i-1].latitude; mvc->plannedTrajectory.list.array[i]->deltaLongitude = trajectory[i].longitude - trajectory[i-1].longitude; mvc->plannedTrajectory.list.array[i]->deltaTime = trajectory[i].timestamp - trajectory[i-1].timestamp; @@ -1159,7 +1159,7 @@ static int mk_vcm() { tx_vcm(vcm); cleanup: - ASN_STRUCT_FREE(asn_DEF_VCM, vcm); + ASN_STRUCT_FREE(asn_DEF_EI1_VCM, vcm); return rv; } @@ -1176,7 +1176,7 @@ static bool vcm_timer_check(coordination_t* coordination, uint64_t now) { return false; } - if (facilities.station_type != StationType_roadSideUnit) { // Vehicle + if (facilities.station_type != EI1_StationType_roadSideUnit) { // Vehicle itss_trajectory_lock(); diff --git a/src/vcm.h b/src/vcm.h index 231f17a..843c855 100644 --- a/src/vcm.h +++ b/src/vcm.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include @@ -53,7 +53,7 @@ typedef struct coordination { double previous_c; struct { - VCM_t* own_req; /* last VCM.request sent */ + EI1_VCM_t* own_req; /* last VCM.request sent */ uint64_t ts; uint32_t nonce; @@ -89,7 +89,7 @@ typedef struct coordination { * @param vcm The VCM to be analyzed * @return 0 on success, other value otherwise */ -int vcm_check(VCM_t* vcm); +int vcm_check(EI1_VCM_t* vcm); /** * VC loop, threaded