iec61850_server.h 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089
  1. /*
  2. * iec61850_server.h
  3. *
  4. * IEC 61850 server API for libiec61850.
  5. *
  6. * Copyright 2013-2024 Michael Zillgith
  7. *
  8. * This file is part of libIEC61850.
  9. *
  10. * libIEC61850 is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * libIEC61850 is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with libIEC61850. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * See COPYING file for the complete license text.
  24. *
  25. */
  26. #ifndef IED_SERVER_API_H_
  27. #define IED_SERVER_API_H_
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /** \defgroup server_api_group IEC 61850/MMS server API
  32. *
  33. * \brief IEC 61850/MMS server API for libiec61850.
  34. *
  35. * This API can be used to create, configure, and run IEC 61850/MMS server instances.
  36. *
  37. * @{
  38. */
  39. #include "mms_server.h"
  40. #include "iec61850_dynamic_model.h"
  41. #include "iec61850_model.h"
  42. #include "hal_filesystem.h"
  43. #include "iso_connection_parameters.h"
  44. #include "iec61850_config_file_parser.h"
  45. /**
  46. * @defgroup IEC61850_SERVER_CONFIG Server configuration related functions
  47. *
  48. * \brief Functions to handle server independent configuration settings to define
  49. * services, features, and other behavior of IEC 61850 server instances.
  50. *
  51. * @{
  52. */
  53. #define IEC61850_REPORTSETTINGS_RPT_ID 1
  54. #define IEC61850_REPORTSETTINGS_BUF_TIME 2
  55. #define IEC61850_REPORTSETTINGS_DATSET 4
  56. #define IEC61850_REPORTSETTINGS_TRG_OPS 8
  57. #define IEC61850_REPORTSETTINGS_OPT_FIELDS 16
  58. #define IEC61850_REPORTSETTINGS_INTG_PD 32
  59. /**
  60. * \brief Configuration object to configure IEC 61850 stack features
  61. */
  62. typedef struct sIedServerConfig* IedServerConfig;
  63. struct sIedServerConfig
  64. {
  65. /** size of the report buffer associated with a buffered report control block */
  66. int reportBufferSize;
  67. /** size of the report buffer associated with an unbuffered report control block */
  68. int reportBufferSizeURCBs;
  69. /** Base path (directory where the file service serves files */
  70. char* fileServiceBasepath;
  71. /** when true (default) enable MMS file service */
  72. bool enableFileService;
  73. /** when true (default) enable dynamic data set services for MMS */
  74. bool enableDynamicDataSetService;
  75. /** the maximum number of allowed association specific data sets */
  76. int maxAssociationSpecificDataSets;
  77. /** the maximum number of allowed domain specific data sets */
  78. int maxDomainSpecificDataSets;
  79. /** maximum number of data set entries of dynamic data sets */
  80. int maxDataSetEntries;
  81. /** when true (default) enable log service */
  82. bool enableLogService;
  83. /** when true (default) the integrated GOOSE publisher is used */
  84. bool useIntegratedGoosePublisher;
  85. /** IEC 61850 edition (0 = edition 1, 1 = edition 2, 2 = edition 2.1, ...) */
  86. uint8_t edition;
  87. /** maximum number of MMS (TCP) connections */
  88. int maxMmsConnections;
  89. /** enable EditSG service (default: true) */
  90. bool enableEditSG;
  91. /** enable visibility of SGCB.ResvTms (default: true) */
  92. bool enableResvTmsForSGCB;
  93. /** BRCB has resvTms attribute - only edition 2 (default: true) */
  94. bool enableResvTmsForBRCB;
  95. /** RCB has owner attribute (default: true) */
  96. bool enableOwnerForRCB;
  97. /** integrity report start times will by synchronized with straight numbers (default: false) */
  98. bool syncIntegrityReportTimes;
  99. /** for each configurable ReportSetting there is a separate flag (default: Dyn = enable write for all) */
  100. uint8_t reportSettingsWritable;
  101. };
  102. /**
  103. * \brief Create a new configuration object
  104. *
  105. * \return a new configuration object with default configuration values
  106. */
  107. LIB61850_API IedServerConfig
  108. IedServerConfig_create(void);
  109. /**
  110. * \brief Destroy the configuration object
  111. */
  112. LIB61850_API void
  113. IedServerConfig_destroy(IedServerConfig self);
  114. /**
  115. * \brief Set the IEC 61850 standard edition to use (default is edition 2)
  116. *
  117. * \param edition IEC_61850_EDITION_1, IEC_61850_EDITION_2, or IEC_61850_EDITION_2_1
  118. */
  119. LIB61850_API void
  120. IedServerConfig_setEdition(IedServerConfig self, uint8_t edition);
  121. /**
  122. * \brief Get the configued IEC 61850 standard edition
  123. *
  124. * \returns IEC_61850_EDITION_1, IEC_61850_EDITION_2, or IEC_61850_EDITION_2_1
  125. */
  126. LIB61850_API uint8_t
  127. IedServerConfig_getEdition(IedServerConfig self);
  128. /**
  129. * \brief Set the report buffer size for buffered reporting
  130. *
  131. * \param reportBufferSize the buffer size for each buffered report control block
  132. */
  133. LIB61850_API void
  134. IedServerConfig_setReportBufferSize(IedServerConfig self, int reportBufferSize);
  135. /**
  136. * \brief Gets the report buffer size for buffered reporting
  137. *
  138. * \return the buffer size for each buffered report control block
  139. */
  140. LIB61850_API int
  141. IedServerConfig_getReportBufferSize(IedServerConfig self);
  142. /**
  143. * \brief Set the report buffer size for unbuffered reporting
  144. *
  145. * \param reportBufferSize the buffer size for each unbuffered report control block
  146. */
  147. LIB61850_API void
  148. IedServerConfig_setReportBufferSizeForURCBs(IedServerConfig self, int reportBufferSize);
  149. /**
  150. * \brief Gets the report buffer size for unbuffered reporting
  151. *
  152. * \return the buffer size for each unbuffered report control block
  153. */
  154. LIB61850_API int
  155. IedServerConfig_getReportBufferSizeForURCBs(IedServerConfig self);
  156. /**
  157. * \brief Set the maximum number of MMS (TCP) connections the server accepts
  158. *
  159. * NOTE: Parameter has to be smaller than CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS if
  160. * CONFIG_MAXIMUM_TCP_CLIENT_CONNECTIONS != -1
  161. *
  162. * \param maxConnection maximum number of TCP connections
  163. */
  164. LIB61850_API void
  165. IedServerConfig_setMaxMmsConnections(IedServerConfig self, int maxConnections);
  166. /**
  167. * \brief Get the maximum number of MMS (TCP) connections the server accepts
  168. *
  169. * \return maximum number of TCP connections
  170. */
  171. LIB61850_API int
  172. IedServerConfig_getMaxMmsConnections(IedServerConfig self);
  173. /**
  174. * \brief Enable synchronized integrity report times
  175. *
  176. * NOTE: When this flag is enabled the integrity report generation times are
  177. * aligned with the UTC epoch. Then the unix time stamps are straight multiples of the
  178. * integrity interval.
  179. *
  180. * \param enable when true synchronized integrity report times are enabled
  181. */
  182. LIB61850_API void
  183. IedServerConfig_setSyncIntegrityReportTimes(IedServerConfig self, bool enable);
  184. /**
  185. * \brief Check if synchronized integrity report times are enabled
  186. *
  187. * NOTE: When this flag is enabled the integrity report generation times are
  188. * aligned with the UTC epoch. Then the unix time stamps are straight multiples of the
  189. * integrity interval.
  190. *
  191. * \return true, when enabled, false otherwise
  192. */
  193. LIB61850_API bool
  194. IedServerConfig_getSyncIntegrityReportTimes(IedServerConfig self);
  195. /**
  196. * \brief Set the basepath of the file services
  197. *
  198. * NOTE: the basepath specifies the local directory that is served by MMS file services
  199. *
  200. * \param basepath new file service base path
  201. */
  202. LIB61850_API void
  203. IedServerConfig_setFileServiceBasePath(IedServerConfig self, const char* basepath);
  204. /**
  205. * \brief Get the basepath of the file services
  206. */
  207. LIB61850_API const char*
  208. IedServerConfig_getFileServiceBasePath(IedServerConfig self);
  209. /**
  210. * \brief Enable/disable the MMS file service support
  211. *
  212. * \param[in] enable set true to enable the file services, otherwise false
  213. */
  214. LIB61850_API void
  215. IedServerConfig_enableFileService(IedServerConfig self, bool enable);
  216. /**
  217. * \brief Is the MMS file service enabled or disabled
  218. *
  219. * \return true if enabled, false otherwise
  220. */
  221. LIB61850_API bool
  222. IedServerConfig_isFileServiceEnabled(IedServerConfig self);
  223. /**
  224. * \brief Enable/disable the dynamic data set service for MMS
  225. *
  226. * \param[in] enable set true to enable dynamic data set service, otherwise false
  227. */
  228. LIB61850_API void
  229. IedServerConfig_enableDynamicDataSetService(IedServerConfig self, bool enable);
  230. /**
  231. * \brief Is the dynamic data set service for MMS enabled or disabled
  232. *
  233. * \return true if enabled, false otherwise
  234. */
  235. LIB61850_API bool
  236. IedServerConfig_isDynamicDataSetServiceEnabled(IedServerConfig self);
  237. /**
  238. * \brief Set the maximum allowed number of association specific (non-permanent) data sets
  239. *
  240. * NOTE: This specifies the maximum number of non-permanent data sets per connection. When
  241. * the connection is closed these data sets are deleted automatically.
  242. *
  243. * \param maxDataSets maximum number of allowed data sets.
  244. */
  245. LIB61850_API void
  246. IedServerConfig_setMaxAssociationSpecificDataSets(IedServerConfig self, int maxDataSets);
  247. /**
  248. * \brief Get the maximum allowed number of association specific (non-permanent) data sets
  249. *
  250. * \return maximum number of allowed data sets.
  251. */
  252. LIB61850_API int
  253. IedServerConfig_getMaxAssociationSpecificDataSets(IedServerConfig self);
  254. /**
  255. * \brief Set the maximum allowed number of domain specific (permanent) data sets
  256. *
  257. * \param maxDataSets maximum number of allowed data sets.
  258. */
  259. LIB61850_API void
  260. IedServerConfig_setMaxDomainSpecificDataSets(IedServerConfig self, int maxDataSets);
  261. /**
  262. * \brief Get the maximum allowed number of domain specific (permanent) data sets
  263. *
  264. * \return maximum number of allowed data sets.
  265. */
  266. LIB61850_API int
  267. IedServerConfig_getMaxDomainSpecificDataSets(IedServerConfig self);
  268. /**
  269. * \brief Set the maximum number of entries in dynamic data sets
  270. *
  271. * NOTE: this comprises the base data set entries (can be simple or complex variables).
  272. * When the client tries to create a data set with more member the request will be
  273. * rejected and the data set will not be created.
  274. *
  275. * \param maxDataSetEntries the maximum number of entries allowed in a data set
  276. */
  277. LIB61850_API void
  278. IedServerConfig_setMaxDataSetEntries(IedServerConfig self, int maxDataSetEntries);
  279. /**
  280. * \brief Get the maximum number of entries in dynamic data sets
  281. *
  282. * \return the maximum number of entries allowed in a data sets
  283. */
  284. LIB61850_API int
  285. IedServerConfig_getMaxDatasSetEntries(IedServerConfig self);
  286. /**
  287. * \brief Enable/disable the log service for MMS
  288. *
  289. * \param[in] enable set true to enable log service, otherwise false
  290. */
  291. LIB61850_API void
  292. IedServerConfig_enableLogService(IedServerConfig self, bool enable);
  293. /**
  294. * \brief Enable/disable the EditSG service to allow clients to change setting groups (default is enabled)
  295. *
  296. * NOTE: When disabled SGCB.ResvTms is not available online and the setting of \ref IedServerConfig_enableResvTmsForSGCB
  297. * is ignored.
  298. *
  299. * \param[in] enable set true to enable, otherwise false (default value it true)
  300. */
  301. LIB61850_API void
  302. IedServerConfig_enableEditSG(IedServerConfig self, bool enable);
  303. /**
  304. * \brief Enable/disable the SGCB.ResvTms when EditSG is enabled
  305. *
  306. * NOTE: When EditSG is disabled (see \ref IedServerConfig_enableEditSG) then this setting is ignored.
  307. *
  308. * \param[in] enable set true to enable, otherwise false (default value it true)
  309. */
  310. LIB61850_API void
  311. IedServerConfig_enableResvTmsForSGCB(IedServerConfig self, bool enable);
  312. /**
  313. * \brief Enable/disable the presence of BRCB.ResvTms (default value is true)
  314. *
  315. * \param[in] enable set true to enable, otherwise false
  316. */
  317. LIB61850_API void
  318. IedServerConfig_enableResvTmsForBRCB(IedServerConfig self, bool enable);
  319. /**
  320. * \brief ResvTms for BRCB enabled (visible)
  321. *
  322. * \return true if enabled, false otherwise
  323. */
  324. LIB61850_API bool
  325. IedServerConfig_isResvTmsForBRCBEnabled(IedServerConfig self);
  326. /**
  327. * \brief Enable/disable the presence of owner in report control blocks (default value is false);
  328. *
  329. * \param[in] enable set true to enable, otherwise false
  330. */
  331. LIB61850_API void
  332. IedServerConfig_enableOwnerForRCB(IedServerConfig self, bool enable);
  333. /**
  334. * \brief Owner for RCBs enabled (visible)
  335. *
  336. * \return true if enabled, false otherwise
  337. */
  338. LIB61850_API bool
  339. IedServerConfig_isOwnerForRCBEnabled(IedServerConfig self);
  340. /**
  341. * \brief Enable/disable using the integrated GOOSE publisher for configured GoCBs
  342. *
  343. * This is enabled by default. Disable it when you want to use a separate GOOSE publisher
  344. *
  345. * \param[in] enable set true to enable the integrated GOOSE publisher, otherwise false
  346. */
  347. LIB61850_API void
  348. IedServerConfig_useIntegratedGoosePublisher(IedServerConfig self, bool enable);
  349. /**
  350. * \brief Is the log service for MMS enabled or disabled
  351. *
  352. * \return true if enabled, false otherwise
  353. */
  354. LIB61850_API bool
  355. IedServerConfig_isLogServiceEnabled(IedServerConfig self);
  356. /**
  357. * \brief Make a configurable report setting writeable or read-only
  358. *
  359. * \note Can be used to implement some of Services\ReportSettings options
  360. *
  361. * \param[in] setting one of IEC61850_REPORTSETTINGS_RPT_ID, _BUF_TIME, _DATSET, _TRG_OPS, _OPT_FIELDS, _INTG_PD
  362. * \param[in] isDyn true, when setting is writable ("Dyn") or false, when read-only
  363. */
  364. LIB61850_API void
  365. IedServerConfig_setReportSetting(IedServerConfig self, uint8_t setting, bool isDyn);
  366. /**
  367. * \brief Check if a configurable report setting is writable or read-only
  368. *
  369. * \param[in] setting one of IEC61850_REPORTSETTINGS_RPT_ID, _BUF_TIME, _DATSET, _TRG_OPS, _OPT_FIELDS, _INTG_PD
  370. *
  371. * \return true, when setting is writable ("Dyn") or false, when read-only
  372. */
  373. LIB61850_API bool
  374. IedServerConfig_getReportSetting(IedServerConfig self, uint8_t setting);
  375. /**@}*/
  376. /**
  377. * @defgroup IEC61850_SERVER_GENERAL General server setup and management functions
  378. *
  379. * \brief Functions to create, configure, and manage an IEC 61850 server instance.
  380. *
  381. * @{
  382. */
  383. /**
  384. * An opaque handle for an IED server instance
  385. */
  386. typedef struct sIedServer* IedServer;
  387. /**
  388. * An opaque handle for a client connection
  389. */
  390. typedef struct sClientConnection* ClientConnection;
  391. /**
  392. * \brief Create a new IedServer instance
  393. *
  394. * \param dataModel reference to the IedModel data structure to be used as IEC 61850 data model of the device
  395. *
  396. * \return the new IedServer instance
  397. */
  398. LIB61850_API IedServer
  399. IedServer_create(IedModel* dataModel);
  400. /**
  401. * \brief Create a new IedServer with TLS support
  402. *
  403. * \param dataModel reference to the IedModel data structure to be used as IEC 61850 data model of the device
  404. * \param tlsConfiguration TLS configuration object, or NULL to not use TLS
  405. *
  406. * \return the new IedServer instance
  407. */
  408. LIB61850_API IedServer
  409. IedServer_createWithTlsSupport(IedModel* dataModel, TLSConfiguration tlsConfiguration);
  410. /**
  411. * \brief Create new new IedServer with extended configurations parameters
  412. *
  413. * \param dataModel reference to the IedModel data structure to be used as IEC 61850 data model of the device
  414. * \param tlsConfiguration TLS configuration object, or NULL to not use TLS
  415. * \param serverConfiguration IED server configuration object for advanced server configuration
  416. */
  417. LIB61850_API IedServer
  418. IedServer_createWithConfig(IedModel* dataModel, TLSConfiguration tlsConfiguration, IedServerConfig serverConfiguration);
  419. /**
  420. * \brief Destroy an IedServer instance and release all resources (memory, TCP sockets)
  421. *
  422. * \param self the instance of IedServer to operate on.
  423. */
  424. LIB61850_API void
  425. IedServer_destroy(IedServer self);
  426. /**
  427. * \brief Add a new local access point (server will listen to provided IP/port combination)
  428. *
  429. * \param self the instance of IedServer to operate on.
  430. * \param ipAddr the local IP address to listen on
  431. * \param tcpPort the local TCP port to listen on or -1 to use the standard TCP port
  432. * \oaram tlsConfiguration the TLS configuration or NULL when TLS is not used for this access point
  433. *
  434. * \return true in case of success, false otherwise
  435. */
  436. LIB61850_API bool
  437. IedServer_addAccessPoint(IedServer self, const char* ipAddr, int tcpPort, TLSConfiguration tlsConfiguration);
  438. /**
  439. * \brief Set the local IP address to listen on
  440. *
  441. * \param self the IedServer instance
  442. * \param localIpAddress the local IP address as C string (an internal copy will be created)
  443. */
  444. LIB61850_API void
  445. IedServer_setLocalIpAddress(IedServer self, const char* localIpAddress);
  446. /**
  447. * \brief Set the identify for the MMS identify service
  448. *
  449. * CONFIG_IEC61850_SUPPORT_SERVER_IDENTITY required
  450. *
  451. * \param self the IedServer instance
  452. * \param vendor the IED vendor name
  453. * \param model the IED model name
  454. * \param revision the IED revision/version number
  455. */
  456. LIB61850_API void
  457. IedServer_setServerIdentity(IedServer self, const char* vendor, const char* model, const char* revision);
  458. /**
  459. * \brief Set the virtual filestore basepath for the MMS file services
  460. *
  461. * All external file service accesses will be mapped to paths relative to the base directory.
  462. * NOTE: This function is only available when the CONFIG_SET_FILESTORE_BASEPATH_AT_RUNTIME
  463. * option in stack_config.h is set.
  464. *
  465. * \param self the IedServer instance
  466. * \param basepath the new virtual filestore basepath
  467. */
  468. LIB61850_API void
  469. IedServer_setFilestoreBasepath(IedServer self, const char* basepath);
  470. /**
  471. * \brief Assign a \ref LogStorage instance to a log reference
  472. *
  473. * \note configuration option CONFIG_IEC61850_LOG_SERVICE is required
  474. *
  475. * \param self the IedServer instance
  476. * \param logRef the log reference to assign the log storage to
  477. * \param logStorage the log storage instance to assign
  478. */
  479. LIB61850_API void
  480. IedServer_setLogStorage(IedServer self, const char* logRef, LogStorage logStorage);
  481. /**
  482. * \brief Start handling client connections
  483. *
  484. * \param self the instance of IedServer to operate on.
  485. * \param tcpPort the TCP port the server is listening (-1 for using the default MMS or secure MMS port)
  486. */
  487. LIB61850_API void
  488. IedServer_start(IedServer self, int tcpPort);
  489. /**
  490. * \brief Stop handling client connections
  491. *
  492. * \param self the instance of IedServer to operate on.
  493. */
  494. LIB61850_API void
  495. IedServer_stop(IedServer self);
  496. /**
  497. * \brief Start handling client connection for non-threaded mode
  498. *
  499. * This function will instruct the TCP(IP stack to listen for incoming connections.
  500. * In order to accept new connection the function IedServer_processIncomingData has to
  501. * be called periodically.
  502. *
  503. * \param self the instance of IedServer to operate on.
  504. * \param tcpPort the TCP port the server is listening (-1 for using the default MMS or secure MMS port)
  505. */
  506. LIB61850_API void
  507. IedServer_startThreadless(IedServer self, int tcpPort);
  508. /**
  509. * \brief Wait until a server connection is ready (with timeout)
  510. *
  511. * The function will wait until a server connection is ready (data available) or the
  512. * timeout elapsed. This function is intended for the non-threaded mode. Its use is optional.
  513. * It is equivalent of using select on sockets on Linux. If the return value is != 0 the
  514. * IedServer_processIncomingData function should be called.
  515. *
  516. * \param self the IedServer instance
  517. * \param timeoutMs the timeout to wait when no connection is ready
  518. *
  519. * \return 0 if no connection is ready; otherwise at least one connection is ready
  520. */
  521. LIB61850_API int
  522. IedServer_waitReady(IedServer self, unsigned int timeoutMs);
  523. /**
  524. * \brief handle incoming TCP data in non-threaded mode
  525. *
  526. * The function should be called periodically. If the function is called more often
  527. * the response time for incoming messages will be faster. As an alternative the
  528. * function may only be called if new TCP data is available.
  529. *
  530. * \param self the instance of IedServer to operate on.
  531. */
  532. LIB61850_API void
  533. IedServer_processIncomingData(IedServer self);
  534. /**
  535. * \brief perform periodic background tasks in non-threaded mode
  536. *
  537. * The function should be called periodically. If the function is called more often
  538. * the more accurate are internal timeouts (e.g. for reports).
  539. *
  540. * \param self the instance of IedServer to operate on.
  541. */
  542. LIB61850_API void
  543. IedServer_performPeriodicTasks(IedServer self);
  544. /**
  545. * \brief Stop handling client connections for non-threaded mode
  546. *
  547. * \param self the instance of IedServer to operate on.
  548. */
  549. LIB61850_API void
  550. IedServer_stopThreadless(IedServer self);
  551. /**
  552. * \brief Return the data model of the server
  553. *
  554. * \param self the instance of IedServer to operate on.
  555. *
  556. * \return the IedModel* instance of the server
  557. */
  558. LIB61850_API IedModel*
  559. IedServer_getDataModel(IedServer self);
  560. /**
  561. * \brief Check if IedServer instance is listening for client connections
  562. *
  563. * \param self the instance of IedServer to operate on.
  564. *
  565. * \return true if IedServer instance is listening for client connections
  566. */
  567. LIB61850_API bool
  568. IedServer_isRunning(IedServer self);
  569. /**
  570. * \brief Get number of open MMS connections
  571. *
  572. * \param self the instance of IedServer to operate on
  573. *
  574. * \return the number of open and accepted MMS connections
  575. */
  576. LIB61850_API int
  577. IedServer_getNumberOfOpenConnections(IedServer self);
  578. /**
  579. * \brief Get access to the underlying MmsServer instance.
  580. *
  581. * This function should be handled with care. Since direct interaction with the
  582. * MmsServer can interfere with the IedServer.
  583. *
  584. * \param self the instance of IedServer to operate on.
  585. *
  586. * \return MmsServer instance that is used by the IedServer
  587. */
  588. LIB61850_API MmsServer
  589. IedServer_getMmsServer(IedServer self);
  590. /**
  591. * \brief Enable all GOOSE control blocks.
  592. *
  593. * This will set the GoEna attribute of all configured GOOSE control blocks
  594. * to true. If this method is not called at the startup or reset of the server
  595. * then configured GOOSE control blocks keep inactive until a MMS client enables
  596. * them by writing to the GOOSE control block.
  597. *
  598. * \note This function has no effect when CONFIG_INCLUDE_GOOSE_SUPPORT is not set.
  599. *
  600. * \param self the instance of IedServer to operate on.
  601. */
  602. LIB61850_API void
  603. IedServer_enableGoosePublishing(IedServer self);
  604. /**
  605. * \brief Disable all GOOSE control blocks.
  606. *
  607. * This will set the GoEna attribute of all configured GOOSE control blocks
  608. * to false. This will stop GOOSE transmission.
  609. *
  610. * \note This function has no effect when CONFIG_INCLUDE_GOOSE_SUPPORT is not set.
  611. *
  612. * \param self the instance of IedServer to operate on.
  613. */
  614. LIB61850_API void
  615. IedServer_disableGoosePublishing(IedServer self);
  616. /**
  617. * \brief Set the Ethernet interface to be used by GOOSE publishing
  618. *
  619. * This function can be used to set the GOOSE interface ID. If not used or set to NULL the
  620. * default interface ID from stack_config.h is used.
  621. *
  622. * \note the interface ID is operating system specific!
  623. *
  624. * \note This function has no effect when CONFIG_INCLUDE_GOOSE_SUPPORT is not set.
  625. *
  626. * \param self the instance of IedServer to operate on.
  627. * \param interfaceId the ID of the ethernet interface to be used for GOOSE publishing
  628. */
  629. LIB61850_API void
  630. IedServer_setGooseInterfaceId(IedServer self, const char* interfaceId);
  631. /**
  632. * \brief Set the Ethernet interface to be used by GOOSE publishing
  633. *
  634. * This function can be used to set the GOOSE interface ID forG all CBs (parameter ln = NULL) or for
  635. * a specific GCB specified by the logical node instance and the GCB name.
  636. *
  637. * \note This function has no effect when CONFIG_INCLUDE_GOOSE_SUPPORT is not set.
  638. *
  639. * \param self the instance of IedServer to operate on.
  640. * \param ln the logical node that contains the GCB or NULL to set the ethernet interface ID for all GCBs
  641. * \param gcbName the name (not object reference!) of the GCB
  642. * \param interfaceId the ID of the ethernet interface to be used for GOOSE publishing
  643. */
  644. LIB61850_API void
  645. IedServer_setGooseInterfaceIdEx(IedServer self, LogicalNode* ln, const char* gcbName, const char* interfaceId);
  646. /**
  647. * \brief Enable/disable the use of VLAN tags in GOOSE messages
  648. *
  649. * This function can be used to enable/disable VLAN tagging for all GCBs (parameter ln = NULL) or for
  650. * a specific GCB specified by the logical node instance and the GCB name.
  651. *
  652. * \note This function has no effect when CONFIG_INCLUDE_GOOSE_SUPPORT is not set.
  653. *
  654. * \param self the instance of IedServer to operate on
  655. * \param ln the logical node that contains the GCB or NULL to enable/disable VLAN tagging for all GCBs
  656. * \param gcbName the name (not object reference!) of the GCB
  657. * \param useVlanTag true to enable VLAN tagging, false otherwise
  658. */
  659. LIB61850_API void
  660. IedServer_useGooseVlanTag(IedServer self, LogicalNode* ln, const char* gcbName, bool useVlanTag);
  661. /**
  662. * \brief Set the time quality for all timestamps internally generated by this IedServer instance
  663. *
  664. * You can call this function during the initialization of the server or whenever a time quality
  665. * flag has to be updated (on clock failure or change of time synchronization state).
  666. *
  667. * \param self the instance of IedServer to operate on.
  668. * \param leapSecondKnown set/unset leap seconds known flag
  669. * \param clockFailure set/unset clock failure flag
  670. * \param clockNotSynchronized set/unset clock not synchronized flag
  671. * \param subsecondPrecision set the subsecond precision (number of significant bits of the fractionOfSecond part of the time stamp)
  672. */
  673. LIB61850_API void
  674. IedServer_setTimeQuality(IedServer self, bool leapSecondKnown, bool clockFailure, bool clockNotSynchronized, int subsecondPrecision);
  675. /**@}*/
  676. /**
  677. * @defgroup IEC61850_SERVER_CONNECTION_HANDLING Connection handling and client authentication
  678. *
  679. * \brief Functions and callbacks to control client access and connection handling.
  680. *
  681. * @{
  682. */
  683. /**
  684. * \brief set the authenticator for this server
  685. *
  686. * This function sets a user specified authenticator that is used to identify and authenticate clients that
  687. * wants to connect. The authenticator is called on each connection attempt. Depending on the return value
  688. * of the authenticator the client connection is accepted or refused. If no authenticator is set all client
  689. * connections are accepted.
  690. *
  691. * \param self the instance of IedServer to operate on.
  692. * \param authenticator the user provided authenticator callback
  693. * \param authenticatorParameter user provided parameter that is passed to the authenticator
  694. */
  695. LIB61850_API void
  696. IedServer_setAuthenticator(IedServer self, AcseAuthenticator authenticator, void* authenticatorParameter);
  697. /**
  698. * \brief get the peer address of this connection as string
  699. *
  700. * \note the returned string is only valid as long as the client connection exists. It is save to use
  701. * the string inside of the connection indication callback function.
  702. *
  703. * \param self the ClientConnection instance
  704. * \return peer address as C string.
  705. */
  706. LIB61850_API const char*
  707. ClientConnection_getPeerAddress(ClientConnection self);
  708. /**
  709. * \brief get the local address of this connection as string
  710. *
  711. * \note the returned string is only valid as long as the client connection exists. It is save to use
  712. * the string inside of the connection indication callback function.
  713. *
  714. * \param self the ClientConnection instance
  715. * \return local address as C string.
  716. */
  717. LIB61850_API const char*
  718. ClientConnection_getLocalAddress(ClientConnection self);
  719. /**
  720. * \brief Get the security token associated with this connection
  721. *
  722. * The security token is an opaque handle that is associated with the connection. It is provided by the
  723. * authenticator (if one is present). If no security token is used then this function returns NULL
  724. *
  725. * \param self the ClientConnection instance
  726. *
  727. * \return the security token or NULL
  728. */
  729. LIB61850_API void*
  730. ClientConnection_getSecurityToken(ClientConnection self);
  731. /**
  732. * \brief User provided callback function that is invoked whenever a new client connects or an existing connection is closed
  733. * or detected as lost.
  734. *
  735. * \param self the instance of IedServer where the connection event occured.
  736. * \param connection the new or closed client connect object
  737. * \param connected true if a new connection is indicated, false if the connection has been closed or detected as lost.
  738. * \param parameter a user provided parameter
  739. */
  740. typedef void (*IedConnectionIndicationHandler) (IedServer self, ClientConnection connection, bool connected, void* parameter);
  741. /**
  742. * \brief set a callback function that will be called on connection events (open or close).
  743. *
  744. * \param self the instance of IedServer to operate on.
  745. * \param handler the user provided callback function
  746. * \param parameter a user provided parameter that is passed to the callback function.
  747. */
  748. LIB61850_API void
  749. IedServer_setConnectionIndicationHandler(IedServer self, IedConnectionIndicationHandler handler, void* parameter);
  750. /**
  751. * \brief Ignore all requests from clients (for testing purposes)
  752. *
  753. * NOTE: This function will block all client requests on MMS layer
  754. *
  755. * \param self the instance of IedServer to configure.
  756. * \param enable when true all requests from clients will be ignored
  757. */
  758. void
  759. IedServer_ignoreClientRequests(IedServer self, bool enable);
  760. /**@}*/
  761. /**
  762. * @defgroup IEC61850_SERVER_DATA_MODEL_ACCESS Data model access and data update
  763. *
  764. * \brief Functions to access and update the data model of an IEC 61850 server instance.
  765. *
  766. * @{
  767. */
  768. /**
  769. * \brief Lock the data model for data update.
  770. *
  771. * This function should be called before the data model is updated.
  772. * After updating the data model the function \ref IedServer_unlockDataModel should be called.
  773. * Client requests will be postponed until the lock is removed.
  774. *
  775. * NOTE: This method should never be called inside of a library callback function. In the context of
  776. * a library callback the data model is always already locked! Calling this function inside of a
  777. * library callback may lead to a deadlock condition.
  778. *
  779. * \param self the instance of IedServer to operate on.
  780. */
  781. LIB61850_API void
  782. IedServer_lockDataModel(IedServer self);
  783. /**
  784. * \brief Unlock the data model and process pending client requests.
  785. *
  786. * NOTE: This method should never be called inside of a library callback function. In the context of
  787. * a library callback the data model is always already locked!
  788. *
  789. * \param self the instance of IedServer to operate on.
  790. */
  791. LIB61850_API void
  792. IedServer_unlockDataModel(IedServer self);
  793. /**
  794. * \brief Get data attribute value
  795. *
  796. * Get the MmsValue object of an MMS Named Variable that is part of the device model.
  797. * You should not manipulate the received object directly. Instead you should use
  798. * the IedServer_updateValue method.
  799. *
  800. * \param self the instance of IedServer to operate on.
  801. * \param dataAttribute the data attribute handle
  802. *
  803. * \return MmsValue object of the MMS Named Variable or NULL if the value does not exist.
  804. */
  805. LIB61850_API MmsValue*
  806. IedServer_getAttributeValue(IedServer self, DataAttribute* dataAttribute);
  807. /**
  808. * \brief Get data attribute value of a boolean data attribute
  809. *
  810. * Get the value of a data attribute of type MMS_BOOLEAN. If the data attribute
  811. * is of a different type the returned value is undefined.
  812. *
  813. * \param self the instance of IedServer to operate on.
  814. * \param dataAttribute the data attribute handle
  815. *
  816. * \return true or false
  817. */
  818. LIB61850_API bool
  819. IedServer_getBooleanAttributeValue(IedServer self, const DataAttribute* dataAttribute);
  820. /**
  821. * \brief Get data attribute value of an integer data attribute
  822. *
  823. * Get the value of a data attribute of type MMS_INTEGER. If the data attribute
  824. * is of a different type the returned value is undefined.
  825. *
  826. * \param self the instance of IedServer to operate on.
  827. * \param dataAttribute the data attribute handle
  828. *
  829. * \return the value as 32 bit integer
  830. */
  831. LIB61850_API int32_t
  832. IedServer_getInt32AttributeValue(IedServer self, const DataAttribute* dataAttribute);
  833. /**
  834. * \brief Get data attribute value of an integer data attribute
  835. *
  836. * Get the value of a data attribute of type MMS_INTEGER. If the data attribute
  837. * is of a different type the returned value is undefined.
  838. *
  839. * \param self the instance of IedServer to operate on.
  840. * \param dataAttribute the data attribute handle
  841. *
  842. * \return the value as 64 bit integer
  843. */
  844. LIB61850_API int64_t
  845. IedServer_getInt64AttributeValue(IedServer self, const DataAttribute* dataAttribute);
  846. /**
  847. * \brief Get data attribute value of an unsigned integer data attribute
  848. *
  849. * Get the value of a data attribute of type MMS_UNSIGNED. If the data attribute
  850. * is of a different type the returned value is undefined.
  851. *
  852. * \param self the instance of IedServer to operate on.
  853. * \param dataAttribute the data attribute handle
  854. *
  855. * \return the value as 32 bit unsigned integer
  856. */
  857. LIB61850_API uint32_t
  858. IedServer_getUInt32AttributeValue(IedServer self, const DataAttribute* dataAttribute);
  859. /**
  860. * \brief Get data attribute value of a floating point data attribute
  861. *
  862. * Get the value of a data attribute of type MMS_FLOAT. If the data attribute
  863. * is of a different type the returned value is undefined.
  864. *
  865. * \param self the instance of IedServer to operate on.
  866. * \param dataAttribute the data attribute handle
  867. *
  868. * \return the value as 32 bit float
  869. */
  870. LIB61850_API float
  871. IedServer_getFloatAttributeValue(IedServer self, const DataAttribute* dataAttribute);
  872. /**
  873. * \brief Get data attribute value of a UTC time data attribute
  874. *
  875. * Get the value of a data attribute of type MMS_UTC_TIME. If the data attribute
  876. * is of a different type the returned value is undefined.
  877. *
  878. * \param self the instance of IedServer to operate on.
  879. * \param dataAttribute the data attribute handle
  880. *
  881. * \return the value as 64 bit unsigned integer representing the time in milliseconds since Epoch
  882. */
  883. LIB61850_API uint64_t
  884. IedServer_getUTCTimeAttributeValue(IedServer self, const DataAttribute* dataAttribute);
  885. /**
  886. * \brief Get data attribute value of a bit string data attribute as integer value
  887. *
  888. * Get the value of a data attribute of type MMS_BIT_STRING. If the data attribute
  889. * is of a different type the returned value is undefined.
  890. * NOTE: The returned integer is determined by calculating the according the follwing
  891. * formula: bit0^0 + bit1^1 + ... + bitn^n
  892. * It is not specified in the IEC 61850 specifications how a bit string can be interpreted
  893. * as an integer. Therefore this function has to be used with care.
  894. *
  895. * \param self the instance of IedServer to operate on.
  896. * \param dataAttribute the data attribute handle
  897. *
  898. * \return the value a 32 bit integer.
  899. */
  900. LIB61850_API uint32_t
  901. IedServer_getBitStringAttributeValue(IedServer self, const DataAttribute* dataAttribute);
  902. /**
  903. * \brief Get data attribute value of a string type data attribute
  904. *
  905. * Get the value of a data attribute of type MMS_STRING or MMS_VISIBLE_STRING. If the data attribute
  906. * is of a different type the returned value is undefined.
  907. *
  908. * \param self the instance of IedServer to operate on.
  909. * \param dataAttribute the data attribute handle
  910. *
  911. * \return the value as a C string (null terminated string)
  912. */
  913. LIB61850_API const char*
  914. IedServer_getStringAttributeValue(IedServer self, const DataAttribute* dataAttribute);
  915. /**
  916. * \brief Get the MmsValue object related to a functional constrained data object (FCD)
  917. *
  918. * Get the MmsValue from the server cache that is associated with the Functional Constrained Data (FCD)
  919. * object that is specified by the DataObject and the given Function Constraint (FC).
  920. * Accessing the value will directly influence the values presented by the server. This kind of direct
  921. * access will also bypass the report notification mechanism (i.e. changes will not cause a report!).
  922. * Therefore this function should be used with care. It could be useful to access arrays of DataObjects.
  923. *
  924. * \param self the instance of IedServer to operate on.
  925. * \param dataObject the data object to specify the FCD
  926. * \param fc the FC to specify the FCD
  927. *
  928. * \return MmsValue object cached by the server.
  929. */
  930. LIB61850_API MmsValue*
  931. IedServer_getFunctionalConstrainedData(IedServer self, DataObject* dataObject, FunctionalConstraint fc);
  932. /**
  933. * \brief Update the MmsValue object of an IEC 61850 data attribute.
  934. *
  935. * The data attribute handle of type DataAttribute* are imported with static_model.h in the case when
  936. * the static data model is used.
  937. * You should use this function instead of directly operating on the MmsValue instance
  938. * that is hold by the MMS server. Otherwise the IEC 61850 server is not aware of the
  939. * changed value and will e.g. not generate a report.
  940. *
  941. * This function will also check if a trigger condition is satisfied in the case when a report or GOOSE
  942. * control block is enabled.
  943. *
  944. * \param self the instance of IedServer to operate on.
  945. * \param dataAttribute the data attribute handle
  946. * \param value MmsValue object used to update the value cached by the server.
  947. */
  948. LIB61850_API void
  949. IedServer_updateAttributeValue(IedServer self, DataAttribute* dataAttribute, MmsValue* value);
  950. /**
  951. * \brief Update the value of an IEC 61850 float data attribute.
  952. *
  953. * Update the value of a float data attribute without handling with MmsValue instances.
  954. *
  955. * This function will also check if a trigger condition is satisfied in the case when a report or GOOSE
  956. * control block is enabled.
  957. *
  958. * \param self the instance of IedServer to operate on.
  959. * \param dataAttribute the data attribute handle
  960. * \param value the new float value of the data attribute.
  961. */
  962. LIB61850_API void
  963. IedServer_updateFloatAttributeValue(IedServer self, DataAttribute* dataAttribute, float value);
  964. /**
  965. * \brief Update the value of an IEC 61850 integer32 data attribute.
  966. *
  967. * Update the value of a integer data attribute without handling with MmsValue instances.
  968. *
  969. * This function will also check if a trigger condition is satisfied in the case when a report or GOOSE
  970. * control block is enabled.
  971. *
  972. * \param self the instance of IedServer to operate on.
  973. * \param dataAttribute the data attribute handle
  974. * \param value the new integer value of the data attribute.
  975. */
  976. LIB61850_API void
  977. IedServer_updateInt32AttributeValue(IedServer self, DataAttribute* dataAttribute, int32_t value);
  978. /**
  979. * \brief Update the value of an IEC 61850 Dbpos (double point/position) data attribute.
  980. *
  981. * Update the value of a integer data attribute without handling with MmsValue instances.
  982. *
  983. * This function will also check if a trigger condition is satisfied in the case when a report or GOOSE
  984. * control block is enabled.
  985. *
  986. * \param self the instance of IedServer to operate on.
  987. * \param dataAttribute the data attribute handle
  988. * \param value the new Dbpos value of the data attribute.
  989. */
  990. LIB61850_API void
  991. IedServer_updateDbposValue(IedServer self, DataAttribute* dataAttribute, Dbpos value);
  992. /**
  993. * \brief Update the value of an IEC 61850 integer64 data attribute (like BCR actVal)
  994. *
  995. * Update the value of a integer data attribute without handling with MmsValue instances.
  996. *
  997. * This function will also check if a trigger condition is satisfied in the case when a report or GOOSE
  998. * control block is enabled.
  999. *
  1000. * \param self the instance of IedServer to operate on.
  1001. * \param dataAttribute the data attribute handle
  1002. * \param value the new 64 bit integer value of the data attribute.
  1003. */
  1004. LIB61850_API void
  1005. IedServer_updateInt64AttributeValue(IedServer self, DataAttribute* dataAttribute, int64_t value);
  1006. /**
  1007. * \brief Update the value of an IEC 61850 unsigned integer data attribute.
  1008. *
  1009. * Update the value of a unsigned data attribute without handling with MmsValue instances.
  1010. *
  1011. * This function will also check if a trigger condition is satisfied in the case when a report or GOOSE
  1012. * control block is enabled.
  1013. *
  1014. * \param self the instance of IedServer to operate on.
  1015. * \param dataAttribute the data attribute handle
  1016. * \param value the new unsigned integer value of the data attribute.
  1017. */
  1018. LIB61850_API void
  1019. IedServer_updateUnsignedAttributeValue(IedServer self, DataAttribute* dataAttribute, uint32_t value);
  1020. /**
  1021. * \brief Update the value of an IEC 61850 bit string data attribute.
  1022. *
  1023. * Update the value of a bit string data attribute without handling with MmsValue instances.
  1024. *
  1025. * This function will also check if a trigger condition is satisfied in the case when a report or GOOSE
  1026. * control block is enabled.
  1027. *
  1028. * \param self the instance of IedServer to operate on.
  1029. * \param dataAttribute the data attribute handle
  1030. * \param value the new bit string integer value of the data attribute.
  1031. */
  1032. LIB61850_API void
  1033. IedServer_updateBitStringAttributeValue(IedServer self, DataAttribute* dataAttribute, uint32_t value);
  1034. /**
  1035. * \brief Update the value of an IEC 61850 boolean data attribute.
  1036. *
  1037. * Update the value of a boolean data attribute without handling with MmsValue instances.
  1038. *
  1039. * This function will also check if a trigger condition is satisfied in the case when a report or GOOSE
  1040. * control block is enabled.
  1041. *
  1042. * \param self the instance of IedServer to operate on.
  1043. * \param dataAttribute the data attribute handle
  1044. * \param value the new boolean value of the data attribute.
  1045. */
  1046. LIB61850_API void
  1047. IedServer_updateBooleanAttributeValue(IedServer self, DataAttribute* dataAttribute, bool value);
  1048. /**
  1049. * \brief Update the value of an IEC 61850 visible string data attribute.
  1050. *
  1051. * Update the value of a visible string data attribute without handling MmsValue instances.
  1052. *
  1053. * This function will also check if a trigger condition is satisfied in the case when a report or GOOSE
  1054. * control block is enabled.
  1055. *
  1056. * \param self the instance of IedServer to operate on.
  1057. * \param dataAttribute the data attribute handle
  1058. * \param value the new visible string value of the data attribute.
  1059. */
  1060. LIB61850_API void
  1061. IedServer_updateVisibleStringAttributeValue(IedServer self, DataAttribute* dataAttribute, char *value);
  1062. /**
  1063. * \brief Update the value of an IEC 61850 UTC time (timestamp) data attribute.
  1064. *
  1065. * Update the value of a UTC time data attribute without handling MmsValue instances.
  1066. *
  1067. * This function will also check if a trigger condition is satisfied in the case when a report or GOOSE
  1068. * control block is enabled.
  1069. *
  1070. * \param self the instance of IedServer to operate on.
  1071. * \param dataAttribute the data attribute handle
  1072. * \param value the new UTC time value of the data attribute as a ms timestamp
  1073. */
  1074. LIB61850_API void
  1075. IedServer_updateUTCTimeAttributeValue(IedServer self, DataAttribute* dataAttribute, uint64_t value);
  1076. /**
  1077. * \brief Update the value of an IEC 61850 UTC time (timestamp) data attribute.
  1078. *
  1079. * Update the value of a UTC time data attribute without handling MmsValue instances.
  1080. *
  1081. * This function will also check if a trigger condition is satisfied in the case when a report or GOOSE
  1082. * control block is enabled.
  1083. *
  1084. * \param self the instance of IedServer to operate on.
  1085. * \param dataAttribute the data attribute handle
  1086. * \param value the new UTC time value of the data attribute as a Timestamp
  1087. */
  1088. LIB61850_API void
  1089. IedServer_updateTimestampAttributeValue(IedServer self, DataAttribute* dataAttribute, Timestamp* timestamp);
  1090. /**
  1091. * \brief Update a quality ("q") IEC 61850 data attribute.
  1092. *
  1093. * This is a specialized function to handle Quality data attributes. It can be used instead of the more
  1094. * generic IedServer_updateAttributeValue function.
  1095. *
  1096. * This function will also check if the quality change (qchg) trigger condition is satisfied and inform a
  1097. * report control block accordingly.
  1098. *
  1099. * \param self the instance of IedServer to operate on.
  1100. * \param dataAttribute the data attribute handle
  1101. * \param quality the new quality value
  1102. *
  1103. */
  1104. LIB61850_API void
  1105. IedServer_updateQuality(IedServer self, DataAttribute* dataAttribute, Quality quality);
  1106. /**@}*/
  1107. /**
  1108. * @defgroup IEC61850_SERVER_SETTING_GROUPS Server side setting group handling
  1109. *
  1110. * \brief Functions and callbacks to handle setting groups on the server side.
  1111. *
  1112. * @{
  1113. */
  1114. /**
  1115. * \brief Change active setting group
  1116. *
  1117. * Inform the IedServer that the active setting group has changed due to an internal event.
  1118. * Before calling this function the user should update the relevant data attributes with FC=SG!
  1119. *
  1120. * \param self the instance of IedServer to operate on.
  1121. * \param sgcb the handle of the setting group control block of the setting group
  1122. * \param newActiveSg the number of the new active setting group
  1123. */
  1124. LIB61850_API void
  1125. IedServer_changeActiveSettingGroup(IedServer self, SettingGroupControlBlock* sgcb, uint8_t newActiveSg);
  1126. /**
  1127. * \brief Get the active setting group number
  1128. *
  1129. * \param self the instance of IedServer to operate on.
  1130. * \param sgcb the handle of the setting group control block of the setting group
  1131. *
  1132. * \return the number of the active setting group
  1133. */
  1134. LIB61850_API uint8_t
  1135. IedServer_getActiveSettingGroup(IedServer self, SettingGroupControlBlock* sgcb);
  1136. /**
  1137. * \brief Callback handler that is invoked when the active setting group is about to be changed by an
  1138. * external client.
  1139. *
  1140. * This function is called BEFORE the active setting group is changed. The user can reject to change the
  1141. * active setting group by returning false.
  1142. *
  1143. * \param user provided parameter
  1144. * \param sgcb the setting group control block of the setting group that is about to be changed
  1145. * \param newActSg the new active setting group
  1146. * \param connection the client connection that requests the change
  1147. *
  1148. * \return true if the change is accepted, false otherwise.
  1149. *
  1150. */
  1151. typedef bool (*ActiveSettingGroupChangedHandler) (void* parameter, SettingGroupControlBlock* sgcb,
  1152. uint8_t newActSg, ClientConnection connection);
  1153. /**
  1154. * \brief Set the callback handler for the SetActSG event
  1155. *
  1156. * \param self the instance of IedServer to operate on.
  1157. * \param sgcb the handle of the setting group control block of the setting group.
  1158. * \param handler the user provided callback handler.
  1159. * \param parameter a user provided parameter that is passed to the control handler.
  1160. */
  1161. LIB61850_API void
  1162. IedServer_setActiveSettingGroupChangedHandler(IedServer self, SettingGroupControlBlock* sgcb,
  1163. ActiveSettingGroupChangedHandler handler, void* parameter);
  1164. /**
  1165. * \brief Callback handler that is invoked when the edit setting group is about to be changed by an
  1166. * external client.
  1167. *
  1168. * In this function the user should update all SE data attributes
  1169. * associated with the given SettingGroupControlBlock.
  1170. * This function is called BEFORE the active setting group is changed. The user can reject to change the
  1171. * edit setting group by returning false. This can be used to implement RBAC.
  1172. *
  1173. * \param user provided parameter
  1174. * \param sgcb the setting group control block of the setting group that is about to be changed
  1175. * \param newEditSg the new edit setting group
  1176. * \param connection the client connection that requests the change
  1177. *
  1178. * \return true if the change is accepted, false otherwise.
  1179. *
  1180. */
  1181. typedef bool (*EditSettingGroupChangedHandler) (void* parameter, SettingGroupControlBlock* sgcb,
  1182. uint8_t newEditSg, ClientConnection connection);
  1183. /**
  1184. * \brief Set the callback handler for the SetEditSG event
  1185. *
  1186. * \param self the instance of IedServer to operate on.
  1187. * \param sgcb the handle of the setting group control block of the setting group.
  1188. * \param handler the user provided callback handler.
  1189. * \param parameter a user provided parameter that is passed to the control handler.
  1190. */
  1191. LIB61850_API void
  1192. IedServer_setEditSettingGroupChangedHandler(IedServer self, SettingGroupControlBlock* sgcb,
  1193. EditSettingGroupChangedHandler handler, void* parameter);
  1194. /**
  1195. * \brief Callback handler that is invoked when the edit setting group has been confirmed by an
  1196. * external client.
  1197. *
  1198. * \param user provided parameter
  1199. * \param sgcb the setting group control block of the setting group that is about to be changed
  1200. * \param editSg the edit setting group that has been confirmed
  1201. *
  1202. */
  1203. typedef void (*EditSettingGroupConfirmationHandler) (void* parameter, SettingGroupControlBlock* sgcb,
  1204. uint8_t editSg);
  1205. /**
  1206. * \brief Set the callback handler for the COnfEditSG event
  1207. *
  1208. * \param self the instance of IedServer to operate on.
  1209. * \param sgcb the handle of the setting group control block of the setting group.
  1210. * \param handler the user provided callback handler.
  1211. * \param parameter a user provided parameter that is passed to the control handler.
  1212. */
  1213. LIB61850_API void
  1214. IedServer_setEditSettingGroupConfirmationHandler(IedServer self, SettingGroupControlBlock* sgcb,
  1215. EditSettingGroupConfirmationHandler handler, void* parameter);
  1216. /**@}*/
  1217. /**
  1218. * @defgroup IEC61850_SERVER_CONTROL Server side control model handling
  1219. *
  1220. * \brief Functions and callbacks to handle control model related operations on the server side
  1221. *
  1222. * @{
  1223. */
  1224. /**
  1225. * \brief result code for ControlPerformCheckHandler
  1226. */
  1227. typedef enum {
  1228. CONTROL_ACCEPTED = -1, /**< check passed */
  1229. CONTROL_WAITING_FOR_SELECT = 0, /**< select operation in progress - handler will be called again later */
  1230. CONTROL_HARDWARE_FAULT = 1, /**< check failed due to hardware fault */
  1231. CONTROL_TEMPORARILY_UNAVAILABLE = 2, /**< control is already selected or operated */
  1232. CONTROL_OBJECT_ACCESS_DENIED = 3, /**< check failed due to access control reason - access denied for this client or state */
  1233. CONTROL_OBJECT_UNDEFINED = 4, /**< object not visible in this security context ??? */
  1234. CONTROL_VALUE_INVALID = 11 /**< ctlVal out of range */
  1235. } CheckHandlerResult;
  1236. /**
  1237. * \brief result codes for control handler (ControlWaitForExecutionHandler and ControlHandler)
  1238. */
  1239. typedef enum {
  1240. CONTROL_RESULT_FAILED = 0, /**< check or operation failed */
  1241. CONTROL_RESULT_OK = 1, /**< check or operation was successful */
  1242. CONTROL_RESULT_WAITING = 2 /**< check or operation is in progress */
  1243. } ControlHandlerResult;
  1244. typedef void* ControlAction;
  1245. /**
  1246. * \brief Sets the error code for the next command termination or application error message
  1247. *
  1248. * \param self the control action instance
  1249. * \param error the error code
  1250. */
  1251. LIB61850_API void
  1252. ControlAction_setError(ControlAction self, ControlLastApplError error);
  1253. /**
  1254. * \brief Sets the add cause for the next command termination or application error message
  1255. *
  1256. * \param self the control action instance
  1257. * \param addCause the additional cause
  1258. */
  1259. LIB61850_API void
  1260. ControlAction_setAddCause(ControlAction self, ControlAddCause addCause);
  1261. /**
  1262. * \brief Gets the originator category provided by the client
  1263. *
  1264. * \param self the control action instance
  1265. *
  1266. * \return the originator category
  1267. */
  1268. LIB61850_API int
  1269. ControlAction_getOrCat(ControlAction self);
  1270. /**
  1271. * \brief Gets the originator identifier provided by the client
  1272. *
  1273. * \param self the control action instance
  1274. *
  1275. * \return the originator identifier
  1276. */
  1277. LIB61850_API uint8_t*
  1278. ControlAction_getOrIdent(ControlAction self, int* orIdentSize);
  1279. /**
  1280. * \brief Get the ctlNum attribute send by the client
  1281. *
  1282. * \param self the control action instance
  1283. *
  1284. * \return the ctlNum value
  1285. */
  1286. LIB61850_API int
  1287. ControlAction_getCtlNum(ControlAction self);
  1288. /**
  1289. * \brief Gets the synchroCheck bit provided by the client
  1290. *
  1291. * \param self the control action instance
  1292. *
  1293. * \return the synchroCheck bit
  1294. */
  1295. LIB61850_API bool
  1296. ControlAction_getSynchroCheck(ControlAction self);
  1297. /**
  1298. * \brief Gets the interlockCheck bit provided by the client
  1299. *
  1300. * \param self the control action instance
  1301. *
  1302. * \return the interlockCheck bit
  1303. */
  1304. LIB61850_API bool
  1305. ControlAction_getInterlockCheck(ControlAction self);
  1306. /**
  1307. * \brief Check if the control callback is called by a select or operate command
  1308. *
  1309. * \param self the control action instance
  1310. *
  1311. * \return true, when called by select, false for operate
  1312. */
  1313. LIB61850_API bool
  1314. ControlAction_isSelect(ControlAction self);
  1315. /**
  1316. * \brief Gets the client object associated with the client that caused the control action
  1317. *
  1318. * \param self the control action instance
  1319. *
  1320. * \return client connection instance
  1321. */
  1322. LIB61850_API ClientConnection
  1323. ControlAction_getClientConnection(ControlAction self);
  1324. /**
  1325. * \brief Gets the control object that is subject to this action
  1326. *
  1327. * \param self the control action instance
  1328. *
  1329. * \return the controllable data object instance
  1330. */
  1331. LIB61850_API DataObject*
  1332. ControlAction_getControlObject(ControlAction self);
  1333. /**
  1334. * \brief Gets the time of the control (attribute "operTm"), if it's a timeActivatedControl, returns 0, if it's not.
  1335. *
  1336. * \param self the control action instance
  1337. *
  1338. * \return the controllable data object instance
  1339. */
  1340. LIB61850_API uint64_t
  1341. ControlAction_getControlTime(ControlAction self);
  1342. /**
  1343. * \brief Gets the time (attribute "T") of the last received control action (Oper or Select)
  1344. *
  1345. * \param self the control action instance
  1346. *
  1347. * \return the time of the last received control action
  1348. */
  1349. LIB61850_API Timestamp*
  1350. ControlAction_getT(ControlAction self);
  1351. /**
  1352. * \brief Control model callback to perform the static tests (optional).
  1353. *
  1354. * \note Signature changed in version 1.4!
  1355. *
  1356. * User provided callback function for the control model. It will be invoked after
  1357. * a control operation has been invoked by the client. This callback function is
  1358. * intended to perform the static tests. It should check if the interlock conditions
  1359. * are met if the interlockCheck parameter is true.
  1360. * This handler can also be check if the client has the required permissions to execute the
  1361. * operation and allow or deny the operation accordingly.
  1362. *
  1363. * \param action the control action parameter that provides access to additional context information
  1364. * \param parameter the parameter that was specified when setting the control handler
  1365. * \param ctlVal the control value of the control operation.
  1366. * \param test indicates if the operate request is a test operation
  1367. * \param interlockCheck the interlockCheck parameter provided by the client
  1368. *
  1369. * \return CONTROL_ACCEPTED if the static tests had been successful, one of the error codes otherwise
  1370. */
  1371. typedef CheckHandlerResult (*ControlPerformCheckHandler) (ControlAction action, void* parameter, MmsValue* ctlVal, bool test, bool interlockCheck);
  1372. /**
  1373. * \brief Control model callback to perform the dynamic tests (optional).
  1374. *
  1375. * \note Signature changed in version 1.4!
  1376. *
  1377. * User provided callback function for the control model. It will be invoked after
  1378. * a control operation has been invoked by the client. This callback function is
  1379. * intended to perform the dynamic tests. It should check if the synchronization conditions
  1380. * are met if the synchroCheck parameter is set to true.
  1381. *
  1382. * \note Since version 0.7.9 this function is intended to return immediately. If the operation
  1383. * cannot be performed immediately the function SHOULD return CONTROL_RESULT_WAITING and the
  1384. * handler will be invoked again later.
  1385. *
  1386. * \param action the control action parameter that provides access to additional context information
  1387. * \param parameter the parameter that was specified when setting the control handler
  1388. * \param ctlVal the control value of the control operation.
  1389. * \param test indicates if the operate request is a test operation
  1390. * \param synchroCheck the synchroCheck parameter provided by the client
  1391. *
  1392. * \return CONTROL_RESULT_OK if the dynamic tests had been successful, CONTROL_RESULT_FAILED otherwise,
  1393. * CONTROL_RESULT_WAITING if the test is not yet finished
  1394. */
  1395. typedef ControlHandlerResult (*ControlWaitForExecutionHandler) (ControlAction action, void* parameter, MmsValue* ctlVal, bool test, bool synchroCheck);
  1396. /**
  1397. * \brief Control model callback to actually perform the control operation.
  1398. *
  1399. * \note Signature changed in version 1.4!
  1400. *
  1401. * User provided callback function for the control model. It will be invoked when
  1402. * a control operation happens (Oper). Here the user should perform the control operation
  1403. * (e.g. by setting an digital output or switching a relay).
  1404. *
  1405. * \note Since version 0.7.9 this function is intended to return immediately. If the operation
  1406. * cannot be performed immediately the function SHOULD return CONTROL_RESULT_WAITING and the
  1407. * handler will be invoked again later.
  1408. *
  1409. * \param action the control action parameter that provides access to additional context information
  1410. * \param parameter the parameter that was specified when setting the control handler
  1411. * \param ctlVal the control value of the control operation.
  1412. * \param test indicates if the operate request is a test operation
  1413. *
  1414. * \return CONTROL_RESULT_OK if the control action bas been successful, CONTROL_RESULT_FAILED otherwise,
  1415. * CONTROL_RESULT_WAITING if the test is not yet finished
  1416. */
  1417. typedef ControlHandlerResult (*ControlHandler) (ControlAction action, void* parameter, MmsValue* ctlVal, bool test);
  1418. /**
  1419. * \brief Reason why a select state of a control object changed
  1420. */
  1421. typedef enum {
  1422. SELECT_STATE_REASON_SELECTED, /**< control has been selected */
  1423. SELECT_STATE_REASON_CANCELED, /**< cancel received for the control */
  1424. SELECT_STATE_REASON_TIMEOUT, /**< unselected due to timeout (sboTimeout) */
  1425. SELECT_STATE_REASON_OPERATED, /**< unselected due to successful operate */
  1426. SELECT_STATE_REASON_OPERATE_FAILED, /**< unselected due to failed operate */
  1427. SELECT_STATE_REASON_DISCONNECTED /**< unselected due to disconnection of selecting client */
  1428. } SelectStateChangedReason;
  1429. /**
  1430. * \brief Control model callback that is called when the select state of a control changes
  1431. *
  1432. * \note New in version 1.5
  1433. *
  1434. * \param action the control action parameter that provides access to additional context information
  1435. * \param parameter the parameter that was specified when setting the control handler
  1436. * \param isSelected true when the control is selected, false otherwise
  1437. * \param reason reason why the select state changed
  1438. */
  1439. typedef void (*ControlSelectStateChangedHandler) (ControlAction action, void* parameter, bool isSelected, SelectStateChangedReason reason);
  1440. /**
  1441. * \brief Set control handler for controllable data object
  1442. *
  1443. * This functions sets a user provided control handler for a data object. The data object
  1444. * has to be an instance of a controllable CDC (Common Data Class) like e.g. SPC, DPC or APC.
  1445. * The control handler is a callback function that will be called by the IEC server when a
  1446. * client invokes a control operation on the data object.
  1447. *
  1448. * \param self the instance of IedServer to operate on.
  1449. * \param node the controllable data object handle
  1450. * \param handler a callback function of type ControlHandler
  1451. * \param parameter a user provided parameter that is passed to the control handler.
  1452. */
  1453. LIB61850_API void
  1454. IedServer_setControlHandler(IedServer self, DataObject* node, ControlHandler handler, void* parameter);
  1455. /**
  1456. * \brief Set a handler for a controllable data object to perform operative tests
  1457. *
  1458. * This functions sets a user provided handler that should perform the operative tests for a control operation.
  1459. * Setting this handler is not required. If not set the server assumes that the checks will always be successful.
  1460. * The handler has to return true upon a successful test of false if the test fails. In the later case the control
  1461. * operation will be aborted.
  1462. *
  1463. * \param self the instance of IedServer to operate on.
  1464. * \param node the controllable data object handle
  1465. * \param handler a callback function of type ControlHandler
  1466. * \param parameter a user provided parameter that is passed to the control handler.
  1467. *
  1468. */
  1469. LIB61850_API void
  1470. IedServer_setPerformCheckHandler(IedServer self, DataObject* node, ControlPerformCheckHandler handler, void* parameter);
  1471. /**
  1472. * \brief Set a handler for a controllable data object to perform dynamic tests
  1473. *
  1474. * This functions sets a user provided handler that should perform the dynamic tests for a control operation.
  1475. * Setting this handler is not required. If not set the server assumes that the checks will always be successful.
  1476. * The handler has to return true upon a successful test of false if the test fails. In the later case the control
  1477. * operation will be aborted.
  1478. *
  1479. * \param self the instance of IedServer to operate on.
  1480. * \param node the controllable data object handle
  1481. * \param handler a callback function of type ControlHandler
  1482. * \param parameter a user provided parameter that is passed to the control handler.
  1483. *
  1484. */
  1485. LIB61850_API void
  1486. IedServer_setWaitForExecutionHandler(IedServer self, DataObject* node, ControlWaitForExecutionHandler handler, void* parameter);
  1487. /**
  1488. * \brief Set a callback handler for a controllable data object to track select state changes
  1489. *
  1490. * The callback is called whenever the select state of a control changes. Reason for changes can be:
  1491. * - a successful select or select-with-value by a client
  1492. * - select timeout
  1493. * - operate or failed operate
  1494. * - cancel request by a client
  1495. * - the client that selected the control has been disconnected
  1496. *
  1497. * \param self the instance of IedServer to operate on.
  1498. * \param node the controllable data object handle
  1499. * \param handler a callback function of type ControlHandler
  1500. * \param parameter a user provided parameter that is passed to the callback handler.
  1501. */
  1502. LIB61850_API void
  1503. IedServer_setSelectStateChangedHandler(IedServer self, DataObject* node, ControlSelectStateChangedHandler handler, void* parameter);
  1504. /**
  1505. * \brief Update the control model for the specified controllable data object with the given value and
  1506. * update "ctlModel" attribute value.
  1507. *
  1508. * \note The corresponding control structures for the control model have to be present in the data model!
  1509. *
  1510. * \param self the instance of IedServer to operate on.
  1511. * \param ctlObject the controllable data object handle
  1512. * \param value the new control model value
  1513. */
  1514. LIB61850_API void
  1515. IedServer_updateCtlModel(IedServer self, DataObject* ctlObject, ControlModel value);
  1516. /**@}*/
  1517. /**
  1518. * @defgroup IEC61850_SERVER_RCB Server side report control block (RCB) handling
  1519. *
  1520. * \brief Functions and callbacks to handle report control blocks (RCBs) on the server side
  1521. *
  1522. * @{
  1523. */
  1524. typedef enum {
  1525. RCB_EVENT_GET_PARAMETER, /* << parameter read by client (not implemented) */
  1526. RCB_EVENT_SET_PARAMETER, /* << parameter set by client */
  1527. RCB_EVENT_UNRESERVED, /* << RCB reservation canceled */
  1528. RCB_EVENT_RESERVED, /* << RCB reserved */
  1529. RCB_EVENT_ENABLE, /* << RCB enabled */
  1530. RCB_EVENT_DISABLE, /* << RCB disabled */
  1531. RCB_EVENT_GI, /* << GI report triggered */
  1532. RCB_EVENT_PURGEBUF, /* << Purge buffer procedure executed */
  1533. RCB_EVENT_OVERFLOW, /* << Report buffer overflow */
  1534. RCB_EVENT_REPORT_CREATED /* << A new report was created and inserted into the buffer */
  1535. } IedServer_RCBEventType;
  1536. /**
  1537. * \brief Callback that is called in case of RCB event
  1538. *
  1539. * \param parameter user provided parameter
  1540. * \param rcb affected report control block
  1541. * \param connection client connection that is involved
  1542. * \param event event type
  1543. * \param parameterName name of the parameter in case of RCB_EVENT_SET_PARAMETER
  1544. * \param serviceError service error in case of RCB_EVENT_SET_PARAMETER
  1545. */
  1546. typedef void (*IedServer_RCBEventHandler) (void* parameter, ReportControlBlock* rcb, ClientConnection connection, IedServer_RCBEventType event, const char* parameterName, MmsDataAccessError serviceError);
  1547. /**
  1548. * \brief Set a handler for report control block (RCB) events
  1549. *
  1550. * \param self the instance of IedServer to operate on.
  1551. * \param handler the event handler to be used
  1552. * \param parameter a user provided parameter that is passed to the handler.
  1553. */
  1554. LIB61850_API void
  1555. IedServer_setRCBEventHandler(IedServer self, IedServer_RCBEventHandler handler, void* parameter);
  1556. /**@}*/
  1557. /**
  1558. * @defgroup IEC61850_SERVER_SVCB Server side sampled values control block (SVCB) handling
  1559. *
  1560. * \brief Functions and callbacks to handle sampled values control blocks on the server side
  1561. *
  1562. * @{
  1563. */
  1564. /** Control block has been enabled by client */
  1565. #define IEC61850_SVCB_EVENT_ENABLE 1
  1566. /** Control block has been disabled by client */
  1567. #define IEC61850_SVCB_EVENT_DISABLE 0
  1568. /**
  1569. * \brief callback handler for SVCB events.
  1570. *
  1571. * \param svcb the related SVCB instance
  1572. * \param the event type
  1573. * \param user defined parameter
  1574. */
  1575. typedef void (*SVCBEventHandler) (SVControlBlock* svcb, int event, void* parameter);
  1576. /**
  1577. * \brief Set a handler for SVCB control block events (enable/disable)
  1578. *
  1579. * \param self the instance of IedServer to operate on.
  1580. * \param svcb the SVCB control block instance
  1581. * \param handler the event handler to be used
  1582. * \param parameter a user provided parameter that is passed to the handler.
  1583. */
  1584. LIB61850_API void
  1585. IedServer_setSVCBHandler(IedServer self, SVControlBlock* svcb, SVCBEventHandler handler, void* parameter);
  1586. /**@}*/
  1587. /**
  1588. * @defgroup IEC61850_SERVER_GOCB Server side GOOSE control block (GoCB) handling
  1589. *
  1590. * \brief Functions and callbacks to handle GOOSE control blocks (GoCBs) on the server side
  1591. *
  1592. * @{
  1593. */
  1594. typedef struct sMmsGooseControlBlock* MmsGooseControlBlock;
  1595. /** Control block has been enabled by client */
  1596. #define IEC61850_GOCB_EVENT_ENABLE 1
  1597. /** Control block has been disabled by client */
  1598. #define IEC61850_GOCB_EVENT_DISABLE 0
  1599. typedef void (*GoCBEventHandler) (MmsGooseControlBlock goCb, int event, void* parameter);
  1600. /**
  1601. * \brief Set a callback handler for GoCB events (enabled/disabled)
  1602. *
  1603. * The callback handler is called whenever a GOOSE control block is enabled or disabled.
  1604. * It can be used to integrate the external GOOSE publisher with the IEC 61850/MMS server.
  1605. *
  1606. * \param self the instance of IedServer to operate on.
  1607. * \param handler the callback handler
  1608. * \param parameter user provided parameter that is passed to the callback handler
  1609. */
  1610. LIB61850_API void
  1611. IedServer_setGoCBHandler(IedServer self, GoCBEventHandler handler, void* parameter);
  1612. LIB61850_API char*
  1613. MmsGooseControlBlock_getName(MmsGooseControlBlock self);
  1614. LIB61850_API LogicalNode*
  1615. MmsGooseControlBlock_getLogicalNode(MmsGooseControlBlock self);
  1616. LIB61850_API DataSet*
  1617. MmsGooseControlBlock_getDataSet(MmsGooseControlBlock self);
  1618. LIB61850_API bool
  1619. MmsGooseControlBlock_getGoEna(MmsGooseControlBlock self);
  1620. LIB61850_API int
  1621. MmsGooseControlBlock_getMinTime(MmsGooseControlBlock self);
  1622. LIB61850_API int
  1623. MmsGooseControlBlock_getMaxTime(MmsGooseControlBlock self);
  1624. LIB61850_API bool
  1625. MmsGooseControlBlock_getFixedOffs(MmsGooseControlBlock self);
  1626. LIB61850_API bool
  1627. MmsGooseControlBlock_getNdsCom(MmsGooseControlBlock self);
  1628. /**@}*/
  1629. /**
  1630. * @defgroup IEC61850_SERVER_EXTERNAL_ACCESS Handle external access to data model and access control
  1631. *
  1632. * \brief Functions and callbacks to handle and restrict external access to the data model and services
  1633. *
  1634. * This module provides functions and callbacks to restrict external access to the data model and services of the IEC 61850 server.
  1635. * They can be used to implement access control mechanisms like role based access control (RBAC) and to restrict access to specific
  1636. * data objects and data attributes.
  1637. *
  1638. * @{
  1639. */
  1640. /***************************************************************************
  1641. * Access control
  1642. **************************************************************************/
  1643. /**
  1644. * \brief callback handler to intercept/control client write access to data attributes
  1645. *
  1646. * User provided callback function to intercept/control MMS client access to
  1647. * IEC 61850 data attributes. The application can install the same handler
  1648. * multiple times and distinguish data attributes by the dataAttribute parameter.
  1649. * This handler can be used to perform write access control do data attributes.
  1650. * One application can be to allow write access only from a specific client. Another
  1651. * application could be to check if the value is in the allowed range before the write
  1652. * is accepted.
  1653. * When the callback returns DATA_ACCESS_ERROR_SUCCESS the write access is accepted and the stack will
  1654. * update the value automatically.
  1655. * When the callback returns DATA_ACCESS_ERROR_SUCCESS_NO_UPDATE the write access is accepted but the
  1656. * stack will not update the value automatically.
  1657. *
  1658. * \param the data attribute that has been written by an MMS client.
  1659. * \param the value the client want to write to the data attribute
  1660. * \param connection the connection object of the client connection that invoked the write operation
  1661. * \param parameter the user provided parameter
  1662. *
  1663. * \return DATA_ACCESS_ERROR_SUCCESS, or DATA_ACCESS_ERROR_SUCCESS_NO_UPDATE if access is accepted, DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED if access is denied.
  1664. */
  1665. typedef MmsDataAccessError
  1666. (*WriteAccessHandler) (DataAttribute* dataAttribute, MmsValue* value, ClientConnection connection, void* parameter);
  1667. /**
  1668. * \brief Install a WriteAccessHandler for a data attribute.
  1669. *
  1670. * This instructs the server to monitor write attempts by MMS clients to specific
  1671. * data attributes. If a client tries to write to the monitored data attribute the
  1672. * handler is invoked. The handler can decide if the write access will be allowed
  1673. * or denied. If a WriteAccessHandler is set for a specific data attribute - the
  1674. * default write access policy will not be performed for that data attribute.
  1675. *
  1676. * \note If the data attribute has sub data attributes, the WriteAccessHandler is not
  1677. * set for the sub data attributes and will not be called when the sub data attribute is
  1678. * written directly!
  1679. *
  1680. * \param self the instance of IedServer to operate on.
  1681. * \param dataAttribute the data attribute to monitor
  1682. * \param handler the callback function that is invoked if a client tries to write to
  1683. * the monitored data attribute.
  1684. * \param parameter a user provided parameter that is passed to the WriteAccessHandler when called.
  1685. */
  1686. LIB61850_API void
  1687. IedServer_handleWriteAccess(IedServer self, DataAttribute* dataAttribute,
  1688. WriteAccessHandler handler, void* parameter);
  1689. /**
  1690. * \brief Install a WriteAccessHandler for a data attribute and for all sub data attributes
  1691. *
  1692. * This instructs the server to monitor write attempts by MMS clients to specific
  1693. * data attributes. If a client tries to write to the monitored data attribute the
  1694. * handler is invoked. The handler can decide if the write access will be allowed
  1695. * or denied. If a WriteAccessHandler is set for a specific data attribute - the
  1696. * default write access policy will not be performed for that data attribute.
  1697. *
  1698. * When the data attribute is a complex attribute then the handler will also be installed
  1699. * for all sub data attributes. When the data attribute is a basic data attribute then
  1700. * this function behaves like \ref IedServer_handleWriteAccess.
  1701. *
  1702. * \param self the instance of IedServer to operate on.
  1703. * \param dataAttribute the data attribute to monitor
  1704. * \param handler the callback function that is invoked if a client tries to write to
  1705. * the monitored data attribute.
  1706. * \param parameter a user provided parameter that is passed to the WriteAccessHandler when called.
  1707. */
  1708. LIB61850_API void
  1709. IedServer_handleWriteAccessForComplexAttribute(IedServer self, DataAttribute* dataAttribute,
  1710. WriteAccessHandler handler, void* parameter);
  1711. /**
  1712. * \brief Install a WriteAccessHandler for all data attributes of a data object with a specific FC
  1713. *
  1714. * \param self the instance of IedServer to operate on.
  1715. * \param dataObject the data object to monitor
  1716. * \param fc the functional constraint to monitor
  1717. * \param handler the callback function that is invoked if a client tries to write to
  1718. * the monitored data attribute.
  1719. * \param parameter a user provided parameter that is passed to the WriteAccessHandler when called.
  1720. */
  1721. LIB61850_API void
  1722. IedServer_handleWriteAccessForDataObject(IedServer self, DataObject* dataObject, FunctionalConstraint fc, WriteAccessHandler handler, void* parameter);
  1723. typedef enum {
  1724. ACCESS_POLICY_ALLOW,
  1725. ACCESS_POLICY_DENY
  1726. } AccessPolicy;
  1727. /**
  1728. * \brief Change the default write access policy for functional constraint data with a specific FC.
  1729. *
  1730. * \param self the instance of IedServer to operate on.
  1731. * \param fc the FC for which to change the default write access policy.
  1732. * \param policy the new policy to apply.
  1733. *
  1734. */
  1735. LIB61850_API void
  1736. IedServer_setWriteAccessPolicy(IedServer self, FunctionalConstraint fc, AccessPolicy policy);
  1737. /**
  1738. * \brief callback handler to control client read access to data attributes
  1739. *
  1740. * User provided callback function to control MMS client read access to IEC 61850
  1741. * data objects. The application is to allow read access to data objects for specific clients only.
  1742. * It can be used to implement a role based access control (RBAC).
  1743. *
  1744. * \param ld the logical device the client wants to access
  1745. * \param ln the logical node the client wants to access
  1746. * \param dataObject the data object the client wants to access
  1747. * \param fc the functional constraint of the access
  1748. * \param connection the client connection that causes the access
  1749. * \param parameter the user provided parameter
  1750. *
  1751. * \return DATA_ACCESS_ERROR_SUCCESS if access is accepted, DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED if access is denied.
  1752. */
  1753. typedef MmsDataAccessError
  1754. (*ReadAccessHandler) (LogicalDevice* ld, LogicalNode* ln, DataObject* dataObject, FunctionalConstraint fc, ClientConnection connection, void* parameter);
  1755. /**
  1756. * \brief Install the global read access handler
  1757. *
  1758. * The read access handler will be called for every read access before the server grants access to the client.
  1759. *
  1760. * \param self the instance of IedServer to operate on.
  1761. * \param handler the callback function that is invoked if a client tries to read a data object.
  1762. * \param parameter a user provided parameter that is passed to the callback function.
  1763. */
  1764. LIB61850_API void
  1765. IedServer_setReadAccessHandler(IedServer self, ReadAccessHandler handler, void* parameter);
  1766. typedef enum {
  1767. DATASET_CREATE,
  1768. DATASET_DELETE,
  1769. DATASET_READ,
  1770. DATASET_WRITE,
  1771. DATASET_GET_DIRECTORY
  1772. } IedServer_DataSetOperation;
  1773. /**
  1774. * \brief Callback that is called when the client is calling a dataset operation (create, delete, read, write, list directory)
  1775. *
  1776. * \note This callback is called before the IedServer_RCBEventHandler and only in case of operations (RCB_EVENT_GET_PARAMETER, RCB_EVENT_SET_PARAMETER, RCB_EVENT_ENABLE
  1777. *
  1778. * \param parameter user provided parameter
  1779. * \param connection client connection that is involved
  1780. * \param operation one of the following operation types: DATASET_CREATE, DATASET_DELETE, DATASET_READ, DATASET_WRITE, DATASET_GET_DIRECTORY
  1781. *
  1782. * \return true to allow operation, false to deny operation
  1783. */
  1784. typedef bool
  1785. (*IedServer_DataSetAccessHandler) (void* parameter, ClientConnection connection, IedServer_DataSetOperation operation, const char* datasetRef);
  1786. /**
  1787. * \brief Set a handler to control access to a dataset (create, delete, read, write, list directory)
  1788. *
  1789. * \param handler the callback handler to be used
  1790. * \param parameter a user provided parameter that is passed to the handler.
  1791. */
  1792. LIB61850_API void
  1793. IedServer_setDataSetAccessHandler(IedServer self, IedServer_DataSetAccessHandler handler, void* parameter);
  1794. typedef enum {
  1795. DIRECTORY_CAT_LD_LIST,
  1796. DIRECTORY_CAT_DATA_LIST,
  1797. DIRECTORY_CAT_DATASET_LIST,
  1798. DIRECTORY_CAT_LOG_LIST
  1799. } IedServer_DirectoryCategory;
  1800. typedef bool
  1801. (*IedServer_DirectoryAccessHandler) (void* parameter, ClientConnection connection, IedServer_DirectoryCategory category, LogicalDevice* logicalDevice);
  1802. LIB61850_API void
  1803. IedServer_setDirectoryAccessHandler(IedServer self, IedServer_DirectoryAccessHandler handler, void* parameter);
  1804. /**
  1805. * \brief Callback that is called when a client is invoking a list objects service
  1806. *
  1807. * This callback can be used to control the list object access to specific objects and is called for each object that are subject to a client request.
  1808. *
  1809. * \param parameter user provided parameter
  1810. * \param connection client connection that is involved
  1811. * \param acsiClass the ACSI class of the object
  1812. * \param ld the logical device of the object
  1813. * \param ln the logical node of the object
  1814. * \param objectName the name of the object (e.g. data object name, data set name, log name, RCB name, ...)
  1815. * \param subObjectName the name of a sub element of an object or NULL
  1816. * \param fc the functional constraint of the object of IEC61850_FC_NONE when the object has no FC.
  1817. *
  1818. * \return true to include the object in the service response, otherwise false
  1819. */
  1820. typedef bool
  1821. (*IedServer_ListObjectsAccessHandler)(void* parameter, ClientConnection connection, ACSIClass acsiClass, LogicalDevice* ld, LogicalNode* ln, const char* objectName, const char* subObjectName, FunctionalConstraint fc);
  1822. /**
  1823. * \brief Set a handler to control which objects are return by the list objects services
  1824. *
  1825. * \param handler the callback handler to be used
  1826. * \param parameter a user provided parameter that is passed to the handler.
  1827. */
  1828. LIB61850_API void
  1829. IedServer_setListObjectsAccessHandler(IedServer self, IedServer_ListObjectsAccessHandler handler, void* parameter);
  1830. typedef enum {
  1831. IEC61850_CB_ACCESS_TYPE_READ,
  1832. IEC61850_CB_ACCESS_TYPE_WRITE
  1833. } IedServer_ControlBlockAccessType;
  1834. /**
  1835. * \brief Callback that is called when a client is invoking a read or write service to a control block or log
  1836. *
  1837. * This callback can be used to control the read and write access to control blocks and logs (SGCB, LCBs, URCBs, BRCBs, GoCBs, SVCBs, logs)
  1838. *
  1839. * \param parameter user provided parameter
  1840. * \param connection client connection that is involved
  1841. * \param acsiClass the ACSI class of the object
  1842. * \param ld the logical device of the object
  1843. * \param ln the logical node of the object
  1844. * \param objectName the name of the object (e.g. data object name, data set name, log name, RCB name, ...)
  1845. * \param subObjectName the name of a sub element of an object or NULL
  1846. * \param accessType access type (read=IEC61850_CB_ACCESS_TYPE_READ or write=IEC61850_CB_ACCESS_TYPE_WRITE)
  1847. *
  1848. * \return true to include the object in the service response, otherwise false
  1849. */
  1850. typedef bool
  1851. (*IedServer_ControlBlockAccessHandler)(void* parameter, ClientConnection connection, ACSIClass acsiClass, LogicalDevice* ld, LogicalNode* ln, const char* objectName, const char* subObjectName, IedServer_ControlBlockAccessType accessType);
  1852. /**
  1853. * \brief Set a handler to control read and write access to control blocks and logs
  1854. *
  1855. * \param handler the callback handler to be used
  1856. * \param parameter a user provided parameter that is passed to the handler.
  1857. */
  1858. LIB61850_API void
  1859. IedServer_setControlBlockAccessHandler(IedServer self, IedServer_ControlBlockAccessHandler handler, void* parameter);
  1860. /**
  1861. * \brief Temporarily ignore read requests (for testing purposes)
  1862. *
  1863. * \param self the instance of IedServer to operate on.
  1864. * \param ignore true to ignore read requests, false to handle read requests.
  1865. */
  1866. LIB61850_API void
  1867. IedServer_ignoreReadAccess(IedServer self, bool ignore);
  1868. /**@}*/
  1869. /**@}*/
  1870. #ifdef __cplusplus
  1871. }
  1872. #endif
  1873. #endif /* IED_SERVER_API_H_ */