static void handleReadNamedVariableListRequest( MmsServerConnection* connection, ReadRequest_t* read, int invokeId, ByteBuffer* response) { if (read->variableAccessSpecification.choice.variableListName.present == ObjectName_PR_domainspecific) { char* domainId = mmsMsg_createStringFromAsnIdentifier( read->variableAccessSpecification.choice.variableListName.choice.domainspecific.domainId); char* listName = mmsMsg_createStringFromAsnIdentifier( read->variableAccessSpecification.choice.variableListName.choice.domainspecific.itemId); VarAccessSpec accessSpec; accessSpec.isNamedVariableList = true; accessSpec.specific = 1; accessSpec.domainId = domainId; accessSpec.itemId = listName; MmsDomain* domain = MmsDevice_getDomain(MmsServer_getDevice(connection->server), domainId); if (domain == NULL) { if (DEBUG) printf("MMS read: domain %s not found!\n", domainId); mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_TYPE_OBJECT_NON_EXISTENT); } else { MmsNamedVariableList namedList = MmsDomain_getNamedVariableList(domain, listName); if (namedList != NULL) { createNamedVariableListResponse(connection, namedList, invokeId, response, read, &accessSpec); } else { if (DEBUG) printf("MMS read: named variable list %s not found!\n", listName); mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_TYPE_OBJECT_NON_EXISTENT); } } free(domainId); free(listName); } else if (read->variableAccessSpecification.choice.variableListName.present == ObjectName_PR_aaspecific) { char* listName = mmsMsg_createStringFromAsnIdentifier(read->variableAccessSpecification. choice.variableListName.choice.aaspecific); MmsNamedVariableList namedList = MmsServerConnection_getNamedVariableList(connection, listName); VarAccessSpec accessSpec; accessSpec.isNamedVariableList = true; accessSpec.specific = 2; accessSpec.domainId = NULL; accessSpec.itemId = listName; if (namedList == NULL) mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_TYPE_OBJECT_NON_EXISTENT); else { createNamedVariableListResponse(connection, namedList, invokeId, response, read, &accessSpec); } free(listName); } else mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_TYPE_OBJECT_ACCESS_UNSUPPORTED); }
void mmsServer_handleDeleteNamedVariableListRequest(MmsServerConnection* connection, DeleteNamedVariableListRequest_t* request, int invokeId, ByteBuffer* response) { //TODO implement for association specific named variable lists MmsDevice* device; long scopeOfDelete; request->scopeOfDelete; asn_INTEGER2long(request->scopeOfDelete, &scopeOfDelete); device = MmsServer_getDevice(connection->server); if (scopeOfDelete == DeleteNamedVariableListRequest__scopeOfDelete_specific) { int numberMatched = 0; int numberDeleted = 0; int numberItems = request->listOfVariableListName->list.count; int i; for (i = 0; i < numberItems; i++) { if (request->listOfVariableListName->list.array[i]->present == ObjectName_PR_domainspecific) { char* domainId = mmsMsg_createStringFromAsnIdentifier( request->listOfVariableListName->list.array[i]->choice.domainspecific.domainId); MmsDomain* domain = MmsDevice_getDomain(device, domainId); char* itemId = mmsMsg_createStringFromAsnIdentifier( request->listOfVariableListName->list.array[i]->choice.domainspecific.itemId); MmsNamedVariableList variableList = MmsDomain_getNamedVariableList(domain, itemId); if (variableList != NULL) { numberMatched++; if (MmsNamedVariableList_isDeletable(variableList)) { MmsDomain_deleteNamedVariableList(domain, itemId); numberDeleted++; } } free(domainId); free(itemId); } else if (request->listOfVariableListName->list.array[i]->present == ObjectName_PR_aaspecific) { char* itemId = mmsMsg_createStringFromAsnIdentifier( request->listOfVariableListName->list.array[i]->choice.aaspecific); MmsNamedVariableList variableList = MmsServerConnection_getNamedVariableList(connection, itemId); if (variableList != NULL) { numberMatched++; numberDeleted++; MmsServerConnection_deleteNamedVariableList(connection, itemId); } free(itemId); } //TODO else send error??? } createDeleteNamedVariableListResponse(invokeId, response, numberMatched, numberDeleted); } else { mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_TYPE_OBJECT_ACCESS_UNSUPPORTED); } }
void mmsServer_handleGetNamedVariableListAttributesRequest( MmsServerConnection connection, uint8_t* buffer, int bufPos, int maxBufPos, uint32_t invokeId, ByteBuffer* response) { GetNamedVariableListAttributesRequest_t* request = 0; asn_dec_rval_t rval = ber_decode(NULL, &asn_DEF_GetNamedVariableListAttributesRequest, (void**) &request, buffer + bufPos, maxBufPos - bufPos); if (rval.code != RC_OK) { mmsServer_writeMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_INVALID_PDU, response); return; } if (request->present == ObjectName_PR_domainspecific) { char domainName[65]; char itemName[65]; if ((request->choice.domainspecific.domainId.size > 64) || (request->choice.domainspecific.itemId.size > 64)) { mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OTHER); goto exit_function; } StringUtils_createStringFromBufferInBuffer(domainName, request->choice.domainspecific.domainId.buf, request->choice.domainspecific.domainId.size); StringUtils_createStringFromBufferInBuffer(itemName, request->choice.domainspecific.itemId.buf, request->choice.domainspecific.itemId.size); MmsDevice* mmsDevice = MmsServer_getDevice(connection->server); MmsDomain* domain = MmsDevice_getDomain(mmsDevice, domainName); if (domain != NULL) { MmsNamedVariableList variableList = MmsDomain_getNamedVariableList(domain, itemName); if (variableList != NULL) createGetNamedVariableListAttributesResponse(invokeId, response, variableList); else mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT); } else mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT); } #if (MMS_DYNAMIC_DATA_SETS == 1) else if (request->present == ObjectName_PR_aaspecific) { char listName[65]; if (request->choice.aaspecific.size > 64) { mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OTHER); goto exit_function; } StringUtils_createStringFromBufferInBuffer(listName, request->choice.aaspecific.buf, request->choice.aaspecific.size); MmsNamedVariableList varList = MmsServerConnection_getNamedVariableList(connection, listName); if (varList != NULL) createGetNamedVariableListAttributesResponse(invokeId, response, varList); else mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT); } #endif /* (MMS_DYNAMIC_DATA_SETS == 1) */ else { mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_ACCESS_UNSUPPORTED); } exit_function: asn_DEF_GetVariableAccessAttributesRequest.free_struct(&asn_DEF_GetNamedVariableListAttributesRequest, request, 0); }
void mmsServer_handleDefineNamedVariableListRequest( MmsServerConnection connection, uint8_t* buffer, int bufPos, int maxBufPos, uint32_t invokeId, ByteBuffer* response) { DefineNamedVariableListRequest_t* request = 0; MmsPdu_t* mmsPdu = 0; asn_dec_rval_t rval = ber_decode(NULL, &asn_DEF_MmsPdu, (void**) &mmsPdu, buffer, maxBufPos); if (rval.code != RC_OK) { mmsServer_writeMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_INVALID_PDU, response); goto exit_function; } request = &(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.defineNamedVariableList); MmsDevice* device = MmsServer_getDevice(connection->server); if (request->variableListName.present == ObjectName_PR_domainspecific) { char domainName[65]; if (request->variableListName.choice.domainspecific.domainId.size > 64) { mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT); goto exit_free_struct; } StringUtils_createStringFromBufferInBuffer(domainName, request->variableListName.choice.domainspecific.domainId.buf, request->variableListName.choice.domainspecific.domainId.size); MmsDomain* domain = MmsDevice_getDomain(device, domainName); if (domain == NULL) { mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT); goto exit_free_struct; } if (LinkedList_size(domain->namedVariableLists) < CONFIG_MMS_MAX_NUMBER_OF_DOMAIN_SPECIFIC_DATA_SETS) { char variableListName[65]; if (request->variableListName.choice.domainspecific.itemId.size > 64) { mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT); goto exit_free_struct; } StringUtils_createStringFromBufferInBuffer(variableListName, request->variableListName.choice.domainspecific.itemId.buf, request->variableListName.choice.domainspecific.itemId.size); if (MmsDomain_getNamedVariableList(domain, variableListName) != NULL) { mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_DEFINITION_OBJECT_EXISTS); } else { MmsError mmsError; MmsNamedVariableList namedVariableList = createNamedVariableList(domain, device, request, variableListName, &mmsError); if (namedVariableList != NULL) { mmsError = mmsServer_callVariableListChangedHandler(true, MMS_DOMAIN_SPECIFIC, domain, variableListName, connection); if (mmsError == MMS_ERROR_NONE) { MmsDomain_addNamedVariableList(domain, namedVariableList); createDefineNamedVariableListResponse(invokeId, response); } else { MmsNamedVariableList_destroy(namedVariableList); mmsServer_createConfirmedErrorPdu(invokeId, response, mmsError); } } else mmsServer_createConfirmedErrorPdu(invokeId, response, mmsError); } } else mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_RESOURCE_CAPABILITY_UNAVAILABLE); } else if (request->variableListName.present == ObjectName_PR_aaspecific) { if (LinkedList_size(connection->namedVariableLists) < CONFIG_MMS_MAX_NUMBER_OF_ASSOCIATION_SPECIFIC_DATA_SETS) { char variableListName[65]; if (request->variableListName.choice.aaspecific.size > 64) { mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT); goto exit_free_struct; } StringUtils_createStringFromBufferInBuffer(variableListName, request->variableListName.choice.aaspecific.buf, request->variableListName.choice.aaspecific.size); if (MmsServerConnection_getNamedVariableList(connection, variableListName) != NULL) { mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_DEFINITION_OBJECT_EXISTS); } else { MmsError mmsError; MmsNamedVariableList namedVariableList = createNamedVariableList(NULL, device, request, variableListName, &mmsError); if (namedVariableList != NULL) { if (mmsServer_callVariableListChangedHandler(true, MMS_ASSOCIATION_SPECIFIC, NULL, variableListName, connection) == MMS_ERROR_NONE) { MmsServerConnection_addNamedVariableList(connection, namedVariableList); createDefineNamedVariableListResponse(invokeId, response); } else { MmsNamedVariableList_destroy(namedVariableList); mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_ACCESS_DENIED); } } else mmsServer_createConfirmedErrorPdu(invokeId, response, mmsError); } } else mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_RESOURCE_CAPABILITY_UNAVAILABLE); } else mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_DEFINITION_TYPE_UNSUPPORTED); exit_free_struct: asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0); exit_function: return; }
void mmsServer_handleDeleteNamedVariableListRequest(MmsServerConnection connection, uint8_t* buffer, int bufPos, int maxBufPos, uint32_t invokeId, ByteBuffer* response) { DeleteNamedVariableListRequest_t* request = 0; MmsPdu_t* mmsPdu = 0; asn_dec_rval_t rval = ber_decode(NULL, &asn_DEF_MmsPdu, (void**) &mmsPdu, buffer, maxBufPos); if (rval.code != RC_OK) { mmsServer_writeMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_INVALID_PDU, response); goto exit_function; } request = &(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.deleteNamedVariableList); long scopeOfDelete; asn_INTEGER2long(request->scopeOfDelete, &scopeOfDelete); MmsDevice* device = MmsServer_getDevice(connection->server); if (scopeOfDelete == DeleteNamedVariableListRequest__scopeOfDelete_specific) { int numberMatched = 0; int numberDeleted = 0; int numberItems = request->listOfVariableListName->list.count; int i; for (i = 0; i < numberItems; i++) { if (request->listOfVariableListName->list.array[i]->present == ObjectName_PR_domainspecific) { char domainName[65]; char listName[65]; mmsMsg_copyAsn1IdentifierToStringBuffer(request->listOfVariableListName->list.array[i]->choice.domainspecific.domainId, domainName, 65); mmsMsg_copyAsn1IdentifierToStringBuffer(request->listOfVariableListName->list.array[i]->choice.domainspecific.itemId, listName, 65); MmsDomain* domain = MmsDevice_getDomain(device, domainName); if (domain != NULL) { MmsNamedVariableList variableList = MmsDomain_getNamedVariableList(domain, listName); if (variableList != NULL) { numberMatched++; if (MmsNamedVariableList_isDeletable(variableList)) { if (mmsServer_callVariableListChangedHandler(false, MMS_DOMAIN_SPECIFIC, domain, listName, connection) == MMS_ERROR_NONE) { MmsDomain_deleteNamedVariableList(domain, listName); numberDeleted++; } } } } } else if (request->listOfVariableListName->list.array[i]->present == ObjectName_PR_aaspecific) { char listName[65]; mmsMsg_copyAsn1IdentifierToStringBuffer(request->listOfVariableListName->list.array[i]->choice.aaspecific, listName, 65); MmsNamedVariableList variableList = MmsServerConnection_getNamedVariableList(connection, listName); if (variableList != NULL) { numberMatched++; if (mmsServer_callVariableListChangedHandler(false, MMS_ASSOCIATION_SPECIFIC, NULL, listName, connection) == MMS_ERROR_NONE) { numberDeleted++; MmsServerConnection_deleteNamedVariableList(connection, listName); } } } } createDeleteNamedVariableListResponse(invokeId, response, numberMatched, numberDeleted); } else { mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_ACCESS_UNSUPPORTED); } asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0); exit_function: return; }
static void handleReadNamedVariableListRequest( MmsServerConnection connection, ReadRequest_t* read, int invokeId, ByteBuffer* response) { if (read->variableAccessSpecification.choice.variableListName.present == ObjectName_PR_domainspecific) { char domainIdStr[65]; char nameIdStr[65]; mmsMsg_copyAsn1IdentifierToStringBuffer(read->variableAccessSpecification.choice.variableListName.choice.domainspecific.domainId, domainIdStr, 65); mmsMsg_copyAsn1IdentifierToStringBuffer(read->variableAccessSpecification.choice.variableListName.choice.domainspecific.itemId, nameIdStr, 65); VarAccessSpec accessSpec; accessSpec.isNamedVariableList = true; accessSpec.specific = 1; accessSpec.domainId = domainIdStr; accessSpec.itemId = nameIdStr; MmsDomain* domain = MmsDevice_getDomain(MmsServer_getDevice(connection->server), domainIdStr); if (domain == NULL) { if (DEBUG_MMS_SERVER) printf("MMS read: domain %s not found!\n", domainIdStr); mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT); } else { MmsNamedVariableList namedList = MmsDomain_getNamedVariableList(domain, nameIdStr); if (namedList != NULL) { createNamedVariableListResponse(connection, namedList, invokeId, response, read, &accessSpec); } else { if (DEBUG_MMS_SERVER) printf("MMS read: named variable list %s not found!\n", nameIdStr); mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT); } } } #if (MMS_DYNAMIC_DATA_SETS == 1) else if (read->variableAccessSpecification.choice.variableListName.present == ObjectName_PR_aaspecific) { char listName[65]; mmsMsg_copyAsn1IdentifierToStringBuffer(read->variableAccessSpecification.choice.variableListName.choice.aaspecific, listName, 65); MmsNamedVariableList namedList = MmsServerConnection_getNamedVariableList(connection, listName); VarAccessSpec accessSpec; accessSpec.isNamedVariableList = true; accessSpec.specific = 2; accessSpec.domainId = NULL; accessSpec.itemId = listName; if (namedList == NULL) mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT); else createNamedVariableListResponse(connection, namedList, invokeId, response, read, &accessSpec); } #endif /* (MMS_DYNAMIC_DATA_SETS == 1) */ else mmsServer_createConfirmedErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_ACCESS_UNSUPPORTED); }