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

Function ParseConnectionPath

source/src/cip/cipconnectionmanager.c:1050–1383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1048}
1049
1050EipUint8 ParseConnectionPath(
1051 CipConnectionObject *connection_object,
1052 CipMessageRouterRequest *message_router_request,
1053 EipUint16 *extended_error
1054 ) {
1055 const EipUint8 *message = message_router_request->data;
1056 const size_t connection_path_size = GetSintFromMessage(&message); /* length in words */
1057 size_t remaining_path = connection_path_size;
1058 CipClass *class = NULL;
1059
1060 CipDword class_id = 0x0;
1061 CipDword instance_id = 0x0;
1062
1063 /* with 256 we mark that we haven't got a PIT segment */
1064 ConnectionObjectSetProductionInhibitTime(connection_object, 256);
1065
1066 if ( (g_kForwardOpenHeaderLength + remaining_path * 2)
1067 < message_router_request->request_path_size ) {
1068 /* the received packet is larger than the data in the path */
1069 *extended_error = 0;
1070 return kCipErrorTooMuchData;
1071 }
1072
1073 if ( (g_kForwardOpenHeaderLength + remaining_path * 2)
1074 > message_router_request->request_path_size ) {
1075 /*there is not enough data in received packet */
1076 *extended_error = 0;
1077 OPENER_TRACE_INFO("Message not long enough for path\n");
1078 return kCipErrorNotEnoughData;
1079 }
1080
1081 if (remaining_path > 0) {
1082 /* first look if there is an electronic key */
1083 if ( kSegmentTypeLogicalSegment == GetPathSegmentType(message) ) {
1084 if ( kLogicalSegmentLogicalTypeSpecial
1085 == GetPathLogicalSegmentLogicalType(message) ) {
1086 if ( kLogicalSegmentSpecialTypeLogicalFormatElectronicKey
1087 == GetPathLogicalSegmentSpecialTypeLogicalType(message) ) {
1088 if ( kElectronicKeySegmentFormatKeyFormat4
1089 == GetPathLogicalSegmentElectronicKeyFormat(message) ) {
1090 /* Check if there is enough data for holding the electronic key segment */
1091 if (remaining_path < 5) {
1092 *extended_error = 0;
1093 OPENER_TRACE_INFO("Message not long enough for electronic key\n");
1094 return kCipErrorNotEnoughData;
1095 }
1096 /* Electronic key format 4 found */
1097 connection_object->electronic_key.key_format = 4;
1098 ElectronicKeyFormat4 *electronic_key = ElectronicKeyFormat4New();
1099 GetElectronicKeyFormat4FromMessage(&message, electronic_key);
1100 /* logical electronic key found */
1101 connection_object->electronic_key.key_data = electronic_key;
1102
1103
1104 remaining_path -= 5; /*length of the electronic key*/
1105 OPENER_TRACE_INFO(
1106 "key: ven ID %d, dev type %d, prod code %d, major %d, minor %d\n",
1107 ElectronicKeyFormat4GetVendorId(connection_object->electronic_key.

Tested by

no test coverage detected