facilities global variable

This commit is contained in:
emanuel 2022-08-23 15:06:27 +01:00
parent 42de2e7a8e
commit 1959f1380d
22 changed files with 608 additions and 586 deletions

122
src/cam.c
View File

@ -85,12 +85,14 @@ static int permissions_check(int cid, uint8_t* permissions, uint8_t permissions_
}
static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len) {
static int mk_cam(uint8_t *cam_oer, uint32_t *cam_len) {
int rv = 0;
int shm_fd, shm_valid = 0;
decoded_can_values_shm* shared_message;
if(facilities->lightship->use_obd){
lightship_t* lightship = &facilities.lightship;
if(lightship->use_obd){
shm_fd = shm_open("it2s-bluetooth-decoded", O_RDONLY, 0666);
if(shm_fd == -1)
syslog_err("[facilities] failed to open CAN shared memory\n");
@ -103,19 +105,18 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len)
cam->header.protocolVersion = 2;
cam->header.messageID = 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;
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;
uint64_t now = itss_time_get();
lightship_t* lightship = facilities->lightship;
pthread_mutex_lock(&lightship->lock);
if (facilities->station_type != StationType_roadSideUnit) {
if (facilities.station_type != StationType_roadSideUnit) {
cam->cam.generationDeltaTime = now % 65536;
itss_space_lock();
@ -132,7 +133,7 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len)
cam->cam.camParameters.highFrequencyContainer.present = HighFrequencyContainer_PR_basicVehicleContainerHighFrequency;
BasicVehicleContainerHighFrequency_t* bvc_hf = &cam->cam.camParameters.highFrequencyContainer.choice.basicVehicleContainerHighFrequency;
if(facilities->lightship->use_obd){
if(lightship->use_obd){
uint8_t ac = 0x00;
// Speed (already getting set bellow)
@ -181,8 +182,8 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len)
bc->referencePosition.positionConfidenceEllipse.semiMajorOrientation = 900;
}
bvc_hf->vehicleWidth = facilities->vehicle.width;
bvc_hf->vehicleLength.vehicleLengthValue = facilities->vehicle.length;
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;
@ -239,7 +240,7 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len)
BasicVehicleContainerLowFrequency_t* bvc_lf = &cam->cam.camParameters.lowFrequencyContainer->choice.basicVehicleContainerLowFrequency;
if(facilities->lightship->use_obd){
if(lightship->use_obd){
uint8_t el = 0x00;
// Exterior Lights
@ -305,36 +306,36 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len)
cam->cam.camParameters.highFrequencyContainer.present = HighFrequencyContainer_PR_rsuContainerHighFrequency;
if (facilities->lightship->protected_zones.pz_len > 0) {
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;
pzs->list.count = facilities->lightship->protected_zones.pz_len;
pzs->list.size = facilities->lightship->protected_zones.pz_len * sizeof(void*);
pzs->list.array = malloc(facilities->lightship->protected_zones.pz_len * sizeof(void*));
for (int i = 0; i < facilities->lightship->protected_zones.pz_len; ++i) {
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]->protectedZoneLatitude = facilities->lightship->protected_zones.pz[i]->protectedZoneLatitude;
pzs->list.array[i]->protectedZoneLongitude = facilities->lightship->protected_zones.pz[i]->protectedZoneLongitude;
pzs->list.array[i]->protectedZoneType = facilities->lightship->protected_zones.pz[i]->protectedZoneType;
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;
if (facilities->lightship->protected_zones.pz[i]->expiryTime) {
pzs->list.array[i]->expiryTime->size = facilities->lightship->protected_zones.pz[i]->expiryTime->size;
pzs->list.array[i]->expiryTime->buf = malloc(facilities->lightship->protected_zones.pz[i]->expiryTime->size);
memcpy(pzs->list.array[i]->expiryTime->buf, facilities->lightship->protected_zones.pz[i]->expiryTime->buf, facilities->lightship->protected_zones.pz[i]->expiryTime->size);
if (lightship->protected_zones.pz[i]->expiryTime) {
pzs->list.array[i]->expiryTime->size = lightship->protected_zones.pz[i]->expiryTime->size;
pzs->list.array[i]->expiryTime->buf = malloc(lightship->protected_zones.pz[i]->expiryTime->size);
memcpy(pzs->list.array[i]->expiryTime->buf, lightship->protected_zones.pz[i]->expiryTime->buf, lightship->protected_zones.pz[i]->expiryTime->size);
}
if (facilities->lightship->protected_zones.pz[i]->protectedZoneID) {
if (lightship->protected_zones.pz[i]->protectedZoneID) {
pzs->list.array[i]->protectedZoneID = malloc(8);
*pzs->list.array[i]->protectedZoneID = *facilities->lightship->protected_zones.pz[i]->protectedZoneID;
*pzs->list.array[i]->protectedZoneID = *lightship->protected_zones.pz[i]->protectedZoneID;
}
if (facilities->lightship->protected_zones.pz[i]->protectedZoneRadius) {
if (lightship->protected_zones.pz[i]->protectedZoneRadius) {
pzs->list.array[i]->protectedZoneRadius = malloc(8);
*pzs->list.array[i]->protectedZoneRadius = *facilities->lightship->protected_zones.pz[i]->protectedZoneRadius;
*pzs->list.array[i]->protectedZoneRadius = *lightship->protected_zones.pz[i]->protectedZoneRadius;
}
}
}
}
pthread_mutex_unlock(&facilities->lightship->lock);
pthread_mutex_unlock(&lightship->lock);
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_CAM, NULL, cam, cam_oer, 512);
@ -345,7 +346,7 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len)
}
*cam_len = (enc.encoded + 7) / 8;
if(facilities->lightship->use_obd){
if(lightship->use_obd){
munmap(shared_message, sizeof(can_values_shm));
if(close(shm_fd) == -1)
syslog_err("[facilities] failed to close CAN shared memory\n");
@ -358,8 +359,9 @@ cleanup:
}
lightship_t* lightship_init() {
lightship_t* lightship = (lightship_t*) calloc(1, sizeof(lightship_t));
int lightship_init() {
lightship_t* lightship = &facilities.lightship;
lightship->protected_zones.pz = calloc(256 , sizeof(void*));
pthread_mutex_init(&lightship->lock, NULL);
@ -379,13 +381,15 @@ lightship_t* lightship_init() {
close(shm_fd);
}
return lightship;
return 0;
}
int lightship_check(lightship_t* lightship) {
int lightship_check() {
int rv = 0;
lightship_t* lightship = &facilities.lightship;
uint64_t now = itss_time_get();
pthread_mutex_lock(&lightship->lock);
@ -445,7 +449,10 @@ int lightship_check(lightship_t* lightship) {
return rv;
}
void lightship_reset_timer(lightship_t* lightship) {
void lightship_reset_timer() {
lightship_t* lightship = &facilities.lightship;
uint64_t now = itss_time_get();
pthread_mutex_lock(&lightship->lock);
@ -463,10 +470,9 @@ void lightship_reset_timer(lightship_t* lightship) {
pthread_mutex_unlock(&lightship->lock);
}
enum CAM_CHECK_R check_cam(void* fc, BTPPacketIndication_t *bpi, CAM_t* cam, uint8_t* ssp, uint32_t ssp_len) {
enum CAM_CHECK_R check_cam(BTPPacketIndication_t *bpi, CAM_t* cam, uint8_t* ssp, uint32_t ssp_len) {
int rv = 0;
facilities_t* facilities = (facilities_t*) fc;
lightship_t *lightship = ((facilities_t*) fc)->lightship;
lightship_t* lightship = &facilities.lightship;
uint64_t now = itss_time_get();
@ -657,10 +663,10 @@ enum CAM_CHECK_R check_cam(void* fc, BTPPacketIndication_t *bpi, CAM_t* cam, uin
}
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_ManagementRequest, NULL, mreq, b_oer, 512);
void* management_socket = zmq_socket(facilities->zmq.ctx, ZMQ_REQ);
void* management_socket = zmq_socket(facilities.zmq.ctx, ZMQ_REQ);
int wait_ms = 1000;
zmq_setsockopt(management_socket, ZMQ_RCVTIMEO, &wait_ms, sizeof(int));
zmq_connect(management_socket, facilities->zmq.management_address);
zmq_connect(management_socket, facilities.zmq.management_address);
zmq_send(management_socket, b_oer, enc.encoded, 0);
syslog_debug("[facilities] [ca]-> sending MReq.attributes.set.protectedZones to ->[management]");
uint8_t code;
@ -675,7 +681,10 @@ enum CAM_CHECK_R check_cam(void* fc, BTPPacketIndication_t *bpi, CAM_t* cam, uin
return rv;
}
static int check_pz(lightship_t *lightship) {
static int check_pz() {
lightship_t* lightship = &facilities.lightship;
bool is_inside = false;
itss_space_lock();
@ -703,9 +712,8 @@ static int check_pz(lightship_t *lightship) {
return is_inside;
}
void *ca_service(void *fc) {
void *ca_service() {
int rv = 0;
facilities_t *facilities = (facilities_t*) fc;
TransportRequest_t* tr = calloc(1, sizeof(TransportRequest_t));
tr->present = TransportRequest_PR_packet;
@ -743,11 +751,11 @@ void *ca_service(void *fc) {
uint8_t fi_oer[1024];
tr_oer[0] = 4; // Facilities
fi_oer[0] = 4;
while (!facilities->exit) {
while (!facilities.exit) {
usleep(1000*50);
if (lightship_check(facilities->lightship) && facilities->lightship->active) {
rv = mk_cam(facilities, bpr->data.buf, (uint32_t *) &bpr->data.size);
if (lightship_check() && facilities.lightship.active) {
rv = mk_cam(bpr->data.buf, (uint32_t *) &bpr->data.size);
if (rv) {
continue;
}
@ -756,7 +764,7 @@ void *ca_service(void *fc) {
// Check if inside PZ
bpr->gn.communicationProfile = 0;
if (facilities->station_type != 15 && check_pz(facilities->lightship)) bpr->gn.communicationProfile = 1;
if (facilities.station_type != 15 && check_pz(facilities.lightship)) bpr->gn.communicationProfile = 1;
uint32_t id = itss_id(bpr->data.buf, bpr->data.size);
bpr->id = id;
@ -774,21 +782,21 @@ void *ca_service(void *fc) {
continue;
}
itss_queue_send(facilities->tx_queue, tr_oer, enc.encoded+1, ITSS_TRANSPORT, id, "TR.packet.btp");
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");
itss_queue_send(facilities.tx_queue, fi_oer, enc_fdi.encoded+1, ITSS_APPLICATIONS, id, "FI.message");
lightship_reset_timer(facilities->lightship);
lightship_reset_timer();
// Logging
if (facilities->logging.dbms) {
pthread_mutex_lock(&facilities->id.lock);
uint64_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_cam, NULL, bpr->data.buf, bpr->data.size);
if (facilities.logging.dbms) {
pthread_mutex_lock(&facilities.id.lock);
uint64_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_cam, NULL, bpr->data.buf, bpr->data.size);
}
if (facilities->logging.recorder) {
if (facilities.logging.recorder) {
uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len];
int e = itss_management_record_packet_sdu(
@ -801,7 +809,7 @@ void *ca_service(void *fc) {
ITSS_FACILITIES,
true);
if (e != -1) {
itss_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set");
itss_queue_send(facilities.tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set");
}
}
}

View File

@ -86,12 +86,12 @@ typedef struct lightship {
} lightship_t;
lightship_t* lightship_init();
int lightship_init();
int lightship_check(lightship_t* lightship);
void lightship_reset_timer(lightship_t*lightship);
int lightship_check();
void lightship_reset_timer();
enum CAM_CHECK_R check_cam(void* fc, BTPPacketIndication_t* bpi, CAM_t* cam,uint8_t* ssp, uint32_t ssp_len);
void* ca_service(void* fc);
enum CAM_CHECK_R check_cam(BTPPacketIndication_t* bpi, CAM_t* cam,uint8_t* ssp, uint32_t ssp_len);
void* ca_service();
#endif

View File

@ -44,17 +44,16 @@ static int fetch_target_address(char** addresses, uint16_t addresses_len) {
return index;
}
int facilities_config(void* facilities_s) {
int facilities_config() {
int rv = 0;
facilities_t *facilities = (facilities_t*) facilities_s;
it2s_config_t* config = calloc(1, sizeof(it2s_config_t));
rv = it2s_config_read("/etc/it2s/itss.toml", config);
if (rv) goto cleanup;
facilities->zmq.responders = calloc(config->facilities.zmq.addresses_len, sizeof(zmq_pollitem_t));
facilities->zmq.n_responders = 0;
facilities.zmq.responders = calloc(config->facilities.zmq.addresses_len, sizeof(zmq_pollitem_t));
facilities.zmq.n_responders = 0;
for (int i = 0; i < config->facilities.zmq.addresses_len; ++i) {
char* addr = config->facilities.zmq.addresses[i];
@ -78,12 +77,12 @@ int facilities_config(void* facilities_s) {
}
// Bind
void* socket = zmq_socket(facilities->zmq.ctx, ZMQ_REP);
void* socket = zmq_socket(facilities.zmq.ctx, ZMQ_REP);
zmq_bind(socket, addr);
facilities->zmq.responders[facilities->zmq.n_responders].socket = socket;
facilities->zmq.responders[facilities->zmq.n_responders].events = ZMQ_POLLIN;
++facilities->zmq.n_responders;
facilities.zmq.responders[facilities.zmq.n_responders].socket = socket;
facilities.zmq.responders[facilities.zmq.n_responders].events = ZMQ_POLLIN;
++facilities.zmq.n_responders;
} else if (!memcmp(addr, "tcp", 3)) {
@ -97,16 +96,16 @@ int facilities_config(void* facilities_s) {
if (found_astk) {
// Bind
void* socket = zmq_socket(facilities->zmq.ctx, ZMQ_REP);
void* socket = zmq_socket(facilities.zmq.ctx, ZMQ_REP);
zmq_bind(socket, addr);
facilities->zmq.responders[facilities->zmq.n_responders].socket = socket;
facilities->zmq.responders[facilities->zmq.n_responders].events = ZMQ_POLLIN;
++facilities->zmq.n_responders;
facilities.zmq.responders[facilities.zmq.n_responders].socket = socket;
facilities.zmq.responders[facilities.zmq.n_responders].events = ZMQ_POLLIN;
++facilities.zmq.n_responders;
}
}
}
if (!facilities->zmq.n_responders) {
if (!facilities.zmq.n_responders) {
syslog_info("[facilities] [config] a valid address to listen to was not found, exiting now");
rv = 1;
goto cleanup;
@ -115,8 +114,8 @@ int facilities_config(void* facilities_s) {
// Fetch [transport] address
int index = fetch_target_address(config->transport.zmq.addresses, config->transport.zmq.addresses_len);
if (index != -1) {
facilities->zmq.transport_address = malloc(strlen(config->transport.zmq.addresses[index])+1);
strcpy(facilities->zmq.transport_address, config->transport.zmq.addresses[index]);
facilities.zmq.transport_address = malloc(strlen(config->transport.zmq.addresses[index])+1);
strcpy(facilities.zmq.transport_address, config->transport.zmq.addresses[index]);
} else {
syslog_err("[facilities] [config] a valid address for [transport] was not found");
rv = 1;
@ -126,8 +125,8 @@ int facilities_config(void* facilities_s) {
// Fetch [applications] address
index = fetch_target_address(config->applications.zmq.addresses, config->applications.zmq.addresses_len);
if (index != -1) {
facilities->zmq.applications_address = malloc(strlen(config->applications.zmq.addresses[index])+1);
strcpy(facilities->zmq.applications_address, config->applications.zmq.addresses[index]);
facilities.zmq.applications_address = malloc(strlen(config->applications.zmq.addresses[index])+1);
strcpy(facilities.zmq.applications_address, config->applications.zmq.addresses[index]);
} else {
syslog_err("[facilities] [config] a valid address for [applications] was not found");
rv = 1;
@ -137,8 +136,8 @@ int facilities_config(void* facilities_s) {
// Fetch [security] address
index = fetch_target_address(config->security.zmq.addresses, config->security.zmq.addresses_len);
if (index != -1) {
facilities->zmq.security_address = malloc(strlen(config->security.zmq.addresses[index])+1);
strcpy(facilities->zmq.security_address, config->security.zmq.addresses[index]);
facilities.zmq.security_address = malloc(strlen(config->security.zmq.addresses[index])+1);
strcpy(facilities.zmq.security_address, config->security.zmq.addresses[index]);
} else {
syslog_err("[facilities] [config] a valid address for [security] was not found");
rv = 1;
@ -148,8 +147,8 @@ int facilities_config(void* facilities_s) {
// Fetch [management] address
index = fetch_target_address(config->management.zmq.addresses, config->management.zmq.addresses_len);
if (index != -1) {
facilities->zmq.management_address = malloc(strlen(config->management.zmq.addresses[index])+1);
strcpy(facilities->zmq.management_address, config->management.zmq.addresses[index]);
facilities.zmq.management_address = malloc(strlen(config->management.zmq.addresses[index])+1);
strcpy(facilities.zmq.management_address, config->management.zmq.addresses[index]);
} else {
syslog_err("[facilities] [config] a valid address for [management] was not found");
rv = 1;
@ -159,48 +158,48 @@ int facilities_config(void* facilities_s) {
// Values
// General
if (!strcmp("obu", config->general.itss_type)) {
facilities->station_type = 5;
facilities.station_type = 5;
} else if (!strcmp("rsu", config->general.itss_type)) {
facilities->station_type = 15;
facilities.station_type = 15;
} else if (!strcmp("unknown", config->general.itss_type)) {
facilities->station_type = 0;
facilities.station_type = 0;
} else if (!strcmp("pedestrian", config->general.itss_type)) {
facilities->station_type = 1;
facilities.station_type = 1;
} else if (!strcmp("cyclist", config->general.itss_type)) {
facilities->station_type = 2;
facilities.station_type = 2;
} else if (!strcmp("moped", config->general.itss_type)) {
facilities->station_type = 3;
facilities.station_type = 3;
} else if (!strcmp("motorcycle", config->general.itss_type)) {
facilities->station_type = 4;
facilities.station_type = 4;
} else if (!strcmp("passengerCar", config->general.itss_type)) {
facilities->station_type = 5;
facilities.station_type = 5;
} else if (!strcmp("bus", config->general.itss_type)) {
facilities->station_type = 6;
facilities.station_type = 6;
} else if (!strcmp("lightTruck", config->general.itss_type)) {
facilities->station_type = 7;
facilities.station_type = 7;
} else if (!strcmp("heavyTruck", config->general.itss_type)) {
facilities->station_type = 8;
facilities.station_type = 8;
} else if (!strcmp("trailer", config->general.itss_type)) {
facilities->station_type = 9;
facilities.station_type = 9;
} else if (!strcmp("specialVehicles", config->general.itss_type)) {
facilities->station_type = 10;
facilities.station_type = 10;
} else if (!strcmp("tram", config->general.itss_type)) {
facilities->station_type = 11;
facilities.station_type = 11;
} else if (!strcmp("roadSideUnit", config->general.itss_type)) {
facilities->station_type = 15;
facilities.station_type = 15;
} else {
syslog_err("[facilities] [config] unrecognized ITS-S type, running as OBU");
facilities->station_type = 5;
facilities.station_type = 5;
}
facilities->use_security = config->security.use_security;
facilities.use_security = config->security.use_security;
pthread_mutex_init(&facilities->id.lock, NULL);
pthread_mutex_init(&facilities->id.change.lock, NULL);
pthread_mutex_init(&facilities.id.lock, NULL);
pthread_mutex_init(&facilities.id.change.lock, NULL);
facilities->id.change.random = config->security.identity.random;
if (facilities->id.change.random) {
facilities.id.change.random = config->security.identity.random;
if (facilities.id.change.random) {
// Ask [security] for station id
SecurityRequest_t* sREQ = calloc(1, sizeof(SecurityRequest_t));
@ -218,8 +217,8 @@ int facilities_config(void* facilities_s) {
uint8_t b_sdu[256];
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sREQ, b_sdu, 256);
void* ss = zmq_socket(facilities->zmq.ctx, ZMQ_REQ);
zmq_connect(ss, facilities->zmq.security_address);
void* ss = zmq_socket(facilities.zmq.ctx, ZMQ_REQ);
zmq_connect(ss, facilities.zmq.security_address);
zmq_send(ss, b_sdu, enc.encoded, 0);
zmq_recv(ss, b_sdu, 256, 0);
zmq_close(ss);
@ -234,10 +233,10 @@ int facilities_config(void* facilities_s) {
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:
facilities->id.station_id = sREP->data->choice.ids.list.array[i]->choice.stationId;
facilities.id.station_id = sREP->data->choice.ids.list.array[i]->choice.stationId;
break;
case SecurityId_PR_ipv6Address:
memcpy(facilities->id.ipv6_addr, sREP->data->choice.ids.list.array[i]->choice.ipv6Address.buf, 16);
memcpy(facilities.id.ipv6_addr, sREP->data->choice.ids.list.array[i]->choice.ipv6Address.buf, 16);
break;
default:
break;
@ -248,7 +247,7 @@ int facilities_config(void* facilities_s) {
ASN_STRUCT_FREE(asn_DEF_SecurityReply, sREP);
} else {
facilities->id.station_id = config->security.identity.station_id;
facilities.id.station_id = config->security.identity.station_id;
uint8_t src_mac[6];
unsigned int tmp_uint[6];
@ -268,69 +267,69 @@ int facilities_config(void* facilities_s) {
src_mac[4] = (uint8_t)tmp_uint[4];
src_mac[5] = (uint8_t)tmp_uint[5];
memset(facilities->id.ipv6_addr, 0, 8);
memcpy(facilities->id.ipv6_addr+8, src_mac, 3);
facilities->id.ipv6_addr[11] = 0xff;
facilities->id.ipv6_addr[12] = 0xfe;
memcpy(facilities->id.ipv6_addr+13, src_mac+3, 3);
facilities->id.ipv6_addr[8] ^= 0x02;
memset(facilities.id.ipv6_addr, 0, 8);
memcpy(facilities.id.ipv6_addr+8, src_mac, 3);
facilities.id.ipv6_addr[11] = 0xff;
facilities.id.ipv6_addr[12] = 0xfe;
memcpy(facilities.id.ipv6_addr+13, src_mac+3, 3);
facilities.id.ipv6_addr[8] ^= 0x02;
}
// DENM
facilities->den->n_max_events = config->facilities.denm.nmax_active_events;
facilities.den.n_max_events = config->facilities.denm.nmax_active_events;
// CAM
facilities->lightship->active = config->facilities.cam.activate;
facilities->lightship->vehicle_gen_min = config->facilities.cam.obu_period_min;
facilities->lightship->vehicle_gen_max = config->facilities.cam.obu_period_max;
facilities->lightship->rsu_gen_min = config->facilities.cam.rsu_period_min;
facilities->lightship->rsu_vehicle_permanence = config->facilities.cam.rsu_vehicle_permanence;
facilities.lightship.active = config->facilities.cam.activate;
facilities.lightship.vehicle_gen_min = config->facilities.cam.obu_period_min;
facilities.lightship.vehicle_gen_max = config->facilities.cam.obu_period_max;
facilities.lightship.rsu_gen_min = config->facilities.cam.rsu_period_min;
facilities.lightship.rsu_vehicle_permanence = config->facilities.cam.rsu_vehicle_permanence;
// IVIM
facilities->infrastructure->n_max_services = config->facilities.ivim.nmax_active_services;
facilities->infrastructure->replay_interval = config->facilities.ivim.replay_interval;
facilities->infrastructure->default_service_duration = config->facilities.ivim.default_service_duration * 60000;
facilities.infrastructure.n_max_services = config->facilities.ivim.nmax_active_services;
facilities.infrastructure.replay_interval = config->facilities.ivim.replay_interval;
facilities.infrastructure.default_service_duration = config->facilities.ivim.default_service_duration * 60000;
// CPM
facilities->dissemination->active = config->facilities.cpm.activate;
facilities->dissemination->T_GenCpmMin = config->facilities.cpm.rsu_obu_period_min;
facilities->dissemination->T_GenCpmMax = config->facilities.cpm.rsu_obu_period_max;
facilities->dissemination->radar_rotation = config->applications.its_center.radar_rotation;
facilities->dissemination->tmc_connect = config->facilities.cpm.tmc_connected;
facilities->dissemination->T_AddSensorInformation = 1000;
facilities.dissemination.active = config->facilities.cpm.activate;
facilities.dissemination.T_GenCpmMin = config->facilities.cpm.rsu_obu_period_min;
facilities.dissemination.T_GenCpmMax = config->facilities.cpm.rsu_obu_period_max;
facilities.dissemination.radar_rotation = config->applications.its_center.radar_rotation;
facilities.dissemination.tmc_connect = config->facilities.cpm.tmc_connected;
facilities.dissemination.T_AddSensorInformation = 1000;
facilities->dissemination->int_radar = malloc(strlen(config->facilities.cpm.radar_interface)+1);
strcpy(facilities->dissemination->int_radar,config->facilities.cpm.radar_interface);
facilities->dissemination->ip_radar = malloc(strlen(config->facilities.cpm.radar_ip)+1);
strcpy(facilities->dissemination->ip_radar,config->facilities.cpm.radar_ip);
facilities.dissemination.int_radar = malloc(strlen(config->facilities.cpm.radar_interface)+1);
strcpy(facilities.dissemination.int_radar,config->facilities.cpm.radar_interface);
facilities.dissemination.ip_radar = malloc(strlen(config->facilities.cpm.radar_ip)+1);
strcpy(facilities.dissemination.ip_radar,config->facilities.cpm.radar_ip);
// TPM
facilities->tolling.enabled = config->facilities.tpm.activate;
facilities.tolling.enabled = config->facilities.tpm.activate;
if (!strcmp("simple", config->facilities.tpm.protocol)) {
facilities->tolling.protocol.p = TOLLING_PROTOCOL_SIMPLE;
facilities.tolling.protocol.p = TOLLING_PROTOCOL_SIMPLE;
} else if (!strcmp("tls", config->facilities.tpm.protocol)) {
facilities->tolling.protocol.p = TOLLING_PROTOCOL_TLS;
facilities.tolling.protocol.p = TOLLING_PROTOCOL_TLS;
} else if (!strcmp("tls-gn", config->facilities.tpm.protocol)) {
facilities->tolling.protocol.p = TOLLING_PROTOCOL_TLS_GN;
facilities.tolling.protocol.p = TOLLING_PROTOCOL_TLS_GN;
} else if (!strcmp("tls-shs", config->facilities.tpm.protocol)) {
facilities->tolling.protocol.p = TOLLING_PROTOCOL_TLS_SHS;
facilities.tolling.protocol.p = TOLLING_PROTOCOL_TLS_SHS;
} else {
syslog_err("[facilities] [config] unrecognized tolling protocol, defaulting to 'simple'");
facilities->tolling.protocol.p = TOLLING_PROTOCOL_SIMPLE;
facilities.tolling.protocol.p = TOLLING_PROTOCOL_SIMPLE;
}
facilities->tolling.station.obu.client_id = config->facilities.tpm.client_id;
facilities.tolling.station.obu.client_id = config->facilities.tpm.client_id;
// VCM
facilities->coordination.active = config->facilities.dcm.activate;
facilities->coordination.vcm_period_min = config->facilities.dcm.period_min;
facilities->coordination.vcm_period_max = config->facilities.dcm.period_max;
facilities.coordination.active = config->facilities.dcm.activate;
facilities.coordination.vcm_period_min = config->facilities.dcm.period_min;
facilities.coordination.vcm_period_max = config->facilities.dcm.period_max;
// Replay
facilities->replay = config->networking.replay.activate;
facilities.replay = config->networking.replay.activate;
// PZ
if (facilities->station_type == 15) {
if (facilities.station_type == 15) {
int i = 0;
@ -361,8 +360,8 @@ int facilities_config(void* facilities_s) {
asn_dec_rval_t dec = xer_decode(NULL, &asn_DEF_ProtectedCommunicationZone, (void**) &zone, pz_xml, size);
if (!dec.code) {
facilities->lightship->protected_zones.pz[i] = zone;
++facilities->lightship->protected_zones.pz_len;
facilities.lightship.protected_zones.pz[i] = zone;
++facilities.lightship.protected_zones.pz_len;
++i;
syslog_debug("[facilities] [config] loaded protection zone @ (%lld, %lld)", zone->protectedZoneLatitude, zone->protectedZoneLongitude);
} else {
@ -376,7 +375,7 @@ int facilities_config(void* facilities_s) {
}
// TZ
if (facilities->station_type == 15) {
if (facilities.station_type == 15) {
int i = 0;
@ -407,9 +406,9 @@ int facilities_config(void* facilities_s) {
asn_dec_rval_t dec = xer_decode(NULL, &asn_DEF_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;
++facilities->tolling.infos.length;
facilities.tolling.infos.z[i] = calloc(1, sizeof(tolling_info_t));
facilities.tolling.infos.z[i]->asn = ti;
++facilities.tolling.infos.length;
++i;
syslog_debug("[facilities] [config] loaded tolling info | id:%lld type:%s",
ti->id,
@ -439,8 +438,8 @@ int facilities_config(void* facilities_s) {
mreq->choice.attributes.choice.get.clock = 1;
mreq->choice.attributes.choice.get.clockOffset = 1;
mreq->choice.attributes.choice.get.trajectory = config->facilities.dcm.activate;
void* management_socket = zmq_socket(facilities->zmq.ctx, ZMQ_REQ);
zmq_connect(management_socket, facilities->zmq.management_address);
void* management_socket = zmq_socket(facilities.zmq.ctx, ZMQ_REQ);
zmq_connect(management_socket, facilities.zmq.management_address);
uint8_t buffer[256];
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_ManagementRequest, NULL, mreq, buffer, 256);
@ -496,22 +495,22 @@ int facilities_config(void* facilities_s) {
zmq_close(management_socket);
if (config->facilities.saem.activate) {
facilities->bulletin.to_provide_len = 1;
facilities->bulletin.to_provide[0] = calloc(1, sizeof(announcement_t));
facilities->bulletin.to_provide[0]->endpoint.port = 7011;
facilities->bulletin.to_provide[0]->its_aid = config->facilities.saem.service_to_advertise;
facilities.bulletin.to_provide_len = 1;
facilities.bulletin.to_provide[0] = calloc(1, sizeof(announcement_t));
facilities.bulletin.to_provide[0]->endpoint.port = 7011;
facilities.bulletin.to_provide[0]->its_aid = config->facilities.saem.service_to_advertise;
}
facilities->vehicle.length = config->facilities.vehicle.length;
facilities->vehicle.width = config->facilities.vehicle.width;
facilities->vehicle.role = config->facilities.vehicle.role;
facilities.vehicle.length = config->facilities.vehicle.length;
facilities.vehicle.width = config->facilities.vehicle.width;
facilities.vehicle.role = config->facilities.vehicle.role;
// Logging
facilities->logging.recorder = config->facilities.logging.management;
facilities.logging.recorder = config->facilities.logging.management;
if (config->general.logging.enabled && config->facilities.logging.dbms) {
facilities->logging.dbms = calloc(1, sizeof(itss_db_t));
facilities.logging.dbms = calloc(1, sizeof(itss_db_t));
if (itss_db_init(
facilities->logging.dbms,
facilities.logging.dbms,
config->general.logging.database,
config->general.logging.table_style,
ITSS_FACILITIES,
@ -521,8 +520,8 @@ int facilities_config(void* facilities_s) {
config->general.logging.password
)) {
syslog_err("[facilities] failed to initialize the database -> turning off logging");
free(facilities->logging.dbms);
facilities->logging.dbms = NULL;
free(facilities.logging.dbms);
facilities.logging.dbms = NULL;
}
}

View File

@ -1,6 +1,4 @@
#ifndef FACILITIES_CONFIG_H
#define FACILITIES_CONFIG_H
#pragma once
int facilities_config(void *facilities_s);
int facilities_config();
#endif

View File

@ -37,7 +37,7 @@ S_INTERFACE_CONNECTION_T raw_socket;
S_OBJECT_CONTROL_T s_objectControl;
S_OBJECTS_T as_objects[NOF_OBJECTS];
int radar_ready(facilities_t* facilities){
int radar_ready(){
// Create temporary ifr struct and socket to
// check if the radar interface is running i.e if the
// radar has booted up
@ -47,7 +47,7 @@ int radar_ready(facilities_t* facilities){
int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
strncpy(ifr.ifr_name, facilities->dissemination->int_radar, sizeof(ifr.ifr_name));
strncpy(ifr.ifr_name, facilities.dissemination.int_radar, sizeof(ifr.ifr_name));
if(ioctl(sock, SIOCGIFFLAGS, &ifr) <0)
syslog_err(" IOCTL failed, could not retrieve radar interface flags");
@ -58,9 +58,9 @@ int radar_ready(facilities_t* facilities){
bool radar_connection(char* radar_port, facilities_t* facilities){
if(radar_ready(facilities) == 1){
if(facilities->dissemination->tmc_connect == false){
bool radar_connection(char* radar_port){
if(radar_ready() == 1){
if(facilities.dissemination.tmc_connect == false){
// Create TCP socket
s_socket.i32_socket = socket(AF_INET, SOCK_STREAM, 0);
@ -73,7 +73,7 @@ bool radar_connection(char* radar_port, facilities_t* facilities){
// Bind it to server address and port
bzero(&s_socket.s_server, sizeof(s_socket.s_server));
s_socket.s_server.sin_family = AF_INET;
s_socket.s_server.sin_addr.s_addr = inet_addr(facilities->dissemination->ip_radar);
s_socket.s_server.sin_addr.s_addr = inet_addr(facilities.dissemination.ip_radar);
s_socket.s_server.sin_port = htons(atoi(radar_port));
if(bind(s_socket.i32_socket, (struct sockaddr*)&s_socket.s_server,sizeof(s_socket.s_server)) < 0){
@ -112,7 +112,7 @@ bool radar_connection(char* radar_port, facilities_t* facilities){
bzero(&raw_socket.sll, sizeof(raw_socket.sll));
bzero(&raw_socket.ifr, sizeof(raw_socket.ifr));
strncpy((char *)raw_socket.ifr.ifr_name, facilities->dissemination->int_radar, IFNAMSIZ);
strncpy((char *)raw_socket.ifr.ifr_name, facilities.dissemination.int_radar, IFNAMSIZ);
if((ioctl(raw_socket.raw_fd, SIOCGIFINDEX, &raw_socket.ifr)) == -1){
syslog_err("Error getting interface index");
return false;
@ -146,9 +146,11 @@ dissemination_t* dissemination_init(){
}
int dissemination_check(dissemination_t* dissemination, int f) {
int dissemination_check(int f) {
int rv = 0;
dissemination_t* dissemination = &facilities.dissemination;
uint64_t now = itss_time_get();
pthread_mutex_lock(&dissemination->lock); // mutex is used to lock shared resources
@ -176,8 +178,9 @@ int dissemination_check(dissemination_t* dissemination, int f) {
}
void dissemination_reset_timer(dissemination_t* dissemination, int f){
void dissemination_reset_timer(int f){
dissemination_t* dissemination = &facilities.dissemination;
uint64_t now = itss_time_get();
/* Both cases for RSU and OBU */
@ -501,7 +504,7 @@ static void set_values(int i, int j, uint64_t timestamp, CPM_t* cpm_tx, long his
}
static int mk_cpm(facilities_t* facilities, 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[]) {
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));
@ -513,9 +516,9 @@ static int mk_cpm(facilities_t* facilities, uint8_t *bdr_oer, uint32_t *bdr_len,
cpm_tx->header.protocolVersion = PROTOCOL_VERSION;
cpm_tx->header.messageID = MESSAGE_ID;
pthread_mutex_lock(&facilities->id.lock);
cpm_tx->header.stationID = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock);
pthread_mutex_lock(&facilities.id.lock);
cpm_tx->header.stationID = facilities.id.station_id;
pthread_mutex_unlock(&facilities.id.lock);
uint64_t generationDeltaTime = itss_time_get() % 65536; // generationDeltaTime = TimestampIts mod 65 536
@ -538,7 +541,7 @@ static int mk_cpm(facilities_t* facilities, uint8_t *bdr_oer, uint32_t *bdr_len,
cpm_tx->cpm.cpmParameters.managementContainer.referencePosition.altitude.altitudeValue = alt;
cpm_tx->cpm.cpmParameters.managementContainer.referencePosition.altitude.altitudeConfidence = alt_conf;
if(dissemination_check(facilities->dissemination,0) == 1){ /* Sensor Information Container Inclusion Management */
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->list.count = 1;
@ -558,7 +561,7 @@ static int mk_cpm(facilities_t* facilities, uint8_t *bdr_oer, uint32_t *bdr_len,
(*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) = 600;
dissemination_reset_timer(facilities->dissemination, 0);
dissemination_reset_timer(0);
}
if (s_objectControl.u8_numberOfObjects > 0) {
@ -591,7 +594,7 @@ static int mk_cpm(facilities_t* facilities, uint8_t *bdr_oer, uint32_t *bdr_len,
// Requirements to include the object in the CPM (> 4 m or > 0.5 m/s or > 4º or > T_GenCpmMax)
if(abs(euclidian_dist) > 400 || abs(abs_speed - abs_speed_hist) > 50 || abs(angle_diff) > 4 || abs(generationDeltaTime - history_timestamp[i]) >= facilities->dissemination->T_GenCpmMax){
if(abs(euclidian_dist) > 400 || abs(abs_speed - abs_speed_hist) > 50 || abs(angle_diff) > 4 || abs(generationDeltaTime - history_timestamp[i]) >= facilities.dissemination.T_GenCpmMax){
set_values(i,j,generationDeltaTime,cpm_tx, history_list, valid_array,history_timestamp);
j++;
@ -639,7 +642,7 @@ cleanup:
return rv;
}
void *cp_service(void *fc){
void *cp_service(){
/* Variables */
int i32_recv_bytes;
u_int8_t au8_readBuffer[READ_BUFFER_SIZE];
@ -649,7 +652,6 @@ void *cp_service(void *fc){
int valid_array[NOF_OBJECTS];
uint64_t history_timestamp[NOF_OBJECTS];
facilities_t *facilities = (facilities_t *) fc;
memset(history_list, 0, sizeof(history_list));
memset(valid_array, 0, sizeof(valid_array));
memset(history_timestamp, 0, sizeof(history_timestamp));
@ -669,8 +671,8 @@ void *cp_service(void *fc){
fi->present = FacilitiesIndication_PR_message;
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);
roadRotationSin = sin(((facilities.dissemination.radar_rotation + 90.0) * PI) / 180);
roadRotationCos = cos(((facilities.dissemination.radar_rotation + 90.0) * PI) / 180);
/*--- Fill mandatory BTP Data Request parameters ---*/
bpr->gn.destinationAddress.buf = malloc(6);
@ -695,26 +697,26 @@ void *cp_service(void *fc){
fmi->data.buf = malloc(1500);
/* Creating sockets and waiting for radar to connect*/
is_radar_connected = radar_connection(RADAR_PORT,facilities);
is_radar_connected = radar_connection(RADAR_PORT);
while(!facilities->exit){
while(!facilities.exit){
usleep(1000*50);
/* If the Radar is not connected to TMC, a TCP socket is needed to fool the Radar */
/* To maintain the connection the content must be read */
if(facilities->dissemination->tmc_connect == false)
if(facilities.dissemination.tmc_connect == false)
i32_recv_bytes = recv(s_socket.i32_client, &au8_readTcp, READ_BUFFER_SIZE, 0);
/* Reads from the radar */
i32_recv_bytes = recv(raw_socket.raw_fd, &au8_readBuffer, READ_BUFFER_SIZE, 0);
if (dissemination_check(facilities->dissemination, 1) && facilities->dissemination->active){
if (dissemination_check(1) && facilities.dissemination.active){
if(is_radar_connected){
/* Information parsing from radar */
parse_input(au8_readBuffer,i32_recv_bytes);
/* CPM build and encoding to BDR and FDI */
if(mk_cpm(facilities, bpr->data.buf, (uint32_t *) &bpr->data.size, fmi->data.buf, (uint32_t *) &fmi->data.size, history_list, valid_array, history_timestamp) == 1)
if(mk_cpm(bpr->data.buf, (uint32_t *) &bpr->data.size, fmi->data.buf, (uint32_t *) &fmi->data.size, history_list, valid_array, history_timestamp) == 1)
continue;
uint32_t id = itss_id(bpr->data.buf, bpr->data.size);
@ -736,22 +738,22 @@ void *cp_service(void *fc){
}
/* Create thread to send packet to the Transport Layer (=3) */
itss_queue_send(facilities->tx_queue, tr_oer, enc_tdr.encoded+1, ITSS_TRANSPORT, id, "TR.packet.btp");
itss_queue_send(facilities.tx_queue, tr_oer, enc_tdr.encoded+1, ITSS_TRANSPORT, id, "TR.packet.btp");
/* Create thread to send packet to the Applications Layer (=5) */
itss_queue_send(facilities->tx_queue, fi_oer, enc_fdi.encoded+1, ITSS_APPLICATIONS, id, "FI.message");
itss_queue_send(facilities.tx_queue, fi_oer, enc_fdi.encoded+1, ITSS_APPLICATIONS, id, "FI.message");
/*Reset Timer for dissemination control */
dissemination_reset_timer(facilities->dissemination, 1);
dissemination_reset_timer(1);
// Logging
if (facilities->logging.dbms) {
pthread_mutex_lock(&facilities->id.lock);
uint64_t station_id = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock);
itss_db_add(facilities->logging.dbms, station_id, bpr->id, true, 14, NULL, bpr->data.buf, bpr->data.size);
if (facilities.logging.dbms) {
pthread_mutex_lock(&facilities.id.lock);
uint64_t station_id = facilities.id.station_id;
pthread_mutex_unlock(&facilities.id.lock);
itss_db_add(facilities.logging.dbms, station_id, bpr->id, true, 14, NULL, bpr->data.buf, bpr->data.size);
}
if (facilities->logging.recorder) {
if (facilities.logging.recorder) {
uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len];
int e = itss_management_record_packet_sdu(
@ -764,12 +766,12 @@ void *cp_service(void *fc){
ITSS_FACILITIES,
true);
if (e != -1) {
itss_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, bpr->id, "MReq.packet.set");
itss_queue_send(facilities.tx_queue, buffer, e, ITSS_MANAGEMENT, bpr->id, "MReq.packet.set");
}
}
}else{
is_radar_connected = radar_connection(RADAR_PORT,facilities);
is_radar_connected = radar_connection(RADAR_PORT);
}
}
}
@ -778,7 +780,7 @@ void *cp_service(void *fc){
ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi);
/* Close sockets */
if(facilities->dissemination->tmc_connect)
if(facilities.dissemination.tmc_connect)
shutdown(s_socket.i32_socket,2);
shutdown(raw_socket.raw_fd,2);

View File

@ -181,6 +181,6 @@ Summary: Read from Radar socket (s_socket.i32_socket) call the function to inter
param[in] void
*/
void* cp_service(void* fc);
void* cp_service();
#endif

View File

@ -69,9 +69,11 @@ static int permissions_check(int cause_code, uint8_t* permissions, uint8_t permi
}
static enum EVENT_CHECK_R event_check(den_t *den, DENM_t *denm, uint8_t* ssp, uint32_t ssp_len) {
static enum EVENT_CHECK_R event_check(DENM_t *denm, uint8_t* ssp, uint32_t ssp_len) {
int rv = 0;
den_t* den = &facilities.den;
uint64_t e_detection_time, e_reference_time;
asn_INTEGER2ulong((INTEGER_t*) &denm->denm.management.detectionTime, (unsigned long long*) &e_detection_time);
asn_INTEGER2ulong((INTEGER_t*) &denm->denm.management.referenceTime, (unsigned long long*) &e_reference_time);
@ -155,8 +157,9 @@ static enum EVENT_CHECK_R event_check(den_t *den, DENM_t *denm, uint8_t* ssp, ui
return EVENT_NEW;
}
static int event_add(den_t *den, DENM_t *denm, uint64_t* id) {
static int event_add(DENM_t *denm, uint64_t* id) {
den_t* den = &facilities.den;
uint64_t now = itss_time_get();
uint64_t e_detection_time, e_reference_time;
@ -225,8 +228,9 @@ static int event_add(den_t *den, DENM_t *denm, uint64_t* id) {
else return 0; // Event added to db
}
static int event_update(den_t *den, DENM_t *denm, uint64_t* id) {
static int event_update(DENM_t *denm, uint64_t* id) {
den_t* den = &facilities.den;
uint64_t now = itss_time_get();
uint64_t e_detection_time, e_reference_time;
@ -308,12 +312,12 @@ static int event_update(den_t *den, DENM_t *denm, uint64_t* id) {
else return 0; // Event updated
}
enum EVENT_CHECK_R event_manage(den_t *den, DENM_t *denm, uint64_t* id, uint8_t* ssp, uint32_t ssp_len) {
enum EVENT_CHECK_R event_manage(DENM_t *denm, uint64_t* id, uint8_t* ssp, uint32_t ssp_len) {
int rv = 0;
switch (rv = event_check(den, denm, ssp, ssp_len)) {
switch (rv = event_check(denm, ssp, ssp_len)) {
case EVENT_NEW:
syslog_debug("[facilities] [den] new event received");
if (event_add(den, denm, id)) {
if (event_add(denm, id)) {
syslog_debug("[facilities] [den] failed adding event, max events reached");
ASN_STRUCT_FREE(asn_DEF_DENM, denm);
rv = -1;
@ -329,7 +333,7 @@ enum EVENT_CHECK_R event_manage(den_t *den, DENM_t *denm, uint64_t* id, uint8_t*
break;
case EVENT_CANCELLATION:
syslog_debug("[facilities] [den] event cancellation received");
if (event_update(den, denm, id)) {
if (event_update(denm, id)) {
syslog_debug("[facilities] [den] failed cancelling event, event not found");
ASN_STRUCT_FREE(asn_DEF_DENM, denm);
rv = EVENT_NUMBER_EXCEEDED;
@ -337,7 +341,7 @@ enum EVENT_CHECK_R event_manage(den_t *den, DENM_t *denm, uint64_t* id, uint8_t*
break;
case EVENT_NEGATION:
syslog_debug("[facilities] [den] event negation received");
if (event_update(den, denm, id)) {
if (event_update(denm, id)) {
syslog_debug("[facilities] [den] failed negating event, event not found");
ASN_STRUCT_FREE(asn_DEF_DENM, denm);
rv = EVENT_NUMBER_EXCEEDED;
@ -345,7 +349,7 @@ enum EVENT_CHECK_R event_manage(den_t *den, DENM_t *denm, uint64_t* id, uint8_t*
break;
case EVENT_UPDATE:
syslog_debug("[facilities] [den] event update received");
if (event_update(den, denm, id)) {
if (event_update(denm, id)) {
syslog_debug("[facilities] [den] failed updating event, event not found");
ASN_STRUCT_FREE(asn_DEF_DENM, denm);
rv = EVENT_NUMBER_EXCEEDED;
@ -367,12 +371,15 @@ enum EVENT_CHECK_R event_manage(den_t *den, DENM_t *denm, uint64_t* id, uint8_t*
return rv;
}
void* den_service(void *fc) {
facilities_t *facilities = (facilities_t *) fc;
int den_init() {
return 0;
}
void* den_service() {
uint64_t now;
den_t *den = facilities->den;
den_t *den = &facilities.den;
pthread_mutex_init(&den->lock, NULL);
den->events = malloc(den->n_max_events * sizeof(void*));
@ -383,7 +390,7 @@ void* den_service(void *fc) {
uint32_t sleep4us = 1e6;
uint32_t sleep_count = 0;
while (!facilities->exit) {
while (!facilities.exit) {
now = itss_time_get();
pthread_mutex_lock(&den->lock);

View File

@ -67,8 +67,9 @@ typedef struct cc_ssp_bm {
* @param ssp permissions
* @return 0 if event OK, 1 if event NOK
*/
enum EVENT_CHECK_R event_manage(den_t* den, DENM_t* denm, uint64_t* id, uint8_t* ssp, uint32_t ssp_len);
enum EVENT_CHECK_R event_manage(DENM_t* denm, uint64_t* id, uint8_t* ssp, uint32_t ssp_len);
void* den_service(void* fc);
int den_init();
void* den_service();
#endif

View File

@ -43,7 +43,9 @@
#include <it2s-tender/recorder.h>
#include <it2s-tender/packet.h>
static int transport_indication(facilities_t *facilities, void* responder, void* security_socket, uint8_t *msg, uint32_t msg_len) {
facilities_t facilities = {0};
static int transport_indication(void* responder, void* security_socket, uint8_t *msg, uint32_t msg_len) {
int rv = 0, code = 0;
bool handled_msg = false;
FacilitiesIndication_t *fi = NULL;
@ -71,7 +73,7 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
case TransportIndication_PR_packet:
break;
case TransportIndication_PR_data:
transport_data_indication(facilities, &ti->choice.data, security_socket);
transport_data_indication(&ti->choice.data, security_socket);
goto cleanup;
default:
syslog_debug("[facilities]<- unrecognized TI.choice received");
@ -176,7 +178,7 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
// Manage message
switch (tpi->choice.btp.destinationPort) {
case Port_cam:
switch (check_cam(facilities, &tpi->choice.btp, its_msg, ssp, ssp_len)) {
switch (check_cam(&tpi->choice.btp, its_msg, ssp, ssp_len)) {
case CAM_OK:
fwd = true;
break;
@ -195,7 +197,7 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
syslog_debug("DENM XER %d: %.*s", (int)rve.encoded, (int)rve.encoded , xml_denm);
free(xml_denm);
#endif
switch (event_manage(facilities->den, its_msg, &id, ssp, ssp_len)) {
switch (event_manage(its_msg, &id, ssp, ssp_len)) {
case EVENT_NEW:
case EVENT_CANCELLATION:
case EVENT_NEGATION:
@ -212,7 +214,7 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
break;
case Port_ivim:
switch (service_eval(facilities->infrastructure, SERVICE_IVI, its_msg, &id, ssp, ssp_len)) {
switch (service_eval(SERVICE_IVI, its_msg, &id, ssp, ssp_len)) {
case SERVICE_NEW:
case SERVICE_CANCELLATION:
case SERVICE_NEGATION:
@ -230,7 +232,7 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
break;
case Port_saem:
switch (saem_check(facilities, &facilities->bulletin, its_msg, neighbour_cert)) {
switch (saem_check(its_msg, neighbour_cert)) {
case SAEM_NEW:
fwd = true;
break;
@ -240,15 +242,15 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
break;
case 7011:
if (facilities->tolling.enabled) {
tpm_recv(facilities, its_msg, security_socket, neighbour_cert, NULL);
if (facilities.tolling.enabled) {
tpm_recv(its_msg, security_socket, neighbour_cert, NULL);
fwd = true;
}
break;
case 2043:
if (facilities->coordination.active) {
vcm_check(facilities, its_msg);
if (facilities.coordination.active) {
vcm_check(its_msg);
}
fwd = true;
break;
@ -270,16 +272,16 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
sreq->choice.tlsRecv.data.buf = malloc(tpi->choice.tcp.data.size);
memcpy(sreq->choice.tlsRecv.data.buf, tpi->choice.tcp.data.buf, tpi->choice.tcp.data.size);
pthread_mutex_lock(&facilities->tolling.lock);
tlsc_t* tlsc = tolling_tlsc_get(&facilities->tolling, tpi->choice.tcp.sourceAddress->buf, 7011);
pthread_mutex_lock(&facilities.tolling.lock);
tlsc_t* tlsc = tolling_tlsc_get(tpi->choice.tcp.sourceAddress->buf, 7011);
if (tlsc) {
id = tlsc->id;
} else {
tlsc = tolling_tlsc_new(&facilities->tolling, tpi->choice.tcp.sourceAddress->buf, 7011);
tlsc = tolling_tlsc_new(tpi->choice.tcp.sourceAddress->buf, 7011);
id = tlsc->id;
}
++tlsc->nmsg;
pthread_mutex_unlock(&facilities->tolling.lock);
pthread_mutex_unlock(&facilities.tolling.lock);
sreq->choice.tlsSend.connId = id;
uint8_t b_sdu[2048];
@ -336,8 +338,8 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
tpr->destinationPort = 7011;
tpr->sourcePort = 7011;
if (facilities->tolling.protocol.p == TOLLING_PROTOCOL_TLS_GN ||
(facilities->tolling.protocol.p == TOLLING_PROTOCOL_TLS_SHS && tlsc->nmsg < 2)) {
if (facilities.tolling.protocol.p == TOLLING_PROTOCOL_TLS_GN ||
(facilities.tolling.protocol.p == TOLLING_PROTOCOL_TLS_SHS && tlsc->nmsg < 2)) {
tpr->gn = calloc(1, sizeof(GeonetworkingOutboundOptions_t));
tpr->gn->packetTransportType = PacketTransportType_shb;
tpr->gn->destinationAddress.buf = calloc(1, 6);
@ -354,10 +356,10 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
goto cleanup;
}
itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, tpr->id, "TR.packet.tcp");
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) {
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) {
syslog_debug("[facilities]<- invalid TPM received");
@ -365,7 +367,7 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
goto cleanup;
}
if (!dec.code) {
tpm_recv(facilities, its_msg, security_socket, NULL, tpi->choice.tcp.sourceAddress->buf);
tpm_recv(its_msg, security_socket, NULL, tpi->choice.tcp.sourceAddress->buf);
// Fwd to [applications]
fi = calloc(1, sizeof(FacilitiesIndication_t));
@ -384,7 +386,7 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
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);
itss_queue_send(facilities->tx_queue, buffer, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message");
itss_queue_send(facilities.tx_queue, buffer, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message");
}
}
}
@ -416,17 +418,17 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
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);
itss_queue_send(facilities->tx_queue, buffer, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message");
itss_queue_send(facilities.tx_queue, buffer, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message");
}
// Logging
if (facilities->logging.dbms) {
pthread_mutex_lock(&facilities->id.lock);
uint64_t station_id = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock);
itss_db_add(facilities->logging.dbms, station_id, id, false, its_msg_type, NULL, packet, packet_len);
if (facilities.logging.dbms) {
pthread_mutex_lock(&facilities.id.lock);
uint64_t station_id = facilities.id.station_id;
pthread_mutex_unlock(&facilities.id.lock);
itss_db_add(facilities.logging.dbms, station_id, id, false, its_msg_type, NULL, packet, packet_len);
}
if (facilities->logging.recorder) {
if (facilities.logging.recorder) {
int e = itss_management_record_packet_sdu(
buf,
buf_len,
@ -437,7 +439,7 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
ITSS_FACILITIES,
false);
if (e != -1) {
itss_queue_send(facilities->tx_queue, buf, e, ITSS_MANAGEMENT, tpi->choice.btp.id, "MReq.packet.set");
itss_queue_send(facilities.tx_queue, buf, e, ITSS_MANAGEMENT, tpi->choice.btp.id, "MReq.packet.set");
}
}
@ -454,7 +456,7 @@ cleanup:
return rv;
}
static int facilities_request(facilities_t *facilities, void* responder, uint8_t *msg, uint32_t msg_len) {
static int facilities_request(void* responder, uint8_t *msg, uint32_t msg_len) {
int rv = 0;
FacilitiesRequest_t *fr = calloc(1, sizeof(FacilitiesRequest_t));
@ -469,25 +471,25 @@ static int facilities_request(facilities_t *facilities, void* responder, uint8_t
switch (fr->present) {
case FacilitiesRequest_PR_message:
rv = facilities_request_single_message(facilities, responder, &fr->choice.message);
rv = facilities_request_single_message(responder, &fr->choice.message);
break;
case FacilitiesRequest_PR_data:
switch (fr->choice.data.present) {
case FacilitiesDataRequest_PR_activeEpisodes:
rv = facilities_request_active_episodes(facilities, responder, fr);
rv = facilities_request_active_episodes(responder, fr);
break;
case FacilitiesDataRequest_PR_attributeTypes:
rv = facilities_request_attribute_types(facilities, responder, fr);
rv = facilities_request_attribute_types(responder, fr);
break;
case FacilitiesDataRequest_PR_loadedProtectionZones:
rv = facilities_request_loaded_protected_zones(facilities, responder, fr);
rv = facilities_request_loaded_protected_zones(responder, fr);
break;
case FacilitiesDataRequest_PR_chainInfoSet:
rv = facilities_request_chaininfo_set(facilities, responder, &fr->choice.data.choice.chainInfoSet);
rv = facilities_request_chaininfo_set(responder, &fr->choice.data.choice.chainInfoSet);
break;
default:
@ -512,7 +514,7 @@ cleanup:
}
static int security_indication(facilities_t *facilities, void* responder_secured, uint8_t *msg, uint32_t msg_len) {
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));
@ -529,18 +531,18 @@ static int security_indication(facilities_t *facilities, void* responder_secured
goto cleanup;
}
pthread_mutex_lock(&facilities->id.change.lock);
if (facilities->id.change.stage == ID_CHANGE_BLOCKED) {
pthread_mutex_unlock(&facilities->id.change.lock);
pthread_mutex_lock(&facilities.id.change.lock);
if (facilities.id.change.stage == ID_CHANGE_BLOCKED) {
pthread_mutex_unlock(&facilities.id.change.lock);
syslog_debug("[facilities] identity change is currently blocked");
rv = 1;
goto cleanup;
}
if (facilities->id.change.stage == ID_CHANGE_PREPARE &&
if (facilities.id.change.stage == ID_CHANGE_PREPARE &&
si->choice.idChangeEvent.command != SecurityIdChangeEventType_commit &&
si->choice.idChangeEvent.command != SecurityIdChangeEventType_abort) {
pthread_mutex_unlock(&facilities->id.change.lock);
pthread_mutex_unlock(&facilities.id.change.lock);
syslog_debug("[facilities] current identity change state is prepare, but received identity change command is not commit nor abort");
rv = 1;
goto cleanup;
@ -551,60 +553,60 @@ static int security_indication(facilities_t *facilities, void* responder_secured
switch (si->choice.idChangeEvent.command) {
case SecurityIdChangeEventType_prepare:
facilities->id.change.stage = ID_CHANGE_PREPARE;
facilities.id.change.stage = ID_CHANGE_PREPARE;
pthread_mutex_lock(&facilities->id.lock);
pthread_mutex_lock(&facilities->lightship->lock);
pthread_mutex_lock(&facilities.id.lock);
pthread_mutex_lock(&facilities.lightship.lock);
break;
case SecurityIdChangeEventType_commit:
;
facilities->id.change.stage = ID_CHANGE_COMMIT;
facilities.id.change.stage = ID_CHANGE_COMMIT;
// Reset lightship
for (int i = 0; i < facilities->lightship->pos_history_len; ++i) {
free(facilities->lightship->pos_history[i]);
for (int i = 0; i < facilities.lightship.pos_history_len; ++i) {
free(facilities.lightship.pos_history[i]);
}
facilities->lightship->pos_history_len = 0;
facilities.lightship.pos_history_len = 0;
facilities->lightship->last_cam = 0;
facilities->lightship->last_cam_lfc = 0;
facilities->lightship->next_cam_max = 0;
facilities->lightship->next_cam_min = 0;
facilities.lightship.last_cam = 0;
facilities.lightship.last_cam_lfc = 0;
facilities.lightship.next_cam_max = 0;
facilities.lightship.next_cam_min = 0;
pthread_mutex_unlock(&facilities->lightship->lock);
pthread_mutex_unlock(&facilities.lightship.lock);
// 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:
facilities->id.station_id = si->choice.idChangeEvent.ids.list.array[i]->choice.stationId;
facilities.id.station_id = si->choice.idChangeEvent.ids.list.array[i]->choice.stationId;
break;
case SecurityId_PR_ipv6Address:
memcpy(facilities->id.ipv6_addr, si->choice.idChangeEvent.ids.list.array[i]->choice.ipv6Address.buf, 16);
memcpy(facilities.id.ipv6_addr, si->choice.idChangeEvent.ids.list.array[i]->choice.ipv6Address.buf, 16);
break;
default:
break;
}
}
facilities->id.change.stage = ID_CHANGE_INACTIVE;
facilities.id.change.stage = ID_CHANGE_INACTIVE;
pthread_mutex_unlock(&facilities->id.lock);
pthread_mutex_unlock(&facilities.id.lock);
id_changed = true;
break;
case SecurityIdChangeEventType_abort:
pthread_mutex_unlock(&facilities->id.lock);
pthread_mutex_unlock(&facilities->lightship->lock);
pthread_mutex_unlock(&facilities.id.lock);
pthread_mutex_unlock(&facilities.lightship.lock);
facilities->id.change.stage = ID_CHANGE_INACTIVE;
facilities.id.change.stage = ID_CHANGE_INACTIVE;
break;
default:
pthread_mutex_unlock(&facilities->id.change.lock);
pthread_mutex_unlock(&facilities.id.change.lock);
syslog_err("[networking]<- unhandled idChangeEvent command type");
rv = 1;
goto cleanup;
@ -616,7 +618,7 @@ static int security_indication(facilities_t *facilities, void* responder_secured
enc = oer_encode_to_buffer(&asn_DEF_SecurityResponse, NULL, sr, buffer, 64);
zmq_send(responder_secured, buffer, enc.encoded, 0);
pthread_mutex_unlock(&facilities->id.change.lock);
pthread_mutex_unlock(&facilities.id.change.lock);
cleanup:
if (rv) {
@ -626,14 +628,14 @@ cleanup:
zmq_send(responder_secured, buffer, enc.encoded, 0);
}
pthread_mutex_unlock(&facilities->id.change.lock);
pthread_mutex_unlock(&facilities.id.change.lock);
ASN_STRUCT_FREE(asn_DEF_SecurityResponse, sr);
ASN_STRUCT_FREE(asn_DEF_SecurityIndication, si);
return rv;
}
static int networking_indication(facilities_t* facilities, void* responder, uint8_t* msg, uint32_t msg_len) {
static int networking_indication(void* responder, uint8_t* msg, uint32_t msg_len) {
int rv = 0;
uint8_t code = 0;
@ -656,10 +658,10 @@ static int networking_indication(facilities_t* facilities, void* responder, uint
if (ni->choice.data.mobileNeighbour &&
*ni->choice.data.mobileNeighbour) {
pthread_mutex_lock(&facilities->lightship->lock);
facilities->lightship->last_vehicle = itss_time_get();
facilities->lightship->is_vehicle_near = true;
pthread_mutex_unlock(&facilities->lightship->lock);
pthread_mutex_lock(&facilities.lightship.lock);
facilities.lightship.last_vehicle = itss_time_get();
facilities.lightship.is_vehicle_near = true;
pthread_mutex_unlock(&facilities.lightship.lock);
}
@ -670,7 +672,7 @@ cleanup:
}
static int management_indication(facilities_t* facilities, void* responder, uint8_t* msg, uint32_t msg_len) {
static int management_indication(void* responder, uint8_t* msg, uint32_t msg_len) {
int rv = 0;
uint8_t code = 0;
@ -723,31 +725,29 @@ cleanup:
}
void* tx(void* fc) {
void* tx() {
int rv = 0;
facilities_t *facilities = (facilities_t*) fc;
itss_queue_t* queue = facilities->tx_queue;
itss_queue_t* queue = facilities.tx_queue;
uint8_t code;
int wait_ms = 1000;
void* applications_socket = zmq_socket(facilities->zmq.ctx, ZMQ_REQ);
void* applications_socket = zmq_socket(facilities.zmq.ctx, ZMQ_REQ);
zmq_setsockopt(applications_socket, ZMQ_RCVTIMEO, &wait_ms, sizeof(int));
zmq_connect(applications_socket, facilities->zmq.applications_address);
zmq_connect(applications_socket, facilities.zmq.applications_address);
void* transport_socket = zmq_socket(facilities->zmq.ctx, ZMQ_REQ);
void* transport_socket = zmq_socket(facilities.zmq.ctx, ZMQ_REQ);
zmq_setsockopt(transport_socket, ZMQ_RCVTIMEO, &wait_ms, sizeof(int));
zmq_connect(transport_socket, facilities->zmq.transport_address);
zmq_connect(transport_socket, facilities.zmq.transport_address);
void* management_socket = zmq_socket(facilities->zmq.ctx, ZMQ_REQ);
void* management_socket = zmq_socket(facilities.zmq.ctx, ZMQ_REQ);
zmq_setsockopt(management_socket, ZMQ_RCVTIMEO, &wait_ms, sizeof(int));
zmq_connect(management_socket, facilities->zmq.management_address);
zmq_connect(management_socket, facilities.zmq.management_address);
itss_queue_t* stream = itss_queue_new();
while (!facilities->exit) {
while (!facilities.exit) {
pthread_mutex_lock(&queue->lock);
while (!queue->len) {
pthread_cond_wait(&queue->trigger, &queue->lock);
@ -806,48 +806,46 @@ int main() {
syslog_info("[facilities] starting");
facilities_t facilities = {0};
facilities.zmq.ctx = zmq_ctx_new();
facilities.tx_queue = itss_queue_new();
facilities.lightship = lightship_init();
facilities.den = calloc(1, sizeof(den_t));
facilities.infrastructure = calloc(1, sizeof(infrastructure_t));
facilities.dissemination = dissemination_init();
bulletin_init(&facilities.bulletin);
coordination_init(&facilities.coordination);
lightship_init();
den_init();
infrastructure_init();
dissemination_init();
bulletin_init();
coordination_init();
time_t t;
srand((unsigned) time(&t));
if (facilities_config(&facilities)) return 1;
facilities.lightship->type = facilities.station_type;
facilities.lightship.type = facilities.station_type;
// Tx
pthread_create(&facilities.transmitting, NULL, tx, (void*) &facilities);
pthread_create(&facilities.transmitting, NULL, tx, NULL);
// CA
pthread_create(&facilities.ca_service, NULL, ca_service, (void*) &facilities);
pthread_create(&facilities.ca_service, NULL, ca_service, NULL);
// DEN
pthread_create(&facilities.den_service, NULL, den_service, (void*) &facilities);
pthread_create(&facilities.den_service, NULL, den_service, NULL);
// Infrastructure
pthread_create(&facilities.infrastructure_service, NULL, infrastructure_service, (void*) &facilities);
pthread_create(&facilities.infrastructure_service, NULL, infrastructure_service, NULL);
// CP
pthread_create(&facilities.cp_service, NULL, cp_service, (void*) &facilities);
pthread_create(&facilities.cp_service, NULL, cp_service, NULL);
// SA
pthread_create(&facilities.sa_service, NULL, sa_service, (void*) &facilities);
pthread_create(&facilities.sa_service, NULL, sa_service, NULL);
// Tolling
tolling_init(&facilities.tolling, facilities.zmq.ctx, facilities.zmq.security_address, facilities.station_type);
tolling_init(facilities.zmq.ctx, facilities.zmq.security_address, facilities.station_type);
// PC
if (facilities.coordination.active)
pthread_create(&facilities.vc_service, NULL, vc_service, (void*) &facilities);
pthread_create(&facilities.vc_service, NULL, vc_service, NULL);
void* security_socket = zmq_socket(facilities.zmq.ctx, ZMQ_REQ);
@ -870,7 +868,7 @@ int main() {
rl = zmq_recv(facilities.zmq.responders[i].socket, buffer, ITSS_SDU_MAX_LEN, 0);
switch (buffer[0]) { /* source */
case ITSS_NETWORKING:
networking_indication(&facilities, facilities.zmq.responders[i].socket, buffer+1, rl);
networking_indication(facilities.zmq.responders[i].socket, buffer+1, rl);
break;
case ITSS_TRANSPORT:
@ -883,7 +881,7 @@ int main() {
pthread_mutex_unlock(&facilities.id.change.lock);
if (!in_idchange) {
transport_indication(&facilities, facilities.zmq.responders[i].socket, security_socket, buffer+1, rl);
transport_indication(facilities.zmq.responders[i].socket, security_socket, buffer+1, rl);
pthread_mutex_lock(&facilities.id.change.lock);
facilities.id.change.stage = ID_CHANGE_INACTIVE;
@ -904,7 +902,7 @@ int main() {
pthread_mutex_unlock(&facilities.id.change.lock);
if (!in_idchange) {
facilities_request(&facilities, facilities.zmq.responders[i].socket, buffer+1, rl);
facilities_request(facilities.zmq.responders[i].socket, buffer+1, rl);
pthread_mutex_lock(&facilities.id.change.lock);
facilities.id.change.stage = ID_CHANGE_INACTIVE;
@ -917,11 +915,11 @@ int main() {
break;
case ITSS_MANAGEMENT:
management_indication(&facilities, facilities.zmq.responders[i].socket, buffer+1, rl);
management_indication(facilities.zmq.responders[i].socket, buffer+1, rl);
break;
case ITSS_SECURITY:
security_indication(&facilities, facilities.zmq.responders[i].socket, buffer+1, rl);
security_indication(facilities.zmq.responders[i].socket, buffer+1, rl);
break;
default:

View File

@ -51,16 +51,16 @@ typedef struct facilities {
itss_queue_t* tx_queue;
// CA
lightship_t* lightship;
lightship_t lightship;
// DEN
den_t *den;
den_t den;
// Infrastructure
infrastructure_t* infrastructure;
infrastructure_t infrastructure;
// CPM
dissemination_t* dissemination;
dissemination_t dissemination;
// SA
bulletin_t bulletin;
@ -69,7 +69,7 @@ typedef struct facilities {
tolling_t tolling;
// PC
coordination_s coordination;
coordination_t coordination;
// Logging
struct {
@ -101,4 +101,6 @@ typedef struct facilities {
bool exit;
} facilities_t;
extern facilities_t facilities;
#endif

View File

@ -4,14 +4,14 @@
#include <itss-security/SecurityRequest.h>
#include <itss-security/SecurityReply.h>
static void tcp_conn_reset(facilities_t* facilities, TCPConnRSTInfo_t* cri, void* security_socket) {
static void tcp_conn_reset(TCPConnRSTInfo_t* cri, void* security_socket) {
if (cri->destinationAddress.size != 16) return;
SecurityRequest_t* sreq = NULL;
// Reset tolling, tls
tolling_t* tolling = &facilities->tolling;
bulletin_t* bulletin = &facilities->bulletin;
tolling_t* tolling = &facilities.tolling;
bulletin_t* bulletin = &facilities.bulletin;
if (tolling->enabled &&
(tolling->protocol.p == TOLLING_PROTOCOL_TLS ||
tolling->protocol.p == TOLLING_PROTOCOL_TLS_GN ||
@ -42,14 +42,14 @@ static void tcp_conn_reset(facilities_t* facilities, TCPConnRSTInfo_t* cri, void
ASN_STRUCT_FREE(asn_DEF_SecurityRequest, sreq);
}
int transport_data_indication(facilities_t* facilities, TransportDataIndication_t* tdi, void* security_socket) {
int transport_data_indication(TransportDataIndication_t* tdi, void* security_socket) {
int rv = 0;
switch (tdi->present) {
case TransportDataIndication_PR_tcp:
switch (tdi->choice.tcp.present) {
case TCPDataIndication_PR_connInfoReset:
tcp_conn_reset(facilities, &tdi->choice.tcp.choice.connInfoReset, security_socket);
tcp_conn_reset(&tdi->choice.tcp.choice.connInfoReset, security_socket);
break;
default:
rv = 1;

View File

@ -3,4 +3,4 @@
#include "facilities.h"
#include <itss-transport/TransportIndication.h>
int transport_data_indication(facilities_t* facilities, TransportDataIndication_t* tpi, void* security_socket);
int transport_data_indication(TransportDataIndication_t* tpi, void* security_socket);

View File

@ -59,9 +59,11 @@ static int permissions_check(int diid, uint8_t* permissions, uint8_t permissions
}
static enum SERVICE_EVAL_R service_check(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, uint8_t* ssp, uint16_t ssp_len) {
static enum SERVICE_EVAL_R service_check(enum SERVICE_TYPE type, void* its_msg, uint8_t* ssp, uint16_t ssp_len) {
int rv = 0;
infrastructure_t* infrastructure = &facilities.infrastructure;
uint64_t now = itss_time_get();
switch (type) {
@ -251,7 +253,9 @@ static enum SERVICE_EVAL_R service_check(infrastructure_t* infrastructure, enum
return SERVICE_NEW;
}
static int service_add(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, uint64_t* id) {
static int service_add(enum SERVICE_TYPE type, void* its_msg, uint64_t* id) {
infrastructure_t* infrastructure = &facilities.infrastructure;
switch (type) {
case SERVICE_IVI:
@ -337,7 +341,9 @@ static int service_add(infrastructure_t* infrastructure, enum SERVICE_TYPE type,
else return 0; // Services added to db
}
static int service_update(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, uint64_t* id) {
static int service_update(enum SERVICE_TYPE type, void* its_msg, uint64_t* id) {
infrastructure_t* infrastructure = &facilities.infrastructure;
switch (type) {
case SERVICE_IVI:
@ -444,12 +450,16 @@ static int service_update(infrastructure_t* infrastructure, enum SERVICE_TYPE ty
else return 0; // Event updated
}
enum SERVICE_EVAL_R service_eval(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, uint64_t* id, uint8_t* ssp, uint16_t ssp_len) {
enum SERVICE_EVAL_R service_eval(enum SERVICE_TYPE type, void* its_msg, uint64_t* id, uint8_t* ssp, uint16_t ssp_len) {
int rv = 0;
switch (rv = service_check(infrastructure, type, its_msg, ssp, ssp_len)) {
infrastructure_t* infrastructure = &facilities.infrastructure;
switch (rv = service_check(type, its_msg, ssp, ssp_len)) {
case SERVICE_NEW:
syslog_debug("[facilities] [infrastructure] new service received");
if (service_add(infrastructure, type, its_msg, id)) {
if (service_add(type, its_msg, id)) {
syslog_debug("[facilities] [infrastructure] failed adding service, max services reached");
ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg);
rv = -1;
@ -465,7 +475,7 @@ enum SERVICE_EVAL_R service_eval(infrastructure_t* infrastructure, enum SERVICE_
break;
case SERVICE_CANCELLATION:
syslog_debug("[facilities] [infrastructure] service cancellation received");
if (service_update(infrastructure, type, its_msg, id)) {
if (service_update(type, its_msg, id)) {
syslog_debug("[facilities] [infrastructure] failed cancelling service, event not found");
ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg);
rv = -1;
@ -473,7 +483,7 @@ enum SERVICE_EVAL_R service_eval(infrastructure_t* infrastructure, enum SERVICE_
break;
case SERVICE_NEGATION:
syslog_debug("[facilities] [infrastructure] service negation received");
if (service_update(infrastructure, type, its_msg, id)) {
if (service_update(type, its_msg, id)) {
syslog_debug("[facilities] [infrastructure] failed negating service, service not found");
ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg);
rv = -1;
@ -481,7 +491,7 @@ enum SERVICE_EVAL_R service_eval(infrastructure_t* infrastructure, enum SERVICE_
break;
case SERVICE_UPDATE:
syslog_debug("[facilities] [infrastructure] service update received");
if (service_update(infrastructure, type, its_msg, id)) {
if (service_update(type, its_msg, id)) {
syslog_debug("[facilities] [infrastructure] failed updating service, service not found");
ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg);
rv = -1;
@ -503,13 +513,16 @@ enum SERVICE_EVAL_R service_eval(infrastructure_t* infrastructure, enum SERVICE_
return rv;
}
void* infrastructure_service(void *fc) {
facilities_t *facilities = (facilities_t *) fc;
int infrastructure_init() {
return 0;
}
void* infrastructure_service() {
struct timespec systemtime;
uint64_t now;
infrastructure_t *infrastructure = facilities->infrastructure;
infrastructure_t *infrastructure = &facilities.infrastructure;
pthread_mutex_init(&infrastructure->lock, NULL);
infrastructure->services = malloc(infrastructure->n_max_services * sizeof(void*));
@ -520,7 +533,7 @@ void* infrastructure_service(void *fc) {
uint32_t sleep4us = 1e6;
uint32_t sleep_count = 0;
while (!facilities->exit) {
while (!facilities.exit) {
now = itss_time_get();
int n_awaiting_services = 0;

View File

@ -1,5 +1,4 @@
#ifndef FACILITIES_INFRASTRUCTURE_H
#define FACILITIES_INFRASTRUCTURE_H
#pragma once
#include <stdint.h>
#include <ivim/IVIM.h>
@ -86,8 +85,7 @@ enum SERVICE_EVAL_R {
SERVICE_BAD_PERMISSIONS
};
enum SERVICE_EVAL_R service_eval(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, uint64_t* id, uint8_t* ssp, uint16_t ssp_len);
enum SERVICE_EVAL_R service_eval(enum SERVICE_TYPE type, void* its_msg, uint64_t* id, uint8_t* ssp, uint16_t ssp_len);
void* infrastructure_service(void* fc);
#endif
int infrastructure_init();
void* infrastructure_service();

View File

@ -45,7 +45,7 @@ int facilities_request_result_rejected(void* responder) {
return rv;
}
int facilities_request_single_message(facilities_t* facilities, void* responder, FacilitiesMessageRequest_t* frm) {
int facilities_request_single_message(void* responder, FacilitiesMessageRequest_t* frm) {
int rv = 0;
@ -126,7 +126,7 @@ int facilities_request_single_message(facilities_t* facilities, void* responder,
if (frm->itsMessageType == ItsMessageType_denm) {
managed_msg = true;
uint8_t event_type = event_manage(facilities->den, its_msg, &id, NULL, 0);
uint8_t event_type = event_manage(its_msg, &id, NULL, 0);
// Do not free its_msg! event_manage takes care of the msg
// id will get set to another val if EVENT NEW or UPDATE or CANCELLATION or NEGATION
if (event_type != EVENT_NEW &&
@ -146,14 +146,14 @@ int facilities_request_single_message(facilities_t* facilities, void* responder,
if (fwd) {
// set stationID
pthread_mutex_lock(&facilities->id.lock);
((DENM_t*)its_msg)->header.stationID = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock);
pthread_mutex_lock(&facilities.id.lock);
((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->pos_history_len > 0) {
if (facilities.station_type != 15) {
pthread_mutex_lock(&facilities.lightship.lock);
if (facilities.lightship.pos_history_len > 0) {
if (!((DENM_t*)its_msg)->denm.location) {
((DENM_t*)its_msg)->denm.location = calloc(1, sizeof(LocationContainer_t));
@ -164,8 +164,8 @@ int facilities_request_single_message(facilities_t* facilities, void* responder,
((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];
pos_vector_t** pos_history = facilities->lightship->pos_history;
uint16_t pos_history_len = facilities->lightship->pos_history_len;
pos_vector_t** pos_history = facilities.lightship.pos_history;
uint16_t pos_history_len = facilities.lightship.pos_history_len;
ph->list.array = malloc((pos_history_len-1) * sizeof(void*));
ph->list.count = pos_history_len-1;
@ -196,7 +196,7 @@ int facilities_request_single_message(facilities_t* facilities, void* responder,
*ph->list.array[i]->pathDeltaTime = (pos_history[i]->ts - pos_history[i+1]->ts)/10;
}
}
pthread_mutex_unlock(&facilities->lightship->lock);
pthread_mutex_unlock(&facilities.lightship.lock);
}
@ -214,7 +214,7 @@ int facilities_request_single_message(facilities_t* facilities, void* responder,
} else if (frm->itsMessageType == ItsMessageType_ivim) {
managed_msg = true;
uint8_t service_type = service_eval(facilities->infrastructure, SERVICE_IVI, its_msg, &id, NULL, 0);
uint8_t service_type = service_eval(SERVICE_IVI, its_msg, &id, NULL, 0);
if (service_type != SERVICE_NEW &&
service_type != SERVICE_UPDATE &&
@ -241,18 +241,18 @@ int facilities_request_single_message(facilities_t* facilities, void* responder,
}
if (!((IVIM_t*) its_msg)->ivi.mandatory.validTo) {
valid_to = valid_from + facilities->infrastructure->default_service_duration;
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);
}
transmission_start = valid_from;
transmission_interval = facilities->infrastructure->replay_interval;
transmission_interval = facilities.infrastructure.replay_interval;
transmission_duration = valid_to - valid_from;
}
}
if (!facilities->replay) {
if (!facilities.replay) {
transmission_interval = 0;
transmission_duration = 0;
}
@ -310,11 +310,11 @@ int facilities_request_single_message(facilities_t* facilities, void* responder,
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, tr_oer, enc.encoded+1, ITSS_TRANSPORT, id, "TR.packet.btp");
}
// Logging
if (facilities->logging.recorder) {
if (facilities.logging.recorder) {
uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len];
int e = itss_management_record_packet_sdu(
@ -327,7 +327,7 @@ int facilities_request_single_message(facilities_t* facilities, void* responder,
ITSS_FACILITIES,
true);
if (e != -1) {
itss_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set");
itss_queue_send(facilities.tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set");
}
}
@ -338,7 +338,7 @@ cleanup:
return rv;
}
int facilities_request_active_episodes(facilities_t* facilities, void* responder, FacilitiesRequest_t* freq) {
int facilities_request_active_episodes(void* responder, FacilitiesRequest_t* freq) {
int rv = 0;
FacilitiesReply_t* frep = calloc(1, sizeof(FacilitiesReply_t));
@ -347,11 +347,11 @@ int facilities_request_active_episodes(facilities_t* facilities, void* responder
frep->present = FacilitiesReply_PR_data;
frep->choice.data.present = FacilitiesDataReply_PR_episodes;
pthread_mutex_lock(&facilities->den->lock);
pthread_mutex_lock(&facilities->infrastructure->lock);
pthread_mutex_lock(&facilities.den.lock);
pthread_mutex_lock(&facilities.infrastructure.lock);
uint16_t nae = facilities->den->n_active_events;
uint16_t nas = facilities->infrastructure->n_active_services;
uint16_t nae = facilities.den.n_active_events;
uint16_t nas = facilities.infrastructure.n_active_services;
uint16_t na = 0;
@ -374,11 +374,11 @@ int facilities_request_active_episodes(facilities_t* facilities, void* responder
switch (*freq->choice.data.choice.activeEpisodes.list.array[e]) {
case EpisodeType_denm:
for (int i = 0, n = 0; n < nae; ++i) {
if (facilities->den->events[i]->enabled && facilities->den->events[i]->state == EVENT_ACTIVE) {
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]->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_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 */
syslog_err("[facilities] failed encoding DENM for FDResult (%s)", enc.failed_type->name);
frep->choice.data.choice.episodes.list.array[j]->data.size = 0;
@ -392,11 +392,11 @@ int facilities_request_active_episodes(facilities_t* facilities, void* responder
break;
case EpisodeType_ivim:
for (int i = 0, n = 0; n < nas; ++i) {
if (facilities->infrastructure->services[i]->enabled && facilities->infrastructure->services[i]->state == SERVICE_ACTIVE) {
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]->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_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 */
syslog_err("[facilities] failed encoding IVIM for FDResult (%s)", enc.failed_type->name);
frep->choice.data.choice.episodes.list.array[j]->data.size = 0;
@ -410,8 +410,8 @@ int facilities_request_active_episodes(facilities_t* facilities, void* responder
break;
default:
syslog_err("[facilities] unrecognized FR event type (%lld)", *freq->choice.data.choice.activeEpisodes.list.array[e]);
pthread_mutex_unlock(&facilities->den->lock);
pthread_mutex_unlock(&facilities->infrastructure->lock);
pthread_mutex_unlock(&facilities.den.lock);
pthread_mutex_unlock(&facilities.infrastructure.lock);
facilities_request_result_rejected(responder);
rv = 1;
@ -419,8 +419,8 @@ int facilities_request_active_episodes(facilities_t* facilities, void* responder
}
}
pthread_mutex_unlock(&facilities->den->lock);
pthread_mutex_unlock(&facilities->infrastructure->lock);
pthread_mutex_unlock(&facilities.den.lock);
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);
@ -441,7 +441,7 @@ cleanup:
return rv;
}
int facilities_request_attribute_types(facilities_t* facilities, void* responder, FacilitiesRequest_t* freq) {
int facilities_request_attribute_types(void* responder, FacilitiesRequest_t* freq) {
int rv = 0;
FacilitiesReply_t* frep = calloc(1, sizeof(FacilitiesReply_t));
@ -458,9 +458,9 @@ int facilities_request_attribute_types(facilities_t* facilities, void* responder
frep->choice.data.choice.attributes.list.array[j] = calloc(1, sizeof(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);
*((uint64_t*) frep->choice.data.choice.attributes.list.array[j]->data.buf) = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock);
pthread_mutex_lock(&facilities.id.lock);
*((uint64_t*) frep->choice.data.choice.attributes.list.array[j]->data.buf) = facilities.id.station_id;
pthread_mutex_unlock(&facilities.id.lock);
break;
default:
@ -488,7 +488,7 @@ cleanup:
}
int facilities_request_loaded_protected_zones(facilities_t* facilities, void* responder, FacilitiesRequest_t* freq) {
int facilities_request_loaded_protected_zones(void* responder, FacilitiesRequest_t* freq) {
int rv = 0;
FacilitiesReply_t* frep = calloc(1, sizeof(FacilitiesReply_t));
@ -496,20 +496,20 @@ int facilities_request_loaded_protected_zones(facilities_t* facilities, void* re
frep->present = FacilitiesReply_PR_data;
frep->choice.data.present = FacilitiesDataReply_PR_protectedCommunicationZones;
pthread_mutex_lock(&facilities->lightship->lock);
pthread_mutex_lock(&facilities.lightship.lock);
frep->choice.data.choice.protectedCommunicationZones.list.count = facilities->lightship->protected_zones.pz_len;
frep->choice.data.choice.protectedCommunicationZones.list.size = facilities->lightship->protected_zones.pz_len * sizeof(void*);
frep->choice.data.choice.protectedCommunicationZones.list.array = malloc(facilities->lightship->protected_zones.pz_len * sizeof(void*));
frep->choice.data.choice.protectedCommunicationZones.list.count = facilities.lightship.protected_zones.pz_len;
frep->choice.data.choice.protectedCommunicationZones.list.size = facilities.lightship.protected_zones.pz_len * sizeof(void*);
frep->choice.data.choice.protectedCommunicationZones.list.array = malloc(facilities.lightship.protected_zones.pz_len * sizeof(void*));
uint8_t buf[256];
for (int z = 0; z < facilities->lightship->protected_zones.pz_len; ++z) {
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);
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);
}
pthread_mutex_unlock(&facilities->lightship->lock);
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);
@ -528,14 +528,14 @@ cleanup:
return rv;
}
int facilities_request_chaininfo_set(facilities_t* facilities, void* responder, ChainInformation_t* cis) {
int facilities_request_chaininfo_set(void* responder, ChainInformation_t* cis) {
int rv = 0;
pthread_mutex_lock(&facilities->coordination.lock);
facilities->coordination.chain.id = cis->id;
memcpy(facilities->coordination.chain.link, cis->link.buf, cis->link.size);
pthread_mutex_lock(&facilities.coordination.lock);
facilities.coordination.chain.id = cis->id;
memcpy(facilities.coordination.chain.link, cis->link.buf, cis->link.size);
// TODO region
pthread_mutex_unlock(&facilities->coordination.lock);
pthread_mutex_unlock(&facilities.coordination.lock);
FacilitiesReply_t* frep = calloc(1, sizeof(FacilitiesReply_t));
frep->present = FacilitiesReply_PR_data;

View File

@ -8,12 +8,12 @@
int facilities_request_result_accepted(void* responder);
int facilities_request_result_rejected(void* responder);
int facilities_request_single_message(facilities_t* facilities, void* responder, FacilitiesMessageRequest_t* frm);
int facilities_request_active_episodes(facilities_t* facilities, void* responder, FacilitiesRequest_t* fr);
int facilities_request_attribute_types(facilities_t* facilities, void* responder, FacilitiesRequest_t* fr);
int facilities_request_loaded_protected_zones(facilities_t* facilities, void* responder, FacilitiesRequest_t* fr);
int facilities_request_chaininfo_set(facilities_t* facilities, void* responder, ChainInformation_t* cis);
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, ChainInformation_t* cis);
int transport_indication_data(facilities_t* facilities, TransportDataIndication_t* tdi);
int transport_indication_data(TransportDataIndication_t* tdi);
#endif

View File

@ -19,12 +19,12 @@
#include <saem/SAEM.h>
SAEM_CODE_R saem_check(void* fc, bulletin_t* bulletin, SAEM_t* saem, uint8_t* neighbour) {
facilities_t* facilities = (facilities_t*) fc;
SAEM_CODE_R saem_check(SAEM_t* saem, uint8_t* neighbour) {
int rv = 0;
bulletin_t* bulletin = &facilities.bulletin;
if (saem->header.messageID != messageID_saem) {
return SAEM_INVALID_HEADER_MESSAGE_ID;
}
@ -68,7 +68,7 @@ SAEM_CODE_R saem_check(void* fc, bulletin_t* bulletin, SAEM_t* saem, uint8_t* ne
si->chOptions.extensions->list.array[e]->choice.applicationDataSAM.size
);
if (facilities->station_type != 15 && facilities->tolling.infos.length < TOLLING_INFOS_MAX_LENGTH) {
if (facilities.station_type != 15 && facilities.tolling.infos.length < TOLLING_INFOS_MAX_LENGTH) {
TollingPaymentInfo_t* tpi = NULL;
asn_dec_rval_t dec = uper_decode_complete(
NULL,
@ -88,9 +88,9 @@ SAEM_CODE_R saem_check(void* fc, bulletin_t* bulletin, SAEM_t* saem, uint8_t* ne
}
if (!found) {
facilities->tolling.infos.z[facilities->tolling.infos.length] = tolling_info_new(tpi);
bulletin->to_consume[bulletin->to_consume_len]->info.internal_p = facilities->tolling.infos.z[facilities->tolling.infos.length];
++facilities->tolling.infos.length;
facilities.tolling.infos.z[facilities.tolling.infos.length] = tolling_info_new(tpi);
bulletin->to_consume[bulletin->to_consume_len]->info.internal_p = facilities.tolling.infos.z[facilities.tolling.infos.length];
++facilities.tolling.infos.length;
new_announcement = true;
}
} else {
@ -141,7 +141,9 @@ SAEM_CODE_R saem_check(void* fc, bulletin_t* bulletin, SAEM_t* saem, uint8_t* ne
return rv == SAEM_NEW ? SAEM_NEW : SAEM_OK;
}
void bulletin_init(bulletin_t* bulletin) {
void bulletin_init() {
bulletin_t* bulletin = &facilities.bulletin;
pthread_mutex_init(&bulletin->lock, NULL);
@ -152,11 +154,11 @@ void bulletin_init(bulletin_t* bulletin) {
}
int mk_saem(facilities_t* facilities, uint8_t* b_saem, uint32_t* b_saem_len) {
int mk_saem(uint8_t* b_saem, uint32_t* b_saem_len) {
int rv = 0;
// Check tolling advertisements
if (!facilities->tolling.infos.length) {
if (!facilities.tolling.infos.length) {
return 1;
}
@ -168,19 +170,19 @@ int mk_saem(facilities_t* facilities, uint8_t* b_saem, uint32_t* b_saem_len) {
saem->header.protocolVersion = 1;
saem->header.messageID = messageID_saem;
pthread_mutex_lock(&facilities->id.lock);
saem->header.stationID = facilities->id.station_id;
pthread_mutex_lock(&facilities.id.lock);
saem->header.stationID = facilities.id.station_id;
/* sam */
saem->sam.version = 0;
saem->sam.body.serviceInfos = calloc(1, sizeof(ServiceInfos_t));
saem->sam.body.serviceInfos->list.count = facilities->tolling.infos.length;
saem->sam.body.serviceInfos->list.size = facilities->tolling.infos.length * sizeof(void*);
saem->sam.body.serviceInfos->list.array = malloc(facilities->tolling.infos.length * sizeof(void*));
saem->sam.body.serviceInfos->list.count = facilities.tolling.infos.length;
saem->sam.body.serviceInfos->list.size = facilities.tolling.infos.length * sizeof(void*);
saem->sam.body.serviceInfos->list.array = malloc(facilities.tolling.infos.length * sizeof(void*));
uint8_t buf[1024];
for (int i = 0; i < facilities->tolling.infos.length; ++i) {
for (int 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]->serviceID = 1;
@ -188,7 +190,7 @@ int mk_saem(facilities_t* facilities, uint8_t* b_saem, uint32_t* b_saem_len) {
ServiceInfoExts_t* exts = saem->sam.body.serviceInfos->list.array[i]->chOptions.extensions;
switch (facilities->tolling.protocol.p) {
switch (facilities.tolling.protocol.p) {
case TOLLING_PROTOCOL_SIMPLE:
exts->list.count = 3;
exts->list.size = 3 * sizeof(void*);
@ -210,7 +212,7 @@ int mk_saem(facilities_t* facilities, uint8_t* b_saem, uint32_t* b_saem_len) {
exts->list.array[2]->present = ServiceInfoExt_PR_applicationDataSAM;
exts->list.array[2]->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_TollingPaymentInfo, NULL, facilities.tolling.infos.z[i]->asn, exts->list.array[2]->choice.applicationDataSAM.buf, 1024);
if (enc.encoded == -1) {
syslog_err("[facilities] [sa] failure to encode TollingPaymentInfo (%s)", enc.failed_type->name);
rv = 1;
@ -238,7 +240,7 @@ int mk_saem(facilities_t* facilities, uint8_t* b_saem, uint32_t* b_saem_len) {
exts->list.array[1]->present = 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);
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;
@ -248,7 +250,7 @@ int mk_saem(facilities_t* facilities, uint8_t* b_saem, uint32_t* b_saem_len) {
exts->list.array[3]->present = 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_TollingPaymentInfo, NULL, facilities.tolling.infos.z[i]->asn, exts->list.array[3]->choice.applicationDataSAM.buf, 1024);
if (enc.encoded == -1) {
syslog_err("[facilities] [sa] failure to encode TollingPaymentInfo (%s)", enc.failed_type->name);
rv = 1;
@ -260,7 +262,7 @@ int mk_saem(facilities_t* facilities, uint8_t* b_saem, uint32_t* b_saem_len) {
}
}
pthread_mutex_unlock(&facilities->id.lock);
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);
if (enc.encoded == -1) {
@ -276,10 +278,9 @@ cleanup:
return rv;
}
void *sa_service(void *fc) {
facilities_t *facilities = (facilities_t*) fc;
void *sa_service() {
pthread_mutex_init(&facilities->bulletin.lock, NULL);
pthread_mutex_init(&facilities.bulletin.lock, NULL);
TransportRequest_t *tr = calloc(1, sizeof(TransportRequest_t));
tr->present = TransportRequest_PR_packet;
@ -288,7 +289,7 @@ void *sa_service(void *fc) {
tpr->present = TransportPacketRequest_PR_btp;
BTPPacketRequest_t *bpr = &tpr->choice.btp;
bulletin_t* bulletin = &facilities->bulletin;
bulletin_t* bulletin = &facilities.bulletin;
bpr->btpType = BTPType_btpB;
@ -309,8 +310,8 @@ void *sa_service(void *fc) {
bpr->gn.securityProfile.sign = true;
void* security_socket = zmq_socket(facilities->zmq.ctx, ZMQ_REQ);
zmq_connect(security_socket, facilities->zmq.security_address);
void* security_socket = zmq_socket(facilities.zmq.ctx, ZMQ_REQ);
zmq_connect(security_socket, facilities.zmq.security_address);
uint8_t tr_oer[1024];
tr_oer[0] = 4; // Facilities
@ -320,10 +321,10 @@ void *sa_service(void *fc) {
int sleep_ms = 100;
int mk_saem_n_sleep = 0;
while (!facilities->exit) {
while (!facilities.exit) {
if (bulletin->to_provide_len && sleep_ms*mk_saem_n_sleep >= 1000) {
rv = mk_saem(facilities, bpr->data.buf, (uint32_t *) &bpr->data.size);
rv = mk_saem(bpr->data.buf, (uint32_t *) &bpr->data.size);
if (!rv) {
bpr->id = itss_id(bpr->data.buf, bpr->data.size);
@ -333,15 +334,15 @@ void *sa_service(void *fc) {
syslog_err("[facilities] encoding TR for SAEM failed");
continue;
} else {
itss_queue_send(facilities->tx_queue, tr_oer, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp");
itss_queue_send(facilities.tx_queue, tr_oer, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp");
// Logging
if (facilities->logging.dbms) {
pthread_mutex_lock(&facilities->id.lock);
uint64_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_saem, NULL, bpr->data.buf, bpr->data.size);
if (facilities.logging.dbms) {
pthread_mutex_lock(&facilities.id.lock);
uint64_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_saem, NULL, bpr->data.buf, bpr->data.size);
}
if (facilities->logging.recorder) {
if (facilities.logging.recorder) {
uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len];
int e = itss_management_record_packet_sdu(
@ -354,7 +355,7 @@ void *sa_service(void *fc) {
ITSS_FACILITIES,
true);
if (e != -1) {
itss_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, bpr->id, "MReq.packet.set");
itss_queue_send(facilities.tx_queue, buffer, e, ITSS_MANAGEMENT, bpr->id, "MReq.packet.set");
}
}
}
@ -375,23 +376,23 @@ void *sa_service(void *fc) {
pthread_mutex_lock(&bulletin->lock);
for (int a = 0; a < bulletin->to_consume_len; ++a) {
// Tolling
if (facilities->tolling.enabled &&
if (facilities.tolling.enabled &&
bulletin->to_consume[a]->its_aid == 1 &&
(
now > bulletin->to_consume[a]->t_trigger + TOLLING_PAYMENT_MIN_PERIOD_MS ||
(facilities->tolling.protocol.p == TOLLING_PROTOCOL_SIMPLE && tpm_should_retransmit(facilities))
(facilities.tolling.protocol.p == TOLLING_PROTOCOL_SIMPLE && tpm_should_retransmit())
) &&
facilities->station_type != 15) {
facilities.station_type != 15) {
tolling_info_t* info = (tolling_info_t*) bulletin->to_consume[a]->info.internal_p;
if (!tpm_is_inside_zone(facilities, info)) {
if (!tpm_is_inside_zone(info)) {
continue;
}
switch (facilities->tolling.protocol.p) {
switch (facilities.tolling.protocol.p) {
case TOLLING_PROTOCOL_SIMPLE:
tpm_pay(facilities, info, security_socket, bulletin->to_consume[a]->certificate_id, NULL);
tpm_pay(info, security_socket, bulletin->to_consume[a]->certificate_id, NULL);
++bulletin->to_consume[a]->n_trigger;
bulletin->to_consume[a]->t_trigger = now;
break;
@ -399,7 +400,7 @@ void *sa_service(void *fc) {
case TOLLING_PROTOCOL_TLS:
case TOLLING_PROTOCOL_TLS_GN:
case TOLLING_PROTOCOL_TLS_SHS:
tpm_pay(facilities, info, security_socket, NULL, bulletin->to_consume[a]->endpoint.ipv6_addr);
tpm_pay(info, security_socket, NULL, bulletin->to_consume[a]->endpoint.ipv6_addr);
++bulletin->to_consume[a]->n_trigger;
bulletin->to_consume[a]->t_trigger = now;
break;
@ -409,10 +410,10 @@ void *sa_service(void *fc) {
pthread_mutex_unlock(&bulletin->lock);
// Tolling management
if (facilities->tolling.protocol.p == TOLLING_PROTOCOL_TLS ||
facilities->tolling.protocol.p == TOLLING_PROTOCOL_TLS_GN ||
facilities->tolling.protocol.p == TOLLING_PROTOCOL_TLS_SHS) {
tolling_tlsc_mgmt(&facilities->tolling, facilities->tx_queue, security_socket);
if (facilities.tolling.protocol.p == TOLLING_PROTOCOL_TLS ||
facilities.tolling.protocol.p == TOLLING_PROTOCOL_TLS_GN ||
facilities.tolling.protocol.p == TOLLING_PROTOCOL_TLS_SHS) {
tolling_tlsc_mgmt(facilities.tx_queue, security_socket);
}
usleep(sleep_ms*1000);

View File

@ -53,26 +53,22 @@ typedef enum SAEM_CODE {
/**
* Initiaties bulletin, the main SA structure
*
* @param bulletin The structure to initialize
* @return Nothing
*/
void bulletin_init(bulletin_t* bulletin);
void bulletin_init();
/**
* Checks SAEM, saves advertisements
*
* @param fc The main facilities structure
* @param bulletin The main SA structure
* @param saem The SAEM message to check
* @param neighbour The certificate used by the neighbour, for encryption
* @return SAEM_CODE
*/
SAEM_CODE_R saem_check(void* fc, bulletin_t* bulletin, SAEM_t* saem, uint8_t* neighbour);
SAEM_CODE_R saem_check(SAEM_t* saem, uint8_t* neighbour);
/**
* The main SA function, run as a thread
*
* @param The main facilities structure
* @return NULL
*/
void* sa_service(void* fc);
void* sa_service();

124
src/tpm.c
View File

@ -20,10 +20,9 @@ static char* tts(int type) {
else return stype[type];
}
int tpm_is_inside_zone(void* fc, tolling_info_t* ti) {
int tpm_is_inside_zone(tolling_info_t* ti) {
int rv = 0;
facilities_t* facilities = (facilities_t*) fc;
double point[2];
itss_space_lock();
itss_space_get();
@ -38,10 +37,9 @@ int tpm_is_inside_zone(void* fc, tolling_info_t* ti) {
return 0;
}
int tpm_should_retransmit(void* fc) {
int tpm_should_retransmit() {
facilities_t* facilities = (facilities_t*) fc;
tolling_t* tolling = &facilities->tolling;
tolling_t* tolling = &facilities.tolling;
uint64_t now = itss_ts_get(TIME_MICROSECONDS);
@ -58,11 +56,10 @@ int tpm_should_retransmit(void* fc) {
return 0;
}
int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neighbour, uint8_t* dst_addr) {
int tpm_pay(tolling_info_t* info, void* security_socket, uint8_t* neighbour, uint8_t* dst_addr) {
int rv = 0;
facilities_t* facilities = (facilities_t*) fc;
tolling_t* tolling = (tolling_t*) &facilities->tolling;
tolling_t* tolling = (tolling_t*) &facilities.tolling;
const size_t buf_len = 2048;
uint8_t tpm_uper[buf_len];
@ -91,9 +88,9 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig
tpm->header.messageID = 117;
tpm->header.protocolVersion = 0;
pthread_mutex_lock(&facilities->id.lock);
tpm->header.stationID = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock);
pthread_mutex_lock(&facilities.id.lock);
tpm->header.stationID = facilities.id.station_id;
pthread_mutex_unlock(&facilities.id.lock);
tpm->tpm = calloc(1, sizeof(TollingPaymentMessage_t));
@ -101,7 +98,7 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig
asn_ulong2INTEGER(&tpm->tpm->timestamp, itss_time_get());
// stationType
tpm->tpm->stationType = facilities->station_type;
tpm->tpm->stationType = facilities.station_type;
// referencePosition
itss_space_lock();
@ -253,7 +250,7 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig
uint64_t id = 0;
switch (facilities->tolling.protocol.p) {
switch (facilities.tolling.protocol.p) {
case TOLLING_PROTOCOL_SIMPLE:
tr->choice.packet.present = TransportPacketRequest_PR_btp;
BTPPacketRequest_t* bpr = &tr->choice.packet.choice.btp;
@ -294,11 +291,11 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig
sreq->choice.tlsSend.data.size = tpm_uper_len;
memcpy(sreq->choice.tlsSend.data.buf, tpm_uper, tpm_uper_len);
tlsc_t* tlsc = tolling_tlsc_get(tolling, dst_addr, 7011);
tlsc_t* tlsc = tolling_tlsc_get(dst_addr, 7011);
if (tlsc) {
id = tlsc->id;
} else {
tlsc = tolling_tlsc_new(tolling, dst_addr, 7011);
tlsc = tolling_tlsc_new(dst_addr, 7011);
id = tlsc->id;
}
++tlsc->nmsg;
@ -367,7 +364,7 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig
goto cleanup;
}
itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, id,
itss_queue_send(facilities.tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, id,
tolling->protocol.p == TOLLING_PROTOCOL_SIMPLE ? "TR.packet.btp" : "TR.packet.tcp");
// Retransmission
@ -378,11 +375,11 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig
tolling->station.obu.rt_t_trigger = itss_ts_get(TIME_MICROSECONDS);
// Logging
if (facilities->logging.dbms) {
pthread_mutex_lock(&facilities->id.lock);
uint64_t station_id = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock);
itss_db_add(facilities->logging.dbms, station_id, id, true, 117, NULL, tpm_uper, tpm_uper_len);
if (facilities.logging.dbms) {
pthread_mutex_lock(&facilities.id.lock);
uint64_t station_id = facilities.id.station_id;
pthread_mutex_unlock(&facilities.id.lock);
itss_db_add(facilities.logging.dbms, station_id, id, true, 117, NULL, tpm_uper, tpm_uper_len);
}
// send to [applications]
@ -399,9 +396,9 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig
rv = 1;
goto cleanup;
}
itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message (TPM.request)");
itss_queue_send(facilities.tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message (TPM.request)");
if (facilities->logging.recorder) {
if (facilities.logging.recorder) {
uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len];
int e = itss_management_record_packet_sdu(
@ -414,7 +411,7 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig
ITSS_FACILITIES,
true);
if (e != -1) {
itss_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set");
itss_queue_send(facilities.tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set");
}
}
@ -429,7 +426,7 @@ cleanup:
return rv;
}
static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, uint8_t* src_addr) {
static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, uint8_t* src_addr) {
if (!tpm_rx->tpm->tollingType) {
syslog_err("[facilities] [tolling] received TPM does not have a type");
@ -554,7 +551,7 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur
return;
}
tolling_t* tolling = &facilities->tolling;
tolling_t* tolling = &facilities.tolling;
switch (tolling->protocol.p) {
case TOLLING_PROTOCOL_SIMPLE:
@ -655,9 +652,9 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur
tpm->header.messageID = 117;
tpm->header.protocolVersion = 0;
pthread_mutex_lock(&facilities->id.lock);
tpm->header.stationID = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock);
pthread_mutex_lock(&facilities.id.lock);
tpm->header.stationID = facilities.id.station_id;
pthread_mutex_unlock(&facilities.id.lock);
tpm->tpm = calloc(1, sizeof(TollingPaymentMessage_t));
@ -665,7 +662,7 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur
asn_ulong2INTEGER(&tpm->tpm->timestamp, itss_time_get());
// stationType
tpm->tpm->stationType = facilities->station_type;
tpm->tpm->stationType = facilities.station_type;
// referencePosition
itss_space_lock();
@ -873,11 +870,11 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur
sreq->choice.tlsSend.data.size = tpm_uper_len;
memcpy(sreq->choice.tlsSend.data.buf, tpm_uper, tpm_uper_len);
tlsc_t* tlsc = tolling_tlsc_get(tolling, src_addr, 7011);
tlsc_t* tlsc = tolling_tlsc_get(src_addr, 7011);
if (tlsc) {
id = tlsc->id;
} else {
tlsc = tolling_tlsc_new(tolling, src_addr, 7011);
tlsc = tolling_tlsc_new(src_addr, 7011);
id = tlsc->id;
}
++tlsc->nmsg;
@ -941,15 +938,15 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur
goto cleanup;
}
itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, id,
itss_queue_send(facilities.tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, id,
tolling->protocol.p == TOLLING_PROTOCOL_SIMPLE ? "TR.packet.btp" : "TR.packet.tcp");
// Logging
if (facilities->logging.dbms) {
pthread_mutex_lock(&facilities->id.lock);
uint64_t station_id = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock);
itss_db_add(facilities->logging.dbms, station_id, id, true, 117, NULL, tpm_uper, tpm_uper_len);
if (facilities.logging.dbms) {
pthread_mutex_lock(&facilities.id.lock);
uint64_t station_id = facilities.id.station_id;
pthread_mutex_unlock(&facilities.id.lock);
itss_db_add(facilities.logging.dbms, station_id, id, true, 117, NULL, tpm_uper, tpm_uper_len);
}
// send to [applications]
@ -966,8 +963,8 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur
goto cleanup;
}
itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message (TPM.reply)");
if (facilities->logging.recorder) {
itss_queue_send(facilities.tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message (TPM.reply)");
if (facilities.logging.recorder) {
uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len];
int e = itss_management_record_packet_sdu(
@ -980,7 +977,7 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur
ITSS_FACILITIES,
true);
if (e != -1) {
itss_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set");
itss_queue_send(facilities.tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set");
}
}
@ -1167,7 +1164,7 @@ static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_so
if (tolling->protocol.p == TOLLING_PROTOCOL_TLS ||
tolling->protocol.p == TOLLING_PROTOCOL_TLS_GN ||
tolling->protocol.p == TOLLING_PROTOCOL_TLS_SHS) {
tlsc_t* tlsc = tolling_tlsc_get(tolling, src_addr, 7011);
tlsc_t* tlsc = tolling_tlsc_get(src_addr, 7011);
if (tlsc) {
sreq = calloc(1, sizeof(SecurityRequest_t));
sreq->present = SecurityRequest_PR_tlsClose;
@ -1217,10 +1214,9 @@ cleanup:
ASN_STRUCT_FREE(asn_DEF_SecurityReply, srep);
}
int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, uint8_t* src_addr) {
int tpm_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, uint8_t* src_addr) {
facilities_t* facilities = (facilities_t*) fc;
tolling_t* tolling = (tolling_t*) &facilities->tolling;
tolling_t* tolling = &facilities.tolling;
if (!tolling->enabled) {
syslog_debug("[facilities] [tolling] tolling is disabled");
@ -1244,14 +1240,14 @@ int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour,
case TollingType_PR_entry:
switch (tpm_rx->tpm->tollingType->choice.entry.present) {
case TollingSingle_PR_request:
if (facilities->station_type != 15) {
if (facilities.station_type != 15) {
syslog_debug("[facilities] [tolling] received TPM.entry.request, ignoring");
goto cleanup;
}
rsu_handle_recv(facilities, tpm_rx, security_socket, neighbour, src_addr);
rsu_handle_recv(tpm_rx, security_socket, neighbour, src_addr);
break;
case TollingSingle_PR_reply:
if (facilities->station_type == 15) {
if (facilities.station_type == 15) {
syslog_debug("[facilities] [tolling] received TPM.entry.reply, ignoring");
goto cleanup;
}
@ -1259,7 +1255,7 @@ int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour,
syslog_info("[facilities] [tolling] entry.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->station.obu.rt_init);
itss_time_unlock();
tolling->station.obu.rt_on = false;
veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, neighbour, src_addr);
veh_handle_recv(tolling, tpm_rx, security_socket, facilities.tx_queue, neighbour, src_addr);
break;
default:
break;
@ -1272,14 +1268,14 @@ int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour,
}
switch (tpm_rx->tpm->tollingType->choice.exit->present) {
case TollingSingle_PR_request:
if (facilities->station_type != 15) {
if (facilities.station_type != 15) {
syslog_debug("[facilities] [tolling] received TPM.exit.request, ignoring");
goto cleanup;
}
rsu_handle_recv(facilities, tpm_rx, security_socket, neighbour, src_addr);
rsu_handle_recv(tpm_rx, security_socket, neighbour, src_addr);
break;
case TollingSingle_PR_reply:
if (facilities->station_type == 15) {
if (facilities.station_type == 15) {
syslog_debug("[facilities] [tolling] received TPM.exit.reply, ignoring");
goto cleanup;
}
@ -1287,7 +1283,7 @@ int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour,
syslog_info("[facilities] [tolling] exit.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->station.obu.rt_init);
itss_time_unlock();
tolling->station.obu.rt_on = false;
veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, neighbour, src_addr);
veh_handle_recv(tolling, tpm_rx, security_socket, facilities.tx_queue, neighbour, src_addr);
break;
default:
break;
@ -1297,14 +1293,14 @@ int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour,
case TollingType_PR_single:
switch (tpm_rx->tpm->tollingType->choice.single.present) {
case TollingSingle_PR_request:
if (facilities->station_type != 15) {
if (facilities.station_type != 15) {
syslog_debug("[facilities] [tolling] received TPM.single.request, ignoring");
goto cleanup;
}
rsu_handle_recv(facilities, tpm_rx, security_socket, neighbour, src_addr);
rsu_handle_recv(tpm_rx, security_socket, neighbour, src_addr);
break;
case TollingSingle_PR_reply:
if (facilities->station_type == 15) {
if (facilities.station_type == 15) {
syslog_debug("[facilities] [tolling] received TPM.single.reply, ignoring");
goto cleanup;
}
@ -1312,7 +1308,7 @@ int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour,
syslog_info("[facilities] [tolling] single.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->station.obu.rt_init);
itss_time_unlock();
tolling->station.obu.rt_on = false;
veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, neighbour, src_addr);
veh_handle_recv(tolling, tpm_rx, security_socket, facilities.tx_queue, neighbour, src_addr);
break;
default:
break;
@ -1329,7 +1325,8 @@ cleanup:
return 0;
}
int tolling_init(tolling_t* tolling, void* zmq_ctx, char* security_address, uint8_t station_type) {
int tolling_init(void* zmq_ctx, char* security_address, uint8_t station_type) {
tolling_t* tolling = &facilities.tolling;
pthread_mutex_init(&tolling->lock, NULL);
switch (station_type) {
@ -1368,7 +1365,10 @@ void tolling_info_free(tolling_info_t* ti) {
free(ti);
}
tlsc_t* tolling_tlsc_new(tolling_t* tolling, uint8_t ipv6[16], uint16_t port) {
tlsc_t* tolling_tlsc_new(uint8_t ipv6[16], uint16_t port) {
tolling_t* tolling = &facilities.tolling;
syslog_debug("[tolling] new tlsc, nconns=%d", tolling->protocol.c.tls.n_tlsc);
if (tolling->protocol.c.tls.n_tlsc >= TOLLING_MAX_CONNS - 1) {
return NULL;
@ -1385,7 +1385,8 @@ tlsc_t* tolling_tlsc_new(tolling_t* tolling, uint8_t ipv6[16], uint16_t port) {
return tlsc;
}
tlsc_t* tolling_tlsc_get(tolling_t* tolling, uint8_t ipv6[16], uint16_t port) {
tlsc_t* tolling_tlsc_get(uint8_t ipv6[16], uint16_t port) {
tolling_t* tolling = &facilities.tolling;
syslog_debug("[tolling] new get , nconns=%d", tolling->protocol.c.tls.n_tlsc);
tlsc_t* tlsc = NULL;
for (int i = 0; i < tolling->protocol.c.tls.n_tlsc; ++i) {
@ -1400,7 +1401,8 @@ tlsc_t* tolling_tlsc_get(tolling_t* tolling, uint8_t ipv6[16], uint16_t port) {
}
void tolling_tlsc_mgmt(tolling_t* tolling, itss_queue_t* tx_queue, void* security_socket) {
void tolling_tlsc_mgmt(itss_queue_t* tx_queue, void* security_socket) {
tolling_t* tolling = &facilities.tolling;
pthread_mutex_lock(&tolling->lock);
uint64_t now = itss_time_get();
for (int i = 0; i < tolling->protocol.c.tls.n_tlsc; ++i) {

View File

@ -102,21 +102,20 @@ typedef struct tolling {
/**
* Initializes the main tolling struture
*
* @param tolling The structure to initialize
* @param zmq_ctx The facilities ZMQ context
* @param security_address The security service ZMQ address
* @return Always successful
*/
int tolling_init(tolling_t* tolling, void* zmq_ctx, char* security_address, uint8_t station_type);
int tolling_init(void* zmq_ctx, char* security_address, uint8_t station_type);
int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neighbour, uint8_t* dst_addr);
int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, uint8_t* src_addr);
int tpm_should_retransmit(void* fc);
int tpm_is_inside_zone(void* fc, tolling_info_t* ti);
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_should_retransmit();
int tpm_is_inside_zone(tolling_info_t* ti);
tolling_info_t* tolling_info_new(TollingPaymentInfo_t* tpi);
void tolling_info_free(tolling_info_t* ti);
tlsc_t* tolling_tlsc_new(tolling_t* tolling, uint8_t ipv6[16], uint16_t port);
tlsc_t* tolling_tlsc_get(tolling_t* tolling, uint8_t ipv6[16], uint16_t port);
void tolling_tlsc_mgmt(tolling_t* tolling, itss_queue_t* tx_queue, void* security_socket);
tlsc_t* tolling_tlsc_new(uint8_t ipv6[16], uint16_t port);
tlsc_t* tolling_tlsc_get(uint8_t ipv6[16], uint16_t port);
void tolling_tlsc_mgmt(itss_queue_t* tx_queue, void* security_socket);

View File

@ -51,14 +51,14 @@ static int are_vehicles_intersecting(
return 0;
}
static int vcm_check_handle_request(facilities_t* facilities, VCM_t* vcm, mc_neighbour_s* neighbour) {
static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) {
int rv = 0;
coordination_s* coordination = &facilities->coordination;
coordination_t* coordination = &facilities.coordination;
pthread_mutex_lock(&facilities->id.lock);
uint64_t my_station_id = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock);
pthread_mutex_lock(&facilities.id.lock);
uint64_t my_station_id = facilities.id.station_id;
pthread_mutex_unlock(&facilities.id.lock);
// Is request for me?
CoordinationRequest_t* request = &vcm->vcm.maneuverContainer.choice.vehicle.negotiation->choice.request;
@ -124,9 +124,9 @@ static int vcm_check_handle_request(facilities_t* facilities, VCM_t* vcm, mc_nei
ManeuverVehicleContainer_t* mvc_rep = &vcm_rep->vcm.maneuverContainer.choice.vehicle;
// Vehicle DimensionsDimensions
mvc_rep->vehicleLength.vehicleLengthValue= facilities->vehicle.length;
mvc_rep->vehicleLength.vehicleLengthValue= facilities.vehicle.length;
mvc_rep->vehicleLength.vehicleLengthConfidenceIndication = 0;
mvc_rep->vehicleWidth = facilities->vehicle.width;
mvc_rep->vehicleWidth = facilities.vehicle.width;
// Accepted trajectory
if (!request->desiredTrajectories.list.count) {
@ -181,7 +181,7 @@ static int vcm_check_handle_request(facilities_t* facilities, VCM_t* vcm, mc_nei
goto cleanup;
}
itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp");
itss_queue_send(facilities.tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp");
fi = calloc(1, sizeof(FacilitiesIndication_t));
fi->present = FacilitiesIndication_PR_message;
@ -198,9 +198,9 @@ static int vcm_check_handle_request(facilities_t* facilities, VCM_t* vcm, mc_nei
goto cleanup;
}
itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, bpr->id, "FI.message");
itss_queue_send(facilities.tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, bpr->id, "FI.message");
if (facilities->logging.recorder) {
if (facilities.logging.recorder) {
uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len];
int e = itss_management_record_packet_sdu(
@ -213,7 +213,7 @@ static int vcm_check_handle_request(facilities_t* facilities, VCM_t* vcm, mc_nei
ITSS_FACILITIES,
true);
if (e != -1) {
itss_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, bpr->id, "MReq.packet.set");
itss_queue_send(facilities.tx_queue, buffer, e, ITSS_MANAGEMENT, bpr->id, "MReq.packet.set");
}
}
@ -224,7 +224,7 @@ cleanup:
return rv;
}
static int vcm_check_handle_reply(facilities_t* facilities, VCM_t* vcm, mc_neighbour_s* neighbour) {
static int vcm_check_handle_reply(VCM_t* vcm, mc_neighbour_s* neighbour) {
int rv = 0;
CoordinationReply_t* reply = &vcm->vcm.maneuverContainer.choice.vehicle.negotiation->choice.reply;
@ -246,11 +246,11 @@ static int vcm_check_handle_reply(facilities_t* facilities, VCM_t* vcm, mc_neigh
return rv;
}
static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm, mc_neighbour_s* neighbour) {
static int vcm_check_intersection_detected(VCM_t* vcm, mc_neighbour_s* neighbour) {
int rv = 0;
coordination_s* coordination = &facilities->coordination;
coordination_t* coordination = &facilities.coordination;
VCM_t* vcm_req = NULL;
TransportRequest_t* tr = NULL;
@ -304,9 +304,9 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm,
vcm_req->header.messageID = 43;
vcm_req->header.protocolVersion = 1;
pthread_mutex_lock(&facilities->id.lock);
vcm_req->header.stationID = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock);
pthread_mutex_lock(&facilities.id.lock);
vcm_req->header.stationID = facilities.id.station_id;
pthread_mutex_unlock(&facilities.id.lock);
vcm_req->vcm.currentPosition.latitude = lat;
vcm_req->vcm.currentPosition.longitude = lon;
@ -325,9 +325,9 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm,
ManeuverVehicleContainer_t* mvc = &vcm_req->vcm.maneuverContainer.choice.vehicle;
// Vehicle Dimensions
mvc->vehicleLength.vehicleLengthValue= facilities->vehicle.length;
mvc->vehicleLength.vehicleLengthValue= facilities.vehicle.length;
mvc->vehicleLength.vehicleLengthConfidenceIndication = 0;
mvc->vehicleWidth = facilities->vehicle.width;
mvc->vehicleWidth = facilities.vehicle.width;
// Planned trajectory
mvc->plannedTrajectory.list.count = --trajectoryA_len;
@ -404,7 +404,7 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm,
goto cleanup;
}
itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp");
itss_queue_send(facilities.tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp");
fi = calloc(1, sizeof(FacilitiesIndication_t));
fi->present = FacilitiesIndication_PR_message;
@ -421,9 +421,9 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm,
goto cleanup;
}
itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, bpr->id, "FI.message");
itss_queue_send(facilities.tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, bpr->id, "FI.message");
if (facilities->logging.recorder) {
if (facilities.logging.recorder) {
uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len];
int e = itss_management_record_packet_sdu(
@ -436,7 +436,7 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm,
ITSS_FACILITIES,
true);
if (e != -1) {
itss_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, bpr->id, "MReq.packet.set");
itss_queue_send(facilities.tx_queue, buffer, e, ITSS_MANAGEMENT, bpr->id, "MReq.packet.set");
}
}
@ -447,9 +447,8 @@ cleanup:
return rv;
}
int vcm_check(void* fc, VCM_t* vcm) {
facilities_t* facilities = (facilities_t*) fc;
coordination_s* coordination = &facilities->coordination;
int vcm_check(VCM_t* vcm) {
coordination_t* coordination = &facilities.coordination;
int rv = 0;
@ -492,10 +491,10 @@ int vcm_check(void* fc, VCM_t* vcm) {
if (mvc->negotiation) {
switch (mvc->negotiation->present) {
case CoordinationNegotiation_PR_request:
vcm_check_handle_request(facilities, vcm, &coordination->neighbours[ni]);
vcm_check_handle_request(vcm, &coordination->neighbours[ni]);
break;
case CoordinationNegotiation_PR_reply:
vcm_check_handle_reply(facilities, vcm, &coordination->neighbours[ni]);
vcm_check_handle_reply(vcm, &coordination->neighbours[ni]);
break;
default:
break;
@ -528,7 +527,7 @@ int vcm_check(void* fc, VCM_t* vcm) {
if (trajectoryA_len > 1 && trajectoryB_len > 1) {
intersecting = are_vehicles_intersecting(
trajectoryA, trajectoryA_len, facilities->vehicle.length, facilities->vehicle.width,
trajectoryA, trajectoryA_len, facilities.vehicle.length, facilities.vehicle.width,
trajectoryB, trajectoryB_len, mvc->vehicleLength.vehicleLengthValue, mvc->vehicleWidth,
&index);
}
@ -540,7 +539,7 @@ int vcm_check(void* fc, VCM_t* vcm) {
trajectoryA[index].longitude/1.0e7,
trajectoryA[index].timestamp - now);
vcm_check_intersection_detected(facilities, vcm, &coordination->neighbours[ni]);
vcm_check_intersection_detected(vcm, &coordination->neighbours[ni]);
}
}
break;
@ -556,10 +555,10 @@ int vcm_check(void* fc, VCM_t* vcm) {
return rv;
}
static int mk_vcm(facilities_t* facilities, uint8_t* vcm_uper, uint16_t* vcm_uper_len) {
static int mk_vcm(uint8_t* vcm_uper, uint16_t* vcm_uper_len) {
int rv = 0;
coordination_s* coordination = &facilities->coordination;
coordination_t* coordination = &facilities.coordination;
itss_st_t trajectory[TRAJECTORY_MAX_LEN];
@ -568,9 +567,9 @@ static int mk_vcm(facilities_t* facilities, uint8_t* vcm_uper, uint16_t* vcm_upe
vcm->header.messageID = 43;
vcm->header.protocolVersion = 1;
uint64_t now = itss_time_get();
pthread_mutex_lock(&facilities->id.lock);
vcm->header.stationID = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock);
pthread_mutex_lock(&facilities.id.lock);
vcm->header.stationID = facilities.id.station_id;
pthread_mutex_unlock(&facilities.id.lock);
int32_t lat, lon;
uint16_t trajectory_len = 0;
@ -598,7 +597,7 @@ static int mk_vcm(facilities_t* facilities, uint8_t* vcm_uper, uint16_t* vcm_upe
vcm->vcm.chain->area.present = ChainGeoRegion_PR_circle;
}
if (facilities->station_type == StationType_roadSideUnit) {
if (facilities.station_type == StationType_roadSideUnit) {
vcm->vcm.maneuverContainer.present = ManeuverContainer_PR_rsu;
ManeuverRSUContainer_t* mrc = &vcm->vcm.maneuverContainer.choice.rsu;
mrc->recommendedTrajectories = NULL; // TODO
@ -606,9 +605,9 @@ static int mk_vcm(facilities_t* facilities, uint8_t* vcm_uper, uint16_t* vcm_upe
vcm->vcm.maneuverContainer.present = ManeuverContainer_PR_vehicle;
ManeuverVehicleContainer_t* mvc = &vcm->vcm.maneuverContainer.choice.vehicle;
// Vehicle Dimensions
mvc->vehicleLength.vehicleLengthValue= facilities->vehicle.length;
mvc->vehicleLength.vehicleLengthValue= facilities.vehicle.length;
mvc->vehicleLength.vehicleLengthConfidenceIndication = 0;
mvc->vehicleWidth = facilities->vehicle.width;
mvc->vehicleWidth = facilities.vehicle.width;
mvc->plannedTrajectory.list.count = trajectory_len;
mvc->plannedTrajectory.list.size = trajectory_len * sizeof(void*);
@ -635,7 +634,7 @@ cleanup:
return rv;
}
static bool vcm_timer_check(coordination_s* coordination, uint64_t now) {
static bool vcm_timer_check(coordination_t* coordination, uint64_t now) {
bool send = false;
@ -646,10 +645,9 @@ static bool vcm_timer_check(coordination_s* coordination, uint64_t now) {
return send;
}
void* vc_service(void* fc) {
void* vc_service() {
facilities_t* facilities = (facilities_t*) fc;
coordination_s* coordination = (coordination_s*) &facilities->coordination;
coordination_t* coordination = (coordination_t*) &facilities.coordination;
uint8_t vcm[512];
@ -679,13 +677,13 @@ void* vc_service(void* fc) {
int rv;
while (!facilities->exit) {
while (!facilities.exit) {
uint64_t now = itss_time_get();
pthread_mutex_lock(&coordination->lock);
if (vcm_timer_check(coordination, now)) {
rv = mk_vcm(facilities, bpr->data.buf, (uint16_t *) &bpr->data.size);
rv = mk_vcm(bpr->data.buf, (uint16_t *) &bpr->data.size);
if (rv) {
continue;
}
@ -697,7 +695,7 @@ void* vc_service(void* fc) {
syslog_err("[facilities] encoding TR for VCM failed");
continue;
}
itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp");
itss_queue_send(facilities.tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp");
fi->choice.message.id = bpr->id;
fi->choice.message.data.size = bpr->data.size;
@ -707,9 +705,9 @@ void* vc_service(void* fc) {
syslog_err("[facilities] encoding FI for VCM failed");
continue;
}
itss_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, bpr->id, "FI.message");
itss_queue_send(facilities.tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, bpr->id, "FI.message");
if (facilities->logging.recorder) {
if (facilities.logging.recorder) {
uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len];
int e = itss_management_record_packet_sdu(
@ -722,7 +720,7 @@ void* vc_service(void* fc) {
ITSS_FACILITIES,
true);
if (e != -1) {
itss_queue_send(facilities->tx_queue, buffer, e, ITSS_MANAGEMENT, bpr->id, "MReq.packet.set");
itss_queue_send(facilities.tx_queue, buffer, e, ITSS_MANAGEMENT, bpr->id, "MReq.packet.set");
}
}
@ -736,6 +734,6 @@ void* vc_service(void* fc) {
return NULL;
}
void coordination_init(coordination_s* coordination) {
void coordination_init(coordination_t* coordination) {
pthread_mutex_init(&coordination->lock, NULL);
}

View File

@ -36,8 +36,8 @@ typedef struct coordination {
itss_region_t region;
} chain;
} coordination_s;
} coordination_t;
int vcm_check(void* fc, VCM_t* vcm);
void* vc_service(void* fc);
void coordination_init(coordination_s* coordination);
int vcm_check(VCM_t* vcm);
void* vc_service();
void coordination_init();