Forward PCMs to applications

This commit is contained in:
emanuel 2022-03-14 10:28:12 +00:00
parent c94964a832
commit 322efce93c
2 changed files with 40 additions and 16 deletions

View File

@ -230,6 +230,7 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
case 2043: case 2043:
pcm_check(facilities, its_msg); pcm_check(facilities, its_msg);
fwd = true;
break; break;
default: default:

View File

@ -7,6 +7,7 @@
#include <it2s-tender/geodesy.h> #include <it2s-tender/geodesy.h>
#include <it2s-tender/recorder.h> #include <it2s-tender/recorder.h>
#include <itss-transport/TransportRequest.h> #include <itss-transport/TransportRequest.h>
#include <itss-facilities/FacilitiesIndication.h>
#include <pcm/PCM.h> #include <pcm/PCM.h>
static int are_vehicles_intersecting( static int are_vehicles_intersecting(
@ -54,6 +55,7 @@ static int pcm_check_handle_request(facilities_t* facilities, PCM_t* pcm, mc_nei
PCM_t* pcm_rep = NULL; PCM_t* pcm_rep = NULL;
TransportRequest_t* tr = NULL; TransportRequest_t* tr = NULL;
FacilitiesIndication_t* fi = NULL;
const ssize_t buf_len = 512; const ssize_t buf_len = 512;
uint8_t buf[buf_len]; uint8_t buf[buf_len];
@ -132,27 +134,19 @@ static int pcm_check_handle_request(facilities_t* facilities, PCM_t* pcm, mc_nei
tr->present = TransportRequest_PR_packet; tr->present = TransportRequest_PR_packet;
tr->choice.packet.present = TransportPacketRequest_PR_btp; tr->choice.packet.present = TransportPacketRequest_PR_btp;
BTPPacketRequest_t* bpr = &tr->choice.packet.choice.btp; BTPPacketRequest_t* bpr = &tr->choice.packet.choice.btp;
bpr->btpType = BTPType_btpB; bpr->btpType = BTPType_btpB;
bpr->id = rand() + 1; bpr->id = rand() + 1;
bpr->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) {
bpr->gn.destinationAddress.buf[i] = 0xff; bpr->gn.destinationAddress.buf[i] = 0xff;
} }
bpr->gn.destinationAddress.size = 6; bpr->gn.destinationAddress.size = 6;
bpr->gn.packetTransportType = PacketTransportType_shb; bpr->gn.packetTransportType = PacketTransportType_shb;
bpr->destinationPort = 2043; bpr->destinationPort = 2043;
bpr->gn.trafficClass = 2; bpr->gn.trafficClass = 2;
bpr->data.buf = malloc(pcm_rep_len); bpr->data.buf = malloc(pcm_rep_len);
memcpy(bpr->data.buf, buf, pcm_rep_len); memcpy(bpr->data.buf, buf, pcm_rep_len);
bpr->data.size = pcm_rep_len; bpr->data.size = pcm_rep_len;
buf[0] = 4; buf[0] = 4;
enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_TransportRequest, tr, buf+1, buf_len-1); enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_TransportRequest, tr, buf+1, buf_len-1);
if (enc.encoded == -1) { if (enc.encoded == -1) {
@ -163,6 +157,23 @@ static int pcm_check_handle_request(facilities_t* facilities, PCM_t* pcm, mc_nei
it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp"); it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp");
fi = calloc(1, sizeof(FacilitiesIndication_t));
fi->present = FacilitiesIndication_PR_message;
fi->choice.message.id = bpr->id;
fi->choice.message.itsMessageType = 43;
fi->choice.message.data.size = bpr->data.size;
fi->choice.message.data.buf = malloc(bpr->data.size);
memcpy(fi->choice.message.data.buf, bpr->data.buf, bpr->data.size);
buf[0] = 4;
enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_FacilitiesIndication, fi, buf+1, buf_len-1);
if (enc.encoded == -1) {
syslog_err("[facilities] [pc] TR PCM.reply encode failure (%s)", enc.failed_type->name);
rv = 1;
goto cleanup;
}
it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, bpr->id, "FI.message");
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];
@ -183,6 +194,7 @@ static int pcm_check_handle_request(facilities_t* facilities, PCM_t* pcm, mc_nei
cleanup: cleanup:
ASN_STRUCT_FREE(asn_DEF_PCM, pcm_rep); ASN_STRUCT_FREE(asn_DEF_PCM, pcm_rep);
ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr); ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr);
ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi);
return rv; return rv;
} }
@ -209,6 +221,7 @@ static int pcm_check_intersection_detected(facilities_t* facilities, PCM_t* pcm,
PCM_t* pcm_req = NULL; PCM_t* pcm_req = NULL;
TransportRequest_t* tr = NULL; TransportRequest_t* tr = NULL;
FacilitiesIndication_t* fi = NULL;
const ssize_t buf_len = 1024; const ssize_t buf_len = 1024;
uint8_t buf[buf_len]; uint8_t buf[buf_len];
@ -321,27 +334,19 @@ static int pcm_check_intersection_detected(facilities_t* facilities, PCM_t* pcm,
tr->present = TransportRequest_PR_packet; tr->present = TransportRequest_PR_packet;
tr->choice.packet.present = TransportPacketRequest_PR_btp; tr->choice.packet.present = TransportPacketRequest_PR_btp;
BTPPacketRequest_t* bpr = &tr->choice.packet.choice.btp; BTPPacketRequest_t* bpr = &tr->choice.packet.choice.btp;
bpr->id = rand() + 1; bpr->id = rand() + 1;
bpr->btpType = BTPType_btpB; bpr->btpType = BTPType_btpB;
bpr->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) {
bpr->gn.destinationAddress.buf[i] = 0xff; bpr->gn.destinationAddress.buf[i] = 0xff;
} }
bpr->gn.destinationAddress.size = 6; bpr->gn.destinationAddress.size = 6;
bpr->gn.packetTransportType = PacketTransportType_shb; bpr->gn.packetTransportType = PacketTransportType_shb;
bpr->destinationPort = 2043; bpr->destinationPort = 2043;
bpr->gn.trafficClass = 2; bpr->gn.trafficClass = 2;
bpr->data.buf = malloc(pcm_req_len); bpr->data.buf = malloc(pcm_req_len);
memcpy(bpr->data.buf, buf, pcm_req_len); memcpy(bpr->data.buf, buf, pcm_req_len);
bpr->data.size = pcm_req_len; bpr->data.size = pcm_req_len;
buf[0] = 4; buf[0] = 4;
enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_TransportRequest, tr, buf+1, buf_len-1); enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_TransportRequest, tr, buf+1, buf_len-1);
if (enc.encoded == -1) { if (enc.encoded == -1) {
@ -352,6 +357,23 @@ static int pcm_check_intersection_detected(facilities_t* facilities, PCM_t* pcm,
it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp"); it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp");
fi = calloc(1, sizeof(FacilitiesIndication_t));
fi->present = FacilitiesIndication_PR_message;
fi->choice.message.id = bpr->id;
fi->choice.message.itsMessageType = 43;
fi->choice.message.data.size = bpr->data.size;
fi->choice.message.data.buf = malloc(bpr->data.size);
memcpy(fi->choice.message.data.buf, bpr->data.buf, bpr->data.size);
buf[0] = 4;
enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_FacilitiesIndication, fi, buf+1, buf_len-1);
if (enc.encoded == -1) {
syslog_err("[facilities] [pc] TR PCM.reply encode failure (%s)", enc.failed_type->name);
rv = 1;
goto cleanup;
}
it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_APPLICATIONS, bpr->id, "FI.message");
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];
@ -372,6 +394,7 @@ static int pcm_check_intersection_detected(facilities_t* facilities, PCM_t* pcm,
cleanup: cleanup:
ASN_STRUCT_FREE(asn_DEF_PCM, pcm_req); ASN_STRUCT_FREE(asn_DEF_PCM, pcm_req);
ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr); ASN_STRUCT_FREE(asn_DEF_TransportRequest, tr);
ASN_STRUCT_FREE(asn_DEF_FacilitiesIndication, fi);
return rv; return rv;
} }