Support for new SDUs
This commit is contained in:
parent
97df23f3f4
commit
9e1896ef92
52
src/cam.c
52
src/cam.c
|
|
@ -2,7 +2,7 @@
|
||||||
#include "facilities.h"
|
#include "facilities.h"
|
||||||
|
|
||||||
#include <camv2/INTEGER.h>
|
#include <camv2/INTEGER.h>
|
||||||
#include <itss-transport/TransportDataRequest.h>
|
#include <itss-transport/TransportRequest.h>
|
||||||
#include <itss-management/ManagementRequest.h>
|
#include <itss-management/ManagementRequest.h>
|
||||||
#include <camv2/CAM.h>
|
#include <camv2/CAM.h>
|
||||||
|
|
||||||
|
|
@ -388,7 +388,7 @@ void lightship_reset_timer(lightship_t* lightship, it2s_tender_epv_t* epv) {
|
||||||
pthread_mutex_unlock(&lightship->lock);
|
pthread_mutex_unlock(&lightship->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum CAM_CHECK_R check_cam(void* fc, BTPDataIndication_t *bdi, CAM_t* cam, it2s_tender_epv_t* epv, uint8_t* ssp, uint32_t ssp_len) {
|
enum CAM_CHECK_R check_cam(void* fc, BTPPacketIndication_t *bpi, CAM_t* cam, it2s_tender_epv_t* epv, uint8_t* ssp, uint32_t ssp_len) {
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
facilities_t* facilities = (facilities_t*) fc;
|
facilities_t* facilities = (facilities_t*) fc;
|
||||||
lightship_t *lightship = ((facilities_t*) fc)->lightship;
|
lightship_t *lightship = ((facilities_t*) fc)->lightship;
|
||||||
|
|
@ -519,7 +519,7 @@ enum CAM_CHECK_R check_cam(void* fc, BTPDataIndication_t *bdi, CAM_t* cam, it2s_
|
||||||
pthread_mutex_lock(&lightship->lock);
|
pthread_mutex_lock(&lightship->lock);
|
||||||
if (lightship->type == StationType_roadSideUnit) {
|
if (lightship->type == StationType_roadSideUnit) {
|
||||||
// Send CAMs if vehicles nearby
|
// Send CAMs if vehicles nearby
|
||||||
if (bdi->stationType != StationType_roadSideUnit && bdi->isNeighbour) {
|
if (bpi->stationType != StationType_roadSideUnit && bpi->isNeighbour) {
|
||||||
lightship->last_vehicle = now;
|
lightship->last_vehicle = now;
|
||||||
lightship->is_vehicle_near = true;
|
lightship->is_vehicle_near = true;
|
||||||
}
|
}
|
||||||
|
|
@ -633,53 +633,55 @@ void *ca_service(void *fc) {
|
||||||
uint8_t code = 0;
|
uint8_t code = 0;
|
||||||
facilities_t *facilities = (facilities_t*) fc;
|
facilities_t *facilities = (facilities_t*) fc;
|
||||||
|
|
||||||
TransportDataRequest_t* tdr = calloc(1, sizeof(TransportDataRequest_t));
|
TransportRequest_t* tr = calloc(1, sizeof(TransportRequest_t));
|
||||||
tdr->present = TransportDataRequest_PR_btp;
|
tr->present = TransportRequest_PR_packet;
|
||||||
BTPDataRequest_t *bdr = &tdr->choice.btp;
|
TransportPacketRequest_t* tpr = &tr->choice.packet;
|
||||||
|
tpr->present = TransportPacketRequest_PR_btp;
|
||||||
|
BTPPacketRequest_t *bpr = &tpr->choice.btp;
|
||||||
|
|
||||||
bdr->btpType = BTPType_btpB;
|
bpr->btpType = BTPType_btpB;
|
||||||
|
|
||||||
bdr->gn.destinationAddress.buf = malloc(6);
|
bpr->gn.destinationAddress.buf = malloc(6);
|
||||||
for (int i = 0; i < 6; ++i) {
|
for (int i = 0; i < 6; ++i) {
|
||||||
bdr->gn.destinationAddress.buf[i] = 0xff;
|
bpr->gn.destinationAddress.buf[i] = 0xff;
|
||||||
}
|
}
|
||||||
bdr->gn.destinationAddress.size = 6;
|
bpr->gn.destinationAddress.size = 6;
|
||||||
|
|
||||||
bdr->gn.packetTransportType = PacketTransportType_shb;
|
bpr->gn.packetTransportType = PacketTransportType_shb;
|
||||||
|
|
||||||
bdr->destinationPort = Port_cam;
|
bpr->destinationPort = Port_cam;
|
||||||
|
|
||||||
bdr->gn.trafficClass = 2;
|
bpr->gn.trafficClass = 2;
|
||||||
|
|
||||||
bdr->data.buf = malloc(512);
|
bpr->data.buf = malloc(512);
|
||||||
|
|
||||||
if (facilities->use_security) {
|
if (facilities->use_security) {
|
||||||
bdr->gn.securityProfile = malloc(sizeof(long));
|
bpr->gn.securityProfile = malloc(sizeof(long));
|
||||||
*bdr->gn.securityProfile = 1;
|
*bpr->gn.securityProfile = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t tdr_oer[1024];
|
uint8_t tr_oer[1024];
|
||||||
tdr_oer[0] = 4; // Facilities
|
tr_oer[0] = 4; // Facilities
|
||||||
while (!facilities->exit) {
|
while (!facilities->exit) {
|
||||||
usleep(1000*50);
|
usleep(1000*50);
|
||||||
|
|
||||||
if (lightship_check(facilities->lightship, &facilities->epv) && facilities->lightship->active) {
|
if (lightship_check(facilities->lightship, &facilities->epv) && facilities->lightship->active) {
|
||||||
rv = mk_cam(facilities, bdr->data.buf, (uint32_t *) &bdr->data.size);
|
rv = mk_cam(facilities, bpr->data.buf, (uint32_t *) &bpr->data.size);
|
||||||
if (rv) {
|
if (rv) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if inside PZ
|
// Check if inside PZ
|
||||||
bdr->gn.communicationProfile = 0;
|
bpr->gn.communicationProfile = 0;
|
||||||
if (facilities->station_type != 15 && check_pz(facilities->lightship, &facilities->epv)) bdr->gn.communicationProfile = 1;
|
if (facilities->station_type != 15 && check_pz(facilities->lightship, &facilities->epv)) bpr->gn.communicationProfile = 1;
|
||||||
|
|
||||||
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportDataRequest, NULL, tdr, tdr_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 BTPDataRequest for cam failed");
|
syslog_err("[facilities] encoding TR for cam failed");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
queue_add(facilities->tx_queue, tdr_oer, enc.encoded+1, 3);
|
queue_add(facilities->tx_queue, tr_oer, enc.encoded+1, 3);
|
||||||
pthread_cond_signal(&facilities->tx_queue->trigger);
|
pthread_cond_signal(&facilities->tx_queue->trigger);
|
||||||
|
|
||||||
lightship_reset_timer(facilities->lightship, &facilities->epv);
|
lightship_reset_timer(facilities->lightship, &facilities->epv);
|
||||||
|
|
@ -687,7 +689,7 @@ void *ca_service(void *fc) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ASN_STRUCT_FREE(asn_DEF_TransportDataRequest, tdr);
|
ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include <camv2/CAM.h>
|
#include <camv2/CAM.h>
|
||||||
#include <itss-transport/BTPDataIndication.h>
|
#include <itss-transport/BTPPacketIndication.h>
|
||||||
|
|
||||||
#include <it2s-tender/epv.h>
|
#include <it2s-tender/epv.h>
|
||||||
|
|
||||||
|
|
@ -89,7 +89,7 @@ lightship_t* lightship_init();
|
||||||
int lightship_check(lightship_t* lightship, it2s_tender_epv_t* epv);
|
int lightship_check(lightship_t* lightship, it2s_tender_epv_t* epv);
|
||||||
void lightship_reset_timer(lightship_t*lightship, it2s_tender_epv_t* epv);
|
void lightship_reset_timer(lightship_t*lightship, it2s_tender_epv_t* epv);
|
||||||
|
|
||||||
enum CAM_CHECK_R check_cam(void* fc, BTPDataIndication_t* bdi, CAM_t* cam, it2s_tender_epv_t* epv, uint8_t* ssp, uint32_t ssp_len);
|
enum CAM_CHECK_R check_cam(void* fc, BTPPacketIndication_t* bpi, CAM_t* cam, it2s_tender_epv_t* epv, uint8_t* ssp, uint32_t ssp_len);
|
||||||
void* ca_service(void* fc);
|
void* ca_service(void* fc);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
73
src/cpm.c
73
src/cpm.c
|
|
@ -4,12 +4,12 @@
|
||||||
#include <cpm/CPM.h>
|
#include <cpm/CPM.h>
|
||||||
#include <cpm/INTEGER.h>
|
#include <cpm/INTEGER.h>
|
||||||
#include <cpm/asn_application.h>
|
#include <cpm/asn_application.h>
|
||||||
#include <itss-transport/TransportDataRequest.h>
|
#include <itss-transport/TransportRequest.h>
|
||||||
#include <it2s-config.h>
|
#include <it2s-config.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <itss-facilities/FacilitiesDataIndication.h>
|
#include <itss-facilities/FacilitiesIndication.h>
|
||||||
|
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
@ -632,43 +632,48 @@ void *cp_service(void *fc){
|
||||||
facilities_t *facilities = (facilities_t *) fc;
|
facilities_t *facilities = (facilities_t *) fc;
|
||||||
memset(valid_array, 0, sizeof(valid_array));
|
memset(valid_array, 0, sizeof(valid_array));
|
||||||
|
|
||||||
uint8_t tdr_oer[2048];
|
uint8_t tr_oer[2048];
|
||||||
uint8_t fdi_oer[2048];
|
uint8_t fi_oer[2048];
|
||||||
tdr_oer[0] = 4; //Facilities
|
tr_oer[0] = 4; //Facilities
|
||||||
fdi_oer[0] = 4;
|
fi_oer[0] = 4;
|
||||||
|
|
||||||
TransportDataRequest_t* tdr = calloc(1, sizeof(TransportDataRequest_t));
|
TransportRequest_t* tr = calloc(1, sizeof(TransportRequest_t));
|
||||||
tdr->present = TransportDataRequest_PR_btp;
|
tr->present = TransportRequest_PR_packet;
|
||||||
BTPDataRequest_t *bdr = &tdr->choice.btp;
|
TransportPacketRequest_t* tpr = &tr->choice.packet;
|
||||||
FacilitiesDataIndication_t *fdi = calloc(1, sizeof(FacilitiesDataIndication_t));
|
tpr->present = TransportPacketRequest_PR_btp;
|
||||||
|
BTPPacketRequest_t *bpr = &tpr->choice.btp;
|
||||||
|
|
||||||
|
FacilitiesIndication_t* fi = calloc(1, sizeof(FacilitiesIndication_t));
|
||||||
|
fi->present = FacilitiesIndication_PR_message;
|
||||||
|
FacilitiesMessageIndication_t* fmi = &fi->choice.message;
|
||||||
|
|
||||||
roadRotationSin = sin(((facilities->dissemination->radar_rotation + 90.0) * PI) / 180);
|
roadRotationSin = sin(((facilities->dissemination->radar_rotation + 90.0) * PI) / 180);
|
||||||
roadRotationCos = cos(((facilities->dissemination->radar_rotation + 90.0) * PI) / 180);
|
roadRotationCos = cos(((facilities->dissemination->radar_rotation + 90.0) * PI) / 180);
|
||||||
|
|
||||||
/*--- Fill mandatory BTP Data Request parameters ---*/
|
/*--- Fill mandatory BTP Data Request parameters ---*/
|
||||||
bdr->gn.destinationAddress.buf = malloc(6);
|
bpr->gn.destinationAddress.buf = malloc(6);
|
||||||
bdr->gn.destinationAddress.size = 6;
|
bpr->gn.destinationAddress.size = 6;
|
||||||
for(int i = 0; i < 6; i++)
|
for(int i = 0; i < 6; i++)
|
||||||
bdr->gn.destinationAddress.buf[i] = 0xff; //Broadcast addr
|
bpr->gn.destinationAddress.buf[i] = 0xff; //Broadcast addr
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bdr->btpType = BTPType_btpB; //BTP Type B is for non-interactive packet transport | BTP Type A is for interactive packet transport
|
bpr->btpType = BTPType_btpB; //BTP Type B is for non-interactive packet transport | BTP Type A is for interactive packet transport
|
||||||
//The former doesn't have a source port and the latter have
|
//The former doesn't have a source port and the latter have
|
||||||
|
|
||||||
bdr->destinationPort = Port_cpm; //CPM entity port for communication between Facilities and Transport
|
bpr->destinationPort = Port_cpm; //CPM entity port for communication between Facilities and Transport
|
||||||
bdr->gn.packetTransportType = PacketTransportType_shb; //shb = Single Hop Broadcast packet
|
bpr->gn.packetTransportType = PacketTransportType_shb; //shb = Single Hop Broadcast packet
|
||||||
bdr->gn.trafficClass = 2; //Identifier assigned to a GeoNetworking packet that expresses its requirements on data transport
|
bpr->gn.trafficClass = 2; //Identifier assigned to a GeoNetworking packet that expresses its requirements on data transport
|
||||||
bdr->data.buf = malloc(1500); //CPM Data to be sent to the Transport layer
|
bpr->data.buf = malloc(1500); //CPM Data to be sent to the Transport layer
|
||||||
|
|
||||||
if(facilities->use_security) {
|
if(facilities->use_security) {
|
||||||
bdr->gn.securityProfile = malloc(sizeof(long));
|
bpr->gn.securityProfile = malloc(sizeof(long));
|
||||||
*bdr->gn.securityProfile = 1;
|
*bpr->gn.securityProfile = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--- Fill mandatory Facilities Data Indication parameters ---*/
|
/*--- Fill mandatory Facilities Message Indication parameters ---*/
|
||||||
fdi->itsMessageType = ItsMessageType_cpm;
|
fmi->itsMessageType = ItsMessageType_cpm;
|
||||||
fdi->data.buf = malloc(1500);
|
fmi->data.buf = malloc(1500);
|
||||||
|
|
||||||
/* Creating sockets and waiting for radar to connect*/
|
/* Creating sockets and waiting for radar to connect*/
|
||||||
radar_connection(RADAR_PORT,facilities);
|
radar_connection(RADAR_PORT,facilities);
|
||||||
|
|
@ -691,29 +696,29 @@ void *cp_service(void *fc){
|
||||||
parse_input(au8_readBuffer,i32_recv_bytes);
|
parse_input(au8_readBuffer,i32_recv_bytes);
|
||||||
|
|
||||||
/* CPM build and encoding to BDR and FDI */
|
/* CPM build and encoding to BDR and FDI */
|
||||||
if(mk_cpm(facilities, bdr->data.buf, (uint32_t *) &bdr->data.size, fdi->data.buf, (uint32_t *) &fdi->data.size) == 1)
|
if(mk_cpm(facilities, bpr->data.buf, (uint32_t *) &bpr->data.size, fmi->data.buf, (uint32_t *) &fmi->data.size) == 1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Encode BTPDataRequest */
|
/* Encode TransportRequest */
|
||||||
asn_enc_rval_t enc_tdr = oer_encode_to_buffer(&asn_DEF_TransportDataRequest, NULL, tdr, tdr_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 BTPDataRequest for cpm failed");
|
syslog_err("[facilities] encoding TR for cpm failed");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Encode FacilitiesDataIndication */
|
/* Encode FacilitiesIndication */
|
||||||
asn_enc_rval_t enc_fdi = oer_encode_to_buffer(&asn_DEF_FacilitiesDataIndication, NULL, fdi, fdi_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 FacilitiesDataIndication for cpm failed");
|
syslog_err("[facilities] encoding FI for cpm failed");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create thread to send packet to the Transport Layer (=3) */
|
/* Create thread to send packet to the Transport Layer (=3) */
|
||||||
queue_add(facilities->tx_queue, tdr_oer, enc_tdr.encoded+1, 3);
|
queue_add(facilities->tx_queue, tr_oer, enc_tdr.encoded+1, 3);
|
||||||
pthread_cond_signal(&facilities->tx_queue->trigger);
|
pthread_cond_signal(&facilities->tx_queue->trigger);
|
||||||
|
|
||||||
/* Create thread to send packet to the Applications Layer (=5) */
|
/* Create thread to send packet to the Applications Layer (=5) */
|
||||||
queue_add(facilities->tx_queue, fdi_oer, enc_fdi.encoded+1, 5);
|
queue_add(facilities->tx_queue, fi_oer, enc_fdi.encoded+1, 5);
|
||||||
pthread_cond_signal(&facilities->tx_queue->trigger);
|
pthread_cond_signal(&facilities->tx_queue->trigger);
|
||||||
|
|
||||||
/*Reset Timer for dissemination control */
|
/*Reset Timer for dissemination control */
|
||||||
|
|
@ -721,8 +726,8 @@ void *cp_service(void *fc){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ASN_STRUCT_FREE(asn_DEF_TransportDataRequest, tdr);
|
ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr);
|
||||||
ASN_STRUCT_FREE(asn_DEF_FacilitiesDataIndication,fdi);
|
ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi);
|
||||||
|
|
||||||
/* Close sockets */
|
/* Close sockets */
|
||||||
if(facilities->dissemination->tmc_connect)
|
if(facilities->dissemination->tmc_connect)
|
||||||
|
|
|
||||||
105
src/facilities.c
105
src/facilities.c
|
|
@ -7,11 +7,11 @@
|
||||||
#include "cpm.h"
|
#include "cpm.h"
|
||||||
#include "sa.h"
|
#include "sa.h"
|
||||||
|
|
||||||
#include <itss-transport/TransportDataRequest.h>
|
#include <itss-transport/TransportRequest.h>
|
||||||
#include <itss-transport/TransportDataIndication.h>
|
#include <itss-transport/TransportIndication.h>
|
||||||
#include <itss-facilities/FacilitiesDataIndication.h>
|
#include <itss-facilities/FacilitiesIndication.h>
|
||||||
#include <itss-facilities/FacilitiesDataRequest.h>
|
#include <itss-facilities/FacilitiesRequest.h>
|
||||||
#include <itss-facilities/FacilitiesDataResult.h>
|
#include <itss-facilities/FacilitiesReply.h>
|
||||||
#include <itss-security/SecurityIndication.h>
|
#include <itss-security/SecurityIndication.h>
|
||||||
#include <itss-security/SecurityResponse.h>
|
#include <itss-security/SecurityResponse.h>
|
||||||
#include <itss-management/ManagementIndication.h>
|
#include <itss-management/ManagementIndication.h>
|
||||||
|
|
@ -46,13 +46,13 @@
|
||||||
static int transport_indication(facilities_t *facilities, void* responder, uint8_t *msg, uint32_t msg_len) {
|
static int transport_indication(facilities_t *facilities, void* responder, uint8_t *msg, uint32_t msg_len) {
|
||||||
int rv = 0, code = 0;
|
int rv = 0, code = 0;
|
||||||
bool handled_msg = false;
|
bool handled_msg = false;
|
||||||
FacilitiesDataIndication_t *fdi = NULL;
|
FacilitiesIndication_t *fi = NULL;
|
||||||
|
|
||||||
TransportDataIndication_t* tdi = calloc(1, sizeof(TransportDataIndication_t));
|
TransportIndication_t* ti = calloc(1, sizeof(TransportIndication_t));
|
||||||
|
|
||||||
asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_TransportDataIndication, (void**) &tdi, 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 TDI received");
|
syslog_err("[facilities]<- invalid TI received");
|
||||||
rv = 1;
|
rv = 1;
|
||||||
code = 1;
|
code = 1;
|
||||||
zmq_send(responder, &code, 1, 0);
|
zmq_send(responder, &code, 1, 0);
|
||||||
|
|
@ -60,20 +60,22 @@ static int transport_indication(facilities_t *facilities, void* responder, uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
zmq_send(responder, &code, 1, 0);
|
zmq_send(responder, &code, 1, 0);
|
||||||
syslog_debug("[facilities]<- received TDI (%dB)", msg_len);
|
syslog_debug("[facilities]<- received TI (%dB)", msg_len);
|
||||||
|
|
||||||
|
TransportPacketIndication_t* tpi = &ti->choice.packet; // TODO
|
||||||
|
|
||||||
bool fwd = false;
|
bool fwd = false;
|
||||||
|
|
||||||
asn_TYPE_descriptor_t *its_msg_descriptor = NULL;
|
asn_TYPE_descriptor_t *its_msg_descriptor = NULL;
|
||||||
void *its_msg = NULL;
|
void *its_msg = NULL;
|
||||||
|
|
||||||
switch (tdi->present) {
|
switch (tpi->present) {
|
||||||
case TransportDataIndication_PR_btp:
|
case TransportPacketIndication_PR_btp:
|
||||||
;
|
;
|
||||||
|
|
||||||
// Parse message
|
// Parse message
|
||||||
|
|
||||||
switch (tdi->choice.btp.destinationPort) {
|
switch (tpi->choice.btp.destinationPort) {
|
||||||
case Port_cam:
|
case Port_cam:
|
||||||
its_msg_descriptor = &asn_DEF_CAM;
|
its_msg_descriptor = &asn_DEF_CAM;
|
||||||
its_msg = calloc(1, sizeof(CAM_t));
|
its_msg = calloc(1, sizeof(CAM_t));
|
||||||
|
|
@ -109,7 +111,7 @@ static int transport_indication(facilities_t *facilities, void* responder, uint8
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
dec = uper_decode_complete(NULL, its_msg_descriptor, (void**) &its_msg, tdi->choice.btp.data.buf, tdi->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);
|
syslog_debug("[facilities]<- invalid %s received", its_msg_descriptor->name);
|
||||||
rv = 1;
|
rv = 1;
|
||||||
|
|
@ -119,15 +121,15 @@ static int transport_indication(facilities_t *facilities, void* responder, uint8
|
||||||
// Get permisisons
|
// Get permisisons
|
||||||
uint8_t* ssp = NULL;
|
uint8_t* ssp = NULL;
|
||||||
uint16_t ssp_len;
|
uint16_t ssp_len;
|
||||||
if (tdi->choice.btp.gn.permissions) {
|
if (tpi->choice.btp.gn.permissions) {
|
||||||
ssp = tdi->choice.btp.gn.permissions->ssp.buf;
|
ssp = tpi->choice.btp.gn.permissions->ssp.buf;
|
||||||
ssp_len = tdi->choice.btp.gn.permissions->ssp.size;
|
ssp_len = tpi->choice.btp.gn.permissions->ssp.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manage message
|
// Manage message
|
||||||
switch (tdi->choice.btp.destinationPort) {
|
switch (tpi->choice.btp.destinationPort) {
|
||||||
case Port_cam:
|
case Port_cam:
|
||||||
switch (check_cam(facilities, &tdi->choice.btp, its_msg, &facilities->epv, ssp, ssp_len)) {
|
switch (check_cam(facilities, &tpi->choice.btp, its_msg, &facilities->epv, ssp, ssp_len)) {
|
||||||
case CAM_OK:
|
case CAM_OK:
|
||||||
fwd = true;
|
fwd = true;
|
||||||
break;
|
break;
|
||||||
|
|
@ -189,40 +191,41 @@ static int transport_indication(facilities_t *facilities, void* responder, uint8
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TransportDataIndication_PR_tcp:
|
case TransportPacketIndication_PR_tcp:
|
||||||
break;
|
break;
|
||||||
case TransportDataIndication_PR_udp:
|
case TransportPacketIndication_PR_udp:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Forward to [applications]
|
||||||
// Forward to application
|
|
||||||
if (fwd) {
|
if (fwd) {
|
||||||
fdi = calloc(1, sizeof(FacilitiesDataIndication_t));
|
fi = calloc(1, sizeof(FacilitiesIndication_t));
|
||||||
|
fi->present = FacilitiesIndication_PR_message;
|
||||||
|
FacilitiesMessageIndication_t* fmi = &fi->choice.message;
|
||||||
|
|
||||||
fdi->itsMessageType = tdi->choice.btp.destinationPort;
|
fmi->itsMessageType = tpi->choice.btp.destinationPort;
|
||||||
|
|
||||||
fdi->data.size = tdi->choice.btp.data.size;
|
fmi->data.size = tpi->choice.btp.data.size;
|
||||||
fdi->data.buf = malloc(tdi->choice.btp.data.size);
|
fmi->data.buf = malloc(tpi->choice.btp.data.size);
|
||||||
memcpy(fdi->data.buf, tdi->choice.btp.data.buf, tdi->choice.btp.data.size);
|
memcpy(fmi->data.buf, tpi->choice.btp.data.buf, tpi->choice.btp.data.size);
|
||||||
|
|
||||||
uint8_t buffer[PACKET_MAX_LEN];
|
uint8_t buffer[PACKET_MAX_LEN];
|
||||||
buffer[0] = 4; // Facilities
|
buffer[0] = 4; // Facilities
|
||||||
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesDataIndication, NULL, fdi, buffer+1, PACKET_MAX_LEN-1);
|
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesIndication, NULL, fi, buffer+1, PACKET_MAX_LEN-1);
|
||||||
|
|
||||||
queue_add(facilities->tx_queue, buffer, enc.encoded+1, 5);
|
queue_add(facilities->tx_queue, buffer, enc.encoded+1, 5);
|
||||||
pthread_cond_signal(&facilities->tx_queue->trigger);
|
pthread_cond_signal(&facilities->tx_queue->trigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (handled_msg && tdi->choice.btp.destinationPort != Port_denm && tdi->choice.btp.destinationPort != Port_ivim) {
|
if (handled_msg && tpi->choice.btp.destinationPort != Port_denm && tpi->choice.btp.destinationPort != Port_ivim) {
|
||||||
ASN_STRUCT_FREE(*its_msg_descriptor, its_msg);
|
ASN_STRUCT_FREE(*its_msg_descriptor, its_msg);
|
||||||
}
|
}
|
||||||
ASN_STRUCT_FREE(asn_DEF_TransportDataIndication, tdi);
|
ASN_STRUCT_FREE(asn_DEF_TransportIndication, ti);
|
||||||
ASN_STRUCT_FREE(asn_DEF_FacilitiesDataIndication, fdi);
|
ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
@ -230,42 +233,52 @@ cleanup:
|
||||||
static int facilities_request(facilities_t *facilities, void* responder, uint8_t *msg, uint32_t msg_len) {
|
static int facilities_request(facilities_t *facilities, void* responder, uint8_t *msg, uint32_t msg_len) {
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
FacilitiesDataRequest_t *fdreq = calloc(1, sizeof(FacilitiesDataRequest_t));
|
FacilitiesRequest_t *fr = calloc(1, sizeof(FacilitiesRequest_t));
|
||||||
|
|
||||||
asn_dec_rval_t dec = oer_decode(NULL, &asn_DEF_FacilitiesDataRequest, (void**) &fdreq, 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 FDRequest received");
|
syslog_err("[facilities]<- invalid FR received");
|
||||||
facilities_request_result_rejected(responder);
|
facilities_request_result_rejected(responder);
|
||||||
rv = 1;
|
rv = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (fdreq->present) {
|
switch (fr->present) {
|
||||||
case FacilitiesDataRequest_PR_singleMessage:
|
case FacilitiesRequest_PR_message:
|
||||||
rv = facilities_request_single_message(facilities, responder, fdreq);
|
rv = facilities_request_single_message(facilities, responder, fr);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case FacilitiesRequest_PR_data:
|
||||||
|
switch (fr->choice.data.present) {
|
||||||
case FacilitiesDataRequest_PR_activeEpisodes:
|
case FacilitiesDataRequest_PR_activeEpisodes:
|
||||||
rv = facilities_request_active_episodes(facilities, responder, fdreq);
|
rv = facilities_request_active_episodes(facilities, responder, fr);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FacilitiesDataRequest_PR_attributeTypes:
|
case FacilitiesDataRequest_PR_attributeTypes:
|
||||||
rv = facilities_request_attribute_types(facilities, responder, fdreq);
|
rv = facilities_request_attribute_types(facilities, responder, fr);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FacilitiesDataRequest_PR_loadedProtectionZones:
|
case FacilitiesDataRequest_PR_loadedProtectionZones:
|
||||||
rv = facilities_request_loaded_protected_zones(facilities, responder, fdreq);
|
rv = facilities_request_loaded_protected_zones(facilities, responder, fr);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
syslog_err("[facilities] unrecognized FDR type received (%d)", fdreq->present);
|
syslog_err("[facilities] unrecognized FDR type received (%d)", fr->choice.data.present);
|
||||||
|
facilities_request_result_rejected(responder);
|
||||||
|
rv = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
syslog_err("[facilities] 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
ASN_STRUCT_FREE(asn_DEF_FacilitiesDataRequest, fdreq);
|
ASN_STRUCT_FREE(asn_DEF_FacilitiesRequest, fr);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
@ -305,6 +318,8 @@ static int security_indication(facilities_t *facilities, void* responder_secured
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool id_changed = false;
|
||||||
|
|
||||||
switch (si->choice.idChangeEvent.command) {
|
switch (si->choice.idChangeEvent.command) {
|
||||||
case SecurityIdChangeEventType_prepare:
|
case SecurityIdChangeEventType_prepare:
|
||||||
|
|
||||||
|
|
@ -338,6 +353,8 @@ static int security_indication(facilities_t *facilities, void* responder_secured
|
||||||
|
|
||||||
pthread_mutex_unlock(&facilities->id.lock);
|
pthread_mutex_unlock(&facilities->id.lock);
|
||||||
|
|
||||||
|
id_changed = true;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SecurityIdChangeEventType_abort:
|
case SecurityIdChangeEventType_abort:
|
||||||
|
|
@ -360,7 +377,7 @@ static int security_indication(facilities_t *facilities, void* responder_secured
|
||||||
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);
|
zmq_send(responder_secured, buffer, enc.encoded, 0);
|
||||||
|
|
||||||
if (facilities->id.change.stage == ID_CHANGE_INACTIVE) {
|
if (id_changed) {
|
||||||
// Inform management
|
// Inform management
|
||||||
ManagementRequest_t* mreq = calloc(1, sizeof(ManagementRequest_t));
|
ManagementRequest_t* mreq = calloc(1, sizeof(ManagementRequest_t));
|
||||||
mreq->present = ManagementRequest_PR_attributes;
|
mreq->present = ManagementRequest_PR_attributes;
|
||||||
|
|
|
||||||
251
src/requests.c
251
src/requests.c
|
|
@ -5,8 +5,8 @@
|
||||||
#include "requests.h"
|
#include "requests.h"
|
||||||
#include "cpm.h"
|
#include "cpm.h"
|
||||||
|
|
||||||
#include <itss-facilities/FacilitiesDataResult.h>
|
#include <itss-facilities/FacilitiesReply.h>
|
||||||
#include <itss-transport/TransportDataRequest.h>
|
#include <itss-transport/TransportRequest.h>
|
||||||
|
|
||||||
#include <zmq.h>
|
#include <zmq.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
@ -27,35 +27,39 @@
|
||||||
int facilities_request_result_accepted(void* responder) {
|
int facilities_request_result_accepted(void* responder) {
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
FacilitiesDataResult_t *fdres = calloc(1, sizeof(FacilitiesDataResult_t));
|
FacilitiesReply_t *fr = calloc(1, sizeof(FacilitiesReply_t));
|
||||||
fdres->code = FacilitiesResultCode_accepted;
|
fr->present = FacilitiesReply_PR_message;
|
||||||
uint8_t fdres_oer[32];
|
fr->choice.message.returnCode = 0;
|
||||||
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesDataResult, NULL, fdres, fdres_oer, 32);
|
uint8_t fr_oer[32];
|
||||||
zmq_send(responder, fdres_oer, enc.encoded, 0);
|
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);
|
||||||
|
|
||||||
ASN_STRUCT_FREE(asn_DEF_FacilitiesDataResult, fdres);
|
ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, fr);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
int facilities_request_result_rejected(void* responder) {
|
int facilities_request_result_rejected(void* responder) {
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
FacilitiesDataResult_t *fdres = calloc(1, sizeof(FacilitiesDataResult_t));
|
FacilitiesReply_t *fr = calloc(1, sizeof(FacilitiesReply_t));
|
||||||
fdres->code = FacilitiesResultCode_rejected;
|
fr->present = FacilitiesReply_PR_message;
|
||||||
uint8_t fdres_oer[32];
|
fr->choice.message.returnCode = 1;
|
||||||
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesDataResult, NULL, fdres, fdres_oer, 32);
|
uint8_t fr_oer[32];
|
||||||
zmq_send(responder, fdres_oer, enc.encoded, 0);
|
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);
|
||||||
|
|
||||||
ASN_STRUCT_FREE(asn_DEF_FacilitiesDataResult, fdres);
|
ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, fr);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
int facilities_request_single_message(facilities_t* facilities, void* responder, FacilitiesDataRequest_t* fdreq) {
|
int facilities_request_single_message(facilities_t* facilities, void* responder, FacilitiesRequest_t* fr) {
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
TransportDataRequest_t* tdr = calloc(1, sizeof(TransportDataRequest_t));
|
TransportRequest_t* tr = calloc(1, sizeof(TransportRequest_t));
|
||||||
tdr->present = TransportDataRequest_PR_btp;
|
tr->present = TransportRequest_PR_packet;
|
||||||
BTPDataRequest_t* bdr = &tdr->choice.btp;
|
TransportPacketRequest_t* tpr = &tr->choice.packet;
|
||||||
|
tpr->present = TransportPacketRequest_PR_btp;
|
||||||
|
BTPPacketRequest_t* bpr = &tpr->choice.btp;
|
||||||
|
|
||||||
void *its_msg = NULL;
|
void *its_msg = NULL;
|
||||||
asn_TYPE_descriptor_t *its_msg_def = NULL;
|
asn_TYPE_descriptor_t *its_msg_def = NULL;
|
||||||
|
|
@ -66,48 +70,48 @@ int facilities_request_single_message(facilities_t* facilities, void* responder,
|
||||||
uint32_t transmission_interval = 0;
|
uint32_t transmission_interval = 0;
|
||||||
uint64_t transmission_start = 0;
|
uint64_t transmission_start = 0;
|
||||||
|
|
||||||
switch (fdreq->choice.singleMessage.itsMessageType) {
|
switch (fr->choice.message.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));
|
||||||
bdr->destinationPort = Port_cam;
|
bpr->destinationPort = Port_cam;
|
||||||
bdr->gn.packetTransportType = PacketTransportType_shb;
|
bpr->gn.packetTransportType = PacketTransportType_shb;
|
||||||
bdr->gn.trafficClass = 1;
|
bpr->gn.trafficClass = 1;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case ItsMessageType_denm:
|
case ItsMessageType_denm:
|
||||||
its_msg_def = &asn_DEF_DENM;
|
its_msg_def = &asn_DEF_DENM;
|
||||||
its_msg = calloc(1, sizeof(DENM_t));
|
its_msg = calloc(1, sizeof(DENM_t));
|
||||||
bdr->destinationPort = Port_denm;
|
bpr->destinationPort = Port_denm;
|
||||||
bdr->gn.packetTransportType = PacketTransportType_gbc;
|
bpr->gn.packetTransportType = PacketTransportType_gbc;
|
||||||
bdr->gn.trafficClass = 2;
|
bpr->gn.trafficClass = 2;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case ItsMessageType_ivim:
|
case ItsMessageType_ivim:
|
||||||
its_msg_def = &asn_DEF_IVIM;
|
its_msg_def = &asn_DEF_IVIM;
|
||||||
its_msg = calloc(1, sizeof(IVIM_t));
|
its_msg = calloc(1, sizeof(IVIM_t));
|
||||||
bdr->destinationPort = Port_ivim;
|
bpr->destinationPort = Port_ivim;
|
||||||
bdr->gn.packetTransportType = PacketTransportType_shb;
|
bpr->gn.packetTransportType = PacketTransportType_shb;
|
||||||
bdr->gn.trafficClass = 1;
|
bpr->gn.trafficClass = 1;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ItsMessageType_cpm:
|
case ItsMessageType_cpm:
|
||||||
its_msg_def = &asn_DEF_CPM;
|
its_msg_def = &asn_DEF_CPM;
|
||||||
its_msg = calloc(1, sizeof(CPM_t));
|
its_msg = calloc(1, sizeof(CPM_t));
|
||||||
bdr->destinationPort = Port_cpm;
|
bpr->destinationPort = Port_cpm;
|
||||||
bdr->gn.packetTransportType = PacketTransportType_shb;
|
bpr->gn.packetTransportType = PacketTransportType_shb;
|
||||||
bdr->gn.trafficClass = 2;
|
bpr->gn.trafficClass = 2;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
syslog_err("[facilities] unrecognized FDRequest message type (%ld)", fdreq->choice.singleMessage.itsMessageType);
|
syslog_err("[facilities] unrecognized FDRequest message type (%ld)", fr->choice.message.itsMessageType);
|
||||||
facilities_request_result_rejected(responder);
|
facilities_request_result_rejected(responder);
|
||||||
rv = 1;
|
rv = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
asn_dec_rval_t dec = uper_decode_complete(NULL, its_msg_def, (void**) &its_msg, fdreq->choice.singleMessage.data.buf, fdreq->choice.singleMessage.data.size);
|
asn_dec_rval_t dec = uper_decode_complete(NULL, its_msg_def, (void**) &its_msg, fr->choice.message.data.buf, fr->choice.message.data.size);
|
||||||
if (dec.code) {
|
if (dec.code) {
|
||||||
syslog_debug("[facilities] invalid FDRequest %s received", its_msg_def->name);
|
syslog_debug("[facilities] invalid FDRequest %s received", its_msg_def->name);
|
||||||
facilities_request_result_rejected(responder);
|
facilities_request_result_rejected(responder);
|
||||||
|
|
@ -119,7 +123,7 @@ int facilities_request_single_message(facilities_t* facilities, void* responder,
|
||||||
bool is_update = false;
|
bool is_update = false;
|
||||||
|
|
||||||
int managed_msg = false;
|
int managed_msg = false;
|
||||||
if (fdreq->choice.singleMessage.itsMessageType == ItsMessageType_denm) {
|
if (fr->choice.message.itsMessageType == ItsMessageType_denm) {
|
||||||
managed_msg = true;
|
managed_msg = true;
|
||||||
|
|
||||||
uint8_t event_type = event_manage(facilities->den, its_msg, &facilities->epv, &id, NULL, 0);
|
uint8_t event_type = event_manage(facilities->den, its_msg, &facilities->epv, &id, NULL, 0);
|
||||||
|
|
@ -207,7 +211,7 @@ int facilities_request_single_message(facilities_t* facilities, void* responder,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (fdreq->choice.singleMessage.itsMessageType == ItsMessageType_ivim) {
|
} else if (fr->choice.message.itsMessageType == ItsMessageType_ivim) {
|
||||||
managed_msg = true;
|
managed_msg = true;
|
||||||
|
|
||||||
uint8_t service_type = service_eval(facilities->infrastructure, SERVICE_IVI, its_msg, &facilities->epv, &id, NULL, 0);
|
uint8_t service_type = service_eval(facilities->infrastructure, SERVICE_IVI, its_msg, &facilities->epv, &id, NULL, 0);
|
||||||
|
|
@ -259,81 +263,80 @@ int facilities_request_single_message(facilities_t* facilities, void* responder,
|
||||||
// Forward message to [transport]
|
// Forward message to [transport]
|
||||||
if (fwd) {
|
if (fwd) {
|
||||||
if (id != -1) {
|
if (id != -1) {
|
||||||
bdr->id = id;
|
bpr->id = id;
|
||||||
} else {
|
} else {
|
||||||
bdr->id = 0;
|
bpr->id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bdr->btpType = BTPType_btpB;
|
bpr->btpType = BTPType_btpB;
|
||||||
|
|
||||||
bdr->data.buf = malloc(2048);
|
bpr->data.buf = malloc(2048);
|
||||||
asn_enc_rval_t enc = uper_encode_to_buffer(its_msg_def, NULL, its_msg, bdr->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);
|
syslog_err("[facilities] failed encoding ITS message into UPER (%s)", enc.failed_type->name);
|
||||||
rv = 1;
|
rv = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
bdr->data.size = (enc.encoded + 7) / 8;
|
bpr->data.size = (enc.encoded + 7) / 8;
|
||||||
|
|
||||||
bdr->gn.destinationAddress.buf = malloc(6);
|
bpr->gn.destinationAddress.buf = malloc(6);
|
||||||
for (int i = 0; i < 6; ++i) bdr->gn.destinationAddress.buf[i] = 0xff;
|
for (int i = 0; i < 6; ++i) bpr->gn.destinationAddress.buf[i] = 0xff;
|
||||||
bdr->gn.destinationAddress.size = 6;
|
bpr->gn.destinationAddress.size = 6;
|
||||||
|
|
||||||
if (transmission_start) {
|
if (transmission_start) {
|
||||||
bdr->gn.repetitionStart = malloc(sizeof(long));
|
bpr->gn.repetitionStart = malloc(sizeof(long));
|
||||||
*bdr->gn.repetitionStart = transmission_start;
|
*bpr->gn.repetitionStart = transmission_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transmission_interval) {
|
if (transmission_interval) {
|
||||||
bdr->gn.repetitionInterval = malloc(sizeof(long));
|
bpr->gn.repetitionInterval = malloc(sizeof(long));
|
||||||
*bdr->gn.repetitionInterval = transmission_interval;
|
*bpr->gn.repetitionInterval = transmission_interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transmission_duration) {
|
if (transmission_duration) {
|
||||||
bdr->gn.maximumRepetitionTime = malloc(sizeof(long));
|
bpr->gn.maximumRepetitionTime = malloc(sizeof(long));
|
||||||
*bdr->gn.maximumRepetitionTime = transmission_duration;
|
*bpr->gn.maximumRepetitionTime = transmission_duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_update) {
|
if (is_update) {
|
||||||
bdr->gn.isUpdate = malloc(sizeof(long));
|
bpr->gn.isUpdate = malloc(sizeof(long));
|
||||||
*bdr->gn.isUpdate = 1;
|
*bpr->gn.isUpdate = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (facilities->use_security) {
|
if (facilities->use_security) {
|
||||||
bdr->gn.securityProfile = malloc(sizeof(long));
|
bpr->gn.securityProfile = malloc(sizeof(long));
|
||||||
*bdr->gn.securityProfile = 1;
|
*bpr->gn.securityProfile = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t tdr_oer[2048];
|
uint8_t tr_oer[2048];
|
||||||
tdr_oer[0] = 4; // [facilities] service id
|
tr_oer[0] = 4; // [facilities] service id
|
||||||
enc = oer_encode_to_buffer(&asn_DEF_TransportDataRequest, NULL, tdr, tdr_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 TDR (%s)", enc.failed_type->name);
|
syslog_err("[facilities] failed encoding TR (%s)", enc.failed_type->name);
|
||||||
rv = 1;
|
rv = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
queue_add(facilities->tx_queue, tdr_oer, enc.encoded+1, 3);
|
queue_add(facilities->tx_queue, tr_oer, enc.encoded+1, 3);
|
||||||
pthread_cond_signal(&facilities->tx_queue->trigger);
|
pthread_cond_signal(&facilities->tx_queue->trigger);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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_TransportDataRequest, tdr);
|
ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
int facilities_request_active_episodes(facilities_t* facilities, void* responder, FacilitiesDataRequest_t* fdreq) {
|
int facilities_request_active_episodes(facilities_t* facilities, void* responder, FacilitiesRequest_t* freq) {
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
FacilitiesDataResult_t* fdres = calloc(1, sizeof(FacilitiesDataResult_t));
|
FacilitiesReply_t* frep = calloc(1, sizeof(FacilitiesReply_t));
|
||||||
uint8_t* fdres_oer = NULL;
|
uint8_t* frep_oer = NULL;
|
||||||
|
|
||||||
fdres->code = FacilitiesResultCode_accepted;
|
frep->present = FacilitiesReply_PR_data;
|
||||||
fdres->result = calloc(1, sizeof(FacilitiesResult_t));
|
frep->choice.data.present = FacilitiesDataReply_PR_episodes;
|
||||||
fdres->result->present = FacilitiesResult_PR_episodes;
|
|
||||||
|
|
||||||
pthread_mutex_lock(&facilities->den->lock);
|
pthread_mutex_lock(&facilities->den->lock);
|
||||||
pthread_mutex_lock(&facilities->infrastructure->lock);
|
pthread_mutex_lock(&facilities->infrastructure->lock);
|
||||||
|
|
@ -343,8 +346,8 @@ int facilities_request_active_episodes(facilities_t* facilities, void* responder
|
||||||
|
|
||||||
uint16_t na = 0;
|
uint16_t na = 0;
|
||||||
|
|
||||||
for (int e = 0; e < fdreq->choice.activeEpisodes.list.count; ++e) {
|
for (int e = 0; e < freq->choice.data.choice.activeEpisodes.list.count; ++e) {
|
||||||
switch (*fdreq->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;
|
||||||
|
|
@ -354,25 +357,25 @@ int facilities_request_active_episodes(facilities_t* facilities, void* responder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fdres->result->choice.episodes.list.count = na;
|
frep->choice.data.choice.episodes.list.count = na;
|
||||||
fdres->result->choice.episodes.list.size = na * sizeof(void *);
|
frep->choice.data.choice.episodes.list.size = na * sizeof(void *);
|
||||||
fdres->result->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 < fdreq->choice.activeEpisodes.list.count; ++e) {
|
for (int e = 0, j = 0; e < freq->choice.data.choice.activeEpisodes.list.count; ++e) {
|
||||||
switch (*fdreq->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) {
|
||||||
fdres->result->choice.episodes.list.array[j] = calloc(1, sizeof(ItsMessage_t));
|
frep->choice.data.choice.episodes.list.array[j] = calloc(1, sizeof(ItsMessage_t));
|
||||||
fdres->result->choice.episodes.list.array[j]->itsMessageType = ItsMessageType_denm;
|
frep->choice.data.choice.episodes.list.array[j]->itsMessageType = ItsMessageType_denm;
|
||||||
fdres->result->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, fdres->result->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);
|
syslog_err("[facilities] failed encoding DENM for FDResult (%s)", enc.failed_type->name);
|
||||||
fdres->result->choice.episodes.list.array[j]->data.size = 0;
|
frep->choice.data.choice.episodes.list.array[j]->data.size = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
fdres->result->choice.episodes.list.array[j]->data.size = (enc.encoded + 7) / 8;
|
frep->choice.data.choice.episodes.list.array[j]->data.size = (enc.encoded + 7) / 8;
|
||||||
++j;
|
++j;
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
|
|
@ -381,23 +384,23 @@ int facilities_request_active_episodes(facilities_t* facilities, void* responder
|
||||||
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) {
|
||||||
fdres->result->choice.episodes.list.array[j] = calloc(1, sizeof(ItsMessage_t));
|
frep->choice.data.choice.episodes.list.array[j] = calloc(1, sizeof(ItsMessage_t));
|
||||||
fdres->result->choice.episodes.list.array[j]->itsMessageType = ItsMessageType_ivim;
|
frep->choice.data.choice.episodes.list.array[j]->itsMessageType = ItsMessageType_ivim;
|
||||||
fdres->result->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, fdres->result->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);
|
syslog_err("[facilities] failed encoding IVIM for FDResult (%s)", enc.failed_type->name);
|
||||||
fdres->result->choice.episodes.list.array[j]->data.size = 0;
|
frep->choice.data.choice.episodes.list.array[j]->data.size = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
fdres->result->choice.episodes.list.array[j]->data.size = (enc.encoded + 7) / 8;
|
frep->choice.data.choice.episodes.list.array[j]->data.size = (enc.encoded + 7) / 8;
|
||||||
++j;
|
++j;
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
syslog_err("[facilities] unrecognized FDR event type (%ld)", *fdreq->choice.activeEpisodes.list.array[0]);
|
syslog_err("[facilities] unrecognized FR event type (%ld)", *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);
|
||||||
|
|
||||||
|
|
@ -410,8 +413,8 @@ int facilities_request_active_episodes(facilities_t* facilities, void* responder
|
||||||
pthread_mutex_unlock(&facilities->den->lock);
|
pthread_mutex_unlock(&facilities->den->lock);
|
||||||
pthread_mutex_unlock(&facilities->infrastructure->lock);
|
pthread_mutex_unlock(&facilities->infrastructure->lock);
|
||||||
|
|
||||||
fdres_oer = malloc(32768);
|
frep_oer = malloc(32768);
|
||||||
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesDataResult, NULL, fdres, fdres_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 FDResult (%s)", enc.failed_type->name);
|
syslog_err("[facilities] failed encoding FDResult (%s)", enc.failed_type->name);
|
||||||
|
|
||||||
|
|
@ -420,89 +423,87 @@ int facilities_request_active_episodes(facilities_t* facilities, void* responder
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
zmq_send(responder, fdres_oer, enc.encoded, 0);
|
zmq_send(responder, frep_oer, enc.encoded, 0);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
free(fdres_oer);
|
free(frep_oer);
|
||||||
ASN_STRUCT_FREE(asn_DEF_FacilitiesDataResult, fdres);
|
ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, frep);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
int facilities_request_attribute_types(facilities_t* facilities, void* responder, FacilitiesDataRequest_t* fdreq) {
|
int facilities_request_attribute_types(facilities_t* facilities, void* responder, FacilitiesRequest_t* freq) {
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
FacilitiesDataResult_t* fdres = calloc(1, sizeof(FacilitiesDataResult_t));
|
FacilitiesReply_t* frep = calloc(1, sizeof(FacilitiesReply_t));
|
||||||
|
frep->present = FacilitiesReply_PR_data;
|
||||||
|
|
||||||
fdres->code = FacilitiesResultCode_accepted;
|
int nra = freq->choice.data.choice.attributeTypes.list.count;
|
||||||
int nra = fdreq->choice.attributeTypes.list.count;
|
frep->choice.data.present = FacilitiesDataReply_PR_attributes;
|
||||||
fdres->result = calloc(1, sizeof(FacilitiesResult_t));
|
frep->choice.data.choice.attributes.list.count = nra;
|
||||||
fdres->result->present = FacilitiesResult_PR_attributes;
|
frep->choice.data.choice.attributes.list.size = sizeof(void*) * nra;
|
||||||
fdres->result->choice.attributes.list.count = nra;
|
frep->choice.data.choice.attributes.list.array = malloc(sizeof(void*) * nra);
|
||||||
fdres->result->choice.attributes.list.size = sizeof(void*) * nra;
|
|
||||||
fdres->result->choice.attributes.list.array = malloc(sizeof(void*) * nra);
|
|
||||||
for (int j = 0; j < nra; ++j) {
|
for (int j = 0; j < nra; ++j) {
|
||||||
switch (*fdreq->choice.attributeTypes.list.array[j]) {
|
switch (*freq->choice.data.choice.attributeTypes.list.array[j]) {
|
||||||
case FacilitiesAttributeType_stationId:
|
case FacilitiesAttributeType_stationId:
|
||||||
fdres->result->choice.attributes.list.array[j] = calloc(1, sizeof(FacilitiesAttribute_t) );
|
frep->choice.data.choice.attributes.list.array[j] = calloc(1, sizeof(FacilitiesAttribute_t) );
|
||||||
fdres->result->choice.attributes.list.array[j]->data.size = 8;
|
frep->choice.data.choice.attributes.list.array[j]->data.size = 8;
|
||||||
fdres->result->choice.attributes.list.array[j]->data.buf = malloc(8);
|
frep->choice.data.choice.attributes.list.array[j]->data.buf = malloc(8);
|
||||||
pthread_mutex_lock(&facilities->id.lock);
|
pthread_mutex_lock(&facilities->id.lock);
|
||||||
*((uint64_t*) fdres->result->choice.attributes.list.array[j]->data.buf) = facilities->id.value;
|
*((uint64_t*) frep->choice.data.choice.attributes.list.array[j]->data.buf) = facilities->id.value;
|
||||||
pthread_mutex_unlock(&facilities->id.lock);
|
pthread_mutex_unlock(&facilities->id.lock);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
syslog_debug("[facilities] unrecognized FDR attribute type request");
|
syslog_debug("[facilities] unrecognized FR attribute type request");
|
||||||
facilities_request_result_rejected(responder);
|
facilities_request_result_rejected(responder);
|
||||||
rv = 1;
|
rv = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uint8_t fdres_oer[256];
|
uint8_t frep_oer[256];
|
||||||
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesDataResult, NULL, fdres, fdres_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 FDResult (%s)", enc.failed_type->name);
|
syslog_err("[facilities] 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, fdres_oer, enc.encoded, 0);
|
zmq_send(responder, frep_oer, enc.encoded, 0);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
ASN_STRUCT_FREE(asn_DEF_FacilitiesDataResult, fdres);
|
ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, frep);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int facilities_request_loaded_protected_zones(facilities_t* facilities, void* responder, FacilitiesDataRequest_t* fdreq) {
|
int facilities_request_loaded_protected_zones(facilities_t* facilities, void* responder, FacilitiesRequest_t* freq) {
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
FacilitiesDataResult_t* fdres = calloc(1, sizeof(FacilitiesDataResult_t));
|
FacilitiesReply_t* frep = calloc(1, sizeof(FacilitiesReply_t));
|
||||||
|
|
||||||
fdres->code = FacilitiesResultCode_accepted;
|
frep->present = FacilitiesReply_PR_data;
|
||||||
fdres->result = calloc(1, sizeof(FacilitiesResult_t));
|
frep->choice.data.present = FacilitiesDataReply_PR_protectedCommunicationZones;
|
||||||
fdres->result->present = FacilitiesResult_PR_protectedCommunicationZones;
|
|
||||||
|
|
||||||
pthread_mutex_lock(&facilities->lightship->lock);
|
pthread_mutex_lock(&facilities->lightship->lock);
|
||||||
|
|
||||||
fdres->result->choice.protectedCommunicationZones.list.count = facilities->lightship->protected_zones.pz_len;
|
frep->choice.data.choice.protectedCommunicationZones.list.count = facilities->lightship->protected_zones.pz_len;
|
||||||
fdres->result->choice.protectedCommunicationZones.list.size = facilities->lightship->protected_zones.pz_len * sizeof(void*);
|
frep->choice.data.choice.protectedCommunicationZones.list.size = facilities->lightship->protected_zones.pz_len * sizeof(void*);
|
||||||
fdres->result->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) {
|
||||||
fdres->result->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**) &fdres->result->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);
|
pthread_mutex_unlock(&facilities->lightship->lock);
|
||||||
|
|
||||||
uint8_t fdres_oer[1024];
|
uint8_t frep_oer[1024];
|
||||||
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_FacilitiesDataResult, NULL, fdres, fdres_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);
|
syslog_err("[facilities] failed encoding FDResult (%s)", enc.failed_type->name);
|
||||||
facilities_request_result_rejected(responder);
|
facilities_request_result_rejected(responder);
|
||||||
|
|
@ -510,10 +511,10 @@ int facilities_request_loaded_protected_zones(facilities_t* facilities, void* re
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
zmq_send(responder, fdres_oer, enc.encoded, 0);
|
zmq_send(responder, frep_oer, enc.encoded, 0);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
ASN_STRUCT_FREE(asn_DEF_FacilitiesDataResult, fdres);
|
ASN_STRUCT_FREE(asn_DEF_FacilitiesReply, frep);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,14 @@
|
||||||
#define FACILITIES_REQUESTS
|
#define FACILITIES_REQUESTS
|
||||||
|
|
||||||
#include "facilities.h"
|
#include "facilities.h"
|
||||||
#include <itss-facilities/FacilitiesDataRequest.h>
|
#include <itss-facilities/FacilitiesRequest.h>
|
||||||
|
|
||||||
int facilities_request_result_accepted(void* responder);
|
int facilities_request_result_accepted(void* responder);
|
||||||
int facilities_request_result_rejected(void* responder);
|
int facilities_request_result_rejected(void* responder);
|
||||||
|
|
||||||
int facilities_request_single_message(facilities_t* facilities, void* responder, FacilitiesDataRequest_t* fdreq);
|
int facilities_request_single_message(facilities_t* facilities, void* responder, FacilitiesRequest_t* fr);
|
||||||
int facilities_request_active_episodes(facilities_t* facilities, void* responder, FacilitiesDataRequest_t* fdreq);
|
int facilities_request_active_episodes(facilities_t* facilities, void* responder, FacilitiesRequest_t* fr);
|
||||||
int facilities_request_attribute_types(facilities_t* facilities, void* responder, FacilitiesDataRequest_t* fdreq);
|
int facilities_request_attribute_types(facilities_t* facilities, void* responder, FacilitiesRequest_t* fr);
|
||||||
int facilities_request_loaded_protected_zones(facilities_t* facilities, void* responder, FacilitiesDataRequest_t* fdreq);
|
int facilities_request_loaded_protected_zones(facilities_t* facilities, void* responder, FacilitiesRequest_t* fr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
77
src/sa.c
77
src/sa.c
|
|
@ -3,7 +3,7 @@
|
||||||
#include "infrastructure.h"
|
#include "infrastructure.h"
|
||||||
|
|
||||||
#include <it2s-tender/time.h>
|
#include <it2s-tender/time.h>
|
||||||
#include <itss-transport/TransportDataRequest.h>
|
#include <itss-transport/TransportRequest.h>
|
||||||
#include <saem/SAEM.h>
|
#include <saem/SAEM.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
|
|
@ -118,7 +118,7 @@ int mk_saem(facilities_t* facilities, uint8_t* b_saem, uint32_t* b_saem_len) {
|
||||||
saem->header.stationID = facilities->id.value;
|
saem->header.stationID = facilities->id.value;
|
||||||
pthread_mutex_unlock(&facilities->id.lock);
|
pthread_mutex_unlock(&facilities->id.lock);
|
||||||
|
|
||||||
uint8_t ipv6_addr[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
|
uint8_t ipv6_addr[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
|
||||||
|
|
||||||
/* sam */
|
/* sam */
|
||||||
saem->sam.version = 0;
|
saem->sam.version = 0;
|
||||||
|
|
@ -170,36 +170,39 @@ void *sa_service(void *fc) {
|
||||||
|
|
||||||
pthread_mutex_init(&facilities->bulletin.lock, NULL);
|
pthread_mutex_init(&facilities->bulletin.lock, NULL);
|
||||||
|
|
||||||
TransportDataRequest_t *tdr = calloc(1, sizeof(TransportDataRequest_t));
|
TransportRequest_t *tr = calloc(1, sizeof(TransportRequest_t));
|
||||||
tdr->present = TransportDataRequest_PR_btp;
|
tr->present = TransportRequest_PR_data;
|
||||||
BTPDataRequest_t *bdr = &tdr->choice.btp;
|
TransportPacketRequest_t* tpr = &tr->choice.packet;
|
||||||
|
|
||||||
|
tpr->present = TransportPacketRequest_PR_btp;
|
||||||
|
BTPPacketRequest_t *bpr = &tpr->choice.btp;
|
||||||
|
|
||||||
bulletin_t* bulletin = &facilities->bulletin;
|
bulletin_t* bulletin = &facilities->bulletin;
|
||||||
|
|
||||||
bdr->btpType = BTPType_btpB;
|
bpr->btpType = BTPType_btpB;
|
||||||
|
|
||||||
bdr->gn.destinationAddress.buf = malloc(6);
|
bpr->gn.destinationAddress.buf = malloc(6);
|
||||||
for (int i = 0; i < 6; ++i) {
|
for (int i = 0; i < 6; ++i) {
|
||||||
bdr->gn.destinationAddress.buf[i] = 0xff;
|
bpr->gn.destinationAddress.buf[i] = 0xff;
|
||||||
}
|
}
|
||||||
bdr->gn.destinationAddress.size = 6;
|
bpr->gn.destinationAddress.size = 6;
|
||||||
|
|
||||||
bdr->gn.packetTransportType = PacketTransportType_shb;
|
bpr->gn.packetTransportType = PacketTransportType_shb;
|
||||||
|
|
||||||
bdr->destinationPort = Port_saem;
|
bpr->destinationPort = Port_saem;
|
||||||
|
|
||||||
bdr->gn.trafficClass = 2;
|
bpr->gn.trafficClass = 2;
|
||||||
|
|
||||||
bdr->data.buf = malloc(512);
|
bpr->data.buf = malloc(512);
|
||||||
bdr->data.size = 512;
|
bpr->data.size = 512;
|
||||||
|
|
||||||
if (facilities->use_security) {
|
if (facilities->use_security) {
|
||||||
bdr->gn.securityProfile = malloc(sizeof(long));
|
bpr->gn.securityProfile = malloc(sizeof(long));
|
||||||
*bdr->gn.securityProfile = 1;
|
*bpr->gn.securityProfile = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t tdr_oer[1024];
|
uint8_t tr_oer[1024];
|
||||||
tdr_oer[0] = 4; // Facilities
|
tr_oer[0] = 4; // Facilities
|
||||||
|
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
|
|
@ -209,14 +212,14 @@ void *sa_service(void *fc) {
|
||||||
while (!facilities->exit) {
|
while (!facilities->exit) {
|
||||||
|
|
||||||
if (bulletin->to_provide_len && sleep_ms*mk_saem_n_sleep >= 1000) {
|
if (bulletin->to_provide_len && sleep_ms*mk_saem_n_sleep >= 1000) {
|
||||||
rv = mk_saem(facilities, bdr->data.buf, (uint32_t *) &bdr->data.size);
|
rv = mk_saem(facilities, bpr->data.buf, (uint32_t *) &bpr->data.size);
|
||||||
if (!rv) {
|
if (!rv) {
|
||||||
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportDataRequest, NULL, tdr, tdr_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 TDR for SAEM failed");
|
syslog_err("[facilities] encoding TR for SAEM failed");
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
queue_add(facilities->tx_queue, tdr_oer, enc.encoded+1, 3);
|
queue_add(facilities->tx_queue, tr_oer, enc.encoded+1, 3);
|
||||||
pthread_cond_signal(&facilities->tx_queue->trigger);
|
pthread_cond_signal(&facilities->tx_queue->trigger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -232,31 +235,33 @@ void *sa_service(void *fc) {
|
||||||
|
|
||||||
if (bulletin->to_consume[a]->its_aid == 0 && !bulletin->to_consume[a]->n_trigger) {
|
if (bulletin->to_consume[a]->its_aid == 0 && !bulletin->to_consume[a]->n_trigger) {
|
||||||
|
|
||||||
TransportDataRequest_t* tdr_etc = calloc(1, sizeof(TransportDataRequest_t));
|
TransportRequest_t* tr_etc = calloc(1, sizeof(TransportRequest_t));
|
||||||
tdr_etc->present = TransportDataRequest_PR_tcp;
|
tr_etc->present = TransportRequest_PR_packet;
|
||||||
|
TransportPacketRequest_t* tpr_etc = &tr_etc->choice.packet;
|
||||||
|
tpr_etc->present = TransportPacketRequest_PR_tcp;
|
||||||
|
|
||||||
tdr_etc->choice.tcp.data.buf = malloc(7);
|
tpr_etc->choice.tcp.data.buf = malloc(7);
|
||||||
tdr_etc->choice.tcp.data.size = 7;
|
tpr_etc->choice.tcp.data.size = 7;
|
||||||
char hello[] = "Hello!";
|
char hello[] = "Hello!";
|
||||||
memcpy(tdr_etc->choice.tcp.data.buf, hello, 7);
|
memcpy(tpr_etc->choice.tcp.data.buf, hello, 7);
|
||||||
|
|
||||||
tdr_etc->choice.tcp.gn = calloc(1, sizeof(GeonetworkingOutboundOptions_t));
|
tpr_etc->choice.tcp.gn = calloc(1, sizeof(GeonetworkingOutboundOptions_t));
|
||||||
tdr_etc->choice.tcp.gn->packetTransportType = PacketTransportType_shb;
|
tpr_etc->choice.tcp.gn->packetTransportType = PacketTransportType_shb;
|
||||||
tdr_etc->choice.tcp.gn->destinationAddress.buf = calloc(1, 6);
|
tpr_etc->choice.tcp.gn->destinationAddress.buf = calloc(1, 6);
|
||||||
tdr_etc->choice.tcp.gn->destinationAddress.size = 6;
|
tpr_etc->choice.tcp.gn->destinationAddress.size = 6;
|
||||||
|
|
||||||
++bulletin->to_consume[a]->n_trigger;
|
++bulletin->to_consume[a]->n_trigger;
|
||||||
|
|
||||||
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportDataRequest, NULL, tdr_etc, tdr_oer+1, 1023);
|
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr_etc, tr_oer+1, 1023);
|
||||||
if (enc.encoded == -1) {
|
if (enc.encoded == -1) {
|
||||||
syslog_err("[facilities] encoding TDR for ETC-Req failed");
|
syslog_err("[facilities] encoding TR for ETC-Req failed");
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
queue_add(facilities->tx_queue, tdr_oer, enc.encoded+1, 3);
|
queue_add(facilities->tx_queue, tr_oer, enc.encoded+1, 3);
|
||||||
pthread_cond_signal(&facilities->tx_queue->trigger);
|
pthread_cond_signal(&facilities->tx_queue->trigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASN_STRUCT_FREE(asn_DEF_TransportDataRequest, tdr_etc);
|
ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr_etc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&bulletin->lock);
|
pthread_mutex_unlock(&bulletin->lock);
|
||||||
|
|
@ -264,7 +269,7 @@ void *sa_service(void *fc) {
|
||||||
usleep(sleep_ms*1000);
|
usleep(sleep_ms*1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASN_STRUCT_FREE(asn_DEF_TransportDataRequest, tdr);
|
ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr);
|
||||||
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#include <itss-transport/TransportDataRequest.h>
|
#include <itss-transport/TransportRequest.h>
|
||||||
#include <itss-transport/TransportDataIndication.h>
|
#include <itss-transport/TransportIndication.h>
|
||||||
#include <itss-facilities/FacilitiesDataIndication.h>
|
#include <itss-facilities/FacilitiesIndication.h>
|
||||||
#include <itss-facilities/FacilitiesDataRequest.h>
|
#include <itss-facilities/FacilitiesRequest.h>
|
||||||
#include <itss-management/ManagementRequest.h>
|
#include <itss-management/ManagementRequest.h>
|
||||||
#include <itss-management/ManagementReply.h>
|
#include <itss-management/ManagementReply.h>
|
||||||
|
|
||||||
|
|
@ -144,15 +144,15 @@ int cam_gen(void* ctx) {
|
||||||
|
|
||||||
zmq_close(transport_socket);
|
zmq_close(transport_socket);
|
||||||
|
|
||||||
TransportDataRequest_t* tdr = NULL;
|
TransportRequest_t* tr = NULL;
|
||||||
asn_dec_rval_t dec = asn_decode(NULL, ATS_CANONICAL_OER, &asn_DEF_TransportDataRequest, (void**) &tdr, buffer+1, 2047);
|
asn_dec_rval_t dec = asn_decode(NULL, ATS_CANONICAL_OER, &asn_DEF_TransportRequest, (void**) &tr, buffer+1, 2047);
|
||||||
if (dec.code) {
|
if (dec.code) {
|
||||||
printf(" FAIL\n"); fflush(stdout);
|
printf(" FAIL\n"); fflush(stdout);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
printf(" - Received CAM BDR (%ldB)\n", tdr->choice.btp.data.size); fflush(stdout);
|
printf(" - Received CAM TR (%ldB)\n", tr->choice.packet.choice.btp.data.size); fflush(stdout);
|
||||||
|
|
||||||
if (tdr->choice.btp.destinationPort == Port_cam) {
|
if (tr->choice.packet.choice.btp.destinationPort == Port_cam) {
|
||||||
printf(" OK\n"); fflush(stdout);
|
printf(" OK\n"); fflush(stdout);
|
||||||
} else {
|
} else {
|
||||||
printf(" FAIL\n"); fflush(stdout);
|
printf(" FAIL\n"); fflush(stdout);
|
||||||
|
|
@ -166,9 +166,10 @@ int cam_gen(void* ctx) {
|
||||||
int forward_up(void* ctx) {
|
int forward_up(void* ctx) {
|
||||||
printf("Testing forwarding up:\n"); fflush(stdout);
|
printf("Testing forwarding up:\n"); fflush(stdout);
|
||||||
|
|
||||||
TransportDataIndication_t* tdi = calloc(1, sizeof(TransportDataIndication_t));
|
TransportIndication_t* ti = calloc(1, sizeof(TransportIndication_t));
|
||||||
tdi->present = TransportDataIndication_PR_btp;
|
ti->present = TransportIndication_PR_packet;
|
||||||
BTPDataIndication_t* bdi = &tdi->choice.btp;
|
ti->choice.packet.present = TransportPacketIndication_PR_btp;
|
||||||
|
BTPPacketIndication_t* bpi = &ti->choice.packet.choice.btp;
|
||||||
|
|
||||||
char* cam_hex = "02027dfddf4403ca4059bba5f38cc40dba9ffffffc2230eff200e11fc0078082a88a8337fee3fff600004dffea800618d08018efff14003ac68800c77ff8e002263460063bffd1000fb1a30031dffe2800958d30018efff840048c68800c77ffae002c63480063bffbd001a31a40031dfff28002d8cf0018c0";
|
char* cam_hex = "02027dfddf4403ca4059bba5f38cc40dba9ffffffc2230eff200e11fc0078082a88a8337fee3fff600004dffea800618d08018efff14003ac68800c77ff8e002263460063bffd1000fb1a30031dffe2800958d30018efff840048c68800c77ffae002c63480063bffbd001a31a40031dfff28002d8cf0018c0";
|
||||||
|
|
||||||
|
|
@ -176,29 +177,29 @@ int forward_up(void* ctx) {
|
||||||
uint16_t cam_len;
|
uint16_t cam_len;
|
||||||
hex2bin(cam_hex, &cam, &cam_len);
|
hex2bin(cam_hex, &cam, &cam_len);
|
||||||
|
|
||||||
bdi->data.buf = cam;
|
bpi->data.buf = cam;
|
||||||
bdi->data.size = cam_len;
|
bpi->data.size = cam_len;
|
||||||
bdi->gn.destinationAddress.buf = calloc(1, 6);
|
bpi->gn.destinationAddress.buf = calloc(1, 6);
|
||||||
bdi->gn.destinationAddress.size = 6;
|
bpi->gn.destinationAddress.size = 6;
|
||||||
bdi->destinationPort = Port_cam;
|
bpi->destinationPort = Port_cam;
|
||||||
|
|
||||||
uint8_t b_tdi_cam[512];
|
uint8_t b_ti_cam[512];
|
||||||
b_tdi_cam[0] = 3;
|
b_ti_cam[0] = 3;
|
||||||
|
|
||||||
asn_enc_rval_t enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_TransportDataIndication, tdi, b_tdi_cam+1, 511);
|
asn_enc_rval_t enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_TransportIndication, ti, b_ti_cam+1, 511);
|
||||||
|
|
||||||
void* facilities_socket = zmq_socket(ctx, ZMQ_REQ);
|
void* facilities_socket = zmq_socket(ctx, ZMQ_REQ);
|
||||||
|
|
||||||
int code = 0;
|
int code = 0;
|
||||||
|
|
||||||
zmq_connect(facilities_socket, "ipc:///tmp/itss/facilities");
|
zmq_connect(facilities_socket, "ipc:///tmp/itss/facilities");
|
||||||
zmq_send(facilities_socket, b_tdi_cam, enc.encoded+1, 0);
|
zmq_send(facilities_socket, b_ti_cam, enc.encoded+1, 0);
|
||||||
zmq_recv(facilities_socket, &code, 1, 0);
|
zmq_recv(facilities_socket, &code, 1, 0);
|
||||||
if (code) {
|
if (code) {
|
||||||
printf(" FAIL\n"); fflush(stdout);
|
printf(" FAIL\n"); fflush(stdout);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
printf(" - Sent CAM BDI (%ldB)\n", bdi->data.size); fflush(stdout);
|
printf(" - Sent CAM TI (%ldB)\n", bpi->data.size); fflush(stdout);
|
||||||
|
|
||||||
void* applications_socket = zmq_socket(ctx, ZMQ_REP);
|
void* applications_socket = zmq_socket(ctx, ZMQ_REP);
|
||||||
|
|
||||||
|
|
@ -211,15 +212,15 @@ int forward_up(void* ctx) {
|
||||||
zmq_close(applications_socket);
|
zmq_close(applications_socket);
|
||||||
zmq_close(facilities_socket);
|
zmq_close(facilities_socket);
|
||||||
|
|
||||||
FacilitiesDataIndication_t* fdi = NULL;
|
FacilitiesIndication_t* fi = NULL;
|
||||||
asn_dec_rval_t dec = asn_decode(NULL, ATS_CANONICAL_OER, &asn_DEF_FacilitiesDataIndication, (void**) &fdi, buffer+1, 2047);
|
asn_dec_rval_t dec = asn_decode(NULL, ATS_CANONICAL_OER, &asn_DEF_FacilitiesIndication, (void**) &fi, buffer+1, 2047);
|
||||||
if (dec.code) {
|
if (dec.code) {
|
||||||
printf(" FAIL\n"); fflush(stdout);
|
printf(" FAIL\n"); fflush(stdout);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
printf(" - Received CAM FDI (%ldB)\n", fdi->data.size); fflush(stdout);
|
printf(" - Received CAM FI (%ldB)\n", fi->choice.message.data.size); fflush(stdout);
|
||||||
|
|
||||||
if (fdi->data.size == bdi->data.size) {
|
if (fi->choice.message.data.size == bpi->data.size) {
|
||||||
printf(" OK\n"); fflush(stdout);
|
printf(" OK\n"); fflush(stdout);
|
||||||
} else {
|
} else {
|
||||||
printf(" FAIL\n"); fflush(stdout);
|
printf(" FAIL\n"); fflush(stdout);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue