cipcommon.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*******************************************************************************
  2. * Copyright (c) 2009, Rockwell Automation, Inc.
  3. * All rights reserved.
  4. *
  5. ******************************************************************************/
  6. #ifndef OPENER_CIPCOMMON_H_
  7. #define OPENER_CIPCOMMON_H_
  8. /** @file cipcommon.h
  9. * Common CIP object interface
  10. */
  11. #include "typedefs.h"
  12. #include "ciptypes.h"
  13. static const EipUint16 kCipUintZero = 0; /**< Zero value for returning the UINT standard value */
  14. /** @brief Check if requested service present in class/instance and call appropriate service.
  15. *
  16. * @param cip_class class receiving the message
  17. * @param message_router_request request message
  18. * @param message_router_response reply message
  19. * @param originator_address address struct of the originator as received
  20. * @param encapsulation_session associated encapsulation session of the explicit message
  21. * @return
  22. * - kEipStatusOkSend ... success
  23. * - kEipStatusOk ... no reply to send back
  24. * - kEipStatusError ... error
  25. */
  26. EipStatus NotifyClass(const CipClass *const RESTRICT cip_class,
  27. CipMessageRouterRequest *const message_router_request,
  28. CipMessageRouterResponse *const message_router_response,
  29. const struct sockaddr *originator_address,
  30. const CipSessionHandle encapsulation_session);
  31. /** @brief Get largest instance_number present in class instances
  32. *
  33. * @param cip_class class to be considered
  34. * @return largest instance_number in class instances
  35. */
  36. CipUint GetMaxInstanceNumber(CipClass *RESTRICT const cip_class);
  37. void GenerateGetAttributeSingleHeader(
  38. const CipMessageRouterRequest *const message_router_request,
  39. CipMessageRouterResponse *const message_router_response);
  40. /** @brief Generic implementation of the GetAttributeSingle CIP service
  41. *
  42. * Check from classID which Object requests an attribute, search if object has
  43. * the appropriate attribute implemented.
  44. * @param instance pointer to instance.
  45. * @param message_router_request pointer to request.
  46. * @param message_router_response pointer to response.
  47. * @param originator_address address struct of the originator as received
  48. * @param encapsulation_session associated encapsulation session of the explicit message
  49. * @return status >0 .. success
  50. * -1 .. requested attribute not available
  51. */
  52. EipStatus GetAttributeSingle(
  53. CipInstance *RESTRICT const instance,
  54. CipMessageRouterRequest *const
  55. message_router_request,
  56. CipMessageRouterResponse *const
  57. message_router_response,
  58. const struct sockaddr *originator_address,
  59. const CipSessionHandle encapsulation_session);
  60. void GenerateSetAttributeSingleHeader(
  61. const CipMessageRouterRequest *const message_router_request,
  62. CipMessageRouterResponse *const message_router_response);
  63. /** @brief Generic implementation of the SetAttributeSingle CIP service
  64. *
  65. * Modifies an attribute value if the requested object has
  66. * the appropriate attribute implemented and if the attribute is settable.
  67. *
  68. * @param instance pointer to instance.
  69. * @param message_router_request pointer to request.
  70. * @param message_router_response pointer to response.
  71. * @param originator_address address struct of the originator as received
  72. * @param encapsulation_session associated encapsulation session of the explicit message
  73. * @return status >0 .. success
  74. * -1 .. requested attribute not set
  75. */
  76. EipStatus SetAttributeSingle(
  77. CipInstance *RESTRICT const instance,
  78. CipMessageRouterRequest *const
  79. message_router_request,
  80. CipMessageRouterResponse *const
  81. message_router_response,
  82. const struct sockaddr *originator_address,
  83. const CipSessionHandle encapsulation_session);
  84. /** @brief Generic implementation of the GetAttributeAll CIP service
  85. *
  86. * Copy all attributes from Object into the global message buffer.
  87. * @param instance pointer to object instance with data.
  88. * @param message_router_request pointer to MR request.
  89. * @param message_router_response pointer for MR response.
  90. * @param originator_address address struct of the originator as received
  91. * @param encapsulation_session associated encapsulation session of the explicit message
  92. * @return length of data stream >0 .. success
  93. * 0 .. no reply to send
  94. */
  95. EipStatus GetAttributeAll(CipInstance *instance,
  96. CipMessageRouterRequest *message_router_request,
  97. CipMessageRouterResponse *message_router_response,
  98. const struct sockaddr *originator_address,
  99. const CipSessionHandle encapsulation_session);
  100. /** @brief Generic implementation of the GetAttributeList CIP service
  101. *
  102. * Copy the contents of the selected gettable attributes of the specified
  103. * object class or instance into the global message buffer.
  104. * @param instance pointer to object instance with data.
  105. * @param message_router_request pointer to MR request.
  106. * @param message_router_response pointer for MR response.
  107. * @param originator_address address struct of the originator as received
  108. * @param encapsulation_session associated encapsulation session of the explicit message
  109. * @return length of data stream >0 .. success
  110. * 0 .. no reply to send
  111. */
  112. EipStatus GetAttributeList(CipInstance *instance,
  113. CipMessageRouterRequest *message_router_request,
  114. CipMessageRouterResponse *message_router_response,
  115. const struct sockaddr *originator_address,
  116. const CipSessionHandle encapsulation_session);
  117. /** @brief Generic implementation of the SetAttributeList CIP service
  118. *
  119. * Sets the values of selected attributes of the specified object class
  120. * or instance.
  121. * @param instance pointer to object instance with data.
  122. * @param message_router_request pointer to MR request.
  123. * @param message_router_response pointer to MR response.
  124. * @param originator_address address struct of the originator as received
  125. * @param encapsulation_session associated encapsulation session of the explicit message
  126. * @return length of data stream >0 .. success
  127. * 0 .. no reply to send
  128. */
  129. EipStatus SetAttributeList(CipInstance *instance,
  130. CipMessageRouterRequest *message_router_request,
  131. CipMessageRouterResponse *message_router_response,
  132. const struct sockaddr *originator_address,
  133. const CipSessionHandle encapsulation_session);
  134. /** @brief Decodes padded EPath
  135. * @param epath EPath object to the receiving element
  136. * @param message pointer to the message to decode
  137. * @return Number of decoded bytes
  138. */
  139. int DecodePaddedEPath(CipEpath *epath,
  140. const EipUint8 **message);
  141. /** @brief Generic implementation of the CIP Create service
  142. *
  143. * Creates dynamically allocated object instance within the specified class.
  144. *
  145. * @param instance pointer to instance.
  146. * @param message_router_request pointer to request.
  147. * @param message_router_response pointer to response.
  148. * @param originator_address address struct of the originator as received
  149. * @param encapsulation_session associated encapsulation session of the explicit message
  150. * @return status >0 .. success
  151. * -1 .. requested instance not created
  152. */
  153. EipStatus CipCreateService(
  154. CipInstance *RESTRICT const instance,
  155. CipMessageRouterRequest *const
  156. message_router_request,
  157. CipMessageRouterResponse *const
  158. message_router_response,
  159. const struct sockaddr *originator_address,
  160. const CipSessionHandle encapsulation_session);
  161. /** @brief Generic implementation of the CIP Delete service
  162. *
  163. * Deletes dynamically allocated object instance within the specified class
  164. * and updates referred class attributes
  165. *
  166. * @param instance pointer to instance.
  167. * @param message_router_request pointer to request.
  168. * @param message_router_response pointer to response.
  169. * @param originator_address address struct of the originator as received
  170. * @param encapsulation_session associated encapsulation session of the explicit message
  171. * @return status >0 .. success
  172. * -1 .. requested instance not deleted
  173. */
  174. EipStatus CipDeleteService(CipInstance *RESTRICT const instance,
  175. CipMessageRouterRequest *const
  176. message_router_request,
  177. CipMessageRouterResponse *const
  178. message_router_response,
  179. const struct sockaddr *originator_address,
  180. const CipSessionHandle encapsulation_session);
  181. /** @brief Generic implementation of the CIP Reset service
  182. *
  183. * Causes a transition to a default state or mode of
  184. * the object instance within the specified class
  185. *
  186. *
  187. * @param instance pointer to instance.
  188. * @param message_router_request pointer to request.
  189. * @param message_router_response pointer to response.
  190. * @param originator_address address struct of the originator as received
  191. * @param encapsulation_session associated encapsulation session of the explicit message
  192. * @return status >0 .. success
  193. * -1 .. requested instance not reseted
  194. */
  195. EipStatus CipResetService(CipInstance *RESTRICT const instance,
  196. CipMessageRouterRequest *const
  197. message_router_request,
  198. CipMessageRouterResponse *const
  199. message_router_response,
  200. const struct sockaddr *originator_address,
  201. const CipSessionHandle encapsulation_session);
  202. #endif /* OPENER_CIPCOMMON_H_ */