Refactored rpm decoding to return proper reject/abort status for malformed requests.

Note: the test code in rpm.c has been changed to accommodate the changes made to the decoding functions but I have not tested the test code as I have not run the test suite.
This commit is contained in:
petermcs
2010-06-10 11:31:53 +00:00
parent 61bb34d726
commit 7b77fe776a
4 changed files with 236 additions and 201 deletions
+125 -127
View File
@@ -36,6 +36,8 @@
#include "apdu.h"
#include "npdu.h"
#include "abort.h"
#include "reject.h"
#include "bacerror.h"
#include "rpm.h"
#include "handlers.h"
/* device object has custom handler for all objects */
@@ -104,10 +106,7 @@ static int RPM_Encode_Property(
uint8_t * apdu,
uint16_t offset,
uint16_t max_apdu,
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance,
BACNET_PROPERTY_ID object_property,
int32_t array_index)
BACNET_RPM_DATA *rpmdata)
{
int len = 0;
size_t copy_len = 0;
@@ -115,26 +114,28 @@ static int RPM_Encode_Property(
BACNET_READ_PROPERTY_DATA rpdata;
len =
rpm_ack_encode_apdu_object_property(&Temp_Buf[0], object_property,
array_index);
rpm_ack_encode_apdu_object_property(&Temp_Buf[0], rpmdata->object_property,
rpmdata->array_index);
copy_len = memcopy(&apdu[0], &Temp_Buf[0], offset, len, max_apdu);
if (copy_len == 0) {
return 0;
rpmdata->error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
return BACNET_STATUS_ABORT;
}
apdu_len += len;
len = 0;
rpdata.error_class = ERROR_CLASS_OBJECT;
rpdata.error_code = ERROR_CODE_UNKNOWN_OBJECT;
rpdata.object_type = object_type;
rpdata.object_instance = object_instance;
rpdata.object_property = object_property;
rpdata.array_index = array_index;
rpdata.object_type = rpmdata->object_type;
rpdata.object_instance = rpmdata->object_instance;
rpdata.object_property = rpmdata->object_property;
rpdata.array_index = rpmdata->array_index;
rpdata.application_data = &Temp_Buf[0];
rpdata.application_data_len = sizeof(Temp_Buf);
len = Device_Read_Property(&rpdata);
if (len < 0) {
if (len == -2) {
return 0; /* Ie, Abort */
if ((len == BACNET_STATUS_ABORT) || (len == BACNET_STATUS_REJECT)){
/* pass on aborts and rejects for now */
return len; /* Ie, Abort */
}
/* error was returned - encode that for the response */
len =
@@ -142,8 +143,10 @@ static int RPM_Encode_Property(
rpdata.error_class, rpdata.error_code);
copy_len =
memcopy(&apdu[0], &Temp_Buf[0], offset + apdu_len, len, max_apdu);
if (copy_len == 0) {
return 0;
rpmdata->error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
return BACNET_STATUS_ABORT;
}
} else if ((offset + apdu_len + 1 + len + 1) < max_apdu) {
/* enough room to fit the property value and tags */
@@ -152,7 +155,8 @@ static int RPM_Encode_Property(
&Temp_Buf[0], len);
} else {
/* not enough room - abort! */
return 0;
rpmdata->error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
return BACNET_STATUS_ABORT;
}
apdu_len += len;
@@ -192,12 +196,10 @@ void handler_read_property_multiple(
BACNET_NPDU_DATA npdu_data;
int bytes_sent;
BACNET_ADDRESS my_address;
BACNET_OBJECT_TYPE object_type;
uint32_t object_instance = 0;
BACNET_RPM_DATA rpmdata;
int apdu_len = 0;
int npdu_len = 0;
BACNET_PROPERTY_ID object_property;
int32_t array_index = 0;
int error = 0;
/* jps_debug - see if we are utilizing all the buffer */
/* memset(&Handler_Transmit_Buffer[0], 0xff, sizeof(Handler_Transmit_Buffer)); */
@@ -208,14 +210,12 @@ void handler_read_property_multiple(
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
&npdu_data);
if (service_data->segmented_message) {
apdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
rpmdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
error = BACNET_STATUS_ABORT;
#if PRINT_ENABLED
printf("RPM: Segmented message. Sending Abort!\r\n");
#endif
goto RPM_ABORT;
goto RPM_FAILURE;
}
/* decode apdu request & encode apdu reply
encode complex ack, invoke id, service choice */
@@ -223,102 +223,61 @@ void handler_read_property_multiple(
rpm_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id);
for(;;) {
/* Start by looking for an object ID */
len =
rpm_decode_object_id(&service_request[decode_len],
service_len - decode_len, &object_type, &object_instance);
/* end of object? */
if (len > 0) {
service_len - decode_len, &rpmdata);
if (len >= 0) { /* Got one so skip to next stage */
decode_len += len;
} else {
len =
rpm_decode_object_end(&service_request[decode_len],
service_len - decode_len);
if (len == 1) {
decode_len++;
len = rpm_ack_encode_apdu_object_end(&Temp_Buf[0]);
copy_len =
memcopy(&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0],
apdu_len, len, sizeof(Handler_Transmit_Buffer));
if (!copy_len) {
apdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
goto RPM_ABORT;
} else {
apdu_len += copy_len;
}
} else {
apdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
goto RPM_ABORT;
}
break;
} else { /* bad encoding - skip to error/reject/abort handling */
#if PRINT_ENABLED
fprintf(stderr, "RPM: Bad Encoding.\n");
#endif
error = len;
goto RPM_FAILURE;
}
len =
rpm_ack_encode_apdu_object_begin(&Temp_Buf[0], object_type,
object_instance);
/* Stick this object id into the reply - if it will fit */
len = rpm_ack_encode_apdu_object_begin(&Temp_Buf[0], &rpmdata);
copy_len =
memcopy(&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0], apdu_len,
len, sizeof(Handler_Transmit_Buffer));
if (!copy_len) {
apdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
goto RPM_ABORT;
} else {
apdu_len += copy_len;
#if PRINT_ENABLED
printf("RPM: Response too big!\r\n");
#endif
rpmdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
error = BACNET_STATUS_ABORT;
goto RPM_FAILURE;
}
apdu_len += copy_len;
/* do each property of this object of the RPM request */
for(;;) {
/* Fetch a property */
len =
rpm_decode_object_property(&service_request[decode_len],
service_len - decode_len, &object_property, &array_index);
/* end of property list? */
if (len > 0) {
decode_len += len;
} else {
len =
rpm_decode_object_end(&service_request[decode_len],
service_len - decode_len);
if (len == 1) {
decode_len++;
len = rpm_ack_encode_apdu_object_end(&Temp_Buf[0]);
copy_len =
memcopy(&Handler_Transmit_Buffer[npdu_len],
&Temp_Buf[0], apdu_len, len,
sizeof(Handler_Transmit_Buffer));
if (!copy_len) {
apdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer
[npdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
goto RPM_ABORT;
} else {
apdu_len += copy_len;
}
} else {
apdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
goto RPM_ABORT;
}
/* stop decoding properties */
break;
service_len - decode_len, &rpmdata);
if (len < 0) { /* bad encoding - skip to error/reject/abort handling */
#if PRINT_ENABLED
fprintf(stderr, "RPM: Bad Encoding.\n");
#endif
error = len;
goto RPM_FAILURE;
}
decode_len += len;
/* handle the special properties */
if ((object_property == PROP_ALL) ||
(object_property == PROP_REQUIRED) ||
(object_property == PROP_OPTIONAL)) {
if ((rpmdata.object_property == PROP_ALL) ||
(rpmdata.object_property == PROP_REQUIRED) ||
(rpmdata.object_property == PROP_OPTIONAL)) {
struct special_property_list_t property_list;
unsigned property_count = 0;
unsigned index = 0;
BACNET_PROPERTY_ID special_object_property;
special_object_property = object_property;
Device_Objects_Property_List(object_type, &property_list);
special_object_property = rpmdata.object_property;
Device_Objects_Property_List(rpmdata.object_type, &property_list);
property_count =
RPM_Object_Property_Count(&property_list,
special_object_property);
@@ -326,34 +285,26 @@ void handler_read_property_multiple(
/* handle the error code - but use the special property */
len =
RPM_Encode_Property(&Handler_Transmit_Buffer[0],
(uint16_t)(npdu_len + apdu_len), MAX_APDU, object_type,
object_instance, object_property, array_index);
(uint16_t)(npdu_len + apdu_len), MAX_APDU, &rpmdata);
if (len > 0) {
apdu_len += len;
} else {
apdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer
[npdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
goto RPM_ABORT;
error = len;
goto RPM_FAILURE;
}
} else {
for (index = 0; index < property_count; index++) {
object_property =
rpmdata.object_property =
RPM_Object_Property(&property_list,
special_object_property, index);
len =
RPM_Encode_Property(&Handler_Transmit_Buffer[0],
(uint16_t)(npdu_len + apdu_len), MAX_APDU, object_type,
object_instance, object_property, array_index);
(uint16_t)(npdu_len + apdu_len), MAX_APDU, &rpmdata);
if (len > 0) {
apdu_len += len;
} else {
apdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer
[npdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
goto RPM_ABORT;
error = len;
goto RPM_FAILURE;
}
}
}
@@ -361,24 +312,37 @@ void handler_read_property_multiple(
/* handle an individual property */
len =
RPM_Encode_Property(&Handler_Transmit_Buffer[0],
(uint16_t)(npdu_len + apdu_len), sizeof(Handler_Transmit_Buffer),
object_type, object_instance, object_property,
array_index);
(uint16_t)(npdu_len + apdu_len), sizeof(Handler_Transmit_Buffer), &rpmdata);
if (len > 0) {
apdu_len += len;
} else {
apdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
goto RPM_ABORT;
error = len;
goto RPM_FAILURE;
}
}
if (decode_is_closing_tag_number(&service_request[decode_len], 1)) {
/* Reached end of property list so cap the result list */
decode_len++;
len = rpm_ack_encode_apdu_object_end(&Temp_Buf[0]);
copy_len =
memcopy(&Handler_Transmit_Buffer[npdu_len],
&Temp_Buf[0], apdu_len, len,
sizeof(Handler_Transmit_Buffer));
if (!copy_len) {
rpmdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
error = BACNET_STATUS_ABORT;
goto RPM_FAILURE;
} else {
apdu_len += copy_len;
}
break; /* finished with this property list */
}
}
if (decode_len >= service_len) {
if(service_len == decode_len) /* Reached the end so finish up */
break;
}
}
if (apdu_len > service_data->max_resp) {
/* too big for the sender - send an abort */
apdu_len =
@@ -388,9 +352,43 @@ void handler_read_property_multiple(
#if PRINT_ENABLED
fprintf(stderr, "RPM: Message too large. Sending Abort!\n");
#endif
goto RPM_ABORT;
goto RPM_FAILURE;
}
RPM_ABORT:
RPM_FAILURE:
if (error) {
if (error == BACNET_STATUS_ABORT) {
/* Kludge alert! At the moment we assume any abort is due to
* to space issues due to segmentation or lack thereof. I wanted to show the proper
* handling via the abort_convert_error_code() so I put the error code
* in here, if you are sure all aborts properly set up the error_code then
* remove this next line
*/
rpmdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
apdu_len =
abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id,
abort_convert_error_code(rpmdata.error_code), true);
#if PRINT_ENABLED
fprintf(stderr, "RP: Sending Abort!\n");
#endif
} else if (error == BACNET_STATUS_ERROR){
apdu_len =
bacerror_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_READ_PROPERTY,
rpmdata.error_class, rpmdata.error_code);
#if PRINT_ENABLED
fprintf(stderr, "RP: Sending Error!\n");
#endif
} else if (error == BACNET_STATUS_REJECT){
apdu_len = reject_encode_apdu(&Handler_Transmit_Buffer[npdu_len],
service_data->invoke_id, reject_convert_error_code(rpmdata.error_code));
#if PRINT_ENABLED
fprintf(stderr, "RP: Sending Reject!\n");
#endif
}
}
pdu_len = apdu_len + npdu_len;
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
@@ -41,7 +41,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\..\include;..\..\..\ports\win32"
AdditionalIncludeDirectories="..\..\..\include;..\..\..\ports\win32;..\..\..\test"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
+17 -6
View File
@@ -40,6 +40,20 @@
#include "bacdef.h"
#include "bacapp.h"
/*
* Bundle together commonly used data items for convenience when calling
* rpm helper functions.
*/
typedef struct BACnet_RPM_Data {
BACNET_OBJECT_TYPE object_type;
uint32_t object_instance;
BACNET_PROPERTY_ID object_property;
int32_t array_index;
BACNET_ERROR_CLASS error_class;
BACNET_ERROR_CODE error_code;
} BACNET_RPM_DATA;
struct BACnet_Read_Access_Data;
typedef struct BACnet_Read_Access_Data {
BACNET_OBJECT_TYPE object_type;
@@ -119,8 +133,7 @@ extern "C" {
int rpm_decode_object_id(
uint8_t * apdu,
unsigned apdu_len,
BACNET_OBJECT_TYPE * object_type,
uint32_t * object_instance);
BACNET_RPM_DATA *rpmdata);
/* is this the end of this object property list? */
int rpm_decode_object_end(
@@ -131,8 +144,7 @@ extern "C" {
int rpm_decode_object_property(
uint8_t * apdu,
unsigned apdu_len,
BACNET_PROPERTY_ID * object_property,
int32_t * array_index);
BACNET_RPM_DATA *rpmdata);
/* RPM Ack - reply from server */
int rpm_ack_encode_apdu_init(
@@ -141,8 +153,7 @@ extern "C" {
int rpm_ack_encode_apdu_object_begin(
uint8_t * apdu,
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance);
BACNET_RPM_DATA *rpmdata);
int rpm_ack_encode_apdu_object_property(
uint8_t * apdu,
+93 -67
View File
@@ -1,3 +1,4 @@
#define TEST
/*####COPYRIGHTBEGIN####
-------------------------------------------
Copyright (C) 2005 Steve Karg
@@ -191,27 +192,35 @@ int rpm_encode_apdu(
return apdu_len;
}
/* decode the object portion of the service request only */
/* decode the object portion of the service request only. Bails out if
* tags are wrong or missing/incomplete
*/
int rpm_decode_object_id(
uint8_t * apdu,
unsigned apdu_len,
BACNET_OBJECT_TYPE * object_type,
uint32_t * object_instance)
BACNET_RPM_DATA *rpmdata)
{
unsigned len = 0;
uint16_t type = 0; /* for decoding */
/* check for value pointers */
if (apdu && apdu_len && object_type && object_instance) {
if (apdu && apdu_len && rpmdata) {
if(apdu_len < 5) { /* Must be at least 2 tags and an object id */
rpmdata->error_code = ERROR_CODE_REJECT_MISSING_REQUIRED_PARAMETER;
return BACNET_STATUS_REJECT;
}
/* Tag 0: Object ID */
if (!decode_is_context_tag(&apdu[len++], 0))
return -1;
len += decode_object_id(&apdu[len], &type, object_instance);
if (object_type)
*object_type = (BACNET_OBJECT_TYPE) type;
if (!decode_is_context_tag(&apdu[len++], 0)) {
rpmdata->error_code = ERROR_CODE_REJECT_INVALID_TAG;
return BACNET_STATUS_REJECT;
}
len += decode_object_id(&apdu[len], &type, &rpmdata->object_instance);
rpmdata->object_type = (BACNET_OBJECT_TYPE) type;
/* Tag 1: sequence of ReadAccessSpecification */
if (!decode_is_opening_tag_number(&apdu[len], 1))
return -1;
if (!decode_is_opening_tag_number(&apdu[len], 1)) {
rpmdata->error_code = ERROR_CODE_REJECT_INVALID_TAG;
return BACNET_STATUS_REJECT;
}
len++; /* opening tag is only one octet */
}
@@ -225,7 +234,7 @@ int rpm_decode_object_end(
int len = 0; /* total length of the apdu, return value */
if (apdu && apdu_len) {
if (decode_is_closing_tag_number(apdu, 1))
if (decode_is_closing_tag_number(apdu, 1) == true)
len = 1;
}
@@ -243,8 +252,7 @@ int rpm_decode_object_end(
int rpm_decode_object_property(
uint8_t * apdu,
unsigned apdu_len,
BACNET_PROPERTY_ID * object_property,
int32_t * array_index)
BACNET_RPM_DATA *rpmdata)
{
unsigned len = 0;
unsigned option_len = 0;
@@ -254,33 +262,46 @@ int rpm_decode_object_property(
uint32_t array_value = 0; /* for decoding */
/* check for valid pointers */
if (apdu && apdu_len && object_property && array_index) {
if (apdu && apdu_len && rpmdata) {
/* Tag 0: propertyIdentifier */
if (!IS_CONTEXT_SPECIFIC(apdu[len]))
return -1;
if (!IS_CONTEXT_SPECIFIC(apdu[len])) {
rpmdata->error_code = ERROR_CODE_REJECT_INVALID_TAG;
return BACNET_STATUS_REJECT;
}
len +=
decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
if (tag_number != 0)
return -1;
if (tag_number != 0) {
rpmdata->error_code = ERROR_CODE_REJECT_INVALID_TAG;
return BACNET_STATUS_REJECT;
}
/* Should be at least the unsigned value + 1 tag left */
if ((len + len_value_type) >= apdu_len) {
rpmdata->error_code = ERROR_CODE_REJECT_MISSING_REQUIRED_PARAMETER;
return BACNET_STATUS_REJECT;
}
len += decode_enumerated(&apdu[len], len_value_type, &property);
if (object_property)
*object_property = (BACNET_PROPERTY_ID) property;
rpmdata->object_property = (BACNET_PROPERTY_ID) property;
/* Tag 1: Optional propertyArrayIndex */
if ((len < apdu_len) && IS_CONTEXT_SPECIFIC(apdu[len]) &&
(!IS_CLOSING_TAG(apdu[len]))) {
rpmdata->array_index = BACNET_ARRAY_ALL; /* Assume most probable outcome */
if (IS_CONTEXT_SPECIFIC(apdu[len]) && !IS_CLOSING_TAG(apdu[len])) {
option_len =
(unsigned) decode_tag_number_and_value(&apdu[len], &tag_number,
&len_value_type);
if (tag_number == 1) {
len += option_len;
/* Should be at least the unsigned array index + 1 tag left */
if ((len + len_value_type) >= apdu_len) {
rpmdata->error_code = ERROR_CODE_REJECT_MISSING_REQUIRED_PARAMETER;
return BACNET_STATUS_REJECT;
}
len +=
decode_unsigned(&apdu[len], len_value_type, &array_value);
*array_index = array_value;
} else
*array_index = BACNET_ARRAY_ALL;
} else
*array_index = BACNET_ARRAY_ALL;
rpmdata->array_index = array_value;
}
}
}
return (int) len;
@@ -304,16 +325,15 @@ int rpm_ack_encode_apdu_init(
int rpm_ack_encode_apdu_object_begin(
uint8_t * apdu,
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance)
BACNET_RPM_DATA *rpmdata)
{
int apdu_len = 0; /* total length of the apdu, return value */
if (apdu) {
/* Tag 0: objectIdentifier */
apdu_len =
encode_context_object_id(&apdu[0], 0, object_type,
object_instance);
encode_context_object_id(&apdu[0], 0, rpmdata->object_type,
rpmdata->object_instance);
/* Tag 1: listOfResults */
apdu_len += encode_opening_tag(&apdu[apdu_len], 1);
}
@@ -555,10 +575,12 @@ void testReadPropertyMultiple(
uint8_t test_invoke_id = 0;
uint8_t *service_request = NULL;
unsigned service_request_len = 0;
BACNET_OBJECT_TYPE object_type = OBJECT_DEVICE;
uint32_t object_instance = 0;
BACNET_PROPERTY_ID object_property = PROP_OBJECT_IDENTIFIER;
int32_t array_index = 0;
BACNET_RPM_DATA rpmdata;
rpmdata.object_type = OBJECT_DEVICE;
rpmdata.object_instance = 0;
rpmdata.object_property = PROP_OBJECT_IDENTIFIER;
rpmdata.array_index = 0;
/* build the RPM - try to make it easy for the Application Layer development */
/* IDEA: similar construction, but pass apdu, apdu_len pointer, size of apdu to
@@ -600,31 +622,31 @@ void testReadPropertyMultiple(
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);
&rpmdata);
ct_test(pTest, test_len > 0);
ct_test(pTest, rpmdata.object_type == OBJECT_DEVICE);
ct_test(pTest, rpmdata.object_instance == 123);
len = test_len;
/* decode the object property portion of the service request */
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);
service_request_len - len, &rpmdata);
ct_test(pTest, test_len > 0);
ct_test(pTest, rpmdata.object_property == PROP_OBJECT_IDENTIFIER);
ct_test(pTest, rpmdata.array_index == BACNET_ARRAY_ALL);
len += test_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);
service_request_len - len, &rpmdata);
ct_test(pTest, test_len > 0);
ct_test(pTest, rpmdata.object_property == PROP_OBJECT_NAME);
ct_test(pTest, rpmdata.array_index == BACNET_ARRAY_ALL);
len += test_len;
/* try again - we should fail */
test_len =
rpm_decode_object_property(&service_request[len],
service_request_len - len, &object_property, &array_index);
ct_test(pTest, test_len == -1);
service_request_len - len, &rpmdata);
ct_test(pTest, test_len < 0);
/* is it the end of this object? */
test_len =
rpm_decode_object_end(&service_request[len],
@@ -634,30 +656,30 @@ void testReadPropertyMultiple(
/* try to decode an object id */
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);
&rpmdata);
ct_test(pTest, test_len > 0);
ct_test(pTest, rpmdata.object_type == OBJECT_ANALOG_INPUT);
ct_test(pTest, rpmdata.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],
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);
service_request_len - len, &rpmdata);
ct_test(pTest, test_len > 0);
ct_test(pTest, rpmdata.object_property == PROP_OBJECT_IDENTIFIER);
ct_test(pTest, rpmdata.array_index == BACNET_ARRAY_ALL);
len += test_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);
service_request_len - len, &rpmdata);
ct_test(pTest, test_len > 0);
ct_test(pTest, rpmdata.object_property == PROP_ALL);
ct_test(pTest, rpmdata.array_index == BACNET_ARRAY_ALL);
len += test_len;
test_len =
rpm_decode_object_property(&service_request[len],
service_request_len - len, &object_property, &array_index);
ct_test(pTest, test_len == -1);
service_request_len - len, &rpmdata);
ct_test(pTest, test_len < 0);
/* got an error -1, is it the end of this object? */
test_len =
rpm_decode_object_end(&service_request[len],
@@ -688,6 +710,7 @@ void testReadPropertyMultipleAck(
int application_data_buffer_len = 0;
BACNET_ERROR_CLASS error_class;
BACNET_ERROR_CODE error_code;
BACNET_RPM_DATA rpmdata;
/* build the RPM - try to make it easy for the
Application Layer development */
@@ -701,8 +724,10 @@ void testReadPropertyMultipleAck(
apdu_len = rpm_ack_encode_apdu_init(&apdu[0], invoke_id);
/* object beginning */
rpmdata.object_type = OBJECT_DEVICE;
rpmdata.object_instance = 123;
apdu_len +=
rpm_ack_encode_apdu_object_begin(&apdu[apdu_len], OBJECT_DEVICE, 123);
rpm_ack_encode_apdu_object_begin(&apdu[apdu_len], &rpmdata);
/* reply property */
apdu_len +=
rpm_ack_encode_apdu_object_property(&apdu[apdu_len],
@@ -734,9 +759,10 @@ void testReadPropertyMultipleAck(
apdu_len += rpm_ack_encode_apdu_object_end(&apdu[apdu_len]);
/* object beginning */
rpmdata.object_type = OBJECT_ANALOG_INPUT;
rpmdata.object_instance = 33;
apdu_len +=
rpm_ack_encode_apdu_object_begin(&apdu[apdu_len], OBJECT_ANALOG_INPUT,
33);
rpm_ack_encode_apdu_object_begin(&apdu[apdu_len], &rpmdata);
/* reply property */
apdu_len +=
rpm_ack_encode_apdu_object_property(&apdu[apdu_len],