- GOOSE L2 Security: moved L2Security from GooseReceiver to GooseSubscriber (LIB61850-329)
parent
ef4e7fdb2e
commit
a328860449
@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
set(goose_publisher_example_SRCS
|
||||||
|
goose_publisher_example2.c
|
||||||
|
)
|
||||||
|
|
||||||
|
IF(MSVC)
|
||||||
|
|
||||||
|
set_source_files_properties(${goose_publisher_example_SRCS}
|
||||||
|
PROPERTIES LANGUAGE CXX)
|
||||||
|
ENDIF(MSVC)
|
||||||
|
|
||||||
|
add_executable(goose_publisher_example2
|
||||||
|
${goose_publisher_example_SRCS}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(goose_publisher_example2
|
||||||
|
iec61850
|
||||||
|
)
|
||||||
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
|||||||
|
LIBIEC_HOME=../..
|
||||||
|
|
||||||
|
PROJECT_BINARY_NAME = goose_publisher_example2
|
||||||
|
PROJECT_SOURCES = goose_publisher_example2.c
|
||||||
|
|
||||||
|
include $(LIBIEC_HOME)/make/target_system.mk
|
||||||
|
include $(LIBIEC_HOME)/make/stack_includes.mk
|
||||||
|
|
||||||
|
all: $(PROJECT_BINARY_NAME)
|
||||||
|
|
||||||
|
include $(LIBIEC_HOME)/make/common_targets.mk
|
||||||
|
|
||||||
|
$(PROJECT_BINARY_NAME): $(PROJECT_SOURCES) $(LIB_NAME)
|
||||||
|
$(CC) $(CFLAGS) $(LDFLAGS) -o $(PROJECT_BINARY_NAME) $(PROJECT_SOURCES) $(INCLUDES) $(LIB_NAME) $(LDLIBS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(PROJECT_BINARY_NAME)
|
@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* goose_publisher_example.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "mms_value.h"
|
||||||
|
#include "goose_publisher.h"
|
||||||
|
#include "hal_thread.h"
|
||||||
|
|
||||||
|
/* has to be executed as root! */
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
char *interface;
|
||||||
|
|
||||||
|
if (argc > 1)
|
||||||
|
interface = argv[1];
|
||||||
|
else
|
||||||
|
interface = "eth0";
|
||||||
|
|
||||||
|
printf("Using interface %s\n", interface);
|
||||||
|
|
||||||
|
LinkedList dataSetValues = LinkedList_create();
|
||||||
|
|
||||||
|
LinkedList_add(dataSetValues, MmsValue_newIntegerFromInt32(1234));
|
||||||
|
LinkedList_add(dataSetValues, MmsValue_newBinaryTime(false));
|
||||||
|
LinkedList_add(dataSetValues, MmsValue_newIntegerFromInt32(5678));
|
||||||
|
|
||||||
|
CommParameters gooseCommParameters;
|
||||||
|
|
||||||
|
gooseCommParameters.appId = 1001;
|
||||||
|
gooseCommParameters.dstAddress[0] = 0x01;
|
||||||
|
gooseCommParameters.dstAddress[1] = 0x0c;
|
||||||
|
gooseCommParameters.dstAddress[2] = 0xcd;
|
||||||
|
gooseCommParameters.dstAddress[3] = 0x01;
|
||||||
|
gooseCommParameters.dstAddress[4] = 0x00;
|
||||||
|
gooseCommParameters.dstAddress[5] = 0x02;
|
||||||
|
gooseCommParameters.vlanId = 0;
|
||||||
|
gooseCommParameters.vlanPriority = 4;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a new GOOSE publisher instance. As the second parameter the interface
|
||||||
|
* name can be provided (e.g. "eth0" on a Linux system). If the second parameter
|
||||||
|
* is NULL the interface name as defined with CONFIG_ETHERNET_INTERFACE_ID in
|
||||||
|
* stack_config.h is used.
|
||||||
|
*/
|
||||||
|
GoosePublisher publisher = GoosePublisher_create(&gooseCommParameters, interface);
|
||||||
|
|
||||||
|
if (publisher)
|
||||||
|
{
|
||||||
|
GoosePublisher_setGoCbRef(publisher, "simpleIOGenericIO/LLN0$GO$gcbAnalogValues2");
|
||||||
|
GoosePublisher_setConfRev(publisher, 1);
|
||||||
|
GoosePublisher_setDataSetRef(publisher, "simpleIOGenericIO/LLN0$AnalogValues2");
|
||||||
|
GoosePublisher_setTimeAllowedToLive(publisher, 500);
|
||||||
|
|
||||||
|
char* key = "ABCDEF0123456789";
|
||||||
|
|
||||||
|
L2Security l2Sec = L2Security_create();
|
||||||
|
|
||||||
|
//L2Security_addKey(l2Sec, 0x12345678, (uint8_t*)key, 16, MC_SEC_SEC_ALGO_NONE, MC_SEC_SIG_ALGO_HMAC_SHA256_256);
|
||||||
|
L2Security_addKey(l2Sec, 0x12345678, (uint8_t*)key, 16, MC_SEC_SEC_ALGO_NONE, MC_SEC_SIG_ALGO_AES_GMAC_128);
|
||||||
|
L2Security_setActiveKey(l2Sec, 1);
|
||||||
|
|
||||||
|
GoosePublisher_setL2Security(publisher, l2Sec);
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < 4; i++) {
|
||||||
|
Thread_sleep(1000);
|
||||||
|
|
||||||
|
if (i == 3) {
|
||||||
|
/* now change dataset to send an invalid GOOSE message */
|
||||||
|
LinkedList_add(dataSetValues, MmsValue_newBoolean(true));
|
||||||
|
GoosePublisher_publish(publisher, dataSetValues);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (GoosePublisher_publish(publisher, dataSetValues) == -1) {
|
||||||
|
printf("Error sending message!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GoosePublisher_destroy(publisher);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("Failed to create GOOSE publisher. Reason can be that the Ethernet interface doesn't exist or root permission are required.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
LinkedList_destroyDeep(dataSetValues, (LinkedListValueDeleteFunction) MmsValue_delete);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue