diff --git a/source/src/cip/cipcommon.c b/source/src/cip/cipcommon.c index 488c2a783..3b8386ecc 100644 --- a/source/src/cip/cipcommon.c +++ b/source/src/cip/cipcommon.c @@ -102,7 +102,7 @@ EipStatus NotifyClass(const CipClass *RESTRICT const cip_class, CipMessageRouterRequest *const message_router_request, CipMessageRouterResponse *const message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session) { + const CipSessionHandle encapsulation_session) { /* find the instance: if instNr==0, the class is addressed, else find the instance */ CipInstanceNum instance_number = @@ -528,7 +528,7 @@ EipStatus GetAttributeSingle(CipInstance *RESTRICT const instance, CipMessageRouterRequest *const message_router_request, CipMessageRouterResponse *const message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session) { + const CipSessionHandle encapsulation_session) { /* Suppress unused parameter compiler warning. */ (void) originator_address; (void) encapsulation_session; @@ -782,7 +782,7 @@ EipStatus SetAttributeSingle(CipInstance *RESTRICT const instance, CipMessageRouterRequest *const message_router_request, CipMessageRouterResponse *const message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session) { + const CipSessionHandle encapsulation_session) { /* Suppress unused parameter compiler warning. */ (void)originator_address; (void)encapsulation_session; @@ -1074,7 +1074,7 @@ EipStatus GetAttributeAll(CipInstance *instance, CipMessageRouterRequest *message_router_request, CipMessageRouterResponse *message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session) { + const CipSessionHandle encapsulation_session) { /* Suppress unused parameter compiler warning. */ (void)originator_address; (void)encapsulation_session; @@ -1115,7 +1115,7 @@ EipStatus GetAttributeList(CipInstance *instance, CipMessageRouterRequest *message_router_request, CipMessageRouterResponse *message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session) { + const CipSessionHandle encapsulation_session) { /* Suppress unused parameter compiler warning. */ (void)originator_address; (void)encapsulation_session; @@ -1221,7 +1221,7 @@ EipStatus SetAttributeList(CipInstance *instance, CipMessageRouterRequest *message_router_request, CipMessageRouterResponse *message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session) { + const CipSessionHandle encapsulation_session) { /* Suppress unused parameter compiler warning. */ (void)originator_address; (void)encapsulation_session; @@ -1468,7 +1468,7 @@ EipStatus CipCreateService(CipInstance *RESTRICT const instance, CipMessageRouterRequest *const message_router_request, CipMessageRouterResponse *const message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session) { + const CipSessionHandle encapsulation_session) { /* Suppress unused parameter compiler warning. */ (void)originator_address; (void)encapsulation_session; @@ -1510,7 +1510,7 @@ EipStatus CipDeleteService(CipInstance *RESTRICT const instance, CipMessageRouterRequest *const message_router_request, CipMessageRouterResponse *const message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session) { + const CipSessionHandle encapsulation_session) { /* Suppress unused parameter compiler warning. */ (void)originator_address; (void)encapsulation_session; @@ -1573,7 +1573,7 @@ EipStatus CipResetService(CipInstance *RESTRICT const instance, CipMessageRouterRequest *const message_router_request, CipMessageRouterResponse *const message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session) { + const CipSessionHandle encapsulation_session) { /* Suppress unused parameter compiler warning. */ (void)originator_address; (void)encapsulation_session; diff --git a/source/src/cip/cipcommon.h b/source/src/cip/cipcommon.h index 593c62918..14952c56b 100644 --- a/source/src/cip/cipcommon.h +++ b/source/src/cip/cipcommon.h @@ -31,7 +31,7 @@ EipStatus NotifyClass(const CipClass *const RESTRICT cip_class, CipMessageRouterRequest *const message_router_request, CipMessageRouterResponse *const message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session); + const CipSessionHandle encapsulation_session); /** @brief Get largest instance_number present in class instances * @@ -63,7 +63,7 @@ EipStatus GetAttributeSingle( CipMessageRouterResponse *const message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session); + const CipSessionHandle encapsulation_session); void GenerateSetAttributeSingleHeader( const CipMessageRouterRequest *const message_router_request, @@ -89,7 +89,7 @@ EipStatus SetAttributeSingle( CipMessageRouterResponse *const message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session); + const CipSessionHandle encapsulation_session); /** @brief Generic implementation of the GetAttributeAll CIP service * @@ -106,7 +106,7 @@ EipStatus GetAttributeAll(CipInstance *instance, CipMessageRouterRequest *message_router_request, CipMessageRouterResponse *message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session); + const CipSessionHandle encapsulation_session); /** @brief Generic implementation of the GetAttributeList CIP service * @@ -124,7 +124,7 @@ EipStatus GetAttributeList(CipInstance *instance, CipMessageRouterRequest *message_router_request, CipMessageRouterResponse *message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session); + const CipSessionHandle encapsulation_session); /** @brief Generic implementation of the SetAttributeList CIP service * @@ -142,7 +142,7 @@ EipStatus SetAttributeList(CipInstance *instance, CipMessageRouterRequest *message_router_request, CipMessageRouterResponse *message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session); + const CipSessionHandle encapsulation_session); /** @brief Decodes padded EPath * @param epath EPath object to the receiving element @@ -171,7 +171,7 @@ EipStatus CipCreateService( CipMessageRouterResponse *const message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session); + const CipSessionHandle encapsulation_session); /** @brief Generic implementation of the CIP Delete service * @@ -192,7 +192,7 @@ EipStatus CipDeleteService(CipInstance *RESTRICT const instance, CipMessageRouterResponse *const message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session); + const CipSessionHandle encapsulation_session); /** @brief Generic implementation of the CIP Reset service * @@ -214,6 +214,6 @@ EipStatus CipResetService(CipInstance *RESTRICT const instance, CipMessageRouterResponse *const message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session); + const CipSessionHandle encapsulation_session); #endif /* OPENER_CIPCOMMON_H_ */ diff --git a/source/src/cip/cipconnectionmanager.c b/source/src/cip/cipconnectionmanager.c index c5d62081c..2c333c787 100644 --- a/source/src/cip/cipconnectionmanager.c +++ b/source/src/cip/cipconnectionmanager.c @@ -59,25 +59,25 @@ EipStatus ForwardOpen(CipInstance *instance, CipMessageRouterRequest *message_router_request, CipMessageRouterResponse *message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session); + const CipSessionHandle encapsulation_session); EipStatus LargeForwardOpen(CipInstance *instance, CipMessageRouterRequest *message_router_request, CipMessageRouterResponse *message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session); + const CipSessionHandle encapsulation_session); EipStatus ForwardClose(CipInstance *instance, CipMessageRouterRequest *message_router_request, CipMessageRouterResponse *message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session); + const CipSessionHandle encapsulation_session); EipStatus GetConnectionOwner(CipInstance *instance, CipMessageRouterRequest *message_router_request, CipMessageRouterResponse *message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session); + const CipSessionHandle encapsulation_session); EipStatus GetConnectionData(CipInstance *instance, CipMessageRouterRequest *message_router_request, @@ -526,7 +526,7 @@ EipStatus ForwardOpenRoutine(CipInstance *instance, CipMessageRouterRequest *message_router_request, CipMessageRouterResponse *message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session); + const CipSessionHandle encapsulation_session); /** @brief Check if resources for new connection available, generate ForwardOpen Reply message. * @@ -536,7 +536,7 @@ EipStatus LargeForwardOpen(CipInstance *instance, CipMessageRouterRequest *message_router_request, CipMessageRouterResponse *message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session) { + const CipSessionHandle encapsulation_session) { g_dummy_connection_object.is_large_forward_open = true; return ForwardOpenRoutine(instance, message_router_request, @@ -570,7 +570,7 @@ EipStatus ForwardOpen(CipInstance *instance, CipMessageRouterRequest *message_router_request, CipMessageRouterResponse *message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session) { + const CipSessionHandle encapsulation_session) { g_dummy_connection_object.is_large_forward_open = false; return ForwardOpenRoutine(instance, message_router_request, @@ -582,7 +582,7 @@ EipStatus ForwardOpenRoutine(CipInstance *instance, CipMessageRouterRequest *message_router_request, CipMessageRouterResponse *message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session) { + const CipSessionHandle encapsulation_session) { (void) instance; /*suppress compiler warning */ bool is_null_request = false; /* 1 = Null Request, 0 = Non-Null Request */ @@ -665,7 +665,7 @@ EipStatus ForwardClose(CipInstance *instance, CipMessageRouterRequest *message_router_request, CipMessageRouterResponse *message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session) { + const CipSessionHandle encapsulation_session) { /*Suppress compiler warning*/ (void) instance; (void) encapsulation_session; @@ -739,7 +739,7 @@ EipStatus GetConnectionOwner(CipInstance *instance, CipMessageRouterRequest *message_router_request, CipMessageRouterResponse *message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session) { + const CipSessionHandle encapsulation_session) { /* suppress compiler warnings */ (void) instance; (void) message_router_request; diff --git a/source/src/cip/cipconnectionobject.h b/source/src/cip/cipconnectionobject.h index 41ff1f55a..331b60932 100644 --- a/source/src/cip/cipconnectionobject.h +++ b/source/src/cip/cipconnectionobject.h @@ -182,7 +182,7 @@ struct cip_connection_object { for scanning if the right packet is arriving */ - size_t associated_encapsulation_session; /* The session handle ID via which the forward open was sent */ + CipSessionHandle associated_encapsulation_session; /* The session handle ID via which the forward open was sent */ /* pointers to connection handling functions */ CipConnectionStateHandler current_state_handler; diff --git a/source/src/cip/cipethernetlink.c b/source/src/cip/cipethernetlink.c index 91acc2ee1..18f20334b 100644 --- a/source/src/cip/cipethernetlink.c +++ b/source/src/cip/cipethernetlink.c @@ -107,7 +107,7 @@ EipStatus GetAndClearEthernetLink( CipMessageRouterRequest *const message_router_request, CipMessageRouterResponse *const message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session); + const CipSessionHandle encapsulation_session); #endif /* ... && 0 != OPENER_ETHLINK_CNTRS_ENABLE */ #if defined(OPENER_ETHLINK_IFACE_CTRL_ENABLE) && \ @@ -503,7 +503,7 @@ EipStatus GetAndClearEthernetLink( CipMessageRouterRequest *const message_router_request, CipMessageRouterResponse *const message_router_response, const struct sockaddr *originator_address, - const int encapsulation_session) { + const CipSessionHandle encapsulation_session) { CipAttributeStruct *attribute = GetCipAttribute( instance, message_router_request->request_path.attribute_number); diff --git a/source/src/cip/cipmessagerouter.c b/source/src/cip/cipmessagerouter.c index 849c2de62..b14d7910b 100644 --- a/source/src/cip/cipmessagerouter.c +++ b/source/src/cip/cipmessagerouter.c @@ -178,7 +178,7 @@ EipStatus NotifyMessageRouter(EipUint8 *data, int data_length, CipMessageRouterResponse *message_router_response, const struct sockaddr *const originator_address, - const int encapsulation_session) { + const CipSessionHandle encapsulation_session) { EipStatus eip_status = kEipStatusOkSend; CipError status = kCipErrorSuccess; diff --git a/source/src/cip/cipmessagerouter.h b/source/src/cip/cipmessagerouter.h index 468331954..c8411f9e2 100644 --- a/source/src/cip/cipmessagerouter.h +++ b/source/src/cip/cipmessagerouter.h @@ -38,7 +38,7 @@ EipStatus NotifyMessageRouter(EipUint8 *data, int data_length, CipMessageRouterResponse *message_router_response, const struct sockaddr *const originator_address, - const int encapsulation_session); + const CipSessionHandle encapsulation_session); /*! Register a class at the message router. * In order that the message router can deliver diff --git a/source/src/cip/ciptypes.h b/source/src/cip/ciptypes.h index f367d7dcc..aa7558173 100644 --- a/source/src/cip/ciptypes.h +++ b/source/src/cip/ciptypes.h @@ -416,7 +416,7 @@ typedef struct cip_class { * @typedef EipStatus (*CipServiceFunction)(CipInstance *const instance, * CipMessageRouterRequest *const message_router_request, * CipMessageRouterResponse *const message_router_response, - * const struct sockaddr *originator_address, const int encapsulation_session) + * const struct sockaddr *originator_address, const CipSessionHandle encapsulation_session) * @brief Signature definition for the implementation of CIP services. * * CIP services have to follow this signature in order to be handled correctly @@ -438,7 +438,7 @@ typedef EipStatus (*CipServiceFunction)(CipInstance *const instance, message_router_response, const struct sockaddr * originator_address, - const int encapsulation_session); + const CipSessionHandle encapsulation_session); /** @brief Service descriptor. These are stored in an array */ typedef struct cip_service_struct { diff --git a/source/src/enet_encap/encap.c b/source/src/enet_encap/encap.c index 38ddb9729..7e9679691 100644 --- a/source/src/enet_encap/encap.c +++ b/source/src/enet_encap/encap.c @@ -274,7 +274,7 @@ void SkipEncapsulationHeader(ENIPMessage *const outgoing_message) { outgoing_message->current_message_position += ENCAPSULATION_HEADER_LENGTH; } -void GenerateEncapsulationHeader(const EncapsulationData *const receive_data, const size_t command_specific_data_length, const size_t session_handle, +void GenerateEncapsulationHeader(const EncapsulationData *const receive_data, const size_t command_specific_data_length, const CipSessionHandle session_handle, const EncapsulationProtocolErrorCode encapsulation_protocol_status, ENIPMessage *const outgoing_message) { AddIntToMessage(receive_data->command_code, outgoing_message); AddIntToMessage(command_specific_data_length, outgoing_message); @@ -416,7 +416,7 @@ void DetermineDelayTime(const EipByte *buffer_start, DelayedEncapsulationMessage delayed_message_buffer->time_out = rand() % maximum_delay_time; } -void EncapsulateRegisterSessionCommandResponseMessage(const EncapsulationData *const receive_data, const size_t session_handle, +void EncapsulateRegisterSessionCommandResponseMessage(const EncapsulationData *const receive_data, const CipSessionHandle session_handle, const EncapsulationProtocolErrorCode encapsulation_protocol_status, ENIPMessage *const outgoing_message) { /* Encapsulation header */ @@ -434,7 +434,7 @@ void EncapsulateRegisterSessionCommandResponseMessage(const EncapsulationData *c */ void HandleReceivedRegisterSessionCommand(int socket, const EncapsulationData *const receive_data, ENIPMessage *const outgoing_message) { int session_index = 0; - size_t session_handle = 0; + CipSessionHandle session_handle = 0; EncapsulationProtocolErrorCode encapsulation_protocol_status = kEncapsulationProtocolSuccess; EipUint16 protocol_version = GetUintFromMessage((const EipUint8** const ) &receive_data->current_communication_buffer_position); @@ -443,7 +443,7 @@ void HandleReceivedRegisterSessionCommand(int socket, const EncapsulationData *c /* check if requested protocol version is supported and the register session option flag is zero*/ if((0 < protocol_version) && (protocol_version <= kSupportedProtocolVersion) && (0 == option_flag)) { /*Option field should be zero*/ /* check if the socket has already a session open */ - for(size_t i = 0; i < OPENER_NUMBER_OF_SUPPORTED_SESSIONS; ++i) { + for(unsigned int i = 0; i < OPENER_NUMBER_OF_SUPPORTED_SESSIONS; ++i) { if(g_registered_sessions[i] == socket) { /* the socket has already registered a session this is not allowed*/ OPENER_TRACE_INFO( @@ -467,7 +467,7 @@ void HandleReceivedRegisterSessionCommand(int socket, const EncapsulationData *c SocketTimerSetSocket(socket_timer, socket); SocketTimerSetLastUpdate(socket_timer, g_actual_time); g_registered_sessions[session_index] = socket; /* store associated socket */ - session_handle = session_index + 1; + session_handle = (CipSessionHandle)(session_index + 1); encapsulation_protocol_status = kEncapsulationProtocolSuccess; } } @@ -490,7 +490,7 @@ EipStatus HandleReceivedUnregisterSessionCommand(const EncapsulationData *const OPENER_TRACE_INFO("encap.c: Unregister Session Command\n"); if((0 < receive_data->session_handle) && (receive_data->session_handle <= OPENER_NUMBER_OF_SUPPORTED_SESSIONS)) { - size_t i = receive_data->session_handle - 1; + CipSessionHandle i = receive_data->session_handle - 1; if(kEipInvalidSocket != g_registered_sessions[i]) { CloseTcpSocket(g_registered_sessions[i]); g_registered_sessions[i] = kEipInvalidSocket; @@ -643,7 +643,7 @@ SessionStatus CheckRegisteredSessions(const EncapsulationData *const receive_dat void CloseSessionBySessionHandle(const CipConnectionObject *const connection_object) { OPENER_TRACE_INFO("encap.c: Close session by handle\n"); - size_t session_handle = connection_object->associated_encapsulation_session; + CipSessionHandle session_handle = connection_object->associated_encapsulation_session; CloseTcpSocket(g_registered_sessions[session_handle - 1]); g_registered_sessions[session_handle - 1] = kEipInvalidSocket; OPENER_TRACE_INFO("encap.c: Close session by handle done\n"); @@ -651,7 +651,7 @@ void CloseSessionBySessionHandle(const CipConnectionObject *const connection_obj void CloseSession(int socket) { OPENER_TRACE_INFO("encap.c: Close session\n"); - for(size_t i = 0; i < OPENER_NUMBER_OF_SUPPORTED_SESSIONS; ++i) { + for(unsigned int i = 0; i < OPENER_NUMBER_OF_SUPPORTED_SESSIONS; ++i) { if(g_registered_sessions[i] == socket) { CloseTcpSocket(socket); g_registered_sessions[i] = kEipInvalidSocket; @@ -663,7 +663,7 @@ void CloseSession(int socket) { void RemoveSession(const int socket) { OPENER_TRACE_INFO("encap.c: Removing session\n"); - for(size_t i = 0; i < OPENER_NUMBER_OF_SUPPORTED_SESSIONS; ++i) { + for(unsigned int i = 0; i < OPENER_NUMBER_OF_SUPPORTED_SESSIONS; ++i) { if(g_registered_sessions[i] == socket) { g_registered_sessions[i] = kEipInvalidSocket; CloseClass3ConnectionBasedOnSession(i + 1); @@ -717,8 +717,8 @@ void CloseEncapsulationSessionBySockAddr(const CipConnectionObject *const connec } } -size_t GetSessionFromSocket(const int socket_handle) { - for(size_t i = 0; i < OPENER_NUMBER_OF_SUPPORTED_SESSIONS; ++i) { +CipSessionHandle GetSessionFromSocket(const int socket_handle) { + for(CipSessionHandle i = 0; i < OPENER_NUMBER_OF_SUPPORTED_SESSIONS; ++i) { if(socket_handle == g_registered_sessions[i]) { return i; } @@ -726,7 +726,7 @@ size_t GetSessionFromSocket(const int socket_handle) { return OPENER_NUMBER_OF_SUPPORTED_SESSIONS; } -void CloseClass3ConnectionBasedOnSession(size_t encapsulation_session_handle) { +void CloseClass3ConnectionBasedOnSession(CipSessionHandle encapsulation_session_handle) { DoublyLinkedListNode *node = connection_list.first; while(NULL != node) { CipConnectionObject *connection_object = node->data; diff --git a/source/src/enet_encap/encap.h b/source/src/enet_encap/encap.h index 151428e3f..ee779ce58 100644 --- a/source/src/enet_encap/encap.h +++ b/source/src/enet_encap/encap.h @@ -39,7 +39,7 @@ typedef enum { typedef struct encapsulation_data { CipUint command_code; CipUint data_length; - CipUdint session_handle; + CipSessionHandle session_handle; CipUdint status; CipOctet sender_context[8]; /**< length of 8, according to the specification */ CipUdint options; @@ -79,7 +79,7 @@ void EncapsulationShutDown(void); */ void ManageEncapsulationMessages(const MilliSeconds elapsed_time); -size_t GetSessionFromSocket(const int socket_handle); +CipSessionHandle GetSessionFromSocket(const int socket_handle); void RemoveSession(const int socket); @@ -87,7 +87,7 @@ void CloseSessionBySessionHandle(const CipConnectionObject *const connection_obj void CloseEncapsulationSessionBySockAddr(const CipConnectionObject *const connection_object); -void CloseClass3ConnectionBasedOnSession(size_t encapsulation_session_handle); +void CloseClass3ConnectionBasedOnSession(CipSessionHandle encapsulation_session_handle); /* No reason to use this functions outside the encapsulation layer, they are here for testing */ typedef struct enip_message ENIPMessage; @@ -100,7 +100,7 @@ int_fast32_t CreateEncapsulationStructure(const EipUint8 *receive_buffer, void SkipEncapsulationHeader(ENIPMessage *const outgoing_message); -void GenerateEncapsulationHeader(const EncapsulationData *const receive_data, const size_t command_specific_data_length, const size_t session_handle, +void GenerateEncapsulationHeader(const EncapsulationData *const receive_data, const size_t command_specific_data_length, const CipSessionHandle session_handle, const EncapsulationProtocolErrorCode encapsulation_protocol_status, ENIPMessage *const outgoing_message); void HandleReceivedListServicesCommand(const EncapsulationData *const receive_data, ENIPMessage *const outgoing_message); diff --git a/source/src/ports/generic_networkhandler.c b/source/src/ports/generic_networkhandler.c index 036371e84..ccda8f543 100644 --- a/source/src/ports/generic_networkhandler.c +++ b/source/src/ports/generic_networkhandler.c @@ -1155,7 +1155,7 @@ void CheckEncapsulationInactivity(int socket_handle) { if( diff_milliseconds >= (MilliSeconds) (1000UL * g_tcpip.encapsulation_inactivity_timeout) ) { - size_t encapsulation_session_handle = + CipSessionHandle encapsulation_session_handle = GetSessionFromSocket(socket_handle); CloseClass3ConnectionBasedOnSession(encapsulation_session_handle); diff --git a/source/src/typedefs.h b/source/src/typedefs.h index b50e8d1b0..0b7127a97 100644 --- a/source/src/typedefs.h +++ b/source/src/typedefs.h @@ -79,6 +79,14 @@ typedef unsigned long long MicroSeconds; typedef CipUint CipInstanceNum; +/** @brief Session handle type. + * + * Data type for storing session identifiers as described by @cite CipVol2, + * 2-3.4; data type is derived from @cite CipVol2, Table 2-3.1. + */ +typedef CipUdint CipSessionHandle; + + /** The following are generally true regarding return status: