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

Function AssembleForwardOpenResponse

source/src/cip/cipconnectionmanager.c:739–839  ·  view source on GitHub ↗

@brief Assembles the Forward Open Response * * @param connection_object pointer to connection Object * @param message_router_response pointer to message router response * @param general_status the general status of the response * @param extended_status extended status in the case of an error otherwise 0 * @return status * kEipStatusOk .. no reply need to be sent back * kEipStatusOkSend

Source from the content-addressed store, hash-verified

737 * kEipStatusError .. error
738 */
739EipStatus AssembleForwardOpenResponse(
740 CipConnectionObject *connection_object,
741 CipMessageRouterResponse *message_router_response,
742 EipUint8 general_status,
743 EipUint16 extended_status
744 ) {
745 /* write reply information in CPF struct dependent of pa_status */
746 CipCommonPacketFormatData *cip_common_packet_format_data =
747 &g_common_packet_format_data_item;
748 EipByte *message = message_router_response->data;
749 cip_common_packet_format_data->item_count = 2;
750 cip_common_packet_format_data->data_item.type_id =
751 kCipItemIdUnconnectedDataItem;
752
753 AddNullAddressItem(cip_common_packet_format_data);
754
755 message_router_response->reply_service = (0x80 | kForwardOpen);
756 message_router_response->general_status = general_status;
757
758 if (kCipErrorSuccess == general_status) {
759 OPENER_TRACE_INFO("assembleFWDOpenResponse: sending success response\n");
760 message_router_response->data_length = 26; /* if there is no application specific data */
761 message_router_response->size_of_additional_status = 0;
762
763 if (cip_common_packet_format_data->address_info_item[0].type_id != 0) {
764 cip_common_packet_format_data->item_count = 3;
765 if (cip_common_packet_format_data->address_info_item[1].type_id != 0) {
766 cip_common_packet_format_data->item_count = 4; /* there are two sockaddrinfo items to add */
767 }
768 }
769
770 AddDintToMessage(connection_object->cip_consumed_connection_id, &message);
771 AddDintToMessage(connection_object->cip_produced_connection_id, &message);
772 } else {
773 /* we have an connection creation error */
774 OPENER_TRACE_INFO("AssembleForwardOpenResponse: sending error response\n");
775 ConnectionObjectSetState(connection_object,
776 kConnectionObjectStateNonExistent);
777 message_router_response->data_length = 10;
778
779 switch (general_status) {
780 case kCipErrorNotEnoughData:
781 case kCipErrorTooMuchData: {
782 message_router_response->size_of_additional_status = 0;
783 break;
784 }
785
786 default: {
787 switch (extended_status) {
788 case
789 kConnectionManagerExtendedStatusCodeErrorInvalidOToTConnectionSize:
790 {
791 message_router_response->size_of_additional_status = 2;
792 message_router_response->additional_status[0] = extended_status;
793 message_router_response->additional_status[1] = connection_object
794 ->
795 correct_originator_to_target_size;
796 break;

Calls 4

AddNullAddressItemFunction · 0.85
AddDintToMessageFunction · 0.85
ConnectionObjectSetStateFunction · 0.85
AddIntToMessageFunction · 0.85

Tested by

no test coverage detected