- some code reformating

pull/143/head
Michael Zillgith 8 years ago
parent 60b7b673f4
commit 7b98f368dc

@ -45,7 +45,8 @@
#define ETH_P_GOOSE 0x88b8
struct sGooseReceiver {
struct sGooseReceiver
{
bool running;
bool stopped;
char* interfaceId;
@ -57,7 +58,6 @@ struct sGooseReceiver {
#endif
};
GooseReceiver
GooseReceiver_create()
{
@ -89,7 +89,6 @@ GooseReceiver_removeSubscriber(GooseReceiver self, GooseSubscriber subscriber)
LinkedList_remove(self->subscriberList, (void*) subscriber);
}
void
GooseReceiver_setInterfaceId(GooseReceiver self, const char* interfaceId)
{
@ -122,7 +121,8 @@ parseAllData(uint8_t* buffer, int allDataLength, MmsValue* dataSetValues)
uint8_t tag = buffer[bufPos++];
if (elementIndex > maxIndex) {
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Malformed message: too much elements!\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Malformed message: too much elements!\n");
return 0;
}
@ -130,41 +130,51 @@ parseAllData(uint8_t* buffer, int allDataLength, MmsValue* dataSetValues)
bufPos = BerDecoder_decodeLength(buffer, &elementLength, bufPos, allDataLength);
if (bufPos < 0) {
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Malformed message: failed to decode BER length tag!\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Malformed message: failed to decode BER length tag!\n");
return 0;
}
if (bufPos + elementLength > allDataLength) {
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Malformed message: sub element is too large!\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Malformed message: sub element is too large!\n");
return 0;
}
switch (tag) {
switch (tag)
{
case 0x80: /* reserved for access result */
printf("GOOSE_SUBSCRIBER: found reserved value (tag 0x80)!\n");
break;
case 0xa1: /* array */
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: found array\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: found array\n");
if (MmsValue_getType(value) == MMS_ARRAY) {
if (!parseAllData(buffer + bufPos, elementLength, value))
return -1;
}
break;
case 0xa2: /* structure */
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: found structure\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: found structure\n");
if (MmsValue_getType(value) == MMS_STRUCTURE) {
if (!parseAllData(buffer + bufPos, elementLength, value))
return -1;
}
break;
case 0x83: /* boolean */
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: found boolean\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: found boolean\n");
if (MmsValue_getType(value) == MMS_BOOLEAN) {
MmsValue_setBoolean(value, BerDecoder_decodeBoolean(buffer, bufPos));
}
else
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: message contains value of wrong type!\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: message contains value of wrong type!\n");
break;
@ -177,10 +187,11 @@ parseAllData(uint8_t* buffer, int allDataLength, MmsValue* dataSetValues)
elementLength - 1);
}
else
if (DEBUG_GOOSE_SUBSCRIBER)
printf("bit-string is of wrong size");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("bit-string is of wrong size");
}
break;
case 0x85: /* integer */
if (MmsValue_getType(value) == MMS_INTEGER) {
if (elementLength <= value->value.integer->maxSize) {
@ -189,6 +200,7 @@ parseAllData(uint8_t* buffer, int allDataLength, MmsValue* dataSetValues)
}
}
break;
case 0x86: /* unsigned integer */
if (MmsValue_getType(value) == MMS_UNSIGNED) {
if (elementLength <= value->value.integer->maxSize) {
@ -197,6 +209,7 @@ parseAllData(uint8_t* buffer, int allDataLength, MmsValue* dataSetValues)
}
}
break;
case 0x87: /* Float */
if (MmsValue_getType(value) == MMS_FLOAT) {
if (elementLength == 9) {
@ -216,6 +229,7 @@ parseAllData(uint8_t* buffer, int allDataLength, MmsValue* dataSetValues)
}
}
break;
case 0x8a: /* visible string */
if (MmsValue_getType(value) == MMS_VISIBLE_STRING) {
@ -235,6 +249,7 @@ parseAllData(uint8_t* buffer, int allDataLength, MmsValue* dataSetValues)
}
break;
case 0x8c: /* binary time */
if (MmsValue_getType(value) == MMS_BINARY_TIME) {
if ((elementLength == 4) || (elementLength == 6)) {
@ -242,17 +257,21 @@ parseAllData(uint8_t* buffer, int allDataLength, MmsValue* dataSetValues)
}
}
break;
case 0x91: /* Utctime */
if (elementLength == 8) {
if (MmsValue_getType(value) == MMS_UTC_TIME) {
MmsValue_setUtcTimeByBuffer(value, buffer + bufPos);
}
else
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: message contains value of wrong type!\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: message contains value of wrong type!\n");
}
else
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: UTCTime element is of wrong size!\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: UTCTime element is of wrong size!\n");
break;
default:
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: found unkown tag %02x\n", tag);
@ -282,16 +301,19 @@ parseAllDataUnknownValue(GooseSubscriber self, uint8_t* buffer, int allDataLengt
bufPos = BerDecoder_decodeLength(buffer, &elementLength, bufPos, allDataLength);
if (bufPos < 0) {
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Malformed message: failed to decode BER length tag!\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Malformed message: failed to decode BER length tag!\n");
return 0;
}
if (bufPos + elementLength > allDataLength) {
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Malformed message: sub element is too large!\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Malformed message: sub element is too large!\n");
goto exit_with_error;
}
switch (tag) {
switch (tag)
{
case 0x80: /* reserved for access result */
break;
case 0xa1: /* array */
@ -340,20 +362,24 @@ parseAllDataUnknownValue(GooseSubscriber self, uint8_t* buffer, int allDataLengt
bufPos = BerDecoder_decodeLength(buffer, &elementLength, bufPos, allDataLength);
if (bufPos < 0) {
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Malformed message: failed to decode BER length tag!\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Malformed message: failed to decode BER length tag!\n");
return 0;
}
if (bufPos + elementLength > allDataLength) {
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Malformed message: sub element is too large!\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Malformed message: sub element is too large!\n");
goto exit_with_error;
}
MmsValue* value = NULL;
switch (tag) {
switch (tag)
{
case 0xa1: /* array */
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: found array\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: found array\n");
value = parseAllDataUnknownValue(self, buffer + bufPos, elementLength, false);
@ -361,8 +387,10 @@ parseAllDataUnknownValue(GooseSubscriber self, uint8_t* buffer, int allDataLengt
goto exit_with_error;
break;
case 0xa2: /* structure */
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: found structure\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: found structure\n");
value = parseAllDataUnknownValue(self, buffer + bufPos, elementLength, true);
@ -370,8 +398,10 @@ parseAllDataUnknownValue(GooseSubscriber self, uint8_t* buffer, int allDataLengt
goto exit_with_error;
break;
case 0x83: /* boolean */
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: found boolean\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: found boolean\n");
value = MmsValue_newBoolean(BerDecoder_decodeBoolean(buffer, bufPos));
break;
@ -385,30 +415,35 @@ parseAllDataUnknownValue(GooseSubscriber self, uint8_t* buffer, int allDataLengt
}
break;
case 0x85: /* integer */
value = MmsValue_newInteger(elementLength * 8);
memcpy(value->value.integer->octets, buffer + bufPos, elementLength);
value->value.integer->size = elementLength;
break;
case 0x86: /* unsigned integer */
value = MmsValue_newUnsigned(elementLength * 8);
memcpy(value->value.integer->octets, buffer + bufPos, elementLength);
value->value.integer->size = elementLength;
break;
case 0x87: /* Float */
if (elementLength == 9)
value = MmsValue_newDouble(BerDecoder_decodeDouble(buffer, bufPos));
else if (elementLength == 5)
value = MmsValue_newFloat(BerDecoder_decodeFloat(buffer, bufPos));
if (elementLength == 9)
value = MmsValue_newDouble(BerDecoder_decodeDouble(buffer, bufPos));
else if (elementLength == 5)
value = MmsValue_newFloat(BerDecoder_decodeFloat(buffer, bufPos));
break;
case 0x89: /* octet string */
value = MmsValue_newOctetString(elementLength, elementLength);
memcpy(value->value.octetString.buf, buffer + bufPos, elementLength);
break;
case 0x8a: /* visible string */
value = MmsValue_newVisibleStringFromByteArray(buffer + bufPos, elementLength);
break;
case 0x8c: /* binary time */
if (elementLength == 4)
value = MmsValue_newBinaryTime(true);
@ -419,16 +454,20 @@ parseAllDataUnknownValue(GooseSubscriber self, uint8_t* buffer, int allDataLengt
memcpy(value->value.binaryTime.buf, buffer + bufPos, elementLength);
break;
case 0x91: /* Utctime */
if (elementLength == 8) {
value = MmsValue_newUtcTime(0);
MmsValue_setUtcTimeByBuffer(value, buffer + bufPos);
}
else
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: UTCTime element is of wrong size!\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: UTCTime element is of wrong size!\n");
break;
default:
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: found unkown tag %02x\n", tag);
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: found unkown tag %02x\n", tag);
goto exit_with_error;
}
@ -444,7 +483,7 @@ parseAllDataUnknownValue(GooseSubscriber self, uint8_t* buffer, int allDataLengt
return dataSetValues;
exit_with_error:
exit_with_error:
if (dataSetValues != NULL)
MmsValue_delete(dataSetValues);
@ -452,7 +491,6 @@ exit_with_error:
return NULL;
}
static int
parseGoosePayload(GooseReceiver self, uint8_t* buffer, int apduLength)
{
@ -474,7 +512,8 @@ parseGoosePayload(GooseReceiver self, uint8_t* buffer, int apduLength)
int gooseLength;
bufPos = BerDecoder_decodeLength(buffer, &gooseLength, bufPos, apduLength);
if (bufPos < 0) {
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Malformed message: failed to decode BER length tag!\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Malformed message: failed to decode BER length tag!\n");
return 0;
}
@ -486,7 +525,8 @@ parseGoosePayload(GooseReceiver self, uint8_t* buffer, int apduLength)
uint8_t tag = buffer[bufPos++];
bufPos = BerDecoder_decodeLength(buffer, &elementLength, bufPos, apduLength);
if (bufPos < 0) {
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Malformed message: failed to decode BER length tag!\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Malformed message: failed to decode BER length tag!\n");
return 0;
}
@ -500,9 +540,11 @@ parseGoosePayload(GooseReceiver self, uint8_t* buffer, int apduLength)
if (bufPos == -1)
goto exit_with_fault;
switch(tag) {
switch (tag)
{
case 0x80: /* gocbRef */
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Found gocbRef\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Found gocbRef\n");
{
LinkedList element = LinkedList_getNext(self->subscriberList);
@ -512,7 +554,8 @@ parseGoosePayload(GooseReceiver self, uint8_t* buffer, int apduLength)
if (subscriber->goCBRefLen == elementLength) {
if (memcmp(subscriber->goCBRef, buffer + bufPos, elementLength) == 0) {
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: gocbRef is matching!\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: gocbRef is matching!\n");
matchingSubscriber = subscriber;
break;
}
@ -531,61 +574,73 @@ parseGoosePayload(GooseReceiver self, uint8_t* buffer, int apduLength)
timeAllowedToLive = BerDecoder_decodeUint32(buffer, elementLength, bufPos);
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Found timeAllowedToLive %u\n", timeAllowedToLive);
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Found timeAllowedToLive %u\n", timeAllowedToLive);
break;
case 0x82:
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Found dataSet\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Found dataSet\n");
break;
case 0x83:
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Found goId\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Found goId\n");
break;
case 0x84:
timestampBufPos = buffer + bufPos;
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Found timestamp\n");
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Found timestamp\n");
break;
case 0x85:
stNum = BerDecoder_decodeUint32(buffer, elementLength, bufPos);
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Found stNum: %u\n", stNum);
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Found stNum: %u\n", stNum);
break;
case 0x86:
sqNum = BerDecoder_decodeUint32(buffer, elementLength, bufPos);
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Found sqNum: %u\n", sqNum);
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Found sqNum: %u\n", sqNum);
break;
case 0x87:
simulation = BerDecoder_decodeBoolean(buffer, bufPos);
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Found simulation: %i\n", simulation);
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Found simulation: %i\n", simulation);
break;
case 0x88:
confRev = BerDecoder_decodeUint32(buffer, elementLength, bufPos);
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Found confRev: %u\n", confRev);
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Found confRev: %u\n", confRev);
break;
case 0x89:
ndsCom = BerDecoder_decodeBoolean(buffer, bufPos);
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Found ndsCom: %i\n", ndsCom);
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Found ndsCom: %i\n", ndsCom);
break;
case 0x8a:
numberOfDatSetEntries = BerDecoder_decodeUint32(buffer, elementLength, bufPos);
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Found number of entries: %u\n", numberOfDatSetEntries);
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Found number of entries: %u\n", numberOfDatSetEntries);
break;
case 0xab:
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Found all data with length: %i\n", elementLength);
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Found all data with length: %i\n", elementLength);
dataSetBufferAddress = buffer + bufPos;
dataSetBufferLength = elementLength;
break;
default:
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Unknown tag %02x\n", tag);
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Unknown tag %02x\n", tag);
break;
}
@ -629,12 +684,12 @@ parseGoosePayload(GooseReceiver self, uint8_t* buffer, int apduLength)
return 0;
}
exit_with_fault:
if (DEBUG_GOOSE_SUBSCRIBER) printf("GOOSE_SUBSCRIBER: Invalid goose payload\n");
exit_with_fault:
if (DEBUG_GOOSE_SUBSCRIBER)
printf("GOOSE_SUBSCRIBER: Invalid goose payload\n");
return -1;
}
static void
parseGooseMessage(GooseReceiver self, int numbytes)
{
@ -642,7 +697,8 @@ parseGooseMessage(GooseReceiver self, int numbytes)
bool subscriberFound = false;
uint8_t* buffer = self->buffer;
if (numbytes < 22) return;
if (numbytes < 22)
return;
/* skip ethernet addresses */
bufPos = 12;
@ -688,7 +744,6 @@ parseGooseMessage(GooseReceiver self, int numbytes)
printf("GOOSE_SUBSCRIBER: APDU length: %i\n", apduLength);
}
// check if there is an interested subscriber
LinkedList element = LinkedList_getNext(self->subscriberList);
@ -711,7 +766,6 @@ parseGooseMessage(GooseReceiver self, int numbytes)
}
}
static void
gooseReceiverLoop(void* threadParameter)
{
@ -733,10 +787,9 @@ gooseReceiverLoop(void* threadParameter)
GooseReceiver_stopThreadless(self);
}
self->stopped = true;
self->stopped = true;
}
// start GOOSE receiver in a separate thread
void
GooseReceiver_start(GooseReceiver self)
@ -811,7 +864,7 @@ GooseReceiver_startThreadless(GooseReceiver self)
}
else
self->running = false;
return self->ethSocket;
}

@ -105,7 +105,7 @@ static void
resetLastApplError(ControlObjectClient self)
{
self->lastApplError.error = 0;
self->lastApplError.addCause = ADD_CAUSE_UNKNOWN;
self->lastApplError.addCause = ADD_CAUSE_UNKNOWN;
self->lastApplError.ctlNum = 0;
}
@ -118,11 +118,11 @@ ControlObjectClient_create(const char* objectReference, IedConnection connection
char reference[129];
if (strlen(objectReference) < 121) {
strcpy(reference, objectReference);
strcat(reference, ".ctlModel");
strcpy(reference, objectReference);
strcat(reference, ".ctlModel");
}
else
goto exit_function;
goto exit_function;
IedClientError error;
@ -136,7 +136,7 @@ ControlObjectClient_create(const char* objectReference, IedConnection connection
}
MmsVariableSpecification* ctlVarSpec =
IedConnection_getVariableSpecification(connection, &error, objectReference, IEC61850_FC_CO);
IedConnection_getVariableSpecification(connection, &error, objectReference, IEC61850_FC_CO);
if (error != IED_ERROR_OK) {
if (DEBUG_IED_CLIENT)
@ -154,10 +154,10 @@ ControlObjectClient_create(const char* objectReference, IedConnection connection
MmsVariableSpecification* t = NULL;
if (MmsVariableSpecification_getType(ctlVarSpec) == MMS_STRUCTURE) {
MmsVariableSpecification* oper = MmsVariableSpecification_getNamedVariableRecursive(ctlVarSpec, "Oper");
MmsVariableSpecification* oper = MmsVariableSpecification_getNamedVariableRecursive(ctlVarSpec, "Oper");
if (oper)
{
if (oper)
{
hasOper = true;
ctlVal = MmsVariableSpecification_getNamedVariableRecursive(oper, "ctlVal");
@ -165,18 +165,18 @@ ControlObjectClient_create(const char* objectReference, IedConnection connection
if (MmsVariableSpecification_getType(ctlVal) == MMS_STRUCTURE)
isAPC = true;
MmsVariableSpecification* operTm = MmsVariableSpecification_getNamedVariableRecursive(oper, "operTm");
MmsVariableSpecification* operTm = MmsVariableSpecification_getNamedVariableRecursive(oper, "operTm");
if (operTm)
hasTimeActivatedControl = true;
if (operTm)
hasTimeActivatedControl = true;
MmsVariableSpecification* ctlNum = MmsVariableSpecification_getNamedVariableRecursive(oper, "ctlNum");
MmsVariableSpecification* ctlNum = MmsVariableSpecification_getNamedVariableRecursive(oper, "ctlNum");
if (ctlNum)
hasCtlNum = true;
if (ctlNum)
hasCtlNum = true;
t = MmsVariableSpecification_getNamedVariableRecursive(oper, "T");
}
t = MmsVariableSpecification_getNamedVariableRecursive(oper, "T");
}
}
if (hasOper == false) {
@ -187,10 +187,10 @@ ControlObjectClient_create(const char* objectReference, IedConnection connection
}
if ((ctlVal == NULL) || (t == NULL)) {
if (DEBUG_IED_CLIENT)
printf("IED_CLIENT: \"Oper\" is missing required element\n");
if (DEBUG_IED_CLIENT)
printf("IED_CLIENT: \"Oper\" is missing required element\n");
goto free_varspec;
goto free_varspec;
}
self = (ControlObjectClient) GLOBAL_CALLOC(1, sizeof(struct sControlObjectClient));
@ -221,10 +221,10 @@ ControlObjectClient_create(const char* objectReference, IedConnection connection
private_IedConnection_addControlClient(connection, self);
free_varspec:
free_varspec:
MmsVariableSpecification_destroy(ctlVarSpec);
exit_function:
exit_function:
return self;
}
@ -241,7 +241,7 @@ ControlObjectClient_destroy(ControlObjectClient self)
MmsValue_delete(self->ctlVal);
if (self->analogValue != NULL)
MmsValue_delete(self->analogValue);
MmsValue_delete(self->analogValue);
if (self->orIdent != NULL)
GLOBAL_FREEMEM(self->orIdent);
@ -320,11 +320,11 @@ createOriginValue(ControlObjectClient self)
goto exit_function;
cleanup_on_error:
cleanup_on_error:
MmsValue_delete(origin);
origin = NULL;
exit_function:
exit_function:
return origin;
}
@ -347,20 +347,20 @@ ControlObjectClient_operate(ControlObjectClient self, MmsValue* ctlVal, uint64_t
int operElementCount = 5;
if (self->hasTimeActivatedMode)
operElementCount++;
operElementCount++;
if (self->hasCtlNum)
operElementCount++;
operElementCount++;
operParameters = MmsValue_createEmptyStructure(operElementCount);
operParameters = MmsValue_createEmptyStructure(operElementCount);
/* support simplified usage of APC controls - user doesn't need to create the structure */
if (self->analogValue != NULL) {
if (MmsValue_getType(ctlVal) != MMS_STRUCTURE) {
MmsValue_setElement(self->analogValue, 0, ctlVal);
ctlVal = self->analogValue;
}
}
/* support simplified usage of APC controls - user doesn't need to create the structure */
if (self->analogValue != NULL) {
if (MmsValue_getType(ctlVal) != MMS_STRUCTURE) {
MmsValue_setElement(self->analogValue, 0, ctlVal);
ctlVal = self->analogValue;
}
}
MmsValue_setElement(operParameters, 0, ctlVal);
@ -381,19 +381,19 @@ ControlObjectClient_operate(ControlObjectClient self, MmsValue* ctlVal, uint64_t
}
if (self->hasCtlNum) {
MmsValue* ctlNum = MmsValue_newUnsignedFromUint32(self->ctlNum);
MmsValue_setElement(operParameters, index++, ctlNum);
MmsValue* ctlNum = MmsValue_newUnsignedFromUint32(self->ctlNum);
MmsValue_setElement(operParameters, index++, ctlNum);
}
uint64_t timestamp;
if ((self->ctlModel == CONTROL_MODEL_SBO_ENHANCED) && (self->useConstantT))
timestamp = self->constantT;
timestamp = self->constantT;
else
timestamp = Hal_getTimeInMs();
timestamp = Hal_getTimeInMs();
if (self->useConstantT)
self->constantT = timestamp;
self->constantT = timestamp;
MmsValue* ctlTime;
@ -446,13 +446,13 @@ ControlObjectClient_operate(ControlObjectClient self, MmsValue* ctlVal, uint64_t
MmsValue_update(self->ctlVal, ctlVal);
if (self->analogValue)
MmsValue_setElement(self->analogValue, 0, NULL);
MmsValue_setElement(self->analogValue, 0, NULL);
self->opertime = operTime;
success = true;
exit_function:
exit_function:
return success;
}
@ -478,20 +478,20 @@ ControlObjectClient_selectWithValue(ControlObjectClient self, MmsValue* ctlVal)
int selValElementCount = 5;
if (self->hasTimeActivatedMode)
selValElementCount++;
selValElementCount++;
if (self->hasCtlNum)
selValElementCount++;
selValElementCount++;
MmsValue* selValParameters = MmsValue_createEmptyStructure(selValElementCount);
/* support simplified usage of APC controls - user doesn't need to create the structure */
if (self->analogValue != NULL) {
if (MmsValue_getType(ctlVal) != MMS_STRUCTURE) {
MmsValue_setElement(self->analogValue, 0, ctlVal);
ctlVal = self->analogValue;
}
}
/* support simplified usage of APC controls - user doesn't need to create the structure */
if (self->analogValue != NULL) {
if (MmsValue_getType(ctlVal) != MMS_STRUCTURE) {
MmsValue_setElement(self->analogValue, 0, ctlVal);
ctlVal = self->analogValue;
}
}
MmsValue_setElement(selValParameters, 0, ctlVal);
@ -508,15 +508,15 @@ ControlObjectClient_selectWithValue(ControlObjectClient self, MmsValue* ctlVal)
self->ctlNum++;
if (self->hasCtlNum) {
MmsValue* ctlNum = MmsValue_newUnsignedFromUint32(self->ctlNum);
MmsValue_setElement(selValParameters, index++, ctlNum);
MmsValue* ctlNum = MmsValue_newUnsignedFromUint32(self->ctlNum);
MmsValue_setElement(selValParameters, index++, ctlNum);
}
uint64_t timestamp = Hal_getTimeInMs();
MmsValue* ctlTime;
if (self->useConstantT)
self->constantT = timestamp;
self->constantT = timestamp;
if (self->edition == 2)
ctlTime = MmsValue_newUtcTimeByMsTime(timestamp);
@ -550,7 +550,7 @@ ControlObjectClient_selectWithValue(ControlObjectClient self, MmsValue* ctlVal)
MmsValue_update(self->ctlVal, ctlVal);
if (self->analogValue)
MmsValue_setElement(self->analogValue, 0, NULL);
MmsValue_setElement(self->analogValue, 0, NULL);
return true;
}
@ -592,7 +592,7 @@ ControlObjectClient_select(ControlObjectClient self)
snprintf(sboReference, 129, "%s/%s", domainId, itemId);
if (MmsValue_getType(value) == MMS_VISIBLE_STRING) {
if (strcmp(MmsValue_toString(value), "") == 0) {
if (strcmp(MmsValue_toString(value), "") == 0) {
if (DEBUG_IED_CLIENT)
printf("select-response-\n");
}
@ -613,7 +613,7 @@ ControlObjectClient_select(ControlObjectClient self)
MmsValue_delete(value);
exit_function:
exit_function:
return selected;
}
@ -648,9 +648,9 @@ ControlObjectClient_cancel(ControlObjectClient self)
uint64_t timestamp;
if (self->useConstantT)
timestamp = self->constantT;
timestamp = self->constantT;
else
timestamp = Hal_getTimeInMs();
timestamp = Hal_getTimeInMs();
MmsValue* ctlTime;
@ -697,7 +697,7 @@ ControlObjectClient_cancel(ControlObjectClient self)
void
ControlObjectClient_useConstantT(ControlObjectClient self, bool useConstantT)
{
self->useConstantT = useConstantT;
self->useConstantT = useConstantT;
}
void
@ -712,7 +712,6 @@ ControlObjectClient_setInterlockCheck(ControlObjectClient self, bool value)
self->interlockCheck = value;
}
void
ControlObjectClient_enableSynchroCheck(ControlObjectClient self)
{

@ -43,7 +43,7 @@ checkAuthMechanismName(uint8_t* authMechanism, int authMechLen)
{
AcseAuthenticationMechanism authenticationMechanism = ACSE_AUTH_NONE;
if (authMechanism != NULL ) {
if (authMechanism != NULL) {
if (authMechLen == 3) {
if (memcmp(auth_mech_password_oid, authMechanism, 3) == 0) {
@ -81,7 +81,7 @@ checkAuthentication(AcseConnection* self, uint8_t* authMechanism, int authMechLe
{
self->securityToken = NULL;
if (self->authenticator != NULL ) {
if (self->authenticator != NULL) {
AcseAuthenticationMechanism mechanism = checkAuthMechanismName(authMechanism, authMechLen);
@ -111,134 +111,139 @@ checkAuthentication(AcseConnection* self, uint8_t* authMechanism, int authMechLe
return true;
}
static int
parseUserInformation(AcseConnection* self, uint8_t* buffer, int bufPos, int maxBufPos, bool* userInfoValid)
{
if (DEBUG_ACSE) printf("ACSE: parseUserInformation %i %i\n", bufPos, maxBufPos);
bool hasindirectReference = false;
bool isDataValid = false;
if (DEBUG_ACSE)
printf("ACSE: parseUserInformation %i %i\n", bufPos, maxBufPos);
while (bufPos < maxBufPos) {
uint8_t tag = buffer[bufPos++];
int len;
bool hasindirectReference = false;
bool isDataValid = false;
bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
while (bufPos < maxBufPos) {
uint8_t tag = buffer[bufPos++];
int len;
if (bufPos < 0) {
*userInfoValid = false;
return -1;
}
bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
switch (tag) {
if (bufPos < 0) {
*userInfoValid = false;
return -1;
}
case 0x02: /* indirect-reference */
self->nextReference = BerDecoder_decodeUint32(buffer, len, bufPos);
bufPos += len;
hasindirectReference = true;
break;
switch (tag)
{
case 0xa0: /* encoding */
isDataValid = true;
case 0x02: /* indirect-reference */
self->nextReference = BerDecoder_decodeUint32(buffer, len, bufPos);
bufPos += len;
hasindirectReference = true;
break;
self->userDataBufferSize = len;
self->userDataBuffer = buffer + bufPos;
case 0xa0: /* encoding */
isDataValid = true;
bufPos += len;
self->userDataBufferSize = len;
self->userDataBuffer = buffer + bufPos;
break;
bufPos += len;
default: /* ignore unknown tag */
bufPos += len;
}
}
break;
default: /* ignore unknown tag */
bufPos += len;
}
}
if (DEBUG_ACSE) {
if (!hasindirectReference) printf("ACSE: User data has no indirect reference!\n");
if (DEBUG_ACSE) {
if (!hasindirectReference)
printf("ACSE: User data has no indirect reference!\n");
if (!isDataValid) printf("ACSE: No valid user data\n");
}
if (!isDataValid)
printf("ACSE: No valid user data\n");
}
if (hasindirectReference && isDataValid)
*userInfoValid = true;
else
*userInfoValid = false;
if (hasindirectReference && isDataValid)
*userInfoValid = true;
else
*userInfoValid = false;
return bufPos;
return bufPos;
}
static AcseIndication
parseAarePdu(AcseConnection* self, uint8_t* buffer, int bufPos, int maxBufPos)
{
if (DEBUG_ACSE) printf("ACSE: parse AARE PDU\n");
if (DEBUG_ACSE)
printf("ACSE: parse AARE PDU\n");
bool userInfoValid = false;
bool userInfoValid = false;
uint32_t result = 99;
uint32_t result = 99;
while (bufPos < maxBufPos) {
uint8_t tag = buffer[bufPos++];
int len;
while (bufPos < maxBufPos) {
uint8_t tag = buffer[bufPos++];
int len;
bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
if (bufPos < 0)
return ACSE_ERROR;
bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
if (bufPos < 0)
return ACSE_ERROR;
switch (tag) {
case 0xa1: /* application context name */
bufPos += len;
break;
switch (tag)
{
case 0xa1: /* application context name */
bufPos += len;
break;
case 0xa2: /* result */
bufPos++;
case 0xa2: /* result */
bufPos++;
bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
if (bufPos < 0)
return ACSE_ERROR;
bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
if (bufPos < 0)
return ACSE_ERROR;
result = BerDecoder_decodeUint32(buffer, len, bufPos);
result = BerDecoder_decodeUint32(buffer, len, bufPos);
bufPos += len;
break;
bufPos += len;
break;
case 0xa3: /* result source diagnostic */
bufPos += len;
break;
case 0xa3: /* result source diagnostic */
bufPos += len;
break;
case 0xbe: /* user information */
if (buffer[bufPos] != 0x28) {
if (DEBUG_ACSE) printf("ACSE: invalid user info\n");
bufPos += len;
}
else {
bufPos++;
case 0xbe: /* user information */
if (buffer[bufPos] != 0x28) {
if (DEBUG_ACSE)
printf("ACSE: invalid user info\n");
bufPos += len;
}
else {
bufPos++;
bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
if (bufPos < 0)
return ACSE_ERROR;
bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
if (bufPos < 0)
return ACSE_ERROR;
bufPos = parseUserInformation(self, buffer, bufPos, bufPos + len, &userInfoValid);
if (bufPos < 0)
return ACSE_ERROR;
}
break;
bufPos = parseUserInformation(self, buffer, bufPos, bufPos + len, &userInfoValid);
if (bufPos < 0)
return ACSE_ERROR;
}
break;
default: /* ignore unknown tag */
if (DEBUG_ACSE)
printf("ACSE: parseAarePdu: unknown tag %02x\n", tag);
default: /* ignore unknown tag */
if (DEBUG_ACSE)
printf("ACSE: parseAarePdu: unknown tag %02x\n", tag);
bufPos += len;
break;
}
}
bufPos += len;
break;
}
}
if (!userInfoValid)
return ACSE_ERROR;
if (!userInfoValid)
return ACSE_ERROR;
if (result != 0)
return ACSE_ASSOCIATE_FAILED;
if (result != 0)
return ACSE_ASSOCIATE_FAILED;
return ACSE_ASSOCIATE;
}
@ -246,119 +251,126 @@ parseAarePdu(AcseConnection* self, uint8_t* buffer, int bufPos, int maxBufPos)
static AcseIndication
parseAarqPdu(AcseConnection* self, uint8_t* buffer, int bufPos, int maxBufPos)
{
if (DEBUG_ACSE) printf("ACSE: parse AARQ PDU\n");
if (DEBUG_ACSE)
printf("ACSE: parse AARQ PDU\n");
uint8_t* authValue = NULL;
int authValueLen = 0;
uint8_t* authMechanism = NULL;
int authMechLen = 0;
bool userInfoValid = false;
uint8_t* authValue = NULL;
int authValueLen = 0;
uint8_t* authMechanism = NULL;
int authMechLen = 0;
bool userInfoValid = false;
while (bufPos < maxBufPos) {
uint8_t tag = buffer[bufPos++];
int len;
while (bufPos < maxBufPos) {
uint8_t tag = buffer[bufPos++];
int len;
bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
if (bufPos < 0) {
if (DEBUG_ACSE) printf("ACSE: Invalid PDU!\n");
return ACSE_ASSOCIATE_FAILED;
}
if (bufPos < 0) {
if (DEBUG_ACSE)
printf("ACSE: Invalid PDU!\n");
return ACSE_ASSOCIATE_FAILED;
}
switch (tag) {
case 0xa1: /* application context name */
bufPos += len;
break;
switch (tag)
{
case 0xa1: /* application context name */
bufPos += len;
break;
case 0xa2: /* called AP title */
bufPos += len;
break;
case 0xa3: /* called AE qualifier */
bufPos += len;
break;
case 0xa2: /* called AP title */
bufPos += len;
break;
case 0xa3: /* called AE qualifier */
bufPos += len;
break;
case 0xa6: /* calling AP title */
{
if (buffer[bufPos] == 0x06) { /* ap-title-form2 */
case 0xa6: /* calling AP title */
{
if (buffer[bufPos] == 0x06) { /* ap-title-form2 */
int innerLength = buffer[bufPos+1];
int innerLength = buffer[bufPos + 1];
if (innerLength == len - 2)
BerDecoder_decodeOID(buffer, bufPos + 2, innerLength, &(self->applicationReference.apTitle));
}
}
bufPos += len;
break;
if (innerLength == len - 2)
BerDecoder_decodeOID(buffer, bufPos + 2, innerLength, &(self->applicationReference.apTitle));
}
}
bufPos += len;
break;
case 0xa7: /* calling AE qualifier */
{
if (buffer[bufPos] == 0x02) { /* ae-qualifier-form2 */
case 0xa7: /* calling AE qualifier */
{
if (buffer[bufPos] == 0x02) { /* ae-qualifier-form2 */
int innerLength = buffer[bufPos+1];
int innerLength = buffer[bufPos + 1];
if (innerLength == len - 2)
self->applicationReference.aeQualifier = BerDecoder_decodeInt32(buffer + 2, buffer[bufPos+1], bufPos);
}
}
bufPos += len;
break;
self->applicationReference.aeQualifier = BerDecoder_decodeInt32(buffer + 2, buffer[bufPos + 1], bufPos);
}
}
bufPos += len;
break;
case 0x8a: /* sender ACSE requirements */
bufPos += len;
break;
case 0x8b: /* (authentication) mechanism name */
authMechLen = len;
authMechanism = buffer + bufPos;
bufPos += len;
break;
case 0xac: /* authentication value */
bufPos++;
bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
if (bufPos < 0) {
if (DEBUG_ACSE)
printf("ACSE: Invalid PDU!\n");
return ACSE_ASSOCIATE_FAILED;
}
authValueLen = len;
authValue = buffer + bufPos;
bufPos += len;
break;
case 0xbe: /* user information */
if (buffer[bufPos] != 0x28) {
if (DEBUG_ACSE)
printf("ACSE: invalid user info\n");
bufPos += len;
}
else {
bufPos++;
bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
if (bufPos < 0) {
if (DEBUG_ACSE)
printf("ACSE: Invalid PDU!\n");
return ACSE_ASSOCIATE_FAILED;
}
bufPos = parseUserInformation(self, buffer, bufPos, bufPos + len, &userInfoValid);
if (bufPos < 0) {
if (DEBUG_ACSE)
printf("ACSE: Invalid PDU!\n");
return ACSE_ASSOCIATE_FAILED;
}
}
break;
default: /* ignore unknown tag */
if (DEBUG_ACSE)
printf("ACSE: parseAarqPdu: unknown tag %02x\n", tag);
case 0x8a: /* sender ACSE requirements */
bufPos += len;
break;
case 0x8b: /* (authentication) mechanism name */
authMechLen = len;
authMechanism = buffer + bufPos;
bufPos += len;
break;
case 0xac: /* authentication value */
bufPos++;
bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
if (bufPos < 0) {
if (DEBUG_ACSE) printf("ACSE: Invalid PDU!\n");
return ACSE_ASSOCIATE_FAILED;
}
authValueLen = len;
authValue = buffer + bufPos;
bufPos += len;
break;
case 0xbe: /* user information */
if (buffer[bufPos] != 0x28) {
if (DEBUG_ACSE) printf("ACSE: invalid user info\n");
bufPos += len;
}
else {
bufPos++;
bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, maxBufPos);
if (bufPos < 0) {
if (DEBUG_ACSE) printf("ACSE: Invalid PDU!\n");
return ACSE_ASSOCIATE_FAILED;
}
bufPos = parseUserInformation(self, buffer, bufPos, bufPos + len, &userInfoValid);
if (bufPos < 0) {
if (DEBUG_ACSE) printf("ACSE: Invalid PDU!\n");
return ACSE_ASSOCIATE_FAILED;
}
}
break;
default: /* ignore unknown tag */
if (DEBUG_ACSE)
printf("ACSE: parseAarqPdu: unknown tag %02x\n", tag);
bufPos += len;
break;
}
}
break;
}
}
if (checkAuthentication(self, authMechanism, authMechLen, authValue, authValueLen) == false) {
if (DEBUG_ACSE)
@ -371,7 +383,7 @@ parseAarqPdu(AcseConnection* self, uint8_t* buffer, int bufPos, int maxBufPos)
if (DEBUG_ACSE)
printf("ACSE: parseAarqPdu: user info invalid!\n");
return ACSE_ASSOCIATE_FAILED;
return ACSE_ASSOCIATE_FAILED;
}
return ACSE_ASSOCIATE;
@ -391,7 +403,8 @@ AcseConnection_init(AcseConnection* self, AcseAuthenticator authenticator, void*
self->tlsSocket = tlsSocket;
#endif
memset(&(self->applicationReference), 0, sizeof(self->applicationReference));
memset(&(self->applicationReference), 0,
sizeof(self->applicationReference));
}
void
@ -416,20 +429,22 @@ AcseConnection_parseMessage(AcseConnection* self, ByteBuffer* message)
bufPos = BerDecoder_decodeLength(buffer, &len, bufPos, messageSize);
if (bufPos < 0) {
if (bufPos < 0)
{
if (DEBUG_ACSE)
printf("ACSE: AcseConnection_parseMessage: invalid ACSE message!\n");
return ACSE_ERROR;
}
switch (messageType) {
switch (messageType)
{
case 0x60:
indication = parseAarqPdu(self, buffer, bufPos, messageSize);
break;
indication = parseAarqPdu(self, buffer, bufPos, messageSize);
break;
case 0x61:
indication = parseAarePdu(self, buffer, bufPos, messageSize);
break;
indication = parseAarePdu(self, buffer, bufPos, messageSize);
break;
case 0x62: /* A_RELEASE.request RLRQ-apdu */
indication = ACSE_RELEASE_REQUEST;
break;
@ -440,9 +455,10 @@ AcseConnection_parseMessage(AcseConnection* self, ByteBuffer* message)
indication = ACSE_ABORT;
break;
default:
if (DEBUG_ACSE) printf("ACSE: Unknown ACSE message\n");
indication = ACSE_ERROR;
break;
if (DEBUG_ACSE)
printf("ACSE: Unknown ACSE message\n");
indication = ACSE_ERROR;
break;
}
return indication;
@ -451,7 +467,7 @@ AcseConnection_parseMessage(AcseConnection* self, ByteBuffer* message)
void
AcseConnection_createAssociateFailedMessage(AcseConnection* self, BufferChain writeBuffer)
{
AcseConnection_createAssociateResponseMessage(self, ACSE_RESULT_REJECT_PERMANENT, writeBuffer, NULL);
AcseConnection_createAssociateResponseMessage(self, ACSE_RESULT_REJECT_PERMANENT, writeBuffer, NULL);
}
void
@ -469,7 +485,8 @@ AcseConnection_createAssociateResponseMessage(AcseConnection* self,
int resultLength = 5;
int resultDiagnosticLength = 5;
int fixedContentLength = appContextLength + resultLength + resultDiagnosticLength;
int fixedContentLength = appContextLength + resultLength
+ resultDiagnosticLength;
int variableContentLength = 0;
@ -554,156 +571,181 @@ AcseConnection_createAssociateRequestMessage(AcseConnection* self,
assert(writeBuffer != NULL);
assert(payload != NULL);
int payloadLength = payload->length;
int authValueLength;
int authValueStringLength = 0;
int passwordLength = 0;
int payloadLength = payload->length;
int authValueLength;
int authValueStringLength = 0;
int contentLength = 0;
int passwordLength = 0;
/* application context name */
contentLength += 9;
int contentLength = 0;
int calledAEQualifierLength = 0;
/* application context name */
contentLength += 9;
if (isoParameters->remoteApTitleLen > 0) {
int calledAEQualifierLength = 0;
if (isoParameters->remoteApTitleLen > 0)
{
/* called AP title */
contentLength += (4 + isoParameters->remoteApTitleLen);
calledAEQualifierLength = BerEncoder_UInt32determineEncodedSize(isoParameters->remoteAEQualifier);
calledAEQualifierLength = BerEncoder_UInt32determineEncodedSize(
isoParameters->remoteAEQualifier);
/* called AE qualifier */
contentLength += (4 + calledAEQualifierLength);
}
}
int callingAEQualifierLength = 0;
int callingAEQualifierLength = 0;
if (isoParameters->localApTitleLen > 0) {
if (isoParameters->localApTitleLen > 0)
{
/* calling AP title */
contentLength += (4 + isoParameters->localApTitleLen);
callingAEQualifierLength = BerEncoder_UInt32determineEncodedSize(isoParameters->localAEQualifier);
callingAEQualifierLength = BerEncoder_UInt32determineEncodedSize(
isoParameters->localAEQualifier);
/* calling AE qualifier */
contentLength += (4 + callingAEQualifierLength);
}
if (authParameter != NULL) {
/* sender ACSE requirements */
contentLength += 4;
}
/* mechanism name */
contentLength += 5;
if (authParameter != NULL)
{
/* sender ACSE requirements */
contentLength += 4;
/* authentication value */
if (authParameter->mechanism == ACSE_AUTH_PASSWORD) {
contentLength += 2;
/* mechanism name */
contentLength += 5;
//if (authParameter->value.password.passwordLength == 0)
/* authentication value */
if (authParameter->mechanism == ACSE_AUTH_PASSWORD)
{
contentLength += 2;
passwordLength = authParameter->value.password.passwordLength;
//if (authParameter->value.password.passwordLength == 0)
authValueStringLength = BerEncoder_determineLengthSize(passwordLength);
passwordLength = authParameter->value.password.passwordLength;
contentLength += passwordLength + authValueStringLength;
authValueStringLength = BerEncoder_determineLengthSize(
passwordLength);
authValueLength = BerEncoder_determineLengthSize(passwordLength + authValueStringLength + 1);
contentLength += passwordLength + authValueStringLength;
contentLength += authValueLength;
}
else {
contentLength += 2;
}
}
authValueLength = BerEncoder_determineLengthSize(
passwordLength + authValueStringLength + 1);
/* user information */
int userInfoLength = 0;
contentLength += authValueLength;
}
else
{
contentLength += 2;
}
}
/* single ASN1 type tag */
userInfoLength += payloadLength;
userInfoLength += 1;
userInfoLength += BerEncoder_determineLengthSize(payloadLength);
/* user information */
int userInfoLength = 0;
/* indirect reference */
userInfoLength += 1;
userInfoLength += 2;
/* single ASN1 type tag */
userInfoLength += payloadLength;
userInfoLength += 1;
userInfoLength += BerEncoder_determineLengthSize(payloadLength);
/* association data */
int assocDataLength = userInfoLength;
userInfoLength += BerEncoder_determineLengthSize(assocDataLength);
userInfoLength += 1;
/* indirect reference */
userInfoLength += 1;
userInfoLength += 2;
/* user information */
int userInfoLen = userInfoLength;
userInfoLength += BerEncoder_determineLengthSize(userInfoLength);
userInfoLength += 1;
/* association data */
int assocDataLength = userInfoLength;
userInfoLength += BerEncoder_determineLengthSize(assocDataLength);
userInfoLength += 1;
contentLength += userInfoLength;
/* user information */
int userInfoLen = userInfoLength;
userInfoLength += BerEncoder_determineLengthSize(userInfoLength);
userInfoLength += 1;
uint8_t* buffer = writeBuffer->buffer;
int bufPos = 0;
contentLength += userInfoLength;
bufPos = BerEncoder_encodeTL(0x60, contentLength, buffer, bufPos);
uint8_t* buffer = writeBuffer->buffer;
int bufPos = 0;
/* application context name */
bufPos = BerEncoder_encodeTL(0xa1, 7, buffer, bufPos);
bufPos = BerEncoder_encodeTL(0x06, 5, buffer, bufPos);
memcpy(buffer + bufPos, appContextNameMms, 5);
bufPos += 5;
bufPos = BerEncoder_encodeTL(0x60, contentLength, buffer, bufPos);
if (isoParameters->remoteApTitleLen > 0) {
/* application context name */
bufPos = BerEncoder_encodeTL(0xa1, 7, buffer, bufPos);
bufPos = BerEncoder_encodeTL(0x06, 5, buffer, bufPos);
memcpy(buffer + bufPos, appContextNameMms, 5);
bufPos += 5;
/* called AP title */
bufPos = BerEncoder_encodeTL(0xa2, isoParameters->remoteApTitleLen + 2, buffer, bufPos);
bufPos = BerEncoder_encodeTL(0x06, isoParameters->remoteApTitleLen, buffer, bufPos);
if (isoParameters->remoteApTitleLen > 0)
{
/* called AP title */
bufPos = BerEncoder_encodeTL(0xa2, isoParameters->remoteApTitleLen + 2,
buffer, bufPos);
bufPos = BerEncoder_encodeTL(0x06, isoParameters->remoteApTitleLen,
buffer, bufPos);
memcpy(buffer + bufPos, isoParameters->remoteApTitle, isoParameters->remoteApTitleLen);
bufPos += isoParameters->remoteApTitleLen;
memcpy(buffer + bufPos, isoParameters->remoteApTitle,
isoParameters->remoteApTitleLen);
bufPos += isoParameters->remoteApTitleLen;
/* called AE qualifier */
bufPos = BerEncoder_encodeTL(0xa3, calledAEQualifierLength + 2, buffer, bufPos);
bufPos = BerEncoder_encodeTL(0x02, calledAEQualifierLength, buffer, bufPos);
bufPos = BerEncoder_encodeUInt32(isoParameters->remoteAEQualifier, buffer, bufPos);
}
bufPos = BerEncoder_encodeTL(0xa3, calledAEQualifierLength + 2, buffer,
bufPos);
bufPos = BerEncoder_encodeTL(0x02, calledAEQualifierLength, buffer,
bufPos);
bufPos = BerEncoder_encodeUInt32(isoParameters->remoteAEQualifier,
buffer, bufPos);
}
if (isoParameters->localApTitleLen > 0) {
if (isoParameters->localApTitleLen > 0)
{
/* calling AP title */
bufPos = BerEncoder_encodeTL(0xa6, isoParameters->localApTitleLen + 2, buffer, bufPos);
bufPos = BerEncoder_encodeTL(0x06, isoParameters->localApTitleLen, buffer, bufPos);
memcpy(buffer + bufPos, isoParameters->localApTitle, isoParameters->localApTitleLen);
bufPos = BerEncoder_encodeTL(0xa6, isoParameters->localApTitleLen + 2,
buffer, bufPos);
bufPos = BerEncoder_encodeTL(0x06, isoParameters->localApTitleLen,
buffer, bufPos);
memcpy(buffer + bufPos, isoParameters->localApTitle,
isoParameters->localApTitleLen);
bufPos += isoParameters->localApTitleLen;
/* calling AE qualifier */
bufPos = BerEncoder_encodeTL(0xa7, callingAEQualifierLength + 2, buffer, bufPos);
bufPos = BerEncoder_encodeTL(0x02, callingAEQualifierLength, buffer, bufPos);
bufPos = BerEncoder_encodeUInt32(isoParameters->localAEQualifier, buffer, bufPos);
}
if (authParameter != NULL) {
/* sender requirements */
bufPos = BerEncoder_encodeTL(0x8a, 2, buffer, bufPos);
buffer[bufPos++] = 0x04;
if (authParameter->mechanism == ACSE_AUTH_PASSWORD) {
buffer[bufPos++] = requirements_authentication[0];
bufPos = BerEncoder_encodeTL(0x8b, 3, buffer, bufPos);
memcpy(buffer + bufPos, auth_mech_password_oid, 3);
bufPos += 3;
/* authentication value */
bufPos = BerEncoder_encodeTL(0xac, authValueStringLength + passwordLength + 1, buffer, bufPos);
bufPos = BerEncoder_encodeTL(0x80, passwordLength, buffer, bufPos);
memcpy(buffer + bufPos, authParameter->value.password.octetString, passwordLength);
bufPos += passwordLength;
}
else { /* AUTH_NONE */
buffer[bufPos++] = 0;
}
}
bufPos = BerEncoder_encodeTL(0xa7, callingAEQualifierLength + 2, buffer,
bufPos);
bufPos = BerEncoder_encodeTL(0x02, callingAEQualifierLength, buffer,
bufPos);
bufPos = BerEncoder_encodeUInt32(isoParameters->localAEQualifier,
buffer, bufPos);
}
if (authParameter != NULL)
{
/* sender requirements */
bufPos = BerEncoder_encodeTL(0x8a, 2, buffer, bufPos);
buffer[bufPos++] = 0x04;
if (authParameter->mechanism == ACSE_AUTH_PASSWORD)
{
buffer[bufPos++] = requirements_authentication[0];
bufPos = BerEncoder_encodeTL(0x8b, 3, buffer, bufPos);
memcpy(buffer + bufPos, auth_mech_password_oid, 3);
bufPos += 3;
/* authentication value */
bufPos = BerEncoder_encodeTL(0xac,
authValueStringLength + passwordLength + 1, buffer, bufPos);
bufPos = BerEncoder_encodeTL(0x80, passwordLength, buffer, bufPos);
memcpy(buffer + bufPos, authParameter->value.password.octetString,
passwordLength);
bufPos += passwordLength;
}
else
{ /* AUTH_NONE */
buffer[bufPos++] = 0;
}
}
/* user information */
bufPos = BerEncoder_encodeTL(0xbe, userInfoLen, buffer, bufPos);
@ -718,9 +760,9 @@ AcseConnection_createAssociateRequestMessage(AcseConnection* self,
/* single ASN1 type */
bufPos = BerEncoder_encodeTL(0xa0, payloadLength, buffer, bufPos);
writeBuffer->partLength = bufPos;
writeBuffer->length = bufPos + payload->length;
writeBuffer->nextPart = payload;
writeBuffer->partLength = bufPos;
writeBuffer->length = bufPos + payload->length;
writeBuffer->nextPart = payload;
}
/**

@ -110,7 +110,7 @@ handleUnconfirmedMmsPdu(MmsConnection self, ByteBuffer* message)
if (DEBUG_MMS_CLIENT)
printf("MMS_CLIENT: report handler rcvd size:%i\n", ByteBuffer_getSize(message));
asn_dec_rval_t rval = ber_decode(NULL, &asn_DEF_MmsPdu,
asn_dec_rval_t rval = ber_decode(NULL, &asn_DEF_MmsPdu,
(void**) &mmsPdu, ByteBuffer_getBuffer(message), ByteBuffer_getSize(message));
if (rval.code == RC_OK) {
@ -121,7 +121,7 @@ handleUnconfirmedMmsPdu(MmsConnection self, ByteBuffer* message)
if (mmsPdu->choice.unconfirmedPDU.unconfirmedService.present ==
UnconfirmedService_PR_informationReport)
{
{
char* domainId = NULL;
InformationReport_t* report =
@ -155,7 +155,7 @@ handleUnconfirmedMmsPdu(MmsConnection self, ByteBuffer* message)
}
else if (report->variableAccessSpecification.present == VariableAccessSpecification_PR_listOfVariable)
{
{
int listSize = report->listOfAccessResult.list.count;
int variableSpecSize = report->variableAccessSpecification.choice.listOfVariable.list.count;
@ -172,10 +172,10 @@ handleUnconfirmedMmsPdu(MmsConnection self, ByteBuffer* message)
for (i = 0; i < variableSpecSize; i++) {
if (report->variableAccessSpecification.choice.listOfVariable.list.array[i]->variableSpecification.present
== VariableSpecification_PR_name)
{
{
if (report->variableAccessSpecification.choice.listOfVariable.list.array[i]
->variableSpecification.choice.name.present == ObjectName_PR_vmdspecific)
{
{
int nameSize =
report->variableAccessSpecification.choice.listOfVariable.list.array[i]
->variableSpecification.choice.name.choice.vmdspecific.size;
@ -208,24 +208,24 @@ handleUnconfirmedMmsPdu(MmsConnection self, ByteBuffer* message)
->variableSpecification.choice.name.present == ObjectName_PR_domainspecific) {
int domainNameSize =
report->variableAccessSpecification.choice.listOfVariable.list.array[i]
->variableSpecification.choice.name.choice.domainspecific.domainId.size;
report->variableAccessSpecification.choice.listOfVariable.list.array[i]
->variableSpecification.choice.name.choice.domainspecific.domainId.size;
int itemNameSize =
report->variableAccessSpecification.choice.listOfVariable.list.array[i]
->variableSpecification.choice.name.choice.domainspecific.itemId.size;
report->variableAccessSpecification.choice.listOfVariable.list.array[i]
->variableSpecification.choice.name.choice.domainspecific.itemId.size;
if (domainNameSize < 65 && itemNameSize < 65) {
char domainNameStr[65];
char itemNameStr[65];
uint8_t* domainNameBuffer =
report->variableAccessSpecification.choice.listOfVariable.list.array[i]
->variableSpecification.choice.name.choice.domainspecific.domainId.buf;
report->variableAccessSpecification.choice.listOfVariable.list.array[i]
->variableSpecification.choice.name.choice.domainspecific.domainId.buf;
uint8_t* itemNamebuffer =
report->variableAccessSpecification.choice.listOfVariable.list.array[i]
->variableSpecification.choice.name.choice.domainspecific.itemId.buf;
->variableSpecification.choice.name.choice.domainspecific.itemId.buf;
memcpy(domainNameStr, domainNameBuffer, domainNameSize);
domainNameStr[domainNameSize] = 0;
@ -235,7 +235,7 @@ handleUnconfirmedMmsPdu(MmsConnection self, ByteBuffer* message)
MmsValue* value = values;
if (variableSpecSize != 1)
value = MmsValue_getElement(values, i);
value = MmsValue_getElement(values, i);
self->reportHandler(self->reportHandlerParameter, domainNameStr, itemNameStr,
value, false);
@ -410,7 +410,7 @@ sendRequestAndWaitForResponse(MmsConnection self, uint32_t invokeId, ByteBuffer*
receivedMessage = NULL;
}
connection_lost:
connection_lost:
removeFromOutstandingCalls(self, invokeId);
@ -455,7 +455,7 @@ static MmsError
convertRejectCodesToMmsError(int rejectType, int rejectReason)
{
if ((rejectType == 1) && (rejectReason == 1))
return MMS_ERROR_REJECT_UNRECOGNIZED_SERVICE;
return MMS_ERROR_REJECT_UNRECOGNIZED_SERVICE;
else if ((rejectType == 5) && (rejectReason == 0))
return MMS_ERROR_REJECT_UNKNOWN_PDU_TYPE;
else if ((rejectType == 1) && (rejectReason == 4))
@ -471,7 +471,8 @@ convertServiceErrorToMmsError(MmsServiceError serviceError)
{
MmsError mmsError;
switch (serviceError.errorClass) {
switch (serviceError.errorClass)
{
case 0: /* class: vmd-state */
mmsError = MMS_ERROR_VMDSTATE_OTHER;
break;
@ -481,7 +482,8 @@ convertServiceErrorToMmsError(MmsServiceError serviceError)
break;
case 2: /* class: definition */
switch (serviceError.errorCode) {
switch (serviceError.errorCode)
{
case 1:
mmsError = MMS_ERROR_DEFINITION_OBJECT_UNDEFINED;
break;
@ -523,7 +525,8 @@ convertServiceErrorToMmsError(MmsServiceError serviceError)
break;
case 7: /* class: access */
switch (serviceError.errorCode) {
switch (serviceError.errorCode)
{
case 1:
mmsError = MMS_ERROR_ACCESS_OBJECT_ACCESS_UNSUPPORTED;
break;
@ -543,7 +546,8 @@ convertServiceErrorToMmsError(MmsServiceError serviceError)
break;
case 11: /* class: file */
switch (serviceError.errorCode) {
switch (serviceError.errorCode)
{
case 1:
mmsError = MMS_ERROR_FILE_FILENAME_AMBIGUOUS;
break;
@ -577,7 +581,6 @@ convertServiceErrorToMmsError(MmsServiceError serviceError)
}
break;
default:
mmsError = MMS_ERROR_OTHER;
}
@ -598,7 +601,8 @@ parseServiceError(uint8_t* buffer, int bufPos, int maxLength, MmsServiceError* e
if (bufPos < 0)
return -1;
switch (tag) {
switch (tag)
{
case 0xa0: /* errorClass */
{
uint8_t errorClassTag = buffer[bufPos++];
@ -656,7 +660,8 @@ mmsMsg_parseConfirmedErrorPDU(uint8_t* buffer, int bufPos, int maxBufPos, uint32
if (bufPos < 0)
goto exit_error;
switch (tag) {
switch (tag)
{
case 0x80: /* invoke Id */
if (invokeId != NULL)
*invokeId = BerDecoder_decodeUint32(buffer, length, bufPos);
@ -678,7 +683,7 @@ mmsMsg_parseConfirmedErrorPDU(uint8_t* buffer, int bufPos, int maxBufPos, uint32
return bufPos;
exit_error:
exit_error:
if (DEBUG_MMS_CLIENT)
printf("MMS_CLIENT: error parsing confirmed error PDU\n");
@ -714,7 +719,6 @@ mmsMsg_parseRejectPDU(uint8_t* buffer, int bufPos, int maxBufPos, uint32_t* invo
if (bufPos < 0)
goto exit_error;
if (tag == 0x80) { /* invoke id */
if (invokeId != NULL)
*invokeId = BerDecoder_decodeUint32(buffer, length, bufPos);
@ -724,7 +728,7 @@ mmsMsg_parseRejectPDU(uint8_t* buffer, int bufPos, int maxBufPos, uint32_t* invo
*rejectReason = BerDecoder_decodeInt32(buffer, length, bufPos);
}
else {
/* unknown - ignore */
/* unknown - ignore */
}
bufPos += length;
@ -732,7 +736,7 @@ mmsMsg_parseRejectPDU(uint8_t* buffer, int bufPos, int maxBufPos, uint32_t* invo
return bufPos;
exit_error:
exit_error:
if (DEBUG_MMS_CLIENT)
printf("MMS_CLIENT: error parsing reject PDU\n");
@ -836,7 +840,8 @@ mmsIsoCallback(IsoIndication indication, void* parameter, ByteBuffer* payload)
if (DEBUG_MMS_CLIENT)
printf("MMS_CLIENT: Confirmed error PDU!\n");
uint32_t invokeId;
MmsServiceError serviceError = {0, 0};
MmsServiceError serviceError =
{ 0, 0 };
if (mmsMsg_parseConfirmedErrorPDU(payload->buffer, 0, payload->size, &invokeId, &serviceError) < 0) {
if (DEBUG_MMS_CLIENT)
@ -972,7 +977,8 @@ mmsIsoCallback(IsoIndication indication, void* parameter, ByteBuffer* payload)
goto exit_with_error;
if (extendedTag) {
switch(nestedTag) {
switch (nestedTag)
{
#if (MMS_FILE_SERVICE == 1)
case 0x48: /* file-open-request */
@ -1022,7 +1028,7 @@ mmsIsoCallback(IsoIndication indication, void* parameter, ByteBuffer* payload)
#endif /* MMS_FILE_SERVICE == 1 */
default:
// mmsServer_writeMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_UNRECOGNIZED_SERVICE, response);
// mmsServer_writeMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_UNRECOGNIZED_SERVICE, response);
if (DEBUG_MMS_CLIENT)
printf("MMS_CLIENT: unexpected message from server!\n");
@ -1032,7 +1038,8 @@ mmsIsoCallback(IsoIndication indication, void* parameter, ByteBuffer* payload)
}
}
else {
switch(nestedTag) {
switch (nestedTag)
{
case 0x02: /* invoke Id */
invokeId = BerDecoder_decodeUint32(buf, length, bufPos);
if (DEBUG_MMS_CLIENT)
@ -1040,9 +1047,8 @@ mmsIsoCallback(IsoIndication indication, void* parameter, ByteBuffer* payload)
self->lastInvokeId = invokeId;
break;
default:
// mmsServer_writeMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_UNRECOGNIZED_SERVICE, response);
// mmsServer_writeMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_UNRECOGNIZED_SERVICE, response);
if (DEBUG_MMS_CLIENT)
printf("MMS_CLIENT: unexpected message from server!\n");
@ -1057,7 +1063,6 @@ mmsIsoCallback(IsoIndication indication, void* parameter, ByteBuffer* payload)
bufPos += length;
}
}
#endif /* (MMS_OBTAIN_FILE_SERVICE == 1) */
@ -1066,14 +1071,13 @@ mmsIsoCallback(IsoIndication indication, void* parameter, ByteBuffer* payload)
return;
exit_with_error:
exit_with_error:
if (DEBUG_MMS_CLIENT)
printf("MMS_CLIENT: received malformed message from server!\n");
IsoClientConnection_releaseReceiveBuffer(self->isoClient);
if (DEBUG_MMS_CLIENT)
printf("MMS_CLIENT: LEAVE mmsIsoCallback - NOT OK!\n");
return;
@ -1108,8 +1112,8 @@ MmsConnection_create()
self->isoParameters = IsoConnectionParameters_create();
/* Load default values for connection parameters */
TSelector tSelector = { 2, { 0, 1 } };
SSelector sSelector = {2, { 0, 1 } };
TSelector tSelector = { 2, { 0, 1 } };
SSelector sSelector = { 2, { 0, 1 } };
IsoConnectionParameters_setLocalAddresses(self->isoParameters, 1, sSelector, tSelector);
IsoConnectionParameters_setLocalApTitle(self->isoParameters, "1.1.1.999", 12);
@ -1141,7 +1145,6 @@ MmsConnection_createSecure(TLSConfiguration tlsConfig)
return self;
}
void
MmsConnection_destroy(MmsConnection self)
{
@ -1214,7 +1217,6 @@ MmsConnection_setRawMessageHandler(MmsConnection self, MmsRawMessageHandler hand
#endif
}
void
MmsConnection_setConnectionLostHandler(MmsConnection self, MmsConnectionLostHandler handler, void* handlerParameter)
{
@ -1281,9 +1283,9 @@ MmsConnection_connect(MmsConnection self, MmsError* mmsError, const char* server
if (serverPort == -1) {
#if (CONFIG_MMS_SUPPORT_TLS == 1)
if (self->isoParameters->tlsConfiguration)
serverPort = 3782;
serverPort = 3782;
else
serverPort = 102;
serverPort = 102;
#else
serverPort = 102;
#endif
@ -1407,7 +1409,7 @@ sendConcludeRequestAndWaitForResponse(MmsConnection self)
self->lastResponseError = MMS_ERROR_SERVICE_TIMEOUT;
}
exit_function:
exit_function:
return;
}
@ -1439,7 +1441,7 @@ MmsConnection_conclude(MmsConnection self, MmsError* mmsError)
self->connectionLostHandler = NULL;
exit_function:
exit_function:
return;
}
@ -1492,7 +1494,7 @@ mmsClient_getNameListSingleRequest(
releaseResponse(self);
exit_function:
exit_function:
return moreFollows;
}
@ -1584,7 +1586,7 @@ MmsConnection_readVariable(MmsConnection self, MmsError* mmsError,
releaseResponse(self);
exit_function:
exit_function:
return value;
}
@ -1614,7 +1616,7 @@ MmsConnection_readArrayElements(MmsConnection self, MmsError* mmsError,
releaseResponse(self);
exit_function:
exit_function:
return value;
}
@ -1642,7 +1644,7 @@ MmsConnection_readMultipleVariables(MmsConnection self, MmsError* mmsError,
releaseResponse(self);
exit_function:
exit_function:
return value;
}
@ -1672,7 +1674,7 @@ MmsConnection_readNamedVariableListValues(MmsConnection self, MmsError* mmsError
releaseResponse(self);
exit_function:
exit_function:
return value;
}
@ -1703,7 +1705,7 @@ MmsConnection_readNamedVariableListValuesAssociationSpecific(
releaseResponse(self);
exit_function:
exit_function:
return value;
}
@ -1733,7 +1735,7 @@ MmsConnection_readNamedVariableListDirectory(MmsConnection self, MmsError* mmsEr
releaseResponse(self);
exit_function:
exit_function:
return attributes;
}
@ -1763,7 +1765,7 @@ MmsConnection_readNamedVariableListDirectoryAssociationSpecific(MmsConnection se
releaseResponse(self);
exit_function:
exit_function:
return attributes;
}
@ -1791,7 +1793,7 @@ MmsConnection_defineNamedVariableList(MmsConnection self, MmsError* mmsError,
releaseResponse(self);
exit_function:
exit_function:
return;
}
@ -1819,8 +1821,7 @@ MmsConnection_defineNamedVariableListAssociationSpecific(MmsConnection self,
releaseResponse(self);
exit_function:
exit_function:
return;
}
@ -1849,7 +1850,7 @@ MmsConnection_deleteNamedVariableList(MmsConnection self, MmsError* mmsError,
releaseResponse(self);
exit_function:
exit_function:
return isDeleted;
}
@ -1879,7 +1880,7 @@ MmsConnection_deleteAssociationSpecificNamedVariableList(MmsConnection self,
releaseResponse(self);
exit_function:
exit_function:
return isDeleted;
}
@ -1907,7 +1908,7 @@ MmsConnection_getVariableAccessAttributes(MmsConnection self, MmsError* mmsError
releaseResponse(self);
exit_function:
exit_function:
return typeSpec;
}
@ -1934,13 +1935,13 @@ MmsConnection_identify(MmsConnection self, MmsError* mmsError)
releaseResponse(self);
exit_function:
exit_function:
return identity;
}
void
MmsConnection_getServerStatus(MmsConnection self, MmsError* mmsError, int* vmdLogicalStatus, int* vmdPhysicalStatus,
bool extendedDerivation)
bool extendedDerivation)
{
ByteBuffer* payload = IsoClientConnection_allocateTransmitBuffer(self->isoClient);
@ -1951,15 +1952,15 @@ MmsConnection_getServerStatus(MmsConnection self, MmsError* mmsError, int* vmdLo
ByteBuffer* responseMessage = sendRequestAndWaitForResponse(self, invokeId, payload, mmsError);
if (responseMessage != NULL) {
if (mmsClient_parseStatusResponse(self, vmdLogicalStatus, vmdPhysicalStatus) == false)
*mmsError = MMS_ERROR_PARSING_RESPONSE;
}
if (mmsClient_parseStatusResponse(self, vmdLogicalStatus, vmdPhysicalStatus) == false)
*mmsError = MMS_ERROR_PARSING_RESPONSE;
}
releaseResponse(self);
releaseResponse(self);
}
static LinkedList
readJournal(MmsConnection self, MmsError* mmsError, uint32_t invokeId, ByteBuffer* payload, bool* moreFollows)
readJournal(MmsConnection self, MmsError* mmsError, uint32_t invokeId, ByteBuffer* payload, bool* moreFollows)
{
ByteBuffer* responseMessage = sendRequestAndWaitForResponse(self, invokeId, payload, mmsError);
@ -1998,7 +1999,6 @@ MmsJournalEntry_destroy(MmsJournalEntry self)
}
}
const MmsValue*
MmsJournalEntry_getEntryID(MmsJournalEntry self)
{
@ -2158,7 +2158,6 @@ MmsConnection_fileRead(MmsConnection self, MmsError* mmsError, int32_t frsmId, M
return moreFollows;
}
bool
MmsConnection_getFileDirectory(MmsConnection self, MmsError* mmsError, const char* fileSpecification, const char* continueAfter,
MmsFileDirectoryHandler handler, void* handlerParameter)
@ -2199,7 +2198,6 @@ MmsConnection_fileRename(MmsConnection self, MmsError* mmsError, const char* cur
releaseResponse(self);
}
void
MmsConnection_obtainFile(MmsConnection self, MmsError* mmsError, const char* sourceFile, const char* destinationFile)
{
@ -2359,13 +2357,13 @@ void
MmsVariableAccessSpecification_destroy(MmsVariableAccessSpecification* self)
{
if (self->domainId != NULL)
GLOBAL_FREEMEM((void*) self->domainId);
GLOBAL_FREEMEM((void* ) self->domainId);
if (self->itemId != NULL)
GLOBAL_FREEMEM((void*) self->itemId);
GLOBAL_FREEMEM((void* ) self->itemId);
if (self->componentName != NULL)
GLOBAL_FREEMEM((void*) self->componentName);
GLOBAL_FREEMEM((void* ) self->componentName);
GLOBAL_FREEMEM(self);
}

@ -31,186 +31,188 @@
#include "mms_client_internal.h"
static MmsVariableSpecification*
createTypeSpecification(TypeSpecification_t* asnTypeSpec) {
MmsVariableSpecification* typeSpec = (MmsVariableSpecification*)
GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification));
switch (asnTypeSpec->present) {
case TypeSpecification_PR_structure:
{
typeSpec->type = MMS_STRUCTURE;
int elementCount = asnTypeSpec->choice.structure.components.list.count;
typeSpec->typeSpec.structure.elementCount = elementCount;
typeSpec->typeSpec.structure.elements = (MmsVariableSpecification**)
GLOBAL_CALLOC(elementCount, sizeof(MmsVariableSpecification*));
int i;
for (i = 0; i < elementCount; i++) {
char* name = StringUtils_createStringFromBuffer(
asnTypeSpec->choice.structure.components.list.array[i]->componentName->buf,
asnTypeSpec->choice.structure.components.list.array[i]->componentName->size);
typeSpec->typeSpec.structure.elements[i] =
createTypeSpecification(asnTypeSpec->choice.structure.components.
list.array[i]->componentType);
typeSpec->typeSpec.structure.elements[i]->name = name;
}
}
break;
case TypeSpecification_PR_array:
{
typeSpec->type = MMS_ARRAY;
long elementCount;
asn_INTEGER2long(&asnTypeSpec->choice.array.numberOfElements, &elementCount);
typeSpec->typeSpec.array.elementCount = elementCount;
typeSpec->typeSpec.array.elementTypeSpec =
createTypeSpecification(asnTypeSpec->choice.array.elementType);
}
break;
case TypeSpecification_PR_boolean:
typeSpec->type = MMS_BOOLEAN;
break;
case TypeSpecification_PR_bitstring:
typeSpec->type = MMS_BIT_STRING;
typeSpec->typeSpec.bitString = asnTypeSpec->choice.bitstring;
break;
case TypeSpecification_PR_integer:
typeSpec->type = MMS_INTEGER;
typeSpec->typeSpec.integer = asnTypeSpec->choice.integer;
break;
case TypeSpecification_PR_unsigned:
typeSpec->type = MMS_UNSIGNED;
typeSpec->typeSpec.unsignedInteger = asnTypeSpec->choice.Unsigned;
break;
case TypeSpecification_PR_floatingpoint:
typeSpec->type = MMS_FLOAT;
typeSpec->typeSpec.floatingpoint.exponentWidth =
asnTypeSpec->choice.floatingpoint.exponentwidth;
typeSpec->typeSpec.floatingpoint.formatWidth =
asnTypeSpec->choice.floatingpoint.formatwidth;
break;
case TypeSpecification_PR_octetstring:
typeSpec->type = MMS_OCTET_STRING;
typeSpec->typeSpec.octetString = asnTypeSpec->choice.octetstring;
break;
case TypeSpecification_PR_visiblestring:
typeSpec->type = MMS_VISIBLE_STRING;
typeSpec->typeSpec.visibleString = asnTypeSpec->choice.visiblestring;
break;
case TypeSpecification_PR_mMSString:
typeSpec->type = MMS_STRING;
typeSpec->typeSpec.mmsString = asnTypeSpec->choice.mMSString;
break;
case TypeSpecification_PR_utctime:
typeSpec->type = MMS_UTC_TIME;
break;
case TypeSpecification_PR_binarytime:
typeSpec->type = MMS_BINARY_TIME;
if (asnTypeSpec->choice.binarytime == 0)
typeSpec->typeSpec.binaryTime = 4;
else
typeSpec->typeSpec.binaryTime = 6;
break;
default:
printf("ERROR: unknown type in type specification\n");
break;
}
return typeSpec;
createTypeSpecification(TypeSpecification_t* asnTypeSpec)
{
MmsVariableSpecification* typeSpec = (MmsVariableSpecification*)
GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification));
switch (asnTypeSpec->present)
{
case TypeSpecification_PR_structure:
{
typeSpec->type = MMS_STRUCTURE;
int elementCount = asnTypeSpec->choice.structure.components.list.count;
typeSpec->typeSpec.structure.elementCount = elementCount;
typeSpec->typeSpec.structure.elements = (MmsVariableSpecification**)
GLOBAL_CALLOC(elementCount, sizeof(MmsVariableSpecification*));
int i;
for (i = 0; i < elementCount; i++) {
char* name = StringUtils_createStringFromBuffer(
asnTypeSpec->choice.structure.components.list.array[i]->componentName->buf,
asnTypeSpec->choice.structure.components.list.array[i]->componentName->size);
typeSpec->typeSpec.structure.elements[i] =
createTypeSpecification(asnTypeSpec->choice.structure.components.
list.array[i]->componentType);
typeSpec->typeSpec.structure.elements[i]->name = name;
}
}
break;
case TypeSpecification_PR_array:
{
typeSpec->type = MMS_ARRAY;
long elementCount;
asn_INTEGER2long(&asnTypeSpec->choice.array.numberOfElements, &elementCount);
typeSpec->typeSpec.array.elementCount = elementCount;
typeSpec->typeSpec.array.elementTypeSpec =
createTypeSpecification(asnTypeSpec->choice.array.elementType);
}
break;
case TypeSpecification_PR_boolean:
typeSpec->type = MMS_BOOLEAN;
break;
case TypeSpecification_PR_bitstring:
typeSpec->type = MMS_BIT_STRING;
typeSpec->typeSpec.bitString = asnTypeSpec->choice.bitstring;
break;
case TypeSpecification_PR_integer:
typeSpec->type = MMS_INTEGER;
typeSpec->typeSpec.integer = asnTypeSpec->choice.integer;
break;
case TypeSpecification_PR_unsigned:
typeSpec->type = MMS_UNSIGNED;
typeSpec->typeSpec.unsignedInteger = asnTypeSpec->choice.Unsigned;
break;
case TypeSpecification_PR_floatingpoint:
typeSpec->type = MMS_FLOAT;
typeSpec->typeSpec.floatingpoint.exponentWidth =
asnTypeSpec->choice.floatingpoint.exponentwidth;
typeSpec->typeSpec.floatingpoint.formatWidth =
asnTypeSpec->choice.floatingpoint.formatwidth;
break;
case TypeSpecification_PR_octetstring:
typeSpec->type = MMS_OCTET_STRING;
typeSpec->typeSpec.octetString = asnTypeSpec->choice.octetstring;
break;
case TypeSpecification_PR_visiblestring:
typeSpec->type = MMS_VISIBLE_STRING;
typeSpec->typeSpec.visibleString = asnTypeSpec->choice.visiblestring;
break;
case TypeSpecification_PR_mMSString:
typeSpec->type = MMS_STRING;
typeSpec->typeSpec.mmsString = asnTypeSpec->choice.mMSString;
break;
case TypeSpecification_PR_utctime:
typeSpec->type = MMS_UTC_TIME;
break;
case TypeSpecification_PR_binarytime:
typeSpec->type = MMS_BINARY_TIME;
if (asnTypeSpec->choice.binarytime == 0)
typeSpec->typeSpec.binaryTime = 4;
else
typeSpec->typeSpec.binaryTime = 6;
break;
default:
printf("ERROR: unknown type in type specification\n");
break;
}
return typeSpec;
}
MmsVariableSpecification*
mmsClient_parseGetVariableAccessAttributesResponse(ByteBuffer* message, uint32_t* invokeId)
{
MmsPdu_t* mmsPdu = 0; /* allow asn1c to allocate structure */
MmsVariableSpecification* typeSpec = NULL;
MmsPdu_t* mmsPdu = 0; /* allow asn1c to allocate structure */
MmsVariableSpecification* typeSpec = NULL;
asn_dec_rval_t rval = ber_decode(NULL, &asn_DEF_MmsPdu,
(void**) &mmsPdu, ByteBuffer_getBuffer(message), ByteBuffer_getSize(message));
asn_dec_rval_t rval = ber_decode(NULL, &asn_DEF_MmsPdu,
(void**) &mmsPdu, ByteBuffer_getBuffer(message), ByteBuffer_getSize(message));
if (rval.code != RC_OK)
return NULL;
if (rval.code != RC_OK)
return NULL;
if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) {
if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) {
if (invokeId != NULL)
*invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu);
if (invokeId != NULL)
*invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu);
if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present ==
ConfirmedServiceResponse_PR_getVariableAccessAttributes)
{
GetVariableAccessAttributesResponse_t* response;
if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present ==
ConfirmedServiceResponse_PR_getVariableAccessAttributes)
{
GetVariableAccessAttributesResponse_t* response;
response = &(mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.choice.getVariableAccessAttributes);
TypeSpecification_t* asnTypeSpec = &response->typeSpecification;
response = &(mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.choice.getVariableAccessAttributes);
TypeSpecification_t* asnTypeSpec = &response->typeSpecification;
typeSpec = createTypeSpecification(asnTypeSpec);
}
}
typeSpec = createTypeSpecification(asnTypeSpec);
}
}
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
return typeSpec;
return typeSpec;
}
int
mmsClient_createGetVariableAccessAttributesRequest(
uint32_t invokeId,
const char* domainId, const char* itemId,
ByteBuffer* writeBuffer)
const char* domainId, const char* itemId,
ByteBuffer* writeBuffer)
{
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present =
ConfirmedServiceRequest_PR_getVariableAccessAttributes;
mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present =
ConfirmedServiceRequest_PR_getVariableAccessAttributes;
GetVariableAccessAttributesRequest_t* request;
GetVariableAccessAttributesRequest_t* request;
request =
&(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.getVariableAccessAttributes);
request =
&(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.getVariableAccessAttributes);
request->present = GetVariableAccessAttributesRequest_PR_name;
request->present = GetVariableAccessAttributesRequest_PR_name;
if (domainId != NULL) {
if (domainId != NULL) {
request->choice.name.present = ObjectName_PR_domainspecific;
request->choice.name.choice.domainspecific.domainId.buf = (uint8_t*) domainId;
request->choice.name.choice.domainspecific.domainId.size = strlen(domainId);
request->choice.name.choice.domainspecific.itemId.buf = (uint8_t*) itemId;
request->choice.name.choice.domainspecific.itemId.size = strlen(itemId);
}
else {
request->choice.name.present = ObjectName_PR_vmdspecific;
request->choice.name.choice.vmdspecific.buf = (uint8_t*) itemId;
request->choice.name.choice.vmdspecific.size = strlen(itemId);
}
}
else {
request->choice.name.present = ObjectName_PR_vmdspecific;
request->choice.name.choice.vmdspecific.buf = (uint8_t*) itemId;
request->choice.name.choice.vmdspecific.size = strlen(itemId);
}
asn_enc_rval_t rval;
asn_enc_rval_t rval;
rval = der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
rval = der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
if (domainId != NULL) {
if (domainId != NULL) {
request->choice.name.choice.domainspecific.domainId.buf = 0;
request->choice.name.choice.domainspecific.domainId.size = 0;
request->choice.name.choice.domainspecific.itemId.buf = 0;
request->choice.name.choice.domainspecific.itemId.size = 0;
}
else {
request->choice.name.choice.vmdspecific.buf = 0;
request->choice.name.choice.vmdspecific.size = 0;
}
}
else {
request->choice.name.choice.vmdspecific.buf = 0;
request->choice.name.choice.vmdspecific.size = 0;
}
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
return rval.encoded;
return rval.encoded;
}

@ -81,92 +81,91 @@ mmsClient_createDeleteNamedVariableListRequest(long invokeId, ByteBuffer* writeB
void
mmsClient_createDeleteAssociationSpecificNamedVariableListRequest(
long invokeId,
ByteBuffer* writeBuffer,
const char* listNameId)
long invokeId,
ByteBuffer* writeBuffer,
const char* listNameId)
{
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present =
ConfirmedServiceRequest_PR_deleteNamedVariableList;
mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present =
ConfirmedServiceRequest_PR_deleteNamedVariableList;
DeleteNamedVariableListRequest_t* request =
&(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.deleteNamedVariableList);
DeleteNamedVariableListRequest_t* request =
&(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.deleteNamedVariableList);
request->listOfVariableListName = (struct DeleteNamedVariableListRequest__listOfVariableListName*) GLOBAL_CALLOC(1,
sizeof(struct DeleteNamedVariableListRequest__listOfVariableListName));
request->listOfVariableListName = (struct DeleteNamedVariableListRequest__listOfVariableListName*) GLOBAL_CALLOC(1,
sizeof(struct DeleteNamedVariableListRequest__listOfVariableListName));
request->listOfVariableListName->list.count = 1;
request->listOfVariableListName->list.size = 1;
request->listOfVariableListName->list.count = 1;
request->listOfVariableListName->list.size = 1;
request->listOfVariableListName->list.array = (ObjectName_t**) GLOBAL_CALLOC(1, sizeof(ObjectName_t*));
request->listOfVariableListName->list.array[0] = (ObjectName_t*) GLOBAL_CALLOC(1, sizeof(ObjectName_t));
request->listOfVariableListName->list.array = (ObjectName_t**) GLOBAL_CALLOC(1, sizeof(ObjectName_t*));
request->listOfVariableListName->list.array[0] = (ObjectName_t*) GLOBAL_CALLOC(1, sizeof(ObjectName_t));
request->listOfVariableListName->list.array[0]->present = ObjectName_PR_aaspecific;
request->listOfVariableListName->list.array[0]->present = ObjectName_PR_aaspecific;
request->listOfVariableListName->list.array[0]->choice.aaspecific.size = strlen(listNameId);
request->listOfVariableListName->list.array[0]->choice.aaspecific.buf = (uint8_t*) StringUtils_copyString(listNameId);
request->listOfVariableListName->list.array[0]->choice.aaspecific.size = strlen(listNameId);
request->listOfVariableListName->list.array[0]->choice.aaspecific.buf = (uint8_t*) StringUtils_copyString(listNameId);
request->scopeOfDelete = (INTEGER_t*) GLOBAL_CALLOC(1, sizeof(INTEGER_t));
asn_long2INTEGER(request->scopeOfDelete, DeleteNamedVariableListRequest__scopeOfDelete_specific);
request->scopeOfDelete = (INTEGER_t*) GLOBAL_CALLOC(1, sizeof(INTEGER_t));
asn_long2INTEGER(request->scopeOfDelete, DeleteNamedVariableListRequest__scopeOfDelete_specific);
der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
}
bool
mmsClient_parseDeleteNamedVariableListResponse(ByteBuffer* message, uint32_t* invokeId)
{
MmsPdu_t* mmsPdu = 0;
MmsPdu_t* mmsPdu = 0;
bool retVal = false;
bool retVal = false;
asn_dec_rval_t rval = ber_decode(NULL, &asn_DEF_MmsPdu,
(void**) &mmsPdu, ByteBuffer_getBuffer(message), ByteBuffer_getSize(message));
asn_dec_rval_t rval = ber_decode(NULL, &asn_DEF_MmsPdu,
(void**) &mmsPdu, ByteBuffer_getBuffer(message), ByteBuffer_getSize(message));
if (rval.code == RC_OK) {
if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) {
if (rval.code == RC_OK) {
if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) {
if (invokeId != NULL)
*invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu);
if (invokeId != NULL)
*invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu);
if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present ==
ConfirmedServiceResponse_PR_deleteNamedVariableList)
{
DeleteNamedVariableListResponse_t* response =
&(mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.choice.deleteNamedVariableList);
if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present ==
ConfirmedServiceResponse_PR_deleteNamedVariableList)
{
DeleteNamedVariableListResponse_t* response =
&(mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.choice.deleteNamedVariableList);
long numberDeleted;
long numberDeleted;
asn_INTEGER2long(&(response->numberDeleted), &numberDeleted);
asn_INTEGER2long(&(response->numberDeleted), &numberDeleted);
if (numberDeleted == 1)
retVal = true;
}
}
}
if (numberDeleted == 1)
retVal = true;
}
}
}
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
return retVal;
return retVal;
}
void
mmsClient_createGetNamedVariableListAttributesRequest(uint32_t invokeId, ByteBuffer* writeBuffer,
const char* domainId, const char* listNameId)
const char* domainId, const char* listNameId)
{
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present =
ConfirmedServiceRequest_PR_getNamedVariableListAttributes;
mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present =
ConfirmedServiceRequest_PR_getNamedVariableListAttributes;
GetNamedVariableListAttributesRequest_t* request =
&(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.getNamedVariableListAttributes);
GetNamedVariableListAttributesRequest_t* request =
&(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.getNamedVariableListAttributes);
if (domainId != NULL) {
if (domainId != NULL) {
request->present = ObjectName_PR_domainspecific;
request->choice.domainspecific.domainId.size = strlen(domainId);
@ -174,18 +173,18 @@ mmsClient_createGetNamedVariableListAttributesRequest(uint32_t invokeId, ByteBuf
request->choice.domainspecific.itemId.size = strlen(listNameId);
request->choice.domainspecific.itemId.buf = (uint8_t*) StringUtils_copyString(listNameId);
}
else {
request->present = ObjectName_PR_vmdspecific;
}
else {
request->present = ObjectName_PR_vmdspecific;
request->choice.vmdspecific.size = strlen(listNameId);
request->choice.vmdspecific.buf = (uint8_t*) StringUtils_copyString(listNameId);
}
request->choice.vmdspecific.size = strlen(listNameId);
request->choice.vmdspecific.buf = (uint8_t*) StringUtils_copyString(listNameId);
}
der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
}
void
@ -195,7 +194,7 @@ mmsClient_createGetNamedVariableListAttributesRequestAssociationSpecific(uint32_
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present =
ConfirmedServiceRequest_PR_getNamedVariableListAttributes;
ConfirmedServiceRequest_PR_getNamedVariableListAttributes;
GetNamedVariableListAttributesRequest_t* request =
&(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.getNamedVariableListAttributes);
@ -214,102 +213,98 @@ mmsClient_createGetNamedVariableListAttributesRequestAssociationSpecific(uint32_
static LinkedList /* <MmsVariableAccessSpecification*> */
parseNamedVariableAttributes(GetNamedVariableListAttributesResponse_t* response, bool* deletable)
{
if (deletable != NULL)
*deletable = response->mmsDeletable;
int attributesCount = response->listOfVariable.list.count;
int i;
if (deletable != NULL)
*deletable = response->mmsDeletable;
LinkedList attributes = LinkedList_create();
int attributesCount = response->listOfVariable.list.count;
int i;
for (i = 0; i < attributesCount; i++) {
LinkedList attributes = LinkedList_create();
char* domainId;
char* itemId;
for (i = 0; i < attributesCount; i++) {
char* domainId;
char* itemId;
if (response->listOfVariable.list.array[i]->variableSpecification.choice.name.present == ObjectName_PR_vmdspecific) {
if (response->listOfVariable.list.array[i]->variableSpecification.choice.name.present == ObjectName_PR_vmdspecific) {
domainId = NULL;
domainId = NULL;
itemId = mmsMsg_createStringFromAsnIdentifier(response->listOfVariable.list.array[i]->
variableSpecification.choice.name.choice.vmdspecific);
}
else {
domainId = mmsMsg_createStringFromAsnIdentifier(response->listOfVariable.list.array[i]->
variableSpecification.choice.name.choice.domainspecific.domainId);
itemId = mmsMsg_createStringFromAsnIdentifier(response->listOfVariable.list.array[i]->
variableSpecification.choice.name.choice.vmdspecific);
}
else {
domainId = mmsMsg_createStringFromAsnIdentifier(response->listOfVariable.list.array[i]->
variableSpecification.choice.name.choice.domainspecific.domainId);
itemId = mmsMsg_createStringFromAsnIdentifier(response->listOfVariable.list.array[i]->
variableSpecification.choice.name.choice.domainspecific.itemId);
}
itemId = mmsMsg_createStringFromAsnIdentifier(response->listOfVariable.list.array[i]->
variableSpecification.choice.name.choice.domainspecific.itemId);
}
MmsVariableAccessSpecification* listEntry = MmsVariableAccessSpecification_create(domainId, itemId);
MmsVariableAccessSpecification* listEntry = MmsVariableAccessSpecification_create(domainId, itemId);
LinkedList_add(attributes, listEntry);
}
LinkedList_add(attributes, listEntry);
}
return attributes;
return attributes;
}
LinkedList /* <MmsVariableAccessSpecification*> */
mmsClient_parseGetNamedVariableListAttributesResponse(ByteBuffer* message, uint32_t* invokeId,
bool* /*OUT*/ deletable)
mmsClient_parseGetNamedVariableListAttributesResponse(ByteBuffer* message, uint32_t* invokeId, bool* /*OUT*/deletable)
{
MmsPdu_t* mmsPdu = 0;
MmsPdu_t* mmsPdu = 0;
LinkedList attributes = NULL;
LinkedList attributes = NULL;
asn_dec_rval_t rval = ber_decode(NULL, &asn_DEF_MmsPdu,
(void**) &mmsPdu, ByteBuffer_getBuffer(message), ByteBuffer_getSize(message));
asn_dec_rval_t rval = ber_decode(NULL, &asn_DEF_MmsPdu,
(void**) &mmsPdu, ByteBuffer_getBuffer(message), ByteBuffer_getSize(message));
if (rval.code == RC_OK) {
if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) {
if (rval.code == RC_OK) {
if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) {
if (invokeId != NULL)
*invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu);
if (invokeId != NULL)
*invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu);
if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present ==
ConfirmedServiceResponse_PR_getNamedVariableListAttributes)
{
attributes = parseNamedVariableAttributes(
&(mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.choice.getNamedVariableListAttributes),
deletable);
}
}
}
if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present ==
ConfirmedServiceResponse_PR_getNamedVariableListAttributes)
{
attributes = parseNamedVariableAttributes(
&(mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.choice.getNamedVariableListAttributes),
deletable);
}
}
}
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
return attributes;
return attributes;
}
void
mmsClient_createDefineNamedVariableListRequest(
uint32_t invokeId,
ByteBuffer* writeBuffer,
const char* domainId,
const char* listNameId,
LinkedList /*<MmsVariableSpecification*>*/ listOfVariables,
bool associationSpecific)
uint32_t invokeId,
ByteBuffer* writeBuffer,
const char* domainId,
const char* listNameId,
LinkedList /*<MmsVariableSpecification*>*/listOfVariables,
bool associationSpecific)
{
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present =
ConfirmedServiceRequest_PR_defineNamedVariableList;
mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present =
ConfirmedServiceRequest_PR_defineNamedVariableList;
DefineNamedVariableListRequest_t* request =
&(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.defineNamedVariableList);
DefineNamedVariableListRequest_t* request =
&(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.defineNamedVariableList);
if (associationSpecific) {
request->variableListName.present = ObjectName_PR_aaspecific;
if (associationSpecific) {
request->variableListName.present = ObjectName_PR_aaspecific;
request->variableListName.choice.aaspecific.size = strlen(listNameId);
request->variableListName.choice.aaspecific.buf = (uint8_t*) StringUtils_copyString(listNameId);
}
else {
if (domainId != NULL) { /* domain scope */
request->variableListName.choice.aaspecific.size = strlen(listNameId);
request->variableListName.choice.aaspecific.buf = (uint8_t*) StringUtils_copyString(listNameId);
}
else {
if (domainId != NULL) { /* domain scope */
request->variableListName.present = ObjectName_PR_domainspecific;
request->variableListName.choice.domainspecific.domainId.size = strlen(domainId);
@ -317,135 +312,132 @@ mmsClient_createDefineNamedVariableListRequest(
request->variableListName.choice.domainspecific.itemId.size = strlen(listNameId);
request->variableListName.choice.domainspecific.itemId.buf = (uint8_t*) StringUtils_copyString(listNameId);
}
else { /* VMD scope */
request->variableListName.present = ObjectName_PR_vmdspecific;
}
else { /* VMD scope */
request->variableListName.present = ObjectName_PR_vmdspecific;
request->variableListName.choice.vmdspecific.size = strlen(listNameId);
request->variableListName.choice.vmdspecific.size = strlen(listNameId);
request->variableListName.choice.vmdspecific.buf = (uint8_t*) StringUtils_copyString(listNameId);
}
}
}
}
int listSize = LinkedList_size(listOfVariables);
int listSize = LinkedList_size(listOfVariables);
request->listOfVariable.list.count = listSize;
request->listOfVariable.list.size = listSize;
request->listOfVariable.list.count = listSize;
request->listOfVariable.list.size = listSize;
request->listOfVariable.list.array =
(struct DefineNamedVariableListRequest__listOfVariable__Member**) GLOBAL_CALLOC(listSize, sizeof(void*));
request->listOfVariable.list.array =
(struct DefineNamedVariableListRequest__listOfVariable__Member**) GLOBAL_CALLOC(listSize, sizeof(void*));
int i = 0;
LinkedList element = LinkedList_getNext(listOfVariables);
while (i < listSize) {
int i = 0;
LinkedList element = LinkedList_getNext(listOfVariables);
while (i < listSize) {
MmsVariableAccessSpecification* variableSpec = (MmsVariableAccessSpecification*) element->data;
MmsVariableAccessSpecification* variableSpec = (MmsVariableAccessSpecification*) element->data;
request->listOfVariable.list.array[i] = (struct DefineNamedVariableListRequest__listOfVariable__Member*)
request->listOfVariable.list.array[i] = (struct DefineNamedVariableListRequest__listOfVariable__Member*)
GLOBAL_CALLOC(1, sizeof(struct DefineNamedVariableListRequest__listOfVariable__Member));
request->listOfVariable.list.array[i]->variableSpecification.present =
VariableSpecification_PR_name;
request->listOfVariable.list.array[i]->variableSpecification.present =
VariableSpecification_PR_name;
request->listOfVariable.list.array[i]->variableSpecification.choice.name.present =
ObjectName_PR_domainspecific;
request->listOfVariable.list.array[i]->variableSpecification.choice.name.present =
ObjectName_PR_domainspecific;
request->listOfVariable.list.array[i]->variableSpecification.choice.name.choice.
domainspecific.domainId.size = strlen(variableSpec->domainId);
request->listOfVariable.list.array[i]->variableSpecification.choice.name.choice.
domainspecific.domainId.size = strlen(variableSpec->domainId);
request->listOfVariable.list.array[i]->variableSpecification.choice.name.choice.
domainspecific.domainId.buf = (uint8_t*) StringUtils_copyString(variableSpec->domainId);
request->listOfVariable.list.array[i]->variableSpecification.choice.name.choice.
domainspecific.domainId.buf = (uint8_t*) StringUtils_copyString(variableSpec->domainId);
request->listOfVariable.list.array[i]->variableSpecification.choice.name.choice.
domainspecific.itemId.size = strlen(variableSpec->itemId);
request->listOfVariable.list.array[i]->variableSpecification.choice.name.choice.
domainspecific.itemId.size = strlen(variableSpec->itemId);
request->listOfVariable.list.array[i]->variableSpecification.choice.name.choice.
domainspecific.itemId.buf = (uint8_t*) StringUtils_copyString(variableSpec->itemId);
request->listOfVariable.list.array[i]->variableSpecification.choice.name.choice.
domainspecific.itemId.buf = (uint8_t*) StringUtils_copyString(variableSpec->itemId);
//TODO add alternate access
if (variableSpec->arrayIndex != -1) {
//TODO add alternate access
if (variableSpec->arrayIndex != -1) {
AlternateAccess_t* alternateAccess = (AlternateAccess_t*) GLOBAL_CALLOC(1, sizeof(AlternateAccess_t));
alternateAccess->list.count = 1;
alternateAccess->list.array = (struct AlternateAccess__Member**) GLOBAL_CALLOC(1, sizeof(struct AlternateAccess__Member*));
alternateAccess->list.array[0] = (struct AlternateAccess__Member*) GLOBAL_CALLOC(1, sizeof(struct AlternateAccess__Member));
AlternateAccess_t* alternateAccess = (AlternateAccess_t*) GLOBAL_CALLOC(1, sizeof(AlternateAccess_t));
alternateAccess->list.count = 1;
alternateAccess->list.array = (struct AlternateAccess__Member**) GLOBAL_CALLOC(1, sizeof(struct AlternateAccess__Member*));
alternateAccess->list.array[0] = (struct AlternateAccess__Member*) GLOBAL_CALLOC(1, sizeof(struct AlternateAccess__Member));
alternateAccess->list.array[0]->present = AlternateAccess__Member_PR_unnamed;
alternateAccess->list.array[0]->choice.unnamed = (AlternateAccessSelection_t*) GLOBAL_CALLOC(1, sizeof(AlternateAccessSelection_t));
alternateAccess->list.array[0]->present = AlternateAccess__Member_PR_unnamed;
alternateAccess->list.array[0]->choice.unnamed = (AlternateAccessSelection_t*) GLOBAL_CALLOC(1, sizeof(AlternateAccessSelection_t));
alternateAccess->list.array[0]->choice.unnamed->present =
AlternateAccessSelection_PR_selectAlternateAccess;
alternateAccess->list.array[0]->choice.unnamed->present =
AlternateAccessSelection_PR_selectAlternateAccess;
alternateAccess->list.array[0]->choice.unnamed->choice.selectAlternateAccess.accessSelection.present =
AlternateAccessSelection__selectAlternateAccess__accessSelection_PR_index;
alternateAccess->list.array[0]->choice.unnamed->choice.selectAlternateAccess.accessSelection.present =
AlternateAccessSelection__selectAlternateAccess__accessSelection_PR_index;
asn_long2INTEGER(&(alternateAccess->list.array[0]->choice.unnamed->choice.selectAlternateAccess.accessSelection.choice.index),
variableSpec->arrayIndex);
asn_long2INTEGER(&(alternateAccess->list.array[0]->choice.unnamed->choice.selectAlternateAccess.accessSelection.choice.index),
variableSpec->arrayIndex);
if (variableSpec->componentName != NULL) {
if (variableSpec->componentName != NULL) {
AlternateAccess_t* componentAccess = (AlternateAccess_t*) GLOBAL_CALLOC(1, sizeof(AlternateAccess_t));
AlternateAccess_t* componentAccess = (AlternateAccess_t*) GLOBAL_CALLOC(1, sizeof(AlternateAccess_t));
componentAccess->list.count = 1;
componentAccess->list.array = (struct AlternateAccess__Member**) GLOBAL_CALLOC(1, sizeof(struct AlternateAccess__Member*));
componentAccess->list.array[0] = (struct AlternateAccess__Member*) GLOBAL_CALLOC(1, sizeof(struct AlternateAccess__Member));
componentAccess->list.count = 1;
componentAccess->list.array = (struct AlternateAccess__Member**) GLOBAL_CALLOC(1, sizeof(struct AlternateAccess__Member*));
componentAccess->list.array[0] = (struct AlternateAccess__Member*) GLOBAL_CALLOC(1, sizeof(struct AlternateAccess__Member));
componentAccess->list.array[0]->present = AlternateAccess__Member_PR_unnamed;
componentAccess->list.array[0]->choice.unnamed = (AlternateAccessSelection_t*) GLOBAL_CALLOC(1, sizeof(AlternateAccessSelection_t));
componentAccess->list.array[0]->present = AlternateAccess__Member_PR_unnamed;
componentAccess->list.array[0]->choice.unnamed = (AlternateAccessSelection_t*) GLOBAL_CALLOC(1, sizeof(AlternateAccessSelection_t));
componentAccess->list.array[0]->choice.unnamed->present = AlternateAccessSelection_PR_selectAccess;
componentAccess->list.array[0]->choice.unnamed->choice.selectAccess.present =
AlternateAccessSelection__selectAccess_PR_component;
componentAccess->list.array[0]->choice.unnamed->present = AlternateAccessSelection_PR_selectAccess;
componentAccess->list.array[0]->choice.unnamed->choice.selectAccess.present =
AlternateAccessSelection__selectAccess_PR_component;
Identifier_t* componentIdentifier =
&(componentAccess->list.array[0]->choice.unnamed->choice.selectAccess.choice.component);
Identifier_t* componentIdentifier =
&(componentAccess->list.array[0]->choice.unnamed->choice.selectAccess.choice.component);
componentIdentifier->size = strlen(variableSpec->componentName);
componentIdentifier->buf = (uint8_t*) StringUtils_copyString(variableSpec->componentName);
componentIdentifier->size = strlen(variableSpec->componentName);
componentIdentifier->buf = (uint8_t*) StringUtils_copyString(variableSpec->componentName);
alternateAccess->list.array[0]->choice.unnamed->choice.selectAlternateAccess.alternateAccess
= componentAccess;
}
alternateAccess->list.array[0]->choice.unnamed->choice.selectAlternateAccess.alternateAccess
= componentAccess;
}
request->listOfVariable.list.array[i]->alternateAccess = alternateAccess;
}
request->listOfVariable.list.array[i]->alternateAccess = alternateAccess;
}
element = LinkedList_getNext(element);
i++;
}
element = LinkedList_getNext(element);
i++;
}
der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
}
bool
mmsClient_parseDefineNamedVariableResponse(ByteBuffer* message, uint32_t* invokeId)
{
MmsPdu_t* mmsPdu = 0;
bool retVal = false;
MmsPdu_t* mmsPdu = 0;
bool retVal = false;
asn_dec_rval_t rval;
asn_dec_rval_t rval;
rval = ber_decode(NULL, &asn_DEF_MmsPdu,
(void**) &mmsPdu, ByteBuffer_getBuffer(message), ByteBuffer_getSize(message));
rval = ber_decode(NULL, &asn_DEF_MmsPdu,
(void**) &mmsPdu, ByteBuffer_getBuffer(message), ByteBuffer_getSize(message));
if (rval.code == RC_OK) {
if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) {
if (invokeId != NULL)
*invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu);
if (rval.code == RC_OK) {
if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) {
if (invokeId != NULL)
*invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu);
if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present ==
ConfirmedServiceResponse_PR_defineNamedVariableList)
retVal = true;
}
}
if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present ==
ConfirmedServiceResponse_PR_defineNamedVariableList)
retVal = true;
}
}
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
return retVal;
return retVal;
}

@ -49,7 +49,8 @@ mmsClient_parseListOfAccessResults(AccessResult_t** accessResultList, int listSi
AccessResult_PR presentType = accessResultList[i]->present;
if (presentType == AccessResult_PR_failure) {
if (DEBUG_MMS_CLIENT) printf("access error!\n");
if (DEBUG_MMS_CLIENT)
printf("access error!\n");
if (accessResultList[i]->choice.failure.size > 0) {
int errorCode = (int) accessResultList[i]->choice.failure.buf[0];
@ -103,7 +104,7 @@ mmsClient_parseListOfAccessResults(AccessResult_t** accessResultList, int listSi
int size = accessResultList[i]->choice.bitstring.size;
value->value.bitString.size = (size * 8)
- accessResultList[i]->choice.bitstring.bits_unused;
- accessResultList[i]->choice.bitstring.bits_unused;
value->value.bitString.buf = (uint8_t*) GLOBAL_MALLOC(size);
memcpy(value->value.bitString.buf,
@ -113,14 +114,14 @@ mmsClient_parseListOfAccessResults(AccessResult_t** accessResultList, int listSi
else if (presentType == AccessResult_PR_integer) {
Asn1PrimitiveValue* berInteger =
BerInteger_createFromBuffer(accessResultList[i]->choice.integer.buf,
accessResultList[i]->choice.integer.size);
accessResultList[i]->choice.integer.size);
value = MmsValue_newIntegerFromBerInteger(berInteger);
}
else if (presentType == AccessResult_PR_unsigned) {
Asn1PrimitiveValue* berInteger =
BerInteger_createFromBuffer(accessResultList[i]->choice.Unsigned.buf,
accessResultList[i]->choice.Unsigned.size);
accessResultList[i]->choice.Unsigned.size);
value = MmsValue_newUnsignedFromBerInteger(berInteger);
}
@ -139,9 +140,9 @@ mmsClient_parseListOfAccessResults(AccessResult_t** accessResultList, int listSi
value->value.floatingPoint.buf = (uint8_t*) GLOBAL_MALLOC(4);
#if (ORDER_LITTLE_ENDIAN == 1)
memcpyReverseByteOrder(value->value.floatingPoint.buf, floatBuf, 4);
memcpyReverseByteOrder(value->value.floatingPoint.buf, floatBuf, 4);
#else
memcpy(value->value.floatingPoint.buf, floatBuf, 4);
memcpy(value->value.floatingPoint.buf, floatBuf, 4);
#endif
}
@ -179,19 +180,19 @@ mmsClient_parseListOfAccessResults(AccessResult_t** accessResultList, int listSi
value->value.visibleString.buf[strSize] = 0;
}
else if (presentType == AccessResult_PR_mMSString) {
value = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue));
value = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue));
value->type = MMS_STRING;
value->type = MMS_STRING;
int strSize = accessResultList[i]->choice.mMSString.size;
int strSize = accessResultList[i]->choice.mMSString.size;
value->value.visibleString.buf = (char*) GLOBAL_MALLOC(strSize + 1);
value->value.visibleString.size = strSize;
value->value.visibleString.buf = (char*) GLOBAL_MALLOC(strSize + 1);
value->value.visibleString.size = strSize;
memcpy(value->value.visibleString.buf,
accessResultList[i]->choice.mMSString.buf, strSize);
memcpy(value->value.visibleString.buf,
accessResultList[i]->choice.mMSString.buf, strSize);
value->value.visibleString.buf[strSize] = 0;
value->value.visibleString.buf[strSize] = 0;
}
else if (presentType == AccessResult_PR_utctime) {
@ -215,14 +216,14 @@ mmsClient_parseListOfAccessResults(AccessResult_t** accessResultList, int listSi
}
}
else if (presentType == AccessResult_PR_octetstring) {
int size = accessResultList[i]->choice.octetstring.size;
value = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue));
value->type = MMS_OCTET_STRING;
value->value.octetString.maxSize = size;
value->value.octetString.size = size;
value->value.octetString.buf = (uint8_t*) GLOBAL_MALLOC(size);
memcpy(value->value.octetString.buf, accessResultList[i]->choice.octetstring.buf, size);
int size = accessResultList[i]->choice.octetstring.size;
value = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue));
value->type = MMS_OCTET_STRING;
value->value.octetString.maxSize = size;
value->value.octetString.size = size;
value->value.octetString.buf = (uint8_t*) GLOBAL_MALLOC(size);
memcpy(value->value.octetString.buf, accessResultList[i]->choice.octetstring.buf, size);
}
else {
printf("unknown type %i\n", presentType);
@ -239,7 +240,6 @@ mmsClient_parseListOfAccessResults(AccessResult_t** accessResultList, int listSi
return valueList;
}
/*
* \param createArray if multiple variables should be read (e.g. if a data set is read) an array should
* be created that contains the access results.
@ -247,68 +247,65 @@ mmsClient_parseListOfAccessResults(AccessResult_t** accessResultList, int listSi
MmsValue*
mmsClient_parseReadResponse(ByteBuffer* message, uint32_t* invokeId, bool createArray)
{
MmsPdu_t* mmsPdu = 0; /* allow asn1c to allocate structure */
MmsPdu_t* mmsPdu = 0; /* allow asn1c to allocate structure */
MmsValue* valueList = NULL;
MmsValue* valueList = NULL;
asn_dec_rval_t rval = ber_decode(NULL, &asn_DEF_MmsPdu,
(void**) &mmsPdu, ByteBuffer_getBuffer(message), ByteBuffer_getSize(message));
asn_dec_rval_t rval = ber_decode(NULL, &asn_DEF_MmsPdu,
(void**) &mmsPdu, ByteBuffer_getBuffer(message), ByteBuffer_getSize(message));
if (rval.code != RC_OK)
return NULL;
if (rval.code != RC_OK)
return NULL;
if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) {
if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) {
if (invokeId != NULL)
*invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu);
if (invokeId != NULL)
*invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu);
if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present == ConfirmedServiceResponse_PR_read) {
ReadResponse_t* response = &(mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.choice.read);
if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present == ConfirmedServiceResponse_PR_read) {
ReadResponse_t* response = &(mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.choice.read);
int elementCount = response->listOfAccessResult.list.count;
int elementCount = response->listOfAccessResult.list.count;
valueList = mmsClient_parseListOfAccessResults(response->listOfAccessResult.list.array,
elementCount, createArray);
}
}
valueList = mmsClient_parseListOfAccessResults(response->listOfAccessResult.list.array,
elementCount, createArray);
}
}
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
return valueList;
return valueList;
}
static ReadRequest_t*
createReadRequest (MmsPdu_t* mmsPdu)
createReadRequest(MmsPdu_t* mmsPdu)
{
mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present =
ConfirmedServiceRequest_PR_read;
mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present =
ConfirmedServiceRequest_PR_read;
return &(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.read);
return &(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.read);
}
int
mmsClient_createReadNamedVariableListRequest(uint32_t invokeId, const char* domainId, const char* itemId,
ByteBuffer* writeBuffer, bool specWithResult)
ByteBuffer* writeBuffer, bool specWithResult)
{
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
ReadRequest_t* readRequest = createReadRequest(mmsPdu);
ReadRequest_t* readRequest = createReadRequest(mmsPdu);
if (specWithResult) {
readRequest->specificationWithResult = (BOOLEAN_t*) GLOBAL_CALLOC(1, sizeof(BOOLEAN_t));
(*(readRequest->specificationWithResult)) = true;
}
else
readRequest->specificationWithResult = NULL;
readRequest->variableAccessSpecification.present = VariableAccessSpecification_PR_variableListName;
if (specWithResult) {
readRequest->specificationWithResult = (BOOLEAN_t*) GLOBAL_CALLOC(1, sizeof(BOOLEAN_t));
(*(readRequest->specificationWithResult)) = true;
}
else
readRequest->specificationWithResult = NULL;
ObjectName_t* objectName = &(readRequest->variableAccessSpecification.choice.variableListName);
readRequest->variableAccessSpecification.present = VariableAccessSpecification_PR_variableListName;
ObjectName_t* objectName = &(readRequest->variableAccessSpecification.choice.variableListName);
if (domainId != NULL) {
if (domainId != NULL) {
objectName->present = ObjectName_PR_domainspecific;
objectName->choice.domainspecific.domainId.buf = (uint8_t*) StringUtils_copyString(domainId);
@ -316,59 +313,59 @@ mmsClient_createReadNamedVariableListRequest(uint32_t invokeId, const char* doma
objectName->choice.domainspecific.itemId.buf = (uint8_t*) StringUtils_copyString(itemId);
objectName->choice.domainspecific.itemId.size = strlen(itemId);
}
else {
}
else {
objectName->present = ObjectName_PR_vmdspecific;
objectName->choice.vmdspecific.buf = (uint8_t*) StringUtils_copyString(itemId);
objectName->choice.vmdspecific.size = strlen(itemId);
}
}
asn_enc_rval_t rval;
asn_enc_rval_t rval;
rval = der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
rval = der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
return rval.encoded;
return rval.encoded;
}
int
mmsClient_createReadAssociationSpecificNamedVariableListRequest(
uint32_t invokeId,
const char* itemId,
ByteBuffer* writeBuffer,
bool specWithResult)
uint32_t invokeId,
const char* itemId,
ByteBuffer* writeBuffer,
bool specWithResult)
{
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
ReadRequest_t* readRequest = createReadRequest(mmsPdu);
ReadRequest_t* readRequest = createReadRequest(mmsPdu);
if (specWithResult) {
readRequest->specificationWithResult = (BOOLEAN_t*) GLOBAL_CALLOC(1, sizeof(BOOLEAN_t));
(*(readRequest->specificationWithResult)) = true;
}
else
readRequest->specificationWithResult = NULL;
if (specWithResult) {
readRequest->specificationWithResult = (BOOLEAN_t*) GLOBAL_CALLOC(1, sizeof(BOOLEAN_t));
(*(readRequest->specificationWithResult)) = true;
}
else
readRequest->specificationWithResult = NULL;
readRequest->variableAccessSpecification.present = VariableAccessSpecification_PR_variableListName;
readRequest->variableAccessSpecification.present = VariableAccessSpecification_PR_variableListName;
ObjectName_t* objectName = &(readRequest->variableAccessSpecification.choice.variableListName);
ObjectName_t* objectName = &(readRequest->variableAccessSpecification.choice.variableListName);
objectName->present = ObjectName_PR_aaspecific;
objectName->present = ObjectName_PR_aaspecific;
objectName->choice.aaspecific.buf = (uint8_t*) StringUtils_copyString(itemId);
objectName->choice.aaspecific.size = strlen(itemId);
objectName->choice.aaspecific.buf = (uint8_t*) StringUtils_copyString(itemId);
objectName->choice.aaspecific.size = strlen(itemId);
asn_enc_rval_t rval;
asn_enc_rval_t rval;
rval = der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
rval = der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
return rval.encoded;
return rval.encoded;
}
/**
@ -377,153 +374,154 @@ mmsClient_createReadAssociationSpecificNamedVariableListRequest(
int
mmsClient_createReadRequest(uint32_t invokeId, const char* domainId, const char* itemId, ByteBuffer* writeBuffer)
{
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
ReadRequest_t* readRequest = createReadRequest(mmsPdu);
ReadRequest_t* readRequest = createReadRequest(mmsPdu);
readRequest->specificationWithResult = NULL;
readRequest->specificationWithResult = NULL;
readRequest->variableAccessSpecification.present = VariableAccessSpecification_PR_listOfVariable;
readRequest->variableAccessSpecification.present = VariableAccessSpecification_PR_listOfVariable;
readRequest->variableAccessSpecification.choice.listOfVariable.list.array =
(ListOfVariableSeq_t**) GLOBAL_CALLOC(1, sizeof(ListOfVariableSeq_t*));
readRequest->variableAccessSpecification.choice.listOfVariable.list.count = 1;
readRequest->variableAccessSpecification.choice.listOfVariable.list.array =
(ListOfVariableSeq_t**) GLOBAL_CALLOC(1, sizeof(ListOfVariableSeq_t*));
readRequest->variableAccessSpecification.choice.listOfVariable.list.count = 1;
ListOfVariableSeq_t* listOfVars = (ListOfVariableSeq_t*) GLOBAL_CALLOC(1, sizeof(ListOfVariableSeq_t));
ListOfVariableSeq_t* listOfVars = (ListOfVariableSeq_t*) GLOBAL_CALLOC(1, sizeof(ListOfVariableSeq_t));
readRequest->variableAccessSpecification.choice.listOfVariable.list.array[0] = listOfVars;
readRequest->variableAccessSpecification.choice.listOfVariable.list.array[0] = listOfVars;
listOfVars->alternateAccess = NULL;
listOfVars->variableSpecification.present = VariableSpecification_PR_name;
listOfVars->alternateAccess = NULL;
listOfVars->variableSpecification.present = VariableSpecification_PR_name;
if (domainId != NULL) {
if (domainId != NULL) {
listOfVars->variableSpecification.choice.name.present = ObjectName_PR_domainspecific;
listOfVars->variableSpecification.choice.name.choice.domainspecific.domainId.buf = (uint8_t*) domainId;
listOfVars->variableSpecification.choice.name.choice.domainspecific.domainId.size = strlen(domainId);
listOfVars->variableSpecification.choice.name.choice.domainspecific.itemId.buf = (uint8_t*) itemId;
listOfVars->variableSpecification.choice.name.choice.domainspecific.itemId.size = strlen(itemId);
}
else {
listOfVars->variableSpecification.choice.name.present = ObjectName_PR_vmdspecific;
listOfVars->variableSpecification.choice.name.choice.vmdspecific.buf = (uint8_t*) itemId;
listOfVars->variableSpecification.choice.name.choice.vmdspecific.size = strlen(itemId);
}
asn_enc_rval_t rval;
rval = der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
/* clean up data structures */
GLOBAL_FREEMEM(listOfVars);
GLOBAL_FREEMEM(readRequest->variableAccessSpecification.choice.listOfVariable.list.array);
readRequest->variableAccessSpecification.choice.listOfVariable.list.array = NULL;
readRequest->variableAccessSpecification.choice.listOfVariable.list.count = 0;
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
return rval.encoded;
}
else {
listOfVars->variableSpecification.choice.name.present = ObjectName_PR_vmdspecific;
listOfVars->variableSpecification.choice.name.choice.vmdspecific.buf = (uint8_t*) itemId;
listOfVars->variableSpecification.choice.name.choice.vmdspecific.size = strlen(itemId);
}
asn_enc_rval_t rval;
rval = der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
/* clean up data structures */
GLOBAL_FREEMEM(listOfVars);
GLOBAL_FREEMEM(readRequest->variableAccessSpecification.choice.listOfVariable.list.array);
readRequest->variableAccessSpecification.choice.listOfVariable.list.array = NULL;
readRequest->variableAccessSpecification.choice.listOfVariable.list.count = 0;
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
return rval.encoded;
}
static AlternateAccess_t*
createAlternateAccess(uint32_t index, uint32_t elementCount)
{
AlternateAccess_t* alternateAccess = (AlternateAccess_t*) GLOBAL_CALLOC(1, sizeof(AlternateAccess_t));
alternateAccess->list.count = 1;
alternateAccess->list.array = (struct AlternateAccess__Member**) GLOBAL_CALLOC(1, sizeof(struct AlternateAccess__Member*));
alternateAccess->list.array[0] = (struct AlternateAccess__Member*) GLOBAL_CALLOC(1, sizeof(struct AlternateAccess__Member));
alternateAccess->list.array[0]->present = AlternateAccess__Member_PR_unnamed;
AlternateAccess_t* alternateAccess = (AlternateAccess_t*) GLOBAL_CALLOC(1, sizeof(AlternateAccess_t));
alternateAccess->list.count = 1;
alternateAccess->list.array = (struct AlternateAccess__Member**) GLOBAL_CALLOC(1, sizeof(struct AlternateAccess__Member*));
alternateAccess->list.array[0] = (struct AlternateAccess__Member*) GLOBAL_CALLOC(1, sizeof(struct AlternateAccess__Member));
alternateAccess->list.array[0]->present = AlternateAccess__Member_PR_unnamed;
alternateAccess->list.array[0]->choice.unnamed = (AlternateAccessSelection_t*) GLOBAL_CALLOC(1, sizeof(AlternateAccessSelection_t));
alternateAccess->list.array[0]->choice.unnamed = (AlternateAccessSelection_t*) GLOBAL_CALLOC(1, sizeof(AlternateAccessSelection_t));
alternateAccess->list.array[0]->choice.unnamed->present = AlternateAccessSelection_PR_selectAccess;
alternateAccess->list.array[0]->choice.unnamed->present = AlternateAccessSelection_PR_selectAccess;
if (elementCount > 0) {
alternateAccess->list.array[0]->choice.unnamed->choice.selectAccess.present =
AlternateAccessSelection__selectAccess_PR_indexRange;
if (elementCount > 0) {
alternateAccess->list.array[0]->choice.unnamed->choice.selectAccess.present =
AlternateAccessSelection__selectAccess_PR_indexRange;
INTEGER_t* asnIndex =
&(alternateAccess->list.array[0]->choice.unnamed->choice.selectAccess.choice.indexRange.lowIndex);
INTEGER_t* asnIndex =
&(alternateAccess->list.array[0]->choice.unnamed->choice.selectAccess.choice.indexRange.lowIndex);
asn_long2INTEGER(asnIndex, index);
asn_long2INTEGER(asnIndex, index);
asnIndex =
&(alternateAccess->list.array[0]->choice.unnamed->choice.selectAccess.choice.indexRange.numberOfElements);
asnIndex =
&(alternateAccess->list.array[0]->choice.unnamed->choice.selectAccess.choice.indexRange.numberOfElements);
asn_long2INTEGER(asnIndex, elementCount);
}
else {
alternateAccess->list.array[0]->choice.unnamed->choice.selectAccess.present =
AlternateAccessSelection__selectAccess_PR_index;
asn_long2INTEGER(asnIndex, elementCount);
}
else {
alternateAccess->list.array[0]->choice.unnamed->choice.selectAccess.present =
AlternateAccessSelection__selectAccess_PR_index;
INTEGER_t* asnIndex =
&(alternateAccess->list.array[0]->choice.unnamed->choice.selectAccess.choice.index);
INTEGER_t* asnIndex =
&(alternateAccess->list.array[0]->choice.unnamed->choice.selectAccess.choice.index);
asn_long2INTEGER(asnIndex, index);
}
asn_long2INTEGER(asnIndex, index);
}
return alternateAccess;
return alternateAccess;
}
static ListOfVariableSeq_t*
createVariableIdentifier(const char* domainId, const char* itemId)
{
ListOfVariableSeq_t* variableIdentifier = (ListOfVariableSeq_t*) GLOBAL_CALLOC(1, sizeof(ListOfVariableSeq_t));
ListOfVariableSeq_t* variableIdentifier = (ListOfVariableSeq_t*) GLOBAL_CALLOC(1, sizeof(ListOfVariableSeq_t));
variableIdentifier->variableSpecification.present = VariableSpecification_PR_name;
variableIdentifier->variableSpecification.choice.name.present = ObjectName_PR_domainspecific;
variableIdentifier->variableSpecification.choice.name.choice.domainspecific.domainId.buf = (uint8_t*) domainId;
variableIdentifier->variableSpecification.choice.name.choice.domainspecific.domainId.size = strlen(domainId);
variableIdentifier->variableSpecification.choice.name.choice.domainspecific.itemId.buf = (uint8_t*) itemId;
variableIdentifier->variableSpecification.choice.name.choice.domainspecific.itemId.size = strlen(itemId);
variableIdentifier->variableSpecification.present = VariableSpecification_PR_name;
variableIdentifier->variableSpecification.choice.name.present = ObjectName_PR_domainspecific;
variableIdentifier->variableSpecification.choice.name.choice.domainspecific.domainId.buf = (uint8_t*) domainId;
variableIdentifier->variableSpecification.choice.name.choice.domainspecific.domainId.size = strlen(domainId);
variableIdentifier->variableSpecification.choice.name.choice.domainspecific.itemId.buf = (uint8_t*) itemId;
variableIdentifier->variableSpecification.choice.name.choice.domainspecific.itemId.size = strlen(itemId);
return variableIdentifier;
return variableIdentifier;
}
int
mmsClient_createReadRequestAlternateAccessIndex(uint32_t invokeId, const char* domainId, const char* itemId,
uint32_t index, uint32_t elementCount, ByteBuffer* writeBuffer)
uint32_t index, uint32_t elementCount, ByteBuffer* writeBuffer)
{
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
ReadRequest_t* readRequest = createReadRequest(mmsPdu);
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
ReadRequest_t* readRequest = createReadRequest(mmsPdu);
readRequest->specificationWithResult = NULL;
readRequest->specificationWithResult = NULL;
readRequest->variableAccessSpecification.present = VariableAccessSpecification_PR_listOfVariable;
readRequest->variableAccessSpecification.present = VariableAccessSpecification_PR_listOfVariable;
readRequest->variableAccessSpecification.choice.listOfVariable.list.array = (ListOfVariableSeq_t**) GLOBAL_CALLOC(1, sizeof(ListOfVariableSeq_t*));
readRequest->variableAccessSpecification.choice.listOfVariable.list.count = 1;
readRequest->variableAccessSpecification.choice.listOfVariable.list.array = (ListOfVariableSeq_t**) GLOBAL_CALLOC(1, sizeof(ListOfVariableSeq_t*));
readRequest->variableAccessSpecification.choice.listOfVariable.list.count = 1;
ListOfVariableSeq_t* variableIdentifier = createVariableIdentifier(domainId, itemId);
ListOfVariableSeq_t* variableIdentifier = createVariableIdentifier(domainId, itemId);
readRequest->variableAccessSpecification.choice.listOfVariable.list.array[0] = variableIdentifier;
readRequest->variableAccessSpecification.choice.listOfVariable.list.array[0] = variableIdentifier;
variableIdentifier->alternateAccess = createAlternateAccess(index, elementCount);
variableIdentifier->alternateAccess = createAlternateAccess(index, elementCount);
asn_enc_rval_t rval;
asn_enc_rval_t rval;
rval = der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
rval = der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
variableIdentifier->variableSpecification.choice.name.choice.domainspecific.domainId.buf = 0;
variableIdentifier->variableSpecification.choice.name.choice.domainspecific.domainId.size = 0;
variableIdentifier->variableSpecification.choice.name.choice.domainspecific.itemId.buf = 0;
variableIdentifier->variableSpecification.choice.name.choice.domainspecific.itemId.size = 0;
variableIdentifier->variableSpecification.choice.name.choice.domainspecific.domainId.buf = 0;
variableIdentifier->variableSpecification.choice.name.choice.domainspecific.domainId.size = 0;
variableIdentifier->variableSpecification.choice.name.choice.domainspecific.itemId.buf = 0;
variableIdentifier->variableSpecification.choice.name.choice.domainspecific.itemId.size = 0;
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
return rval.encoded;
return rval.encoded;
}
static ListOfVariableSeq_t**
createListOfVariables(ReadRequest_t* readRequest, int valuesCount) {
readRequest->variableAccessSpecification.present = VariableAccessSpecification_PR_listOfVariable;
createListOfVariables(ReadRequest_t* readRequest, int valuesCount)
{
readRequest->variableAccessSpecification.present = VariableAccessSpecification_PR_listOfVariable;
readRequest->variableAccessSpecification.choice.listOfVariable.list.array = (ListOfVariableSeq_t**)
GLOBAL_CALLOC(valuesCount, sizeof(ListOfVariableSeq_t*));
readRequest->variableAccessSpecification.choice.listOfVariable.list.count = valuesCount;
readRequest->variableAccessSpecification.choice.listOfVariable.list.size = valuesCount;
readRequest->variableAccessSpecification.choice.listOfVariable.list.array = (ListOfVariableSeq_t**)
GLOBAL_CALLOC(valuesCount, sizeof(ListOfVariableSeq_t*));
readRequest->variableAccessSpecification.choice.listOfVariable.list.count = valuesCount;
readRequest->variableAccessSpecification.choice.listOfVariable.list.size = valuesCount;
return readRequest->variableAccessSpecification.choice.listOfVariable.list.array;
return readRequest->variableAccessSpecification.choice.listOfVariable.list.array;
}
/**
@ -531,44 +529,43 @@ createListOfVariables(ReadRequest_t* readRequest, int valuesCount) {
*/
int
mmsClient_createReadRequestMultipleValues(uint32_t invokeId, const char* domainId, LinkedList items,
ByteBuffer* writeBuffer)
ByteBuffer* writeBuffer)
{
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
ReadRequest_t* readRequest = createReadRequest(mmsPdu);
ReadRequest_t* readRequest = createReadRequest(mmsPdu);
readRequest->specificationWithResult = NULL;
readRequest->specificationWithResult = NULL;
int valuesCount = LinkedList_size(items);
int valuesCount = LinkedList_size(items);
ListOfVariableSeq_t** listOfVars = createListOfVariables(readRequest, valuesCount);
ListOfVariableSeq_t** listOfVars = createListOfVariables(readRequest, valuesCount);
LinkedList item = items;
LinkedList item = items;
int i = 0;
while ((item = LinkedList_getNext(item)) != NULL) {
listOfVars[i] = createVariableIdentifier(domainId, (char*) (item->data));
i++;
}
int i = 0;
asn_enc_rval_t rval;
while ((item = LinkedList_getNext(item)) != NULL) {
listOfVars[i] = createVariableIdentifier(domainId, (char*) (item->data));
i++;
}
rval = der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
asn_enc_rval_t rval;
for (i = 0; i < valuesCount; i++) {
GLOBAL_FREEMEM(listOfVars[i]);
}
GLOBAL_FREEMEM(listOfVars);
rval = der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
readRequest->variableAccessSpecification.choice.listOfVariable.list.count = 0;
readRequest->variableAccessSpecification.choice.listOfVariable.list.size = 0;
readRequest->variableAccessSpecification.choice.listOfVariable.list.array = NULL;
for (i = 0; i < valuesCount; i++) {
GLOBAL_FREEMEM(listOfVars[i]);
}
GLOBAL_FREEMEM(listOfVars);
readRequest->variableAccessSpecification.choice.listOfVariable.list.count = 0;
readRequest->variableAccessSpecification.choice.listOfVariable.list.size = 0;
readRequest->variableAccessSpecification.choice.listOfVariable.list.array = NULL;
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
asn_DEF_MmsPdu.free_struct(&asn_DEF_MmsPdu, mmsPdu, 0);
return rval.encoded;
return rval.encoded;
}

File diff suppressed because it is too large Load Diff

@ -48,20 +48,19 @@
static LinkedList
getDomainNames(MmsServerConnection connection)
{
MmsDevice* device = MmsServer_getDevice(connection->server);
MmsDevice* device = MmsServer_getDevice(connection->server);
LinkedList list = LinkedList_create();
LinkedList list = LinkedList_create();
int i;
int i;
for (i = 0; i < device->domainCount; i++) {
LinkedList_add(list, device->domains[i]->domainName);
}
for (i = 0; i < device->domainCount; i++) {
LinkedList_add(list, device->domains[i]->domainName);
}
return list;
return list;
}
#if (CONFIG_MMS_SUPPORT_VMD_SCOPE_NAMED_VARIABLES == 1)
static LinkedList
getNameListVMDSpecific(MmsServerConnection connection)
@ -80,7 +79,6 @@ getNameListVMDSpecific(MmsServerConnection connection)
}
#endif /* (CONFIG_MMS_SUPPORT_VMD_SCOPE_NAMED_VARIABLES == 1) */
#if (CONFIG_MMS_SORT_NAME_LIST == 1)
static void
sortIndex(int* index, int size, MmsVariableSpecification** namedVariables)
@ -173,9 +171,6 @@ addSubNamedVaribleNamesToList(LinkedList nameList, char* prefix, MmsVariableSpec
#endif /* (CONFIG_MMS_SUPPORT_FLATTED_NAME_SPACE == 1) */
static LinkedList
getJournalListDomainSpecific(MmsServerConnection connection, char* domainName)
{
@ -259,7 +254,6 @@ getNameListDomainSpecific(MmsServerConnection connection, char* domainName)
return nameList;
}
#if (MMS_DATA_SET_SERVICE == 1)
static LinkedList
@ -315,13 +309,13 @@ getNamedVariableListsVMDSpecific(MmsServerConnection connection)
static LinkedList
getNamedVariableListAssociationSpecific(MmsServerConnection connection)
{
LinkedList nameList = NULL;
LinkedList nameList = NULL;
LinkedList variableLists = MmsServerConnection_getNamedVariableLists(connection);
LinkedList variableLists = MmsServerConnection_getNamedVariableLists(connection);
nameList = createStringsFromNamedVariableList(nameList, variableLists);
nameList = createStringsFromNamedVariableList(nameList, variableLists);
return nameList;
return nameList;
}
#endif /* (MMS_DYNAMIC_DATA_SETS == 1) */
@ -389,7 +383,7 @@ createNameListResponse(
uint32_t getNameListSize = listOfIdentifierSize;
if (moreFollows == false)
getNameListSize += 3;
getNameListSize += 3;
uint32_t confirmedServiceResponseSize = 1 + BerEncoder_determineLengthSize(getNameListSize) + getNameListSize;
@ -423,7 +417,7 @@ createNameListResponse(
}
if (moreFollows == false)
bufPos = BerEncoder_encodeBoolean(0x81, moreFollows, buffer, bufPos);
bufPos = BerEncoder_encodeBoolean(0x81, moreFollows, buffer, bufPos);
response->size = bufPos;
@ -433,115 +427,116 @@ createNameListResponse(
void
mmsServer_handleGetNameListRequest(
MmsServerConnection connection,
uint8_t* buffer, int bufPos, int maxBufPos,
uint32_t invokeId,
ByteBuffer* response)
MmsServerConnection connection,
uint8_t* buffer, int bufPos, int maxBufPos,
uint32_t invokeId,
ByteBuffer* response)
{
int objectClass = -1;
int objectScope = -1;
char* domainId = NULL;
int domainIdLength;
char* continueAfter = NULL;
int continueAfterLength;
while (bufPos < maxBufPos) {
uint8_t tag = buffer[bufPos++];
int length;
bufPos = BerDecoder_decodeLength(buffer, &length, bufPos, maxBufPos);
if (bufPos < 0) {
mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_INVALID_PDU, response);
return;
}
switch (tag) {
case 0xa0: /* objectClass */
bufPos++;
length = buffer[bufPos++];
objectClass = BerDecoder_decodeUint32(buffer, length, bufPos);
break;
case 0xa1: /* objectScope */
{
uint8_t objectScopeTag = buffer[bufPos++];
bufPos = BerDecoder_decodeLength(buffer, &length, bufPos, maxBufPos);
if (bufPos < 0) {
mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_INVALID_PDU, response);
return;
}
switch (objectScopeTag) {
case 0x80: /* vmd-specific */
objectScope = OBJECT_SCOPE_VMD;
break;
case 0x81: /* domain-specific */
domainIdLength = length;
domainId = (char*) (buffer + bufPos);
objectScope = OBJECT_SCOPE_DOMAIN;
break;
case 0x82: /* association-specific */
objectScope = OBJECT_SCOPE_ASSOCIATION;
break;
default:
mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_UNRECOGNIZED_MODIFIER, response);
return;
}
}
break;
case 0x82: /* continueAfter */
continueAfter = (char*) (buffer + bufPos);
continueAfterLength = length;
break;
default:
/* ignore unknown tag */
break;
}
bufPos += length;
}
char continueAfterIdMemory[130];
char* continueAfterId = NULL;
if (continueAfter != NULL) {
continueAfterId = continueAfterIdMemory;
memcpy(continueAfterId, continueAfter, continueAfterLength);
continueAfterId[continueAfterLength] = 0;
if (DEBUG_MMS_SERVER)
printf("MMS_SERVER: getNameListRequest - continue after: (%s)\n", continueAfterId);
}
if (objectScope == OBJECT_SCOPE_DOMAIN) {
char domainSpecificName[130];
memcpy(domainSpecificName, domainId, domainIdLength);
domainSpecificName[domainIdLength] = 0;
if (objectClass == OBJECT_CLASS_NAMED_VARIABLE) {
if (DEBUG_MMS_SERVER)
printf("MMS_SERVER: get namelist for (%s)\n", domainSpecificName);
LinkedList nameList = getNameListDomainSpecific(connection, domainSpecificName);
if (nameList == NULL)
mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT);
else {
createNameListResponse(connection, invokeId, nameList, response, continueAfterId);
LinkedList_destroy(nameList);
}
}
else if (objectClass == OBJECT_CLASS_JOURNAL) {
LinkedList nameList = getJournalListDomainSpecific(connection, domainSpecificName);
int objectClass = -1;
int objectScope = -1;
char* domainId = NULL;
int domainIdLength;
char* continueAfter = NULL;
int continueAfterLength;
while (bufPos < maxBufPos) {
uint8_t tag = buffer[bufPos++];
int length;
bufPos = BerDecoder_decodeLength(buffer, &length, bufPos, maxBufPos);
if (bufPos < 0) {
mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_INVALID_PDU, response);
return;
}
switch (tag)
{
case 0xa0: /* objectClass */
bufPos++;
length = buffer[bufPos++];
objectClass = BerDecoder_decodeUint32(buffer, length, bufPos);
break;
case 0xa1: /* objectScope */
{
uint8_t objectScopeTag = buffer[bufPos++];
bufPos = BerDecoder_decodeLength(buffer, &length, bufPos, maxBufPos);
if (bufPos < 0) {
mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_INVALID_PDU, response);
return;
}
switch (objectScopeTag)
{
case 0x80: /* vmd-specific */
objectScope = OBJECT_SCOPE_VMD;
break;
case 0x81: /* domain-specific */
domainIdLength = length;
domainId = (char*) (buffer + bufPos);
objectScope = OBJECT_SCOPE_DOMAIN;
break;
case 0x82: /* association-specific */
objectScope = OBJECT_SCOPE_ASSOCIATION;
break;
default:
mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_UNRECOGNIZED_MODIFIER, response);
return;
}
}
break;
case 0x82: /* continueAfter */
continueAfter = (char*) (buffer + bufPos);
continueAfterLength = length;
break;
default:
/* ignore unknown tag */
break;
}
bufPos += length;
}
char continueAfterIdMemory[130];
char* continueAfterId = NULL;
if (continueAfter != NULL) {
continueAfterId = continueAfterIdMemory;
memcpy(continueAfterId, continueAfter, continueAfterLength);
continueAfterId[continueAfterLength] = 0;
if (DEBUG_MMS_SERVER)
printf("MMS_SERVER: getNameListRequest - continue after: (%s)\n", continueAfterId);
}
if (objectScope == OBJECT_SCOPE_DOMAIN) {
char domainSpecificName[130];
memcpy(domainSpecificName, domainId, domainIdLength);
domainSpecificName[domainIdLength] = 0;
if (objectClass == OBJECT_CLASS_NAMED_VARIABLE) {
if (DEBUG_MMS_SERVER)
printf("MMS_SERVER: get namelist for (%s)\n", domainSpecificName);
LinkedList nameList = getNameListDomainSpecific(connection, domainSpecificName);
if (nameList == NULL)
mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT);
else {
createNameListResponse(connection, invokeId, nameList, response, continueAfterId);
LinkedList_destroy(nameList);
}
}
else if (objectClass == OBJECT_CLASS_JOURNAL) {
LinkedList nameList = getJournalListDomainSpecific(connection, domainSpecificName);
if (nameList == NULL)
mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT);
@ -553,117 +548,120 @@ mmsServer_handleGetNameListRequest(
createNameListResponse(connection, invokeId, nameList, response, continueAfterId);
LinkedList_destroyStatic(nameList);
}
}
}
#if (MMS_DATA_SET_SERVICE == 1)
else if (objectClass == OBJECT_CLASS_NAMED_VARIABLE_LIST) {
LinkedList nameList = getNamedVariableListsDomainSpecific(connection, domainSpecificName);
else if (objectClass == OBJECT_CLASS_NAMED_VARIABLE_LIST) {
LinkedList nameList = getNamedVariableListsDomainSpecific(connection, domainSpecificName);
if (nameList == NULL)
mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT);
else {
if (nameList == NULL)
mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT);
else {
#if (CONFIG_MMS_SORT_NAME_LIST == 1)
StringUtils_sortList(nameList);
StringUtils_sortList(nameList);
#endif
createNameListResponse(connection, invokeId, nameList, response, continueAfter);
LinkedList_destroy(nameList);
}
}
}
}
#endif /* (MMS_DATA_SET_SERVICE == 1) */
else {
if (DEBUG_MMS_SERVER) printf("MMS_SERVER: getNameList domain specific objectClass %i not supported!\n", objectClass);
else {
if (DEBUG_MMS_SERVER)
printf("MMS_SERVER: getNameList domain specific objectClass %i not supported!\n", objectClass);
mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_ACCESS_UNSUPPORTED);
}
}
mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_ACCESS_UNSUPPORTED);
}
}
else if (objectScope == OBJECT_SCOPE_VMD) { /* vmd-specific */
else if (objectScope == OBJECT_SCOPE_VMD) { /* vmd-specific */
if (objectClass == OBJECT_CLASS_DOMAIN) {
if (objectClass == OBJECT_CLASS_DOMAIN) {
LinkedList nameList = getDomainNames(connection);
LinkedList nameList = getDomainNames(connection);
#if (CONFIG_MMS_SORT_NAME_LIST == 1)
StringUtils_sortList(nameList);
StringUtils_sortList(nameList);
#endif
createNameListResponse(connection, invokeId, nameList, response, continueAfter);
createNameListResponse(connection, invokeId, nameList, response, continueAfter);
LinkedList_destroyStatic(nameList);
}
LinkedList_destroyStatic(nameList);
}
#if (CONFIG_MMS_SUPPORT_VMD_SCOPE_NAMED_VARIABLES == 1)
else if (objectClass == OBJECT_CLASS_NAMED_VARIABLE) {
else if (objectClass == OBJECT_CLASS_NAMED_VARIABLE) {
LinkedList nameList = getNameListVMDSpecific(connection);
createNameListResponse(connection, invokeId, nameList, response, continueAfter);
LinkedList_destroyStatic(nameList);
}
}
#endif /* (CONFIG_MMS_SUPPORT_VMD_SCOPE_NAMED_VARIABLES == 1) */
#if (MMS_DATA_SET_SERVICE == 1)
else if (objectClass == OBJECT_CLASS_NAMED_VARIABLE_LIST) {
LinkedList nameList = getNamedVariableListsVMDSpecific(connection);
else if (objectClass == OBJECT_CLASS_NAMED_VARIABLE_LIST) {
LinkedList nameList = getNamedVariableListsVMDSpecific(connection);
#if (CONFIG_MMS_SORT_NAME_LIST == 1)
StringUtils_sortList(nameList);
StringUtils_sortList(nameList);
#endif
createNameListResponse(connection, invokeId, nameList, response, continueAfter);
createNameListResponse(connection, invokeId, nameList, response, continueAfter);
LinkedList_destroy(nameList);
}
LinkedList_destroy(nameList);
}
#endif /* (MMS_DATA_SET_SERVICE == 1) */
else if (objectClass == OBJECT_CLASS_JOURNAL) {
LinkedList nameList = LinkedList_create();
else if (objectClass == OBJECT_CLASS_JOURNAL) {
LinkedList nameList = LinkedList_create();
#if (CONFIG_MMS_SORT_NAME_LIST == 1)
StringUtils_sortList(nameList);
StringUtils_sortList(nameList);
#endif
createNameListResponse(connection, invokeId, nameList, response, continueAfter);
createNameListResponse(connection, invokeId, nameList, response, continueAfter);
LinkedList_destroy(nameList);
}
LinkedList_destroy(nameList);
}
else {
if (DEBUG_MMS_SERVER) printf("MMS_SERVER: getNameList VMD specific objectClass %i not supported!\n", objectClass);
if (DEBUG_MMS_SERVER)
printf("MMS_SERVER: getNameList VMD specific objectClass %i not supported!\n", objectClass);
mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_ACCESS_UNSUPPORTED);
}
}
}
#if (MMS_DATA_SET_SERVICE == 1)
#if (MMS_DYNAMIC_DATA_SETS == 1)
else if (objectScope == OBJECT_SCOPE_ASSOCIATION) { /* association-specific */
else if (objectScope == OBJECT_SCOPE_ASSOCIATION) { /* association-specific */
if (objectClass == OBJECT_CLASS_NAMED_VARIABLE_LIST) {
LinkedList nameList = getNamedVariableListAssociationSpecific(connection);
if (objectClass == OBJECT_CLASS_NAMED_VARIABLE_LIST) {
LinkedList nameList = getNamedVariableListAssociationSpecific(connection);
#if (CONFIG_MMS_SORT_NAME_LIST == 1)
StringUtils_sortList(nameList);
StringUtils_sortList(nameList);
#endif
createNameListResponse(connection, invokeId, nameList, response, continueAfter);
createNameListResponse(connection, invokeId, nameList, response, continueAfter);
LinkedList_destroy(nameList);
}
else
mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_ACCESS_UNSUPPORTED);
}
LinkedList_destroy(nameList);
}
else
mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_ACCESS_UNSUPPORTED);
}
#endif /* (MMS_DYNAMIC_DATA_SETS == 1) */
#endif /* (MMS_DATA_SET_SERVICE == 1) */
else {
if (DEBUG_MMS_SERVER) printf("MMS_SERVER: getNameList(%i) not supported!\n", objectScope);
mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_ACCESS_UNSUPPORTED);
}
else {
if (DEBUG_MMS_SERVER)
printf("MMS_SERVER: getNameList(%i) not supported!\n", objectScope);
}
mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_ACCESS_UNSUPPORTED);
}
}
#endif /* (MMS_GET_NAME_LIST == 1) */

@ -83,8 +83,8 @@ mmsMsg_encodeMmsRejectPdu(uint32_t* invokeId, int rejectType, int rejectReason,
if (invokeId != NULL) {
/* original invokeId */
bufPos = BerEncoder_encodeTL(0x80, invokeIdLength, buffer, bufPos);
bufPos = BerEncoder_encodeUInt32(*invokeId, buffer, bufPos);
bufPos = BerEncoder_encodeTL(0x80, invokeIdLength, buffer, bufPos);
bufPos = BerEncoder_encodeUInt32(*invokeId, buffer, bufPos);
}
buffer[bufPos++] = (uint8_t) (0x80 + rejectType);
@ -100,7 +100,8 @@ mmsMsg_createMmsRejectPdu(uint32_t* invokeId, int reason, ByteBuffer* response)
int rejectType = 0;
int rejectReason = 0;
switch (reason) {
switch (reason)
{
case MMS_ERROR_REJECT_UNRECOGNIZED_SERVICE:
rejectType = MMS_REJECT_CONFIRMED_REQUEST;
@ -136,42 +137,43 @@ mmsMsg_createMmsRejectPdu(uint32_t* invokeId, int reason, ByteBuffer* response)
static void
handleConfirmedRequestPdu(
MmsServerConnection self,
uint8_t* buffer, int bufPos, int maxBufPos,
ByteBuffer* response)
MmsServerConnection self,
uint8_t* buffer, int bufPos, int maxBufPos,
ByteBuffer* response)
{
uint32_t invokeId = 0;
uint32_t invokeId = 0;
while (bufPos < maxBufPos) {
uint8_t tag = buffer[bufPos++];
int length;
while (bufPos < maxBufPos) {
uint8_t tag = buffer[bufPos++];
int length;
bool extendedTag = false;
bool extendedTag = false;
if ((tag & 0x1f) == 0x1f) {
extendedTag = true;
tag = buffer[bufPos++];
}
if ((tag & 0x1f) == 0x1f) {
extendedTag = true;
tag = buffer[bufPos++];
}
bufPos = BerDecoder_decodeLength(buffer, &length, bufPos, maxBufPos);
bufPos = BerDecoder_decodeLength(buffer, &length, bufPos, maxBufPos);
if (bufPos < 0) {
mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_INVALID_PDU, response);
return;
if (bufPos < 0) {
mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_INVALID_PDU, response);
return;
}
if (bufPos + length > maxBufPos) {
mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_INVALID_PDU, response);
return;
}
if (extendedTag) {
switch(tag) {
if (extendedTag) {
switch (tag)
{
#if (MMS_OBTAIN_FILE_SERVICE == 1)
case 0x2e: /* obtain-file */
mmsServer_handleObtainFileRequest(self, buffer, bufPos, bufPos + length, invokeId, response);
break;
case 0x2e: /* obtain-file */
mmsServer_handleObtainFileRequest(self, buffer, bufPos, bufPos + length, invokeId, response);
break;
#endif /* MMS_OBTAIN_FILE_SERVICE == 1 */
#if (MMS_JOURNAL_SERVICE == 1)
@ -181,39 +183,40 @@ handleConfirmedRequestPdu(
#endif /* (MMS_JOURNAL_SERVICE == 1) */
#if (MMS_FILE_SERVICE == 1)
case 0x48: /* file-open-request */
mmsServer_handleFileOpenRequest(self, buffer, bufPos, bufPos + length, invokeId, response);
break;
case 0x48: /* file-open-request */
mmsServer_handleFileOpenRequest(self, buffer, bufPos, bufPos + length, invokeId, response);
break;
case 0x49: /* file-read-request */
mmsServer_handleFileReadRequest(self, buffer, bufPos, bufPos + length, invokeId, response);
break;
case 0x49: /* file-read-request */
mmsServer_handleFileReadRequest(self, buffer, bufPos, bufPos + length, invokeId, response);
break;
case 0x4a: /* file-close-request */
mmsServer_handleFileCloseRequest(self, buffer, bufPos, bufPos + length, invokeId, response);
break;
case 0x4a: /* file-close-request */
mmsServer_handleFileCloseRequest(self, buffer, bufPos, bufPos + length, invokeId, response);
break;
case 0x4b: /* file-rename-request */
case 0x4b: /* file-rename-request */
mmsServer_handleFileRenameRequest(self, buffer, bufPos, bufPos + length, invokeId, response);
break;
case 0x4c: /* file-delete-request */
mmsServer_handleFileDeleteRequest(self, buffer, bufPos, bufPos + length, invokeId, response);
break;
case 0x4c: /* file-delete-request */
mmsServer_handleFileDeleteRequest(self, buffer, bufPos, bufPos + length, invokeId, response);
break;
case 0x4d: /* file-directory-request */
mmsServer_handleFileDirectoryRequest(self, buffer, bufPos, bufPos + length, invokeId, response);
break;
case 0x4d: /* file-directory-request */
mmsServer_handleFileDirectoryRequest(self, buffer, bufPos, bufPos + length, invokeId, response);
break;
#endif /* MMS_FILE_SERVICE == 1 */
default:
mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_UNRECOGNIZED_SERVICE, response);
return;
break;
}
}
else {
switch(tag) {
}
}
else {
switch (tag)
{
case 0x02: /* invoke Id */
invokeId = BerDecoder_decodeUint32(buffer, length, bufPos);
if (DEBUG_MMS_SERVER)
@ -248,7 +251,7 @@ handleConfirmedRequestPdu(
#if (MMS_WRITE_SERVICE == 1)
case 0xa5: /* write-request */
mmsServer_handleWriteRequest(self, buffer, bufPos, bufPos + length,
invokeId, response);
invokeId, response);
break;
#endif /* (MMS_WRITE_SERVICE == 1) */
@ -260,7 +263,6 @@ handleConfirmedRequestPdu(
break;
#endif /* MMS_GET_VARIABLE_ACCESS_ATTRIBUTES == 1 */
#if (MMS_DYNAMIC_DATA_SETS == 1)
case 0xab: /* define-named-variable-list */
mmsServer_handleDefineNamedVariableListRequest(self,
@ -269,7 +271,6 @@ handleConfirmedRequestPdu(
break;
#endif /* (MMS_DYNAMIC_DATA_SETS == 1) */
#if (MMS_GET_DATA_SET_ATTRIBUTES == 1)
case 0xac: /* get-named-variable-list-attributes-request */
mmsServer_handleGetNamedVariableListAttributesRequest(self,
@ -291,10 +292,10 @@ handleConfirmedRequestPdu(
return;
break;
}
}
}
bufPos += length;
}
bufPos += length;
}
}
#if (MMS_OBTAIN_FILE_SERVICE == 1)
@ -334,7 +335,6 @@ handleConfirmedErrorPdu(
}
}
static MmsObtainFileTask
getUploadTaskByInvokeId(MmsServer mmsServer, uint32_t invokeId)
{
@ -381,13 +381,14 @@ handleConfirmedResponsePdu(
bufPos = BerDecoder_decodeLength(buffer, &length, bufPos, maxBufPos);
if (bufPos < 0) {
if (bufPos < 0) {
mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_UNRECOGNIZED_SERVICE, response);
return;
}
if (extendedTag) {
switch(tag) {
switch (tag)
{
#if (MMS_FILE_SERVICE == 1)
case 0x48: /* file-open-response */
@ -400,7 +401,7 @@ handleConfirmedResponsePdu(
if (fileTask != NULL) {
int32_t frmsId;
int32_t frmsId;
if (mmsMsg_parseFileOpenResponse(buffer, startBufPos, maxBufPos, &frmsId, NULL, NULL)) {
fileTask->frmsId = frmsId;
@ -487,7 +488,8 @@ handleConfirmedResponsePdu(
}
}
else {
switch(tag) {
switch (tag)
{
case 0x02: /* invoke Id */
invokeId = BerDecoder_decodeUint32(buffer, length, bufPos);
if (DEBUG_MMS_SERVER)
@ -512,58 +514,59 @@ MmsServerConnection_parseMessage(MmsServerConnection self, ByteBuffer* message,
{
uint8_t* buffer = message->buffer;
if (message->size < 2)
goto parsing_error;
if (message->size < 2)
goto parsing_error;
int bufPos = 0;
int bufPos = 0;
uint8_t pduType = buffer[bufPos++];
int pduLength;
uint8_t pduType = buffer[bufPos++];
int pduLength;
bufPos = BerDecoder_decodeLength(buffer, &pduLength, bufPos, message->size);
bufPos = BerDecoder_decodeLength(buffer, &pduLength, bufPos, message->size);
if (bufPos < 0)
goto parsing_error;
if (bufPos < 0)
goto parsing_error;
if (DEBUG_MMS_SERVER)
printf("MMS_SERVER: recvd MMS-PDU type: %02x size: %i\n", pduType, pduLength);
if (DEBUG_MMS_SERVER)
printf("MMS_SERVER: recvd MMS-PDU type: %02x size: %i\n", pduType, pduLength);
switch (pduType) {
case 0xa8: /* Initiate request PDU */
mmsServer_handleInitiateRequest(self, buffer, bufPos, bufPos + pduLength, response);
break;
switch (pduType)
{
case 0xa8: /* Initiate request PDU */
mmsServer_handleInitiateRequest(self, buffer, bufPos, bufPos + pduLength, response);
break;
case 0xa0: /* Confirmed request PDU */
handleConfirmedRequestPdu(self, buffer, bufPos, bufPos + pduLength, response);
break;
case 0xa0: /* Confirmed request PDU */
handleConfirmedRequestPdu(self, buffer, bufPos, bufPos + pduLength, response);
break;
#if (MMS_OBTAIN_FILE_SERVICE == 1)
case 0xa1: /* Confirmed response PDU */
handleConfirmedResponsePdu(self, buffer, bufPos, bufPos + pduLength, response);
break;
case 0xa1: /* Confirmed response PDU */
handleConfirmedResponsePdu(self, buffer, bufPos, bufPos + pduLength, response);
break;
case 0xa2: /* Confirmed error PDU */
handleConfirmedErrorPdu(self, buffer, 0, bufPos + pduLength, response);
break;
case 0xa2: /* Confirmed error PDU */
handleConfirmedErrorPdu(self, buffer, 0, bufPos + pduLength, response);
break;
#endif /* (MMS_OBTAIN_FILE_SERVICE == 1) */
case 0x8b: /* Conclude request PDU */
mmsServer_writeConcludeResponsePdu(response);
break;
case 0x8b: /* Conclude request PDU */
mmsServer_writeConcludeResponsePdu(response);
break;
case 0xa4: /* Reject PDU - silently ignore */
if (DEBUG_MMS_SERVER)
printf("MMS_SERVER: received reject PDU!\n");
break;
case 0xa4: /* Reject PDU - silently ignore */
if (DEBUG_MMS_SERVER)
printf("MMS_SERVER: received reject PDU!\n");
break;
default:
mmsMsg_createMmsRejectPdu(NULL, MMS_ERROR_REJECT_UNKNOWN_PDU_TYPE, response);
break;
}
default:
mmsMsg_createMmsRejectPdu(NULL, MMS_ERROR_REJECT_UNKNOWN_PDU_TYPE, response);
break;
}
return;
return;
parsing_error:
parsing_error:
if (DEBUG_MMS_SERVER)
printf("MMS_SERVER: error parsing message\n");
@ -573,9 +576,9 @@ parsing_error:
static void /* will be called by IsoConnection */
messageReceived(void* parameter, ByteBuffer* message, ByteBuffer* response)
{
MmsServerConnection self = (MmsServerConnection) parameter;
MmsServerConnection self = (MmsServerConnection) parameter;
MmsServerConnection_parseMessage(self, message, response);
MmsServerConnection_parseMessage(self, message, response);
}
/**********************************************************************************************
@ -585,31 +588,31 @@ messageReceived(void* parameter, ByteBuffer* message, ByteBuffer* response)
MmsServerConnection
MmsServerConnection_init(MmsServerConnection connection, MmsServer server, IsoConnection isoCon)
{
MmsServerConnection self;
MmsServerConnection self;
if (connection == NULL)
self = (MmsServerConnection) GLOBAL_CALLOC(1, sizeof(struct sMmsServerConnection));
else
self = connection;
if (connection == NULL)
self = (MmsServerConnection) GLOBAL_CALLOC(1, sizeof(struct sMmsServerConnection));
else
self = connection;
self->maxServOutstandingCalled = 0;
self->maxServOutstandingCalling = 0;
self->maxPduSize = CONFIG_MMS_MAXIMUM_PDU_SIZE;
self->dataStructureNestingLevel = 0;
self->server = server;
self->isoConnection = isoCon;
self->maxServOutstandingCalled = 0;
self->maxServOutstandingCalling = 0;
self->maxPduSize = CONFIG_MMS_MAXIMUM_PDU_SIZE;
self->dataStructureNestingLevel = 0;
self->server = server;
self->isoConnection = isoCon;
#if (MMS_DYNAMIC_DATA_SETS == 1)
self->namedVariableLists = LinkedList_create();
self->namedVariableLists = LinkedList_create();
#endif
#if (MMS_OBTAIN_FILE_SERVICE == 1)
self->lastRequestInvokeId = 0;
self->lastRequestInvokeId = 0;
#endif
IsoConnection_installListener(isoCon, messageReceived, (void*) self);
IsoConnection_installListener(isoCon, messageReceived, (void*) self);
return self;
return self;
}
void
@ -625,27 +628,27 @@ MmsServerConnection_destroy(MmsServerConnection self)
#endif
#if (MMS_DYNAMIC_DATA_SETS == 1)
LinkedList_destroyDeep(self->namedVariableLists, (LinkedListValueDeleteFunction) MmsNamedVariableList_destroy);
LinkedList_destroyDeep(self->namedVariableLists, (LinkedListValueDeleteFunction) MmsNamedVariableList_destroy);
#endif
GLOBAL_FREEMEM(self);
GLOBAL_FREEMEM(self);
}
#if (MMS_DYNAMIC_DATA_SETS == 1)
bool
MmsServerConnection_addNamedVariableList(MmsServerConnection self, MmsNamedVariableList variableList)
{
//TODO check if operation is allowed!
//TODO check if operation is allowed!
LinkedList_add(self->namedVariableLists, variableList);
LinkedList_add(self->namedVariableLists, variableList);
return true;
return true;
}
void
MmsServerConnection_deleteNamedVariableList(MmsServerConnection self, char* listName)
{
mmsServer_deleteVariableList(self->namedVariableLists, listName);
mmsServer_deleteVariableList(self->namedVariableLists, listName);
}
MmsNamedVariableList
@ -655,11 +658,10 @@ MmsServerConnection_getNamedVariableList(MmsServerConnection self, const char* v
}
#endif /* (MMS_DYNAMIC_DATA_SETS == 1) */
char*
MmsServerConnection_getClientAddress(MmsServerConnection self)
{
return IsoConnection_getPeerAddress(self->isoConnection);
return IsoConnection_getPeerAddress(self->isoConnection);
}
IsoConnection
@ -672,7 +674,7 @@ MmsServerConnection_getIsoConnection(MmsServerConnection self)
LinkedList
MmsServerConnection_getNamedVariableLists(MmsServerConnection self)
{
return self->namedVariableLists;
return self->namedVariableLists;
}
#endif /* (MMS_DYNAMIC_DATA_SETS == 1) */
@ -691,7 +693,6 @@ MmsServerConnection_getNextRequestInvokeId(MmsServerConnection self)
}
#endif /* (MMS_OBTAIN_FILE_SERVICE == 1) */
const char*
MmsServerConnection_getFilesystemBasepath(MmsServerConnection self)
{

Loading…
Cancel
Save