EPV global variable

This commit is contained in:
emanuel 2022-08-18 12:43:44 +01:00
parent 548f7b7ba2
commit 6d9d413c7e
15 changed files with 260 additions and 264 deletions

View File

@ -110,7 +110,7 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len)
BasicContainer_t* bc = &cam->cam.camParameters.basicContainer;
uint64_t now = itss_time_get(&facilities->epv);
uint64_t now = itss_time_get();
lightship_t* lightship = facilities->lightship;
pthread_mutex_lock(&lightship->lock);
@ -118,16 +118,16 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len)
if (facilities->station_type != StationType_roadSideUnit) {
cam->cam.generationDeltaTime = now % 65536;
itss_space_lock(&facilities->epv);
itss_space_get(&facilities->epv);
bc->referencePosition.altitude.altitudeValue = facilities->epv.space.altitude;
bc->referencePosition.altitude.altitudeConfidence = facilities->epv.space.altitude_conf;
itss_space_lock();
itss_space_get();
bc->referencePosition.altitude.altitudeValue = epv.space.altitude;
bc->referencePosition.altitude.altitudeConfidence = epv.space.altitude_conf;
// Set GPS coordinates
bc->referencePosition.latitude = facilities->epv.space.latitude;
bc->referencePosition.longitude = facilities->epv.space.longitude;
uint16_t lat_conf = facilities->epv.space.latitude_conf;
uint16_t lon_conf = facilities->epv.space.longitude_conf;
bc->referencePosition.latitude = epv.space.latitude;
bc->referencePosition.longitude = epv.space.longitude;
uint16_t lat_conf = epv.space.latitude_conf;
uint16_t lon_conf = epv.space.longitude_conf;
cam->cam.camParameters.highFrequencyContainer.present = HighFrequencyContainer_PR_basicVehicleContainerHighFrequency;
BasicVehicleContainerHighFrequency_t* bvc_hf = &cam->cam.camParameters.highFrequencyContainer.choice.basicVehicleContainerHighFrequency;
@ -162,14 +162,14 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len)
}
// Set speed
bvc_hf->speed.speedValue = facilities->epv.space.speed;
bvc_hf->speed.speedConfidence = facilities->epv.space.speed_conf;
bvc_hf->speed.speedValue = epv.space.speed;
bvc_hf->speed.speedConfidence = epv.space.speed_conf;
// Set heading
bvc_hf->heading.headingValue = facilities->epv.space.heading;
bvc_hf->heading.headingConfidence = facilities->epv.space.heading_conf;
bvc_hf->heading.headingValue = epv.space.heading;
bvc_hf->heading.headingConfidence = epv.space.heading_conf;
itss_space_unlock(&facilities->epv);
itss_space_unlock(epv);
if (lat_conf > lon_conf) {
bc->referencePosition.positionConfidenceEllipse.semiMinorConfidence = lon_conf;
@ -290,18 +290,18 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len)
} else {
cam->cam.generationDeltaTime = now % 65536;
itss_space_lock(&facilities->epv);
itss_space_get(&facilities->epv);
bc->referencePosition.altitude.altitudeValue = facilities->epv.space.altitude;
bc->referencePosition.altitude.altitudeConfidence = facilities->epv.space.altitude_conf;
itss_space_lock();
itss_space_get();
bc->referencePosition.altitude.altitudeValue = epv.space.altitude;
bc->referencePosition.altitude.altitudeConfidence = epv.space.altitude_conf;
// Set GPS coordinates
bc->referencePosition.latitude = facilities->epv.space.latitude;
bc->referencePosition.longitude = facilities->epv.space.longitude;
bc->referencePosition.latitude = epv.space.latitude;
bc->referencePosition.longitude = epv.space.longitude;
bc->referencePosition.positionConfidenceEllipse.semiMinorConfidence = SemiAxisLength_unavailable;
bc->referencePosition.positionConfidenceEllipse.semiMajorConfidence = SemiAxisLength_unavailable;
bc->referencePosition.positionConfidenceEllipse.semiMajorOrientation = HeadingValue_unavailable;
itss_space_unlock(&facilities->epv);
itss_space_unlock();
cam->cam.camParameters.highFrequencyContainer.present = HighFrequencyContainer_PR_rsuContainerHighFrequency;
@ -383,10 +383,10 @@ lightship_t* lightship_init() {
}
int lightship_check(lightship_t* lightship, itss_epv_t* epv) {
int lightship_check(lightship_t* lightship) {
int rv = 0;
uint64_t now = itss_time_get(epv);
uint64_t now = itss_time_get();
pthread_mutex_lock(&lightship->lock);
@ -399,22 +399,22 @@ int lightship_check(lightship_t* lightship, itss_epv_t* epv) {
rv = 1;
} else if (now > lightship->next_cam_min) {
itss_space_lock(epv);
itss_space_get(epv);
itss_space_lock();
itss_space_get();
// Check heading delta > 4º
int diff = epv->space.heading - lightship->pos_history[0]->heading;
int diff = epv.space.heading - lightship->pos_history[0]->heading;
if (abs(diff) > 40) rv = 1;
if (!rv) {
// Check speed delta > 0.5 m/s
diff = epv->space.speed - lightship->pos_history[0]->speed;
diff = epv.space.speed - lightship->pos_history[0]->speed;
if (abs(diff) > 50) rv = 1;
if (!rv) {
// Check position delta > 4 m
// TODO make an *accurate* distance calculator using GPS coords
int32_t avg_speed = (epv->space.speed + lightship->pos_history[0]->speed)/2 / 100; /* cm/s to m/s */
int32_t avg_speed = (epv.space.speed + lightship->pos_history[0]->speed)/2 / 100; /* cm/s to m/s */
uint64_t delta_time = (now - lightship->last_cam) / 1000; /* ms to s */
if (avg_speed * delta_time > 4) rv = 1;
}
@ -445,8 +445,8 @@ int lightship_check(lightship_t* lightship, itss_epv_t* epv) {
return rv;
}
void lightship_reset_timer(lightship_t* lightship, itss_epv_t* epv) {
uint64_t now = itss_time_get(epv);
void lightship_reset_timer(lightship_t* lightship) {
uint64_t now = itss_time_get();
pthread_mutex_lock(&lightship->lock);
@ -463,12 +463,12 @@ void lightship_reset_timer(lightship_t* lightship, itss_epv_t* epv) {
pthread_mutex_unlock(&lightship->lock);
}
enum CAM_CHECK_R check_cam(void* fc, BTPPacketIndication_t *bpi, CAM_t* cam, itss_epv_t* epv, uint8_t* ssp, uint32_t ssp_len) {
enum CAM_CHECK_R check_cam(void* fc, 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;
uint64_t now = itss_time_get(epv);
uint64_t now = itss_time_get();
// Check permissions
if (ssp) {
@ -675,14 +675,14 @@ enum CAM_CHECK_R check_cam(void* fc, BTPPacketIndication_t *bpi, CAM_t* cam, its
return rv;
}
static int check_pz(lightship_t *lightship, itss_epv_t* epv) {
static int check_pz(lightship_t *lightship) {
bool is_inside = false;
itss_space_lock(epv);
itss_space_get(epv);
double lat = epv->space.latitude/10000000.0;
double lon = epv->space.longitude/10000000.0;
itss_space_unlock(epv);
itss_space_lock();
itss_space_get();
double lat = epv.space.latitude/10000000.0;
double lon = epv.space.longitude/10000000.0;
itss_space_unlock();
pthread_mutex_lock(&lightship->lock);
@ -746,7 +746,7 @@ void *ca_service(void *fc) {
while (!facilities->exit) {
usleep(1000*50);
if (lightship_check(facilities->lightship, &facilities->epv) && facilities->lightship->active) {
if (lightship_check(facilities->lightship) && facilities->lightship->active) {
rv = mk_cam(facilities, bpr->data.buf, (uint32_t *) &bpr->data.size);
if (rv) {
continue;
@ -756,7 +756,7 @@ void *ca_service(void *fc) {
// Check if inside PZ
bpr->gn.communicationProfile = 0;
if (facilities->station_type != 15 && check_pz(facilities->lightship, &facilities->epv)) 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;
@ -778,14 +778,14 @@ void *ca_service(void *fc) {
itss_queue_send(facilities->tx_queue, fi_oer, enc_fdi.encoded+1, ITSS_APPLICATIONS, id, "FI.message");
lightship_reset_timer(facilities->lightship, &facilities->epv);
lightship_reset_timer(facilities->lightship);
// 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, &facilities->epv, true, messageID_cam, NULL, bpr->data.buf, bpr->data.size);
itss_db_add(facilities->logging.dbms, station_id, bpr->id, true, messageID_cam, NULL, bpr->data.buf, bpr->data.size);
}
if (facilities->logging.recorder) {
@ -797,7 +797,7 @@ void *ca_service(void *fc) {
bpr->data.buf,
bpr->data.size,
id,
itss_time_get(&facilities->epv),
itss_time_get(),
ITSS_FACILITIES,
true);
if (e != -1) {

View File

@ -88,10 +88,10 @@ typedef struct lightship {
lightship_t* lightship_init();
int lightship_check(lightship_t* lightship, itss_epv_t* epv);
void lightship_reset_timer(lightship_t*lightship, itss_epv_t* epv);
int lightship_check(lightship_t* lightship);
void lightship_reset_timer(lightship_t*lightship);
enum CAM_CHECK_R check_cam(void* fc, BTPPacketIndication_t* bpi, CAM_t* cam, itss_epv_t* epv, uint8_t* ssp, uint32_t ssp_len);
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);
#endif

View File

@ -425,9 +425,7 @@ int facilities_config(void* facilities_s) {
}
}
pthread_mutex_init(&facilities->epv.space.lock, NULL);
pthread_mutex_init(&facilities->epv.time.lock, NULL);
facilities->epv.time.resolution = TIME_MILLISECONDS;
itss_epv_init();
ManagementRequest_t* mreq = calloc(1, sizeof(ManagementRequest_t));
mreq->present = ManagementRequest_PR_attributes;
@ -463,29 +461,29 @@ int facilities_config(void* facilities_s) {
mrep->data->choice.attributes.clockOffset &&
mrep->data->choice.attributes.gpsType &&
(!!mrep->data->choice.attributes.trajectory == mreq->choice.attributes.choice.get.trajectory)) {
facilities->epv.space.latitude = mrep->data->choice.attributes.coordinates->latitude;
facilities->epv.space.latitude_conf = mrep->data->choice.attributes.coordinates->latitudeConfidence;
facilities->epv.space.longitude = mrep->data->choice.attributes.coordinates->longitude;
facilities->epv.space.longitude_conf = mrep->data->choice.attributes.coordinates->longitudeConfidence;
facilities->epv.space.altitude = mrep->data->choice.attributes.altitude->altitudeValue;
facilities->epv.space.altitude_conf = mrep->data->choice.attributes.altitude->altitudeConfidence;
facilities->epv.space.heading = mrep->data->choice.attributes.heading->headingValue;
facilities->epv.space.heading_conf = mrep->data->choice.attributes.heading->headingConfidence;
facilities->epv.space.speed = mrep->data->choice.attributes.speed->speedValue;
facilities->epv.space.speed_conf = mrep->data->choice.attributes.speed->speedConfidence;
epv.space.latitude = mrep->data->choice.attributes.coordinates->latitude;
epv.space.latitude_conf = mrep->data->choice.attributes.coordinates->latitudeConfidence;
epv.space.longitude = mrep->data->choice.attributes.coordinates->longitude;
epv.space.longitude_conf = mrep->data->choice.attributes.coordinates->longitudeConfidence;
epv.space.altitude = mrep->data->choice.attributes.altitude->altitudeValue;
epv.space.altitude_conf = mrep->data->choice.attributes.altitude->altitudeConfidence;
epv.space.heading = mrep->data->choice.attributes.heading->headingValue;
epv.space.heading_conf = mrep->data->choice.attributes.heading->headingConfidence;
epv.space.speed = mrep->data->choice.attributes.speed->speedValue;
epv.space.speed_conf = mrep->data->choice.attributes.speed->speedConfidence;
facilities->epv.space.type = *mrep->data->choice.attributes.gpsType;
facilities->epv.time.type = *mrep->data->choice.attributes.clockType;
epv.space.type = *mrep->data->choice.attributes.gpsType;
epv.time.type = *mrep->data->choice.attributes.clockType;
asn_INTEGER2ulong(mrep->data->choice.attributes.clock, (unsigned long long*) &facilities->epv.time.clock);
asn_INTEGER2ulong(mrep->data->choice.attributes.clockOffset,(unsigned long long*) &facilities->epv.time.offset);
asn_INTEGER2ulong(mrep->data->choice.attributes.clock, (unsigned long long*) &epv.time.clock);
asn_INTEGER2ulong(mrep->data->choice.attributes.clockOffset,(unsigned long long*) &epv.time.offset);
if (config->facilities.dcm.activate) {
facilities->epv.trajectory.len = mrep->data->choice.attributes.trajectory->list.count;
epv.trajectory.len = mrep->data->choice.attributes.trajectory->list.count;
for (int i = 0; i < mrep->data->choice.attributes.trajectory->list.count; ++i) {
facilities->epv.trajectory.path[i].latitude = mrep->data->choice.attributes.trajectory->list.array[i]->latitude;
facilities->epv.trajectory.path[i].longitude = mrep->data->choice.attributes.trajectory->list.array[i]->longitude;
asn_INTEGER2ulong(&mrep->data->choice.attributes.trajectory->list.array[i]->timestamp, (unsigned long long*) &facilities->epv.trajectory.path[i].timestamp);
epv.trajectory.path[i].latitude = mrep->data->choice.attributes.trajectory->list.array[i]->latitude;
epv.trajectory.path[i].longitude = mrep->data->choice.attributes.trajectory->list.array[i]->longitude;
asn_INTEGER2ulong(&mrep->data->choice.attributes.trajectory->list.array[i]->timestamp, (unsigned long long*) &epv.trajectory.path[i].timestamp);
}
}
} else {

View File

@ -146,10 +146,10 @@ dissemination_t* dissemination_init(){
}
int dissemination_check(dissemination_t* dissemination, itss_epv_t* epv, int f) {
int dissemination_check(dissemination_t* dissemination, int f) {
int rv = 0;
uint64_t now = itss_time_get(epv);
uint64_t now = itss_time_get();
pthread_mutex_lock(&dissemination->lock); // mutex is used to lock shared resources
@ -176,9 +176,9 @@ int dissemination_check(dissemination_t* dissemination, itss_epv_t* epv, int f)
}
void dissemination_reset_timer(dissemination_t* dissemination, itss_epv_t* epv, int f){
void dissemination_reset_timer(dissemination_t* dissemination, int f){
uint64_t now = itss_time_get(epv);
uint64_t now = itss_time_get();
/* Both cases for RSU and OBU */
@ -517,16 +517,16 @@ static int mk_cpm(facilities_t* facilities, uint8_t *bdr_oer, uint32_t *bdr_len,
cpm_tx->header.stationID = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock);
uint64_t generationDeltaTime = itss_time_get(&facilities->epv) % 65536; // generationDeltaTime = TimestampIts mod 65 536
uint64_t generationDeltaTime = itss_time_get() % 65536; // generationDeltaTime = TimestampIts mod 65 536
int32_t lat, lon, alt, alt_conf;
itss_space_lock(&facilities->epv);
itss_space_get(&facilities->epv);
lat = facilities->epv.space.latitude;
lon = facilities->epv.space.longitude;
alt = facilities->epv.space.altitude;
alt_conf = facilities->epv.space.altitude_conf;
itss_space_unlock(&facilities->epv);
itss_space_lock();
itss_space_get();
lat = epv.space.latitude;
lon = epv.space.longitude;
alt = epv.space.altitude;
alt_conf = epv.space.altitude_conf;
itss_space_unlock();
cpm_tx->cpm.generationDeltaTime = generationDeltaTime;
cpm_tx->cpm.cpmParameters.managementContainer.stationType = StationType_roadSideUnit;
@ -538,7 +538,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,&facilities->epv,0) == 1){ /* Sensor Information Container Inclusion Management */
if(dissemination_check(facilities->dissemination,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 +558,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, &facilities->epv, 0);
dissemination_reset_timer(facilities->dissemination, 0);
}
if (s_objectControl.u8_numberOfObjects > 0) {
@ -708,7 +708,7 @@ void *cp_service(void *fc){
/* Reads from the radar */
i32_recv_bytes = recv(raw_socket.raw_fd, &au8_readBuffer, READ_BUFFER_SIZE, 0);
if (dissemination_check(facilities->dissemination, &facilities->epv,1) && facilities->dissemination->active){
if (dissemination_check(facilities->dissemination, 1) && facilities->dissemination->active){
if(is_radar_connected){
/* Information parsing from radar */
parse_input(au8_readBuffer,i32_recv_bytes);
@ -742,14 +742,14 @@ void *cp_service(void *fc){
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, &facilities->epv,1);
dissemination_reset_timer(facilities->dissemination, 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, &facilities->epv, true, 14, NULL, bpr->data.buf, bpr->data.size);
itss_db_add(facilities->logging.dbms, station_id, bpr->id, true, 14, NULL, bpr->data.buf, bpr->data.size);
}
if (facilities->logging.recorder) {
uint16_t buffer_len = 2048;
@ -760,7 +760,7 @@ void *cp_service(void *fc){
bpr->data.buf,
bpr->data.size,
bpr->id,
itss_time_get(&facilities->epv),
itss_time_get(),
ITSS_FACILITIES,
true);
if (e != -1) {

View File

@ -69,7 +69,7 @@ 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, itss_epv_t* epv, uint8_t* ssp, uint32_t ssp_len) {
static enum EVENT_CHECK_R event_check(den_t *den, DENM_t *denm, uint8_t* ssp, uint32_t ssp_len) {
int rv = 0;
uint64_t e_detection_time, e_reference_time;
@ -94,7 +94,7 @@ static enum EVENT_CHECK_R event_check(den_t *den, DENM_t *denm, itss_epv_t* epv,
e_validity_duration = 600 * 1000;
}
uint64_t now = itss_time_get(epv);
uint64_t now = itss_time_get();
if (e_detection_time + e_validity_duration < now) {
return EVENT_PASSED;
@ -155,9 +155,9 @@ static enum EVENT_CHECK_R event_check(den_t *den, DENM_t *denm, itss_epv_t* epv,
return EVENT_NEW;
}
static int event_add(den_t *den, DENM_t *denm, itss_epv_t* epv, uint64_t* id) {
static int event_add(den_t *den, DENM_t *denm, uint64_t* id) {
uint64_t now = itss_time_get(epv);
uint64_t now = itss_time_get();
uint64_t e_detection_time, e_reference_time;
asn_INTEGER2ulong((INTEGER_t*) &denm->denm.management.detectionTime, (unsigned long long*) &e_detection_time);
@ -225,9 +225,9 @@ static int event_add(den_t *den, DENM_t *denm, itss_epv_t* epv, uint64_t* id) {
else return 0; // Event added to db
}
static int event_update(den_t *den, DENM_t *denm, itss_epv_t* epv, uint64_t* id) {
static int event_update(den_t *den, DENM_t *denm, uint64_t* id) {
uint64_t now = itss_time_get(epv);
uint64_t now = itss_time_get();
uint64_t e_detection_time, e_reference_time;
asn_INTEGER2ulong((INTEGER_t*) &denm->denm.management.detectionTime, (unsigned long long*) &e_detection_time);
@ -308,12 +308,12 @@ static int event_update(den_t *den, DENM_t *denm, itss_epv_t* epv, uint64_t* id)
else return 0; // Event updated
}
enum EVENT_CHECK_R event_manage(den_t *den, DENM_t *denm, itss_epv_t* epv, uint64_t* id, uint8_t* ssp, uint32_t ssp_len) {
enum EVENT_CHECK_R event_manage(den_t *den, DENM_t *denm, uint64_t* id, uint8_t* ssp, uint32_t ssp_len) {
int rv = 0;
switch (rv = event_check(den, denm, epv, ssp, ssp_len)) {
switch (rv = event_check(den, denm, ssp, ssp_len)) {
case EVENT_NEW:
syslog_debug("[facilities] [den] new event received");
if (event_add(den, denm, epv, id)) {
if (event_add(den, denm, id)) {
syslog_debug("[facilities] [den] failed adding event, max events reached");
ASN_STRUCT_FREE(asn_DEF_DENM, denm);
rv = -1;
@ -329,7 +329,7 @@ enum EVENT_CHECK_R event_manage(den_t *den, DENM_t *denm, itss_epv_t* epv, uint6
break;
case EVENT_CANCELLATION:
syslog_debug("[facilities] [den] event cancellation received");
if (event_update(den, denm, epv, id)) {
if (event_update(den, 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 +337,7 @@ enum EVENT_CHECK_R event_manage(den_t *den, DENM_t *denm, itss_epv_t* epv, uint6
break;
case EVENT_NEGATION:
syslog_debug("[facilities] [den] event negation received");
if (event_update(den, denm, epv, id)) {
if (event_update(den, 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 +345,7 @@ enum EVENT_CHECK_R event_manage(den_t *den, DENM_t *denm, itss_epv_t* epv, uint6
break;
case EVENT_UPDATE:
syslog_debug("[facilities] [den] event update received");
if (event_update(den, denm, epv, id)) {
if (event_update(den, denm, id)) {
syslog_debug("[facilities] [den] failed updating event, event not found");
ASN_STRUCT_FREE(asn_DEF_DENM, denm);
rv = EVENT_NUMBER_EXCEEDED;
@ -384,7 +384,7 @@ void* den_service(void *fc) {
uint32_t sleep_count = 0;
while (!facilities->exit) {
now = itss_time_get(&facilities->epv);
now = itss_time_get();
pthread_mutex_lock(&den->lock);
for (int i = 0; i < den->n_max_events; ++i) {

View File

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

View File

@ -176,7 +176,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, &facilities->epv, ssp, ssp_len)) {
switch (check_cam(facilities, &tpi->choice.btp, its_msg, ssp, ssp_len)) {
case CAM_OK:
fwd = true;
break;
@ -195,7 +195,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, &facilities->epv, &id, ssp, ssp_len)) {
switch (event_manage(facilities->den, its_msg, &id, ssp, ssp_len)) {
case EVENT_NEW:
case EVENT_CANCELLATION:
case EVENT_NEGATION:
@ -212,7 +212,7 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
break;
case Port_ivim:
switch (service_eval(facilities->infrastructure, SERVICE_IVI, its_msg, &facilities->epv, &id, ssp, ssp_len)) {
switch (service_eval(facilities->infrastructure, SERVICE_IVI, its_msg, &id, ssp, ssp_len)) {
case SERVICE_NEW:
case SERVICE_CANCELLATION:
case SERVICE_NEGATION:
@ -271,11 +271,11 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
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, &facilities->epv, tpi->choice.tcp.sourceAddress->buf, 7011);
tlsc_t* tlsc = tolling_tlsc_get(&facilities->tolling, tpi->choice.tcp.sourceAddress->buf, 7011);
if (tlsc) {
id = tlsc->id;
} else {
tlsc = tolling_tlsc_new(&facilities->tolling, &facilities->epv, tpi->choice.tcp.sourceAddress->buf, 7011);
tlsc = tolling_tlsc_new(&facilities->tolling, tpi->choice.tcp.sourceAddress->buf, 7011);
id = tlsc->id;
}
++tlsc->nmsg;
@ -424,7 +424,7 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
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, &facilities->epv, false, its_msg_type, NULL, packet, packet_len);
itss_db_add(facilities->logging.dbms, station_id, id, false, its_msg_type, NULL, packet, packet_len);
}
if (facilities->logging.recorder) {
int e = itss_management_record_packet_sdu(
@ -433,7 +433,7 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
tpi->choice.btp.data.buf,
tpi->choice.btp.data.size,
tpi->choice.btp.id,
itss_time_get(&facilities->epv),
itss_time_get(),
ITSS_FACILITIES,
false);
if (e != -1) {
@ -657,7 +657,7 @@ static int networking_indication(facilities_t* facilities, void* responder, uint
*ni->choice.data.mobileNeighbour) {
pthread_mutex_lock(&facilities->lightship->lock);
facilities->lightship->last_vehicle = itss_time_get(&facilities->epv);
facilities->lightship->last_vehicle = itss_time_get();
facilities->lightship->is_vehicle_near = true;
pthread_mutex_unlock(&facilities->lightship->lock);
}
@ -687,33 +687,33 @@ static int management_indication(facilities_t* facilities, void* responder, uint
zmq_send(responder, &code, 1, 0);
if (mi->present == ManagementIndication_PR_attributes) {
itss_space_lock(&facilities->epv);
facilities->epv.space.latitude = mi->choice.attributes.coordinates.latitude;
facilities->epv.space.latitude_conf = mi->choice.attributes.coordinates.latitudeConfidence;
facilities->epv.space.longitude = mi->choice.attributes.coordinates.longitude;
facilities->epv.space.longitude_conf = mi->choice.attributes.coordinates.longitudeConfidence;
facilities->epv.space.speed = mi->choice.attributes.speed.speedValue;
facilities->epv.space.speed_conf = mi->choice.attributes.speed.speedConfidence;
facilities->epv.space.heading = mi->choice.attributes.heading.headingValue;
facilities->epv.space.heading_conf = mi->choice.attributes.heading.headingConfidence;
facilities->epv.space.altitude = mi->choice.attributes.altitude.altitudeValue;
facilities->epv.space.altitude_conf = mi->choice.attributes.altitude.altitudeConfidence;
itss_space_unlock(&facilities->epv);
itss_space_lock();
epv.space.latitude = mi->choice.attributes.coordinates.latitude;
epv.space.latitude_conf = mi->choice.attributes.coordinates.latitudeConfidence;
epv.space.longitude = mi->choice.attributes.coordinates.longitude;
epv.space.longitude_conf = mi->choice.attributes.coordinates.longitudeConfidence;
epv.space.speed = mi->choice.attributes.speed.speedValue;
epv.space.speed_conf = mi->choice.attributes.speed.speedConfidence;
epv.space.heading = mi->choice.attributes.heading.headingValue;
epv.space.heading_conf = mi->choice.attributes.heading.headingConfidence;
epv.space.altitude = mi->choice.attributes.altitude.altitudeValue;
epv.space.altitude_conf = mi->choice.attributes.altitude.altitudeConfidence;
itss_space_unlock();
itss_trajectory_lock(&facilities->epv);
itss_trajectory_lock();
if (mi->choice.attributes.trajectory) {
facilities->epv.trajectory.len = mi->choice.attributes.trajectory->list.count;
epv.trajectory.len = mi->choice.attributes.trajectory->list.count;
for (int i = 0; i < mi->choice.attributes.trajectory->list.count; ++i) {
facilities->epv.trajectory.path[i].latitude = mi->choice.attributes.trajectory->list.array[i]->latitude;
facilities->epv.trajectory.path[i].longitude = mi->choice.attributes.trajectory->list.array[i]->longitude;
asn_INTEGER2ulong(&mi->choice.attributes.trajectory->list.array[i]->timestamp, (unsigned long long*) &facilities->epv.trajectory.path[i].timestamp);
epv.trajectory.path[i].latitude = mi->choice.attributes.trajectory->list.array[i]->latitude;
epv.trajectory.path[i].longitude = mi->choice.attributes.trajectory->list.array[i]->longitude;
asn_INTEGER2ulong(&mi->choice.attributes.trajectory->list.array[i]->timestamp, (unsigned long long*) &epv.trajectory.path[i].timestamp);
}
}
itss_trajectory_unlock(&facilities->epv);
itss_trajectory_unlock();
itss_time_lock(&facilities->epv);
asn_INTEGER2ulong(&mi->choice.attributes.clock, (unsigned long long*) &facilities->epv.time.clock);
itss_time_unlock(&facilities->epv);
itss_time_lock();
asn_INTEGER2ulong(&mi->choice.attributes.clock, (unsigned long long*) &epv.time.clock);
itss_time_unlock();
}
cleanup:

View File

@ -98,8 +98,6 @@ typedef struct facilities {
} change;
} id;
itss_epv_t epv;
bool exit;
} facilities_t;

View File

@ -59,10 +59,10 @@ 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, itss_epv_t* epv, uint8_t* ssp, uint16_t ssp_len) {
static enum SERVICE_EVAL_R service_check(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, uint8_t* ssp, uint16_t ssp_len) {
int rv = 0;
uint64_t now = itss_time_get(epv);
uint64_t now = itss_time_get();
switch (type) {
case SERVICE_IVI:
@ -251,7 +251,7 @@ 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, itss_epv_t* epv, uint64_t* id) {
static int service_add(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, uint64_t* id) {
switch (type) {
case SERVICE_IVI:
@ -262,7 +262,7 @@ static int service_add(infrastructure_t* infrastructure, enum SERVICE_TYPE type,
IVIM_t* ivim = (IVIM_t*) its_msg;
uint64_t now = itss_time_get(epv);
uint64_t now = itss_time_get();
uint64_t timestamp, valid_to, valid_from;
if (!ivim->ivi.mandatory.timeStamp) {
@ -337,7 +337,7 @@ 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, itss_epv_t* epv, uint64_t* id) {
static int service_update(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, uint64_t* id) {
switch (type) {
case SERVICE_IVI:
@ -348,7 +348,7 @@ static int service_update(infrastructure_t* infrastructure, enum SERVICE_TYPE ty
IVIM_t* ivim = (IVIM_t*) its_msg;
uint64_t now = itss_time_get(epv);
uint64_t now = itss_time_get();
uint64_t timestamp, valid_to, valid_from;
if (!ivim->ivi.mandatory.timeStamp) {
@ -444,12 +444,12 @@ 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, itss_epv_t* epv, uint64_t* id, uint8_t* ssp, uint16_t ssp_len) {
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) {
int rv = 0;
switch (rv = service_check(infrastructure, type, its_msg, epv, ssp, ssp_len)) {
switch (rv = service_check(infrastructure, type, its_msg, ssp, ssp_len)) {
case SERVICE_NEW:
syslog_debug("[facilities] [infrastructure] new service received");
if (service_add(infrastructure, type, its_msg, epv, id)) {
if (service_add(infrastructure, 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 +465,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, epv, id)) {
if (service_update(infrastructure, 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 +473,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, epv, id)) {
if (service_update(infrastructure, 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 +481,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, epv, id)) {
if (service_update(infrastructure, type, its_msg, id)) {
syslog_debug("[facilities] [infrastructure] failed updating service, service not found");
ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg);
rv = -1;
@ -521,7 +521,7 @@ void* infrastructure_service(void *fc) {
uint32_t sleep_count = 0;
while (!facilities->exit) {
now = itss_time_get(&facilities->epv);
now = itss_time_get();
int n_awaiting_services = 0;
pthread_mutex_lock(&infrastructure->lock);

View File

@ -86,7 +86,7 @@ enum SERVICE_EVAL_R {
SERVICE_BAD_PERMISSIONS
};
enum SERVICE_EVAL_R service_eval(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, itss_epv_t* epv, uint64_t* id, uint8_t* ssp, uint16_t ssp_len);
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);
void* infrastructure_service(void* fc);

View File

@ -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, &facilities->epv, &id, NULL, 0);
uint8_t event_type = event_manage(facilities->den, 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 &&
@ -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, &facilities->epv, &id, NULL, 0);
uint8_t service_type = service_eval(facilities->infrastructure, SERVICE_IVI, its_msg, &id, NULL, 0);
if (service_type != SERVICE_NEW &&
service_type != SERVICE_UPDATE &&
@ -235,7 +235,7 @@ int facilities_request_single_message(facilities_t* facilities, void* responder,
uint64_t valid_to, valid_from;
if (!((IVIM_t*) its_msg)->ivi.mandatory.validFrom) {
valid_from = itss_time_get(&facilities->epv);;
valid_from = itss_time_get();
} else {
asn_INTEGER2ulong((INTEGER_t*) ((IVIM_t*) its_msg)->ivi.mandatory.validFrom, (unsigned long long*) &valid_from);
}
@ -323,7 +323,7 @@ int facilities_request_single_message(facilities_t* facilities, void* responder,
frm->data.buf,
frm->data.size,
id,
itss_time_get(&facilities->epv),
itss_time_get(),
ITSS_FACILITIES,
true);
if (e != -1) {

View File

@ -88,7 +88,7 @@ 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(&facilities->epv, tpi);
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;
@ -124,7 +124,7 @@ SAEM_CODE_R saem_check(void* fc, bulletin_t* bulletin, SAEM_t* saem, uint8_t* ne
if (new_announcement && bulletin->to_consume_len < MAX_ANNOUNCEMENTS_LEN - 1) {
bulletin->to_consume[bulletin->to_consume_len]->its_aid = its_aid;
bulletin->to_consume[bulletin->to_consume_len]->station_id = saem->header.stationID;
bulletin->to_consume[bulletin->to_consume_len]->timestamp = itss_time_get(&facilities->epv);
bulletin->to_consume[bulletin->to_consume_len]->timestamp = itss_time_get();
if (neighbour) {
bulletin->to_consume[bulletin->to_consume_len]->certificate_id = malloc(8);
memcpy(bulletin->to_consume[bulletin->to_consume_len]->certificate_id, neighbour, 8);
@ -339,7 +339,7 @@ void *sa_service(void *fc) {
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, &facilities->epv, true, messageID_saem, NULL, bpr->data.buf, bpr->data.size);
itss_db_add(facilities->logging.dbms, station_id, bpr->id, true, messageID_saem, NULL, bpr->data.buf, bpr->data.size);
}
if (facilities->logging.recorder) {
uint16_t buffer_len = 2048;
@ -350,7 +350,7 @@ void *sa_service(void *fc) {
bpr->data.buf,
bpr->data.size,
bpr->id,
itss_time_get(&facilities->epv),
itss_time_get(),
ITSS_FACILITIES,
true);
if (e != -1) {
@ -364,13 +364,13 @@ void *sa_service(void *fc) {
++mk_saem_n_sleep;
int32_t lat, lon;
itss_space_lock(&facilities->epv);
itss_space_get(&facilities->epv);
lat = facilities->epv.space.latitude;
lon = facilities->epv.space.longitude;
itss_space_unlock(&facilities->epv);
itss_space_lock();
itss_space_get();
lat = epv.space.latitude;
lon = epv.space.longitude;
itss_space_unlock();
uint64_t now = itss_time_get(&facilities->epv);
uint64_t now = itss_time_get();
pthread_mutex_lock(&bulletin->lock);
for (int a = 0; a < bulletin->to_consume_len; ++a) {
@ -412,7 +412,7 @@ void *sa_service(void *fc) {
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->epv, facilities->tx_queue, security_socket);
tolling_tlsc_mgmt(&facilities->tolling, facilities->tx_queue, security_socket);
}
usleep(sleep_ms*1000);

114
src/tpm.c
View File

@ -25,11 +25,11 @@ int tpm_is_inside_zone(void* fc, tolling_info_t* ti) {
facilities_t* facilities = (facilities_t*) fc;
double point[2];
itss_space_lock(&facilities->epv);
itss_space_get(&facilities->epv);
point[0] = facilities->epv.space.latitude/1.0e7;
point[1] = facilities->epv.space.longitude/1.0e7;
itss_space_unlock(&facilities->epv);
itss_space_lock();
itss_space_get();
point[0] = epv.space.latitude/1.0e7;
point[1] = epv.space.longitude/1.0e7;
itss_space_unlock();
if (itss_is_inside_polygon(point, ti->zone.polygon, ti->zone.polygon_len)) {
return 1;
@ -43,7 +43,7 @@ int tpm_should_retransmit(void* fc) {
facilities_t* facilities = (facilities_t*) fc;
tolling_t* tolling = &facilities->tolling;
uint64_t now = itss_time_get(&facilities->epv);
uint64_t now = itss_time_get();
if (tolling->station.obu.rt_on) {
if (now > tolling->station.obu.rt_init + TOLLING_RT_TIMEOUT_MS) {
@ -73,16 +73,16 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig
return rv;
}
pthread_mutex_lock(&facilities->epv.time.lock);
itss_time_lock();
tolling->tz = itss_ts_get(TIME_MICROSECONDS);
pthread_mutex_unlock(&facilities->epv.time.lock);
itss_time_unlock();
// Retransmission
if (!tolling->station.obu.rt_on) {
tolling->station.obu.rt_init = itss_time_get(&facilities->epv);
tolling->station.obu.rt_init = itss_time_get();
tolling->station.obu.rt_on = true;
}
tolling->station.obu.rt_t_trigger = itss_time_get(&facilities->epv);
tolling->station.obu.rt_t_trigger = itss_time_get();
TPM_t* tpm = NULL;
TransportRequest_t* tr = NULL;
@ -109,21 +109,21 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig
tpm->tpm = calloc(1, sizeof(TollingPaymentMessage_t));
// timestamp
asn_ulong2INTEGER(&tpm->tpm->timestamp, itss_time_get(&facilities->epv));
asn_ulong2INTEGER(&tpm->tpm->timestamp, itss_time_get());
// stationType
tpm->tpm->stationType = facilities->station_type;
// referencePosition
itss_space_lock(&facilities->epv);
itss_space_get(&facilities->epv);
tpm->tpm->referencePosition.altitude.altitudeValue = facilities->epv.space.altitude;
tpm->tpm->referencePosition.altitude.altitudeConfidence = facilities->epv.space.altitude_conf;
tpm->tpm->referencePosition.latitude = facilities->epv.space.latitude;
tpm->tpm->referencePosition.longitude = facilities->epv.space.longitude;
uint16_t lat_conf = facilities->epv.space.latitude_conf;
uint16_t lon_conf = facilities->epv.space.longitude_conf;
itss_space_unlock(&facilities->epv);
itss_space_lock();
itss_space_get();
tpm->tpm->referencePosition.altitude.altitudeValue = epv.space.altitude;
tpm->tpm->referencePosition.altitude.altitudeConfidence = epv.space.altitude_conf;
tpm->tpm->referencePosition.latitude = epv.space.latitude;
tpm->tpm->referencePosition.longitude = epv.space.longitude;
uint16_t lat_conf = epv.space.latitude_conf;
uint16_t lon_conf = epv.space.longitude_conf;
itss_space_unlock();
if (lat_conf > lon_conf) {
tpm->tpm->referencePosition.positionConfidenceEllipse.semiMinorConfidence = lon_conf;
tpm->tpm->referencePosition.positionConfidenceEllipse.semiMajorConfidence = lat_conf;
@ -301,11 +301,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, &facilities->epv, dst_addr, 7011);
tlsc_t* tlsc = tolling_tlsc_get(tolling, dst_addr, 7011);
if (tlsc) {
id = tlsc->id;
} else {
tlsc = tolling_tlsc_new(tolling, &facilities->epv, dst_addr, 7011);
tlsc = tolling_tlsc_new(tolling, dst_addr, 7011);
id = tlsc->id;
}
++tlsc->nmsg;
@ -382,7 +382,7 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig
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, &facilities->epv, true, 117, NULL, tpm_uper, tpm_uper_len);
itss_db_add(facilities->logging.dbms, station_id, id, true, 117, NULL, tpm_uper, tpm_uper_len);
}
// send to [applications]
@ -410,7 +410,7 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig
tpm_uper,
tpm_uper_len,
id,
itss_time_get(&facilities->epv),
itss_time_get(),
ITSS_FACILITIES,
true);
if (e != -1) {
@ -662,21 +662,21 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur
tpm->tpm = calloc(1, sizeof(TollingPaymentMessage_t));
// timestamp
asn_ulong2INTEGER(&tpm->tpm->timestamp, itss_time_get(&facilities->epv));
asn_ulong2INTEGER(&tpm->tpm->timestamp, itss_time_get());
// stationType
tpm->tpm->stationType = facilities->station_type;
// referencePosition
itss_space_lock(&facilities->epv);
itss_space_get(&facilities->epv);
tpm->tpm->referencePosition.altitude.altitudeValue = facilities->epv.space.altitude;
tpm->tpm->referencePosition.altitude.altitudeConfidence = facilities->epv.space.altitude_conf;
tpm->tpm->referencePosition.latitude = facilities->epv.space.latitude;
tpm->tpm->referencePosition.longitude = facilities->epv.space.longitude;
uint16_t lat_conf = facilities->epv.space.latitude_conf;
uint16_t lon_conf = facilities->epv.space.longitude_conf;
itss_space_unlock(&facilities->epv);
itss_space_lock();
itss_space_get();
tpm->tpm->referencePosition.altitude.altitudeValue = epv.space.altitude;
tpm->tpm->referencePosition.altitude.altitudeConfidence = epv.space.altitude_conf;
tpm->tpm->referencePosition.latitude = epv.space.latitude;
tpm->tpm->referencePosition.longitude = epv.space.longitude;
uint16_t lat_conf = epv.space.latitude_conf;
uint16_t lon_conf = epv.space.longitude_conf;
itss_space_unlock();
if (lat_conf > lon_conf) {
tpm->tpm->referencePosition.positionConfidenceEllipse.semiMinorConfidence = lon_conf;
tpm->tpm->referencePosition.positionConfidenceEllipse.semiMajorConfidence = lat_conf;
@ -829,11 +829,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, &facilities->epv, src_addr, 7011);
tlsc_t* tlsc = tolling_tlsc_get(tolling, src_addr, 7011);
if (tlsc) {
id = tlsc->id;
} else {
tlsc = tolling_tlsc_new(tolling, &facilities->epv, src_addr, 7011);
tlsc = tolling_tlsc_new(tolling, src_addr, 7011);
id = tlsc->id;
}
++tlsc->nmsg;
@ -905,7 +905,7 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur
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, &facilities->epv, true, 117, NULL, tpm_uper, tpm_uper_len);
itss_db_add(facilities->logging.dbms, station_id, id, true, 117, NULL, tpm_uper, tpm_uper_len);
}
// send to [applications]
@ -932,7 +932,7 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur
tpm_uper,
tpm_uper_len,
id,
itss_time_get(&facilities->epv),
itss_time_get(),
ITSS_FACILITIES,
true);
if (e != -1) {
@ -948,7 +948,7 @@ cleanup:
ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi);
}
static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_socket, itss_queue_t* tx_queue, itss_epv_t* epv, uint8_t* neighbour, uint8_t* src_addr) {
static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_socket, itss_queue_t* tx_queue, uint8_t* neighbour, uint8_t* src_addr) {
if (!tpm_rx->tpm->tollingType) {
syslog_err("[facilities] [tolling] received TPM does not have a type");
@ -1123,7 +1123,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, epv, src_addr, 7011);
tlsc_t* tlsc = tolling_tlsc_get(tolling, src_addr, 7011);
if (tlsc) {
sreq = calloc(1, sizeof(SecurityRequest_t));
sreq->present = SecurityRequest_PR_tlsClose;
@ -1211,11 +1211,11 @@ int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour,
syslog_debug("[facilities] [tolling] received TPM.entry.reply, ignoring");
goto cleanup;
}
pthread_mutex_lock(&facilities->epv.time.lock);
itss_time_lock();
syslog_info("[facilities] [tolling] entry.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->tz);
pthread_mutex_unlock(&facilities->epv.time.lock);
itss_time_unlock();
tolling->station.obu.rt_on = false;
veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, &facilities->epv, neighbour, src_addr);
veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, neighbour, src_addr);
break;
default:
break;
@ -1239,11 +1239,11 @@ int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour,
syslog_debug("[facilities] [tolling] received TPM.exit.reply, ignoring");
goto cleanup;
}
pthread_mutex_lock(&facilities->epv.time.lock);
itss_time_lock();
syslog_info("[facilities] [tolling] exit.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->tz);
pthread_mutex_unlock(&facilities->epv.time.lock);
itss_time_unlock();
tolling->station.obu.rt_on = false;
veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, &facilities->epv, neighbour, src_addr);
veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, neighbour, src_addr);
break;
default:
break;
@ -1264,11 +1264,11 @@ int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour,
syslog_debug("[facilities] [tolling] received TPM.single.reply, ignoring");
goto cleanup;
}
pthread_mutex_lock(&facilities->epv.time.lock);
itss_time_lock();
syslog_info("[facilities] [tolling] single.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->tz);
pthread_mutex_unlock(&facilities->epv.time.lock);
itss_time_unlock();
tolling->station.obu.rt_on = false;
veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, &facilities->epv, neighbour, src_addr);
veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, neighbour, src_addr);
break;
default:
break;
@ -1298,10 +1298,10 @@ int tolling_init(tolling_t* tolling, void* zmq_ctx, char* security_address, uint
return 0;
}
tolling_info_t* tolling_info_new(itss_epv_t* epv, TollingPaymentInfo_t* tpi) {
tolling_info_t* tolling_info_new(TollingPaymentInfo_t* tpi) {
tolling_info_t* ti = calloc(1, sizeof(tolling_info_t));
ti->timestamp = itss_time_get(epv);
ti->timestamp = itss_time_get();
ti->asn = tpi;
ti->zone.polygon_len = tpi->zone.list.count;
@ -1321,7 +1321,7 @@ void tolling_info_free(tolling_info_t* ti) {
free(ti);
}
tlsc_t* tolling_tlsc_new(tolling_t* tolling, itss_epv_t* epv, uint8_t ipv6[16], uint16_t port) {
tlsc_t* tolling_tlsc_new(tolling_t* tolling, uint8_t ipv6[16], uint16_t port) {
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;
@ -1331,21 +1331,21 @@ tlsc_t* tolling_tlsc_new(tolling_t* tolling, itss_epv_t* epv, uint8_t ipv6[16],
memcpy(tlsc->ipv6, ipv6, 16);
tlsc->port = port;
tlsc->id = rand();
tlsc->ts = itss_time_get(epv);
tlsc->ts = itss_time_get();
tlsc->nmsg = 0;
tlsc->state = 0;
++tolling->protocol.c.tls.n_tlsc;
return tlsc;
}
tlsc_t* tolling_tlsc_get(tolling_t* tolling, itss_epv_t* epv, uint8_t ipv6[16], uint16_t port) {
tlsc_t* tolling_tlsc_get(tolling_t* tolling, uint8_t ipv6[16], uint16_t port) {
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) {
if (!memcmp(tolling->protocol.c.tls.tls_conns[i]->ipv6, ipv6, 16) &&
tolling->protocol.c.tls.tls_conns[i]->port == port) {
tlsc = tolling->protocol.c.tls.tls_conns[i];
tlsc->ts = itss_time_get(epv);
tlsc->ts = itss_time_get();
break;
}
}
@ -1353,9 +1353,9 @@ tlsc_t* tolling_tlsc_get(tolling_t* tolling, itss_epv_t* epv, uint8_t ipv6[16],
}
void tolling_tlsc_mgmt(tolling_t* tolling, itss_epv_t* epv, itss_queue_t* tx_queue, void* security_socket) {
void tolling_tlsc_mgmt(tolling_t* tolling, itss_queue_t* tx_queue, void* security_socket) {
pthread_mutex_lock(&tolling->lock);
uint64_t now = itss_time_get(epv);
uint64_t now = itss_time_get();
for (int i = 0; i < tolling->protocol.c.tls.n_tlsc; ++i) {
tlsc_t* tlsc = tolling->protocol.c.tls.tls_conns[i];
if (tlsc->ts + TOLLING_CONN_TIMEOUT_MS < now) {

View File

@ -105,9 +105,9 @@ int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour,
int tpm_should_retransmit(void* fc);
int tpm_is_inside_zone(void* fc, tolling_info_t* ti);
tolling_info_t* tolling_info_new(itss_epv_t* epv, TollingPaymentInfo_t* tpi);
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, itss_epv_t* epv, uint8_t ipv6[16], uint16_t port);
tlsc_t* tolling_tlsc_get(tolling_t* tolling, itss_epv_t* epv, uint8_t ipv6[16], uint16_t port);
void tolling_tlsc_mgmt(tolling_t* tolling, itss_epv_t* epv, itss_queue_t* tx_queue, void* security_socket);
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);

View File

@ -89,17 +89,17 @@ static int vcm_check_handle_request(facilities_t* facilities, VCM_t* vcm, mc_nei
itss_st_t trajectoryB[TRAJECTORY_MAX_LEN+1]; /* neighbour trajectory */
uint16_t trajectoryB_len = 0;
uint64_t now = itss_time_get(&facilities->epv);
uint64_t now = itss_time_get();
neighbour->proposed = true;
neighbour->t_proposal = now;
int32_t lat, lon;
itss_space_lock(&facilities->epv);
itss_space_get(&facilities->epv);
lat = facilities->epv.space.latitude;
lon = facilities->epv.space.longitude;
itss_space_unlock(&facilities->epv);
itss_space_lock();
itss_space_get();
lat = epv.space.latitude;
lon = epv.space.longitude;
itss_space_unlock();
vcm_rep = calloc(1, sizeof(VCM_t));
@ -209,7 +209,7 @@ static int vcm_check_handle_request(facilities_t* facilities, VCM_t* vcm, mc_nei
bpr->data.buf,
bpr->data.size,
bpr->id,
itss_time_get(&facilities->epv),
itss_time_get(),
ITSS_FACILITIES,
true);
if (e != -1) {
@ -229,9 +229,9 @@ static int vcm_check_handle_reply(facilities_t* facilities, VCM_t* vcm, mc_neigh
CoordinationReply_t* reply = &vcm->vcm.maneuverContainer.choice.vehicle.negotiation->choice.reply;
pthread_mutex_lock(&facilities->epv.time.lock);
itss_time_lock();
uint64_t now_us = itss_ts_get(TIME_MICROSECONDS);
pthread_mutex_unlock(&facilities->epv.time.lock);
itss_time_unlock();
if (neighbour->intersecting) {
syslog_info("[facilities] [vc] received VCM.reply with %d accepted trajectories | took %ld us", reply->acceptedTrajectoriesIds.list.count, now_us-neighbour->t_iid);
@ -262,7 +262,7 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm,
itss_st_t trajectoryA[TRAJECTORY_MAX_LEN+1]; /* ego trajectory */
uint16_t trajectoryA_len = 0;
uint64_t now = itss_time_get(&facilities->epv);
uint64_t now = itss_time_get();
if (now < neighbour->t_iid/1000 + MC_RESOLUTION_TIMEOUT) {
rv = 0;
@ -271,9 +271,9 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm,
neighbour->intersecting = true;
pthread_mutex_lock(&facilities->epv.time.lock);
itss_time_lock();
uint64_t now_us = itss_ts_get(TIME_MICROSECONDS) ;
pthread_mutex_unlock(&facilities->epv.time.lock);
itss_time_unlock();
neighbour->t_iid = now_us;
if (now < neighbour->t_proposal + MC_RESOLUTION_TIMEOUT) {
@ -282,16 +282,16 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm,
}
int32_t lat, lon;
itss_space_lock(&facilities->epv);
itss_space_get(&facilities->epv);
lat = facilities->epv.space.latitude;
lon = facilities->epv.space.longitude;
itss_space_unlock(&facilities->epv);
itss_space_lock();
itss_space_get();
lat = epv.space.latitude;
lon = epv.space.longitude;
itss_space_unlock();
itss_trajectory_lock(&facilities->epv);
trajectoryA_len = facilities->epv.trajectory.len;
memcpy(trajectoryA + 1, facilities->epv.trajectory.path, trajectoryA_len * sizeof(itss_st_t));
itss_trajectory_unlock(&facilities->epv);
itss_trajectory_lock();
trajectoryA_len = epv.trajectory.len;
memcpy(trajectoryA + 1, epv.trajectory.path, trajectoryA_len * sizeof(itss_st_t));
itss_trajectory_unlock();
trajectoryA[0].latitude = lat;
@ -432,7 +432,7 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm,
bpr->data.buf,
bpr->data.size,
bpr->id,
itss_time_get(&facilities->epv),
itss_time_get(),
ITSS_FACILITIES,
true);
if (e != -1) {
@ -458,14 +458,14 @@ int vcm_check(void* fc, VCM_t* vcm) {
uint16_t trajectoryA_len = 0;
uint16_t trajectoryB_len = 0;
uint64_t now = itss_time_get(&facilities->epv);
uint64_t now = itss_time_get();
int32_t lat, lon;
itss_space_lock(&facilities->epv);
itss_space_get(&facilities->epv);
lat = facilities->epv.space.latitude;
lon = facilities->epv.space.longitude;
itss_space_unlock(&facilities->epv);
itss_space_lock();
itss_space_get();
lat = epv.space.latitude;
lon = epv.space.longitude;
itss_space_unlock();
pthread_mutex_lock(&coordination->lock);
@ -502,10 +502,10 @@ int vcm_check(void* fc, VCM_t* vcm) {
}
} else {
itss_trajectory_lock(&facilities->epv);
trajectoryA_len = facilities->epv.trajectory.len;
memcpy(trajectoryA + 1, facilities->epv.trajectory.path, trajectoryA_len * sizeof(itss_st_t));
itss_trajectory_unlock(&facilities->epv);
itss_trajectory_lock();
trajectoryA_len = epv.trajectory.len;
memcpy(trajectoryA + 1, epv.trajectory.path, trajectoryA_len * sizeof(itss_st_t));
itss_trajectory_unlock();
trajectoryA[0].latitude = lat;
trajectoryA[0].longitude = lon;
@ -567,23 +567,23 @@ 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(&facilities->epv);
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);
int32_t lat, lon;
uint16_t trajectory_len = 0;
itss_space_lock(&facilities->epv);
itss_space_get(&facilities->epv);
lat = facilities->epv.space.latitude;
lon = facilities->epv.space.longitude;
itss_space_unlock(&facilities->epv);
itss_space_lock();
itss_space_get();
lat = epv.space.latitude;
lon = epv.space.longitude;
itss_space_unlock();
itss_trajectory_lock(&facilities->epv);
trajectory_len = facilities->epv.trajectory.len;
memcpy(trajectory, facilities->epv.trajectory.path, trajectory_len * sizeof(itss_st_t));
itss_trajectory_unlock(&facilities->epv);
itss_trajectory_lock();
trajectory_len = epv.trajectory.len;
memcpy(trajectory, epv.trajectory.path, trajectory_len * sizeof(itss_st_t));
itss_trajectory_unlock();
vcm->vcm.currentPosition.latitude = lat;
vcm->vcm.currentPosition.longitude = lon;
@ -681,7 +681,7 @@ void* vc_service(void* fc) {
while (!facilities->exit) {
uint64_t now = itss_time_get(&facilities->epv);
uint64_t now = itss_time_get();
pthread_mutex_lock(&coordination->lock);
if (vcm_timer_check(coordination, now)) {
@ -718,7 +718,7 @@ void* vc_service(void* fc) {
bpr->data.buf,
bpr->data.size,
bpr->id,
itss_time_get(&facilities->epv),
itss_time_get(),
ITSS_FACILITIES,
true);
if (e != -1) {