added managed_msg for evrsrm
This commit is contained in:
parent
0c76b48ef6
commit
a8a1509175
238
src/requests.c
238
src/requests.c
|
|
@ -19,7 +19,8 @@
|
||||||
#include <it2s-tender/space.h>
|
#include <it2s-tender/space.h>
|
||||||
#include <it2s-tender/time.h>
|
#include <it2s-tender/time.h>
|
||||||
|
|
||||||
int facilities_request_result_accepted(void* responder) {
|
int facilities_request_result_accepted(void *responder)
|
||||||
|
{
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
FacilitiesReply_t *fr = calloc(1, sizeof(FacilitiesReply_t));
|
FacilitiesReply_t *fr = calloc(1, sizeof(FacilitiesReply_t));
|
||||||
|
|
@ -33,7 +34,8 @@ int facilities_request_result_accepted(void* responder) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
int facilities_request_result_rejected(void* responder) {
|
int facilities_request_result_rejected(void *responder)
|
||||||
|
{
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
FacilitiesReply_t *fr = calloc(1, sizeof(FacilitiesReply_t));
|
FacilitiesReply_t *fr = calloc(1, sizeof(FacilitiesReply_t));
|
||||||
|
|
@ -47,10 +49,10 @@ int facilities_request_result_rejected(void* responder) {
|
||||||
return rv;
|
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;
|
int rv = 0;
|
||||||
|
|
||||||
|
|
||||||
TransportRequest_t *tr = calloc(1, sizeof(TransportRequest_t));
|
TransportRequest_t *tr = calloc(1, sizeof(TransportRequest_t));
|
||||||
tr->present = TransportRequest_PR_packet;
|
tr->present = TransportRequest_PR_packet;
|
||||||
TransportPacketRequest_t *tpr = &tr->choice.packet;
|
TransportPacketRequest_t *tpr = &tr->choice.packet;
|
||||||
|
|
@ -66,7 +68,8 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
|
||||||
uint32_t transmission_interval = 0;
|
uint32_t transmission_interval = 0;
|
||||||
uint64_t transmission_start = 0;
|
uint64_t transmission_start = 0;
|
||||||
|
|
||||||
switch (frm->itsMessageType) {
|
switch (frm->itsMessageType)
|
||||||
|
{
|
||||||
case ItsMessageType_cam:
|
case ItsMessageType_cam:
|
||||||
its_msg_def = &asn_DEF_CAM;
|
its_msg_def = &asn_DEF_CAM;
|
||||||
its_msg = calloc(1, sizeof(CAM_t));
|
its_msg = calloc(1, sizeof(CAM_t));
|
||||||
|
|
@ -125,7 +128,8 @@ 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)
|
||||||
|
{
|
||||||
log_debug("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;
|
||||||
|
|
@ -133,16 +137,20 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t id = 0;
|
uint64_t id = 0;
|
||||||
if (!frm->id) {
|
if (!frm->id)
|
||||||
|
{
|
||||||
id = itss_id(frm->data.buf, frm->data.size);
|
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);
|
id = itss_id(frm->data.buf, frm->data.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_update = false;
|
bool is_update = false;
|
||||||
|
|
||||||
int managed_msg = false;
|
int managed_msg = false;
|
||||||
if (frm->itsMessageType == ItsMessageType_denm) {
|
if (frm->itsMessageType == ItsMessageType_denm)
|
||||||
|
{
|
||||||
managed_msg = true;
|
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);
|
||||||
|
|
@ -151,30 +159,36 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
|
||||||
if (event_type != EVENT_NEW &&
|
if (event_type != EVENT_NEW &&
|
||||||
event_type != EVENT_UPDATE &&
|
event_type != EVENT_UPDATE &&
|
||||||
event_type != EVENT_CANCELLATION &&
|
event_type != EVENT_CANCELLATION &&
|
||||||
event_type != EVENT_NEGATION) {
|
event_type != EVENT_NEGATION)
|
||||||
|
{
|
||||||
|
|
||||||
fwd = false;
|
fwd = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event_type == EVENT_UPDATE ||
|
if (event_type == EVENT_UPDATE ||
|
||||||
event_type == EVENT_CANCELLATION ||
|
event_type == EVENT_CANCELLATION ||
|
||||||
event_type == EVENT_NEGATION) {
|
event_type == EVENT_NEGATION)
|
||||||
|
{
|
||||||
|
|
||||||
is_update = true;
|
is_update = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fwd) {
|
if (fwd)
|
||||||
|
{
|
||||||
// set stationID
|
// set stationID
|
||||||
pthread_mutex_lock(&facilities.id.lock);
|
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);
|
pthread_mutex_unlock(&facilities.id.lock);
|
||||||
|
|
||||||
// Set only one trace
|
// Set only one trace
|
||||||
if (facilities.station_type != 15) {
|
if (facilities.station_type != 15)
|
||||||
|
{
|
||||||
pthread_mutex_lock(&facilities.lightship.lock);
|
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) {
|
if (!((DENM_t *)its_msg)->denm.location)
|
||||||
|
{
|
||||||
((DENM_t *)its_msg)->denm.location = calloc(1, sizeof(LocationContainer_t));
|
((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.count = 1;
|
||||||
|
|
@ -193,21 +207,30 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
|
||||||
ph->list.array[0] = calloc(1, sizeof(PathPoint_t));
|
ph->list.array[0] = calloc(1, sizeof(PathPoint_t));
|
||||||
|
|
||||||
itss_space_lock();
|
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;
|
ph->list.array[0]->pathPosition.deltaAltitude = path_history[0]->alt - epv.space.altitude;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ph->list.array[0]->pathPosition.deltaAltitude = DeltaAltitude_unavailable;
|
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;
|
ph->list.array[0]->pathPosition.deltaLatitude = path_history[0]->lat - epv.space.latitude;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ph->list.array[0]->pathPosition.deltaLatitude = DeltaLatitude_unavailable;
|
ph->list.array[0]->pathPosition.deltaLatitude = DeltaLatitude_unavailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path_history[0]->lon != Longitude_unavailable && epv.space.longitude != Longitude_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;
|
ph->list.array[0]->pathPosition.deltaLongitude = path_history[0]->lon - epv.space.longitude;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ph->list.array[0]->pathPosition.deltaLongitude = DeltaLongitude_unavailable;
|
ph->list.array[0]->pathPosition.deltaLongitude = DeltaLongitude_unavailable;
|
||||||
}
|
}
|
||||||
itss_space_unlock();
|
itss_space_unlock();
|
||||||
|
|
@ -215,47 +238,62 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
|
||||||
ph->list.array[0]->pathDeltaTime = calloc(1, sizeof(PathDeltaTime_t));
|
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 = (itss_time_get() - path_history[0]->ts) / 10;
|
||||||
|
|
||||||
for (int i = 1; i < path_history_len; ++i) {
|
for (int i = 1; i < path_history_len; ++i)
|
||||||
|
{
|
||||||
ph->list.array[i] = calloc(1, sizeof(PathPoint_t));
|
ph->list.array[i] = calloc(1, sizeof(PathPoint_t));
|
||||||
|
|
||||||
if (path_history[i]->alt != AltitudeValue_unavailable && path_history[i-1]->alt != AltitudeValue_unavailable) {
|
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;
|
ph->list.array[i]->pathPosition.deltaAltitude = path_history[i]->alt - path_history[i - 1]->alt;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ph->list.array[i]->pathPosition.deltaAltitude = DeltaAltitude_unavailable;
|
ph->list.array[i]->pathPosition.deltaAltitude = DeltaAltitude_unavailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path_history[i]->lat != Latitude_unavailable && path_history[i-1]->lat != Latitude_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;
|
ph->list.array[i]->pathPosition.deltaLatitude = path_history[i]->lat - path_history[i - 1]->lat;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ph->list.array[i]->pathPosition.deltaLatitude = DeltaLatitude_unavailable;
|
ph->list.array[i]->pathPosition.deltaLatitude = DeltaLatitude_unavailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path_history[i]->lon != Longitude_unavailable && path_history[i-1]->lon != Longitude_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;
|
ph->list.array[i]->pathPosition.deltaLongitude = path_history[i]->lon - path_history[i - 1]->lon;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ph->list.array[i]->pathPosition.deltaLongitude = DeltaLongitude_unavailable;
|
ph->list.array[i]->pathPosition.deltaLongitude = DeltaLongitude_unavailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
ph->list.array[i]->pathDeltaTime = calloc(1, sizeof(PathDeltaTime_t));
|
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 = (path_history[i - 1]->ts - path_history[i]->ts) / 10;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&facilities.lightship.lock);
|
pthread_mutex_unlock(&facilities.lightship.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get, set retransmission, duration
|
// get, set retransmission, duration
|
||||||
if ( ((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);
|
transmission_interval = *((uint32_t *)((DENM_t *)its_msg)->denm.management.transmissionInterval);
|
||||||
|
|
||||||
if ( ((DENM_t*)its_msg)->denm.management.validityDuration ) {
|
if (((DENM_t *)its_msg)->denm.management.validityDuration)
|
||||||
|
{
|
||||||
transmission_duration = *((uint32_t *)((DENM_t *)its_msg)->denm.management.validityDuration) * 1000;
|
transmission_duration = *((uint32_t *)((DENM_t *)its_msg)->denm.management.validityDuration) * 1000;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
transmission_duration = 600 * 1000;
|
transmission_duration = 600 * 1000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (frm->itsMessageType == ItsMessageType_ivim) {
|
}
|
||||||
|
else if (frm->itsMessageType == ItsMessageType_ivim)
|
||||||
|
{
|
||||||
managed_msg = true;
|
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);
|
||||||
|
|
@ -263,30 +301,39 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
|
||||||
if (service_type != SERVICE_NEW &&
|
if (service_type != SERVICE_NEW &&
|
||||||
service_type != SERVICE_UPDATE &&
|
service_type != SERVICE_UPDATE &&
|
||||||
service_type != SERVICE_CANCELLATION &&
|
service_type != SERVICE_CANCELLATION &&
|
||||||
service_type != SERVICE_NEGATION) {
|
service_type != SERVICE_NEGATION)
|
||||||
|
{
|
||||||
|
|
||||||
fwd = false;
|
fwd = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (service_type == SERVICE_UPDATE ||
|
if (service_type == SERVICE_UPDATE ||
|
||||||
service_type == SERVICE_CANCELLATION ||
|
service_type == SERVICE_CANCELLATION ||
|
||||||
service_type == SERVICE_NEGATION) {
|
service_type == SERVICE_NEGATION)
|
||||||
|
{
|
||||||
|
|
||||||
is_update = true;
|
is_update = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fwd) {
|
if (fwd)
|
||||||
|
{
|
||||||
uint64_t valid_to, valid_from;
|
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();
|
valid_from = itss_time_get();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
asn_INTEGER2ulong((INTEGER_t *)((IVIM_t *)its_msg)->ivi.mandatory.validFrom, (unsigned long long *)&valid_from);
|
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;
|
valid_to = valid_from + facilities.infrastructure.default_service_duration;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
asn_INTEGER2ulong((INTEGER_t *)((IVIM_t *)its_msg)->ivi.mandatory.validTo, (unsigned long long *)&valid_to);
|
asn_INTEGER2ulong((INTEGER_t *)((IVIM_t *)its_msg)->ivi.mandatory.validTo, (unsigned long long *)&valid_to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -295,8 +342,11 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
|
||||||
transmission_duration = valid_to - valid_from;
|
transmission_duration = valid_to - valid_from;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (frm->itsMessageType == ItsMessageType_evrsr) {
|
||||||
if (!facilities.replay) {
|
managed_msg = true;
|
||||||
|
}
|
||||||
|
if (!facilities.replay)
|
||||||
|
{
|
||||||
transmission_interval = 0;
|
transmission_interval = 0;
|
||||||
transmission_duration = 0;
|
transmission_duration = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -305,14 +355,16 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
|
||||||
facilities_request_result_accepted(responder);
|
facilities_request_result_accepted(responder);
|
||||||
|
|
||||||
// Forward message to [transport]
|
// Forward message to [transport]
|
||||||
if (fwd) {
|
if (fwd)
|
||||||
|
{
|
||||||
bpr->btpType = BTPType_btpB;
|
bpr->btpType = BTPType_btpB;
|
||||||
|
|
||||||
bpr->id = id;
|
bpr->id = id;
|
||||||
|
|
||||||
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)
|
||||||
|
{
|
||||||
log_error("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;
|
||||||
|
|
@ -320,25 +372,30 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
|
||||||
bpr->data.size = (enc.encoded + 7) / 8;
|
bpr->data.size = (enc.encoded + 7) / 8;
|
||||||
|
|
||||||
bpr->gn.destinationAddress.buf = malloc(6);
|
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;
|
bpr->gn.destinationAddress.size = 6;
|
||||||
|
|
||||||
if (transmission_start) {
|
if (transmission_start)
|
||||||
|
{
|
||||||
bpr->gn.repetitionStart = malloc(sizeof(long));
|
bpr->gn.repetitionStart = malloc(sizeof(long));
|
||||||
*bpr->gn.repetitionStart = transmission_start;
|
*bpr->gn.repetitionStart = transmission_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transmission_interval) {
|
if (transmission_interval)
|
||||||
|
{
|
||||||
bpr->gn.repetitionInterval = malloc(sizeof(long));
|
bpr->gn.repetitionInterval = malloc(sizeof(long));
|
||||||
*bpr->gn.repetitionInterval = transmission_interval;
|
*bpr->gn.repetitionInterval = transmission_interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transmission_duration) {
|
if (transmission_duration)
|
||||||
|
{
|
||||||
bpr->gn.maximumRepetitionTime = malloc(sizeof(long));
|
bpr->gn.maximumRepetitionTime = malloc(sizeof(long));
|
||||||
*bpr->gn.maximumRepetitionTime = transmission_duration;
|
*bpr->gn.maximumRepetitionTime = transmission_duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_update) {
|
if (is_update)
|
||||||
|
{
|
||||||
bpr->gn.isUpdate = malloc(sizeof(long));
|
bpr->gn.isUpdate = malloc(sizeof(long));
|
||||||
*bpr->gn.isUpdate = 1;
|
*bpr->gn.isUpdate = 1;
|
||||||
}
|
}
|
||||||
|
|
@ -348,7 +405,8 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
|
||||||
uint8_t tr_oer[2048];
|
uint8_t tr_oer[2048];
|
||||||
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)
|
||||||
|
{
|
||||||
log_error("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;
|
||||||
|
|
@ -358,7 +416,8 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
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];
|
||||||
int e = itss_management_record_packet_sdu(
|
int e = itss_management_record_packet_sdu(
|
||||||
|
|
@ -370,19 +429,22 @@ int facilities_request_single_message(void* responder, FacilitiesMessageRequest_
|
||||||
itss_time_get(),
|
itss_time_get(),
|
||||||
ITSS_FACILITIES,
|
ITSS_FACILITIES,
|
||||||
true);
|
true);
|
||||||
if (e != -1) {
|
if (e != -1)
|
||||||
|
{
|
||||||
itss_queue_send(facilities.tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set");
|
itss_queue_send(facilities.tx_queue, buffer, e, ITSS_MANAGEMENT, id, "MReq.packet.set");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
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);
|
ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr);
|
||||||
|
|
||||||
return rv;
|
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;
|
int rv = 0;
|
||||||
|
|
||||||
FacilitiesReply_t *frep = calloc(1, sizeof(FacilitiesReply_t));
|
FacilitiesReply_t *frep = calloc(1, sizeof(FacilitiesReply_t));
|
||||||
|
|
@ -399,8 +461,10 @@ int facilities_request_active_episodes(void* responder, FacilitiesRequest_t* fre
|
||||||
|
|
||||||
uint16_t na = 0;
|
uint16_t na = 0;
|
||||||
|
|
||||||
for (int e = 0; e < freq->choice.data.choice.activeEpisodes.list.count; ++e) {
|
for (int e = 0; e < freq->choice.data.choice.activeEpisodes.list.count; ++e)
|
||||||
switch (*freq->choice.data.choice.activeEpisodes.list.array[e]) {
|
{
|
||||||
|
switch (*freq->choice.data.choice.activeEpisodes.list.array[e])
|
||||||
|
{
|
||||||
case EpisodeType_denm:
|
case EpisodeType_denm:
|
||||||
na += nae;
|
na += nae;
|
||||||
break;
|
break;
|
||||||
|
|
@ -414,16 +478,21 @@ 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.size = na * sizeof(void *);
|
||||||
frep->choice.data.choice.episodes.list.array = malloc(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) {
|
for (int e = 0, j = 0; e < freq->choice.data.choice.activeEpisodes.list.count; ++e)
|
||||||
switch (*freq->choice.data.choice.activeEpisodes.list.array[e]) {
|
{
|
||||||
|
switch (*freq->choice.data.choice.activeEpisodes.list.array[e])
|
||||||
|
{
|
||||||
case EpisodeType_denm:
|
case EpisodeType_denm:
|
||||||
for (int i = 0, n = 0; n < nae; ++i) {
|
for (int i = 0, n = 0; n < nae; ++i)
|
||||||
if (facilities.den.events[i]->enabled && facilities.den.events[i]->state == EVENT_ACTIVE) {
|
{
|
||||||
|
if (facilities.den.events[i]->enabled && facilities.den.events[i]->state == EVENT_ACTIVE)
|
||||||
|
{
|
||||||
frep->choice.data.choice.episodes.list.array[j] = calloc(1, sizeof(ItsMessage_t));
|
frep->choice.data.choice.episodes.list.array[j] = calloc(1, sizeof(ItsMessage_t));
|
||||||
frep->choice.data.choice.episodes.list.array[j]->itsMessageType = ItsMessageType_denm;
|
frep->choice.data.choice.episodes.list.array[j]->itsMessageType = ItsMessageType_denm;
|
||||||
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 */
|
||||||
log_error("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;
|
||||||
|
|
@ -435,13 +504,16 @@ int facilities_request_active_episodes(void* responder, FacilitiesRequest_t* fre
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EpisodeType_ivim:
|
case EpisodeType_ivim:
|
||||||
for (int i = 0, n = 0; n < nas; ++i) {
|
for (int i = 0, n = 0; n < nas; ++i)
|
||||||
if (facilities.infrastructure.services[i]->enabled && facilities.infrastructure.services[i]->state == SERVICE_ACTIVE) {
|
{
|
||||||
|
if (facilities.infrastructure.services[i]->enabled && facilities.infrastructure.services[i]->state == SERVICE_ACTIVE)
|
||||||
|
{
|
||||||
frep->choice.data.choice.episodes.list.array[j] = calloc(1, sizeof(ItsMessage_t));
|
frep->choice.data.choice.episodes.list.array[j] = calloc(1, sizeof(ItsMessage_t));
|
||||||
frep->choice.data.choice.episodes.list.array[j]->itsMessageType = ItsMessageType_ivim;
|
frep->choice.data.choice.episodes.list.array[j]->itsMessageType = ItsMessageType_ivim;
|
||||||
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 */
|
||||||
log_error("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;
|
||||||
|
|
@ -468,7 +540,8 @@ 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)
|
||||||
|
{
|
||||||
log_error("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);
|
||||||
|
|
@ -485,7 +558,8 @@ cleanup:
|
||||||
return rv;
|
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;
|
int rv = 0;
|
||||||
|
|
||||||
FacilitiesReply_t *frep = calloc(1, sizeof(FacilitiesReply_t));
|
FacilitiesReply_t *frep = calloc(1, sizeof(FacilitiesReply_t));
|
||||||
|
|
@ -496,8 +570,10 @@ int facilities_request_attribute_types(void* responder, FacilitiesRequest_t* fre
|
||||||
frep->choice.data.choice.attributes.list.count = nra;
|
frep->choice.data.choice.attributes.list.count = nra;
|
||||||
frep->choice.data.choice.attributes.list.size = sizeof(void *) * nra;
|
frep->choice.data.choice.attributes.list.size = sizeof(void *) * nra;
|
||||||
frep->choice.data.choice.attributes.list.array = malloc(sizeof(void *) * nra);
|
frep->choice.data.choice.attributes.list.array = malloc(sizeof(void *) * nra);
|
||||||
for (int j = 0; j < nra; ++j) {
|
for (int j = 0; j < nra; ++j)
|
||||||
switch (*freq->choice.data.choice.attributeTypes.list.array[j]) {
|
{
|
||||||
|
switch (*freq->choice.data.choice.attributeTypes.list.array[j])
|
||||||
|
{
|
||||||
case FacilitiesAttributeType_stationId:
|
case FacilitiesAttributeType_stationId:
|
||||||
frep->choice.data.choice.attributes.list.array[j] = calloc(1, sizeof(FacilitiesAttribute_t));
|
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.size = 8;
|
||||||
|
|
@ -516,7 +592,8 @@ 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)
|
||||||
|
{
|
||||||
log_error("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;
|
||||||
|
|
@ -531,8 +608,8 @@ cleanup:
|
||||||
return rv;
|
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;
|
int rv = 0;
|
||||||
|
|
||||||
FacilitiesReply_t *frep = calloc(1, sizeof(FacilitiesReply_t));
|
FacilitiesReply_t *frep = calloc(1, sizeof(FacilitiesReply_t));
|
||||||
|
|
@ -547,7 +624,8 @@ int facilities_request_loaded_protected_zones(void* responder, FacilitiesRequest
|
||||||
frep->choice.data.choice.protectedCommunicationZones.list.array = malloc(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];
|
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));
|
frep->choice.data.choice.protectedCommunicationZones.list.array[z] = calloc(1, sizeof(ProtectedCommunicationZone_t));
|
||||||
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_ProtectedCommunicationZone, NULL, facilities.lightship.protected_zones.pz[z], buf, 256);
|
asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_ProtectedCommunicationZone, NULL, facilities.lightship.protected_zones.pz[z], buf, 256);
|
||||||
uper_decode_complete(NULL, &asn_DEF_ProtectedCommunicationZone, (void **)&frep->choice.data.choice.protectedCommunicationZones.list.array[z], buf, (enc.encoded + 7) / 8);
|
uper_decode_complete(NULL, &asn_DEF_ProtectedCommunicationZone, (void **)&frep->choice.data.choice.protectedCommunicationZones.list.array[z], buf, (enc.encoded + 7) / 8);
|
||||||
|
|
@ -557,7 +635,8 @@ 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)
|
||||||
|
{
|
||||||
log_error("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;
|
||||||
|
|
@ -572,17 +651,18 @@ cleanup:
|
||||||
return rv;
|
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;
|
int rv = 0;
|
||||||
|
|
||||||
pthread_mutex_lock(&facilities.coordination.lock);
|
pthread_mutex_lock(&facilities.coordination.lock);
|
||||||
facilities.coordination.chain.id = cis->idSet;
|
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(
|
memcpy(
|
||||||
facilities.coordination.chain.links[i],
|
facilities.coordination.chain.links[i],
|
||||||
cis->linkSet.list.array[i]->buf,
|
cis->linkSet.list.array[i]->buf,
|
||||||
cis->linkSet.list.array[i]->size
|
cis->linkSet.list.array[i]->size);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
facilities.coordination.chain.n_links = cis->linkSet.list.count;
|
facilities.coordination.chain.n_links = cis->linkSet.list.count;
|
||||||
// TODO region
|
// TODO region
|
||||||
|
|
@ -595,7 +675,8 @@ int facilities_request_chaininfo_set(void* responder, ChainInformationSet_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)
|
||||||
|
{
|
||||||
log_error("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;
|
||||||
|
|
@ -609,4 +690,3 @@ cleanup:
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue