Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
mzillgith committed Oct 17, 2018
2 parents 3375bca + 2769573 commit 87c5c67
Show file tree
Hide file tree
Showing 38 changed files with 3,006 additions and 655 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
Changes to version 2.1.0
------------------------
- added non-threaded moded for CS 104 slave
- separated thread and semaphore support for CS 104 slave
- CS101 unbalanced link layer (master): automatically send request UD 1 when ACD bit is set in received frame
- added CS101_ASDU_getElementEx function to avoid dynamic memory allocation
- added support for static ASDU object allocation
- fixed length check when parsing M_EP_TD_1
- CS101 unbalanced master: fixed state machine problem with multiple slaves (some responses don't change state and master keeps locked on the slave)
- optionally compile library without HAL to simply using together with libiec61850

Changes to version 2.0.2
------------------------
- CS104 slave: added new CS104_ConnectionEventHandler to track connection events
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ the project folder and run cmake to create the build files:
`cd build`
`cmake ..`

## Building without common code and HAL

The library contains some common code and a platform abstraction layer (HAL) that is shared with
other protocol libraries of MZ Automation (e.g. libiec61850). In order to simplify using these
protocol libraries together it is possible to compile the library without the common parts.

This can be done by using the *WITHOUT_HAL* and *WITHOUT_COMMON* defines when calling make:

`make WITHOUT_HAL=1 WITHOUT_COMMON=1`

## Building with TLS support

The library can be build with support for TLS. In order to do so you have to download mbedtls version 2.6.0.
Expand All @@ -49,7 +59,7 @@ The cmake build system will automatically detect the mbedtls source and build th

When using make you have to call make with WITH_MBEDTLS=1

make WITH_MBEDTLS=1
`make WITH_MBEDTLS=1`

## Contact:

Expand Down
20 changes: 13 additions & 7 deletions lib60870-C/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ project(lib60870-C)
ENABLE_TESTING()

set(LIB_VERSION_MAJOR "2")
set(LIB_VERSION_MINOR "0")
set(LIB_VERSION_PATCH "2")
set(LIB_VERSION_MINOR "1")
set(LIB_VERSION_PATCH "0")

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/third_party/cmake/modules/")

Expand All @@ -28,25 +28,31 @@ check_library_exists(rt clock_gettime "time.h" CONFIG_SYSTEM_HAS_CLOCK_GETTIME)
include (TestBigEndian)
test_big_endian(PLATFORM_IS_BIGENDIAN)

option(BUILD_HAL "Build the platform abstraction layer (HAL)" ON)
option(BUILD_COMMON "Build common code (shared with other libraries - e.g. libiec61850)" ON)

option(BUILD_EXAMPLES "Build the examples" ON)
option(BUILD_TESTS "Build the tests" ON)

if(BUILD_HAL)

if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/dependencies/mbedtls-2.6.0)
set(WITH_MBEDTLS 1)
endif(EXISTS ${CMAKE_CURRENT_LIST_DIR}/dependencies/mbedtls-2.6.0)

option(BUILD_EXAMPLES "Build the examples" ON)
option(BUILD_TESTS "Build the tests" ON)
endif(BUILD_HAL)

include_directories(
${CMAKE_CURRENT_LIST_DIR}/config
${CMAKE_CURRENT_LIST_DIR}/src/inc/api
${CMAKE_CURRENT_LIST_DIR}/src/inc/internal
${CMAKE_CURRENT_LIST_DIR}/src/common/inc
${CMAKE_CURRENT_LIST_DIR}/src/hal/inc
${CMAKE_CURRENT_LIST_DIR}/src/tls
)

if(WITH_MBEDTLS)
include_directories(
${CMAKE_CURRENT_LIST_DIR}/src/tls/mbedtls
${CMAKE_CURRENT_LIST_DIR}/src/hal/tls/mbedtls
${CMAKE_CURRENT_LIST_DIR}/dependencies/mbedtls-2.6.0/include
)

Expand All @@ -63,6 +69,7 @@ set(API_HEADERS
${CMAKE_CURRENT_LIST_DIR}/src/hal/inc/hal_thread.h
${CMAKE_CURRENT_LIST_DIR}/src/hal/inc/hal_socket.h
${CMAKE_CURRENT_LIST_DIR}/src/hal/inc/hal_serial.h
${CMAKE_CURRENT_LIST_DIR}/src/hal/inc/tls_config.h
${CMAKE_CURRENT_LIST_DIR}/src/inc/api/cs101_master.h
${CMAKE_CURRENT_LIST_DIR}/src/inc/api/cs101_slave.h
${CMAKE_CURRENT_LIST_DIR}/src/inc/api/cs104_slave.h
Expand All @@ -72,7 +79,6 @@ set(API_HEADERS
${CMAKE_CURRENT_LIST_DIR}/src/inc/api/cs101_information_objects.h
${CMAKE_CURRENT_LIST_DIR}/src/inc/api/cs104_connection.h
${CMAKE_CURRENT_LIST_DIR}/src/inc/api/link_layer_parameters.h
${CMAKE_CURRENT_LIST_DIR}/src/tls/tls_api.h
)


Expand Down
19 changes: 15 additions & 4 deletions lib60870-C/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,53 @@ LIB60870_HOME=.

include make/target_system.mk

ifndef WITHOUT_COMMON

LIB_SOURCE_DIRS = src/common

endif

LIB_SOURCE_DIRS += src/iec60870
LIB_SOURCE_DIRS += src/iec60870/cs101
LIB_SOURCE_DIRS += src/iec60870/cs104
LIB_SOURCE_DIRS += src/iec60870/link_layer
LIB_SOURCE_DIRS += src/iec60870/apl

ifndef WITHOUT_HAL

ifeq ($(HAL_IMPL), WIN32)
LIB_SOURCE_DIRS += src/hal/socket/win32
LIB_SOURCE_DIRS += src/hal/thread/win32
LIB_SOURCE_DIRS += src/hal/time/win32
LIB_SOURCE_DIRS += src/hal/memory
else ifeq ($(HAL_IMPL), POSIX)
LIB_SOURCE_DIRS += src/hal/socket/linux
LIB_SOURCE_DIRS += src/hal/thread/linux
LIB_SOURCE_DIRS += src/hal/time/unix
LIB_SOURCE_DIRS += src/hal/serial/linux
LIB_SOURCE_DIRS += src/hal/memory
else ifeq ($(HAL_IMPL), BSD)
LIB_SOURCE_DIRS += src/hal/socket/bsd
LIB_SOURCE_DIRS += src/hal/thread/bsd
LIB_SOURCE_DIRS += src/hal/time/unix
LIB_SOURCE_DIRS += src/hal/memory
endif

ifdef WITH_MBEDTLS
LIB_SOURCE_DIRS += dependencies/mbedtls-2.6.0/library
LIB_SOURCE_DIRS += src/tls/mbedtls
LIB_INCLUDE_DIRS += src/tls/mbedtls
LIB_SOURCE_DIRS += src/hal/tls/mbedtls
LIB_INCLUDE_DIRS += src/hal/tls/mbedtls
LIB_INCLUDE_DIRS += dependencies/mbedtls-2.6.0/include
CFLAGS += -D'MBEDTLS_CONFIG_FILE="mbedtls_config.h"'
CFLAGS += -D'CONFIG_CS104_SUPPORT_TLS=1'
endif

endif

LIB_INCLUDE_DIRS += config
LIB_INCLUDE_DIRS += src/inc/api
LIB_INCLUDE_DIRS += src/inc/internal
LIB_INCLUDE_DIRS += src/hal/inc
LIB_INCLUDE_DIRS += src/tls
LIB_INCLUDE_DIRS += src/common/inc


Expand All @@ -60,7 +71,7 @@ LIB_API_HEADER_FILES += src/inc/api/iec60870_common.h
LIB_API_HEADER_FILES += src/inc/api/iec60870_master.h
LIB_API_HEADER_FILES += src/inc/api/iec60870_slave.h
LIB_API_HEADER_FILES += src/inc/api/link_layer_parameters.h
LIB_API_HEADER_FILES += src/tls/tls_api.h
LIB_API_HEADER_FILES += src/hal/inc/tls_config.h

LIB_TEST_SOURCES = tests/all_tests.c
LIB_TEST_SOURCES += tests/unity/unity.c
Expand Down
79 changes: 56 additions & 23 deletions lib60870-C/config/lib60870_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,37 @@
/* print debugging information with printf if set to 1 */
#define CONFIG_DEBUG_OUTPUT 0



/**
* Use static memory for the slave (outstation) message queue.
* Configure CS104 slave to allocate memory from static memory pool (don't use dynamic memory)
*
* Note: Use only when statically linking the library. You can only have
* a single slave instance!
* */
#define CONFIG_SLAVE_WITH_STATIC_MESSAGE_QUEUE 0

/**
* Compile the library to use threads. This will require semaphore support
* Note: This setting will create different memory pools for objects like client connections,
* ASDU queues, and slave instances. The following settings have to be defined also:
* - \ref CONFIG_CS104_SLAVE_POOL_SIZE (number of slave instances)
* - \ref CONFIG_CS104_MESSAGE_QUEUE_POOL_SIZE (message queue pool size)
* - \ref CONFIG_CS104_MESSAGE_QUEUE_SIZE (size of ASDU message queue)
* - \ref CONFIG_CS104_MESSAGE_QUEUE_HIGH_PRIO_SIZE (size of high priority message queue)
* - \ref CONFIG_CS104_MAX_K_BUFFER_SIZE (size of k-buffer - restricts the maximum value of the k parameter!)
*
* CONFIG_USE_THREADS = 0 not yet supported
*/
#define CONFIG_USE_THREADS 1
#define CONFIG_CS104_SLAVE_POOL 0

/**
* Use a separate thread to call the callback functions. This allows the user
* to have a more natural program flow in the callback function. Otherwise callback
* functions have to return immediately and send functions called from the callback
* may not work when the send message queue is full.
* Define the number of slave instances that are available in the pool
*/
#define CONFIG_SLAVE_USE_SEPARATE_CALLBACK_THREAD 0
#define CONFIG_CS104_SLAVE_POOL_SIZE 1

/**
* Queue to store received ASDUs before passing them to the user provided callback.
* Define the number of message queues in the pool to be shared between different slaves
*/
#define CONFIG_SLAVE_SEPARATE_CALLBACK_THREAD_QUEUE_SIZE 12
#define CONFIG_CS104_MESSAGE_QUEUE_POOL_SIZE 1

/**
* Define the default size for the slave (outstation) message queue. This is used also
* to buffer ASDUs in the case when the connection is lost.
*
* For each queued message about 256 bytes of memory are required.
*/
#define CONFIG_SLAVE_ASDU_QUEUE_SIZE 100
#define CONFIG_CS104_MESSAGE_QUEUE_SIZE 100

/**
* This is a connection specific ASDU queue for the slave (outstation). It is used for connection
Expand All @@ -54,22 +48,61 @@
*
* For each queued message about 256 bytes of memory are required.
*/
#define CONFIG_SLAVE_CONNECTION_ASDU_QUEUE_SIZE 10
#define CONFIG_CS104_MESSAGE_QUEUE_HIGH_PRIO_SIZE 50

/**
* \brief This parameter restricts the k-buffer size when \ref CONFIG_CS104_SLAVE_POOL is enabled
*
* The actual size of the k-buffer (corresponding to the APCI parameter k) is defined by the runtime parameter.
* However the runtime parameter is restricted to the maximum of this value.
*/
#define CONFIG_CS104_MAX_K_BUFFER_SIZE 30

/**
* Compile the library to use threads. This will require semaphore support
*/
#define CONFIG_USE_THREADS 1

/**
* Compile the library using semaphore to protect critical objects.
* Required when CONFIG_USE_THREADS = 1.
*/
#define CONFIG_USE_SEMAPHORES 1

/**
* Use a separate thread to call the callback functions. This allows the user
* to have a more natural program flow in the callback function. Otherwise callback
* functions have to return immediately and send functions called from the callback
* may not work when the send message queue is full.
*/
#define CONFIG_SLAVE_USE_SEPARATE_CALLBACK_THREAD 0

/**
* Queue to store received ASDUs before passing them to the user provided callback.
*/
#define CONFIG_SLAVE_SEPARATE_CALLBACK_THREAD_QUEUE_SIZE 12



/**
* Compile library with support for SINGLE_REDUNDANCY_GROUP server mode (only CS104 server)
*/
#define CONFIG_CS104_SUPPORT_SERVER_MODE_SINGLE_REDUNDANCY_GROUP 1

/**
* Compile library with support for MULTIPLE_REDUNDANCY_GROUPS server mode (only CS104 server)
*/
#define CONFIG_CS104_SUPPORT_SERVER_MODE_MULTIPLE_REDUNDANCY_GROUPS 1

/**
* Compile library with support for CONNECTION_IS_REDUNDANCY_GROUP server mode (only CS104 server)
*/
#define CONFIG_CS104_SUPPORT_SERVER_MODE_CONNECTION_IS_REDUNDANCY_GROUP 1

/**
* Set the maximum number of client connections or 0 for no restriction
* Set the maximum number of client connections
*/
#define CONFIG_CS104_MAX_CLIENT_CONNECTIONS 0
#define CONFIG_CS104_MAX_CLIENT_CONNECTIONS 5

/* activate TCP keep alive mechanism. 1 -> activate */
#define CONFIG_ACTIVATE_TCP_KEEPALIVE 0
Expand Down
2 changes: 2 additions & 0 deletions lib60870-C/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ add_subdirectory(cs101_master_unbalanced)
add_subdirectory(cs101_slave)
add_subdirectory(cs104_client)
add_subdirectory(cs104_server)
add_subdirectory(cs104_server_no_threads)
add_subdirectory(cs104_redundancy_server)
add_subdirectory(multi_client_server)

if (WITH_MBEDTLS)
Expand Down
20 changes: 20 additions & 0 deletions lib60870-C/examples/cs104_redundancy_server/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
include_directories(
.
)

set(example_SRCS
cs104_redundancy_server.c
)

IF(WIN32)
set_source_files_properties(${example_SRCS}
PROPERTIES LANGUAGE CXX)
ENDIF(WIN32)

add_executable(cs104_redundancy_server
${example_SRCS}
)

target_link_libraries(cs104_redundancy_server
lib60870
)
20 changes: 20 additions & 0 deletions lib60870-C/examples/cs104_redundancy_server/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
LIB60870_HOME=../..

PROJECT_BINARY_NAME = cs104_redundancy_server
PROJECT_SOURCES = cs104_redundancy_server.c

include $(LIB60870_HOME)/make/target_system.mk
include $(LIB60870_HOME)/make/stack_includes.mk

all: $(PROJECT_BINARY_NAME)

include $(LIB60870_HOME)/make/common_targets.mk


$(PROJECT_BINARY_NAME): $(PROJECT_SOURCES) $(LIB_NAME)
$(CC) $(CFLAGS) $(LDFLAGS) -g -o $(PROJECT_BINARY_NAME) $(PROJECT_SOURCES) $(INCLUDES) $(LIB_NAME) $(LDLIBS)

clean:
rm -f $(PROJECT_BINARY_NAME)


Loading

0 comments on commit 87c5c67

Please sign in to comment.