├── .clang-format ├── .github └── workflows │ └── main.yml ├── CHANGELOG ├── COPYING ├── README.md ├── lib60870-C ├── CMakeLists.txt ├── Doxyfile ├── Makefile ├── config │ └── lib60870_config.h ├── dependencies │ └── README.md ├── doxydoc │ └── mz-automation.ico ├── examples │ ├── CMakeLists.txt │ ├── cs101_master_balanced │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ └── master_example.c │ ├── cs101_master_unbalanced │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ └── master_example.c │ ├── cs101_slave │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ └── slave_example.c │ ├── cs101_slave_files │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ └── cs101_slave_files.c │ ├── cs104_client │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ └── simple_client.c │ ├── cs104_client_async │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ └── cs104_client_async.c │ ├── cs104_redundancy_server │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ └── cs104_redundancy_server.c │ ├── cs104_server │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ └── simple_server.c │ ├── cs104_server_files │ │ ├── CMakeLists.txt │ │ └── cs104_server_files.c │ ├── cs104_server_no_threads │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ └── cs104_server_no_threads.c │ ├── multi_client_server │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ └── multi_client_server.c │ ├── tls_client │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ ├── client_CA1_1.key │ │ ├── client_CA1_1.pem │ │ ├── root_CA1.pem │ │ ├── server_CA1_1.pem │ │ └── tls_client.c │ └── tls_server │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ ├── client_CA1_1.pem │ │ ├── root_CA1.pem │ │ ├── server_CA1_1.key │ │ ├── server_CA1_1.pem │ │ └── tls_server.c ├── make │ ├── common_targets.mk │ ├── stack_includes.mk │ └── target_system.mk ├── src │ ├── CMakeLists.txt │ ├── common │ │ ├── inc │ │ │ └── linked_list.h │ │ └── linked_list.c │ ├── file-service │ │ ├── cs101_file_service.h │ │ └── file_server.c │ ├── hal │ │ ├── CMakeLists.txt │ │ ├── inc │ │ │ ├── hal_base.h │ │ │ ├── hal_serial.h │ │ │ ├── hal_socket.h │ │ │ ├── hal_thread.h │ │ │ ├── hal_time.h │ │ │ ├── lib_memory.h │ │ │ ├── platform_endian.h │ │ │ ├── tls_ciphers.h │ │ │ ├── tls_config.h │ │ │ └── tls_socket.h │ │ ├── memory │ │ │ └── lib_memory.c │ │ ├── serial │ │ │ ├── linux │ │ │ │ └── serial_port_linux.c │ │ │ └── win32 │ │ │ │ └── serial_port_win32.c │ │ ├── socket │ │ │ ├── bsd │ │ │ │ └── socket_bsd.c │ │ │ ├── linux │ │ │ │ └── socket_linux.c │ │ │ └── win32 │ │ │ │ └── socket_win32.c │ │ ├── thread │ │ │ ├── bsd │ │ │ │ └── thread_bsd.c │ │ │ ├── linux │ │ │ │ └── thread_linux.c │ │ │ ├── macos │ │ │ │ └── thread_macos.c │ │ │ └── win32 │ │ │ │ └── thread_win32.c │ │ ├── time │ │ │ ├── unix │ │ │ │ └── time.c │ │ │ └── win32 │ │ │ │ └── time.c │ │ └── tls │ │ │ ├── mbedtls │ │ │ ├── mbedtls_config.h │ │ │ └── tls_mbedtls.c │ │ │ └── mbedtls3 │ │ │ ├── mbedtls_config.h │ │ │ └── tls_mbedtls.c │ ├── iec60870 │ │ ├── apl │ │ │ └── cpXXtime2a.c │ │ ├── cs101 │ │ │ ├── cs101_asdu.c │ │ │ ├── cs101_bcr.c │ │ │ ├── cs101_information_objects.c │ │ │ ├── cs101_master.c │ │ │ ├── cs101_master_connection.c │ │ │ ├── cs101_queue.c │ │ │ └── cs101_slave.c │ │ ├── cs104 │ │ │ ├── cs104_connection.c │ │ │ ├── cs104_frame.c │ │ │ └── cs104_slave.c │ │ ├── frame.c │ │ ├── lib60870_common.c │ │ └── link_layer │ │ │ ├── buffer_frame.c │ │ │ ├── link_layer.c │ │ │ └── serial_transceiver_ft_1_2.c │ ├── inc │ │ ├── api │ │ │ ├── cs101_information_objects.h │ │ │ ├── cs101_master.h │ │ │ ├── cs101_slave.h │ │ │ ├── cs104_connection.h │ │ │ ├── cs104_slave.h │ │ │ ├── iec60870_common.h │ │ │ ├── iec60870_master.h │ │ │ ├── iec60870_slave.h │ │ │ └── link_layer_parameters.h │ │ └── internal │ │ │ ├── apl_types_internal.h │ │ │ ├── buffer_frame.h │ │ │ ├── cs101_asdu_internal.h │ │ │ ├── cs101_queue.h │ │ │ ├── cs104_frame.h │ │ │ ├── frame.h │ │ │ ├── information_objects_internal.h │ │ │ ├── lib60870_internal.h │ │ │ ├── link_layer.h │ │ │ ├── link_layer_private.h │ │ │ ├── platform_endian.h │ │ │ └── serial_transceiver_ft_1_2.h │ ├── lib60870.pc.in │ └── version.rc.in └── tests │ ├── CMakeLists.txt │ ├── all_tests.c │ ├── certs │ ├── README.md │ ├── client_CA1_1.key │ ├── client_CA1_1.pem │ ├── client_CA1_2.key │ ├── client_CA1_2.pem │ ├── client_CA1_3.key │ ├── client_CA1_3.pem │ ├── client_CA1_4.key │ ├── client_CA1_4.pem │ ├── crl_number │ ├── crl_number.old │ ├── crl_openssl.conf │ ├── index.txt │ ├── index.txt.attr │ ├── index.txt.attr.old │ ├── index.txt.old │ ├── root_CA1.key │ ├── root_CA1.pem │ ├── root_CA1.srl │ ├── server_CA1_1.key │ ├── server_CA1_1.pem │ ├── server_CA1_1_chain.pem │ └── test.crl │ ├── client1-key.pem │ ├── client1.cer │ ├── client2.cer │ ├── root.cer │ ├── server-key.pem │ ├── server.cer │ └── unity │ ├── unity.c │ ├── unity.h │ └── unity_internals.h ├── sonar-project.properties └── user_guide.adoc /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | # BasedOnStyle: Microsoft 4 | AccessModifierOffset: -2 5 | AlignAfterOpenBracket: Align 6 | AlignArrayOfStructures: None 7 | AlignConsecutiveMacros: None 8 | AlignConsecutiveAssignments: None 9 | AlignConsecutiveBitFields: None 10 | AlignConsecutiveDeclarations: None 11 | AlignEscapedNewlines: Right 12 | AlignOperands: Align 13 | AlignTrailingComments: true 14 | AllowAllArgumentsOnNextLine: true 15 | AllowAllParametersOfDeclarationOnNextLine: true 16 | AllowShortEnumsOnASingleLine: false 17 | AllowShortBlocksOnASingleLine: Never 18 | AllowShortCaseLabelsOnASingleLine: false 19 | AllowShortFunctionsOnASingleLine: None 20 | AllowShortLambdasOnASingleLine: All 21 | AllowShortIfStatementsOnASingleLine: Never 22 | AllowShortLoopsOnASingleLine: false 23 | AlwaysBreakAfterDefinitionReturnType: None 24 | AlwaysBreakAfterReturnType: All 25 | AlwaysBreakBeforeMultilineStrings: false 26 | AlwaysBreakTemplateDeclarations: MultiLine 27 | AttributeMacros: 28 | - __capability 29 | BinPackArguments: true 30 | BinPackParameters: true 31 | BraceWrapping: 32 | AfterCaseLabel: false 33 | AfterClass: true 34 | AfterControlStatement: Always 35 | AfterEnum: true 36 | AfterFunction: true 37 | AfterNamespace: true 38 | AfterObjCDeclaration: true 39 | AfterStruct: true 40 | AfterUnion: false 41 | AfterExternBlock: true 42 | BeforeCatch: true 43 | BeforeElse: true 44 | BeforeLambdaBody: false 45 | BeforeWhile: false 46 | IndentBraces: false 47 | SplitEmptyFunction: true 48 | SplitEmptyRecord: true 49 | SplitEmptyNamespace: true 50 | BreakBeforeBinaryOperators: None 51 | BreakBeforeConceptDeclarations: true 52 | BreakBeforeBraces: Custom 53 | BreakBeforeInheritanceComma: false 54 | BreakInheritanceList: BeforeColon 55 | BreakBeforeTernaryOperators: true 56 | BreakConstructorInitializersBeforeComma: false 57 | BreakConstructorInitializers: BeforeColon 58 | BreakAfterJavaFieldAnnotations: false 59 | BreakStringLiterals: true 60 | ColumnLimit: 120 61 | CommentPragmas: '^ IWYU pragma:' 62 | QualifierAlignment: Leave 63 | CompactNamespaces: false 64 | ConstructorInitializerIndentWidth: 4 65 | ContinuationIndentWidth: 4 66 | Cpp11BracedListStyle: true 67 | DeriveLineEnding: true 68 | DerivePointerAlignment: false 69 | DisableFormat: false 70 | EmptyLineAfterAccessModifier: Never 71 | EmptyLineBeforeAccessModifier: LogicalBlock 72 | ExperimentalAutoDetectBinPacking: false 73 | PackConstructorInitializers: BinPack 74 | BasedOnStyle: '' 75 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 76 | AllowAllConstructorInitializersOnNextLine: true 77 | FixNamespaceComments: true 78 | ForEachMacros: 79 | - foreach 80 | - Q_FOREACH 81 | - BOOST_FOREACH 82 | IfMacros: 83 | - KJ_IF_MAYBE 84 | IncludeBlocks: Preserve 85 | IncludeCategories: 86 | - Regex: '^"(llvm|llvm-c|clang|clang-c)/' 87 | Priority: 2 88 | SortPriority: 0 89 | CaseSensitive: false 90 | - Regex: '^(<|"(gtest|gmock|isl|json)/)' 91 | Priority: 3 92 | SortPriority: 0 93 | CaseSensitive: false 94 | - Regex: '.*' 95 | Priority: 1 96 | SortPriority: 0 97 | CaseSensitive: false 98 | IncludeIsMainRegex: '(Test)?$' 99 | IncludeIsMainSourceRegex: '' 100 | IndentAccessModifiers: false 101 | IndentCaseLabels: false 102 | IndentCaseBlocks: false 103 | IndentGotoLabels: true 104 | IndentPPDirectives: None 105 | IndentExternBlock: NoIndent 106 | IndentRequires: false 107 | IndentWidth: 4 108 | IndentWrappedFunctionNames: false 109 | InsertTrailingCommas: None 110 | JavaScriptQuotes: Leave 111 | JavaScriptWrapImports: true 112 | KeepEmptyLinesAtTheStartOfBlocks: false 113 | LambdaBodyIndentation: Signature 114 | MacroBlockBegin: '' 115 | MacroBlockEnd: '' 116 | MaxEmptyLinesToKeep: 1 117 | NamespaceIndentation: None 118 | ObjCBinPackProtocolList: Auto 119 | ObjCBlockIndentWidth: 2 120 | ObjCBreakBeforeNestedBlockParam: true 121 | ObjCSpaceAfterProperty: false 122 | ObjCSpaceBeforeProtocolList: true 123 | PenaltyBreakAssignment: 2 124 | PenaltyBreakBeforeFirstCallParameter: 19 125 | PenaltyBreakComment: 300 126 | PenaltyBreakFirstLessLess: 120 127 | PenaltyBreakOpenParenthesis: 0 128 | PenaltyBreakString: 1000 129 | PenaltyBreakTemplateDeclaration: 10 130 | PenaltyExcessCharacter: 1000000 131 | PenaltyReturnTypeOnItsOwnLine: 1000 132 | PenaltyIndentedWhitespace: 0 133 | PointerAlignment: Left 134 | PPIndentWidth: -1 135 | ReferenceAlignment: Pointer 136 | ReflowComments: true 137 | RemoveBracesLLVM: false 138 | SeparateDefinitionBlocks: Leave 139 | ShortNamespaceLines: 1 140 | SortIncludes: CaseSensitive 141 | SortJavaStaticImport: Before 142 | SortUsingDeclarations: true 143 | SpaceAfterCStyleCast: false 144 | SpaceAfterLogicalNot: false 145 | SpaceAfterTemplateKeyword: true 146 | SpaceBeforeAssignmentOperators: true 147 | SpaceBeforeCaseColon: false 148 | SpaceBeforeCpp11BracedList: false 149 | SpaceBeforeCtorInitializerColon: true 150 | SpaceBeforeInheritanceColon: true 151 | SpaceBeforeParens: ControlStatements 152 | SpaceBeforeParensOptions: 153 | AfterControlStatements: true 154 | AfterForeachMacros: true 155 | AfterFunctionDefinitionName: false 156 | AfterFunctionDeclarationName: false 157 | AfterIfMacros: true 158 | AfterOverloadedOperator: false 159 | BeforeNonEmptyParentheses: false 160 | SpaceAroundPointerQualifiers: Default 161 | SpaceBeforeRangeBasedForLoopColon: true 162 | SpaceInEmptyBlock: false 163 | SpaceInEmptyParentheses: false 164 | SpacesBeforeTrailingComments: 1 165 | SpacesInAngles: Never 166 | SpacesInConditionalStatement: false 167 | SpacesInContainerLiterals: true 168 | SpacesInCStyleCastParentheses: false 169 | SpacesInLineCommentPrefix: 170 | Minimum: 1 171 | Maximum: -1 172 | SpacesInParentheses: false 173 | SpacesInSquareBrackets: false 174 | SpaceBeforeSquareBrackets: false 175 | BitFieldColonSpacing: Both 176 | Standard: Latest 177 | StatementAttributeLikeMacros: 178 | - Q_EMIT 179 | StatementMacros: 180 | - Q_UNUSED 181 | - QT_REQUIRE_VERSION 182 | TabWidth: 4 183 | UseCRLF: false 184 | UseTab: Never 185 | WhitespaceSensitiveMacros: 186 | - STRINGIZE 187 | - PP_STRINGIZE 188 | - BOOST_PP_STRINGIZE 189 | - NS_SWIFT_NAME 190 | - CF_SWIFT_NAME 191 | ... 192 | 193 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: SonarQube 2 | on: 3 | workflow_dispatch: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | types: [opened, synchronize, reopened] 9 | jobs: 10 | build: 11 | name: Build and analyze 12 | runs-on: ubuntu-latest 13 | env: 14 | BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed 15 | steps: 16 | - uses: actions/checkout@v4 17 | with: 18 | fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis 19 | - name: Install Build Wrapper 20 | uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v5 21 | - name: Run Build Wrapper 22 | run: | 23 | mkdir build 24 | cmake -S lib60870-C -B build 25 | build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build/ 26 | - name: SonarQube Scan 27 | uses: SonarSource/sonarqube-scan-action@v5 28 | env: 29 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 30 | with: 31 | args: > 32 | --define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json" 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # README lib60870-C {#mainpage} 2 | 3 | lib60870 library for IEC 60870-5 based protocols in C 4 | 5 | The current implementation contains code for the IEC 60870-5-101 (application layer and serial link layer) and IEC 60870-5-104 (protocool over TCP/IP) specifications. 6 | 7 | Features: 8 | 9 | - support for all application layer message types 10 | - master and slave 11 | - balanced and unbalanced link layers (for CS 101 serial communication) 12 | - client/server for CS 104 TCP/IP communication 13 | - CS 104 redundancy group support 14 | - CS101 slave/CS104 server: file service support 15 | - Supports most TLS features required by IEC 62351-3 (third party code mbedtls required) 16 | - portable C99 code 17 | 18 | Please also consider the User Guide and the API reference documentation (https://support.mz-automation.de/doc/lib60870/latest/) 19 | 20 | 21 | ## Compiling and running the examples: 22 | 23 | 24 | In the lib60870-C folder build the library with 25 | 26 | `make` 27 | 28 | Go to the examples folder and build the examples with 29 | 30 | `make` 31 | 32 | in each examples' directory. 33 | 34 | The library and examples can also be build with _CMake_. 35 | 36 | To build the library in a separate folder create a new folder as subdirectory of 37 | the project folder and run cmake to create the build files: 38 | 39 | `mkdir build` 40 | 41 | `cd build` 42 | 43 | `cmake ..` 44 | 45 | ## Building without common code and HAL 46 | 47 | The library contains some common code and a platform abstraction layer (HAL) that is shared with 48 | other protocol libraries of MZ Automation (e.g. libiec61850). In order to simplify using these 49 | protocol libraries together it is possible to compile the library without the common parts. 50 | 51 | This can be done by using the *WITHOUT_HAL* and *WITHOUT_COMMON* defines when calling make: 52 | 53 | `make WITHOUT_HAL=1 WITHOUT_COMMON=1` 54 | 55 | ## Building with TLS support 56 | 57 | The library can be build with support for TLS. In order to do so you have to download mbedtls version 2.28.x. 58 | 59 | Unpack the mbedtls tarball in the dependencies folder so that a folder 60 | 61 | dependencies/mbedtls-2.28 62 | 63 | exists. 64 | 65 | The cmake build system will automatically detect the mbedtls source and build the library with TLS support and mbedtls included 66 | 67 | When using make you have to call make with WITH_MBEDTLS=1 68 | 69 | `make WITH_MBEDTLS=1` 70 | 71 | ## Library configuration 72 | 73 | There are different runtime and compile-time configuration options. 74 | 75 | Compile time configuration options can be used to shrink down the library for small embedded systems. Compile time configuration can be changed by modifying the file _config/lib60870_config.h_. 76 | 77 | ## Memory allocation 78 | 79 | The library uses dynamic memory allocation (malloc/calloc wrapped by own functions that can be replaced when required). 80 | 81 | The CS104 slave uses dynamic memory allocation only at setup time (when calling the function _CS104_Slave_create_ and 82 | _CS104_Slave_start_/_CS104_Slave_startThreadless_. 83 | 84 | For details please have a look at the _User Guide_. 85 | 86 | ## Contact: 87 | 88 | The library is developed by Michael Zillgith and supported by MZ Automation GmbH. 89 | 90 | For bug reports, hints or support please contact info@mz-automation.de 91 | 92 | 93 | 94 | ## Licensing 95 | 96 | This software can be dual licensed under the GPLv3 (https://www.gnu.org/licenses/gpl-3.0.en.html) and a commercial license agreement. 97 | 98 | When using the library in commercial and non-GPL applications you should buy a commercial license. 99 | 100 | ## Commercial licenses and support 101 | 102 | Support and commercial license options are provided by MZ Automation GmbH. Please contact info@mz-automation.de for more details. 103 | 104 | ## Contributing 105 | 106 | If you want to contribute to the improvement and development of the library please send me comments, feature requests, bug reports, or patches. 107 | 108 | For more than trivial contributions I require you to sign a Contributor License Agreement. Please contact info@libiec61850.ccom 109 | -------------------------------------------------------------------------------- /lib60870-C/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # automagically detect if we should cross-compile 4 | if(DEFINED ENV{TOOLCHAIN}) 5 | set(CMAKE_C_COMPILER $ENV{TOOLCHAIN}gcc) 6 | set(CMAKE_CXX_COMPILER $ENV{TOOLCHAIN}g++) 7 | set(CMAKE_AR "$ENV{TOOLCHAIN}ar" CACHE FILEPATH "CW archiver" FORCE) 8 | endif() 9 | 10 | project(lib60870-C) 11 | ENABLE_TESTING() 12 | 13 | set(LIB_VERSION_MAJOR "2") 14 | set(LIB_VERSION_MINOR "3") 15 | set(LIB_VERSION_PATCH "5") 16 | 17 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/third_party/cmake/modules/") 18 | 19 | macro(ADD_C_FLAGS flags) 20 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flags}") 21 | endmacro() 22 | 23 | # feature checks 24 | include(CheckLibraryExists) 25 | 26 | # check if we are on a little or a big endian 27 | include (TestBigEndian) 28 | test_big_endian(PLATFORM_IS_BIGENDIAN) 29 | 30 | option(BUILD_HAL "Build the platform abstraction layer (HAL)" ON) 31 | option(BUILD_COMMON "Build common code (shared with other libraries - e.g. libiec61850)" ON) 32 | 33 | option(BUILD_EXAMPLES "Build the examples" ON) 34 | option(BUILD_TESTS "Build the tests" ON) 35 | 36 | if(BUILD_HAL) 37 | 38 | if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/dependencies/mbedtls-2.28) 39 | set(WITH_MBEDTLS 1) 40 | message("mbedtls 2.28 found") 41 | ELSEIF(EXISTS ${CMAKE_CURRENT_LIST_DIR}/dependencies/mbedtls-3.6) 42 | set(WITH_MBEDTLS3 1) 43 | message("mbedtls 3.6 found") 44 | else() 45 | message("NOTE: mbedtls 2.28 or 3.6 is required for TLS support!") 46 | endif(EXISTS ${CMAKE_CURRENT_LIST_DIR}/dependencies/mbedtls-2.28) 47 | 48 | endif(BUILD_HAL) 49 | 50 | include_directories( 51 | ${CMAKE_CURRENT_LIST_DIR}/config 52 | ${CMAKE_CURRENT_LIST_DIR}/src/file-service 53 | ${CMAKE_CURRENT_LIST_DIR}/src/inc/api 54 | ${CMAKE_CURRENT_LIST_DIR}/src/inc/internal 55 | ${CMAKE_CURRENT_LIST_DIR}/src/common/inc 56 | ${CMAKE_CURRENT_LIST_DIR}/src/hal/inc 57 | ) 58 | 59 | if(WITH_MBEDTLS) 60 | include_directories( 61 | ${CMAKE_CURRENT_LIST_DIR}/src/hal/tls/mbedtls 62 | ${CMAKE_CURRENT_LIST_DIR}/dependencies/mbedtls-2.28/include 63 | ) 64 | 65 | file(GLOB tls_SRCS ${CMAKE_CURRENT_LIST_DIR}/dependencies/mbedtls-2.28/library/*.c) 66 | 67 | add_definitions(-DCONFIG_CS104_SUPPORT_TLS=1) 68 | add_definitions(-DMBEDTLS_CONFIG_FILE="mbedtls_config.h") 69 | 70 | endif(WITH_MBEDTLS) 71 | 72 | if(WITH_MBEDTLS3) 73 | include_directories( 74 | ${CMAKE_CURRENT_LIST_DIR}/src/hal/tls/mbedtls3 75 | ${CMAKE_CURRENT_LIST_DIR}/dependencies/mbedtls-3.6/include 76 | ) 77 | 78 | file(GLOB tls_SRCS ${CMAKE_CURRENT_LIST_DIR}/dependencies/mbedtls-3.6/library/*.c) 79 | 80 | add_definitions(-DCONFIG_CS104_SUPPORT_TLS=1) 81 | add_definitions(-DMBEDTLS_CONFIG_FILE="mbedtls_config.h") 82 | 83 | endif(WITH_MBEDTLS3) 84 | 85 | 86 | set(API_HEADERS 87 | ${CMAKE_CURRENT_LIST_DIR}/src/hal/inc/hal_time.h 88 | ${CMAKE_CURRENT_LIST_DIR}/src/hal/inc/hal_thread.h 89 | ${CMAKE_CURRENT_LIST_DIR}/src/hal/inc/hal_socket.h 90 | ${CMAKE_CURRENT_LIST_DIR}/src/hal/inc/hal_serial.h 91 | ${CMAKE_CURRENT_LIST_DIR}/src/hal/inc/hal_base.h 92 | ${CMAKE_CURRENT_LIST_DIR}/src/hal/inc/tls_config.h 93 | ${CMAKE_CURRENT_LIST_DIR}/src/hal/inc/tls_ciphers.h 94 | ${CMAKE_CURRENT_LIST_DIR}/src/common/inc/linked_list.h 95 | ${CMAKE_CURRENT_LIST_DIR}/src/inc/api/cs101_master.h 96 | ${CMAKE_CURRENT_LIST_DIR}/src/inc/api/cs101_slave.h 97 | ${CMAKE_CURRENT_LIST_DIR}/src/inc/api/cs104_slave.h 98 | ${CMAKE_CURRENT_LIST_DIR}/src/inc/api/iec60870_master.h 99 | ${CMAKE_CURRENT_LIST_DIR}/src/inc/api/iec60870_slave.h 100 | ${CMAKE_CURRENT_LIST_DIR}/src/inc/api/iec60870_common.h 101 | ${CMAKE_CURRENT_LIST_DIR}/src/inc/api/cs101_information_objects.h 102 | ${CMAKE_CURRENT_LIST_DIR}/src/inc/api/cs104_connection.h 103 | ${CMAKE_CURRENT_LIST_DIR}/src/inc/api/link_layer_parameters.h 104 | ${CMAKE_CURRENT_LIST_DIR}/src/file-service/cs101_file_service.h 105 | ) 106 | 107 | include(CheckCCompilerFlag) 108 | 109 | check_c_compiler_flag("-Wredundant-decls" SUPPORT_REDUNDANT_DECLS) 110 | if (SUPPORT_REDUNDANT_DECLS) 111 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wredundant-decls") 112 | endif(SUPPORT_REDUNDANT_DECLS) 113 | 114 | # write the detected stuff to this file 115 | # configure_file(config/lib60870_config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config/lib60870_config.h) 116 | 117 | if(BUILD_EXAMPLES) 118 | add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/examples) 119 | endif(BUILD_EXAMPLES) 120 | 121 | if(BUILD_TESTS) 122 | add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tests) 123 | endif(BUILD_TESTS) 124 | 125 | add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/src) 126 | 127 | INSTALL(FILES ${API_HEADERS} DESTINATION include/lib60870 COMPONENT Development) 128 | 129 | IF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake") 130 | INCLUDE(InstallRequiredSystemLibraries) 131 | 132 | SET(CPACK_PACKAGE_DESCRIPTION "IEC 60870-5-101/104 master/slave library") 133 | SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "IEC 60870-5-101/104 master/slave library") 134 | SET(CPACK_PACKAGE_VENDOR "MZ Automation GmbH") 135 | SET(CPACK_PACKAGE_CONTACT "info@mz-automation.de") 136 | SET(CPACK_PACKAGE_VERSION_MAJOR "${LIB_VERSION_MAJOR}") 137 | SET(CPACK_PACKAGE_VERSION_MINOR "${LIB_VERSION_MINOR}") 138 | SET(CPACK_PACKAGE_VERSION_PATCH "${LIB_VERSION_PATCH}") 139 | SET(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}_${CMAKE_SYSTEM_PROCESSOR}") 140 | SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}_${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") 141 | 142 | SET(CPACK_COMPONENTS_ALL Libraries Development Applications) 143 | #set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CMAKE_PROJECT_NAME}") 144 | INCLUDE(CPack) 145 | 146 | ENDIF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake") 147 | -------------------------------------------------------------------------------- /lib60870-C/Makefile: -------------------------------------------------------------------------------- 1 | LIB60870_HOME=. 2 | 3 | include make/target_system.mk 4 | 5 | ifndef WITHOUT_COMMON 6 | 7 | LIB_SOURCE_DIRS = src/common 8 | 9 | endif 10 | 11 | LIB_SOURCE_DIRS += src/iec60870 12 | LIB_SOURCE_DIRS += src/iec60870/cs101 13 | LIB_SOURCE_DIRS += src/iec60870/cs104 14 | LIB_SOURCE_DIRS += src/iec60870/link_layer 15 | LIB_SOURCE_DIRS += src/iec60870/apl 16 | 17 | ifndef WITHOUT_HAL 18 | 19 | ifeq ($(HAL_IMPL), WIN32) 20 | LIB_SOURCE_DIRS += src/hal/socket/win32 21 | LIB_SOURCE_DIRS += src/hal/thread/win32 22 | LIB_SOURCE_DIRS += src/hal/time/win32 23 | LIB_SOURCE_DIRS += src/hal/memory 24 | else ifeq ($(HAL_IMPL), POSIX) 25 | LIB_SOURCE_DIRS += src/hal/socket/linux 26 | LIB_SOURCE_DIRS += src/hal/thread/linux 27 | LIB_SOURCE_DIRS += src/hal/time/unix 28 | LIB_SOURCE_DIRS += src/hal/serial/linux 29 | LIB_SOURCE_DIRS += src/hal/memory 30 | else ifeq ($(HAL_IMPL), BSD) 31 | LIB_SOURCE_DIRS += src/hal/socket/bsd 32 | LIB_SOURCE_DIRS += src/hal/thread/bsd 33 | LIB_SOURCE_DIRS += src/hal/time/unix 34 | LIB_SOURCE_DIRS += src/hal/memory 35 | endif 36 | 37 | ifdef WITH_MBEDTLS 38 | LIB_SOURCE_DIRS += dependencies/mbedtls-2.28/library 39 | LIB_SOURCE_DIRS += src/hal/tls/mbedtls 40 | LIB_INCLUDE_DIRS += src/hal/tls/mbedtls 41 | LIB_INCLUDE_DIRS += dependencies/mbedtls-2.28/include 42 | CFLAGS += -D'MBEDTLS_CONFIG_FILE="mbedtls_config.h"' 43 | CFLAGS += -D'CONFIG_CS104_SUPPORT_TLS=1' 44 | endif 45 | 46 | ifdef WITH_MBEDTLS3 47 | LIB_SOURCE_DIRS += dependencies/mbedtls-3.6/library 48 | LIB_SOURCE_DIRS += src/hal/tls/mbedtls3 49 | LIB_INCLUDE_DIRS += src/hal/tls/mbedtls3 50 | LIB_INCLUDE_DIRS += dependencies/mbedtls-3.6/include 51 | CFLAGS += -D'MBEDTLS_CONFIG_FILE="mbedtls_config.h"' 52 | CFLAGS += -D'CONFIG_CS104_SUPPORT_TLS=1' 53 | endif 54 | 55 | endif 56 | 57 | LIB_INCLUDE_DIRS += config 58 | LIB_INCLUDE_DIRS += src/inc/api 59 | LIB_INCLUDE_DIRS += src/inc/internal 60 | LIB_INCLUDE_DIRS += src/hal/inc 61 | LIB_INCLUDE_DIRS += src/common/inc 62 | 63 | 64 | LIB_INCLUDES = $(addprefix -I,$(LIB_INCLUDE_DIRS)) 65 | 66 | ifndef INSTALL_PREFIX 67 | INSTALL_PREFIX = ./.install 68 | endif 69 | 70 | LIB_API_HEADER_FILES = src/hal/inc/hal_time.h 71 | LIB_API_HEADER_FILES += src/hal/inc/hal_thread.h 72 | LIB_API_HEADER_FILES += src/hal/inc/hal_socket.h 73 | LIB_API_HEADER_FILES += src/hal/inc/hal_serial.h 74 | LIB_API_HEADER_FILES += src/hal/inc/hal_base.h 75 | LIB_API_HEADER_FILES += src/common/inc/linked_list.h 76 | LIB_API_HEADER_FILES += src/inc/api/cs101_information_objects.h 77 | LIB_API_HEADER_FILES += src/inc/api/cs101_master.h 78 | LIB_API_HEADER_FILES += src/inc/api/cs101_slave.h 79 | LIB_API_HEADER_FILES += src/inc/api/cs104_connection.h 80 | LIB_API_HEADER_FILES += src/inc/api/cs104_slave.h 81 | LIB_API_HEADER_FILES += src/inc/api/iec60870_common.h 82 | LIB_API_HEADER_FILES += src/inc/api/iec60870_master.h 83 | LIB_API_HEADER_FILES += src/inc/api/iec60870_slave.h 84 | LIB_API_HEADER_FILES += src/inc/api/link_layer_parameters.h 85 | LIB_API_HEADER_FILES += src/hal/inc/tls_config.h 86 | LIB_API_HEADER_FILES += src/hal/inc/tls_ciphers.h 87 | LIB_API_HEADER_FILES += src/file-service/cs101_file_service.h 88 | 89 | LIB_TEST_SOURCES = tests/all_tests.c 90 | LIB_TEST_SOURCES += tests/unity/unity.c 91 | 92 | LIB_TEST_INCLUDE_DIRS = tests/unity 93 | 94 | TEST_INCLUDES = $(addprefix -I,$(LIB_TEST_INCLUDE_DIRS)) 95 | 96 | get_sources_from_directory = $(wildcard $1/*.c) 97 | get_sources = $(foreach dir, $1, $(call get_sources_from_directory,$(dir))) 98 | src_to = $(addprefix $(LIB_OBJS_DIR)/,$(subst .c,$1,$2)) 99 | 100 | LIB_SOURCES = $(call get_sources,$(LIB_SOURCE_DIRS)) 101 | 102 | LIB_OBJS = $(call src_to,.o,$(LIB_SOURCES)) 103 | TEST_OBJS = $(call src_to,.o,$(LIB_TEST_SOURCES)) 104 | CFLAGS += -std=gnu99 105 | #CFLAGS += -Wno-error=format 106 | CFLAGS += -Wstrict-prototypes -Wall -Wextra 107 | 108 | ifneq ($(HAL_IMPL), WIN32) 109 | CFLAGS += -Wuninitialized 110 | endif 111 | 112 | CFLAGS += -Wsign-compare 113 | CFLAGS += -Wpointer-arith 114 | CFLAGS += -Wnested-externs 115 | CFLAGS += -Wmissing-declarations 116 | CFLAGS += -Wshadow 117 | CFLAGS += -Wall 118 | #CFLAGS += -Werror 119 | 120 | all: lib 121 | 122 | static_checks: lib 123 | splint -preproc +posixlib +skip-sys-headers +gnuextensions $(LIB_INCLUDES) $(LIB_SOURCES) 124 | 125 | cppcheck: lib 126 | cppcheck --xml --force --std=c99 --enable=all $(LIB_INCLUDES) $(LIB_SOURCES) 2> cppcheck-output.xml 127 | 128 | lib: $(LIB_NAME) 129 | 130 | tests: $(TEST_NAME) 131 | 132 | dynlib: CFLAGS += -fPIC 133 | 134 | dynlib: $(DYN_LIB_NAME) 135 | 136 | .PHONY: examples 137 | 138 | examples: 139 | cd examples; $(MAKE) 140 | 141 | $(TEST_NAME): $(LIB_OBJS) $(TEST_OBJS) 142 | $(CC) -o $(TEST_NAME) $(LIB_OBJS) $(TEST_OBJS) -lpthread 143 | 144 | $(LIB_NAME): $(LIB_OBJS) 145 | $(AR) r $(LIB_NAME) $(LIB_OBJS) 146 | $(RANLIB) $(LIB_NAME) 147 | 148 | $(DYN_LIB_NAME): $(LIB_OBJS) 149 | $(CC) $(LDFLAGS) $(DYNLIB_LDFLAGS) -shared -o $(DYN_LIB_NAME) $(LIB_OBJS) $(LDLIBS) 150 | 151 | $(LIB_OBJS_DIR)/%.o: %.c config 152 | @echo compiling $(notdir $<) 153 | $(SILENCE)mkdir -p $(dir $@) 154 | $(CC) $(CFLAGS) -c $(LIB_INCLUDES) $(TEST_INCLUDES) $(OUTPUT_OPTION) $< 155 | 156 | install: $(LIB_NAME) 157 | mkdir -p $(INSTALL_PREFIX)/include 158 | mkdir -p $(INSTALL_PREFIX)/lib 159 | cp $(LIB_API_HEADER_FILES) $(INSTALL_PREFIX)/include 160 | cp $(LIB_NAME) $(INSTALL_PREFIX)/lib 161 | 162 | clean: 163 | rm -f $(EXAMPLES) 164 | rm -rf $(LIB_OBJS_DIR) 165 | 166 | -------------------------------------------------------------------------------- /lib60870-C/config/lib60870_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lib60870_config.h 3 | */ 4 | 5 | #ifndef CONFIG_LIB60870_CONFIG_H_ 6 | #define CONFIG_LIB60870_CONFIG_H_ 7 | 8 | 9 | /* print debugging information with printf if set to 1 */ 10 | #ifndef CONFIG_DEBUG_OUTPUT 11 | #define CONFIG_DEBUG_OUTPUT 0 12 | #endif 13 | 14 | /** 15 | * Define the maximum slave message queue size (for CS 101) 16 | * 17 | * When set to -1 the message queue size is not limited can be set by the application 18 | */ 19 | #ifndef CONFIG_SLAVE_MESSAGE_QUEUE_SIZE 20 | #define CONFIG_SLAVE_MESSAGE_QUEUE_SIZE -1 21 | #endif 22 | 23 | /** 24 | * Define the default size for the slave (outstation) message queue. This is used also 25 | * to buffer ASDUs in the case when the connection is lost. 26 | * 27 | * For each queued message a maximum of 256 bytes of memory are required. Usually messages are 28 | * smaller so more then thus number of messages can be stored in the message queue 29 | */ 30 | #ifndef CONFIG_CS104_MESSAGE_QUEUE_SIZE 31 | #define CONFIG_CS104_MESSAGE_QUEUE_SIZE 100 32 | #endif 33 | 34 | /** 35 | * This is a connection specific ASDU queue for the slave (outstation). It is used for connection 36 | * specific ASDUs like those that are automatically generated by the stack or created in 37 | * the slave side callback. The messages in the queue are removed when the connection is lost. 38 | * 39 | * For each queued message about 256 bytes of memory are required. 40 | */ 41 | #ifndef CONFIG_CS104_MESSAGE_QUEUE_HIGH_PRIO_SIZE 42 | #define CONFIG_CS104_MESSAGE_QUEUE_HIGH_PRIO_SIZE 50 43 | #endif 44 | 45 | /** 46 | * Compile the library to use threads. This will require semaphore support 47 | */ 48 | #ifndef CONFIG_USE_THREADS 49 | #define CONFIG_USE_THREADS 1 50 | #endif 51 | 52 | /** 53 | * Compile the library using semaphore to protect critical objects. 54 | * Required when CONFIG_USE_THREADS = 1. 55 | */ 56 | #ifndef CONFIG_USE_SEMAPHORES 57 | #define CONFIG_USE_SEMAPHORES 1 58 | #endif 59 | 60 | /** 61 | * Compile library with support for SINGLE_REDUNDANCY_GROUP server mode (only CS104 server) 62 | */ 63 | #ifndef CONFIG_CS104_SUPPORT_SERVER_MODE_SINGLE_REDUNDANCY_GROUP 64 | #define CONFIG_CS104_SUPPORT_SERVER_MODE_SINGLE_REDUNDANCY_GROUP 1 65 | #endif 66 | 67 | /** 68 | * Compile library with support for MULTIPLE_REDUNDANCY_GROUPS server mode (only CS104 server) 69 | */ 70 | #ifndef CONFIG_CS104_SUPPORT_SERVER_MODE_MULTIPLE_REDUNDANCY_GROUPS 71 | #define CONFIG_CS104_SUPPORT_SERVER_MODE_MULTIPLE_REDUNDANCY_GROUPS 1 72 | #endif 73 | 74 | /** 75 | * Compile library with support for CONNECTION_IS_REDUNDANCY_GROUP server mode (only CS104 server) 76 | */ 77 | #ifndef CONFIG_CS104_SUPPORT_SERVER_MODE_CONNECTION_IS_REDUNDANCY_GROUP 78 | #define CONFIG_CS104_SUPPORT_SERVER_MODE_CONNECTION_IS_REDUNDANCY_GROUP 1 79 | #endif 80 | 81 | /** 82 | * Set the maximum number of client connections 83 | */ 84 | #ifndef CONFIG_CS104_MAX_CLIENT_CONNECTIONS 85 | #define CONFIG_CS104_MAX_CLIENT_CONNECTIONS 100 86 | #endif 87 | 88 | /* activate TCP keep alive mechanism. 1 -> activate */ 89 | #ifndef CONFIG_ACTIVATE_TCP_KEEPALIVE 90 | #define CONFIG_ACTIVATE_TCP_KEEPALIVE 0 91 | #endif 92 | 93 | /* time (in s) between last message and first keepalive message */ 94 | #ifndef CONFIG_TCP_KEEPALIVE_IDLE 95 | #define CONFIG_TCP_KEEPALIVE_IDLE 5 96 | #endif 97 | 98 | /* time between subsequent keepalive messages if no ack received */ 99 | #ifndef CONFIG_TCP_KEEPALIVE_INTERVAL 100 | #define CONFIG_TCP_KEEPALIVE_INTERVAL 2 101 | #endif 102 | 103 | /* number of not missing keepalive responses until socket is considered dead */ 104 | #ifndef CONFIG_TCP_KEEPALIVE_CNT 105 | #define CONFIG_TCP_KEEPALIVE_CNT 2 106 | #endif 107 | 108 | /* test command without timestamp is not allowed for CS104. Set to 1 to enable it anyway. */ 109 | #ifndef CONFIG_ALLOW_C_TS_NA_1_FOR_CS104 110 | #define CONFIG_ALLOW_C_TS_NA_1_FOR_CS104 0 111 | #endif 112 | 113 | #endif /* CONFIG_LIB60870_CONFIG_H_ */ 114 | -------------------------------------------------------------------------------- /lib60870-C/dependencies/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | Please add optional dependencies in this folder 4 | 5 | ## TLS Support 6 | 7 | At the moment there are two different options for TLS support. 8 | 9 | * mbedtls 2.28 supports TLS version 1.2, 1.1 and older versions of TLS 10 | * mbedtls 3.6 supports TLS versions 1.2 and 1.3 11 | 12 | ### mbedtls 2.28 13 | 14 | For TLS support with mbedtls 2.28 download the source tarball of version 2.28.x and extract here in the subfolder (Version 2.28.9 https://github.com/Mbed-TLS/mbedtls/releases/download/mbedtls-2.28.9/mbedtls-2.28.9.tar.bz2) 15 | 16 | Rename the extracted mbedtls folder to mbedtls-2.28 (otherwise the build script cannot find the folder and will compile the library without TLS support). 17 | 18 | 19 | On a Linux command line enter the following commands in this directory: 20 | 21 | wget https://github.com/Mbed-TLS/mbedtls/releases/download/mbedtls-2.28.9/mbedtls-2.28.9.tar.bz2 22 | tar xfj mbedtls-2.28.9.tar.bz2 23 | mv mbedtls-2.28.9 mbedtls-2.28 24 | 25 | When using make the make command has to be invoked with the WITH_MBEDTLS=1 parameter 26 | 27 | make WITH_MBEDTLS=1 28 | 29 | ### mbedtls 3.6 30 | 31 | For TLS support with mbedtls 3.6 download the source tarball of version 3.6.x and extract here in the subfolder (Version 3.6.2 https://github.com/Mbed-TLS/mbedtls/releases/download/mbedtls-3.6.2/mbedtls-3.6.2.tar.bz2) 32 | 33 | On a Linux command line enter the following commands in this directory: 34 | 35 | wget https://github.com/Mbed-TLS/mbedtls/releases/download/mbedtls-3.6.2/mbedtls-3.6.2.tar.bz2 36 | tar xfj mbedtls-3.6.2.tar.bz2 37 | mv mbedtls-3.6.2 mbedtls-3.6 38 | 39 | When running cmake the build system will automatically find the mbedtls source code and includes it into the library build. 40 | 41 | When using make the make command has to be invoked with the WITH_MBEDTLS3=1 parameter 42 | 43 | make WITH_MBEDTLS3=1 44 | 45 | -------------------------------------------------------------------------------- /lib60870-C/doxydoc/mz-automation.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mz-automation/lib60870/63028a9287da3b075d4225effcf1dfaf5ea47ed1/lib60870-C/doxydoc/mz-automation.ico -------------------------------------------------------------------------------- /lib60870-C/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(cs101_master_balanced) 2 | add_subdirectory(cs101_master_unbalanced) 3 | add_subdirectory(cs101_slave) 4 | add_subdirectory(cs101_slave_files) 5 | add_subdirectory(cs104_client) 6 | add_subdirectory(cs104_client_async) 7 | add_subdirectory(cs104_server) 8 | add_subdirectory(cs104_server_no_threads) 9 | add_subdirectory(cs104_server_files) 10 | add_subdirectory(cs104_redundancy_server) 11 | add_subdirectory(multi_client_server) 12 | 13 | if (WITH_MBEDTLS OR WITH_MBEDTLS3) 14 | add_subdirectory(tls_client) 15 | add_subdirectory(tls_server) 16 | endif (WITH_MBEDTLS OR WITH_MBEDTLS3) 17 | 18 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs101_master_balanced/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | . 3 | ) 4 | 5 | set(example_SRCS 6 | master_example.c 7 | ) 8 | 9 | IF(WIN32) 10 | set_source_files_properties(${example_SRCS} 11 | PROPERTIES LANGUAGE CXX) 12 | ENDIF(WIN32) 13 | 14 | add_executable(cs101_master_balanced 15 | ${example_SRCS} 16 | ) 17 | 18 | target_link_libraries(cs101_master_balanced 19 | lib60870 20 | ) 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs101_master_balanced/Makefile: -------------------------------------------------------------------------------- 1 | LIB60870_HOME=../.. 2 | 3 | PROJECT_BINARY_NAME = cs101_master 4 | PROJECT_SOURCES = master_example.c 5 | 6 | include $(LIB60870_HOME)/make/target_system.mk 7 | include $(LIB60870_HOME)/make/stack_includes.mk 8 | 9 | all: $(PROJECT_BINARY_NAME) 10 | 11 | include $(LIB60870_HOME)/make/common_targets.mk 12 | 13 | 14 | $(PROJECT_BINARY_NAME): $(PROJECT_SOURCES) $(LIB_NAME) 15 | $(CC) $(CFLAGS) $(LDFLAGS) -g -o $(PROJECT_BINARY_NAME) $(PROJECT_SOURCES) $(INCLUDES) $(LIB_NAME) $(LDLIBS) 16 | 17 | clean: 18 | rm -f $(PROJECT_BINARY_NAME) 19 | 20 | 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs101_master_balanced/master_example.c: -------------------------------------------------------------------------------- 1 | /* 2 | * master_example.c 3 | */ 4 | 5 | #include "hal_time.h" 6 | #include "hal_thread.h" 7 | #include "hal_serial.h" 8 | #include "cs101_master.h" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | static bool running = false; 15 | 16 | void 17 | sigint_handler(int signalId) 18 | { 19 | running = false; 20 | } 21 | 22 | /* Callback handler to log sent or received messages (optional) */ 23 | static void 24 | rawMessageHandler (void* parameter, uint8_t* msg, int msgSize, bool sent) 25 | { 26 | if (sent) 27 | printf("SEND: "); 28 | else 29 | printf("RCVD: "); 30 | 31 | int i; 32 | for (i = 0; i < msgSize; i++) { 33 | printf("%02x ", msg[i]); 34 | } 35 | 36 | printf("\n"); 37 | } 38 | 39 | static bool 40 | asduReceivedHandler (void* parameter, int address, CS101_ASDU asdu) 41 | { 42 | printf("RECVD ASDU type: %s(%i) elements: %i\n", 43 | TypeID_toString(CS101_ASDU_getTypeID(asdu)), 44 | CS101_ASDU_getTypeID(asdu), 45 | CS101_ASDU_getNumberOfElements(asdu)); 46 | 47 | if (CS101_ASDU_getTypeID(asdu) == M_ME_TE_1) { 48 | 49 | printf(" measured scaled values with CP56Time2a timestamp:\n"); 50 | 51 | int i; 52 | 53 | for (i = 0; i < CS101_ASDU_getNumberOfElements(asdu); i++) { 54 | 55 | MeasuredValueScaledWithCP56Time2a io = 56 | (MeasuredValueScaledWithCP56Time2a) CS101_ASDU_getElement(asdu, i); 57 | 58 | if (io) 59 | { 60 | printf(" IOA: %i value: %i\n", 61 | InformationObject_getObjectAddress((InformationObject) io), 62 | MeasuredValueScaled_getValue((MeasuredValueScaled) io) 63 | ); 64 | 65 | MeasuredValueScaledWithCP56Time2a_destroy(io); 66 | } 67 | } 68 | } 69 | else if (CS101_ASDU_getTypeID(asdu) == M_SP_NA_1) { 70 | printf(" single point information:\n"); 71 | 72 | int i; 73 | 74 | for (i = 0; i < CS101_ASDU_getNumberOfElements(asdu); i++) { 75 | 76 | SinglePointInformation io = 77 | (SinglePointInformation) CS101_ASDU_getElement(asdu, i); 78 | 79 | if (io) 80 | { 81 | printf(" IOA: %i value: %i\n", 82 | InformationObject_getObjectAddress((InformationObject) io), 83 | SinglePointInformation_getValue((SinglePointInformation) io) 84 | ); 85 | 86 | SinglePointInformation_destroy(io); 87 | } 88 | } 89 | } 90 | 91 | return true; 92 | } 93 | 94 | static void 95 | linkLayerStateChanged(void* parameter, int address, LinkLayerState state) 96 | { 97 | printf("Link layer state: "); 98 | 99 | switch (state) { 100 | case LL_STATE_IDLE: 101 | printf("IDLE\n"); 102 | break; 103 | case LL_STATE_ERROR: 104 | printf("ERROR\n"); 105 | break; 106 | case LL_STATE_BUSY: 107 | printf("BUSY\n"); 108 | break; 109 | case LL_STATE_AVAILABLE: 110 | printf("AVAILABLE\n"); 111 | break; 112 | } 113 | } 114 | 115 | int 116 | main(int argc, char** argv) 117 | { 118 | signal(SIGINT, sigint_handler); 119 | 120 | const char* serialPort = "/dev/ttyUSB0"; 121 | 122 | if (argc > 1) 123 | serialPort = argv[1]; 124 | 125 | SerialPort port = SerialPort_create(serialPort, 9600, 8, 'E', 1); 126 | 127 | CS101_Master master = CS101_Master_create(port, NULL, NULL, IEC60870_LINK_LAYER_BALANCED); 128 | 129 | CS101_Master_setOwnAddress(master, 2); 130 | 131 | /* Set the address of the slave (optional for balanced master */ 132 | CS101_Master_useSlaveAddress(master, 3); 133 | 134 | /* set handler for received ASDUs (application layer data) */ 135 | CS101_Master_setASDUReceivedHandler(master, asduReceivedHandler, NULL); 136 | 137 | /* modify some of the default parameters */ 138 | LinkLayerParameters llParams = CS101_Master_getLinkLayerParameters(master); 139 | llParams->useSingleCharACK = false; 140 | llParams->addressLength = 1; 141 | 142 | /* set handler for link layer state changes */ 143 | CS101_Master_setLinkLayerStateChanged(master, linkLayerStateChanged, NULL); 144 | 145 | /* log messages */ 146 | CS101_Master_setRawMessageHandler(master, rawMessageHandler, NULL); 147 | 148 | SerialPort_open(port); 149 | 150 | running = true; 151 | 152 | int cycleCounter = 0; 153 | 154 | while (running) { 155 | 156 | CS101_Master_run(master); 157 | 158 | if (cycleCounter == 10) 159 | CS101_Master_sendInterrogationCommand(master, CS101_COT_ACTIVATION, 1, IEC60870_QOI_STATION); 160 | 161 | if (cycleCounter == 50) { 162 | 163 | InformationObject sc = (InformationObject) 164 | SingleCommand_create(NULL, 5000, true, false, 0); 165 | 166 | printf("Send control command C_SC_NA_1\n"); 167 | CS101_Master_sendProcessCommand(master, CS101_COT_ACTIVATION, 1, sc); 168 | 169 | InformationObject_destroy(sc); 170 | } 171 | 172 | if (cycleCounter == 80) { 173 | /* Send clock synchronization command */ 174 | struct sCP56Time2a newTime; 175 | 176 | CP56Time2a_createFromMsTimestamp(&newTime, Hal_getTimeInMs()); 177 | 178 | printf("Send time sync command\n"); 179 | CS101_Master_sendClockSyncCommand(master, 1, &newTime); 180 | } 181 | 182 | Thread_sleep(1); 183 | 184 | cycleCounter++; 185 | } 186 | 187 | CS101_Master_destroy(master); 188 | 189 | SerialPort_close(port); 190 | SerialPort_destroy(port); 191 | } 192 | 193 | 194 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs101_master_unbalanced/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | . 3 | ) 4 | 5 | set(example_SRCS 6 | master_example.c 7 | ) 8 | 9 | IF(WIN32) 10 | set_source_files_properties(${example_SRCS} 11 | PROPERTIES LANGUAGE CXX) 12 | ENDIF(WIN32) 13 | 14 | add_executable(cs101_master_unbalanced 15 | ${example_SRCS} 16 | ) 17 | 18 | target_link_libraries(cs101_master_unbalanced 19 | lib60870 20 | ) 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs101_master_unbalanced/Makefile: -------------------------------------------------------------------------------- 1 | LIB60870_HOME=../.. 2 | 3 | PROJECT_BINARY_NAME = cs101_master 4 | PROJECT_SOURCES = master_example.c 5 | 6 | include $(LIB60870_HOME)/make/target_system.mk 7 | include $(LIB60870_HOME)/make/stack_includes.mk 8 | 9 | all: $(PROJECT_BINARY_NAME) 10 | 11 | include $(LIB60870_HOME)/make/common_targets.mk 12 | 13 | 14 | $(PROJECT_BINARY_NAME): $(PROJECT_SOURCES) $(LIB_NAME) 15 | $(CC) $(CFLAGS) $(LDFLAGS) -g -o $(PROJECT_BINARY_NAME) $(PROJECT_SOURCES) $(INCLUDES) $(LIB_NAME) $(LDLIBS) 16 | 17 | clean: 18 | rm -f $(PROJECT_BINARY_NAME) 19 | 20 | 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs101_slave/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | . 3 | ) 4 | 5 | set(example_SRCS 6 | slave_example.c 7 | ) 8 | 9 | IF(WIN32) 10 | set_source_files_properties(${example_SRCS} 11 | PROPERTIES LANGUAGE CXX) 12 | ENDIF(WIN32) 13 | 14 | add_executable(cs101_slave 15 | ${example_SRCS} 16 | ) 17 | 18 | target_link_libraries(cs101_slave 19 | lib60870 20 | ) 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs101_slave/Makefile: -------------------------------------------------------------------------------- 1 | LIB60870_HOME=../.. 2 | 3 | PROJECT_BINARY_NAME = cs101_slave 4 | PROJECT_SOURCES = slave_example.c 5 | 6 | include $(LIB60870_HOME)/make/target_system.mk 7 | include $(LIB60870_HOME)/make/stack_includes.mk 8 | 9 | all: $(PROJECT_BINARY_NAME) 10 | 11 | include $(LIB60870_HOME)/make/common_targets.mk 12 | 13 | 14 | $(PROJECT_BINARY_NAME): $(PROJECT_SOURCES) $(LIB_NAME) 15 | $(CC) $(CFLAGS) $(LDFLAGS) -g -o $(PROJECT_BINARY_NAME) $(PROJECT_SOURCES) $(INCLUDES) $(LIB_NAME) $(LDLIBS) 16 | 17 | clean: 18 | rm -f $(PROJECT_BINARY_NAME) 19 | 20 | 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs101_slave_files/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | . 3 | ) 4 | 5 | set(example_SRCS 6 | cs101_slave_files.c 7 | ) 8 | 9 | IF(WIN32) 10 | set_source_files_properties(${example_SRCS} 11 | PROPERTIES LANGUAGE CXX) 12 | ENDIF(WIN32) 13 | 14 | add_executable(cs101_slave_files 15 | ${example_SRCS} 16 | ) 17 | 18 | target_link_libraries(cs101_slave_files 19 | lib60870 20 | ) 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs101_slave_files/Makefile: -------------------------------------------------------------------------------- 1 | LIB60870_HOME=../.. 2 | 3 | PROJECT_BINARY_NAME = cs101_slave_files 4 | PROJECT_SOURCES = cs101_slave_files.c 5 | 6 | include $(LIB60870_HOME)/make/target_system.mk 7 | include $(LIB60870_HOME)/make/stack_includes.mk 8 | 9 | all: $(PROJECT_BINARY_NAME) 10 | 11 | include $(LIB60870_HOME)/make/common_targets.mk 12 | 13 | 14 | $(PROJECT_BINARY_NAME): $(PROJECT_SOURCES) $(LIB_NAME) 15 | $(CC) $(CFLAGS) $(LDFLAGS) -g -o $(PROJECT_BINARY_NAME) $(PROJECT_SOURCES) $(INCLUDES) $(LIB_NAME) $(LDLIBS) 16 | 17 | clean: 18 | rm -f $(PROJECT_BINARY_NAME) 19 | 20 | 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs104_client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | . 3 | ) 4 | 5 | set(example_SRCS 6 | simple_client.c 7 | ) 8 | 9 | IF(WIN32) 10 | set_source_files_properties(${example_SRCS} 11 | PROPERTIES LANGUAGE CXX) 12 | ENDIF(WIN32) 13 | 14 | add_executable(simple_client 15 | ${example_SRCS} 16 | ) 17 | 18 | target_link_libraries(simple_client 19 | lib60870 20 | ) 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs104_client/Makefile: -------------------------------------------------------------------------------- 1 | LIB60870_HOME=../.. 2 | 3 | PROJECT_BINARY_NAME = simple_client 4 | PROJECT_SOURCES = simple_client.c 5 | 6 | include $(LIB60870_HOME)/make/target_system.mk 7 | include $(LIB60870_HOME)/make/stack_includes.mk 8 | 9 | all: $(PROJECT_BINARY_NAME) 10 | 11 | include $(LIB60870_HOME)/make/common_targets.mk 12 | 13 | 14 | $(PROJECT_BINARY_NAME): $(PROJECT_SOURCES) $(LIB_NAME) 15 | $(CC) $(CFLAGS) $(LDFLAGS) -g -o $(PROJECT_BINARY_NAME) $(PROJECT_SOURCES) $(INCLUDES) $(LIB_NAME) $(LDLIBS) 16 | 17 | clean: 18 | rm -f $(PROJECT_BINARY_NAME) 19 | 20 | 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs104_client/simple_client.c: -------------------------------------------------------------------------------- 1 | #include "cs104_connection.h" 2 | #include "hal_time.h" 3 | #include "hal_thread.h" 4 | 5 | #include 6 | #include 7 | 8 | /* Callback handler to log sent or received messages (optional) */ 9 | static void 10 | rawMessageHandler (void* parameter, uint8_t* msg, int msgSize, bool sent) 11 | { 12 | if (sent) 13 | printf("SEND: "); 14 | else 15 | printf("RCVD: "); 16 | 17 | int i; 18 | for (i = 0; i < msgSize; i++) { 19 | printf("%02x ", msg[i]); 20 | } 21 | 22 | printf("\n"); 23 | } 24 | 25 | /* Connection event handler */ 26 | static void 27 | connectionHandler (void* parameter, CS104_Connection connection, CS104_ConnectionEvent event) 28 | { 29 | switch (event) { 30 | case CS104_CONNECTION_OPENED: 31 | printf("Connection established\n"); 32 | break; 33 | case CS104_CONNECTION_CLOSED: 34 | printf("Connection closed\n"); 35 | break; 36 | case CS104_CONNECTION_FAILED: 37 | printf("Failed to connect\n"); 38 | break; 39 | case CS104_CONNECTION_STARTDT_CON_RECEIVED: 40 | printf("Received STARTDT_CON\n"); 41 | break; 42 | case CS104_CONNECTION_STOPDT_CON_RECEIVED: 43 | printf("Received STOPDT_CON\n"); 44 | break; 45 | } 46 | } 47 | 48 | /* 49 | * CS101_ASDUReceivedHandler implementation 50 | * 51 | * For CS104 the address parameter has to be ignored 52 | */ 53 | static bool 54 | asduReceivedHandler (void* parameter, int address, CS101_ASDU asdu) 55 | { 56 | printf("RECVD ASDU type: %s(%i) elements: %i\n", 57 | TypeID_toString(CS101_ASDU_getTypeID(asdu)), 58 | CS101_ASDU_getTypeID(asdu), 59 | CS101_ASDU_getNumberOfElements(asdu)); 60 | 61 | if (CS101_ASDU_getTypeID(asdu) == M_ME_TE_1) { 62 | 63 | printf(" measured scaled values with CP56Time2a timestamp:\n"); 64 | 65 | int i; 66 | 67 | for (i = 0; i < CS101_ASDU_getNumberOfElements(asdu); i++) { 68 | 69 | MeasuredValueScaledWithCP56Time2a io = 70 | (MeasuredValueScaledWithCP56Time2a) CS101_ASDU_getElement(asdu, i); 71 | 72 | if (io) 73 | { 74 | printf(" IOA: %i value: %i\n", 75 | InformationObject_getObjectAddress((InformationObject) io), 76 | MeasuredValueScaled_getValue((MeasuredValueScaled) io) 77 | ); 78 | 79 | MeasuredValueScaledWithCP56Time2a_destroy(io); 80 | } 81 | } 82 | } 83 | else if (CS101_ASDU_getTypeID(asdu) == M_SP_NA_1) 84 | { 85 | printf(" single point information:\n"); 86 | 87 | int i; 88 | 89 | for (i = 0; i < CS101_ASDU_getNumberOfElements(asdu); i++) 90 | { 91 | SinglePointInformation io = 92 | (SinglePointInformation) CS101_ASDU_getElement(asdu, i); 93 | 94 | if (io) 95 | { 96 | printf(" IOA: %i value: %i\n", 97 | InformationObject_getObjectAddress((InformationObject) io), 98 | SinglePointInformation_getValue((SinglePointInformation) io) 99 | ); 100 | 101 | SinglePointInformation_destroy(io); 102 | } 103 | } 104 | } 105 | else if (CS101_ASDU_getTypeID(asdu) == C_TS_TA_1) { 106 | printf(" test command with timestamp\n"); 107 | } 108 | 109 | return true; 110 | } 111 | 112 | int 113 | main(int argc, char** argv) 114 | { 115 | const char* ip = "localhost"; 116 | uint16_t port = IEC_60870_5_104_DEFAULT_PORT; 117 | const char* localIp = NULL; 118 | int localPort = -1; 119 | 120 | if (argc > 1) 121 | ip = argv[1]; 122 | 123 | if (argc > 2) 124 | port = atoi(argv[2]); 125 | 126 | if (argc > 3) 127 | localIp = argv[3]; 128 | 129 | if (argc > 4) 130 | port = atoi(argv[4]); 131 | 132 | printf("Connecting to: %s:%i\n", ip, port); 133 | CS104_Connection con = CS104_Connection_create(ip, port); 134 | 135 | CS101_AppLayerParameters alParams = CS104_Connection_getAppLayerParameters(con); 136 | alParams->originatorAddress = 3; 137 | 138 | CS104_Connection_setConnectionHandler(con, connectionHandler, NULL); 139 | CS104_Connection_setASDUReceivedHandler(con, asduReceivedHandler, NULL); 140 | 141 | /* optional bind to local IP address/interface */ 142 | if (localIp) 143 | CS104_Connection_setLocalAddress(con, localIp, localPort); 144 | 145 | /* uncomment to log messages */ 146 | //CS104_Connection_setRawMessageHandler(con, rawMessageHandler, NULL); 147 | 148 | if (CS104_Connection_connect(con)) { 149 | printf("Connected!\n"); 150 | 151 | CS104_Connection_sendStartDT(con); 152 | 153 | Thread_sleep(2000); 154 | 155 | CS104_Connection_sendInterrogationCommand(con, CS101_COT_ACTIVATION, 1, IEC60870_QOI_STATION); 156 | 157 | Thread_sleep(5000); 158 | 159 | struct sCP56Time2a testTimestamp; 160 | CP56Time2a_createFromMsTimestamp(&testTimestamp, Hal_getTimeInMs()); 161 | 162 | CS104_Connection_sendTestCommandWithTimestamp(con, 1, 0x4938, &testTimestamp); 163 | 164 | #if 0 165 | InformationObject sc = (InformationObject) 166 | SingleCommand_create(NULL, 5000, true, false, 0); 167 | 168 | printf("Send control command C_SC_NA_1\n"); 169 | CS104_Connection_sendProcessCommandEx(con, CS101_COT_ACTIVATION, 1, sc); 170 | 171 | InformationObject_destroy(sc); 172 | 173 | /* Send clock synchronization command */ 174 | struct sCP56Time2a newTime; 175 | 176 | CP56Time2a_createFromMsTimestamp(&newTime, Hal_getTimeInMs()); 177 | 178 | printf("Send time sync command\n"); 179 | CS104_Connection_sendClockSyncCommand(con, 1, &newTime); 180 | #endif 181 | 182 | printf("Wait ...\n"); 183 | 184 | Thread_sleep(1000); 185 | } 186 | else 187 | printf("Connect failed!\n"); 188 | 189 | Thread_sleep(1000); 190 | 191 | CS104_Connection_destroy(con); 192 | 193 | printf("exit\n"); 194 | } 195 | 196 | 197 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs104_client_async/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | . 3 | ) 4 | 5 | set(example_SRCS 6 | cs104_client_async.c 7 | ) 8 | 9 | IF(WIN32) 10 | set_source_files_properties(${example_SRCS} 11 | PROPERTIES LANGUAGE CXX) 12 | ENDIF(WIN32) 13 | 14 | add_executable(cs104_client_async 15 | ${example_SRCS} 16 | ) 17 | 18 | target_link_libraries(cs104_client_async 19 | lib60870 20 | ) 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs104_client_async/Makefile: -------------------------------------------------------------------------------- 1 | LIB60870_HOME=../.. 2 | 3 | PROJECT_BINARY_NAME = cs104_client_async 4 | PROJECT_SOURCES = cs104_client_async.c 5 | 6 | include $(LIB60870_HOME)/make/target_system.mk 7 | include $(LIB60870_HOME)/make/stack_includes.mk 8 | 9 | all: $(PROJECT_BINARY_NAME) 10 | 11 | include $(LIB60870_HOME)/make/common_targets.mk 12 | 13 | 14 | $(PROJECT_BINARY_NAME): $(PROJECT_SOURCES) $(LIB_NAME) 15 | $(CC) $(CFLAGS) $(LDFLAGS) -g -o $(PROJECT_BINARY_NAME) $(PROJECT_SOURCES) $(INCLUDES) $(LIB_NAME) $(LDLIBS) 16 | 17 | clean: 18 | rm -f $(PROJECT_BINARY_NAME) 19 | 20 | 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs104_redundancy_server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | . 3 | ) 4 | 5 | set(example_SRCS 6 | cs104_redundancy_server.c 7 | ) 8 | 9 | IF(WIN32) 10 | set_source_files_properties(${example_SRCS} 11 | PROPERTIES LANGUAGE CXX) 12 | ENDIF(WIN32) 13 | 14 | add_executable(cs104_redundancy_server 15 | ${example_SRCS} 16 | ) 17 | 18 | target_link_libraries(cs104_redundancy_server 19 | lib60870 20 | ) 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs104_redundancy_server/Makefile: -------------------------------------------------------------------------------- 1 | LIB60870_HOME=../.. 2 | 3 | PROJECT_BINARY_NAME = cs104_redundancy_server 4 | PROJECT_SOURCES = cs104_redundancy_server.c 5 | 6 | include $(LIB60870_HOME)/make/target_system.mk 7 | include $(LIB60870_HOME)/make/stack_includes.mk 8 | 9 | all: $(PROJECT_BINARY_NAME) 10 | 11 | include $(LIB60870_HOME)/make/common_targets.mk 12 | 13 | 14 | $(PROJECT_BINARY_NAME): $(PROJECT_SOURCES) $(LIB_NAME) 15 | $(CC) $(CFLAGS) $(LDFLAGS) -g -o $(PROJECT_BINARY_NAME) $(PROJECT_SOURCES) $(INCLUDES) $(LIB_NAME) $(LDLIBS) 16 | 17 | clean: 18 | rm -f $(PROJECT_BINARY_NAME) 19 | 20 | 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs104_server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | . 3 | ) 4 | 5 | set(example_SRCS 6 | simple_server.c 7 | ) 8 | 9 | IF(WIN32) 10 | set_source_files_properties(${example_SRCS} 11 | PROPERTIES LANGUAGE CXX) 12 | ENDIF(WIN32) 13 | 14 | add_executable(cs104_server 15 | ${example_SRCS} 16 | ) 17 | 18 | target_link_libraries(cs104_server 19 | lib60870 20 | ) 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs104_server/Makefile: -------------------------------------------------------------------------------- 1 | LIB60870_HOME=../.. 2 | 3 | PROJECT_BINARY_NAME = simple_server 4 | PROJECT_SOURCES = simple_server.c 5 | 6 | include $(LIB60870_HOME)/make/target_system.mk 7 | include $(LIB60870_HOME)/make/stack_includes.mk 8 | 9 | all: $(PROJECT_BINARY_NAME) 10 | 11 | include $(LIB60870_HOME)/make/common_targets.mk 12 | 13 | 14 | $(PROJECT_BINARY_NAME): $(PROJECT_SOURCES) $(LIB_NAME) 15 | $(CC) $(CFLAGS) $(LDFLAGS) -g -o $(PROJECT_BINARY_NAME) $(PROJECT_SOURCES) $(INCLUDES) $(LIB_NAME) $(LDLIBS) 16 | 17 | clean: 18 | rm -f $(PROJECT_BINARY_NAME) 19 | 20 | 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs104_server_files/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | . 3 | ) 4 | 5 | set(example_SRCS 6 | cs104_server_files.c 7 | ) 8 | 9 | IF(WIN32) 10 | set_source_files_properties(${example_SRCS} 11 | PROPERTIES LANGUAGE CXX) 12 | ENDIF(WIN32) 13 | 14 | add_executable(cs104_server_files 15 | ${example_SRCS} 16 | ) 17 | 18 | target_link_libraries(cs104_server_files 19 | lib60870 20 | ) 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs104_server_no_threads/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | . 3 | ) 4 | 5 | set(example_SRCS 6 | cs104_server_no_threads.c 7 | ) 8 | 9 | IF(WIN32) 10 | set_source_files_properties(${example_SRCS} 11 | PROPERTIES LANGUAGE CXX) 12 | ENDIF(WIN32) 13 | 14 | add_executable(cs104_server_no_threads 15 | ${example_SRCS} 16 | ) 17 | 18 | target_link_libraries(cs104_server_no_threads 19 | lib60870 20 | ) 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/cs104_server_no_threads/Makefile: -------------------------------------------------------------------------------- 1 | LIB60870_HOME=../.. 2 | 3 | PROJECT_BINARY_NAME = cs104_server_no_threads 4 | PROJECT_SOURCES = cs104_server_no_threads.c 5 | 6 | include $(LIB60870_HOME)/make/target_system.mk 7 | include $(LIB60870_HOME)/make/stack_includes.mk 8 | 9 | all: $(PROJECT_BINARY_NAME) 10 | 11 | include $(LIB60870_HOME)/make/common_targets.mk 12 | 13 | 14 | $(PROJECT_BINARY_NAME): $(PROJECT_SOURCES) $(LIB_NAME) 15 | $(CC) $(CFLAGS) $(LDFLAGS) -g -o $(PROJECT_BINARY_NAME) $(PROJECT_SOURCES) $(INCLUDES) $(LIB_NAME) $(LDLIBS) 16 | 17 | clean: 18 | rm -f $(PROJECT_BINARY_NAME) 19 | 20 | 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/multi_client_server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | . 3 | ) 4 | 5 | set(example_SRCS 6 | multi_client_server.c 7 | ) 8 | 9 | IF(WIN32) 10 | set_source_files_properties(${example_SRCS} 11 | PROPERTIES LANGUAGE CXX) 12 | ENDIF(WIN32) 13 | 14 | add_executable(multi_client_server 15 | ${example_SRCS} 16 | ) 17 | 18 | target_link_libraries(multi_client_server 19 | lib60870 20 | ) 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/multi_client_server/Makefile: -------------------------------------------------------------------------------- 1 | LIB60870_HOME=../.. 2 | 3 | PROJECT_BINARY_NAME = multi_client_server 4 | PROJECT_SOURCES = multi_client_server.c 5 | 6 | include $(LIB60870_HOME)/make/target_system.mk 7 | include $(LIB60870_HOME)/make/stack_includes.mk 8 | 9 | all: $(PROJECT_BINARY_NAME) 10 | 11 | include $(LIB60870_HOME)/make/common_targets.mk 12 | 13 | 14 | $(PROJECT_BINARY_NAME): $(PROJECT_SOURCES) $(LIB_NAME) 15 | $(CC) $(CFLAGS) $(LDFLAGS) -g -o $(PROJECT_BINARY_NAME) $(PROJECT_SOURCES) $(INCLUDES) $(LIB_NAME) $(LDLIBS) 16 | 17 | clean: 18 | rm -f $(PROJECT_BINARY_NAME) 19 | 20 | 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/tls_client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | . 3 | ) 4 | 5 | set(example_SRCS 6 | tls_client.c 7 | ) 8 | 9 | IF(WIN32) 10 | set_source_files_properties(${example_SRCS} 11 | PROPERTIES LANGUAGE CXX) 12 | ENDIF(WIN32) 13 | 14 | configure_file(client_CA1_1.key client_CA1_1.key COPYONLY) 15 | configure_file(client_CA1_1.pem client_CA1_1.pem COPYONLY) 16 | configure_file(root_CA1.pem root_CA1.pem COPYONLY) 17 | configure_file(server_CA1_1.pem server_CA1_1.pem COPYONLY) 18 | 19 | add_executable(tls_client 20 | ${example_SRCS} 21 | ) 22 | 23 | target_link_libraries(tls_client 24 | lib60870 25 | ) 26 | -------------------------------------------------------------------------------- /lib60870-C/examples/tls_client/Makefile: -------------------------------------------------------------------------------- 1 | LIB60870_HOME=../.. 2 | 3 | PROJECT_BINARY_NAME = tls_client 4 | PROJECT_SOURCES = tls_client.c 5 | 6 | include $(LIB60870_HOME)/make/target_system.mk 7 | include $(LIB60870_HOME)/make/stack_includes.mk 8 | 9 | all: $(PROJECT_BINARY_NAME) 10 | 11 | include $(LIB60870_HOME)/make/common_targets.mk 12 | 13 | 14 | $(PROJECT_BINARY_NAME): $(PROJECT_SOURCES) $(LIB_NAME) 15 | $(CC) $(CFLAGS) $(LDFLAGS) -g -o $(PROJECT_BINARY_NAME) $(PROJECT_SOURCES) $(INCLUDES) $(LIB_NAME) $(LDLIBS) 16 | 17 | clean: 18 | rm -f $(PROJECT_BINARY_NAME) 19 | 20 | 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/tls_client/client_CA1_1.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpQIBAAKCAQEA2PuXMNUYO43NbEvBmEAru/uL1JdU6gFuhMKLuZOPaOGjGhth 3 | JiDO9AsnUGzKAk3m9QZ/YhAzY9CiEeYsnGaPeI0OBdkgWmpz5k9Fw+bqaqlxYQTy 4 | Bw69/kYbwNyMmGsb8XqXKZvhPXdLoaxkVmS+AMlxVcN/7c2ldZGTTDrhBtJnfuPK 5 | rGmH9cFg+XVvUskPQsUIwJtn1sN+niZ++hkuiCzmoZ4A+m73QACltdcr7aNtHJmh 6 | aU/p1bmLIhYfbxGmyvm2faJ8htYuaRBj6DcZq44IyDGz2LThmdWzpIcYbovCzB2X 7 | Pn26b0BXsXBpN+ptf2xpAEDWDdzaR6Xp4BgJwQIDAQABAoIBAQDQGLJOlgBQlVWv 8 | CBSaNOj8t2nKsHwylL7uujoQ95DxUH0BO8L3Mz3n1Y6V1lAC172pvtqKLOlsUBov 9 | OmYMdVwhjH4nY65gqHmRJvPMxviI5Qqktn58AEp8w7Y4SAza3NaGyECTGjlxnqi9 10 | XD06khGbZZa5Xu6hHboSwFPZJxrLU1jaopJUgFG+p9oUgiSp5cfGDwAsU9JELmkP 11 | MVF0GWedpypBBKi9JsniOulr1USpNZN2rzEkkxwY0QQttw3E9dgheIsut7dUYWLz 12 | 9NLKcRWIK/Y29NzS6Urye8lUTHHBrXgk5pUcdN3vuY7mkleqIn5tYY6xf93/5/VA 13 | jF+HcgolAoGBAPDhS986xppbfLmrresIUUZKxk2s/Vg+vHPLX0SJFF7Uhy8nMYoJ 14 | JqfG2mS+/tiM/wPBglVhsrlsfnDIag7Brqx7sjH2OHO6VX8jQPYgOuCbNwp7uL1w 15 | bG82R5rujcxxFAtMVAM3zYz9sNGSu8u7M/U3kfTBwtntFJ6iPC60REbjAoGBAOaa 16 | SdtX0bOQAYDM4moEDVnRPMHp8lZAjqKphGqTDrGOqU4usNW8+ZNBhn3vF1+n2Gq5 17 | KY2IWSF0j71jqpOXahW0EBoXpcTLs5JBWet8J5vKzbpN8Uq8TvTABn67G1F/DZub 18 | FOiCDy/Kku4yWT2aUqNwS07va7gzFhyyjMl/JWoLAoGAATpEtriH9pVsx012r3H1 19 | aBRNemvdRqvbLgPlUmYYcntGzRi4CeoOBmDfEBBhIB1n108PKPw8evFwm4aJ89VM 20 | 3JgsylBk7UIP2XwGgrqbUjW4TBdhU6XVB6QRLVr14grZfU1ASFvqckOAuTC0QE+N 21 | 7jwARG0QXyf0KPLOt7Y3et0CgYEAhJcd9EJQTsB0PMyROofN7WDDYHPVZQaFfL2f 22 | Z2/auPjgHBX4k0yu6553aB17AQMPCn4giEJnjTbqFukhgO9EjeoUgAwswjSlsWhl 23 | /WJLm+ZF1+NM473WYB+xHFkU4gz9lATdRrrRZJdDWDYW3bbH4TWF94LuGuE0y5dW 24 | H909c/UCgYEAiYY/TTZvfEsQvCo4Rv6qg7cI2/OdGwGhMmtziYy4SIAAm0Ga2s3R 25 | L7Kq72In+nbaDIUD2zTSGQmwTm3B0C73vIUAXvupcl28nE5px0YNV6NZJaaFSV66 26 | hP1CgPBYe6KjnVufOiqhcnDdJQ6XdqK0tblj+cavkZgW+UdeqVBXCFQ= 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /lib60870-C/examples/tls_client/client_CA1_1.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDWzCCAkMCFFTJkICEIidmnrisIFxZ99KKLhDFMA0GCSqGSIb3DQEBCwUAMGox 3 | CzAJBgNVBAYTAkRFMQswCQYDVQQIDAJCVzERMA8GA1UEBwwIRnJlaWJ1cmcxGzAZ 4 | BgNVBAoMEk1aIEF1dG9tYXRpb24gR21iSDEMMAoGA1UECwwDUiZEMRAwDgYDVQQD 5 | DAdyb290X0NBMB4XDTIyMDMxODA5MzMxOFoXDTIyMDQxNzA5MzMxOFowajELMAkG 6 | A1UEBhMCREUxCzAJBgNVBAgMAkJXMREwDwYDVQQHDAhGcmVpYnVyZzEbMBkGA1UE 7 | CgwSTVogQXV0b21hdGlvbiBHbWJIMQwwCgYDVQQLDANSJkQxEDAOBgNVBAMMB2Ns 8 | aWVudDEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDY+5cw1Rg7jc1s 9 | S8GYQCu7+4vUl1TqAW6Ewou5k49o4aMaG2EmIM70CydQbMoCTeb1Bn9iEDNj0KIR 10 | 5iycZo94jQ4F2SBaanPmT0XD5upqqXFhBPIHDr3+RhvA3IyYaxvxepcpm+E9d0uh 11 | rGRWZL4AyXFVw3/tzaV1kZNMOuEG0md+48qsaYf1wWD5dW9SyQ9CxQjAm2fWw36e 12 | Jn76GS6ILOahngD6bvdAAKW11yvto20cmaFpT+nVuYsiFh9vEabK+bZ9onyG1i5p 13 | EGPoNxmrjgjIMbPYtOGZ1bOkhxhui8LMHZc+fbpvQFexcGk36m1/bGkAQNYN3NpH 14 | pengGAnBAgMBAAEwDQYJKoZIhvcNAQELBQADggEBADSnrKdPqeUr3F1MIk6P8SKo 15 | yR1VrPmNCljaC1i3realDlG+7jlPHfTCkwZwlEfKGa/yANJAw4hv+2tR5m4CsgMB 16 | x6FkKG9p6NTXyv4gXZeLa3ivqFqz7awTVMBf1C1VVeTi/H2kvHSBRmbj6Z5p7/MN 17 | 9E1t5NsgbKKfbj4hQD+f7r6zgFdgTK8C5OYT2ijYryFl1Qqrl5CYPpswm3vL0KkM 18 | e3RMOBqamkFqr4OCZw5juNpGrp3bK3dLF+N6Ceb+PGnS0YU29NpUXo64lzIxdwxs 19 | NDqbFMYXEXGKqUDVQAuj1374M85Cvqlso0Jenc+hWN2/kfAgHGE1Ne3sD9oJg5w= 20 | -----END CERTIFICATE----- 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/tls_client/root_CA1.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDtTCCAp2gAwIBAgIUJysTAOCqE3IaNO1QgtOPxMq6M8EwDQYJKoZIhvcNAQEL 3 | BQAwajELMAkGA1UEBhMCREUxCzAJBgNVBAgMAkJXMREwDwYDVQQHDAhGcmVpYnVy 4 | ZzEbMBkGA1UECgwSTVogQXV0b21hdGlvbiBHbWJIMQwwCgYDVQQLDANSJkQxEDAO 5 | BgNVBAMMB3Jvb3RfQ0EwHhcNMjIwMzE4MDkyNzEwWhcNMzIwMzE1MDkyNzEwWjBq 6 | MQswCQYDVQQGEwJERTELMAkGA1UECAwCQlcxETAPBgNVBAcMCEZyZWlidXJnMRsw 7 | GQYDVQQKDBJNWiBBdXRvbWF0aW9uIEdtYkgxDDAKBgNVBAsMA1ImRDEQMA4GA1UE 8 | AwwHcm9vdF9DQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOMyaDaT 9 | +a4DT0s2NCrjUN8coLPfFrLRdN0Gx0hRViuLUFxd001jXruRgXKt2g8lR+YnzUeA 10 | PQHbcIfRQhL+jy/ZMXpmz4Nrl7vyOWFdu8nBKU6c7y9LmSGbnOJZjDXwlX6ERwui 11 | qFzAvRA6YXbPN8gY0B3Ou+T/mjkWN9L1x+V+7bGs9rVIoM78fVyM2FERBfsBtT76 12 | QVQv3KZ+a9EOLxqcZ/nGqsFFysFOSkiRC6Cy4mC5CSik9S5D7X9lz/bdga7O+hqd 13 | SKfir6YMlQGV37JPqmz69N6vvb9UOX/G989T4qdVB/zQOvMdcIWXkqb3vSAXYi/c 14 | ClVS1Pymsy/MXQ0CAwEAAaNTMFEwHQYDVR0OBBYEFGYgIECdrhTsmgCKpVM0RHeC 15 | kFUmMB8GA1UdIwQYMBaAFGYgIECdrhTsmgCKpVM0RHeCkFUmMA8GA1UdEwEB/wQF 16 | MAMBAf8wDQYJKoZIhvcNAQELBQADggEBACsiuHFQjqOglenp/fcNbU034m/vvkyV 17 | SZXau9amXBWdeTEpc1HaPOYO7jFFnu/QoH6AbGZkpL0yWZJA2rf102AkOdAe6E0g 18 | 2H77/hHoHVCfxOiOl3+icsLXJ4VXqV2vmUOEVnWfHRtej4My6avT9uCNMO2bw9hm 19 | 56RAZrs82T9Mpg/1XQ9YUO1q4/JfP/+dCzPXAdwJ/h2cJ/q6Q9g1gRns8IzVlGOZ 20 | 0ZBQCLqLl8vUei+t6YgjyBbeNCz4CEcmXKIJeqMB1jhpsgr6BBMTNTU2Q60b9fzU 21 | OCGLw94EnKYtHWGy2WHMFNbwkNCR0/jwhxKkU0HXy1aNMUBWp99M7P8= 22 | -----END CERTIFICATE----- 23 | -------------------------------------------------------------------------------- /lib60870-C/examples/tls_client/server_CA1_1.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDWzCCAkMCFFTJkICEIidmnrisIFxZ99KKLhDIMA0GCSqGSIb3DQEBCwUAMGox 3 | CzAJBgNVBAYTAkRFMQswCQYDVQQIDAJCVzERMA8GA1UEBwwIRnJlaWJ1cmcxGzAZ 4 | BgNVBAoMEk1aIEF1dG9tYXRpb24gR21iSDEMMAoGA1UECwwDUiZEMRAwDgYDVQQD 5 | DAdyb290X0NBMB4XDTIyMDUyNjEwNDc0NFoXDTMwMDgxMjEwNDc0NFowajELMAkG 6 | A1UEBhMCREUxCzAJBgNVBAgMAkJXMREwDwYDVQQHDAhGcmVpYnVyZzEbMBkGA1UE 7 | CgwSTVogQXV0b21hdGlvbiBHbWJIMQwwCgYDVQQLDANSJkQxEDAOBgNVBAMMB3Nl 8 | cnZlcjEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDYUV+nESoiZ3TU 9 | D1D5xxNEOuhWnPzjR6S1evjlXRFCSnPzNK4i/kZc+oFfBKApeyiOguQJgr5WaVfg 10 | ZDrFduUAoB39+VRL5ZWxSr2Qv1y53fR3BgqHZXj9Ob829SJmxhXdvn/xF9SljBU0 11 | Fb95Jxs1etUc2SIGtwgm2LGu4qzIf52tyQ/sriP4BmHjcsawro1j6ml/nAcFy0ZY 12 | U4IV0lKtptyTih6bzTsI4pf0+FN8Pzs6eMFByp0eS6zxZk/9IadlX7pzWTRI3g7Q 13 | TgxqGlaSvwPZmOxuEYUhbwBTg12huyiEKVYBnQwNHU3iijSyPgeBjaEZHYBtH/lj 14 | YsfiRFylAgMBAAEwDQYJKoZIhvcNAQELBQADggEBANPRnvfByVoKwfMcQYUnYT6l 15 | 5OhYt8f2tQfoa0EXirP0O2xG052ZBl3Z5ZzBCcsq1zveaPoeqXFl6HjqIqURB5NS 16 | imJIi7kB7o6C2z19yxOndPm3urKGyfvxtSy2iyzTMZ8eL8RFMJC5DVV+n5Y+1EgC 17 | pYIu//I0ojnFOemEJXVjfxQhiUbx6Nw8HalHOhW1i017XcOWMKji/lwHfWF2PFmn 18 | pIWZCFPCUtHzBUkXCRzn9ESeMDcMXN6qLb2wGJkRUDw+Ls1RGJd6dnB811vOuOd+ 19 | QQc8lyyBZ1byARcxQ8lAtof6Mv7Yzebv1OxRr7NcrV/+ujnSFyJWKrJdcMx7+10= 20 | -----END CERTIFICATE----- 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/tls_server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | . 3 | ) 4 | 5 | set(example_SRCS 6 | tls_server.c 7 | ) 8 | 9 | IF(WIN32) 10 | set_source_files_properties(${example_SRCS} 11 | PROPERTIES LANGUAGE CXX) 12 | ENDIF(WIN32) 13 | 14 | configure_file(server_CA1_1.key server_CA1_1.key COPYONLY) 15 | configure_file(client_CA1_1.pem client_CA1_1.pem COPYONLY) 16 | configure_file(root_CA1.pem root_CA1.pem COPYONLY) 17 | configure_file(server_CA1_1.pem server_CA1_1.pem COPYONLY) 18 | 19 | add_executable(tls_server 20 | ${example_SRCS} 21 | ) 22 | 23 | target_link_libraries(tls_server 24 | lib60870 25 | ) 26 | -------------------------------------------------------------------------------- /lib60870-C/examples/tls_server/Makefile: -------------------------------------------------------------------------------- 1 | LIB60870_HOME=../.. 2 | 3 | PROJECT_BINARY_NAME = tls_server 4 | PROJECT_SOURCES = tls_server.c 5 | 6 | include $(LIB60870_HOME)/make/target_system.mk 7 | include $(LIB60870_HOME)/make/stack_includes.mk 8 | 9 | all: $(PROJECT_BINARY_NAME) 10 | 11 | include $(LIB60870_HOME)/make/common_targets.mk 12 | 13 | 14 | $(PROJECT_BINARY_NAME): $(PROJECT_SOURCES) $(LIB_NAME) 15 | $(CC) $(CFLAGS) $(LDFLAGS) -g -o $(PROJECT_BINARY_NAME) $(PROJECT_SOURCES) $(INCLUDES) $(LIB_NAME) $(LDLIBS) 16 | 17 | clean: 18 | rm -f $(PROJECT_BINARY_NAME) 19 | 20 | 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/tls_server/client_CA1_1.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDWzCCAkMCFFTJkICEIidmnrisIFxZ99KKLhDFMA0GCSqGSIb3DQEBCwUAMGox 3 | CzAJBgNVBAYTAkRFMQswCQYDVQQIDAJCVzERMA8GA1UEBwwIRnJlaWJ1cmcxGzAZ 4 | BgNVBAoMEk1aIEF1dG9tYXRpb24gR21iSDEMMAoGA1UECwwDUiZEMRAwDgYDVQQD 5 | DAdyb290X0NBMB4XDTIyMDMxODA5MzMxOFoXDTIyMDQxNzA5MzMxOFowajELMAkG 6 | A1UEBhMCREUxCzAJBgNVBAgMAkJXMREwDwYDVQQHDAhGcmVpYnVyZzEbMBkGA1UE 7 | CgwSTVogQXV0b21hdGlvbiBHbWJIMQwwCgYDVQQLDANSJkQxEDAOBgNVBAMMB2Ns 8 | aWVudDEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDY+5cw1Rg7jc1s 9 | S8GYQCu7+4vUl1TqAW6Ewou5k49o4aMaG2EmIM70CydQbMoCTeb1Bn9iEDNj0KIR 10 | 5iycZo94jQ4F2SBaanPmT0XD5upqqXFhBPIHDr3+RhvA3IyYaxvxepcpm+E9d0uh 11 | rGRWZL4AyXFVw3/tzaV1kZNMOuEG0md+48qsaYf1wWD5dW9SyQ9CxQjAm2fWw36e 12 | Jn76GS6ILOahngD6bvdAAKW11yvto20cmaFpT+nVuYsiFh9vEabK+bZ9onyG1i5p 13 | EGPoNxmrjgjIMbPYtOGZ1bOkhxhui8LMHZc+fbpvQFexcGk36m1/bGkAQNYN3NpH 14 | pengGAnBAgMBAAEwDQYJKoZIhvcNAQELBQADggEBADSnrKdPqeUr3F1MIk6P8SKo 15 | yR1VrPmNCljaC1i3realDlG+7jlPHfTCkwZwlEfKGa/yANJAw4hv+2tR5m4CsgMB 16 | x6FkKG9p6NTXyv4gXZeLa3ivqFqz7awTVMBf1C1VVeTi/H2kvHSBRmbj6Z5p7/MN 17 | 9E1t5NsgbKKfbj4hQD+f7r6zgFdgTK8C5OYT2ijYryFl1Qqrl5CYPpswm3vL0KkM 18 | e3RMOBqamkFqr4OCZw5juNpGrp3bK3dLF+N6Ceb+PGnS0YU29NpUXo64lzIxdwxs 19 | NDqbFMYXEXGKqUDVQAuj1374M85Cvqlso0Jenc+hWN2/kfAgHGE1Ne3sD9oJg5w= 20 | -----END CERTIFICATE----- 21 | -------------------------------------------------------------------------------- /lib60870-C/examples/tls_server/root_CA1.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDtTCCAp2gAwIBAgIUJysTAOCqE3IaNO1QgtOPxMq6M8EwDQYJKoZIhvcNAQEL 3 | BQAwajELMAkGA1UEBhMCREUxCzAJBgNVBAgMAkJXMREwDwYDVQQHDAhGcmVpYnVy 4 | ZzEbMBkGA1UECgwSTVogQXV0b21hdGlvbiBHbWJIMQwwCgYDVQQLDANSJkQxEDAO 5 | BgNVBAMMB3Jvb3RfQ0EwHhcNMjIwMzE4MDkyNzEwWhcNMzIwMzE1MDkyNzEwWjBq 6 | MQswCQYDVQQGEwJERTELMAkGA1UECAwCQlcxETAPBgNVBAcMCEZyZWlidXJnMRsw 7 | GQYDVQQKDBJNWiBBdXRvbWF0aW9uIEdtYkgxDDAKBgNVBAsMA1ImRDEQMA4GA1UE 8 | AwwHcm9vdF9DQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOMyaDaT 9 | +a4DT0s2NCrjUN8coLPfFrLRdN0Gx0hRViuLUFxd001jXruRgXKt2g8lR+YnzUeA 10 | PQHbcIfRQhL+jy/ZMXpmz4Nrl7vyOWFdu8nBKU6c7y9LmSGbnOJZjDXwlX6ERwui 11 | qFzAvRA6YXbPN8gY0B3Ou+T/mjkWN9L1x+V+7bGs9rVIoM78fVyM2FERBfsBtT76 12 | QVQv3KZ+a9EOLxqcZ/nGqsFFysFOSkiRC6Cy4mC5CSik9S5D7X9lz/bdga7O+hqd 13 | SKfir6YMlQGV37JPqmz69N6vvb9UOX/G989T4qdVB/zQOvMdcIWXkqb3vSAXYi/c 14 | ClVS1Pymsy/MXQ0CAwEAAaNTMFEwHQYDVR0OBBYEFGYgIECdrhTsmgCKpVM0RHeC 15 | kFUmMB8GA1UdIwQYMBaAFGYgIECdrhTsmgCKpVM0RHeCkFUmMA8GA1UdEwEB/wQF 16 | MAMBAf8wDQYJKoZIhvcNAQELBQADggEBACsiuHFQjqOglenp/fcNbU034m/vvkyV 17 | SZXau9amXBWdeTEpc1HaPOYO7jFFnu/QoH6AbGZkpL0yWZJA2rf102AkOdAe6E0g 18 | 2H77/hHoHVCfxOiOl3+icsLXJ4VXqV2vmUOEVnWfHRtej4My6avT9uCNMO2bw9hm 19 | 56RAZrs82T9Mpg/1XQ9YUO1q4/JfP/+dCzPXAdwJ/h2cJ/q6Q9g1gRns8IzVlGOZ 20 | 0ZBQCLqLl8vUei+t6YgjyBbeNCz4CEcmXKIJeqMB1jhpsgr6BBMTNTU2Q60b9fzU 21 | OCGLw94EnKYtHWGy2WHMFNbwkNCR0/jwhxKkU0HXy1aNMUBWp99M7P8= 22 | -----END CERTIFICATE----- 23 | -------------------------------------------------------------------------------- /lib60870-C/examples/tls_server/server_CA1_1.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpAIBAAKCAQEA2FFfpxEqImd01A9Q+ccTRDroVpz840ektXr45V0RQkpz8zSu 3 | Iv5GXPqBXwSgKXsojoLkCYK+VmlX4GQ6xXblAKAd/flUS+WVsUq9kL9cud30dwYK 4 | h2V4/Tm/NvUiZsYV3b5/8RfUpYwVNBW/eScbNXrVHNkiBrcIJtixruKsyH+drckP 5 | 7K4j+AZh43LGsK6NY+ppf5wHBctGWFOCFdJSrabck4oem807COKX9PhTfD87OnjB 6 | QcqdHkus8WZP/SGnZV+6c1k0SN4O0E4MahpWkr8D2ZjsbhGFIW8AU4NdobsohClW 7 | AZ0MDR1N4oo0sj4HgY2hGR2AbR/5Y2LH4kRcpQIDAQABAoIBAEK2tf1cedYqegl8 8 | v8iI8RQ15rnvqL6ftdiSmHiEf3ImbCQxtxLrwN+kEoovbwXcCeIJ1DJqtDEKRCPc 9 | RZPo2y+aMiXF442UvNn05wnhOsPIBEFBB7ZCQVI3oRVd/MIdjVjaC7NbWiXEUjXC 10 | D09aFDYmL9u5y5iukkEIy6PYHNmokN0MlHwhFqqp72hGe6UvHfZ6yu46z1eF6zLN 11 | S4b2ULUzJ6Ov0Y7kmN7vP058yfZYHoj4TPeRBDm3Qx8g9c5d6da22vfkt61UzXEN 12 | ih8fIejq6BGila2wMuZKyCM/Oxv5WX0RTzVQO13+42f29BM47Mdk/a8ijBZCzXnC 13 | oAnHcwECgYEA7Isah3VNc4KkSNRrnV1UrInQ8BAlNLTN4cJTbyOkogCUECvfzAS+ 14 | K/l8YZOzZ7YoJkK7RzDeUqRfrZhyJut6x7J/3Vl6qLXpnx3iEPJdxaD5L1iftnIP 15 | NOytbphClO+VAjSO3frhlCwZ00Z6o6meTV+CNmRT2LDFEzxAMc3GtrECgYEA6hxh 16 | m3S5KX7Ze/m5v9l4vi2iGDNBJkk48Cc+qfgVLGa0TSd7cY+8bjYNufr6vqThKlVu 17 | RByZ3Wo5C5PfrkU69YbJ9LnQ+RTZPu+IxPIsUM3xlyTin7bufyOcWhPr1820MKqP 18 | A/mRJ/SKel7ubrURai7KDETR0mI9XajhtwF/qjUCgYEAvW1sclwTCVTuwVAzWhM6 19 | 0u2PACC92uaMFaYscM1nc0DpUcYA8/48WTTzUaUZwA1VO8am+Yz+DcqKwJdbmyVq 20 | 7u9YjGey3dbIX19sAcxGIhUWWL8tL8tJuEVtYirW7zSp7NkwLD5UVfe3OsWvQs97 21 | 8VRyD6LqrpZpTE0sz3WOFBECgYAxgOLa3mmw7pPKdVnjyXaQsFGQUHY8REt37LSB 22 | eGXxx53kmq6tqrkrjN6GLx4KZg7+xqXUXT/j4+xAGHq5/QWkmWXnC8u2f8QYXMpM 23 | 6vCX/ZRSY4hQQXxZAgyzt3atYV/y0n3/VyxsiHcnvR8p5bvS+iXbRkof9IoJXgas 24 | jfKS6QKBgQC6ZFuvYIeqkfZ0Yyxxum3qlGxpR41wcuIpb4hBQ0gr1haTL0aaoUiQ 25 | qqUfzVRst/oPxf6vqeCxtWh1/3lGa1QXP9KJDA5twFMqTg5jv92vjMIgPTEZ2Oif 26 | +YyTs72V197KHctx2/T4RxAGhxCLJwDzk2shvLS+1voU/w40YRy9yA== 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /lib60870-C/examples/tls_server/server_CA1_1.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDWzCCAkMCFFTJkICEIidmnrisIFxZ99KKLhDIMA0GCSqGSIb3DQEBCwUAMGox 3 | CzAJBgNVBAYTAkRFMQswCQYDVQQIDAJCVzERMA8GA1UEBwwIRnJlaWJ1cmcxGzAZ 4 | BgNVBAoMEk1aIEF1dG9tYXRpb24gR21iSDEMMAoGA1UECwwDUiZEMRAwDgYDVQQD 5 | DAdyb290X0NBMB4XDTIyMDUyNjEwNDc0NFoXDTMwMDgxMjEwNDc0NFowajELMAkG 6 | A1UEBhMCREUxCzAJBgNVBAgMAkJXMREwDwYDVQQHDAhGcmVpYnVyZzEbMBkGA1UE 7 | CgwSTVogQXV0b21hdGlvbiBHbWJIMQwwCgYDVQQLDANSJkQxEDAOBgNVBAMMB3Nl 8 | cnZlcjEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDYUV+nESoiZ3TU 9 | D1D5xxNEOuhWnPzjR6S1evjlXRFCSnPzNK4i/kZc+oFfBKApeyiOguQJgr5WaVfg 10 | ZDrFduUAoB39+VRL5ZWxSr2Qv1y53fR3BgqHZXj9Ob829SJmxhXdvn/xF9SljBU0 11 | Fb95Jxs1etUc2SIGtwgm2LGu4qzIf52tyQ/sriP4BmHjcsawro1j6ml/nAcFy0ZY 12 | U4IV0lKtptyTih6bzTsI4pf0+FN8Pzs6eMFByp0eS6zxZk/9IadlX7pzWTRI3g7Q 13 | TgxqGlaSvwPZmOxuEYUhbwBTg12huyiEKVYBnQwNHU3iijSyPgeBjaEZHYBtH/lj 14 | YsfiRFylAgMBAAEwDQYJKoZIhvcNAQELBQADggEBANPRnvfByVoKwfMcQYUnYT6l 15 | 5OhYt8f2tQfoa0EXirP0O2xG052ZBl3Z5ZzBCcsq1zveaPoeqXFl6HjqIqURB5NS 16 | imJIi7kB7o6C2z19yxOndPm3urKGyfvxtSy2iyzTMZ8eL8RFMJC5DVV+n5Y+1EgC 17 | pYIu//I0ojnFOemEJXVjfxQhiUbx6Nw8HalHOhW1i017XcOWMKji/lwHfWF2PFmn 18 | pIWZCFPCUtHzBUkXCRzn9ESeMDcMXN6qLb2wGJkRUDw+Ls1RGJd6dnB811vOuOd+ 19 | QQc8lyyBZ1byARcxQ8lAtof6Mv7Yzebv1OxRr7NcrV/+ujnSFyJWKrJdcMx7+10= 20 | -----END CERTIFICATE----- 21 | -------------------------------------------------------------------------------- /lib60870-C/make/common_targets.mk: -------------------------------------------------------------------------------- 1 | $(LIB_NAME): 2 | cd $(LIB60870_HOME); $(MAKE) -f Makefile 3 | 4 | lib: $(LIB_NAME) 5 | 6 | libclean: clean 7 | cd $(LIB60870_HOME); $(MAKE) -f Makefile clean 8 | -------------------------------------------------------------------------------- /lib60870-C/make/stack_includes.mk: -------------------------------------------------------------------------------- 1 | INCLUDES += -I$(LIB60870_HOME)/src/inc/api 2 | INCLUDES += -I$(LIB60870_HOME)/src/hal/inc 3 | INCLUDES += -I$(LIB60870_HOME)/src/tls 4 | -------------------------------------------------------------------------------- /lib60870-C/make/target_system.mk: -------------------------------------------------------------------------------- 1 | UNAME := $(shell uname) 2 | 3 | MIPSEL_TOOLCHAIN_PREFIX=mipsel-openwrt-linux- 4 | #ARM_TOOLCHAIN_PREFIX=arm-linux-gnueabihf- 5 | #ARM_TOOLCHAIN_PREFIX=arm-linux-gnueabi- 6 | #ARM_TOOLCHAIN_PREFIX=arm-poky-linux-gnueabi- 7 | ARM_TOOLCHAIN_PREFIX=arm-linux-gnueabihf- 8 | UCLINUX_ARM_TOOLCHAIN_PREFIX=arm-uclinux-elf- 9 | UCLINUX_XPORT_TOOLCHAIN_PREFIX=m68k-uclinux- 10 | #MINGW_TOOLCHAIN_PREFIX=i586-mingw32msvc- 11 | MINGW_TOOLCHAIN_PREFIX=i686-w64-mingw32- 12 | MINGW64_TOOLCHAIN_PREFIX=x86_64-w64-mingw32- 13 | 14 | #POWERPC_TOOLCHAIN_PREFIX=powerpc-poky-linux- 15 | POWERPC_TOOLCHAIN_PREFIX=powerpc-linux-gnu- 16 | 17 | ifndef TARGET 18 | ifeq ($(UNAME), Linux) 19 | TARGET=POSIX 20 | else ifeq ($(findstring MINGW,$(UNAME)), MINGW) 21 | TARGET=WIN32 22 | else ifeq ($(UNAME), Darwin) 23 | TARGET=BSD 24 | else ifeq ($(UNAME), FreeBSD) 25 | TARGET=BSD 26 | endif 27 | endif 28 | 29 | ifeq ($(TARGET), WIN32) 30 | WINDOWS=1 31 | endif 32 | 33 | ifeq ($(TARGET), WIN64) 34 | WINDOWS=1 35 | endif 36 | 37 | ifdef WINDOWS 38 | ifeq ($(UNAME), Linux) 39 | ifeq ($(TARGET), WIN32) 40 | TOOLCHAIN_PREFIX=$(MINGW_TOOLCHAIN_PREFIX) 41 | endif 42 | ifeq ($(TARGET), WIN64) 43 | TOOLCHAIN_PREFIX=$(MINGW64_TOOLCHAIN_PREFIX) 44 | endif 45 | else 46 | TOOLCHAIN_PREFIX= 47 | endif 48 | endif 49 | 50 | ifeq ($(TARGET), LINUX-POWERPC) 51 | TOOLCHAIN_PREFIX=$(POWERPC_TOOLCHAIN_PREFIX) 52 | endif 53 | 54 | ifeq ($(TARGET), LINUX-MIPSEL) 55 | TOOLCHAIN_PREFIX=$(MIPSEL_TOOLCHAIN_PREFIX) 56 | endif 57 | 58 | ifeq ($(TARGET), LINUX-ARM) 59 | TOOLCHAIN_PREFIX=$(ARM_TOOLCHAIN_PREFIX) 60 | CFLAGS += -mno-unaligned-access 61 | # CFLAGS += -mcpu=arm926ej-s 62 | endif 63 | 64 | ifeq ($(TARGET), UCLINUX-WAGO) 65 | TOOLCHAIN_PREFIX=$(UCLINUX_ARM_TOOLCHAIN_PREFIX) 66 | CFLAGS += -msoft-float 67 | CFLAGS += -Wall 68 | CFLAGS += -DEMBED 69 | CFLAGS += -Dlinux -D__linux__ -Dunix 70 | CFLAGS += -D__uClinux__ 71 | CFLAGS += -DTARGET=UCLINUX-WAGO 72 | LDFLAGS += -Wl,-move-rodata -Wl,-elf2flt 73 | endif 74 | 75 | ifeq ($(TARGET), UCLINUX-XPORT) 76 | TOOLCHAIN_PREFIX=$(UCLINUX_XPORT_TOOLCHAIN_PREFIX) 77 | CFLAGS += -DPLATFORM_BYTE_ORDER 78 | CFLAGS += -mcpu=5208 79 | CFLAGS += -fno-builtin -fno-common 80 | CFLAGS += -fno-dwarf2-cfi-asm -msep-data -DCONFIG_COLDFIRE -D__linux__ -Dunix -D__uClinux__ 81 | endif 82 | 83 | 84 | ifdef WINDOWS 85 | HAL_IMPL = WIN32 86 | LIB_OBJS_DIR = $(LIB60870_HOME)/build_win32 87 | CFLAGS=-g -DWIN32 88 | 89 | ifeq ($(TARGET), WIN32) 90 | CFLAGS+=-m32 91 | endif 92 | 93 | ifeq ($(TARGET), WIN64) 94 | CFLAGS+=-m64 95 | endif 96 | 97 | LDLIBS=-lws2_32 98 | DYNLIB_LDFLAGS=-Wl,-no-undefined -Wl,--enable-runtime-pseudo-reloc -Wl,--output-def,libiec61850.def,--out-implib,libiec61850.a 99 | 100 | 101 | # on Windows: only compile with ethernet support if winpcap files are in third_party/winpcap! 102 | ifneq (, $(wildcard $(LIB60870_HOME)/third_party/winpcap/Include/.)) 103 | 104 | ifeq ($(TARGET), WIN64) 105 | LDFLAGS += -L$(LIB60870_HOME)/third_party/winpcap/Lib/x64 106 | else 107 | LDFLAGS += -L$(LIB60870_HOME)/third_party/winpcap/Lib 108 | endif 109 | 110 | LDLIBS+=-liphlpapi -lwpcap 111 | else 112 | $(warning winpcap not found - will build without GOOSE support!) 113 | CFLAGS += -DEXCLUDE_ETHERNET_WINDOWS 114 | EXCLUDE_ETHERNET_WINDOWS = 1 115 | endif 116 | 117 | 118 | else 119 | ifeq ($(TARGET), BSD) 120 | HAL_IMPL = BSD 121 | else 122 | HAL_IMPL = POSIX 123 | endif 124 | 125 | 126 | LDLIBS = -lpthread 127 | 128 | 129 | ifeq ($(TARGET), LINUX-MIPSEL) 130 | LIB_OBJS_DIR = $(LIB60870_HOME)/build-mipsel 131 | else ifeq ($(TARGET), LINUX-ARM) 132 | LIB_OBJS_DIR = $(LIB60870_HOME)/build-arm 133 | else ifeq ($(TARGET), UCLINUX-WAGO) 134 | LIB_OBJS_DIR = $(LIB60870_HOME)/build-wago 135 | CFLAGS += -DTARGET_SYSTEM_UCLINUX_WAGO 136 | else ifeq ($(TARGET), LINUX-POWERPC) 137 | LIB_OBJS_DIR = $(LIB60870_HOME)/build-powerpc 138 | else 139 | LIB_OBJS_DIR = $(LIB60870_HOME)/build 140 | endif 141 | 142 | CFLAGS += -g 143 | #CFLAGS += -Os 144 | 145 | DYNLIB_LDFLAGS=-lpthread 146 | endif 147 | 148 | ifneq ($(TARGET), CLANG-CHECK) 149 | CC=$(TOOLCHAIN_PREFIX)gcc 150 | CPP=$(TOOLCHAIN_PREFIX)g++ 151 | endif 152 | 153 | ifeq ($(TARGET), BSD) 154 | CC=cc 155 | CPP=c++ 156 | endif 157 | 158 | AR=$(TOOLCHAIN_PREFIX)ar 159 | RANLIB=$(TOOLCHAIN_PREFIX)ranlib 160 | 161 | 162 | ifeq ($(TARGET), WIN32) 163 | PROJECT_BINARY_NAME := $(PROJECT_BINARY_NAME).exe 164 | endif 165 | 166 | LIB_NAME = $(LIB_OBJS_DIR)/liblib60870.a 167 | 168 | TEST_NAME = $(LIB_OBJS_DIR)/tests.exe 169 | 170 | ifeq ($(TARGET), BSD) 171 | CFLAGS += -arch i386 172 | LDFLAGS += -arch i386 173 | endif 174 | 175 | ifeq ($(TARGET), WIN32) 176 | DYN_LIB_NAME = $(LIB_OBJS_DIR)/lib60870.dll 177 | else 178 | 179 | ifeq ($(TARGET), BSD) 180 | DYN_LIB_NAME = $(LIB_OBJS_DIR)/liblib60870.dylib 181 | else 182 | DYN_LIB_NAME = $(LIB_OBJS_DIR)/liblib60870.so 183 | endif 184 | 185 | endif 186 | -------------------------------------------------------------------------------- /lib60870-C/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set (lib_common_SRCS 3 | ./file-service/file_server.c 4 | ./iec60870/apl/cpXXtime2a.c 5 | ./iec60870/cs101/cs101_asdu.c 6 | ./iec60870/cs101/cs101_bcr.c 7 | ./iec60870/cs101/cs101_information_objects.c 8 | ./iec60870/cs101/cs101_master_connection.c 9 | ./iec60870/cs101/cs101_master.c 10 | ./iec60870/cs101/cs101_queue.c 11 | ./iec60870/cs101/cs101_slave.c 12 | ./iec60870/cs104/cs104_connection.c 13 | ./iec60870/cs104/cs104_frame.c 14 | ./iec60870/cs104/cs104_slave.c 15 | ./iec60870/link_layer/buffer_frame.c 16 | ./iec60870/link_layer/link_layer.c 17 | ./iec60870/link_layer/serial_transceiver_ft_1_2.c 18 | ./iec60870/frame.c 19 | ./iec60870/lib60870_common.c 20 | ) 21 | 22 | if (BUILD_COMMON) 23 | list (APPEND lib_common_SRCS ./common/linked_list.c) 24 | endif (BUILD_COMMON) 25 | 26 | if (BUILD_HAL) 27 | 28 | set (lib_linux_SRCS 29 | ./hal/serial/linux/serial_port_linux.c 30 | ./hal/socket/linux/socket_linux.c 31 | ./hal/thread/linux/thread_linux.c 32 | ./hal/time/unix/time.c 33 | ./hal/memory/lib_memory.c 34 | ) 35 | 36 | set (lib_windows_SRCS 37 | ./hal/serial/win32/serial_port_win32.c 38 | ./hal/socket/win32/socket_win32.c 39 | ./hal/thread/win32/thread_win32.c 40 | ./hal/time/win32/time.c 41 | ./hal/memory/lib_memory.c 42 | ) 43 | 44 | set (lib_bsd_SRCS 45 | ./hal/serial/linux/serial_port_linux.c 46 | ./hal/socket/bsd/socket_bsd.c 47 | ./hal/thread/bsd/thread_bsd.c 48 | ./hal/time/unix/time.c 49 | ./hal/memory/lib_memory.c 50 | ) 51 | 52 | set (lib_macos_SRCS 53 | ./hal/serial/linux/serial_port_linux.c 54 | ./hal/socket/bsd/socket_bsd.c 55 | ./hal/thread/macos/thread_macos.c 56 | ./hal/time/unix/time.c 57 | ./hal/memory/lib_memory.c 58 | ) 59 | 60 | endif (BUILD_HAL) 61 | 62 | IF(WIN32) 63 | 64 | IF(MSVC) 65 | set_source_files_properties(${lib_common_SRCS} ${lib_windows_SRCS} 66 | PROPERTIES LANGUAGE CXX) 67 | ENDIF() 68 | 69 | set (library_SRCS 70 | ${lib_common_SRCS} 71 | ${lib_windows_SRCS} 72 | ) 73 | 74 | set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}\"/DEF:${CMAKE_CURRENT_SOURCE_DIR}/vs/lib60870.def\"") 75 | 76 | ELSEIF(UNIX) 77 | IF(APPLE) 78 | set (library_SRCS 79 | ${lib_common_SRCS} 80 | ${lib_macos_SRCS} 81 | ) 82 | ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") 83 | set (library_SRCS 84 | ${lib_common_SRCS} 85 | ${lib_bsd_SRCS} 86 | ) 87 | ELSE() 88 | set (library_SRCS 89 | ${lib_common_SRCS} 90 | ${lib_linux_SRCS} 91 | ) 92 | ENDIF(APPLE) 93 | ENDIF(WIN32) 94 | 95 | IF(WITH_MBEDTLS) 96 | 97 | list (APPEND library_SRCS ${tls_SRCS}) 98 | list (APPEND library_SRCS ./hal/tls/mbedtls/tls_mbedtls.c) 99 | 100 | add_definitions(-DLIB60870_HAS_TLS_SUPPORT=1) 101 | 102 | ENDIF(WITH_MBEDTLS) 103 | 104 | IF(WITH_MBEDTLS3) 105 | 106 | list (APPEND library_SRCS ${tls_SRCS}) 107 | list (APPEND library_SRCS ./hal/tls/mbedtls3/tls_mbedtls.c) 108 | 109 | add_definitions(-DLIB60870_HAS_TLS_SUPPORT=1) 110 | 111 | ENDIF(WITH_MBEDTLS3) 112 | 113 | include (GenerateExportHeader) 114 | 115 | set(RES_FILES "") 116 | if ( WIN32 ) 117 | # Adding RC resource file for adding information to the archive 118 | set(RES_FILES "${CMAKE_CURRENT_BINARY_DIR}/version.rc") 119 | message(STATUS "Generating RC file : ${RES_FILES}") 120 | configure_file( 121 | ${CMAKE_CURRENT_SOURCE_DIR}/version.rc.in 122 | ${RES_FILES} 123 | @ONLY) 124 | if( MINGW ) 125 | set(CMAKE_RC_COMPILER_INIT windres) 126 | ENABLE_LANGUAGE(RC) 127 | SET(CMAKE_RC_COMPILE_OBJECT 128 | " -O coff -i -o ") 129 | endif(MINGW) 130 | set(library_SRCS ${library_SRCS} ${RES_FILES}) 131 | endif( WIN32 ) 132 | 133 | add_library (lib60870-shared SHARED ${library_SRCS} ) 134 | 135 | set_target_properties(lib60870-shared PROPERTIES 136 | OUTPUT_NAME lib60870 137 | SOVERSION "${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_PATCH}" 138 | WINDOWS_EXPORT_ALL_SYMBOLS true 139 | ) 140 | 141 | 142 | GENERATE_EXPORT_HEADER(lib60870-shared 143 | BASE_NAME lib60870-shared 144 | EXPORT_MACRO_NAME lib60870-shared_EXPORT 145 | EXPORT_FILE_NAME lib60870-shared_export.h 146 | STATIC_DEFINE lib60870-shared_BUILT_AS_STATIC 147 | ) 148 | 149 | add_library (lib60870 STATIC ${library_SRCS}) 150 | 151 | IF(UNIX) 152 | target_link_libraries (lib60870 153 | -lpthread 154 | -lm 155 | -lrt 156 | ) 157 | 158 | configure_file( 159 | ${CMAKE_CURRENT_LIST_DIR}/lib60870.pc.in 160 | ${CMAKE_CURRENT_BINARY_DIR}/lib60870.pc @ONLY 161 | ) 162 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/lib60870.pc" DESTINATION "${CMAKE_INSTALL_PREFIX}/share/pkgconfig") 163 | ENDIF(UNIX) 164 | IF(MINGW) 165 | target_link_libraries(lib60870-shared ws2_32 iphlpapi bcrypt) 166 | target_link_libraries(lib60870 ws2_32 iphlpapi bcrypt) 167 | ENDIF(MINGW) 168 | IF(MSVC) 169 | target_link_libraries(lib60870-shared ws2_32 iphlpapi bcrypt) 170 | target_link_libraries(lib60870 ws2_32 iphlpapi bcrypt) 171 | ENDIF(MSVC) 172 | 173 | install (TARGETS lib60870 lib60870-shared 174 | RUNTIME DESTINATION bin COMPONENT Applications 175 | ARCHIVE DESTINATION lib COMPONENT Libraries 176 | LIBRARY DESTINATION lib COMPONENT Libraries 177 | ) 178 | -------------------------------------------------------------------------------- /lib60870-C/src/common/inc/linked_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2022 Michael Zillgith 3 | * 4 | * This file is part of lib60870-C 5 | * 6 | * lib60870-C is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * lib60870-C is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with lib60870-C. If not, see . 18 | * 19 | * See COPYING file for the complete license text. 20 | */ 21 | 22 | #ifndef LINKED_LIST_H_ 23 | #define LINKED_LIST_H_ 24 | 25 | #include 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /** 32 | * \addtogroup common_api_group 33 | */ 34 | /**@{*/ 35 | 36 | /** 37 | * \defgroup LINKED_LIST LinkedList data type definition and handling functions 38 | */ 39 | /**@{*/ 40 | 41 | 42 | struct sLinkedList { 43 | void* data; 44 | struct sLinkedList* next; 45 | }; 46 | 47 | /** 48 | * \brief Reference to a linked list or to a linked list element. 49 | */ 50 | typedef struct sLinkedList* LinkedList; 51 | 52 | /** 53 | * \brief Create a new LinkedList object 54 | * 55 | * \return the newly created LinkedList instance 56 | */ 57 | LinkedList 58 | LinkedList_create(void); 59 | 60 | /** 61 | * \brief Delete a LinkedList object 62 | * 63 | * This function destroy the LinkedList object. It will free all data structures used by the LinkedList 64 | * instance. It will call free for all elements of the linked list. This function should only be used if 65 | * simple objects (like dynamically allocated strings) are stored in the linked list. 66 | * 67 | * \param self the LinkedList instance 68 | */ 69 | void 70 | LinkedList_destroy(LinkedList self); 71 | 72 | 73 | typedef void (*LinkedListValueDeleteFunction) (void*); 74 | 75 | /** 76 | * \brief Delete a LinkedList object 77 | * 78 | * This function destroy the LinkedList object. It will free all data structures used by the LinkedList 79 | * instance. It will call a user provided function for each data element. This user provided function is 80 | * responsible to properly free the data element. 81 | * 82 | * \param self the LinkedList instance 83 | * \param valueDeleteFunction a function that is called for each data element of the LinkedList with the pointer 84 | * to the linked list data element. 85 | */ 86 | void 87 | LinkedList_destroyDeep(LinkedList self, LinkedListValueDeleteFunction valueDeleteFunction); 88 | 89 | /** 90 | * \brief Delete a LinkedList object without freeing the element data 91 | * 92 | * This function should be used statically allocated data objects are stored in the LinkedList instance. 93 | * Other use cases would be if the data elements in the list should not be deleted. 94 | * 95 | * \param self the LinkedList instance 96 | */ 97 | void 98 | LinkedList_destroyStatic(LinkedList self); 99 | 100 | /** 101 | * \brief Add a new element to the list 102 | * 103 | * This function will add a new data element to the list. The new element will the last element in the 104 | * list. 105 | * 106 | * \param self the LinkedList instance 107 | * \param data data to append to the LinkedList instance 108 | */ 109 | void 110 | LinkedList_add(LinkedList self, void* data); 111 | 112 | /** 113 | * \brief Removed the specified element from the list 114 | * 115 | * \param self the LinkedList instance 116 | * \param data data to remove from the LinkedList instance 117 | */ 118 | bool 119 | LinkedList_remove(LinkedList self, const void* data); 120 | 121 | /** 122 | * \brief Get the list element specified by index (starting with 0). 123 | * 124 | * \param self the LinkedList instance 125 | * \param index index of the requested element. 126 | */ 127 | LinkedList 128 | LinkedList_get(LinkedList self, int index); 129 | 130 | /** 131 | * \brief Get the next element in the list (iterator). 132 | * 133 | * \param self the LinkedList instance 134 | */ 135 | LinkedList 136 | LinkedList_getNext(LinkedList self); 137 | 138 | /** 139 | * \brief Get the last element in the list. 140 | * 141 | * \param listElement the LinkedList instance 142 | */ 143 | LinkedList 144 | LinkedList_getLastElement(LinkedList self); 145 | 146 | /** 147 | * \brief Insert a new element int the list 148 | * 149 | * \param listElement the LinkedList instance 150 | */ 151 | LinkedList 152 | LinkedList_insertAfter(LinkedList listElement, void* data); 153 | 154 | /** 155 | * \brief Get the size of the list 156 | * 157 | * \param self the LinkedList instance 158 | * 159 | * \return number of data elements stored in the list 160 | */ 161 | int 162 | LinkedList_size(LinkedList self); 163 | 164 | void* 165 | LinkedList_getData(LinkedList self); 166 | 167 | /**@}*/ 168 | 169 | /**@}*/ 170 | 171 | #ifdef __cplusplus 172 | } 173 | #endif 174 | 175 | #endif /* LINKED_LIST_H_ */ 176 | -------------------------------------------------------------------------------- /lib60870-C/src/common/linked_list.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2022 Michael Zillgith 3 | * 4 | * This file is part of lib60870-C 5 | * 6 | * lib60870-C is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * lib60870-C is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with lib60870-C. If not, see . 18 | * 19 | * See COPYING file for the complete license text. 20 | */ 21 | 22 | #include "linked_list.h" 23 | #include "lib_memory.h" 24 | 25 | #ifndef CONFIG_COMPILE_WITHOUT_COMMON 26 | 27 | LinkedList 28 | LinkedList_getLastElement(LinkedList list) 29 | { 30 | while (list->next != NULL) { 31 | list = list->next; 32 | } 33 | return list; 34 | } 35 | 36 | LinkedList 37 | LinkedList_create() 38 | { 39 | LinkedList newList; 40 | 41 | newList = (LinkedList) GLOBAL_MALLOC(sizeof(struct sLinkedList)); 42 | newList->data = NULL; 43 | newList->next = NULL; 44 | 45 | return newList; 46 | } 47 | 48 | /** 49 | * Destroy list (free). Also frees element data with helper function. 50 | */ 51 | void 52 | LinkedList_destroyDeep(LinkedList list, LinkedListValueDeleteFunction valueDeleteFunction) 53 | { 54 | LinkedList nextElement = list; 55 | LinkedList currentElement; 56 | 57 | do { 58 | currentElement = nextElement; 59 | nextElement = currentElement->next; 60 | 61 | if (currentElement->data != NULL) 62 | valueDeleteFunction(currentElement->data); 63 | 64 | GLOBAL_FREEMEM(currentElement); 65 | } 66 | while (nextElement != NULL); 67 | } 68 | 69 | void 70 | LinkedList_destroy(LinkedList list) 71 | { 72 | LinkedList_destroyDeep(list, Memory_free); 73 | } 74 | 75 | /** 76 | * Destroy list (free) without freeing the element data 77 | */ 78 | void 79 | LinkedList_destroyStatic(LinkedList list) 80 | { 81 | LinkedList nextElement = list; 82 | LinkedList currentElement; 83 | 84 | do { 85 | currentElement = nextElement; 86 | nextElement = currentElement->next; 87 | GLOBAL_FREEMEM(currentElement); 88 | } 89 | while (nextElement != NULL); 90 | } 91 | 92 | int 93 | LinkedList_size(LinkedList list) 94 | { 95 | LinkedList nextElement = list; 96 | int size = 0; 97 | 98 | while (nextElement->next != NULL) { 99 | nextElement = nextElement->next; 100 | size++; 101 | } 102 | 103 | return size; 104 | } 105 | 106 | void 107 | LinkedList_add(LinkedList list, void* data) 108 | { 109 | LinkedList newElement = LinkedList_create(); 110 | 111 | newElement->data = data; 112 | 113 | LinkedList listEnd = LinkedList_getLastElement(list); 114 | 115 | listEnd->next = newElement; 116 | } 117 | 118 | bool 119 | LinkedList_remove(LinkedList list, const void* data) 120 | { 121 | LinkedList lastElement = list; 122 | 123 | LinkedList currentElement = list->next; 124 | 125 | while (currentElement != NULL) { 126 | if (currentElement->data == data) { 127 | lastElement->next = currentElement->next; 128 | GLOBAL_FREEMEM(currentElement); 129 | return true; 130 | } 131 | 132 | lastElement = currentElement; 133 | currentElement = currentElement->next; 134 | } 135 | 136 | return false; 137 | } 138 | 139 | LinkedList 140 | LinkedList_insertAfter(LinkedList list, void* data) 141 | { 142 | LinkedList originalNextElement = LinkedList_getNext(list); 143 | 144 | LinkedList newElement = LinkedList_create(); 145 | 146 | newElement->data = data; 147 | newElement->next = originalNextElement; 148 | 149 | list->next = newElement; 150 | 151 | return newElement; 152 | } 153 | 154 | LinkedList 155 | LinkedList_getNext(LinkedList list) 156 | { 157 | return list->next; 158 | } 159 | 160 | LinkedList 161 | LinkedList_get(LinkedList list, int index) 162 | { 163 | LinkedList element = LinkedList_getNext(list); 164 | 165 | int i = 0; 166 | 167 | while (i < index) { 168 | element = LinkedList_getNext(element); 169 | 170 | if (element == NULL) 171 | return NULL; 172 | 173 | i++; 174 | } 175 | 176 | return element; 177 | } 178 | 179 | void* 180 | LinkedList_getData(LinkedList self) 181 | { 182 | return self->data; 183 | } 184 | 185 | #endif 186 | 187 | -------------------------------------------------------------------------------- /lib60870-C/src/file-service/cs101_file_service.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 Michael Zillgith 3 | * 4 | * This file is part of lib60870-C 5 | * 6 | * lib60870-C is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * lib60870-C is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with lib60870-C. If not, see . 18 | * 19 | * See COPYING file for the complete license text. 20 | */ 21 | 22 | #ifndef LIB60870_C_FILE_SERVICE_FILE_SERVICE_H_ 23 | #define LIB60870_C_FILE_SERVICE_FILE_SERVICE_H_ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #include 30 | #include 31 | #include "iec60870_common.h" 32 | #include "iec60870_slave.h" 33 | 34 | typedef enum 35 | { 36 | CS101_FILE_ERROR_SUCCESS, 37 | CS101_FILE_ERROR_TIMEOUT, 38 | CS101_FILE_ERROR_FILE_NOT_READY, 39 | CS101_FILE_ERROR_SECTION_NOT_READY, 40 | CS101_FILE_ERROR_UNKNOWN_CA, 41 | CS101_FILE_ERROR_UNKNOWN_IOA, 42 | CS101_FILE_ERROR_UNKNOWN_SERVICE, 43 | CS101_FILE_ERROR_PROTOCOL_ERROR, 44 | CS101_FILE_ERROR_ABORTED_BY_REMOTE 45 | } CS101_FileErrorCode; 46 | 47 | typedef struct sCS101_FileServer* CS101_FileServer; 48 | 49 | typedef struct sCS101_IFileReceiver* CS101_IFileReceiver; 50 | 51 | struct sCS101_IFileReceiver 52 | { 53 | void* object; /* user provided context object */ 54 | 55 | void (*finished) (CS101_IFileReceiver self, CS101_FileErrorCode result); 56 | void (*segmentReceived) (CS101_IFileReceiver self, uint8_t sectionName, int offset, int size, uint8_t* data); 57 | }; 58 | 59 | typedef struct sCS101_IFileProvider* CS101_IFileProvider; 60 | 61 | struct sCS101_IFileProvider { 62 | int ca; 63 | int ioa; 64 | uint8_t nof; 65 | 66 | void* object; /* user provided context object */ 67 | 68 | uint64_t (*getFileDate) (CS101_IFileProvider self); 69 | int (*getFileSize) (CS101_IFileProvider self); 70 | int (*getSectionSize) (CS101_IFileProvider self, int sectionNumber); 71 | 72 | /** 73 | * \brief Get section data (will be called by the file service implementation) 74 | * 75 | * \param offset byte offset of segment in the section 76 | * \param size of segment (has to be at most the size of the provided data buffer) 77 | * \param data buffer to store the segment data 78 | */ 79 | bool (*getSegmentData) (CS101_IFileProvider self, int sectionNumber, int offset, int size, uint8_t* data); 80 | 81 | void (*transferComplete) (CS101_IFileProvider self, bool success); 82 | }; 83 | 84 | /** 85 | * \brief Will be called by the \ŕef CS101_FileServer when the master sends a FILE READY (file download announcement) message to the slave 86 | * 87 | * \param parameter user provided context parameter 88 | * \param ca CA of the file 89 | * \param ioa IOA of the file 90 | * \param nof the name of file (file type) of the file 91 | * \param lengthOfFile the length of the file to be sent 92 | * \param[out] errCode error code of file service (0 - ok, 1 - unknown CA, 2 - unknown IOA, 3-unknown name of file, 4 - file not ready ) 93 | * 94 | * \return file handle (interface to access the file) 95 | */ 96 | typedef CS101_IFileReceiver (*CS101_FileReadyHandler) (void* parameter, int ca, int ioa, uint16_t nof, int lengthOfFile, int* errCode); 97 | 98 | typedef struct sCS101_FilesAvailable* CS101_FilesAvailable; 99 | 100 | struct sCS101_FilesAvailable 101 | { 102 | /** 103 | * Used to handle request directory call 104 | * 105 | * \return The next file or NULL if no more file available 106 | */ 107 | CS101_IFileProvider (*getNextFile) (void* parameter, CS101_IFileProvider continueAfter); 108 | 109 | CS101_IFileProvider (*getFile) (void* parameter, int ca, int ioa, uint16_t nof, int* errCode); 110 | 111 | void* parameter; 112 | }; 113 | 114 | 115 | /** 116 | * \brief Handle transparent files (implement CS101_IFileProvider interface) 117 | */ 118 | typedef struct sCS101_TransparentFile* CS101_TransparentFile; 119 | 120 | CS101_IFileProvider 121 | CS101_TransparentFile_create(int ca, int ioa, uint8_t nof); 122 | 123 | CS101_FileServer 124 | CS101_FileServer_create(CS101_AppLayerParameters alParams); 125 | 126 | void 127 | CS101_FileServer_destroy(CS101_FileServer self); 128 | 129 | void 130 | CS101_FileServer_setFilesAvailableIfc(CS101_FileServer self, CS101_FilesAvailable ifc); 131 | 132 | void 133 | CS101_FileServer_setFileReadyHandler(CS101_FileServer self, CS101_FileReadyHandler handler, void* parameter); 134 | 135 | CS101_SlavePlugin 136 | CS101_FileServer_getSlavePlugin(CS101_FileServer self); 137 | 138 | #ifdef __cplusplus 139 | } 140 | #endif 141 | 142 | 143 | #endif /* LIB60870_C_FILE_SERVICE_FILE_SERVICE_H_ */ 144 | -------------------------------------------------------------------------------- /lib60870-C/src/hal/inc/hal_base.h: -------------------------------------------------------------------------------- 1 | /* 2 | * hal_base.h 3 | * 4 | * Copyright 2013-2021 Michael Zillgith 5 | * 6 | * This file is part of Platform Abstraction Layer (libpal) 7 | * for libiec61850, libmms, and lib60870. 8 | */ 9 | 10 | #ifndef HAL_INC_HAL_BASE_H_ 11 | #define HAL_INC_HAL_BASE_H_ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #ifdef __GNUC__ 20 | #define ATTRIBUTE_PACKED __attribute__ ((__packed__)) 21 | #else 22 | #define ATTRIBUTE_PACKED 23 | #endif 24 | 25 | #ifndef DEPRECATED 26 | #if defined(__GNUC__) || defined(__clang__) 27 | #define DEPRECATED __attribute__((deprecated)) 28 | #else 29 | #define DEPRECATED 30 | #endif 31 | #endif 32 | 33 | #if defined _WIN32 || defined __CYGWIN__ 34 | #ifdef EXPORT_FUNCTIONS_FOR_DLL 35 | #define PAL_API __declspec(dllexport) 36 | #else 37 | #define PAL_API 38 | #endif 39 | 40 | #define PAL_INTERNAL 41 | #else 42 | #if __GNUC__ >= 4 43 | #define PAL_API __attribute__ ((visibility ("default"))) 44 | #define PAL_INTERNAL __attribute__ ((visibility ("hidden"))) 45 | #else 46 | #define PAL_API 47 | #define PAL_INTERNAL 48 | #endif 49 | #endif 50 | 51 | #endif /* HAL_INC_HAL_BASE_H_ */ 52 | -------------------------------------------------------------------------------- /lib60870-C/src/hal/inc/hal_serial.h: -------------------------------------------------------------------------------- 1 | /* 2 | * hal_serial.h 3 | * 4 | * Copyright 2013-2021 Michael Zillgith 5 | * 6 | * This file is part of Platform Abstraction Layer (libpal) 7 | * for libiec61850, libmms, and lib60870. 8 | */ 9 | 10 | #ifndef SRC_IEC60870_LINK_LAYER_SERIAL_PORT_H_ 11 | #define SRC_IEC60870_LINK_LAYER_SERIAL_PORT_H_ 12 | 13 | #include "hal_base.h" 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | /** 20 | * \file hal_serial.h 21 | * \brief Abstraction layer for serial ports. 22 | * Has to be implemented for the serial link layer of CS 101. 23 | */ 24 | 25 | /*! \addtogroup hal Platform (Hardware/OS) abstraction layer 26 | * 27 | * @{ 28 | */ 29 | 30 | /** 31 | * @defgroup HAL_SERIAL Access to serial interfaces 32 | * 33 | * Serial interface abstraction layer. This functions have to be implemented to 34 | * port lib60870 to new platforms when the serial link layers are required. 35 | * 36 | * @{ 37 | */ 38 | 39 | typedef struct sSerialPort* SerialPort; 40 | 41 | typedef enum { 42 | SERIAL_PORT_ERROR_NONE = 0, 43 | SERIAL_PORT_ERROR_INVALID_ARGUMENT = 1, 44 | SERIAL_PORT_ERROR_INVALID_BAUDRATE = 2, 45 | SERIAL_PORT_ERROR_OPEN_FAILED = 3, 46 | SERIAL_PORT_ERROR_UNKNOWN = 99 47 | } SerialPortError; 48 | 49 | /** 50 | * \brief Create a new SerialPort instance 51 | * 52 | * \param interfaceName identifier or name of the serial interface (e.g. "/dev/ttyS1" or "COM4") 53 | * \param baudRate the baud rate in baud (e.g. 9600) 54 | * \param dataBits the number of data bits (usually 8) 55 | * \param parity defines what kind of parity to use ('E' - even parity, 'O' - odd parity, 'N' - no parity) 56 | * \param stopBits the number of stop buts (usually 1) 57 | * 58 | * \return the new SerialPort instance 59 | */ 60 | PAL_API SerialPort 61 | SerialPort_create(const char* interfaceName, int baudRate, uint8_t dataBits, char parity, uint8_t stopBits); 62 | 63 | /** 64 | * \brief Destroy the SerialPort instance and release all resources 65 | */ 66 | PAL_API void 67 | SerialPort_destroy(SerialPort self); 68 | 69 | /** 70 | * \brief Open the serial interface 71 | * 72 | * \return true in case of success, false otherwise (use \ref SerialPort_getLastError for a detailed error code) 73 | */ 74 | PAL_API bool 75 | SerialPort_open(SerialPort self); 76 | 77 | /** 78 | * \brief Close (release) the serial interface 79 | */ 80 | PAL_API void 81 | SerialPort_close(SerialPort self); 82 | 83 | /** 84 | * \brief Get the baudrate used by the serial interface 85 | * 86 | * \return the baud rate in baud 87 | */ 88 | PAL_API int 89 | SerialPort_getBaudRate(SerialPort self); 90 | 91 | /** 92 | * \brief Set the timeout used for message reception 93 | * 94 | * \param timeout the timeout value in ms. 95 | */ 96 | PAL_API void 97 | SerialPort_setTimeout(SerialPort self, int timeout); 98 | 99 | /** 100 | * \brief Discard all data in the input buffer of the serial interface 101 | */ 102 | PAL_API void 103 | SerialPort_discardInBuffer(SerialPort self); 104 | 105 | /** 106 | * \brief Read a byte from the interface 107 | * 108 | * \return number of read bytes of -1 in case of an error 109 | */ 110 | PAL_API int 111 | SerialPort_readByte(SerialPort self); 112 | 113 | /** 114 | * \brief Write the number of bytes from the buffer to the serial interface 115 | * 116 | * \param buffer the buffer containing the data to write 117 | * \param startPos start position in the buffer of the data to write 118 | * \param numberOfBytes number of bytes to write 119 | * 120 | * \return number of bytes written, or -1 in case of an error 121 | */ 122 | PAL_API int 123 | SerialPort_write(SerialPort self, uint8_t* buffer, int startPos, int numberOfBytes); 124 | 125 | /** 126 | * \brief Get the error code of the last operation 127 | */ 128 | PAL_API SerialPortError 129 | SerialPort_getLastError(SerialPort self); 130 | 131 | /*! @} */ 132 | 133 | /*! @} */ 134 | 135 | #ifdef __cplusplus 136 | } 137 | #endif 138 | 139 | 140 | #endif /* SRC_IEC60870_LINK_LAYER_SERIAL_PORT_H_ */ 141 | -------------------------------------------------------------------------------- /lib60870-C/src/hal/inc/hal_thread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * thread_hal.h 3 | * 4 | * Multi-threading abstraction layer 5 | * 6 | * Copyright 2013-2021 Michael Zillgith 7 | * 8 | * This file is part of Platform Abstraction Layer (libpal) 9 | * for libiec61850, libmms, and lib60870. 10 | */ 11 | 12 | #ifndef THREAD_HAL_H_ 13 | #define THREAD_HAL_H_ 14 | 15 | #include "hal_base.h" 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | /** 22 | * \file hal_thread.h 23 | * \brief Abstraction layer for threading and synchronization 24 | */ 25 | 26 | /*! \addtogroup hal 27 | * 28 | * @{ 29 | */ 30 | 31 | /** 32 | * @defgroup HAL_THREAD Threading and synchronization API 33 | * 34 | * @{ 35 | */ 36 | 37 | /** Opaque reference of a Thread instance */ 38 | typedef struct sThread* Thread; 39 | 40 | /** Qpaque reference of a Semaphore instance */ 41 | typedef void* Semaphore; 42 | 43 | /** Reference to a function that is called when starting the thread */ 44 | typedef void* (*ThreadExecutionFunction) (void*); 45 | 46 | /** 47 | * \brief Create a new Thread instance 48 | * 49 | * \param function the entry point of the thread 50 | * \param parameter a parameter that is passed to the threads start function 51 | * \param autodestroy the thread is automatically destroyed if the ThreadExecutionFunction has finished. 52 | * 53 | * \return the newly created Thread instance 54 | */ 55 | PAL_API Thread 56 | Thread_create(ThreadExecutionFunction function, void* parameter, bool autodestroy); 57 | 58 | /** 59 | * \brief Start a Thread. 60 | * 61 | * This function invokes the start function of the thread. The thread terminates when 62 | * the start function returns. 63 | * 64 | * \param thread the Thread instance to start 65 | */ 66 | PAL_API void 67 | Thread_start(Thread thread); 68 | 69 | /** 70 | * \brief Destroy a Thread and free all related resources. 71 | * 72 | * \param thread the Thread instance to destroy 73 | */ 74 | PAL_API void 75 | Thread_destroy(Thread thread); 76 | 77 | /** 78 | * \brief Suspend execution of the Thread for the specified number of milliseconds 79 | */ 80 | PAL_API void 81 | Thread_sleep(int millies); 82 | 83 | PAL_API Semaphore 84 | Semaphore_create(int initialValue); 85 | 86 | /* Wait until semaphore value is greater than zero. Then decrease the semaphore value. */ 87 | PAL_API void 88 | Semaphore_wait(Semaphore self); 89 | 90 | PAL_API void 91 | Semaphore_post(Semaphore self); 92 | 93 | PAL_API void 94 | Semaphore_destroy(Semaphore self); 95 | 96 | /*! @} */ 97 | 98 | /*! @} */ 99 | 100 | #ifdef __cplusplus 101 | } 102 | #endif 103 | 104 | 105 | #endif /* THREAD_HAL_H_ */ 106 | -------------------------------------------------------------------------------- /lib60870-C/src/hal/inc/hal_time.h: -------------------------------------------------------------------------------- 1 | /* 2 | * time.c 3 | * 4 | * Copyright 2013-2024 Michael Zillgith 5 | * 6 | * This file is part of Platform Abstraction Layer (libpal) 7 | * for libiec61850, libmms, and lib60870. 8 | */ 9 | 10 | #ifndef HAL_C_ 11 | #define HAL_C_ 12 | 13 | #include "hal_base.h" 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | /** 20 | * \file hal_time.h 21 | * \brief Abstraction layer for system time access 22 | */ 23 | 24 | /*! \addtogroup hal 25 | * 26 | * @{ 27 | */ 28 | 29 | /** 30 | * @defgroup HAL_TIME Time related functions 31 | * 32 | * @{ 33 | */ 34 | 35 | typedef uint64_t nsSinceEpoch; 36 | typedef uint64_t msSinceEpoch; 37 | 38 | /** 39 | * Get the system time in milliseconds. 40 | * 41 | * The time value returned as 64-bit unsigned integer should represent the milliseconds 42 | * since the UNIX epoch (1970/01/01 00:00 UTC). 43 | * 44 | * \return the system time with millisecond resolution. 45 | */ 46 | PAL_API msSinceEpoch 47 | Hal_getTimeInMs(void); 48 | 49 | /** 50 | * Get the system time in nanoseconds. 51 | * 52 | * The time value returned as 64-bit unsigned integer should represent the nanoseconds 53 | * since the UNIX epoch (1970/01/01 00:00 UTC). 54 | * 55 | * \return the system time with nanosecond resolution. 56 | */ 57 | PAL_API nsSinceEpoch 58 | Hal_getTimeInNs(void); 59 | 60 | /** 61 | * Set the system time from ns time 62 | * 63 | * The time value returned as 64-bit unsigned integer should represent the nanoseconds 64 | * since the UNIX epoch (1970/01/01 00:00 UTC). 65 | * 66 | * \return true on success, otherwise false 67 | */ 68 | PAL_API bool 69 | Hal_setTimeInNs(nsSinceEpoch nsTime); 70 | 71 | /** 72 | * Get the monotonic time or system tick time in ms 73 | * 74 | * \return the system time with millisecond resolution. 75 | */ 76 | PAL_API msSinceEpoch 77 | Hal_getMonotonicTimeInMs(void); 78 | 79 | /** 80 | * Get the monotonic time or system tick in nanoseconds. 81 | * 82 | * \return the system time with nanosecond resolution. 83 | */ 84 | PAL_API nsSinceEpoch 85 | Hal_getMonotonicTimeInNs(void); 86 | 87 | /*! @} */ 88 | 89 | /*! @} */ 90 | 91 | #ifdef __cplusplus 92 | } 93 | #endif 94 | 95 | 96 | #endif /* HAL_C_ */ 97 | -------------------------------------------------------------------------------- /lib60870-C/src/hal/inc/lib_memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lib_memory.h 3 | * 4 | * Copyright 2014-2021 Michael Zillgith 5 | * 6 | * This file is part of Platform Abstraction Layer (libpal) 7 | * for libiec61850, libmms, and lib60870. 8 | */ 9 | 10 | #ifndef MEMORY_H_ 11 | #define MEMORY_H_ 12 | 13 | #include "hal_base.h" 14 | 15 | #define CALLOC(nmemb, size) Memory_calloc(nmemb, size) 16 | #define MALLOC(size) Memory_malloc(size) 17 | #define REALLOC(oldptr, size) Memory_realloc(oldptr, size) 18 | #define FREEMEM(ptr) Memory_free(ptr) 19 | 20 | #define GLOBAL_CALLOC(nmemb, size) Memory_calloc(nmemb, size) 21 | #define GLOBAL_MALLOC(size) Memory_malloc(size) 22 | #define GLOBAL_REALLOC(oldptr, size) Memory_realloc(oldptr, size) 23 | #define GLOBAL_FREEMEM(ptr) Memory_free(ptr) 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #include 30 | 31 | typedef void 32 | (*MemoryExceptionHandler) (void* parameter); 33 | 34 | PAL_API void 35 | Memory_installExceptionHandler(MemoryExceptionHandler handler, void* parameter); 36 | 37 | PAL_API void* 38 | Memory_malloc(size_t size); 39 | 40 | PAL_API void* 41 | Memory_calloc(size_t nmemb, size_t size); 42 | 43 | PAL_API void * 44 | Memory_realloc(void *ptr, size_t size); 45 | 46 | PAL_API void 47 | Memory_free(void* memb); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* MEMORY_H_ */ 54 | -------------------------------------------------------------------------------- /lib60870-C/src/hal/inc/platform_endian.h: -------------------------------------------------------------------------------- 1 | /* 2 | * platform_endian.h 3 | * 4 | * Copyright 2013-2021 Michael Zillgith 5 | * 6 | * This file is part of Platform Abstraction Layer (libpal) 7 | * for libiec61850, libmms, and lib60870. 8 | */ 9 | 10 | #ifndef ENDIAN_H_ 11 | #define ENDIAN_H_ 12 | 13 | #ifndef PLATFORM_IS_BIGENDIAN 14 | #ifdef __GNUC__ 15 | #ifdef __BYTE_ORDER__ 16 | #if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) 17 | #define PLATFORM_IS_BIGENDIAN 1 18 | #endif 19 | 20 | #else 21 | 22 | /* older versions of GCC have __BYTE_ORDER__ not defined! */ 23 | #ifdef __PPC__ 24 | #define PLATFORM_IS_BIGENDIAN 1 25 | #endif 26 | 27 | #endif /* __BYTE_ORDER__ */ 28 | #endif /* __GNUC__ */ 29 | #endif 30 | 31 | #if (PLATFORM_IS_BIGENDIAN == 1) 32 | # define ORDER_LITTLE_ENDIAN 0 33 | #else 34 | # define ORDER_LITTLE_ENDIAN 1 35 | #endif 36 | 37 | #endif /* ENDIAN_H_ */ 38 | -------------------------------------------------------------------------------- /lib60870-C/src/hal/inc/tls_socket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * tls_socket.h 3 | * 4 | * TLS socket API for protocol libraries using TCP/IP 5 | * 6 | * Copyright 2017-2021 Michael Zillgith, MZ Automation GmbH 7 | * 8 | * Abstraction layer for different TLS implementations 9 | * 10 | * The implementation has to connect the TLS API layer with the socket API layer 11 | * and perform all TLS tasks like handshake, encryption/decryption. 12 | * 13 | */ 14 | 15 | #ifndef SRC_TLS_SOCKET_API_H_ 16 | #define SRC_TLS_SOCKET_API_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /** 23 | * \file tls_socket.h 24 | * \brief Abstraction layer for different TLS implementations. 25 | * 26 | * The implementation has to connect the TLS API layer with the socket API layer 27 | * and perform all TLS tasks like handshake, encryption/decryption. 28 | */ 29 | 30 | /*! \addtogroup hal Platform (Hardware/OS) abstraction layer 31 | * 32 | * @{ 33 | */ 34 | 35 | /** 36 | * @defgroup HAL_TLS_SOCKET Abstraction layer for different TLS implementations. 37 | * 38 | * The implementation has to connect the TLS API layer with the socket API layer 39 | * and perform all TLS tasks like handshake, encryption/decryption. 40 | * 41 | * @{ 42 | */ 43 | 44 | #include 45 | #include "tls_config.h" 46 | #include "hal_socket.h" 47 | 48 | typedef struct sTLSSocket* TLSSocket; 49 | 50 | /** 51 | * \brief This function create a new TLSSocket instance using the given Socket instance 52 | * 53 | * NOTE: This function also has to perform the TLS handshake 54 | * 55 | * \param socket the socket instance to use for the TLS connection 56 | * \param configuration the TLS configuration object to use 57 | * \param storeClientCert if true, the client certificate will be stored 58 | * for later access by \ref TLSSocket_getPeerCertificate 59 | * 60 | * \return new TLS connection instance 61 | */ 62 | PAL_API TLSSocket 63 | TLSSocket_create(Socket socket, TLSConfiguration configuration, bool storeClientCert); 64 | 65 | /** 66 | * \brief Perform a new TLS handshake/session renegotiation 67 | */ 68 | PAL_API bool 69 | TLSSocket_performHandshake(TLSSocket self); 70 | 71 | /** 72 | * \brief Access the certificate used by the peer 73 | * 74 | * \param[out] certSize the size of the certificate in bytes 75 | * 76 | * \return the certificate byte buffer 77 | */ 78 | PAL_API uint8_t* 79 | TLSSocket_getPeerCertificate(TLSSocket self, int* certSize); 80 | 81 | /** 82 | * \brief read from socket to local buffer (non-blocking) 83 | * 84 | * The function shall return immediately if no data is available. In this case 85 | * the function returns 0. If an error happens the function shall return -1. 86 | * 87 | * \param self the client, connection or server socket instance 88 | * \param buf the buffer where the read bytes are copied to 89 | * \param size the maximum number of bytes to read (size of the provided buffer) 90 | * 91 | * \return the number of bytes read or -1 if an error occurred 92 | */ 93 | PAL_API int 94 | TLSSocket_read(TLSSocket self, uint8_t* buf, int size); 95 | 96 | /** 97 | * \brief send a message through the socket 98 | * 99 | * Implementation of this function is MANDATORY 100 | * 101 | * \param self client, connection or server socket instance 102 | * 103 | * \return number of bytes transmitted of -1 in case of an error 104 | */ 105 | PAL_API int 106 | TLSSocket_write(TLSSocket self, uint8_t* buf, int size); 107 | 108 | /** 109 | * \brief Closes the TLS connection and released all resources 110 | */ 111 | PAL_API void 112 | TLSSocket_close(TLSSocket self); 113 | 114 | /*! @} */ 115 | 116 | /*! @} */ 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #endif /* SRC_TLS_SOCKET_API_H_ */ 123 | -------------------------------------------------------------------------------- /lib60870-C/src/hal/memory/lib_memory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * lib_memory.c 3 | * 4 | * Copyright 2014-2021 Michael Zillgith 5 | * 6 | * This file is part of Platform Abstraction Layer (libpal) 7 | * for libiec61850, libmms, and lib60870. 8 | */ 9 | 10 | #include 11 | #include "lib_memory.h" 12 | 13 | static MemoryExceptionHandler exceptionHandler = NULL; 14 | static void* exceptionHandlerParameter = NULL; 15 | 16 | static void 17 | noMemoryAvailableHandler(void) 18 | { 19 | if (exceptionHandler != NULL) 20 | exceptionHandler(exceptionHandlerParameter); 21 | } 22 | 23 | void 24 | Memory_installExceptionHandler(MemoryExceptionHandler handler, void* parameter) 25 | { 26 | exceptionHandler = handler; 27 | exceptionHandlerParameter = parameter; 28 | } 29 | 30 | void* 31 | Memory_malloc(size_t size) 32 | { 33 | void* memory = malloc(size); 34 | 35 | if (memory == NULL) 36 | noMemoryAvailableHandler(); 37 | 38 | return memory; 39 | } 40 | 41 | void* 42 | Memory_calloc(size_t nmemb, size_t size) 43 | { 44 | void* memory = calloc(nmemb, size); 45 | 46 | if (memory == NULL) 47 | noMemoryAvailableHandler(); 48 | 49 | return memory; 50 | } 51 | 52 | void * 53 | Memory_realloc(void *ptr, size_t size) 54 | { 55 | void* memory = realloc(ptr, size); 56 | 57 | if (memory == NULL) 58 | noMemoryAvailableHandler(); 59 | 60 | return memory; 61 | } 62 | 63 | void 64 | Memory_free(void* memb) 65 | { 66 | free(memb); 67 | } 68 | 69 | -------------------------------------------------------------------------------- /lib60870-C/src/hal/thread/bsd/thread_bsd.c: -------------------------------------------------------------------------------- 1 | /** 2 | * thread_bsd.c 3 | * 4 | * Copyright 2013-2021 Michael Zillgith 5 | * 6 | * This file is part of Platform Abstraction Layer (libpal) 7 | * for libiec61850, libmms, and lib60870. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include "hal_thread.h" 14 | #include "lib_memory.h" 15 | 16 | struct sThread { 17 | ThreadExecutionFunction function; 18 | void* parameter; 19 | pthread_t pthread; 20 | int state; 21 | bool autodestroy; 22 | }; 23 | 24 | Semaphore 25 | Semaphore_create(int initialValue) 26 | { 27 | Semaphore self = GLOBAL_MALLOC(sizeof(sem_t)); 28 | 29 | sem_init((sem_t*) self, 0, initialValue); 30 | 31 | return self; 32 | } 33 | 34 | /* Wait until semaphore value is more than zero. Then decrease the semaphore value. */ 35 | void 36 | Semaphore_wait(Semaphore self) 37 | { 38 | sem_wait((sem_t*) self); 39 | } 40 | 41 | void 42 | Semaphore_post(Semaphore self) 43 | { 44 | sem_post((sem_t*) self); 45 | } 46 | 47 | void 48 | Semaphore_destroy(Semaphore self) 49 | { 50 | sem_destroy((sem_t*) self); 51 | GLOBAL_FREEMEM(self); 52 | } 53 | 54 | Thread 55 | Thread_create(ThreadExecutionFunction function, void* parameter, bool autodestroy) 56 | { 57 | Thread thread = (Thread) GLOBAL_MALLOC(sizeof(struct sThread)); 58 | 59 | if (thread != NULL) { 60 | thread->parameter = parameter; 61 | thread->function = function; 62 | thread->state = 0; 63 | thread->autodestroy = autodestroy; 64 | } 65 | 66 | return thread; 67 | } 68 | 69 | static void* 70 | destroyAutomaticThread(void* parameter) 71 | { 72 | Thread thread = (Thread) parameter; 73 | 74 | thread->function(thread->parameter); 75 | 76 | GLOBAL_FREEMEM(thread); 77 | 78 | pthread_exit(NULL); 79 | } 80 | 81 | void 82 | Thread_start(Thread thread) 83 | { 84 | if (thread->autodestroy == true) { 85 | pthread_create(&thread->pthread, NULL, destroyAutomaticThread, thread); 86 | pthread_detach(thread->pthread); 87 | } 88 | else 89 | pthread_create(&thread->pthread, NULL, thread->function, thread->parameter); 90 | 91 | thread->state = 1; 92 | } 93 | 94 | void 95 | Thread_destroy(Thread thread) 96 | { 97 | if (thread->state == 1) { 98 | pthread_join(thread->pthread, NULL); 99 | } 100 | 101 | GLOBAL_FREEMEM(thread); 102 | } 103 | 104 | void 105 | Thread_sleep(int millies) 106 | { 107 | usleep(millies * 1000); 108 | } 109 | 110 | -------------------------------------------------------------------------------- /lib60870-C/src/hal/thread/linux/thread_linux.c: -------------------------------------------------------------------------------- 1 | /* 2 | * thread_linux.c 3 | * 4 | * Copyright 2013-2021 Michael Zillgith 5 | * 6 | * This file is part of Platform Abstraction Layer (libpal) 7 | * for libiec61850, libmms, and lib60870. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include "hal_thread.h" 14 | #include "lib_memory.h" 15 | 16 | struct sThread { 17 | ThreadExecutionFunction function; 18 | void* parameter; 19 | pthread_t pthread; 20 | int state; 21 | bool autodestroy; 22 | }; 23 | 24 | Semaphore 25 | Semaphore_create(int initialValue) 26 | { 27 | Semaphore self = GLOBAL_MALLOC(sizeof(sem_t)); 28 | 29 | sem_init((sem_t*) self, 0, initialValue); 30 | 31 | return self; 32 | } 33 | 34 | /* Wait until semaphore value is more than zero. Then decrease the semaphore value. */ 35 | void 36 | Semaphore_wait(Semaphore self) 37 | { 38 | sem_wait((sem_t*) self); 39 | } 40 | 41 | void 42 | Semaphore_post(Semaphore self) 43 | { 44 | sem_post((sem_t*) self); 45 | } 46 | 47 | void 48 | Semaphore_destroy(Semaphore self) 49 | { 50 | sem_destroy((sem_t*) self); 51 | GLOBAL_FREEMEM(self); 52 | } 53 | 54 | Thread 55 | Thread_create(ThreadExecutionFunction function, void* parameter, bool autodestroy) 56 | { 57 | Thread thread = (Thread) GLOBAL_MALLOC(sizeof(struct sThread)); 58 | 59 | if (thread != NULL) { 60 | thread->parameter = parameter; 61 | thread->function = function; 62 | thread->state = 0; 63 | thread->autodestroy = autodestroy; 64 | } 65 | 66 | return thread; 67 | } 68 | 69 | static void* 70 | destroyAutomaticThread(void* parameter) 71 | { 72 | Thread thread = (Thread) parameter; 73 | 74 | thread->function(thread->parameter); 75 | 76 | GLOBAL_FREEMEM(thread); 77 | 78 | pthread_exit(NULL); 79 | } 80 | 81 | void 82 | Thread_start(Thread thread) 83 | { 84 | if (thread->autodestroy == true) { 85 | pthread_create(&thread->pthread, NULL, destroyAutomaticThread, thread); 86 | pthread_detach(thread->pthread); 87 | } 88 | else 89 | pthread_create(&thread->pthread, NULL, thread->function, thread->parameter); 90 | 91 | thread->state = 1; 92 | } 93 | 94 | void 95 | Thread_destroy(Thread thread) 96 | { 97 | if (thread->state == 1) { 98 | pthread_join(thread->pthread, NULL); 99 | } 100 | 101 | GLOBAL_FREEMEM(thread); 102 | } 103 | 104 | void 105 | Thread_sleep(int millies) 106 | { 107 | usleep(millies * 1000); 108 | } 109 | 110 | -------------------------------------------------------------------------------- /lib60870-C/src/hal/thread/macos/thread_macos.c: -------------------------------------------------------------------------------- 1 | /** 2 | * thread_macos.c 3 | * 4 | * Copyright 2013-2021 Michael Zillgith 5 | * 6 | * This file is part of Platform Abstraction Layer (libpal) 7 | * for libiec61850, libmms, and lib60870. 8 | */ 9 | 10 | /* 11 | * NOTE: MacOS needs own thread layer because it doesn't support unnamed semaphores! 12 | * NOTE: named semaphores were replaced by POSIX mutex 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "hal_thread.h" 21 | #include "lib_memory.h" 22 | 23 | struct sThread { 24 | ThreadExecutionFunction function; 25 | void* parameter; 26 | pthread_t pthread; 27 | int state; 28 | bool autodestroy; 29 | }; 30 | 31 | typedef struct sSemaphore* mSemaphore; 32 | 33 | struct sSemaphore 34 | { 35 | pthread_mutex_t mutex; 36 | }; 37 | 38 | /* 39 | * NOTE: initialValue is ignored because semaphore was replaced by mutex 40 | */ 41 | Semaphore 42 | Semaphore_create(int initialValue) 43 | { 44 | mSemaphore self = NULL; 45 | 46 | self = (mSemaphore) GLOBAL_CALLOC(1, sizeof(struct sSemaphore)); 47 | 48 | if (self) { 49 | pthread_mutex_init(&(self->mutex), NULL); 50 | } 51 | 52 | return (Semaphore)self; 53 | } 54 | 55 | /* lock mutex */ 56 | void 57 | Semaphore_wait(Semaphore self) 58 | { 59 | mSemaphore mSelf = (mSemaphore) self; 60 | 61 | int retVal = pthread_mutex_lock(&(mSelf->mutex)); 62 | 63 | if (retVal) { 64 | printf("FATAL ERROR: pthread_mutex_lock failed (err=%i)\n", retVal); 65 | exit(-1); 66 | } 67 | } 68 | 69 | /* unlock mutex */ 70 | void 71 | Semaphore_post(Semaphore self) 72 | { 73 | mSemaphore mSelf = (mSemaphore) self; 74 | 75 | int retVal = pthread_mutex_unlock(&(mSelf->mutex)); 76 | 77 | if (retVal) { 78 | printf("FATAL ERROR: pthread_mutex_unlock failed (err=%i)\n", retVal); 79 | exit(-1); 80 | } 81 | } 82 | 83 | void 84 | Semaphore_destroy(Semaphore self) 85 | { 86 | if (self) { 87 | mSemaphore mSelf = (mSemaphore) self; 88 | 89 | pthread_mutex_destroy(&(mSelf->mutex)); 90 | 91 | GLOBAL_FREEMEM(mSelf); 92 | } 93 | } 94 | 95 | Thread 96 | Thread_create(ThreadExecutionFunction function, void* parameter, bool autodestroy) 97 | { 98 | Thread thread = (Thread) GLOBAL_MALLOC(sizeof(struct sThread)); 99 | 100 | if (thread != NULL) { 101 | thread->parameter = parameter; 102 | thread->function = function; 103 | thread->state = 0; 104 | thread->autodestroy = autodestroy; 105 | } 106 | 107 | return thread; 108 | } 109 | 110 | static void* 111 | destroyAutomaticThread(void* parameter) 112 | { 113 | Thread thread = (Thread) parameter; 114 | 115 | thread->function(thread->parameter); 116 | 117 | GLOBAL_FREEMEM(thread); 118 | 119 | pthread_exit(NULL); 120 | } 121 | 122 | void 123 | Thread_start(Thread thread) 124 | { 125 | if (thread->autodestroy == true) { 126 | pthread_create(&thread->pthread, NULL, destroyAutomaticThread, thread); 127 | pthread_detach(thread->pthread); 128 | } 129 | else 130 | pthread_create(&thread->pthread, NULL, thread->function, thread->parameter); 131 | 132 | thread->state = 1; 133 | } 134 | 135 | void 136 | Thread_destroy(Thread thread) 137 | { 138 | if (thread->state == 1) { 139 | pthread_join(thread->pthread, NULL); 140 | } 141 | 142 | GLOBAL_FREEMEM(thread); 143 | } 144 | 145 | void 146 | Thread_sleep(int millies) 147 | { 148 | usleep(millies * 1000); 149 | } 150 | -------------------------------------------------------------------------------- /lib60870-C/src/hal/thread/win32/thread_win32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * thread_win32.c 3 | * 4 | * Copyright 2013-2021 Michael Zillgith 5 | * 6 | * This file is part of Platform Abstraction Layer (libpal) 7 | * for libiec61850, libmms, and lib60870. 8 | */ 9 | 10 | #include 11 | #include "lib_memory.h" 12 | #include "hal_thread.h" 13 | 14 | struct sThread { 15 | ThreadExecutionFunction function; 16 | void* parameter; 17 | HANDLE handle; 18 | int state; 19 | bool autodestroy; 20 | }; 21 | 22 | static DWORD WINAPI 23 | destroyAutomaticThreadRunner(LPVOID parameter) 24 | { 25 | Thread thread = (Thread) parameter; 26 | 27 | thread->function(thread->parameter); 28 | 29 | thread->state = 0; 30 | 31 | Thread_destroy(thread); 32 | 33 | return 0; 34 | } 35 | 36 | static DWORD WINAPI 37 | threadRunner(LPVOID parameter) 38 | { 39 | Thread thread = (Thread) parameter; 40 | 41 | thread->function(thread->parameter); 42 | 43 | return (DWORD)0; 44 | } 45 | 46 | Thread 47 | Thread_create(ThreadExecutionFunction function, void* parameter, bool autodestroy) 48 | { 49 | DWORD threadId; 50 | Thread thread = (Thread) GLOBAL_MALLOC(sizeof(struct sThread)); 51 | 52 | thread->parameter = parameter; 53 | thread->function = function; 54 | thread->state = 0; 55 | thread->autodestroy = autodestroy; 56 | 57 | if (autodestroy == true) 58 | thread->handle = CreateThread(0, 0, destroyAutomaticThreadRunner, thread, CREATE_SUSPENDED, &threadId); 59 | else 60 | thread->handle = CreateThread(0, 0, threadRunner, thread, CREATE_SUSPENDED, &threadId); 61 | 62 | return thread; 63 | } 64 | 65 | void 66 | Thread_start(Thread thread) 67 | { 68 | thread->state = 1; 69 | ResumeThread(thread->handle); 70 | } 71 | 72 | void 73 | Thread_destroy(Thread thread) 74 | { 75 | if (thread->state == 1) 76 | WaitForSingleObject(thread->handle, INFINITE); 77 | 78 | CloseHandle(thread->handle); 79 | 80 | GLOBAL_FREEMEM(thread); 81 | } 82 | 83 | void 84 | Thread_sleep(int millies) 85 | { 86 | Sleep(millies); 87 | } 88 | 89 | Semaphore 90 | Semaphore_create(int initialValue) 91 | { 92 | HANDLE self = CreateSemaphore(NULL, 1, 1, NULL); 93 | 94 | return self; 95 | } 96 | 97 | /* Wait until semaphore value is greater than zero. Then decrease the semaphore value. */ 98 | void 99 | Semaphore_wait(Semaphore self) 100 | { 101 | WaitForSingleObject((HANDLE) self, INFINITE); 102 | } 103 | 104 | void 105 | Semaphore_post(Semaphore self) 106 | { 107 | ReleaseSemaphore((HANDLE) self, 1, NULL); 108 | } 109 | 110 | void 111 | Semaphore_destroy(Semaphore self) 112 | { 113 | CloseHandle((HANDLE) self); 114 | } 115 | -------------------------------------------------------------------------------- /lib60870-C/src/hal/time/unix/time.c: -------------------------------------------------------------------------------- 1 | /* 2 | * time.c 3 | * 4 | * Copyright 2013-2024 Michael Zillgith 5 | * 6 | * This file is part of Platform Abstraction Layer (libpal) 7 | * for libiec61850, libmms, and lib60870. 8 | */ 9 | 10 | #include "hal_time.h" 11 | #include 12 | #include 13 | 14 | msSinceEpoch 15 | Hal_getTimeInMs() 16 | { 17 | struct timeval now; 18 | 19 | gettimeofday(&now, NULL); 20 | 21 | return ((uint64_t) now.tv_sec * 1000LL) + (now.tv_usec / 1000); 22 | } 23 | 24 | nsSinceEpoch 25 | Hal_getTimeInNs() 26 | { 27 | struct timespec now; 28 | 29 | clock_gettime(CLOCK_REALTIME, &now); 30 | 31 | nsSinceEpoch nsTime = (nsSinceEpoch)(now.tv_sec) * 1000000000UL; 32 | nsTime += (nsSinceEpoch)(now.tv_nsec); 33 | 34 | return nsTime; 35 | } 36 | 37 | bool 38 | Hal_setTimeInNs(nsSinceEpoch nsTime) 39 | { 40 | struct timespec tv; 41 | 42 | tv.tv_sec = nsTime / 1000000000UL; 43 | tv.tv_nsec = nsTime % 1000000000UL; 44 | 45 | if (clock_settime(CLOCK_REALTIME, &tv) < 0) { 46 | return false; 47 | } 48 | 49 | return true; 50 | } 51 | 52 | msSinceEpoch 53 | Hal_getMonotonicTimeInMs() 54 | { 55 | uint64_t timeVal = 0; 56 | 57 | struct timespec ts; 58 | 59 | if (clock_gettime (CLOCK_MONOTONIC, &ts) == 0) 60 | { 61 | timeVal = ((uint64_t)ts.tv_sec * 1000LL) + (ts.tv_nsec / 1000000); 62 | } 63 | 64 | return timeVal; 65 | } 66 | 67 | nsSinceEpoch 68 | Hal_getMonotonicTimeInNs() 69 | { 70 | uint64_t nsTime = 0; 71 | 72 | struct timespec ts; 73 | 74 | if (clock_gettime(CLOCK_REALTIME, &ts) == 0) 75 | { 76 | nsTime = ts.tv_sec * 1000000000UL; 77 | nsTime += ts.tv_nsec; 78 | } 79 | 80 | return nsTime; 81 | } 82 | -------------------------------------------------------------------------------- /lib60870-C/src/hal/time/win32/time.c: -------------------------------------------------------------------------------- 1 | /* 2 | * time.c 3 | * 4 | * Copyright 2013-2024 Michael Zillgith 5 | * 6 | * This file is part of Platform Abstraction Layer (libpal) 7 | * for libiec61850, libmms, and lib60870. 8 | */ 9 | 10 | #include "hal_time.h" 11 | #include 12 | #include 13 | 14 | uint64_t 15 | Hal_getTimeInMs() 16 | { 17 | FILETIME ft; 18 | uint64_t now; 19 | 20 | static const uint64_t DIFF_TO_UNIXTIME = 11644473600000ULL; 21 | 22 | GetSystemTimeAsFileTime(&ft); 23 | 24 | now = (LONGLONG)ft.dwLowDateTime + ((LONGLONG)(ft.dwHighDateTime) << 32LL); 25 | 26 | return (now / 10000LL) - DIFF_TO_UNIXTIME; 27 | } 28 | 29 | nsSinceEpoch 30 | Hal_getTimeInNs() 31 | { 32 | FILETIME ft; 33 | 34 | static const uint64_t DIFF_TO_UNIXTIME = 11644473600000000000ULL; 35 | 36 | GetSystemTimeAsFileTime(&ft); 37 | 38 | nsSinceEpoch nsTime = (LONGLONG)ft.dwLowDateTime + ((LONGLONG)(ft.dwHighDateTime) << 32LL); 39 | 40 | nsTime = nsTime * 100LL - DIFF_TO_UNIXTIME; 41 | 42 | return nsTime; 43 | } 44 | 45 | bool 46 | Hal_setTimeInNs(nsSinceEpoch nsTime) 47 | { 48 | uint64_t t = (nsTime / 100ULL) + 116444736000000000ULL; 49 | 50 | FILETIME ft; 51 | 52 | ft.dwLowDateTime = (uint32_t)(t & 0xffffffff); 53 | ft.dwHighDateTime = (uint32_t)(t >> 32); 54 | 55 | SYSTEMTIME st; 56 | 57 | FileTimeToSystemTime(&ft, &st); 58 | 59 | return SetSystemTime(&st); 60 | } 61 | 62 | msSinceEpoch 63 | Hal_getMonotonicTimeInMs() 64 | { 65 | return (msSinceEpoch)GetTickCount64(); 66 | } 67 | 68 | nsSinceEpoch 69 | Hal_getMonotonicTimeInNs() 70 | { 71 | return (nsSinceEpoch)(GetTickCount64() * 1000000ULL); 72 | } 73 | -------------------------------------------------------------------------------- /lib60870-C/src/hal/tls/mbedtls/mbedtls_config.h: -------------------------------------------------------------------------------- 1 | #ifndef MBEDTLS_CONFIG_H 2 | #define MBEDTLS_CONFIG_H 3 | 4 | /* System support */ 5 | #define MBEDTLS_HAVE_ASM 6 | #define MBEDTLS_HAVE_TIME 7 | #define MBEDTLS_HAVE_TIME_DATE 8 | #define MBEDTLS_NO_UDBL_DIVISION 9 | #define MBEDTLS_PLATFORM_C 10 | #define MBEDTLS_DEBUG_C 11 | 12 | /* mbed TLS feature support */ 13 | #define MBEDTLS_CIPHER_MODE_CBC 14 | #define MBEDTLS_PKCS1_V15 15 | #define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED 16 | #define MBEDTLS_SSL_PROTO_TLS1_2 17 | #define MBEDTLS_SSL_PROTO_TLS1_1 18 | #define MBEDTLS_SSL_PROTO_TLS1 19 | #define MBEDTLS_SSL_RENEGOTIATION 20 | #define MBEDTLS_ENABLE_WEAK_CIPHERSUITES 21 | #define MBEDTLS_CIPHER_NULL_CIPHER 22 | 23 | #define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES 24 | 25 | /* mbed TLS modules */ 26 | #define MBEDTLS_GCM_C 27 | #define MBEDTLS_AES_C 28 | #define MBEDTLS_ASN1_PARSE_C 29 | #define MBEDTLS_ASN1_WRITE_C 30 | #define MBEDTLS_BIGNUM_C 31 | #define MBEDTLS_CIPHER_C 32 | #define MBEDTLS_CTR_DRBG_C 33 | /* #define MBEDTLS_DES_C */ 34 | #define MBEDTLS_ENTROPY_C 35 | #define MBEDTLS_MD_C 36 | #define MBEDTLS_MD5_C 37 | #define MBEDTLS_NET_C 38 | #define MBEDTLS_OID_C 39 | #define MBEDTLS_PK_C 40 | #define MBEDTLS_PK_PARSE_C 41 | #define MBEDTLS_RSA_C 42 | #define MBEDTLS_SHA1_C 43 | #define MBEDTLS_SHA256_C 44 | #define MBEDTLS_SSL_CLI_C 45 | #define MBEDTLS_SSL_SRV_C 46 | #define MBEDTLS_SSL_TLS_C 47 | #define MBEDTLS_X509_CRT_PARSE_C 48 | #define MBEDTLS_X509_CRL_PARSE_C 49 | #define MBEDTLS_X509_USE_C 50 | #define MBEDTLS_SSL_CACHE_C 51 | 52 | /* For test certificates */ 53 | #define MBEDTLS_BASE64_C 54 | #define MBEDTLS_CERTS_C 55 | #define MBEDTLS_PEM_PARSE_C 56 | 57 | #define MBEDTLS_PKCS12_C 58 | #define MBEDTLS_PKCS5_C 59 | 60 | /* For testing with compat.sh */ 61 | #define MBEDTLS_FS_IO 62 | 63 | #define MBEDTLS_X509_CHECK_KEY_USAGE 64 | #define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE 65 | 66 | #include "mbedtls/check_config.h" 67 | 68 | #endif /* MBEDTLS_CONFIG_H */ 69 | -------------------------------------------------------------------------------- /lib60870-C/src/hal/tls/mbedtls3/mbedtls_config.h: -------------------------------------------------------------------------------- 1 | // https://github.com/Mbed-TLS/mbedtls/blob/development/docs/3.0-migration-guide.md#introduce-a-level-of-indirection-and-versioning-in-the-config-files 2 | // #ifndef MBEDTLS_CONFIG_H 3 | // #define MBEDTLS_CONFIG_H 4 | 5 | /* System support */ 6 | #define MBEDTLS_HAVE_ASM 7 | #define MBEDTLS_HAVE_TIME 8 | #define MBEDTLS_HAVE_TIME_DATE 9 | #define MBEDTLS_NO_UDBL_DIVISION 10 | #define MBEDTLS_PLATFORM_C 11 | #define MBEDTLS_DEBUG_C 12 | 13 | /* mbed TLS feature support */ 14 | #define MBEDTLS_CIPHER_MODE_CBC 15 | #define MBEDTLS_PKCS1_V15 16 | #define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED 17 | #define MBEDTLS_SSL_PROTO_TLS1_2 18 | #define MBEDTLS_SSL_PROTO_TLS1_3 19 | // MIGRATE 2.28->3.x.x: https://github.com/Mbed-TLS/mbedtls/blob/development/docs/3.0-migration-guide.md#remove-support-for-tls-10-11-and-dtls-10 20 | // #define MBEDTLS_SSL_PROTO_TLS1_1 21 | // #define MBEDTLS_SSL_PROTO_TLS1 22 | #define MBEDTLS_SSL_RENEGOTIATION 23 | 24 | #error "MBEDTLS" 25 | 26 | #define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES 27 | 28 | /* mbed TLS modules */ 29 | #define MBEDTLS_GCM_C 30 | #define MBEDTLS_AES_C 31 | #define MBEDTLS_ASN1_PARSE_C 32 | #define MBEDTLS_ASN1_WRITE_C 33 | #define MBEDTLS_BIGNUM_C 34 | #define MBEDTLS_CIPHER_C 35 | #define MBEDTLS_CTR_DRBG_C 36 | /* #define MBEDTLS_DES_C */ 37 | #define MBEDTLS_ENTROPY_C 38 | #define MBEDTLS_MD_C 39 | #define MBEDTLS_MD5_C 40 | #define MBEDTLS_NET_C 41 | #define MBEDTLS_OID_C 42 | #define MBEDTLS_PK_C 43 | #define MBEDTLS_PK_PARSE_C 44 | #define MBEDTLS_RSA_C 45 | #define MBEDTLS_SHA1_C 46 | #define MBEDTLS_SHA256_C 47 | #define MBEDTLS_SSL_CLI_C 48 | #define MBEDTLS_SSL_SRV_C 49 | #define MBEDTLS_SSL_TLS_C 50 | #define MBEDTLS_X509_CRT_PARSE_C 51 | #define MBEDTLS_X509_CRL_PARSE_C 52 | #define MBEDTLS_X509_USE_C 53 | #define MBEDTLS_SSL_CACHE_C 54 | 55 | /* For test certificates */ 56 | #define MBEDTLS_BASE64_C 57 | #define MBEDTLS_CERTS_C 58 | #define MBEDTLS_PEM_PARSE_C 59 | 60 | #define MBEDTLS_PKCS12_C 61 | #define MBEDTLS_PKCS5_C 62 | 63 | /* For testing with compat.sh */ 64 | #define MBEDTLS_FS_IO 65 | 66 | // MIGRATE 2.28->3.x.x: https://github.com/Mbed-TLS/mbedtls/blob/development/docs/3.0-migration-guide.md#remove-mbedtls_x509_check__key_usage-options-from-mbedtls_configh 67 | // #define MBEDTLS_X509_CHECK_KEY_USAGE 68 | // #define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE 69 | 70 | // MIGRATE 2.28->3.x.x: https://github.com/Mbed-TLS/mbedtls/blob/development/docs/3.0-migration-guide.md#introduce-a-level-of-indirection-and-versioning-in-the-config-files 71 | // #include "mbedtls/check_config.h" 72 | 73 | // #endif /* MBEDTLS_CONFIG_H */ 74 | -------------------------------------------------------------------------------- /lib60870-C/src/iec60870/cs101/cs101_bcr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * bcr.c 3 | * 4 | * Implementation of Binary Counter Reading (BCR) data type. 5 | * 6 | * Copyright 2016 MZ Automation GmbH 7 | * 8 | * This file is part of lib60870-C 9 | * 10 | * lib60870-C is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * lib60870-C is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with lib60870-C. If not, see . 22 | * 23 | * See COPYING file for the complete license text. 24 | */ 25 | 26 | #include "iec60870_common.h" 27 | 28 | #include 29 | 30 | #include "platform_endian.h" 31 | #include "apl_types_internal.h" 32 | #include "lib_memory.h" 33 | 34 | BinaryCounterReading 35 | BinaryCounterReading_create(BinaryCounterReading self, int32_t value, int seqNumber, 36 | bool hasCarry, bool isAdjusted, bool isInvalid) 37 | { 38 | if (self == NULL) 39 | self = (BinaryCounterReading) GLOBAL_MALLOC(sizeof(struct sBinaryCounterReading)); 40 | 41 | if (self != NULL) { 42 | BinaryCounterReading_setValue(self, value); 43 | BinaryCounterReading_setSequenceNumber(self, seqNumber); 44 | BinaryCounterReading_setCarry(self, hasCarry); 45 | BinaryCounterReading_setAdjusted(self, isAdjusted); 46 | BinaryCounterReading_setInvalid(self, isInvalid); 47 | } 48 | 49 | return self; 50 | } 51 | 52 | void 53 | BinaryCounterReading_destroy(BinaryCounterReading self) 54 | { 55 | GLOBAL_FREEMEM(self); 56 | } 57 | 58 | int32_t 59 | BinaryCounterReading_getValue(BinaryCounterReading self) 60 | { 61 | int32_t value; 62 | 63 | uint8_t* valueBytes = (uint8_t*) &(value); 64 | uint8_t* encodedValue = self->encodedValue; 65 | 66 | #if (ORDER_LITTLE_ENDIAN == 1) 67 | valueBytes[0] = encodedValue[0]; 68 | valueBytes[1] = encodedValue[1]; 69 | valueBytes[2] = encodedValue[2]; 70 | valueBytes[3] = encodedValue[3]; 71 | #else 72 | valueBytes[0] = encodedValue[3]; 73 | valueBytes[1] = encodedValue[2]; 74 | valueBytes[2] = encodedValue[1]; 75 | valueBytes[3] = encodedValue[0]; 76 | #endif 77 | 78 | return value; 79 | } 80 | 81 | void 82 | BinaryCounterReading_setValue(BinaryCounterReading self, int32_t value) 83 | { 84 | uint8_t* valueBytes = (uint8_t*) &(value); 85 | uint8_t* encodedValue = self->encodedValue; 86 | 87 | #if (ORDER_LITTLE_ENDIAN == 1) 88 | encodedValue[0] = valueBytes[0]; 89 | encodedValue[1] = valueBytes[1]; 90 | encodedValue[2] = valueBytes[2]; 91 | encodedValue[3] = valueBytes[3]; 92 | #else 93 | encodedValue[0] = valueBytes[3]; 94 | encodedValue[1] = valueBytes[2]; 95 | encodedValue[2] = valueBytes[1]; 96 | encodedValue[3] = valueBytes[0]; 97 | #endif 98 | } 99 | 100 | int 101 | BinaryCounterReading_getSequenceNumber(BinaryCounterReading self) 102 | { 103 | return (self->encodedValue[4] & 0x1f); 104 | } 105 | 106 | void 107 | BinaryCounterReading_setSequenceNumber(BinaryCounterReading self, int value) 108 | { 109 | int seqNumber = value & 0x1f; 110 | int flags = self->encodedValue[4] & 0xe0; 111 | 112 | self->encodedValue[4] = flags | seqNumber; 113 | } 114 | 115 | bool 116 | BinaryCounterReading_hasCarry(BinaryCounterReading self) 117 | { 118 | return ((self->encodedValue[4] & 0x20) == 0x20); 119 | } 120 | 121 | void 122 | BinaryCounterReading_setCarry(BinaryCounterReading self, bool value) 123 | { 124 | if (value) 125 | self->encodedValue[4] |= 0x20; 126 | else 127 | self->encodedValue[4] &= 0xdf; 128 | } 129 | 130 | bool 131 | BinaryCounterReading_isAdjusted(BinaryCounterReading self) 132 | { 133 | return ((self->encodedValue[4] & 0x40) == 0x40); 134 | } 135 | 136 | void 137 | BinaryCounterReading_setAdjusted(BinaryCounterReading self, bool value) 138 | { 139 | if (value) 140 | self->encodedValue[4] |= 0x40; 141 | else 142 | self->encodedValue[4] &= 0xbf; 143 | } 144 | 145 | bool 146 | BinaryCounterReading_isInvalid(BinaryCounterReading self) 147 | { 148 | return ((self->encodedValue[4] & 0x80) == 0x80); 149 | } 150 | 151 | void 152 | BinaryCounterReading_setInvalid(BinaryCounterReading self, bool value) 153 | { 154 | if (value) 155 | self->encodedValue[4] |= 0x80; 156 | else 157 | self->encodedValue[4] &= 0x7f; 158 | } 159 | -------------------------------------------------------------------------------- /lib60870-C/src/iec60870/cs101/cs101_master_connection.c: -------------------------------------------------------------------------------- 1 | /* 2 | * cs101_master_connection.c 3 | * 4 | * Copyright 2017 MZ Automation GmbH 5 | * 6 | * This file is part of lib60870-C 7 | * 8 | * lib60870-C is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * lib60870-C is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with lib60870-C. If not, see . 20 | * 21 | * See COPYING file for the complete license text. 22 | */ 23 | 24 | #include "iec60870_slave.h" 25 | 26 | bool 27 | IMasterConnection_isReady(IMasterConnection self) 28 | { 29 | return self->isReady(self); 30 | } 31 | 32 | bool 33 | IMasterConnection_sendASDU(IMasterConnection self, CS101_ASDU asdu) 34 | { 35 | return self->sendASDU(self, asdu); 36 | } 37 | 38 | bool 39 | IMasterConnection_sendACT_CON(IMasterConnection self, CS101_ASDU asdu, bool negative) 40 | { 41 | return self->sendACT_CON(self, asdu, negative); 42 | } 43 | 44 | bool 45 | IMasterConnection_sendACT_TERM(IMasterConnection self, CS101_ASDU asdu) 46 | { 47 | return self->sendACT_TERM(self, asdu); 48 | } 49 | 50 | CS101_AppLayerParameters 51 | IMasterConnection_getApplicationLayerParameters(IMasterConnection self) 52 | { 53 | return self->getApplicationLayerParameters(self); 54 | } 55 | 56 | void 57 | IMasterConnection_close(IMasterConnection self) 58 | { 59 | if (self->close) 60 | self->close(self); 61 | } 62 | 63 | int 64 | IMasterConnection_getPeerAddress(IMasterConnection self, char* addrBuf, int addrBufSize) 65 | { 66 | if (self->getPeerAddress) 67 | return self->getPeerAddress(self, addrBuf, addrBufSize); 68 | else 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /lib60870-C/src/iec60870/cs101/cs101_queue.c: -------------------------------------------------------------------------------- 1 | /* 2 | * cs101_queue.c 3 | * 4 | * Copyright 2017-2018 MZ Automation GmbH 5 | * 6 | * This file is part of lib60870-C 7 | * 8 | * lib60870-C is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * lib60870-C is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with lib60870-C. If not, see . 20 | * 21 | * See COPYING file for the complete license text. 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "buffer_frame.h" 29 | #include "lib_memory.h" 30 | #include "lib60870_config.h" 31 | #include "lib60870_internal.h" 32 | #include "apl_types_internal.h" 33 | #include "cs101_queue.h" 34 | 35 | /******************************************** 36 | * CS101_Queue 37 | ********************************************/ 38 | 39 | void 40 | CS101_Queue_initialize(CS101_Queue self, int maxQueueSize) 41 | { 42 | self->entryCounter = 0; 43 | self->firstMsgIndex = 0; 44 | self->lastMsgIndex = 0; 45 | self->size = maxQueueSize; 46 | 47 | BufferFrame_initialize(&(self->encodeFrame), NULL, 0); 48 | 49 | #if (CS101_MAX_QUEUE_SIZE == -1) 50 | int queueSize = maxQueueSize; 51 | 52 | if (maxQueueSize == -1) 53 | queueSize = 100; 54 | 55 | self->elements = (CS101_QueueElement) GLOBAL_CALLOC(queueSize, sizeof(struct sCS101_QueueElement)); 56 | 57 | self->size = queueSize; 58 | #else 59 | self->size = CS101_MAX_QUEUE_SIZE; 60 | #endif 61 | 62 | 63 | #if (CONFIG_USE_SEMAPHORES == 1) 64 | self->queueLock = Semaphore_create(1); 65 | #endif 66 | } 67 | 68 | void 69 | CS101_Queue_dispose(CS101_Queue self) 70 | { 71 | #if (CONFIG_USE_SEMAPHORES == 1) 72 | Semaphore_destroy(self->queueLock); 73 | #endif 74 | 75 | #if (CS101_MAX_QUEUE_SIZE == -1) 76 | GLOBAL_FREEMEM(self->elements); 77 | #endif 78 | } 79 | 80 | void 81 | CS101_Queue_lock(CS101_Queue self) 82 | { 83 | #if (CONFIG_USE_SEMAPHORES == 1) 84 | Semaphore_wait(self->queueLock); 85 | #endif 86 | } 87 | 88 | void 89 | CS101_Queue_unlock(CS101_Queue self) 90 | { 91 | #if (CONFIG_USE_SEMAPHORES == 1) 92 | Semaphore_post(self->queueLock); 93 | #endif 94 | } 95 | 96 | void 97 | CS101_Queue_enqueue(CS101_Queue self, CS101_ASDU asdu) 98 | { 99 | CS101_Queue_lock(self); 100 | 101 | int nextIndex; 102 | bool removeEntry = false; 103 | 104 | if (self->entryCounter == 0) { 105 | self->firstMsgIndex = 0; 106 | nextIndex = 0; 107 | } 108 | else 109 | nextIndex = self->lastMsgIndex + 1; 110 | 111 | if (nextIndex == self->size) 112 | nextIndex = 0; 113 | 114 | if (self->entryCounter == self->size) 115 | removeEntry = true; 116 | 117 | if (removeEntry == false) { 118 | DEBUG_PRINT("add entry (nextIndex:%i)\n", nextIndex); 119 | self->lastMsgIndex = nextIndex; 120 | self->entryCounter++; 121 | } 122 | else { 123 | DEBUG_PRINT("add entry (nextIndex:%i) -> remove oldest\n", nextIndex); 124 | 125 | /* remove oldest entry */ 126 | self->lastMsgIndex = nextIndex; 127 | 128 | int firstIndex = nextIndex + 1; 129 | 130 | if (firstIndex == self->size) 131 | firstIndex = 0; 132 | 133 | self->firstMsgIndex = firstIndex; 134 | } 135 | 136 | self->encodeFrame.buffer = self->elements[nextIndex].buffer; 137 | self->encodeFrame.startSize = 0; 138 | self->encodeFrame.msgSize = 0; 139 | 140 | CS101_ASDU_encode(asdu, (Frame)&(self->encodeFrame)); 141 | 142 | int srcSize = self->encodeFrame.msgSize; 143 | self->elements[nextIndex].size = srcSize; 144 | 145 | DEBUG_PRINT("Events in FIFO: %i (first: %i, last: %i)\n", self->entryCounter, 146 | self->firstMsgIndex, self->lastMsgIndex); 147 | 148 | CS101_Queue_unlock(self); 149 | } 150 | 151 | 152 | /* 153 | * NOTE: Locking has to be done by caller! 154 | */ 155 | Frame 156 | CS101_Queue_dequeue(CS101_Queue self, Frame resultStorage) 157 | { 158 | Frame frame = NULL; 159 | 160 | if (self->entryCounter != 0) { 161 | 162 | if (resultStorage) { 163 | frame = resultStorage; 164 | 165 | int currentIndex = self->firstMsgIndex; 166 | 167 | Frame_appendBytes(frame, self->elements[currentIndex].buffer, self->elements[currentIndex].size); 168 | 169 | self->firstMsgIndex = (currentIndex + 1) % self->size; 170 | self->entryCounter--; 171 | } 172 | } 173 | 174 | return frame; 175 | } 176 | 177 | bool 178 | CS101_Queue_isFull(CS101_Queue self) 179 | { 180 | return (self->entryCounter == self->size); 181 | } 182 | 183 | bool 184 | CS101_Queue_isEmpty(CS101_Queue self) 185 | { 186 | return (self->entryCounter == 0); 187 | } 188 | 189 | 190 | void 191 | CS101_Queue_flush(CS101_Queue self) 192 | { 193 | CS101_Queue_lock(self); 194 | self->entryCounter = 0; 195 | self->firstMsgIndex = 0; 196 | self->lastMsgIndex = 0; 197 | CS101_Queue_unlock(self); 198 | } 199 | 200 | 201 | /******************************************** 202 | * END CS101_Queue 203 | ********************************************/ 204 | -------------------------------------------------------------------------------- /lib60870-C/src/iec60870/cs104/cs104_frame.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 Michael Zillgith 3 | * 4 | * This file is part of lib60870-C 5 | * 6 | * lib60870-C is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * lib60870-C is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with lib60870-C. If not, see . 18 | * 19 | * See COPYING file for the complete license text. 20 | */ 21 | 22 | #include "cs104_frame.h" 23 | 24 | #include 25 | #include 26 | 27 | #include "frame.h" 28 | #include "lib60870_internal.h" 29 | #include "lib_memory.h" 30 | 31 | #ifndef CONFIG_LIB60870_STATIC_FRAMES 32 | #define CONFIG_LIB60870_STATIC_FRAMES 0 33 | #endif 34 | 35 | 36 | struct sT104Frame { 37 | FrameVFT virtualFunctionTable; 38 | 39 | uint8_t buffer[256]; 40 | int msgSize; 41 | 42 | #if (CONFIG_LIB60870_STATIC_FRAMES == 1) 43 | /* TODO move to base class? */ 44 | uint8_t allocated; 45 | #endif 46 | }; 47 | 48 | static struct sFrameVFT t104FrameVFT = { 49 | T104Frame_destroy, 50 | T104Frame_resetFrame, 51 | T104Frame_setNextByte, 52 | T104Frame_appendBytes, 53 | T104Frame_getMsgSize, 54 | T104Frame_getBuffer, 55 | T104Frame_getSpaceLeft 56 | }; 57 | 58 | #if (CONFIG_LIB60870_STATIC_FRAMES == 1) 59 | 60 | static int staticFramesInitialized = 0; 61 | 62 | #ifndef CONFIG_LIB60870_MAX_FRAMES 63 | #define CONFIG_LIB60870_MAX_FRAMES 10 64 | #endif 65 | 66 | struct sT104Frame staticFrames[CONFIG_LIB60870_MAX_FRAMES]; 67 | 68 | static void 69 | initializeFrames(void) 70 | { 71 | int i; 72 | 73 | for (i = 0; i < CONFIG_LIB60870_MAX_FRAMES; i++) { 74 | staticFrames[i].virtualFunctionTable = &t104FrameVFT; 75 | staticFrames[i].allocated = 0; 76 | staticFrames[i].buffer[0] = 0x68; 77 | } 78 | } 79 | 80 | static T104Frame 81 | getNextFreeFrame(void) 82 | { 83 | int i; 84 | 85 | for (i = 0; i < CONFIG_LIB60870_MAX_FRAMES; i++) { 86 | 87 | if (staticFrames[i].allocated == 0) { 88 | staticFrames[i].msgSize = 6; 89 | staticFrames[i].allocated = 1; 90 | 91 | return &staticFrames[i]; 92 | } 93 | } 94 | 95 | return NULL; 96 | } 97 | 98 | #endif /* (CONFIG_LIB60870_STATIC_FRAMES == 1) */ 99 | 100 | 101 | T104Frame 102 | T104Frame_create() 103 | { 104 | #if (CONFIG_LIB60870_STATIC_FRAMES == 1) 105 | 106 | if (staticFramesInitialized == 0) { 107 | initializeFrames(); 108 | staticFramesInitialized = 1; 109 | } 110 | 111 | T104Frame self = getNextFreeFrame(); 112 | 113 | #else 114 | T104Frame self = (T104Frame) GLOBAL_MALLOC(sizeof(struct sT104Frame)); 115 | 116 | if (self != NULL) { 117 | 118 | int i; 119 | for (i = 0; i < 256; i++) 120 | self->buffer[i] = 0; 121 | 122 | self->virtualFunctionTable = &t104FrameVFT; 123 | self->buffer[0] = 0x68; 124 | self->msgSize = 6; 125 | } 126 | #endif 127 | 128 | return self; 129 | } 130 | 131 | void 132 | T104Frame_destroy(Frame super) 133 | { 134 | T104Frame self = (T104Frame) super; 135 | 136 | #if (CONFIG_LIB60870_STATIC_FRAMES == 1) 137 | self->allocated = 0; 138 | #else 139 | GLOBAL_FREEMEM(self); 140 | #endif 141 | } 142 | 143 | void 144 | T104Frame_resetFrame(Frame super) 145 | { 146 | T104Frame self = (T104Frame) super; 147 | 148 | self->msgSize = 6; 149 | } 150 | 151 | void 152 | T104Frame_prepareToSend(T104Frame self, int sendCounter, int receiveCounter) 153 | { 154 | uint8_t* buffer = self->buffer; 155 | 156 | buffer[1] = (uint8_t) (self->msgSize - 2); 157 | 158 | buffer[2] = (uint8_t) ((sendCounter % 128) * 2); 159 | buffer[3] = (uint8_t) (sendCounter / 128); 160 | 161 | buffer[4] = (uint8_t) ((receiveCounter % 128) * 2); 162 | buffer[5] = (uint8_t) (receiveCounter / 128); 163 | } 164 | 165 | void 166 | T104Frame_setNextByte(Frame super, uint8_t byte) 167 | { 168 | T104Frame self = (T104Frame) super; 169 | 170 | self->buffer[self->msgSize++] = byte; 171 | } 172 | 173 | void 174 | T104Frame_appendBytes(Frame super, const uint8_t* bytes, int numberOfBytes) 175 | { 176 | T104Frame self = (T104Frame) super; 177 | 178 | int i; 179 | 180 | uint8_t* target = self->buffer + self->msgSize; 181 | 182 | for (i = 0; i < numberOfBytes; i++) 183 | target[i] = bytes[i]; 184 | 185 | self->msgSize += numberOfBytes; 186 | } 187 | 188 | int 189 | T104Frame_getMsgSize(Frame super) 190 | { 191 | T104Frame self = (T104Frame) super; 192 | 193 | return self->msgSize; 194 | } 195 | 196 | uint8_t* 197 | T104Frame_getBuffer(Frame super) 198 | { 199 | T104Frame self = (T104Frame) super; 200 | 201 | return self->buffer; 202 | } 203 | 204 | int 205 | T104Frame_getSpaceLeft(Frame super) 206 | { 207 | T104Frame self = (T104Frame) super; 208 | 209 | return (IEC60870_5_104_MAX_ASDU_LENGTH + IEC60870_5_104_APCI_LENGTH - self->msgSize); 210 | } 211 | -------------------------------------------------------------------------------- /lib60870-C/src/iec60870/frame.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 MZ Automation GmbH 3 | * 4 | * This file is part of lib60870-C 5 | * 6 | * lib60870-C is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * lib60870-C is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with lib60870-C. If not, see . 18 | * 19 | * See COPYING file for the complete license text. 20 | */ 21 | 22 | #include "frame.h" 23 | #include "iec60870_common.h" 24 | 25 | struct sFrame { 26 | FrameVFT virtualFunctionTable; 27 | }; 28 | 29 | 30 | void 31 | Frame_destroy(Frame self) 32 | { 33 | self->virtualFunctionTable->destroy(self); 34 | } 35 | 36 | void 37 | Frame_resetFrame(Frame self) 38 | { 39 | self->virtualFunctionTable->resetFrame(self); 40 | } 41 | 42 | void 43 | Frame_setNextByte(Frame self, uint8_t byte) 44 | { 45 | self->virtualFunctionTable->setNextByte(self, byte); 46 | } 47 | 48 | void 49 | Frame_appendBytes(Frame self, uint8_t* bytes, int numberOfBytes) 50 | { 51 | self->virtualFunctionTable->appendBytes(self, bytes, numberOfBytes); 52 | } 53 | 54 | int 55 | Frame_getMsgSize(Frame self) 56 | { 57 | return self->virtualFunctionTable->getMsgSize(self); 58 | } 59 | 60 | uint8_t* 61 | Frame_getBuffer(Frame self) 62 | { 63 | return self->virtualFunctionTable->getBuffer(self); 64 | } 65 | 66 | 67 | int 68 | Frame_getSpaceLeft(Frame self) 69 | { 70 | return self->virtualFunctionTable->getSpaceLeft(self); 71 | } 72 | -------------------------------------------------------------------------------- /lib60870-C/src/iec60870/lib60870_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 MZ Automation GmbH 3 | * 4 | * This file is part of lib60870-C 5 | * 6 | * lib60870-C is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * lib60870-C is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with lib60870-C. If not, see . 18 | * 19 | * See COPYING file for the complete license text. 20 | */ 21 | 22 | #include "iec60870_common.h" 23 | #include "lib60870_internal.h" 24 | 25 | #include 26 | #include 27 | 28 | #if (CONFIG_DEBUG_OUTPUT == 1) 29 | static bool debugOutputEnabled = 1; 30 | #endif 31 | 32 | void 33 | lib60870_debug_print(const char *format, ...) 34 | { 35 | #if (CONFIG_DEBUG_OUTPUT == 1) 36 | if (debugOutputEnabled) 37 | { 38 | printf("DEBUG_LIB60870: "); 39 | va_list ap; 40 | va_start(ap, format); 41 | vprintf(format, ap); 42 | va_end(ap); 43 | } 44 | #else 45 | UNUSED_PARAMETER(format); 46 | #endif 47 | } 48 | 49 | void 50 | Lib60870_enableDebugOutput(bool value) 51 | { 52 | #if (CONFIG_DEBUG_OUTPUT == 1) 53 | debugOutputEnabled = value; 54 | #else 55 | UNUSED_PARAMETER(value); 56 | #endif 57 | } 58 | 59 | Lib60870VersionInfo 60 | Lib60870_getLibraryVersionInfo() 61 | { 62 | Lib60870VersionInfo versionInfo; 63 | 64 | versionInfo.major = LIB60870_VERSION_MAJOR; 65 | versionInfo.minor = LIB60870_VERSION_MINOR; 66 | versionInfo.patch = LIB60870_VERSION_PATCH; 67 | 68 | return versionInfo; 69 | } 70 | -------------------------------------------------------------------------------- /lib60870-C/src/iec60870/link_layer/buffer_frame.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Michael Zillgith 3 | * 4 | * This file is part of lib60870-C 5 | * 6 | * lib60870-C is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * lib60870-C is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with lib60870-C. If not, see . 18 | * 19 | * See COPYING file for the complete license text. 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | #include "frame.h" 26 | #include "buffer_frame.h" 27 | 28 | static struct sFrameVFT bufferFrameVFT = { 29 | BufferFrame_destroy, 30 | BufferFrame_resetFrame, 31 | BufferFrame_setNextByte, 32 | BufferFrame_appendBytes, 33 | BufferFrame_getMsgSize, 34 | BufferFrame_getBuffer, 35 | BufferFrame_getSpaceLeft 36 | }; 37 | 38 | Frame 39 | BufferFrame_initialize(BufferFrame self, uint8_t* buffer, int startSize) 40 | { 41 | self->virtualFunctionTable = &bufferFrameVFT; 42 | self->buffer = buffer; 43 | 44 | self->startSize = startSize; 45 | self->msgSize = startSize; 46 | self->isUsed = false; 47 | 48 | return (Frame) self; 49 | } 50 | 51 | void 52 | BufferFrame_destroy(Frame super) 53 | { 54 | BufferFrame self = (BufferFrame) super; 55 | 56 | self->isUsed = false; 57 | } 58 | 59 | void 60 | BufferFrame_resetFrame(Frame super) 61 | { 62 | BufferFrame self = (BufferFrame) super; 63 | 64 | self->msgSize = self->startSize; 65 | } 66 | 67 | void 68 | BufferFrame_setNextByte(Frame super, uint8_t byte) 69 | { 70 | BufferFrame self = (BufferFrame) super; 71 | 72 | self->buffer[self->msgSize++] = byte; 73 | } 74 | 75 | void 76 | BufferFrame_appendBytes(Frame super, const uint8_t* bytes, int numberOfBytes) 77 | { 78 | BufferFrame self = (BufferFrame) super; 79 | 80 | int i; 81 | 82 | uint8_t* target = self->buffer + self->msgSize; 83 | 84 | for (i = 0; i < numberOfBytes; i++) 85 | target[i] = bytes[i]; 86 | 87 | self->msgSize += numberOfBytes; 88 | } 89 | 90 | int 91 | BufferFrame_getMsgSize(Frame super) 92 | { 93 | BufferFrame self = (BufferFrame) super; 94 | 95 | return self->msgSize; 96 | } 97 | 98 | uint8_t* 99 | BufferFrame_getBuffer(Frame super) 100 | { 101 | BufferFrame self = (BufferFrame) super; 102 | 103 | return self->buffer; 104 | } 105 | 106 | int 107 | BufferFrame_getSpaceLeft(Frame super) 108 | { 109 | BufferFrame self = (BufferFrame) super; 110 | 111 | return ((self->startSize) - self->msgSize); 112 | } 113 | 114 | bool 115 | BufferFrame_isUsed(BufferFrame self) 116 | { 117 | return self->isUsed; 118 | } 119 | 120 | void 121 | BufferFrame_markAsUsed(BufferFrame self) 122 | { 123 | self->isUsed = true; 124 | } 125 | -------------------------------------------------------------------------------- /lib60870-C/src/iec60870/link_layer/serial_transceiver_ft_1_2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * serial_transceiver_ft_1_2.c 3 | * 4 | * Copyright 2017-2022 Michael Zillgith 5 | * 6 | * This file is part of lib60870-C 7 | * 8 | * lib60870-C is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * lib60870-C is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with lib60870-C. If not, see . 20 | * 21 | * See COPYING file for the complete license text. 22 | */ 23 | 24 | #include "hal_serial.h" 25 | #include "serial_transceiver_ft_1_2.h" 26 | #include "lib_memory.h" 27 | #include 28 | #include 29 | #include "lib60870_internal.h" 30 | 31 | struct sSerialTransceiverFT12 { 32 | int messageTimeout; 33 | int characterTimeout; 34 | LinkLayerParameters linkLayerParameters; 35 | SerialPort serialPort; 36 | IEC60870_RawMessageHandler rawMessageHandler; 37 | void* rawMessageHandlerParameter; 38 | }; 39 | 40 | SerialTransceiverFT12 41 | SerialTransceiverFT12_create(SerialPort serialPort, LinkLayerParameters linkLayerParameters) 42 | { 43 | SerialTransceiverFT12 self = (SerialTransceiverFT12) GLOBAL_MALLOC(sizeof(struct sSerialTransceiverFT12)); 44 | 45 | if (self != NULL) { 46 | self->messageTimeout = 10; 47 | self->characterTimeout = 300; 48 | self->linkLayerParameters = linkLayerParameters; 49 | self->serialPort = serialPort; 50 | self->rawMessageHandler = NULL; 51 | } 52 | 53 | return self; 54 | } 55 | 56 | void 57 | SerialTransceiverFT12_destroy(SerialTransceiverFT12 self) 58 | { 59 | if (self != NULL) 60 | GLOBAL_FREEMEM(self); 61 | } 62 | 63 | void 64 | SerialTransceiverFT12_setTimeouts(SerialTransceiverFT12 self, int messageTimeout, int characterTimeout) 65 | { 66 | self->messageTimeout = messageTimeout; 67 | self->characterTimeout = characterTimeout; 68 | } 69 | 70 | void 71 | SerialTransceiverFT12_setRawMessageHandler(SerialTransceiverFT12 self, IEC60870_RawMessageHandler handler, void* parameter) 72 | { 73 | self->rawMessageHandler = handler; 74 | self->rawMessageHandlerParameter = parameter; 75 | } 76 | 77 | int 78 | SerialTransceiverFT12_getBaudRate(SerialTransceiverFT12 self) 79 | { 80 | return SerialPort_getBaudRate(self->serialPort); 81 | } 82 | 83 | void 84 | SerialTransceiverFT12_sendMessage(SerialTransceiverFT12 self, uint8_t* msg, int msgSize) 85 | { 86 | if (self->rawMessageHandler) 87 | self->rawMessageHandler(self->rawMessageHandlerParameter, msg, msgSize, true); 88 | 89 | SerialPort_write(self->serialPort, msg, 0, msgSize); 90 | } 91 | 92 | static int 93 | readBytesWithTimeout(SerialTransceiverFT12 self, uint8_t* buffer, int startIndex, int count) 94 | { 95 | int readByte; 96 | int readBytes = 0; 97 | 98 | while ((readByte = SerialPort_readByte(self->serialPort)) != -1) { 99 | buffer[startIndex++] = (uint8_t) readByte; 100 | 101 | readBytes++; 102 | 103 | if (readBytes >= count) 104 | break; 105 | } 106 | 107 | return readBytes; 108 | } 109 | 110 | void 111 | SerialTransceiverFT12_readNextMessage(SerialTransceiverFT12 self, uint8_t* buffer, 112 | SerialTXMessageHandler messageHandler, void* parameter) 113 | { 114 | SerialPort_setTimeout(self->serialPort, self->messageTimeout); 115 | 116 | int read = SerialPort_readByte(self->serialPort); 117 | 118 | if (read != -1) { 119 | 120 | if (read == 0x68) { 121 | 122 | SerialPort_setTimeout(self->serialPort, self->characterTimeout); 123 | 124 | int msgSize = SerialPort_readByte(self->serialPort); 125 | 126 | if (msgSize == -1) 127 | goto sync_error; 128 | 129 | buffer[0] = (uint8_t) 0x68; 130 | buffer[1] = (uint8_t) msgSize; 131 | 132 | msgSize += 4; 133 | 134 | int readBytes = readBytesWithTimeout(self, buffer, 2, msgSize); 135 | 136 | if (readBytes == msgSize) { 137 | msgSize += 2; 138 | 139 | if (self->rawMessageHandler) 140 | self->rawMessageHandler(self->rawMessageHandlerParameter, buffer, msgSize, false); 141 | 142 | messageHandler(parameter, buffer, msgSize); 143 | } 144 | else { 145 | DEBUG_PRINT("RECV: Timeout reading variable length frame size = %i (expected = %i)\n", readBytes, msgSize); 146 | } 147 | 148 | } 149 | else if (read == 0x10) { 150 | 151 | SerialPort_setTimeout(self->serialPort, self->characterTimeout); 152 | 153 | buffer[0] = 0x10; 154 | 155 | int msgSize = 3 + self->linkLayerParameters->addressLength; 156 | 157 | int readBytes = readBytesWithTimeout(self, buffer, 1, msgSize); 158 | 159 | if (readBytes == msgSize) { 160 | msgSize += 1; 161 | 162 | if (self->rawMessageHandler) 163 | self->rawMessageHandler(self->rawMessageHandlerParameter, buffer, msgSize, false); 164 | 165 | messageHandler(parameter, buffer, msgSize); 166 | } 167 | else { 168 | DEBUG_PRINT("RECV: Timeout reading fixed length frame size = %i (expected = %i)\n", readBytes, msgSize); 169 | } 170 | 171 | } 172 | else if (read == 0xe5) { 173 | int msgSize = 1; 174 | buffer[0] = (uint8_t) read; 175 | 176 | if (self->rawMessageHandler) 177 | self->rawMessageHandler(self->rawMessageHandlerParameter, buffer, msgSize, false); 178 | 179 | messageHandler(parameter, buffer, msgSize); 180 | } 181 | else { 182 | goto sync_error; 183 | } 184 | 185 | } 186 | 187 | return; 188 | 189 | sync_error: 190 | 191 | DEBUG_PRINT("RECV: SYNC ERROR\n"); 192 | 193 | SerialPort_discardInBuffer(self->serialPort); 194 | 195 | return; 196 | } 197 | -------------------------------------------------------------------------------- /lib60870-C/src/inc/api/iec60870_master.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 Michael Zillgith 3 | * 4 | * This file is part of lib60870-C 5 | * 6 | * lib60870-C is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * lib60870-C is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with lib60870-C. If not, see . 18 | * 19 | * See COPYING file for the complete license text. 20 | */ 21 | 22 | #ifndef SRC_IEC60870_MASTER_H_ 23 | #define SRC_IEC60870_MASTER_H_ 24 | 25 | #include 26 | #include 27 | 28 | #include "iec60870_common.h" 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** 35 | * \file iec60870_master.h 36 | * \brief Common master side definitions for IEC 60870-5-101/104 37 | * These types are used by CS101/CS104 master 38 | */ 39 | 40 | /** 41 | * \brief Callback handler for received ASDUs 42 | * 43 | * This callback handler will be called for each received ASDU. 44 | * The CS101_ASDU object that is passed is only valid in the context 45 | * of the callback function. 46 | * 47 | * \param parameter user provided parameter 48 | * \param address address of the sender (slave/other station) - undefined for CS 104 49 | * \param asdu object representing the received ASDU 50 | * 51 | * \return true if the ASDU has been handled by the callback, false otherwise 52 | */ 53 | typedef bool (*CS101_ASDUReceivedHandler) (void* parameter, int address, CS101_ASDU asdu); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif /* SRC_IEC60870_MASTER_H_ */ 60 | -------------------------------------------------------------------------------- /lib60870-C/src/inc/api/link_layer_parameters.h: -------------------------------------------------------------------------------- 1 | /* 2 | * link_layer_parameters.h 3 | * 4 | * Copyright 2017-2022 Michael Zillgith 5 | * 6 | * This file is part of lib60870-C 7 | * 8 | * lib60870-C is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * lib60870-C is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with lib60870-C. If not, see . 20 | * 21 | * See COPYING file for the complete license text. 22 | */ 23 | 24 | #ifndef SRC_IEC60870_LINK_LAYER_LINK_LAYER_PARAMETERS_H_ 25 | #define SRC_IEC60870_LINK_LAYER_LINK_LAYER_PARAMETERS_H_ 26 | 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | /** 34 | * \file link_layer_parameters.h 35 | * 36 | * \brief Parameters for serial link layers 37 | */ 38 | 39 | /** \brief Parameters for the IEC 60870-5 link layer */ 40 | typedef struct sLinkLayerParameters* LinkLayerParameters; 41 | 42 | struct sLinkLayerParameters { 43 | int addressLength; /** Length of link layer address (1 or 2 byte) */ 44 | int timeoutForAck; /** timeout for link layer ACK in ms */ 45 | int timeoutRepeat; /** timeout for repeated message transmission when no ACK received in ms */ 46 | bool useSingleCharACK; /** use single char ACK for ACK (FC=0) or RESP_NO_USER_DATA (FC=9) */ 47 | int timeoutLinkState; /** interval to repeat request status of link (FC=9) after response timeout */ 48 | }; 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif /* SRC_IEC60870_LINK_LAYER_LINK_LAYER_PARAMETERS_H_ */ 55 | -------------------------------------------------------------------------------- /lib60870-C/src/inc/internal/apl_types_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * apl_types_internal.h 3 | * 4 | * Copyright 2016-2022 Michael Zillgith 5 | * 6 | * This file is part of lib60870-C 7 | * 8 | * lib60870-C is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * lib60870-C is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with lib60870-C. If not, see . 20 | * 21 | * See COPYING file for the complete license text. 22 | */ 23 | 24 | #ifndef SRC_INC_APL_TYPES_INTERNAL_H_ 25 | #define SRC_INC_APL_TYPES_INTERNAL_H_ 26 | 27 | #include 28 | #include 29 | 30 | #include "frame.h" 31 | #include "iec60870_common.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | void 38 | CS101_ASDU_encode(CS101_ASDU self, Frame frame); 39 | 40 | bool 41 | CP16Time2a_getFromBuffer (CP16Time2a self, const uint8_t* msg, int msgSize, int startIndex); 42 | 43 | uint8_t* 44 | CP16Time2a_getEncodedValue(CP16Time2a self); 45 | 46 | bool 47 | CP24Time2a_getFromBuffer (CP24Time2a self, const uint8_t* msg, int msgSize, int startIndex); 48 | 49 | bool 50 | CP32Time2a_getFromBuffer (CP32Time2a self, const uint8_t* msg, int msgSize, int startIndex); 51 | 52 | uint8_t* 53 | CP32Time2a_getEncodedValue(CP32Time2a self); 54 | 55 | bool 56 | CP56Time2a_getFromBuffer (CP56Time2a self, const uint8_t* msg, int msgSize, int startIndex); 57 | 58 | uint8_t* 59 | CP56Time2a_getEncodedValue(CP56Time2a self); 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif /* SRC_INC_APL_TYPES_INTERNAL_H_ */ 66 | -------------------------------------------------------------------------------- /lib60870-C/src/inc/internal/buffer_frame.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2022 Michael Zillgith 3 | * 4 | * This file is part of lib60870-C 5 | * 6 | * lib60870-C is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * lib60870-C is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with lib60870-C. If not, see . 18 | * 19 | * See COPYING file for the complete license text. 20 | */ 21 | 22 | #ifndef SRC_IEC60870_T104_BUFFER_FRAME_H_ 23 | #define SRC_IEC60870_T104_BUFFER_FRAME_H_ 24 | 25 | #include "frame.h" 26 | 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | struct sBufferFrame { 34 | FrameVFT virtualFunctionTable; 35 | 36 | uint8_t* buffer; 37 | int msgSize; 38 | int startSize; 39 | bool isUsed; 40 | }; 41 | 42 | typedef struct sBufferFrame* BufferFrame; 43 | 44 | Frame 45 | BufferFrame_initialize(BufferFrame self, uint8_t* buffer, int startSize); 46 | 47 | void 48 | BufferFrame_destroy(Frame super); 49 | 50 | void 51 | BufferFrame_resetFrame(Frame super); 52 | 53 | void 54 | BufferFrame_setNextByte(Frame super, uint8_t byte); 55 | 56 | void 57 | BufferFrame_appendBytes(Frame super, const uint8_t* bytes, int numberOfBytes); 58 | 59 | int 60 | BufferFrame_getMsgSize(Frame super); 61 | 62 | uint8_t* 63 | BufferFrame_getBuffer(Frame super); 64 | 65 | int 66 | BufferFrame_getSpaceLeft(Frame super); 67 | 68 | bool 69 | BufferFrame_isUsed(BufferFrame self); 70 | 71 | void 72 | BufferFrame_markAsUsed(BufferFrame self); 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif 77 | 78 | #endif /* SRC_IEC60870_T104_BUFFER_FRAME_H_ */ 79 | -------------------------------------------------------------------------------- /lib60870-C/src/inc/internal/cs101_asdu_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016, 2017 MZ Automation GmbH 3 | * 4 | * This file is part of lib60870-C 5 | * 6 | * lib60870-C is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * lib60870-C is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with lib60870-C. If not, see . 18 | * 19 | * See COPYING file for the complete license text. 20 | */ 21 | 22 | 23 | #ifndef SRC_INC_INTERNAL_CS101_ASDU_INTERNAL_H_ 24 | #define SRC_INC_INTERNAL_CS101_ASDU_INTERNAL_H_ 25 | 26 | #include 27 | #include 28 | 29 | #include "iec60870_common.h" 30 | #include "information_objects_internal.h" 31 | #include "apl_types_internal.h" 32 | #include "lib_memory.h" 33 | #include "lib60870_internal.h" 34 | 35 | struct sCS101_ASDU { 36 | CS101_AppLayerParameters parameters; 37 | uint8_t* asdu; 38 | int asduHeaderLength; 39 | uint8_t* payload; 40 | int payloadSize; 41 | }; 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | /** 48 | * \brief Create a new ASDU instance from a buffer containing the raw ASDU message bytes 49 | * 50 | * \param asdu pointer to the statically allocated data structure or NULL to allocate ASDU dynamically 51 | * \param parameters the application layer parameters used to encode the ASDU 52 | * \param msg the buffer containing the raw ASDU message bytes 53 | * \param msgLength the length of the message 54 | * 55 | * \return the created ASDU instance or NULL if the message is invalid 56 | */ 57 | CS101_ASDU 58 | CS101_ASDU_createFromBufferEx(CS101_ASDU asdu, CS101_AppLayerParameters parameters, uint8_t* msg, int msgLength); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif /* SRC_INC_INTERNAL_CS101_ASDU_INTERNAL_H_ */ 65 | -------------------------------------------------------------------------------- /lib60870-C/src/inc/internal/cs101_queue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cs101_queue.h 3 | * 4 | * Copyright 2017 MZ Automation GmbH 5 | * 6 | * This file is part of lib60870-C 7 | * 8 | * lib60870-C is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * lib60870-C is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with lib60870-C. If not, see . 20 | * 21 | * See COPYING file for the complete license text. 22 | */ 23 | 24 | #ifndef SRC_INC_INTERNAL_CS101_QUEUE_H_ 25 | #define SRC_INC_INTERNAL_CS101_QUEUE_H_ 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #if ((CONFIG_USE_THREADS == 1) || (CONFIG_USE_SEMAPHORES == 1)) 32 | #include "hal_thread.h" 33 | #endif 34 | 35 | #ifdef CONFIG_SLAVE_MESSAGE_QUEUE_SIZE 36 | #define CS101_MAX_QUEUE_SIZE CONFIG_SLAVE_MESSAGE_QUEUE_SIZE 37 | #else 38 | #define CS101_MAX_QUEUE_SIZE 10 39 | #endif 40 | 41 | typedef struct sCS101_QueueElement* CS101_QueueElement; 42 | 43 | struct sCS101_QueueElement { 44 | uint8_t size; 45 | uint8_t buffer[256]; 46 | }; 47 | 48 | typedef struct sCS101_Queue* CS101_Queue; 49 | 50 | struct sCS101_Queue { 51 | 52 | int size; 53 | int entryCounter; 54 | int lastMsgIndex; 55 | int firstMsgIndex; 56 | 57 | struct sBufferFrame encodeFrame; 58 | 59 | #if (CS101_MAX_QUEUE_SIZE == -1) 60 | struct sCS101_QueueElement* elements; 61 | #else 62 | struct sCS101_QueueElement elements[CS101_MAX_QUEUE_SIZE]; 63 | #endif 64 | 65 | #if (CONFIG_USE_SEMAPHORES == 1) 66 | Semaphore queueLock; 67 | #endif 68 | }; 69 | 70 | void 71 | CS101_Queue_initialize(CS101_Queue self, int maxQueueSize); 72 | 73 | void 74 | CS101_Queue_dispose(CS101_Queue self); 75 | 76 | void 77 | CS101_Queue_lock(CS101_Queue self); 78 | 79 | void 80 | CS101_Queue_unlock(CS101_Queue self); 81 | 82 | void 83 | CS101_Queue_enqueue(CS101_Queue self, CS101_ASDU asdu); 84 | 85 | /* 86 | * NOTE: Locking has to be done by caller! 87 | */ 88 | Frame 89 | CS101_Queue_dequeue(CS101_Queue self, Frame resultStorage); 90 | 91 | bool 92 | CS101_Queue_isFull(CS101_Queue self); 93 | 94 | bool 95 | CS101_Queue_isEmpty(CS101_Queue self); 96 | 97 | void 98 | CS101_Queue_flush(CS101_Queue self); 99 | 100 | #ifdef __cplusplus 101 | } 102 | #endif 103 | 104 | #endif /* SRC_INC_INTERNAL_CS101_QUEUE_H_ */ 105 | -------------------------------------------------------------------------------- /lib60870-C/src/inc/internal/cs104_frame.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 Michael Zillgith 3 | * 4 | * This file is part of lib60870-C 5 | * 6 | * lib60870-C is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * lib60870-C is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with lib60870-C. If not, see . 18 | * 19 | * See COPYING file for the complete license text. 20 | */ 21 | 22 | #ifndef SRC_INC_T104_FRAME_H_ 23 | #define SRC_INC_T104_FRAME_H_ 24 | 25 | #include 26 | 27 | #include "frame.h" 28 | 29 | typedef struct sT104Frame* T104Frame; 30 | 31 | T104Frame 32 | T104Frame_create(void); 33 | 34 | void 35 | T104Frame_destroy(Frame self); 36 | 37 | void 38 | T104Frame_resetFrame(Frame self); 39 | 40 | void 41 | T104Frame_prepareToSend(T104Frame self, int sendCounter, int receiveCounter); 42 | 43 | void 44 | T104Frame_setNextByte(Frame self, uint8_t byte); 45 | 46 | void 47 | T104Frame_appendBytes(Frame self, const uint8_t* bytes, int numberOfBytes); 48 | 49 | int 50 | T104Frame_getMsgSize(Frame self); 51 | 52 | uint8_t* 53 | T104Frame_getBuffer(Frame self); 54 | 55 | int 56 | T104Frame_getSpaceLeft(Frame self); 57 | 58 | 59 | #endif /* SRC_INC_T104_FRAME_H_ */ 60 | -------------------------------------------------------------------------------- /lib60870-C/src/inc/internal/frame.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 Michael Zillgith 3 | * 4 | * This file is part of lib60870-C 5 | * 6 | * lib60870-C is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * lib60870-C is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with lib60870-C. If not, see . 18 | * 19 | * See COPYING file for the complete license text. 20 | */ 21 | 22 | #ifndef SRC_INC_FRAME_H_ 23 | #define SRC_INC_FRAME_H_ 24 | 25 | #include 26 | 27 | #include "iec60870_common.h" 28 | 29 | typedef struct sFrameVFT* FrameVFT; 30 | 31 | struct sFrameVFT { 32 | void (*destroy)(Frame self); 33 | void (*resetFrame)(Frame self); 34 | void (*setNextByte)(Frame self, uint8_t byte); 35 | void (*appendBytes)(Frame self, const uint8_t* bytes, int numberOfBytes); 36 | int (*getMsgSize)(Frame self); 37 | uint8_t* (*getBuffer)(Frame self); 38 | int (*getSpaceLeft)(Frame self); 39 | }; 40 | 41 | #endif /* SRC_INC_FRAME_H_ */ 42 | -------------------------------------------------------------------------------- /lib60870-C/src/inc/internal/lib60870_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 MZ Automation GmbH 3 | * 4 | * This file is part of lib60870-C 5 | * 6 | * lib60870-C is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * lib60870-C is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with lib60870-C. If not, see . 18 | * 19 | * See COPYING file for the complete license text. 20 | */ 21 | 22 | #ifndef SRC_INC_INTERNAL_LIB60870_INTERNAL_H_ 23 | #define SRC_INC_INTERNAL_LIB60870_INTERNAL_H_ 24 | 25 | #include "lib60870_config.h" 26 | 27 | void 28 | lib60870_debug_print(const char *format, ...); 29 | 30 | #if (CONFIG_DEBUG_OUTPUT == 1) 31 | #define DEBUG_PRINT(...) do{ lib60870_debug_print(__VA_ARGS__ ); } while( false ) 32 | #else 33 | #define DEBUG_PRINT(...) do{ } while ( false ) 34 | #endif 35 | 36 | #define IEC60870_5_104_MAX_ASDU_LENGTH 249 37 | #define IEC60870_5_104_APCI_LENGTH 6 38 | 39 | #define UNUSED_PARAMETER(x) (void)(x) 40 | 41 | #endif /* SRC_INC_INTERNAL_LIB60870_INTERNAL_H_ */ 42 | -------------------------------------------------------------------------------- /lib60870-C/src/inc/internal/link_layer_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * link_layer_private.h 3 | * 4 | * Copyright 2017-2024 Michael Zillgith 5 | * 6 | * This file is part of lib60870-C 7 | * 8 | * lib60870-C is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * lib60870-C is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with lib60870-C. If not, see . 20 | * 21 | * See COPYING file for the complete license text. 22 | */ 23 | 24 | #ifndef SRC_IEC60870_LINK_LAYER_LINK_LAYER_PRIVATE_H_ 25 | #define SRC_IEC60870_LINK_LAYER_LINK_LAYER_PRIVATE_H_ 26 | 27 | 28 | /* primary to secondary function codes */ 29 | #define LL_FC_00_RESET_REMOTE_LINK 0 30 | #define LL_FC_01_RESET_USER_PROCESS 1 31 | #define LL_FC_02_TEST_FUNCTION_FOR_LINK 2 32 | #define LL_FC_03_USER_DATA_CONFIRMED 3 33 | #define LL_FC_04_USER_DATA_NO_REPLY 4 34 | #define LL_FC_07_RESET_FCB 7 35 | #define LL_FC_08_REQUEST_FOR_ACCESS_DEMAND 8 36 | #define LL_FC_09_REQUEST_LINK_STATUS 9 37 | #define LL_FC_10_REQUEST_USER_DATA_CLASS_1 10 38 | #define LL_FC_11_REQUEST_USER_DATA_CLASS_2 11 39 | 40 | /* secondary to primary function codes */ 41 | #define LL_FC_00_ACK 0 42 | #define LL_FC_01_NACK 1 43 | #define LL_FC_08_RESP_USER_DATA 8 44 | #define LL_FC_09_RESP_NACK_NO_DATA 9 45 | #define LL_FC_11_STATUS_OF_LINK_OR_ACCESS_DEMAND 11 46 | #define LL_FC_14_SERVICE_NOT_FUNCTIONING 14 47 | #define LL_FC_15_SERVICE_NOT_IMPLEMENTED 15 48 | 49 | #endif /* SRC_IEC60870_LINK_LAYER_LINK_LAYER_PRIVATE_H_ */ 50 | -------------------------------------------------------------------------------- /lib60870-C/src/inc/internal/platform_endian.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 MZ Automation GmbH 3 | * 4 | * This file is part of lib60870-C 5 | * 6 | * lib60870-C is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * lib60870-C is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with lib60870-C. If not, see . 18 | * 19 | * See COPYING file for the complete license text. 20 | */ 21 | 22 | #ifndef ENDIAN_H_ 23 | #define ENDIAN_H_ 24 | 25 | #include "lib60870_config.h" 26 | 27 | #ifndef PLATFORM_IS_BIGENDIAN 28 | #ifdef __GNUC__ 29 | #ifdef __BYTE_ORDER__ 30 | #if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) 31 | #define PLATFORM_IS_BIGENDIAN 1 32 | #else 33 | #define PLATFORM_IS_BIGENDIAN 0 34 | #endif 35 | 36 | #else 37 | 38 | /* older versions of GCC have __BYTE_ORDER__ not defined! */ 39 | #ifdef __PPC__ 40 | #define PLATFORM_IS_BIGENDIAN 1 41 | #endif 42 | 43 | #ifdef __m68k__ 44 | #define PLATFORM_IS_BIGENDIAN 1 45 | #endif 46 | 47 | #endif /* __BYTE_ORDER__ */ 48 | #endif /* __GNUC__ */ 49 | #endif 50 | 51 | #if (PLATFORM_IS_BIGENDIAN == 1) 52 | # define ORDER_LITTLE_ENDIAN 0 53 | #else 54 | # define ORDER_LITTLE_ENDIAN 1 55 | #endif 56 | 57 | #endif /* ENDIAN_H_ */ 58 | -------------------------------------------------------------------------------- /lib60870-C/src/inc/internal/serial_transceiver_ft_1_2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * serial_transceiver_ft_1_2.h 3 | * 4 | * Copyright 2017 MZ Automation GmbH 5 | * 6 | * This file is part of lib60870-C 7 | * 8 | * lib60870-C is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * lib60870-C is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with lib60870-C. If not, see . 20 | * 21 | * See COPYING file for the complete license text. 22 | */ 23 | 24 | #ifndef SRC_IEC60870_LINK_LAYER_SERIAL_TRANSCEIVER_FT_1_2_H_ 25 | #define SRC_IEC60870_LINK_LAYER_SERIAL_TRANSCEIVER_FT_1_2_H_ 26 | 27 | #include "link_layer_parameters.h" 28 | #include "hal_serial.h" 29 | #include "iec60870_common.h" 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | typedef struct sSerialTransceiverFT12* SerialTransceiverFT12; 36 | 37 | typedef void (*SerialTXMessageHandler) (void* parameter, uint8_t* msg, int msgSize); 38 | 39 | SerialTransceiverFT12 40 | SerialTransceiverFT12_create(SerialPort serialPort, LinkLayerParameters linkLayerParameters); 41 | 42 | void 43 | SerialTransceiverFT12_destroy(SerialTransceiverFT12 self); 44 | 45 | void 46 | SerialTransceiverFT12_setTimeouts(SerialTransceiverFT12 self, int messageTimeout, int characterTimeout); 47 | 48 | void 49 | SerialTransceiverFT12_setRawMessageHandler(SerialTransceiverFT12 self, IEC60870_RawMessageHandler handler, void* parameter); 50 | 51 | int 52 | SerialTransceiverFT12_getBaudRate(SerialTransceiverFT12 self); 53 | 54 | void 55 | SerialTransceiverFT12_sendMessage(SerialTransceiverFT12 self, uint8_t* msg, int msgSize); 56 | 57 | void 58 | SerialTransceiverFT12_readNextMessage(SerialTransceiverFT12 self, uint8_t* buffer, 59 | SerialTXMessageHandler, void* parameter); 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif /* SRC_IEC60870_LINK_LAYER_SERIAL_TRANSCEIVER_FT_1_2_H_ */ 66 | 67 | 68 | -------------------------------------------------------------------------------- /lib60870-C/src/lib60870.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=@CMAKE_INSTALL_PREFIX@/bin 3 | libdir=@CMAKE_INSTALL_PREFIX@/lib 4 | sharedlibdir=@CMAKE_INSTALL_PREFIX@/lib 5 | includedir=@CMAKE_INSTALL_PREFIX@/include 6 | 7 | Name: @PROJECT_NAME@ 8 | Description: @CPACK_PACKAGE_DESCRIPTION@ 9 | Version: @LIB_VERSION_MAJOR@.@LIB_VERSION_MINOR@.@LIB_VERSION_PATCH@ 10 | 11 | Requires: 12 | Libs: -L${libdir} -L${sharedlibdir} -llib60870 13 | Cflags: -I${includedir} -------------------------------------------------------------------------------- /lib60870-C/src/version.rc.in: -------------------------------------------------------------------------------- 1 | 1 VERSIONINFO 2 | FILEVERSION @LIB_VERSION_MAJOR@,@LIB_VERSION_MINOR@,@LIB_VERSION_PATCH@,0 3 | PRODUCTVERSION @LIB_VERSION_MAJOR@,@LIB_VERSION_MINOR@,@LIB_VERSION_PATCH@,0 4 | BEGIN 5 | BLOCK "StringFileInfo" 6 | BEGIN 7 | BLOCK "040904E4" 8 | BEGIN 9 | VALUE "FileVersion", "@LIB_VERSION_MAJOR@.@LIB_VERSION_MINOR@.@LIB_VERSION_PATCH@.0" 10 | VALUE "ProductVersion", "@LIB_VERSION_MAJOR@.@LIB_VERSION_MINOR@.@LIB_VERSION_PATCH@.0" 11 | VALUE "ProductName", "libIEC61850" 12 | VALUE "FileDescription", "lib60870 - library for IEC 60870-5-104" 13 | VALUE "LegalCopyright", "Dual license : Commercial or GPLv3" 14 | END 15 | END 16 | BLOCK "VarFileInfo" 17 | BEGIN 18 | VALUE "Translation", 0x400, 1252 19 | END 20 | END 21 | -------------------------------------------------------------------------------- /lib60870-C/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | ./unity 3 | ) 4 | 5 | set(tests_SRCS 6 | all_tests.c 7 | unity/unity.c 8 | ) 9 | 10 | IF(WIN32) 11 | set_source_files_properties(${tests_SRCS} 12 | PROPERTIES LANGUAGE CXX) 13 | ENDIF(WIN32) 14 | 15 | configure_file(server-key.pem server-key.pem COPYONLY) 16 | configure_file(client1-key.pem client1-key.pem COPYONLY) 17 | configure_file(client1.cer client1.cer COPYONLY) 18 | configure_file(client2.cer client2.cer COPYONLY) 19 | configure_file(root.cer root.cer COPYONLY) 20 | configure_file(server.cer server.cer COPYONLY) 21 | 22 | configure_file(certs/server_CA1_1.key server_CA1_1.key COPYONLY) 23 | configure_file(certs/server_CA1_1.pem server_CA1_1.pem COPYONLY) 24 | configure_file(certs/root_CA1.pem root_CA1.pem COPYONLY) 25 | 26 | configure_file(certs/client_CA1_1.key client_CA1_1.key COPYONLY) 27 | configure_file(certs/client_CA1_1.pem client_CA1_1.pem COPYONLY) 28 | 29 | configure_file(certs/client_CA1_2.key client_CA1_2.key COPYONLY) 30 | configure_file(certs/client_CA1_2.pem client_CA1_2.pem COPYONLY) 31 | 32 | configure_file(certs/client_CA1_3.key client_CA1_3.key COPYONLY) 33 | configure_file(certs/client_CA1_3.pem client_CA1_3.pem COPYONLY) 34 | 35 | configure_file(certs/client_CA1_4.key client_CA1_4.key COPYONLY) 36 | configure_file(certs/client_CA1_4.pem client_CA1_4.pem COPYONLY) 37 | 38 | configure_file(certs/server_CA1_1_chain.pem server_CA1_1_chain.pem) 39 | 40 | configure_file(certs/test.crl test.crl COPYONLY) 41 | 42 | add_executable(tests 43 | ${tests_SRCS} 44 | ) 45 | 46 | target_link_libraries(tests 47 | lib60870 48 | ) 49 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/README.md: -------------------------------------------------------------------------------- 1 | This folder include test certificates for TLS related tests 2 | 3 | * Three different root CAs 4 | ** root_CA1 5 | ** root_CA2 6 | ** root_CA3 7 | 8 | * For each root CAs there are two clients and two server keys/certificates 9 | ** server_CA1_1 10 | ** server_CA1_2 11 | ** client_CA1_1 12 | ** client_CA1_2 13 | ** server_CA2_1 14 | ** server_CA2_2 15 | ** client_CA2_1 16 | ** client_CA2_2 17 | ** server_CA3_1 18 | ** server_CA3_2 19 | ** client_CA3_1 20 | ** client_CA3_2 21 | 22 | 23 | Example: Generate root CA keys and certificates: 24 | 25 | openssl genrsa -out root_CA1.key 2048 26 | openssl req -x509 -new -nodes -key root_CA1.key -sha256 -days 3650 -out root_CA1.pem 27 | 28 | Example: Create endpoint (client/server) certificates: 29 | 30 | openssl genrsa -out server_CA1_2.key 2048 31 | 32 | openssl req -new -key server_CA1_1.key -out server_CA1_1.csr 33 | 34 | openssl x509 -req -in server_CA1_1.csr -CA root_CA1.pem -CAkey root_CA1.key -CAcreateserial -out server_CA1_1.pem 35 | 36 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/client_CA1_1.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpQIBAAKCAQEA2PuXMNUYO43NbEvBmEAru/uL1JdU6gFuhMKLuZOPaOGjGhth 3 | JiDO9AsnUGzKAk3m9QZ/YhAzY9CiEeYsnGaPeI0OBdkgWmpz5k9Fw+bqaqlxYQTy 4 | Bw69/kYbwNyMmGsb8XqXKZvhPXdLoaxkVmS+AMlxVcN/7c2ldZGTTDrhBtJnfuPK 5 | rGmH9cFg+XVvUskPQsUIwJtn1sN+niZ++hkuiCzmoZ4A+m73QACltdcr7aNtHJmh 6 | aU/p1bmLIhYfbxGmyvm2faJ8htYuaRBj6DcZq44IyDGz2LThmdWzpIcYbovCzB2X 7 | Pn26b0BXsXBpN+ptf2xpAEDWDdzaR6Xp4BgJwQIDAQABAoIBAQDQGLJOlgBQlVWv 8 | CBSaNOj8t2nKsHwylL7uujoQ95DxUH0BO8L3Mz3n1Y6V1lAC172pvtqKLOlsUBov 9 | OmYMdVwhjH4nY65gqHmRJvPMxviI5Qqktn58AEp8w7Y4SAza3NaGyECTGjlxnqi9 10 | XD06khGbZZa5Xu6hHboSwFPZJxrLU1jaopJUgFG+p9oUgiSp5cfGDwAsU9JELmkP 11 | MVF0GWedpypBBKi9JsniOulr1USpNZN2rzEkkxwY0QQttw3E9dgheIsut7dUYWLz 12 | 9NLKcRWIK/Y29NzS6Urye8lUTHHBrXgk5pUcdN3vuY7mkleqIn5tYY6xf93/5/VA 13 | jF+HcgolAoGBAPDhS986xppbfLmrresIUUZKxk2s/Vg+vHPLX0SJFF7Uhy8nMYoJ 14 | JqfG2mS+/tiM/wPBglVhsrlsfnDIag7Brqx7sjH2OHO6VX8jQPYgOuCbNwp7uL1w 15 | bG82R5rujcxxFAtMVAM3zYz9sNGSu8u7M/U3kfTBwtntFJ6iPC60REbjAoGBAOaa 16 | SdtX0bOQAYDM4moEDVnRPMHp8lZAjqKphGqTDrGOqU4usNW8+ZNBhn3vF1+n2Gq5 17 | KY2IWSF0j71jqpOXahW0EBoXpcTLs5JBWet8J5vKzbpN8Uq8TvTABn67G1F/DZub 18 | FOiCDy/Kku4yWT2aUqNwS07va7gzFhyyjMl/JWoLAoGAATpEtriH9pVsx012r3H1 19 | aBRNemvdRqvbLgPlUmYYcntGzRi4CeoOBmDfEBBhIB1n108PKPw8evFwm4aJ89VM 20 | 3JgsylBk7UIP2XwGgrqbUjW4TBdhU6XVB6QRLVr14grZfU1ASFvqckOAuTC0QE+N 21 | 7jwARG0QXyf0KPLOt7Y3et0CgYEAhJcd9EJQTsB0PMyROofN7WDDYHPVZQaFfL2f 22 | Z2/auPjgHBX4k0yu6553aB17AQMPCn4giEJnjTbqFukhgO9EjeoUgAwswjSlsWhl 23 | /WJLm+ZF1+NM473WYB+xHFkU4gz9lATdRrrRZJdDWDYW3bbH4TWF94LuGuE0y5dW 24 | H909c/UCgYEAiYY/TTZvfEsQvCo4Rv6qg7cI2/OdGwGhMmtziYy4SIAAm0Ga2s3R 25 | L7Kq72In+nbaDIUD2zTSGQmwTm3B0C73vIUAXvupcl28nE5px0YNV6NZJaaFSV66 26 | hP1CgPBYe6KjnVufOiqhcnDdJQ6XdqK0tblj+cavkZgW+UdeqVBXCFQ= 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/client_CA1_1.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDWzCCAkMCFFTJkICEIidmnrisIFxZ99KKLhDFMA0GCSqGSIb3DQEBCwUAMGox 3 | CzAJBgNVBAYTAkRFMQswCQYDVQQIDAJCVzERMA8GA1UEBwwIRnJlaWJ1cmcxGzAZ 4 | BgNVBAoMEk1aIEF1dG9tYXRpb24gR21iSDEMMAoGA1UECwwDUiZEMRAwDgYDVQQD 5 | DAdyb290X0NBMB4XDTIyMDMxODA5MzMxOFoXDTIyMDQxNzA5MzMxOFowajELMAkG 6 | A1UEBhMCREUxCzAJBgNVBAgMAkJXMREwDwYDVQQHDAhGcmVpYnVyZzEbMBkGA1UE 7 | CgwSTVogQXV0b21hdGlvbiBHbWJIMQwwCgYDVQQLDANSJkQxEDAOBgNVBAMMB2Ns 8 | aWVudDEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDY+5cw1Rg7jc1s 9 | S8GYQCu7+4vUl1TqAW6Ewou5k49o4aMaG2EmIM70CydQbMoCTeb1Bn9iEDNj0KIR 10 | 5iycZo94jQ4F2SBaanPmT0XD5upqqXFhBPIHDr3+RhvA3IyYaxvxepcpm+E9d0uh 11 | rGRWZL4AyXFVw3/tzaV1kZNMOuEG0md+48qsaYf1wWD5dW9SyQ9CxQjAm2fWw36e 12 | Jn76GS6ILOahngD6bvdAAKW11yvto20cmaFpT+nVuYsiFh9vEabK+bZ9onyG1i5p 13 | EGPoNxmrjgjIMbPYtOGZ1bOkhxhui8LMHZc+fbpvQFexcGk36m1/bGkAQNYN3NpH 14 | pengGAnBAgMBAAEwDQYJKoZIhvcNAQELBQADggEBADSnrKdPqeUr3F1MIk6P8SKo 15 | yR1VrPmNCljaC1i3realDlG+7jlPHfTCkwZwlEfKGa/yANJAw4hv+2tR5m4CsgMB 16 | x6FkKG9p6NTXyv4gXZeLa3ivqFqz7awTVMBf1C1VVeTi/H2kvHSBRmbj6Z5p7/MN 17 | 9E1t5NsgbKKfbj4hQD+f7r6zgFdgTK8C5OYT2ijYryFl1Qqrl5CYPpswm3vL0KkM 18 | e3RMOBqamkFqr4OCZw5juNpGrp3bK3dLF+N6Ceb+PGnS0YU29NpUXo64lzIxdwxs 19 | NDqbFMYXEXGKqUDVQAuj1374M85Cvqlso0Jenc+hWN2/kfAgHGE1Ne3sD9oJg5w= 20 | -----END CERTIFICATE----- 21 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/client_CA1_2.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpQIBAAKCAQEAvIZ3f7Hf5yyazcH3ouZaYYEu9X6T+eu8YJKxmhMtP5ciEnrm 3 | CvJ5KxyN0+XM9CB7FURmotHED3az+dFXZ+5I9qzP1sw+0c0kWSAcnXeLZwmQc/25 4 | LU0bWDVb3u/h2j/beBcUHZDBeCtyZhP4/4GEmIpkePQxY1yNqJvZF1meqXUFMmil 5 | K/s8YJqL7UI7XO8HU3SprChUMUEIXc1kGoxKWjUy/iUycqwmXLa8miC4GL+HL0G6 6 | ReeM23EbHaD0ZD+ms7EfRg4QmMncM1BjK9gmdguAUcAfAobMA7FOosMOXpxdr1iF 7 | GN+lb45kgw67B9cOFfVApEo2DINFUDJsHPJHqwIDAQABAoIBAQC2JdVfcyS53sbS 8 | 9g2lPpskigQs/VdLqRAg3prqGo0lW4h4AnYxLYUUuknt6aHUXW2OZsAjoDimGDJb 9 | tH+W0wt8CgvlpQEtA9+SnQwIuG/f5cXDy+kWc+FvoF5bT7oPfJM3vFSbHDlROekV 10 | 50Y015adK1lX49e0AMB9n9ZoURaS8ev3Hcvf0ExcKObBK9jM61RdTxDyfHF5Ae5m 11 | ZvWaplTtTxGh7r8Onv0OLkcu25dGa2dqcktWnE6nSQ8pIxIbuSrm6fqwqtMUSULP 12 | /9Nng6JzAl+Wxe009br0uTH6a8yRElx95nhiseQnrpO/skj17tLrgskZWGjW2PsN 13 | CTo5tIeBAoGBAOmzpMqwTLbAK35AKRToXO/iqp1o8iqlyLcFMC5c4hsqRM03Y4qy 14 | 0c2WK/TEnnfwIrD/A+XRC7IdUis7qnSDr2EXlxkdJnmtR+5/6vialxFFRTC8Myes 15 | YhduUB8Sn6XFhWmRtLPZNz9QPK0Z3qDVwi95kLyEfAQ07xUIM62QXkEzAoGBAM6D 16 | WclZxMo1pWlMHxfuEa6cuvuZav7tGgnVPq+CGq1goedflCTM9cJjluNF5Eqxzbd4 17 | fYYE+8no0M0Sb99DdQtLOQj+zaKAqK4LGfokvsMj4eO2pfOjPSANMjIag3DkAHwO 18 | Gl0hV7TGlusBiNF8eQjPV9niBeGykgOO172p+8+pAoGAEEZmb4cfkIqJfN1S/xW/ 19 | gyUx5IxucPHirHw8Ar6NMH8dE32L/Ri+66ZNoVof/xJGGDVqPBL20YyhMEmTcVHK 20 | YOSXrTQOfeLHY6Cc6Hs7kgRU8TPqDBVBL4iLI97UJ2M+C0AOaYfzBQG9eACZNHIu 21 | d8frgHVpfZGCJODRWID5T2kCgYEAnoGW4sLyFrqCUYXJv9ZM4BcQNZkV1MEr4Sw5 22 | xwA3dafb3PkxfeWLJD7IS30TsnkyioYC4mDk2Z7G1QA3ucfPCHIePtdEAlx6G8wN 23 | jj+x45mhAeTpD03V1soKIwbSqE14Sb+RYLX82ZYrtAkjeJbvV2G97lBbb1ZeWDjF 24 | QqA71LECgYEA2kEhWou5i6TrACFAvGmJPaekBYRRIC6vjxKvsDT0fc1sKz0QKP96 25 | OTYK9eteSn25KsfHb1UlgsSa8Dh+sBkQU9R0KBrbZPHyDXodjdI45AKrSrWsz1UI 26 | rZBrspjN7m7wXrGdM437E1AkAcWy81fN+829AmL6WrT2Oe6Wq+wqKBw= 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/client_CA1_2.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDWzCCAkMCFFTJkICEIidmnrisIFxZ99KKLhDGMA0GCSqGSIb3DQEBCwUAMGox 3 | CzAJBgNVBAYTAkRFMQswCQYDVQQIDAJCVzERMA8GA1UEBwwIRnJlaWJ1cmcxGzAZ 4 | BgNVBAoMEk1aIEF1dG9tYXRpb24gR21iSDEMMAoGA1UECwwDUiZEMRAwDgYDVQQD 5 | DAdyb290X0NBMB4XDTIyMDMxODA5MzY0OVoXDTIyMDQxNzA5MzY0OVowajELMAkG 6 | A1UEBhMCREUxCzAJBgNVBAgMAkJXMREwDwYDVQQHDAhGcmVpYnVyZzEbMBkGA1UE 7 | CgwSTVogQXV0b21hdGlvbiBHbWJIMQwwCgYDVQQLDANSJkQxEDAOBgNVBAMMB2Ns 8 | aWVudDIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC8hnd/sd/nLJrN 9 | wfei5lphgS71fpP567xgkrGaEy0/lyISeuYK8nkrHI3T5cz0IHsVRGai0cQPdrP5 10 | 0Vdn7kj2rM/WzD7RzSRZIBydd4tnCZBz/bktTRtYNVve7+HaP9t4FxQdkMF4K3Jm 11 | E/j/gYSYimR49DFjXI2om9kXWZ6pdQUyaKUr+zxgmovtQjtc7wdTdKmsKFQxQQhd 12 | zWQajEpaNTL+JTJyrCZctryaILgYv4cvQbpF54zbcRsdoPRkP6azsR9GDhCYydwz 13 | UGMr2CZ2C4BRwB8ChswDsU6iww5enF2vWIUY36VvjmSDDrsH1w4V9UCkSjYMg0VQ 14 | Mmwc8kerAgMBAAEwDQYJKoZIhvcNAQELBQADggEBALYG8KSPm82uvgmeto76kL+N 15 | nUgV1ojxj+X9yBrbrkgo4rnsXFU1NUqncdCfpvA7u9mqAjZ4KN+ORZIUp1SXUl3Z 16 | TIpBClO5ML7wz1Iy6QrExeFwb2783Gl1jeq0lSQwWffNMwkPEqG1QYr/2IK9eSRJ 17 | hDrure/Ys3s5F7grQ6vTWBQrEXynd81YqqZuBFFs7FuLhg0GK/OdpJ5i2BsLS+B3 18 | nEOxmgxZ1qLSqbYDjhawsjiSItvO8XxZjA99n3MpBVharqqwp0Xpkm+X30rWolUp 19 | wur154X0dMZh8jF98KVrB/3Te9aidtyuO9EiGU2Qbkre7jK+Ol3nITR50Gy8yYU= 20 | -----END CERTIFICATE----- 21 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/client_CA1_3.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEogIBAAKCAQEA3XP+DAhoJt12nyYcRfweABS1+kINdIMwf2AW0g5qxHvvAKTi 3 | hfbKtU3USllRPcjPtX/4BcGZZYMLIXW4MU9Gt8Le6zJRrbAazgnZUXg31vrAX6sL 4 | IQY5GwTmWu4yGu2AUoYB2A8W7DXwUpBG9c9z5+Wt8Vi1neKpEZY2zCnHPn9Qh+0s 5 | KpH/juhE+LDmeeNSEqfie87STlDg936VPxUxXBSyXEu6QMrynEYiDbrjsvJsZKuY 6 | VJbJLCDw70RwcS14tcD2xiqMLwp66wSkC+7aVuugQ15VmkGgvgf+vmCQGzMTj4vY 7 | RVrXcDBUdPkR88iSwmZWWKI4n5YvlmkEclJDnQIDAQABAoIBAB3QOth13Ue2Mv0U 8 | DWRin8tU/nbVo6gW7VWIoyneZQNUyAVnLVPpuLqV4smroqNVwJjnxIVJ3hPrg3ka 9 | txR0Xsnog0hYuuROPB2W99ne/G2FzpZSman1g4SesUB2puo3JTp27hKfXW+ph1Qm 10 | NldreWgz5KoETlcWJ7rFZVUxHrDMBPaZyIww4iK9BoF7TX1gnXeEhxHYGUwJaeYj 11 | IrPTIcscGnKVALlTSgzxgytiW1ZU717BEyptubqA5P8mitErIZXAcxx+Ek40u2AA 12 | vuO+UMi/t/ppGvhaqifhJbeTzAQ+H/pTkTTaTrSALPPr/7s91/UBpqiN6w346aVI 13 | 8gpphgECgYEA8YESS4IYiBwTBQniEhzD6ojj5ENpIivoxLD9BjygcLtL91iDhlko 14 | 0u9jdmlBk8UMnSj96OphyKV12Qlo1DRqPC0zN2uip6NYLJy9vrss/LI13UnXHFP/ 15 | nKuMdo9fO3hCSFHpcU5/OuiwAx5IXVXJnUGG6nmeRgXU+0sRY3FzWB0CgYEA6r7R 16 | YqV5MivqXZm9xP67zNrc5mNdGHCNe9XIEeXSr3GyFSUMnIYOIs1dsO0cwyDPrf2p 17 | C41Y8nniNR1gh3/9+Fn0WUfAtctawCO8whO0IFjhB/CW0qKB5G4TCAgydwSoxagi 18 | Bihmk9SRmPlZpDAKh75lZMkXoZf8WRvT1T/JwYECgYBwKvm7Vl5cgWWYFoII1ZFt 19 | Uk0+jMy80VYYXPf4OJpwIZ3j8RmNgcXDSuqQaczKfGAicpKT5qCqF6eHuaYVwY6C 20 | CqBaIkT2xZhDiD1c5AS+DWuVLyGZB66WLttbibW6ol1ux5S8SrAvRTnTCPKlXx34 21 | SyIFr50Cetz0JmaaIGxpRQKBgHy3osE5TxnD0UGng/ZcrGRbR4+z7OsmKVVIsIIp 22 | y3ThAA9R3tBuPKZq28M7RtO44/35zc1QbJhu/yrfD8EN1F4VVMf2YkFz6CQ7GHc4 23 | RrQE5JH2VftU0ZQOk1fqGv224QAaovEIl+8kubI/kEu2JnIWSwJwAHkfKbgiG7qp 24 | qESBAoGAC/vRxjHXnU8KOvQ6f70gM6QpXJiABK475JTaspPWJvd9hCy114kEC8Yk 25 | 7TUJ7802D0tzkkbnq5TYGwWxFBiCMdeH+BrynwSrwgdiS/fVGiwYjzMlZEs5LCOD 26 | c0tt0S2GLcYbQFUAsCusw9Vir3Szn5HpX7HvIP51nWOk8bbXA5o= 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/client_CA1_3.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDWzCCAkMCFFTJkICEIidmnrisIFxZ99KKLhDJMA0GCSqGSIb3DQEBCwUAMGox 3 | CzAJBgNVBAYTAkRFMQswCQYDVQQIDAJCVzERMA8GA1UEBwwIRnJlaWJ1cmcxGzAZ 4 | BgNVBAoMEk1aIEF1dG9tYXRpb24gR21iSDEMMAoGA1UECwwDUiZEMRAwDgYDVQQD 5 | DAdyb290X0NBMB4XDTIyMDUyNjEwNDk1NFoXDTMwMDgxMjEwNDk1NFowajELMAkG 6 | A1UEBhMCREUxCzAJBgNVBAgMAkJXMREwDwYDVQQHDAhGcmVpYnVyZzEbMBkGA1UE 7 | CgwSTVogQXV0b21hdGlvbiBHbWJIMQwwCgYDVQQLDANSJkQxEDAOBgNVBAMMB2Ns 8 | aWVudDMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDdc/4MCGgm3Xaf 9 | JhxF/B4AFLX6Qg10gzB/YBbSDmrEe+8ApOKF9sq1TdRKWVE9yM+1f/gFwZllgwsh 10 | dbgxT0a3wt7rMlGtsBrOCdlReDfW+sBfqwshBjkbBOZa7jIa7YBShgHYDxbsNfBS 11 | kEb1z3Pn5a3xWLWd4qkRljbMKcc+f1CH7Swqkf+O6ET4sOZ541ISp+J7ztJOUOD3 12 | fpU/FTFcFLJcS7pAyvKcRiINuuOy8mxkq5hUlsksIPDvRHBxLXi1wPbGKowvCnrr 13 | BKQL7tpW66BDXlWaQaC+B/6+YJAbMxOPi9hFWtdwMFR0+RHzyJLCZlZYojifli+W 14 | aQRyUkOdAgMBAAEwDQYJKoZIhvcNAQELBQADggEBACiLTRiylV63ZoMWmUewYksr 15 | PIMqW7HWgBLdO6O+56grF2Sux1Z3LEJjRrLBzI8w9nIWKlnhszl0KF8EKHDPf3j7 16 | MB8LpW5iOSSevW8dXV9Dfgfkp8ZiOkBTpsid7/v60xsnxRt0Qhydfkpjt5ze/GRU 17 | rr4867VIOK3UYC0f8tjf3hCfMjwSEhE42yl5MWW06SirmVe32vDxUw0Nel5bB/sx 18 | BxnK8bjIfgbI0iW6XU73+8+ajSsoU3rSNXpB/1lViruzNsH9DDF/QFcQWIjE90By 19 | PTy3i/+lYsHQYaNP1Tfr0cbkZDYjOKYsb9plxzZVrTlQhLyvS1oUBRGolQ6JG9U= 20 | -----END CERTIFICATE----- 21 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/client_CA1_4.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpAIBAAKCAQEAvDPZNjU3CYNYiyG/JfM2+lpv5bbVau9ZZuC/lUbDUfb9a0jS 3 | RJzA+ZZq9VkIgUL+WirzqIuUD3MJ+yabrBkG1bSXUUMPIefCnYVuD8j0FjFrbJws 4 | McbepHDBrjKu7dQcNefN5F/cSEdUWtx1RXsMSoGQkJwaJaqfAhpgFSRO/HVS4eUh 5 | E++jvkhV3997JkfXvfRffA/Ww9PQ1et4MYk3yugYc0Uasi+wehK1jDFcINn1kvWo 6 | YRGgvM39JjveCUAGPesUezhch4UIE8X3R18xWQ67xqXU6HVfj9K8zgGl95mzO5LU 7 | x2qJ82HwG/75NntVQCgqP+4o59muNf+PDTbbLwIDAQABAoIBAQCDUeZRZcZWc/i3 8 | dD+tWkzVWX9UmUPHTuVh3JaxsWOecKoZTwGw8HPSc7uEILDHiRhzkB7eTy5rrUic 9 | ny7mYbwcJ9uhzxni/ZUVVsIab4ypY6hia4KG5Q37TdZHF4Rp3KQmlO1cWesZ3/Oj 10 | RsrpRVepMUjPLq0r9SboT8EVX3Vhv8VQsioN+BRLcX/de5sknD1n1hZ7SP9zJVe1 11 | iNJLxIeJ/+H2twIyS+AYjq82lWNcLu+zOmMufMTu85agjPotY9rfzwNva1pNCJbw 12 | bTEzK6YwfYgxQ6uu7d5RXKg+oRxf9K6yyXpvh1K6rrOcTQnHxSIlvXvwjhgRvlRp 13 | VE7UDHXZAoGBAN6mSZlmXt7VClzSF25HRhcyP/Z0P37tpgUX4euSDTGNancMTeND 14 | bZiywgwV1RorVRMKNydEyfokyT3x8MUzdnxvVIehSlMZK0z8LEKGwRHhYV7RUDHx 15 | pmWaUEsd6KFaiYY47Hz6JKudPXOErADhM5vb5knSQakF/nnQca5RCFx7AoGBANhk 16 | qAyIn0uHLfoiZw7YmEJ1AzEi0ozfh29d/dx47j+QErA0wt5HllGBOKWgRr0N/LWa 17 | IyQO0+OMbtXJYCXTk2b6FMQMDqoqE1P6mG0ZWwVZ4pkhAFCSck7cKTpR8ftU0t80 18 | NxmVXAZUejofqiIvszAKYVzb/eH1PwZ4kqb5+n/dAoGABiORnfArp3s6SOrmCH1g 19 | ml0hVFtKMOa+kB9jdEpXoMkkaVnmf+CpEe/D1+92K72MH/VFJgkIhKQlBFc6a0WK 20 | +81aCE9TLE1iW0IMulzaz/Jl6+ZbjrT6AI0rr5aIhoJnjlLdemivQCgavKeo0nFj 21 | KeX7SIfKla17ocI0kDjdwScCgYEAsaEmxWsc/93OYwb8fBZWHi95WEtSdKtEvKl2 22 | KxXl1K2KebRFxjsTbIJborHHf4dMyzHk6MN3MdHkZX+xejuMQzrD8w5Gt25kgUoy 23 | 91OaAPGA7dxGKt2cEZnuCd6ceYhutSRimpCdguCzmKTHftqTB7ttotE/Pc2YV9J/ 24 | 56tJ8s0CgYB0/u1rIF4wlTOGqv1ndLOvffmj0RUEEYAE9Gsf9ktavn6pFXAgHjVI 25 | Bz0fuAKSRUFTEVRwzNikT+xiK8YXVv23izZvxIdFDSSCHmcjgHOMqX5TPi3D7zpA 26 | OIk4gUbqNKL0CYgmVZBJUbsG4pARLy7VxidKmmtmkibB7ZOP22QYRQ== 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/client_CA1_4.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDWzCCAkMCFFTJkICEIidmnrisIFxZ99KKLhDKMA0GCSqGSIb3DQEBCwUAMGox 3 | CzAJBgNVBAYTAkRFMQswCQYDVQQIDAJCVzERMA8GA1UEBwwIRnJlaWJ1cmcxGzAZ 4 | BgNVBAoMEk1aIEF1dG9tYXRpb24gR21iSDEMMAoGA1UECwwDUiZEMRAwDgYDVQQD 5 | DAdyb290X0NBMB4XDTIyMDUyNjEwNTEyM1oXDTMwMDgxMjEwNTEyM1owajELMAkG 6 | A1UEBhMCREUxCzAJBgNVBAgMAkJXMREwDwYDVQQHDAhGcmVpYnVyZzEbMBkGA1UE 7 | CgwSTVogQXV0b21hdGlvbiBHbWJIMQwwCgYDVQQLDANSJkQxEDAOBgNVBAMMB2Ns 8 | aWVudDQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC8M9k2NTcJg1iL 9 | Ib8l8zb6Wm/lttVq71lm4L+VRsNR9v1rSNJEnMD5lmr1WQiBQv5aKvOoi5QPcwn7 10 | JpusGQbVtJdRQw8h58KdhW4PyPQWMWtsnCwxxt6kcMGuMq7t1Bw1583kX9xIR1Ra 11 | 3HVFewxKgZCQnBolqp8CGmAVJE78dVLh5SET76O+SFXf33smR9e99F98D9bD09DV 12 | 63gxiTfK6BhzRRqyL7B6ErWMMVwg2fWS9ahhEaC8zf0mO94JQAY96xR7OFyHhQgT 13 | xfdHXzFZDrvGpdTodV+P0rzOAaX3mbM7ktTHaonzYfAb/vk2e1VAKCo/7ijn2a41 14 | /48NNtsvAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAJW47knBIi501FllKalScSs8 15 | dCHMfELWi2b+sfb06VH/UXTUA8u3mYFQWDsJbcbQH1CbOa/kgEqWNlej0NwVLhg5 16 | Ge9jTNu0WSLz3equ0BVkZpYiyqjH+oUgAs6Vr4D6VBew+D00Kt906qT4i4Z6d/rl 17 | LqxszgNLMWZUXu8R5T47GWiV4W/HdBgHUwEmBH05nBus/JFE0REJXi3KbiKUTeTe 18 | IXEnb3nVax8cur4sBFTT9/AztEE54rIx+s/d6oNStQuBJUb8OIOo6YHHbCfIT2hm 19 | sPNAjjDjZHvOuLiFD2DByHMIYlioDfUbnUTv5z6vqB5qf9wcuaKizzQI0QiQYZ8= 20 | -----END CERTIFICATE----- 21 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/crl_number: -------------------------------------------------------------------------------- 1 | 03 2 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/crl_number.old: -------------------------------------------------------------------------------- 1 | 02 2 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/crl_openssl.conf: -------------------------------------------------------------------------------- 1 | # OpenSSL configuration for CRL generation 2 | # 3 | #################################################################### 4 | [ ca ] 5 | default_ca= CA_default# The default ca section 6 | 7 | #################################################################### 8 | [ CA_default ] 9 | database = index.txt 10 | crlnumber = crl_number 11 | 12 | 13 | default_days= 365# how long to certify for 14 | default_crl_days= 30# how long before next CRL 15 | default_md= default# use public key default MD 16 | preserve= no# keep passed DN ordering 17 | 18 | #################################################################### 19 | [ crl_ext ] 20 | # CRL extensions. 21 | # Only issuerAltName and authorityKeyIdentifier make any sense in a CRL. 22 | # issuerAltName=issuer:copy 23 | authorityKeyIdentifier=keyid:always,issuer:always 24 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/index.txt: -------------------------------------------------------------------------------- 1 | R 220417093649Z 220526085045Z 54C99080842227669EB8AC205C59F7D28A2E10C6 unknown /C=DE/ST=BW/L=Freiburg/O=MZ Automation GmbH/OU=R&D/CN=client2 2 | R 300812104954Z 220526105546Z 54C99080842227669EB8AC205C59F7D28A2E10C9 unknown /C=DE/ST=BW/L=Freiburg/O=MZ Automation GmbH/OU=R&D/CN=client3 3 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/index.txt.attr: -------------------------------------------------------------------------------- 1 | unique_subject = yes 2 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/index.txt.attr.old: -------------------------------------------------------------------------------- 1 | unique_subject = yes 2 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/index.txt.old: -------------------------------------------------------------------------------- 1 | R 220417093649Z 220526085045Z 54C99080842227669EB8AC205C59F7D28A2E10C6 unknown /C=DE/ST=BW/L=Freiburg/O=MZ Automation GmbH/OU=R&D/CN=client2 2 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/root_CA1.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpAIBAAKCAQEA4zJoNpP5rgNPSzY0KuNQ3xygs98WstF03QbHSFFWK4tQXF3T 3 | TWNeu5GBcq3aDyVH5ifNR4A9Adtwh9FCEv6PL9kxembPg2uXu/I5YV27ycEpTpzv 4 | L0uZIZuc4lmMNfCVfoRHC6KoXMC9EDphds83yBjQHc675P+aORY30vXH5X7tsaz2 5 | tUigzvx9XIzYUREF+wG1PvpBVC/cpn5r0Q4vGpxn+caqwUXKwU5KSJELoLLiYLkJ 6 | KKT1LkPtf2XP9t2Brs76Gp1Ip+KvpgyVAZXfsk+qbPr03q+9v1Q5f8b3z1Pip1UH 7 | /NA68x1whZeSpve9IBdiL9wKVVLU/KazL8xdDQIDAQABAoIBAQCie+xYDCAmuSs+ 8 | aPeKLKQrzHeJ7GR5Yp8na6+eIr1zyuCgDmIOGKEpl/hyIa+v4UO4cIK5PhdjeqLS 9 | H3AX0YJp//UIyvphzNLpkWREJBsnQUPfexD8TB6qEHZ00wIZmYPwxX1h7uRl4VnV 10 | f0sxAyWrr0M37iAmuD590Uv/TdO2ZmUXMZ1PGQQrWLcNjFDM7IYoOiHflFj35xv+ 11 | 8FUKk0SGsXtbuA4TePgfm8xQ/jilnw3Q75CJmJdPe390V4ufCEJu/DB3Xz8Icc/G 12 | bSPBBtoEV3Ogot7kY6swXc4fn5hSsKKCX0JARRrm3PO+MWCBYjZ0uolc+F7Pqpf+ 13 | 1e2ZNlqBAoGBAPynrJedrBWrb7BZ5kaNJyvU+io9fEfFe1W31wC/de3mDv3JMQFW 14 | 4MXcxFG+D/3wrlaSwlJSTmipmYY/p4WCnBizP83/MCIyYEj6waPPsrB7/hygIc3E 15 | DFC+UGiDEEEv/DmdoAbGMgW/qTInaQNJbtBSRuhWAmP3R6tpHKtrSIURAoGBAOY0 16 | cpaabvv1TfnGV/h0Ffe0T5AyO6c77Ii8AmGPXrwWcj84RGwf42vFLVOFdFF4hr1K 17 | IJwnqOuqFhXYcS4BW/rR5z5D0wNDnZmmOuIWGAoFXGEtBNnEcj+/D/M280Dn2X6S 18 | TMbtJde3Cxky4nX2m0nyQwMI/7h6l0BgonFXGig9AoGAHWwpXT6vW5arWw4dEvo9 19 | JY2X1HN0lacZxdGy6BNj2GCCPmu/mThU1LXw5tQLaLculkZg+tU67FVT255uE84x 20 | /25gb8zX/iN/swAArOLzHDpUTWEYjq3WAVEobANXUUAVT2Bb0m4iRSkcuwp74DYd 21 | AYWTXFsnzBxv7DZBcHT97QECgYAfh29qURyCRca4PwItdTjNBFUhWr/w17Q9xgJN 22 | emVvPWPIZNx6MqPjTs42ckDMJ8XMhyqQOJ5aKKF9vHdD5cvDPpx9Wqy79bbQJIRM 23 | EtqYBMPyS0guy0kakgCNPylx6k9PlpoNZM2aDefnO6Dopy39osCq2cCsc53jo1ic 24 | TWG3wQKBgQDtqL+Hjl1OgzBirrJ08cqMH+0Blz3xhxUKhaIcYBuHX5gsqRRE/llt 25 | fhCEpZ2jrqL8D100sNaah5UBYlBqv8qY5GUUoLgYh5A3zrpmMIDfk2uSXvAzPvkb 26 | r+REq58IQAmLku937YUP8B5DBzkItMqEefZNJm6DwE0Wujej4S0P8Q== 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/root_CA1.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDtTCCAp2gAwIBAgIUJysTAOCqE3IaNO1QgtOPxMq6M8EwDQYJKoZIhvcNAQEL 3 | BQAwajELMAkGA1UEBhMCREUxCzAJBgNVBAgMAkJXMREwDwYDVQQHDAhGcmVpYnVy 4 | ZzEbMBkGA1UECgwSTVogQXV0b21hdGlvbiBHbWJIMQwwCgYDVQQLDANSJkQxEDAO 5 | BgNVBAMMB3Jvb3RfQ0EwHhcNMjIwMzE4MDkyNzEwWhcNMzIwMzE1MDkyNzEwWjBq 6 | MQswCQYDVQQGEwJERTELMAkGA1UECAwCQlcxETAPBgNVBAcMCEZyZWlidXJnMRsw 7 | GQYDVQQKDBJNWiBBdXRvbWF0aW9uIEdtYkgxDDAKBgNVBAsMA1ImRDEQMA4GA1UE 8 | AwwHcm9vdF9DQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOMyaDaT 9 | +a4DT0s2NCrjUN8coLPfFrLRdN0Gx0hRViuLUFxd001jXruRgXKt2g8lR+YnzUeA 10 | PQHbcIfRQhL+jy/ZMXpmz4Nrl7vyOWFdu8nBKU6c7y9LmSGbnOJZjDXwlX6ERwui 11 | qFzAvRA6YXbPN8gY0B3Ou+T/mjkWN9L1x+V+7bGs9rVIoM78fVyM2FERBfsBtT76 12 | QVQv3KZ+a9EOLxqcZ/nGqsFFysFOSkiRC6Cy4mC5CSik9S5D7X9lz/bdga7O+hqd 13 | SKfir6YMlQGV37JPqmz69N6vvb9UOX/G989T4qdVB/zQOvMdcIWXkqb3vSAXYi/c 14 | ClVS1Pymsy/MXQ0CAwEAAaNTMFEwHQYDVR0OBBYEFGYgIECdrhTsmgCKpVM0RHeC 15 | kFUmMB8GA1UdIwQYMBaAFGYgIECdrhTsmgCKpVM0RHeCkFUmMA8GA1UdEwEB/wQF 16 | MAMBAf8wDQYJKoZIhvcNAQELBQADggEBACsiuHFQjqOglenp/fcNbU034m/vvkyV 17 | SZXau9amXBWdeTEpc1HaPOYO7jFFnu/QoH6AbGZkpL0yWZJA2rf102AkOdAe6E0g 18 | 2H77/hHoHVCfxOiOl3+icsLXJ4VXqV2vmUOEVnWfHRtej4My6avT9uCNMO2bw9hm 19 | 56RAZrs82T9Mpg/1XQ9YUO1q4/JfP/+dCzPXAdwJ/h2cJ/q6Q9g1gRns8IzVlGOZ 20 | 0ZBQCLqLl8vUei+t6YgjyBbeNCz4CEcmXKIJeqMB1jhpsgr6BBMTNTU2Q60b9fzU 21 | OCGLw94EnKYtHWGy2WHMFNbwkNCR0/jwhxKkU0HXy1aNMUBWp99M7P8= 22 | -----END CERTIFICATE----- 23 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/root_CA1.srl: -------------------------------------------------------------------------------- 1 | 54C99080842227669EB8AC205C59F7D28A2E10CA 2 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/server_CA1_1.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpAIBAAKCAQEA2FFfpxEqImd01A9Q+ccTRDroVpz840ektXr45V0RQkpz8zSu 3 | Iv5GXPqBXwSgKXsojoLkCYK+VmlX4GQ6xXblAKAd/flUS+WVsUq9kL9cud30dwYK 4 | h2V4/Tm/NvUiZsYV3b5/8RfUpYwVNBW/eScbNXrVHNkiBrcIJtixruKsyH+drckP 5 | 7K4j+AZh43LGsK6NY+ppf5wHBctGWFOCFdJSrabck4oem807COKX9PhTfD87OnjB 6 | QcqdHkus8WZP/SGnZV+6c1k0SN4O0E4MahpWkr8D2ZjsbhGFIW8AU4NdobsohClW 7 | AZ0MDR1N4oo0sj4HgY2hGR2AbR/5Y2LH4kRcpQIDAQABAoIBAEK2tf1cedYqegl8 8 | v8iI8RQ15rnvqL6ftdiSmHiEf3ImbCQxtxLrwN+kEoovbwXcCeIJ1DJqtDEKRCPc 9 | RZPo2y+aMiXF442UvNn05wnhOsPIBEFBB7ZCQVI3oRVd/MIdjVjaC7NbWiXEUjXC 10 | D09aFDYmL9u5y5iukkEIy6PYHNmokN0MlHwhFqqp72hGe6UvHfZ6yu46z1eF6zLN 11 | S4b2ULUzJ6Ov0Y7kmN7vP058yfZYHoj4TPeRBDm3Qx8g9c5d6da22vfkt61UzXEN 12 | ih8fIejq6BGila2wMuZKyCM/Oxv5WX0RTzVQO13+42f29BM47Mdk/a8ijBZCzXnC 13 | oAnHcwECgYEA7Isah3VNc4KkSNRrnV1UrInQ8BAlNLTN4cJTbyOkogCUECvfzAS+ 14 | K/l8YZOzZ7YoJkK7RzDeUqRfrZhyJut6x7J/3Vl6qLXpnx3iEPJdxaD5L1iftnIP 15 | NOytbphClO+VAjSO3frhlCwZ00Z6o6meTV+CNmRT2LDFEzxAMc3GtrECgYEA6hxh 16 | m3S5KX7Ze/m5v9l4vi2iGDNBJkk48Cc+qfgVLGa0TSd7cY+8bjYNufr6vqThKlVu 17 | RByZ3Wo5C5PfrkU69YbJ9LnQ+RTZPu+IxPIsUM3xlyTin7bufyOcWhPr1820MKqP 18 | A/mRJ/SKel7ubrURai7KDETR0mI9XajhtwF/qjUCgYEAvW1sclwTCVTuwVAzWhM6 19 | 0u2PACC92uaMFaYscM1nc0DpUcYA8/48WTTzUaUZwA1VO8am+Yz+DcqKwJdbmyVq 20 | 7u9YjGey3dbIX19sAcxGIhUWWL8tL8tJuEVtYirW7zSp7NkwLD5UVfe3OsWvQs97 21 | 8VRyD6LqrpZpTE0sz3WOFBECgYAxgOLa3mmw7pPKdVnjyXaQsFGQUHY8REt37LSB 22 | eGXxx53kmq6tqrkrjN6GLx4KZg7+xqXUXT/j4+xAGHq5/QWkmWXnC8u2f8QYXMpM 23 | 6vCX/ZRSY4hQQXxZAgyzt3atYV/y0n3/VyxsiHcnvR8p5bvS+iXbRkof9IoJXgas 24 | jfKS6QKBgQC6ZFuvYIeqkfZ0Yyxxum3qlGxpR41wcuIpb4hBQ0gr1haTL0aaoUiQ 25 | qqUfzVRst/oPxf6vqeCxtWh1/3lGa1QXP9KJDA5twFMqTg5jv92vjMIgPTEZ2Oif 26 | +YyTs72V197KHctx2/T4RxAGhxCLJwDzk2shvLS+1voU/w40YRy9yA== 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/server_CA1_1.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDWzCCAkMCFFTJkICEIidmnrisIFxZ99KKLhDIMA0GCSqGSIb3DQEBCwUAMGox 3 | CzAJBgNVBAYTAkRFMQswCQYDVQQIDAJCVzERMA8GA1UEBwwIRnJlaWJ1cmcxGzAZ 4 | BgNVBAoMEk1aIEF1dG9tYXRpb24gR21iSDEMMAoGA1UECwwDUiZEMRAwDgYDVQQD 5 | DAdyb290X0NBMB4XDTIyMDUyNjEwNDc0NFoXDTMwMDgxMjEwNDc0NFowajELMAkG 6 | A1UEBhMCREUxCzAJBgNVBAgMAkJXMREwDwYDVQQHDAhGcmVpYnVyZzEbMBkGA1UE 7 | CgwSTVogQXV0b21hdGlvbiBHbWJIMQwwCgYDVQQLDANSJkQxEDAOBgNVBAMMB3Nl 8 | cnZlcjEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDYUV+nESoiZ3TU 9 | D1D5xxNEOuhWnPzjR6S1evjlXRFCSnPzNK4i/kZc+oFfBKApeyiOguQJgr5WaVfg 10 | ZDrFduUAoB39+VRL5ZWxSr2Qv1y53fR3BgqHZXj9Ob829SJmxhXdvn/xF9SljBU0 11 | Fb95Jxs1etUc2SIGtwgm2LGu4qzIf52tyQ/sriP4BmHjcsawro1j6ml/nAcFy0ZY 12 | U4IV0lKtptyTih6bzTsI4pf0+FN8Pzs6eMFByp0eS6zxZk/9IadlX7pzWTRI3g7Q 13 | TgxqGlaSvwPZmOxuEYUhbwBTg12huyiEKVYBnQwNHU3iijSyPgeBjaEZHYBtH/lj 14 | YsfiRFylAgMBAAEwDQYJKoZIhvcNAQELBQADggEBANPRnvfByVoKwfMcQYUnYT6l 15 | 5OhYt8f2tQfoa0EXirP0O2xG052ZBl3Z5ZzBCcsq1zveaPoeqXFl6HjqIqURB5NS 16 | imJIi7kB7o6C2z19yxOndPm3urKGyfvxtSy2iyzTMZ8eL8RFMJC5DVV+n5Y+1EgC 17 | pYIu//I0ojnFOemEJXVjfxQhiUbx6Nw8HalHOhW1i017XcOWMKji/lwHfWF2PFmn 18 | pIWZCFPCUtHzBUkXCRzn9ESeMDcMXN6qLb2wGJkRUDw+Ls1RGJd6dnB811vOuOd+ 19 | QQc8lyyBZ1byARcxQ8lAtof6Mv7Yzebv1OxRr7NcrV/+ujnSFyJWKrJdcMx7+10= 20 | -----END CERTIFICATE----- 21 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/server_CA1_1_chain.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDWzCCAkMCFFTJkICEIidmnrisIFxZ99KKLhDIMA0GCSqGSIb3DQEBCwUAMGox 3 | CzAJBgNVBAYTAkRFMQswCQYDVQQIDAJCVzERMA8GA1UEBwwIRnJlaWJ1cmcxGzAZ 4 | BgNVBAoMEk1aIEF1dG9tYXRpb24gR21iSDEMMAoGA1UECwwDUiZEMRAwDgYDVQQD 5 | DAdyb290X0NBMB4XDTIyMDUyNjEwNDc0NFoXDTMwMDgxMjEwNDc0NFowajELMAkG 6 | A1UEBhMCREUxCzAJBgNVBAgMAkJXMREwDwYDVQQHDAhGcmVpYnVyZzEbMBkGA1UE 7 | CgwSTVogQXV0b21hdGlvbiBHbWJIMQwwCgYDVQQLDANSJkQxEDAOBgNVBAMMB3Nl 8 | cnZlcjEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDYUV+nESoiZ3TU 9 | D1D5xxNEOuhWnPzjR6S1evjlXRFCSnPzNK4i/kZc+oFfBKApeyiOguQJgr5WaVfg 10 | ZDrFduUAoB39+VRL5ZWxSr2Qv1y53fR3BgqHZXj9Ob829SJmxhXdvn/xF9SljBU0 11 | Fb95Jxs1etUc2SIGtwgm2LGu4qzIf52tyQ/sriP4BmHjcsawro1j6ml/nAcFy0ZY 12 | U4IV0lKtptyTih6bzTsI4pf0+FN8Pzs6eMFByp0eS6zxZk/9IadlX7pzWTRI3g7Q 13 | TgxqGlaSvwPZmOxuEYUhbwBTg12huyiEKVYBnQwNHU3iijSyPgeBjaEZHYBtH/lj 14 | YsfiRFylAgMBAAEwDQYJKoZIhvcNAQELBQADggEBANPRnvfByVoKwfMcQYUnYT6l 15 | 5OhYt8f2tQfoa0EXirP0O2xG052ZBl3Z5ZzBCcsq1zveaPoeqXFl6HjqIqURB5NS 16 | imJIi7kB7o6C2z19yxOndPm3urKGyfvxtSy2iyzTMZ8eL8RFMJC5DVV+n5Y+1EgC 17 | pYIu//I0ojnFOemEJXVjfxQhiUbx6Nw8HalHOhW1i017XcOWMKji/lwHfWF2PFmn 18 | pIWZCFPCUtHzBUkXCRzn9ESeMDcMXN6qLb2wGJkRUDw+Ls1RGJd6dnB811vOuOd+ 19 | QQc8lyyBZ1byARcxQ8lAtof6Mv7Yzebv1OxRr7NcrV/+ujnSFyJWKrJdcMx7+10= 20 | -----END CERTIFICATE----- 21 | -----BEGIN CERTIFICATE----- 22 | MIIDtTCCAp2gAwIBAgIUJysTAOCqE3IaNO1QgtOPxMq6M8EwDQYJKoZIhvcNAQEL 23 | BQAwajELMAkGA1UEBhMCREUxCzAJBgNVBAgMAkJXMREwDwYDVQQHDAhGcmVpYnVy 24 | ZzEbMBkGA1UECgwSTVogQXV0b21hdGlvbiBHbWJIMQwwCgYDVQQLDANSJkQxEDAO 25 | BgNVBAMMB3Jvb3RfQ0EwHhcNMjIwMzE4MDkyNzEwWhcNMzIwMzE1MDkyNzEwWjBq 26 | MQswCQYDVQQGEwJERTELMAkGA1UECAwCQlcxETAPBgNVBAcMCEZyZWlidXJnMRsw 27 | GQYDVQQKDBJNWiBBdXRvbWF0aW9uIEdtYkgxDDAKBgNVBAsMA1ImRDEQMA4GA1UE 28 | AwwHcm9vdF9DQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOMyaDaT 29 | +a4DT0s2NCrjUN8coLPfFrLRdN0Gx0hRViuLUFxd001jXruRgXKt2g8lR+YnzUeA 30 | PQHbcIfRQhL+jy/ZMXpmz4Nrl7vyOWFdu8nBKU6c7y9LmSGbnOJZjDXwlX6ERwui 31 | qFzAvRA6YXbPN8gY0B3Ou+T/mjkWN9L1x+V+7bGs9rVIoM78fVyM2FERBfsBtT76 32 | QVQv3KZ+a9EOLxqcZ/nGqsFFysFOSkiRC6Cy4mC5CSik9S5D7X9lz/bdga7O+hqd 33 | SKfir6YMlQGV37JPqmz69N6vvb9UOX/G989T4qdVB/zQOvMdcIWXkqb3vSAXYi/c 34 | ClVS1Pymsy/MXQ0CAwEAAaNTMFEwHQYDVR0OBBYEFGYgIECdrhTsmgCKpVM0RHeC 35 | kFUmMB8GA1UdIwQYMBaAFGYgIECdrhTsmgCKpVM0RHeCkFUmMA8GA1UdEwEB/wQF 36 | MAMBAf8wDQYJKoZIhvcNAQELBQADggEBACsiuHFQjqOglenp/fcNbU034m/vvkyV 37 | SZXau9amXBWdeTEpc1HaPOYO7jFFnu/QoH6AbGZkpL0yWZJA2rf102AkOdAe6E0g 38 | 2H77/hHoHVCfxOiOl3+icsLXJ4VXqV2vmUOEVnWfHRtej4My6avT9uCNMO2bw9hm 39 | 56RAZrs82T9Mpg/1XQ9YUO1q4/JfP/+dCzPXAdwJ/h2cJ/q6Q9g1gRns8IzVlGOZ 40 | 0ZBQCLqLl8vUei+t6YgjyBbeNCz4CEcmXKIJeqMB1jhpsgr6BBMTNTU2Q60b9fzU 41 | OCGLw94EnKYtHWGy2WHMFNbwkNCR0/jwhxKkU0HXy1aNMUBWp99M7P8= 42 | -----END CERTIFICATE----- 43 | -------------------------------------------------------------------------------- /lib60870-C/tests/certs/test.crl: -------------------------------------------------------------------------------- 1 | -----BEGIN X509 CRL----- 2 | MIICEzCB/AIBATANBgkqhkiG9w0BAQsFADBqMQswCQYDVQQGEwJERTELMAkGA1UE 3 | CAwCQlcxETAPBgNVBAcMCEZyZWlidXJnMRswGQYDVQQKDBJNWiBBdXRvbWF0aW9u 4 | IEdtYkgxDDAKBgNVBAsMA1ImRDEQMA4GA1UEAwwHcm9vdF9DQRcNMjIwNTI2MTA1 5 | NjM5WhcNMjIwNjI1MTA1NjM5WjBOMCUCFFTJkICEIidmnrisIFxZ99KKLhDGFw0y 6 | MjA1MjYwODUwNDVaMCUCFFTJkICEIidmnrisIFxZ99KKLhDJFw0yMjA1MjYxMDU1 7 | NDZaoA4wDDAKBgNVHRQEAwIBAjANBgkqhkiG9w0BAQsFAAOCAQEAFddsFFBmc0a4 8 | F0NalGy3RBN9ui3H7N2qzN93B3GkeI0ziPJjAnv+HZy2dSIn+LOftgMN+DBfReeU 9 | cpVNPxEOnPNE/bKRev2LWhn/KLOX4FufSHrTWQlLAaqlq7+ScdSsNWmblx1s5DC5 10 | EoLMkO4I8p3Q1jpiyIpayNhL6T5FkbM1QwrX5wLRW7Lg1hSPUT+8yAXwDthyVuO+ 11 | s0aJOVDqGietCcfbQpNzJKjckuLrbesB0Y1C6SNk/c55zUFQT80jj3+GZ/guNFf4 12 | j0DmFAj8GoR64UxlfpW9Fns+XOAulmbT+oFmbMe2Q+XZ2aAFuDHsqQ00At1aRjBP 13 | ZQXpF7wJKQ== 14 | -----END X509 CRL----- 15 | -------------------------------------------------------------------------------- /lib60870-C/tests/client1-key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpAIBAAKCAQEAxAMUXdnem99n5J8Z8Wa0fdPtoMCTdkQJrOO6WJ4XePrpQgHU 3 | HDziSmdIZDDkpJ3Ey0Byy+b+iiRDmOuIZGSCsI0ehggWaia12h2osUK0BLyThuZ/ 4 | RQw54K0dy61eviNaYsftiBcxHYKyKmWch/wLLYxdd1qLzd0reAbSUaHDkDzrj9hO 5 | 8qr7DhKpqx7PoVh1gFhAKPKuY6b+4xqv5eZvt8QflQTWYGxaxmUIEinqCnzh1l5d 6 | tp0rhnBsz9Y4y8dXjh0m7pbXmRNY6opMxXatqgYEqsntLy1N6x7DvWLBqtVvEmox 7 | Tc5bbAoRW3eEToClDdFQBzLsMVcSEX8vwttk3QIDAQABAoIBABHr1ijeiqPlwTH9 8 | +flAUrBOeCOCd/kQL3JHP/pqOestxbXrROFwD6CN4OiIL999LUkIE3bhH9SxjByn 9 | LElBh1FtFaVbh/EcqPPQUmQinSLxuutSl8BQZdpM+bRtnYP054awkN8of60bDf8i 10 | WzVzrfH0K3eGJ9Iirp7CwOgFykOdpQyxsI+HG8grcwA87x1ZsAIfHhiKmQByliNl 11 | BkbJmYBOtfVgXje5QdxTptlTNljFSbZcaCXv1P3aOqctcgJMQjg0T+E37Y8Cav80 12 | 6SuXbpv/cdacG695MAT7Vtywue0Axh59DvxAzc+deyQT70Hzw+Mo6pgi0clFnwzU 13 | Y5ViDWECgYEAxxhRKzpz7klnmGob5CZvrbqDfC3JUEOxKH0e342S/HmT05bTI21w 14 | N8A0KStNjQXS1mmkAkY/OO1Zutmf6yjqsxAIEO5UMTCSEP7YLRB7qBdN7dOt3JaK 15 | 4wxErMCljdT68Vj5Qj8YzIXJkWPk871oFTvVNe2qxgrCUigE5ai2I8cCgYEA/Akv 16 | E0L+2uXayEucEamzO3n9xVziNanjyHilnJJvduvO9gd+crBbxSKqaXSdfPnp2mSa 17 | +e3N7elxP2b/kPrGkzZekSaMh1nPH4Upu+ISK117r1x+vmnxZHRpehrVh1QzOQ5p 18 | Ljt+GaXa3ur3P/6uW5KMbtGGW6MEgDwLMLvpqjsCgYA5pnfyfYWOTWEbCDa1VM/n 19 | zWc/cP6nKELHR5vF/fe+9fFxRm4zBwCElDpGZYyaNkJ75bEhG3g5Irll2phs/rcf 20 | TJgZVvm4GKljFHhCbFByNvVQ1Ye1pT3oSugj4dDOhgp4Elxy61Rh/KeGWxez4Heg 21 | FmhBqmVV3U2xfncUjUrYhwKBgQCKtPM3gpOIHSA/Q31tKxv9C7JiQDAuoIU/+0YJ 22 | 2X2G0VhhhtZMgErBP8bRquBRu6i8DMpN6lZ/LQ6qeiEExT8sHawF7lVA2GhpTHwf 23 | btfZDeXYKOuIF/5F7ttt2/7QL8LRD+FLFGrd6q1+KYpRqfSDaS/ofV+YZys+98yg 24 | 0YpTqQKBgQCWJpV2ySgXcKJzAUh14VNpLTRzJOMSpsU576nwz0TLUREVjiH6rvKr 25 | gxllDEe1bVNMEekaZ+dOqiJX+4aTnEbIrEXki5Dvz0vq8biImW9RRdPEHgYVTv/d 26 | qBOPHiIq2JiY6abD9XNPM3VQ/z8em6/4mkC8COCJRd2mA89FOYRxOQ== 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /lib60870-C/tests/client1.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mz-automation/lib60870/63028a9287da3b075d4225effcf1dfaf5ea47ed1/lib60870-C/tests/client1.cer -------------------------------------------------------------------------------- /lib60870-C/tests/client2.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mz-automation/lib60870/63028a9287da3b075d4225effcf1dfaf5ea47ed1/lib60870-C/tests/client2.cer -------------------------------------------------------------------------------- /lib60870-C/tests/root.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mz-automation/lib60870/63028a9287da3b075d4225effcf1dfaf5ea47ed1/lib60870-C/tests/root.cer -------------------------------------------------------------------------------- /lib60870-C/tests/server-key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpAIBAAKCAQEAu3Fjxb904UdyV/dDfvs8SFi6zJeNoMYjmpXm/LBcFSH3zGoK 3 | wdcMovrUTED3Cc6Ww84AYpJ5MRMPTct7DfKJkWfSnkzOPmLldTSTv3RvzGVb4NzK 4 | QqA5aSVDqAzPiP5RnFT6Q4KWRe69TMFxpw7zMXCJx9jDggqN1oojGGkmSgYGXnFd 5 | Nc20Mujejh5pihgwnN4Y/bPFyxJwvIMj+D8qr9klhEmXKPTiX9UFd8oLkn9JCB6+ 6 | SiHhNyFIo+Llossn1Q2hxCGty36fAhEWzpfBTaY510VLjie9y4q9GPTwxITDqSQd 7 | xcX8IuvrbxX0DyEK507SMmTJmB9448eF9ZCWFQIDAQABAoIBAC80BuQtqslwrKLq 8 | adz4d93gOmp7X/c07pJnXZwU7ZuEylp3+e2Gsm/4qq3pTkzx8ZWtsvsf19U774av 9 | z3VbtrkfZDLpNKcRUKeLbgmw0NawT8r4zxaoMsz/zWHsl/bv1K2B2ORXZnCGBrXl 10 | oTFo2mWA6bGiLNn6vm1grCXhlPreywyG/kFK3pi2VvkpvG3XZSI7mmZ0Dq/MD3nO 11 | 03oOZBqwwnMObfQQdhKE7646/+KgeuF/JsXaUH4bkHmtzYWyocWYMqpC0hjpNWlQ 12 | cKuQ7t1kfmpsGD9aNW4+ND2ok9BdxIiC+rPXS9NDqZxoWLp+a8seU++uqk1l8RPq 13 | tPE3LqECgYEAz1NmemNLiUsKvyemUvjp8+dJupzWtdV7fsnCbYhj/5gDA2UhFKCf 14 | dP9xiHCdNe0797oAqHY7c3JhS4ug8haDy9aDIu5GG2DNYzjX/oYm4ywbCdRx+uEN 15 | RcTw69FjSYVGkObmxWYszwsFybRasV6PYamg65qYR3FlvW2Td4Fndy8CgYEA53L/ 16 | zHtBRQiNGJU9jfMHeX0bTtXIAt622Qn78jw0it/rhXWi2RwG2Cw5Q2aPRJ6uMt9F 17 | yk1+GAPZcwYqwjq/nKRrl71Tn+KDWIk5rz1fNYRkaXtnMLs2MOogqoDTBshW0QBq 18 | tnPrFNsaLKX6V92Az69wHjd2uwvLQLTvS/EuNfsCgYEAr3to/uhytAd3VirKRep3 19 | o0E+D5zWw1upxrwhPDK4aUuSKVp8sIfvz8iyoQiomE9vdZPTIMPKOEI1BgtuM9pI 20 | vcyYfIVvg5bg4T3o3H9SBPB9BknyG6ZHZKl4PjGht0X+X4GBDM4Z2Tj8Mijcpsph 21 | 1AkOsrzMbZQWyEoqCnnWSHMCgYAFEHUcak4BTrCXqxxPsNOnCt/AF9lqhqkFkrxa 22 | joqvxzqGDw7jJUPZEw6ltObJn5c8Mbp7NLrfl6X4aFgjK9npeYeJKHFd/DzXgRks 23 | BnHA4Aa6cCLP5CjJZTYVxP/ZFCUiKZosJ9kq+ahW9cLGjWg2IyaW4qvMZ/OolMzv 24 | onVaZQKBgQCir8u1vDsyA4JQXMytPHBJe27XaLRGULvteNydVB59Vt21a99o5gt1 25 | 5B9gwWArZdZby3/KZiliNmzp8lMCrLJYjTL5WK6dbWdq92X5hCOofKPIjEcgHjhk 26 | mvnAos3HeC83bJQtADXhw9jR7Vr6GJLM9HDcIgeIMzX7+BuqlMgaHA== 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /lib60870-C/tests/server.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mz-automation/lib60870/63028a9287da3b075d4225effcf1dfaf5ea47ed1/lib60870-C/tests/server.cer -------------------------------------------------------------------------------- /sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.projectKey=mz-automation_lib608702 2 | sonar.organization=mz-automation 3 | 4 | # This is the name and version displayed in the SonarCloud UI. 5 | sonar.projectName=lib60870 6 | sonar.projectVersion=2.3.6 7 | 8 | sonar.sources=lib60870-C/src,lib60870-C/config 9 | 10 | --------------------------------------------------------------------------------