cleaner wiretapping handling
This commit is contained in:
parent
bdd66072d1
commit
e67ff6a937
@ -1,11 +1,10 @@
|
|||||||
target_sources(${LIB_FSFW_NAME}
|
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||||
PRIVATE
|
TcWinUdpPollingTask.cpp
|
||||||
TcWinUdpPollingTask.cpp
|
TmTcWinUdpBridge.cpp
|
||||||
TmTcWinUdpBridge.cpp
|
TcWinTcpServer.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(${LIB_FSFW_NAME}
|
target_link_libraries(${LIB_FSFW_NAME} PRIVATE
|
||||||
PRIVATE
|
wsock32
|
||||||
wsock32
|
ws2_32
|
||||||
ws2_32
|
|
||||||
)
|
)
|
46
osal/windows/TcWinTcpServer.cpp
Normal file
46
osal/windows/TcWinTcpServer.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#include "TcWinTcpServer.h"
|
||||||
|
#include "../../serviceinterface/ServiceInterface.h"
|
||||||
|
#include <winsock2.h>
|
||||||
|
|
||||||
|
TcWinTcpServer::TcWinTcpServer(object_id_t objectId, object_id_t tmtcUnixUdpBridge):
|
||||||
|
SystemObject(objectId) {
|
||||||
|
/* Open TCP socket */
|
||||||
|
serverTcpSocket = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
if(serverTcpSocket == 0) {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::warning << "TcWinTcpServer::TcWinTcpServer: Socket creation failed!" << std::endl;
|
||||||
|
handleSocketError();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
setsockopt(serverTcpSocket, SOL_SOCKET, SO_REUSEADDR | SO_BROADCAST,
|
||||||
|
&tcpSockOpt, sizeof(tcpSockOpt));
|
||||||
|
}
|
||||||
|
|
||||||
|
TcWinTcpServer::~TcWinTcpServer() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcWinTcpServer::handleSocketError() {
|
||||||
|
int errCode = WSAGetLastError();
|
||||||
|
switch(errCode) {
|
||||||
|
case(WSANOTINITIALISED): {
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::warning << "TmTcWinUdpBridge::handleSocketError: WSANOTINITIALISED: WSAStartup"
|
||||||
|
" call necessary" << std::endl;
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
/*
|
||||||
|
https://docs.microsoft.com/en-us/windows/win32/winsock/
|
||||||
|
windows-sockets-error-codes-2
|
||||||
|
*/
|
||||||
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
|
sif::warning << "TmTcWinUdpBridge::handleSocketError: Error code: " << errCode << std::endl;
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
30
osal/windows/TcWinTcpServer.h
Normal file
30
osal/windows/TcWinTcpServer.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_
|
||||||
|
#define FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_
|
||||||
|
|
||||||
|
#include "../../objectmanager/SystemObject.h"
|
||||||
|
#include "../../tasks/ExecutableObjectIF.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class TcWinTcpServer:
|
||||||
|
public SystemObject,
|
||||||
|
public ExecutableObjectIF {
|
||||||
|
public:
|
||||||
|
/* The ports chosen here should not be used by any other process. */
|
||||||
|
static constexpr uint16_t DEFAULT_TCP_SERVER_PORT = 7301;
|
||||||
|
static constexpr uint16_t DEFAULT_TCP_CLIENT_PORT = 7302;
|
||||||
|
|
||||||
|
TcWinTcpServer(object_id_t objectId, object_id_t tmtcUnixUdpBridge);
|
||||||
|
virtual~ TcWinTcpServer();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
SOCKET serverTcpSocket = 0;
|
||||||
|
|
||||||
|
std::vector<uint8_t> receptionBuffer;
|
||||||
|
int tcpSockOpt = 0;
|
||||||
|
|
||||||
|
void handleSocketError();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FSFW_OSAL_WINDOWS_TCWINTCPSERVER_H_ */
|
@ -20,8 +20,8 @@ TcWinUdpPollingTask::TcWinUdpPollingTask(object_id_t objectId,
|
|||||||
this->frameSize = DEFAULT_MAX_FRAME_SIZE;
|
this->frameSize = DEFAULT_MAX_FRAME_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up reception buffer with specified frame size.
|
/* Set up reception buffer with specified frame size.
|
||||||
// For now, it is assumed that only one frame is held in the buffer!
|
For now, it is assumed that only one frame is held in the buffer! */
|
||||||
receptionBuffer.reserve(this->frameSize);
|
receptionBuffer.reserve(this->frameSize);
|
||||||
receptionBuffer.resize(this->frameSize);
|
receptionBuffer.resize(this->frameSize);
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ TcWinUdpPollingTask::TcWinUdpPollingTask(object_id_t objectId,
|
|||||||
TcWinUdpPollingTask::~TcWinUdpPollingTask() {}
|
TcWinUdpPollingTask::~TcWinUdpPollingTask() {}
|
||||||
|
|
||||||
ReturnValue_t TcWinUdpPollingTask::performOperation(uint8_t opCode) {
|
ReturnValue_t TcWinUdpPollingTask::performOperation(uint8_t opCode) {
|
||||||
// Poll for new UDP datagrams in permanent loop.
|
/* Poll for new UDP datagrams in permanent loop. */
|
||||||
while(true) {
|
while(true) {
|
||||||
//! Sender Address is cached here.
|
//! Sender Address is cached here.
|
||||||
struct sockaddr_in senderAddress;
|
struct sockaddr_in senderAddress;
|
||||||
@ -46,7 +46,7 @@ ReturnValue_t TcWinUdpPollingTask::performOperation(uint8_t opCode) {
|
|||||||
receptionFlags, reinterpret_cast<sockaddr*>(&senderAddress),
|
receptionFlags, reinterpret_cast<sockaddr*>(&senderAddress),
|
||||||
&senderAddressSize);
|
&senderAddressSize);
|
||||||
if(bytesReceived == SOCKET_ERROR) {
|
if(bytesReceived == SOCKET_ERROR) {
|
||||||
// handle error
|
/* Handle error */
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "TcWinUdpPollingTask::performOperation: Reception"
|
sif::error << "TcWinUdpPollingTask::performOperation: Reception"
|
||||||
" error." << std::endl;
|
" error." << std::endl;
|
||||||
@ -54,9 +54,9 @@ ReturnValue_t TcWinUdpPollingTask::performOperation(uint8_t opCode) {
|
|||||||
handleReadError();
|
handleReadError();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_WIRETAPPING_ENABLED == 1
|
||||||
//sif::debug << "TcWinUdpPollingTask::performOperation: " << bytesReceived
|
sif::debug << "TcWinUdpPollingTask::performOperation: " << bytesReceived <<
|
||||||
// << " bytes received" << std::endl;
|
" bytes received" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ReturnValue_t result = handleSuccessfullTcRead(bytesReceived);
|
ReturnValue_t result = handleSuccessfullTcRead(bytesReceived);
|
||||||
@ -74,12 +74,14 @@ ReturnValue_t TcWinUdpPollingTask::handleSuccessfullTcRead(size_t bytesRead) {
|
|||||||
store_address_t storeId;
|
store_address_t storeId;
|
||||||
ReturnValue_t result = tcStore->addData(&storeId,
|
ReturnValue_t result = tcStore->addData(&storeId,
|
||||||
receptionBuffer.data(), bytesRead);
|
receptionBuffer.data(), bytesRead);
|
||||||
// arrayprinter::print(receptionBuffer.data(), bytesRead);
|
#if FSFW_UDP_WIRETAPPING_ENABLED == 1
|
||||||
|
arrayprinter::print(receptionBuffer.data(), bytesRead);#
|
||||||
|
#endif
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "TcSerialPollingTask::transferPusToSoftwareBus: Data "
|
sif::warning<< "TcSerialPollingTask::transferPusToSoftwareBus: Data "
|
||||||
"storage failed" << std::endl;
|
"storage failed" << std::endl;
|
||||||
sif::error << "Packet size: " << bytesRead << std::endl;
|
sif::warning << "Packet size: " << bytesRead << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
@ -89,8 +91,7 @@ ReturnValue_t TcWinUdpPollingTask::handleSuccessfullTcRead(size_t bytesRead) {
|
|||||||
result = MessageQueueSenderIF::sendMessage(targetTcDestination, &message);
|
result = MessageQueueSenderIF::sendMessage(targetTcDestination, &message);
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "Serial Polling: Sending message to queue failed"
|
sif::warning << "Serial Polling: Sending message to queue failed" << std::endl;
|
||||||
<< std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
tcStore->deleteData(storeId);
|
tcStore->deleteData(storeId);
|
||||||
}
|
}
|
||||||
@ -117,9 +118,9 @@ ReturnValue_t TcWinUdpPollingTask::initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
serverUdpSocket = tmtcBridge->serverSocket;
|
serverUdpSocket = tmtcBridge->serverSocket;
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_WIRETAPPING_ENABLED == 1
|
||||||
//sif::info << "TcWinUdpPollingTask::initialize: Server UDP socket "
|
sif::info << "TcWinUdpPollingTask::initialize: Server UDP socket " << serverUdpSocket <<
|
||||||
// << serverUdpSocket << std::endl;
|
std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
//! Debugging preprocessor define.
|
||||||
|
#define FSFW_UDP_RCV_WIRETAPPING_ENABLED 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This class can be used to implement the polling of a Unix socket,
|
* @brief This class can be used to implement the polling of a Unix socket,
|
||||||
* using UDP for now.
|
* using UDP for now.
|
||||||
@ -51,8 +54,7 @@ private:
|
|||||||
//! Reception flags: https://linux.die.net/man/2/recvfrom.
|
//! Reception flags: https://linux.die.net/man/2/recvfrom.
|
||||||
int receptionFlags = 0;
|
int receptionFlags = 0;
|
||||||
|
|
||||||
//! Server socket, which is member of TMTC bridge and is assigned in
|
//! Server socket, which is member of TMTC bridge and is assigned in constructor
|
||||||
//! constructor
|
|
||||||
SOCKET serverUdpSocket = 0;
|
SOCKET serverUdpSocket = 0;
|
||||||
|
|
||||||
std::vector<uint8_t> receptionBuffer;
|
std::vector<uint8_t> receptionBuffer;
|
||||||
|
@ -85,13 +85,12 @@ TmTcWinUdpBridge::~TmTcWinUdpBridge() {
|
|||||||
ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
|
ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
|
|
||||||
//clientAddress.sin_addr.s_addr = htons(INADDR_ANY);
|
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
|
||||||
//clientAddressLen = sizeof(serverAddress);
|
clientAddress.sin_addr.s_addr = htons(INADDR_ANY);
|
||||||
|
clientAddressLen = sizeof(serverAddress);
|
||||||
// char ipAddress [15];
|
char ipAddress [15];
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,
|
||||||
// sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,
|
&clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
|
||||||
// &clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ssize_t bytesSent = sendto(serverSocket,
|
ssize_t bytesSent = sendto(serverSocket,
|
||||||
@ -104,9 +103,9 @@ ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
|
|||||||
#endif
|
#endif
|
||||||
handleSendError();
|
handleSendError();
|
||||||
}
|
}
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
|
||||||
// sif::debug << "TmTcUnixUdpBridge::sendTm: " << bytesSent << " bytes were"
|
sif::debug << "TmTcUnixUdpBridge::sendTm: " << bytesSent << " bytes were"
|
||||||
// " sent." << std::endl;
|
" sent." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
@ -114,16 +113,16 @@ ReturnValue_t TmTcWinUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
|
|||||||
void TmTcWinUdpBridge::checkAndSetClientAddress(sockaddr_in newAddress) {
|
void TmTcWinUdpBridge::checkAndSetClientAddress(sockaddr_in newAddress) {
|
||||||
MutexHelper lock(mutex, MutexIF::TimeoutType::WAITING, 10);
|
MutexHelper lock(mutex, MutexIF::TimeoutType::WAITING, 10);
|
||||||
|
|
||||||
// char ipAddress [15];
|
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
char ipAddress [15];
|
||||||
// sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,
|
sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,
|
||||||
// &newAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
|
&newAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
|
||||||
// sif::debug << "IP Address Old: " << inet_ntop(AF_INET,
|
sif::debug << "IP Address Old: " << inet_ntop(AF_INET,
|
||||||
// &clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
|
&clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
|
||||||
#endif
|
#endif
|
||||||
registerCommConnect();
|
registerCommConnect();
|
||||||
|
|
||||||
// Set new IP address if it has changed.
|
/* Set new IP address if it has changed. */
|
||||||
if(clientAddress.sin_addr.s_addr != newAddress.sin_addr.s_addr) {
|
if(clientAddress.sin_addr.s_addr != newAddress.sin_addr.s_addr) {
|
||||||
clientAddress.sin_addr.s_addr = newAddress.sin_addr.s_addr;
|
clientAddress.sin_addr.s_addr = newAddress.sin_addr.s_addr;
|
||||||
clientAddressLen = sizeof(clientAddress);
|
clientAddressLen = sizeof(clientAddress);
|
||||||
@ -135,8 +134,8 @@ void TmTcWinUdpBridge::handleSocketError() {
|
|||||||
switch(errCode) {
|
switch(errCode) {
|
||||||
case(WSANOTINITIALISED): {
|
case(WSANOTINITIALISED): {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::info << "TmTcWinUdpBridge::handleSocketError: WSANOTINITIALISED: "
|
sif::warning << "TmTcWinUdpBridge::handleSocketError: WSANOTINITIALISED: WSAStartup"
|
||||||
<< "WSAStartup(...) call necessary" << std::endl;
|
" call necessary" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -146,8 +145,7 @@ void TmTcWinUdpBridge::handleSocketError() {
|
|||||||
windows-sockets-error-codes-2
|
windows-sockets-error-codes-2
|
||||||
*/
|
*/
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::info << "TmTcWinUdpBridge::handleSocketError: Error code: "
|
sif::warning << "TmTcWinUdpBridge::handleSocketError: Error code: " << errCode << std::endl;
|
||||||
<< errCode << std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,13 @@
|
|||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
//! Debugging preprocessor define.
|
||||||
|
#define FSFW_UDP_SEND_WIRETAPPING_ENABLED 0
|
||||||
|
|
||||||
class TmTcWinUdpBridge: public TmTcBridge {
|
class TmTcWinUdpBridge: public TmTcBridge {
|
||||||
friend class TcWinUdpPollingTask;
|
friend class TcWinUdpPollingTask;
|
||||||
public:
|
public:
|
||||||
// The ports chosen here should not be used by any other process.
|
/* The ports chosen here should not be used by any other process. */
|
||||||
static constexpr uint16_t DEFAULT_UDP_SERVER_PORT = 7301;
|
static constexpr uint16_t DEFAULT_UDP_SERVER_PORT = 7301;
|
||||||
static constexpr uint16_t DEFAULT_UDP_CLIENT_PORT = 7302;
|
static constexpr uint16_t DEFAULT_UDP_CLIENT_PORT = 7302;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user