libIEC61850  0.8.2
Open-source IEC 61850 MMS/GOOSE server and client library
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
mms_server.h
Go to the documentation of this file.
1 /*
2  * mms_server.h
3  *
4  * Copyright 2013, 2014 Michael Zillgith
5  *
6  * This file is part of libIEC61850.
7  *
8  * libIEC61850 is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * libIEC61850 is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with libIEC61850. If not, see <http://www.gnu.org/licenses/>.
20  *
21  * See COPYING file for the complete license text.
22  */
23 
24 #ifndef MMS_SERVER_H_
25 #define MMS_SERVER_H_
26 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #include "mms_device_model.h"
36 #include "mms_value.h"
37 
38 #include "iso_server.h"
39 
40 typedef enum {
43 
44 typedef struct sMmsServer* MmsServer;
45 
46 #if (MMS_FILE_SERVICE == 1)
47 
48 #ifndef CONFIG_MMS_MAX_NUMBER_OF_OPEN_FILES_PER_CONNECTION
49 #define CONFIG_MMS_MAX_NUMBER_OF_OPEN_FILES_PER_CONNECTION 5
50 #endif
51 
52 #include "hal_filesystem.h"
53 
54 typedef struct {
55  int32_t frsmId;
56  uint32_t readPosition;
57  uint32_t fileSize;
58  FileHandle fileHandle;
59 } MmsFileReadStateMachine;
60 
61 #endif /* (MMS_FILE_SERVICE == 1) */
62 
63 typedef struct sMmsServerConnection {
67  int maxPduSize; /* local detail */
69  MmsServer server;
70  LinkedList /*<MmsNamedVariableList>*/namedVariableLists; /* aa-specific named variable lists */
71  uint32_t lastInvokeId;
72 
73 
74 #if (MMS_FILE_SERVICE == 1)
75  int32_t nextFrsmId;
76  MmsFileReadStateMachine frsms[CONFIG_MMS_MAX_NUMBER_OF_OPEN_FILES_PER_CONNECTION];
77 #endif
78 
80 
81 typedef MmsValue* (*MmsReadVariableHandler)(void* parameter, MmsDomain* domain,
82  char* variableId, MmsServerConnection* connection);
83 
84 typedef MmsDataAccessError (*MmsReadAccessHandler) (void* parameter, MmsDomain* domain,
85  char* variableId, MmsServerConnection* connection);
86 
87 typedef MmsDataAccessError (*MmsWriteVariableHandler)(void* parameter,
88  MmsDomain* domain, char* variableId, MmsValue* value,
89  MmsServerConnection* connection);
90 
91 typedef void (*MmsConnectionHandler)(void* parameter,
92  MmsServerConnection* connection, MmsServerEvent event);
93 
94 MmsServer
95 MmsServer_create(IsoServer isoServer, MmsDevice* device);
96 
97 void
98 MmsServer_destroy(MmsServer self);
99 
100 void
102  void* parameter);
103 
104 void
105 MmsServer_installReadAccessHandler(MmsServer self, MmsReadAccessHandler, void* parameter);
106 
107 void
109  void* parameter);
110 
114 void
116  void* parameter);
117 
118 void
119 MmsServer_setClientAuthenticator(MmsServer self, AcseAuthenticator authenticator, void* authenticatorParameter);
120 
121 MmsDevice*
122 MmsServer_getDevice(MmsServer self);
123 
124 MmsValue*
125 MmsServer_getValueFromCache(MmsServer self, MmsDomain* domain, char* itemId);
126 
127 bool
128 MmsServer_isLocked(MmsServer self);
129 
139 void
140 MmsServer_lockModel(MmsServer self);
141 
150 void
151 MmsServer_unlockModel(MmsServer self);
152 
153 void
154 MmsServer_insertIntoCache(MmsServer self, MmsDomain* domain, char* itemId,
155  MmsValue* value);
156 
157 void
158 MmsServer_setDevice(MmsServer self, MmsDevice* device);
159 
160 /***************************************************
161  * Functions for multi-threaded operation mode
162  ***************************************************/
163 
170 void
171 MmsServer_startListening(MmsServer self, int tcpPort);
172 
178 void
179 MmsServer_stopListening(MmsServer self);
180 
181 /***************************************************
182  * Functions for threadless operation mode
183  ***************************************************/
184 
191 void
192 MmsServer_startListeningThreadless(MmsServer self, int tcpPort);
193 
201 int
202 MmsServer_waitReady(MmsServer self, unsigned int timeoutMs);
203 
212 void
213 MmsServer_handleIncomingMessages(MmsServer self);
214 
220 void
221 MmsServer_stopListeningThreadless(MmsServer self);
222 
223 
224 /***************************************************
225  * Functions for MMS identify service
226  ***************************************************/
227 
239 void
240 MmsServer_setServerIdentity(MmsServer self, char* vendorName, char* modelName, char* revision);
241 
248 char*
249 MmsServer_getVendorName(MmsServer self);
250 
257 char*
258 MmsServer_getModelName(MmsServer self);
259 
266 char*
267 MmsServer_getRevision(MmsServer self);
268 
269 /***************************************************
270  * Functions for MMS status service
271  ***************************************************/
272 
273 #define MMS_LOGICAL_STATE_STATE_CHANGES_ALLOWED 0
274 #define MMS_LOGICAL_STATE_NO_STATE_CHANGES_ALLOWED 1
275 #define MMS_LOGICAL_STATE_LIMITED_SERVICES_PERMITTED 2
276 #define MMS_LOGICAL_STATE_SUPPORT_SERVICES_ALLOWED 3
277 
278 #define MMS_PHYSICAL_STATE_OPERATIONAL 0
279 #define MMS_PHYSICAL_STATE_PARTIALLY_OPERATIONAL 1
280 #define MMS_PHYSICAL_STATE_INOPERATIONAL 2
281 #define MMS_PHYSICAL_STATE_NEEDS_COMMISSIONING 3
282 
294 typedef void (*MmsStatusRequestListener)(void* parameter, MmsServer mmsServer, MmsServerConnection* connection, bool extendedDerivation);
295 
303 void
304 MmsServer_setVMDStatus(MmsServer self, int vmdLogicalStatus, int vmdPhysicalStatus);
305 
311 int
312 MmsServer_getVMDLogicalStatus(MmsServer self);
313 
319 int
320 MmsServer_getVMDPhysicalStatus(MmsServer self);
321 
333 void
334 MmsServer_setStatusRequestListener(MmsServer self, MmsStatusRequestListener listener, void* parameter);
335 
338 #ifdef __cplusplus
339 }
340 #endif
341 
342 #endif /* MMS_SERVER_H_ */