From cec871f2e3be3fe29a8cb396089d4564a7f61316 Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Mon, 31 Oct 2022 18:58:02 +0100 Subject: [PATCH] - make rsession code compatible with MSVC (LIB61850-360) --- .../r_goose_publisher_example.c | 3 +-- .../r_goose_subscriber_example.c | 2 +- .../rsv_publisher_example/r_sv_publisher_example.c | 4 ++-- hal/socket/win32/socket_win32.c | 10 +++++----- src/CMakeLists.txt | 5 ++++- src/r_session/r_session.c | 12 ++++++------ 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/examples/r_goose_publisher_example/r_goose_publisher_example.c b/examples/r_goose_publisher_example/r_goose_publisher_example.c index 5d7ca294..d55ae993 100644 --- a/examples/r_goose_publisher_example/r_goose_publisher_example.c +++ b/examples/r_goose_publisher_example/r_goose_publisher_example.c @@ -56,10 +56,9 @@ main(int argc, char **argv) GoosePublisher publisher = GoosePublisher_createRemote(rSession, 0x4001); - //char* key = "0123456789ABCDEF"; char* key = "0123456789ABCDEF"; - RSession_addKey(rSession, 1, key, 16, R_SESSION_SEC_ALGO_AES_128_GCM, R_SESSION_SIG_ALGO_NONE); + RSession_addKey(rSession, 1, (uint8_t*)key, 16, R_SESSION_SEC_ALGO_AES_128_GCM, R_SESSION_SIG_ALGO_NONE); RSession_setActiveKey(rSession, 1); if (publisher) { diff --git a/examples/r_goose_receiver_example/r_goose_subscriber_example.c b/examples/r_goose_receiver_example/r_goose_subscriber_example.c index f70a71a9..34f225ee 100644 --- a/examples/r_goose_receiver_example/r_goose_subscriber_example.c +++ b/examples/r_goose_receiver_example/r_goose_subscriber_example.c @@ -56,7 +56,7 @@ main(int argc, char** argv) RSession_setLocalAddress(sessionP, "0.0.0.0", 102); char* key = "0123456789ABCDEF"; - RSession_addKey(sessionP, 1, key, 16, R_SESSION_SEC_ALGO_AES_128_GCM, R_SESSION_SIG_ALGO_NONE); + RSession_addKey(sessionP, 1, (uint8_t*)key, 16, R_SESSION_SEC_ALGO_AES_128_GCM, R_SESSION_SIG_ALGO_NONE); RSession_addMulticastGroup(sessionP, "230.0.10.11"); diff --git a/examples/rsv_publisher_example/r_sv_publisher_example.c b/examples/rsv_publisher_example/r_sv_publisher_example.c index f9c9a12b..8256ee6a 100644 --- a/examples/rsv_publisher_example/r_sv_publisher_example.c +++ b/examples/rsv_publisher_example/r_sv_publisher_example.c @@ -39,8 +39,8 @@ main(int argc, char** argv) char* key1 = "0123456789ABCDEF"; char* key2 = "FEDCBA9876543210"; - RSession_addKey(rSession, 1, key1, 16, R_SESSION_SEC_ALGO_AES_128_GCM, R_SESSION_SIG_ALGO_NONE); - RSession_addKey(rSession, 2, key2, 16, R_SESSION_SEC_ALGO_AES_128_GCM, R_SESSION_SIG_ALGO_NONE); + RSession_addKey(rSession, 1, (uint8_t*)key1, 16, R_SESSION_SEC_ALGO_AES_128_GCM, R_SESSION_SIG_ALGO_NONE); + RSession_addKey(rSession, 2, (uint8_t*)key2, 16, R_SESSION_SEC_ALGO_AES_128_GCM, R_SESSION_SIG_ALGO_NONE); RSession_setActiveKey(rSession, activeKeyId); diff --git a/hal/socket/win32/socket_win32.c b/hal/socket/win32/socket_win32.c index fb727452..db799c7e 100644 --- a/hal/socket/win32/socket_win32.c +++ b/hal/socket/win32/socket_win32.c @@ -668,8 +668,8 @@ Socket_destroy(Socket self) GLOBAL_FREEMEM(self); } -UdpSocket -UdpSocket_create() +static UdpSocket +UdpSocket_createUsingNamespace(int ns) { UdpSocket self = NULL; @@ -782,7 +782,7 @@ UdpSocket_bind(UdpSocket self, const char* address, int port) struct sockaddr_in localAddress; if (!prepareAddress(address, port, &localAddress)) { - closesocket(self->fd); + closesocket(self->fd); self->fd = 0; return false; } @@ -793,7 +793,7 @@ UdpSocket_bind(UdpSocket self, const char* address, int port) if (DEBUG_SOCKET) printf("SOCKET: failed to bind UDP socket (errno=%i)\n", errno); - closesocket(self->fd); + closesocket(self->fd); self->fd = 0; return false; @@ -873,7 +873,7 @@ UdpSocket_receiveFrom(UdpSocket self, char* address, int maxAddrSize, uint8_t* m isIPv6 = true; } else - return result ; + return result; if (isIPv6) snprintf(address, maxAddrSize, "[%s]:%i", addrString, port); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1210883d..e8f8a3fb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -217,6 +217,8 @@ set_source_files_properties(${lib_asn1c_SRCS} IF(MSVC) set_source_files_properties(${lib_common_SRCS} ${lib_windows_SRCS} PROPERTIES LANGUAGE CXX) +set_source_files_properties(${lib_rsession_SRCS} + PROPERTIES LANGUAGE CXX) ENDIF() IF(WITH_WPCAP) @@ -224,7 +226,8 @@ IF(MSVC) set_source_files_properties(${lib_goose_SRCS} PROPERTIES LANGUAGE CXX) set_source_files_properties(${lib_sv_SRCS} - PROPERTIES LANGUAGE CXX) + PROPERTIES LANGUAGE CXX) + ENDIF() ELSE() add_definitions(-DEXCLUDE_ETHERNET_WINDOWS) diff --git a/src/r_session/r_session.c b/src/r_session/r_session.c index 0bab6b05..7e6677a7 100644 --- a/src/r_session/r_session.c +++ b/src/r_session/r_session.c @@ -506,7 +506,7 @@ parseSessionMessage(RSession self, uint8_t* buffer, int msgSize, RSessionPayload /* parse payload elements */ uint32_t payloadEnd = bufPos + payloadLength; - if (payloadEnd > msgSize) { + if (payloadEnd > (uint32_t)msgSize) { DEBUG_PRINTF("ERROR - payload size field invalid"); goto exit_error; } @@ -549,7 +549,7 @@ parseSessionMessage(RSession self, uint8_t* buffer, int msgSize, RSessionPayload } } - while (bufPos < payloadEnd) { + while ((uint32_t)bufPos < payloadEnd) { int payloadElementType = buffer[bufPos++]; bool simulation; @@ -639,7 +639,7 @@ parseSessionMessage(RSession self, uint8_t* buffer, int msgSize, RSessionPayload /* parse payload elements */ uint32_t payloadEnd = bufPos + payloadLength; - if (payloadEnd > msgSize) { + if (payloadEnd > (uint32_t)msgSize) { DEBUG_PRINTF("ERROR - payload size field invalid"); goto exit_error; } @@ -685,9 +685,9 @@ parseSessionMessage(RSession self, uint8_t* buffer, int msgSize, RSessionPayload /* Check signature and decrypt application layer */ if (secAlgo != R_SESSION_SEC_ALGO_NONE) { /* Check for HMAC */ - if (payloadEnd + 18 <= msgSize) { + if (payloadEnd + 18 <= (uint32_t)msgSize) { if (self->payloadBuffer == NULL) - self->payloadBuffer = GLOBAL_MALLOC(65000); + self->payloadBuffer = (uint8_t*)GLOBAL_MALLOC(65000); if (self->payloadBuffer) { //TODO check MMAC tag @@ -711,7 +711,7 @@ parseSessionMessage(RSession self, uint8_t* buffer, int msgSize, RSessionPayload } } - while (bufPos < payloadEnd) { + while ((uint32_t)bufPos < payloadEnd) { int payloadElementType = buffer[bufPos++]; bool simulation;