mms_server.h 13 KB

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