libIEC61850  0.8.4
Open-source IEC 61850 MMS/GOOSE server and client library
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros 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 "stack_config.h"
36 
37 #include "mms_device_model.h"
38 #include "mms_value.h"
39 #include "iso_server.h"
40 
41 typedef enum {
44 
45 typedef struct sMmsServer* MmsServer;
46 
47 #if (MMS_FILE_SERVICE == 1)
48 
49 #ifndef CONFIG_MMS_MAX_NUMBER_OF_OPEN_FILES_PER_CONNECTION
50 #define CONFIG_MMS_MAX_NUMBER_OF_OPEN_FILES_PER_CONNECTION 5
51 #endif
52 
53 #include "hal_filesystem.h"
54 
55 typedef struct {
56  int32_t frsmId;
57  uint32_t readPosition;
58  uint32_t fileSize;
59  FileHandle fileHandle;
60 } MmsFileReadStateMachine;
61 
62 #endif /* (MMS_FILE_SERVICE == 1) */
63 
64 typedef struct sMmsServerConnection {
68  int maxPduSize; /* local detail */
70  MmsServer server;
71  uint32_t lastInvokeId;
72 
73 #if (MMS_DYNAMIC_DATA_SETS == 1)
74  LinkedList /*<MmsNamedVariableList>*/namedVariableLists; /* aa-specific named variable lists */
75 #endif
76 
77 #if (MMS_FILE_SERVICE == 1)
78  int32_t nextFrsmId;
79  MmsFileReadStateMachine frsms[CONFIG_MMS_MAX_NUMBER_OF_OPEN_FILES_PER_CONNECTION];
80 #endif
81 
83 
84 typedef enum {
89 
90 typedef MmsValue* (*MmsReadVariableHandler)(void* parameter, MmsDomain* domain,
91  char* variableId, MmsServerConnection* connection);
92 
93 typedef MmsDataAccessError (*MmsReadAccessHandler) (void* parameter, MmsDomain* domain,
94  char* variableId, MmsServerConnection* connection);
95 
96 typedef MmsDataAccessError (*MmsWriteVariableHandler)(void* parameter,
97  MmsDomain* domain, char* variableId, MmsValue* value,
98  MmsServerConnection* connection);
99 
100 typedef void (*MmsConnectionHandler)(void* parameter,
101  MmsServerConnection* connection, MmsServerEvent event);
102 
103 MmsServer
104 MmsServer_create(IsoServer isoServer, MmsDevice* device);
105 
106 void
107 MmsServer_destroy(MmsServer self);
108 
109 void
111  void* parameter);
112 
113 void
114 MmsServer_installReadAccessHandler(MmsServer self, MmsReadAccessHandler, void* parameter);
115 
116 void
118  void* parameter);
119 
123 void
125  void* parameter);
126 
127 void
128 MmsServer_setClientAuthenticator(MmsServer self, AcseAuthenticator authenticator, void* authenticatorParameter);
129 
130 MmsDevice*
131 MmsServer_getDevice(MmsServer self);
132 
133 MmsValue*
134 MmsServer_getValueFromCache(MmsServer self, MmsDomain* domain, char* itemId);
135 
136 bool
137 MmsServer_isLocked(MmsServer self);
138 
152 typedef bool (*MmsNamedVariableListChangedHandler)(void* parameter, bool create, MmsVariableListType listType, MmsDomain* domain,
153  char* listName, MmsServerConnection* connection);
154 
162 void
164 
174 void
175 MmsServer_lockModel(MmsServer self);
176 
185 void
186 MmsServer_unlockModel(MmsServer self);
187 
188 void
189 MmsServer_insertIntoCache(MmsServer self, MmsDomain* domain, char* itemId,
190  MmsValue* value);
191 
192 void
193 MmsServer_setDevice(MmsServer self, MmsDevice* device);
194 
195 /***************************************************
196  * Functions for multi-threaded operation mode
197  ***************************************************/
198 
205 void
206 MmsServer_startListening(MmsServer self, int tcpPort);
207 
213 void
214 MmsServer_stopListening(MmsServer self);
215 
216 /***************************************************
217  * Functions for threadless operation mode
218  ***************************************************/
219 
226 void
227 MmsServer_startListeningThreadless(MmsServer self, int tcpPort);
228 
236 int
237 MmsServer_waitReady(MmsServer self, unsigned int timeoutMs);
238 
247 void
248 MmsServer_handleIncomingMessages(MmsServer self);
249 
255 void
256 MmsServer_stopListeningThreadless(MmsServer self);
257 
258 
259 /***************************************************
260  * Functions for MMS identify service
261  ***************************************************/
262 
274 void
275 MmsServer_setServerIdentity(MmsServer self, char* vendorName, char* modelName, char* revision);
276 
283 char*
284 MmsServer_getVendorName(MmsServer self);
285 
292 char*
293 MmsServer_getModelName(MmsServer self);
294 
301 char*
302 MmsServer_getRevision(MmsServer self);
303 
304 /***************************************************
305  * Functions for MMS status service
306  ***************************************************/
307 
308 #define MMS_LOGICAL_STATE_STATE_CHANGES_ALLOWED 0
309 #define MMS_LOGICAL_STATE_NO_STATE_CHANGES_ALLOWED 1
310 #define MMS_LOGICAL_STATE_LIMITED_SERVICES_PERMITTED 2
311 #define MMS_LOGICAL_STATE_SUPPORT_SERVICES_ALLOWED 3
312 
313 #define MMS_PHYSICAL_STATE_OPERATIONAL 0
314 #define MMS_PHYSICAL_STATE_PARTIALLY_OPERATIONAL 1
315 #define MMS_PHYSICAL_STATE_INOPERATIONAL 2
316 #define MMS_PHYSICAL_STATE_NEEDS_COMMISSIONING 3
317 
329 typedef void (*MmsStatusRequestListener)(void* parameter, MmsServer mmsServer, MmsServerConnection* connection, bool extendedDerivation);
330 
338 void
339 MmsServer_setVMDStatus(MmsServer self, int vmdLogicalStatus, int vmdPhysicalStatus);
340 
346 int
347 MmsServer_getVMDLogicalStatus(MmsServer self);
348 
354 int
355 MmsServer_getVMDPhysicalStatus(MmsServer self);
356 
368 void
369 MmsServer_setStatusRequestListener(MmsServer self, MmsStatusRequestListener listener, void* parameter);
370 
373 #ifdef __cplusplus
374 }
375 #endif
376 
377 #endif /* MMS_SERVER_H_ */