Send stationID to [management]
This commit is contained in:
parent
b7ea3981bf
commit
79a66dd0de
19
src/config.c
19
src/config.c
|
|
@ -186,6 +186,23 @@ int facilities_config(void* facilities_s) {
|
||||||
} else {
|
} else {
|
||||||
facilities->id.value = config->security.identity.station_id;
|
facilities->id.value = config->security.identity.station_id;
|
||||||
}
|
}
|
||||||
|
// Inform management
|
||||||
|
ManagementRequest_t* mreq_set = calloc(1, sizeof(ManagementRequest_t));
|
||||||
|
mreq_set->present = ManagementRequest_PR_set;
|
||||||
|
mreq_set->choice.set.stationId = malloc(sizeof(long));
|
||||||
|
*mreq_set->choice.set.stationId = facilities->id.value;
|
||||||
|
uint8_t b_oer[128];
|
||||||
|
asn_enc_rval_t enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_ManagementRequest, mreq_set, b_oer, 128);
|
||||||
|
if (enc.encoded != -1) {
|
||||||
|
void* management_socket = zmq_socket(facilities->zmq.ctx, ZMQ_REQ);
|
||||||
|
zmq_connect(management_socket, facilities->zmq.management_address);
|
||||||
|
zmq_send(management_socket, b_oer, enc.encoded, 0);
|
||||||
|
uint8_t code;
|
||||||
|
zmq_recv(management_socket, &code, 1, 0);
|
||||||
|
zmq_close(management_socket);
|
||||||
|
}
|
||||||
|
ASN_STRUCT_FREE(asn_DEF_ManagementRequest, mreq_set);
|
||||||
|
|
||||||
|
|
||||||
// DENM
|
// DENM
|
||||||
facilities->den->default_event_duration = config->facilities.denm.default_event_duration;
|
facilities->den->default_event_duration = config->facilities.denm.default_event_duration;
|
||||||
|
|
@ -274,7 +291,7 @@ int facilities_config(void* facilities_s) {
|
||||||
void* management_socket = zmq_socket(facilities->zmq.ctx, ZMQ_REQ);
|
void* management_socket = zmq_socket(facilities->zmq.ctx, ZMQ_REQ);
|
||||||
zmq_connect(management_socket, facilities->zmq.management_address);
|
zmq_connect(management_socket, facilities->zmq.management_address);
|
||||||
uint8_t buffer[256];
|
uint8_t buffer[256];
|
||||||
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_ManagementRequest, NULL, mreq, buffer, 256);
|
enc = oer_encode_to_buffer(&asn_DEF_ManagementRequest, NULL, mreq, buffer, 256);
|
||||||
|
|
||||||
zmq_send(management_socket, buffer, enc.encoded, 0);
|
zmq_send(management_socket, buffer, enc.encoded, 0);
|
||||||
zmq_recv(management_socket, buffer, 256, 0);
|
zmq_recv(management_socket, buffer, 256, 0);
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
#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>
|
||||||
|
#include <itss-management/ManagementRequest.h>
|
||||||
|
|
||||||
#include <camv2/CAM.h>
|
#include <camv2/CAM.h>
|
||||||
#include <denmv2/DENM.h>
|
#include <denmv2/DENM.h>
|
||||||
|
|
@ -285,10 +286,6 @@ static int security_indication(facilities_t *facilities, void* responder_secured
|
||||||
;
|
;
|
||||||
facilities->id.change.stage = ID_CHANGE_COMMIT;
|
facilities->id.change.stage = ID_CHANGE_COMMIT;
|
||||||
|
|
||||||
// Change Station ID
|
|
||||||
facilities->id.value = rand();
|
|
||||||
pthread_mutex_unlock(&facilities->id.lock);
|
|
||||||
|
|
||||||
// Reset lightship
|
// Reset lightship
|
||||||
for (int i = 0; i < facilities->lightship->pos_history_len; ++i) {
|
for (int i = 0; i < facilities->lightship->pos_history_len; ++i) {
|
||||||
free(facilities->lightship->pos_history[i]);
|
free(facilities->lightship->pos_history[i]);
|
||||||
|
|
@ -302,7 +299,13 @@ static int security_indication(facilities_t *facilities, void* responder_secured
|
||||||
|
|
||||||
pthread_mutex_unlock(&facilities->lightship->lock);
|
pthread_mutex_unlock(&facilities->lightship->lock);
|
||||||
|
|
||||||
|
// Change Station ID
|
||||||
|
facilities->id.value = rand();
|
||||||
|
|
||||||
facilities->id.change.stage = ID_CHANGE_INACTIVE;
|
facilities->id.change.stage = ID_CHANGE_INACTIVE;
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&facilities->id.lock);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SecurityIdChangeEventType_abort:
|
case SecurityIdChangeEventType_abort:
|
||||||
|
|
@ -319,13 +322,35 @@ static int security_indication(facilities_t *facilities, void* responder_secured
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&facilities->id.change.lock);
|
|
||||||
|
|
||||||
sr->present = SecurityResponse_PR_idChangeEvent;
|
sr->present = SecurityResponse_PR_idChangeEvent;
|
||||||
sr->choice.idChangeEvent.returnCode = 0;
|
sr->choice.idChangeEvent.returnCode = 0;
|
||||||
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) {
|
||||||
|
// Inform management
|
||||||
|
ManagementRequest_t* mreq = calloc(1, sizeof(ManagementRequest_t));
|
||||||
|
mreq->present = ManagementRequest_PR_set;
|
||||||
|
mreq->choice.set.stationId = malloc(sizeof(long));
|
||||||
|
*mreq->choice.set.stationId = facilities->id.value;
|
||||||
|
uint8_t b_oer[128];
|
||||||
|
asn_enc_rval_t enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_ManagementRequest, mreq, b_oer, 128);
|
||||||
|
if (enc.encoded != -1) {
|
||||||
|
int wait_ms = 1000;
|
||||||
|
void* management_socket = zmq_socket(facilities->zmq.ctx, ZMQ_REQ);
|
||||||
|
zmq_setsockopt(management_socket, ZMQ_RCVTIMEO, &wait_ms, sizeof(int));
|
||||||
|
zmq_connect(management_socket, facilities->zmq.management_address);
|
||||||
|
zmq_send(management_socket, b_oer, enc.encoded, 0);
|
||||||
|
uint8_t code;
|
||||||
|
rv = zmq_recv(management_socket, &code, 1, 0);
|
||||||
|
if (rv == -1) {syslog_err("[facilities]-> timeout sending MReq set.stationId to ->[management]");}
|
||||||
|
zmq_close(management_socket);
|
||||||
|
}
|
||||||
|
ASN_STRUCT_FREE(asn_DEF_ManagementRequest, mreq);
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&facilities->id.change.lock);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (rv) {
|
if (rv) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue