cipepath.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. /*******************************************************************************
  2. * Copyright (c) 2016, Rockwell Automation, Inc.
  3. * All rights reserved.
  4. *
  5. ******************************************************************************/
  6. #ifndef SRC_CIP_CIPEPATH_H_
  7. #define SRC_CIP_CIPEPATH_H_
  8. #include <stdbool.h>
  9. #include "ciptypes.h"
  10. #include "cipelectronickey.h"
  11. #define SEGMENT_TYPE_PORT_SEGMENT 0x00 /**< Message value of the Port segment */
  12. #define SEGMENT_TYPE_LOGICAL_SEGMENT 0x20 /**< Message value of the Logical segment */
  13. #define SEGMENT_TYPE_NETWORK_SEGMENT 0x40 /**< Message value of the Network segment */
  14. #define SEGMENT_TYPE_SYMBOLIC_SEGMENT 0x60 /**< Message value of the Symbolic segment */
  15. #define SEGMENT_TYPE_DATA_SEGMENT 0x80 /**< Message value of the Data segment */
  16. #define SEGMENT_TYPE_DATA_TYPE_CONSTRUCTED 0xA0 /**< Message value of the Data type constructed */
  17. #define SEGMENT_TYPE_DATA_TYPE_ELEMENTARTY 0xC0 /**< Message value of the Data type elementary */
  18. #define SEGMENT_TYPE_SEGMENT_RESERVED 0xE0 /**< Reserved value */
  19. #define LOGICAL_SEGMENT_TYPE_CLASS_ID 0x00 /**< Message value of the logical segment/logical type Class ID */
  20. #define LOGICAL_SEGMENT_TYPE_INSTANCE_ID 0x04 /**< Message value of the logical segment/logical type Instance ID */
  21. #define LOGICAL_SEGMENT_TYPE_MEMBER_ID 0x08 /**< Message value of the logical segment/logical type Member ID */
  22. #define LOGICAL_SEGMENT_TYPE_CONNECTION_POINT 0x0C /**< Message value of the logical segment/logical type Connection Point */
  23. #define LOGICAL_SEGMENT_TYPE_ATTRIBUTE_ID 0x10 /**< Message value of the logical segment/logical type Attribute ID */
  24. #define LOGICAL_SEGMENT_TYPE_SPECIAL 0x14 /**< Message value of the logical segment/logical type Special */
  25. #define LOGICAL_SEGMENT_TYPE_SERVICE_ID 0x18 /**< Message value of the logical segment/logical type Service ID */
  26. #define LOGICAL_SEGMENT_TYPE_EXTENDED_LOGICAL 0x1C /**< Message value of the logical segment/logical type Extended Logical */
  27. #define LOGICAL_SEGMENT_FORMAT_EIGHT_BIT 0x00 /**< Message value indicating an 8 bit value */
  28. #define LOGICAL_SEGMENT_FORMAT_SIXTEEN_BIT 0x01 /**< Message value indicating an 16 bit value */
  29. #define LOGICAL_SEGMENT_FORMAT_THIRTY_TWO_BIT 0x02 /**< Message value indicating an 32 bit value */
  30. #define LOGICAL_SEGMENT_EXTENDED_TYPE_RESERVED 0x00 /**< Message value indicating an reserved/unused Extended Logical Segment type */
  31. #define LOGICAL_SEGMENT_EXTENDED_TYPE_ARRAY_INDEX 0x01 /**< Message value indicating the Array Index Extended Logical Segment type */
  32. #define LOGICAL_SEGMENT_EXTENDED_TYPE_INDIRECT_ARRAY_INDEX 0x02 /**< Message value indicating the Indirect Array Index Extended Logical Segment type */
  33. #define LOGICAL_SEGMENT_EXTENDED_TYPE_BIT_INDEX 0x03 /**< Message value indicating the Bit Index Extended Logical Segment type */
  34. #define LOGICAL_SEGMENT_EXTENDED_TYPE_INDIRECT_BIT_INDEX 0x04 /**< Message value indicating the Indirect Bit Index Extended Logical Segment type */
  35. #define LOGICAL_SEGMENT_EXTENDED_TYPE_STRUCTURE_MEMBER_NUMBER 0x05 /**< Message value indicating the Structured Member Number Extended Logical Segment type */
  36. #define LOGICAL_SEGMENT_EXTENDED_TYPE_STRUCTURE_MEMBER_HANDLE 0x06 /**< Message value indicating the Structured Member Handler Extended Logical Segment type */
  37. #define LOGICAL_SEGMENT_SPECIAL_TYPE_FORMAT_ELECTRONIC_KEY 0x00 /**< Message value indicating an electronic key */
  38. #define ELECTRONIC_KEY_SEGMENT_KEY_FORMAT_4 0x04
  39. #define NETWORK_SEGMENT_SCHEDULE 0x01 /**< Message value indicating a network segment schedule message */
  40. #define NETWORK_SEGMENT_FIXED_TAG 0x02 /**< Message value indicating a network segment fixed tag message */
  41. #define NETWORK_SEGMENT_PRODUCTION_INHIBIT_TIME_IN_MILLISECONDS 0x03 /**< Message value indicating a network segment PIT in milliseconds message */
  42. #define NETWORK_SEGMENT_SAFETY 0x04 /**< Message value indicating a network segment safety message */
  43. #define NETWORK_SEGMENT_PRODUCTION_INHIBIT_TIME_IN_MICROSECONDS 0x10 /**< Message value indicating a network segment PIT in microseconds message */
  44. #define NETWORK_SEGMENT_EXTENDED_NETWORK 0x1F /**< Message indicating a network message extended network message */
  45. #define SYMBOLIC_SEGMENT_FORMAT_EXTENDED_STRING 0x00
  46. #define SYMBOLIC_SEGMENT_EXTENDED_FORMAT_DOUBLE_CHAR 0x20
  47. #define SYMBOLIC_SEGMENT_EXTENDED_FORMAT_TRIPLE_CHAR 0x40
  48. #define SYMBOLIC_SEGMENT_EXTENDED_FORMAT_NUMERIC 0xC0
  49. #define SYMBOLIC_SEGMENT_EXTENDED_FORMAT_NUMERIC_USINT_TYPE 0x06
  50. #define SYMBOLIC_SEGMENT_EXTENDED_FORMAT_NUMERIC_UINT_TYPE 0x07
  51. #define SYMBOLIC_SEGMENT_EXTENDED_FORMAT_NUMERIC_UDINT_TYPE 0x08
  52. #define DATA_SEGMENT_SUBTYPE_SIMPLE_DATA 0x00
  53. #define DATA_SEGMENT_SUBTYPE_ANSI_EXTENDED_SYMBOL 0x11
  54. /** @brief Segment type Enum
  55. *
  56. * Bits 7-5 in the Segment Type/Format byte
  57. *
  58. */
  59. typedef enum segment_type {
  60. /* Segments */
  61. kSegmentTypePortSegment, /**< Port segment */
  62. kSegmentTypeLogicalSegment, /**< Logical segment */
  63. kSegmentTypeNetworkSegment, /**< Network segment */
  64. kSegmentTypeSymbolicSegment, /**< Symbolic segment */
  65. kSegmentTypeDataSegment, /**< Data segment */
  66. kSegmentTypeDataTypeConstructed, /**< Data type constructed */
  67. kSegmentTypeDataTypeElementary, /**< Data type elementary */
  68. kSegmentTypeReserved, /**< Reserved segment type */
  69. kSegmentTypeInvalid /**< Invalid segment type */
  70. } SegmentType;
  71. /** @brief Port Segment flags */
  72. typedef enum port_segment_type {
  73. kPortSegmentFlagExtendedLinkAddressSize = 0x10 /**< Extended Link Address Size flag, Port segment */
  74. } PortSegmentFlag;
  75. /** @brief Enum containing values which kind of logical segment is encoded */
  76. typedef enum logical_segment_type {
  77. kLogicalSegmentLogicalTypeClassId, /**< Class ID */
  78. kLogicalSegmentLogicalTypeInstanceId, /**< Instance ID */
  79. kLogicalSegmentLogicalTypeMemberId, /**< Member ID */
  80. kLogicalSegmentLogicalTypeConnectionPoint, /**< Connection Point */
  81. kLogicalSegmentLogicalTypeAttributeId, /**< Attribute ID */
  82. kLogicalSegmentLogicalTypeSpecial, /**< Special */
  83. kLogicalSegmentLogicalTypeServiceId, /**< Service ID */
  84. kLogicalSegmentLogicalTypeExtendedLogical, /**< Extended Logical */
  85. kLogicalSegmentLogicalTypeInvalid /**< Invalid segment type */
  86. } LogicalSegmentLogicalType;
  87. typedef enum logical_segment_extended_logical_type {
  88. kLogicalSegmentExtendedLogicalTypeReserved,
  89. kLogicalSegmentExtendedLogicalTypeArrayIndex,
  90. kLogicalSegmentExtendedLogicalTypeIndirectArrayIndex,
  91. kLogicalSegmentExtendedLogicalTypeBitIndex,
  92. kLogicalSegmentExtendedLogicalTypeIndirectBitIndex,
  93. kLogicalSegmentExtendedLogicalTypeStructureMemberNumber,
  94. kLogicalSegmentExtendedLogicalTypeStructureMemberHandle,
  95. kLogicalSegmentExtendedLogicalTypeInvalid
  96. } LogicalSegmentExtendedLogicalType;
  97. /** @brief Enum containing values how long the encoded value will be (8, 16, or
  98. * 32 bit) */
  99. typedef enum logical_segment_logical_format {
  100. kLogicalSegmentLogicalFormatEightBit,
  101. kLogicalSegmentLogicalFormatSixteenBit,
  102. kLogicalSegmentLogicalFormatThirtyTwoBit,
  103. kLogicalSegmentLogicalFormatInvalid
  104. } LogicalSegmentLogicalFormat;
  105. typedef enum logical_segment_special_type_logical_format {
  106. kLogicalSegmentSpecialTypeLogicalFormatReserved,
  107. kLogicalSegmentSpecialTypeLogicalFormatElectronicKey
  108. } LogicalSegmentSpecialTypeLogicalFormat;
  109. /** @brief Electronic key formats
  110. *
  111. */
  112. typedef enum electronic_key_segment_format {
  113. kElectronicKeySegmentFormatReserved, /**< Reserved */
  114. kElectronicKeySegmentFormatKeyFormat4 /**< Electronic key format 4 key */
  115. } ElectronicKeySegmentFormat;
  116. /** @brief All types of network segment types for the use in all code
  117. *
  118. * Enum constants for the different network segment subtypes to decouple code from the actual needed message values
  119. */
  120. typedef enum network_segment_subtype {
  121. kNetworkSegmentSubtypeReserved, /**< Reserverd */
  122. kNetworkSegmentSubtypeScheduleSegment, /**< Schedule segment */
  123. kNetworkSegmentSubtypeFixedTagSegment, /**< Fixed tag segment */
  124. kNetworkSegmentSubtypeProductionInhibitTimeInMilliseconds, /**< Production Inhibit Time in milliseconds segment */
  125. kNetworkSegmentSubtypeSafetySegment, /**< Safety segment */
  126. kNetworkSegmentSubtypeProductionInhibitTimeInMicroseconds, /**< Production Inhibit Time in microseconds segment */
  127. kNetworkSegmentSubtypeExtendedNetworkSegment /**< Extended network segment */
  128. } NetworkSegmentSubtype;
  129. /** @brief Data segment sub types
  130. *
  131. */
  132. typedef enum data_segment_subtype {
  133. kDataSegmentSubtypeReserved, /**< Reserved */
  134. kDataSegmentSubtypeSimpleData, /**< Simple Data segment */
  135. kDataSegmentSubtypeANSIExtendedSymbol /**< ANSI extended symbol segment */
  136. } DataSegmentSubtype;
  137. /** @brief Symbolic segment formats
  138. *
  139. */
  140. typedef enum symbolic_segment_format {
  141. kSymbolicSegmentFormatASCII, /**< ASCII format */
  142. kSymbolicSegmentFormatExtendedString /**< Extended String format */
  143. } SymbolicSegmentFormat;
  144. /** @brief Extended symbolic symbol formats
  145. *
  146. */
  147. typedef enum symbolic_segment_extended_format {
  148. kSymbolicSegmentExtendedFormatDoubleByteChars, /**< Double byte character encoding */
  149. kSymbolicSegmentExtendedFormatTripleByteChars, /**< Triple byte character encoding */
  150. kSymbolicSegmentExtendedFormatNumericSymbolUSINT, /**< Numeric USINT symbol */
  151. kSymbolicSegmentExtendedFormatNumericSymbolUINT, /**< Numeric UINT symbol */
  152. kSymbolicSegmentExtendedFormatNumericSymbolUDINT, /**< Numeric UDINT symbol */
  153. kSymbolicSegmentExtendedFormatReserved /**< Reserved */
  154. } SymbolicSegmentExtendedFormat;
  155. /* Start - Often used types of EPaths */
  156. typedef struct connection_path_epath {
  157. CipDword class_id; /**< here in accordance with Vol. 1 C-1.4.2 */
  158. CipInstanceNum instance_id;
  159. CipDword attribute_id_or_connection_point;
  160. } CipConnectionPathEpath;
  161. /* End - Often used types of EPaths */
  162. /** @brief Gets the basic segment type of a CIP EPath
  163. *
  164. * @param cip_path The start of the EPath message
  165. * @return The basic segment type
  166. */
  167. SegmentType GetPathSegmentType(const CipOctet *const cip_path);
  168. /** @brief Sets the basic segment type of an CIP EPath to be sent
  169. *
  170. * @param segment_type The segment type
  171. * @param cip_path A message buffer - Will be written on!
  172. */
  173. void SetPathSegmentType(SegmentType segment_type,
  174. unsigned char *const cip_path);
  175. /*********************************************************
  176. * Port Segment functions
  177. *********************************************************/
  178. /** @brief Only to be used on Port Segments. Returns if the Port Segment has the extended link address size bit set
  179. *
  180. * @param cip_path The start of the EPath message
  181. * @return True if extended link addres size bit set, false otherwise
  182. */
  183. bool GetPathPortSegmentExtendedLinkAddressSizeBit(
  184. const unsigned char *const cip_path);
  185. /** @brief Only to be used on Port Segments. Returns the Port Identifier
  186. *
  187. * @param cip_path The start of the EPath message
  188. * @return The Port Identifier
  189. */
  190. unsigned int GetPathPortSegmentPortIdentifier(
  191. const unsigned char *const cip_path);
  192. /** @brief Sets the Port Identifier form an Port Segment EPath to be sent.
  193. *
  194. * @param port_identifier The port identifier
  195. * @param cip_path A message buffer - Will be written on!
  196. */
  197. void SetPathPortSegmentPortIdentifier(const unsigned int port_identifier,
  198. unsigned char *const cip_path);
  199. /** @brief Only to be used on Port Segments. Gets the Link Address Size
  200. *
  201. * @param cip_path The start of the EPath message
  202. * @return The Link Address Size
  203. */
  204. unsigned int GetPathPortSegmentLinkAddressSize(
  205. const unsigned char *const cip_path);
  206. /** @brief Only to be used on Port Segments with Extended Port Number. Gets the Extended Port Number
  207. *
  208. * @param cip_path The start of the EPath message
  209. * @return The Link Address Size
  210. */
  211. unsigned int GetPathPortSegmentExtendedPortNumber(
  212. const unsigned char *const cip_path);
  213. /** @brief Sets the Extended Port Identifier in a EPath Port Segment message
  214. *
  215. * @param extended_port_identifier The extended port identifier to be encoded into the message
  216. * @param cip_path The start for the EPatch message
  217. */
  218. void SetPathPortSegmentExtendedPortIdentifier(
  219. const unsigned int extended_port_identifier,
  220. CipOctet *const cip_path);
  221. /** @brief Gets the Logical Type of an EPath Logical Segment message
  222. *
  223. * @param cip_path The start of the EPath message
  224. * @return The logical type of the logical segment
  225. */
  226. LogicalSegmentLogicalType GetPathLogicalSegmentLogicalType(
  227. const unsigned char *const cip_path);
  228. void SetPathLogicalSegmentLogicalType(LogicalSegmentLogicalType logical_type,
  229. CipOctet *const cip_path);
  230. /** @brief Gets the Logical Format of a Logical Segment EPath message
  231. *
  232. * @param cip_path The start of the EPath message
  233. * @return The logical format of the logical format
  234. */
  235. LogicalSegmentLogicalFormat GetPathLogicalSegmentLogicalFormat(
  236. const unsigned char *const cip_path);
  237. void SetPathLogicalSegmentLogicalFormat(LogicalSegmentLogicalFormat format,
  238. CipOctet *const cip_path);
  239. CipDword CipEpathGetLogicalValue(const EipUint8 **message);
  240. void CipEpathSetLogicalValue(const CipDword logical_value,
  241. const LogicalSegmentLogicalFormat logical_format,
  242. CipMessageRouterResponse *const message);
  243. /** @brief Gets the Extended Logical Type of a Logical Segment EPath message
  244. *
  245. * @param cip_path The start of the EPath message
  246. * @return The extended logical type of the logical segment
  247. */
  248. LogicalSegmentExtendedLogicalType GetPathLogicalSegmentExtendedLogicalType(
  249. const unsigned char *const cip_path);
  250. /** @brief Gets the Special Type Logical Type of a Logical Segment EPath message
  251. *
  252. * @param cip_path The start of the EPath message
  253. * @return The Special Type Logical Format subtype of a Logical Segment EPath message
  254. */
  255. LogicalSegmentSpecialTypeLogicalFormat
  256. GetPathLogicalSegmentSpecialTypeLogicalType(
  257. const unsigned char *const cip_path);
  258. /** @brief Gets the Electronic Key format of a Logical Segment Special Type EPath message
  259. *
  260. * @param cip_path The start of the EPath message
  261. * @return The Electronic Key Format used in the EPath
  262. */
  263. ElectronicKeySegmentFormat GetPathLogicalSegmentElectronicKeyFormat(
  264. const unsigned char *const cip_path);
  265. /** @brief Gets the data for an Electronic Key of format 4 from the EPath message
  266. *
  267. * @param cip_path The start of the EPath message
  268. * @param key Writes the data on the user provided data electronic key struct
  269. */
  270. void GetElectronicKeyFormat4FromMessage(const CipOctet **const cip_path,
  271. ElectronicKeyFormat4 *key);
  272. /** @brief Gets the Network Segment Subtype of a EPatch Network Segement EPath message
  273. *
  274. * @param cip_path The start of the EPath message
  275. * @return Network Segment subtype
  276. */
  277. NetworkSegmentSubtype GetPathNetworkSegmentSubtype(
  278. const unsigned char *const cip_path);
  279. /** @brief Gets the Production Inhibit Time in Milliseconds
  280. *
  281. * @param cip_path The start of the EPath message
  282. * @return The production Inhibit Time in Milliseconds
  283. */
  284. CipUsint GetPathNetworkSegmentProductionInhibitTimeInMilliseconds(
  285. const unsigned char *const cip_path);
  286. /** @brief Gets the Production Inhibit Time in Microseconds
  287. *
  288. * @param cip_path The start of the EPath message
  289. * @return The production Inhibit Time in Microseconds
  290. */
  291. CipUdint GetPathNetworkSegmentProductionInhibitTimeInMicroseconds(
  292. const unsigned char *const cip_path);
  293. /** @brief Gets the Data Segment subtype of a Data Segment EPath message
  294. *
  295. * @param cip_path The start of the EPath message
  296. * @return The Data Segment subtype
  297. */
  298. DataSegmentSubtype GetPathDataSegmentSubtype(
  299. const unsigned char *const cip_path);
  300. /** @brief Gets the data word length of a Simple Data segment
  301. *
  302. * @param cip_path The start of the EPath message
  303. * @return The length in words of the Simple Data segment
  304. */
  305. CipUsint GetPathDataSegmentSimpleDataWordLength(
  306. const unsigned char *const cip_path);
  307. /** @brief Gets the Symbolic Segment Format of the Symbolic Segment EPath message
  308. *
  309. * @param cip_path The start of the EPath message
  310. * @return The Symbolic Segment Format
  311. */
  312. SymbolicSegmentFormat GetPathSymbolicSegmentFormat(
  313. const unsigned char *const cip_path);
  314. /** @brief Gets the Numeric subtype of a Symbolic Segment Extended Format EPath message
  315. *
  316. * @param cip_path The start of the EPath message
  317. * @return The Numeric Extended Format subtype
  318. */
  319. SymbolicSegmentExtendedFormat GetPathSymbolicSegmentNumericType(
  320. const unsigned char *const cip_path);
  321. /** @brief Gets the Extended Format subtype of a Symbolic Segment EPath message
  322. *
  323. * @param cip_path The start of the EPath message
  324. * @return Symbolic Segment Extended Format
  325. */
  326. SymbolicSegmentExtendedFormat GetPathSymbolicSegmentExtendedFormat(
  327. const unsigned char *const cip_path);
  328. /* Special purpose encoding and decoding functions */
  329. size_t CipEpathEncodeConnectionEpath(
  330. const CipConnectionPathEpath *const connection_epath,
  331. CipOctet **encoded_path);
  332. bool CipEpathEqual(const CipOctet *const path1,
  333. const CipUint path1_length,
  334. const CipOctet *const path2,
  335. const CipUint path2_length);
  336. #endif /* SRC_CIP_CIPEPATH_H_ */