Merge branch 'EV_Messages'
This commit is contained in:
commit
dbb5a8addc
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"files.associations": {
|
||||
"prereservation-id.h": "c",
|
||||
"constr_sequence.h": "c",
|
||||
"array": "c",
|
||||
"string_view": "c",
|
||||
"initializer_list": "c",
|
||||
"nativeenumerated.h": "c",
|
||||
"asn_application.h": "c"
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ ADD_EXECUTABLE(it2s-itss-facilities
|
|||
saem.c
|
||||
tpm.c
|
||||
vcm.c
|
||||
evm.c
|
||||
)
|
||||
|
||||
TARGET_LINK_LIBRARIES(it2s-itss-facilities
|
||||
|
|
@ -28,6 +29,8 @@ TARGET_LINK_LIBRARIES(it2s-itss-facilities
|
|||
-lit2s-asn-saem
|
||||
-lit2s-asn-tpm
|
||||
-lit2s-asn-vcm
|
||||
-lit2s-asn-evcsnm
|
||||
-lit2s-asn-evrsrm
|
||||
-lit2s-asn-verco
|
||||
-lit2s-tender
|
||||
-lit2s-obd
|
||||
|
|
|
|||
|
|
@ -394,6 +394,9 @@ int facilities_config() {
|
|||
facilities.coordination.vcm_period_min = config->facilities.mcm.period_min;
|
||||
facilities.coordination.vcm_period_max = config->facilities.mcm.period_max;
|
||||
|
||||
// EVCSNM
|
||||
facilities.evm_args.activate = config->facilities.evcsnm.activate;
|
||||
|
||||
// Replay
|
||||
facilities.replay = config->networking.replay.activate;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,365 @@
|
|||
#include "evm.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <it2s-asn/evcsnm/EvcsnPdu.h>
|
||||
#include <it2s-asn/itss-facilities/FacilitiesIndication.h>
|
||||
#include <it2s-asn/itss-management/ManagementRequest.h>
|
||||
#include <it2s-asn/itss-transport/TransportRequest.h>
|
||||
#include <it2s-tender/constants.h>
|
||||
#include <it2s-tender/database.h>
|
||||
#include <it2s-tender/packet.h>
|
||||
#include <it2s-tender/recorder.h>
|
||||
#include <it2s-tender/space.h>
|
||||
#include <it2s-tender/time.h>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/mman.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <zmq.h>
|
||||
|
||||
#include "facilities.h"
|
||||
|
||||
static UTF8String_t *create_utf8_from_string(const char *string, size_t length) {
|
||||
UTF8String_t *utf8_string = calloc(1, sizeof(UTF8String_t));
|
||||
utf8_string->buf = calloc(length, sizeof(uint8_t));
|
||||
utf8_string->size = length;
|
||||
memcpy(utf8_string->buf, string, length);
|
||||
return utf8_string;
|
||||
}
|
||||
|
||||
static UTF8String_t *create_empty_utf8_string() {
|
||||
UTF8String_t *utf8_string = calloc(1, sizeof(UTF8String_t));
|
||||
utf8_string->size = 0;
|
||||
return utf8_string;
|
||||
}
|
||||
|
||||
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));
|
||||
evcsnm->header.protocolVersion = 2;
|
||||
evcsnm->header.messageID = 1;
|
||||
pthread_mutex_lock(&facilities.id.lock);
|
||||
evcsnm->header.stationID = facilities.id.station_id;
|
||||
pthread_mutex_unlock(&facilities.id.lock);
|
||||
|
||||
uint64_t now = itss_time_get();
|
||||
|
||||
evcsnm->evcsn.poiHeader.poiType = 1; // set to "EV charging station POI ID = 1"
|
||||
asn_ulong2INTEGER(&evcsnm->evcsn.poiHeader.timeStamp, now);
|
||||
evcsnm->evcsn.poiHeader.relayCapable = 1;
|
||||
|
||||
evcsnm->evcsn.evcsnData.totalNumberOfStations = 1;
|
||||
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];
|
||||
cs0->chargingStationID = 0;
|
||||
itss_space_lock();
|
||||
itss_space_get();
|
||||
cs0->chargingStationLocation.latitude = 405970830;
|
||||
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->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"));
|
||||
const char *booking_url = "ccam.av.it.pt";
|
||||
cs0->bookingContactInfo = create_utf8_from_string(booking_url, strlen(booking_url));
|
||||
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];
|
||||
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;
|
||||
cs_elem0->type.bits_unused = 0;
|
||||
cs_elem0->type.buf[0] = 0x03;
|
||||
cs_elem0->typeOfReceptacle.buf = calloc(1, sizeof(uint8_t));
|
||||
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->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];
|
||||
spot->maxWaitingTimeMinutes = 0;
|
||||
spot->blocking = 1;
|
||||
}
|
||||
itss_space_unlock(epv);
|
||||
// if (facilities.station_type == StationType_roadSideUnit)
|
||||
//{
|
||||
// }
|
||||
|
||||
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_EvcsnPdu, NULL, evcsnm, evcsnm_oer, 512);
|
||||
if (enc.encoded == -1) {
|
||||
log_error("[ca] failed encoding evcsnm (%s)", enc.failed_type->name);
|
||||
rv = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
*evcsnm_len = (enc.encoded + 7) / 8;
|
||||
|
||||
cleanup:
|
||||
ASN_STRUCT_FREE(asn_DEF_EvcsnPdu, evcsnm);
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int pre_reservation_id = 0;
|
||||
|
||||
int evrsrm_recv(EV_RSR_t *evrsr_request) {
|
||||
int rv = 0;
|
||||
TransportRequest_t *tr = calloc(1, sizeof(TransportRequest_t));
|
||||
tr->present = TransportRequest_PR_packet;
|
||||
TransportPacketRequest_t *tpr = &tr->choice.packet;
|
||||
tpr->present = TransportPacketRequest_PR_btp;
|
||||
BTPPacketRequest_t *bpr = &tpr->choice.btp;
|
||||
|
||||
bpr->btpType = BTPType_btpB;
|
||||
|
||||
bpr->gn.destinationAddress.buf = malloc(6);
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
bpr->gn.destinationAddress.buf[i] = 0xff;
|
||||
}
|
||||
bpr->gn.destinationAddress.size = 6;
|
||||
|
||||
bpr->gn.packetTransportType = PacketTransportType_shb;
|
||||
|
||||
bpr->destinationPort = Port_evrsr;
|
||||
|
||||
bpr->gn.trafficClass = 2;
|
||||
|
||||
bpr->data.buf = malloc(512);
|
||||
|
||||
// Fill header for FacilitiesIndication and FacilitiesMessageIndication structs
|
||||
|
||||
bpr->gn.securityProfile.sign = true;
|
||||
|
||||
FacilitiesIndication_t *fi = calloc(1, sizeof(FacilitiesIndication_t));
|
||||
fi->present = FacilitiesIndication_PR_message;
|
||||
FacilitiesMessageIndication_t *fmi = &fi->choice.message;
|
||||
fmi->itsMessageType = 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) {
|
||||
rv = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
int evrsr_response;
|
||||
if (evrsr_request->messageBody.present == EV_RSR_MessageBody_PR_preReservationRequestMessage)
|
||||
evrsr_response = evrsrm_pre_reservation_response(bpr->data.buf, (uint32_t *)&bpr->data.size);
|
||||
// else if (evrsr_request->messageBody.present == EV_RSR_MessageBody_PR_reservationRequestMessage)
|
||||
// evrsr_response = evrsrm_reservation_response(evrsr_request);
|
||||
if (evrsr_response != 0) {
|
||||
rv = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
memcpy(fmi->data.buf, bpr->data.buf, bpr->data.size);
|
||||
fmi->data.size = bpr->data.size;
|
||||
|
||||
// Check if inside PZ
|
||||
bpr->gn.communicationProfile = 0;
|
||||
if (facilities.station_type != 15) bpr->gn.communicationProfile = 1;
|
||||
|
||||
uint32_t id = itss_id(bpr->data.buf, bpr->data.size);
|
||||
bpr->id = id;
|
||||
fmi->id = id;
|
||||
|
||||
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_FacilitiesIndication, NULL, fi, tr_oer + 1, 1024);
|
||||
if (enc.encoded == -1) {
|
||||
log_error("[ca] failed encoding facilities indication (%s)", enc.failed_type->name);
|
||||
rv = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
tr->choice.packet.choice.btp.data.size = (enc.encoded + 7) / 8;
|
||||
|
||||
enc = uper_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, tr_oer, 1024);
|
||||
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);
|
||||
if (enc_fdi.encoded == -1) {
|
||||
log_error("[ev] encoding FI for evrsrm failed");
|
||||
rv = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
itss_queue_send(facilities.tx_queue, tr_oer, enc.encoded + 1, ITSS_TRANSPORT, id, "TR.packet.btp");
|
||||
|
||||
itss_queue_send(facilities.tx_queue, fi_oer, enc_fdi.encoded + 1, ITSS_APPLICATIONS, id, "FI.message");
|
||||
|
||||
cleanup:
|
||||
log_debug("[ev] evrsrm_recv done");
|
||||
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));
|
||||
evrsr_response->header.protocolVersion = 1;
|
||||
evrsr_response->header.messageID = 1;
|
||||
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;
|
||||
|
||||
PreReservationResponseMessage_t response = evrsr_response->messageBody.choice.preReservationResponseMessage;
|
||||
char *pre_reservation_id = calloc(1, sizeof(char) * 10);
|
||||
sprintf(pre_reservation_id, "%d", pre_reservation_id);
|
||||
response.preReservation_ID = *create_utf8_from_string(pre_reservation_id, strlen(pre_reservation_id));
|
||||
|
||||
response.availabilityStatus = 0;
|
||||
|
||||
response.supportedPaymentTypes.buf = calloc(1, sizeof(uint8_t));
|
||||
response.supportedPaymentTypes.bits_unused = 0;
|
||||
response.supportedPaymentTypes.size = 1;
|
||||
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);
|
||||
if (enc.encoded == -1) {
|
||||
log_error("[ca] failed encoding evrsrm (%s)", enc.failed_type->name);
|
||||
rv = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
*evrsrm_len = (enc.encoded + 7) / 8;
|
||||
pre_reservation_id++;
|
||||
cleanup:
|
||||
ASN_STRUCT_FREE(asn_DEF_EV_RSR, evrsr_response);
|
||||
return rv;
|
||||
}
|
||||
|
||||
int evcsnm_check(EvcsnPdu_t *evcsnm) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int evrsrm_check(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) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum EVM_CHECK_R check_evrsrm(BTPPacketIndication_t *bpi, EV_RSR_t *evrsrm, uint8_t *ssp, uint32_t ssp_len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *evcsn_service() {
|
||||
int rv = 0;
|
||||
|
||||
TransportRequest_t *tr = calloc(1, sizeof(TransportRequest_t));
|
||||
tr->present = TransportRequest_PR_packet;
|
||||
TransportPacketRequest_t *tpr = &tr->choice.packet;
|
||||
tpr->present = TransportPacketRequest_PR_btp;
|
||||
BTPPacketRequest_t *bpr = &tpr->choice.btp;
|
||||
|
||||
bpr->btpType = BTPType_btpB;
|
||||
|
||||
bpr->gn.destinationAddress.buf = malloc(6);
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
bpr->gn.destinationAddress.buf[i] = 0xff;
|
||||
}
|
||||
bpr->gn.destinationAddress.size = 6;
|
||||
|
||||
bpr->gn.packetTransportType = PacketTransportType_shb;
|
||||
|
||||
bpr->destinationPort = Port_poi;
|
||||
|
||||
bpr->gn.trafficClass = 2;
|
||||
|
||||
bpr->data.buf = malloc(512);
|
||||
|
||||
// Fill header for FacilitiesIndication and FacilitiesMessageIndication structs
|
||||
|
||||
bpr->gn.securityProfile.sign = true;
|
||||
|
||||
FacilitiesIndication_t *fi = calloc(1, sizeof(FacilitiesIndication_t));
|
||||
fi->present = FacilitiesIndication_PR_message;
|
||||
FacilitiesMessageIndication_t *fmi = &fi->choice.message;
|
||||
fmi->itsMessageType = ItsMessageType_poi;
|
||||
fmi->data.buf = malloc(512);
|
||||
|
||||
uint8_t tr_oer[1024];
|
||||
uint8_t fi_oer[1024];
|
||||
tr_oer[0] = 4; // Facilities
|
||||
fi_oer[0] = 4;
|
||||
while (!facilities.exit) {
|
||||
usleep(1000 * 1000);
|
||||
if (facilities.evm_args.activate) {
|
||||
rv = mk_evcsnm(bpr->data.buf, (uint32_t *)&bpr->data.size);
|
||||
if (rv) {
|
||||
continue;
|
||||
}
|
||||
memcpy(fmi->data.buf, bpr->data.buf, bpr->data.size);
|
||||
fmi->data.size = bpr->data.size;
|
||||
|
||||
uint32_t id = itss_id(bpr->data.buf, bpr->data.size);
|
||||
bpr->id = id;
|
||||
fmi->id = id;
|
||||
|
||||
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, 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);
|
||||
if (enc_fdi.encoded == -1) {
|
||||
log_error("encoding FI for evcsnm failed");
|
||||
continue;
|
||||
}
|
||||
|
||||
itss_queue_send(facilities.tx_queue, tr_oer, enc.encoded + 1, ITSS_TRANSPORT, id, "TR.packet.btp");
|
||||
|
||||
itss_queue_send(facilities.tx_queue, fi_oer, enc_fdi.encoded + 1, ITSS_APPLICATIONS, id, "FI.message");
|
||||
|
||||
// Logging
|
||||
if (facilities.logging.dbms) {
|
||||
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, bpr->id, true, messageID_evcsn, NULL, bpr->data.buf, bpr->data.size);
|
||||
}
|
||||
|
||||
if (facilities.logging.recorder) {
|
||||
uint16_t buffer_len = 2048;
|
||||
uint8_t buffer[buffer_len];
|
||||
int e = itss_management_record_packet_sdu(
|
||||
buffer,
|
||||
buffer_len,
|
||||
bpr->data.buf,
|
||||
bpr->data.size,
|
||||
id,
|
||||
itss_time_get(),
|
||||
ITSS_FACILITIES,
|
||||
true);
|
||||
if (e != -1) {
|
||||
itss_queue_send(facilities.tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
#ifndef FACILITIES_EVM_H
|
||||
#define FACILITIES_EVM_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <it2s-asn/evcsnm/EvcsnPdu.h>
|
||||
#include <it2s-asn/evrsrm/EV-RSR.h>
|
||||
#include <it2s-asn/itss-transport/BTPPacketIndication.h>
|
||||
|
||||
#include <it2s-tender/epv.h>
|
||||
|
||||
enum EVM_CHECK_R {
|
||||
EVM_OK,
|
||||
EVM_INVALID,
|
||||
EVM_BAD_PERMISSIONS
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief Analyzes a received EVCSNM
|
||||
*
|
||||
* @return A EVM check code
|
||||
*/
|
||||
enum EVM_CHECK_R check_evcsnm(BTPPacketIndication_t *bpi, 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);
|
||||
|
||||
/*
|
||||
* @brief Main CA service
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
void* evcsn_service();
|
||||
|
||||
/**
|
||||
* @brief Creates a EVCSNM response and sends it
|
||||
* @param evcsnm_request The EVCSNM request
|
||||
*
|
||||
* @return 0 on success, 1 otherwise
|
||||
*/
|
||||
int evrsrm_recv(EV_RSR_t *evrsr_request);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Creates a pre reservation response.
|
||||
* @param evrsrm_oer The encoded pre reservation response
|
||||
* @param evrsrm_len The length of the encoded pre reservation response
|
||||
*
|
||||
* @return The reservation response or NULL if the request isn't a Pre reservation request
|
||||
*/
|
||||
|
||||
static int evrsrm_pre_reservation_response(uint8_t *evrsrm_oer, uint32_t *evrsrm_len);
|
||||
|
||||
/**
|
||||
* Analyses a evcsnm
|
||||
* @param evcsnm The evcsnm to be analyzed
|
||||
* @return 0 on success, other value otherwise
|
||||
*/
|
||||
int evcsnm_check(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);
|
||||
|
||||
typedef struct evm_args {
|
||||
bool activate;
|
||||
} evm_args_t;
|
||||
|
||||
#endif
|
||||
117
src/facilities.c
117
src/facilities.c
|
|
@ -1,47 +1,46 @@
|
|||
#include "facilities.h"
|
||||
#include "cam.h"
|
||||
#include "config.h"
|
||||
#include "denm.h"
|
||||
#include "infrastructure.h"
|
||||
#include "indications.h"
|
||||
#include "requests.h"
|
||||
#include "cpm.h"
|
||||
#include "saem.h"
|
||||
#include "tpm.h"
|
||||
#include "vcm.h"
|
||||
|
||||
#include <it2s-asn/itss-networking/NetworkingIndication.h>
|
||||
#include <it2s-asn/itss-transport/TransportRequest.h>
|
||||
#include <it2s-asn/itss-transport/TransportIndication.h>
|
||||
#include <it2s-asn/itss-facilities/FacilitiesIndication.h>
|
||||
#include <it2s-asn/itss-facilities/FacilitiesRequest.h>
|
||||
#include <it2s-asn/itss-facilities/FacilitiesReply.h>
|
||||
#include <it2s-asn/itss-security/SecurityIndication.h>
|
||||
#include <it2s-asn/itss-security/SecurityResponse.h>
|
||||
#include <it2s-asn/itss-management/ManagementIndication.h>
|
||||
#include <it2s-asn/itss-management/ManagementRequest.h>
|
||||
#include <it2s-asn/itss-security/SecurityRequest.h>
|
||||
#include <it2s-asn/itss-security/SecurityReply.h>
|
||||
|
||||
#include <it2s-asn/camv2/CAM.h>
|
||||
#include <it2s-asn/denmv2/DENM.h>
|
||||
#include <it2s-asn/ivim/IVIM.h>
|
||||
#include <it2s-asn/cpm/CPM.h>
|
||||
#include <it2s-asn/denmv2/DENM.h>
|
||||
#include <it2s-asn/itss-facilities/FacilitiesIndication.h>
|
||||
#include <it2s-asn/itss-facilities/FacilitiesReply.h>
|
||||
#include <it2s-asn/itss-facilities/FacilitiesRequest.h>
|
||||
#include <it2s-asn/itss-management/ManagementIndication.h>
|
||||
#include <it2s-asn/itss-management/ManagementRequest.h>
|
||||
#include <it2s-asn/itss-networking/NetworkingIndication.h>
|
||||
#include <it2s-asn/itss-security/SecurityIndication.h>
|
||||
#include <it2s-asn/itss-security/SecurityReply.h>
|
||||
#include <it2s-asn/itss-security/SecurityRequest.h>
|
||||
#include <it2s-asn/itss-security/SecurityResponse.h>
|
||||
#include <it2s-asn/itss-transport/TransportIndication.h>
|
||||
#include <it2s-asn/itss-transport/TransportRequest.h>
|
||||
#include <it2s-asn/ivim/IVIM.h>
|
||||
#include <it2s-asn/saem/SAEM.h>
|
||||
#include <it2s-asn/verco/VERCOe.h>
|
||||
|
||||
#include <zmq.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <it2s-tender/packet.h>
|
||||
#include <it2s-tender/recorder.h>
|
||||
#include <it2s-tender/space.h>
|
||||
#include <it2s-tender/time.h>
|
||||
#include <it2s-tender/trajectory.h>
|
||||
#include <it2s-tender/recorder.h>
|
||||
#include <it2s-tender/packet.h>
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <zmq.h>
|
||||
|
||||
#include "cam.h"
|
||||
#include "config.h"
|
||||
#include "cpm.h"
|
||||
#include "denm.h"
|
||||
#include "evm.h"
|
||||
#include "indications.h"
|
||||
#include "infrastructure.h"
|
||||
#include "requests.h"
|
||||
#include "saem.h"
|
||||
#include "tpm.h"
|
||||
#include "vcm.h"
|
||||
|
||||
facilities_t facilities = {0};
|
||||
|
||||
|
|
@ -158,6 +157,22 @@ static int transport_indication(void* responder, void** security_socket, uint8_t
|
|||
fwd = true;
|
||||
break;
|
||||
|
||||
case Port_poi: /* EVCSNM */
|
||||
its_msg_descriptor = &asn_DEF_EvcsnPdu;
|
||||
its_msg = calloc(1, sizeof(EvcsnPdu_t));
|
||||
its_msg_type = messageID_evcsn;
|
||||
handled_msg = true;
|
||||
fwd = true;
|
||||
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;
|
||||
handled_msg = true;
|
||||
fwd = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
log_debug("messsage with unhandled BTP port received (%lld), ignoring", tpi->choice.btp.destinationPort);
|
||||
goto cleanup;
|
||||
|
|
@ -198,8 +213,7 @@ static int transport_indication(void* responder, void** security_socket, uint8_t
|
|||
}
|
||||
break;
|
||||
|
||||
case Port_denm:
|
||||
;
|
||||
case 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);
|
||||
|
|
@ -263,7 +277,20 @@ static int transport_indication(void* responder, void** security_socket, uint8_t
|
|||
}
|
||||
fwd = true;
|
||||
break;
|
||||
case Port_poi:
|
||||
if (facilities.evm_args.activate) {
|
||||
evcsnm_check(its_msg);
|
||||
fwd = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case Port_evrsr:
|
||||
if (facilities.evm_args.activate) {
|
||||
evrsrm_check(its_msg);
|
||||
fwd = true;
|
||||
EV_RSR_t *evrsr_request = (EV_RSR_t *)its_msg;
|
||||
evrsrm_recv(evrsr_request);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -367,7 +394,6 @@ static int transport_indication(void* responder, void** security_socket, uint8_t
|
|||
|
||||
itss_queue_send(facilities.tx_queue, buf, enc.encoded + 1, ITSS_TRANSPORT, tpr->id, "TR.packet.tcp");
|
||||
} else {
|
||||
|
||||
if (facilities.tolling.enabled && srep->data->choice.tlsRecv.data.size) {
|
||||
dec = uper_decode_complete(NULL, &asn_DEF_TPM, (void **)&its_msg, srep->data->choice.tlsRecv.data.buf, srep->data->choice.tlsRecv.data.size);
|
||||
if (dec.code) {
|
||||
|
|
@ -522,7 +548,6 @@ cleanup:
|
|||
return rv;
|
||||
}
|
||||
|
||||
|
||||
static int security_indication(void *responder_secured, uint8_t *msg, uint32_t msg_len) {
|
||||
int rv = 0;
|
||||
|
||||
|
|
@ -568,8 +593,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 SecurityIdChangeEventType_commit:;
|
||||
facilities.id.change.stage = ID_CHANGE_COMMIT;
|
||||
|
||||
// Reset lightship
|
||||
|
|
@ -619,7 +643,6 @@ static int security_indication(void* responder_secured, uint8_t *msg, uint32_t m
|
|||
log_error("[networking]<- unhandled idChangeEvent command type");
|
||||
rv = 1;
|
||||
goto cleanup;
|
||||
|
||||
}
|
||||
|
||||
sr->present = SecurityResponse_PR_idChangeEvent;
|
||||
|
|
@ -666,21 +689,18 @@ static int networking_indication(void* responder, uint8_t* msg, uint32_t msg_len
|
|||
|
||||
if (ni->choice.data.mobileNeighbour &&
|
||||
*ni->choice.data.mobileNeighbour) {
|
||||
|
||||
pthread_mutex_lock(&facilities.lightship.lock);
|
||||
facilities.lightship.t_last_vehicle = itss_time_get();
|
||||
facilities.lightship.is_vehicle_near = true;
|
||||
pthread_mutex_unlock(&facilities.lightship.lock);
|
||||
}
|
||||
|
||||
|
||||
cleanup:
|
||||
ASN_STRUCT_FREE(asn_DEF_NetworkingIndication, ni);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
static int management_indication(void *responder, uint8_t *msg, uint32_t msg_len) {
|
||||
int rv = 0;
|
||||
|
||||
|
|
@ -734,7 +754,6 @@ cleanup:
|
|||
return rv;
|
||||
}
|
||||
|
||||
|
||||
void *tx() {
|
||||
int rv = 0;
|
||||
|
||||
|
|
@ -818,7 +837,6 @@ int main() {
|
|||
signal(SIGINT, sigh);
|
||||
signal(SIGKILL, sigh);
|
||||
|
||||
|
||||
facilities.tx_queue = itss_queue_new();
|
||||
lightship_init();
|
||||
den_init();
|
||||
|
|
@ -861,6 +879,10 @@ int main() {
|
|||
pthread_create(&facilities.vc_service, NULL, vc_service, NULL);
|
||||
}
|
||||
|
||||
// EVCSN
|
||||
if (facilities.evm_args.activate)
|
||||
pthread_create(&facilities.evcsn_service, NULL, evcsn_service, NULL);
|
||||
|
||||
security_socket = itss_0connect(facilities.zmq.security_address, ZMQ_REQ);
|
||||
|
||||
uint8_t buffer[ITSS_SDU_MAX_LEN];
|
||||
|
|
@ -948,6 +970,7 @@ int main() {
|
|||
|
||||
// Exit
|
||||
cleanup:
|
||||
pthread_join(facilities.evcsn_service, NULL);
|
||||
pthread_join(facilities.ca_service, NULL);
|
||||
pthread_join(facilities.den_service, NULL);
|
||||
pthread_join(facilities.infrastructure_service, NULL);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include "saem.h"
|
||||
#include "tpm.h"
|
||||
#include "vcm.h"
|
||||
#include "evm.h"
|
||||
|
||||
#include <it2s-tender/epv.h>
|
||||
#include <it2s-tender/database.h>
|
||||
|
|
@ -34,6 +35,7 @@ typedef struct facilities {
|
|||
pthread_t cp_service;
|
||||
pthread_t sa_service;
|
||||
pthread_t vc_service;
|
||||
pthread_t evcsn_service;
|
||||
|
||||
// ZMQ
|
||||
struct {
|
||||
|
|
@ -70,6 +72,9 @@ typedef struct facilities {
|
|||
// PC
|
||||
coordination_t coordination;
|
||||
|
||||
// EVCSN
|
||||
evm_args_t evm_args;
|
||||
|
||||
// Logging
|
||||
struct {
|
||||
bool recorder;
|
||||
|
|
|
|||
|
|
@ -1,22 +1,21 @@
|
|||
#include "facilities.h"
|
||||
#include "cam.h"
|
||||
#include "denm.h"
|
||||
#include "infrastructure.h"
|
||||
#include "requests.h"
|
||||
#include "cpm.h"
|
||||
|
||||
#include <it2s-asn/cpm/CPM.h>
|
||||
#include <it2s-asn/itss-facilities/FacilitiesReply.h>
|
||||
#include <it2s-asn/itss-transport/TransportRequest.h>
|
||||
|
||||
#include <zmq.h>
|
||||
#include <it2s-asn/cpm/CPM.h>
|
||||
#include <it2s-asn/verco/VERCOe.h>
|
||||
|
||||
#include <it2s-tender/time.h>
|
||||
#include <it2s-tender/recorder.h>
|
||||
#include <it2s-tender/packet.h>
|
||||
#include <it2s-tender/recorder.h>
|
||||
#include <it2s-tender/space.h>
|
||||
#include <it2s-tender/time.h>
|
||||
#include <zmq.h>
|
||||
|
||||
#include "cam.h"
|
||||
#include "cpm.h"
|
||||
#include "denm.h"
|
||||
#include "evm.h"
|
||||
#include "facilities.h"
|
||||
#include "infrastructure.h"
|
||||
|
||||
int facilities_request_result_accepted(void *responder) {
|
||||
int rv = 0;
|
||||
|
|
@ -49,7 +48,6 @@ int facilities_request_result_rejected(void* responder) {
|
|||
int facilities_request_single_message(void *responder, FacilitiesMessageRequest_t *frm) {
|
||||
int rv = 0;
|
||||
|
||||
|
||||
TransportRequest_t *tr = calloc(1, sizeof(TransportRequest_t));
|
||||
tr->present = TransportRequest_PR_packet;
|
||||
TransportPacketRequest_t *tpr = &tr->choice.packet;
|
||||
|
|
@ -108,6 +106,14 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
|
|||
bpr->gn.trafficClass = 2;
|
||||
break;
|
||||
|
||||
case ItsMessageType_evrsr:
|
||||
its_msg_def = &asn_DEF_EV_RSR;
|
||||
its_msg = calloc(1, sizeof(EV_RSR_t));
|
||||
bpr->destinationPort = Port_evrsr;
|
||||
bpr->gn.packetTransportType = PacketTransportType_shb;
|
||||
bpr->gn.trafficClass = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
log_error("unrecognized FR message type (%lld)", frm->itsMessageType);
|
||||
facilities_request_result_rejected(responder);
|
||||
|
|
@ -143,14 +149,12 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
|
|||
event_type != EVENT_UPDATE &&
|
||||
event_type != EVENT_CANCELLATION &&
|
||||
event_type != EVENT_NEGATION) {
|
||||
|
||||
fwd = false;
|
||||
}
|
||||
|
||||
if (event_type == EVENT_UPDATE ||
|
||||
event_type == EVENT_CANCELLATION ||
|
||||
event_type == EVENT_NEGATION) {
|
||||
|
||||
is_update = true;
|
||||
}
|
||||
|
||||
|
|
@ -164,7 +168,6 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
|
|||
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));
|
||||
}
|
||||
|
|
@ -229,7 +232,6 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
|
|||
|
||||
ph->list.array[i]->pathDeltaTime = calloc(1, sizeof(PathDeltaTime_t));
|
||||
*ph->list.array[i]->pathDeltaTime = (path_history[i - 1]->ts - path_history[i]->ts) / 10;
|
||||
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&facilities.lightship.lock);
|
||||
|
|
@ -255,14 +257,12 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
|
|||
service_type != SERVICE_UPDATE &&
|
||||
service_type != SERVICE_CANCELLATION &&
|
||||
service_type != SERVICE_NEGATION) {
|
||||
|
||||
fwd = false;
|
||||
}
|
||||
|
||||
if (service_type == SERVICE_UPDATE ||
|
||||
service_type == SERVICE_CANCELLATION ||
|
||||
service_type == SERVICE_NEGATION) {
|
||||
|
||||
is_update = true;
|
||||
}
|
||||
|
||||
|
|
@ -285,8 +285,9 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
|
|||
transmission_interval = facilities.infrastructure.replay_interval;
|
||||
transmission_duration = valid_to - valid_from;
|
||||
}
|
||||
} else if (frm->itsMessageType == ItsMessageType_evrsr) {
|
||||
managed_msg = true;
|
||||
}
|
||||
|
||||
if (!facilities.replay) {
|
||||
transmission_interval = 0;
|
||||
transmission_duration = 0;
|
||||
|
|
@ -311,7 +312,8 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
|
|||
bpr->data.size = (enc.encoded + 7) / 8;
|
||||
|
||||
bpr->gn.destinationAddress.buf = malloc(6);
|
||||
for (int i = 0; i < 6; ++i) bpr->gn.destinationAddress.buf[i] = 0xff;
|
||||
for (int i = 0; i < 6; ++i)
|
||||
bpr->gn.destinationAddress.buf[i] = 0xff;
|
||||
bpr->gn.destinationAddress.size = 6;
|
||||
|
||||
if (transmission_start) {
|
||||
|
|
@ -367,7 +369,8 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
|
|||
}
|
||||
|
||||
cleanup:
|
||||
if (its_msg_def && !managed_msg) ASN_STRUCT_FREE(*its_msg_def, its_msg);
|
||||
if (its_msg_def && !managed_msg)
|
||||
ASN_STRUCT_FREE(*its_msg_def, its_msg);
|
||||
ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr);
|
||||
|
||||
return rv;
|
||||
|
|
@ -522,7 +525,6 @@ cleanup:
|
|||
return rv;
|
||||
}
|
||||
|
||||
|
||||
int facilities_request_loaded_protected_zones(void *responder, FacilitiesRequest_t *freq) {
|
||||
int rv = 0;
|
||||
|
||||
|
|
@ -572,8 +574,7 @@ int facilities_request_chaininfo_set(void* responder, ChainInformationSet_t* cis
|
|||
memcpy(
|
||||
facilities.coordination.chain.links[i],
|
||||
cis->linkSet.list.array[i]->buf,
|
||||
cis->linkSet.list.array[i]->size
|
||||
);
|
||||
cis->linkSet.list.array[i]->size);
|
||||
}
|
||||
facilities.coordination.chain.n_links = cis->linkSet.list.count;
|
||||
// TODO region
|
||||
|
|
@ -600,4 +601,3 @@ cleanup:
|
|||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue