|
|
@@ -194,7 +194,8 @@ unsigned int GetPathPortSegmentExtendedPortNumber(
|
|
|
}
|
|
|
|
|
|
void SetPathPortSegmentExtendedPortIdentifier(
|
|
|
- const unsigned int extended_port_identifier, CipOctet *const cip_path) {
|
|
|
+ const unsigned int extended_port_identifier,
|
|
|
+ CipOctet *const cip_path) {
|
|
|
SetPathPortSegmentPortIdentifier(kPortSegmentExtendedPort, cip_path);
|
|
|
const unsigned int kExtendedPortSegmentPosition =
|
|
|
GetPathPortSegmentExtendedLinkAddressSizeBit(cip_path) == true ? 2 : 1;
|
|
|
@@ -246,38 +247,39 @@ LogicalSegmentLogicalType GetPathLogicalSegmentLogicalType(
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-void SetPathLogicalSegmentLogicalType(LogicalSegmentLogicalType logical_type, CipOctet *const cip_path) {
|
|
|
+void SetPathLogicalSegmentLogicalType(LogicalSegmentLogicalType logical_type,
|
|
|
+ CipOctet *const cip_path) {
|
|
|
OPENER_ASSERT( kSegmentTypeLogicalSegment == GetPathSegmentType(cip_path) );
|
|
|
switch (logical_type) {
|
|
|
- case kLogicalSegmentLogicalTypeClassId:
|
|
|
- (*cip_path) |= LOGICAL_SEGMENT_TYPE_CLASS_ID;
|
|
|
- break;
|
|
|
- case kLogicalSegmentLogicalTypeInstanceId:
|
|
|
- (*cip_path) |= LOGICAL_SEGMENT_TYPE_INSTANCE_ID;
|
|
|
- break;
|
|
|
- case kLogicalSegmentLogicalTypeMemberId:
|
|
|
- (*cip_path) |= LOGICAL_SEGMENT_TYPE_MEMBER_ID;
|
|
|
- break;
|
|
|
- case kLogicalSegmentLogicalTypeConnectionPoint:
|
|
|
- (*cip_path) |= LOGICAL_SEGMENT_TYPE_CONNECTION_POINT;
|
|
|
- break;
|
|
|
- case kLogicalSegmentLogicalTypeAttributeId:
|
|
|
- (*cip_path) |= LOGICAL_SEGMENT_TYPE_ATTRIBUTE_ID;
|
|
|
- break;
|
|
|
- case kLogicalSegmentLogicalTypeSpecial:
|
|
|
- (*cip_path) |= LOGICAL_SEGMENT_TYPE_SPECIAL;
|
|
|
- break;
|
|
|
- case kLogicalSegmentLogicalTypeServiceId:
|
|
|
- (*cip_path) |= LOGICAL_SEGMENT_TYPE_SERVICE_ID;
|
|
|
- break;
|
|
|
- case kLogicalSegmentLogicalTypeExtendedLogical:
|
|
|
- (*cip_path) |= LOGICAL_SEGMENT_TYPE_EXTENDED_LOGICAL;
|
|
|
- break;
|
|
|
- default:
|
|
|
- OPENER_ASSERT(
|
|
|
- "Logical segment/logical type: It is not possible to reach this point!\n");
|
|
|
- break;
|
|
|
- }
|
|
|
+ case kLogicalSegmentLogicalTypeClassId:
|
|
|
+ (*cip_path) |= LOGICAL_SEGMENT_TYPE_CLASS_ID;
|
|
|
+ break;
|
|
|
+ case kLogicalSegmentLogicalTypeInstanceId:
|
|
|
+ (*cip_path) |= LOGICAL_SEGMENT_TYPE_INSTANCE_ID;
|
|
|
+ break;
|
|
|
+ case kLogicalSegmentLogicalTypeMemberId:
|
|
|
+ (*cip_path) |= LOGICAL_SEGMENT_TYPE_MEMBER_ID;
|
|
|
+ break;
|
|
|
+ case kLogicalSegmentLogicalTypeConnectionPoint:
|
|
|
+ (*cip_path) |= LOGICAL_SEGMENT_TYPE_CONNECTION_POINT;
|
|
|
+ break;
|
|
|
+ case kLogicalSegmentLogicalTypeAttributeId:
|
|
|
+ (*cip_path) |= LOGICAL_SEGMENT_TYPE_ATTRIBUTE_ID;
|
|
|
+ break;
|
|
|
+ case kLogicalSegmentLogicalTypeSpecial:
|
|
|
+ (*cip_path) |= LOGICAL_SEGMENT_TYPE_SPECIAL;
|
|
|
+ break;
|
|
|
+ case kLogicalSegmentLogicalTypeServiceId:
|
|
|
+ (*cip_path) |= LOGICAL_SEGMENT_TYPE_SERVICE_ID;
|
|
|
+ break;
|
|
|
+ case kLogicalSegmentLogicalTypeExtendedLogical:
|
|
|
+ (*cip_path) |= LOGICAL_SEGMENT_TYPE_EXTENDED_LOGICAL;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ OPENER_ASSERT(
|
|
|
+ "Logical segment/logical type: It is not possible to reach this point!\n");
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
LogicalSegmentLogicalFormat GetPathLogicalSegmentLogicalFormat(
|
|
|
@@ -304,8 +306,10 @@ LogicalSegmentLogicalFormat GetPathLogicalSegmentLogicalFormat(
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-void SetPathLogicalSegmentLogicalFormat(LogicalSegmentLogicalFormat format, CipOctet *const cip_path) {
|
|
|
- OPENER_ASSERT( kSegmentTypeLogicalSegment == GetPathSegmentType((const CipOctet *)cip_path) );
|
|
|
+void SetPathLogicalSegmentLogicalFormat(LogicalSegmentLogicalFormat format,
|
|
|
+ CipOctet *const cip_path) {
|
|
|
+ OPENER_ASSERT( kSegmentTypeLogicalSegment ==
|
|
|
+ GetPathSegmentType( (const CipOctet *)cip_path ) );
|
|
|
switch (format) {
|
|
|
case kLogicalSegmentLogicalFormatEightBit:
|
|
|
(*cip_path) |= LOGICAL_SEGMENT_FORMAT_EIGHT_BIT;
|
|
|
@@ -324,12 +328,13 @@ void SetPathLogicalSegmentLogicalFormat(LogicalSegmentLogicalFormat format, CipO
|
|
|
}
|
|
|
|
|
|
const CipDword CipEpathGetLogicalValue(const EipUint8 **message) {
|
|
|
- LogicalSegmentLogicalFormat logical_format = GetPathLogicalSegmentLogicalFormat(*message);
|
|
|
+ LogicalSegmentLogicalFormat logical_format =
|
|
|
+ GetPathLogicalSegmentLogicalFormat(*message);
|
|
|
CipDword data = 0;
|
|
|
MoveMessageNOctets(1, message); /* Move to logical value */
|
|
|
- switch (logical_format){
|
|
|
+ switch (logical_format) {
|
|
|
case kLogicalSegmentLogicalFormatEightBit:
|
|
|
- data = GetSintFromMessage(message);
|
|
|
+ data = GetSintFromMessage(message);
|
|
|
break;
|
|
|
case kLogicalSegmentLogicalFormatSixteenBit:
|
|
|
MoveMessageNOctets(1, message); /* Pad byte needs to be skipped */
|
|
|
@@ -345,11 +350,24 @@ const CipDword CipEpathGetLogicalValue(const EipUint8 **message) {
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
-size_t CipEpathSetLogicalValue(const CipDword logical_value, const LogicalSegmentLogicalFormat logical_format, CipOctet **message) {
|
|
|
+size_t CipEpathSetLogicalValue(const CipDword logical_value,
|
|
|
+ const LogicalSegmentLogicalFormat logical_format,
|
|
|
+ CipOctet **message) {
|
|
|
switch(logical_value) {
|
|
|
- case kLogicalSegmentLogicalFormatEightBit: AddSintToMessage(logical_value, message); return 1; break;
|
|
|
- case kLogicalSegmentLogicalFormatSixteenBit: MoveMessageNOctets(1, (const CipOctet**)message); AddIntToMessage(logical_value, message); return 3; break;
|
|
|
- case kLogicalSegmentLogicalFormatThirtyTwoBit: MoveMessageNOctets(1, (const CipOctet**)message); AddDintToMessage(logical_value, message); return 5; break;
|
|
|
+ case kLogicalSegmentLogicalFormatEightBit: AddSintToMessage(logical_value,
|
|
|
+ message);
|
|
|
+ return 1; break;
|
|
|
+ case kLogicalSegmentLogicalFormatSixteenBit: MoveMessageNOctets(1,
|
|
|
+ (const
|
|
|
+ CipOctet **)message);
|
|
|
+ AddIntToMessage(logical_value, message);
|
|
|
+ return 3; break;
|
|
|
+ case kLogicalSegmentLogicalFormatThirtyTwoBit: MoveMessageNOctets(1,
|
|
|
+ (const
|
|
|
+ CipOctet
|
|
|
+ **)message);
|
|
|
+ AddDintToMessage(logical_value, message);
|
|
|
+ return 5; break;
|
|
|
}
|
|
|
OPENER_ASSERT(false); /* This should never happen! */
|
|
|
return 0;
|
|
|
@@ -419,16 +437,18 @@ ElectronicKeySegmentFormat GetPathLogicalSegmentElectronicKeyFormat(
|
|
|
}
|
|
|
|
|
|
void GetElectronicKeyFormat4FromMessage(
|
|
|
- const CipOctet **const message, ElectronicKeyFormat4 *key) {
|
|
|
+ const CipOctet **const message,
|
|
|
+ ElectronicKeyFormat4 *key) {
|
|
|
OPENER_ASSERT( kElectronicKeySegmentFormatKeyFormat4 ==
|
|
|
GetPathLogicalSegmentElectronicKeyFormat(*message) );
|
|
|
|
|
|
MoveMessageNOctets(2, message);
|
|
|
- ElectronicKeyFormat4SetVendorId(key, GetIntFromMessage(message));
|
|
|
- ElectronicKeyFormat4SetDeviceType(key, GetIntFromMessage(message));
|
|
|
- ElectronicKeyFormat4SetProductCode(key, GetIntFromMessage(message));
|
|
|
- ElectronicKeyFormat4SetMajorRevisionCompatibility(key, GetSintFromMessage(message));
|
|
|
- ElectronicKeyFormat4SetMinorRevision(key, GetSintFromMessage(message));
|
|
|
+ ElectronicKeyFormat4SetVendorId(key, GetIntFromMessage(message) );
|
|
|
+ ElectronicKeyFormat4SetDeviceType(key, GetIntFromMessage(message) );
|
|
|
+ ElectronicKeyFormat4SetProductCode(key, GetIntFromMessage(message) );
|
|
|
+ ElectronicKeyFormat4SetMajorRevisionCompatibility(key,
|
|
|
+ GetSintFromMessage(message) );
|
|
|
+ ElectronicKeyFormat4SetMinorRevision(key, GetSintFromMessage(message) );
|
|
|
}
|
|
|
|
|
|
/*** Logical Segment ***/
|
|
|
@@ -607,8 +627,10 @@ CipUsint GetPathDataSegmentSimpleDataWordLength(
|
|
|
|
|
|
/* Special purpose functions */
|
|
|
|
|
|
-LogicalSegmentLogicalFormat CipEpathGetNeededLogicalFormatForValue(CipDword value) {
|
|
|
- LogicalSegmentLogicalFormat logical_format = kLogicalSegmentLogicalFormatEightBit;
|
|
|
+LogicalSegmentLogicalFormat CipEpathGetNeededLogicalFormatForValue(
|
|
|
+ CipDword value) {
|
|
|
+ LogicalSegmentLogicalFormat logical_format =
|
|
|
+ kLogicalSegmentLogicalFormatEightBit;
|
|
|
if(0xFF < value) {
|
|
|
logical_format = kLogicalSegmentLogicalFormatSixteenBit;
|
|
|
}
|
|
|
@@ -618,42 +640,62 @@ LogicalSegmentLogicalFormat CipEpathGetNeededLogicalFormatForValue(CipDword valu
|
|
|
return logical_format;
|
|
|
}
|
|
|
|
|
|
-size_t CipEpathEncodeConnectionEpath(const CipConnectionPathEpath *const connection_epath, CipOctet **encoded_path) {
|
|
|
+size_t CipEpathEncodeConnectionEpath(
|
|
|
+ const CipConnectionPathEpath *const connection_epath,
|
|
|
+ CipOctet **encoded_path) {
|
|
|
|
|
|
- size_t encoded_path_length = 0;
|
|
|
+ size_t encoded_path_length = 0;
|
|
|
{
|
|
|
- SetPathSegmentType(kSegmentTypeLogicalSegment, *encoded_path);
|
|
|
- SetPathLogicalSegmentLogicalType(kLogicalSegmentLogicalTypeClassId, *encoded_path);
|
|
|
- LogicalSegmentLogicalFormat logical_value = CipEpathGetNeededLogicalFormatForValue(connection_epath->class_id);
|
|
|
- SetPathLogicalSegmentLogicalFormat(logical_value, *encoded_path);
|
|
|
- encoded_path_length += 1;
|
|
|
- MoveMessageNOctets(1, (const CipOctet**)encoded_path);
|
|
|
- encoded_path_length += CipEpathSetLogicalValue(connection_epath->class_id, logical_value, encoded_path);
|
|
|
+ SetPathSegmentType(kSegmentTypeLogicalSegment, *encoded_path);
|
|
|
+ SetPathLogicalSegmentLogicalType(kLogicalSegmentLogicalTypeClassId,
|
|
|
+ *encoded_path);
|
|
|
+ LogicalSegmentLogicalFormat logical_value =
|
|
|
+ CipEpathGetNeededLogicalFormatForValue(connection_epath->class_id);
|
|
|
+ SetPathLogicalSegmentLogicalFormat(logical_value, *encoded_path);
|
|
|
+ encoded_path_length += 1;
|
|
|
+ MoveMessageNOctets(1, (const CipOctet **)encoded_path);
|
|
|
+ encoded_path_length += CipEpathSetLogicalValue(connection_epath->class_id,
|
|
|
+ logical_value,
|
|
|
+ encoded_path);
|
|
|
}
|
|
|
|
|
|
{
|
|
|
- SetPathSegmentType(kSegmentTypeLogicalSegment, *encoded_path);
|
|
|
- SetPathLogicalSegmentLogicalType(kLogicalSegmentLogicalTypeClassId, *encoded_path);
|
|
|
- LogicalSegmentLogicalFormat logical_value = CipEpathGetNeededLogicalFormatForValue(connection_epath->instance_id);
|
|
|
- SetPathLogicalSegmentLogicalFormat(logical_value, *encoded_path);
|
|
|
- encoded_path_length += 1;
|
|
|
- MoveMessageNOctets(1, (const CipOctet**)encoded_path);
|
|
|
- encoded_path_length += CipEpathSetLogicalValue(connection_epath->instance_id, logical_value, encoded_path);
|
|
|
+ SetPathSegmentType(kSegmentTypeLogicalSegment, *encoded_path);
|
|
|
+ SetPathLogicalSegmentLogicalType(kLogicalSegmentLogicalTypeClassId,
|
|
|
+ *encoded_path);
|
|
|
+ LogicalSegmentLogicalFormat logical_value =
|
|
|
+ CipEpathGetNeededLogicalFormatForValue(connection_epath->instance_id);
|
|
|
+ SetPathLogicalSegmentLogicalFormat(logical_value, *encoded_path);
|
|
|
+ encoded_path_length += 1;
|
|
|
+ MoveMessageNOctets(1, (const CipOctet **)encoded_path);
|
|
|
+ encoded_path_length += CipEpathSetLogicalValue(
|
|
|
+ connection_epath->instance_id,
|
|
|
+ logical_value,
|
|
|
+ encoded_path);
|
|
|
}
|
|
|
|
|
|
- if(0 != connection_epath->attribute_id_or_connection_point){
|
|
|
+ if(0 != connection_epath->attribute_id_or_connection_point) {
|
|
|
SetPathSegmentType(kSegmentTypeLogicalSegment, *encoded_path);
|
|
|
- SetPathLogicalSegmentLogicalType(kLogicalSegmentLogicalTypeClassId, *encoded_path);
|
|
|
- LogicalSegmentLogicalFormat logical_value = CipEpathGetNeededLogicalFormatForValue(connection_epath->attribute_id_or_connection_point);
|
|
|
+ SetPathLogicalSegmentLogicalType(kLogicalSegmentLogicalTypeClassId,
|
|
|
+ *encoded_path);
|
|
|
+ LogicalSegmentLogicalFormat logical_value =
|
|
|
+ CipEpathGetNeededLogicalFormatForValue(
|
|
|
+ connection_epath->attribute_id_or_connection_point);
|
|
|
SetPathLogicalSegmentLogicalFormat(logical_value, *encoded_path);
|
|
|
encoded_path_length += 1;
|
|
|
- MoveMessageNOctets(1, (const CipOctet**)encoded_path);
|
|
|
- encoded_path_length += CipEpathSetLogicalValue(connection_epath->attribute_id_or_connection_point, logical_value, encoded_path);
|
|
|
+ MoveMessageNOctets(1, (const CipOctet **)encoded_path);
|
|
|
+ encoded_path_length += CipEpathSetLogicalValue(
|
|
|
+ connection_epath->attribute_id_or_connection_point,
|
|
|
+ logical_value,
|
|
|
+ encoded_path);
|
|
|
}
|
|
|
return encoded_path_length += 1;
|
|
|
}
|
|
|
|
|
|
-bool CipEpathEqual(const CipOctet *const path1, const CipUint path1_length, const CipOctet *const path2, const CipUint path2_length) {
|
|
|
+bool CipEpathEqual(const CipOctet *const path1,
|
|
|
+ const CipUint path1_length,
|
|
|
+ const CipOctet *const path2,
|
|
|
+ const CipUint path2_length) {
|
|
|
if(path1_length != path2_length) {
|
|
|
return false;
|
|
|
}
|