indented.

This commit is contained in:
skarg
2007-11-29 16:39:48 +00:00
parent 06d23fcf1f
commit 1477603af6
123 changed files with 1994 additions and 1688 deletions
+18 -12
View File
@@ -103,8 +103,9 @@ int abort_decode_apdu(
else
*server = false;
if (apdu_len > 1) {
len = abort_decode_service_request(&apdu[1],
apdu_len - 1, invoke_id, abort_reason);
len =
abort_decode_service_request(&apdu[1], apdu_len - 1, invoke_id,
abort_reason);
}
}
@@ -127,8 +128,9 @@ void testAbortAPDU(
len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason, server);
apdu_len = len;
ct_test(pTest, len != 0);
len = abort_decode_apdu(&apdu[0],
apdu_len, &test_invoke_id, &test_abort_reason, &test_server);
len =
abort_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_abort_reason, &test_server);
ct_test(pTest, len != -1);
ct_test(pTest, test_invoke_id == invoke_id);
ct_test(pTest, test_abort_reason == abort_reason);
@@ -154,8 +156,9 @@ void testAbort(
len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason, server);
ct_test(pTest, len != 0);
apdu_len = len;
len = abort_decode_apdu(&apdu[0],
apdu_len, &test_invoke_id, &test_abort_reason, &test_server);
len =
abort_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_abort_reason, &test_server);
ct_test(pTest, len != -1);
ct_test(pTest, test_invoke_id == invoke_id);
ct_test(pTest, test_abort_reason == abort_reason);
@@ -163,18 +166,21 @@ void testAbort(
/* change type to get negative response */
apdu[0] = PDU_TYPE_REJECT;
len = abort_decode_apdu(&apdu[0],
apdu_len, &test_invoke_id, &test_abort_reason, &test_server);
len =
abort_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_abort_reason, &test_server);
ct_test(pTest, len == -1);
/* test NULL APDU */
len = abort_decode_apdu(NULL,
apdu_len, &test_invoke_id, &test_abort_reason, &test_server);
len =
abort_decode_apdu(NULL, apdu_len, &test_invoke_id, &test_abort_reason,
&test_server);
ct_test(pTest, len == -1);
/* force a zero length */
len = abort_decode_apdu(&apdu[0],
0, &test_invoke_id, &test_abort_reason, &test_server);
len =
abort_decode_apdu(&apdu[0], 0, &test_invoke_id, &test_abort_reason,
&test_server);
ct_test(pTest, len == 0);
/* check them all... */
+3 -4
View File
@@ -59,8 +59,7 @@ void address_remove_device(
unsigned i;
for (i = 0; i < MAX_ADDRESS_CACHE; i++) {
if ((Address_Cache[i].valid ||
Address_Cache[i].bind_request) &&
if ((Address_Cache[i].valid || Address_Cache[i].bind_request) &&
(Address_Cache[i].device_id == device_id)) {
Address_Cache[i].valid = false;
break;
@@ -320,8 +319,8 @@ void testAddress(
&test_address));
ct_test(pTest, test_max_apdu == max_apdu);
ct_test(pTest, bacnet_address_same(&test_address, &src));
ct_test(pTest, address_get_by_index(i, &test_device_id,
&test_max_apdu, &test_address));
ct_test(pTest, address_get_by_index(i, &test_device_id, &test_max_apdu,
&test_address));
ct_test(pTest, test_device_id == device_id);
ct_test(pTest, test_max_apdu == max_apdu);
ct_test(pTest, bacnet_address_same(&test_address, &src));
+3 -5
View File
@@ -304,9 +304,8 @@ void apdu_handler(
switch (apdu[0] & 0xF0) {
case PDU_TYPE_CONFIRMED_SERVICE_REQUEST:
len = apdu_decode_confirmed_service_request(&apdu[0], /* APDU data */
apdu_len,
&service_data,
&service_choice, &service_request, &service_request_len);
apdu_len, &service_data, &service_choice, &service_request,
&service_request_len);
/* When network communications are completely disabled,
only DeviceCommunicationControl and ReinitializeDevice APDUs
shall be processed and no messages shall be initiated. */
@@ -437,8 +436,7 @@ void apdu_handler(
len += decode_enumerated(&apdu[len], len_value, &error_code);
if (service_choice < MAX_BACNET_CONFIRMED_SERVICE) {
if (Error_Function[service_choice])
Error_Function[service_choice] (src,
invoke_id,
Error_Function[service_choice] (src, invoke_id,
(BACNET_ERROR_CLASS) error_class,
(BACNET_ERROR_CODE) error_code);
}
+100 -63
View File
@@ -55,22 +55,27 @@ int arf_encode_apdu(
apdu[2] = invoke_id;
apdu[3] = SERVICE_CONFIRMED_ATOMIC_READ_FILE; /* service choice */
apdu_len = 4;
apdu_len += encode_application_object_id(&apdu[apdu_len],
data->object_type, data->object_instance);
apdu_len +=
encode_application_object_id(&apdu[apdu_len], data->object_type,
data->object_instance);
switch (data->access) {
case FILE_STREAM_ACCESS:
apdu_len += encode_opening_tag(&apdu[apdu_len], 0);
apdu_len += encode_application_signed(&apdu[apdu_len],
apdu_len +=
encode_application_signed(&apdu[apdu_len],
data->type.stream.fileStartPosition);
apdu_len += encode_application_unsigned(&apdu[apdu_len],
apdu_len +=
encode_application_unsigned(&apdu[apdu_len],
data->type.stream.requestedOctetCount);
apdu_len += encode_closing_tag(&apdu[apdu_len], 0);
break;
case FILE_RECORD_ACCESS:
apdu_len += encode_opening_tag(&apdu[apdu_len], 1);
apdu_len += encode_application_signed(&apdu[apdu_len],
apdu_len +=
encode_application_signed(&apdu[apdu_len],
data->type.record.fileStartRecord);
apdu_len += encode_application_unsigned(&apdu[apdu_len],
apdu_len +=
encode_application_unsigned(&apdu[apdu_len],
data->type.record.RecordCount);
apdu_len += encode_closing_tag(&apdu[apdu_len], 1);
break;
@@ -108,21 +113,25 @@ int arf_decode_service_request(
/* a tag number is not extended so only one octet */
len++;
/* fileStartPosition */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT)
return -1;
len += decode_signed(&apdu[len],
len_value_type, &data->type.stream.fileStartPosition);
len +=
decode_signed(&apdu[len], len_value_type,
&data->type.stream.fileStartPosition);
/* requestedOctetCount */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
return -1;
len += decode_unsigned(&apdu[len],
len_value_type, &data->type.stream.requestedOctetCount);
len +=
decode_unsigned(&apdu[len], len_value_type,
&data->type.stream.requestedOctetCount);
if (!decode_is_closing_tag_number(&apdu[len], 0))
return -1;
/* a tag number is not extended so only one octet */
@@ -132,21 +141,25 @@ int arf_decode_service_request(
/* a tag number is not extended so only one octet */
len++;
/* fileStartRecord */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT)
return -1;
len += decode_signed(&apdu[len],
len_value_type, &data->type.record.fileStartRecord);
len +=
decode_signed(&apdu[len], len_value_type,
&data->type.record.fileStartRecord);
/* RecordCount */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
return -1;
len += decode_unsigned(&apdu[len],
len_value_type, &data->type.record.RecordCount);
len +=
decode_unsigned(&apdu[len], len_value_type,
&data->type.record.RecordCount);
if (!decode_is_closing_tag_number(&apdu[len], 1))
return -1;
/* a tag number is not extended so only one octet */
@@ -179,8 +192,8 @@ int arf_decode_apdu(
offset = 4;
if (apdu_len > offset) {
len = arf_decode_service_request(&apdu[offset],
apdu_len - offset, data);
len =
arf_decode_service_request(&apdu[offset], apdu_len - offset, data);
}
return len;
@@ -205,19 +218,24 @@ int arf_ack_encode_apdu(
switch (data->access) {
case FILE_STREAM_ACCESS:
apdu_len += encode_opening_tag(&apdu[apdu_len], 0);
apdu_len += encode_application_signed(&apdu[apdu_len],
apdu_len +=
encode_application_signed(&apdu[apdu_len],
data->type.stream.fileStartPosition);
apdu_len += encode_application_octet_string(&apdu[apdu_len],
apdu_len +=
encode_application_octet_string(&apdu[apdu_len],
&data->fileData);
apdu_len += encode_closing_tag(&apdu[apdu_len], 0);
break;
case FILE_RECORD_ACCESS:
apdu_len += encode_opening_tag(&apdu[apdu_len], 1);
apdu_len += encode_application_signed(&apdu[apdu_len],
apdu_len +=
encode_application_signed(&apdu[apdu_len],
data->type.record.fileStartRecord);
apdu_len += encode_application_unsigned(&apdu[apdu_len],
apdu_len +=
encode_application_unsigned(&apdu[apdu_len],
data->type.record.RecordCount);
apdu_len += encode_application_octet_string(&apdu[apdu_len],
apdu_len +=
encode_application_octet_string(&apdu[apdu_len],
&data->fileData);
apdu_len += encode_closing_tag(&apdu[apdu_len], 1);
break;
@@ -253,21 +271,25 @@ int arf_ack_decode_service_request(
/* a tag number is not extended so only one octet */
len++;
/* fileStartPosition */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT)
return -1;
len += decode_signed(&apdu[len],
len_value_type, &data->type.stream.fileStartPosition);
len +=
decode_signed(&apdu[len], len_value_type,
&data->type.stream.fileStartPosition);
/* fileData */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING)
return -1;
len += decode_octet_string(&apdu[len],
len_value_type, &data->fileData);
len +=
decode_octet_string(&apdu[len], len_value_type,
&data->fileData);
if (!decode_is_closing_tag_number(&apdu[len], 0))
return -1;
/* a tag number is not extended so only one octet */
@@ -277,29 +299,35 @@ int arf_ack_decode_service_request(
/* a tag number is not extended so only one octet */
len++;
/* fileStartRecord */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT)
return -1;
len += decode_signed(&apdu[len],
len_value_type, &data->type.record.fileStartRecord);
len +=
decode_signed(&apdu[len], len_value_type,
&data->type.record.fileStartRecord);
/* returnedRecordCount */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
return -1;
len += decode_unsigned(&apdu[len],
len_value_type, &data->type.record.RecordCount);
len +=
decode_unsigned(&apdu[len], len_value_type,
&data->type.record.RecordCount);
/* fileData */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING)
return -1;
len += decode_octet_string(&apdu[len],
len_value_type, &data->fileData);
len +=
decode_octet_string(&apdu[len], len_value_type,
&data->fileData);
if (!decode_is_closing_tag_number(&apdu[len], 1))
return -1;
/* a tag number is not extended so only one octet */
@@ -331,8 +359,9 @@ int arf_ack_decode_apdu(
offset = 3;
if (apdu_len > offset) {
len = arf_ack_decode_service_request(&apdu[offset],
apdu_len - offset, data);
len =
arf_ack_decode_service_request(&apdu[offset], apdu_len - offset,
data);
}
return len;
@@ -364,15 +393,19 @@ void testAtomicReadFileAckAccess(
ct_test(pTest, test_data.endOfFile == data->endOfFile);
ct_test(pTest, test_data.access == data->access);
if (test_data.access == FILE_STREAM_ACCESS) {
ct_test(pTest, test_data.type.stream.fileStartPosition ==
ct_test(pTest,
test_data.type.stream.fileStartPosition ==
data->type.stream.fileStartPosition);
} else if (test_data.access == FILE_RECORD_ACCESS) {
ct_test(pTest, test_data.type.record.fileStartRecord ==
ct_test(pTest,
test_data.type.record.fileStartRecord ==
data->type.record.fileStartRecord);
ct_test(pTest, test_data.type.record.RecordCount ==
ct_test(pTest,
test_data.type.record.RecordCount ==
data->type.record.RecordCount);
}
ct_test(pTest, octetstring_length(&test_data.fileData) ==
ct_test(pTest,
octetstring_length(&test_data.fileData) ==
octetstring_length(&data->fileData));
ct_test(pTest, memcmp(octetstring_value(&test_data.fileData),
octetstring_value(&data->fileData),
@@ -389,16 +422,16 @@ void testAtomicReadFileAck(
data.endOfFile = true;
data.access = FILE_STREAM_ACCESS;
data.type.stream.fileStartPosition = 0;
octetstring_init(&data.fileData,
test_octet_string, sizeof(test_octet_string));
octetstring_init(&data.fileData, test_octet_string,
sizeof(test_octet_string));
testAtomicReadFileAckAccess(pTest, &data);
data.endOfFile = false;
data.access = FILE_RECORD_ACCESS;
data.type.record.fileStartRecord = 1;
data.type.record.RecordCount = 2;
octetstring_init(&data.fileData,
test_octet_string, sizeof(test_octet_string));
octetstring_init(&data.fileData, test_octet_string,
sizeof(test_octet_string));
testAtomicReadFileAckAccess(pTest, &data);
return;
@@ -425,14 +458,18 @@ void testAtomicReadFileAccess(
ct_test(pTest, test_data.object_instance == data->object_instance);
ct_test(pTest, test_data.access == data->access);
if (test_data.access == FILE_STREAM_ACCESS) {
ct_test(pTest, test_data.type.stream.fileStartPosition ==
ct_test(pTest,
test_data.type.stream.fileStartPosition ==
data->type.stream.fileStartPosition);
ct_test(pTest, test_data.type.stream.requestedOctetCount ==
ct_test(pTest,
test_data.type.stream.requestedOctetCount ==
data->type.stream.requestedOctetCount);
} else if (test_data.access == FILE_RECORD_ACCESS) {
ct_test(pTest, test_data.type.record.fileStartRecord ==
ct_test(pTest,
test_data.type.record.fileStartRecord ==
data->type.record.fileStartRecord);
ct_test(pTest, test_data.type.record.RecordCount ==
ct_test(pTest,
test_data.type.record.RecordCount ==
data->type.record.RecordCount);
}
}
+66 -43
View File
@@ -55,24 +55,30 @@ int awf_encode_apdu(
apdu[2] = invoke_id;
apdu[3] = SERVICE_CONFIRMED_ATOMIC_WRITE_FILE; /* service choice */
apdu_len = 4;
apdu_len += encode_application_object_id(&apdu[apdu_len],
data->object_type, data->object_instance);
apdu_len +=
encode_application_object_id(&apdu[apdu_len], data->object_type,
data->object_instance);
switch (data->access) {
case FILE_STREAM_ACCESS:
apdu_len += encode_opening_tag(&apdu[apdu_len], 0);
apdu_len += encode_application_signed(&apdu[apdu_len],
apdu_len +=
encode_application_signed(&apdu[apdu_len],
data->type.stream.fileStartPosition);
apdu_len += encode_application_octet_string(&apdu[apdu_len],
apdu_len +=
encode_application_octet_string(&apdu[apdu_len],
&data->fileData);
apdu_len += encode_closing_tag(&apdu[apdu_len], 0);
break;
case FILE_RECORD_ACCESS:
apdu_len += encode_opening_tag(&apdu[apdu_len], 1);
apdu_len += encode_application_signed(&apdu[apdu_len],
apdu_len +=
encode_application_signed(&apdu[apdu_len],
data->type.record.fileStartRecord);
apdu_len += encode_application_unsigned(&apdu[apdu_len],
apdu_len +=
encode_application_unsigned(&apdu[apdu_len],
data->type.record.returnedRecordCount);
apdu_len += encode_application_octet_string(&apdu[apdu_len],
apdu_len +=
encode_application_octet_string(&apdu[apdu_len],
&data->fileData);
apdu_len += encode_closing_tag(&apdu[apdu_len], 1);
break;
@@ -112,21 +118,24 @@ int awf_decode_service_request(
/* a tag number of 2 is not extended so only one octet */
len++;
/* fileStartPosition */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT)
return -1;
len += decode_signed(&apdu[len], len_value_type, &signed_value);
data->type.stream.fileStartPosition = signed_value;
/* fileData */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING)
return -1;
len += decode_octet_string(&apdu[len],
len_value_type, &data->fileData);
len +=
decode_octet_string(&apdu[len], len_value_type,
&data->fileData);
if (!decode_is_closing_tag_number(&apdu[len], 0))
return -1;
/* a tag number is not extended so only one octet */
@@ -136,30 +145,34 @@ int awf_decode_service_request(
/* a tag number is not extended so only one octet */
len++;
/* fileStartRecord */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT)
return -1;
len += decode_signed(&apdu[len], len_value_type, &signed_value);
data->type.record.fileStartRecord = signed_value;
/* returnedRecordCount */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
return -1;
len += decode_unsigned(&apdu[len], len_value_type,
&unsigned_value);
len +=
decode_unsigned(&apdu[len], len_value_type, &unsigned_value);
data->type.record.returnedRecordCount = unsigned_value;
/* fileData */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += tag_len;
if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING)
return -1;
len += decode_octet_string(&apdu[len],
len_value_type, &data->fileData);
len +=
decode_octet_string(&apdu[len], len_value_type,
&data->fileData);
if (!decode_is_closing_tag_number(&apdu[len], 1))
return -1;
/* a tag number is not extended so only one octet */
@@ -192,8 +205,8 @@ int awf_decode_apdu(
offset = 4;
if (apdu_len > offset) {
len = awf_decode_service_request(&apdu[offset],
apdu_len - offset, data);
len =
awf_decode_service_request(&apdu[offset], apdu_len - offset, data);
}
return len;
@@ -213,11 +226,13 @@ int awf_ack_encode_apdu(
apdu_len = 3;
switch (data->access) {
case FILE_STREAM_ACCESS:
apdu_len += encode_context_signed(&apdu[apdu_len], 0,
apdu_len +=
encode_context_signed(&apdu[apdu_len], 0,
data->type.stream.fileStartPosition);
break;
case FILE_RECORD_ACCESS:
apdu_len += encode_context_signed(&apdu[apdu_len], 1,
apdu_len +=
encode_context_signed(&apdu[apdu_len], 1,
data->type.record.fileStartRecord);
break;
default:
@@ -245,12 +260,14 @@ int awf_ack_decode_service_request(
&len_value_type);
if (tag_number == 0) {
data->access = FILE_STREAM_ACCESS;
len += decode_signed(&apdu[len],
len_value_type, &data->type.stream.fileStartPosition);
len +=
decode_signed(&apdu[len], len_value_type,
&data->type.stream.fileStartPosition);
} else if (tag_number == 1) {
data->access = FILE_RECORD_ACCESS;
len += decode_signed(&apdu[len],
len_value_type, &data->type.record.fileStartRecord);
len +=
decode_signed(&apdu[len], len_value_type,
&data->type.record.fileStartRecord);
} else
return -1;
}
@@ -278,8 +295,8 @@ int awf_ack_decode_apdu(
offset = 3;
if (apdu_len > offset) {
len = awf_decode_service_request(&apdu[offset],
apdu_len - offset, data);
len =
awf_decode_service_request(&apdu[offset], apdu_len - offset, data);
}
return len;
@@ -311,15 +328,19 @@ void testAtomicWriteFileAccess(
ct_test(pTest, test_data.object_instance == data->object_instance);
ct_test(pTest, test_data.access == data->access);
if (test_data.access == FILE_STREAM_ACCESS) {
ct_test(pTest, test_data.type.stream.fileStartPosition ==
ct_test(pTest,
test_data.type.stream.fileStartPosition ==
data->type.stream.fileStartPosition);
} else if (test_data.access == FILE_RECORD_ACCESS) {
ct_test(pTest, test_data.type.record.fileStartRecord ==
ct_test(pTest,
test_data.type.record.fileStartRecord ==
data->type.record.fileStartRecord);
ct_test(pTest, test_data.type.record.returnedRecordCount ==
ct_test(pTest,
test_data.type.record.returnedRecordCount ==
data->type.record.returnedRecordCount);
}
ct_test(pTest, octetstring_length(&test_data.fileData) ==
ct_test(pTest,
octetstring_length(&test_data.fileData) ==
octetstring_length(&data->fileData));
ct_test(pTest, memcmp(octetstring_value(&test_data.fileData),
octetstring_value(&data->fileData),
@@ -336,8 +357,8 @@ void testAtomicWriteFile(
data.object_instance = 1;
data.access = FILE_STREAM_ACCESS;
data.type.stream.fileStartPosition = 0;
octetstring_init(&data.fileData,
test_octet_string, sizeof(test_octet_string));
octetstring_init(&data.fileData, test_octet_string,
sizeof(test_octet_string));
testAtomicWriteFileAccess(pTest, &data);
data.object_type = OBJECT_FILE;
@@ -345,8 +366,8 @@ void testAtomicWriteFile(
data.access = FILE_RECORD_ACCESS;
data.type.record.fileStartRecord = 1;
data.type.record.returnedRecordCount = 2;
octetstring_init(&data.fileData,
test_octet_string, sizeof(test_octet_string));
octetstring_init(&data.fileData, test_octet_string,
sizeof(test_octet_string));
testAtomicWriteFileAccess(pTest, &data);
return;
@@ -371,10 +392,12 @@ void testAtomicWriteFileAckAccess(
ct_test(pTest, len != -1);
ct_test(pTest, test_data.access == data->access);
if (test_data.access == FILE_STREAM_ACCESS) {
ct_test(pTest, test_data.type.stream.fileStartPosition ==
ct_test(pTest,
test_data.type.stream.fileStartPosition ==
data->type.stream.fileStartPosition);
} else if (test_data.access == FILE_RECORD_ACCESS) {
ct_test(pTest, test_data.type.record.fileStartRecord ==
ct_test(pTest,
test_data.type.record.fileStartRecord ==
data->type.record.fileStartRecord);
}
}
+135 -89
View File
@@ -62,19 +62,21 @@ int bacapp_encode_application_data(
#endif
#if defined (BACAPP_BOOLEAN)
case BACNET_APPLICATION_TAG_BOOLEAN:
apdu_len = encode_application_boolean(&apdu[0],
value->type.Boolean);
apdu_len =
encode_application_boolean(&apdu[0], value->type.Boolean);
break;
#endif
#if defined (BACAPP_UNSIGNED)
case BACNET_APPLICATION_TAG_UNSIGNED_INT:
apdu_len = encode_application_unsigned(&apdu[0],
apdu_len =
encode_application_unsigned(&apdu[0],
value->type.Unsigned_Int);
break;
#endif
#if defined (BACAPP_SIGNED)
case BACNET_APPLICATION_TAG_SIGNED_INT:
apdu_len = encode_application_signed(&apdu[0],
apdu_len =
encode_application_signed(&apdu[0],
value->type.Signed_Int);
break;
#endif
@@ -86,31 +88,35 @@ int bacapp_encode_application_data(
#if defined (BACAPP_DOUBLE)
case BACNET_APPLICATION_TAG_DOUBLE:
/* FIXME: double is not implemented yet. */
apdu_len = encode_application_double(&apdu[0],
value->type.Double);
apdu_len =
encode_application_double(&apdu[0], value->type.Double);
break;
#endif
#if defined (BACAPP_OCTET_STRING)
case BACNET_APPLICATION_TAG_OCTET_STRING:
apdu_len = encode_application_octet_string(&apdu[0],
apdu_len =
encode_application_octet_string(&apdu[0],
&value->type.Octet_String);
break;
#endif
#if defined (BACAPP_CHARACTER_STRING)
case BACNET_APPLICATION_TAG_CHARACTER_STRING:
apdu_len = encode_application_character_string(&apdu[0],
apdu_len =
encode_application_character_string(&apdu[0],
&value->type.Character_String);
break;
#endif
#if defined (BACAPP_BIT_STRING)
case BACNET_APPLICATION_TAG_BIT_STRING:
apdu_len = encode_application_bitstring(&apdu[0],
apdu_len =
encode_application_bitstring(&apdu[0],
&value->type.Bit_String);
break;
#endif
#if defined (BACAPP_ENUMERATED)
case BACNET_APPLICATION_TAG_ENUMERATED:
apdu_len = encode_application_enumerated(&apdu[0],
apdu_len =
encode_application_enumerated(&apdu[0],
value->type.Enumerated);
break;
#endif
@@ -128,7 +134,8 @@ int bacapp_encode_application_data(
#endif
#if defined (BACAPP_OBJECT_ID)
case BACNET_APPLICATION_TAG_OBJECT_ID:
apdu_len = encode_application_object_id(&apdu[0],
apdu_len =
encode_application_object_id(&apdu[0],
value->type.Object_Id.type,
value->type.Object_Id.instance);
break;
@@ -166,14 +173,16 @@ int bacapp_decode_data(
#endif
#if defined (BACAPP_UNSIGNED)
case BACNET_APPLICATION_TAG_UNSIGNED_INT:
len = decode_unsigned(&apdu[0],
len_value_type, &value->type.Unsigned_Int);
len =
decode_unsigned(&apdu[0], len_value_type,
&value->type.Unsigned_Int);
break;
#endif
#if defined (BACAPP_SIGNED)
case BACNET_APPLICATION_TAG_SIGNED_INT:
len = decode_signed(&apdu[0],
len_value_type, &value->type.Signed_Int);
len =
decode_signed(&apdu[0], len_value_type,
&value->type.Signed_Int);
break;
#endif
#if defined (BACAPP_REAL)
@@ -188,26 +197,30 @@ int bacapp_decode_data(
#endif
#if defined (BACAPP_OCTET_STRING)
case BACNET_APPLICATION_TAG_OCTET_STRING:
len = decode_octet_string(&apdu[0],
len_value_type, &value->type.Octet_String);
len =
decode_octet_string(&apdu[0], len_value_type,
&value->type.Octet_String);
break;
#endif
#if defined (BACAPP_CHARACTER_STRING)
case BACNET_APPLICATION_TAG_CHARACTER_STRING:
len = decode_character_string(&apdu[0],
len_value_type, &value->type.Character_String);
len =
decode_character_string(&apdu[0], len_value_type,
&value->type.Character_String);
break;
#endif
#if defined (BACAPP_BIT_STRING)
case BACNET_APPLICATION_TAG_BIT_STRING:
len = decode_bitstring(&apdu[0],
len_value_type, &value->type.Bit_String);
len =
decode_bitstring(&apdu[0], len_value_type,
&value->type.Bit_String);
break;
#endif
#if defined (BACAPP_ENUMERATED)
case BACNET_APPLICATION_TAG_ENUMERATED:
len = decode_enumerated(&apdu[0],
len_value_type, &value->type.Enumerated);
len =
decode_enumerated(&apdu[0], len_value_type,
&value->type.Enumerated);
break;
#endif
#if defined (BACAPP_DATE)
@@ -253,13 +266,15 @@ int bacapp_decode_application_data(
max_apdu_len = max_apdu_len;
if (apdu && value && !decode_is_context_specific(apdu)) {
value->context_specific = false;
tag_len = decode_tag_number_and_value(&apdu[0],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[0], &tag_number,
&len_value_type);
if (tag_len) {
len += tag_len;
value->tag = tag_number;
len += bacapp_decode_data(&apdu[len],
tag_number, len_value_type, value);
len +=
bacapp_decode_data(&apdu[len], tag_number, len_value_type,
value);
}
value->next = NULL;
}
@@ -283,7 +298,8 @@ int bacapp_encode_context_data_value(
#endif
#if defined (BACAPP_BOOLEAN)
case BACNET_APPLICATION_TAG_BOOLEAN:
apdu_len = encode_context_boolean(&apdu[0], context_tag_number,
apdu_len =
encode_context_boolean(&apdu[0], context_tag_number,
value->type.Boolean);
break;
#endif
@@ -296,20 +312,23 @@ int bacapp_encode_context_data_value(
#endif
#if defined (BACAPP_SIGNED)
case BACNET_APPLICATION_TAG_SIGNED_INT:
apdu_len = encode_context_signed(&apdu[0], context_tag_number,
apdu_len =
encode_context_signed(&apdu[0], context_tag_number,
value->type.Signed_Int);
break;
#endif
#if defined (BACAPP_REAL)
case BACNET_APPLICATION_TAG_REAL:
apdu_len = encode_context_real(&apdu[0], context_tag_number,
apdu_len =
encode_context_real(&apdu[0], context_tag_number,
value->type.Real);
break;
#endif
#if defined (BACAPP_DOUBLE)
case BACNET_APPLICATION_TAG_DOUBLE:
/* FIXME: double is not implemented yet. */
apdu_len = encode_context_double(&apdu[0], context_tag_number,
apdu_len =
encode_context_double(&apdu[0], context_tag_number,
value->type.Double);
break;
#endif
@@ -343,13 +362,15 @@ int bacapp_encode_context_data_value(
#endif
#if defined (BACAPP_DATE)
case BACNET_APPLICATION_TAG_DATE:
apdu_len = encode_context_date(&apdu[0], context_tag_number,
apdu_len =
encode_context_date(&apdu[0], context_tag_number,
&value->type.Date);
break;
#endif
#if defined (BACAPP_TIME)
case BACNET_APPLICATION_TAG_TIME:
apdu_len = encode_context_time(&apdu[0], context_tag_number,
apdu_len =
encode_context_time(&apdu[0], context_tag_number,
&value->type.Time);
break;
#endif
@@ -445,8 +466,9 @@ int bacapp_encode_context_data(
if (value && apdu) {
tag_data_type = bacapp_context_tag_type(property, value->context_tag);
if (tag_data_type < MAX_BACNET_APPLICATION_TAG) {
apdu_len = bacapp_encode_context_data_value(&apdu[0],
value->context_tag, value);
apdu_len =
bacapp_encode_context_data_value(&apdu[0], value->context_tag,
value);
} else {
/* FIXME: what now? */
apdu_len = 0;
@@ -472,15 +494,17 @@ int bacapp_decode_context_data(
max_apdu_len = max_apdu_len;
if (apdu && value && decode_is_context_specific(apdu)) {
value->context_specific = true;
tag_len = decode_tag_number_and_value(&apdu[0],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[0], &tag_number,
&len_value_type);
if (tag_len) {
apdu_len = tag_len;
value->context_tag = tag_number;
value->tag = bacapp_context_tag_type(property, tag_number);
if (value->tag < MAX_BACNET_APPLICATION_TAG) {
len = bacapp_decode_data(&apdu[apdu_len],
value->tag, len_value_type, value);
len =
bacapp_decode_data(&apdu[apdu_len], value->tag,
len_value_type, value);
apdu_len += len;
} else {
/* FIXME: what now? */
@@ -501,8 +525,9 @@ int bacapp_encode_data(
if (value && apdu) {
if (value->context_specific) {
apdu_len = bacapp_encode_context_data_value(&apdu[0],
value->context_tag, value);
apdu_len =
bacapp_encode_context_data_value(&apdu[0], value->context_tag,
value);
} else {
apdu_len = bacapp_encode_application_data(&apdu[0], value);
}
@@ -622,29 +647,33 @@ int bacapp_data_len(
BACNET_APPLICATION_DATA_VALUE application_value;
if (decode_is_opening_tag(&apdu[0])) {
len = decode_tag_number_and_value(&apdu[apdu_len],
&tag_number, &value);
len =
decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &value);
apdu_len += len;
opening_tag_number = tag_number;
opening_tag_number_counter = 1;
while (opening_tag_number_counter) {
if (decode_is_opening_tag(&apdu[apdu_len])) {
len = decode_tag_number_and_value(&apdu[apdu_len],
&tag_number, &value);
len =
decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
&value);
if (tag_number == opening_tag_number)
opening_tag_number_counter++;
} else if (decode_is_closing_tag(&apdu[apdu_len])) {
len = decode_tag_number_and_value(&apdu[apdu_len],
&tag_number, &value);
len =
decode_tag_number_and_value(&apdu[apdu_len], &tag_number,
&value);
if (tag_number == opening_tag_number)
opening_tag_number_counter--;
} else if (decode_is_context_specific(&apdu[apdu_len])) {
/* context-specific tagged data */
len = bacapp_decode_context_data(&apdu[apdu_len],
len =
bacapp_decode_context_data(&apdu[apdu_len],
max_apdu_len - apdu_len, &application_value, property);
} else {
/* application tagged data */
len = bacapp_decode_application_data(&apdu[apdu_len],
len =
bacapp_decode_application_data(&apdu[apdu_len],
max_apdu_len - apdu_len, &application_value);
}
apdu_len += len;
@@ -850,7 +879,8 @@ bool bacapp_parse_application_data(
break;
#endif
case BACNET_APPLICATION_TAG_OCTET_STRING:
status = octetstring_init(&value->type.Octet_String,
status =
octetstring_init(&value->type.Octet_String,
(uint8_t *) argv, strlen(argv));
break;
case BACNET_APPLICATION_TAG_CHARACTER_STRING:
@@ -871,8 +901,8 @@ bool bacapp_parse_application_data(
count =
sscanf(argv, "%d/%d/%d:%d", &year, &month, &day, &wday);
if (count == 3) {
datetime_set_date(&value->type.Date,
(uint16_t) year, (uint8_t) month, (uint8_t) day);
datetime_set_date(&value->type.Date, (uint16_t) year,
(uint8_t) month, (uint8_t) day);
} else if (count == 4) {
value->type.Date.year = year;
value->type.Date.month = month;
@@ -1012,7 +1042,8 @@ bool bacapp_same_value(
#endif
#if defined (BACAPP_CHARACTER_STRING)
case BACNET_APPLICATION_TAG_CHARACTER_STRING:
status = characterstring_same(&value->type.Character_String,
status =
characterstring_same(&value->type.Character_String,
&test_value->type.Character_String);
break;
#endif
@@ -1046,7 +1077,8 @@ void testBACnetApplicationDataLength(
len = encode_closing_tag(&apdu[apdu_len], 3);
apdu_len += len;
/* verify the length of the data inside the opening/closing tags */
len = bacapp_data_len(&apdu[0], apdu_len,
len =
bacapp_data_len(&apdu[0], apdu_len,
PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES);
ct_test(pTest, test_len == len);
@@ -1194,27 +1226,30 @@ void testBACnetApplicationData(
bool status = false;
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_NULL,
NULL, &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_NULL, NULL,
&value);
ct_test(pTest, status == true);
status = testBACnetApplicationDataValue(&value);
ct_test(pTest, status == true);
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_BOOLEAN,
"1", &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_BOOLEAN, "1",
&value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Boolean == true);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_BOOLEAN,
"0", &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_BOOLEAN, "0",
&value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Boolean == false);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_UNSIGNED_INT,
"0", &value);
bacapp_parse_application_data(BACNET_APPLICATION_TAG_UNSIGNED_INT, "0",
&value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Unsigned_Int == 0);
ct_test(pTest, testBACnetApplicationDataValue(&value));
@@ -1232,14 +1267,14 @@ void testBACnetApplicationData(
ct_test(pTest, testBACnetApplicationDataValue(&value));
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_SIGNED_INT,
"0", &value);
bacapp_parse_application_data(BACNET_APPLICATION_TAG_SIGNED_INT, "0",
&value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Signed_Int == 0);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_SIGNED_INT,
"-1", &value);
bacapp_parse_application_data(BACNET_APPLICATION_TAG_SIGNED_INT, "-1",
&value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Signed_Int == -1);
ct_test(pTest, testBACnetApplicationDataValue(&value));
@@ -1256,30 +1291,35 @@ void testBACnetApplicationData(
ct_test(pTest, value.type.Signed_Int == -32768);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL,
"0.0", &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "0.0",
&value);
ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL,
"-1.0", &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "-1.0",
&value);
ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL,
"1.0", &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "1.0",
&value);
ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL,
"3.14159", &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "3.14159",
&value);
ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL,
"-3.14159", &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "-3.14159",
&value);
ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_ENUMERATED,
"0", &value);
bacapp_parse_application_data(BACNET_APPLICATION_TAG_ENUMERATED, "0",
&value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Enumerated == 0);
ct_test(pTest, testBACnetApplicationDataValue(&value));
@@ -1296,7 +1336,8 @@ void testBACnetApplicationData(
ct_test(pTest, value.type.Enumerated == 0xFFFFFFFF);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE,
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE,
"2005/5/22:1", &value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Date.year == 2005);
@@ -1306,8 +1347,9 @@ void testBACnetApplicationData(
ct_test(pTest, testBACnetApplicationDataValue(&value));
/* Happy Valentines Day! */
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE,
"2007/2/14", &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE, "2007/2/14",
&value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Date.year == 2007);
ct_test(pTest, value.type.Date.month == 2);
@@ -1316,7 +1358,8 @@ void testBACnetApplicationData(
ct_test(pTest, testBACnetApplicationDataValue(&value));
/* Wildcard Values */
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE,
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE,
"2155/255/255:255", &value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Date.year == 2155);
@@ -1325,7 +1368,8 @@ void testBACnetApplicationData(
ct_test(pTest, value.type.Date.wday == 255);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME,
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME,
"23:59:59.12", &value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Time.hour == 23);
@@ -1334,8 +1378,9 @@ void testBACnetApplicationData(
ct_test(pTest, value.type.Time.hundredths == 12);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME,
"23:59:59", &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME, "23:59:59",
&value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Time.hour == 23);
ct_test(pTest, value.type.Time.min == 59);
@@ -1343,8 +1388,9 @@ void testBACnetApplicationData(
ct_test(pTest, value.type.Time.hundredths == 0);
ct_test(pTest, testBACnetApplicationDataValue(&value));
status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME,
"23:59", &value);
status =
bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME, "23:59",
&value);
ct_test(pTest, status == true);
ct_test(pTest, value.type.Time.hour == 23);
ct_test(pTest, value.type.Time.min == 59);
@@ -1361,8 +1407,8 @@ void testBACnetApplicationData(
ct_test(pTest, testBACnetApplicationDataValue(&value));
status =
bacapp_parse_application_data
(BACNET_APPLICATION_TAG_CHARACTER_STRING, "Karg!", &value);
bacapp_parse_application_data(BACNET_APPLICATION_TAG_CHARACTER_STRING,
"Karg!", &value);
ct_test(pTest, status == true);
ct_test(pTest, testBACnetApplicationDataValue(&value));
+40 -30
View File
@@ -442,8 +442,8 @@ int encode_application_boolean(
if (boolean_value)
len_value = 1;
len = encode_tag(&apdu[0], BACNET_APPLICATION_TAG_BOOLEAN, false,
len_value);
len =
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_BOOLEAN, false, len_value);
return len;
}
@@ -553,8 +553,8 @@ int decode_bitstring(
byte_reverse_bits(apdu[len++]));
}
unused_bits = apdu[0] & 0x07;
bitstring_set_bits_used(bit_string,
(uint8_t) bytes_used, unused_bits);
bitstring_set_bits_used(bit_string, (uint8_t) bytes_used,
unused_bits);
}
}
@@ -577,8 +577,8 @@ int encode_bitstring(
apdu[len++] = 0;
else {
used_bytes = bitstring_bytes_used(bit_string);
remaining_used_bits = bitstring_bits_used(bit_string) -
((used_bytes - 1) * 8);
remaining_used_bits =
bitstring_bits_used(bit_string) - ((used_bytes - 1) * 8);
/* number of unused bits in the subsequent final octet */
apdu[len++] = 8 - remaining_used_bits;
for (i = 0; i < used_bytes; i++) {
@@ -598,7 +598,8 @@ int encode_application_bitstring(
/* bit string may use more than 1 octet for the tag, so find out how many */
bit_string_encoded_length += bitstring_bytes_used(bit_string);
len = encode_tag(&apdu[0], BACNET_APPLICATION_TAG_BIT_STRING, false,
len =
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_BIT_STRING, false,
bit_string_encoded_length);
len += encode_bitstring(&apdu[len], bit_string);
@@ -652,8 +653,9 @@ int encode_bacnet_object_id(
int len = 0;
type = object_type;
value = ((type & BACNET_MAX_OBJECT) << BACNET_INSTANCE_BITS) |
(instance & BACNET_MAX_INSTANCE);
value =
((type & BACNET_MAX_OBJECT) << BACNET_INSTANCE_BITS) | (instance &
BACNET_MAX_INSTANCE);
len = encode_unsigned32(apdu, value);
return len;
@@ -732,8 +734,8 @@ int encode_application_octet_string(
if (octet_string) {
apdu_len =
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_OCTET_STRING,
false, octetstring_length(octet_string));
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_OCTET_STRING, false,
octetstring_length(octet_string));
/* FIXME: probably need to pass in the length of the APDU
to bounds check since it might not be the only data chunk */
if ((apdu_len + octetstring_length(octet_string)) < MAX_APDU)
@@ -756,8 +758,9 @@ int encode_context_octet_string(
int apdu_len = 0;
if (apdu && octet_string) {
apdu_len = encode_tag(&apdu[0], (uint8_t) tag_number,
true, octetstring_length(octet_string));
apdu_len =
encode_tag(&apdu[0], (uint8_t) tag_number, true,
octetstring_length(octet_string));
if ((apdu_len + octetstring_length(octet_string)) < MAX_APDU)
apdu_len += encode_octet_string(&apdu[apdu_len], octet_string);
else
@@ -816,8 +819,8 @@ int encode_application_character_string(
string_len = characterstring_length(char_string) + 1 /* for encoding */ ;
len =
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_CHARACTER_STRING,
false, string_len);
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_CHARACTER_STRING, false,
string_len);
if ((len + string_len) < MAX_APDU)
len += encode_bacnet_character_string(&apdu[len], char_string);
else
@@ -855,7 +858,8 @@ int decode_character_string(
int len = 0; /* return value */
bool status = false;
status = characterstring_init(char_string, apdu[0], (char *) &apdu[1],
status =
characterstring_init(char_string, apdu[0], (char *) &apdu[1],
len_value - 1);
if (status)
len = len_value;
@@ -950,8 +954,8 @@ int encode_application_unsigned(
int len = 0;
len = encode_bacnet_unsigned(&apdu[1], value);
len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_UNSIGNED_INT,
false, len);
len +=
encode_tag(&apdu[0], BACNET_APPLICATION_TAG_UNSIGNED_INT, false, len);
return len;
}
@@ -1410,7 +1414,8 @@ void testBACDCodeTags(
/* test the len-value-type portion */
for (value = 1;; value = value << 1) {
len = encode_tag(&apdu[0], tag_number, false, value);
len = decode_tag_number_and_value(&apdu[0], &test_tag_number,
len =
decode_tag_number_and_value(&apdu[0], &test_tag_number,
&test_value);
ct_test(pTest, tag_number == test_tag_number);
ct_test(pTest, value == test_value);
@@ -1682,7 +1687,8 @@ void testBACDCodeOctetString(
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OCTET_STRING);
len += decode_octet_string(&array[len], len_value, &test_octet_string);
ct_test(pTest, apdu_len == len);
diff = memcmp(octetstring_value(&octet_string), &test_value[0],
diff =
memcmp(octetstring_value(&octet_string), &test_value[0],
octetstring_length(&octet_string));
ct_test(pTest, diff == 0);
@@ -1696,13 +1702,15 @@ void testBACDCodeOctetString(
decode_tag_number_and_value(&encoded_array[0], &tag_number,
&len_value);
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OCTET_STRING);
len += decode_octet_string(&encoded_array[len], len_value,
len +=
decode_octet_string(&encoded_array[len], len_value,
&test_octet_string);
if (apdu_len != len) {
printf("test octet string=#%d\n", i);
}
ct_test(pTest, apdu_len == len);
diff = memcmp(octetstring_value(&octet_string), &test_value[0],
diff =
memcmp(octetstring_value(&octet_string), &test_value[0],
octetstring_length(&octet_string));
if (diff) {
printf("test octet string=#%d\n", i);
@@ -1736,7 +1744,8 @@ void testBACDCodeCharacterString(
ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_CHARACTER_STRING);
len += decode_character_string(&array[len], len_value, &test_char_string);
ct_test(pTest, apdu_len == len);
diff = memcmp(characterstring_value(&char_string), &test_value[0],
diff =
memcmp(characterstring_value(&char_string), &test_value[0],
characterstring_length(&char_string));
ct_test(pTest, diff == 0);
for (i = 0; i < MAX_CHARACTER_STRING_BYTES - 1; i++) {
@@ -1758,7 +1767,8 @@ void testBACDCodeCharacterString(
printf("test string=#%d apdu_len=%d len=%d\n", i, apdu_len, len);
}
ct_test(pTest, apdu_len == len);
diff = memcmp(characterstring_value(&char_string), &test_value[0],
diff =
memcmp(characterstring_value(&char_string), &test_value[0],
characterstring_length(&char_string));
if (diff) {
printf("test string=#%d\n", i);
@@ -1784,8 +1794,8 @@ void testBACDCodeObject(
uint32_t decoded_instance = 0;
encode_bacnet_object_id(&encoded_array[0], type, instance);
decode_object_id(&encoded_array[0],
(int *) &decoded_type, &decoded_instance);
decode_object_id(&encoded_array[0], (int *) &decoded_type,
&decoded_instance);
ct_test(pTest, decoded_type == type);
ct_test(pTest, decoded_instance == instance);
encode_bacnet_object_id(&object_array[0], type, instance);
@@ -1794,13 +1804,13 @@ void testBACDCodeObject(
for (type = 0; type < 1024; type++) {
for (instance = 0; instance <= BACNET_MAX_INSTANCE; instance += 1024) {
encode_bacnet_object_id(&encoded_array[0], type, instance);
decode_object_id(&encoded_array[0],
(int *) &decoded_type, &decoded_instance);
decode_object_id(&encoded_array[0], (int *) &decoded_type,
&decoded_instance);
ct_test(pTest, decoded_type == type);
ct_test(pTest, decoded_instance == instance);
encode_bacnet_object_id(&object_array[0], type, instance);
ct_test(pTest, memcmp(&object_array[0],
&encoded_array[0], sizeof(object_array)) == 0);
ct_test(pTest, memcmp(&object_array[0], &encoded_array[0],
sizeof(object_array)) == 0);
}
}
+42 -36
View File
@@ -74,16 +74,18 @@ int bacerror_decode_error_class_and_code(
if (apdu_len) {
/* error class */
len += decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
len +=
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED)
return 0;
len += decode_enumerated(&apdu[len], len_value_type, &decoded_value);
if (error_class)
*error_class = (BACNET_ERROR_CLASS) decoded_value;
/* error code */
len += decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
len +=
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED)
return 0;
len += decode_enumerated(&apdu[len], len_value_type, &decoded_value);
@@ -111,8 +113,9 @@ int bacerror_decode_service_request(
if (service)
*service = (BACNET_CONFIRMED_SERVICE) apdu[1];
/* decode the application class and code */
len = bacerror_decode_error_class_and_code(&apdu[2],
apdu_len - 2, error_class, error_code);
len =
bacerror_decode_error_class_and_code(&apdu[2], apdu_len - 2,
error_class, error_code);
}
return len;
@@ -141,8 +144,9 @@ int bacerror_decode_apdu(
if (apdu[0] != PDU_TYPE_ERROR)
return -1;
if (apdu_len > 1) {
len = bacerror_decode_service_request(&apdu[1],
apdu_len - 1, invoke_id, service, error_class, error_code);
len =
bacerror_decode_service_request(&apdu[1], apdu_len - 1,
invoke_id, service, error_class, error_code);
}
}
@@ -164,14 +168,15 @@ void testBACError(
BACNET_ERROR_CLASS test_error_class = 0;
BACNET_ERROR_CODE test_error_code = 0;
len = bacerror_encode_apdu(&apdu[0],
invoke_id, service, error_class, error_code);
len =
bacerror_encode_apdu(&apdu[0], invoke_id, service, error_class,
error_code);
ct_test(pTest, len != 0);
apdu_len = len;
len = bacerror_decode_apdu(&apdu[0],
apdu_len,
&test_invoke_id, &test_service, &test_error_class, &test_error_code);
len =
bacerror_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_service, &test_error_class, &test_error_code);
ct_test(pTest, len != -1);
ct_test(pTest, test_invoke_id == invoke_id);
ct_test(pTest, test_service == service);
@@ -180,37 +185,37 @@ void testBACError(
/* change type to get negative response */
apdu[0] = PDU_TYPE_ABORT;
len = bacerror_decode_apdu(&apdu[0],
apdu_len,
&test_invoke_id, &test_service, &test_error_class, &test_error_code);
len =
bacerror_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_service, &test_error_class, &test_error_code);
ct_test(pTest, len == -1);
/* test NULL APDU */
len = bacerror_decode_apdu(NULL,
apdu_len,
&test_invoke_id, &test_service, &test_error_class, &test_error_code);
len =
bacerror_decode_apdu(NULL, apdu_len, &test_invoke_id, &test_service,
&test_error_class, &test_error_code);
ct_test(pTest, len == -1);
/* force a zero length */
len = bacerror_decode_apdu(&apdu[0],
0,
&test_invoke_id, &test_service, &test_error_class, &test_error_code);
len =
bacerror_decode_apdu(&apdu[0], 0, &test_invoke_id, &test_service,
&test_error_class, &test_error_code);
ct_test(pTest, len == 0);
/* check them all... */
for (service = 0; service < MAX_BACNET_CONFIRMED_SERVICE; service++) {
for (error_class = 0;
error_class < MAX_BACNET_ERROR_CLASS; error_class++) {
for (error_code = 0;
error_code < MAX_BACNET_ERROR_CODE; error_code++) {
len = bacerror_encode_apdu(&apdu[0],
invoke_id, service, error_class, error_code);
for (error_class = 0; error_class < MAX_BACNET_ERROR_CLASS;
error_class++) {
for (error_code = 0; error_code < MAX_BACNET_ERROR_CODE;
error_code++) {
len =
bacerror_encode_apdu(&apdu[0], invoke_id, service,
error_class, error_code);
apdu_len = len;
ct_test(pTest, len != 0);
len = bacerror_decode_apdu(&apdu[0],
apdu_len,
&test_invoke_id,
len =
bacerror_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_service, &test_error_class, &test_error_code);
ct_test(pTest, len != -1);
ct_test(pTest, test_invoke_id == invoke_id);
@@ -225,13 +230,14 @@ void testBACError(
service = 255;
error_class = LAST_PROPRIETARY_ERROR_CLASS;
error_code = LAST_PROPRIETARY_ERROR_CODE;
len = bacerror_encode_apdu(&apdu[0],
invoke_id, service, error_class, error_code);
len =
bacerror_encode_apdu(&apdu[0], invoke_id, service, error_class,
error_code);
apdu_len = len;
ct_test(pTest, len != 0);
len = bacerror_decode_apdu(&apdu[0],
apdu_len,
&test_invoke_id, &test_service, &test_error_class, &test_error_code);
len =
bacerror_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_service, &test_error_class, &test_error_code);
ct_test(pTest, len != -1);
ct_test(pTest, test_invoke_id == invoke_id);
ct_test(pTest, test_service == service);
+20 -17
View File
@@ -229,16 +229,15 @@ bool characterstring_init_ansi(
BACNET_CHARACTER_STRING * char_string,
char *value)
{
return characterstring_init(char_string,
CHARACTER_ANSI_X34, value, value ? strlen(value) : 0);
return characterstring_init(char_string, CHARACTER_ANSI_X34, value,
value ? strlen(value) : 0);
}
bool characterstring_copy(
BACNET_CHARACTER_STRING * dest,
BACNET_CHARACTER_STRING * src)
{
return characterstring_init(dest,
characterstring_encoding(src),
return characterstring_init(dest, characterstring_encoding(src),
characterstring_value(src), characterstring_length(src));
}
@@ -429,8 +428,8 @@ bool octetstring_copy(
BACNET_OCTET_STRING * dest,
BACNET_OCTET_STRING * src)
{
return octetstring_init(dest,
octetstring_value(src), octetstring_length(src));
return octetstring_init(dest, octetstring_value(src),
octetstring_length(src));
}
/* returns false if the string exceeds capacity */
@@ -568,9 +567,9 @@ void testCharacterString(
ct_test(pTest,
characterstring_encoding(&bacnet_string) == CHARACTER_ANSI_X34);
/* bounds check */
status = characterstring_init(&bacnet_string,
CHARACTER_ANSI_X34,
NULL, characterstring_capacity(&bacnet_string) + 1);
status =
characterstring_init(&bacnet_string, CHARACTER_ANSI_X34, NULL,
characterstring_capacity(&bacnet_string) + 1);
ct_test(pTest, status == false);
status =
characterstring_truncate(&bacnet_string,
@@ -582,8 +581,9 @@ void testCharacterString(
ct_test(pTest, status == true);
test_length = strlen(test_value);
status = characterstring_init(&bacnet_string,
CHARACTER_ANSI_X34, &test_value[0], test_length);
status =
characterstring_init(&bacnet_string, CHARACTER_ANSI_X34,
&test_value[0], test_length);
ct_test(pTest, status == true);
value = characterstring_value(&bacnet_string);
length = characterstring_length(&bacnet_string);
@@ -592,8 +592,9 @@ void testCharacterString(
ct_test(pTest, value[i] == test_value[i]);
}
test_length = strlen(test_append_value);
status = characterstring_append(&bacnet_string,
&test_append_value[0], test_length);
status =
characterstring_append(&bacnet_string, &test_append_value[0],
test_length);
strcat(test_append_string, test_value);
strcat(test_append_string, test_append_value);
test_length = strlen(test_append_string);
@@ -628,10 +629,12 @@ void testOctetString(
ct_test(pTest, value[i] == 0);
}
/* bounds check */
status = octetstring_init(&bacnet_string, NULL,
status =
octetstring_init(&bacnet_string, NULL,
octetstring_capacity(&bacnet_string) + 1);
ct_test(pTest, status == false);
status = octetstring_init(&bacnet_string, NULL,
status =
octetstring_init(&bacnet_string, NULL,
octetstring_capacity(&bacnet_string));
ct_test(pTest, status == true);
status =
@@ -654,8 +657,8 @@ void testOctetString(
}
test_length = strlen((char *) test_append_value);
status = octetstring_append(&bacnet_string,
&test_append_value[0], test_length);
status =
octetstring_append(&bacnet_string, &test_append_value[0], test_length);
strcat((char *) test_append_string, (char *) test_value);
strcat((char *) test_append_string, (char *) test_append_value);
test_length = strlen((char *) test_append_string);
+40 -44
View File
@@ -78,8 +78,8 @@ INDTEXT_DATA bacnet_confirmed_service_names[] = {
const char *bactext_confirmed_service_name(
int index)
{
return indtext_by_index_default(bacnet_confirmed_service_names,
index, ASHRAE_Reserved_String);
return indtext_by_index_default(bacnet_confirmed_service_names, index,
ASHRAE_Reserved_String);
}
INDTEXT_DATA bacnet_unconfirmed_service_names[] = {
@@ -110,8 +110,8 @@ INDTEXT_DATA bacnet_unconfirmed_service_names[] = {
const char *bactext_unconfirmed_service_name(
int index)
{
return indtext_by_index_default(bacnet_unconfirmed_service_names,
index, ASHRAE_Reserved_String);
return indtext_by_index_default(bacnet_unconfirmed_service_names, index,
ASHRAE_Reserved_String);
}
INDTEXT_DATA bacnet_application_tag_names[] = {
@@ -153,8 +153,8 @@ INDTEXT_DATA bacnet_application_tag_names[] = {
const char *bactext_application_tag_name(
int index)
{
return indtext_by_index_default(bacnet_application_tag_names,
index, ASHRAE_Reserved_String);
return indtext_by_index_default(bacnet_application_tag_names, index,
ASHRAE_Reserved_String);
}
INDTEXT_DATA bacnet_object_type_names[] = {
@@ -229,8 +229,8 @@ INDTEXT_DATA bacnet_object_type_names[] = {
const char *bactext_object_type_name(
int index)
{
return indtext_by_index_split_default(bacnet_object_type_names,
index, 128, ASHRAE_Reserved_String, Vendor_Proprietary_String);
return indtext_by_index_split_default(bacnet_object_type_names, index, 128,
ASHRAE_Reserved_String, Vendor_Proprietary_String);
}
INDTEXT_DATA bacnet_property_names[] = {
@@ -692,8 +692,8 @@ INDTEXT_DATA bacnet_property_names[] = {
const char *bactext_property_name(
int index)
{
return indtext_by_index_split_default(bacnet_property_names,
index, 512, ASHRAE_Reserved_String, Vendor_Proprietary_String);
return indtext_by_index_split_default(bacnet_property_names, index, 512,
ASHRAE_Reserved_String, Vendor_Proprietary_String);
}
unsigned bactext_property_id(
@@ -1099,8 +1099,8 @@ INDTEXT_DATA bacnet_engineering_unit_names[] = {
const char *bactext_engineering_unit_name(
int index)
{
return indtext_by_index_split_default(bacnet_engineering_unit_names,
index, 256, ASHRAE_Reserved_String, Vendor_Proprietary_String);
return indtext_by_index_split_default(bacnet_engineering_unit_names, index,
256, ASHRAE_Reserved_String, Vendor_Proprietary_String);
}
INDTEXT_DATA bacnet_reject_reason_names[] = {
@@ -1131,10 +1131,9 @@ INDTEXT_DATA bacnet_reject_reason_names[] = {
const char *bactext_reject_reason_name(
int index)
{
return indtext_by_index_split_default(bacnet_reject_reason_names,
index,
FIRST_PROPRIETARY_REJECT_REASON,
ASHRAE_Reserved_String, Vendor_Proprietary_String);
return indtext_by_index_split_default(bacnet_reject_reason_names, index,
FIRST_PROPRIETARY_REJECT_REASON, ASHRAE_Reserved_String,
Vendor_Proprietary_String);
}
INDTEXT_DATA bacnet_abort_reason_names[] = {
@@ -1155,10 +1154,9 @@ INDTEXT_DATA bacnet_abort_reason_names[] = {
const char *bactext_abort_reason_name(
int index)
{
return indtext_by_index_split_default(bacnet_abort_reason_names,
index,
FIRST_PROPRIETARY_ABORT_REASON,
ASHRAE_Reserved_String, Vendor_Proprietary_String);
return indtext_by_index_split_default(bacnet_abort_reason_names, index,
FIRST_PROPRIETARY_ABORT_REASON, ASHRAE_Reserved_String,
Vendor_Proprietary_String);
}
INDTEXT_DATA bacnet_error_class_names[] = {
@@ -1182,10 +1180,9 @@ INDTEXT_DATA bacnet_error_class_names[] = {
const char *bactext_error_class_name(
int index)
{
return indtext_by_index_split_default(bacnet_error_class_names,
index,
FIRST_PROPRIETARY_ERROR_CLASS,
ASHRAE_Reserved_String, Vendor_Proprietary_String);
return indtext_by_index_split_default(bacnet_error_class_names, index,
FIRST_PROPRIETARY_ERROR_CLASS, ASHRAE_Reserved_String,
Vendor_Proprietary_String);
}
INDTEXT_DATA bacnet_error_code_names[] = {
@@ -1307,10 +1304,9 @@ INDTEXT_DATA bacnet_error_code_names[] = {
const char *bactext_error_code_name(
int index)
{
return indtext_by_index_split_default(bacnet_error_code_names,
index,
FIRST_PROPRIETARY_ERROR_CLASS,
ASHRAE_Reserved_String, Vendor_Proprietary_String);
return indtext_by_index_split_default(bacnet_error_code_names, index,
FIRST_PROPRIETARY_ERROR_CLASS, ASHRAE_Reserved_String,
Vendor_Proprietary_String);
}
INDTEXT_DATA bacnet_month_names[] = {
@@ -1346,8 +1342,8 @@ INDTEXT_DATA bacnet_month_names[] = {
const char *bactext_month_name(
int index)
{
return indtext_by_index_default(bacnet_month_names,
index, ASHRAE_Reserved_String);
return indtext_by_index_default(bacnet_month_names, index,
ASHRAE_Reserved_String);
}
INDTEXT_DATA bacnet_week_of_month_names[] = {
@@ -1371,8 +1367,8 @@ INDTEXT_DATA bacnet_week_of_month_names[] = {
const char *bactext_week_of_month_name(
int index)
{
return indtext_by_index_default(bacnet_week_of_month_names,
index, ASHRAE_Reserved_String);
return indtext_by_index_default(bacnet_week_of_month_names, index,
ASHRAE_Reserved_String);
}
/* note: different than DaysOfWeek bit string where 0=monday */
@@ -1399,8 +1395,8 @@ INDTEXT_DATA bacnet_day_of_week_names[] = {
const char *bactext_day_of_week_name(
int index)
{
return indtext_by_index_default(bacnet_day_of_week_names,
index, ASHRAE_Reserved_String);
return indtext_by_index_default(bacnet_day_of_week_names, index,
ASHRAE_Reserved_String);
}
INDTEXT_DATA bacnet_event_state_names[] = {
@@ -1420,8 +1416,8 @@ INDTEXT_DATA bacnet_event_state_names[] = {
const char *bactext_event_state_name(
int index)
{
return indtext_by_index_default(bacnet_event_state_names,
index, ASHRAE_Reserved_String);
return indtext_by_index_default(bacnet_event_state_names, index,
ASHRAE_Reserved_String);
}
INDTEXT_DATA bacnet_binary_present_value_names[] = {
@@ -1435,8 +1431,8 @@ INDTEXT_DATA bacnet_binary_present_value_names[] = {
const char *bactext_binary_present_value_name(
int index)
{
return indtext_by_index_default(bacnet_binary_present_value_names,
index, ASHRAE_Reserved_String);
return indtext_by_index_default(bacnet_binary_present_value_names, index,
ASHRAE_Reserved_String);
}
INDTEXT_DATA bacnet_reliability_names[] = {
@@ -1468,8 +1464,8 @@ INDTEXT_DATA bacnet_reliability_names[] = {
const char *bactext_reliability_name(
int index)
{
return indtext_by_index_default(bacnet_reliability_names,
index, ASHRAE_Reserved_String);
return indtext_by_index_default(bacnet_reliability_names, index,
ASHRAE_Reserved_String);
}
INDTEXT_DATA bacnet_device_status_names[] = {
@@ -1489,8 +1485,8 @@ INDTEXT_DATA bacnet_device_status_names[] = {
const char *bactext_device_status_name(
int index)
{
return indtext_by_index_default(bacnet_device_status_names,
index, ASHRAE_Reserved_String);
return indtext_by_index_default(bacnet_device_status_names, index,
ASHRAE_Reserved_String);
}
INDTEXT_DATA bacnet_segmentation_names[] = {
@@ -1508,6 +1504,6 @@ INDTEXT_DATA bacnet_segmentation_names[] = {
const char *bactext_segmentation_name(
int index)
{
return indtext_by_index_default(bacnet_segmentation_names,
index, ASHRAE_Reserved_String);
return indtext_by_index_default(bacnet_segmentation_names, index,
ASHRAE_Reserved_String);
}
+5 -3
View File
@@ -163,7 +163,8 @@ int bip_send_pdu(
mtu_len += pdu_len;
/* Send the packet */
bytes_sent = sendto(BIP_Socket, (char *) mtu, mtu_len, 0,
bytes_sent =
sendto(BIP_Socket, (char *) mtu, mtu_len, 0,
(struct sockaddr *) &bip_dest, sizeof(struct sockaddr));
return bytes_sent;
@@ -206,8 +207,9 @@ uint16_t bip_receive(
max = BIP_Socket;
/* see if there is a packet for us */
if (select(max + 1, &read_fds, NULL, NULL, &select_timeout) > 0)
received_bytes = recvfrom(BIP_Socket,
(char *) &pdu[0], max_pdu, 0, (struct sockaddr *) &sin, &sin_len);
received_bytes =
recvfrom(BIP_Socket, (char *) &pdu[0], max_pdu, 0,
(struct sockaddr *) &sin, &sin_len);
else
return 0;
+13 -10
View File
@@ -253,9 +253,10 @@ int bvlc_encode_read_bdt_ack(
pdu_len = 0;
break;
}
len = bvlc_encode_address_entry(&pdu[pdu_len],
&BBMD_Table[i].dest_address,
BBMD_Table[i].dest_port, &BBMD_Table[i].broadcast_mask);
len =
bvlc_encode_address_entry(&pdu[pdu_len],
&BBMD_Table[i].dest_address, BBMD_Table[i].dest_port,
&BBMD_Table[i].broadcast_mask);
pdu_len += len;
}
}
@@ -375,7 +376,8 @@ int bvlc_encode_read_fdt_ack(
pdu_len = 0;
break;
}
len = bvlc_encode_bip_address(&pdu[pdu_len],
len =
bvlc_encode_bip_address(&pdu[pdu_len],
&FD_Table[i].dest_address, FD_Table[i].dest_port);
pdu_len += len;
encode_unsigned16(&pdu[pdu_len], FD_Table[i].time_to_live);
@@ -656,8 +658,8 @@ void bvlc_bdt_forward_npdu(
mask in the BDT entry and logically ORing it with the
BBMD address of the same entry. */
bip_dest.sin_addr.s_addr =
htonl(((~BBMD_Table[i].broadcast_mask.s_addr) |
BBMD_Table[i].dest_address.s_addr));
htonl(((~BBMD_Table[i].broadcast_mask.s_addr) | BBMD_Table[i].
dest_address.s_addr));
bip_dest.sin_port = htons(BBMD_Table[i].dest_port);
/* don't send to my broadcast address and same port */
if ((bip_dest.sin_addr.s_addr == htonl(bip_get_broadcast_addr()))
@@ -843,9 +845,9 @@ uint16_t bvlc_receive(
max = bip_socket();
/* see if there is a packet for us */
if (select(max + 1, &read_fds, NULL, NULL, &select_timeout) > 0) {
received_bytes = recvfrom(bip_socket(),
(char *) &npdu[0],
max_npdu, 0, (struct sockaddr *) &sin, &sin_len);
received_bytes =
recvfrom(bip_socket(), (char *) &npdu[0], max_npdu, 0,
(struct sockaddr *) &sin, &sin_len);
} else {
return 0;
}
@@ -1110,7 +1112,8 @@ int bvlc_send_pdu(
mtu_len += pdu_len;
/* Send the packet */
bytes_sent = sendto(bip_socket(), (char *) mtu, mtu_len, 0,
bytes_sent =
sendto(bip_socket(), (char *) mtu, mtu_len, 0,
(struct sockaddr *) &bvlc_dest, sizeof(struct sockaddr));
return bytes_sent;
+58 -43
View File
@@ -59,16 +59,18 @@ static int notify_encode_adpu(
if (apdu) {
/* tag 0 - subscriberProcessIdentifier */
len = encode_context_unsigned(&apdu[apdu_len],
0, data->subscriberProcessIdentifier);
len =
encode_context_unsigned(&apdu[apdu_len], 0,
data->subscriberProcessIdentifier);
apdu_len += len;
/* tag 1 - initiatingDeviceIdentifier */
len = encode_context_object_id(&apdu[apdu_len],
1, OBJECT_DEVICE, data->initiatingDeviceIdentifier);
len =
encode_context_object_id(&apdu[apdu_len], 1, OBJECT_DEVICE,
data->initiatingDeviceIdentifier);
apdu_len += len;
/* tag 2 - monitoredObjectIdentifier */
len = encode_context_object_id(&apdu[apdu_len],
2,
len =
encode_context_object_id(&apdu[apdu_len], 2,
data->monitoredObjectIdentifier.type,
data->monitoredObjectIdentifier.instance);
apdu_len += len;
@@ -85,27 +87,30 @@ static int notify_encode_adpu(
value = &data->listOfValues;
while (value != NULL) {
/* tag 0 - propertyIdentifier */
len = encode_context_enumerated(&apdu[apdu_len],
0, value->propertyIdentifier);
len =
encode_context_enumerated(&apdu[apdu_len], 0,
value->propertyIdentifier);
apdu_len += len;
/* tag 1 - propertyArrayIndex OPTIONAL */
if (value->propertyArrayIndex != BACNET_ARRAY_ALL) {
len = encode_context_unsigned(&apdu[apdu_len],
1, value->propertyArrayIndex);
len =
encode_context_unsigned(&apdu[apdu_len], 1,
value->propertyArrayIndex);
apdu_len += len;
}
/* tag 2 - value */
/* abstract syntax gets enclosed in a context tag */
len = encode_opening_tag(&apdu[apdu_len], 2);
apdu_len += len;
len = bacapp_encode_application_data(&apdu[apdu_len],
&value->value);
len =
bacapp_encode_application_data(&apdu[apdu_len], &value->value);
apdu_len += len;
len = encode_closing_tag(&apdu[apdu_len], 2);
apdu_len += len;
/* tag 3 - priority OPTIONAL */
if (value->priority != BACNET_NO_PRIORITY) {
len = encode_context_unsigned(&apdu[apdu_len], 3,
len =
encode_context_unsigned(&apdu[apdu_len], 3,
value->priority);
apdu_len += len;
}
@@ -248,8 +253,9 @@ int cov_notify_decode_service_request(
return -1;
/* a tag number of 2 is not extended so only one octet */
len++;
len += bacapp_decode_application_data(&apdu[len],
apdu_len - len, &value->value);
len +=
bacapp_decode_application_data(&apdu[len], apdu_len - len,
&value->value);
/* FIXME: check the return value; abort if no valid data? */
/* FIXME: there might be more than one data element in here! */
if (!decode_is_closing_tag_number(&apdu[len], 2))
@@ -313,12 +319,13 @@ int cov_subscribe_encode_adpu(
apdu[3] = SERVICE_CONFIRMED_SUBSCRIBE_COV;
apdu_len = 4;
/* tag 0 - subscriberProcessIdentifier */
len = encode_context_unsigned(&apdu[apdu_len],
0, data->subscriberProcessIdentifier);
len =
encode_context_unsigned(&apdu[apdu_len], 0,
data->subscriberProcessIdentifier);
apdu_len += len;
/* tag 1 - monitoredObjectIdentifier */
len = encode_context_object_id(&apdu[apdu_len],
1,
len =
encode_context_object_id(&apdu[apdu_len], 1,
data->monitoredObjectIdentifier.type,
data->monitoredObjectIdentifier.instance);
apdu_len += len;
@@ -329,8 +336,9 @@ int cov_subscribe_encode_adpu(
*/
if (!data->cancellationRequest) {
/* tag 2 - issueConfirmedNotifications */
len = encode_context_boolean(&apdu[apdu_len],
2, data->issueConfirmedNotifications);
len =
encode_context_boolean(&apdu[apdu_len], 2,
data->issueConfirmedNotifications);
apdu_len += len;
/* tag 3 - lifetime */
len = encode_context_unsigned(&apdu[apdu_len], 3, data->lifetime);
@@ -441,19 +449,21 @@ int cov_subscribe_property_encode_adpu(
apdu[3] = SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY;
apdu_len = 4;
/* tag 0 - subscriberProcessIdentifier */
len = encode_context_unsigned(&apdu[apdu_len],
0, data->subscriberProcessIdentifier);
len =
encode_context_unsigned(&apdu[apdu_len], 0,
data->subscriberProcessIdentifier);
apdu_len += len;
/* tag 1 - monitoredObjectIdentifier */
len = encode_context_object_id(&apdu[apdu_len],
1,
len =
encode_context_object_id(&apdu[apdu_len], 1,
data->monitoredObjectIdentifier.type,
data->monitoredObjectIdentifier.instance);
apdu_len += len;
if (!data->cancellationRequest) {
/* tag 2 - issueConfirmedNotifications */
len = encode_context_boolean(&apdu[apdu_len],
2, data->issueConfirmedNotifications);
len =
encode_context_boolean(&apdu[apdu_len], 2,
data->issueConfirmedNotifications);
apdu_len += len;
/* tag 3 - lifetime */
len = encode_context_unsigned(&apdu[apdu_len], 3, data->lifetime);
@@ -462,12 +472,14 @@ int cov_subscribe_property_encode_adpu(
/* tag 4 - monitoredPropertyIdentifier */
len = encode_opening_tag(&apdu[apdu_len], 4);
apdu_len += len;
len = encode_context_enumerated(&apdu[apdu_len],
0, data->monitoredProperty.propertyIdentifier);
len =
encode_context_enumerated(&apdu[apdu_len], 0,
data->monitoredProperty.propertyIdentifier);
apdu_len += len;
if (data->monitoredProperty.propertyArrayIndex != BACNET_ARRAY_ALL) {
len = encode_context_unsigned(&apdu[apdu_len],
1, data->monitoredProperty.propertyArrayIndex);
len =
encode_context_unsigned(&apdu[apdu_len], 1,
data->monitoredProperty.propertyArrayIndex);
apdu_len += len;
}
@@ -634,8 +646,8 @@ int ccov_notify_decode_apdu(
/* optional limits - must be used as a pair */
if (apdu_len > offset) {
len =
cov_notify_decode_service_request(&apdu[offset],
apdu_len - offset, data);
cov_notify_decode_service_request(&apdu[offset], apdu_len - offset,
data);
}
return len;
@@ -660,8 +672,8 @@ int ucov_notify_decode_apdu(
offset = 2;
if (apdu_len > offset) {
len =
cov_notify_decode_service_request(&apdu[offset],
apdu_len - offset, data);
cov_notify_decode_service_request(&apdu[offset], apdu_len - offset,
data);
}
return len;
@@ -830,8 +842,9 @@ void testCCOVNotifyData(
apdu_len = len;
test_data.listOfValues.next = NULL;
len = ccov_notify_decode_apdu(&apdu[0], apdu_len,
&test_invoke_id, &test_data);
len =
ccov_notify_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_data);
ct_test(pTest, len > 0);
ct_test(pTest, test_invoke_id == invoke_id);
testCOVNotifyData(pTest, data, &test_data);
@@ -852,8 +865,8 @@ void testCOVNotify(
data.listOfValues.propertyIdentifier = PROP_PRESENT_VALUE;
data.listOfValues.propertyArrayIndex = BACNET_ARRAY_ALL;
bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL,
"21.0", &data.listOfValues.value);
bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "21.0",
&data.listOfValues.value);
data.listOfValues.priority = 0;
data.listOfValues.next = NULL;
@@ -924,8 +937,9 @@ void testCOVSubscribeEncoding(
ct_test(pTest, len != 0);
apdu_len = len;
len = cov_subscribe_decode_apdu(&apdu[0], apdu_len,
&test_invoke_id, &test_data);
len =
cov_subscribe_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_data);
ct_test(pTest, len > 0);
ct_test(pTest, test_invoke_id == invoke_id);
testCOVSubscribeData(pTest, data, &test_data);
@@ -946,8 +960,9 @@ void testCOVSubscribePropertyEncoding(
ct_test(pTest, len != 0);
apdu_len = len;
len = cov_subscribe_property_decode_apdu(&apdu[0], apdu_len,
&test_invoke_id, &test_data);
len =
cov_subscribe_property_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_data);
ct_test(pTest, len > 0);
ct_test(pTest, test_invoke_id == invoke_id);
testCOVSubscribePropertyData(pTest, data, &test_data);
+2 -2
View File
@@ -43,8 +43,8 @@ int (
uint8_t * pdu,
unsigned pdu_len);
uint16_t(*datalink_receive) (BACNET_ADDRESS * src,
uint8_t * pdu, uint16_t max_pdu, unsigned timeout);
uint16_t(*datalink_receive) (BACNET_ADDRESS * src, uint8_t * pdu,
uint16_t max_pdu, unsigned timeout);
void (
*datalink_cleanup) (
+18 -18
View File
@@ -354,10 +354,12 @@ void datetime_add_minutes(
uint32_t days = 0;
/* convert bdatetime to seconds and days */
bdatetime_minutes = seconds_since_midnight(bdatetime->time.hour,
bdatetime->time.min, bdatetime->time.sec) / 60;
bdatetime_days = days_since_epoch(bdatetime->date.year,
bdatetime->date.month, bdatetime->date.day);
bdatetime_minutes =
seconds_since_midnight(bdatetime->time.hour, bdatetime->time.min,
bdatetime->time.sec) / 60;
bdatetime_days =
days_since_epoch(bdatetime->date.year, bdatetime->date.month,
bdatetime->date.day);
/* add */
days = minutes / (24 * 60);
@@ -370,10 +372,11 @@ void datetime_add_minutes(
/* convert bdatetime from seconds and days */
seconds_since_midnight_into_hms(bdatetime_minutes * 60,
&bdatetime->time.hour, &bdatetime->time.min, &bdatetime->time.sec);
days_since_epoch_into_ymd(bdatetime_days,
&bdatetime->date.year, &bdatetime->date.month, &bdatetime->date.day);
bdatetime->date.wday = day_of_week(bdatetime->date.year,
bdatetime->date.month, bdatetime->date.day);
days_since_epoch_into_ymd(bdatetime_days, &bdatetime->date.year,
&bdatetime->date.month, &bdatetime->date.day);
bdatetime->date.wday =
day_of_week(bdatetime->date.year, bdatetime->date.month,
bdatetime->date.day);
}
bool datetime_wildcard(
@@ -383,12 +386,9 @@ bool datetime_wildcard(
if (bdatetime) {
if ((bdatetime->date.year == (1900 + 0xFF)) &&
(bdatetime->date.month == 0xFF) &&
(bdatetime->date.day == 0xFF) &&
(bdatetime->date.wday == 0xFF) &&
(bdatetime->time.hour == 0xFF) &&
(bdatetime->time.min == 0xFF) &&
(bdatetime->time.sec == 0xFF) &&
(bdatetime->date.month == 0xFF) && (bdatetime->date.day == 0xFF) &&
(bdatetime->date.wday == 0xFF) && (bdatetime->time.hour == 0xFF) &&
(bdatetime->time.min == 0xFF) && (bdatetime->time.sec == 0xFF) &&
(bdatetime->time.hundredths == 0xFF)) {
wildcard_present = true;
}
@@ -494,8 +494,8 @@ void testBACnetDateTimeSeconds(
for (minute = 0; minute < 60; minute += 3) {
for (second = 0; second < 60; second += 17) {
seconds = seconds_since_midnight(hour, minute, second);
seconds_since_midnight_into_hms(seconds,
&test_hour, &test_minute, &test_second);
seconds_since_midnight_into_hms(seconds, &test_hour,
&test_minute, &test_second);
test_seconds =
seconds_since_midnight(test_hour, test_minute,
test_second);
@@ -705,8 +705,8 @@ void testDateEpoch(
for (month = 1; month <= 12; month++) {
for (day = 1; day <= month_days(year, month); day++) {
days = days_since_epoch(year, month, day);
days_since_epoch_into_ymd(days,
&test_year, &test_month, &test_day);
days_since_epoch_into_ymd(days, &test_year, &test_month,
&test_day);
ct_test(pTest, year == test_year);
ct_test(pTest, month == test_month);
ct_test(pTest, day == test_day);
+20 -16
View File
@@ -178,7 +178,8 @@ int dcc_decode_service_request(
if (apdu_len) {
/* Tag 0: timeDuration --optional-- */
if (decode_is_context_tag(&apdu[len], 0)) {
len += decode_tag_number_and_value(&apdu[len], &tag_number,
len +=
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += decode_unsigned(&apdu[len], len_value_type, &value32);
if (timeDuration)
@@ -188,8 +189,9 @@ int dcc_decode_service_request(
/* Tag 1: enable_disable */
if (!decode_is_context_tag(&apdu[len], 1))
return -1;
len += decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
len +=
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += decode_enumerated(&apdu[len], len_value_type, &value);
if (enable_disable)
*enable_disable = (BACNET_COMMUNICATION_ENABLE_DISABLE) value;
@@ -197,8 +199,9 @@ int dcc_decode_service_request(
if (len < apdu_len) {
if (!decode_is_context_tag(&apdu[len], 2))
return -1;
len += decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
len +=
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len +=
decode_character_string(&apdu[len], len_value_type, password);
} else if (password)
@@ -236,8 +239,9 @@ int dcc_decode_apdu(
offset = 4;
if (apdu_len > offset) {
len = dcc_decode_service_request(&apdu[offset],
apdu_len - offset, timeDuration, enable_disable, password);
len =
dcc_decode_service_request(&apdu[offset], apdu_len - offset,
timeDuration, enable_disable, password);
}
return len;
@@ -258,14 +262,14 @@ void test_DeviceCommunicationControlData(
BACNET_COMMUNICATION_ENABLE_DISABLE test_enable_disable;
BACNET_CHARACTER_STRING test_password;
len = dcc_encode_apdu(&apdu[0],
invoke_id, timeDuration, enable_disable, password);
len =
dcc_encode_apdu(&apdu[0], invoke_id, timeDuration, enable_disable,
password);
ct_test(pTest, len != 0);
apdu_len = len;
len = dcc_decode_apdu(&apdu[0],
apdu_len,
&test_invoke_id,
len =
dcc_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_timeDuration, &test_enable_disable, &test_password);
ct_test(pTest, len != -1);
ct_test(pTest, test_invoke_id == invoke_id);
@@ -285,13 +289,13 @@ void test_DeviceCommunicationControl(
timeDuration = 0;
enable_disable = COMMUNICATION_DISABLE_INITIATION;
characterstring_init_ansi(&password, "John 3:16");
test_DeviceCommunicationControlData(pTest,
invoke_id, timeDuration, enable_disable, &password);
test_DeviceCommunicationControlData(pTest, invoke_id, timeDuration,
enable_disable, &password);
timeDuration = 12345;
enable_disable = COMMUNICATION_DISABLE;
test_DeviceCommunicationControlData(pTest,
invoke_id, timeDuration, enable_disable, NULL);
test_DeviceCommunicationControlData(pTest, invoke_id, timeDuration,
enable_disable, NULL);
return;
}
+14 -10
View File
@@ -56,8 +56,9 @@ int iam_encode_apdu(
apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST;
apdu[1] = SERVICE_UNCONFIRMED_I_AM; /* service choice */
apdu_len = 2;
len = encode_application_object_id(&apdu[apdu_len],
OBJECT_DEVICE, device_id);
len =
encode_application_object_id(&apdu[apdu_len], OBJECT_DEVICE,
device_id);
apdu_len += len;
len = encode_application_unsigned(&apdu[apdu_len], max_apdu);
apdu_len += len;
@@ -150,8 +151,8 @@ int iam_encode_pdu(
npdu_encode_npdu_data(npdu_data, false, MESSAGE_PRIORITY_NORMAL);
pdu_len = npdu_encode_pdu(&buffer[0], dest, NULL, npdu_data);
/* encode the APDU portion of the packet */
len = iam_encode_apdu(&buffer[pdu_len],
Device_Object_Instance_Number(),
len =
iam_encode_apdu(&buffer[pdu_len], Device_Object_Instance_Number(),
MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier());
pdu_len += len;
@@ -199,8 +200,9 @@ int iam_decode_apdu(
return -1;
if (apdu[1] != SERVICE_UNCONFIRMED_I_AM)
return -1;
apdu_len = iam_decode_service_request(&apdu[2],
pDevice_id, pMax_apdu, pSegmentation, pVendor_id);
apdu_len =
iam_decode_service_request(&apdu[2], pDevice_id, pMax_apdu,
pSegmentation, pVendor_id);
return apdu_len;
}
@@ -219,12 +221,14 @@ void testIAm(
int test_segmentation = 0;
uint16_t test_vendor_id = 0;
len = iam_encode_apdu(&apdu[0],
device_id, max_apdu, segmentation, vendor_id);
len =
iam_encode_apdu(&apdu[0], device_id, max_apdu, segmentation,
vendor_id);
ct_test(pTest, len != 0);
len = iam_decode_apdu(&apdu[0],
&test_device_id, &test_max_apdu, &test_segmentation, &test_vendor_id);
len =
iam_decode_apdu(&apdu[0], &test_device_id, &test_max_apdu,
&test_segmentation, &test_vendor_id);
ct_test(pTest, len != -1);
ct_test(pTest, test_device_id == device_id);
+14 -8
View File
@@ -49,15 +49,18 @@ int ihave_encode_apdu(
apdu[1] = SERVICE_UNCONFIRMED_I_HAVE;
apdu_len = 2;
/* deviceIdentifier */
len = encode_application_object_id(&apdu[apdu_len],
data->device_id.type, data->device_id.instance);
len =
encode_application_object_id(&apdu[apdu_len], data->device_id.type,
data->device_id.instance);
apdu_len += len;
/* objectIdentifier */
len = encode_application_object_id(&apdu[apdu_len],
data->object_id.type, data->object_id.instance);
len =
encode_application_object_id(&apdu[apdu_len], data->object_id.type,
data->object_id.instance);
apdu_len += len;
/* objectName */
len = encode_application_character_string(&apdu[apdu_len],
len =
encode_application_character_string(&apdu[apdu_len],
&data->object_name);
apdu_len += len;
}
@@ -81,7 +84,8 @@ int ihave_decode_service_request(
len +=
decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
if (tag_number == BACNET_APPLICATION_TAG_OBJECT_ID) {
len += decode_object_id(&apdu[len], &decoded_type,
len +=
decode_object_id(&apdu[len], &decoded_type,
&data->device_id.instance);
data->device_id.type = decoded_type;
} else
@@ -90,7 +94,8 @@ int ihave_decode_service_request(
len +=
decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
if (tag_number == BACNET_APPLICATION_TAG_OBJECT_ID) {
len += decode_object_id(&apdu[len], &decoded_type,
len +=
decode_object_id(&apdu[len], &decoded_type,
&data->object_id.instance);
data->object_id.type = decoded_type;
} else
@@ -99,7 +104,8 @@ int ihave_decode_service_request(
len +=
decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
if (tag_number == BACNET_APPLICATION_TAG_CHARACTER_STRING) {
len += decode_character_string(&apdu[len], len_value,
len +=
decode_character_string(&apdu[len], len_value,
&data->object_name);
} else
return -1;
+6 -6
View File
@@ -224,8 +224,8 @@ void *Keylist_Data_Delete_By_Index(
struct Keylist_Node *node;
void *data = NULL;
if (list && list->array && list->count &&
(index >= 0) && (index < list->count)) {
if (list && list->array && list->count && (index >= 0) &&
(index < list->count)) {
node = list->array[index];
if (node)
data = node->data;
@@ -314,8 +314,8 @@ void *Keylist_Data_Index(
{
struct Keylist_Node *node = NULL;
if (list && list->array && list->count &&
(index >= 0) && (index < list->count))
if (list && list->array && list->count && (index >= 0) &&
(index < list->count))
node = list->array[index];
return node ? node->data : NULL;
@@ -329,8 +329,8 @@ KEY Keylist_Key(
KEY key = 0; /* return value */
struct Keylist_Node *node;
if (list && list->array && list->count &&
(index >= 0) && (index < list->count)) {
if (list && list->array && list->count && (index >= 0) &&
(index < list->count)) {
node = list->array[index];
if (node)
key = node->key;
+2 -2
View File
@@ -53,6 +53,6 @@ static INDTEXT_DATA mstp_frame_type_text[] = {
const char *mstptext_frame_type(
int index)
{
return indtext_by_index_split_default(mstp_frame_type_text,
index, FRAME_TYPE_PROPRIETARY_MIN, "UNKNOWN", "PROPRIETARY");
return indtext_by_index_split_default(mstp_frame_type_text, index,
FRAME_TYPE_PROPRIETARY_MIN, "UNKNOWN", "PROPRIETARY");
}
+14 -10
View File
@@ -58,8 +58,8 @@ int rd_encode_apdu(
/* optional password */
if (password) {
/* FIXME: must be at least 1 character, limited to 20 characters */
len = encode_context_character_string(&apdu[apdu_len], 1,
password);
len =
encode_context_character_string(&apdu[apdu_len], 1, password);
apdu_len += len;
}
}
@@ -84,8 +84,9 @@ int rd_decode_service_request(
/* Tag 0: reinitializedStateOfDevice */
if (!decode_is_context_tag(&apdu[len], 0))
return -1;
len += decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
len +=
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len += decode_enumerated(&apdu[len], len_value_type, &value);
if (state)
*state = (BACNET_REINITIALIZED_STATE) value;
@@ -93,8 +94,9 @@ int rd_decode_service_request(
if (len < apdu_len) {
if (!decode_is_context_tag(&apdu[len], 1))
return -1;
len += decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
len +=
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
len +=
decode_character_string(&apdu[len], len_value_type, password);
}
@@ -130,8 +132,9 @@ int rd_decode_apdu(
offset = 4;
if (apdu_len > offset) {
len = rd_decode_service_request(&apdu[offset],
apdu_len - offset, state, password);
len =
rd_decode_service_request(&apdu[offset], apdu_len - offset, state,
password);
}
return len;
@@ -156,8 +159,9 @@ void test_ReinitializeDevice(
ct_test(pTest, len != 0);
apdu_len = len;
len = rd_decode_apdu(&apdu[0],
apdu_len, &test_invoke_id, &test_state, &test_password);
len =
rd_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_state,
&test_password);
ct_test(pTest, len != -1);
ct_test(pTest, test_invoke_id == invoke_id);
ct_test(pTest, test_state == state);
+17 -12
View File
@@ -94,8 +94,9 @@ int reject_decode_apdu(
if (apdu[0] != PDU_TYPE_REJECT)
return -1;
if (apdu_len > 1) {
len = reject_decode_service_request(&apdu[1],
apdu_len - 1, invoke_id, reject_reason);
len =
reject_decode_service_request(&apdu[1], apdu_len - 1,
invoke_id, reject_reason);
}
}
@@ -117,26 +118,29 @@ void testReject(
ct_test(pTest, len != 0);
apdu_len = len;
len = reject_decode_apdu(&apdu[0],
apdu_len, &test_invoke_id, &test_reject_reason);
len =
reject_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_reject_reason);
ct_test(pTest, len != -1);
ct_test(pTest, test_invoke_id == invoke_id);
ct_test(pTest, test_reject_reason == reject_reason);
/* change type to get negative response */
apdu[0] = PDU_TYPE_ABORT;
len = reject_decode_apdu(&apdu[0],
apdu_len, &test_invoke_id, &test_reject_reason);
len =
reject_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_reject_reason);
ct_test(pTest, len == -1);
/* test NULL APDU */
len = reject_decode_apdu(NULL,
apdu_len, &test_invoke_id, &test_reject_reason);
len =
reject_decode_apdu(NULL, apdu_len, &test_invoke_id,
&test_reject_reason);
ct_test(pTest, len == -1);
/* force a zero length */
len = reject_decode_apdu(&apdu[0],
0, &test_invoke_id, &test_reject_reason);
len =
reject_decode_apdu(&apdu[0], 0, &test_invoke_id, &test_reject_reason);
ct_test(pTest, len == 0);
@@ -146,8 +150,9 @@ void testReject(
len = reject_encode_apdu(&apdu[0], invoke_id, reject_reason);
apdu_len = len;
ct_test(pTest, len != 0);
len = reject_decode_apdu(&apdu[0],
apdu_len, &test_invoke_id, &test_reject_reason);
len =
reject_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
&test_reject_reason);
ct_test(pTest, len != -1);
ct_test(pTest, test_invoke_id == invoke_id);
ct_test(pTest, test_reject_reason == reject_reason);
+37 -25
View File
@@ -52,15 +52,18 @@ int rp_encode_apdu(
apdu[2] = invoke_id;
apdu[3] = SERVICE_CONFIRMED_READ_PROPERTY; /* service choice */
apdu_len = 4;
len = encode_context_object_id(&apdu[apdu_len], 0,
rpdata->object_type, rpdata->object_instance);
len =
encode_context_object_id(&apdu[apdu_len], 0, rpdata->object_type,
rpdata->object_instance);
apdu_len += len;
len = encode_context_enumerated(&apdu[apdu_len], 1,
len =
encode_context_enumerated(&apdu[apdu_len], 1,
rpdata->object_property);
apdu_len += len;
/* optional array index */
if (rpdata->array_index != BACNET_ARRAY_ALL) {
len = encode_context_unsigned(&apdu[apdu_len], 2,
len =
encode_context_unsigned(&apdu[apdu_len], 2,
rpdata->array_index);
apdu_len += len;
}
@@ -90,19 +93,21 @@ int rp_decode_service_request(
len += decode_object_id(&apdu[len], &type, &rpdata->object_instance);
rpdata->object_type = (BACNET_OBJECT_TYPE) type;
/* Tag 1: Property ID */
len += decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
len +=
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
if (tag_number != 1)
return -1;
len += decode_enumerated(&apdu[len], len_value_type, &property);
rpdata->object_property = (BACNET_PROPERTY_ID) property;
/* Tag 2: Optional Array Index */
if (len < apdu_len) {
len += decode_tag_number_and_value(&apdu[len], &tag_number,
len +=
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
if (tag_number == 2) {
len += decode_unsigned(&apdu[len], len_value_type,
&array_value);
len +=
decode_unsigned(&apdu[len], len_value_type, &array_value);
rpdata->array_index = array_value;
} else
rpdata->array_index = BACNET_ARRAY_ALL;
@@ -127,13 +132,16 @@ int rp_ack_encode_apdu(
apdu[2] = SERVICE_CONFIRMED_READ_PROPERTY; /* service choice */
apdu_len = 3;
/* service ack follows */
apdu_len += encode_context_object_id(&apdu[apdu_len], 0,
rpdata->object_type, rpdata->object_instance);
apdu_len += encode_context_enumerated(&apdu[apdu_len], 1,
apdu_len +=
encode_context_object_id(&apdu[apdu_len], 0, rpdata->object_type,
rpdata->object_instance);
apdu_len +=
encode_context_enumerated(&apdu[apdu_len], 1,
rpdata->object_property);
/* context 2 array index is optional */
if (rpdata->array_index != BACNET_ARRAY_ALL) {
apdu_len += encode_context_unsigned(&apdu[apdu_len], 2,
apdu_len +=
encode_context_unsigned(&apdu[apdu_len], 2,
rpdata->array_index);
}
/* propertyValue */
@@ -167,15 +175,15 @@ int rp_ack_decode_service_request(
len += decode_object_id(&apdu[len], &object, &rpdata->object_instance);
rpdata->object_type = (BACNET_OBJECT_TYPE) object;
/* Tag 1: Property ID */
len += decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
len +=
decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
if (tag_number != 1)
return -1;
len += decode_enumerated(&apdu[len], len_value_type, &property);
rpdata->object_property = (BACNET_PROPERTY_ID) property;
/* Tag 2: Optional Array Index */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
if (tag_number == 2) {
len += tag_len;
len += decode_unsigned(&apdu[len], len_value_type, &array_value);
@@ -221,8 +229,9 @@ int rp_decode_apdu(
offset = 4;
if (apdu_len > offset) {
len = rp_decode_service_request(&apdu[offset],
apdu_len - offset, rpdata);
len =
rp_decode_service_request(&apdu[offset], apdu_len - offset,
rpdata);
}
return len;
@@ -247,8 +256,9 @@ int rp_ack_decode_apdu(
return -1;
offset = 3;
if (apdu_len > offset) {
len = rp_ack_decode_service_request(&apdu[offset],
apdu_len - offset, rpdata);
len =
rp_ack_decode_service_request(&apdu[offset], apdu_len - offset,
rpdata);
}
return len;
@@ -274,8 +284,9 @@ void testReadPropertyAck(
rpdata.object_property = PROP_OBJECT_IDENTIFIER;
rpdata.array_index = BACNET_ARRAY_ALL;
rpdata.application_data_len = encode_bacnet_object_id(&apdu2[0],
rpdata.object_type, rpdata.object_instance);
rpdata.application_data_len =
encode_bacnet_object_id(&apdu2[0], rpdata.object_type,
rpdata.object_instance);
rpdata.application_data = &apdu2[0];
len = rp_ack_encode_apdu(&apdu[0], invoke_id, &rpdata);
@@ -296,8 +307,9 @@ void testReadPropertyAck(
/* since object property == object_id, decode the application data using
the appropriate decode function */
len = decode_object_id(test_data.application_data,
&object, &object_instance);
len =
decode_object_id(test_data.application_data, &object,
&object_instance);
object_type = object;
ct_test(pTest, object_type == rpdata.object_type);
ct_test(pTest, object_instance == rpdata.object_instance);
+108 -70
View File
@@ -65,8 +65,9 @@ int rpm_encode_apdu_object_begin(
int apdu_len = 0; /* total length of the apdu, return value */
if (apdu) {
apdu_len = encode_context_object_id(&apdu[0], 0,
object_type, object_instance);
apdu_len =
encode_context_object_id(&apdu[0], 0, object_type,
object_instance);
/* Tag 1: sequence of ReadAccessSpecification */
apdu_len += encode_opening_tag(&apdu[apdu_len], 1);
}
@@ -85,8 +86,8 @@ int rpm_encode_apdu_object_property(
apdu_len = encode_context_enumerated(&apdu[0], 0, object_property);
/* optional array index */
if (array_index != BACNET_ARRAY_ALL)
apdu_len += encode_context_unsigned(&apdu[apdu_len], 1,
array_index);
apdu_len +=
encode_context_unsigned(&apdu[apdu_len], 1, array_index);
}
return apdu_len;
@@ -171,24 +172,24 @@ int rpm_decode_object_property(
/* Tag 0: propertyIdentifier */
if (!decode_is_context_specific(&apdu[len]))
return -1;
len += decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
len +=
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
if (tag_number != 0)
return -1;
len += decode_enumerated(&apdu[len], len_value_type, &property);
if (object_property)
*object_property = (BACNET_PROPERTY_ID) property;
/* Tag 1: Optional propertyArrayIndex */
if ((len < apdu_len) &&
decode_is_context_specific(&apdu[len]) &&
if ((len < apdu_len) && decode_is_context_specific(&apdu[len]) &&
(!decode_is_closing_tag(&apdu[len]))) {
option_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
if (tag_number == 1) {
len += option_len;
len += decode_unsigned(&apdu[len], len_value_type,
&array_value);
len +=
decode_unsigned(&apdu[len], len_value_type, &array_value);
*array_index = array_value;
} else
*array_index = BACNET_ARRAY_ALL;
@@ -224,8 +225,9 @@ int rpm_ack_encode_apdu_object_begin(
if (apdu) {
/* Tag 0: objectIdentifier */
apdu_len = encode_context_object_id(&apdu[0], 0,
object_type, object_instance);
apdu_len =
encode_context_object_id(&apdu[0], 0, object_type,
object_instance);
/* Tag 1: listOfResults */
apdu_len += encode_opening_tag(&apdu[apdu_len], 1);
}
@@ -245,8 +247,8 @@ int rpm_ack_encode_apdu_object_property(
apdu_len = encode_context_enumerated(&apdu[0], 2, object_property);
/* Tag 3: optional propertyArrayIndex */
if (array_index != BACNET_ARRAY_ALL)
apdu_len += encode_context_unsigned(&apdu[apdu_len], 3,
array_index);
apdu_len +=
encode_context_unsigned(&apdu[apdu_len], 3, array_index);
}
return apdu_len;
@@ -363,23 +365,24 @@ int rpm_ack_decode_object_property(
/* Tag 2: propertyIdentifier */
if (!decode_is_context_specific(&apdu[len]))
return -1;
len += decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
len +=
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
if (tag_number != 2)
return -1;
len += decode_enumerated(&apdu[len], len_value_type, &property);
if (object_property)
*object_property = (BACNET_PROPERTY_ID) property;
/* Tag 3: Optional propertyArrayIndex */
if ((len < apdu_len) &&
decode_is_context_specific(&apdu[len]) &&
if ((len < apdu_len) && decode_is_context_specific(&apdu[len]) &&
(!decode_is_closing_tag(&apdu[len]))) {
tag_len = decode_tag_number_and_value(&apdu[len], &tag_number,
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
if (tag_number == 3) {
len += tag_len;
len += decode_unsigned(&apdu[len], len_value_type,
&array_value);
len +=
decode_unsigned(&apdu[len], len_value_type, &array_value);
*array_index = array_value;
} else {
*array_index = BACNET_ARRAY_ALL;
@@ -479,21 +482,25 @@ void testReadPropertyMultiple(
Also check case of storing a backoff point (i.e. save enough room for object_end) */
apdu_len = rpm_encode_apdu_init(&apdu[0], invoke_id);
/* each object has a beginning and an end */
apdu_len += rpm_encode_apdu_object_begin(&apdu[apdu_len],
OBJECT_DEVICE, 123);
apdu_len +=
rpm_encode_apdu_object_begin(&apdu[apdu_len], OBJECT_DEVICE, 123);
/* then stuff as many properties into it as APDU length will allow */
apdu_len += rpm_encode_apdu_object_property(&apdu[apdu_len],
apdu_len +=
rpm_encode_apdu_object_property(&apdu[apdu_len],
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL);
apdu_len += rpm_encode_apdu_object_property(&apdu[apdu_len],
PROP_OBJECT_NAME, BACNET_ARRAY_ALL);
apdu_len +=
rpm_encode_apdu_object_property(&apdu[apdu_len], PROP_OBJECT_NAME,
BACNET_ARRAY_ALL);
apdu_len += rpm_encode_apdu_object_end(&apdu[apdu_len]);
/* each object has a beginning and an end */
apdu_len += rpm_encode_apdu_object_begin(&apdu[apdu_len],
OBJECT_ANALOG_INPUT, 33);
apdu_len += rpm_encode_apdu_object_property(&apdu[apdu_len],
apdu_len +=
rpm_encode_apdu_object_begin(&apdu[apdu_len], OBJECT_ANALOG_INPUT, 33);
apdu_len +=
rpm_encode_apdu_object_property(&apdu[apdu_len],
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL);
apdu_len += rpm_encode_apdu_object_property(&apdu[apdu_len],
PROP_ALL, BACNET_ARRAY_ALL);
apdu_len +=
rpm_encode_apdu_object_property(&apdu[apdu_len], PROP_ALL,
BACNET_ARRAY_ALL);
apdu_len += rpm_encode_apdu_object_end(&apdu[apdu_len]);
ct_test(pTest, apdu_len != 0);
@@ -505,59 +512,69 @@ void testReadPropertyMultiple(
ct_test(pTest, service_request != NULL);
ct_test(pTest, service_request_len > 0);
test_len = rpm_decode_object_id(service_request,
service_request_len, &object_type, &object_instance);
test_len =
rpm_decode_object_id(service_request, service_request_len,
&object_type, &object_instance);
ct_test(pTest, test_len != -1);
ct_test(pTest, object_type == OBJECT_DEVICE);
ct_test(pTest, object_instance == 123);
len = test_len;
/* decode the object property portion of the service request */
test_len = rpm_decode_object_property(&service_request[len],
test_len =
rpm_decode_object_property(&service_request[len],
service_request_len - len, &object_property, &array_index);
ct_test(pTest, test_len != -1);
ct_test(pTest, object_property == PROP_OBJECT_IDENTIFIER);
ct_test(pTest, array_index == BACNET_ARRAY_ALL);
len += test_len;
test_len = rpm_decode_object_property(&service_request[len],
test_len =
rpm_decode_object_property(&service_request[len],
service_request_len - len, &object_property, &array_index);
ct_test(pTest, test_len != -1);
ct_test(pTest, object_property == PROP_OBJECT_NAME);
ct_test(pTest, array_index == BACNET_ARRAY_ALL);
len += test_len;
/* try again - we should fail */
test_len = rpm_decode_object_property(&service_request[len],
test_len =
rpm_decode_object_property(&service_request[len],
service_request_len - len, &object_property, &array_index);
ct_test(pTest, test_len == -1);
/* is it the end of this object? */
test_len = rpm_decode_object_end(&service_request[len],
test_len =
rpm_decode_object_end(&service_request[len],
service_request_len - len);
ct_test(pTest, test_len == 1);
len += test_len;
/* try to decode an object id */
test_len = rpm_decode_object_id(&service_request[len],
service_request_len - len, &object_type, &object_instance);
test_len =
rpm_decode_object_id(&service_request[len], service_request_len - len,
&object_type, &object_instance);
ct_test(pTest, test_len != -1);
ct_test(pTest, object_type == OBJECT_ANALOG_INPUT);
ct_test(pTest, object_instance == 33);
len += test_len;
/* decode the object property portion of the service request only */
test_len = rpm_decode_object_property(&service_request[len],
test_len =
rpm_decode_object_property(&service_request[len],
service_request_len - len, &object_property, &array_index);
ct_test(pTest, test_len != -1);
ct_test(pTest, object_property == PROP_OBJECT_IDENTIFIER);
ct_test(pTest, array_index == BACNET_ARRAY_ALL);
len += test_len;
test_len = rpm_decode_object_property(&service_request[len],
test_len =
rpm_decode_object_property(&service_request[len],
service_request_len - len, &object_property, &array_index);
ct_test(pTest, test_len != -1);
ct_test(pTest, object_property == PROP_ALL);
ct_test(pTest, array_index == BACNET_ARRAY_ALL);
len += test_len;
test_len = rpm_decode_object_property(&service_request[len],
test_len =
rpm_decode_object_property(&service_request[len],
service_request_len - len, &object_property, &array_index);
ct_test(pTest, test_len == -1);
/* got an error -1, is it the end of this object? */
test_len = rpm_decode_object_end(&service_request[len],
test_len =
rpm_decode_object_end(&service_request[len],
service_request_len - len);
ct_test(pTest, test_len == 1);
len += test_len;
@@ -598,10 +615,11 @@ void testReadPropertyMultipleAck(
apdu_len = rpm_ack_encode_apdu_init(&apdu[0], invoke_id);
/* object beginning */
apdu_len += rpm_ack_encode_apdu_object_begin(&apdu[apdu_len],
OBJECT_DEVICE, 123);
apdu_len +=
rpm_ack_encode_apdu_object_begin(&apdu[apdu_len], OBJECT_DEVICE, 123);
/* reply property */
apdu_len += rpm_ack_encode_apdu_object_property(&apdu[apdu_len],
apdu_len +=
rpm_ack_encode_apdu_object_property(&apdu[apdu_len],
PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL);
/* reply value */
application_data[0].tag = BACNET_APPLICATION_TAG_OBJECT_ID;
@@ -614,8 +632,9 @@ void testReadPropertyMultipleAck(
rpm_ack_encode_apdu_object_property_value(&apdu[apdu_len],
&application_data_buffer[0], application_data_buffer_len);
/* reply property */
apdu_len += rpm_ack_encode_apdu_object_property(&apdu[apdu_len],
PROP_OBJECT_TYPE, BACNET_ARRAY_ALL);
apdu_len +=
rpm_ack_encode_apdu_object_property(&apdu[apdu_len], PROP_OBJECT_TYPE,
BACNET_ARRAY_ALL);
/* reply value */
application_data[1].tag = BACNET_APPLICATION_TAG_ENUMERATED;
application_data[1].type.Enumerated = OBJECT_DEVICE;
@@ -629,10 +648,12 @@ void testReadPropertyMultipleAck(
apdu_len += rpm_ack_encode_apdu_object_end(&apdu[apdu_len]);
/* object beginning */
apdu_len += rpm_ack_encode_apdu_object_begin(&apdu[apdu_len],
OBJECT_ANALOG_INPUT, 33);
apdu_len +=
rpm_ack_encode_apdu_object_begin(&apdu[apdu_len], OBJECT_ANALOG_INPUT,
33);
/* reply property */
apdu_len += rpm_ack_encode_apdu_object_property(&apdu[apdu_len],
apdu_len +=
rpm_ack_encode_apdu_object_property(&apdu[apdu_len],
PROP_PRESENT_VALUE, BACNET_ARRAY_ALL);
/* reply value */
application_data[2].tag = BACNET_APPLICATION_TAG_REAL;
@@ -644,10 +665,12 @@ void testReadPropertyMultipleAck(
rpm_ack_encode_apdu_object_property_value(&apdu[apdu_len],
&application_data_buffer[0], application_data_buffer_len);
/* reply property */
apdu_len += rpm_ack_encode_apdu_object_property(&apdu[apdu_len],
PROP_DEADBAND, BACNET_ARRAY_ALL);
apdu_len +=
rpm_ack_encode_apdu_object_property(&apdu[apdu_len], PROP_DEADBAND,
BACNET_ARRAY_ALL);
/* reply error */
apdu_len += rpm_ack_encode_apdu_object_property_error(&apdu[apdu_len],
apdu_len +=
rpm_ack_encode_apdu_object_property_error(&apdu[apdu_len],
ERROR_CLASS_PROPERTY, ERROR_CODE_UNKNOWN_PROPERTY);
/* object end */
apdu_len += rpm_ack_encode_apdu_object_end(&apdu[apdu_len]);
@@ -661,14 +684,16 @@ void testReadPropertyMultipleAck(
ct_test(pTest, service_request != NULL);
ct_test(pTest, service_request_len > 0);
/* the first part should be the first object id */
test_len = rpm_ack_decode_object_id(service_request,
service_request_len, &object_type, &object_instance);
test_len =
rpm_ack_decode_object_id(service_request, service_request_len,
&object_type, &object_instance);
ct_test(pTest, test_len != -1);
ct_test(pTest, object_type == OBJECT_DEVICE);
ct_test(pTest, object_instance == 123);
len = test_len;
/* extract the property */
test_len = rpm_ack_decode_object_property(&service_request[len],
test_len =
rpm_ack_decode_object_property(&service_request[len],
service_request_len - len, &object_property, &array_index);
ct_test(pTest, object_property == PROP_OBJECT_IDENTIFIER);
ct_test(pTest, array_index == BACNET_ARRAY_ALL);
@@ -679,7 +704,8 @@ void testReadPropertyMultipleAck(
/* decode the object property portion of the service request */
/* note: if this was an array, there could have been
more than one element to decode */
test_len = bacapp_decode_application_data(&service_request[len],
test_len =
bacapp_decode_application_data(&service_request[len],
service_request_len - len, &test_application_data);
ct_test(pTest, test_len > 0);
ct_test(pTest, bacapp_same_value(&application_data[0],
@@ -688,7 +714,8 @@ void testReadPropertyMultipleAck(
ct_test(pTest, decode_is_closing_tag_number(&service_request[len], 4));
len++;
/* see if there is another property */
test_len = rpm_ack_decode_object_property(&service_request[len],
test_len =
rpm_ack_decode_object_property(&service_request[len],
service_request_len - len, &object_property, &array_index);
ct_test(pTest, test_len != -1);
ct_test(pTest, object_property == PROP_OBJECT_TYPE);
@@ -698,7 +725,8 @@ void testReadPropertyMultipleAck(
ct_test(pTest, decode_is_opening_tag_number(&service_request[len], 4));
len++;
/* decode the object property portion of the service request */
test_len = bacapp_decode_application_data(&service_request[len],
test_len =
bacapp_decode_application_data(&service_request[len],
service_request_len - len, &test_application_data);
ct_test(pTest, test_len > 0);
ct_test(pTest, bacapp_same_value(&application_data[1],
@@ -708,23 +736,27 @@ void testReadPropertyMultipleAck(
len++;
/* see if there is another property */
/* this time we should fail */
test_len = rpm_ack_decode_object_property(&service_request[len],
test_len =
rpm_ack_decode_object_property(&service_request[len],
service_request_len - len, &object_property, &array_index);
ct_test(pTest, test_len == -1);
/* see if it is the end of this object */
test_len = rpm_ack_decode_object_end(&service_request[len],
test_len =
rpm_ack_decode_object_end(&service_request[len],
service_request_len - len);
ct_test(pTest, test_len == 1);
len += test_len;
/* try to decode another object id */
test_len = rpm_ack_decode_object_id(&service_request[len],
test_len =
rpm_ack_decode_object_id(&service_request[len],
service_request_len - len, &object_type, &object_instance);
ct_test(pTest, test_len != -1);
ct_test(pTest, object_type == OBJECT_ANALOG_INPUT);
ct_test(pTest, object_instance == 33);
len += test_len;
/* decode the object property portion of the service request only */
test_len = rpm_ack_decode_object_property(&service_request[len],
test_len =
rpm_ack_decode_object_property(&service_request[len],
service_request_len - len, &object_property, &array_index);
ct_test(pTest, test_len != -1);
ct_test(pTest, object_property == PROP_PRESENT_VALUE);
@@ -734,7 +766,8 @@ void testReadPropertyMultipleAck(
ct_test(pTest, decode_is_opening_tag_number(&service_request[len], 4));
len++;
/* decode the object property portion of the service request */
test_len = bacapp_decode_application_data(&service_request[len],
test_len =
bacapp_decode_application_data(&service_request[len],
service_request_len - len, &test_application_data);
ct_test(pTest, test_len > 0);
ct_test(pTest, bacapp_same_value(&application_data[2],
@@ -743,7 +776,8 @@ void testReadPropertyMultipleAck(
ct_test(pTest, decode_is_closing_tag_number(&service_request[len], 4));
len++;
/* see if there is another property */
test_len = rpm_ack_decode_object_property(&service_request[len],
test_len =
rpm_ack_decode_object_property(&service_request[len],
service_request_len - len, &object_property, &array_index);
ct_test(pTest, test_len != -1);
ct_test(pTest, object_property == PROP_DEADBAND);
@@ -753,7 +787,8 @@ void testReadPropertyMultipleAck(
ct_test(pTest, decode_is_opening_tag_number(&service_request[len], 5));
len++;
/* it was an error reply */
test_len = bacerror_decode_error_class_and_code(&service_request[len],
test_len =
bacerror_decode_error_class_and_code(&service_request[len],
service_request_len - len, &error_class, &error_code);
ct_test(pTest, test_len != 0);
ct_test(pTest, error_class == ERROR_CLASS_PROPERTY);
@@ -762,16 +797,19 @@ void testReadPropertyMultipleAck(
ct_test(pTest, decode_is_closing_tag_number(&service_request[len], 5));
len++;
/* is there another property? */
test_len = rpm_ack_decode_object_property(&service_request[len],
test_len =
rpm_ack_decode_object_property(&service_request[len],
service_request_len - len, &object_property, &array_index);
ct_test(pTest, test_len == -1);
/* got an error -1, is it the end of this object? */
test_len = rpm_ack_decode_object_end(&service_request[len],
test_len =
rpm_ack_decode_object_end(&service_request[len],
service_request_len - len);
ct_test(pTest, test_len == 1);
len += test_len;
/* check for another object */
test_len = rpm_ack_decode_object_id(&service_request[len],
test_len =
rpm_ack_decode_object_id(&service_request[len],
service_request_len - len, &object_type, &object_instance);
ct_test(pTest, test_len == 0);
ct_test(pTest, len == service_request_len);
+5 -4
View File
@@ -133,8 +133,9 @@ int timesync_decode_apdu_service(
return -1;
/* optional limits - must be used as a pair */
if (apdu_len > 2) {
len = timesync_decode_service_request(&apdu[2], apdu_len - 2,
my_date, my_time);
len =
timesync_decode_service_request(&apdu[2], apdu_len - 2, my_date,
my_time);
}
return len;
@@ -147,8 +148,8 @@ int timesync_utc_decode_apdu(
BACNET_TIME * my_time)
{
return timesync_decode_apdu_service(apdu,
SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION,
apdu_len, my_date, my_time);
SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION, apdu_len, my_date,
my_time);
}
int timesync_decode_apdu(
+4 -3
View File
@@ -256,9 +256,10 @@ void tsm_timer_milliseconds(
TSM_List[i].RetryCount--;
TSM_List[i].RequestTimer = Device_APDU_Timeout();
if (TSM_List[i].RetryCount) {
bytes_sent = datalink_send_pdu(&TSM_List[i].dest,
&TSM_List[i].npdu_data,
&TSM_List[i].apdu[0], TSM_List[i].apdu_len);
bytes_sent =
datalink_send_pdu(&TSM_List[i].dest,
&TSM_List[i].npdu_data, &TSM_List[i].apdu[0],
TSM_List[i].apdu_len);
} else {
/* note: the invoke id has not been cleared yet
and this indicates a failed message:
+13 -13
View File
@@ -57,17 +57,18 @@ int whohas_encode_apdu(
&& (data->high_limit <= BACNET_MAX_INSTANCE)) {
len = encode_context_unsigned(&apdu[apdu_len], 0, data->low_limit);
apdu_len += len;
len = encode_context_unsigned(&apdu[apdu_len],
1, data->high_limit);
len =
encode_context_unsigned(&apdu[apdu_len], 1, data->high_limit);
apdu_len += len;
}
if (data->object_name) {
len = encode_context_character_string(&apdu[apdu_len],
3, &data->object.name);
len =
encode_context_character_string(&apdu[apdu_len], 3,
&data->object.name);
apdu_len += len;
} else {
len = encode_context_object_id(&apdu[apdu_len],
2,
len =
encode_context_object_id(&apdu[apdu_len], 2,
data->object.identifier.type,
data->object.identifier.instance);
apdu_len += len;
@@ -186,9 +187,10 @@ void testWhoHasData(
ct_test(pTest, test_data.object_name == data->object_name);
/* Object ID */
if (data->object_name == false) {
ct_test(pTest, test_data.object.identifier.type ==
data->object.identifier.type);
ct_test(pTest, test_data.object.identifier.instance ==
ct_test(pTest,
test_data.object.identifier.type == data->object.identifier.type);
ct_test(pTest,
test_data.object.identifier.instance ==
data->object.identifier.instance);
}
/* Object Name */
@@ -210,11 +212,9 @@ void testWhoHas(
data.object.identifier.instance = 1;
testWhoHasData(pTest, &data);
for (data.low_limit = 0;
data.low_limit <= BACNET_MAX_INSTANCE;
for (data.low_limit = 0; data.low_limit <= BACNET_MAX_INSTANCE;
data.low_limit += (BACNET_MAX_INSTANCE / 4)) {
for (data.high_limit = 0;
data.high_limit <= BACNET_MAX_INSTANCE;
for (data.high_limit = 0; data.high_limit <= BACNET_MAX_INSTANCE;
data.high_limit += (BACNET_MAX_INSTANCE / 4)) {
data.object_name = false;
for (data.object.identifier.type = OBJECT_ANALOG_INPUT;
+11 -10
View File
@@ -121,8 +121,9 @@ int whois_decode_apdu(
return -1;
/* optional limits - must be used as a pair */
if (apdu_len > 2) {
len = whois_decode_service_request(&apdu[2],
apdu_len - 2, pLow_limit, pHigh_limit);
len =
whois_decode_service_request(&apdu[2], apdu_len - 2, pLow_limit,
pHigh_limit);
}
return len;
@@ -143,23 +144,23 @@ void testWhoIs(
ct_test(pTest, len != 0);
apdu_len = len;
len = whois_decode_apdu(&apdu[0],
apdu_len, &test_low_limit, &test_high_limit);
len =
whois_decode_apdu(&apdu[0], apdu_len, &test_low_limit,
&test_high_limit);
ct_test(pTest, len != -1);
ct_test(pTest, test_low_limit == low_limit);
ct_test(pTest, test_high_limit == high_limit);
for (low_limit = 0;
low_limit <= BACNET_MAX_INSTANCE;
for (low_limit = 0; low_limit <= BACNET_MAX_INSTANCE;
low_limit += (BACNET_MAX_INSTANCE / 4)) {
for (high_limit = 0;
high_limit <= BACNET_MAX_INSTANCE;
for (high_limit = 0; high_limit <= BACNET_MAX_INSTANCE;
high_limit += (BACNET_MAX_INSTANCE / 4)) {
len = whois_encode_apdu(&apdu[0], low_limit, high_limit);
apdu_len = len;
ct_test(pTest, len != 0);
len = whois_decode_apdu(&apdu[0],
apdu_len, &test_low_limit, &test_high_limit);
len =
whois_decode_apdu(&apdu[0], apdu_len, &test_low_limit,
&test_high_limit);
ct_test(pTest, len != -1);
ct_test(pTest, test_low_limit == low_limit);
ct_test(pTest, test_high_limit == high_limit);
+42 -31
View File
@@ -54,15 +54,18 @@ int wp_encode_apdu(
apdu[2] = invoke_id;
apdu[3] = SERVICE_CONFIRMED_WRITE_PROPERTY; /* service choice */
apdu_len = 4;
len = encode_context_object_id(&apdu[apdu_len], 0,
wpdata->object_type, wpdata->object_instance);
len =
encode_context_object_id(&apdu[apdu_len], 0, wpdata->object_type,
wpdata->object_instance);
apdu_len += len;
len = encode_context_enumerated(&apdu[apdu_len], 1,
len =
encode_context_enumerated(&apdu[apdu_len], 1,
wpdata->object_property);
apdu_len += len;
/* optional array index; ALL is -1 which is assumed when missing */
if (wpdata->array_index != BACNET_ARRAY_ALL) {
len = encode_context_unsigned(&apdu[apdu_len], 2,
len =
encode_context_unsigned(&apdu[apdu_len], 2,
wpdata->array_index);
apdu_len += len;
}
@@ -77,8 +80,8 @@ int wp_encode_apdu(
apdu_len += len;
/* optional priority - 0 if not set, 1..16 if set */
if (wpdata->priority != BACNET_NO_PRIORITY) {
len = encode_context_unsigned(&apdu[apdu_len], 4,
wpdata->priority);
len =
encode_context_unsigned(&apdu[apdu_len], 4, wpdata->priority);
apdu_len += len;
}
}
@@ -111,20 +114,22 @@ int wp_decode_service_request(
len += decode_object_id(&apdu[len], &type, &wpdata->object_instance);
wpdata->object_type = (BACNET_OBJECT_TYPE) type;
/* Tag 1: Property ID */
len += decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
len +=
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
if (tag_number != 1)
return -1;
len += decode_enumerated(&apdu[len], len_value_type, &property);
wpdata->object_property = (BACNET_PROPERTY_ID) property;
/* Tag 2: Optional Array Index */
/* note: decode without incrementing len so we can check for opening tag */
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
if (tag_number == 2) {
len += tag_len;
len += decode_unsigned(&apdu[len], len_value_type,
&unsigned_value);
len +=
decode_unsigned(&apdu[len], len_value_type, &unsigned_value);
wpdata->array_index = unsigned_value;
} else
wpdata->array_index = BACNET_ARRAY_ALL;
@@ -132,8 +137,9 @@ int wp_decode_service_request(
if (!decode_is_opening_tag_number(&apdu[len], 3))
return -1;
/* determine the length of the data blob */
wpdata->application_data_len = bacapp_data_len(&apdu[len],
apdu_len - len, (BACNET_PROPERTY_ID) property);
wpdata->application_data_len =
bacapp_data_len(&apdu[len], apdu_len - len,
(BACNET_PROPERTY_ID) property);
/* a tag number of 3 is not extended so only one octet */
len++;
/* copy the data from the APDU */
@@ -149,8 +155,9 @@ int wp_decode_service_request(
/* Tag 4: optional Priority - assumed MAX if not explicitly set */
wpdata->priority = BACNET_MAX_PRIORITY;
if ((unsigned) len < apdu_len) {
tag_len = decode_tag_number_and_value(&apdu[len],
&tag_number, &len_value_type);
tag_len =
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
if (tag_number == 4) {
len += tag_len;
len =
@@ -194,8 +201,9 @@ int wp_decode_apdu(
offset = 4;
if (apdu_len > offset) {
len = wp_decode_service_request(&apdu[offset],
apdu_len - offset, wpdata);
len =
wp_decode_service_request(&apdu[offset], apdu_len - offset,
wpdata);
}
return len;
@@ -227,7 +235,8 @@ void testWritePropertyTag(
ct_test(pTest, test_data.object_property == wpdata.object_property);
ct_test(pTest, test_data.array_index == wpdata.array_index);
/* decode the application value of the request */
len = bacapp_decode_application_data(test_data.application_data,
len =
bacapp_decode_application_data(test_data.application_data,
test_data.application_data_len, &test_value);
ct_test(pTest, test_value.tag == value->tag);
switch (test_value.tag) {
@@ -237,24 +246,24 @@ void testWritePropertyTag(
ct_test(pTest, test_value.type.Boolean == value->type.Boolean);
break;
case BACNET_APPLICATION_TAG_UNSIGNED_INT:
ct_test(pTest, test_value.type.Unsigned_Int ==
value->type.Unsigned_Int);
ct_test(pTest,
test_value.type.Unsigned_Int == value->type.Unsigned_Int);
break;
case BACNET_APPLICATION_TAG_SIGNED_INT:
ct_test(pTest, test_value.type.Signed_Int ==
value->type.Signed_Int);
ct_test(pTest,
test_value.type.Signed_Int == value->type.Signed_Int);
break;
case BACNET_APPLICATION_TAG_REAL:
ct_test(pTest, test_value.type.Real == value->type.Real);
break;
case BACNET_APPLICATION_TAG_ENUMERATED:
ct_test(pTest, test_value.type.Enumerated ==
value->type.Enumerated);
ct_test(pTest,
test_value.type.Enumerated == value->type.Enumerated);
break;
case BACNET_APPLICATION_TAG_DATE:
ct_test(pTest, test_value.type.Date.year == value->type.Date.year);
ct_test(pTest, test_value.type.Date.month ==
value->type.Date.month);
ct_test(pTest,
test_value.type.Date.month == value->type.Date.month);
ct_test(pTest, test_value.type.Date.day == value->type.Date.day);
ct_test(pTest, test_value.type.Date.wday == value->type.Date.wday);
break;
@@ -262,13 +271,15 @@ void testWritePropertyTag(
ct_test(pTest, test_value.type.Time.hour == value->type.Time.hour);
ct_test(pTest, test_value.type.Time.min == value->type.Time.min);
ct_test(pTest, test_value.type.Time.sec == value->type.Time.sec);
ct_test(pTest, test_value.type.Time.hundredths ==
ct_test(pTest,
test_value.type.Time.hundredths ==
value->type.Time.hundredths);
break;
case BACNET_APPLICATION_TAG_OBJECT_ID:
ct_test(pTest, test_value.type.Object_Id.type ==
value->type.Object_Id.type);
ct_test(pTest, test_value.type.Object_Id.instance ==
ct_test(pTest,
test_value.type.Object_Id.type == value->type.Object_Id.type);
ct_test(pTest,
test_value.type.Object_Id.instance ==
value->type.Object_Id.instance);
break;
default: