added managed_msg for evrsrm

This commit is contained in:
gilteixeira 2023-04-05 16:01:49 +01:00
parent 0c76b48ef6
commit a8a1509175
1 changed files with 317 additions and 237 deletions

View File

@ -19,7 +19,8 @@
#include <it2s-tender/space.h>
#include <it2s-tender/time.h>
int facilities_request_result_accepted(void* responder) {
int facilities_request_result_accepted(void *responder)
{
int rv = 0;
FacilitiesReply_t *fr = calloc(1, sizeof(FacilitiesReply_t));
@ -33,7 +34,8 @@ int facilities_request_result_accepted(void* responder) {
return rv;
}
int facilities_request_result_rejected(void* responder) {
int facilities_request_result_rejected(void *responder)
{
int rv = 0;
FacilitiesReply_t *fr = calloc(1, sizeof(FacilitiesReply_t));
@ -47,15 +49,15 @@ int facilities_request_result_rejected(void* responder) {
return rv;
}
int facilities_request_single_message(void* responder, FacilitiesMessageRequest_t* frm) {
int facilities_request_single_message(void *responder, FacilitiesMessageRequest_t *frm)
{
int rv = 0;
TransportRequest_t* tr = calloc(1, sizeof(TransportRequest_t));
TransportRequest_t *tr = calloc(1, sizeof(TransportRequest_t));
tr->present = TransportRequest_PR_packet;
TransportPacketRequest_t* tpr = &tr->choice.packet;
TransportPacketRequest_t *tpr = &tr->choice.packet;
tpr->present = TransportPacketRequest_PR_btp;
BTPPacketRequest_t* bpr = &tpr->choice.btp;
BTPPacketRequest_t *bpr = &tpr->choice.btp;
void *its_msg = NULL;
asn_TYPE_descriptor_t *its_msg_def = NULL;
@ -66,66 +68,68 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
uint32_t transmission_interval = 0;
uint64_t transmission_start = 0;
switch (frm->itsMessageType) {
case ItsMessageType_cam:
its_msg_def = &asn_DEF_CAM;
its_msg = calloc(1, sizeof(CAM_t));
bpr->destinationPort = Port_cam;
bpr->gn.packetTransportType = PacketTransportType_shb;
bpr->gn.trafficClass = 1;
switch (frm->itsMessageType)
{
case ItsMessageType_cam:
its_msg_def = &asn_DEF_CAM;
its_msg = calloc(1, sizeof(CAM_t));
bpr->destinationPort = Port_cam;
bpr->gn.packetTransportType = PacketTransportType_shb;
bpr->gn.trafficClass = 1;
break;
case ItsMessageType_denm:
its_msg_def = &asn_DEF_DENM;
its_msg = calloc(1, sizeof(DENM_t));
bpr->destinationPort = Port_denm;
bpr->gn.packetTransportType = PacketTransportType_gbc;
bpr->gn.trafficClass = 2;
break;
case ItsMessageType_denm:
its_msg_def = &asn_DEF_DENM;
its_msg = calloc(1, sizeof(DENM_t));
bpr->destinationPort = Port_denm;
bpr->gn.packetTransportType = PacketTransportType_gbc;
bpr->gn.trafficClass = 2;
break;
case ItsMessageType_ivim:
its_msg_def = &asn_DEF_IVIM;
its_msg = calloc(1, sizeof(IVIM_t));
bpr->destinationPort = Port_ivim;
bpr->gn.packetTransportType = PacketTransportType_shb;
bpr->gn.trafficClass = 1;
break;
case ItsMessageType_ivim:
its_msg_def = &asn_DEF_IVIM;
its_msg = calloc(1, sizeof(IVIM_t));
bpr->destinationPort = Port_ivim;
bpr->gn.packetTransportType = PacketTransportType_shb;
bpr->gn.trafficClass = 1;
break;
break;
case ItsMessageType_cpm:
its_msg_def = &asn_DEF_CPM;
its_msg = calloc(1, sizeof(CPM_t));
bpr->destinationPort = Port_cpm;
bpr->gn.packetTransportType = PacketTransportType_shb;
bpr->gn.trafficClass = 2;
case ItsMessageType_cpm:
its_msg_def = &asn_DEF_CPM;
its_msg = calloc(1, sizeof(CPM_t));
bpr->destinationPort = Port_cpm;
bpr->gn.packetTransportType = PacketTransportType_shb;
bpr->gn.trafficClass = 2;
break;
break;
case 2044: //VERCOe
its_msg_def = &asn_DEF_VERCOe;
its_msg = calloc(1, sizeof(VERCOe_t));
bpr->destinationPort = 2044;
bpr->gn.packetTransportType = PacketTransportType_shb;
bpr->gn.trafficClass = 2;
break;
case 2044: // VERCOe
its_msg_def = &asn_DEF_VERCOe;
its_msg = calloc(1, sizeof(VERCOe_t));
bpr->destinationPort = 2044;
bpr->gn.packetTransportType = PacketTransportType_shb;
bpr->gn.trafficClass = 2;
break;
case ItsMessageType_evrsr:
its_msg_def = &asn_DEF_EV_RSR;
its_msg = calloc(1, sizeof(EV_RSR_t));
bpr->destinationPort = Port_evrsr;
bpr->gn.packetTransportType = PacketTransportType_shb;
bpr->gn.trafficClass = 1;
break;
case ItsMessageType_evrsr:
its_msg_def = &asn_DEF_EV_RSR;
its_msg = calloc(1, sizeof(EV_RSR_t));
bpr->destinationPort = Port_evrsr;
bpr->gn.packetTransportType = PacketTransportType_shb;
bpr->gn.trafficClass = 1;
break;
default:
log_error("unrecognized FR message type (%lld)", frm->itsMessageType);
facilities_request_result_rejected(responder);
rv = 1;
goto cleanup;
default:
log_error("unrecognized FR message type (%lld)", frm->itsMessageType);
facilities_request_result_rejected(responder);
rv = 1;
goto cleanup;
}
asn_dec_rval_t dec = uper_decode_complete(NULL, its_msg_def, (void**) &its_msg, frm->data.buf, frm->data.size);
if (dec.code) {
asn_dec_rval_t dec = uper_decode_complete(NULL, its_msg_def, (void **)&its_msg, frm->data.buf, frm->data.size);
if (dec.code)
{
log_debug("invalid FR %s received", its_msg_def->name);
facilities_request_result_rejected(responder);
rv = 1;
@ -133,161 +137,204 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
}
uint64_t id = 0;
if (!frm->id) {
if (!frm->id)
{
id = itss_id(frm->data.buf, frm->data.size);
} else if (*frm->id == 0) {
}
else if (*frm->id == 0)
{
id = itss_id(frm->data.buf, frm->data.size);
}
bool is_update = false;
int managed_msg = false;
if (frm->itsMessageType == ItsMessageType_denm) {
if (frm->itsMessageType == ItsMessageType_denm)
{
managed_msg = true;
uint8_t event_type = event_manage(its_msg, &id, NULL, 0);
uint8_t event_type = event_manage(its_msg, &id, NULL, 0);
// Do not free its_msg! event_manage takes care of the msg
// id will get set to another val if EVENT NEW or UPDATE or CANCELLATION or NEGATION
if (event_type != EVENT_NEW &&
event_type != EVENT_UPDATE &&
event_type != EVENT_CANCELLATION &&
event_type != EVENT_NEGATION) {
event_type != EVENT_UPDATE &&
event_type != EVENT_CANCELLATION &&
event_type != EVENT_NEGATION)
{
fwd = false;
}
if (event_type == EVENT_UPDATE ||
event_type == EVENT_CANCELLATION ||
event_type == EVENT_NEGATION) {
event_type == EVENT_CANCELLATION ||
event_type == EVENT_NEGATION)
{
is_update = true;
}
if (fwd) {
if (fwd)
{
// set stationID
pthread_mutex_lock(&facilities.id.lock);
((DENM_t*)its_msg)->header.stationID = facilities.id.station_id;
((DENM_t *)its_msg)->header.stationID = facilities.id.station_id;
pthread_mutex_unlock(&facilities.id.lock);
// Set only one trace
if (facilities.station_type != 15) {
if (facilities.station_type != 15)
{
pthread_mutex_lock(&facilities.lightship.lock);
if (facilities.lightship.path_history_len > 0) {
if (facilities.lightship.path_history_len > 0)
{
if (!((DENM_t*)its_msg)->denm.location) {
((DENM_t*)its_msg)->denm.location = calloc(1, sizeof(LocationContainer_t));
if (!((DENM_t *)its_msg)->denm.location)
{
((DENM_t *)its_msg)->denm.location = calloc(1, sizeof(LocationContainer_t));
}
((DENM_t*)its_msg)->denm.location->traces.list.count = 1;
((DENM_t*)its_msg)->denm.location->traces.list.size = 1 * sizeof(void*);
((DENM_t*)its_msg)->denm.location->traces.list.array = malloc(1 * sizeof(void*));
((DENM_t*)its_msg)->denm.location->traces.list.array[0] = calloc(1, sizeof(PathHistory_t));
PathHistory_t* ph = ((DENM_t*)its_msg)->denm.location->traces.list.array[0];
((DENM_t *)its_msg)->denm.location->traces.list.count = 1;
((DENM_t *)its_msg)->denm.location->traces.list.size = 1 * sizeof(void *);
((DENM_t *)its_msg)->denm.location->traces.list.array = malloc(1 * sizeof(void *));
((DENM_t *)its_msg)->denm.location->traces.list.array[0] = calloc(1, sizeof(PathHistory_t));
PathHistory_t *ph = ((DENM_t *)its_msg)->denm.location->traces.list.array[0];
pos_point_t** path_history = facilities.lightship.path_history;
pos_point_t **path_history = facilities.lightship.path_history;
uint16_t path_history_len = facilities.lightship.path_history_len;
ph->list.array = malloc((path_history_len) * sizeof(void*));
ph->list.array = malloc((path_history_len) * sizeof(void *));
ph->list.count = path_history_len;
ph->list.size = (path_history_len) * sizeof(void*);
ph->list.size = (path_history_len) * sizeof(void *);
ph->list.array[0] = calloc(1,sizeof(PathPoint_t));
ph->list.array[0] = calloc(1, sizeof(PathPoint_t));
itss_space_lock();
if (path_history[0]->alt != AltitudeValue_unavailable && epv.space.altitude != AltitudeValue_unavailable) {
if (path_history[0]->alt != AltitudeValue_unavailable && epv.space.altitude != AltitudeValue_unavailable)
{
ph->list.array[0]->pathPosition.deltaAltitude = path_history[0]->alt - epv.space.altitude;
} else {
}
else
{
ph->list.array[0]->pathPosition.deltaAltitude = DeltaAltitude_unavailable;
}
if (path_history[0]->lat != Latitude_unavailable && epv.space.latitude != Latitude_unavailable) {
if (path_history[0]->lat != Latitude_unavailable && epv.space.latitude != Latitude_unavailable)
{
ph->list.array[0]->pathPosition.deltaLatitude = path_history[0]->lat - epv.space.latitude;
} else {
}
else
{
ph->list.array[0]->pathPosition.deltaLatitude = DeltaLatitude_unavailable;
}
if (path_history[0]->lon != Longitude_unavailable && epv.space.longitude != Longitude_unavailable) {
ph->list.array[0]->pathPosition.deltaLongitude =path_history[0]->lon - epv.space.longitude;
} else {
if (path_history[0]->lon != Longitude_unavailable && epv.space.longitude != Longitude_unavailable)
{
ph->list.array[0]->pathPosition.deltaLongitude = path_history[0]->lon - epv.space.longitude;
}
else
{
ph->list.array[0]->pathPosition.deltaLongitude = DeltaLongitude_unavailable;
}
itss_space_unlock();
ph->list.array[0]->pathDeltaTime = calloc(1,sizeof(PathDeltaTime_t));
*ph->list.array[0]->pathDeltaTime = (itss_time_get() - path_history[0]->ts)/10;
ph->list.array[0]->pathDeltaTime = calloc(1, sizeof(PathDeltaTime_t));
*ph->list.array[0]->pathDeltaTime = (itss_time_get() - path_history[0]->ts) / 10;
for (int i = 1; i < path_history_len; ++i) {
ph->list.array[i] = calloc(1,sizeof(PathPoint_t));
for (int i = 1; i < path_history_len; ++i)
{
ph->list.array[i] = calloc(1, sizeof(PathPoint_t));
if (path_history[i]->alt != AltitudeValue_unavailable && path_history[i-1]->alt != AltitudeValue_unavailable) {
ph->list.array[i]->pathPosition.deltaAltitude = path_history[i]->alt - path_history[i-1]->alt;
} else {
if (path_history[i]->alt != AltitudeValue_unavailable && path_history[i - 1]->alt != AltitudeValue_unavailable)
{
ph->list.array[i]->pathPosition.deltaAltitude = path_history[i]->alt - path_history[i - 1]->alt;
}
else
{
ph->list.array[i]->pathPosition.deltaAltitude = DeltaAltitude_unavailable;
}
if (path_history[i]->lat != Latitude_unavailable && path_history[i-1]->lat != Latitude_unavailable) {
ph->list.array[i]->pathPosition.deltaLatitude = path_history[i]->lat - path_history[i-1]->lat;
} else {
if (path_history[i]->lat != Latitude_unavailable && path_history[i - 1]->lat != Latitude_unavailable)
{
ph->list.array[i]->pathPosition.deltaLatitude = path_history[i]->lat - path_history[i - 1]->lat;
}
else
{
ph->list.array[i]->pathPosition.deltaLatitude = DeltaLatitude_unavailable;
}
if (path_history[i]->lon != Longitude_unavailable && path_history[i-1]->lon != Longitude_unavailable) {
ph->list.array[i]->pathPosition.deltaLongitude = path_history[i]->lon - path_history[i-1]->lon;
} else {
if (path_history[i]->lon != Longitude_unavailable && path_history[i - 1]->lon != Longitude_unavailable)
{
ph->list.array[i]->pathPosition.deltaLongitude = path_history[i]->lon - path_history[i - 1]->lon;
}
else
{
ph->list.array[i]->pathPosition.deltaLongitude = DeltaLongitude_unavailable;
}
ph->list.array[i]->pathDeltaTime = calloc(1,sizeof(PathDeltaTime_t));
*ph->list.array[i]->pathDeltaTime = (path_history[i-1]->ts - path_history[i]->ts)/10;
ph->list.array[i]->pathDeltaTime = calloc(1, sizeof(PathDeltaTime_t));
*ph->list.array[i]->pathDeltaTime = (path_history[i - 1]->ts - path_history[i]->ts) / 10;
}
}
pthread_mutex_unlock(&facilities.lightship.lock);
}
// get, set retransmission, duration
if ( ((DENM_t*)its_msg)->denm.management.transmissionInterval ) {
transmission_interval = *( (uint32_t*) ((DENM_t*)its_msg)->denm.management.transmissionInterval );
if (((DENM_t *)its_msg)->denm.management.transmissionInterval)
{
transmission_interval = *((uint32_t *)((DENM_t *)its_msg)->denm.management.transmissionInterval);
if ( ((DENM_t*)its_msg)->denm.management.validityDuration ) {
transmission_duration = *( (uint32_t*) ((DENM_t*)its_msg)->denm.management.validityDuration ) * 1000;
} else {
if (((DENM_t *)its_msg)->denm.management.validityDuration)
{
transmission_duration = *((uint32_t *)((DENM_t *)its_msg)->denm.management.validityDuration) * 1000;
}
else
{
transmission_duration = 600 * 1000;
}
}
}
} else if (frm->itsMessageType == ItsMessageType_ivim) {
}
else if (frm->itsMessageType == ItsMessageType_ivim)
{
managed_msg = true;
uint8_t service_type = service_eval(SERVICE_IVI, its_msg, &id, NULL, 0);
uint8_t service_type = service_eval(SERVICE_IVI, its_msg, &id, NULL, 0);
if (service_type != SERVICE_NEW &&
service_type != SERVICE_UPDATE &&
service_type != SERVICE_CANCELLATION &&
service_type != SERVICE_NEGATION) {
service_type != SERVICE_UPDATE &&
service_type != SERVICE_CANCELLATION &&
service_type != SERVICE_NEGATION)
{
fwd = false;
}
if (service_type == SERVICE_UPDATE ||
service_type == SERVICE_CANCELLATION ||
service_type == SERVICE_NEGATION) {
service_type == SERVICE_CANCELLATION ||
service_type == SERVICE_NEGATION)
{
is_update = true;
}
if (fwd) {
if (fwd)
{
uint64_t valid_to, valid_from;
if (!((IVIM_t*) its_msg)->ivi.mandatory.validFrom) {
if (!((IVIM_t *)its_msg)->ivi.mandatory.validFrom)
{
valid_from = itss_time_get();
} else {
asn_INTEGER2ulong((INTEGER_t*) ((IVIM_t*) its_msg)->ivi.mandatory.validFrom, (unsigned long long*) &valid_from);
}
else
{
asn_INTEGER2ulong((INTEGER_t *)((IVIM_t *)its_msg)->ivi.mandatory.validFrom, (unsigned long long *)&valid_from);
}
if (!((IVIM_t*) its_msg)->ivi.mandatory.validTo) {
if (!((IVIM_t *)its_msg)->ivi.mandatory.validTo)
{
valid_to = valid_from + facilities.infrastructure.default_service_duration;
} else {
asn_INTEGER2ulong((INTEGER_t*) ((IVIM_t*) its_msg)->ivi.mandatory.validTo, (unsigned long long*) &valid_to);
}
else
{
asn_INTEGER2ulong((INTEGER_t *)((IVIM_t *)its_msg)->ivi.mandatory.validTo, (unsigned long long *)&valid_to);
}
transmission_start = valid_from;
@ -295,8 +342,11 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
transmission_duration = valid_to - valid_from;
}
}
if (!facilities.replay) {
else if (frm->itsMessageType == ItsMessageType_evrsr) {
managed_msg = true;
}
if (!facilities.replay)
{
transmission_interval = 0;
transmission_duration = 0;
}
@ -305,14 +355,16 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
facilities_request_result_accepted(responder);
// Forward message to [transport]
if (fwd) {
if (fwd)
{
bpr->btpType = BTPType_btpB;
bpr->id = id;
bpr->data.buf = malloc(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)
{
log_error("failed encoding ITS message into UPER (%s)", enc.failed_type->name);
rv = 1;
goto cleanup;
@ -320,25 +372,30 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
bpr->data.size = (enc.encoded + 7) / 8;
bpr->gn.destinationAddress.buf = malloc(6);
for (int i = 0; i < 6; ++i) bpr->gn.destinationAddress.buf[i] = 0xff;
for (int i = 0; i < 6; ++i)
bpr->gn.destinationAddress.buf[i] = 0xff;
bpr->gn.destinationAddress.size = 6;
if (transmission_start) {
if (transmission_start)
{
bpr->gn.repetitionStart = malloc(sizeof(long));
*bpr->gn.repetitionStart = transmission_start;
}
if (transmission_interval) {
if (transmission_interval)
{
bpr->gn.repetitionInterval = malloc(sizeof(long));
*bpr->gn.repetitionInterval = transmission_interval;
}
if (transmission_duration) {
if (transmission_duration)
{
bpr->gn.maximumRepetitionTime = malloc(sizeof(long));
*bpr->gn.maximumRepetitionTime = transmission_duration;
}
if (is_update) {
if (is_update)
{
bpr->gn.isUpdate = malloc(sizeof(long));
*bpr->gn.isUpdate = 1;
}
@ -348,45 +405,50 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
uint8_t tr_oer[2048];
tr_oer[0] = 4; // [facilities] service id
enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, tr_oer + 1, 2047);
if (enc.encoded == -1) {
if (enc.encoded == -1)
{
log_error("failed encoding TR (%s)", enc.failed_type->name);
rv = 1;
goto cleanup;
}
itss_queue_send(facilities.tx_queue, tr_oer, enc.encoded+1, ITSS_TRANSPORT, id, "TR.packet.btp");
itss_queue_send(facilities.tx_queue, tr_oer, enc.encoded + 1, ITSS_TRANSPORT, id, "TR.packet.btp");
}
// Logging
if (facilities.logging.recorder) {
if (facilities.logging.recorder)
{
uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len];
int e = itss_management_record_packet_sdu(
buffer,
buffer_len,
frm->data.buf,
frm->data.size,
id,
itss_time_get(),
ITSS_FACILITIES,
true);
if (e != -1) {
itss_queue_send(facilities.tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set");
buffer,
buffer_len,
frm->data.buf,
frm->data.size,
id,
itss_time_get(),
ITSS_FACILITIES,
true);
if (e != -1)
{
itss_queue_send(facilities.tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set");
}
}
cleanup:
if (its_msg_def && !managed_msg) ASN_STRUCT_FREE(*its_msg_def, its_msg);
if (its_msg_def && !managed_msg)
ASN_STRUCT_FREE(*its_msg_def, its_msg);
ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr);
return rv;
}
int facilities_request_active_episodes(void* responder, FacilitiesRequest_t* freq) {
int facilities_request_active_episodes(void *responder, FacilitiesRequest_t *freq)
{
int rv = 0;
FacilitiesReply_t* frep = calloc(1, sizeof(FacilitiesReply_t));
uint8_t* frep_oer = NULL;
FacilitiesReply_t *frep = calloc(1, sizeof(FacilitiesReply_t));
uint8_t *frep_oer = NULL;
frep->present = FacilitiesReply_PR_data;
frep->choice.data.present = FacilitiesDataReply_PR_episodes;
@ -399,14 +461,16 @@ int facilities_request_active_episodes(void* responder, FacilitiesRequest_t* fre
uint16_t na = 0;
for (int e = 0; e < freq->choice.data.choice.activeEpisodes.list.count; ++e) {
switch (*freq->choice.data.choice.activeEpisodes.list.array[e]) {
case EpisodeType_denm:
na += nae;
break;
case EpisodeType_ivim:
na += nas;
break;
for (int e = 0; e < freq->choice.data.choice.activeEpisodes.list.count; ++e)
{
switch (*freq->choice.data.choice.activeEpisodes.list.array[e])
{
case EpisodeType_denm:
na += nae;
break;
case EpisodeType_ivim:
na += nas;
break;
}
}
@ -414,52 +478,60 @@ int facilities_request_active_episodes(void* responder, FacilitiesRequest_t* fre
frep->choice.data.choice.episodes.list.size = na * sizeof(void *);
frep->choice.data.choice.episodes.list.array = malloc(na * sizeof(void *));
for (int e = 0, j = 0; e < freq->choice.data.choice.activeEpisodes.list.count; ++e) {
switch (*freq->choice.data.choice.activeEpisodes.list.array[e]) {
case EpisodeType_denm:
for (int i = 0, n = 0; n < nae; ++i) {
if (facilities.den.events[i]->enabled && facilities.den.events[i]->state == EVENT_ACTIVE) {
frep->choice.data.choice.episodes.list.array[j] = calloc(1, sizeof(ItsMessage_t));
frep->choice.data.choice.episodes.list.array[j]->itsMessageType = ItsMessageType_denm;
frep->choice.data.choice.episodes.list.array[j]->data.buf = malloc(2048);
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_DENM, NULL, facilities.den.events[i]->denm, frep->choice.data.choice.episodes.list.array[j]->data.buf, 2048);
if (enc.encoded == -1) { /* encoding shouldn't fail as all saved DENMs are structurally valid */
log_error("failed encoding DENM for FDResult (%s)", enc.failed_type->name);
frep->choice.data.choice.episodes.list.array[j]->data.size = 0;
continue;
}
frep->choice.data.choice.episodes.list.array[j]->data.size = (enc.encoded + 7) / 8;
++j;
++n;
for (int e = 0, j = 0; e < freq->choice.data.choice.activeEpisodes.list.count; ++e)
{
switch (*freq->choice.data.choice.activeEpisodes.list.array[e])
{
case EpisodeType_denm:
for (int i = 0, n = 0; n < nae; ++i)
{
if (facilities.den.events[i]->enabled && facilities.den.events[i]->state == EVENT_ACTIVE)
{
frep->choice.data.choice.episodes.list.array[j] = calloc(1, sizeof(ItsMessage_t));
frep->choice.data.choice.episodes.list.array[j]->itsMessageType = ItsMessageType_denm;
frep->choice.data.choice.episodes.list.array[j]->data.buf = malloc(2048);
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_DENM, NULL, facilities.den.events[i]->denm, frep->choice.data.choice.episodes.list.array[j]->data.buf, 2048);
if (enc.encoded == -1)
{ /* encoding shouldn't fail as all saved DENMs are structurally valid */
log_error("failed encoding DENM for FDResult (%s)", enc.failed_type->name);
frep->choice.data.choice.episodes.list.array[j]->data.size = 0;
continue;
}
frep->choice.data.choice.episodes.list.array[j]->data.size = (enc.encoded + 7) / 8;
++j;
++n;
}
break;
case EpisodeType_ivim:
for (int i = 0, n = 0; n < nas; ++i) {
if (facilities.infrastructure.services[i]->enabled && facilities.infrastructure.services[i]->state == SERVICE_ACTIVE) {
frep->choice.data.choice.episodes.list.array[j] = calloc(1, sizeof(ItsMessage_t));
frep->choice.data.choice.episodes.list.array[j]->itsMessageType = ItsMessageType_ivim;
frep->choice.data.choice.episodes.list.array[j]->data.buf = malloc(2048);
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_IVIM, NULL, facilities.infrastructure.services[i]->ivim, frep->choice.data.choice.episodes.list.array[j]->data.buf, 2048);
if (enc.encoded == -1) { /* encoding shouldn't fail as all saved DENMs are structurally valid */
log_error("failed encoding IVIM for FDResult (%s)", enc.failed_type->name);
frep->choice.data.choice.episodes.list.array[j]->data.size = 0;
continue;
}
frep->choice.data.choice.episodes.list.array[j]->data.size = (enc.encoded + 7) / 8;
++j;
++n;
}
break;
case EpisodeType_ivim:
for (int i = 0, n = 0; n < nas; ++i)
{
if (facilities.infrastructure.services[i]->enabled && facilities.infrastructure.services[i]->state == SERVICE_ACTIVE)
{
frep->choice.data.choice.episodes.list.array[j] = calloc(1, sizeof(ItsMessage_t));
frep->choice.data.choice.episodes.list.array[j]->itsMessageType = ItsMessageType_ivim;
frep->choice.data.choice.episodes.list.array[j]->data.buf = malloc(2048);
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_IVIM, NULL, facilities.infrastructure.services[i]->ivim, frep->choice.data.choice.episodes.list.array[j]->data.buf, 2048);
if (enc.encoded == -1)
{ /* encoding shouldn't fail as all saved DENMs are structurally valid */
log_error("failed encoding IVIM for FDResult (%s)", enc.failed_type->name);
frep->choice.data.choice.episodes.list.array[j]->data.size = 0;
continue;
}
frep->choice.data.choice.episodes.list.array[j]->data.size = (enc.encoded + 7) / 8;
++j;
++n;
}
break;
default:
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.infrastructure.lock);
}
break;
default:
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.infrastructure.lock);
facilities_request_result_rejected(responder);
rv = 1;
goto cleanup;
facilities_request_result_rejected(responder);
rv = 1;
goto cleanup;
}
}
@ -468,7 +540,8 @@ int facilities_request_active_episodes(void* responder, FacilitiesRequest_t* fre
frep_oer = malloc(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)
{
log_error("failed encoding FReply (%s)", enc.failed_type->name);
facilities_request_result_rejected(responder);
@ -485,38 +558,42 @@ cleanup:
return rv;
}
int facilities_request_attribute_types(void* responder, FacilitiesRequest_t* freq) {
int facilities_request_attribute_types(void *responder, FacilitiesRequest_t *freq)
{
int rv = 0;
FacilitiesReply_t* frep = calloc(1, sizeof(FacilitiesReply_t));
FacilitiesReply_t *frep = calloc(1, sizeof(FacilitiesReply_t));
frep->present = FacilitiesReply_PR_data;
int nra = freq->choice.data.choice.attributeTypes.list.count;
frep->choice.data.present = FacilitiesDataReply_PR_attributes;
frep->choice.data.choice.attributes.list.count = nra;
frep->choice.data.choice.attributes.list.size = sizeof(void*) * nra;
frep->choice.data.choice.attributes.list.array = malloc(sizeof(void*) * nra);
for (int j = 0; j < nra; ++j) {
switch (*freq->choice.data.choice.attributeTypes.list.array[j]) {
case FacilitiesAttributeType_stationId:
frep->choice.data.choice.attributes.list.array[j] = calloc(1, sizeof(FacilitiesAttribute_t) );
frep->choice.data.choice.attributes.list.array[j]->data.size = 8;
frep->choice.data.choice.attributes.list.array[j]->data.buf = malloc(8);
pthread_mutex_lock(&facilities.id.lock);
*((uint64_t*) frep->choice.data.choice.attributes.list.array[j]->data.buf) = facilities.id.station_id;
pthread_mutex_unlock(&facilities.id.lock);
break;
frep->choice.data.choice.attributes.list.size = sizeof(void *) * nra;
frep->choice.data.choice.attributes.list.array = malloc(sizeof(void *) * nra);
for (int j = 0; j < nra; ++j)
{
switch (*freq->choice.data.choice.attributeTypes.list.array[j])
{
case FacilitiesAttributeType_stationId:
frep->choice.data.choice.attributes.list.array[j] = calloc(1, sizeof(FacilitiesAttribute_t));
frep->choice.data.choice.attributes.list.array[j]->data.size = 8;
frep->choice.data.choice.attributes.list.array[j]->data.buf = malloc(8);
pthread_mutex_lock(&facilities.id.lock);
*((uint64_t *)frep->choice.data.choice.attributes.list.array[j]->data.buf) = facilities.id.station_id;
pthread_mutex_unlock(&facilities.id.lock);
break;
default:
log_debug("unrecognized FR attribute type request");
facilities_request_result_rejected(responder);
rv = 1;
goto cleanup;
default:
log_debug("unrecognized FR attribute type request");
facilities_request_result_rejected(responder);
rv = 1;
goto cleanup;
}
}
}
uint8_t 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)
{
log_error("failed encoding FReply (%s)", enc.failed_type->name);
facilities_request_result_rejected(responder);
rv = 1;
@ -531,11 +608,11 @@ cleanup:
return rv;
}
int facilities_request_loaded_protected_zones(void* responder, FacilitiesRequest_t* freq) {
int facilities_request_loaded_protected_zones(void *responder, FacilitiesRequest_t *freq)
{
int rv = 0;
FacilitiesReply_t* frep = calloc(1, sizeof(FacilitiesReply_t));
FacilitiesReply_t *frep = calloc(1, sizeof(FacilitiesReply_t));
frep->present = FacilitiesReply_PR_data;
frep->choice.data.present = FacilitiesDataReply_PR_protectedCommunicationZones;
@ -543,21 +620,23 @@ int facilities_request_loaded_protected_zones(void* responder, FacilitiesRequest
pthread_mutex_lock(&facilities.lightship.lock);
frep->choice.data.choice.protectedCommunicationZones.list.count = facilities.lightship.protected_zones.pz_len;
frep->choice.data.choice.protectedCommunicationZones.list.size = facilities.lightship.protected_zones.pz_len * sizeof(void*);
frep->choice.data.choice.protectedCommunicationZones.list.array = malloc(facilities.lightship.protected_zones.pz_len * sizeof(void*));
frep->choice.data.choice.protectedCommunicationZones.list.size = facilities.lightship.protected_zones.pz_len * sizeof(void *);
frep->choice.data.choice.protectedCommunicationZones.list.array = malloc(facilities.lightship.protected_zones.pz_len * sizeof(void *));
uint8_t buf[256];
for (int z = 0; z < facilities.lightship.protected_zones.pz_len; ++z) {
for (int z = 0; z < facilities.lightship.protected_zones.pz_len; ++z)
{
frep->choice.data.choice.protectedCommunicationZones.list.array[z] = calloc(1, sizeof(ProtectedCommunicationZone_t));
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_ProtectedCommunicationZone, NULL, facilities.lightship.protected_zones.pz[z], buf, 256);
uper_decode_complete(NULL, &asn_DEF_ProtectedCommunicationZone, (void**) &frep->choice.data.choice.protectedCommunicationZones.list.array[z], buf, (enc.encoded+7) / 8);
uper_decode_complete(NULL, &asn_DEF_ProtectedCommunicationZone, (void **)&frep->choice.data.choice.protectedCommunicationZones.list.array[z], buf, (enc.encoded + 7) / 8);
}
pthread_mutex_unlock(&facilities.lightship.lock);
uint8_t 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)
{
log_error("failed encoding FDResult (%s)", enc.failed_type->name);
facilities_request_result_rejected(responder);
rv = 1;
@ -572,30 +651,32 @@ cleanup:
return rv;
}
int facilities_request_chaininfo_set(void* responder, ChainInformationSet_t* cis) {
int facilities_request_chaininfo_set(void *responder, ChainInformationSet_t *cis)
{
int rv = 0;
pthread_mutex_lock(&facilities.coordination.lock);
facilities.coordination.chain.id = cis->idSet;
for (int i = 0; i < cis->linkSet.list.count; ++i) {
for (int i = 0; i < cis->linkSet.list.count; ++i)
{
memcpy(
facilities.coordination.chain.links[i],
cis->linkSet.list.array[i]->buf,
cis->linkSet.list.array[i]->size
);
facilities.coordination.chain.links[i],
cis->linkSet.list.array[i]->buf,
cis->linkSet.list.array[i]->size);
}
facilities.coordination.chain.n_links = cis->linkSet.list.count;
// TODO region
pthread_mutex_unlock(&facilities.coordination.lock);
FacilitiesReply_t* frep = calloc(1, sizeof(FacilitiesReply_t));
FacilitiesReply_t *frep = calloc(1, sizeof(FacilitiesReply_t));
frep->present = FacilitiesReply_PR_data;
frep->choice.data.present = FacilitiesDataReply_PR_chainInfoSet;
frep->choice.data.choice.chainInfoSet = FacilitiesResultCode_accepted;
uint8_t 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)
{
log_error("failed encoding FDResult (%s)", enc.failed_type->name);
facilities_request_result_rejected(responder);
rv = 1;
@ -609,4 +690,3 @@ cleanup:
return rv;
}