mms_server.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. /*
  2. * mms_server.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 MMS_SERVER_H_
  24. #define MMS_SERVER_H_
  25. /** \addtogroup mms_server_api_group
  26. * @{
  27. */
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #include "mms_value.h"
  32. #include "iso_connection_parameters.h"
  33. typedef enum {
  34. MMS_SERVER_NEW_CONNECTION,
  35. MMS_SERVER_CONNECTION_CLOSED,
  36. MMS_SERVER_CONNECTION_TICK
  37. } MmsServerEvent;
  38. typedef struct sMmsServer* MmsServer;
  39. typedef struct sMmsServerConnection* MmsServerConnection;
  40. typedef enum {
  41. MMS_DOMAIN_SPECIFIC,
  42. MMS_ASSOCIATION_SPECIFIC,
  43. MMS_VMD_SPECIFIC
  44. } MmsVariableListType;
  45. LIB61850_INTERNAL void
  46. MmsServer_setLocalIpAddress(MmsServer self, const char* localIpAddress);
  47. LIB61850_INTERNAL bool
  48. MmsServer_isRunning(MmsServer self);
  49. typedef enum {
  50. MMS_VARLIST_CREATE,
  51. MMS_VARLIST_DELETE,
  52. MMS_VARLIST_READ,
  53. MMS_VARLIST_WRITE,
  54. MMS_VARLIST_GET_DIRECTORY
  55. } MmsVariableListAccessType;
  56. /**
  57. * \brief callback handler that is called for each named variable list access
  58. *
  59. * \param parameter a user provided parameter
  60. * \param accessType the kind of access (create, delete, read, write, get directory)
  61. * \param listType the type (scope) of the named variable list (either domain, association or VMD specific)
  62. * \param domain the MMS domain the list is belonging to (is NULL for association or VMD specific lists!)
  63. * \param listName the name
  64. * \param connection client connection that is accessing the named variable list
  65. *
  66. * \return MMS_ERROR_NONE if the request is accepted, otherwise the MmsError value that has to be sent back to the client
  67. */
  68. typedef MmsError (*MmsNamedVariableListAccessHandler)(void* parameter, MmsVariableListAccessType accessType, MmsVariableListType listType, MmsDomain* domain,
  69. char* listName, MmsServerConnection connection);
  70. /**
  71. * \brief Install callback handler that is called when a named variable list is accessed by a client
  72. *
  73. * \param self the MmsServer instance to operate on
  74. * \param handler the callback handler function
  75. * \param parameter user provided parameter that is passed to the callback handler
  76. */
  77. LIB61850_INTERNAL void
  78. MmsServer_installVariableListAccessHandler(MmsServer self, MmsNamedVariableListAccessHandler handler, void* parameter);
  79. /**
  80. * \brief callback handler that is called for each received read journal request
  81. *
  82. * \param parameter a user provided parameter
  83. * \param domain the MMS domain the journal is belonging to
  84. * \param logName the name of the journal
  85. * \param connection client connection that is accessing the journal
  86. */
  87. typedef bool (*MmsReadJournalHandler)(void* parameter, MmsDomain* domain, const char* logName, MmsServerConnection connection);
  88. /**
  89. * \brief Install callback handler that is called when a journal is accessed by a client
  90. *
  91. * \param self the MmsServer instance to operate on
  92. * \param handler the callback handler function
  93. * \param parameter user provided parameter that is passed to the callback handler
  94. */
  95. LIB61850_INTERNAL void
  96. MmsServer_installReadJournalHandler(MmsServer self, MmsReadJournalHandler handler, void* parameter);
  97. typedef enum {
  98. MMS_GETNAMELIST_DOMAINS,
  99. MMS_GETNAMELIST_JOURNALS,
  100. MMS_GETNAMELIST_DATASETS,
  101. MMS_GETNAMELIST_DATA
  102. } MmsGetNameListType;
  103. typedef bool (*MmsGetNameListHandler)(void* parameter, MmsGetNameListType nameListType, MmsDomain* domain, MmsServerConnection connection);
  104. LIB61850_INTERNAL void
  105. MmsServer_installGetNameListHandler(MmsServer self, MmsGetNameListHandler handler, void* parameter);
  106. /**
  107. * \brief ObtainFile service callback handler
  108. *
  109. * This is invoked when the obtainFile service is requested by the client. It can be used to accept or deny the
  110. * write access to the file system based on the client connection.
  111. *
  112. * \param parameter user provided parameter that is passed to the callback handler
  113. * \param connection the connection that requested the service
  114. * \param sourceFilename the source file name on the client side system
  115. * \param destinationFilename the target file name on the server side system
  116. */
  117. typedef bool (*MmsObtainFileHandler)(void* parameter, MmsServerConnection connection, const char* sourceFilename, const char* destinationFilename);
  118. /**
  119. * \brief Install callback handler that is invoked when the file upload (obtainFile service) is invoked by the client
  120. *
  121. * This handler can be used to apply access restrictions on the file upload (obtainFile) service
  122. *
  123. * \param self the MmsServer instance to operate on
  124. * \param handler the callback handler function
  125. * \param parameter user provided parameter that is passed to the callback handler
  126. */
  127. LIB61850_INTERNAL void
  128. MmsServer_installObtainFileHandler(MmsServer self, MmsObtainFileHandler handler, void* parameter);
  129. /**
  130. * \brief Get file complete (obtainFile service terminated) callback handler
  131. *
  132. * This handler can be used to invoke some actions after a file upload is complete.
  133. *
  134. * \param parameter user provided parameter that is passed to the callback handler
  135. * \param connection the connection that requested the service
  136. * \param destinationFilename the target file name on the server side system
  137. */
  138. typedef void (*MmsGetFileCompleteHandler)(void* parameter, MmsServerConnection connection, const char* destinationFilename);
  139. /**
  140. * \brief Install callback handler that is invoked when the file upload (obtainFile service) is completed and the
  141. * file has been uploaded.
  142. *
  143. * \param self the MmsServer instance
  144. * \param handler the callback handler function
  145. * \param parameter user provided parameter that is passed to the callback handler
  146. */
  147. LIB61850_INTERNAL void
  148. MmsServer_installGetFileCompleteHandler(MmsServer self, MmsGetFileCompleteHandler handler, void* parameter);
  149. typedef enum {
  150. MMS_FILE_ACCESS_TYPE_READ_DIRECTORY,
  151. MMS_FILE_ACCESS_TYPE_OPEN,
  152. MMS_FILE_ACCESS_TYPE_OBTAIN,
  153. MMS_FILE_ACCESS_TYPE_DELETE,
  154. MMS_FILE_ACCESS_TYPE_RENAME
  155. } MmsFileServiceType;
  156. /**
  157. * \brief MmsFileAccessHandler callback function. Use to monitor and control file access
  158. *
  159. * \param parameter user provided parameter that is passed to the callback handler
  160. * \param connection the connection that requested the service
  161. * \param service the requested file service
  162. * \param localFilename the requested file or directory name at the server
  163. * \param otherFilename a second file name parameter (e.g. source file of the ObtainFile or new file of rename file)
  164. *
  165. * \return MMS_ERROR_NONE when the request is accepted, otherwise use the appropriate error code (e.g. MMS_ERROR_FILE_FILE_ACCESS_DENIED)
  166. */
  167. typedef MmsError (*MmsFileAccessHandler) (void* parameter, MmsServerConnection connection, MmsFileServiceType service,
  168. const char* localFilename, const char* otherFilename);
  169. /**
  170. * \brief Install a callback handler this is invoked when the client requests a file server. This function can be
  171. * used to monitor and control file access
  172. *
  173. * \param self the MmsServer instance
  174. * \param handler the callback handler function
  175. * \param parameter user provided parameter that is passed to the callback handler
  176. */
  177. LIB61850_API void
  178. MmsServer_installFileAccessHandler(MmsServer self, MmsFileAccessHandler handler, void* parameter);
  179. /**
  180. * \brief Set the virtual filestore basepath for the MMS file services
  181. *
  182. * All external file service accesses will be mapped to paths relative to the base directory.
  183. * NOTE: This function is only available when the CONFIG_SET_FILESTORE_BASEPATH_AT_RUNTIME
  184. * option in stack_config.h is set.
  185. *
  186. * \param self the MmsServer instance
  187. * \param basepath the new virtual filestore basepath
  188. */
  189. LIB61850_INTERNAL void
  190. MmsServer_setFilestoreBasepath(MmsServer self, const char* basepath);
  191. /**
  192. * \brief Set the maximum number of TCP client connections
  193. *
  194. * \param[in] maxConnections the maximum number of TCP client connections to accept
  195. */
  196. LIB61850_INTERNAL void
  197. MmsServer_setMaxConnections(MmsServer self, int maxConnections);
  198. /**
  199. * \brief Enable/disable MMS file services at runtime
  200. *
  201. * NOTE: requires CONFIG_MMS_SERVER_CONFIG_SERVICES_AT_RUNTIME = 1 in stack configuration
  202. *
  203. * \param[in] self the MmsServer instance
  204. * \param[in] enable true to enable file services, false to disable
  205. */
  206. LIB61850_INTERNAL void
  207. MmsServer_enableFileService(MmsServer self, bool enable);
  208. /**
  209. * \brief Enable/disable dynamic named variable list (data set) service
  210. *
  211. * NOTE: requires CONFIG_MMS_SERVER_CONFIG_SERVICES_AT_RUNTIME = 1 in stack configuration
  212. *
  213. * \param[in] self the MmsServer instance
  214. * \param[in] enable true to enable named variable list services, false to disable
  215. */
  216. LIB61850_INTERNAL void
  217. MmsServer_enableDynamicNamedVariableListService(MmsServer self, bool enable);
  218. /**
  219. * \brief Set the maximum number of association specific data sets (per connection)
  220. *
  221. * \param[in] self the MmsServer instance
  222. * \param[in] maxDataSets maximum number association specific data sets
  223. */
  224. LIB61850_INTERNAL void
  225. MmsServer_setMaxAssociationSpecificDataSets(MmsServer self, int maxDataSets);
  226. /**
  227. * \brief Set the maximum number of domain specific data sets
  228. *
  229. * \param[in] self the MmsServer instance
  230. * \param[in] maxDataSets maximum number domain specific data sets
  231. */
  232. LIB61850_INTERNAL void
  233. MmsServer_setMaxDomainSpecificDataSets(MmsServer self, int maxDataSets);
  234. /**
  235. * \brief Set the maximum number of data set entries (for dynamic data sets)
  236. *
  237. * \param[in] self the MmsServer instance
  238. * \param[in] maxDataSetEntries maximum number of dynamic data set entries
  239. */
  240. LIB61850_INTERNAL void
  241. MmsServer_setMaxDataSetEntries(MmsServer self, int maxDataSetEntries);
  242. /**
  243. * \brief Enable/disable journal service
  244. *
  245. * NOTE: requires CONFIG_MMS_SERVER_CONFIG_SERVICES_AT_RUNTIME = 1 in stack configuration
  246. *
  247. * \param[in] self the MmsServer instance
  248. * \param[in] enable true to enable journal service, false to disable
  249. */
  250. LIB61850_INTERNAL void
  251. MmsServer_enableJournalService(MmsServer self, bool enable);
  252. /***************************************************
  253. * Functions for MMS identify service
  254. ***************************************************/
  255. /**
  256. * \brief set the values that the server will give as response for an MMS identify request
  257. *
  258. * With this function the VMD identity attributes can be set programmatically. If not set by this
  259. * function the default values form stack_config.h are used.
  260. *
  261. * \param self the MmsServer instance to operate on
  262. * \param vendorName the vendor name attribute of the VMD
  263. * \param modelName the model name attribute of the VMD
  264. * \param revision the revision attribute of the VMD
  265. */
  266. LIB61850_INTERNAL void
  267. MmsServer_setServerIdentity(MmsServer self, char* vendorName, char* modelName, char* revision);
  268. /**
  269. * \brief get the vendor name attribute of the VMD identity
  270. *
  271. * \param self the MmsServer instance to operate on
  272. * \return the vendor name attribute of the VMD as C string
  273. */
  274. LIB61850_INTERNAL char*
  275. MmsServer_getVendorName(MmsServer self);
  276. /**
  277. * \brief get the model name attribute of the VMD identity
  278. *
  279. * \param self the MmsServer instance to operate on
  280. * \return the model name attribute of the VMD as C string
  281. */
  282. LIB61850_INTERNAL char*
  283. MmsServer_getModelName(MmsServer self);
  284. /**
  285. * \brief get the revision attribute of the VMD identity
  286. *
  287. * \param self the MmsServer instance to operate on
  288. * \return the revision attribute of the VMD as C string
  289. */
  290. LIB61850_INTERNAL char*
  291. MmsServer_getRevision(MmsServer self);
  292. /***************************************************
  293. * Functions for MMS status service
  294. ***************************************************/
  295. #define MMS_LOGICAL_STATE_STATE_CHANGES_ALLOWED 0
  296. #define MMS_LOGICAL_STATE_NO_STATE_CHANGES_ALLOWED 1
  297. #define MMS_LOGICAL_STATE_LIMITED_SERVICES_PERMITTED 2
  298. #define MMS_LOGICAL_STATE_SUPPORT_SERVICES_ALLOWED 3
  299. #define MMS_PHYSICAL_STATE_OPERATIONAL 0
  300. #define MMS_PHYSICAL_STATE_PARTIALLY_OPERATIONAL 1
  301. #define MMS_PHYSICAL_STATE_INOPERATIONAL 2
  302. #define MMS_PHYSICAL_STATE_NEEDS_COMMISSIONING 3
  303. /**
  304. * \brief User provided handler that is invoked on a MMS status request
  305. *
  306. * The extendedDerivation parameter indicates that the client requests the server to perform
  307. * self diagnosis tests before answering the request.
  308. *
  309. * \param parameter is a user provided parameter
  310. * \param mmsServer is the MmsServer instance
  311. * \param connection is the MmsServerConnection instance that received the MMS status request
  312. * \param extendedDerivation indicates if the request contains the extendedDerivation parameter
  313. */
  314. typedef void (*MmsStatusRequestListener)(void* parameter, MmsServer mmsServer, MmsServerConnection connection, bool extendedDerivation);
  315. /**
  316. * \brief set the VMD state values for the VMD status service
  317. *
  318. * \param self the MmsServer instance to operate on
  319. * \param vmdLogicalStatus the logical status attribute of the VMD
  320. * \param vmdPhysicalStatus the physical status attribute of the VMD
  321. */
  322. LIB61850_INTERNAL void
  323. MmsServer_setVMDStatus(MmsServer self, int vmdLogicalStatus, int vmdPhysicalStatus);
  324. /**
  325. * \brief get the logical status attribute of the VMD
  326. *
  327. * \param self the MmsServer instance to operate on
  328. */
  329. LIB61850_INTERNAL int
  330. MmsServer_getVMDLogicalStatus(MmsServer self);
  331. /**
  332. * \brief get the physical status attribute of the VMD
  333. *
  334. * \param self the MmsServer instance to operate on
  335. */
  336. LIB61850_INTERNAL int
  337. MmsServer_getVMDPhysicalStatus(MmsServer self);
  338. /**
  339. * \brief set the MmsStatusRequestListener for this MmsServer
  340. *
  341. * With this function the API user can register a listener that is invoked whenever a
  342. * MMS status request is received from a client. Inside of the handler the user can
  343. * provide new status values with the MmsServer_setVMDStatus function.
  344. *
  345. * \param self the MmsServer instance to operate on
  346. * \param listener the listener that is called when a MMS status request is received
  347. * \param parameter a user provided parameter that is handed over to the listener
  348. */
  349. LIB61850_INTERNAL void
  350. MmsServer_setStatusRequestListener(MmsServer self, MmsStatusRequestListener listener, void* parameter);
  351. LIB61850_INTERNAL char*
  352. MmsServerConnection_getClientAddress(MmsServerConnection self);
  353. LIB61850_INTERNAL char*
  354. MmsServerConnection_getLocalAddress(MmsServerConnection self);
  355. LIB61850_INTERNAL void*
  356. MmsServerConnection_getSecurityToken(MmsServerConnection self);
  357. LIB61850_INTERNAL void
  358. MmsServer_ignoreClientRequests(MmsServer self, bool enable);;
  359. /**@}*/
  360. #ifdef __cplusplus
  361. }
  362. #endif
  363. #endif /* MMS_SERVER_H_ */