- some code reformating

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

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

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

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

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

@ -31,186 +31,188 @@
#include "mms_client_internal.h" #include "mms_client_internal.h"
static MmsVariableSpecification* static MmsVariableSpecification*
createTypeSpecification(TypeSpecification_t* asnTypeSpec) { createTypeSpecification(TypeSpecification_t* asnTypeSpec)
MmsVariableSpecification* typeSpec = (MmsVariableSpecification*) {
GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification)); MmsVariableSpecification* typeSpec = (MmsVariableSpecification*)
GLOBAL_CALLOC(1, sizeof(MmsVariableSpecification));
switch (asnTypeSpec->present) {
case TypeSpecification_PR_structure: switch (asnTypeSpec->present)
{ {
typeSpec->type = MMS_STRUCTURE; case TypeSpecification_PR_structure:
{
int elementCount = asnTypeSpec->choice.structure.components.list.count; typeSpec->type = MMS_STRUCTURE;
typeSpec->typeSpec.structure.elementCount = elementCount;
int elementCount = asnTypeSpec->choice.structure.components.list.count;
typeSpec->typeSpec.structure.elements = (MmsVariableSpecification**) typeSpec->typeSpec.structure.elementCount = elementCount;
GLOBAL_CALLOC(elementCount, sizeof(MmsVariableSpecification*));
typeSpec->typeSpec.structure.elements = (MmsVariableSpecification**)
int i; GLOBAL_CALLOC(elementCount, sizeof(MmsVariableSpecification*));
for (i = 0; i < elementCount; i++) { int i;
char* name = StringUtils_createStringFromBuffer( for (i = 0; i < elementCount; i++) {
asnTypeSpec->choice.structure.components.list.array[i]->componentName->buf,
asnTypeSpec->choice.structure.components.list.array[i]->componentName->size); char* name = StringUtils_createStringFromBuffer(
asnTypeSpec->choice.structure.components.list.array[i]->componentName->buf,
typeSpec->typeSpec.structure.elements[i] = asnTypeSpec->choice.structure.components.list.array[i]->componentName->size);
createTypeSpecification(asnTypeSpec->choice.structure.components.
list.array[i]->componentType); typeSpec->typeSpec.structure.elements[i] =
createTypeSpecification(asnTypeSpec->choice.structure.components.
typeSpec->typeSpec.structure.elements[i]->name = name; list.array[i]->componentType);
}
} typeSpec->typeSpec.structure.elements[i]->name = name;
break; }
case TypeSpecification_PR_array: }
{ break;
typeSpec->type = MMS_ARRAY; case TypeSpecification_PR_array:
{
long elementCount; typeSpec->type = MMS_ARRAY;
asn_INTEGER2long(&asnTypeSpec->choice.array.numberOfElements, &elementCount);
long elementCount;
typeSpec->typeSpec.array.elementCount = elementCount; asn_INTEGER2long(&asnTypeSpec->choice.array.numberOfElements, &elementCount);
typeSpec->typeSpec.array.elementTypeSpec = typeSpec->typeSpec.array.elementCount = elementCount;
createTypeSpecification(asnTypeSpec->choice.array.elementType);
} typeSpec->typeSpec.array.elementTypeSpec =
break; createTypeSpecification(asnTypeSpec->choice.array.elementType);
case TypeSpecification_PR_boolean: }
typeSpec->type = MMS_BOOLEAN; break;
break; case TypeSpecification_PR_boolean:
case TypeSpecification_PR_bitstring: typeSpec->type = MMS_BOOLEAN;
typeSpec->type = MMS_BIT_STRING; break;
typeSpec->typeSpec.bitString = asnTypeSpec->choice.bitstring; case TypeSpecification_PR_bitstring:
break; typeSpec->type = MMS_BIT_STRING;
case TypeSpecification_PR_integer: typeSpec->typeSpec.bitString = asnTypeSpec->choice.bitstring;
typeSpec->type = MMS_INTEGER; break;
typeSpec->typeSpec.integer = asnTypeSpec->choice.integer; case TypeSpecification_PR_integer:
break; typeSpec->type = MMS_INTEGER;
case TypeSpecification_PR_unsigned: typeSpec->typeSpec.integer = asnTypeSpec->choice.integer;
typeSpec->type = MMS_UNSIGNED; break;
typeSpec->typeSpec.unsignedInteger = asnTypeSpec->choice.Unsigned; case TypeSpecification_PR_unsigned:
break; typeSpec->type = MMS_UNSIGNED;
case TypeSpecification_PR_floatingpoint: typeSpec->typeSpec.unsignedInteger = asnTypeSpec->choice.Unsigned;
typeSpec->type = MMS_FLOAT; break;
typeSpec->typeSpec.floatingpoint.exponentWidth = case TypeSpecification_PR_floatingpoint:
asnTypeSpec->choice.floatingpoint.exponentwidth; typeSpec->type = MMS_FLOAT;
typeSpec->typeSpec.floatingpoint.formatWidth = typeSpec->typeSpec.floatingpoint.exponentWidth =
asnTypeSpec->choice.floatingpoint.formatwidth; asnTypeSpec->choice.floatingpoint.exponentwidth;
break; typeSpec->typeSpec.floatingpoint.formatWidth =
case TypeSpecification_PR_octetstring: asnTypeSpec->choice.floatingpoint.formatwidth;
typeSpec->type = MMS_OCTET_STRING; break;
typeSpec->typeSpec.octetString = asnTypeSpec->choice.octetstring; case TypeSpecification_PR_octetstring:
break; typeSpec->type = MMS_OCTET_STRING;
case TypeSpecification_PR_visiblestring: typeSpec->typeSpec.octetString = asnTypeSpec->choice.octetstring;
typeSpec->type = MMS_VISIBLE_STRING; break;
typeSpec->typeSpec.visibleString = asnTypeSpec->choice.visiblestring; case TypeSpecification_PR_visiblestring:
break; typeSpec->type = MMS_VISIBLE_STRING;
case TypeSpecification_PR_mMSString: typeSpec->typeSpec.visibleString = asnTypeSpec->choice.visiblestring;
typeSpec->type = MMS_STRING; break;
typeSpec->typeSpec.mmsString = asnTypeSpec->choice.mMSString; case TypeSpecification_PR_mMSString:
break; typeSpec->type = MMS_STRING;
case TypeSpecification_PR_utctime: typeSpec->typeSpec.mmsString = asnTypeSpec->choice.mMSString;
typeSpec->type = MMS_UTC_TIME; break;
break; case TypeSpecification_PR_utctime:
case TypeSpecification_PR_binarytime: typeSpec->type = MMS_UTC_TIME;
typeSpec->type = MMS_BINARY_TIME; break;
if (asnTypeSpec->choice.binarytime == 0) case TypeSpecification_PR_binarytime:
typeSpec->typeSpec.binaryTime = 4; typeSpec->type = MMS_BINARY_TIME;
else if (asnTypeSpec->choice.binarytime == 0)
typeSpec->typeSpec.binaryTime = 6; typeSpec->typeSpec.binaryTime = 4;
break; else
default: typeSpec->typeSpec.binaryTime = 6;
printf("ERROR: unknown type in type specification\n"); break;
break; default:
} printf("ERROR: unknown type in type specification\n");
break;
return typeSpec; }
return typeSpec;
} }
MmsVariableSpecification* MmsVariableSpecification*
mmsClient_parseGetVariableAccessAttributesResponse(ByteBuffer* message, uint32_t* invokeId) mmsClient_parseGetVariableAccessAttributesResponse(ByteBuffer* message, uint32_t* invokeId)
{ {
MmsPdu_t* mmsPdu = 0; /* allow asn1c to allocate structure */ MmsPdu_t* mmsPdu = 0; /* allow asn1c to allocate structure */
MmsVariableSpecification* typeSpec = NULL; MmsVariableSpecification* typeSpec = NULL;
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)); (void**) &mmsPdu, ByteBuffer_getBuffer(message), ByteBuffer_getSize(message));
if (rval.code != RC_OK) if (rval.code != RC_OK)
return NULL; return NULL;
if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) { if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) {
if (invokeId != NULL) if (invokeId != NULL)
*invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu); *invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu);
if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present == if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present ==
ConfirmedServiceResponse_PR_getVariableAccessAttributes) ConfirmedServiceResponse_PR_getVariableAccessAttributes)
{ {
GetVariableAccessAttributesResponse_t* response; GetVariableAccessAttributesResponse_t* response;
response = &(mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.choice.getVariableAccessAttributes); response = &(mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.choice.getVariableAccessAttributes);
TypeSpecification_t* asnTypeSpec = &response->typeSpecification; 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 int
mmsClient_createGetVariableAccessAttributesRequest( mmsClient_createGetVariableAccessAttributesRequest(
uint32_t invokeId, uint32_t invokeId,
const char* domainId, const char* itemId, const char* domainId, const char* itemId,
ByteBuffer* writeBuffer) ByteBuffer* writeBuffer)
{ {
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId); MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present = mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present =
ConfirmedServiceRequest_PR_getVariableAccessAttributes; ConfirmedServiceRequest_PR_getVariableAccessAttributes;
GetVariableAccessAttributesRequest_t* request; GetVariableAccessAttributesRequest_t* request;
request = request =
&(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.getVariableAccessAttributes); &(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.present = ObjectName_PR_domainspecific;
request->choice.name.choice.domainspecific.domainId.buf = (uint8_t*) domainId; request->choice.name.choice.domainspecific.domainId.buf = (uint8_t*) domainId;
request->choice.name.choice.domainspecific.domainId.size = strlen(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.buf = (uint8_t*) itemId;
request->choice.name.choice.domainspecific.itemId.size = strlen(itemId); request->choice.name.choice.domainspecific.itemId.size = strlen(itemId);
} }
else { else {
request->choice.name.present = ObjectName_PR_vmdspecific; request->choice.name.present = ObjectName_PR_vmdspecific;
request->choice.name.choice.vmdspecific.buf = (uint8_t*) itemId; request->choice.name.choice.vmdspecific.buf = (uint8_t*) itemId;
request->choice.name.choice.vmdspecific.size = strlen(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, rval = der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer); (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.buf = 0;
request->choice.name.choice.domainspecific.domainId.size = 0; request->choice.name.choice.domainspecific.domainId.size = 0;
request->choice.name.choice.domainspecific.itemId.buf = 0; request->choice.name.choice.domainspecific.itemId.buf = 0;
request->choice.name.choice.domainspecific.itemId.size = 0; request->choice.name.choice.domainspecific.itemId.size = 0;
} }
else { else {
request->choice.name.choice.vmdspecific.buf = 0; request->choice.name.choice.vmdspecific.buf = 0;
request->choice.name.choice.vmdspecific.size = 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 void
mmsClient_createDeleteAssociationSpecificNamedVariableListRequest( mmsClient_createDeleteAssociationSpecificNamedVariableListRequest(
long invokeId, long invokeId,
ByteBuffer* writeBuffer, ByteBuffer* writeBuffer,
const char* listNameId) const char* listNameId)
{ {
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId); MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present = mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present =
ConfirmedServiceRequest_PR_deleteNamedVariableList; ConfirmedServiceRequest_PR_deleteNamedVariableList;
DeleteNamedVariableListRequest_t* request = DeleteNamedVariableListRequest_t* request =
&(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.deleteNamedVariableList); &(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.deleteNamedVariableList);
request->listOfVariableListName = (struct DeleteNamedVariableListRequest__listOfVariableListName*) GLOBAL_CALLOC(1, request->listOfVariableListName = (struct DeleteNamedVariableListRequest__listOfVariableListName*) GLOBAL_CALLOC(1,
sizeof(struct DeleteNamedVariableListRequest__listOfVariableListName)); sizeof(struct DeleteNamedVariableListRequest__listOfVariableListName));
request->listOfVariableListName->list.count = 1; request->listOfVariableListName->list.count = 1;
request->listOfVariableListName->list.size = 1; request->listOfVariableListName->list.size = 1;
request->listOfVariableListName->list.array = (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] = (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.size = strlen(listNameId);
request->listOfVariableListName->list.array[0]->choice.aaspecific.buf = (uint8_t*) StringUtils_copyString(listNameId); request->listOfVariableListName->list.array[0]->choice.aaspecific.buf = (uint8_t*) StringUtils_copyString(listNameId);
request->scopeOfDelete = (INTEGER_t*) GLOBAL_CALLOC(1, sizeof(INTEGER_t)); request->scopeOfDelete = (INTEGER_t*) GLOBAL_CALLOC(1, sizeof(INTEGER_t));
asn_long2INTEGER(request->scopeOfDelete, DeleteNamedVariableListRequest__scopeOfDelete_specific); asn_long2INTEGER(request->scopeOfDelete, DeleteNamedVariableListRequest__scopeOfDelete_specific);
der_encode(&asn_DEF_MmsPdu, mmsPdu, der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer); (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 bool
mmsClient_parseDeleteNamedVariableListResponse(ByteBuffer* message, uint32_t* invokeId) 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, asn_dec_rval_t rval = ber_decode(NULL, &asn_DEF_MmsPdu,
(void**) &mmsPdu, ByteBuffer_getBuffer(message), ByteBuffer_getSize(message)); (void**) &mmsPdu, ByteBuffer_getBuffer(message), ByteBuffer_getSize(message));
if (rval.code == RC_OK) { if (rval.code == RC_OK) {
if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) { if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) {
if (invokeId != NULL) if (invokeId != NULL)
*invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu); *invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu);
if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present == if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present ==
ConfirmedServiceResponse_PR_deleteNamedVariableList) ConfirmedServiceResponse_PR_deleteNamedVariableList)
{ {
DeleteNamedVariableListResponse_t* response = DeleteNamedVariableListResponse_t* response =
&(mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.choice.deleteNamedVariableList); &(mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.choice.deleteNamedVariableList);
long numberDeleted; long numberDeleted;
asn_INTEGER2long(&(response->numberDeleted), &numberDeleted); asn_INTEGER2long(&(response->numberDeleted), &numberDeleted);
if (numberDeleted == 1) if (numberDeleted == 1)
retVal = true; 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 void
mmsClient_createGetNamedVariableListAttributesRequest(uint32_t invokeId, ByteBuffer* writeBuffer, 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 = mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present =
ConfirmedServiceRequest_PR_getNamedVariableListAttributes; ConfirmedServiceRequest_PR_getNamedVariableListAttributes;
GetNamedVariableListAttributesRequest_t* request = GetNamedVariableListAttributesRequest_t* request =
&(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.getNamedVariableListAttributes); &(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.getNamedVariableListAttributes);
if (domainId != NULL) { if (domainId != NULL) {
request->present = ObjectName_PR_domainspecific; request->present = ObjectName_PR_domainspecific;
request->choice.domainspecific.domainId.size = strlen(domainId); 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.size = strlen(listNameId);
request->choice.domainspecific.itemId.buf = (uint8_t*) StringUtils_copyString(listNameId); request->choice.domainspecific.itemId.buf = (uint8_t*) StringUtils_copyString(listNameId);
} }
else { else {
request->present = ObjectName_PR_vmdspecific; request->present = ObjectName_PR_vmdspecific;
request->choice.vmdspecific.size = strlen(listNameId); request->choice.vmdspecific.size = strlen(listNameId);
request->choice.vmdspecific.buf = (uint8_t*) StringUtils_copyString(listNameId); request->choice.vmdspecific.buf = (uint8_t*) StringUtils_copyString(listNameId);
} }
der_encode(&asn_DEF_MmsPdu, mmsPdu, der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer); (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 void
@ -195,7 +194,7 @@ mmsClient_createGetNamedVariableListAttributesRequestAssociationSpecific(uint32_
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId); MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present = mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present =
ConfirmedServiceRequest_PR_getNamedVariableListAttributes; ConfirmedServiceRequest_PR_getNamedVariableListAttributes;
GetNamedVariableListAttributesRequest_t* request = GetNamedVariableListAttributesRequest_t* request =
&(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.getNamedVariableListAttributes); &(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.getNamedVariableListAttributes);
@ -214,102 +213,98 @@ mmsClient_createGetNamedVariableListAttributesRequestAssociationSpecific(uint32_
static LinkedList /* <MmsVariableAccessSpecification*> */ static LinkedList /* <MmsVariableAccessSpecification*> */
parseNamedVariableAttributes(GetNamedVariableListAttributesResponse_t* response, bool* deletable) parseNamedVariableAttributes(GetNamedVariableListAttributesResponse_t* response, bool* deletable)
{ {
if (deletable != NULL) if (deletable != NULL)
*deletable = response->mmsDeletable; *deletable = response->mmsDeletable;
int attributesCount = response->listOfVariable.list.count;
int i;
LinkedList attributes = LinkedList_create(); int attributesCount = response->listOfVariable.list.count;
int i;
for (i = 0; i < attributesCount; i++) { LinkedList attributes = LinkedList_create();
char* domainId; for (i = 0; i < attributesCount; i++) {
char* itemId;
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]-> itemId = mmsMsg_createStringFromAsnIdentifier(response->listOfVariable.list.array[i]->
variableSpecification.choice.name.choice.vmdspecific); variableSpecification.choice.name.choice.vmdspecific);
} }
else { else {
domainId = mmsMsg_createStringFromAsnIdentifier(response->listOfVariable.list.array[i]-> domainId = mmsMsg_createStringFromAsnIdentifier(response->listOfVariable.list.array[i]->
variableSpecification.choice.name.choice.domainspecific.domainId); variableSpecification.choice.name.choice.domainspecific.domainId);
itemId = mmsMsg_createStringFromAsnIdentifier(response->listOfVariable.list.array[i]-> itemId = mmsMsg_createStringFromAsnIdentifier(response->listOfVariable.list.array[i]->
variableSpecification.choice.name.choice.domainspecific.itemId); 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*> */ LinkedList /* <MmsVariableAccessSpecification*> */
mmsClient_parseGetNamedVariableListAttributesResponse(ByteBuffer* message, uint32_t* invokeId, mmsClient_parseGetNamedVariableListAttributesResponse(ByteBuffer* message, uint32_t* invokeId, bool* /*OUT*/deletable)
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, asn_dec_rval_t rval = ber_decode(NULL, &asn_DEF_MmsPdu,
(void**) &mmsPdu, ByteBuffer_getBuffer(message), ByteBuffer_getSize(message)); (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 (invokeId != NULL)
if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) { *invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu);
if (invokeId != NULL) if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present ==
*invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu); ConfirmedServiceResponse_PR_getNamedVariableListAttributes)
{
if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present == attributes = parseNamedVariableAttributes(
ConfirmedServiceResponse_PR_getNamedVariableListAttributes) &(mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.choice.getNamedVariableListAttributes),
{ deletable);
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 void
mmsClient_createDefineNamedVariableListRequest( mmsClient_createDefineNamedVariableListRequest(
uint32_t invokeId, uint32_t invokeId,
ByteBuffer* writeBuffer, ByteBuffer* writeBuffer,
const char* domainId, const char* domainId,
const char* listNameId, const char* listNameId,
LinkedList /*<MmsVariableSpecification*>*/ listOfVariables, LinkedList /*<MmsVariableSpecification*>*/listOfVariables,
bool associationSpecific) bool associationSpecific)
{ {
MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId); MmsPdu_t* mmsPdu = mmsClient_createConfirmedRequestPdu(invokeId);
mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present = mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present =
ConfirmedServiceRequest_PR_defineNamedVariableList; ConfirmedServiceRequest_PR_defineNamedVariableList;
DefineNamedVariableListRequest_t* request = DefineNamedVariableListRequest_t* request =
&(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.defineNamedVariableList); &(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.defineNamedVariableList);
if (associationSpecific) { if (associationSpecific) {
request->variableListName.present = ObjectName_PR_aaspecific; request->variableListName.present = ObjectName_PR_aaspecific;
request->variableListName.choice.aaspecific.size = strlen(listNameId); request->variableListName.choice.aaspecific.size = strlen(listNameId);
request->variableListName.choice.aaspecific.buf = (uint8_t*) StringUtils_copyString(listNameId); request->variableListName.choice.aaspecific.buf = (uint8_t*) StringUtils_copyString(listNameId);
} }
else { else {
if (domainId != NULL) { /* domain scope */ if (domainId != NULL) { /* domain scope */
request->variableListName.present = ObjectName_PR_domainspecific; request->variableListName.present = ObjectName_PR_domainspecific;
request->variableListName.choice.domainspecific.domainId.size = strlen(domainId); 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.size = strlen(listNameId);
request->variableListName.choice.domainspecific.itemId.buf = (uint8_t*) StringUtils_copyString(listNameId); request->variableListName.choice.domainspecific.itemId.buf = (uint8_t*) StringUtils_copyString(listNameId);
} }
else { /* VMD scope */ else { /* VMD scope */
request->variableListName.present = ObjectName_PR_vmdspecific; 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); 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.count = listSize;
request->listOfVariable.list.size = listSize; request->listOfVariable.list.size = listSize;
request->listOfVariable.list.array = request->listOfVariable.list.array =
(struct DefineNamedVariableListRequest__listOfVariable__Member**) GLOBAL_CALLOC(listSize, sizeof(void*)); (struct DefineNamedVariableListRequest__listOfVariable__Member**) GLOBAL_CALLOC(listSize, sizeof(void*));
int i = 0; int i = 0;
LinkedList element = LinkedList_getNext(listOfVariables); LinkedList element = LinkedList_getNext(listOfVariables);
while (i < listSize) { 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)); GLOBAL_CALLOC(1, sizeof(struct DefineNamedVariableListRequest__listOfVariable__Member));
request->listOfVariable.list.array[i]->variableSpecification.present = request->listOfVariable.list.array[i]->variableSpecification.present =
VariableSpecification_PR_name; VariableSpecification_PR_name;
request->listOfVariable.list.array[i]->variableSpecification.choice.name.present = request->listOfVariable.list.array[i]->variableSpecification.choice.name.present =
ObjectName_PR_domainspecific; ObjectName_PR_domainspecific;
request->listOfVariable.list.array[i]->variableSpecification.choice.name.choice. request->listOfVariable.list.array[i]->variableSpecification.choice.name.choice.
domainspecific.domainId.size = strlen(variableSpec->domainId); domainspecific.domainId.size = strlen(variableSpec->domainId);
request->listOfVariable.list.array[i]->variableSpecification.choice.name.choice. request->listOfVariable.list.array[i]->variableSpecification.choice.name.choice.
domainspecific.domainId.buf = (uint8_t*) StringUtils_copyString(variableSpec->domainId); domainspecific.domainId.buf = (uint8_t*) StringUtils_copyString(variableSpec->domainId);
request->listOfVariable.list.array[i]->variableSpecification.choice.name.choice. request->listOfVariable.list.array[i]->variableSpecification.choice.name.choice.
domainspecific.itemId.size = strlen(variableSpec->itemId); domainspecific.itemId.size = strlen(variableSpec->itemId);
request->listOfVariable.list.array[i]->variableSpecification.choice.name.choice. request->listOfVariable.list.array[i]->variableSpecification.choice.name.choice.
domainspecific.itemId.buf = (uint8_t*) StringUtils_copyString(variableSpec->itemId); domainspecific.itemId.buf = (uint8_t*) StringUtils_copyString(variableSpec->itemId);
//TODO add alternate access //TODO add alternate access
if (variableSpec->arrayIndex != -1) { if (variableSpec->arrayIndex != -1) {
AlternateAccess_t* alternateAccess = (AlternateAccess_t*) GLOBAL_CALLOC(1, sizeof(AlternateAccess_t)); AlternateAccess_t* alternateAccess = (AlternateAccess_t*) GLOBAL_CALLOC(1, sizeof(AlternateAccess_t));
alternateAccess->list.count = 1; alternateAccess->list.count = 1;
alternateAccess->list.array = (struct AlternateAccess__Member**) GLOBAL_CALLOC(1, sizeof(struct AlternateAccess__Member*)); 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] = (struct AlternateAccess__Member*) GLOBAL_CALLOC(1, sizeof(struct AlternateAccess__Member));
alternateAccess->list.array[0]->present = AlternateAccess__Member_PR_unnamed; 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 = alternateAccess->list.array[0]->choice.unnamed->present =
AlternateAccessSelection_PR_selectAlternateAccess; AlternateAccessSelection_PR_selectAlternateAccess;
alternateAccess->list.array[0]->choice.unnamed->choice.selectAlternateAccess.accessSelection.present = alternateAccess->list.array[0]->choice.unnamed->choice.selectAlternateAccess.accessSelection.present =
AlternateAccessSelection__selectAlternateAccess__accessSelection_PR_index; AlternateAccessSelection__selectAlternateAccess__accessSelection_PR_index;
asn_long2INTEGER(&(alternateAccess->list.array[0]->choice.unnamed->choice.selectAlternateAccess.accessSelection.choice.index), asn_long2INTEGER(&(alternateAccess->list.array[0]->choice.unnamed->choice.selectAlternateAccess.accessSelection.choice.index),
variableSpec->arrayIndex); 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.count = 1;
componentAccess->list.array = (struct AlternateAccess__Member**) GLOBAL_CALLOC(1, sizeof(struct AlternateAccess__Member*)); 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] = (struct AlternateAccess__Member*) GLOBAL_CALLOC(1, sizeof(struct AlternateAccess__Member));
componentAccess->list.array[0]->present = AlternateAccess__Member_PR_unnamed; 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 = (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; Identifier_t* componentIdentifier =
componentAccess->list.array[0]->choice.unnamed->choice.selectAccess.present = &(componentAccess->list.array[0]->choice.unnamed->choice.selectAccess.choice.component);
AlternateAccessSelection__selectAccess_PR_component;
Identifier_t* componentIdentifier = componentIdentifier->size = strlen(variableSpec->componentName);
&(componentAccess->list.array[0]->choice.unnamed->choice.selectAccess.choice.component); componentIdentifier->buf = (uint8_t*) StringUtils_copyString(variableSpec->componentName);
componentIdentifier->size = strlen(variableSpec->componentName); alternateAccess->list.array[0]->choice.unnamed->choice.selectAlternateAccess.alternateAccess
componentIdentifier->buf = (uint8_t*) StringUtils_copyString(variableSpec->componentName); = componentAccess;
}
alternateAccess->list.array[0]->choice.unnamed->choice.selectAlternateAccess.alternateAccess request->listOfVariable.list.array[i]->alternateAccess = alternateAccess;
= componentAccess; }
}
request->listOfVariable.list.array[i]->alternateAccess = alternateAccess; element = LinkedList_getNext(element);
}
i++;
}
element = LinkedList_getNext(element); der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
i++;
}
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 bool
mmsClient_parseDefineNamedVariableResponse(ByteBuffer* message, uint32_t* invokeId) mmsClient_parseDefineNamedVariableResponse(ByteBuffer* message, uint32_t* invokeId)
{ {
MmsPdu_t* mmsPdu = 0; MmsPdu_t* mmsPdu = 0;
bool retVal = false; bool retVal = false;
asn_dec_rval_t rval; asn_dec_rval_t rval;
rval = ber_decode(NULL, &asn_DEF_MmsPdu, rval = ber_decode(NULL, &asn_DEF_MmsPdu,
(void**) &mmsPdu, ByteBuffer_getBuffer(message), ByteBuffer_getSize(message)); (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->choice.confirmedResponsePdu.confirmedServiceResponse.present ==
if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) { ConfirmedServiceResponse_PR_defineNamedVariableList)
if (invokeId != NULL) retVal = true;
*invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu); }
}
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; AccessResult_PR presentType = accessResultList[i]->present;
if (presentType == AccessResult_PR_failure) { 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) { if (accessResultList[i]->choice.failure.size > 0) {
int errorCode = (int) accessResultList[i]->choice.failure.buf[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; int size = accessResultList[i]->choice.bitstring.size;
value->value.bitString.size = (size * 8) 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); value->value.bitString.buf = (uint8_t*) GLOBAL_MALLOC(size);
memcpy(value->value.bitString.buf, memcpy(value->value.bitString.buf,
@ -113,14 +114,14 @@ mmsClient_parseListOfAccessResults(AccessResult_t** accessResultList, int listSi
else if (presentType == AccessResult_PR_integer) { else if (presentType == AccessResult_PR_integer) {
Asn1PrimitiveValue* berInteger = Asn1PrimitiveValue* berInteger =
BerInteger_createFromBuffer(accessResultList[i]->choice.integer.buf, BerInteger_createFromBuffer(accessResultList[i]->choice.integer.buf,
accessResultList[i]->choice.integer.size); accessResultList[i]->choice.integer.size);
value = MmsValue_newIntegerFromBerInteger(berInteger); value = MmsValue_newIntegerFromBerInteger(berInteger);
} }
else if (presentType == AccessResult_PR_unsigned) { else if (presentType == AccessResult_PR_unsigned) {
Asn1PrimitiveValue* berInteger = Asn1PrimitiveValue* berInteger =
BerInteger_createFromBuffer(accessResultList[i]->choice.Unsigned.buf, BerInteger_createFromBuffer(accessResultList[i]->choice.Unsigned.buf,
accessResultList[i]->choice.Unsigned.size); accessResultList[i]->choice.Unsigned.size);
value = MmsValue_newUnsignedFromBerInteger(berInteger); value = MmsValue_newUnsignedFromBerInteger(berInteger);
} }
@ -139,9 +140,9 @@ mmsClient_parseListOfAccessResults(AccessResult_t** accessResultList, int listSi
value->value.floatingPoint.buf = (uint8_t*) GLOBAL_MALLOC(4); value->value.floatingPoint.buf = (uint8_t*) GLOBAL_MALLOC(4);
#if (ORDER_LITTLE_ENDIAN == 1) #if (ORDER_LITTLE_ENDIAN == 1)
memcpyReverseByteOrder(value->value.floatingPoint.buf, floatBuf, 4); memcpyReverseByteOrder(value->value.floatingPoint.buf, floatBuf, 4);
#else #else
memcpy(value->value.floatingPoint.buf, floatBuf, 4); memcpy(value->value.floatingPoint.buf, floatBuf, 4);
#endif #endif
} }
@ -179,19 +180,19 @@ mmsClient_parseListOfAccessResults(AccessResult_t** accessResultList, int listSi
value->value.visibleString.buf[strSize] = 0; value->value.visibleString.buf[strSize] = 0;
} }
else if (presentType == AccessResult_PR_mMSString) { 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.buf = (char*) GLOBAL_MALLOC(strSize + 1);
value->value.visibleString.size = strSize; value->value.visibleString.size = strSize;
memcpy(value->value.visibleString.buf, memcpy(value->value.visibleString.buf,
accessResultList[i]->choice.mMSString.buf, strSize); accessResultList[i]->choice.mMSString.buf, strSize);
value->value.visibleString.buf[strSize] = 0; value->value.visibleString.buf[strSize] = 0;
} }
else if (presentType == AccessResult_PR_utctime) { else if (presentType == AccessResult_PR_utctime) {
@ -215,14 +216,14 @@ mmsClient_parseListOfAccessResults(AccessResult_t** accessResultList, int listSi
} }
} }
else if (presentType == AccessResult_PR_octetstring) { else if (presentType == AccessResult_PR_octetstring) {
int size = accessResultList[i]->choice.octetstring.size; int size = accessResultList[i]->choice.octetstring.size;
value = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue)); value = (MmsValue*) GLOBAL_CALLOC(1, sizeof(MmsValue));
value->type = MMS_OCTET_STRING; value->type = MMS_OCTET_STRING;
value->value.octetString.maxSize = size; value->value.octetString.maxSize = size;
value->value.octetString.size = size; value->value.octetString.size = size;
value->value.octetString.buf = (uint8_t*) GLOBAL_MALLOC(size); value->value.octetString.buf = (uint8_t*) GLOBAL_MALLOC(size);
memcpy(value->value.octetString.buf, accessResultList[i]->choice.octetstring.buf, size); memcpy(value->value.octetString.buf, accessResultList[i]->choice.octetstring.buf, size);
} }
else { else {
printf("unknown type %i\n", presentType); printf("unknown type %i\n", presentType);
@ -239,7 +240,6 @@ mmsClient_parseListOfAccessResults(AccessResult_t** accessResultList, int listSi
return valueList; return valueList;
} }
/* /*
* \param createArray if multiple variables should be read (e.g. if a data set is read) an array should * \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. * be created that contains the access results.
@ -247,68 +247,65 @@ mmsClient_parseListOfAccessResults(AccessResult_t** accessResultList, int listSi
MmsValue* MmsValue*
mmsClient_parseReadResponse(ByteBuffer* message, uint32_t* invokeId, bool createArray) 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, asn_dec_rval_t rval = ber_decode(NULL, &asn_DEF_MmsPdu,
(void**) &mmsPdu, ByteBuffer_getBuffer(message), ByteBuffer_getSize(message)); (void**) &mmsPdu, ByteBuffer_getBuffer(message), ByteBuffer_getSize(message));
if (rval.code != RC_OK) if (rval.code != RC_OK)
return NULL; return NULL;
if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) { if (mmsPdu->present == MmsPdu_PR_confirmedResponsePdu) {
if (invokeId != NULL) if (invokeId != NULL)
*invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu); *invokeId = mmsClient_getInvokeId(&mmsPdu->choice.confirmedResponsePdu);
if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present == ConfirmedServiceResponse_PR_read) { if (mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.present == ConfirmedServiceResponse_PR_read) {
ReadResponse_t* response = &(mmsPdu->choice.confirmedResponsePdu.confirmedServiceResponse.choice.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, valueList = mmsClient_parseListOfAccessResults(response->listOfAccessResult.list.array,
elementCount, createArray); 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* static ReadRequest_t*
createReadRequest (MmsPdu_t* mmsPdu) createReadRequest(MmsPdu_t* mmsPdu)
{ {
mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present = mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.present =
ConfirmedServiceRequest_PR_read; ConfirmedServiceRequest_PR_read;
return &(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.read); return &(mmsPdu->choice.confirmedRequestPdu.confirmedServiceRequest.choice.read);
} }
int int
mmsClient_createReadNamedVariableListRequest(uint32_t invokeId, const char* domainId, const char* itemId, 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) { if (specWithResult) {
readRequest->specificationWithResult = (BOOLEAN_t*) GLOBAL_CALLOC(1, sizeof(BOOLEAN_t)); readRequest->specificationWithResult = (BOOLEAN_t*) GLOBAL_CALLOC(1, sizeof(BOOLEAN_t));
(*(readRequest->specificationWithResult)) = true; (*(readRequest->specificationWithResult)) = true;
} }
else else
readRequest->specificationWithResult = NULL; readRequest->specificationWithResult = NULL;
readRequest->variableAccessSpecification.present = VariableAccessSpecification_PR_variableListName;
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->present = ObjectName_PR_domainspecific;
objectName->choice.domainspecific.domainId.buf = (uint8_t*) StringUtils_copyString(domainId); 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.buf = (uint8_t*) StringUtils_copyString(itemId);
objectName->choice.domainspecific.itemId.size = strlen(itemId); objectName->choice.domainspecific.itemId.size = strlen(itemId);
} }
else { else {
objectName->present = ObjectName_PR_vmdspecific; objectName->present = ObjectName_PR_vmdspecific;
objectName->choice.vmdspecific.buf = (uint8_t*) StringUtils_copyString(itemId); objectName->choice.vmdspecific.buf = (uint8_t*) StringUtils_copyString(itemId);
objectName->choice.vmdspecific.size = strlen(itemId); objectName->choice.vmdspecific.size = strlen(itemId);
} }
asn_enc_rval_t rval; asn_enc_rval_t rval;
rval = der_encode(&asn_DEF_MmsPdu, mmsPdu, rval = der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer); (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 int
mmsClient_createReadAssociationSpecificNamedVariableListRequest( mmsClient_createReadAssociationSpecificNamedVariableListRequest(
uint32_t invokeId, uint32_t invokeId,
const char* itemId, const char* itemId,
ByteBuffer* writeBuffer, ByteBuffer* writeBuffer,
bool specWithResult) 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) { if (specWithResult) {
readRequest->specificationWithResult = (BOOLEAN_t*) GLOBAL_CALLOC(1, sizeof(BOOLEAN_t)); readRequest->specificationWithResult = (BOOLEAN_t*) GLOBAL_CALLOC(1, sizeof(BOOLEAN_t));
(*(readRequest->specificationWithResult)) = true; (*(readRequest->specificationWithResult)) = true;
} }
else else
readRequest->specificationWithResult = NULL; 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.buf = (uint8_t*) StringUtils_copyString(itemId);
objectName->choice.aaspecific.size = strlen(itemId); objectName->choice.aaspecific.size = strlen(itemId);
asn_enc_rval_t rval; asn_enc_rval_t rval;
rval = der_encode(&asn_DEF_MmsPdu, mmsPdu, rval = der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer); (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 int
mmsClient_createReadRequest(uint32_t invokeId, const char* domainId, const char* itemId, ByteBuffer* writeBuffer) 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 = readRequest->variableAccessSpecification.choice.listOfVariable.list.array =
(ListOfVariableSeq_t**) GLOBAL_CALLOC(1, sizeof(ListOfVariableSeq_t*)); (ListOfVariableSeq_t**) GLOBAL_CALLOC(1, sizeof(ListOfVariableSeq_t*));
readRequest->variableAccessSpecification.choice.listOfVariable.list.count = 1; 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->alternateAccess = NULL;
listOfVars->variableSpecification.present = VariableSpecification_PR_name; listOfVars->variableSpecification.present = VariableSpecification_PR_name;
if (domainId != NULL) { if (domainId != NULL) {
listOfVars->variableSpecification.choice.name.present = ObjectName_PR_domainspecific; 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.buf = (uint8_t*) domainId;
listOfVars->variableSpecification.choice.name.choice.domainspecific.domainId.size = strlen(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.buf = (uint8_t*) itemId;
listOfVars->variableSpecification.choice.name.choice.domainspecific.itemId.size = strlen(itemId); listOfVars->variableSpecification.choice.name.choice.domainspecific.itemId.size = strlen(itemId);
} }
else { else {
listOfVars->variableSpecification.choice.name.present = ObjectName_PR_vmdspecific; listOfVars->variableSpecification.choice.name.present = ObjectName_PR_vmdspecific;
listOfVars->variableSpecification.choice.name.choice.vmdspecific.buf = (uint8_t*) itemId; listOfVars->variableSpecification.choice.name.choice.vmdspecific.buf = (uint8_t*) itemId;
listOfVars->variableSpecification.choice.name.choice.vmdspecific.size = strlen(itemId); listOfVars->variableSpecification.choice.name.choice.vmdspecific.size = strlen(itemId);
} }
asn_enc_rval_t rval; asn_enc_rval_t rval;
rval = der_encode(&asn_DEF_MmsPdu, mmsPdu, rval = der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer); (asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
/* clean up data structures */ /* clean up data structures */
GLOBAL_FREEMEM(listOfVars); GLOBAL_FREEMEM(listOfVars);
GLOBAL_FREEMEM(readRequest->variableAccessSpecification.choice.listOfVariable.list.array); GLOBAL_FREEMEM(readRequest->variableAccessSpecification.choice.listOfVariable.list.array);
readRequest->variableAccessSpecification.choice.listOfVariable.list.array = NULL; readRequest->variableAccessSpecification.choice.listOfVariable.list.array = NULL;
readRequest->variableAccessSpecification.choice.listOfVariable.list.count = 0; readRequest->variableAccessSpecification.choice.listOfVariable.list.count = 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 AlternateAccess_t* static AlternateAccess_t*
createAlternateAccess(uint32_t index, uint32_t elementCount) createAlternateAccess(uint32_t index, uint32_t elementCount)
{ {
AlternateAccess_t* alternateAccess = (AlternateAccess_t*) GLOBAL_CALLOC(1, sizeof(AlternateAccess_t)); AlternateAccess_t* alternateAccess = (AlternateAccess_t*) GLOBAL_CALLOC(1, sizeof(AlternateAccess_t));
alternateAccess->list.count = 1; alternateAccess->list.count = 1;
alternateAccess->list.array = (struct AlternateAccess__Member**) GLOBAL_CALLOC(1, sizeof(struct AlternateAccess__Member*)); 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] = (struct AlternateAccess__Member*) GLOBAL_CALLOC(1, sizeof(struct AlternateAccess__Member));
alternateAccess->list.array[0]->present = AlternateAccess__Member_PR_unnamed; 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) { if (elementCount > 0) {
alternateAccess->list.array[0]->choice.unnamed->choice.selectAccess.present = alternateAccess->list.array[0]->choice.unnamed->choice.selectAccess.present =
AlternateAccessSelection__selectAccess_PR_indexRange; AlternateAccessSelection__selectAccess_PR_indexRange;
INTEGER_t* asnIndex = INTEGER_t* asnIndex =
&(alternateAccess->list.array[0]->choice.unnamed->choice.selectAccess.choice.indexRange.lowIndex); &(alternateAccess->list.array[0]->choice.unnamed->choice.selectAccess.choice.indexRange.lowIndex);
asn_long2INTEGER(asnIndex, index); asn_long2INTEGER(asnIndex, index);
asnIndex = asnIndex =
&(alternateAccess->list.array[0]->choice.unnamed->choice.selectAccess.choice.indexRange.numberOfElements); &(alternateAccess->list.array[0]->choice.unnamed->choice.selectAccess.choice.indexRange.numberOfElements);
asn_long2INTEGER(asnIndex, elementCount); asn_long2INTEGER(asnIndex, elementCount);
} }
else { else {
alternateAccess->list.array[0]->choice.unnamed->choice.selectAccess.present = alternateAccess->list.array[0]->choice.unnamed->choice.selectAccess.present =
AlternateAccessSelection__selectAccess_PR_index; AlternateAccessSelection__selectAccess_PR_index;
INTEGER_t* asnIndex = INTEGER_t* asnIndex =
&(alternateAccess->list.array[0]->choice.unnamed->choice.selectAccess.choice.index); &(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* static ListOfVariableSeq_t*
createVariableIdentifier(const char* domainId, const char* itemId) 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.present = VariableSpecification_PR_name;
variableIdentifier->variableSpecification.choice.name.present = ObjectName_PR_domainspecific; 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.buf = (uint8_t*) domainId;
variableIdentifier->variableSpecification.choice.name.choice.domainspecific.domainId.size = strlen(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.buf = (uint8_t*) itemId;
variableIdentifier->variableSpecification.choice.name.choice.domainspecific.itemId.size = strlen(itemId); variableIdentifier->variableSpecification.choice.name.choice.domainspecific.itemId.size = strlen(itemId);
return variableIdentifier; return variableIdentifier;
} }
int int
mmsClient_createReadRequestAlternateAccessIndex(uint32_t invokeId, const char* domainId, const char* itemId, 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); 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.array = (ListOfVariableSeq_t**) GLOBAL_CALLOC(1, sizeof(ListOfVariableSeq_t*));
readRequest->variableAccessSpecification.choice.listOfVariable.list.count = 1; 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, rval = der_encode(&asn_DEF_MmsPdu, mmsPdu,
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer); (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.buf = 0;
variableIdentifier->variableSpecification.choice.name.choice.domainspecific.domainId.size = 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.buf = 0;
variableIdentifier->variableSpecification.choice.name.choice.domainspecific.itemId.size = 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** static ListOfVariableSeq_t**
createListOfVariables(ReadRequest_t* readRequest, int valuesCount) { createListOfVariables(ReadRequest_t* readRequest, int valuesCount)
readRequest->variableAccessSpecification.present = VariableAccessSpecification_PR_listOfVariable; {
readRequest->variableAccessSpecification.present = VariableAccessSpecification_PR_listOfVariable;
readRequest->variableAccessSpecification.choice.listOfVariable.list.array = (ListOfVariableSeq_t**) readRequest->variableAccessSpecification.choice.listOfVariable.list.array = (ListOfVariableSeq_t**)
GLOBAL_CALLOC(valuesCount, sizeof(ListOfVariableSeq_t*)); GLOBAL_CALLOC(valuesCount, sizeof(ListOfVariableSeq_t*));
readRequest->variableAccessSpecification.choice.listOfVariable.list.count = valuesCount; readRequest->variableAccessSpecification.choice.listOfVariable.list.count = valuesCount;
readRequest->variableAccessSpecification.choice.listOfVariable.list.size = 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 int
mmsClient_createReadRequestMultipleValues(uint32_t invokeId, const char* domainId, LinkedList items, 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; int i = 0;
while ((item = LinkedList_getNext(item)) != NULL) {
listOfVars[i] = createVariableIdentifier(domainId, (char*) (item->data));
i++;
}
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_enc_rval_t rval;
(asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
for (i = 0; i < valuesCount; i++) { rval = der_encode(&asn_DEF_MmsPdu, mmsPdu,
GLOBAL_FREEMEM(listOfVars[i]); (asn_app_consume_bytes_f*) mmsClient_write_out, (void*) writeBuffer);
}
GLOBAL_FREEMEM(listOfVars);
readRequest->variableAccessSpecification.choice.listOfVariable.list.count = 0; for (i = 0; i < valuesCount; i++) {
readRequest->variableAccessSpecification.choice.listOfVariable.list.size = 0; GLOBAL_FREEMEM(listOfVars[i]);
readRequest->variableAccessSpecification.choice.listOfVariable.list.array = NULL; }
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 static LinkedList
getDomainNames(MmsServerConnection connection) 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++) { for (i = 0; i < device->domainCount; i++) {
LinkedList_add(list, device->domains[i]->domainName); LinkedList_add(list, device->domains[i]->domainName);
} }
return list; return list;
} }
#if (CONFIG_MMS_SUPPORT_VMD_SCOPE_NAMED_VARIABLES == 1) #if (CONFIG_MMS_SUPPORT_VMD_SCOPE_NAMED_VARIABLES == 1)
static LinkedList static LinkedList
getNameListVMDSpecific(MmsServerConnection connection) getNameListVMDSpecific(MmsServerConnection connection)
@ -80,7 +79,6 @@ getNameListVMDSpecific(MmsServerConnection connection)
} }
#endif /* (CONFIG_MMS_SUPPORT_VMD_SCOPE_NAMED_VARIABLES == 1) */ #endif /* (CONFIG_MMS_SUPPORT_VMD_SCOPE_NAMED_VARIABLES == 1) */
#if (CONFIG_MMS_SORT_NAME_LIST == 1) #if (CONFIG_MMS_SORT_NAME_LIST == 1)
static void static void
sortIndex(int* index, int size, MmsVariableSpecification** namedVariables) 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) */ #endif /* (CONFIG_MMS_SUPPORT_FLATTED_NAME_SPACE == 1) */
static LinkedList static LinkedList
getJournalListDomainSpecific(MmsServerConnection connection, char* domainName) getJournalListDomainSpecific(MmsServerConnection connection, char* domainName)
{ {
@ -259,7 +254,6 @@ getNameListDomainSpecific(MmsServerConnection connection, char* domainName)
return nameList; return nameList;
} }
#if (MMS_DATA_SET_SERVICE == 1) #if (MMS_DATA_SET_SERVICE == 1)
static LinkedList static LinkedList
@ -315,13 +309,13 @@ getNamedVariableListsVMDSpecific(MmsServerConnection connection)
static LinkedList static LinkedList
getNamedVariableListAssociationSpecific(MmsServerConnection connection) 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) */ #endif /* (MMS_DYNAMIC_DATA_SETS == 1) */
@ -389,7 +383,7 @@ createNameListResponse(
uint32_t getNameListSize = listOfIdentifierSize; uint32_t getNameListSize = listOfIdentifierSize;
if (moreFollows == false) if (moreFollows == false)
getNameListSize += 3; getNameListSize += 3;
uint32_t confirmedServiceResponseSize = 1 + BerEncoder_determineLengthSize(getNameListSize) + getNameListSize; uint32_t confirmedServiceResponseSize = 1 + BerEncoder_determineLengthSize(getNameListSize) + getNameListSize;
@ -423,7 +417,7 @@ createNameListResponse(
} }
if (moreFollows == false) if (moreFollows == false)
bufPos = BerEncoder_encodeBoolean(0x81, moreFollows, buffer, bufPos); bufPos = BerEncoder_encodeBoolean(0x81, moreFollows, buffer, bufPos);
response->size = bufPos; response->size = bufPos;
@ -433,115 +427,116 @@ createNameListResponse(
void void
mmsServer_handleGetNameListRequest( mmsServer_handleGetNameListRequest(
MmsServerConnection connection, MmsServerConnection connection,
uint8_t* buffer, int bufPos, int maxBufPos, uint8_t* buffer, int bufPos, int maxBufPos,
uint32_t invokeId, uint32_t invokeId,
ByteBuffer* response) ByteBuffer* response)
{ {
int objectClass = -1; int objectClass = -1;
int objectScope = -1; int objectScope = -1;
char* domainId = NULL; char* domainId = NULL;
int domainIdLength; int domainIdLength;
char* continueAfter = NULL; char* continueAfter = NULL;
int continueAfterLength; int continueAfterLength;
while (bufPos < maxBufPos) { while (bufPos < maxBufPos) {
uint8_t tag = buffer[bufPos++]; uint8_t tag = buffer[bufPos++];
int length; int length;
bufPos = BerDecoder_decodeLength(buffer, &length, bufPos, maxBufPos); bufPos = BerDecoder_decodeLength(buffer, &length, bufPos, maxBufPos);
if (bufPos < 0) { if (bufPos < 0) {
mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_INVALID_PDU, response); mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_INVALID_PDU, response);
return; return;
} }
switch (tag) { switch (tag)
{
case 0xa0: /* objectClass */
bufPos++; case 0xa0: /* objectClass */
length = buffer[bufPos++]; bufPos++;
objectClass = BerDecoder_decodeUint32(buffer, length, bufPos); length = buffer[bufPos++];
break; objectClass = BerDecoder_decodeUint32(buffer, length, bufPos);
break;
case 0xa1: /* objectScope */
{ case 0xa1: /* objectScope */
uint8_t objectScopeTag = buffer[bufPos++]; {
bufPos = BerDecoder_decodeLength(buffer, &length, bufPos, maxBufPos); uint8_t objectScopeTag = buffer[bufPos++];
bufPos = BerDecoder_decodeLength(buffer, &length, bufPos, maxBufPos);
if (bufPos < 0) {
mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_INVALID_PDU, response); if (bufPos < 0) {
return; mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_INVALID_PDU, response);
} return;
}
switch (objectScopeTag) {
case 0x80: /* vmd-specific */ switch (objectScopeTag)
objectScope = OBJECT_SCOPE_VMD; {
break; case 0x80: /* vmd-specific */
case 0x81: /* domain-specific */ objectScope = OBJECT_SCOPE_VMD;
domainIdLength = length; break;
domainId = (char*) (buffer + bufPos); case 0x81: /* domain-specific */
objectScope = OBJECT_SCOPE_DOMAIN; domainIdLength = length;
break; domainId = (char*) (buffer + bufPos);
case 0x82: /* association-specific */ objectScope = OBJECT_SCOPE_DOMAIN;
objectScope = OBJECT_SCOPE_ASSOCIATION; break;
break; case 0x82: /* association-specific */
default: objectScope = OBJECT_SCOPE_ASSOCIATION;
mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_UNRECOGNIZED_MODIFIER, response); break;
return; default:
} mmsMsg_createMmsRejectPdu(&invokeId, MMS_ERROR_REJECT_UNRECOGNIZED_MODIFIER, response);
} return;
break; }
}
case 0x82: /* continueAfter */ break;
continueAfter = (char*) (buffer + bufPos);
continueAfterLength = length; case 0x82: /* continueAfter */
break; continueAfter = (char*) (buffer + bufPos);
default: continueAfterLength = length;
/* ignore unknown tag */ break;
break; default:
} /* ignore unknown tag */
break;
bufPos += length; }
}
bufPos += length;
}
char continueAfterIdMemory[130];
char* continueAfterId = NULL; char continueAfterIdMemory[130];
char* continueAfterId = NULL;
if (continueAfter != NULL) {
continueAfterId = continueAfterIdMemory; if (continueAfter != NULL) {
memcpy(continueAfterId, continueAfter, continueAfterLength); continueAfterId = continueAfterIdMemory;
continueAfterId[continueAfterLength] = 0; memcpy(continueAfterId, continueAfter, continueAfterLength);
continueAfterId[continueAfterLength] = 0;
if (DEBUG_MMS_SERVER)
printf("MMS_SERVER: getNameListRequest - continue after: (%s)\n", continueAfterId); if (DEBUG_MMS_SERVER)
} printf("MMS_SERVER: getNameListRequest - continue after: (%s)\n", continueAfterId);
}
if (objectScope == OBJECT_SCOPE_DOMAIN) {
char domainSpecificName[130]; if (objectScope == OBJECT_SCOPE_DOMAIN) {
char domainSpecificName[130];
memcpy(domainSpecificName, domainId, domainIdLength);
domainSpecificName[domainIdLength] = 0; memcpy(domainSpecificName, domainId, domainIdLength);
domainSpecificName[domainIdLength] = 0;
if (objectClass == OBJECT_CLASS_NAMED_VARIABLE) {
if (DEBUG_MMS_SERVER) if (objectClass == OBJECT_CLASS_NAMED_VARIABLE) {
printf("MMS_SERVER: get namelist for (%s)\n", domainSpecificName); if (DEBUG_MMS_SERVER)
printf("MMS_SERVER: get namelist for (%s)\n", domainSpecificName);
LinkedList nameList = getNameListDomainSpecific(connection, domainSpecificName);
LinkedList nameList = getNameListDomainSpecific(connection, domainSpecificName);
if (nameList == NULL)
mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT); if (nameList == NULL)
else { mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT);
createNameListResponse(connection, invokeId, nameList, response, continueAfterId); else {
LinkedList_destroy(nameList); createNameListResponse(connection, invokeId, nameList, response, continueAfterId);
} LinkedList_destroy(nameList);
} }
else if (objectClass == OBJECT_CLASS_JOURNAL) { }
LinkedList nameList = getJournalListDomainSpecific(connection, domainSpecificName); else if (objectClass == OBJECT_CLASS_JOURNAL) {
LinkedList nameList = getJournalListDomainSpecific(connection, domainSpecificName);
if (nameList == NULL) if (nameList == NULL)
mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT); mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT);
@ -553,117 +548,120 @@ mmsServer_handleGetNameListRequest(
createNameListResponse(connection, invokeId, nameList, response, continueAfterId); createNameListResponse(connection, invokeId, nameList, response, continueAfterId);
LinkedList_destroyStatic(nameList); LinkedList_destroyStatic(nameList);
} }
} }
#if (MMS_DATA_SET_SERVICE == 1) #if (MMS_DATA_SET_SERVICE == 1)
else if (objectClass == OBJECT_CLASS_NAMED_VARIABLE_LIST) { else if (objectClass == OBJECT_CLASS_NAMED_VARIABLE_LIST) {
LinkedList nameList = getNamedVariableListsDomainSpecific(connection, domainSpecificName); LinkedList nameList = getNamedVariableListsDomainSpecific(connection, domainSpecificName);
if (nameList == NULL) if (nameList == NULL)
mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT); mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_NON_EXISTENT);
else { else {
#if (CONFIG_MMS_SORT_NAME_LIST == 1) #if (CONFIG_MMS_SORT_NAME_LIST == 1)
StringUtils_sortList(nameList); StringUtils_sortList(nameList);
#endif #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) */ #endif /* (MMS_DATA_SET_SERVICE == 1) */
else { else {
if (DEBUG_MMS_SERVER) printf("MMS_SERVER: getNameList domain specific objectClass %i not supported!\n", objectClass); 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) #if (CONFIG_MMS_SORT_NAME_LIST == 1)
StringUtils_sortList(nameList); StringUtils_sortList(nameList);
#endif #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) #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); LinkedList nameList = getNameListVMDSpecific(connection);
createNameListResponse(connection, invokeId, nameList, response, continueAfter); createNameListResponse(connection, invokeId, nameList, response, continueAfter);
LinkedList_destroyStatic(nameList); LinkedList_destroyStatic(nameList);
} }
#endif /* (CONFIG_MMS_SUPPORT_VMD_SCOPE_NAMED_VARIABLES == 1) */ #endif /* (CONFIG_MMS_SUPPORT_VMD_SCOPE_NAMED_VARIABLES == 1) */
#if (MMS_DATA_SET_SERVICE == 1) #if (MMS_DATA_SET_SERVICE == 1)
else if (objectClass == OBJECT_CLASS_NAMED_VARIABLE_LIST) { else if (objectClass == OBJECT_CLASS_NAMED_VARIABLE_LIST) {
LinkedList nameList = getNamedVariableListsVMDSpecific(connection); LinkedList nameList = getNamedVariableListsVMDSpecific(connection);
#if (CONFIG_MMS_SORT_NAME_LIST == 1) #if (CONFIG_MMS_SORT_NAME_LIST == 1)
StringUtils_sortList(nameList); StringUtils_sortList(nameList);
#endif #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) */ #endif /* (MMS_DATA_SET_SERVICE == 1) */
else if (objectClass == OBJECT_CLASS_JOURNAL) { else if (objectClass == OBJECT_CLASS_JOURNAL) {
LinkedList nameList = LinkedList_create(); LinkedList nameList = LinkedList_create();
#if (CONFIG_MMS_SORT_NAME_LIST == 1) #if (CONFIG_MMS_SORT_NAME_LIST == 1)
StringUtils_sortList(nameList); StringUtils_sortList(nameList);
#endif #endif
createNameListResponse(connection, invokeId, nameList, response, continueAfter); createNameListResponse(connection, invokeId, nameList, response, continueAfter);
LinkedList_destroy(nameList); LinkedList_destroy(nameList);
} }
else { 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); mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_ACCESS_UNSUPPORTED);
} }
} }
#if (MMS_DATA_SET_SERVICE == 1) #if (MMS_DATA_SET_SERVICE == 1)
#if (MMS_DYNAMIC_DATA_SETS == 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) { if (objectClass == OBJECT_CLASS_NAMED_VARIABLE_LIST) {
LinkedList nameList = getNamedVariableListAssociationSpecific(connection); LinkedList nameList = getNamedVariableListAssociationSpecific(connection);
#if (CONFIG_MMS_SORT_NAME_LIST == 1) #if (CONFIG_MMS_SORT_NAME_LIST == 1)
StringUtils_sortList(nameList); StringUtils_sortList(nameList);
#endif #endif
createNameListResponse(connection, invokeId, nameList, response, continueAfter); createNameListResponse(connection, invokeId, nameList, response, continueAfter);
LinkedList_destroy(nameList); LinkedList_destroy(nameList);
} }
else else
mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_ACCESS_UNSUPPORTED); mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_ACCESS_UNSUPPORTED);
} }
#endif /* (MMS_DYNAMIC_DATA_SETS == 1) */ #endif /* (MMS_DYNAMIC_DATA_SETS == 1) */
#endif /* (MMS_DATA_SET_SERVICE == 1) */ #endif /* (MMS_DATA_SET_SERVICE == 1) */
else { else {
if (DEBUG_MMS_SERVER) printf("MMS_SERVER: getNameList(%i) not supported!\n", objectScope); if (DEBUG_MMS_SERVER)
mmsMsg_createServiceErrorPdu(invokeId, response, MMS_ERROR_ACCESS_OBJECT_ACCESS_UNSUPPORTED); 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) */ #endif /* (MMS_GET_NAME_LIST == 1) */

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

Loading…
Cancel
Save