diff --git a/src/cam.c b/src/cam.c index 98a0b0f..e6f77bc 100644 --- a/src/cam.c +++ b/src/cam.c @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -109,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 = it2s_tender_get_clock(&facilities->epv); + uint64_t now = itss_time_get(&facilities->epv); lightship_t* lightship = facilities->lightship; pthread_mutex_lock(&lightship->lock); @@ -117,8 +118,8 @@ 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; - it2s_tender_lock_space(&facilities->epv); - it2s_tender_get_space(&facilities->epv); + 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; @@ -168,7 +169,7 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len) bvc_hf->heading.headingValue = facilities->epv.space.heading; bvc_hf->heading.headingConfidence = facilities->epv.space.heading_conf; - it2s_tender_unlock_space(&facilities->epv); + itss_space_unlock(&facilities->epv); if (lat_conf > lon_conf) { bc->referencePosition.positionConfidenceEllipse.semiMinorConfidence = lon_conf; @@ -289,8 +290,8 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len) } else { cam->cam.generationDeltaTime = now % 65536; - it2s_tender_lock_space(&facilities->epv); - it2s_tender_get_space(&facilities->epv); + 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; @@ -300,7 +301,7 @@ static int mk_cam(facilities_t* facilities, uint8_t *cam_oer, uint32_t *cam_len) bc->referencePosition.positionConfidenceEllipse.semiMinorConfidence = SemiAxisLength_unavailable; bc->referencePosition.positionConfidenceEllipse.semiMajorConfidence = SemiAxisLength_unavailable; bc->referencePosition.positionConfidenceEllipse.semiMajorOrientation = HeadingValue_unavailable; - it2s_tender_unlock_space(&facilities->epv); + itss_space_unlock(&facilities->epv); cam->cam.camParameters.highFrequencyContainer.present = HighFrequencyContainer_PR_rsuContainerHighFrequency; @@ -382,10 +383,10 @@ lightship_t* lightship_init() { } -int lightship_check(lightship_t* lightship, it2s_tender_epv_t* epv) { +int lightship_check(lightship_t* lightship, itss_epv_t* epv) { int rv = 0; - uint64_t now = it2s_tender_get_clock(epv); + uint64_t now = itss_time_get(epv); pthread_mutex_lock(&lightship->lock); @@ -398,8 +399,8 @@ int lightship_check(lightship_t* lightship, it2s_tender_epv_t* epv) { rv = 1; } else if (now > lightship->next_cam_min) { - it2s_tender_lock_space(epv); - it2s_tender_get_space(epv); + itss_space_lock(epv); + itss_space_get(epv); // Check heading delta > 4ยบ int diff = epv->space.heading - lightship->pos_history[0]->heading; @@ -418,7 +419,7 @@ int lightship_check(lightship_t* lightship, it2s_tender_epv_t* epv) { if (avg_speed * delta_time > 4) rv = 1; } } - it2s_tender_unlock_space(epv); + itss_space_unlock(epv); } @@ -444,8 +445,8 @@ int lightship_check(lightship_t* lightship, it2s_tender_epv_t* epv) { return rv; } -void lightship_reset_timer(lightship_t* lightship, it2s_tender_epv_t* epv) { - uint64_t now = it2s_tender_get_clock(epv); +void lightship_reset_timer(lightship_t* lightship, itss_epv_t* epv) { + uint64_t now = itss_time_get(epv); pthread_mutex_lock(&lightship->lock); @@ -462,12 +463,12 @@ void lightship_reset_timer(lightship_t* lightship, it2s_tender_epv_t* epv) { pthread_mutex_unlock(&lightship->lock); } -enum CAM_CHECK_R check_cam(void* fc, BTPPacketIndication_t *bpi, CAM_t* cam, it2s_tender_epv_t* epv, uint8_t* ssp, uint32_t ssp_len) { +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) { int rv = 0; facilities_t* facilities = (facilities_t*) fc; lightship_t *lightship = ((facilities_t*) fc)->lightship; - uint64_t now = it2s_tender_get_clock(epv); + uint64_t now = itss_time_get(epv); // Check permissions if (ssp) { @@ -674,14 +675,14 @@ enum CAM_CHECK_R check_cam(void* fc, BTPPacketIndication_t *bpi, CAM_t* cam, it2 return rv; } -static int check_pz(lightship_t *lightship, it2s_tender_epv_t* epv) { +static int check_pz(lightship_t *lightship, itss_epv_t* epv) { bool is_inside = false; - it2s_tender_lock_space(epv); - it2s_tender_get_space(epv); + itss_space_lock(epv); + itss_space_get(epv); double lat = epv->space.latitude/10000000.0; double lon = epv->space.longitude/10000000.0; - it2s_tender_unlock_space(epv); + itss_space_unlock(epv); pthread_mutex_lock(&lightship->lock); @@ -757,7 +758,7 @@ void *ca_service(void *fc) { bpr->gn.communicationProfile = 0; if (facilities->station_type != 15 && check_pz(facilities->lightship, &facilities->epv)) bpr->gn.communicationProfile = 1; - uint64_t id = rand() + 1; + uint32_t id = itss_id(bpr->data.buf, bpr->data.size); bpr->id = id; fmi->id = id; @@ -773,9 +774,9 @@ void *ca_service(void *fc) { continue; } - it2s_tender_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"); - it2s_tender_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, &facilities->epv); @@ -784,23 +785,23 @@ void *ca_service(void *fc) { pthread_mutex_lock(&facilities->id.lock); uint64_t station_id = facilities->id.station_id; pthread_mutex_unlock(&facilities->id.lock); - it2s_tender_db_add(facilities->logging.dbms, station_id, bpr->id, &facilities->epv, true, ItsPduHeader__messageID_cam, NULL, bpr->data.buf, bpr->data.size); + itss_db_add(facilities->logging.dbms, station_id, bpr->id, &facilities->epv, true, ItsPduHeader__messageID_cam, NULL, bpr->data.buf, bpr->data.size); } if (facilities->logging.recorder) { uint16_t buffer_len = 2048; uint8_t buffer[buffer_len]; - int e = it2s_tender_management_record_packet_sdu( + int e = itss_management_record_packet_sdu( buffer, buffer_len, bpr->data.buf, bpr->data.size, id, - it2s_tender_get_clock(&facilities->epv), + itss_time_get(&facilities->epv), ITSS_FACILITIES, true); if (e != -1) { - it2s_tender_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"); } } } diff --git a/src/cam.h b/src/cam.h index 6eaa8fb..34a73af 100644 --- a/src/cam.h +++ b/src/cam.h @@ -88,10 +88,10 @@ typedef struct lightship { lightship_t* lightship_init(); -int lightship_check(lightship_t* lightship, it2s_tender_epv_t* epv); -void lightship_reset_timer(lightship_t*lightship, it2s_tender_epv_t* epv); +int lightship_check(lightship_t* lightship, itss_epv_t* epv); +void lightship_reset_timer(lightship_t*lightship, itss_epv_t* epv); -enum CAM_CHECK_R check_cam(void* fc, BTPPacketIndication_t* bpi, CAM_t* cam, it2s_tender_epv_t* epv, uint8_t* ssp, uint32_t ssp_len); +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); void* ca_service(void* fc); #endif diff --git a/src/config.c b/src/config.c index 02bade6..0407e08 100644 --- a/src/config.c +++ b/src/config.c @@ -507,8 +507,8 @@ int facilities_config(void* facilities_s) { // Logging facilities->logging.recorder = config->facilities.logging.management; if (config->general.logging.enabled && config->facilities.logging.dbms) { - facilities->logging.dbms = calloc(1, sizeof(it2s_tender_database_s)); - if (it2s_tender_db_init( + facilities->logging.dbms = calloc(1, sizeof(itss_db_t)); + if (itss_db_init( facilities->logging.dbms, config->general.logging.database, config->general.logging.table_style, diff --git a/src/cpm.c b/src/cpm.c index 649ccc4..c058764 100644 --- a/src/cpm.c +++ b/src/cpm.c @@ -23,6 +23,7 @@ #include #include #include +#include #define PI 3.141592654 @@ -145,10 +146,10 @@ dissemination_t* dissemination_init(){ } -int dissemination_check(dissemination_t* dissemination, it2s_tender_epv_t* epv, int f) { +int dissemination_check(dissemination_t* dissemination, itss_epv_t* epv, int f) { int rv = 0; - uint64_t now = it2s_tender_get_clock(epv); + uint64_t now = itss_time_get(epv); pthread_mutex_lock(&dissemination->lock); // mutex is used to lock shared resources @@ -175,9 +176,9 @@ int dissemination_check(dissemination_t* dissemination, it2s_tender_epv_t* epv, } -void dissemination_reset_timer(dissemination_t* dissemination, it2s_tender_epv_t* epv, int f){ +void dissemination_reset_timer(dissemination_t* dissemination, itss_epv_t* epv, int f){ - uint64_t now = it2s_tender_get_clock(epv); + uint64_t now = itss_time_get(epv); /* Both cases for RSU and OBU */ @@ -516,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 = it2s_tender_get_clock(&facilities->epv) % 65536; // generationDeltaTime = TimestampIts mod 65 536 + uint64_t generationDeltaTime = itss_time_get(&facilities->epv) % 65536; // generationDeltaTime = TimestampIts mod 65 536 int32_t lat, lon, alt, alt_conf; - pthread_mutex_lock(&facilities->epv.space.lock); - it2s_tender_get_space(&facilities->epv); + 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; - pthread_mutex_unlock(&facilities->epv.space.lock); + itss_space_unlock(&facilities->epv); cpm_tx->cpm.generationDeltaTime = generationDeltaTime; cpm_tx->cpm.cpmParameters.managementContainer.stationType = StationType_roadSideUnit; @@ -716,7 +717,7 @@ void *cp_service(void *fc){ 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) continue; - uint64_t id = rand() + 1; + uint32_t id = itss_id(bpr->data.buf, bpr->data.size); bpr->id = id; fmi->id = id; @@ -735,10 +736,10 @@ void *cp_service(void *fc){ } /* Create thread to send packet to the Transport Layer (=3) */ - it2s_tender_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) */ - it2s_tender_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, &facilities->epv,1); @@ -748,22 +749,22 @@ void *cp_service(void *fc){ pthread_mutex_lock(&facilities->id.lock); uint64_t station_id = facilities->id.station_id; pthread_mutex_unlock(&facilities->id.lock); - it2s_tender_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, &facilities->epv, true, 14, NULL, bpr->data.buf, bpr->data.size); } if (facilities->logging.recorder) { uint16_t buffer_len = 2048; uint8_t buffer[buffer_len]; - int e = it2s_tender_management_record_packet_sdu( + int e = itss_management_record_packet_sdu( buffer, buffer_len, bpr->data.buf, bpr->data.size, bpr->id, - it2s_tender_get_clock(&facilities->epv), + itss_time_get(&facilities->epv), ITSS_FACILITIES, true); if (e != -1) { - it2s_tender_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"); } } diff --git a/src/denm.c b/src/denm.c index a0b193c..a733ada 100644 --- a/src/denm.c +++ b/src/denm.c @@ -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, it2s_tender_epv_t* epv, uint8_t* ssp, uint32_t ssp_len) { +static enum EVENT_CHECK_R event_check(den_t *den, DENM_t *denm, itss_epv_t* epv, 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, it2s_tender_epv_ e_validity_duration = 600 * 1000; } - uint64_t now = it2s_tender_get_clock(epv); + uint64_t now = itss_time_get(epv); 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, it2s_tender_epv_ return EVENT_NEW; } -static int event_add(den_t *den, DENM_t *denm, it2s_tender_epv_t* epv, uint64_t* id) { +static int event_add(den_t *den, DENM_t *denm, itss_epv_t* epv, uint64_t* id) { - uint64_t now = it2s_tender_get_clock(epv); + uint64_t now = itss_time_get(epv); 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, it2s_tender_epv_t* epv, uint64_t* else return 0; // Event added to db } -static int event_update(den_t *den, DENM_t *denm, it2s_tender_epv_t* epv, uint64_t* id) { +static int event_update(den_t *den, DENM_t *denm, itss_epv_t* epv, uint64_t* id) { - uint64_t now = it2s_tender_get_clock(epv); + uint64_t now = itss_time_get(epv); uint64_t e_detection_time, e_reference_time; asn_INTEGER2ulong((INTEGER_t*) &denm->denm.management.detectionTime, (unsigned long long*) &e_detection_time); @@ -308,7 +308,7 @@ static int event_update(den_t *den, DENM_t *denm, it2s_tender_epv_t* epv, uint64 else return 0; // Event updated } -enum EVENT_CHECK_R event_manage(den_t *den, DENM_t *denm, it2s_tender_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, itss_epv_t* epv, uint64_t* id, uint8_t* ssp, uint32_t ssp_len) { int rv = 0; switch (rv = event_check(den, denm, epv, ssp, ssp_len)) { case EVENT_NEW: @@ -384,7 +384,7 @@ void* den_service(void *fc) { uint32_t sleep_count = 0; while (!facilities->exit) { - now = it2s_tender_get_clock(&facilities->epv); + now = itss_time_get(&facilities->epv); pthread_mutex_lock(&den->lock); for (int i = 0; i < den->n_max_events; ++i) { diff --git a/src/denm.h b/src/denm.h index 6bc7995..ecc1d3c 100644 --- a/src/denm.h +++ b/src/denm.h @@ -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, it2s_tender_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, itss_epv_t* epv, uint64_t* id, uint8_t* ssp, uint32_t ssp_len); void* den_service(void* fc); diff --git a/src/facilities.c b/src/facilities.c index 6f142b8..e5d42dc 100644 --- a/src/facilities.c +++ b/src/facilities.c @@ -40,6 +40,7 @@ #include #include #include +#include static int transport_indication(facilities_t *facilities, void* responder, void* security_socket, uint8_t *msg, uint32_t msg_len) { int rv = 0, code = 0; @@ -93,7 +94,7 @@ static int transport_indication(facilities_t *facilities, void* responder, void* switch (tpi->present) { case TransportPacketIndication_PR_btp: id = tpi->choice.btp.id; - syslog_debug("[facilities]<- TI.packet.btp | id:%ld size:%dB", id, msg_len); + syslog_debug("[facilities]<- TI.packet.btp | id:%08x size:%dB", (uint32_t) id, msg_len); // Parse message switch (tpi->choice.btp.destinationPort) { case Port_cam: @@ -326,7 +327,7 @@ static int transport_indication(facilities_t *facilities, void* responder, void* tpr->gn->destinationAddress.buf = calloc(1, 6); tpr->gn->destinationAddress.size = 6; - tpr->id = rand() + 1; + tpr->id = itss_id(tpr->data.buf, tpr->data.size); buf[0] = 4; enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, buf_len-1); @@ -336,7 +337,7 @@ static int transport_indication(facilities_t *facilities, void* responder, void* goto cleanup; } - it2s_tender_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) { @@ -379,7 +380,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); - it2s_tender_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 @@ -387,20 +388,20 @@ 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); - it2s_tender_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, &facilities->epv, false, its_msg_type, NULL, packet, packet_len); } if (facilities->logging.recorder) { - int e = it2s_tender_management_record_packet_sdu( + int e = itss_management_record_packet_sdu( buf, buf_len, tpi->choice.btp.data.buf, tpi->choice.btp.data.size, tpi->choice.btp.id, - it2s_tender_get_clock(&facilities->epv), + itss_time_get(&facilities->epv), ITSS_FACILITIES, false); if (e != -1) { - it2s_tender_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"); } } @@ -620,7 +621,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 = it2s_tender_get_clock(&facilities->epv); + facilities->lightship->last_vehicle = itss_time_get(&facilities->epv); facilities->lightship->is_vehicle_near = true; pthread_mutex_unlock(&facilities->lightship->lock); } @@ -650,7 +651,7 @@ static int management_indication(facilities_t* facilities, void* responder, uint zmq_send(responder, &code, 1, 0); if (mi->present == ManagementIndication_PR_attributes) { - it2s_tender_lock_space(&facilities->epv); + 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; @@ -661,9 +662,9 @@ static int management_indication(facilities_t* facilities, void* responder, uint 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; - it2s_tender_unlock_space(&facilities->epv); + itss_space_unlock(&facilities->epv); - it2s_tender_lock_trajectory(&facilities->epv); + itss_trajectory_lock(&facilities->epv); if (mi->choice.attributes.trajectory) { facilities->epv.trajectory.len = mi->choice.attributes.trajectory->list.count; for (int i = 0; i < mi->choice.attributes.trajectory->list.count; ++i) { @@ -672,11 +673,11 @@ static int management_indication(facilities_t* facilities, void* responder, uint asn_INTEGER2ulong(&mi->choice.attributes.trajectory->list.array[i]->timestamp, (unsigned long long*) &facilities->epv.trajectory.path[i].timestamp); } } - it2s_tender_unlock_trajectory(&facilities->epv); + itss_trajectory_unlock(&facilities->epv); - it2s_tender_lock_time(&facilities->epv); + itss_time_lock(&facilities->epv); asn_INTEGER2ulong(&mi->choice.attributes.clock, (unsigned long long*) &facilities->epv.time.clock); - it2s_tender_unlock_time(&facilities->epv); + itss_time_unlock(&facilities->epv); } cleanup: @@ -691,7 +692,7 @@ void* tx(void* fc) { facilities_t *facilities = (facilities_t*) fc; - it2s_tender_queue_t* queue = facilities->tx_queue; + itss_queue_t* queue = facilities->tx_queue; uint8_t code; int wait_ms = 1000; @@ -708,7 +709,7 @@ void* tx(void* fc) { zmq_setsockopt(management_socket, ZMQ_RCVTIMEO, &wait_ms, sizeof(int)); zmq_connect(management_socket, facilities->zmq.management_address); - it2s_tender_queue_t* stream = it2s_tender_queue_new(); + itss_queue_t* stream = itss_queue_new(); while (!facilities->exit) { pthread_mutex_lock(&queue->lock); @@ -730,31 +731,31 @@ void* tx(void* fc) { for (int i = 0; i < stream->len; ++i) { switch (stream->destination[i]) { case ITSS_TRANSPORT: - syslog_debug("[facilities]-> %s ->[transport] | id:%ld size:%dB", - stream->info_msg[i], stream->id[i], stream->packet_len[i]); + syslog_debug("[facilities]-> %s ->[transport] | id:%08x size:%dB", + stream->info_msg[i], (uint32_t) stream->id[i], stream->packet_len[i]); zmq_send(transport_socket, stream->packet[i], stream->packet_len[i], 0); rv = zmq_recv(transport_socket, &code, 1, 0); if (rv == -1) { - syslog_err("[facilities]-> %s ->[transport] | id:%ld size:%dB ", - stream->info_msg[i], stream->id[i], stream->packet_len[i]); + syslog_err("[facilities]-> %s ->[transport] | id:%08x size:%dB ", + stream->info_msg[i], (uint32_t) stream->id[i], stream->packet_len[i]); } break; case ITSS_APPLICATIONS: - syslog_debug("[facilities]-> %s ->[applications] | id:%ld size:%dB", - stream->info_msg[i], stream->id[i], stream->packet_len[i]); + syslog_debug("[facilities]-> %s ->[applications] | id:%08x size:%dB", + stream->info_msg[i], (uint32_t) stream->id[i], stream->packet_len[i]); zmq_send(applications_socket, stream->packet[i], stream->packet_len[i], 0); rv = zmq_recv(applications_socket, &code, 1, 0); if (rv == -1) { - syslog_err("[facilities]-> %s ->[applications] | id:%ld size:%dB ", - stream->info_msg[i], stream->id[i], stream->packet_len[i]); + syslog_err("[facilities]-> %s ->[applications] | id:%08x size:%dB ", + stream->info_msg[i], (uint32_t) stream->id[i], stream->packet_len[i]); } break; case ITSS_MANAGEMENT: zmq_send(management_socket, stream->packet[i], stream->packet_len[i], 0); rv = zmq_recv(management_socket, &code, 1, 0); if (rv == -1) { - syslog_err("[facilities]-> %s ->[management] | id:%ld size:%dB ", - stream->info_msg[i], stream->id[i], stream->packet_len[i]); + syslog_err("[facilities]-> %s ->[management] | id:%08x size:%dB ", + stream->info_msg[i], (uint32_t) stream->id[i], stream->packet_len[i]); } break; } @@ -772,7 +773,7 @@ int main() { facilities_t facilities = {0}; facilities.zmq.ctx = zmq_ctx_new(); - facilities.tx_queue = it2s_tender_queue_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)); diff --git a/src/facilities.h b/src/facilities.h index 8abc2a3..6d36277 100644 --- a/src/facilities.h +++ b/src/facilities.h @@ -48,7 +48,7 @@ typedef struct facilities { } zmq; // Transmitter - it2s_tender_queue_t* tx_queue; + itss_queue_t* tx_queue; // CA lightship_t* lightship; @@ -74,7 +74,7 @@ typedef struct facilities { // Logging struct { bool recorder; - it2s_tender_database_s* dbms; + itss_db_t* dbms; } logging; int station_type; @@ -98,7 +98,7 @@ typedef struct facilities { } change; } id; - it2s_tender_epv_t epv; + itss_epv_t epv; bool exit; } facilities_t; diff --git a/src/infrastructure.c b/src/infrastructure.c index 8bcc520..ee09113 100644 --- a/src/infrastructure.c +++ b/src/infrastructure.c @@ -60,10 +60,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, it2s_tender_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, itss_epv_t* epv, uint8_t* ssp, uint16_t ssp_len) { int rv = 0; - uint64_t now = it2s_tender_get_clock(epv); + uint64_t now = itss_time_get(epv); switch (type) { case SERVICE_IVI: @@ -252,7 +252,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, it2s_tender_epv_t* epv, uint64_t* id) { +static int service_add(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, itss_epv_t* epv, uint64_t* id) { switch (type) { case SERVICE_IVI: @@ -263,7 +263,7 @@ static int service_add(infrastructure_t* infrastructure, enum SERVICE_TYPE type, IVIM_t* ivim = (IVIM_t*) its_msg; - uint64_t now = it2s_tender_get_clock(epv); + uint64_t now = itss_time_get(epv); uint64_t timestamp, valid_to, valid_from; if (!ivim->ivi.mandatory.timeStamp) { @@ -338,7 +338,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, it2s_tender_epv_t* epv, uint64_t* id) { +static int service_update(infrastructure_t* infrastructure, enum SERVICE_TYPE type, void* its_msg, itss_epv_t* epv, uint64_t* id) { switch (type) { case SERVICE_IVI: @@ -349,7 +349,7 @@ static int service_update(infrastructure_t* infrastructure, enum SERVICE_TYPE ty IVIM_t* ivim = (IVIM_t*) its_msg; - uint64_t now = it2s_tender_get_clock(epv); + uint64_t now = itss_time_get(epv); uint64_t timestamp, valid_to, valid_from; if (!ivim->ivi.mandatory.timeStamp) { @@ -445,7 +445,7 @@ 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, it2s_tender_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, itss_epv_t* epv, 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)) { case SERVICE_NEW: @@ -522,7 +522,7 @@ void* infrastructure_service(void *fc) { uint32_t sleep_count = 0; while (!facilities->exit) { - now = it2s_tender_get_clock(&facilities->epv); + now = itss_time_get(&facilities->epv); int n_awaiting_services = 0; pthread_mutex_lock(&infrastructure->lock); diff --git a/src/infrastructure.h b/src/infrastructure.h index 805e163..1d24f3d 100644 --- a/src/infrastructure.h +++ b/src/infrastructure.h @@ -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, it2s_tender_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, itss_epv_t* epv, uint64_t* id, uint8_t* ssp, uint16_t ssp_len); void* infrastructure_service(void* fc); diff --git a/src/requests.c b/src/requests.c index 56a27ef..b2ee1fe 100644 --- a/src/requests.c +++ b/src/requests.c @@ -15,6 +15,7 @@ #include #include #include +#include int facilities_request_result_accepted(void* responder) { int rv = 0; @@ -47,12 +48,6 @@ int facilities_request_result_rejected(void* responder) { int facilities_request_single_message(facilities_t* facilities, void* responder, FacilitiesMessageRequest_t* frm) { int rv = 0; - uint64_t id = 0; - if (!frm->id) { - id = rand(); - } else if (*frm->id == 0) { - id = rand(); - } TransportRequest_t* tr = calloc(1, sizeof(TransportRequest_t)); tr->present = TransportRequest_PR_packet; @@ -118,6 +113,13 @@ int facilities_request_single_message(facilities_t* facilities, void* responder, goto cleanup; } + uint64_t id = 0; + if (!frm->id) { + id = itss_id(frm->data.buf, frm->data.size); + } else if (*frm->id == 0) { + id = itss_id(frm->data.buf, frm->data.size); + } + bool is_update = false; int managed_msg = false; @@ -233,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 = it2s_tender_get_clock(&facilities->epv);; + valid_from = itss_time_get(&facilities->epv);; } else { asn_INTEGER2ulong((INTEGER_t*) ((IVIM_t*) its_msg)->ivi.mandatory.validFrom, (unsigned long long*) &valid_from); } @@ -308,24 +310,24 @@ int facilities_request_single_message(facilities_t* facilities, void* responder, goto cleanup; } - it2s_tender_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) { uint16_t buffer_len = 2048; uint8_t buffer[buffer_len]; - int e = it2s_tender_management_record_packet_sdu( + int e = itss_management_record_packet_sdu( buffer, buffer_len, frm->data.buf, frm->data.size, id, - it2s_tender_get_clock(&facilities->epv), + itss_time_get(&facilities->epv), ITSS_FACILITIES, true); if (e != -1) { - it2s_tender_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"); } } diff --git a/src/saem.c b/src/saem.c index 66fa7df..88d18dd 100644 --- a/src/saem.c +++ b/src/saem.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -123,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 = it2s_tender_get_clock(&facilities->epv); + bulletin->to_consume[bulletin->to_consume_len]->timestamp = itss_time_get(&facilities->epv); 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); @@ -323,35 +324,35 @@ void *sa_service(void *fc) { rv = mk_saem(facilities, bpr->data.buf, (uint32_t *) &bpr->data.size); if (!rv) { - bpr->id = rand() + 1; + bpr->id = itss_id(bpr->data.buf, bpr->data.size); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, tr_oer+1, 1023); if (enc.encoded == -1) { syslog_err("[facilities] encoding TR for SAEM failed"); continue; } else { - it2s_tender_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); - it2s_tender_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, &facilities->epv, true, messageID_saem, NULL, bpr->data.buf, bpr->data.size); } if (facilities->logging.recorder) { uint16_t buffer_len = 2048; uint8_t buffer[buffer_len]; - int e = it2s_tender_management_record_packet_sdu( + int e = itss_management_record_packet_sdu( buffer, buffer_len, bpr->data.buf, bpr->data.size, bpr->id, - it2s_tender_get_clock(&facilities->epv), + itss_time_get(&facilities->epv), ITSS_FACILITIES, true); if (e != -1) { - it2s_tender_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"); } } } @@ -361,13 +362,13 @@ void *sa_service(void *fc) { ++mk_saem_n_sleep; int32_t lat, lon; - it2s_tender_lock_space(&facilities->epv); - it2s_tender_get_space(&facilities->epv); + itss_space_lock(&facilities->epv); + itss_space_get(&facilities->epv); lat = facilities->epv.space.latitude; lon = facilities->epv.space.longitude; - it2s_tender_unlock_space(&facilities->epv); + itss_space_unlock(&facilities->epv); - uint64_t now = it2s_tender_get_clock(&facilities->epv); + uint64_t now = itss_time_get(&facilities->epv); pthread_mutex_lock(&bulletin->lock); for (int a = 0; a < bulletin->to_consume_len; ++a) { diff --git a/src/tpm.c b/src/tpm.c index da4d720..3770334 100644 --- a/src/tpm.c +++ b/src/tpm.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -24,13 +25,13 @@ int tpm_is_inside_zone(void* fc, tolling_info_t* ti) { facilities_t* facilities = (facilities_t*) fc; double point[2]; - it2s_tender_lock_space(&facilities->epv); - it2s_tender_get_space(&facilities->epv); + 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; - it2s_tender_unlock_space(&facilities->epv); + itss_space_unlock(&facilities->epv); - if (it2s_tender_is_inside_polygon(point, ti->zone.polygon, ti->zone.polygon_len)) { + if (itss_is_inside_polygon(point, ti->zone.polygon, ti->zone.polygon_len)) { return 1; } @@ -53,7 +54,7 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig } pthread_mutex_lock(&facilities->epv.time.lock); - tolling->tz = it2s_tender_get_now(TIME_MICROSECONDS) ; + tolling->tz = itss_ts_get(TIME_MICROSECONDS) ; pthread_mutex_unlock(&facilities->epv.time.lock); TPM_t* tpm = NULL; @@ -81,21 +82,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, it2s_tender_get_clock(&facilities->epv)); + asn_ulong2INTEGER(&tpm->tpm->timestamp, itss_time_get(&facilities->epv)); // stationType tpm->tpm->stationType = facilities->station_type; // referencePosition - it2s_tender_lock_space(&facilities->epv); - it2s_tender_get_space(&facilities->epv); + 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; - it2s_tender_unlock_space(&facilities->epv); + itss_space_unlock(&facilities->epv); if (lat_conf > lon_conf) { tpm->tpm->referencePosition.positionConfidenceEllipse.semiMinorConfidence = lon_conf; tpm->tpm->referencePosition.positionConfidenceEllipse.semiMajorConfidence = lat_conf; @@ -237,8 +238,6 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig tr->choice.packet.present = TransportPacketRequest_PR_btp; BTPPacketRequest_t* bpr = &tr->choice.packet.choice.btp; - bpr->id = rand() + 1; - id = bpr->id; bpr->gn.securityProfile.encrypt = true; bpr->gn.securityProfile.sign = true; @@ -252,6 +251,9 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig bpr->data.buf = malloc(tpm_uper_len); memcpy(bpr->data.buf, tpm_uper, tpm_uper_len); + bpr->id = itss_id(bpr->data.buf, bpr->data.size); + id = bpr->id; + bpr->destinationPort = 7011; bpr->btpType = BTPType_btpB; bpr->gn.destinationAddress.buf = malloc(6); @@ -339,7 +341,7 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig goto cleanup; } - it2s_tender_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 @@ -347,7 +349,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); - it2s_tender_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, &facilities->epv, true, 117, NULL, tpm_uper, tpm_uper_len); } // send to [applications] @@ -364,22 +366,22 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig rv = 1; goto cleanup; } - it2s_tender_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) { uint16_t buffer_len = 2048; uint8_t buffer[buffer_len]; - int e = it2s_tender_management_record_packet_sdu( + int e = itss_management_record_packet_sdu( buffer, buffer_len, tpm_uper, tpm_uper_len, id, - it2s_tender_get_clock(&facilities->epv), + itss_time_get(&facilities->epv), ITSS_FACILITIES, true); if (e != -1) { - it2s_tender_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"); } } @@ -557,21 +559,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, it2s_tender_get_clock(&facilities->epv)); + asn_ulong2INTEGER(&tpm->tpm->timestamp, itss_time_get(&facilities->epv)); // stationType tpm->tpm->stationType = facilities->station_type; // referencePosition - it2s_tender_lock_space(&facilities->epv); - it2s_tender_get_space(&facilities->epv); + 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; - it2s_tender_unlock_space(&facilities->epv); + itss_space_unlock(&facilities->epv); if (lat_conf > lon_conf) { tpm->tpm->referencePosition.positionConfidenceEllipse.semiMinorConfidence = lon_conf; tpm->tpm->referencePosition.positionConfidenceEllipse.semiMajorConfidence = lat_conf; @@ -678,8 +680,6 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur tr->choice.packet.present = TransportPacketRequest_PR_btp; BTPPacketRequest_t* bpr = &tr->choice.packet.choice.btp; - bpr->id = rand() + 1; - id = bpr->id; bpr->gn.securityProfile.encrypt = true; bpr->gn.securityProfile.sign = true; @@ -688,6 +688,9 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur bpr->data.buf = malloc(tpm_uper_len); memcpy(bpr->data.buf, tpm_uper, tpm_uper_len); + bpr->id = itss_id(bpr->data.buf, bpr->data.size); + id = bpr->id; + bpr->destinationPort = 7011; bpr->btpType = BTPType_btpB; bpr->gn.destinationAddress.buf = malloc(6); @@ -778,7 +781,7 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur goto cleanup; } - it2s_tender_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 @@ -786,7 +789,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); - it2s_tender_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, &facilities->epv, true, 117, NULL, tpm_uper, tpm_uper_len); } // send to [applications] @@ -803,21 +806,21 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, void* secur goto cleanup; } - it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message (TPM.reply)"); + 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 = it2s_tender_management_record_packet_sdu( + int e = itss_management_record_packet_sdu( buffer, buffer_len, tpm_uper, tpm_uper_len, id, - it2s_tender_get_clock(&facilities->epv), + itss_time_get(&facilities->epv), ITSS_FACILITIES, true); if (e != -1) { - it2s_tender_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"); } } @@ -829,7 +832,7 @@ cleanup: ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi); } -static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_socket, it2s_tender_queue_t* tx_queue, it2s_tender_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, itss_epv_t* epv, uint8_t* neighbour, uint8_t* src_addr) { if (!tpm_rx->tpm->tollingType) { syslog_err("[facilities] [tolling] received TPM does not have a type"); @@ -1015,7 +1018,7 @@ static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_so int32_t rl = zmq_recv(security_socket, buf, buf_len, 0); syslog_debug("[facilities]<-[security] SecurityReply.tlsClose (%dB)", rl); - uint64_t id = rand() + 1; + uint32_t id = rand(); tr = calloc(1, sizeof(TransportRequest_t)); tr->present = TransportRequest_PR_data; tr->choice.data.present = TransportDataRequest_PR_tcp; @@ -1029,7 +1032,7 @@ static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_so buf[0] = 4; enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, buf_len-1); - it2s_tender_queue_send(tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, id, "TR.data.tcp.connClose"); + itss_queue_send(tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, id, "TR.data.tcp.connClose"); free(tlsc); for (int i = 0; i < tolling->protocol.c.tls.n_tlsc; ++i) { @@ -1091,7 +1094,7 @@ int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, goto cleanup; } pthread_mutex_lock(&facilities->epv.time.lock); - syslog_info("[facilities] [tolling] entry.reply took %ld us", it2s_tender_get_now(TIME_MICROSECONDS) - tolling->tz); + syslog_info("[facilities] [tolling] entry.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->tz); pthread_mutex_unlock(&facilities->epv.time.lock); veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, &facilities->epv, neighbour, src_addr); break; @@ -1118,7 +1121,7 @@ int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, goto cleanup; } pthread_mutex_lock(&facilities->epv.time.lock); - syslog_info("[facilities] [tolling] exit.reply took %ld us", it2s_tender_get_now(TIME_MICROSECONDS) - tolling->tz); + syslog_info("[facilities] [tolling] exit.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->tz); pthread_mutex_unlock(&facilities->epv.time.lock); veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, &facilities->epv, neighbour, src_addr); break; @@ -1142,7 +1145,7 @@ int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, goto cleanup; } pthread_mutex_lock(&facilities->epv.time.lock); - syslog_info("[facilities] [tolling] single.reply took %ld us", it2s_tender_get_now(TIME_MICROSECONDS) - tolling->tz); + syslog_info("[facilities] [tolling] single.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->tz); pthread_mutex_unlock(&facilities->epv.time.lock); veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, &facilities->epv, neighbour, src_addr); break; @@ -1174,10 +1177,10 @@ int tolling_init(tolling_t* tolling, void* zmq_ctx, char* security_address, uint return 0; } -tolling_info_t* tolling_info_new(it2s_tender_epv_t* epv, TollingPaymentInfo_t* tpi) { +tolling_info_t* tolling_info_new(itss_epv_t* epv, TollingPaymentInfo_t* tpi) { tolling_info_t* ti = calloc(1, sizeof(tolling_info_t)); - ti->timestamp = it2s_tender_get_clock(epv); + ti->timestamp = itss_time_get(epv); ti->asn = tpi; ti->zone.polygon_len = tpi->zone.list.count; @@ -1197,7 +1200,7 @@ void tolling_info_free(tolling_info_t* ti) { free(ti); } -tlsc_t* tolling_tlsc_new(tolling_t* tolling, it2s_tender_epv_t* epv, uint8_t ipv6[16], uint16_t port) { +tlsc_t* tolling_tlsc_new(tolling_t* tolling, itss_epv_t* epv, uint8_t ipv6[16], uint16_t port) { if (tolling->protocol.c.tls.n_tlsc >= TOLLING_MAX_CONNS - 1) { return NULL; } @@ -1206,18 +1209,18 @@ tlsc_t* tolling_tlsc_new(tolling_t* tolling, it2s_tender_epv_t* epv, uint8_t ipv memcpy(tlsc->ipv6, ipv6, 16); tlsc->port = port; tlsc->id = rand(); - tlsc->ts = it2s_tender_get_clock(epv); + tlsc->ts = itss_time_get(epv); ++tolling->protocol.c.tls.n_tlsc; return tlsc; } -tlsc_t* tolling_tlsc_get(tolling_t* tolling, it2s_tender_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) { 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 = it2s_tender_get_clock(epv); + tlsc->ts = itss_time_get(epv); break; } } @@ -1225,9 +1228,9 @@ tlsc_t* tolling_tlsc_get(tolling_t* tolling, it2s_tender_epv_t* epv, uint8_t ipv } -void tolling_tlsc_mgmt(tolling_t* tolling, it2s_tender_epv_t* epv, it2s_tender_queue_t* tx_queue, void* security_socket) { +void tolling_tlsc_mgmt(tolling_t* tolling, itss_epv_t* epv, itss_queue_t* tx_queue, void* security_socket) { pthread_mutex_lock(&tolling->lock); - uint64_t now = it2s_tender_get_clock(epv); + uint64_t now = itss_time_get(epv); 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) { @@ -1262,7 +1265,7 @@ void tolling_tlsc_mgmt(tolling_t* tolling, it2s_tender_epv_t* epv, it2s_tender_q buf[0] = 4; enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, buf_len-1); - it2s_tender_queue_send(tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, id, "TR.data.tcp.connClose"); + itss_queue_send(tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, id, "TR.data.tcp.connClose"); free(tlsc); for (int j = i; j < tolling->protocol.c.tls.n_tlsc-1; ++j) { diff --git a/src/tpm.h b/src/tpm.h index db44454..3b0c5c1 100644 --- a/src/tpm.h +++ b/src/tpm.h @@ -93,9 +93,9 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, uint8_t* src_addr); int tpm_is_inside_zone(void* fc, tolling_info_t* ti); -tolling_info_t* tolling_info_new(it2s_tender_epv_t* epv, TollingPaymentInfo_t* tpi); +tolling_info_t* tolling_info_new(itss_epv_t* epv, TollingPaymentInfo_t* tpi); void tolling_info_free(tolling_info_t* ti); -tlsc_t* tolling_tlsc_new(tolling_t* tolling, it2s_tender_epv_t* epv, uint8_t ipv6[16], uint16_t port); -tlsc_t* tolling_tlsc_get(tolling_t* tolling, it2s_tender_epv_t* epv, uint8_t ipv6[16], uint16_t port); -void tolling_tlsc_mgmt(tolling_t* tolling, it2s_tender_epv_t* epv, it2s_tender_queue_t* tx_queue, void* security_socket); +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); diff --git a/src/vcm.c b/src/vcm.c index e18f002..c2acaca 100644 --- a/src/vcm.c +++ b/src/vcm.c @@ -6,13 +6,14 @@ #include #include #include +#include #include #include #include static int are_vehicles_intersecting( - it2s_tender_st_s* tA, int tA_len, uint16_t vA_length, uint16_t vA_width, - it2s_tender_st_s* tB, int tB_len, uint16_t vB_length, uint16_t vB_width, + itss_st_t* tA, int tA_len, uint16_t vA_length, uint16_t vA_width, + itss_st_t* tB, int tB_len, uint16_t vB_length, uint16_t vB_width, int* index ) { @@ -34,10 +35,10 @@ static int are_vehicles_intersecting( // B2[0] = tB[b+1].latitude; // B2[1] = tB[b+1].longitude; -// if (it2s_tender_do_segments_intersect(A1, A2, B1, B2)) { +// if (itss_do_segments_intersect(A1, A2, B1, B2)) { // printf("tA[a].lat=%d tA[a].lon=%d tB[b].lat=%d tB[b].lon=%d tA[a].ts=%ld tB[b].ts=%ld\n", // tA[a].latitude, tA[a].longitude, tB[b].latitude, tB[b].longitude, tA[a].timestamp, tB[b].timestamp); fflush(stdout); - if (it2s_tender_is_inside_circle(tA[a].latitude, tA[a].longitude, tB[b].latitude, tB[b].longitude, 8, DCM_HAVERSINE)) { + if (itss_is_inside_circle(tA[a].latitude, tA[a].longitude, tB[b].latitude, tB[b].longitude, 8, DCM_HAVERSINE)) { if (tA[a].timestamp < tB[b].timestamp + 2000 && tA[a].timestamp > tB[b].timestamp - 2000) { *index = a; @@ -83,22 +84,22 @@ static int vcm_check_handle_request(facilities_t* facilities, VCM_t* vcm, mc_nei const ssize_t buf_len = 512; uint8_t buf[buf_len]; - it2s_tender_st_s trajectoryA[TRAJECTORY_MAX_LEN+1]; /* ego trajectory */ + itss_st_t trajectoryA[TRAJECTORY_MAX_LEN+1]; /* ego trajectory */ ssize_t trajectoryA_len = 0; - it2s_tender_st_s trajectoryB[TRAJECTORY_MAX_LEN+1]; /* neighbour trajectory */ + itss_st_t trajectoryB[TRAJECTORY_MAX_LEN+1]; /* neighbour trajectory */ uint16_t trajectoryB_len = 0; - uint64_t now = it2s_tender_get_clock(&facilities->epv); + uint64_t now = itss_time_get(&facilities->epv); neighbour->proposed = true; neighbour->t_proposal = now; int32_t lat, lon; - it2s_tender_lock_space(&facilities->epv); - it2s_tender_get_space(&facilities->epv); + itss_space_lock(&facilities->epv); + itss_space_get(&facilities->epv); lat = facilities->epv.space.latitude; lon = facilities->epv.space.longitude; - it2s_tender_unlock_space(&facilities->epv); + itss_space_unlock(&facilities->epv); vcm_rep = calloc(1, sizeof(VCM_t)); @@ -160,7 +161,7 @@ static int vcm_check_handle_request(facilities_t* facilities, VCM_t* vcm, mc_nei tr->choice.packet.present = TransportPacketRequest_PR_btp; BTPPacketRequest_t* bpr = &tr->choice.packet.choice.btp; bpr->btpType = BTPType_btpB; - bpr->id = rand() + 1; + bpr->id = itss_id(buf, vcm_rep_len); bpr->gn.destinationAddress.buf = malloc(6); for (int i = 0; i < 6; ++i) { bpr->gn.destinationAddress.buf[i] = 0xff; @@ -180,7 +181,7 @@ static int vcm_check_handle_request(facilities_t* facilities, VCM_t* vcm, mc_nei goto cleanup; } - it2s_tender_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; @@ -197,22 +198,22 @@ static int vcm_check_handle_request(facilities_t* facilities, VCM_t* vcm, mc_nei goto cleanup; } - it2s_tender_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) { uint16_t buffer_len = 2048; uint8_t buffer[buffer_len]; - int e = it2s_tender_management_record_packet_sdu( + int e = itss_management_record_packet_sdu( buffer, buffer_len, bpr->data.buf, bpr->data.size, bpr->id, - it2s_tender_get_clock(&facilities->epv), + itss_time_get(&facilities->epv), ITSS_FACILITIES, true); if (e != -1) { - it2s_tender_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"); } } @@ -229,7 +230,7 @@ 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); - uint64_t now_us = it2s_tender_get_now(TIME_MICROSECONDS); + uint64_t now_us = itss_ts_get(TIME_MICROSECONDS); pthread_mutex_unlock(&facilities->epv.time.lock); if (neighbour->intersecting) { @@ -258,10 +259,10 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm, const ssize_t buf_len = 1024; uint8_t buf[buf_len]; - it2s_tender_st_s trajectoryA[TRAJECTORY_MAX_LEN+1]; /* ego trajectory */ + itss_st_t trajectoryA[TRAJECTORY_MAX_LEN+1]; /* ego trajectory */ uint16_t trajectoryA_len = 0; - uint64_t now = it2s_tender_get_clock(&facilities->epv); + uint64_t now = itss_time_get(&facilities->epv); if (now < neighbour->t_iid/1000 + MC_RESOLUTION_TIMEOUT) { rv = 0; @@ -271,7 +272,7 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm, neighbour->intersecting = true; pthread_mutex_lock(&facilities->epv.time.lock); - uint64_t now_us = it2s_tender_get_now(TIME_MICROSECONDS) ; + uint64_t now_us = itss_ts_get(TIME_MICROSECONDS) ; pthread_mutex_unlock(&facilities->epv.time.lock); neighbour->t_iid = now_us; @@ -281,16 +282,16 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm, } int32_t lat, lon; - it2s_tender_lock_space(&facilities->epv); - it2s_tender_get_space(&facilities->epv); + itss_space_lock(&facilities->epv); + itss_space_get(&facilities->epv); lat = facilities->epv.space.latitude; lon = facilities->epv.space.longitude; - it2s_tender_unlock_space(&facilities->epv); + itss_space_unlock(&facilities->epv); - it2s_tender_lock_trajectory(&facilities->epv); + itss_trajectory_lock(&facilities->epv); trajectoryA_len = facilities->epv.trajectory.len; - memcpy(trajectoryA + 1, facilities->epv.trajectory.path, trajectoryA_len * sizeof(it2s_tender_st_s)); - it2s_tender_unlock_trajectory(&facilities->epv); + memcpy(trajectoryA + 1, facilities->epv.trajectory.path, trajectoryA_len * sizeof(itss_st_t)); + itss_trajectory_unlock(&facilities->epv); trajectoryA[0].latitude = lat; @@ -382,7 +383,7 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm, tr->present = TransportRequest_PR_packet; tr->choice.packet.present = TransportPacketRequest_PR_btp; BTPPacketRequest_t* bpr = &tr->choice.packet.choice.btp; - bpr->id = rand() + 1; + bpr->id = itss_id(buf, vcm_req_len); bpr->btpType = BTPType_btpB; bpr->gn.destinationAddress.buf = malloc(6); for (int i = 0; i < 6; ++i) { @@ -403,7 +404,7 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm, goto cleanup; } - it2s_tender_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; @@ -420,22 +421,22 @@ static int vcm_check_intersection_detected(facilities_t* facilities, VCM_t* vcm, goto cleanup; } - it2s_tender_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) { uint16_t buffer_len = 2048; uint8_t buffer[buffer_len]; - int e = it2s_tender_management_record_packet_sdu( + int e = itss_management_record_packet_sdu( buffer, buffer_len, bpr->data.buf, bpr->data.size, bpr->id, - it2s_tender_get_clock(&facilities->epv), + itss_time_get(&facilities->epv), ITSS_FACILITIES, true); if (e != -1) { - it2s_tender_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"); } } @@ -452,19 +453,19 @@ int vcm_check(void* fc, VCM_t* vcm) { int rv = 0; - it2s_tender_st_s trajectoryA[TRAJECTORY_MAX_LEN+1]; /* ego trajectory */ - it2s_tender_st_s trajectoryB[TRAJECTORY_MAX_LEN+1]; /* neighbour trajectory */ + itss_st_t trajectoryA[TRAJECTORY_MAX_LEN+1]; /* ego trajectory */ + itss_st_t trajectoryB[TRAJECTORY_MAX_LEN+1]; /* neighbour trajectory */ uint16_t trajectoryA_len = 0; uint16_t trajectoryB_len = 0; - uint64_t now = it2s_tender_get_clock(&facilities->epv); + uint64_t now = itss_time_get(&facilities->epv); int32_t lat, lon; - it2s_tender_lock_space(&facilities->epv); - it2s_tender_get_space(&facilities->epv); + itss_space_lock(&facilities->epv); + itss_space_get(&facilities->epv); lat = facilities->epv.space.latitude; lon = facilities->epv.space.longitude; - it2s_tender_unlock_space(&facilities->epv); + itss_space_unlock(&facilities->epv); pthread_mutex_lock(&coordination->lock); @@ -501,10 +502,10 @@ int vcm_check(void* fc, VCM_t* vcm) { } } else { - it2s_tender_lock_trajectory(&facilities->epv); + itss_trajectory_lock(&facilities->epv); trajectoryA_len = facilities->epv.trajectory.len; - memcpy(trajectoryA + 1, facilities->epv.trajectory.path, trajectoryA_len * sizeof(it2s_tender_st_s)); - it2s_tender_unlock_trajectory(&facilities->epv); + memcpy(trajectoryA + 1, facilities->epv.trajectory.path, trajectoryA_len * sizeof(itss_st_t)); + itss_trajectory_unlock(&facilities->epv); trajectoryA[0].latitude = lat; trajectoryA[0].longitude = lon; @@ -560,29 +561,29 @@ static int mk_vcm(facilities_t* facilities, uint8_t* vcm_uper, uint16_t* vcm_upe coordination_s* coordination = &facilities->coordination; - it2s_tender_st_s trajectory[TRAJECTORY_MAX_LEN]; + itss_st_t trajectory[TRAJECTORY_MAX_LEN]; VCM_t* vcm = calloc(1, sizeof(VCM_t)); vcm->header.messageID = 43; vcm->header.protocolVersion = 1; - uint64_t now = it2s_tender_get_clock(&facilities->epv); + uint64_t now = itss_time_get(&facilities->epv); 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; - it2s_tender_lock_space(&facilities->epv); - it2s_tender_get_space(&facilities->epv); + itss_space_lock(&facilities->epv); + itss_space_get(&facilities->epv); lat = facilities->epv.space.latitude; lon = facilities->epv.space.longitude; - it2s_tender_unlock_space(&facilities->epv); + itss_space_unlock(&facilities->epv); - it2s_tender_lock_trajectory(&facilities->epv); + itss_trajectory_lock(&facilities->epv); trajectory_len = facilities->epv.trajectory.len; - memcpy(trajectory, facilities->epv.trajectory.path, trajectory_len * sizeof(it2s_tender_st_s)); - it2s_tender_unlock_trajectory(&facilities->epv); + memcpy(trajectory, facilities->epv.trajectory.path, trajectory_len * sizeof(itss_st_t)); + itss_trajectory_unlock(&facilities->epv); vcm->vcm.currentPosition.latitude = lat; vcm->vcm.currentPosition.longitude = lon; @@ -680,7 +681,7 @@ void* vc_service(void* fc) { while (!facilities->exit) { - uint64_t now = it2s_tender_get_clock(&facilities->epv); + uint64_t now = itss_time_get(&facilities->epv); pthread_mutex_lock(&coordination->lock); if (vcm_timer_check(coordination, now)) { @@ -689,14 +690,14 @@ void* vc_service(void* fc) { continue; } - bpr->id = rand() + 1; + bpr->id = itss_id(bpr->data.buf, bpr->data.size); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, 1023); if (enc.encoded == -1) { syslog_err("[facilities] encoding TR for VCM failed"); continue; } - it2s_tender_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; @@ -706,22 +707,22 @@ void* vc_service(void* fc) { syslog_err("[facilities] encoding FI for VCM failed"); continue; } - it2s_tender_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) { uint16_t buffer_len = 2048; uint8_t buffer[buffer_len]; - int e = it2s_tender_management_record_packet_sdu( + int e = itss_management_record_packet_sdu( buffer, buffer_len, bpr->data.buf, bpr->data.size, bpr->id, - it2s_tender_get_clock(&facilities->epv), + itss_time_get(&facilities->epv), ITSS_FACILITIES, true); if (e != -1) { - it2s_tender_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"); } } diff --git a/src/vcm.h b/src/vcm.h index d8a6070..8c988e8 100644 --- a/src/vcm.h +++ b/src/vcm.h @@ -33,7 +33,7 @@ typedef struct coordination { struct { uint64_t id; uint8_t link[32]; - it2s_tender_region_t region; + itss_region_t region; } chain; } coordination_s;