iso_connection_parameters.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /*
  2. * iso_connection_parameters.h
  3. *
  4. * Copyright 2013-2023 Michael Zillgith
  5. *
  6. * This file is part of libIEC61850.
  7. *
  8. * libIEC61850 is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * libIEC61850 is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with libIEC61850. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. * See COPYING file for the complete license text.
  22. */
  23. #ifndef ISO_CONNECTION_PARAMETERS_H_
  24. #define ISO_CONNECTION_PARAMETERS_H_
  25. #ifndef CONFIG_MMS_SUPPORT_TLS
  26. #define CONFIG_MMS_SUPPORT_TLS 0
  27. #endif
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #include "tls_config.h"
  32. /**
  33. * \addtogroup mms_client_api_group
  34. */
  35. /**@{*/
  36. /**
  37. * \brief authentication mechanism used by AcseAuthenticator
  38. */
  39. typedef enum
  40. {
  41. /** Neither ACSE nor TLS authentication used */
  42. ACSE_AUTH_NONE = 0,
  43. /** Use ACSE password for client authentication */
  44. ACSE_AUTH_PASSWORD = 1,
  45. /** Use ACSE certificate for client authentication */
  46. ACSE_AUTH_CERTIFICATE = 2,
  47. /** Use TLS certificate for client authentication */
  48. ACSE_AUTH_TLS = 3
  49. } AcseAuthenticationMechanism;
  50. typedef struct sAcseAuthenticationParameter* AcseAuthenticationParameter;
  51. struct sAcseAuthenticationParameter
  52. {
  53. AcseAuthenticationMechanism mechanism;
  54. union
  55. {
  56. struct
  57. {
  58. uint8_t* octetString;
  59. int passwordLength;
  60. } password; /* for mechanism = ACSE_AUTH_PASSWORD */
  61. struct
  62. {
  63. uint8_t* buf;
  64. int length;
  65. } certificate; /* for mechanism = ACSE_AUTH_CERTIFICATE or ACSE_AUTH_TLS */
  66. } value;
  67. };
  68. LIB61850_API AcseAuthenticationParameter
  69. AcseAuthenticationParameter_create(void);
  70. LIB61850_API void
  71. AcseAuthenticationParameter_destroy(AcseAuthenticationParameter self);
  72. LIB61850_API void
  73. AcseAuthenticationParameter_setAuthMechanism(AcseAuthenticationParameter self, AcseAuthenticationMechanism mechanism);
  74. LIB61850_API void
  75. AcseAuthenticationParameter_setPassword(AcseAuthenticationParameter self, char* password);
  76. /**
  77. * \brief Callback function to authenticate a client
  78. *
  79. * \param parameter user provided parameter - set when user registers the authenticator
  80. * \param authParameter the authentication parameters provided by the client
  81. * \param securityToken pointer where to store an application specific security token - can be ignored if not used.
  82. * \param appReference ISO application reference (ap-title + ae-qualifier)
  83. *
  84. * \return true if client connection is accepted, false otherwise
  85. */
  86. typedef bool
  87. (*AcseAuthenticator)(void* parameter, AcseAuthenticationParameter authParameter, void** securityToken, IsoApplicationReference* appReference);
  88. /**
  89. * \brief COTP T selector
  90. *
  91. * To not use T SEL set size to 0.
  92. */
  93. typedef struct {
  94. uint8_t size; /** 0 .. 4 - 0 means T-selector is not present */
  95. uint8_t value[4]; /** T-selector value */
  96. } TSelector;
  97. /**
  98. * \brief OSI session selector
  99. *
  100. * To not use S SEL set size to 0
  101. */
  102. typedef struct {
  103. uint8_t size; /** 0 .. 16 - 0 means S-selector is not present */
  104. uint8_t value[16]; /** S-selector value */
  105. } SSelector;
  106. /**
  107. * \brief OSI presentation (P) selector
  108. *
  109. * To not use P SEL set size to 0
  110. */
  111. typedef struct {
  112. uint8_t size; /** 0 .. 16 - 0 means P-selector is not present */
  113. uint8_t value[16]; /** P-selector value */
  114. } PSelector;
  115. struct sIsoConnectionParameters
  116. {
  117. AcseAuthenticationParameter acseAuthParameter;
  118. #if (CONFIG_MMS_SUPPORT_TLS == 1)
  119. TLSConfiguration tlsConfiguration;
  120. #endif
  121. const char* hostname;
  122. int tcpPort;
  123. const char* localIpAddress;
  124. int localTcpPort;
  125. uint8_t remoteApTitle[10];
  126. int remoteApTitleLen;
  127. int remoteAEQualifier;
  128. PSelector remotePSelector;
  129. SSelector remoteSSelector;
  130. TSelector remoteTSelector;
  131. uint8_t localApTitle[10];
  132. int localApTitleLen;
  133. int localAEQualifier;
  134. PSelector localPSelector;
  135. SSelector localSSelector;
  136. TSelector localTSelector;
  137. };
  138. typedef struct sIsoConnectionParameters* IsoConnectionParameters;
  139. /**
  140. * \brief create a new IsoConnectionParameters instance (FOR LIBRARY INTERNAL USE)
  141. *
  142. * NOTE: This function used internally by the MMS client library. When using the MMS or IEC 61850 API
  143. * there should be no reason for the user to call this function.
  144. *
  145. * \return new IsoConnectionParameters instance
  146. */
  147. LIB61850_API IsoConnectionParameters
  148. IsoConnectionParameters_create(void);
  149. /**
  150. * \brief Destroy an IsoConnectionParameters instance (FOR LIBRARY INTERNAL USE)
  151. *
  152. * NOTE: This function used internally by the MMS client library. When using the MMS or IEC 61850 API
  153. * there should be no reason for the user to call this function.
  154. *
  155. * \param self the IsoConnectionParameters instance
  156. */
  157. LIB61850_API void
  158. IsoConnectionParameters_destroy(IsoConnectionParameters self);
  159. LIB61850_API void
  160. IsoConnectionParameters_setTlsConfiguration(IsoConnectionParameters self, TLSConfiguration tlsConfig);
  161. /**
  162. * \brief set the authentication parameter
  163. *
  164. * This will set the authentication parameter and activates authentication.
  165. *
  166. * \param self the IsoConnectionParameters instance
  167. * \param acseAuthParameter
  168. */
  169. LIB61850_API void
  170. IsoConnectionParameters_setAcseAuthenticationParameter(IsoConnectionParameters self,
  171. AcseAuthenticationParameter acseAuthParameter);
  172. /**
  173. * \brief Set TCP parameters (FOR LIBRARY INTERNAL USE)
  174. *
  175. * NOTE: This function used internally by the MMS client library. When using the MMS or IEC 61850 API
  176. * there should be no reason for the user to call this function
  177. *
  178. * \param self the IsoConnectionParameters instance
  179. * \param hostname the hostname of IP address if the server
  180. * \param tcpPort the TCP port number of the server
  181. */
  182. LIB61850_API void
  183. IsoConnectionParameters_setTcpParameters(IsoConnectionParameters self, const char* hostname, int tcpPort);
  184. /**
  185. * \brief Set Local TCP parameters (FOR LIBRARY INTERNAL USE)
  186. *
  187. * NOTE: This function used internally by the MMS Client library. When using the MMS or IEC 61850 API
  188. * there should be no reason for the user to call this function
  189. *
  190. * \param self the IsoConnectionParameters instance
  191. * \param localIpAddress the hostname of local IP address of the server
  192. * \param localTcpPort the local TCP port number of the server
  193. */
  194. LIB61850_API void
  195. IsoConnectionParameters_setLocalTcpParameters(IsoConnectionParameters self, const char* localIpAddress, int localTcpPort);
  196. /**
  197. * \brief set the remote AP-Title and AE-Qualifier
  198. *
  199. * Calling this function is optional and not recommended. If not called the default
  200. * parameters are used.
  201. * If apTitle is NULL the parameter the AP-Title and AE-Qualifier will not be transmitted.
  202. * This seems to be required by some server devices.
  203. *
  204. * \param self the IsoConnectionParameters instance
  205. * \param apTitle the AP-Title OID as string.
  206. * \param aeQualifier the AP-qualifier
  207. */
  208. LIB61850_API void
  209. IsoConnectionParameters_setRemoteApTitle(IsoConnectionParameters self, const char* apTitle, int aeQualifier);
  210. /**
  211. * \brief set remote addresses for the lower layers
  212. *
  213. * This function can be used to set the addresses for the lower layer protocols (presentation, session, and transport
  214. * layer). Calling this function is optional and not recommended. If not called the default
  215. * parameters are used.
  216. *
  217. * \param self the IsoConnectionParameters instance
  218. * \param pSelector the P-Selector (presentation layer address)
  219. * \param sSelector the S-Selector (session layer address)
  220. * \param tSelector the T-Selector (ISO transport layer address)
  221. */
  222. LIB61850_API void
  223. IsoConnectionParameters_setRemoteAddresses(IsoConnectionParameters self, PSelector pSelector, SSelector sSelector, TSelector tSelector);
  224. /**
  225. * \brief set the local AP-Title and AE-Qualifier
  226. *
  227. * Calling this function is optional and not recommended. If not called the default
  228. * parameters are used.
  229. * If apTitle is NULL the parameter the AP-Title and AE-Qualifier will not be transmitted.
  230. * This seems to be required by some server devices.
  231. *
  232. * \param self the IsoConnectionParameters instance
  233. * \param apTitle the AP-Title OID as string.
  234. * \param aeQualifier the AP-qualifier
  235. */
  236. LIB61850_API void
  237. IsoConnectionParameters_setLocalApTitle(IsoConnectionParameters self, const char* apTitle, int aeQualifier);
  238. /**
  239. * \brief set local addresses for the lower layers
  240. *
  241. * This function can be used to set the addresses for the lower layer protocols (presentation, session, and transport
  242. * layer). Calling this function is optional and not recommended. If not called the default
  243. * parameters are used.
  244. *
  245. * \param self the IsoConnectionParameters instance
  246. * \param pSelector the P-Selector (presentation layer address)
  247. * \param sSelector the S-Selector (session layer address)
  248. * \param tSelector the T-Selector (ISO transport layer address)
  249. */
  250. LIB61850_API void
  251. IsoConnectionParameters_setLocalAddresses(IsoConnectionParameters self, PSelector pSelector, SSelector sSelector, TSelector tSelector);
  252. /**@}*/
  253. #ifdef __cplusplus
  254. }
  255. #endif
  256. #endif /* ISO_CONNECTION_PARAMETERS_H_ */