33 * All rights reserved.
44 *
55 ******************************************************************************/
6- #include "encap.h"
6+ #include "enet_encap/ encap.h"
77
88#include <stdbool.h>
99#include <stdlib.h>
1010#include <string.h>
1111
12- #include "cipcommon.h"
13- #include "cipconnectionmanager.h"
14- #include "cipidentity.h"
15- #include "cipmessagerouter.h"
16- #include "ciptcpipinterface.h"
17- #include "cpf.h"
18- #include "endianconv.h"
19- #include "generic_networkhandler.h"
20- #include "opener_api.h"
21- #include "opener_error.h"
12+ #include "cip/ cipcommon.h"
13+ #include "cip/ cipconnectionmanager.h"
14+ #include "cip/ cipidentity.h"
15+ #include "cip/ cipmessagerouter.h"
16+ #include "cip/ ciptcpipinterface.h"
17+ #include "enet_encap/ cpf.h"
18+ #include "enet_encap/ endianconv.h"
19+ #include "ports/ generic_networkhandler.h"
20+ #include "api/ opener_api.h"
21+ #include "ports/ opener_error.h"
2222#include "opener_user_conf.h"
23- #include "socket_timer.h"
24- #include "trace.h"
23+ #include "ports/ socket_timer.h"
24+ #include "core/ trace.h"
2525
2626/* IP address data taken from TCPIPInterfaceObject*/
2727const EipUint16 kSupportedProtocolVersion =
@@ -581,12 +581,12 @@ void HandleReceivedRegisterSessionCommand(
581581
582582 if (kSessionStatusInvalid != session_index ) {
583583 session_index = GetFreeSessionIndex ();
584- if (kSessionStatusInvalid ==
585- session_index ) /* no more sessions available */
586- {
584+ if (kSessionStatusInvalid == session_index ) {
585+ // no more sessions available
587586 encapsulation_protocol_status =
588587 kEncapsulationProtocolInsufficientMemory ;
589- } else { /* successful session registered */
588+ } else {
589+ // successful session registered
590590 SocketTimer * socket_timer = SocketTimerArrayGetEmptySocketTimer (
591591 g_timestamps , OPENER_NUMBER_OF_SUPPORTED_SESSIONS );
592592 SocketTimerSetSocket (socket_timer , socket );
@@ -597,7 +597,8 @@ void HandleReceivedRegisterSessionCommand(
597597 encapsulation_protocol_status = kEncapsulationProtocolSuccess ;
598598 }
599599 }
600- } else { /* protocol not supported */
600+ } else {
601+ // protocol not supported
601602 encapsulation_protocol_status = kEncapsulationProtocolUnsupportedProtocol ;
602603 }
603604
@@ -631,7 +632,7 @@ EipStatus HandleReceivedUnregisterSessionCommand(
631632 }
632633 }
633634
634- /* no such session registered */
635+ // no such session registered
635636 GenerateEncapsulationHeader (receive_data ,
636637 0 ,
637638 receive_data -> session_handle ,
@@ -649,42 +650,35 @@ EipStatus HandleReceivedSendUnitDataCommand(
649650 const EncapsulationData * const receive_data ,
650651 const struct sockaddr * const originator_address ,
651652 ENIPMessage * const outgoing_message ) {
652- EipStatus return_value = kEipStatusOkSend ;
653- /*EipStatus*/ return_value =
654- kEipStatusOk ; /* TODO: Shouldn't this be kEipStatusOk cause we must not
655- send any response if data_length < 6? */
653+ // EipStatus return_value = kEipStatusOkSend;
654+ // TODO(MartinMelikMerkumians): Shouldn't this be kEipStatusOk cause we must not send any response if data_length < 6?
655+ EipStatus return_value = kEipStatusOk ;
656656
657657 if (receive_data -> data_length >= 6 ) {
658- /* Command specific data UDINT .. Interface Handle, UINT .. Timeout, CPF
659- * packets */
660- /* don't use the data yet */
661- GetDintFromMessage (
662- (const EipUint8 * * const )& receive_data
663- -> current_communication_buffer_position ); /* skip over null
664- interface handle*/
665- GetIntFromMessage (
666- (const EipUint8 * * const )& receive_data
667- -> current_communication_buffer_position ); /* skip over unused
668- timeout value*/
669- ((EncapsulationData * const )receive_data )-> data_length -=
670- 6 ; /* the rest is in CPF format*/
671-
672- if (kSessionStatusValid ==
673- CheckRegisteredSessions (
674- receive_data )) /* see if the EIP session is registered*/
675- {
658+ // Command specific data UDINT .. Interface Handle, UINT .. Timeout, CPF packets
659+ // don't use the data yet
660+
661+ // skip over null interface handle
662+ GetDintFromMessage ((const EipUint8 * * const )& receive_data -> current_communication_buffer_position );
663+ // skip over unused timeout value
664+ GetIntFromMessage ((const EipUint8 * * const )& receive_data -> current_communication_buffer_position );
665+ // the rest is in CPF format
666+ ((EncapsulationData * const )receive_data )-> data_length -= 6 ;
667+
668+ // see if the EIP session is registered
669+ if (kSessionStatusValid == CheckRegisteredSessions (receive_data )) {
676670 return_value = NotifyConnectedCommonPacketFormat (
677671 receive_data , originator_address , outgoing_message );
678- } else { /* received a package with non registered session handle */
672+ } else {
673+ // received a package with non registered session handle
679674 InitializeENIPMessage (outgoing_message );
680675 GenerateEncapsulationHeader (receive_data ,
681676 0 ,
682677 receive_data -> session_handle ,
683678 kEncapsulationProtocolInvalidSessionHandle ,
684679 outgoing_message );
685- return_value =
686- kEipStatusOkSend ; /* TODO: Needs to be here if line with first TODO of
687- this function is adjusted. */
680+ // TODO(MartinMelikMerkumians): Needs to be here if line with first TODO of this function is adjusted.
681+ return_value = kEipStatusOkSend ;
688682 }
689683 }
690684 return return_value ;
@@ -702,30 +696,23 @@ EipStatus HandleReceivedSendRequestResponseDataCommand(
702696 const EncapsulationData * const receive_data ,
703697 const struct sockaddr * const originator_address ,
704698 ENIPMessage * const outgoing_message ) {
705- EipStatus return_value = kEipStatusOkSend ;
706- /* EipStatus*/ return_value =
707- kEipStatusOk ; /* TODO: Shouldn't this be kEipStatusOk cause we must not
708- send any response if data_length < 6? */
699+ // EipStatus return_value = kEipStatusOkSend;
700+ // TODO(MartinMelikMerkumians): Shouldn't this be kEipStatusOk cause we must not send any response if data_length < 6?
701+ EipStatus = kEipStatusOk ;
709702
710703 if (receive_data -> data_length >= 6 ) {
711- /* Command specific data UDINT .. Interface Handle, UINT .. Timeout, CPF
712- * packets */
713- /* don't use the data yet */
714- GetDintFromMessage (
715- (const EipUint8 * * const )& receive_data
716- -> current_communication_buffer_position ); /* skip over null
717- interface handle*/
718- GetIntFromMessage (
719- (const EipUint8 * * const )& receive_data
720- -> current_communication_buffer_position ); /* skip over unused
721- timeout value*/
722- ((EncapsulationData * const )receive_data )-> data_length -=
723- 6 ; /* the rest is in CPF format*/
724-
725- if (kSessionStatusValid ==
726- CheckRegisteredSessions (
727- receive_data )) /* see if the EIP session is registered*/
728- {
704+ // Command specific data UDINT .. Interface Handle, UINT .. Timeout, CPF packets
705+ // don't use the data yet
706+
707+ // skip over null interface handle
708+ GetDintFromMessage ((const EipUint8 * * const )& receive_data -> current_communication_buffer_position );
709+ // skip over unused timeout value
710+ GetIntFromMessage ((const EipUint8 * * const )& receive_data -> current_communication_buffer_position );
711+ // the rest is in CPF format
712+ ((EncapsulationData * const )receive_data )-> data_length -= 6 ;
713+
714+ // see if the EIP session is registered
715+ if (kSessionStatusValid == CheckRegisteredSessions (receive_data )) {
729716 return_value = NotifyCommonPacketFormat (
730717 receive_data , originator_address , outgoing_message );
731718 } else { /* received a package with non registered session handle */
@@ -735,9 +722,8 @@ EipStatus HandleReceivedSendRequestResponseDataCommand(
735722 receive_data -> session_handle ,
736723 kEncapsulationProtocolInvalidSessionHandle ,
737724 outgoing_message );
738- return_value =
739- kEipStatusOkSend ; /* TODO: Needs to be here if line with first TODO of
740- this function is adjusted. */
725+ // TODO(MartinMelikMerkumians): Needs to be here if line with first TODO of this function is adjusted.
726+ return_value = kEipStatusOkSend ;
741727 }
742728 }
743729 return return_value ;
0 commit comments