iso_connection_parameters.h 8.6 KB

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