MCPcopy Create free account
hub / github.com/EIPStackGroup/OpENer / ForwardClose

Function ForwardClose

source/src/cip/cipconnectionmanager.c:559–632  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

557}
558
559EipStatus ForwardClose(
560 CipInstance *instance,
561 CipMessageRouterRequest *message_router_request,
562 CipMessageRouterResponse *message_router_response,
563 struct sockaddr *originator_address,
564 const int encapsulation_session) {
565 /*Suppress compiler warning*/
566 (void) instance;
567
568 /* check connection_serial_number && originator_vendor_id && originator_serial_number if connection is established */
569 ConnectionManagerExtendedStatusCode connection_status =
570 kConnectionManagerExtendedStatusCodeErrorConnectionTargetConnectionNotFound;
571
572 /* set AddressInfo Items to invalid TypeID to prevent assembleLinearMsg to read them */
573 g_common_packet_format_data_item.address_info_item[0].type_id = 0;
574 g_common_packet_format_data_item.address_info_item[1].type_id = 0;
575
576 message_router_request->data += 2; /* ignore Priority/Time_tick and Time-out_ticks */
577
578 EipUint16 connection_serial_number = GetIntFromMessage(
579 &message_router_request->data);
580 EipUint16 originator_vendor_id = GetIntFromMessage(
581 &message_router_request->data);
582 EipUint32 originator_serial_number = GetDintFromMessage(
583 &message_router_request->data);
584
585 OPENER_TRACE_INFO("ForwardClose: ConnSerNo %d\n", connection_serial_number);
586
587 DoublyLinkedListNode *node = connection_list.first;
588
589 while (NULL != node) {
590 /* this check should not be necessary as only established connections should be in the active connection list */
591 CipConnectionObject *connection_object = node->data;
592 if ( (kConnectionObjectStateEstablished ==
593 ConnectionObjectGetState(connection_object) )
594 || (kConnectionObjectStateTimedOut ==
595 ConnectionObjectGetState(connection_object) ) ) {
596 if ( (connection_object->connection_serial_number
597 == connection_serial_number)
598 && (connection_object->originator_vendor_id == originator_vendor_id)
599 && (connection_object->originator_serial_number
600 == originator_serial_number) ) {
601 /* found the corresponding connection object -> close it */
602 OPENER_ASSERT(NULL != connection_object->connection_close_function)
603 if ( ( (struct sockaddr_in *) originator_address )->sin_addr.s_addr
604 == connection_object->originator_address.sin_addr.s_addr ) {
605 connection_object->connection_close_function(connection_object);
606 connection_status = kConnectionManagerExtendedStatusCodeSuccess;
607 } else {
608 connection_status = kConnectionManagerExtendedStatusWrongCloser;
609 }
610 break;
611 }
612 }
613 node = node->next;
614 }
615 if(
616 kConnectionManagerExtendedStatusCodeErrorConnectionTargetConnectionNotFound

Callers

nothing calls this directly

Calls 4

GetIntFromMessageFunction · 0.85
GetDintFromMessageFunction · 0.85
ConnectionObjectGetStateFunction · 0.85

Tested by

no test coverage detected