|
|
@@ -1,6 +1,6 @@
|
|
|
/*******************************************************************************
|
|
|
* Copyright (c) 2009, Rockwell Automation, Inc.
|
|
|
- * All rights reserved.
|
|
|
+ * All rights reserved.
|
|
|
*
|
|
|
******************************************************************************/
|
|
|
#include <string.h>
|
|
|
@@ -66,7 +66,8 @@ typedef enum {
|
|
|
|
|
|
#define ENCAP_NUMBER_OF_SUPPORTED_DELAYED_ENCAP_MESSAGES 2 /**< According to EIP spec at least 2 delayed message requests should be supported */
|
|
|
|
|
|
-#define ENCAP_MAX_DELAYED_ENCAP_MESSAGE_SIZE (ENCAPSULATION_HEADER_LENGTH + 39 + sizeof(OPENER_DEVICE_NAME)) /* currently we only have the size of an encapsulation message */
|
|
|
+#define ENCAP_MAX_DELAYED_ENCAP_MESSAGE_SIZE ( ENCAPSULATION_HEADER_LENGTH + \
|
|
|
+ 39 + sizeof(OPENER_DEVICE_NAME) ) /* currently we only have the size of an encapsulation message */
|
|
|
|
|
|
/* Encapsulation layer data */
|
|
|
|
|
|
@@ -83,7 +84,8 @@ EncapsulationInterfaceInformation g_interface_information;
|
|
|
|
|
|
int g_registered_sessions[OPENER_NUMBER_OF_SUPPORTED_SESSIONS];
|
|
|
|
|
|
-DelayedEncapsulationMessage g_delayed_encapsulation_messages[ENCAP_NUMBER_OF_SUPPORTED_DELAYED_ENCAP_MESSAGES];
|
|
|
+DelayedEncapsulationMessage g_delayed_encapsulation_messages[
|
|
|
+ ENCAP_NUMBER_OF_SUPPORTED_DELAYED_ENCAP_MESSAGES];
|
|
|
|
|
|
/*** private functions ***/
|
|
|
void HandleReceivedListServicesCommand(EncapsulationData *receive_data);
|
|
|
@@ -100,12 +102,12 @@ void HandleReceivedRegisterSessionCommand(int socket,
|
|
|
EncapsulationData *receive_data);
|
|
|
|
|
|
EipStatus HandleReceivedUnregisterSessionCommand(
|
|
|
- EncapsulationData *receive_data);
|
|
|
+ EncapsulationData *receive_data);
|
|
|
|
|
|
EipStatus HandleReceivedSendUnitDataCommand(EncapsulationData *receive_data);
|
|
|
|
|
|
EipStatus HandleReceivedSendRequestResponseDataCommand(
|
|
|
- EncapsulationData *receive_data);
|
|
|
+ EncapsulationData *receive_data);
|
|
|
|
|
|
int GetFreeSessionIndex(void);
|
|
|
|
|
|
@@ -136,7 +138,8 @@ void EncapsulationInit(void) {
|
|
|
g_registered_sessions[i] = kEipInvalidSocket;
|
|
|
}
|
|
|
|
|
|
- for (unsigned int i = 0; i < ENCAP_NUMBER_OF_SUPPORTED_DELAYED_ENCAP_MESSAGES; i++) {
|
|
|
+ for (unsigned int i = 0; i < ENCAP_NUMBER_OF_SUPPORTED_DELAYED_ENCAP_MESSAGES;
|
|
|
+ i++) {
|
|
|
g_delayed_encapsulation_messages[i].socket = -1;
|
|
|
}
|
|
|
|
|
|
@@ -146,12 +149,14 @@ void EncapsulationInit(void) {
|
|
|
g_interface_information.length = sizeof(g_interface_information);
|
|
|
g_interface_information.encapsulation_protocol_version = 1;
|
|
|
g_interface_information.capability_flags = kCapabilityFlagsCipTcp
|
|
|
- | kCapabilityFlagsCipUdpClass0or1;
|
|
|
- strcpy((char *) g_interface_information.name_of_service, "Communications");
|
|
|
+ | kCapabilityFlagsCipUdpClass0or1;
|
|
|
+ strcpy( (char *) g_interface_information.name_of_service, "Communications" );
|
|
|
}
|
|
|
|
|
|
-int HandleReceivedExplictTcpData(int socket, EipUint8 *buffer,
|
|
|
- unsigned int length, int *remaining_bytes) {
|
|
|
+int HandleReceivedExplictTcpData(int socket,
|
|
|
+ EipUint8 *buffer,
|
|
|
+ unsigned int length,
|
|
|
+ int *remaining_bytes) {
|
|
|
EipStatus return_value = kEipStatusOk;
|
|
|
EncapsulationData encapsulation_data;
|
|
|
/* eat the encapsulation header*/
|
|
|
@@ -192,12 +197,12 @@ int HandleReceivedExplictTcpData(int socket, EipUint8 *buffer,
|
|
|
|
|
|
case (kEncapsulationCommandUnregisterSession):
|
|
|
return_value = HandleReceivedUnregisterSessionCommand(
|
|
|
- &encapsulation_data);
|
|
|
+ &encapsulation_data);
|
|
|
break;
|
|
|
|
|
|
case (kEncapsulationCommandSendRequestReplyData):
|
|
|
return_value = HandleReceivedSendRequestResponseDataCommand(
|
|
|
- &encapsulation_data);
|
|
|
+ &encapsulation_data);
|
|
|
break;
|
|
|
|
|
|
case (kEncapsulationCommandSendUnitData):
|
|
|
@@ -219,16 +224,19 @@ int HandleReceivedExplictTcpData(int socket, EipUint8 *buffer,
|
|
|
return return_value;
|
|
|
}
|
|
|
|
|
|
-int HandleReceivedExplictUdpData(int socket, struct sockaddr_in *from_address,
|
|
|
- EipUint8 *buffer, unsigned int buffer_length,
|
|
|
- int *number_of_remaining_bytes, int unicast) {
|
|
|
+int HandleReceivedExplictUdpData(int socket,
|
|
|
+ struct sockaddr_in *from_address,
|
|
|
+ EipUint8 *buffer,
|
|
|
+ unsigned int buffer_length,
|
|
|
+ int *number_of_remaining_bytes,
|
|
|
+ int unicast) {
|
|
|
EipStatus status = kEipStatusOk;
|
|
|
EncapsulationData encapsulation_data;
|
|
|
/* eat the encapsulation header*/
|
|
|
/* the structure contains a pointer to the encapsulated data*/
|
|
|
/* returns how many bytes are left after the encapsulated data*/
|
|
|
*number_of_remaining_bytes = CreateEncapsulationStructure(
|
|
|
- buffer, buffer_length, &encapsulation_data);
|
|
|
+ buffer, buffer_length, &encapsulation_data);
|
|
|
|
|
|
if (kEncapsulationHeaderOptionsFlag == encapsulation_data.options) /*TODO generate appropriate error response*/
|
|
|
{
|
|
|
@@ -244,21 +252,21 @@ int HandleReceivedExplictUdpData(int socket, struct sockaddr_in *from_address,
|
|
|
break;
|
|
|
|
|
|
case (kEncapsulationCommandListIdentity):
|
|
|
- if(unicast == true) {
|
|
|
- HandleReceivedListIdentityCommandTcp(&encapsulation_data);
|
|
|
- }
|
|
|
- else {
|
|
|
- HandleReceivedListIdentityCommandUdp(socket, from_address,
|
|
|
- &encapsulation_data);
|
|
|
- status = kEipStatusOk;
|
|
|
- }/* as the response has to be delayed do not send it now */
|
|
|
+ if(unicast == true) {
|
|
|
+ HandleReceivedListIdentityCommandTcp(&encapsulation_data);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ HandleReceivedListIdentityCommandUdp(socket, from_address,
|
|
|
+ &encapsulation_data);
|
|
|
+ status = kEipStatusOk;
|
|
|
+ } /* as the response has to be delayed do not send it now */
|
|
|
break;
|
|
|
|
|
|
case (kEncapsulationCommandListInterfaces):
|
|
|
HandleReceivedListInterfacesCommand(&encapsulation_data);
|
|
|
break;
|
|
|
|
|
|
- /* The following commands are not to be sent via UDP */
|
|
|
+ /* The following commands are not to be sent via UDP */
|
|
|
case (kEncapsulationCommandNoOperation):
|
|
|
case (kEncapsulationCommandRegisterSession):
|
|
|
case (kEncapsulationCommandUnregisterSession):
|
|
|
@@ -295,33 +303,33 @@ int EncapsulateData(const EncapsulationData *const send_data) {
|
|
|
*/
|
|
|
void HandleReceivedListServicesCommand(EncapsulationData *receive_data) {
|
|
|
EipUint8 *communication_buffer = receive_data
|
|
|
- ->current_communication_buffer_position;
|
|
|
+ ->current_communication_buffer_position;
|
|
|
|
|
|
receive_data->data_length = g_interface_information.length + 2;
|
|
|
|
|
|
/* copy Interface data to msg for sending */
|
|
|
AddIntToMessage(1, &communication_buffer);
|
|
|
AddIntToMessage(g_interface_information.type_code, &communication_buffer);
|
|
|
- AddIntToMessage((EipUint16) (g_interface_information.length - 4),
|
|
|
- &communication_buffer);
|
|
|
+ AddIntToMessage( (EipUint16) (g_interface_information.length - 4),
|
|
|
+ &communication_buffer );
|
|
|
AddIntToMessage(g_interface_information.encapsulation_protocol_version,
|
|
|
&communication_buffer);
|
|
|
AddIntToMessage(g_interface_information.capability_flags,
|
|
|
&communication_buffer);
|
|
|
- memcpy(communication_buffer, g_interface_information.name_of_service,
|
|
|
- sizeof(g_interface_information.name_of_service));
|
|
|
+ memcpy( communication_buffer, g_interface_information.name_of_service,
|
|
|
+ sizeof(g_interface_information.name_of_service) );
|
|
|
}
|
|
|
|
|
|
void HandleReceivedListInterfacesCommand(EncapsulationData *receive_data) {
|
|
|
EipUint8 *communication_buffer = receive_data
|
|
|
- ->current_communication_buffer_position;
|
|
|
+ ->current_communication_buffer_position;
|
|
|
receive_data->data_length = 2;
|
|
|
AddIntToMessage(0x0000, &communication_buffer); /* copy Interface data to msg for sending */
|
|
|
}
|
|
|
|
|
|
-void HandleReceivedListIdentityCommandTcp(EncapsulationData * receive_data) {
|
|
|
+void HandleReceivedListIdentityCommandTcp(EncapsulationData *receive_data) {
|
|
|
receive_data->data_length = EncapsulateListIdentyResponseMessage(
|
|
|
- receive_data->current_communication_buffer_position);
|
|
|
+ receive_data->current_communication_buffer_position);
|
|
|
}
|
|
|
|
|
|
void HandleReceivedListIdentityCommandUdp(int socket,
|
|
|
@@ -329,7 +337,8 @@ void HandleReceivedListIdentityCommandUdp(int socket,
|
|
|
EncapsulationData *receive_data) {
|
|
|
DelayedEncapsulationMessage *delayed_message_buffer = NULL;
|
|
|
|
|
|
- for (unsigned int i = 0; i < ENCAP_NUMBER_OF_SUPPORTED_DELAYED_ENCAP_MESSAGES; i++) {
|
|
|
+ for (unsigned int i = 0; i < ENCAP_NUMBER_OF_SUPPORTED_DELAYED_ENCAP_MESSAGES;
|
|
|
+ i++) {
|
|
|
if (kEipInvalidSocket == g_delayed_encapsulation_messages[i].socket) {
|
|
|
delayed_message_buffer = &(g_delayed_encapsulation_messages[i]);
|
|
|
break;
|
|
|
@@ -338,8 +347,8 @@ void HandleReceivedListIdentityCommandUdp(int socket,
|
|
|
|
|
|
if (NULL != delayed_message_buffer) {
|
|
|
delayed_message_buffer->socket = socket;
|
|
|
- memcpy((&delayed_message_buffer->receiver), from_address,
|
|
|
- sizeof(struct sockaddr_in));
|
|
|
+ memcpy( (&delayed_message_buffer->receiver), from_address,
|
|
|
+ sizeof(struct sockaddr_in) );
|
|
|
|
|
|
DetermineDelayTime(receive_data->communication_buffer_start,
|
|
|
delayed_message_buffer);
|
|
|
@@ -349,7 +358,7 @@ void HandleReceivedListIdentityCommandUdp(int socket,
|
|
|
ENCAPSULATION_HEADER_LENGTH);
|
|
|
|
|
|
delayed_message_buffer->message_size = EncapsulateListIdentyResponseMessage(
|
|
|
- &(delayed_message_buffer->message[ENCAPSULATION_HEADER_LENGTH]));
|
|
|
+ &(delayed_message_buffer->message[ENCAPSULATION_HEADER_LENGTH]) );
|
|
|
|
|
|
EipUint8 *communication_buffer = delayed_message_buffer->message + 2;
|
|
|
AddIntToMessage(delayed_message_buffer->message_size,
|
|
|
@@ -361,7 +370,7 @@ void HandleReceivedListIdentityCommandUdp(int socket,
|
|
|
int EncapsulateListIdentyResponseMessage(EipByte *const communication_buffer) {
|
|
|
EipUint8 *communication_buffer_runner = communication_buffer;
|
|
|
|
|
|
- AddIntToMessage(1, &(communication_buffer_runner)); /* Item count: one item */
|
|
|
+ AddIntToMessage( 1, &(communication_buffer_runner) ); /* Item count: one item */
|
|
|
AddIntToMessage(kCipItemIdListIdentityResponse, &communication_buffer_runner);
|
|
|
|
|
|
EipByte *id_length_buffer = communication_buffer_runner;
|
|
|
@@ -399,14 +408,15 @@ void DetermineDelayTime(EipByte *buffer_start,
|
|
|
DelayedEncapsulationMessage *delayed_message_buffer) {
|
|
|
|
|
|
buffer_start += 12; /* start of the sender context */
|
|
|
- EipUint16 maximum_delay_time = GetIntFromMessage((const EipUint8 **const)&buffer_start);
|
|
|
+ EipUint16 maximum_delay_time = GetIntFromMessage(
|
|
|
+ (const EipUint8 **const)&buffer_start );
|
|
|
|
|
|
if (0 == maximum_delay_time) {
|
|
|
maximum_delay_time = kListIdentityDefaultDelayTime;
|
|
|
} else if (kListIdentityMinimumDelayTime > maximum_delay_time) { /* if maximum_delay_time is between 1 and 500ms set it to 500ms */
|
|
|
maximum_delay_time = kListIdentityMinimumDelayTime;
|
|
|
}
|
|
|
- delayed_message_buffer->time_out = (maximum_delay_time * rand()) / RAND_MAX; /* Sets delay time between 0 and maximum_delay_time */
|
|
|
+ delayed_message_buffer->time_out = ( maximum_delay_time * rand() ) / RAND_MAX; /* Sets delay time between 0 and maximum_delay_time */
|
|
|
}
|
|
|
|
|
|
/* @brief Check supported protocol, generate session handle, send replay back to originator.
|
|
|
@@ -418,13 +428,13 @@ void HandleReceivedRegisterSessionCommand(int socket,
|
|
|
int session_index = 0;
|
|
|
const EipUint8 *receive_data_buffer = NULL;
|
|
|
EipUint16 protocol_version = GetIntFromMessage(
|
|
|
- (const EipUint8 **const)&receive_data->current_communication_buffer_position);
|
|
|
+ (const EipUint8 **const)&receive_data->current_communication_buffer_position);
|
|
|
EipUint16 nOptionFlag = GetIntFromMessage(
|
|
|
- (const EipUint8 **const)&receive_data->current_communication_buffer_position);
|
|
|
+ (const EipUint8 **const)&receive_data->current_communication_buffer_position);
|
|
|
|
|
|
/* check if requested protocol version is supported and the register session option flag is zero*/
|
|
|
- if ((0 < protocol_version) && (protocol_version <= kSupportedProtocolVersion)
|
|
|
- && (0 == nOptionFlag)) { /*Option field should be zero*/
|
|
|
+ if ( (0 < protocol_version) && (protocol_version <= kSupportedProtocolVersion)
|
|
|
+ && (0 == nOptionFlag) ) { /*Option field should be zero*/
|
|
|
/* check if the socket has already a session open */
|
|
|
for (int i = 0; i < OPENER_NUMBER_OF_SUPPORTED_SESSIONS; ++i) {
|
|
|
if (g_registered_sessions[i] == socket) {
|
|
|
@@ -433,8 +443,10 @@ void HandleReceivedRegisterSessionCommand(int socket,
|
|
|
receive_data->status = kEncapsulationProtocolInvalidCommand;
|
|
|
session_index = kSessionStatusInvalid;
|
|
|
receive_data_buffer =
|
|
|
- &receive_data->communication_buffer_start[kEncapsulationHeaderSessionHandlePosition];
|
|
|
- AddDintToMessage(receive_data->session_handle, (EipUint8 **const)&receive_data_buffer); /*EncapsulateData will not update the session handle so we have to do it here by hand*/
|
|
|
+ &receive_data->communication_buffer_start[
|
|
|
+ kEncapsulationHeaderSessionHandlePosition];
|
|
|
+ AddDintToMessage(receive_data->session_handle,
|
|
|
+ (EipUint8 **const)&receive_data_buffer); /*EncapsulateData will not update the session handle so we have to do it here by hand*/
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -449,8 +461,10 @@ void HandleReceivedRegisterSessionCommand(int socket,
|
|
|
receive_data->session_handle = session_index + 1;
|
|
|
receive_data->status = kEncapsulationProtocolSuccess;
|
|
|
receive_data_buffer =
|
|
|
- &receive_data->communication_buffer_start[kEncapsulationHeaderSessionHandlePosition];
|
|
|
- AddDintToMessage(receive_data->session_handle, (EipUint8 **const)&receive_data_buffer); /*EncapsulateData will not update the session handle so we have to do it here by hand*/
|
|
|
+ &receive_data->communication_buffer_start[
|
|
|
+ kEncapsulationHeaderSessionHandlePosition];
|
|
|
+ AddDintToMessage(receive_data->session_handle,
|
|
|
+ (EipUint8 **const)&receive_data_buffer); /*EncapsulateData will not update the session handle so we have to do it here by hand*/
|
|
|
}
|
|
|
}
|
|
|
} else { /* protocol not supported */
|
|
|
@@ -465,10 +479,11 @@ void HandleReceivedRegisterSessionCommand(int socket,
|
|
|
* pa_S_ReceiveData pointer to unregister session request with corresponding socket handle.
|
|
|
*/
|
|
|
EipStatus HandleReceivedUnregisterSessionCommand(
|
|
|
- EncapsulationData *receive_data) {
|
|
|
+ EncapsulationData *receive_data) {
|
|
|
|
|
|
- if ((0 < receive_data->session_handle)
|
|
|
- && (receive_data->session_handle <= OPENER_NUMBER_OF_SUPPORTED_SESSIONS)) {
|
|
|
+ if ( (0 < receive_data->session_handle)
|
|
|
+ && (receive_data->session_handle <=
|
|
|
+ OPENER_NUMBER_OF_SUPPORTED_SESSIONS) ) {
|
|
|
int i = receive_data->session_handle - 1;
|
|
|
if (kEipInvalidSocket != g_registered_sessions[i]) {
|
|
|
IApp_CloseSocket_tcp(g_registered_sessions[i]);
|
|
|
@@ -493,16 +508,18 @@ EipStatus HandleReceivedSendUnitDataCommand(EncapsulationData *receive_data) {
|
|
|
if (receive_data->data_length >= 6) {
|
|
|
/* Command specific data UDINT .. Interface Handle, UINT .. Timeout, CPF packets */
|
|
|
/* don't use the data yet */
|
|
|
- GetDintFromMessage((const EipUint8 **const)&receive_data->current_communication_buffer_position); /* skip over null interface handle*/
|
|
|
- GetIntFromMessage((const EipUint8 **const)&receive_data->current_communication_buffer_position); /* skip over unused timeout value*/
|
|
|
+ GetDintFromMessage(
|
|
|
+ (const EipUint8 **const)&receive_data->current_communication_buffer_position ); /* skip over null interface handle*/
|
|
|
+ GetIntFromMessage(
|
|
|
+ (const EipUint8 **const)&receive_data->current_communication_buffer_position ); /* skip over unused timeout value*/
|
|
|
receive_data->data_length -= 6; /* the rest is in CPF format*/
|
|
|
|
|
|
- if (kSessionStatusValid == CheckRegisteredSessions(receive_data)) /* see if the EIP session is registered*/
|
|
|
+ if ( kSessionStatusValid == CheckRegisteredSessions(receive_data) ) /* see if the EIP session is registered*/
|
|
|
{
|
|
|
send_size =
|
|
|
- NotifyConnectedCommonPacketFormat(
|
|
|
- receive_data,
|
|
|
- &receive_data->communication_buffer_start[ENCAPSULATION_HEADER_LENGTH]);
|
|
|
+ NotifyConnectedCommonPacketFormat(
|
|
|
+ receive_data,
|
|
|
+ &receive_data->communication_buffer_start[ENCAPSULATION_HEADER_LENGTH]);
|
|
|
|
|
|
if (0 < send_size) { /* need to send reply */
|
|
|
receive_data->data_length = send_size;
|
|
|
@@ -519,27 +536,29 @@ EipStatus HandleReceivedSendUnitDataCommand(EncapsulationData *receive_data) {
|
|
|
|
|
|
/** @brief Call UCMM or Message Router if UCMM not implemented.
|
|
|
* @param receive_data Pointer to structure with data and header information.
|
|
|
- * @return status 0 .. success.
|
|
|
- * -1 .. error
|
|
|
+ * @return status 0 .. success.
|
|
|
+ * -1 .. error
|
|
|
*/
|
|
|
EipStatus HandleReceivedSendRequestResponseDataCommand(
|
|
|
- EncapsulationData *receive_data) {
|
|
|
+ EncapsulationData *receive_data) {
|
|
|
EipInt16 send_size = 0;
|
|
|
EipStatus return_value = kEipStatusOkSend;
|
|
|
|
|
|
if (receive_data->data_length >= 6) {
|
|
|
/* Command specific data UDINT .. Interface Handle, UINT .. Timeout, CPF packets */
|
|
|
/* don't use the data yet */
|
|
|
- GetDintFromMessage((const EipUint8 **const)&receive_data->current_communication_buffer_position); /* skip over null interface handle*/
|
|
|
- GetIntFromMessage((const EipUint8 **const)&receive_data->current_communication_buffer_position); /* skip over unused timeout value*/
|
|
|
+ GetDintFromMessage(
|
|
|
+ (const EipUint8 **const)&receive_data->current_communication_buffer_position ); /* skip over null interface handle*/
|
|
|
+ GetIntFromMessage(
|
|
|
+ (const EipUint8 **const)&receive_data->current_communication_buffer_position ); /* skip over unused timeout value*/
|
|
|
receive_data->data_length -= 6; /* the rest is in CPF format*/
|
|
|
|
|
|
- if (kSessionStatusValid == CheckRegisteredSessions(receive_data)) /* see if the EIP session is registered*/
|
|
|
+ if ( kSessionStatusValid == CheckRegisteredSessions(receive_data) ) /* see if the EIP session is registered*/
|
|
|
{
|
|
|
send_size =
|
|
|
- NotifyCommonPacketFormat(
|
|
|
- receive_data,
|
|
|
- &receive_data->communication_buffer_start[ENCAPSULATION_HEADER_LENGTH]);
|
|
|
+ NotifyCommonPacketFormat(
|
|
|
+ receive_data,
|
|
|
+ &receive_data->communication_buffer_start[ENCAPSULATION_HEADER_LENGTH]);
|
|
|
|
|
|
if (send_size >= 0) { /* need to send reply */
|
|
|
receive_data->data_length = send_size;
|
|
|
@@ -556,10 +575,11 @@ EipStatus HandleReceivedSendRequestResponseDataCommand(
|
|
|
|
|
|
/** @brief search for available sessions an return index.
|
|
|
* @return return index of free session in anRegisteredSessions.
|
|
|
- * kInvalidSession .. no free session available
|
|
|
+ * kInvalidSession .. no free session available
|
|
|
*/
|
|
|
int GetFreeSessionIndex(void) {
|
|
|
- for (int session_index = 0; session_index < OPENER_NUMBER_OF_SUPPORTED_SESSIONS; session_index++) {
|
|
|
+ for (int session_index = 0;
|
|
|
+ session_index < OPENER_NUMBER_OF_SUPPORTED_SESSIONS; session_index++) {
|
|
|
if (kEipInvalidSocket == g_registered_sessions[session_index]) {
|
|
|
return session_index;
|
|
|
}
|
|
|
@@ -572,9 +592,9 @@ int GetFreeSessionIndex(void) {
|
|
|
* @param length Length of the data in receive_buffer. Might be more than one message
|
|
|
* @param encapsulation_data structure to which data shall be copied
|
|
|
* @return return difference between bytes in pa_buf an data_length
|
|
|
- * 0 .. full package received
|
|
|
- * >0 .. more than one packet received
|
|
|
- * <0 .. only fragment of data portion received
|
|
|
+ * 0 .. full package received
|
|
|
+ * >0 .. more than one packet received
|
|
|
+ * <0 .. only fragment of data portion received
|
|
|
*/
|
|
|
EipInt16 CreateEncapsulationStructure(const EipUint8 *receive_buffer,
|
|
|
int receive_buffer_length,
|
|
|
@@ -587,19 +607,21 @@ EipInt16 CreateEncapsulationStructure(const EipUint8 *receive_buffer,
|
|
|
|
|
|
receive_buffer += kSenderContextSize;
|
|
|
encapsulation_data->options = GetDintFromMessage(&receive_buffer);
|
|
|
- encapsulation_data->current_communication_buffer_position = (EipUint8 *)receive_buffer;
|
|
|
+ encapsulation_data->current_communication_buffer_position =
|
|
|
+ (EipUint8 *)receive_buffer;
|
|
|
return (receive_buffer_length - ENCAPSULATION_HEADER_LENGTH
|
|
|
- - encapsulation_data->data_length);
|
|
|
+ - encapsulation_data->data_length);
|
|
|
}
|
|
|
|
|
|
/** @brief Check if received package belongs to registered session.
|
|
|
* @param receive_data Received data.
|
|
|
* @return 0 .. Session registered
|
|
|
- * kInvalidSession .. invalid session -> return unsupported command received
|
|
|
+ * kInvalidSession .. invalid session -> return unsupported command received
|
|
|
*/
|
|
|
SessionStatus CheckRegisteredSessions(EncapsulationData *receive_data) {
|
|
|
- if ((0 < receive_data->session_handle)
|
|
|
- && (receive_data->session_handle <= OPENER_NUMBER_OF_SUPPORTED_SESSIONS)) {
|
|
|
+ if ( (0 < receive_data->session_handle)
|
|
|
+ && (receive_data->session_handle <=
|
|
|
+ OPENER_NUMBER_OF_SUPPORTED_SESSIONS) ) {
|
|
|
if (kEipInvalidSocket
|
|
|
!= g_registered_sessions[receive_data->session_handle - 1]) {
|
|
|
return kSessionStatusValid;
|
|
|
@@ -629,10 +651,11 @@ void EncapsulationShutDown(void) {
|
|
|
}
|
|
|
|
|
|
void ManageEncapsulationMessages(const MilliSeconds elapsed_time) {
|
|
|
- for (unsigned int i = 0; i < ENCAP_NUMBER_OF_SUPPORTED_DELAYED_ENCAP_MESSAGES; i++) {
|
|
|
+ for (unsigned int i = 0; i < ENCAP_NUMBER_OF_SUPPORTED_DELAYED_ENCAP_MESSAGES;
|
|
|
+ i++) {
|
|
|
if (kEipInvalidSocket != g_delayed_encapsulation_messages[i].socket) {
|
|
|
g_delayed_encapsulation_messages[i].time_out -=
|
|
|
- elapsed_time;
|
|
|
+ elapsed_time;
|
|
|
if (0 > g_delayed_encapsulation_messages[i].time_out) {
|
|
|
/* If delay is reached or passed, send the UDP message */
|
|
|
SendUdpData(&(g_delayed_encapsulation_messages[i].receiver),
|