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

Function NotifyConnectedCommonPacketFormat

source/src/enet_encap/cpf.c:91–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89}
90
91int NotifyConnectedCommonPacketFormat(
92 const EncapsulationData *const received_data,
93 const struct sockaddr *const originator_address,
94 ENIPMessage *const outgoing_message) {
95
96 int return_value = CreateCommonPacketFormatStructure(
97 received_data->current_communication_buffer_position,
98 received_data->data_length, &g_common_packet_format_data_item);
99
100 if (kEipStatusError == return_value) {
101 OPENER_TRACE_ERR("notifyConnectedCPF: error from createCPFstructure\n");
102 } else {
103 return_value = kEipStatusError; /* For connected explicit messages status always has to be 0*/
104 if (g_common_packet_format_data_item.address_item.type_id
105 == kCipItemIdConnectionAddress) /* check if ConnectedAddressItem received, otherwise it is no connected message and should not be here*/
106 { /* ConnectedAddressItem item */
107 CipConnectionObject *connection_object = GetConnectedObject(
108 g_common_packet_format_data_item.address_item.data
109 .connection_identifier);
110 if (NULL != connection_object) {
111 /* reset the watchdog timer */
112 ConnectionObjectResetInactivityWatchdogTimerValue(connection_object);
113
114 /*TODO check connection id and sequence count */
115 if (g_common_packet_format_data_item.data_item.type_id
116 == kCipItemIdConnectedDataItem) { /* connected data item received*/
117 EipUint8 *buffer = g_common_packet_format_data_item.data_item.data;
118 g_common_packet_format_data_item.address_item.data.sequence_number =
119 (EipUint32) GetIntFromMessage( (const EipUint8 **const)&buffer );
120 OPENER_TRACE_INFO(
121 "Class 3 sequence number: %d, last sequence number: %d\n",
122 g_common_packet_format_data_item.address_item.data.sequence_number,
123 connection_object->sequence_count_consuming);
124 if(connection_object->sequence_count_consuming ==
125 g_common_packet_format_data_item.address_item.data.sequence_number)
126 {
127 memcpy(outgoing_message,
128 &(connection_object->last_reply_sent),
129 sizeof(ENIPMessage) );
130 outgoing_message->current_message_position =
131 outgoing_message->message_buffer;
132 /* Regenerate encapsulation header for new message */
133 outgoing_message->used_message_length -=
134 ENCAPSULATION_HEADER_LENGTH;
135 GenerateEncapsulationHeader(received_data,
136 outgoing_message->used_message_length,
137 received_data->session_handle,
138 kEncapsulationProtocolSuccess,
139 outgoing_message);
140 outgoing_message->current_message_position = buffer;
141 /* End regenerate encapsulation header for new message */
142 return outgoing_message->used_message_length;
143 }
144 connection_object->sequence_count_consuming =
145 g_common_packet_format_data_item.address_item.data.sequence_number;
146
147 ConnectionObjectResetInactivityWatchdogTimerValue(connection_object);
148

Callers 1

Tested by

no test coverage detected