static void /* will be called by ISO server stack */ isoConnectionIndicationHandler(IsoConnectionIndication indication, void* parameter, IsoConnection connection) { MmsServer mmsServer = (MmsServer) parameter; if (indication == ISO_CONNECTION_OPENED) { MmsServerConnection* mmsCon = MmsServerConnection_init(0, mmsServer, connection); Map_addEntry(mmsServer->openConnections, connection, mmsCon); if (mmsServer->connectionHandler != NULL) mmsServer->connectionHandler(mmsServer->connectionHandlerParameter, mmsCon, MMS_SERVER_NEW_CONNECTION); } else if (indication == ISO_CONNECTION_CLOSED) { MmsServerConnection* mmsCon = (MmsServerConnection*) Map_removeEntry(mmsServer->openConnections, connection, false); if (mmsServer->connectionHandler != NULL) mmsServer->connectionHandler(mmsServer->connectionHandlerParameter, mmsCon, MMS_SERVER_CONNECTION_CLOSED); if (mmsCon != NULL) MmsServerConnection_destroy(mmsCon); } }
MmsValueIndication MmsServer_setValue(MmsServer self, MmsDomain* domain, char* itemId, MmsValue* value) { MmsValueIndication indication; if (self->writeHandler != NULL) { indication = self->writeHandler(self->writeHandlerParameter, domain, itemId, value); } else { //TODO if value in cache write to cache //else access denied MmsValue* cachedValue; cachedValue = MmsServer_getValueFromCache(self, domain, itemId); if (cachedValue != NULL) { MmsValue_update(cachedValue, value); indication = MMS_VALUE_OK; } else indication = MMS_VALUE_ACCESS_DENIED; } return indication; }
MmsDataAccessError mmsServer_setValue(MmsServer self, MmsDomain* domain, char* itemId, MmsValue* value, MmsServerConnection* connection) { MmsDataAccessError indication; if (self->writeHandler != NULL) { indication = self->writeHandler(self->writeHandlerParameter, domain, itemId, value, connection); } else { MmsValue* cachedValue; if (domain == NULL) domain = (MmsDomain*) self->device; cachedValue = MmsServer_getValueFromCache(self, domain, itemId); if (cachedValue != NULL) { MmsValue_update(cachedValue, value); indication = DATA_ACCESS_ERROR_SUCCESS; } else indication = DATA_ACCESS_ERROR_OBJECT_VALUE_INVALID; } return indication; }
MmsError mmsServer_callVariableListChangedHandler(bool create, MmsVariableListType listType, MmsDomain* domain, char* listName, MmsServerConnection connection) { MmsServer self = connection->server; if (self->variableListChangedHandler != NULL) { if (DEBUG_MMS_SERVER) printf("MMS_SERVER: call MmsNamedVariableListChangedHandler for new list %s\n", listName); return self->variableListChangedHandler(self->variableListChangedHandlerParameter, create, listType, domain, listName, connection); } else return MMS_ERROR_NONE; }
void mmsServer_handleStatusRequest( MmsServerConnection connection, uint8_t* requestBuffer, int bufPos, int invokeId, ByteBuffer* response) { /* check for extended derivation */ bool extendedDerivation = BerDecoder_decodeBoolean(requestBuffer, bufPos); if (DEBUG_MMS_SERVER) printf("mms_status_service.c: statusRequest (extendedDerivation: %i)\n", extendedDerivation); bufPos = 0; uint8_t* buffer = response->buffer; uint32_t invokeIdLength = BerEncoder_UInt32determineEncodedSize(invokeId); MmsServer mmsServer = connection->server; /* Invoke user provided callback */ if (mmsServer->statusRequestListener != NULL) mmsServer->statusRequestListener(mmsServer->statusRequestListenerParameter, mmsServer, connection, extendedDerivation); uint32_t vmdPhysicalStatusLength = BerEncoder_UInt32determineEncodedSize((uint32_t) mmsServer->vmdPhysicalStatus); uint32_t vmdLogicalStatusLength = BerEncoder_UInt32determineEncodedSize((uint32_t) mmsServer->vmdLogicalStatus); uint32_t statusLength = 2 + vmdPhysicalStatusLength + 2 + vmdLogicalStatusLength; uint32_t statusResponseLength = invokeIdLength + 2 + 1 + BerEncoder_determineLengthSize(statusLength) + statusLength; /* Status response pdu */ bufPos = BerEncoder_encodeTL(0xa1, statusResponseLength, buffer, bufPos); /* invokeId */ bufPos = BerEncoder_encodeTL(0x02, invokeIdLength, buffer, bufPos); bufPos = BerEncoder_encodeUInt32(invokeId, buffer, bufPos); bufPos = BerEncoder_encodeTL(0xa0, statusLength, buffer, bufPos); bufPos = BerEncoder_encodeTL(0x80, vmdLogicalStatusLength, buffer, bufPos); bufPos = BerEncoder_encodeUInt32((uint32_t) mmsServer->vmdLogicalStatus, buffer, bufPos); bufPos = BerEncoder_encodeTL(0x81, vmdPhysicalStatusLength, buffer, bufPos); bufPos = BerEncoder_encodeUInt32((uint32_t) mmsServer->vmdPhysicalStatus, buffer, bufPos); response->size = bufPos; }