|
|
|
|
@ -0,0 +1,129 @@
|
|
|
|
|
#include "facilities.h"
|
|
|
|
|
|
|
|
|
|
#include <itss-transport/BTPDataRequest.h>
|
|
|
|
|
#include <itss-transport/BTPDataIndication.h>
|
|
|
|
|
#include <itss-facilities/FacilitiesDataIndication.h>
|
|
|
|
|
#include <itss-facilities/FacilitiesDataRequest.h>
|
|
|
|
|
|
|
|
|
|
#include <camv2/CAM.h>
|
|
|
|
|
#include <denmv2/DENM.h>
|
|
|
|
|
#include <itss-transport/per_decoder.h>
|
|
|
|
|
#include <ivim/IVIM.h>
|
|
|
|
|
|
|
|
|
|
#include <it2s-btp.h>
|
|
|
|
|
|
|
|
|
|
#include <zmq.h>
|
|
|
|
|
#include <syslog.h>
|
|
|
|
|
|
|
|
|
|
#define syslog_info(msg, ...) syslog(LOG_INFO, msg, ##__VA_ARGS__)
|
|
|
|
|
#define syslog_emerg(msg, ...) syslog(LOG_EMERG, "%s:%d [" msg "]", __func__, __LINE__, ##__VA_ARGS__)
|
|
|
|
|
#define syslog_err(msg, ...) syslog(LOG_ERR, "%s:%d [" msg "]", __func__, __LINE__, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
|
#define syslog_debug(msg, ...) syslog(LOG_DEBUG, "%s:%d " msg "", __func__, __LINE__, ##__VA_ARGS__)
|
|
|
|
|
#else
|
|
|
|
|
#define syslog_debug(msg, ...)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static int transport_indication(void *responder, uint8_t *msg, uint32_t msg_len, void* app_sock) {
|
|
|
|
|
int rv = 0, code = 0;
|
|
|
|
|
FacilitiesDataIndication_t *fdi = NULL;
|
|
|
|
|
|
|
|
|
|
BTPDataIndication_t *bdi = calloc(1, sizeof(BTPDataIndication_t));
|
|
|
|
|
|
|
|
|
|
asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_BTPDataIndication, (void**) &bdi, msg, msg_len);
|
|
|
|
|
if (dec.code) {
|
|
|
|
|
syslog_err("[facilities] [in] invalid BTPDataIndication received");
|
|
|
|
|
rv = 1;
|
|
|
|
|
code = 1;
|
|
|
|
|
zmq_send(responder, &code, 1, 0);
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
zmq_send(responder, &code, 1, 0);
|
|
|
|
|
syslog_debug("[facilities] [in] received BTPDataIndication (%ldB)", bdi->data.size);
|
|
|
|
|
|
|
|
|
|
// Parse message
|
|
|
|
|
asn_TYPE_descriptor_t *msg_descriptor;
|
|
|
|
|
void *msg_struct;
|
|
|
|
|
switch (bdi->destinationPort) {
|
|
|
|
|
case Port_cam:
|
|
|
|
|
msg_descriptor = &asn_DEF_CAM;
|
|
|
|
|
msg_struct = calloc(1, sizeof(CAM_t));
|
|
|
|
|
break;
|
|
|
|
|
case Port_denm:
|
|
|
|
|
msg_descriptor = &asn_DEF_DENM;
|
|
|
|
|
msg_struct = calloc(1, sizeof(DENM_t));
|
|
|
|
|
break;
|
|
|
|
|
case Port_ivim:
|
|
|
|
|
msg_descriptor = &asn_DEF_IVIM;
|
|
|
|
|
msg_struct = calloc(1, sizeof(IVIM_t));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
syslog_debug("[facilities] messsage with unhandled BTP port received, ignoring");
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dec = uper_decode_complete(NULL, msg_descriptor, (void**) msg_struct, bdi->data.buf, bdi->data.size);
|
|
|
|
|
if (dec.code) {
|
|
|
|
|
syslog_debug("[facilities] invalid %s received", msg_descriptor->name);
|
|
|
|
|
rv = 1;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Forward to app
|
|
|
|
|
fdi = calloc(1, sizeof(FacilitiesDataIndication_t));
|
|
|
|
|
|
|
|
|
|
fdi->itssMessageType = bdi->destinationPort;
|
|
|
|
|
|
|
|
|
|
fdi->data.size = bdi->data.size;
|
|
|
|
|
fdi->data.buf = malloc(bdi->data.size);
|
|
|
|
|
memcpy(fdi->data.buf, bdi->data.buf, bdi->data.size);
|
|
|
|
|
|
|
|
|
|
uint8_t buffer[512];
|
|
|
|
|
buffer[0] = 4; // Facilities
|
|
|
|
|
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesDataIndication, NULL, fdi, buffer+1, 511);
|
|
|
|
|
syslog_debug("[facilities] [out] sending FacilitiesDataIndication to [app] (%ldB)", enc.encoded);
|
|
|
|
|
zmq_send(app_sock, buffer, enc.encoded, 0);
|
|
|
|
|
zmq_recv(app_sock, &code, 1, 0);
|
|
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
|
ASN_STRUCT_FREE(asn_DEF_BTPDataIndication, bdi);
|
|
|
|
|
ASN_STRUCT_FREE(asn_DEF_FacilitiesDataIndication, fdi);
|
|
|
|
|
ASN_STRUCT_FREE(*msg_descriptor, msg_struct);
|
|
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
syslog_info("[facilities] starting");
|
|
|
|
|
|
|
|
|
|
facilities_t facilities;
|
|
|
|
|
|
|
|
|
|
void *context = zmq_ctx_new();
|
|
|
|
|
void *responder = zmq_socket(context, ZMQ_REP);
|
|
|
|
|
int rc = zmq_bind(responder, "ipc:///tmp/itss/facilities");
|
|
|
|
|
|
|
|
|
|
void *app_sock = zmq_socket(context, ZMQ_REQ);
|
|
|
|
|
rc = zmq_connect(app_sock, "ipc:///tmp/itss/application");
|
|
|
|
|
|
|
|
|
|
uint8_t buffer[512];
|
|
|
|
|
uint8_t code;
|
|
|
|
|
syslog_info("[facilities] listening");
|
|
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
|
zmq_recv(responder, buffer, 512, 0);
|
|
|
|
|
|
|
|
|
|
switch (buffer[0]) {
|
|
|
|
|
case 3:
|
|
|
|
|
code = transport_indication(responder, buffer+1, 511, app_sock);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
syslog_debug("[facilities] unrecognized service");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|