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

Function NotifyCommonPacketFormat

source/src/enet_encap/cpf.c:26–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24CipCommonPacketFormatData g_common_packet_format_data_item; /**< CPF global data items */
25
26int NotifyCommonPacketFormat(EncapsulationData *const received_data,
27 const struct sockaddr *const originator_address,
28 ENIPMessage *const outgoing_message) {
29 int return_value = kEipStatusError;
30
31 if (kEipStatusError == ( return_value = CreateCommonPacketFormatStructure(
32 received_data->
33 current_communication_buffer_position,
34 received_data->data_length,
35 &g_common_packet_format_data_item) ) ) {
36 OPENER_TRACE_ERR("notifyCPF: error from createCPFstructure\n");
37 } else {
38 return_value = kEipStatusOk; /* In cases of errors we normally need to send an error response */
39 if (g_common_packet_format_data_item.address_item.type_id
40 == kCipItemIdNullAddress) /* check if NullAddressItem received, otherwise it is no unconnected message and should not be here*/
41 { /* found null address item*/
42 if (g_common_packet_format_data_item.data_item.type_id
43 == kCipItemIdUnconnectedDataItem) { /* unconnected data item received*/
44 return_value = NotifyMessageRouter(
45 g_common_packet_format_data_item.data_item.data,
46 g_common_packet_format_data_item.data_item.length,
47 originator_address,
48 received_data->session_handle);
49 if (return_value != kEipStatusError) {
50 SkipEncapsulationHeader(outgoing_message);
51 return_value = AssembleLinearMessage(
52 &g_message_router_response, &g_common_packet_format_data_item,
53 outgoing_message);
54
55 CipOctet *buffer = outgoing_message->current_message_position;
56 outgoing_message->current_message_position =
57 outgoing_message->message_buffer;
58 GenerateEncapsulationHeader(received_data,
59 return_value,
60 received_data->session_handle,
61 kEncapsulationProtocolSuccess,
62 outgoing_message);
63 outgoing_message->current_message_position = buffer;
64 return_value = outgoing_message->used_message_length;
65 }
66 } else {
67 /* wrong data item detected*/
68 OPENER_TRACE_ERR(
69 "notifyCPF: got something besides the expected CIP_ITEM_ID_UNCONNECTEDMESSAGE\n");
70 GenerateEncapsulationHeader(received_data,
71 return_value,
72 received_data->session_handle,
73 kEncapsulationProtocolIncorrectData,
74 outgoing_message);
75 return_value = outgoing_message->used_message_length;
76 }
77 } else {
78 OPENER_TRACE_ERR(
79 "notifyCPF: got something besides the expected CIP_ITEM_ID_NULL\n");
80 GenerateEncapsulationHeader(received_data,
81 return_value,
82 received_data->session_handle,
83 kEncapsulationProtocolIncorrectData,

Calls 5

NotifyMessageRouterFunction · 0.85
SkipEncapsulationHeaderFunction · 0.85
AssembleLinearMessageFunction · 0.85

Tested by

no test coverage detected