New log options, quick shutdown, ZMQ reconnect

This commit is contained in:
emanuel 2022-08-30 19:06:43 +01:00
parent 1959f1380d
commit 856e459319
15 changed files with 492 additions and 446 deletions

View File

@ -12,7 +12,6 @@
#include <time.h> #include <time.h>
#include <zmq.h> #include <zmq.h>
#include <unistd.h> #include <unistd.h>
#include <syslog.h>
#include <math.h> #include <math.h>
#include <fcntl.h> #include <fcntl.h>
@ -71,7 +70,7 @@ static int permissions_check(int cid, uint8_t* permissions, uint8_t permissions_
*/ */
if (permissions_len < 3) { if (permissions_len < 3) {
syslog_debug("[facilities] [ca] permissions length too small"); log_debug("[ca] permissions length too small");
return 0; return 0;
} }
@ -95,10 +94,10 @@ static int mk_cam(uint8_t *cam_oer, uint32_t *cam_len) {
if(lightship->use_obd){ if(lightship->use_obd){
shm_fd = shm_open("it2s-bluetooth-decoded", O_RDONLY, 0666); shm_fd = shm_open("it2s-bluetooth-decoded", O_RDONLY, 0666);
if(shm_fd == -1) if(shm_fd == -1)
syslog_err("[facilities] failed to open CAN shared memory\n"); log_error("failed to open CAN shared memory\n");
shared_message = (decoded_can_values_shm *)mmap(0, sizeof(decoded_can_values_shm), PROT_READ, MAP_SHARED, shm_fd, 0); shared_message = (decoded_can_values_shm *)mmap(0, sizeof(decoded_can_values_shm), PROT_READ, MAP_SHARED, shm_fd, 0);
if(shared_message == MAP_FAILED) if(shared_message == MAP_FAILED)
syslog_err("[facilities] failed to map CAN shared memory\n"); log_error("failed to map CAN shared memory\n");
} }
CAM_t *cam = calloc(1, sizeof(CAM_t)); CAM_t *cam = calloc(1, sizeof(CAM_t));
@ -340,7 +339,7 @@ static int mk_cam(uint8_t *cam_oer, uint32_t *cam_len) {
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_CAM, NULL, cam, cam_oer, 512); asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_CAM, NULL, cam, cam_oer, 512);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [ca] failed encoding CAM (%s)", enc.failed_type->name); log_error("[ca] failed encoding CAM (%s)", enc.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -349,7 +348,7 @@ static int mk_cam(uint8_t *cam_oer, uint32_t *cam_len) {
if(lightship->use_obd){ if(lightship->use_obd){
munmap(shared_message, sizeof(can_values_shm)); munmap(shared_message, sizeof(can_values_shm));
if(close(shm_fd) == -1) if(close(shm_fd) == -1)
syslog_err("[facilities] failed to close CAN shared memory\n"); log_error("failed to close CAN shared memory\n");
} }
cleanup: cleanup:
@ -372,11 +371,11 @@ int lightship_init() {
shm_fd = shm_open("it2s-bluetooth-decoded", O_RDONLY, 0666); shm_fd = shm_open("it2s-bluetooth-decoded", O_RDONLY, 0666);
if(shm_fd == -1){ if(shm_fd == -1){
syslog_debug("[facilities] obd shmem not found\n"); log_debug("obd shmem not found\n");
lightship->use_obd = 0; lightship->use_obd = 0;
} }
else{ else{
syslog_debug("[facilities] obd shmem found\n"); log_debug("obd shmem found\n");
lightship->use_obd = 1; lightship->use_obd = 1;
close(shm_fd); close(shm_fd);
} }
@ -482,7 +481,7 @@ enum CAM_CHECK_R check_cam(BTPPacketIndication_t *bpi, CAM_t* cam, uint8_t* ssp,
cam->cam.camParameters.highFrequencyContainer.choice.rsuContainerHighFrequency.protectedCommunicationZonesRSU) { cam->cam.camParameters.highFrequencyContainer.choice.rsuContainerHighFrequency.protectedCommunicationZonesRSU) {
if (!permissions_check(CID_PROTECTED_ZONES, ssp, ssp_len)) { if (!permissions_check(CID_PROTECTED_ZONES, ssp, ssp_len)) {
rv = CAM_BAD_PERMISSIONS; rv = CAM_BAD_PERMISSIONS;
syslog_debug("[facilities] [ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_PROTECTED_ZONES].container); log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_PROTECTED_ZONES].container);
return rv; return rv;
} }
} }
@ -493,34 +492,34 @@ enum CAM_CHECK_R check_cam(BTPPacketIndication_t *bpi, CAM_t* cam, uint8_t* ssp,
case SpecialVehicleContainer_PR_publicTransportContainer: case SpecialVehicleContainer_PR_publicTransportContainer:
if (!permissions_check(CID_PUBLIC_TRANSPORT, ssp, ssp_len)) { if (!permissions_check(CID_PUBLIC_TRANSPORT, ssp, ssp_len)) {
rv = CAM_BAD_PERMISSIONS; rv = CAM_BAD_PERMISSIONS;
syslog_debug("[facilities] [ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_PUBLIC_TRANSPORT].container); log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_PUBLIC_TRANSPORT].container);
return rv; return rv;
} }
break; break;
case SpecialVehicleContainer_PR_specialTransportContainer: case SpecialVehicleContainer_PR_specialTransportContainer:
if (!permissions_check(CID_SPECIAL_TRANSPORT, ssp, ssp_len)) { if (!permissions_check(CID_SPECIAL_TRANSPORT, ssp, ssp_len)) {
rv = CAM_BAD_PERMISSIONS; rv = CAM_BAD_PERMISSIONS;
syslog_debug("[facilities] [ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_SPECIAL_TRANSPORT].container); log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_SPECIAL_TRANSPORT].container);
return rv; return rv;
} }
break; break;
case SpecialVehicleContainer_PR_dangerousGoodsContainer: case SpecialVehicleContainer_PR_dangerousGoodsContainer:
if (!permissions_check(CID_DANGEROUS_GOODS, ssp, ssp_len)) { if (!permissions_check(CID_DANGEROUS_GOODS, ssp, ssp_len)) {
rv = CAM_BAD_PERMISSIONS; rv = CAM_BAD_PERMISSIONS;
syslog_debug("[facilities] [ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_DANGEROUS_GOODS].container); log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_DANGEROUS_GOODS].container);
return rv; return rv;
} }
break; break;
case SpecialVehicleContainer_PR_roadWorksContainerBasic: case SpecialVehicleContainer_PR_roadWorksContainerBasic:
if (!permissions_check(CID_ROADWORK, ssp, ssp_len)) { if (!permissions_check(CID_ROADWORK, ssp, ssp_len)) {
rv = CAM_BAD_PERMISSIONS; rv = CAM_BAD_PERMISSIONS;
syslog_debug("[facilities] [ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_ROADWORK].container); log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_ROADWORK].container);
return rv; return rv;
} }
if (cam->cam.camParameters.specialVehicleContainer->choice.roadWorksContainerBasic.closedLanes) { if (cam->cam.camParameters.specialVehicleContainer->choice.roadWorksContainerBasic.closedLanes) {
if (!permissions_check(CID_CLOSED_LANES, ssp, ssp_len)) { if (!permissions_check(CID_CLOSED_LANES, ssp, ssp_len)) {
rv = CAM_BAD_PERMISSIONS; rv = CAM_BAD_PERMISSIONS;
syslog_debug("[facilities] [ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_CLOSED_LANES].container); log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_CLOSED_LANES].container);
return rv; return rv;
} }
} }
@ -528,14 +527,14 @@ enum CAM_CHECK_R check_cam(BTPPacketIndication_t *bpi, CAM_t* cam, uint8_t* ssp,
case SpecialVehicleContainer_PR_rescueContainer: case SpecialVehicleContainer_PR_rescueContainer:
if (!permissions_check(CID_RESCUE, ssp, ssp_len)) { if (!permissions_check(CID_RESCUE, ssp, ssp_len)) {
rv = CAM_BAD_PERMISSIONS; rv = CAM_BAD_PERMISSIONS;
syslog_debug("[facilities] [ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_RESCUE].container); log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_RESCUE].container);
return rv; return rv;
} }
break; break;
case SpecialVehicleContainer_PR_emergencyContainer: case SpecialVehicleContainer_PR_emergencyContainer:
if (!permissions_check(CID_EMERGENCY, ssp, ssp_len)) { if (!permissions_check(CID_EMERGENCY, ssp, ssp_len)) {
rv = CAM_BAD_PERMISSIONS; rv = CAM_BAD_PERMISSIONS;
syslog_debug("[facilities] [ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_EMERGENCY].container); log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_EMERGENCY].container);
return rv; return rv;
} }
if (cam->cam.camParameters.specialVehicleContainer->choice.emergencyContainer.emergencyPriority && if (cam->cam.camParameters.specialVehicleContainer->choice.emergencyContainer.emergencyPriority &&
@ -545,14 +544,14 @@ enum CAM_CHECK_R check_cam(BTPPacketIndication_t *bpi, CAM_t* cam, uint8_t* ssp,
if (bm & 0x02) { if (bm & 0x02) {
if (!permissions_check(CID_REQUEST_FOR_RIGHT_OF_WAY, ssp, ssp_len)) { if (!permissions_check(CID_REQUEST_FOR_RIGHT_OF_WAY, ssp, ssp_len)) {
rv = CAM_BAD_PERMISSIONS; rv = CAM_BAD_PERMISSIONS;
syslog_debug("[facilities] [ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_REQUEST_FOR_RIGHT_OF_WAY].container); log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_REQUEST_FOR_RIGHT_OF_WAY].container);
return rv; return rv;
} }
} }
if (bm & 0x01) { if (bm & 0x01) {
if (!permissions_check(CID_REQUEST_FOR_FREE_CROSSING_AT_A_TRAFFIC_LIGHT, ssp, ssp_len)) { if (!permissions_check(CID_REQUEST_FOR_FREE_CROSSING_AT_A_TRAFFIC_LIGHT, ssp, ssp_len)) {
rv = CAM_BAD_PERMISSIONS; rv = CAM_BAD_PERMISSIONS;
syslog_debug("[facilities] [ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_REQUEST_FOR_FREE_CROSSING_AT_A_TRAFFIC_LIGHT].container); log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_REQUEST_FOR_FREE_CROSSING_AT_A_TRAFFIC_LIGHT].container);
return rv; return rv;
} }
} }
@ -561,7 +560,7 @@ enum CAM_CHECK_R check_cam(BTPPacketIndication_t *bpi, CAM_t* cam, uint8_t* ssp,
case SpecialVehicleContainer_PR_safetyCarContainer: case SpecialVehicleContainer_PR_safetyCarContainer:
if (!permissions_check(CID_SAFETY_CAR, ssp, ssp_len)) { if (!permissions_check(CID_SAFETY_CAR, ssp, ssp_len)) {
rv = CAM_BAD_PERMISSIONS; rv = CAM_BAD_PERMISSIONS;
syslog_debug("[facilities] [ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_SAFETY_CAR].container); log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_SAFETY_CAR].container);
return rv; return rv;
} }
if (cam->cam.camParameters.specialVehicleContainer->choice.safetyCarContainer.trafficRule) { if (cam->cam.camParameters.specialVehicleContainer->choice.safetyCarContainer.trafficRule) {
@ -569,14 +568,14 @@ enum CAM_CHECK_R check_cam(BTPPacketIndication_t *bpi, CAM_t* cam, uint8_t* ssp,
case TrafficRule_noPassing: case TrafficRule_noPassing:
if (!permissions_check(CID_NO_PASSING, ssp, ssp_len)) { if (!permissions_check(CID_NO_PASSING, ssp, ssp_len)) {
rv = CAM_BAD_PERMISSIONS; rv = CAM_BAD_PERMISSIONS;
syslog_debug("[facilities] [ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_NO_PASSING].container); log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_NO_PASSING].container);
return rv; return rv;
} }
break; break;
case TrafficRule_noPassingForTrucks: case TrafficRule_noPassingForTrucks:
if (!permissions_check(CID_NO_PASSING_FOR_TRUCKS, ssp, ssp_len)) { if (!permissions_check(CID_NO_PASSING_FOR_TRUCKS, ssp, ssp_len)) {
rv = CAM_BAD_PERMISSIONS; rv = CAM_BAD_PERMISSIONS;
syslog_debug("[facilities] [ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_NO_PASSING_FOR_TRUCKS].container); log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_NO_PASSING_FOR_TRUCKS].container);
return rv; return rv;
} }
break; break;
@ -588,7 +587,7 @@ enum CAM_CHECK_R check_cam(BTPPacketIndication_t *bpi, CAM_t* cam, uint8_t* ssp,
if (cam->cam.camParameters.specialVehicleContainer->choice.safetyCarContainer.speedLimit) { if (cam->cam.camParameters.specialVehicleContainer->choice.safetyCarContainer.speedLimit) {
if (!permissions_check(CID_SPEED_LIMIT, ssp, ssp_len)) { if (!permissions_check(CID_SPEED_LIMIT, ssp, ssp_len)) {
rv = CAM_BAD_PERMISSIONS; rv = CAM_BAD_PERMISSIONS;
syslog_debug("[facilities] [ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_SPEED_LIMIT].container); log_debug("[ca] received cam does not have permissions for '%s'", CID_SSP_BM_MAP[CID_SPEED_LIMIT].container);
return rv; return rv;
} }
} }
@ -663,15 +662,12 @@ enum CAM_CHECK_R check_cam(BTPPacketIndication_t *bpi, CAM_t* cam, uint8_t* ssp,
} }
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_ManagementRequest, NULL, mreq, b_oer, 512); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_ManagementRequest, NULL, mreq, b_oer, 512);
void* management_socket = zmq_socket(facilities.zmq.ctx, ZMQ_REQ); void* management_socket = itss_0connect(facilities.zmq.management_address, ZMQ_REQ);
int wait_ms = 1000; itss_0send(management_socket, b_oer, enc.encoded);
zmq_setsockopt(management_socket, ZMQ_RCVTIMEO, &wait_ms, sizeof(int)); log_debug("[ca]-> sending MReq.attributes.set.protectedZones to ->[management]");
zmq_connect(management_socket, facilities.zmq.management_address);
zmq_send(management_socket, b_oer, enc.encoded, 0);
syslog_debug("[facilities] [ca]-> sending MReq.attributes.set.protectedZones to ->[management]");
uint8_t code; uint8_t code;
zmq_recv(management_socket, &code, 1, 0); itss_0recv_rt(&management_socket, &code, 1, b_oer, enc.encoded, 1000);
zmq_close(management_socket); itss_0close(management_socket);
} }
} }
} }
@ -764,7 +760,7 @@ void *ca_service() {
// Check if inside PZ // Check if inside PZ
bpr->gn.communicationProfile = 0; bpr->gn.communicationProfile = 0;
if (facilities.station_type != 15 && check_pz(facilities.lightship)) bpr->gn.communicationProfile = 1; if (facilities.station_type != 15 && check_pz()) bpr->gn.communicationProfile = 1;
uint32_t id = itss_id(bpr->data.buf, bpr->data.size); uint32_t id = itss_id(bpr->data.buf, bpr->data.size);
bpr->id = id; bpr->id = id;
@ -772,13 +768,13 @@ void *ca_service() {
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, tr_oer+1, 1023); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, tr_oer+1, 1023);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] encoding TR for cam failed"); log_error("encoding TR for cam failed");
continue; continue;
} }
asn_enc_rval_t enc_fdi = oer_encode_to_buffer(&asn_DEF_FacilitiesIndication, NULL, fi, fi_oer+1, 1023); asn_enc_rval_t enc_fdi = oer_encode_to_buffer(&asn_DEF_FacilitiesIndication, NULL, fi, fi_oer+1, 1023);
if(enc_fdi.encoded == -1){ if(enc_fdi.encoded == -1){
syslog_err("[facilities] encoding FI for cam failed"); log_error("encoding FI for cam failed");
continue; continue;
} }

View File

@ -13,6 +13,8 @@
#include <tpm/TollingPaymentInfo.h> #include <tpm/TollingPaymentInfo.h>
#include <zmq.h> #include <zmq.h>
#include <it2s-tender/packet.h>
#include <itss-management/ManagementRequest.h> #include <itss-management/ManagementRequest.h>
#include <itss-management/ManagementReply.h> #include <itss-management/ManagementReply.h>
#include <itss-security/SecurityRequest.h> #include <itss-security/SecurityRequest.h>
@ -47,13 +49,35 @@ static int fetch_target_address(char** addresses, uint16_t addresses_len) {
int facilities_config() { int facilities_config() {
int rv = 0; int rv = 0;
it2s_config_t* config = calloc(1, sizeof(it2s_config_t)); it2s_config_t* config = calloc(1, sizeof(it2s_config_t));
rv = it2s_config_read("/etc/it2s/itss.toml", config); rv = it2s_config_read("/etc/it2s/itss.toml", config);
if (rv) goto cleanup; if (rv) {
log_error("[config] read config failed");
goto cleanup;
}
facilities.zmq.responders = calloc(config->facilities.zmq.addresses_len, sizeof(zmq_pollitem_t)); // Logging - status messages
facilities.zmq.n_responders = 0; bool use_syslog = false, use_std = false, use_file = false;
for (int i = 0; i < config->general.logging.status_len; ++i) {
if (!strcmp(config->general.logging.status[i], "syslog")) {
use_syslog = true;
} else if (!strcmp(config->general.logging.status[i], "std")) {
use_std = true;
} else if (!strcmp(config->general.logging.status[i], "file")) {
use_file = true;
}
}
log_init(use_syslog, use_std, use_file, "facilities", NULL);
itss_0init(&facilities.exit);
facilities.zmq.responders = calloc(config->facilities.zmq.addresses_len + 1, sizeof(zmq_pollitem_t));
facilities.zmq.n_responders = 1;
// Internal socket
void* socket = itss_0bind(ZMQ_INTERNAL_ADDR, ZMQ_PAIR);
facilities.zmq.responders[0].socket = socket;
facilities.zmq.responders[0].events = ZMQ_POLLIN;
for (int i = 0; i < config->facilities.zmq.addresses_len; ++i) { for (int i = 0; i < config->facilities.zmq.addresses_len; ++i) {
char* addr = config->facilities.zmq.addresses[i]; char* addr = config->facilities.zmq.addresses[i];
@ -77,8 +101,7 @@ int facilities_config() {
} }
// Bind // Bind
void* socket = zmq_socket(facilities.zmq.ctx, ZMQ_REP); void* socket = itss_0bind(addr, ZMQ_REP);
zmq_bind(socket, addr);
facilities.zmq.responders[facilities.zmq.n_responders].socket = socket; facilities.zmq.responders[facilities.zmq.n_responders].socket = socket;
facilities.zmq.responders[facilities.zmq.n_responders].events = ZMQ_POLLIN; facilities.zmq.responders[facilities.zmq.n_responders].events = ZMQ_POLLIN;
@ -96,8 +119,7 @@ int facilities_config() {
if (found_astk) { if (found_astk) {
// Bind // Bind
void* socket = zmq_socket(facilities.zmq.ctx, ZMQ_REP); void* socket = itss_0bind(addr, ZMQ_REP);
zmq_bind(socket, addr);
facilities.zmq.responders[facilities.zmq.n_responders].socket = socket; facilities.zmq.responders[facilities.zmq.n_responders].socket = socket;
facilities.zmq.responders[facilities.zmq.n_responders].events = ZMQ_POLLIN; facilities.zmq.responders[facilities.zmq.n_responders].events = ZMQ_POLLIN;
@ -106,7 +128,7 @@ int facilities_config() {
} }
} }
if (!facilities.zmq.n_responders) { if (!facilities.zmq.n_responders) {
syslog_info("[facilities] [config] a valid address to listen to was not found, exiting now"); log_info("[config] a valid address to listen to was not found, exiting now");
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -117,7 +139,7 @@ int facilities_config() {
facilities.zmq.transport_address = malloc(strlen(config->transport.zmq.addresses[index])+1); facilities.zmq.transport_address = malloc(strlen(config->transport.zmq.addresses[index])+1);
strcpy(facilities.zmq.transport_address, config->transport.zmq.addresses[index]); strcpy(facilities.zmq.transport_address, config->transport.zmq.addresses[index]);
} else { } else {
syslog_err("[facilities] [config] a valid address for [transport] was not found"); log_error("[config] a valid address for [transport] was not found");
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -128,7 +150,7 @@ int facilities_config() {
facilities.zmq.applications_address = malloc(strlen(config->applications.zmq.addresses[index])+1); facilities.zmq.applications_address = malloc(strlen(config->applications.zmq.addresses[index])+1);
strcpy(facilities.zmq.applications_address, config->applications.zmq.addresses[index]); strcpy(facilities.zmq.applications_address, config->applications.zmq.addresses[index]);
} else { } else {
syslog_err("[facilities] [config] a valid address for [applications] was not found"); log_error("[config] a valid address for [applications] was not found");
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -139,7 +161,7 @@ int facilities_config() {
facilities.zmq.security_address = malloc(strlen(config->security.zmq.addresses[index])+1); facilities.zmq.security_address = malloc(strlen(config->security.zmq.addresses[index])+1);
strcpy(facilities.zmq.security_address, config->security.zmq.addresses[index]); strcpy(facilities.zmq.security_address, config->security.zmq.addresses[index]);
} else { } else {
syslog_err("[facilities] [config] a valid address for [security] was not found"); log_error("[config] a valid address for [security] was not found");
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -150,7 +172,7 @@ int facilities_config() {
facilities.zmq.management_address = malloc(strlen(config->management.zmq.addresses[index])+1); facilities.zmq.management_address = malloc(strlen(config->management.zmq.addresses[index])+1);
strcpy(facilities.zmq.management_address, config->management.zmq.addresses[index]); strcpy(facilities.zmq.management_address, config->management.zmq.addresses[index]);
} else { } else {
syslog_err("[facilities] [config] a valid address for [management] was not found"); log_error("[config] a valid address for [management] was not found");
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -188,7 +210,7 @@ int facilities_config() {
} else if (!strcmp("roadSideUnit", config->general.itss_type)) { } else if (!strcmp("roadSideUnit", config->general.itss_type)) {
facilities.station_type = 15; facilities.station_type = 15;
} else { } else {
syslog_err("[facilities] [config] unrecognized ITS-S type, running as OBU"); log_error("[config] unrecognized ITS-S type, running as OBU");
facilities.station_type = 5; facilities.station_type = 5;
} }
@ -214,16 +236,19 @@ int facilities_config() {
sREQ->choice.ids.list.array[1] = calloc(1, sizeof(SecurityIdType_t)); sREQ->choice.ids.list.array[1] = calloc(1, sizeof(SecurityIdType_t));
*sREQ->choice.ids.list.array[1] = SecurityIdType_ipv6Address; *sREQ->choice.ids.list.array[1] = SecurityIdType_ipv6Address;
uint8_t b_sdu[256]; uint8_t b_tx[256], b_rx[256];
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sREQ, b_sdu, 256); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sREQ, b_tx, 256);
void* ss = zmq_socket(facilities.zmq.ctx, ZMQ_REQ); void* ss = itss_0connect(facilities.zmq.security_address, ZMQ_REQ);
zmq_connect(ss, facilities.zmq.security_address); itss_0send(ss, b_tx, enc.encoded);
zmq_send(ss, b_sdu, enc.encoded, 0); int rl = itss_0recv_rt(&ss, b_rx, 256, b_tx, 256, -1);
zmq_recv(ss, b_sdu, 256, 0); itss_0close(ss);
zmq_close(ss); if (rl == -1) {
rv = 1;
goto cleanup;
}
asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &sREP, b_sdu, 256); asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &sREP, b_rx, 256);
if (sREP->returnCode == SecurityReplyReturnCode_rejected) { if (sREP->returnCode == SecurityReplyReturnCode_rejected) {
// TODO handle it // TODO handle it
@ -315,7 +340,7 @@ int facilities_config() {
} else if (!strcmp("tls-shs", config->facilities.tpm.protocol)) { } else if (!strcmp("tls-shs", config->facilities.tpm.protocol)) {
facilities.tolling.protocol.p = TOLLING_PROTOCOL_TLS_SHS; facilities.tolling.protocol.p = TOLLING_PROTOCOL_TLS_SHS;
} else { } else {
syslog_err("[facilities] [config] unrecognized tolling protocol, defaulting to 'simple'"); log_error("[config] unrecognized tolling protocol, defaulting to 'simple'");
facilities.tolling.protocol.p = TOLLING_PROTOCOL_SIMPLE; facilities.tolling.protocol.p = TOLLING_PROTOCOL_SIMPLE;
} }
facilities.tolling.station.obu.client_id = config->facilities.tpm.client_id; facilities.tolling.station.obu.client_id = config->facilities.tpm.client_id;
@ -363,9 +388,9 @@ int facilities_config() {
facilities.lightship.protected_zones.pz[i] = zone; facilities.lightship.protected_zones.pz[i] = zone;
++facilities.lightship.protected_zones.pz_len; ++facilities.lightship.protected_zones.pz_len;
++i; ++i;
syslog_debug("[facilities] [config] loaded protection zone @ (%lld, %lld)", zone->protectedZoneLatitude, zone->protectedZoneLongitude); log_debug("[config] loaded protection zone @ (%lld, %lld)", zone->protectedZoneLatitude, zone->protectedZoneLongitude);
} else { } else {
syslog_err("[facilities] [config] failure to decode protection zone '%s'", dir->d_name); log_error("[config] failure to decode protection zone '%s'", dir->d_name);
ASN_STRUCT_FREE(asn_DEF_ProtectedCommunicationZone, zone); ASN_STRUCT_FREE(asn_DEF_ProtectedCommunicationZone, zone);
} }
@ -410,12 +435,12 @@ int facilities_config() {
facilities.tolling.infos.z[i]->asn = ti; facilities.tolling.infos.z[i]->asn = ti;
++facilities.tolling.infos.length; ++facilities.tolling.infos.length;
++i; ++i;
syslog_debug("[facilities] [config] loaded tolling info | id:%lld type:%s", log_debug("[config] loaded tolling info | id:%lld type:%s",
ti->id, ti->id,
ti->tollType==TollType_entry ? "entry": ti->tollType==TollType_exit ? "exit": "single" ti->tollType==TollType_entry ? "entry": ti->tollType==TollType_exit ? "exit": "single"
); );
} else { } else {
syslog_err("[facilities] [config] failure to decode tolling info '%s'", dir->d_name); log_error("[config] failure to decode tolling info '%s'", dir->d_name);
ASN_STRUCT_FREE(asn_DEF_TollingPaymentInfo, ti); ASN_STRUCT_FREE(asn_DEF_TollingPaymentInfo, ti);
} }
@ -438,16 +463,20 @@ int facilities_config() {
mreq->choice.attributes.choice.get.clock = 1; mreq->choice.attributes.choice.get.clock = 1;
mreq->choice.attributes.choice.get.clockOffset = 1; mreq->choice.attributes.choice.get.clockOffset = 1;
mreq->choice.attributes.choice.get.trajectory = config->facilities.dcm.activate; mreq->choice.attributes.choice.get.trajectory = config->facilities.dcm.activate;
void* management_socket = zmq_socket(facilities.zmq.ctx, ZMQ_REQ); void* management_socket = itss_0connect(facilities.zmq.management_address, ZMQ_REQ);
zmq_connect(management_socket, facilities.zmq.management_address); uint8_t b_tx[256], b_rx[256];
uint8_t buffer[256]; asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_ManagementRequest, NULL, mreq, b_tx, 256);
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_ManagementRequest, NULL, mreq, buffer, 256);
zmq_send(management_socket, buffer, enc.encoded, 0); itss_0send(management_socket, b_tx, enc.encoded);
zmq_recv(management_socket, buffer, 256, 0); int rl = itss_0recv_rt(&management_socket, b_rx, 256, b_tx, 256, -1);
itss_0close(management_socket);
if (rl == -1) {
rv = 1;
goto cleanup;
}
ManagementReply_t* mrep = calloc(1, sizeof(ManagementReply_t)); ManagementReply_t* mrep = calloc(1, sizeof(ManagementReply_t));
oer_decode(NULL, &asn_DEF_ManagementReply, (void**) &mrep, buffer, 256); oer_decode(NULL, &asn_DEF_ManagementReply, (void**) &mrep, b_rx, 256);
long lat, lon, alt, alt_conf; long lat, lon, alt, alt_conf;
if (mrep->returnCode == ManagementReplyReturnCode_accepted && if (mrep->returnCode == ManagementReplyReturnCode_accepted &&
mrep->data && mrep->data &&
@ -486,13 +515,12 @@ int facilities_config() {
} }
} }
} else { } else {
syslog_err("[applications] rejected MR attribute request"); log_error("rejected MR attribute request");
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
ASN_STRUCT_FREE(asn_DEF_ManagementRequest, mreq); ASN_STRUCT_FREE(asn_DEF_ManagementRequest, mreq);
ASN_STRUCT_FREE(asn_DEF_ManagementReply, mrep); ASN_STRUCT_FREE(asn_DEF_ManagementReply, mrep);
zmq_close(management_socket);
if (config->facilities.saem.activate) { if (config->facilities.saem.activate) {
facilities.bulletin.to_provide_len = 1; facilities.bulletin.to_provide_len = 1;
@ -519,7 +547,7 @@ int facilities_config() {
config->general.logging.username, config->general.logging.username,
config->general.logging.password config->general.logging.password
)) { )) {
syslog_err("[facilities] failed to initialize the database -> turning off logging"); log_error("failed to initialize the database -> turning off logging");
free(facilities.logging.dbms); free(facilities.logging.dbms);
facilities.logging.dbms = NULL; facilities.logging.dbms = NULL;
} }

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
int facilities_config(); #define ZMQ_INTERNAL_ADDR "inproc://internal"
int facilities_config();

View File

@ -49,7 +49,7 @@ int radar_ready(){
strncpy(ifr.ifr_name, facilities.dissemination.int_radar, sizeof(ifr.ifr_name)); strncpy(ifr.ifr_name, facilities.dissemination.int_radar, sizeof(ifr.ifr_name));
if(ioctl(sock, SIOCGIFFLAGS, &ifr) <0) if(ioctl(sock, SIOCGIFFLAGS, &ifr) <0)
syslog_err(" IOCTL failed, could not retrieve radar interface flags"); log_error(" IOCTL failed, could not retrieve radar interface flags");
close(sock); close(sock);
@ -66,7 +66,7 @@ bool radar_connection(char* radar_port){
s_socket.i32_socket = socket(AF_INET, SOCK_STREAM, 0); s_socket.i32_socket = socket(AF_INET, SOCK_STREAM, 0);
if(s_socket.i32_socket < 0){ if(s_socket.i32_socket < 0){
syslog_err("Initializing socket failed ..."); log_error("Initializing socket failed ...");
return false; return false;
} }
@ -77,7 +77,7 @@ bool radar_connection(char* radar_port){
s_socket.s_server.sin_port = htons(atoi(radar_port)); s_socket.s_server.sin_port = htons(atoi(radar_port));
if(bind(s_socket.i32_socket, (struct sockaddr*)&s_socket.s_server,sizeof(s_socket.s_server)) < 0){ if(bind(s_socket.i32_socket, (struct sockaddr*)&s_socket.s_server,sizeof(s_socket.s_server)) < 0){
syslog_err("Binding socket to address error ..."); log_error("Binding socket to address error ...");
return false; return false;
} }
@ -85,16 +85,16 @@ bool radar_connection(char* radar_port){
unsigned int len = sizeof(s_socket.s_client); unsigned int len = sizeof(s_socket.s_client);
if(listen(s_socket.i32_socket,1)<0){ if(listen(s_socket.i32_socket,1)<0){
syslog_err("Waiting for incoming requests failed..."); log_error("Waiting for incoming requests failed...");
return false; return false;
} }
if((s_socket.i32_client = accept(s_socket.i32_socket, (struct sockaddr*)&s_socket.s_server, &len)) < 0){ if((s_socket.i32_client = accept(s_socket.i32_socket, (struct sockaddr*)&s_socket.s_server, &len)) < 0){
syslog_err("Client disconnected..."); log_error("Client disconnected...");
return false; return false;
} }
syslog_debug("Radar connected"); log_debug("Radar connected");
} }
@ -103,7 +103,7 @@ bool radar_connection(char* radar_port){
raw_socket.raw_fd = socket(AF_PACKET, SOCK_RAW, htons(0x0800)); raw_socket.raw_fd = socket(AF_PACKET, SOCK_RAW, htons(0x0800));
if(raw_socket.raw_fd < 0){ if(raw_socket.raw_fd < 0){
syslog_err("Failed to initializing RAW socket ..."); log_error("Failed to initializing RAW socket ...");
return false; return false;
} }
@ -114,7 +114,7 @@ bool radar_connection(char* radar_port){
strncpy((char *)raw_socket.ifr.ifr_name, facilities.dissemination.int_radar, IFNAMSIZ); strncpy((char *)raw_socket.ifr.ifr_name, facilities.dissemination.int_radar, IFNAMSIZ);
if((ioctl(raw_socket.raw_fd, SIOCGIFINDEX, &raw_socket.ifr)) == -1){ if((ioctl(raw_socket.raw_fd, SIOCGIFINDEX, &raw_socket.ifr)) == -1){
syslog_err("Error getting interface index"); log_error("Error getting interface index");
return false; return false;
} }
@ -125,7 +125,7 @@ bool radar_connection(char* radar_port){
// Bind it to the interface // Bind it to the interface
if(bind(raw_socket.raw_fd, (struct sockaddr *)&raw_socket.sll, sizeof(raw_socket.sll))<0){ if(bind(raw_socket.raw_fd, (struct sockaddr *)&raw_socket.sll, sizeof(raw_socket.sll))<0){
syslog_err("Error binding RAW socket ..."); log_error("Error binding RAW socket ...");
return false; return false;
} }
@ -618,7 +618,7 @@ static int mk_cpm(uint8_t *bdr_oer, uint32_t *bdr_len, uint8_t *fdi_oer, uint32_
memset(bdr_oer, 0, 1500); memset(bdr_oer, 0, 1500);
asn_enc_rval_t retval_enc_bdr = uper_encode_to_buffer(&asn_DEF_CPM, NULL, cpm_tx, bdr_oer, 1500); asn_enc_rval_t retval_enc_bdr = uper_encode_to_buffer(&asn_DEF_CPM, NULL, cpm_tx, bdr_oer, 1500);
if (retval_enc_bdr.encoded == -1) { if (retval_enc_bdr.encoded == -1) {
syslog_err("[facilities] [cp] failed encoding CPM (%s)", retval_enc_bdr.failed_type->name); log_error("[cp] failed encoding CPM (%s)", retval_enc_bdr.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -629,7 +629,7 @@ static int mk_cpm(uint8_t *bdr_oer, uint32_t *bdr_len, uint8_t *fdi_oer, uint32_
memset(fdi_oer, 0, 1500); memset(fdi_oer, 0, 1500);
asn_enc_rval_t retval_enc_fdi = uper_encode_to_buffer(&asn_DEF_CPM, NULL, cpm_tx, fdi_oer, 1500); asn_enc_rval_t retval_enc_fdi = uper_encode_to_buffer(&asn_DEF_CPM, NULL, cpm_tx, fdi_oer, 1500);
if (retval_enc_fdi.encoded == -1) { if (retval_enc_fdi.encoded == -1) {
syslog_err("[facilities] [cp] failed encoding CPM (%s)", retval_enc_fdi.failed_type->name); log_error("[cp] failed encoding CPM (%s)", retval_enc_fdi.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -726,14 +726,14 @@ void *cp_service(){
/* Encode TransportRequest */ /* Encode TransportRequest */
asn_enc_rval_t enc_tdr = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, tr_oer+1, 2047); asn_enc_rval_t enc_tdr = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, tr_oer+1, 2047);
if(enc_tdr.encoded == -1){ if(enc_tdr.encoded == -1){
syslog_err("[facilities] encoding TR for cpm failed"); log_error("encoding TR for cpm failed");
continue; continue;
} }
/* Encode FacilitiesIndication */ /* Encode FacilitiesIndication */
asn_enc_rval_t enc_fdi = oer_encode_to_buffer(&asn_DEF_FacilitiesIndication, NULL, fi, fi_oer+1, 2047); asn_enc_rval_t enc_fdi = oer_encode_to_buffer(&asn_DEF_FacilitiesIndication, NULL, fi, fi_oer+1, 2047);
if(enc_fdi.encoded == -1){ if(enc_fdi.encoded == -1){
syslog_err("[facilities] encoding FI for cpm failed"); log_error("encoding FI for cpm failed");
continue; continue;
} }

View File

@ -46,7 +46,7 @@ static int permissions_check(int cause_code, uint8_t* permissions, uint8_t permi
*/ */
if (permissions_len < 4) { if (permissions_len < 4) {
syslog_debug("[facilities] [den] permissions length too small"); log_debug("[den] permissions length too small");
return 0; return 0;
} }
@ -316,55 +316,55 @@ enum EVENT_CHECK_R event_manage(DENM_t *denm, uint64_t* id, uint8_t* ssp, uint32
int rv = 0; int rv = 0;
switch (rv = event_check(denm, ssp, ssp_len)) { switch (rv = event_check(denm, ssp, ssp_len)) {
case EVENT_NEW: case EVENT_NEW:
syslog_debug("[facilities] [den] new event received"); log_debug("[den] new event received");
if (event_add(denm, id)) { if (event_add(denm, id)) {
syslog_debug("[facilities] [den] failed adding event, max events reached"); log_debug("[den] failed adding event, max events reached");
ASN_STRUCT_FREE(asn_DEF_DENM, denm); ASN_STRUCT_FREE(asn_DEF_DENM, denm);
rv = -1; rv = -1;
} }
break; break;
case EVENT_INVALID: case EVENT_INVALID:
syslog_debug("[facilities] [den] invalid event received, ignoring"); log_debug("[den] invalid event received, ignoring");
ASN_STRUCT_FREE(asn_DEF_DENM, denm); ASN_STRUCT_FREE(asn_DEF_DENM, denm);
break; break;
case EVENT_PASSED: case EVENT_PASSED:
syslog_debug("[facilities] [den] old event received, ignoring"); log_debug("[den] old event received, ignoring");
ASN_STRUCT_FREE(asn_DEF_DENM, denm); ASN_STRUCT_FREE(asn_DEF_DENM, denm);
break; break;
case EVENT_CANCELLATION: case EVENT_CANCELLATION:
syslog_debug("[facilities] [den] event cancellation received"); log_debug("[den] event cancellation received");
if (event_update(denm, id)) { if (event_update(denm, id)) {
syslog_debug("[facilities] [den] failed cancelling event, event not found"); log_debug("[den] failed cancelling event, event not found");
ASN_STRUCT_FREE(asn_DEF_DENM, denm); ASN_STRUCT_FREE(asn_DEF_DENM, denm);
rv = EVENT_NUMBER_EXCEEDED; rv = EVENT_NUMBER_EXCEEDED;
} }
break; break;
case EVENT_NEGATION: case EVENT_NEGATION:
syslog_debug("[facilities] [den] event negation received"); log_debug("[den] event negation received");
if (event_update(denm, id)) { if (event_update(denm, id)) {
syslog_debug("[facilities] [den] failed negating event, event not found"); log_debug("[den] failed negating event, event not found");
ASN_STRUCT_FREE(asn_DEF_DENM, denm); ASN_STRUCT_FREE(asn_DEF_DENM, denm);
rv = EVENT_NUMBER_EXCEEDED; rv = EVENT_NUMBER_EXCEEDED;
} }
break; break;
case EVENT_UPDATE: case EVENT_UPDATE:
syslog_debug("[facilities] [den] event update received"); log_debug("[den] event update received");
if (event_update(denm, id)) { if (event_update(denm, id)) {
syslog_debug("[facilities] [den] failed updating event, event not found"); log_debug("[den] failed updating event, event not found");
ASN_STRUCT_FREE(asn_DEF_DENM, denm); ASN_STRUCT_FREE(asn_DEF_DENM, denm);
rv = EVENT_NUMBER_EXCEEDED; rv = EVENT_NUMBER_EXCEEDED;
} }
break; break;
case EVENT_REPEATED: case EVENT_REPEATED:
syslog_debug("[facilities] [den] repeated event received or referenceTime doesn't allow an update, ignoring"); log_debug("[den] repeated event received or referenceTime doesn't allow an update, ignoring");
ASN_STRUCT_FREE(asn_DEF_DENM, denm); ASN_STRUCT_FREE(asn_DEF_DENM, denm);
break; break;
case EVENT_NUMBER_EXCEEDED: case EVENT_NUMBER_EXCEEDED:
syslog_debug("[facilities] [den] max events reached, ignoring"); log_debug("[den] max events reached, ignoring");
ASN_STRUCT_FREE(asn_DEF_DENM, denm); ASN_STRUCT_FREE(asn_DEF_DENM, denm);
break; break;
case EVENT_BAD_PERMISSIONS: case EVENT_BAD_PERMISSIONS:
syslog_debug("[facilities] [den] permisisons check failed for the received event, ignoring"); log_debug("[den] permisisons check failed for the received event, ignoring");
ASN_STRUCT_FREE(asn_DEF_DENM, denm); ASN_STRUCT_FREE(asn_DEF_DENM, denm);
break; break;
} }
@ -397,7 +397,7 @@ void* den_service() {
for (int i = 0; i < den->n_max_events; ++i) { for (int i = 0; i < den->n_max_events; ++i) {
if (den->events[i]->enabled) { if (den->events[i]->enabled) {
if (now >= den->events[i]->expiration_time) { // Remove event if (now >= den->events[i]->expiration_time) { // Remove event
syslog_debug("[facilities] [den] removed event %d (expiration)", i); log_debug("[den] removed event %d (expiration)", i);
den->events[i]->enabled = false; den->events[i]->enabled = false;
ASN_STRUCT_FREE(asn_DEF_DENM, den->events[i]->denm); ASN_STRUCT_FREE(asn_DEF_DENM, den->events[i]->denm);
@ -415,7 +415,7 @@ void* den_service() {
} else { } else {
switch (den->events[i]->state) { switch (den->events[i]->state) {
case EVENT_ACTIVE: case EVENT_ACTIVE:
syslog_debug("[facilities] [den] event %d expiring in %ld second(s)", i, (den->events[i]->expiration_time - now)/1000); log_debug("[den] event %d expiring in %ld second(s)", i, (den->events[i]->expiration_time - now)/1000);
break; break;
case EVENT_CANCELLED: case EVENT_CANCELLED:
break; break;
@ -427,7 +427,7 @@ void* den_service() {
} }
if (sleep4us * sleep_count > 5e6) { /* Print info every 5 seconds */ if (sleep4us * sleep_count > 5e6) { /* Print info every 5 seconds */
syslog_info("[facilities] [den] events :: [ %d active | %d cancelled | %d negated ]", den->n_active_events, den->n_cancelled_events, den->n_negated_events); log_info("[den] events :: [ %d active | %d cancelled | %d negated ]", den->n_active_events, den->n_cancelled_events, den->n_negated_events);
sleep_count = 0; sleep_count = 0;
} }

View File

@ -30,11 +30,11 @@
#include <saem/SAEM.h> #include <saem/SAEM.h>
#include <zmq.h> #include <zmq.h>
#include <syslog.h>
#include <stdbool.h> #include <stdbool.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h>
#include <it2s-tender/space.h> #include <it2s-tender/space.h>
#include <it2s-tender/time.h> #include <it2s-tender/time.h>
@ -45,8 +45,9 @@
facilities_t facilities = {0}; facilities_t facilities = {0};
static int transport_indication(void* responder, void* security_socket, uint8_t *msg, uint32_t msg_len) { static int transport_indication(void* responder, void** security_socket, uint8_t *msg, uint32_t msg_len) {
int rv = 0, code = 0; int rv = 0;
uint8_t code = 0;
bool handled_msg = false; bool handled_msg = false;
FacilitiesIndication_t *fi = NULL; FacilitiesIndication_t *fi = NULL;
SecurityRequest_t* sreq = NULL; SecurityRequest_t* sreq = NULL;
@ -60,14 +61,14 @@ static int transport_indication(void* responder, void* security_socket, uint8_t
asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_TransportIndication, (void**) &ti, msg, msg_len); asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_TransportIndication, (void**) &ti, msg, msg_len);
if (dec.code) { if (dec.code) {
syslog_err("[facilities]<- invalid TI received"); log_error("[sdu]<- invalid TI received");
rv = 1; rv = 1;
code = 1; code = 1;
zmq_send(responder, &code, 1, 0); itss_0send(responder, &code, 1);
goto cleanup; goto cleanup;
} }
zmq_send(responder, &code, 1, 0); itss_0send(responder, &code, 1);
switch (ti->present) { switch (ti->present) {
case TransportIndication_PR_packet: case TransportIndication_PR_packet:
@ -76,7 +77,7 @@ static int transport_indication(void* responder, void* security_socket, uint8_t
transport_data_indication(&ti->choice.data, security_socket); transport_data_indication(&ti->choice.data, security_socket);
goto cleanup; goto cleanup;
default: default:
syslog_debug("[facilities]<- unrecognized TI.choice received"); log_debug("[sdu]<- unrecognized TI.choice received");
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -97,7 +98,7 @@ static int transport_indication(void* responder, void* security_socket, uint8_t
switch (tpi->present) { switch (tpi->present) {
case TransportPacketIndication_PR_btp: case TransportPacketIndication_PR_btp:
id = tpi->choice.btp.id; id = tpi->choice.btp.id;
syslog_debug("[facilities]<- TI.packet.btp | id:%08x size:%dB", (uint32_t) id, msg_len); log_debug("[sdu]<- TI.packet.btp | id:%08x size:%dB", (uint32_t) id, msg_len);
// Parse message // Parse message
switch (tpi->choice.btp.destinationPort) { switch (tpi->choice.btp.destinationPort) {
case Port_cam: case Port_cam:
@ -150,7 +151,7 @@ static int transport_indication(void* responder, void* security_socket, uint8_t
break; break;
default: default:
syslog_debug("[facilities] messsage with unhandled BTP port received (%lld), ignoring", tpi->choice.btp.destinationPort); log_debug("messsage with unhandled BTP port received (%lld), ignoring", tpi->choice.btp.destinationPort);
goto cleanup; goto cleanup;
} }
@ -159,7 +160,7 @@ static int transport_indication(void* responder, void* security_socket, uint8_t
dec = uper_decode_complete(NULL, its_msg_descriptor, (void**) &its_msg, tpi->choice.btp.data.buf, tpi->choice.btp.data.size); dec = uper_decode_complete(NULL, its_msg_descriptor, (void**) &its_msg, tpi->choice.btp.data.buf, tpi->choice.btp.data.size);
if (dec.code) { if (dec.code) {
syslog_debug("[facilities]<- invalid %s received", its_msg_descriptor->name); log_debug("[sdu]<- invalid %s received", its_msg_descriptor->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -194,7 +195,7 @@ static int transport_indication(void* responder, void* security_socket, uint8_t
#ifdef DEBUG #ifdef DEBUG
uint8_t* xml_denm = malloc(32768); uint8_t* xml_denm = malloc(32768);
asn_enc_rval_t rve = xer_encode_to_buffer(xml_denm, 32768, 0x02, &asn_DEF_DENM, its_msg); asn_enc_rval_t rve = xer_encode_to_buffer(xml_denm, 32768, 0x02, &asn_DEF_DENM, its_msg);
syslog_debug("DENM XER %d: %.*s", (int)rve.encoded, (int)rve.encoded , xml_denm); log_debug("DENM XER %d: %.*s", (int)rve.encoded, (int)rve.encoded , xml_denm);
free(xml_denm); free(xml_denm);
#endif #endif
switch (event_manage(its_msg, &id, ssp, ssp_len)) { switch (event_manage(its_msg, &id, ssp, ssp_len)) {
@ -264,7 +265,7 @@ static int transport_indication(void* responder, void* security_socket, uint8_t
id = tpi->choice.tcp.id; id = tpi->choice.tcp.id;
packet = tpi->choice.tcp.data.buf; packet = tpi->choice.tcp.data.buf;
packet_len = tpi->choice.tcp.data.size; packet_len = tpi->choice.tcp.data.size;
syslog_debug("[facilities]<- TI.packet.tcp | id:%ld size:%dB", id, msg_len); log_debug("[sdu]<- TI.packet.tcp | id:%ld size:%dB", id, msg_len);
sreq = calloc(1, sizeof(SecurityRequest_t)); sreq = calloc(1, sizeof(SecurityRequest_t));
sreq->present = SecurityRequest_PR_tlsRecv; sreq->present = SecurityRequest_PR_tlsRecv;
@ -284,39 +285,39 @@ static int transport_indication(void* responder, void* security_socket, uint8_t
pthread_mutex_unlock(&facilities.tolling.lock); pthread_mutex_unlock(&facilities.tolling.lock);
sreq->choice.tlsSend.connId = id; sreq->choice.tlsSend.connId = id;
uint8_t b_sdu[2048]; uint8_t b_tx[2048], b_rx[2048];
b_sdu[0] = 4; b_tx[0] = 4;
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, b_sdu+1, 2047); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, b_tx+1, 2047);
syslog_debug("[facilities]->[security] SecurityRequest.tlsRecv (%ldB)", enc.encoded+1); log_debug("[sdu]->[security] SecurityRequest.tlsRecv (%ldB)", enc.encoded+1);
zmq_send(security_socket, b_sdu, enc.encoded+1, 0); itss_0send(*security_socket, b_tx, enc.encoded+1);
int32_t rl = zmq_recv(security_socket, b_sdu, 2048, 0); int32_t rl = itss_0recv_rt(security_socket, b_rx, 2048, b_tx, enc.encoded+1, 1000);
syslog_debug("[facilities]<-[security] SecurityReply.tlsRecv (%dB)", rl); log_debug("[sdu]<-[security] SecurityReply.tlsRecv (%dB)", rl);
if (oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, b_sdu, rl).code) { if (oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, b_rx, rl).code) {
syslog_err("[facilities] SecurityReply.tlsRecv decode failure"); log_error("SecurityReply.tlsRecv decode failure");
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
if (srep->returnCode == SecurityReplyReturnCode_rejected) { if (srep->returnCode == SecurityReplyReturnCode_rejected) {
syslog_err("[facilities] SecurityReply.tlsRecv rejected"); log_error("SecurityReply.tlsRecv rejected");
SecurityRequest_t* sREQ = calloc(1, sizeof(SecurityRequest_t)); SecurityRequest_t* sREQ = calloc(1, sizeof(SecurityRequest_t));
sREQ->present = SecurityRequest_PR_tlsShutdown; sREQ->present = SecurityRequest_PR_tlsShutdown;
sREQ->choice.tlsShutdown.connId = id; sREQ->choice.tlsShutdown.connId = id;
b_sdu[0] = 4; b_tx[0] = 4;
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sREQ, b_sdu+1, 2047); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sREQ, b_tx+1, 2047);
syslog_debug("[facilities]->[security] SecurityRequest.tlsShutdown (%ldB)", enc.encoded+1); log_debug("[sdu]->[security] SecurityRequest.tlsShutdown (%ldB)", enc.encoded+1);
zmq_send(security_socket, b_sdu, enc.encoded+1, 0); itss_0send(*security_socket, b_tx, enc.encoded+1);
int32_t rl = zmq_recv(security_socket, b_sdu, 2048, 0); int32_t rl = itss_0recv_rt(security_socket, b_rx, 2048, b_tx, enc.encoded+1, 1000);
syslog_debug("[facilities]<-[security] SecurityReply.tlsShutdown (%dB)", rl); log_debug("[sdu]<-[security] SecurityReply.tlsShutdown (%dB)", rl);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
syslog_debug("[facilities] [tolling] tls n-msg:%d state:%d", tlsc->nmsg, tlsc->state); log_debug("[tolling] tls n-msg:%d state:%d", tlsc->nmsg, tlsc->state);
// Forward to [transport] // Forward to [transport]
if (srep->data->choice.tlsRecv.state != 1) { if (srep->data->choice.tlsRecv.state != 1) {
@ -351,7 +352,7 @@ static int transport_indication(void* responder, void* security_socket, uint8_t
buf[0] = 4; buf[0] = 4;
enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, buf_len-1); enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, buf_len-1);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("TransportRequest encoding fail"); log_error("TransportRequest encoding fail");
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -362,7 +363,7 @@ static int transport_indication(void* responder, void* security_socket, uint8_t
if (facilities.tolling.enabled && srep->data->choice.tlsRecv.data.size) { if (facilities.tolling.enabled && srep->data->choice.tlsRecv.data.size) {
dec = uper_decode_complete(NULL, &asn_DEF_TPM, (void**) &its_msg, srep->data->choice.tlsRecv.data.buf, srep->data->choice.tlsRecv.data.size); dec = uper_decode_complete(NULL, &asn_DEF_TPM, (void**) &its_msg, srep->data->choice.tlsRecv.data.buf, srep->data->choice.tlsRecv.data.size);
if (dec.code) { if (dec.code) {
syslog_debug("[facilities]<- invalid TPM received"); log_debug("[sdu]<- invalid TPM received");
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -393,7 +394,7 @@ static int transport_indication(void* responder, void* security_socket, uint8_t
break; break;
case TransportPacketIndication_PR_udp: case TransportPacketIndication_PR_udp:
id = tpi->choice.udp.id; id = tpi->choice.udp.id;
syslog_debug("[facilities]<- TI.packet.udp | id:%ld size:%dB", id, msg_len); log_debug("[sdu]<- TI.packet.udp | id:%ld size:%dB", id, msg_len);
break; break;
default: default:
@ -463,7 +464,7 @@ static int facilities_request(void* responder, uint8_t *msg, uint32_t msg_len) {
asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_FacilitiesRequest, (void**) &fr, msg, msg_len); asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_FacilitiesRequest, (void**) &fr, msg, msg_len);
if (dec.code) { if (dec.code) {
syslog_err("[facilities]<- invalid FR received"); log_error("[sdu]<- invalid FR received");
facilities_request_result_rejected(responder); facilities_request_result_rejected(responder);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
@ -493,7 +494,7 @@ static int facilities_request(void* responder, uint8_t *msg, uint32_t msg_len) {
break; break;
default: default:
syslog_err("[facilities] unrecognized FDR type received (%d)", fr->choice.data.present); log_error("[sdu]<- unrecognized FDR type received (%d)", fr->choice.data.present);
facilities_request_result_rejected(responder); facilities_request_result_rejected(responder);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
@ -501,7 +502,7 @@ static int facilities_request(void* responder, uint8_t *msg, uint32_t msg_len) {
break; break;
default: default:
syslog_err("[facilities] unrecognized FR type received (%d)", fr->present); log_error("[sdu]<- unrecognized FR type received (%d)", fr->present);
facilities_request_result_rejected(responder); facilities_request_result_rejected(responder);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
@ -526,7 +527,7 @@ static int security_indication(void* responder_secured, uint8_t *msg, uint32_t m
asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_SecurityIndication, (void**) &si, msg, msg_len); asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_SecurityIndication, (void**) &si, msg, msg_len);
if (dec.code) { if (dec.code) {
syslog_err("[facilities]<- invalid SIndication received"); log_error("[sdu]<- invalid SIndication received");
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -534,7 +535,7 @@ static int security_indication(void* responder_secured, uint8_t *msg, uint32_t m
pthread_mutex_lock(&facilities.id.change.lock); pthread_mutex_lock(&facilities.id.change.lock);
if (facilities.id.change.stage == ID_CHANGE_BLOCKED) { if (facilities.id.change.stage == ID_CHANGE_BLOCKED) {
pthread_mutex_unlock(&facilities.id.change.lock); pthread_mutex_unlock(&facilities.id.change.lock);
syslog_debug("[facilities] identity change is currently blocked"); log_debug("identity change is currently blocked");
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -543,7 +544,7 @@ static int security_indication(void* responder_secured, uint8_t *msg, uint32_t m
si->choice.idChangeEvent.command != SecurityIdChangeEventType_commit && si->choice.idChangeEvent.command != SecurityIdChangeEventType_commit &&
si->choice.idChangeEvent.command != SecurityIdChangeEventType_abort) { si->choice.idChangeEvent.command != SecurityIdChangeEventType_abort) {
pthread_mutex_unlock(&facilities.id.change.lock); pthread_mutex_unlock(&facilities.id.change.lock);
syslog_debug("[facilities] current identity change state is prepare, but received identity change command is not commit nor abort"); log_debug("current identity change state is prepare, but received identity change command is not commit nor abort");
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -607,7 +608,7 @@ static int security_indication(void* responder_secured, uint8_t *msg, uint32_t m
default: default:
pthread_mutex_unlock(&facilities.id.change.lock); pthread_mutex_unlock(&facilities.id.change.lock);
syslog_err("[networking]<- unhandled idChangeEvent command type"); log_error("[networking]<- unhandled idChangeEvent command type");
rv = 1; rv = 1;
goto cleanup; goto cleanup;
@ -616,7 +617,7 @@ static int security_indication(void* responder_secured, uint8_t *msg, uint32_t m
sr->present = SecurityResponse_PR_idChangeEvent; sr->present = SecurityResponse_PR_idChangeEvent;
sr->choice.idChangeEvent.returnCode = 0; sr->choice.idChangeEvent.returnCode = 0;
enc = oer_encode_to_buffer(&asn_DEF_SecurityResponse, NULL, sr, buffer, 64); enc = oer_encode_to_buffer(&asn_DEF_SecurityResponse, NULL, sr, buffer, 64);
zmq_send(responder_secured, buffer, enc.encoded, 0); itss_0send(responder_secured, buffer, enc.encoded);
pthread_mutex_unlock(&facilities.id.change.lock); pthread_mutex_unlock(&facilities.id.change.lock);
@ -625,7 +626,7 @@ cleanup:
sr->present = SecurityResponse_PR_idChangeEvent; sr->present = SecurityResponse_PR_idChangeEvent;
sr->choice.idChangeEvent.returnCode = 1; sr->choice.idChangeEvent.returnCode = 1;
enc = oer_encode_to_buffer(&asn_DEF_SecurityResponse, NULL, sr, buffer, 64); enc = oer_encode_to_buffer(&asn_DEF_SecurityResponse, NULL, sr, buffer, 64);
zmq_send(responder_secured, buffer, enc.encoded, 0); itss_0send(responder_secured, buffer, enc.encoded);
} }
pthread_mutex_unlock(&facilities.id.change.lock); pthread_mutex_unlock(&facilities.id.change.lock);
@ -646,10 +647,10 @@ static int networking_indication(void* responder, uint8_t* msg, uint32_t msg_len
if (dec.code) { if (dec.code) {
rv = 1; rv = 1;
code = 1; code = 1;
zmq_send(responder, &code, 1, 0); itss_0send(responder, &code, 1);
goto cleanup; goto cleanup;
} }
zmq_send(responder, &code, 1, 0); itss_0send(responder, &code, 1);
if (ni->present != NetworkingIndication_PR_data) { if (ni->present != NetworkingIndication_PR_data) {
goto cleanup; goto cleanup;
@ -683,10 +684,10 @@ static int management_indication(void* responder, uint8_t* msg, uint32_t msg_len
if (dec.code) { if (dec.code) {
rv = 1; rv = 1;
code = 1; code = 1;
zmq_send(responder, &code, 1, 0); itss_0send(responder, &code, 1);
goto cleanup; goto cleanup;
} }
zmq_send(responder, &code, 1, 0); itss_0send(responder, &code, 1);
if (mi->present == ManagementIndication_PR_attributes) { if (mi->present == ManagementIndication_PR_attributes) {
itss_space_lock(); itss_space_lock();
@ -731,25 +732,15 @@ void* tx() {
itss_queue_t* queue = facilities.tx_queue; itss_queue_t* queue = facilities.tx_queue;
uint8_t code; uint8_t code;
int wait_ms = 1000; void* applications_socket = itss_0connect(facilities.zmq.applications_address, ZMQ_REQ);
void* transport_socket = itss_0connect(facilities.zmq.transport_address, ZMQ_REQ);
void* applications_socket = zmq_socket(facilities.zmq.ctx, ZMQ_REQ); void* management_socket = itss_0connect(facilities.zmq.management_address, ZMQ_REQ);
zmq_setsockopt(applications_socket, ZMQ_RCVTIMEO, &wait_ms, sizeof(int));
zmq_connect(applications_socket, facilities.zmq.applications_address);
void* transport_socket = zmq_socket(facilities.zmq.ctx, ZMQ_REQ);
zmq_setsockopt(transport_socket, ZMQ_RCVTIMEO, &wait_ms, sizeof(int));
zmq_connect(transport_socket, facilities.zmq.transport_address);
void* management_socket = zmq_socket(facilities.zmq.ctx, ZMQ_REQ);
zmq_setsockopt(management_socket, ZMQ_RCVTIMEO, &wait_ms, sizeof(int));
zmq_connect(management_socket, facilities.zmq.management_address);
itss_queue_t* stream = itss_queue_new(); itss_queue_t* stream = itss_queue_new();
while (!facilities.exit) { while (!facilities.exit) {
pthread_mutex_lock(&queue->lock); pthread_mutex_lock(&queue->lock);
while (!queue->len) { while (!queue->len && !facilities.exit) {
pthread_cond_wait(&queue->trigger, &queue->lock); pthread_cond_wait(&queue->trigger, &queue->lock);
} }
for (int i = 0; i < queue->len; ++i) { for (int i = 0; i < queue->len; ++i) {
@ -767,30 +758,30 @@ void* tx() {
for (int i = 0; i < stream->len; ++i) { for (int i = 0; i < stream->len; ++i) {
switch (stream->destination[i]) { switch (stream->destination[i]) {
case ITSS_TRANSPORT: case ITSS_TRANSPORT:
syslog_debug("[facilities]-> %s ->[transport] | id:%08x size:%dB", log_debug("[sdu]-> %s ->[transport] | id:%08x size:%dB",
stream->info_msg[i], (uint32_t) stream->id[i], stream->packet_len[i]); 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); itss_0send(transport_socket, stream->packet[i], stream->packet_len[i]);
rv = zmq_recv(transport_socket, &code, 1, 0); rv = itss_0recv_rt(&transport_socket, &code, 1, stream->packet[i], stream->packet_len[i], 1000);
if (rv == -1) { if (rv == -1) {
syslog_err("[facilities]-> %s ->[transport] | id:%08x size:%dB <TIMEOUT>", log_error("[sdu]-> %s ->[transport] | id:%08x size:%dB <TIMEOUT>",
stream->info_msg[i], (uint32_t) stream->id[i], stream->packet_len[i]); stream->info_msg[i], (uint32_t) stream->id[i], stream->packet_len[i]);
} }
break; break;
case ITSS_APPLICATIONS: case ITSS_APPLICATIONS:
syslog_debug("[facilities]-> %s ->[applications] | id:%08x size:%dB", log_debug("[sdu]-> %s ->[applications] | id:%08x size:%dB",
stream->info_msg[i], (uint32_t) stream->id[i], stream->packet_len[i]); 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); itss_0send(applications_socket, stream->packet[i], stream->packet_len[i]);
rv = zmq_recv(applications_socket, &code, 1, 0); rv = itss_0recv_rt(&applications_socket, &code, 1, stream->packet[i], stream->packet_len[i], 1000);
if (rv == -1) { if (rv == -1) {
syslog_err("[facilities]-> %s ->[applications] | id:%08x size:%dB <TIMEOUT>", log_error("[sdu]-> %s ->[applications] | id:%08x size:%dB <TIMEOUT>",
stream->info_msg[i], (uint32_t) stream->id[i], stream->packet_len[i]); stream->info_msg[i], (uint32_t) stream->id[i], stream->packet_len[i]);
} }
break; break;
case ITSS_MANAGEMENT: case ITSS_MANAGEMENT:
zmq_send(management_socket, stream->packet[i], stream->packet_len[i], 0); itss_0send(management_socket, stream->packet[i], stream->packet_len[i]);
rv = zmq_recv(management_socket, &code, 1, 0); rv = itss_0recv_rt(&management_socket, &code, 1, stream->packet[i], stream->packet_len[i], 1000);
if (rv == -1) { if (rv == -1) {
syslog_err("[facilities]-> %s ->[management] | id:%08x size:%dB <TIMEOUT>", log_error("[sdu]-> %s ->[management] | id:%08x size:%dB <TIMEOUT>",
stream->info_msg[i], (uint32_t) stream->id[i], stream->packet_len[i]); stream->info_msg[i], (uint32_t) stream->id[i], stream->packet_len[i]);
} }
break; break;
@ -798,15 +789,27 @@ void* tx() {
} }
} }
itss_0close(transport_socket);
itss_0close(management_socket);
itss_0close(applications_socket);
return NULL; return NULL;
} }
static void sigh(int signum) {
facilities.exit = true;
uint8_t code = 0;
void* socket = itss_0connect(ZMQ_INTERNAL_ADDR, ZMQ_PAIR);
itss_0send(socket, &code, sizeof(code));
itss_0close(socket);
}
int main() { int main() {
int rv = 0; signal(SIGTERM, sigh);
signal(SIGHUP, sigh);
signal(SIGINT, sigh);
signal(SIGKILL, sigh);
syslog_info("[facilities] starting");
facilities.zmq.ctx = zmq_ctx_new();
facilities.tx_queue = itss_queue_new(); facilities.tx_queue = itss_queue_new();
lightship_init(); lightship_init();
den_init(); den_init();
@ -814,11 +817,14 @@ int main() {
dissemination_init(); dissemination_init();
bulletin_init(); bulletin_init();
coordination_init(); coordination_init();
void* security_socket = NULL;
time_t t; time_t t;
srand((unsigned) time(&t)); srand((unsigned) time(&t));
if (facilities_config(&facilities)) return 1; if (facilities_config(&facilities)) {
goto cleanup;
}
facilities.lightship.type = facilities.station_type; facilities.lightship.type = facilities.station_type;
@ -841,32 +847,33 @@ int main() {
pthread_create(&facilities.sa_service, NULL, sa_service, NULL); pthread_create(&facilities.sa_service, NULL, sa_service, NULL);
// Tolling // Tolling
tolling_init(facilities.zmq.ctx, facilities.zmq.security_address, facilities.station_type); tolling_init(facilities.station_type);
// PC // PC
if (facilities.coordination.active) if (facilities.coordination.active)
pthread_create(&facilities.vc_service, NULL, vc_service, NULL); pthread_create(&facilities.vc_service, NULL, vc_service, NULL);
void* security_socket = zmq_socket(facilities.zmq.ctx, ZMQ_REQ); security_socket = itss_0connect(facilities.zmq.security_address, ZMQ_REQ);
int wait_ms = 1000;
zmq_setsockopt(security_socket, ZMQ_RCVTIMEO, &wait_ms, sizeof(int));
zmq_connect(security_socket, facilities.zmq.security_address);
uint8_t buffer[ITSS_SDU_MAX_LEN]; uint8_t buffer[ITSS_SDU_MAX_LEN];
syslog_info("[facilities] listening"); log_info("listening");
uint8_t code; uint8_t code;
bool in_idchange; bool in_idchange;
int32_t rl; int32_t rl;
while (!facilities.exit) { while (!facilities.exit) {
zmq_poll(facilities.zmq.responders, facilities.zmq.n_responders, -1); itss_0poll(facilities.zmq.responders, facilities.zmq.n_responders, -1);
for (int i = 0; i < facilities.zmq.n_responders; ++i) { for (int i = 0; i < facilities.zmq.n_responders; ++i) {
if (facilities.zmq.responders[i].revents) { if (facilities.zmq.responders[i].revents) {
rl = zmq_recv(facilities.zmq.responders[i].socket, buffer, ITSS_SDU_MAX_LEN, 0); rl = itss_0recv(facilities.zmq.responders[i].socket, buffer, ITSS_SDU_MAX_LEN);
switch (buffer[0]) { /* source */ switch (buffer[0]) { /* source */
case ITSS_INTERNAL:
break;
case ITSS_NETWORKING: case ITSS_NETWORKING:
networking_indication(facilities.zmq.responders[i].socket, buffer+1, rl); networking_indication(facilities.zmq.responders[i].socket, buffer+1, rl);
break; break;
@ -881,14 +888,14 @@ int main() {
pthread_mutex_unlock(&facilities.id.change.lock); pthread_mutex_unlock(&facilities.id.change.lock);
if (!in_idchange) { if (!in_idchange) {
transport_indication(facilities.zmq.responders[i].socket, security_socket, buffer+1, rl); transport_indication(facilities.zmq.responders[i].socket, &security_socket, buffer+1, rl);
pthread_mutex_lock(&facilities.id.change.lock); pthread_mutex_lock(&facilities.id.change.lock);
facilities.id.change.stage = ID_CHANGE_INACTIVE; facilities.id.change.stage = ID_CHANGE_INACTIVE;
pthread_mutex_unlock(&facilities.id.change.lock); pthread_mutex_unlock(&facilities.id.change.lock);
} else { } else {
code = 1; code = 1;
zmq_send(facilities.zmq.responders[i].socket, &code, 1, 0); itss_0send(facilities.zmq.responders[i].socket, &code, 1);
} }
break; break;
@ -909,7 +916,7 @@ int main() {
pthread_mutex_unlock(&facilities.id.change.lock); pthread_mutex_unlock(&facilities.id.change.lock);
} else { } else {
code = 1; code = 1;
zmq_send(facilities.zmq.responders[i].socket, &code, 1, 0); itss_0send(facilities.zmq.responders[i].socket, &code, 1);
} }
break; break;
@ -923,20 +930,35 @@ int main() {
break; break;
default: default:
syslog_debug("[facilities] unrecognized service"); log_debug("[sdu]<- unrecognized service");
code = 1; code = 1;
zmq_send(facilities.zmq.responders[i].socket, &code, 1, 0); itss_0send(facilities.zmq.responders[i].socket, &code, 1);
continue; continue;
} }
} }
} }
} }
pthread_join(facilities.transmitting, NULL); // Exit
cleanup:
pthread_join(facilities.ca_service, NULL); pthread_join(facilities.ca_service, NULL);
pthread_join(facilities.den_service, NULL); pthread_join(facilities.den_service, NULL);
pthread_join(facilities.infrastructure_service, NULL); pthread_join(facilities.infrastructure_service, NULL);
pthread_join(facilities.cp_service, NULL); pthread_join(facilities.cp_service, NULL);
pthread_join(facilities.sa_service, NULL);
itss_queue_trigger(facilities.tx_queue);
pthread_join(facilities.transmitting, NULL);
if (facilities.coordination.active)
pthread_join(facilities.vc_service, NULL);
itss_0close(security_socket);
for (int i = 0; i < facilities.zmq.n_responders; ++i) {
itss_0close(facilities.zmq.responders[i].socket);
}
itss_0destroy();
log_info("exiting");
log_close();
return 0; return 0;
} }

View File

@ -14,8 +14,8 @@
#include "vcm.h" #include "vcm.h"
#include <it2s-tender/epv.h> #include <it2s-tender/epv.h>
#include <it2s-tender/syslog.h>
#include <it2s-tender/database.h> #include <it2s-tender/database.h>
#include <it2s-tender/log.h>
#include <it2s-tender/constants.h> #include <it2s-tender/constants.h>
#include <it2s-tender/queue.h> #include <it2s-tender/queue.h>
@ -37,7 +37,6 @@ typedef struct facilities {
// ZMQ // ZMQ
struct { struct {
void* ctx;
zmq_pollitem_t* responders; zmq_pollitem_t* responders;
uint16_t n_responders; uint16_t n_responders;

View File

@ -1,10 +1,11 @@
#include "indications.h" #include "indications.h"
#include <camv2/asn_application.h>
#include <itss-security/SecurityRequest.h> #include <itss-security/SecurityRequest.h>
#include <itss-security/SecurityReply.h> #include <itss-security/SecurityReply.h>
static void tcp_conn_reset(TCPConnRSTInfo_t* cri, void* security_socket) { #include <it2s-tender/packet.h>
static void tcp_conn_reset(TCPConnRSTInfo_t* cri, void** security_socket) {
if (cri->destinationAddress.size != 16) return; if (cri->destinationAddress.size != 16) return;
SecurityRequest_t* sreq = NULL; SecurityRequest_t* sreq = NULL;
@ -23,15 +24,15 @@ static void tcp_conn_reset(TCPConnRSTInfo_t* cri, void* security_socket) {
sreq->present = SecurityRequest_PR_tlsReset; sreq->present = SecurityRequest_PR_tlsReset;
sreq->choice.tlsReset.connId = tolling->station.obu.tls_conn_id; sreq->choice.tlsReset.connId = tolling->station.obu.tls_conn_id;
uint8_t b_s[64]; uint8_t b_s[64], b_r[64];
b_s[0] = 4; b_s[0] = 4;
asn_enc_rval_t enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_SecurityRequest, sreq, b_s+1, 63); asn_enc_rval_t enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_SecurityRequest, sreq, b_s+1, 63);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] SecurityRequest.tlsReset encoding failed"); log_error("[facilities] SecurityRequest.tlsReset encoding failed");
} }
zmq_send(security_socket, b_s, enc.encoded+1, 0); itss_0send(*security_socket, b_s, enc.encoded+1);
zmq_recv(security_socket, b_s, 64, 0); itss_0recv_rt(security_socket, b_r, 64, b_s, 64, 1000);
// TODO handle SReply // TODO handle SReply
} }
@ -42,7 +43,7 @@ static void tcp_conn_reset(TCPConnRSTInfo_t* cri, void* security_socket) {
ASN_STRUCT_FREE(asn_DEF_SecurityRequest, sreq); ASN_STRUCT_FREE(asn_DEF_SecurityRequest, sreq);
} }
int transport_data_indication(TransportDataIndication_t* tdi, void* security_socket) { int transport_data_indication(TransportDataIndication_t* tdi, void** security_socket) {
int rv = 0; int rv = 0;
switch (tdi->present) { switch (tdi->present) {

View File

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

View File

@ -38,7 +38,7 @@ static int permissions_check(int diid, uint8_t* permissions, uint8_t permissions
*/ */
if (permissions_len < 6) { if (permissions_len < 6) {
syslog_debug("[facilities] [infrastrucutre] [ivi] permissions length too small"); log_debug("[infrastrucutre] [ivi] permissions length too small");
return 0; return 0;
} }
@ -458,55 +458,55 @@ enum SERVICE_EVAL_R service_eval(enum SERVICE_TYPE type, void* its_msg, uint64_t
switch (rv = service_check(type, its_msg, ssp, ssp_len)) { switch (rv = service_check(type, its_msg, ssp, ssp_len)) {
case SERVICE_NEW: case SERVICE_NEW:
syslog_debug("[facilities] [infrastructure] new service received"); log_debug("[infrastructure] new service received");
if (service_add(type, its_msg, id)) { if (service_add(type, its_msg, id)) {
syslog_debug("[facilities] [infrastructure] failed adding service, max services reached"); log_debug("[infrastructure] failed adding service, max services reached");
ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg); ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg);
rv = -1; rv = -1;
} }
break; break;
case SERVICE_INVALID: case SERVICE_INVALID:
syslog_debug("[facilities] [infrastructure] invalid service received, ignoring"); log_debug("[infrastructure] invalid service received, ignoring");
ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg); ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg);
break; break;
case SERVICE_PASSED: case SERVICE_PASSED:
syslog_debug("[facilities] [infrastructure] old service received, ignoring"); log_debug("[infrastructure] old service received, ignoring");
ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg); ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg);
break; break;
case SERVICE_CANCELLATION: case SERVICE_CANCELLATION:
syslog_debug("[facilities] [infrastructure] service cancellation received"); log_debug("[infrastructure] service cancellation received");
if (service_update(type, its_msg, id)) { if (service_update(type, its_msg, id)) {
syslog_debug("[facilities] [infrastructure] failed cancelling service, event not found"); log_debug("[infrastructure] failed cancelling service, event not found");
ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg); ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg);
rv = -1; rv = -1;
} }
break; break;
case SERVICE_NEGATION: case SERVICE_NEGATION:
syslog_debug("[facilities] [infrastructure] service negation received"); log_debug("[infrastructure] service negation received");
if (service_update(type, its_msg, id)) { if (service_update(type, its_msg, id)) {
syslog_debug("[facilities] [infrastructure] failed negating service, service not found"); log_debug("[infrastructure] failed negating service, service not found");
ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg); ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg);
rv = -1; rv = -1;
} }
break; break;
case SERVICE_UPDATE: case SERVICE_UPDATE:
syslog_debug("[facilities] [infrastructure] service update received"); log_debug("[infrastructure] service update received");
if (service_update(type, its_msg, id)) { if (service_update(type, its_msg, id)) {
syslog_debug("[facilities] [infrastructure] failed updating service, service not found"); log_debug("[infrastructure] failed updating service, service not found");
ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg); ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg);
rv = -1; rv = -1;
} }
break; break;
case SERVICE_REPEATED: case SERVICE_REPEATED:
syslog_debug("[facilities] [infrastructure] repeated service received or timeStamp doesn't allow an update, ignoring"); log_debug("[infrastructure] repeated service received or timeStamp doesn't allow an update, ignoring");
ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg); ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg);
break; break;
case SERVICE_NUMBER_EXCEEDED: case SERVICE_NUMBER_EXCEEDED:
syslog_debug("[facilities] [infrastructure] max services reached, ignoring"); log_debug("[infrastructure] max services reached, ignoring");
ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg); ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg);
break; break;
case SERVICE_BAD_PERMISSIONS: case SERVICE_BAD_PERMISSIONS:
syslog_debug("[facilities] [infrastructure] invalid service permissions, ignoring"); log_debug("[infrastructure] invalid service permissions, ignoring");
ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg); ASN_STRUCT_FREE(asn_DEF_IVIM, its_msg);
break; break;
} }
@ -541,7 +541,7 @@ void* infrastructure_service() {
for (int i = 0; i < infrastructure->n_max_services; ++i) { for (int i = 0; i < infrastructure->n_max_services; ++i) {
if (infrastructure->services[i]->enabled) { if (infrastructure->services[i]->enabled) {
if (now > infrastructure->services[i]->valid_to) { // Remove service if (now > infrastructure->services[i]->valid_to) { // Remove service
syslog_debug("[facilities] [infrastructure] removed service %d (expiration)", i); log_debug("[infrastructure] removed service %d (expiration)", i);
infrastructure->services[i]->enabled = false; infrastructure->services[i]->enabled = false;
ASN_STRUCT_FREE(asn_DEF_IVIM, infrastructure->services[i]->ivim); ASN_STRUCT_FREE(asn_DEF_IVIM, infrastructure->services[i]->ivim);
@ -560,9 +560,9 @@ void* infrastructure_service() {
switch (infrastructure->services[i]->state) { switch (infrastructure->services[i]->state) {
case SERVICE_ACTIVE: case SERVICE_ACTIVE:
if (now > infrastructure->services[i]->valid_from) { if (now > infrastructure->services[i]->valid_from) {
syslog_debug("[facilities] [infrastructure] service %d expiring in %ld second(s)", i, (infrastructure->services[i]->valid_to - now)/1000); log_debug("[infrastructure] service %d expiring in %ld second(s)", i, (infrastructure->services[i]->valid_to - now)/1000);
} else { } else {
syslog_debug("[facilities] [infrastructure] service %d starting in %ld seconds with a duration of %ld seconds", i, (infrastructure->services[i]->valid_from - now)/1000, (infrastructure->services[i]->valid_to - infrastructure->services[i]->valid_from)/1000); log_debug("[infrastructure] service %d starting in %ld seconds with a duration of %ld seconds", i, (infrastructure->services[i]->valid_from - now)/1000, (infrastructure->services[i]->valid_to - infrastructure->services[i]->valid_from)/1000);
++n_awaiting_services; ++n_awaiting_services;
} }
break; break;
@ -576,7 +576,7 @@ void* infrastructure_service() {
} }
if (sleep_count * sleep4us > 5e6) { /* Print info every 5 seconds */ if (sleep_count * sleep4us > 5e6) { /* Print info every 5 seconds */
syslog_info("[facilities] [infrastructure] services :: [ %d active | %d awaiting | %d cancelled | %d negated ]", infrastructure->n_active_services - n_awaiting_services, n_awaiting_services, infrastructure->n_cancelled_services, infrastructure->n_negated_services); log_info("[infrastructure] services :: [ %d active | %d awaiting | %d cancelled | %d negated ]", infrastructure->n_active_services - n_awaiting_services, n_awaiting_services, infrastructure->n_cancelled_services, infrastructure->n_negated_services);
sleep_count = 0; sleep_count = 0;
} }

View File

@ -25,7 +25,7 @@ int facilities_request_result_accepted(void* responder) {
fr->choice.message.returnCode = 0; fr->choice.message.returnCode = 0;
uint8_t fr_oer[32]; uint8_t fr_oer[32];
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesReply, NULL, fr, fr_oer, 32); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesReply, NULL, fr, fr_oer, 32);
zmq_send(responder, fr_oer, enc.encoded, 0); itss_0send(responder, fr_oer, enc.encoded);
ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, fr); ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, fr);
return rv; return rv;
@ -39,7 +39,7 @@ int facilities_request_result_rejected(void* responder) {
fr->choice.message.returnCode = 1; fr->choice.message.returnCode = 1;
uint8_t fr_oer[32]; uint8_t fr_oer[32];
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesReply, NULL, fr, fr_oer, 32); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesReply, NULL, fr, fr_oer, 32);
zmq_send(responder, fr_oer, enc.encoded, 0); itss_0send(responder, fr_oer, enc.encoded);
ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, fr); ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, fr);
return rv; return rv;
@ -99,7 +99,7 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
break; break;
default: default:
syslog_err("[facilities] unrecognized FR message type (%lld)", frm->itsMessageType); log_error("unrecognized FR message type (%lld)", frm->itsMessageType);
facilities_request_result_rejected(responder); facilities_request_result_rejected(responder);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
@ -107,7 +107,7 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
asn_dec_rval_t dec = uper_decode_complete(NULL, its_msg_def, (void**) &its_msg, frm->data.buf, frm->data.size); asn_dec_rval_t dec = uper_decode_complete(NULL, its_msg_def, (void**) &its_msg, frm->data.buf, frm->data.size);
if (dec.code) { if (dec.code) {
syslog_debug("[facilities] invalid FR %s received", its_msg_def->name); log_debug("invalid FR %s received", its_msg_def->name);
facilities_request_result_rejected(responder); facilities_request_result_rejected(responder);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
@ -269,7 +269,7 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
bpr->data.buf = malloc(2048); bpr->data.buf = malloc(2048);
asn_enc_rval_t enc = uper_encode_to_buffer(its_msg_def, NULL, its_msg, bpr->data.buf, 2048); asn_enc_rval_t enc = uper_encode_to_buffer(its_msg_def, NULL, its_msg, bpr->data.buf, 2048);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] failed encoding ITS message into UPER (%s)", enc.failed_type->name); log_error("failed encoding ITS message into UPER (%s)", enc.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -305,7 +305,7 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
tr_oer[0] = 4; // [facilities] service id tr_oer[0] = 4; // [facilities] service id
enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, tr_oer + 1, 2047); enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, tr_oer + 1, 2047);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] failed encoding TR (%s)", enc.failed_type->name); log_error("failed encoding TR (%s)", enc.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -380,7 +380,7 @@ int facilities_request_active_episodes(void* responder, FacilitiesRequest_t* fre
frep->choice.data.choice.episodes.list.array[j]->data.buf = malloc(2048); frep->choice.data.choice.episodes.list.array[j]->data.buf = malloc(2048);
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_DENM, NULL, facilities.den.events[i]->denm, frep->choice.data.choice.episodes.list.array[j]->data.buf, 2048); asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_DENM, NULL, facilities.den.events[i]->denm, frep->choice.data.choice.episodes.list.array[j]->data.buf, 2048);
if (enc.encoded == -1) { /* encoding shouldn't fail as all saved DENMs are structurally valid */ if (enc.encoded == -1) { /* encoding shouldn't fail as all saved DENMs are structurally valid */
syslog_err("[facilities] failed encoding DENM for FDResult (%s)", enc.failed_type->name); log_error("failed encoding DENM for FDResult (%s)", enc.failed_type->name);
frep->choice.data.choice.episodes.list.array[j]->data.size = 0; frep->choice.data.choice.episodes.list.array[j]->data.size = 0;
continue; continue;
} }
@ -398,7 +398,7 @@ int facilities_request_active_episodes(void* responder, FacilitiesRequest_t* fre
frep->choice.data.choice.episodes.list.array[j]->data.buf = malloc(2048); frep->choice.data.choice.episodes.list.array[j]->data.buf = malloc(2048);
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_IVIM, NULL, facilities.infrastructure.services[i]->ivim, frep->choice.data.choice.episodes.list.array[j]->data.buf, 2048); asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_IVIM, NULL, facilities.infrastructure.services[i]->ivim, frep->choice.data.choice.episodes.list.array[j]->data.buf, 2048);
if (enc.encoded == -1) { /* encoding shouldn't fail as all saved DENMs are structurally valid */ if (enc.encoded == -1) { /* encoding shouldn't fail as all saved DENMs are structurally valid */
syslog_err("[facilities] failed encoding IVIM for FDResult (%s)", enc.failed_type->name); log_error("failed encoding IVIM for FDResult (%s)", enc.failed_type->name);
frep->choice.data.choice.episodes.list.array[j]->data.size = 0; frep->choice.data.choice.episodes.list.array[j]->data.size = 0;
continue; continue;
} }
@ -409,7 +409,7 @@ int facilities_request_active_episodes(void* responder, FacilitiesRequest_t* fre
} }
break; break;
default: default:
syslog_err("[facilities] unrecognized FR event type (%lld)", *freq->choice.data.choice.activeEpisodes.list.array[e]); log_error("unrecognized FR event type (%lld)", *freq->choice.data.choice.activeEpisodes.list.array[e]);
pthread_mutex_unlock(&facilities.den.lock); pthread_mutex_unlock(&facilities.den.lock);
pthread_mutex_unlock(&facilities.infrastructure.lock); pthread_mutex_unlock(&facilities.infrastructure.lock);
@ -425,14 +425,14 @@ int facilities_request_active_episodes(void* responder, FacilitiesRequest_t* fre
frep_oer = malloc(32768); frep_oer = malloc(32768);
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesReply, NULL, frep, frep_oer, 32768); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesReply, NULL, frep, frep_oer, 32768);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] failed encoding FReply (%s)", enc.failed_type->name); log_error("failed encoding FReply (%s)", enc.failed_type->name);
facilities_request_result_rejected(responder); facilities_request_result_rejected(responder);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
zmq_send(responder, frep_oer, enc.encoded, 0); itss_0send(responder, frep_oer, enc.encoded);
cleanup: cleanup:
free(frep_oer); free(frep_oer);
@ -464,7 +464,7 @@ int facilities_request_attribute_types(void* responder, FacilitiesRequest_t* fre
break; break;
default: default:
syslog_debug("[facilities] unrecognized FR attribute type request"); log_debug("unrecognized FR attribute type request");
facilities_request_result_rejected(responder); facilities_request_result_rejected(responder);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
@ -473,13 +473,13 @@ int facilities_request_attribute_types(void* responder, FacilitiesRequest_t* fre
uint8_t frep_oer[256]; uint8_t frep_oer[256];
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesReply, NULL, frep, frep_oer, 256); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesReply, NULL, frep, frep_oer, 256);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] failed encoding FReply (%s)", enc.failed_type->name); log_error("failed encoding FReply (%s)", enc.failed_type->name);
facilities_request_result_rejected(responder); facilities_request_result_rejected(responder);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
zmq_send(responder, frep_oer, enc.encoded, 0); itss_0send(responder, frep_oer, enc.encoded);
cleanup: cleanup:
ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, frep); ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, frep);
@ -514,13 +514,13 @@ int facilities_request_loaded_protected_zones(void* responder, FacilitiesRequest
uint8_t frep_oer[1024]; uint8_t frep_oer[1024];
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesReply, NULL, frep, frep_oer, 1024); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesReply, NULL, frep, frep_oer, 1024);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] failed encoding FDResult (%s)", enc.failed_type->name); log_error("failed encoding FDResult (%s)", enc.failed_type->name);
facilities_request_result_rejected(responder); facilities_request_result_rejected(responder);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
zmq_send(responder, frep_oer, enc.encoded, 0); itss_0send(responder, frep_oer, enc.encoded);
cleanup: cleanup:
ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, frep); ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, frep);
@ -545,13 +545,13 @@ int facilities_request_chaininfo_set(void* responder, ChainInformation_t* cis) {
uint8_t frep_oer[1024]; uint8_t frep_oer[1024];
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesReply, NULL, frep, frep_oer, 1024); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesReply, NULL, frep, frep_oer, 1024);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] failed encoding FDResult (%s)", enc.failed_type->name); log_error("failed encoding FDResult (%s)", enc.failed_type->name);
facilities_request_result_rejected(responder); facilities_request_result_rejected(responder);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
zmq_send(responder, frep_oer, enc.encoded, 0); itss_0send(responder, frep_oer, enc.encoded);
cleanup: cleanup:
ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, frep); ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, frep);

View File

@ -17,6 +17,7 @@
#include <saem/per_encoder.h> #include <saem/per_encoder.h>
#include <tpm/TollingPaymentInfo.h> #include <tpm/TollingPaymentInfo.h>
#include <saem/SAEM.h> #include <saem/SAEM.h>
#include <zmq.h>
SAEM_CODE_R saem_check(SAEM_t* saem, uint8_t* neighbour) { SAEM_CODE_R saem_check(SAEM_t* saem, uint8_t* neighbour) {
@ -214,7 +215,7 @@ int mk_saem(uint8_t* b_saem, uint32_t* b_saem_len) {
enc = uper_encode_to_buffer(&asn_DEF_TollingPaymentInfo, NULL, facilities.tolling.infos.z[i]->asn, exts->list.array[2]->choice.applicationDataSAM.buf, 1024); enc = uper_encode_to_buffer(&asn_DEF_TollingPaymentInfo, NULL, facilities.tolling.infos.z[i]->asn, exts->list.array[2]->choice.applicationDataSAM.buf, 1024);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [sa] failure to encode TollingPaymentInfo (%s)", enc.failed_type->name); log_error("[sa] failure to encode TollingPaymentInfo (%s)", enc.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -252,7 +253,7 @@ int mk_saem(uint8_t* b_saem, uint32_t* b_saem_len) {
enc = uper_encode_to_buffer(&asn_DEF_TollingPaymentInfo, NULL, facilities.tolling.infos.z[i]->asn, exts->list.array[3]->choice.applicationDataSAM.buf, 1024); enc = uper_encode_to_buffer(&asn_DEF_TollingPaymentInfo, NULL, facilities.tolling.infos.z[i]->asn, exts->list.array[3]->choice.applicationDataSAM.buf, 1024);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [sa] failure to encode TollingPaymentInfo (%s)", enc.failed_type->name); log_error("[sa] failure to encode TollingPaymentInfo (%s)", enc.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -266,7 +267,7 @@ int mk_saem(uint8_t* b_saem, uint32_t* b_saem_len) {
enc = asn_encode_to_buffer(NULL, ATS_UNALIGNED_CANONICAL_PER, &asn_DEF_SAEM, saem, b_saem, *b_saem_len); enc = asn_encode_to_buffer(NULL, ATS_UNALIGNED_CANONICAL_PER, &asn_DEF_SAEM, saem, b_saem, *b_saem_len);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [sa] failure to encode SAEM (%s)", enc.failed_type->name); log_error("[sa] failure to encode SAEM (%s)", enc.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -310,8 +311,8 @@ void *sa_service() {
bpr->gn.securityProfile.sign = true; bpr->gn.securityProfile.sign = true;
void* security_socket = zmq_socket(facilities.zmq.ctx, ZMQ_REQ); int linger_ms = 0;
zmq_connect(security_socket, facilities.zmq.security_address); void* security_socket = itss_0connect(facilities.zmq.security_address, ZMQ_REQ);
uint8_t tr_oer[1024]; uint8_t tr_oer[1024];
tr_oer[0] = 4; // Facilities tr_oer[0] = 4; // Facilities
@ -331,7 +332,7 @@ void *sa_service() {
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, tr_oer+1, 1023); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, tr_oer+1, 1023);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] encoding TR for SAEM failed"); log_error("encoding TR for SAEM failed");
continue; continue;
} else { } else {
itss_queue_send(facilities.tx_queue, tr_oer, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp"); itss_queue_send(facilities.tx_queue, tr_oer, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp");
@ -392,7 +393,7 @@ void *sa_service() {
switch (facilities.tolling.protocol.p) { switch (facilities.tolling.protocol.p) {
case TOLLING_PROTOCOL_SIMPLE: case TOLLING_PROTOCOL_SIMPLE:
tpm_pay(info, security_socket, bulletin->to_consume[a]->certificate_id, NULL); tpm_pay(info, &security_socket, bulletin->to_consume[a]->certificate_id, NULL);
++bulletin->to_consume[a]->n_trigger; ++bulletin->to_consume[a]->n_trigger;
bulletin->to_consume[a]->t_trigger = now; bulletin->to_consume[a]->t_trigger = now;
break; break;
@ -400,7 +401,7 @@ void *sa_service() {
case TOLLING_PROTOCOL_TLS: case TOLLING_PROTOCOL_TLS:
case TOLLING_PROTOCOL_TLS_GN: case TOLLING_PROTOCOL_TLS_GN:
case TOLLING_PROTOCOL_TLS_SHS: case TOLLING_PROTOCOL_TLS_SHS:
tpm_pay(info, security_socket, NULL, bulletin->to_consume[a]->endpoint.ipv6_addr); tpm_pay(info, &security_socket, NULL, bulletin->to_consume[a]->endpoint.ipv6_addr);
++bulletin->to_consume[a]->n_trigger; ++bulletin->to_consume[a]->n_trigger;
bulletin->to_consume[a]->t_trigger = now; bulletin->to_consume[a]->t_trigger = now;
break; break;
@ -413,7 +414,7 @@ void *sa_service() {
if (facilities.tolling.protocol.p == TOLLING_PROTOCOL_TLS || if (facilities.tolling.protocol.p == TOLLING_PROTOCOL_TLS ||
facilities.tolling.protocol.p == TOLLING_PROTOCOL_TLS_GN || facilities.tolling.protocol.p == TOLLING_PROTOCOL_TLS_GN ||
facilities.tolling.protocol.p == TOLLING_PROTOCOL_TLS_SHS) { facilities.tolling.protocol.p == TOLLING_PROTOCOL_TLS_SHS) {
tolling_tlsc_mgmt(facilities.tx_queue, security_socket); tolling_tlsc_mgmt(facilities.tx_queue, &security_socket);
} }
usleep(sleep_ms*1000); usleep(sleep_ms*1000);
@ -421,6 +422,8 @@ void *sa_service() {
ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr); ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr);
itss_0close(security_socket);
return NULL; return NULL;
} }

352
src/tpm.c
View File

@ -56,17 +56,17 @@ int tpm_should_retransmit() {
return 0; return 0;
} }
int tpm_pay(tolling_info_t* info, void* security_socket, uint8_t* neighbour, uint8_t* dst_addr) { int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, uint8_t* dst_addr) {
int rv = 0; int rv = 0;
tolling_t* tolling = (tolling_t*) &facilities.tolling; tolling_t* tolling = (tolling_t*) &facilities.tolling;
const size_t buf_len = 2048; const size_t buf_len = 2048;
uint8_t tpm_uper[buf_len]; uint8_t tpm_uper[buf_len];
uint8_t buf[buf_len]; uint8_t buf1[buf_len], buf2[buf_len];
if (!tolling->enabled) { if (!tolling->enabled) {
syslog_debug("[facilities] [tolling] tolling is disabled"); log_debug("[tolling] tolling is disabled");
return rv; return rv;
} }
@ -81,7 +81,7 @@ int tpm_pay(tolling_info_t* info, void* security_socket, uint8_t* neighbour, uin
tolling->station.obu.active = true; tolling->station.obu.active = true;
tolling->station.obu.nonce = rand() + 1; tolling->station.obu.nonce = rand() + 1;
syslog_info("[facilities] [tolling] issuing toll %s.request | client: %ld nonce: %ld", tts(info->asn->tollType), tolling->station.obu.client_id, tolling->station.obu.nonce); log_info("[tolling] issuing toll %s.request | client: %ld nonce: %ld", tts(info->asn->tollType), tolling->station.obu.client_id, tolling->station.obu.nonce);
// TPM // TPM
tpm = calloc(1, sizeof(TPM_t)); tpm = calloc(1, sizeof(TPM_t));
@ -127,7 +127,7 @@ int tpm_pay(tolling_info_t* info, void* security_socket, uint8_t* neighbour, uin
case TollType_entry: case TollType_entry:
if (tolling->station.obu.toll_type != -1 && if (tolling->station.obu.toll_type != -1 &&
!tolling->station.obu.rt_on) { !tolling->station.obu.rt_on) {
syslog_err("[facilities] [tolling] trying to issue entry.request but current tolling state is %s - resetting", log_error("[tolling] trying to issue entry.request but current tolling state is %s - resetting",
tts(tolling->station.obu.toll_type)); tts(tolling->station.obu.toll_type));
tolling->station.obu.toll_type = -1; tolling->station.obu.toll_type = -1;
tolling->station.obu.active = false; tolling->station.obu.active = false;
@ -152,13 +152,13 @@ int tpm_pay(tolling_info_t* info, void* security_socket, uint8_t* neighbour, uin
if (tolling->station.obu.toll_type != TollingType_PR_entry && if (tolling->station.obu.toll_type != TollingType_PR_entry &&
!tolling->station.obu.rt_on) { !tolling->station.obu.rt_on) {
syslog_err("[facilities] [tolling] trying to issue exit.request but current tolling state is %s - will not provide entry proof", log_error("[tolling] trying to issue exit.request but current tolling state is %s - will not provide entry proof",
tts(tolling->station.obu.toll_type)); tts(tolling->station.obu.toll_type));
} else { } else {
uint8_t b_tep[1024]; uint8_t b_tep[1024];
asn_enc_rval_t e_tep = uper_encode_to_buffer(&asn_DEF_TPM, NULL, tolling->station.obu.entry_proof, b_tep, 1024); asn_enc_rval_t e_tep = uper_encode_to_buffer(&asn_DEF_TPM, NULL, tolling->station.obu.entry_proof, b_tep, 1024);
if (e_tep.encoded == -1) { if (e_tep.encoded == -1) {
syslog_err("[facilities] [tolling] error encoding TPM entry proof (%s)", e_tep.failed_type->name); log_error("[tolling] error encoding TPM entry proof (%s)", e_tep.failed_type->name);
ASN_STRUCT_FREE(asn_DEF_TPM, tolling->station.obu.entry_proof); ASN_STRUCT_FREE(asn_DEF_TPM, tolling->station.obu.entry_proof);
tolling->station.obu.entry_proof = NULL; tolling->station.obu.entry_proof = NULL;
rv = 1; rv = 1;
@ -171,7 +171,7 @@ int tpm_pay(tolling_info_t* info, void* security_socket, uint8_t* neighbour, uin
case TollType_single: case TollType_single:
if (tolling->station.obu.toll_type != -1 && if (tolling->station.obu.toll_type != -1 &&
!tolling->station.obu.rt_on) { !tolling->station.obu.rt_on) {
syslog_err("[facilities] [tolling] trying to issue single.request but current tolling state is %s", log_error("[tolling] trying to issue single.request but current tolling state is %s",
tts(tolling->station.obu.toll_type)); tts(tolling->station.obu.toll_type));
rv = 1; rv = 1;
goto cleanup; goto cleanup;
@ -188,9 +188,9 @@ int tpm_pay(tolling_info_t* info, void* security_socket, uint8_t* neighbour, uin
// Encode TollingPaymentMessage // Encode TollingPaymentMessage
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TollingPaymentMessage, NULL, tpm->tpm, buf, buf_len); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TollingPaymentMessage, NULL, tpm->tpm, buf1, buf_len);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [tolling] error encoding TollingPaymentMessage (%s)", enc.failed_type->name); log_error("[tolling] error encoding TollingPaymentMessage (%s)", enc.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -201,23 +201,23 @@ int tpm_pay(tolling_info_t* info, void* security_socket, uint8_t* neighbour, uin
sreq->present = SecurityRequest_PR_sign; sreq->present = SecurityRequest_PR_sign;
sreq->choice.sign.data.size = enc.encoded; sreq->choice.sign.data.size = enc.encoded;
sreq->choice.sign.data.buf = malloc(enc.encoded); sreq->choice.sign.data.buf = malloc(enc.encoded);
memcpy(sreq->choice.sign.data.buf, buf, enc.encoded); memcpy(sreq->choice.sign.data.buf, buf1, enc.encoded);
buf[0] = 4; buf2[0] = 4;
enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf+1, 2047); enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf2+1, 2047);
syslog_debug("[facilities]->[security] SecurityRequest.sign (%ldB)", enc.encoded+1); log_debug("[sdu]->[security] SecurityRequest.sign (%ldB)", enc.encoded+1);
zmq_send(security_socket, buf, enc.encoded+1, 0); itss_0send(*security_socket, buf2, enc.encoded+1);
int32_t rl = zmq_recv(security_socket, buf, buf_len, 0); int32_t rl = itss_0recv_rt(security_socket, buf1, buf_len, buf2, enc.encoded+1, 1000);
syslog_debug("[facilities]<-[security] SecurityReply.sign (%dB)", rl); log_debug("[sdu]<-[security] SecurityReply.sign (%dB)", rl);
if (oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf, rl).code) { if (oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf1, rl).code) {
syslog_err("[facilities] SecurityReply.sign decode failure"); log_error("SecurityReply.sign decode failure");
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
if (srep->returnCode == SecurityReplyReturnCode_rejected) { if (srep->returnCode == SecurityReplyReturnCode_rejected) {
syslog_err("[facilities] SecurityReply.sign rejected"); log_error("SecurityReply.sign rejected");
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -238,7 +238,7 @@ int tpm_pay(tolling_info_t* info, void* security_socket, uint8_t* neighbour, uin
// Encode TPM // Encode TPM
enc = uper_encode_to_buffer(&asn_DEF_TPM, NULL, tpm, tpm_uper, buf_len); enc = uper_encode_to_buffer(&asn_DEF_TPM, NULL, tpm, tpm_uper, buf_len);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [tolling] error encoding TPM.request (%s)", enc.failed_type->name); log_error("[tolling] error encoding TPM.request (%s)", enc.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -301,27 +301,27 @@ int tpm_pay(tolling_info_t* info, void* security_socket, uint8_t* neighbour, uin
++tlsc->nmsg; ++tlsc->nmsg;
sreq->choice.tlsSend.connId = id; sreq->choice.tlsSend.connId = id;
buf[0] = 4; buf1[0] = 4;
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf+1, buf_len-1); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf1+1, buf_len-1);
syslog_debug("[facilities] [tolling]-> SecurityRequest.tlsSend ->[security] | size:%ldB", enc.encoded); log_debug("[tolling]-> SecurityRequest.tlsSend ->[security] | size:%ldB", enc.encoded);
zmq_send(security_socket, buf, enc.encoded+1, 0); itss_0send(*security_socket, buf1, enc.encoded+1);
int rc = zmq_recv(security_socket, buf, buf_len, 0); int rc = itss_0recv_rt(security_socket, buf2, buf_len, buf1, enc.encoded+1, 1000);
if (rc == -1) { if (rc == -1) {
syslog_err("[facilities] [tolling]-> SecurityRequest.tlsSend ->[security] <TIMEOUT>"); log_error("[tolling]-> SecurityRequest.tlsSend ->[security] <TIMEOUT>");
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
syslog_debug("[facilities] [tolling]<- SecurityReply.tlsSend <-[security] | size:%dB", rc); log_debug("[tolling]<- SecurityReply.tlsSend <-[security] | size:%dB", rc);
SecurityReply_t* srep = NULL; SecurityReply_t* srep = NULL;
asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf, buf_len); asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf2, buf_len);
if (dec.code || if (dec.code ||
srep->returnCode != SecurityReplyReturnCode_accepted || srep->returnCode != SecurityReplyReturnCode_accepted ||
!srep->data || !srep->data ||
srep->data->present != SecurityReplyData_PR_tlsSend) { srep->data->present != SecurityReplyData_PR_tlsSend) {
syslog_err("[facilities] [tolling]<- SecurityReply.tlsSend rejected"); log_error("[tolling]<- SecurityReply.tlsSend rejected");
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -356,15 +356,15 @@ int tpm_pay(tolling_info_t* info, void* security_socket, uint8_t* neighbour, uin
} }
// encode TR // encode TR
buf[0] = 4; buf1[0] = 4;
enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, buf_len-1); enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf1+1, buf_len-1);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [tolling] error encoding TR TPM.request (%s)", enc.failed_type->name); log_error("[tolling] error encoding TR TPM.request (%s)", enc.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
itss_queue_send(facilities.tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, id, itss_queue_send(facilities.tx_queue, buf1, enc.encoded+1, ITSS_TRANSPORT, id,
tolling->protocol.p == TOLLING_PROTOCOL_SIMPLE ? "TR.packet.btp" : "TR.packet.tcp"); tolling->protocol.p == TOLLING_PROTOCOL_SIMPLE ? "TR.packet.btp" : "TR.packet.tcp");
// Retransmission // Retransmission
@ -390,13 +390,13 @@ int tpm_pay(tolling_info_t* info, void* security_socket, uint8_t* neighbour, uin
fi->choice.message.data.size = tpm_uper_len; fi->choice.message.data.size = tpm_uper_len;
fi->choice.message.data.buf = malloc(tpm_uper_len); fi->choice.message.data.buf = malloc(tpm_uper_len);
memcpy(fi->choice.message.data.buf, tpm_uper, tpm_uper_len); memcpy(fi->choice.message.data.buf, tpm_uper, tpm_uper_len);
enc = oer_encode_to_buffer(&asn_DEF_FacilitiesIndication, NULL, fi, buf+1, buf_len-1); enc = oer_encode_to_buffer(&asn_DEF_FacilitiesIndication, NULL, fi, buf1+1, buf_len-1);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [tolling] error encoding FI TPM.request (%s)", enc.failed_type->name); log_error("[tolling] error encoding FI TPM.request (%s)", enc.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
itss_queue_send(facilities.tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message (TPM.request)"); itss_queue_send(facilities.tx_queue, buf1, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message (TPM.request)");
if (facilities.logging.recorder) { if (facilities.logging.recorder) {
uint16_t buffer_len = 2048; uint16_t buffer_len = 2048;
@ -426,10 +426,10 @@ cleanup:
return rv; return rv;
} }
static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, uint8_t* src_addr) { static void rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neighbour, uint8_t* src_addr) {
if (!tpm_rx->tpm->tollingType) { if (!tpm_rx->tpm->tollingType) {
syslog_err("[facilities] [tolling] received TPM does not have a type"); log_error("[tolling] received TPM does not have a type");
return; return;
} }
@ -437,7 +437,7 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neigh
uint64_t client_id, nonce, info_id; uint64_t client_id, nonce, info_id;
const uint32_t buf_len = 1800; const uint32_t buf_len = 1800;
uint8_t buf[buf_len]; uint8_t buf1[buf_len], buf2[buf_len];
uint8_t tpm_uper[buf_len]; uint8_t tpm_uper[buf_len];
SecurityRequest_t* sreq = NULL; SecurityRequest_t* sreq = NULL;
@ -446,7 +446,7 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neigh
switch (type_rx->present) { switch (type_rx->present) {
case TollingType_PR_entry: case TollingType_PR_entry:
if (type_rx->choice.entry.present != TollingEntry_PR_request) { if (type_rx->choice.entry.present != TollingEntry_PR_request) {
syslog_err("[facilities] [tolling] received TPM.entry is not request"); log_error("[tolling] received TPM.entry is not request");
return; return;
} }
client_id = type_rx->choice.entry.choice.request.clientId; client_id = type_rx->choice.entry.choice.request.clientId;
@ -459,7 +459,7 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neigh
type_rx->choice.exit->present != TollingExit_PR_request || type_rx->choice.exit->present != TollingExit_PR_request ||
!type_rx->choice.exit->choice.request !type_rx->choice.exit->choice.request
) { ) {
syslog_err("[facilities] [tolling] received TPM.exit is not request"); log_error("[tolling] received TPM.exit is not request");
return; return;
} }
client_id = type_rx->choice.exit->choice.request->clientId; client_id = type_rx->choice.exit->choice.request->clientId;
@ -467,21 +467,21 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neigh
info_id = type_rx->choice.exit->choice.request->infoId; info_id = type_rx->choice.exit->choice.request->infoId;
if (!type_rx->choice.exit->choice.request->entryProof) { if (!type_rx->choice.exit->choice.request->entryProof) {
syslog_err("[facilities] [tolling] received TPM.exit.request does not contain entry proof"); log_error("[tolling] received TPM.exit.request does not contain entry proof");
return; return;
} }
TPM_t* ep = (TPM_t*) type_rx->choice.exit->choice.request->entryProof; TPM_t* ep = (TPM_t*) type_rx->choice.exit->choice.request->entryProof;
if (!ep->tpmSignature) { if (!ep->tpmSignature) {
syslog_err("[facilities] [tolling] received TPM.exit.request.entryProof does not contain signature");; log_error("[tolling] received TPM.exit.request.entryProof does not contain signature");;
return; return;
} }
// Encode TollingPaymentMessage // Encode TollingPaymentMessage
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TollingPaymentMessage, NULL, ep->tpm, buf, buf_len); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TollingPaymentMessage, NULL, ep->tpm, buf1, buf_len);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [tolling] error encoding TollingPaymentMessage (%s)", enc.failed_type->name); log_error("[tolling] error encoding TollingPaymentMessage (%s)", enc.failed_type->name);
goto cleanup; goto cleanup;
} }
@ -491,7 +491,7 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neigh
// message // message
sreq->choice.verify.message.size = enc.encoded; sreq->choice.verify.message.size = enc.encoded;
sreq->choice.verify.message.buf = malloc(enc.encoded); sreq->choice.verify.message.buf = malloc(enc.encoded);
memcpy(sreq->choice.verify.message.buf, buf, enc.encoded); memcpy(sreq->choice.verify.message.buf, buf1, enc.encoded);
// r // r
sreq->choice.verify.r.size = ep->tpmSignature->r.size; sreq->choice.verify.r.size = ep->tpmSignature->r.size;
@ -508,25 +508,25 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neigh
// signature type // signature type
sreq->choice.verify.type = ep->tpmSignature->type; sreq->choice.verify.type = ep->tpmSignature->type;
buf[0] = 4; buf1[0] = 4;
enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf+1, buf_len-1); enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf1+1, buf_len-1);
syslog_debug("[facilities]->[security] SecurityRequest.verify (%ldB)", enc.encoded+1); log_debug("[sdu]->[security] SecurityRequest.verify (%ldB)", enc.encoded+1);
zmq_send(security_socket, buf, enc.encoded+1, 0); itss_0send(*security_socket, buf1, enc.encoded+1);
int32_t rl = zmq_recv(security_socket, buf, buf_len, 0); int32_t rl = itss_0recv_rt(security_socket, buf2, buf_len, buf1, enc.encoded+1, 1000);
syslog_debug("[facilities]<-[security] SecurityReply.verify (%dB)", rl); log_debug("[sdu]<-[security] SecurityReply.verify (%dB)", rl);
if (oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf, rl).code) { if (oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf2, rl).code) {
syslog_err("[facilities] SecurityReply.verify decode failure"); log_error("SecurityReply.verify decode failure");
goto cleanup; goto cleanup;
} }
if (srep->returnCode == SecurityReplyReturnCode_rejected) { if (srep->returnCode == SecurityReplyReturnCode_rejected) {
syslog_err("[facilities] SecurityReply.verify rejected"); log_error("SecurityReply.verify rejected");
goto cleanup; goto cleanup;
} }
if (srep->data->choice.verify.report != SecurityVerifyConfirmCode_success) { if (srep->data->choice.verify.report != SecurityVerifyConfirmCode_success) {
syslog_debug("[facilities] entry proof signature verify failed"); log_debug("entry proof signature verify failed");
goto cleanup; goto cleanup;
} }
@ -538,7 +538,7 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neigh
case TollingType_PR_single: case TollingType_PR_single:
if (type_rx->choice.single.present != TollingSingle_PR_request) { if (type_rx->choice.single.present != TollingSingle_PR_request) {
syslog_err("[facilities] [tolling] received TPM.single is not request"); log_error("[tolling] received TPM.single is not request");
return; return;
} }
client_id = type_rx->choice.single.choice.request.clientId; client_id = type_rx->choice.single.choice.request.clientId;
@ -547,7 +547,7 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neigh
break; break;
default: default:
syslog_err("[facilities] [tolling] received TPM has unrecognized type"); log_error("[tolling] received TPM has unrecognized type");
return; return;
} }
@ -555,7 +555,7 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neigh
switch (tolling->protocol.p) { switch (tolling->protocol.p) {
case TOLLING_PROTOCOL_SIMPLE: case TOLLING_PROTOCOL_SIMPLE:
syslog_info("[facilities] [tolling] received toll %s.request | client: %lld (certificate id: 0x%02x%02x%02x) nonce: %lld", log_info("[tolling] received toll %s.request | client: %lld (certificate id: 0x%02x%02x%02x) nonce: %lld",
tts(type_rx->present), tts(type_rx->present),
(long long) client_id, (long long) client_id,
neighbour ? neighbour[5] : 0, neighbour ? neighbour[5] : 0,
@ -567,7 +567,7 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neigh
case TOLLING_PROTOCOL_TLS: case TOLLING_PROTOCOL_TLS:
case TOLLING_PROTOCOL_TLS_GN: case TOLLING_PROTOCOL_TLS_GN:
case TOLLING_PROTOCOL_TLS_SHS: case TOLLING_PROTOCOL_TLS_SHS:
syslog_info("[facilities] [tolling] received toll %s.request | client: %lld nonce: %lld", log_info("[tolling] received toll %s.request | client: %lld nonce: %lld",
tts(type_rx->present), tts(type_rx->present),
(long long) client_id, (long long) client_id,
(long long) nonce (long long) nonce
@ -584,14 +584,14 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neigh
if (tolling->protocol.p == TOLLING_PROTOCOL_SIMPLE) { if (tolling->protocol.p == TOLLING_PROTOCOL_SIMPLE) {
if (!tpm_rx->tpmSignature) { if (!tpm_rx->tpmSignature) {
syslog_err("[facilities] [tolling] in simple mode but TPM without signature received"); log_error("[tolling] in simple mode but TPM without signature received");
goto cleanup; goto cleanup;
} }
// Encode TollingPaymentMessage // Encode TollingPaymentMessage
enc = oer_encode_to_buffer(&asn_DEF_TollingPaymentMessage, NULL, tpm_rx->tpm, buf, buf_len); enc = oer_encode_to_buffer(&asn_DEF_TollingPaymentMessage, NULL, tpm_rx->tpm, buf1, buf_len);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [tolling] error encoding TollingPaymentMessage (%s)", enc.failed_type->name); log_error("[tolling] error encoding TollingPaymentMessage (%s)", enc.failed_type->name);
goto cleanup; goto cleanup;
} }
@ -601,7 +601,7 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neigh
// message // message
sreq->choice.verify.message.size = enc.encoded; sreq->choice.verify.message.size = enc.encoded;
sreq->choice.verify.message.buf = malloc(enc.encoded); sreq->choice.verify.message.buf = malloc(enc.encoded);
memcpy(sreq->choice.verify.message.buf, buf, enc.encoded); memcpy(sreq->choice.verify.message.buf, buf1, enc.encoded);
// r // r
sreq->choice.verify.r.size = tpm_rx->tpmSignature->r.size; sreq->choice.verify.r.size = tpm_rx->tpmSignature->r.size;
@ -618,25 +618,25 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neigh
// signature type // signature type
sreq->choice.verify.type = tpm_rx->tpmSignature->type; sreq->choice.verify.type = tpm_rx->tpmSignature->type;
buf[0] = 4; buf1[0] = 4;
enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf+1, buf_len-1); enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf1+1, buf_len-1);
syslog_debug("[facilities]->[security] SecurityRequest.verify (%ldB)", enc.encoded+1); log_debug("[sdu]->[security] SecurityRequest.verify (%ldB)", enc.encoded+1);
zmq_send(security_socket, buf, enc.encoded+1, 0); itss_0send(*security_socket, buf1, enc.encoded+1);
int32_t rl = zmq_recv(security_socket, buf, buf_len, 0); int32_t rl = itss_0recv_rt(security_socket, buf2, buf_len, buf1, enc.encoded+1, 1000);
syslog_debug("[facilities]<-[security] SecurityReply.verify (%dB)", rl); log_debug("[sdu]<-[security] SecurityReply.verify (%dB)", rl);
if (oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf, rl).code) { if (oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf2, rl).code) {
syslog_err("[facilities] SecurityReply.verify decode failure"); log_error("SecurityReply.verify decode failure");
goto cleanup; goto cleanup;
} }
if (srep->returnCode == SecurityReplyReturnCode_rejected) { if (srep->returnCode == SecurityReplyReturnCode_rejected) {
syslog_err("[facilities] SecurityReply.verify rejected"); log_error("SecurityReply.verify rejected");
goto cleanup; goto cleanup;
} }
if (srep->data->choice.verify.report != SecurityVerifyConfirmCode_success) { if (srep->data->choice.verify.report != SecurityVerifyConfirmCode_success) {
syslog_debug("[facilities] signature verify failed"); log_debug("signature verify failed");
goto cleanup; goto cleanup;
} }
@ -707,7 +707,7 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neigh
// Create client // Create client
if (!client) { if (!client) {
if (tolling->station.rsu.clients_len-1 >= TOLLING_MAX_CLIENTS) { if (tolling->station.rsu.clients_len-1 >= TOLLING_MAX_CLIENTS) {
syslog_err("[facilities] [tolling] max clients reached"); log_error("[tolling] max clients reached");
goto cleanup; goto cleanup;
} }
tolling->station.rsu.clients[tolling->station.rsu.clients_len] = malloc(sizeof(toll_client_t)); tolling->station.rsu.clients[tolling->station.rsu.clients_len] = malloc(sizeof(toll_client_t));
@ -762,9 +762,9 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neigh
// TODO check clientId // TODO check clientId
// Encode TollingPaymentMessage // Encode TollingPaymentMessage
enc = oer_encode_to_buffer(&asn_DEF_TollingPaymentMessage, NULL, tpm->tpm, buf, buf_len); enc = oer_encode_to_buffer(&asn_DEF_TollingPaymentMessage, NULL, tpm->tpm, buf1, buf_len);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [tolling] error encoding TollingPaymentMessage (%s)", enc.failed_type->name); log_error("[tolling] error encoding TollingPaymentMessage (%s)", enc.failed_type->name);
goto cleanup; goto cleanup;
} }
@ -773,26 +773,26 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neigh
sreq->present = SecurityRequest_PR_sign; sreq->present = SecurityRequest_PR_sign;
sreq->choice.sign.data.size = enc.encoded; sreq->choice.sign.data.size = enc.encoded;
sreq->choice.sign.data.buf = malloc(enc.encoded); sreq->choice.sign.data.buf = malloc(enc.encoded);
memcpy(sreq->choice.sign.data.buf, buf, enc.encoded); memcpy(sreq->choice.sign.data.buf, buf1, enc.encoded);
buf[0] = 4; buf1[0] = 4;
enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf+1, buf_len-1); enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf1+1, buf_len-1);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [tolling] error encoding SecurityRequest (%s)", enc.failed_type->name); log_error("[tolling] error encoding SecurityRequest (%s)", enc.failed_type->name);
goto cleanup; goto cleanup;
} }
syslog_debug("[facilities]->[security] SecurityRequest.sign (%ldB)", enc.encoded+1); log_debug("[sdu]->[security] SecurityRequest.sign (%ldB)", enc.encoded+1);
zmq_send(security_socket, buf, enc.encoded+1, 0); itss_0send(*security_socket, buf1, enc.encoded+1);
int rc = zmq_recv(security_socket, buf, buf_len, 0); int rc = itss_0recv_rt(security_socket, buf2, buf_len, buf1, enc.encoded+1, 1000);
syslog_debug("[facilities]<-[security] SecurityReply.sign (%dB)", rc); log_debug("[sdu]<-[security] SecurityReply.sign (%dB)", rc);
if (oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf, rc).code) { if (oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf2, rc).code) {
syslog_err("[facilities] SecurityReply.sign decode failure"); log_error("SecurityReply.sign decode failure");
goto cleanup; goto cleanup;
} }
if (srep->returnCode == SecurityReplyReturnCode_rejected) { if (srep->returnCode == SecurityReplyReturnCode_rejected) {
syslog_err("[facilities] SecurityReply.sign rejected"); log_error("SecurityReply.sign rejected");
goto cleanup; goto cleanup;
} }
@ -816,7 +816,7 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neigh
// encode TPM // encode TPM
enc = uper_encode_to_buffer(&asn_DEF_TPM, NULL, tpm, tpm_uper, buf_len); enc = uper_encode_to_buffer(&asn_DEF_TPM, NULL, tpm, tpm_uper, buf_len);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [tolling] error encoding TPM.reply (%s)", enc.failed_type->name); log_error("[tolling] error encoding TPM.reply (%s)", enc.failed_type->name);
goto cleanup; goto cleanup;
} }
size_t tpm_uper_len = (enc.encoded + 7) / 8; size_t tpm_uper_len = (enc.encoded + 7) / 8;
@ -880,25 +880,25 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neigh
++tlsc->nmsg; ++tlsc->nmsg;
sreq->choice.tlsSend.connId = id; sreq->choice.tlsSend.connId = id;
buf[0] = 4; buf1[0] = 4;
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf+1, buf_len-1); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf1+1, buf_len-1);
syslog_debug("[facilities] [tolling]-> SecurityRequest.tlsSend ->[security] | size:%ldB", enc.encoded); log_debug("[tolling]-> SecurityRequest.tlsSend ->[security] | size:%ldB", enc.encoded);
zmq_send(security_socket, buf, enc.encoded+1, 0); itss_0send(*security_socket, buf1, enc.encoded+1);
int rc = zmq_recv(security_socket, buf, buf_len, 0); int rc = itss_0recv_rt(security_socket, buf2, buf_len, buf1, enc.encoded+1, 1000);
if (rc == -1) { if (rc == -1) {
syslog_err("[facilities] [tolling]-> SecurityRequest.tlsSend ->[security] <TIMEOUT>"); log_error("[tolling]-> SecurityRequest.tlsSend ->[security] <TIMEOUT>");
goto cleanup; goto cleanup;
} }
syslog_debug("[facilities] [tolling]<- SecurityReply.tlsSend <-[security] | size:%dB", rc); log_debug("[tolling]<- SecurityReply.tlsSend <-[security] | size:%dB", rc);
asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf, rc); asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf2, rc);
if (dec.code || if (dec.code ||
srep->returnCode != SecurityReplyReturnCode_accepted || srep->returnCode != SecurityReplyReturnCode_accepted ||
!srep->data || !srep->data ||
srep->data->present != SecurityReplyData_PR_tlsSend) { srep->data->present != SecurityReplyData_PR_tlsSend) {
syslog_err("[facilities] [tolling]<- SecurityReply.tlsSend rejected"); log_error("[tolling]<- SecurityReply.tlsSend rejected");
goto cleanup; goto cleanup;
} }
@ -931,14 +931,14 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neigh
} }
// encode TR // encode TR
buf[0] = 4; buf1[0] = 4;
enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, buf_len-1); enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf1+1, buf_len-1);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [tolling] error encoding TR TPM.reply (%s)", enc.failed_type->name); log_error("[tolling] error encoding TR TPM.reply (%s)", enc.failed_type->name);
goto cleanup; goto cleanup;
} }
itss_queue_send(facilities.tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, id, itss_queue_send(facilities.tx_queue, buf1, enc.encoded+1, ITSS_TRANSPORT, id,
tolling->protocol.p == TOLLING_PROTOCOL_SIMPLE ? "TR.packet.btp" : "TR.packet.tcp"); tolling->protocol.p == TOLLING_PROTOCOL_SIMPLE ? "TR.packet.btp" : "TR.packet.tcp");
// Logging // Logging
@ -957,13 +957,13 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neigh
fi->choice.message.data.size = tpm_uper_len; fi->choice.message.data.size = tpm_uper_len;
fi->choice.message.data.buf = malloc(tpm_uper_len); fi->choice.message.data.buf = malloc(tpm_uper_len);
memcpy(fi->choice.message.data.buf, tpm_uper, tpm_uper_len); memcpy(fi->choice.message.data.buf, tpm_uper, tpm_uper_len);
enc = oer_encode_to_buffer(&asn_DEF_FacilitiesIndication, NULL, fi, buf+1, buf_len-1); enc = oer_encode_to_buffer(&asn_DEF_FacilitiesIndication, NULL, fi, buf1+1, buf_len-1);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [tolling] error encoding FI TPM.reply (%s)", enc.failed_type->name); log_error("[tolling] error encoding FI TPM.reply (%s)", enc.failed_type->name);
goto cleanup; goto cleanup;
} }
itss_queue_send(facilities.tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message (TPM.reply)"); itss_queue_send(facilities.tx_queue, buf1, enc.encoded+1, ITSS_APPLICATIONS, id, "FI.message (TPM.reply)");
if (facilities.logging.recorder) { if (facilities.logging.recorder) {
uint16_t buffer_len = 2048; uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len]; uint8_t buffer[buffer_len];
@ -989,10 +989,10 @@ cleanup:
ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi); 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, 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) { if (!tpm_rx->tpm->tollingType) {
syslog_err("[facilities] [tolling] received TPM does not have a type"); log_error("[tolling] received TPM does not have a type");
return; return;
} }
@ -1005,17 +1005,17 @@ static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_so
SecurityReply_t* srep = NULL; SecurityReply_t* srep = NULL;
TransportRequest_t* tr = NULL; TransportRequest_t* tr = NULL;
const uint16_t buf_len = 1024; const uint16_t buf_len = 2048;
uint8_t buf[buf_len]; uint8_t buf1[buf_len], buf2[buf_len];
switch (type_rx->present) { switch (type_rx->present) {
case TollingType_PR_entry: case TollingType_PR_entry:
if (type_rx->choice.entry.present != TollingEntry_PR_reply) { if (type_rx->choice.entry.present != TollingEntry_PR_reply) {
syslog_err("[facilities] [tolling] received TPM.entry is not reply"); log_error("[tolling] received TPM.entry is not reply");
return; return;
} }
if (tolling->station.obu.toll_type != TollingType_PR_entry) { if (tolling->station.obu.toll_type != TollingType_PR_entry) {
syslog_err("[facilities] [tolling] received TPM toll (%d) is not expected toll type (%d)", log_error("[tolling] received TPM toll (%d) is not expected toll type (%d)",
TollingType_PR_entry, tolling->station.obu.toll_type); TollingType_PR_entry, tolling->station.obu.toll_type);
} }
client_id = type_rx->choice.entry.choice.reply.clientId; client_id = type_rx->choice.entry.choice.reply.clientId;
@ -1023,10 +1023,10 @@ static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_so
info_id = type_rx->choice.entry.choice.reply.infoId; info_id = type_rx->choice.entry.choice.reply.infoId;
confirmation_code = type_rx->choice.entry.choice.reply.confirmationCode; confirmation_code = type_rx->choice.entry.choice.reply.confirmationCode;
uint8_t b_tep[1024]; uint8_t b_tep[2048];
asn_enc_rval_t e_tep = uper_encode_to_buffer(&asn_DEF_TPM, NULL, tpm_rx, b_tep, 1024); asn_enc_rval_t e_tep = uper_encode_to_buffer(&asn_DEF_TPM, NULL, tpm_rx, b_tep, 2048);
if (e_tep.encoded == -1) { if (e_tep.encoded == -1) {
syslog_err("[facilities] [tolling] error encoding received TPM as entry proof"); log_error("[tolling] error encoding received TPM as entry proof");
return; return;
} }
uper_decode_complete(NULL, &asn_DEF_TPM, (void**) &tolling->station.obu.entry_proof, b_tep, (e_tep.encoded+7)/8); uper_decode_complete(NULL, &asn_DEF_TPM, (void**) &tolling->station.obu.entry_proof, b_tep, (e_tep.encoded+7)/8);
@ -1036,11 +1036,11 @@ static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_so
if (!type_rx->choice.exit || if (!type_rx->choice.exit ||
type_rx->choice.exit->present != TollingExit_PR_reply type_rx->choice.exit->present != TollingExit_PR_reply
) { ) {
syslog_err("[facilities] [tolling] received TPM.exit is not reply"); log_error("[tolling] received TPM.exit is not reply");
return; return;
} }
if (tolling->station.obu.toll_type != TollingType_PR_exit) { if (tolling->station.obu.toll_type != TollingType_PR_exit) {
syslog_err("[facilities] [tolling] received TPM toll (%d) is not expected toll type (%d)", log_error("[tolling] received TPM toll (%d) is not expected toll type (%d)",
TollingType_PR_exit, tolling->station.obu.toll_type); TollingType_PR_exit, tolling->station.obu.toll_type);
return; return;
} }
@ -1052,11 +1052,11 @@ static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_so
case TollingType_PR_single: case TollingType_PR_single:
if (type_rx->choice.single.present != TollingSingle_PR_reply) { if (type_rx->choice.single.present != TollingSingle_PR_reply) {
syslog_err("[facilities] [tolling] received TPM.single is not reply"); log_error("[tolling] received TPM.single is not reply");
return; return;
} }
if (tolling->station.obu.toll_type != TollingType_PR_single) { if (tolling->station.obu.toll_type != TollingType_PR_single) {
syslog_err("[facilities] [tolling] received TPM type (%d) is not expected toll type (%d)", log_error("[tolling] received TPM type (%d) is not expected toll type (%d)",
TollingType_PR_single, tolling->station.obu.toll_type); TollingType_PR_single, tolling->station.obu.toll_type);
} }
client_id = type_rx->choice.single.choice.reply.clientId; client_id = type_rx->choice.single.choice.reply.clientId;
@ -1066,25 +1066,25 @@ static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_so
break; break;
default: default:
syslog_err("[facilities] [tolling] received TPM has unrecognized type"); log_error("[tolling] received TPM has unrecognized type");
return; return;
} }
if (client_id != tolling->station.obu.client_id) { if (client_id != tolling->station.obu.client_id) {
syslog_debug("[facilities] [tolling]<- received TPM.reply clientId different from ego"); log_debug("[tolling]<- received TPM.reply clientId different from ego");
return; return;
} }
if (nonce != tolling->station.obu.nonce) { if (nonce != tolling->station.obu.nonce) {
syslog_err("[facilities] [tolling]<- received TPM.reply nonce different from sent request"); log_error("[tolling]<- received TPM.reply nonce different from sent request");
return; return;
} }
// Encode TollingPaymentMessage // Encode TollingPaymentMessage
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TollingPaymentMessage, NULL, tpm_rx->tpm, buf, buf_len); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TollingPaymentMessage, NULL, tpm_rx->tpm, buf1, buf_len);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [tolling] error encoding TollingPaymentMessage (%s)", enc.failed_type->name); log_error("[tolling] error encoding TollingPaymentMessage (%s)", enc.failed_type->name);
goto cleanup; goto cleanup;
} }
@ -1096,7 +1096,7 @@ static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_so
// message // message
sreq->choice.verify.message.size = enc.encoded; sreq->choice.verify.message.size = enc.encoded;
sreq->choice.verify.message.buf = malloc(enc.encoded); sreq->choice.verify.message.buf = malloc(enc.encoded);
memcpy(sreq->choice.verify.message.buf, buf, enc.encoded); memcpy(sreq->choice.verify.message.buf, buf1, enc.encoded);
// r // r
sreq->choice.verify.r.size = tpm_rx->tpmSignature->r.size; sreq->choice.verify.r.size = tpm_rx->tpmSignature->r.size;
sreq->choice.verify.r.buf = malloc(tpm_rx->tpmSignature->r.size); sreq->choice.verify.r.buf = malloc(tpm_rx->tpmSignature->r.size);
@ -1112,25 +1112,25 @@ static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_so
// signature type // signature type
sreq->choice.verify.type = tpm_rx->tpmSignature->type; sreq->choice.verify.type = tpm_rx->tpmSignature->type;
buf[0] = 4; buf1[0] = 4;
enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf+1, 2047); enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf1+1, 2047);
syslog_debug("[facilities]->[security] SecurityRequest.verify (%ldB)", enc.encoded+1); log_debug("[sdu]->[security] SecurityRequest.verify (%ldB)", enc.encoded+1);
zmq_send(security_socket, buf, enc.encoded+1, 0); itss_0send(*security_socket, buf1, enc.encoded+1);
int32_t rl = zmq_recv(security_socket, buf, buf_len, 0); int32_t rl = itss_0recv_rt(security_socket, buf2, buf_len, buf1, enc.encoded+1, 1000);
syslog_debug("[facilities]<-[security] SecurityReply.verify (%dB)", rl); log_debug("[sdu]<-[security] SecurityReply.verify (%dB)", rl);
if (oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf, rl).code) { if (oer_decode(NULL, &asn_DEF_SecurityReply, (void**) &srep, buf2, rl).code) {
syslog_err("[facilities] SecurityReply.verify decode failure"); log_error("SecurityReply.verify decode failure");
goto cleanup; goto cleanup;
} }
if (srep->returnCode == SecurityReplyReturnCode_rejected) { if (srep->returnCode == SecurityReplyReturnCode_rejected) {
syslog_err("[facilities] SecurityReply.verify rejected"); log_error("SecurityReply.verify rejected");
goto cleanup; goto cleanup;
} }
if (srep->data->choice.verify.report != SecurityVerifyConfirmCode_success) { if (srep->data->choice.verify.report != SecurityVerifyConfirmCode_success) {
syslog_debug("[facilities] signature verify failed"); log_debug("signature verify failed");
goto cleanup; goto cleanup;
} }
@ -1139,11 +1139,11 @@ static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_so
switch (type_rx->present) { switch (type_rx->present) {
case TollingType_PR_entry: case TollingType_PR_entry:
syslog_info("[facilities] [tolling] received entry.reply | client: %lld nonce: %ld accepted: %s", (long long) tolling->station.obu.client_id, tolling->station.obu.nonce, accepted ? "yes" : "no"); log_info("[tolling] received entry.reply | client: %lld nonce: %ld accepted: %s", (long long) tolling->station.obu.client_id, tolling->station.obu.nonce, accepted ? "yes" : "no");
break; break;
case TollingType_PR_exit: case TollingType_PR_exit:
syslog_info("[facilities] [tolling] received exit.reply | client: %lld nonce: %ld accepted: %s", (long long) tolling->station.obu.client_id, tolling->station.obu.nonce, accepted ? "yes" : "no"); log_info("[tolling] received exit.reply | client: %lld nonce: %ld accepted: %s", (long long) tolling->station.obu.client_id, tolling->station.obu.nonce, accepted ? "yes" : "no");
tolling->station.obu.toll_type = -1; tolling->station.obu.toll_type = -1;
tolling->station.obu.active = false; tolling->station.obu.active = false;
ASN_STRUCT_FREE(asn_DEF_TPM, tolling->station.obu.entry_proof); ASN_STRUCT_FREE(asn_DEF_TPM, tolling->station.obu.entry_proof);
@ -1151,7 +1151,7 @@ static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_so
break; break;
case TollingType_PR_single: case TollingType_PR_single:
syslog_info("[facilities] [tolling] received single.reply | client: %lld nonce: %ld accepted: %s", (long long) tolling->station.obu.client_id, tolling->station.obu.nonce, accepted ? "yes" : "no"); log_info("[tolling] received single.reply | client: %lld nonce: %ld accepted: %s", (long long) tolling->station.obu.client_id, tolling->station.obu.nonce, accepted ? "yes" : "no");
tolling->station.obu.toll_type = -1; tolling->station.obu.toll_type = -1;
tolling->station.obu.active = false; tolling->station.obu.active = false;
break; break;
@ -1170,12 +1170,12 @@ static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_so
sreq->present = SecurityRequest_PR_tlsClose; sreq->present = SecurityRequest_PR_tlsClose;
sreq->choice.tlsClose.connId = tlsc->id; sreq->choice.tlsClose.connId = tlsc->id;
buf[0] = 4; buf1[0] = 4;
enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf+1, buf_len-1); enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf1+1, buf_len-1);
syslog_debug("[facilities]->[security] SecurityRequest.tlsClose (%ldB)", enc.encoded+1); log_debug("[sdu]->[security] SecurityRequest.tlsClose (%ldB)", enc.encoded+1);
zmq_send(security_socket, buf, enc.encoded+1, 0); itss_0send(*security_socket, buf1, enc.encoded+1);
int32_t rl = zmq_recv(security_socket, buf, buf_len, 0); int32_t rl = itss_0recv_rt(security_socket, buf2, buf_len, buf1, enc.encoded+1, 1000);
syslog_debug("[facilities]<-[security] SecurityReply.tlsClose (%dB)", rl); log_debug("[sdu]<-[security] SecurityReply.tlsClose (%dB)", rl);
uint32_t id = rand(); uint32_t id = rand();
tr = calloc(1, sizeof(TransportRequest_t)); tr = calloc(1, sizeof(TransportRequest_t));
@ -1189,9 +1189,9 @@ static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_so
memcpy(tr->choice.data.choice.tcp.choice.connCloseReq.destinationAddress.buf, src_addr, 16); memcpy(tr->choice.data.choice.tcp.choice.connCloseReq.destinationAddress.buf, src_addr, 16);
tr->choice.data.choice.tcp.choice.connCloseReq.id = id; tr->choice.data.choice.tcp.choice.connCloseReq.id = id;
buf[0] = 4; buf1[0] = 4;
enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, buf_len-1); enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf1+1, buf_len-1);
itss_queue_send(tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, id, "TR.data.tcp.connClose"); itss_queue_send(tx_queue, buf1, enc.encoded+1, ITSS_TRANSPORT, id, "TR.data.tcp.connClose");
free(tlsc); free(tlsc);
for (int i = 0; i < tolling->protocol.c.tls.n_tlsc; ++i) { for (int i = 0; i < tolling->protocol.c.tls.n_tlsc; ++i) {
@ -1204,7 +1204,7 @@ static void veh_handle_recv(tolling_t* tolling, TPM_t* tpm_rx, void* security_so
} }
} }
} else { } else {
syslog_debug("[facilities] [tolling] unable to close TLS connection, not found"); log_debug("[tolling] unable to close TLS connection, not found");
} }
} }
@ -1214,22 +1214,22 @@ cleanup:
ASN_STRUCT_FREE(asn_DEF_SecurityReply, srep); ASN_STRUCT_FREE(asn_DEF_SecurityReply, srep);
} }
int tpm_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, uint8_t* src_addr) { int tpm_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neighbour, uint8_t* src_addr) {
tolling_t* tolling = &facilities.tolling; tolling_t* tolling = &facilities.tolling;
if (!tolling->enabled) { if (!tolling->enabled) {
syslog_debug("[facilities] [tolling] tolling is disabled"); log_debug("[tolling] tolling is disabled");
return 0; return 0;
} }
if (!tpm_rx->tpm) { if (!tpm_rx->tpm) {
syslog_err("[facilities] [tolling] received TPM does not have substructure TollingPaymentMessage"); log_error("[tolling] received TPM does not have substructure TollingPaymentMessage");
return 1; return 1;
} }
if (!tpm_rx->tpm->tollingType) { if (!tpm_rx->tpm->tollingType) {
syslog_err("[facilities] [tolling] received TPM does not have a type"); log_error("[tolling] received TPM does not have a type");
return 1; return 1;
} }
@ -1241,18 +1241,18 @@ int tpm_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, uint8_t*
switch (tpm_rx->tpm->tollingType->choice.entry.present) { switch (tpm_rx->tpm->tollingType->choice.entry.present) {
case TollingSingle_PR_request: case TollingSingle_PR_request:
if (facilities.station_type != 15) { if (facilities.station_type != 15) {
syslog_debug("[facilities] [tolling] received TPM.entry.request, ignoring"); log_debug("[tolling] received TPM.entry.request, ignoring");
goto cleanup; goto cleanup;
} }
rsu_handle_recv(tpm_rx, security_socket, neighbour, src_addr); rsu_handle_recv(tpm_rx, security_socket, neighbour, src_addr);
break; break;
case TollingSingle_PR_reply: case TollingSingle_PR_reply:
if (facilities.station_type == 15) { if (facilities.station_type == 15) {
syslog_debug("[facilities] [tolling] received TPM.entry.reply, ignoring"); log_debug("[tolling] received TPM.entry.reply, ignoring");
goto cleanup; goto cleanup;
} }
itss_time_lock(); itss_time_lock();
syslog_info("[facilities] [tolling] entry.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->station.obu.rt_init); log_info("[tolling] entry.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->station.obu.rt_init);
itss_time_unlock(); itss_time_unlock();
tolling->station.obu.rt_on = false; tolling->station.obu.rt_on = false;
veh_handle_recv(tolling, tpm_rx, security_socket, facilities.tx_queue, neighbour, src_addr); veh_handle_recv(tolling, tpm_rx, security_socket, facilities.tx_queue, neighbour, src_addr);
@ -1269,18 +1269,18 @@ int tpm_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, uint8_t*
switch (tpm_rx->tpm->tollingType->choice.exit->present) { switch (tpm_rx->tpm->tollingType->choice.exit->present) {
case TollingSingle_PR_request: case TollingSingle_PR_request:
if (facilities.station_type != 15) { if (facilities.station_type != 15) {
syslog_debug("[facilities] [tolling] received TPM.exit.request, ignoring"); log_debug("[tolling] received TPM.exit.request, ignoring");
goto cleanup; goto cleanup;
} }
rsu_handle_recv(tpm_rx, security_socket, neighbour, src_addr); rsu_handle_recv(tpm_rx, security_socket, neighbour, src_addr);
break; break;
case TollingSingle_PR_reply: case TollingSingle_PR_reply:
if (facilities.station_type == 15) { if (facilities.station_type == 15) {
syslog_debug("[facilities] [tolling] received TPM.exit.reply, ignoring"); log_debug("[tolling] received TPM.exit.reply, ignoring");
goto cleanup; goto cleanup;
} }
itss_time_lock(); itss_time_lock();
syslog_info("[facilities] [tolling] exit.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->station.obu.rt_init); log_info("[tolling] exit.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->station.obu.rt_init);
itss_time_unlock(); itss_time_unlock();
tolling->station.obu.rt_on = false; tolling->station.obu.rt_on = false;
veh_handle_recv(tolling, tpm_rx, security_socket, facilities.tx_queue, neighbour, src_addr); veh_handle_recv(tolling, tpm_rx, security_socket, facilities.tx_queue, neighbour, src_addr);
@ -1294,18 +1294,18 @@ int tpm_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, uint8_t*
switch (tpm_rx->tpm->tollingType->choice.single.present) { switch (tpm_rx->tpm->tollingType->choice.single.present) {
case TollingSingle_PR_request: case TollingSingle_PR_request:
if (facilities.station_type != 15) { if (facilities.station_type != 15) {
syslog_debug("[facilities] [tolling] received TPM.single.request, ignoring"); log_debug("[tolling] received TPM.single.request, ignoring");
goto cleanup; goto cleanup;
} }
rsu_handle_recv(tpm_rx, security_socket, neighbour, src_addr); rsu_handle_recv(tpm_rx, security_socket, neighbour, src_addr);
break; break;
case TollingSingle_PR_reply: case TollingSingle_PR_reply:
if (facilities.station_type == 15) { if (facilities.station_type == 15) {
syslog_debug("[facilities] [tolling] received TPM.single.reply, ignoring"); log_debug("[tolling] received TPM.single.reply, ignoring");
goto cleanup; goto cleanup;
} }
itss_time_lock(); itss_time_lock();
syslog_info("[facilities] [tolling] single.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->station.obu.rt_init); log_info("[tolling] single.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->station.obu.rt_init);
itss_time_unlock(); itss_time_unlock();
tolling->station.obu.rt_on = false; tolling->station.obu.rt_on = false;
veh_handle_recv(tolling, tpm_rx, security_socket, facilities.tx_queue, neighbour, src_addr); veh_handle_recv(tolling, tpm_rx, security_socket, facilities.tx_queue, neighbour, src_addr);
@ -1325,7 +1325,7 @@ cleanup:
return 0; return 0;
} }
int tolling_init(void* zmq_ctx, char* security_address, uint8_t station_type) { int tolling_init(uint8_t station_type) {
tolling_t* tolling = &facilities.tolling; tolling_t* tolling = &facilities.tolling;
pthread_mutex_init(&tolling->lock, NULL); pthread_mutex_init(&tolling->lock, NULL);
@ -1369,7 +1369,7 @@ tlsc_t* tolling_tlsc_new(uint8_t ipv6[16], uint16_t port) {
tolling_t* tolling = &facilities.tolling; tolling_t* tolling = &facilities.tolling;
syslog_debug("[tolling] new tlsc, nconns=%d", tolling->protocol.c.tls.n_tlsc); log_debug("[tolling] new tlsc, nconns=%d", tolling->protocol.c.tls.n_tlsc);
if (tolling->protocol.c.tls.n_tlsc >= TOLLING_MAX_CONNS - 1) { if (tolling->protocol.c.tls.n_tlsc >= TOLLING_MAX_CONNS - 1) {
return NULL; return NULL;
} }
@ -1387,7 +1387,7 @@ tlsc_t* tolling_tlsc_new(uint8_t ipv6[16], uint16_t port) {
tlsc_t* tolling_tlsc_get(uint8_t ipv6[16], uint16_t port) { tlsc_t* tolling_tlsc_get(uint8_t ipv6[16], uint16_t port) {
tolling_t* tolling = &facilities.tolling; tolling_t* tolling = &facilities.tolling;
syslog_debug("[tolling] new get , nconns=%d", tolling->protocol.c.tls.n_tlsc); log_debug("[tolling] new get , nconns=%d", tolling->protocol.c.tls.n_tlsc);
tlsc_t* tlsc = NULL; tlsc_t* tlsc = NULL;
for (int i = 0; i < tolling->protocol.c.tls.n_tlsc; ++i) { for (int i = 0; i < tolling->protocol.c.tls.n_tlsc; ++i) {
if (!memcmp(tolling->protocol.c.tls.tls_conns[i]->ipv6, ipv6, 16) && if (!memcmp(tolling->protocol.c.tls.tls_conns[i]->ipv6, ipv6, 16) &&
@ -1401,7 +1401,7 @@ tlsc_t* tolling_tlsc_get(uint8_t ipv6[16], uint16_t port) {
} }
void tolling_tlsc_mgmt(itss_queue_t* tx_queue, void* security_socket) { void tolling_tlsc_mgmt(itss_queue_t* tx_queue, void** security_socket) {
tolling_t* tolling = &facilities.tolling; tolling_t* tolling = &facilities.tolling;
pthread_mutex_lock(&tolling->lock); pthread_mutex_lock(&tolling->lock);
uint64_t now = itss_time_get(); uint64_t now = itss_time_get();
@ -1411,19 +1411,19 @@ void tolling_tlsc_mgmt(itss_queue_t* tx_queue, void* security_socket) {
SecurityRequest_t* sreq = NULL; SecurityRequest_t* sreq = NULL;
TransportRequest_t* tr = NULL; TransportRequest_t* tr = NULL;
const uint32_t buf_len = 1024; const uint32_t buf_len = 1024;
uint8_t buf[buf_len]; uint8_t buf1[buf_len], buf2[buf_len];
syslog_debug("[facilities] [tolling] closing TCP/TLS connection"); log_debug("[tolling] closing TCP/TLS connection");
sreq = calloc(1, sizeof(SecurityRequest_t)); sreq = calloc(1, sizeof(SecurityRequest_t));
sreq->present = SecurityRequest_PR_tlsClose; sreq->present = SecurityRequest_PR_tlsClose;
sreq->choice.tlsClose.connId = tlsc->id; sreq->choice.tlsClose.connId = tlsc->id;
buf[0] = 4; buf1[0] = 4;
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf+1, buf_len-1); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_SecurityRequest, NULL, sreq, buf1+1, buf_len-1);
syslog_debug("[facilities]->[security] SecurityRequest.tlsClose (%ldB)", enc.encoded+1); log_debug("[sdu]->[security] SecurityRequest.tlsClose (%ldB)", enc.encoded+1);
zmq_send(security_socket, buf, enc.encoded+1, 0); itss_0send(*security_socket, buf1, enc.encoded+1);
int32_t rl = zmq_recv(security_socket, buf, buf_len, 0); int32_t rl = itss_0recv_rt(security_socket, buf2, buf_len, buf1, enc.encoded+1, 1000);
syslog_debug("[facilities]<-[security] SecurityReply.tlsClose (%dB)", rl); log_debug("[sdu]<-[security] SecurityReply.tlsClose (%dB)", rl);
uint64_t id = rand() + 1; uint64_t id = rand() + 1;
tr = calloc(1, sizeof(TransportRequest_t)); tr = calloc(1, sizeof(TransportRequest_t));
@ -1437,9 +1437,9 @@ void tolling_tlsc_mgmt(itss_queue_t* tx_queue, void* security_socket) {
memcpy(tr->choice.data.choice.tcp.choice.connCloseReq.destinationAddress.buf, tlsc->ipv6, 16); memcpy(tr->choice.data.choice.tcp.choice.connCloseReq.destinationAddress.buf, tlsc->ipv6, 16);
tr->choice.data.choice.tcp.choice.connCloseReq.id = id; tr->choice.data.choice.tcp.choice.connCloseReq.id = id;
buf[0] = 4; buf1[0] = 4;
enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, buf_len-1); enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf1+1, buf_len-1);
itss_queue_send(tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, id, "TR.data.tcp.connClose"); itss_queue_send(tx_queue, buf1, enc.encoded+1, ITSS_TRANSPORT, id, "TR.data.tcp.connClose");
free(tlsc); free(tlsc);
for (int j = i; j < tolling->protocol.c.tls.n_tlsc-1; ++j) { for (int j = i; j < tolling->protocol.c.tls.n_tlsc-1; ++j) {

View File

@ -101,15 +101,11 @@ typedef struct tolling {
/** /**
* Initializes the main tolling struture * Initializes the main tolling struture
*
* @param zmq_ctx The facilities ZMQ context
* @param security_address The security service ZMQ address
* @return Always successful
*/ */
int tolling_init(void* zmq_ctx, char* security_address, uint8_t station_type); int tolling_init(uint8_t station_type);
int tpm_pay(tolling_info_t* info, void* security_socket, uint8_t* neighbour, uint8_t* dst_addr); int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, uint8_t* dst_addr);
int tpm_recv(TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, uint8_t* src_addr); int tpm_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neighbour, uint8_t* src_addr);
int tpm_should_retransmit(); int tpm_should_retransmit();
int tpm_is_inside_zone(tolling_info_t* ti); int tpm_is_inside_zone(tolling_info_t* ti);
@ -118,4 +114,4 @@ void tolling_info_free(tolling_info_t* ti);
tlsc_t* tolling_tlsc_new(uint8_t ipv6[16], uint16_t port); tlsc_t* tolling_tlsc_new(uint8_t ipv6[16], uint16_t port);
tlsc_t* tolling_tlsc_get(uint8_t ipv6[16], uint16_t port); tlsc_t* tolling_tlsc_get(uint8_t ipv6[16], uint16_t port);
void tolling_tlsc_mgmt(itss_queue_t* tx_queue, void* security_socket); void tolling_tlsc_mgmt(itss_queue_t* tx_queue, void** security_socket);

View File

@ -65,7 +65,7 @@ static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) {
bool is_req4me = false; bool is_req4me = false;
for (int i = 0; i < request->desiredTrajectories.list.count && !is_req4me; ++i) { for (int i = 0; i < request->desiredTrajectories.list.count && !is_req4me; ++i) {
for (int j = 0; j < request->desiredTrajectories.list.array[i]->affectingStations.list.count; ++j) { for (int j = 0; j < request->desiredTrajectories.list.array[i]->affectingStations.list.count; ++j) {
syslog_debug("[facilities] [vc] VCM.request meant for %lld", *request->desiredTrajectories.list.array[i]->affectingStations.list.array[j]); log_debug("[vc] VCM.request meant for %lld", *request->desiredTrajectories.list.array[i]->affectingStations.list.array[j]);
if (my_station_id == *request->desiredTrajectories.list.array[i]->affectingStations.list.array[j]) { if (my_station_id == *request->desiredTrajectories.list.array[i]->affectingStations.list.array[j]) {
is_req4me = true; is_req4me = true;
break; break;
@ -73,7 +73,7 @@ static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) {
} }
} }
if (!is_req4me) { if (!is_req4me) {
syslog_debug("[facilities] [vc] received VCM.request not affecting me"); log_debug("[vc] received VCM.request not affecting me");
return 0; return 0;
} }
@ -130,7 +130,7 @@ static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) {
// Accepted trajectory // Accepted trajectory
if (!request->desiredTrajectories.list.count) { if (!request->desiredTrajectories.list.count) {
syslog_debug("[facilities] [vc] received VCM request has no desired trajectories"); log_debug("[vc] received VCM request has no desired trajectories");
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -150,7 +150,7 @@ static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) {
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_VCM, NULL, vcm_rep, buf, buf_len); asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_VCM, NULL, vcm_rep, buf, buf_len);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [vc] VCM.reply encode failure (%s)", enc.failed_type->name); log_error("[vc] VCM.reply encode failure (%s)", enc.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -176,7 +176,7 @@ static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) {
buf[0] = 4; buf[0] = 4;
enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_TransportRequest, tr, buf+1, buf_len-1); enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_TransportRequest, tr, buf+1, buf_len-1);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [vc] TR VCM.reply encode failure (%s)", enc.failed_type->name); log_error("[vc] TR VCM.reply encode failure (%s)", enc.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -193,7 +193,7 @@ static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) {
buf[0] = 4; buf[0] = 4;
enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_FacilitiesIndication, fi, buf+1, buf_len-1); enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_FacilitiesIndication, fi, buf+1, buf_len-1);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [vc] TR VCM.reply encode failure (%s)", enc.failed_type->name); log_error("[vc] TR VCM.reply encode failure (%s)", enc.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -234,9 +234,9 @@ static int vcm_check_handle_reply(VCM_t* vcm, mc_neighbour_s* neighbour) {
itss_time_unlock(); itss_time_unlock();
if (neighbour->intersecting) { 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); log_info("[vc] received VCM.reply with %d accepted trajectories | took %ld us", reply->acceptedTrajectoriesIds.list.count, now_us-neighbour->t_iid);
} else { } else {
syslog_info("[facilities] [vc] received VCM.reply is response to another ITS-S VCM.request"); log_info("[vc] received VCM.reply is response to another ITS-S VCM.request");
} }
@ -369,11 +369,11 @@ static int vcm_check_intersection_detected(VCM_t* vcm, mc_neighbour_s* neighbour
pt->affectingStations.list.array = malloc(sizeof(void*)); pt->affectingStations.list.array = malloc(sizeof(void*));
pt->affectingStations.list.array[0] = malloc(sizeof(long long)); pt->affectingStations.list.array[0] = malloc(sizeof(long long));
*pt->affectingStations.list.array[0] = neighbour->station_id; *pt->affectingStations.list.array[0] = neighbour->station_id;
syslog_debug("[facilities] [vc] this VCM.request affects %ld", neighbour->station_id); log_debug("[vc] this VCM.request affects %ld", neighbour->station_id);
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_VCM, NULL, vcm_req, buf, buf_len); asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_VCM, NULL, vcm_req, buf, buf_len);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [vc] VCM.request encode failure (%s)", enc.failed_type->name); log_error("[vc] VCM.request encode failure (%s)", enc.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -399,7 +399,7 @@ static int vcm_check_intersection_detected(VCM_t* vcm, mc_neighbour_s* neighbour
buf[0] = 4; buf[0] = 4;
enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_TransportRequest, tr, buf+1, buf_len-1); enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_TransportRequest, tr, buf+1, buf_len-1);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [vc] TR VCM.request encode failure (%s)", enc.failed_type->name); log_error("[vc] TR VCM.request encode failure (%s)", enc.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -416,7 +416,7 @@ static int vcm_check_intersection_detected(VCM_t* vcm, mc_neighbour_s* neighbour
buf[0] = 4; buf[0] = 4;
enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_FacilitiesIndication, fi, buf+1, buf_len-1); enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_FacilitiesIndication, fi, buf+1, buf_len-1);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [vc] TR VCM.reply encode failure (%s)", enc.failed_type->name); log_error("[vc] TR VCM.reply encode failure (%s)", enc.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -533,7 +533,7 @@ int vcm_check(VCM_t* vcm) {
} }
if (intersecting) { if (intersecting) {
syslog_info("[facilities] [vc] intersection danger with %lld @ (%f, %f) in %ld ms", log_info("[vc] intersection danger with %lld @ (%f, %f) in %ld ms",
vcm->header.stationID, vcm->header.stationID,
trajectoryA[index].latitude/1.0e7, trajectoryA[index].latitude/1.0e7,
trajectoryA[index].longitude/1.0e7, trajectoryA[index].longitude/1.0e7,
@ -546,7 +546,7 @@ int vcm_check(VCM_t* vcm) {
case ManeuverContainer_PR_rsu: case ManeuverContainer_PR_rsu:
break; break;
default: default:
syslog_debug("[facilities] [vc] received VCM contains unrecognized ManeuverContainer type"); log_debug("[vc] received VCM contains unrecognized ManeuverContainer type");
rv = 1; rv = 1;
} }
@ -622,7 +622,7 @@ static int mk_vcm(uint8_t* vcm_uper, uint16_t* vcm_uper_len) {
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_VCM, NULL, vcm, vcm_uper, 512); asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_VCM, NULL, vcm, vcm_uper, 512);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] [vc] failed encoding VCM (%s)", enc.failed_type->name); log_error("[vc] failed encoding VCM (%s)", enc.failed_type->name);
rv = 1; rv = 1;
goto cleanup; goto cleanup;
} }
@ -692,7 +692,7 @@ void* vc_service() {
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, 1023); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, 1023);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] encoding TR for VCM failed"); log_error("encoding TR for VCM failed");
continue; continue;
} }
itss_queue_send(facilities.tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp"); itss_queue_send(facilities.tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp");
@ -702,7 +702,7 @@ void* vc_service() {
memcpy(fi->choice.message.data.buf, bpr->data.buf, bpr->data.size); memcpy(fi->choice.message.data.buf, bpr->data.buf, bpr->data.size);
enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_FacilitiesIndication, fi, buf+1, 1023); enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_FacilitiesIndication, fi, buf+1, 1023);
if (enc.encoded == -1) { if (enc.encoded == -1) {
syslog_err("[facilities] encoding FI for VCM failed"); log_error("encoding FI for VCM failed");
continue; continue;
} }
itss_queue_send(facilities.tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, bpr->id, "FI.message"); itss_queue_send(facilities.tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, bpr->id, "FI.message");