cipelectronickey.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*******************************************************************************
  2. * Copyright (c) 2016, Rockwell Automation, Inc.
  3. * All rights reserved.
  4. *
  5. ******************************************************************************/
  6. #ifndef SRC_CIP_CIPELECTRONICKEY_H_
  7. #define SRC_CIP_CIPELECTRONICKEY_H_
  8. #include <stdbool.h>
  9. #include "typedefs.h"
  10. /** @brief CIP Electronic Key Segment struct
  11. *
  12. */
  13. typedef struct {
  14. CipUsint key_format; /**< Key Format 0-3 reserved, 4 = see Key Format Table,
  15. 5-255 = Reserved */
  16. void *key_data; /**< Depends on key format used, usually Key Format 4 as
  17. specified in CIP Specification, Volume 1*/
  18. } CipElectronicKey;
  19. void ElectronicKeySetSegmentType(CipElectronicKey *const electronic_key,
  20. const CipUsint segment_type);
  21. CipUsint ElectronicKeyGetSegmentType(
  22. const CipElectronicKey *const electronic_key);
  23. void ElectronicKeySetKeyFormat(CipElectronicKey *const electronic_key,
  24. const CipUsint key_format);
  25. CipUint ElectronicKeyGetKeyFormat(const CipElectronicKey *const electronic_key);
  26. void ElectronicKeySetKeyData(CipElectronicKey *const electronic_key,
  27. void *key_data);
  28. void *ElectronicKeyGetKeyData(const CipElectronicKey *const electronic_key);
  29. /** @brief Declaration of the electronic key format 4 data struct for the class
  30. *
  31. */
  32. typedef struct electronic_key_format_4 ElectronicKeyFormat4;
  33. extern const size_t kElectronicKeyFormat4Size;
  34. /** @brief Constructor for the electroic key format 4 class
  35. *
  36. * @return A new unset electronic key
  37. */
  38. ElectronicKeyFormat4 *ElectronicKeyFormat4New(void);
  39. /** @brief Destructor for the electroic key format 4 class
  40. *
  41. * Safe destructor/free, nulls the pointer after freeing it
  42. * @param electronic_key A format 4 electronic key
  43. */
  44. void ElectronicKeyFormat4Delete(ElectronicKeyFormat4 **electronic_key);
  45. /** @brief Sets vendor ID in the electronic key
  46. * @param electronic_key The electronic key to be set - will be modified
  47. * @param vendor_id The vendor ID to be set into the electronic key
  48. */
  49. void ElectronicKeyFormat4SetVendorId(ElectronicKeyFormat4 *const electronic_key,
  50. const CipUint vendor_id);
  51. /** @brief Gets the vendor ID form the electronic key
  52. *
  53. * @param electronic_key The format 4 electronic key from which the vendor ID will be extracted
  54. * @return The vendor ID
  55. */
  56. CipUint ElectronicKeyFormat4GetVendorId(
  57. const ElectronicKeyFormat4 *const electronic_key);
  58. /** @brief Sets the device type in the electronic key
  59. *
  60. * @param electronic_key A format 4 electronic key
  61. * @param device_type The device type which shall be inserted into the electronic key
  62. */
  63. void ElectronicKeyFormat4SetDeviceType(
  64. ElectronicKeyFormat4 *const electronic_key,
  65. const CipUint device_type);
  66. /** @brief Gets the device type from a format 4 electronic key
  67. *
  68. * @param electronic_key The format 4 electronic key from which the device type will be extracted
  69. * @return The device type
  70. */
  71. CipUint ElectronicKeyFormat4GetDeviceType(
  72. const ElectronicKeyFormat4 *const electronic_key);
  73. /** @brief Set product code in the electronic key
  74. *
  75. * @param electronic_key The electronic key to be modified
  76. * @param product_code The product code to be inserted
  77. */
  78. void ElectronicKeyFormat4SetProductCode(
  79. ElectronicKeyFormat4 *const electronic_key,
  80. const CipUint product_code);
  81. /** @brief Gets the product code from an format 4 electronic key
  82. *
  83. * @param electronic_key The format 4 electronic key to be read
  84. * @return The product code
  85. */
  86. CipUint ElectronicKeyFormat4GetProductCode(
  87. const ElectronicKeyFormat4 *const electronic_key);
  88. /** @brief Sets the major revision byte including the compatibility flag
  89. *
  90. * @param major_revision_compatibility The major revision byte including the compatibility flag
  91. * @param electronic_key The electronic key to be modified
  92. */
  93. void ElectronicKeyFormat4SetMajorRevisionCompatibility(
  94. ElectronicKeyFormat4 *const electronic_key,
  95. const CipByte major_revision_compatibility);
  96. /** @brief Gets the major revision from an format 4 electronic key
  97. *
  98. * @param electronic_key An format 4 electronic key
  99. * @return The device's major revision
  100. */
  101. CipByte ElectronicKeyFormat4GetMajorRevision(
  102. const ElectronicKeyFormat4 *const electronic_key);
  103. /** @brief Gets the Compatibility flag from the format 4 electronic key
  104. *
  105. * @param electronic_key The format 4 electronic key to be read
  106. * @return True if compatibility bit is set, false if otherwise
  107. */
  108. bool ElectronicKeyFormat4GetMajorRevisionCompatibility(
  109. const ElectronicKeyFormat4 *const electronic_key);
  110. /** @brief Sets the devices minor revision in an format 4 electronic key
  111. *
  112. * @param minor_revision The minor revision to be set in the electronic key
  113. * @param electronic_key The electronic key to be modified
  114. */
  115. void ElectronicKeyFormat4SetMinorRevision(
  116. ElectronicKeyFormat4 *const electronic_key,
  117. const CipUsint minor_revision);
  118. /** @brief Gets the minor revision from an format 4 electronic key
  119. *
  120. * @param electronic_key The format 4 electronic key to be read
  121. * @return The device's minor revision
  122. */
  123. CipUsint ElectronicKeyFormat4GetMinorRevision(
  124. const ElectronicKeyFormat4 *const electronic_key);
  125. #endif /* SRC_CIP_CIPELECTRONICKEY_H_ */