|
|
@ -1,7 +1,7 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* mms_server.c
|
|
|
|
* mms_server.c
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright 2013-2023 Michael Zillgith
|
|
|
|
* Copyright 2013-2024 Michael Zillgith
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This file is part of libIEC61850.
|
|
|
|
* This file is part of libIEC61850.
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -34,7 +34,8 @@ createValueCaches(MmsDevice* device)
|
|
|
|
Map valueCaches = Map_create();
|
|
|
|
Map valueCaches = Map_create();
|
|
|
|
|
|
|
|
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < device->domainCount; i++) {
|
|
|
|
for (i = 0; i < device->domainCount; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
MmsValueCache valueCache = MmsValueCache_create(device->domains[i]);
|
|
|
|
MmsValueCache valueCache = MmsValueCache_create(device->domains[i]);
|
|
|
|
Map_addEntry(valueCaches, device->domains[i], valueCache);
|
|
|
|
Map_addEntry(valueCaches, device->domains[i], valueCache);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -52,7 +53,8 @@ MmsServer_create(MmsDevice* device, TLSConfiguration tlsConfiguration)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MmsServer self = (MmsServer) GLOBAL_CALLOC(1, sizeof(struct sMmsServer));
|
|
|
|
MmsServer self = (MmsServer) GLOBAL_CALLOC(1, sizeof(struct sMmsServer));
|
|
|
|
|
|
|
|
|
|
|
|
if (self) {
|
|
|
|
if (self)
|
|
|
|
|
|
|
|
{
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1)
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1)
|
|
|
|
self->openConnectionsLock = Semaphore_create(1);
|
|
|
|
self->openConnectionsLock = Semaphore_create(1);
|
|
|
|
|
|
|
|
|
|
|
@ -75,7 +77,8 @@ MmsServer_create(MmsDevice* device, TLSConfiguration tlsConfiguration)
|
|
|
|
if (self->isoServerList == NULL)
|
|
|
|
if (self->isoServerList == NULL)
|
|
|
|
goto exit_error;
|
|
|
|
goto exit_error;
|
|
|
|
|
|
|
|
|
|
|
|
if (tlsConfiguration) {
|
|
|
|
if (tlsConfiguration)
|
|
|
|
|
|
|
|
{
|
|
|
|
IsoServer isoServer = IsoServer_create(tlsConfiguration);
|
|
|
|
IsoServer isoServer = IsoServer_create(tlsConfiguration);
|
|
|
|
|
|
|
|
|
|
|
|
if (isoServer == NULL)
|
|
|
|
if (isoServer == NULL)
|
|
|
@ -115,7 +118,8 @@ MmsServer_create(MmsDevice* device, TLSConfiguration tlsConfiguration)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_MMS_SERVER_MAX_GET_FILE_TASKS; i++) {
|
|
|
|
for (i = 0; i < CONFIG_MMS_SERVER_MAX_GET_FILE_TASKS; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
self->fileUploadTasks[i].state = 0;
|
|
|
|
self->fileUploadTasks[i].state = 0;
|
|
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1)
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1)
|
|
|
@ -140,8 +144,8 @@ MmsServer_addAP(MmsServer self, const char* ipAddr, int tcpPort, TLSConfiguratio
|
|
|
|
{
|
|
|
|
{
|
|
|
|
IsoServer isoServer = IsoServer_create(tlsConfiguration);
|
|
|
|
IsoServer isoServer = IsoServer_create(tlsConfiguration);
|
|
|
|
|
|
|
|
|
|
|
|
if (isoServer) {
|
|
|
|
if (isoServer)
|
|
|
|
|
|
|
|
{
|
|
|
|
IsoServer_setLocalIpAddress(isoServer, ipAddr);
|
|
|
|
IsoServer_setLocalIpAddress(isoServer, ipAddr);
|
|
|
|
|
|
|
|
|
|
|
|
if (tcpPort != -1)
|
|
|
|
if (tcpPort != -1)
|
|
|
@ -161,13 +165,15 @@ MmsServer_addAP(MmsServer self, const char* ipAddr, int tcpPort, TLSConfiguratio
|
|
|
|
void
|
|
|
|
void
|
|
|
|
MmsServer_setLocalIpAddress(MmsServer self, const char* localIpAddress)
|
|
|
|
MmsServer_setLocalIpAddress(MmsServer self, const char* localIpAddress)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (LinkedList_size(self->isoServerList) == 0) {
|
|
|
|
if (LinkedList_size(self->isoServerList) == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
MmsServer_addAP(self, NULL, -1, NULL);
|
|
|
|
MmsServer_addAP(self, NULL, -1, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LinkedList elem = LinkedList_get(self->isoServerList, 0);
|
|
|
|
LinkedList elem = LinkedList_get(self->isoServerList, 0);
|
|
|
|
|
|
|
|
|
|
|
|
if (elem) {
|
|
|
|
if (elem)
|
|
|
|
|
|
|
|
{
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
|
|
|
|
|
|
|
|
IsoServer_setLocalIpAddress(isoServer, localIpAddress);
|
|
|
|
IsoServer_setLocalIpAddress(isoServer, localIpAddress);
|
|
|
@ -179,7 +185,8 @@ MmsServer_isRunning(MmsServer self)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LinkedList elem = LinkedList_get(self->isoServerList, 0);
|
|
|
|
LinkedList elem = LinkedList_get(self->isoServerList, 0);
|
|
|
|
|
|
|
|
|
|
|
|
if (elem) {
|
|
|
|
if (elem)
|
|
|
|
|
|
|
|
{
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
|
|
|
|
|
|
|
|
if (IsoServer_getState(isoServer) == ISO_SVR_STATE_RUNNING)
|
|
|
|
if (IsoServer_getState(isoServer) == ISO_SVR_STATE_RUNNING)
|
|
|
@ -193,12 +200,13 @@ void
|
|
|
|
MmsServer_setFilestoreBasepath(MmsServer self, const char* basepath)
|
|
|
|
MmsServer_setFilestoreBasepath(MmsServer self, const char* basepath)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#if (CONFIG_SET_FILESTORE_BASEPATH_AT_RUNTIME == 1)
|
|
|
|
#if (CONFIG_SET_FILESTORE_BASEPATH_AT_RUNTIME == 1)
|
|
|
|
if (self->filestoreBasepath != NULL) {
|
|
|
|
if (self->filestoreBasepath)
|
|
|
|
|
|
|
|
{
|
|
|
|
GLOBAL_FREEMEM(self->filestoreBasepath);
|
|
|
|
GLOBAL_FREEMEM(self->filestoreBasepath);
|
|
|
|
self->filestoreBasepath = NULL;
|
|
|
|
self->filestoreBasepath = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (basepath != NULL)
|
|
|
|
if (basepath)
|
|
|
|
self->filestoreBasepath = StringUtils_copyString(basepath);
|
|
|
|
self->filestoreBasepath = StringUtils_copyString(basepath);
|
|
|
|
#endif /* (CONFIG_SET_FILESTORE_BASEPATH_AT_RUNTIME == 1) */
|
|
|
|
#endif /* (CONFIG_SET_FILESTORE_BASEPATH_AT_RUNTIME == 1) */
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -208,15 +216,17 @@ MmsServer_setFilestoreBasepath(MmsServer self, const char* basepath)
|
|
|
|
void
|
|
|
|
void
|
|
|
|
MmsServer_setMaxConnections(MmsServer self, int maxConnections)
|
|
|
|
MmsServer_setMaxConnections(MmsServer self, int maxConnections)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (self->isoServerList) {
|
|
|
|
if (self->isoServerList)
|
|
|
|
|
|
|
|
{
|
|
|
|
if (LinkedList_size(self->isoServerList) == 0) {
|
|
|
|
if (LinkedList_size(self->isoServerList) == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
MmsServer_addAP(self, NULL, -1, NULL);
|
|
|
|
MmsServer_addAP(self, NULL, -1, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LinkedList elem = LinkedList_getNext(self->isoServerList);
|
|
|
|
LinkedList elem = LinkedList_getNext(self->isoServerList);
|
|
|
|
|
|
|
|
|
|
|
|
while (elem) {
|
|
|
|
while (elem)
|
|
|
|
|
|
|
|
{
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
|
|
|
|
|
|
|
|
IsoServer_setMaxConnections(isoServer, maxConnections);
|
|
|
|
IsoServer_setMaxConnections(isoServer, maxConnections);
|
|
|
@ -307,13 +317,14 @@ MmsServer_getObtainFileTask(MmsServer self)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_MMS_SERVER_MAX_GET_FILE_TASKS; i++) {
|
|
|
|
for (i = 0; i < CONFIG_MMS_SERVER_MAX_GET_FILE_TASKS; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1)
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1)
|
|
|
|
Semaphore_wait(self->fileUploadTasks[i].taskLock);
|
|
|
|
Semaphore_wait(self->fileUploadTasks[i].taskLock);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
if (self->fileUploadTasks[i].state == 0) {
|
|
|
|
if (self->fileUploadTasks[i].state == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
self->fileUploadTasks[i].state = 1;
|
|
|
|
self->fileUploadTasks[i].state = 1;
|
|
|
|
|
|
|
|
|
|
|
|
return &(self->fileUploadTasks[i]);
|
|
|
|
return &(self->fileUploadTasks[i]);
|
|
|
@ -322,7 +333,6 @@ MmsServer_getObtainFileTask(MmsServer self)
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1)
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1)
|
|
|
|
Semaphore_post(self->fileUploadTasks[i].taskLock);
|
|
|
|
Semaphore_post(self->fileUploadTasks[i].taskLock);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
return NULL;
|
|
|
@ -392,11 +402,12 @@ MmsServer_setClientAuthenticator(MmsServer self, AcseAuthenticator authenticator
|
|
|
|
self->authenticator = authenticator;
|
|
|
|
self->authenticator = authenticator;
|
|
|
|
self->authenticatorParameter = authenticatorParameter;
|
|
|
|
self->authenticatorParameter = authenticatorParameter;
|
|
|
|
|
|
|
|
|
|
|
|
if (self->isoServerList) {
|
|
|
|
if (self->isoServerList)
|
|
|
|
|
|
|
|
{
|
|
|
|
LinkedList elem = LinkedList_getNext(self->isoServerList);
|
|
|
|
LinkedList elem = LinkedList_getNext(self->isoServerList);
|
|
|
|
|
|
|
|
|
|
|
|
while (elem) {
|
|
|
|
while (elem)
|
|
|
|
|
|
|
|
{
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
|
|
|
|
|
|
|
|
IsoServer_setAuthenticator(isoServer, authenticator, authenticatorParameter);
|
|
|
|
IsoServer_setAuthenticator(isoServer, authenticator, authenticatorParameter);
|
|
|
@ -448,7 +459,8 @@ deleteSingleCache(MmsValueCache cache)
|
|
|
|
void
|
|
|
|
void
|
|
|
|
MmsServer_destroy(MmsServer self)
|
|
|
|
MmsServer_destroy(MmsServer self)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (self) {
|
|
|
|
if (self)
|
|
|
|
|
|
|
|
{
|
|
|
|
LinkedList_destroyDeep(self->isoServerList, (LinkedListValueDeleteFunction) IsoServer_destroy);
|
|
|
|
LinkedList_destroyDeep(self->isoServerList, (LinkedListValueDeleteFunction) IsoServer_destroy);
|
|
|
|
|
|
|
|
|
|
|
|
Map_deleteDeep(self->openConnections, false, closeConnection);
|
|
|
|
Map_deleteDeep(self->openConnections, false, closeConnection);
|
|
|
@ -476,7 +488,8 @@ MmsServer_destroy(MmsServer self)
|
|
|
|
#if (MMS_OBTAIN_FILE_SERVICE == 1)
|
|
|
|
#if (MMS_OBTAIN_FILE_SERVICE == 1)
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1)
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1)
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < CONFIG_MMS_SERVER_MAX_GET_FILE_TASKS; i++) {
|
|
|
|
for (i = 0; i < CONFIG_MMS_SERVER_MAX_GET_FILE_TASKS; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
if (self->fileUploadTasks[i].taskLock)
|
|
|
|
if (self->fileUploadTasks[i].taskLock)
|
|
|
|
Semaphore_destroy(self->fileUploadTasks[i].taskLock);
|
|
|
|
Semaphore_destroy(self->fileUploadTasks[i].taskLock);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -492,10 +505,10 @@ MmsServer_getValueFromCache(MmsServer self, MmsDomain* domain, const char* itemI
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MmsValueCache cache = (MmsValueCache) Map_getEntry(self->valueCaches, domain);
|
|
|
|
MmsValueCache cache = (MmsValueCache) Map_getEntry(self->valueCaches, domain);
|
|
|
|
|
|
|
|
|
|
|
|
if (cache != NULL)
|
|
|
|
if (cache)
|
|
|
|
return MmsValueCache_lookupValue(cache, itemId, NULL);
|
|
|
|
return MmsValueCache_lookupValue(cache, itemId, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
return NULL ;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MmsValue*
|
|
|
|
MmsValue*
|
|
|
@ -503,10 +516,10 @@ MmsServer_getValueFromCacheEx(MmsServer self, MmsDomain* domain, const char* ite
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MmsValueCache cache = (MmsValueCache) Map_getEntry(self->valueCaches, domain);
|
|
|
|
MmsValueCache cache = (MmsValueCache) Map_getEntry(self->valueCaches, domain);
|
|
|
|
|
|
|
|
|
|
|
|
if (cache != NULL)
|
|
|
|
if (cache)
|
|
|
|
return MmsValueCache_lookupValue(cache, itemId, typeSpec);
|
|
|
|
return MmsValueCache_lookupValue(cache, itemId, typeSpec);
|
|
|
|
|
|
|
|
|
|
|
|
return NULL ;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MmsValue*
|
|
|
|
MmsValue*
|
|
|
@ -514,10 +527,10 @@ MmsServer_getValueFromCacheEx2(MmsServer self, MmsDomain* domain, const char* it
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MmsValueCache cache = (MmsValueCache) Map_getEntry(self->valueCaches, domain);
|
|
|
|
MmsValueCache cache = (MmsValueCache) Map_getEntry(self->valueCaches, domain);
|
|
|
|
|
|
|
|
|
|
|
|
if (cache != NULL)
|
|
|
|
if (cache)
|
|
|
|
return MmsValueCache_lookupValueEx(cache, itemId, idx, componentId, NULL);
|
|
|
|
return MmsValueCache_lookupValueEx(cache, itemId, idx, componentId, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
return NULL ;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
@ -525,9 +538,8 @@ MmsServer_insertIntoCache(MmsServer self, MmsDomain* domain, char* itemId, MmsVa
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MmsValueCache cache = (MmsValueCache) Map_getEntry(self->valueCaches, domain);
|
|
|
|
MmsValueCache cache = (MmsValueCache) Map_getEntry(self->valueCaches, domain);
|
|
|
|
|
|
|
|
|
|
|
|
if (cache != NULL) {
|
|
|
|
if (cache)
|
|
|
|
MmsValueCache_insertValue(cache, itemId, value);
|
|
|
|
MmsValueCache_insertValue(cache, itemId, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MmsDataAccessError
|
|
|
|
MmsDataAccessError
|
|
|
@ -541,7 +553,8 @@ mmsServer_setValue(MmsServer self, MmsDomain* domain, char* itemId, MmsValue* va
|
|
|
|
indication = self->writeHandler(self->writeHandlerParameter, domain,
|
|
|
|
indication = self->writeHandler(self->writeHandlerParameter, domain,
|
|
|
|
itemId, -1, NULL, value, connection);
|
|
|
|
itemId, -1, NULL, value, connection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
MmsValue* cachedValue;
|
|
|
|
MmsValue* cachedValue;
|
|
|
|
|
|
|
|
|
|
|
|
if (domain == NULL)
|
|
|
|
if (domain == NULL)
|
|
|
@ -549,7 +562,8 @@ mmsServer_setValue(MmsServer self, MmsDomain* domain, char* itemId, MmsValue* va
|
|
|
|
|
|
|
|
|
|
|
|
cachedValue = MmsServer_getValueFromCache(self, domain, itemId);
|
|
|
|
cachedValue = MmsServer_getValueFromCache(self, domain, itemId);
|
|
|
|
|
|
|
|
|
|
|
|
if (cachedValue) {
|
|
|
|
if (cachedValue)
|
|
|
|
|
|
|
|
{
|
|
|
|
MmsValue_update(cachedValue, value);
|
|
|
|
MmsValue_update(cachedValue, value);
|
|
|
|
indication = DATA_ACCESS_ERROR_SUCCESS;
|
|
|
|
indication = DATA_ACCESS_ERROR_SUCCESS;
|
|
|
|
} else
|
|
|
|
} else
|
|
|
@ -570,7 +584,8 @@ mmsServer_setValueEx(MmsServer self, MmsDomain* domain, char* itemId, MmsValue*
|
|
|
|
indication = self->writeHandler(self->writeHandlerParameter, domain,
|
|
|
|
indication = self->writeHandler(self->writeHandlerParameter, domain,
|
|
|
|
itemId, arrayIdx, componentId, value, connection);
|
|
|
|
itemId, arrayIdx, componentId, value, connection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
MmsValue* cachedValue = NULL;
|
|
|
|
MmsValue* cachedValue = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (domain == NULL)
|
|
|
|
if (domain == NULL)
|
|
|
@ -578,10 +593,12 @@ mmsServer_setValueEx(MmsServer self, MmsDomain* domain, char* itemId, MmsValue*
|
|
|
|
|
|
|
|
|
|
|
|
cachedValue = MmsServer_getValueFromCacheEx2(self, domain, itemId, arrayIdx, componentId);
|
|
|
|
cachedValue = MmsServer_getValueFromCacheEx2(self, domain, itemId, arrayIdx, componentId);
|
|
|
|
|
|
|
|
|
|
|
|
if (cachedValue) {
|
|
|
|
if (cachedValue)
|
|
|
|
|
|
|
|
{
|
|
|
|
MmsValue_update(cachedValue, value);
|
|
|
|
MmsValue_update(cachedValue, value);
|
|
|
|
indication = DATA_ACCESS_ERROR_SUCCESS;
|
|
|
|
indication = DATA_ACCESS_ERROR_SUCCESS;
|
|
|
|
} else
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
indication = DATA_ACCESS_ERROR_OBJECT_VALUE_INVALID;
|
|
|
|
indication = DATA_ACCESS_ERROR_OBJECT_VALUE_INVALID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -593,12 +610,14 @@ mmsServer_getValue(MmsServer self, MmsDomain* domain, char* itemId, MmsServerCon
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MmsValue* value = NULL;
|
|
|
|
MmsValue* value = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (self->readAccessHandler != NULL) {
|
|
|
|
if (self->readAccessHandler != NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
MmsDataAccessError accessError =
|
|
|
|
MmsDataAccessError accessError =
|
|
|
|
self->readAccessHandler(self->readAccessHandlerParameter, (domain == (MmsDomain*) self->device) ? NULL : domain,
|
|
|
|
self->readAccessHandler(self->readAccessHandlerParameter, (domain == (MmsDomain*) self->device) ? NULL : domain,
|
|
|
|
itemId, connection, isDirectAccess);
|
|
|
|
itemId, connection, isDirectAccess);
|
|
|
|
|
|
|
|
|
|
|
|
if (accessError != DATA_ACCESS_ERROR_SUCCESS) {
|
|
|
|
if (accessError != DATA_ACCESS_ERROR_SUCCESS)
|
|
|
|
|
|
|
|
{
|
|
|
|
value = MmsValue_newDataAccessError(accessError);
|
|
|
|
value = MmsValue_newDataAccessError(accessError);
|
|
|
|
MmsValue_setDeletable(value);
|
|
|
|
MmsValue_setDeletable(value);
|
|
|
|
goto exit_function;
|
|
|
|
goto exit_function;
|
|
|
@ -616,26 +635,13 @@ exit_function:
|
|
|
|
return value;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MmsDataAccessError
|
|
|
|
|
|
|
|
mmsServer_checkReadAccess(MmsServer self, MmsDomain* domain, char* itemId, MmsServerConnection connection, bool isDirectAccess)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
MmsDataAccessError accessError = DATA_ACCESS_ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (self->readAccessHandler) {
|
|
|
|
|
|
|
|
accessError =
|
|
|
|
|
|
|
|
self->readAccessHandler(self->readAccessHandlerParameter, (domain == (MmsDomain*) self->device) ? NULL : domain,
|
|
|
|
|
|
|
|
itemId, connection, isDirectAccess);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return accessError;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
bool
|
|
|
|
mmsServer_checkListAccess(MmsServer self, MmsGetNameListType listType, MmsDomain* domain, char* itemId, MmsServerConnection connection)
|
|
|
|
mmsServer_checkListAccess(MmsServer self, MmsGetNameListType listType, MmsDomain* domain, char* itemId, MmsServerConnection connection)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool allowAccess = true;
|
|
|
|
bool allowAccess = true;
|
|
|
|
|
|
|
|
|
|
|
|
if (self->listAccessHandler) {
|
|
|
|
if (self->listAccessHandler)
|
|
|
|
|
|
|
|
{
|
|
|
|
allowAccess = self->listAccessHandler(self->listAccessHandlerParameter, listType, domain, itemId, connection);
|
|
|
|
allowAccess = self->listAccessHandler(self->listAccessHandlerParameter, listType, domain, itemId, connection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -654,7 +660,8 @@ isoConnectionIndicationHandler(IsoConnectionIndication indication,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MmsServer self = (MmsServer) parameter;
|
|
|
|
MmsServer self = (MmsServer) parameter;
|
|
|
|
|
|
|
|
|
|
|
|
if (indication == ISO_CONNECTION_OPENED) {
|
|
|
|
if (indication == ISO_CONNECTION_OPENED)
|
|
|
|
|
|
|
|
{
|
|
|
|
MmsServerConnection mmsCon = MmsServerConnection_init(0, self, connection);
|
|
|
|
MmsServerConnection mmsCon = MmsServerConnection_init(0, self, connection);
|
|
|
|
|
|
|
|
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1)
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1)
|
|
|
@ -671,8 +678,8 @@ isoConnectionIndicationHandler(IsoConnectionIndication indication,
|
|
|
|
self->connectionHandler(self->connectionHandlerParameter,
|
|
|
|
self->connectionHandler(self->connectionHandlerParameter,
|
|
|
|
mmsCon, MMS_SERVER_NEW_CONNECTION);
|
|
|
|
mmsCon, MMS_SERVER_NEW_CONNECTION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (indication == ISO_CONNECTION_CLOSED) {
|
|
|
|
else if (indication == ISO_CONNECTION_CLOSED)
|
|
|
|
|
|
|
|
{
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1)
|
|
|
|
#if (CONFIG_MMS_THREADLESS_STACK != 1)
|
|
|
|
Semaphore_wait(self->openConnectionsLock);
|
|
|
|
Semaphore_wait(self->openConnectionsLock);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
@ -697,15 +704,17 @@ isoConnectionIndicationHandler(IsoConnectionIndication indication,
|
|
|
|
void
|
|
|
|
void
|
|
|
|
MmsServer_startListening(MmsServer self, int tcpPort)
|
|
|
|
MmsServer_startListening(MmsServer self, int tcpPort)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (self->isoServerList) {
|
|
|
|
if (self->isoServerList)
|
|
|
|
|
|
|
|
{
|
|
|
|
if (LinkedList_size(self->isoServerList) == 0) {
|
|
|
|
if (LinkedList_size(self->isoServerList) == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
MmsServer_addAP(self, NULL, -1, NULL);
|
|
|
|
MmsServer_addAP(self, NULL, -1, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LinkedList elem = LinkedList_getNext(self->isoServerList);
|
|
|
|
LinkedList elem = LinkedList_getNext(self->isoServerList);
|
|
|
|
|
|
|
|
|
|
|
|
while (elem) {
|
|
|
|
while (elem)
|
|
|
|
|
|
|
|
{
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
|
|
|
|
|
|
|
|
IsoServer_setConnectionHandler(isoServer, isoConnectionIndicationHandler, (void*) self);
|
|
|
|
IsoServer_setConnectionHandler(isoServer, isoConnectionIndicationHandler, (void*) self);
|
|
|
@ -723,10 +732,12 @@ MmsServer_startListening(MmsServer self, int tcpPort)
|
|
|
|
void
|
|
|
|
void
|
|
|
|
MmsServer_stopListening(MmsServer self)
|
|
|
|
MmsServer_stopListening(MmsServer self)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (self->isoServerList) {
|
|
|
|
if (self->isoServerList)
|
|
|
|
|
|
|
|
{
|
|
|
|
LinkedList elem = LinkedList_getNext(self->isoServerList);
|
|
|
|
LinkedList elem = LinkedList_getNext(self->isoServerList);
|
|
|
|
|
|
|
|
|
|
|
|
while (elem) {
|
|
|
|
while (elem)
|
|
|
|
|
|
|
|
{
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
|
|
|
|
|
|
|
|
IsoServer_stopListening(isoServer);
|
|
|
|
IsoServer_stopListening(isoServer);
|
|
|
@ -740,15 +751,17 @@ MmsServer_stopListening(MmsServer self)
|
|
|
|
void
|
|
|
|
void
|
|
|
|
MmsServer_startListeningThreadless(MmsServer self, int tcpPort)
|
|
|
|
MmsServer_startListeningThreadless(MmsServer self, int tcpPort)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (self->isoServerList) {
|
|
|
|
if (self->isoServerList)
|
|
|
|
|
|
|
|
{
|
|
|
|
if (LinkedList_size(self->isoServerList) == 0) {
|
|
|
|
if (LinkedList_size(self->isoServerList) == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
MmsServer_addAP(self, NULL, -1, NULL);
|
|
|
|
MmsServer_addAP(self, NULL, -1, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LinkedList elem = LinkedList_getNext(self->isoServerList);
|
|
|
|
LinkedList elem = LinkedList_getNext(self->isoServerList);
|
|
|
|
|
|
|
|
|
|
|
|
while (elem) {
|
|
|
|
while (elem)
|
|
|
|
|
|
|
|
{
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
|
|
|
|
|
|
|
|
IsoServer_setConnectionHandler(isoServer, isoConnectionIndicationHandler, (void*) self);
|
|
|
|
IsoServer_setConnectionHandler(isoServer, isoConnectionIndicationHandler, (void*) self);
|
|
|
@ -768,21 +781,25 @@ MmsServer_waitReady(MmsServer self, unsigned int timeoutMs)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (self->isoServerList) {
|
|
|
|
if (self->isoServerList)
|
|
|
|
|
|
|
|
{
|
|
|
|
bool isFirst = true;
|
|
|
|
bool isFirst = true;
|
|
|
|
|
|
|
|
|
|
|
|
LinkedList elem = LinkedList_getNext(self->isoServerList);
|
|
|
|
LinkedList elem = LinkedList_getNext(self->isoServerList);
|
|
|
|
|
|
|
|
|
|
|
|
while (elem) {
|
|
|
|
while (elem)
|
|
|
|
|
|
|
|
{
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
|
|
|
|
|
|
|
|
int serverResult;
|
|
|
|
int serverResult;
|
|
|
|
|
|
|
|
|
|
|
|
if (isFirst) {
|
|
|
|
if (isFirst)
|
|
|
|
|
|
|
|
{
|
|
|
|
serverResult = IsoServer_waitReady(isoServer, timeoutMs);
|
|
|
|
serverResult = IsoServer_waitReady(isoServer, timeoutMs);
|
|
|
|
isFirst = false;
|
|
|
|
isFirst = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
serverResult = IsoServer_waitReady(isoServer, 0);
|
|
|
|
serverResult = IsoServer_waitReady(isoServer, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -799,10 +816,12 @@ MmsServer_waitReady(MmsServer self, unsigned int timeoutMs)
|
|
|
|
void
|
|
|
|
void
|
|
|
|
MmsServer_handleIncomingMessages(MmsServer self)
|
|
|
|
MmsServer_handleIncomingMessages(MmsServer self)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (self->isoServerList) {
|
|
|
|
if (self->isoServerList)
|
|
|
|
|
|
|
|
{
|
|
|
|
LinkedList elem = LinkedList_getNext(self->isoServerList);
|
|
|
|
LinkedList elem = LinkedList_getNext(self->isoServerList);
|
|
|
|
|
|
|
|
|
|
|
|
while (elem) {
|
|
|
|
while (elem)
|
|
|
|
|
|
|
|
{
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
|
|
|
|
|
|
|
|
IsoServer_processIncomingMessages(isoServer);
|
|
|
|
IsoServer_processIncomingMessages(isoServer);
|
|
|
@ -844,10 +863,12 @@ MmsServer_getConnectionCounter(MmsServer self)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (self->isoServerList) {
|
|
|
|
if (self->isoServerList)
|
|
|
|
|
|
|
|
{
|
|
|
|
LinkedList elem = LinkedList_getNext(self->isoServerList);
|
|
|
|
LinkedList elem = LinkedList_getNext(self->isoServerList);
|
|
|
|
|
|
|
|
|
|
|
|
while (elem) {
|
|
|
|
while (elem)
|
|
|
|
|
|
|
|
{
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
|
|
|
|
|
|
|
|
count += IsoServer_getConnectionCounter(isoServer);
|
|
|
|
count += IsoServer_getConnectionCounter(isoServer);
|
|
|
@ -862,7 +883,8 @@ MmsServer_getConnectionCounter(MmsServer self)
|
|
|
|
void
|
|
|
|
void
|
|
|
|
MmsServer_callConnectionHandler(MmsServer self, MmsServerConnection connection)
|
|
|
|
MmsServer_callConnectionHandler(MmsServer self, MmsServerConnection connection)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (self->connectionHandler) {
|
|
|
|
if (self->connectionHandler)
|
|
|
|
|
|
|
|
{
|
|
|
|
self->connectionHandler(self->connectionHandlerParameter, connection, MMS_SERVER_CONNECTION_TICK);
|
|
|
|
self->connectionHandler(self->connectionHandlerParameter, connection, MMS_SERVER_CONNECTION_TICK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -870,10 +892,12 @@ MmsServer_callConnectionHandler(MmsServer self, MmsServerConnection connection)
|
|
|
|
void
|
|
|
|
void
|
|
|
|
MmsServer_stopListeningThreadless(MmsServer self)
|
|
|
|
MmsServer_stopListeningThreadless(MmsServer self)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (self->isoServerList) {
|
|
|
|
if (self->isoServerList)
|
|
|
|
|
|
|
|
{
|
|
|
|
LinkedList elem = LinkedList_getNext(self->isoServerList);
|
|
|
|
LinkedList elem = LinkedList_getNext(self->isoServerList);
|
|
|
|
|
|
|
|
|
|
|
|
while (elem) {
|
|
|
|
while (elem)
|
|
|
|
|
|
|
|
{
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
IsoServer isoServer = (IsoServer) LinkedList_getData(elem);
|
|
|
|
|
|
|
|
|
|
|
|
IsoServer_stopListeningThreadless(isoServer);
|
|
|
|
IsoServer_stopListeningThreadless(isoServer);
|
|
|
|