void test_Private_Transfer_Error( Test * pTest) { uint8_t apdu[480] = { 0 }; int len = 0; int apdu_len = 0; uint8_t invoke_id = 128; uint8_t test_invoke_id = 0; BACNET_ERROR_CLASS error_class = ERROR_CLASS_RESOURCES; BACNET_ERROR_CODE error_code = ERROR_CODE_OPERATIONAL_PROBLEM; BACNET_ERROR_CLASS test_error_class = 0; BACNET_ERROR_CODE test_error_code = 0; BACNET_PRIVATE_TRANSFER_DATA private_data; BACNET_PRIVATE_TRANSFER_DATA test_data; uint8_t test_value[480] = { 0 }; int private_data_len = 0; char private_data_chunk[33] = { "00112233445566778899AABBCCDDEEFF" }; BACNET_APPLICATION_DATA_VALUE data_value; BACNET_APPLICATION_DATA_VALUE test_data_value; bool status = false; private_data.vendorID = BACNET_VENDOR_ID; private_data.serviceNumber = 1; status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING, &private_data_chunk[0], &data_value); ct_test(pTest, status == true); private_data_len = bacapp_encode_application_data(&test_value[0], &data_value); private_data.serviceParameters = &test_value[0]; private_data.serviceParametersLen = private_data_len; len = ptransfer_error_encode_apdu(&apdu[0], invoke_id, error_class, error_code, &private_data); ct_test(pTest, len != 0); ct_test(pTest, len != -1); apdu_len = len; len = ptransfer_error_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_error_class, &test_error_code, &test_data); ct_test(pTest, len != -1); ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_data.vendorID == private_data.vendorID); ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber); ct_test(pTest, test_error_class == error_class); ct_test(pTest, test_error_code == error_code); ct_test(pTest, test_data.serviceParametersLen == private_data.serviceParametersLen); len = bacapp_decode_application_data(test_data.serviceParameters, test_data.serviceParametersLen, &test_data_value); ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true); }
int bacapp_encode_time_value(uint8_t * apdu, BACNET_TIME_VALUE * value) { int len; int apdu_len = 0; len = encode_application_time(&apdu[apdu_len], &value->Time); apdu_len += len; len = bacapp_encode_application_data(&apdu[apdu_len], &value->Value); apdu_len += len; return apdu_len; }
void test_Private_Transfer_Request( Test * pTest) { uint8_t apdu[480] = { 0 }; uint8_t test_value[480] = { 0 }; int len = 0; int apdu_len = 0; uint8_t invoke_id = 128; uint8_t test_invoke_id = 0; int private_data_len = 0; char private_data_chunk[33] = { "00112233445566778899AABBCCDDEEFF" }; BACNET_APPLICATION_DATA_VALUE data_value = { 0 }; BACNET_APPLICATION_DATA_VALUE test_data_value = { 0 }; BACNET_PRIVATE_TRANSFER_DATA private_data = { 0 }; BACNET_PRIVATE_TRANSFER_DATA test_data = { 0 }; bool status = false; private_data.vendorID = BACNET_VENDOR_ID; private_data.serviceNumber = 1; status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING, &private_data_chunk[0], &data_value); ct_test(pTest, status == true); private_data_len = bacapp_encode_application_data(&test_value[0], &data_value); private_data.serviceParameters = &test_value[0]; private_data.serviceParametersLen = private_data_len; len = ptransfer_encode_apdu(&apdu[0], invoke_id, &private_data); ct_test(pTest, len != 0); apdu_len = len; len = ptransfer_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_data); ct_test(pTest, len != -1); ct_test(pTest, test_data.vendorID == private_data.vendorID); ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber); ct_test(pTest, test_data.serviceParametersLen == private_data.serviceParametersLen); len = bacapp_decode_application_data(test_data.serviceParameters, test_data.serviceParametersLen, &test_data_value); ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true); return; }
void test_Private_Transfer_Ack( Test * pTest) { uint8_t apdu[480] = { 0 }; int len = 0; int apdu_len = 0; uint8_t invoke_id = 128; uint8_t test_invoke_id = 0; BACNET_PRIVATE_TRANSFER_DATA private_data; BACNET_PRIVATE_TRANSFER_DATA test_data; uint8_t test_value[480] = { 0 }; int private_data_len = 0; uint8_t private_data_chunk[32] = { "I Love You, Patricia!" }; BACNET_APPLICATION_DATA_VALUE data_value; BACNET_APPLICATION_DATA_VALUE test_data_value; private_data.vendorID = BACNET_VENDOR_ID; private_data.serviceNumber = 1; bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING, &private_data_chunk[0], &data_value); private_data_len = bacapp_encode_application_data(&test_value[0], &data_value); private_data.serviceParameters = &test_value[0]; private_data.serviceParametersLen = private_data_len; len = ptransfer_ack_encode_apdu(&apdu[0], invoke_id, &private_data); ct_test(pTest, len != 0); ct_test(pTest, len != -1); apdu_len = len; len = ptransfer_ack_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_data); ct_test(pTest, len != -1); ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_data.vendorID == private_data.vendorID); ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber); ct_test(pTest, test_data.serviceParametersLen == private_data.serviceParametersLen); len = bacapp_decode_application_data(test_data.serviceParameters, test_data.serviceParametersLen, &test_data_value); ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true); }
void test_Unconfirmed_Private_Transfer_Request( Test * pTest) { uint8_t apdu[480] = { 0 }; uint8_t test_value[480] = { 0 }; int len = 0; int apdu_len = 0; int private_data_len = 0; char private_data_chunk[32] = { "I Love You, Patricia!" }; BACNET_APPLICATION_DATA_VALUE data_value; BACNET_APPLICATION_DATA_VALUE test_data_value; BACNET_PRIVATE_TRANSFER_DATA private_data; BACNET_PRIVATE_TRANSFER_DATA test_data; bool status = false; private_data.vendorID = BACNET_VENDOR_ID; private_data.serviceNumber = 1; status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_CHARACTER_STRING, &private_data_chunk[0], &data_value); ct_test(pTest, status == true); private_data_len = bacapp_encode_application_data(&test_value[0], &data_value); private_data.serviceParameters = &test_value[0]; private_data.serviceParametersLen = private_data_len; len = uptransfer_encode_apdu(&apdu[0], &private_data); ct_test(pTest, len != 0); apdu_len = len; len = uptransfer_decode_apdu(&apdu[0], apdu_len, &test_data); ct_test(pTest, len != -1); ct_test(pTest, test_data.vendorID == private_data.vendorID); ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber); ct_test(pTest, test_data.serviceParametersLen == private_data.serviceParametersLen); len = bacapp_decode_application_data(test_data.serviceParameters, test_data.serviceParametersLen, &test_data_value); ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true); return; }
void testReadPropertyMultipleAck( Test * pTest) { uint8_t apdu[480] = { 0 }; int len = 0; int test_len = 0; int apdu_len = 0; uint8_t invoke_id = 12; 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; uint32_t array_index = 0; BACNET_APPLICATION_DATA_VALUE application_data[4] = { {0} }; BACNET_APPLICATION_DATA_VALUE test_application_data = { 0 }; uint8_t application_data_buffer[MAX_APDU] = { 0 }; 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 */ /* IDEA: similar construction, but pass apdu, apdu_len pointer, size of apdu to let the called function handle the out of space problem that these get into by returning a boolean of success/failure. It almost needs to use the keylist library or something similar. Also check case of storing a backoff point (i.e. save enough room for object_end) */ 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], &rpmdata); /* reply property */ 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; application_data[0].type.Object_Id.type = OBJECT_DEVICE; application_data[0].type.Object_Id.instance = 123; application_data_buffer_len = bacapp_encode_application_data(&application_data_buffer[0], &application_data[0]); apdu_len += 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); /* reply value */ application_data[1].tag = BACNET_APPLICATION_TAG_ENUMERATED; application_data[1].type.Enumerated = OBJECT_DEVICE; application_data_buffer_len = bacapp_encode_application_data(&application_data_buffer[0], &application_data[1]); apdu_len += rpm_ack_encode_apdu_object_property_value(&apdu[apdu_len], &application_data_buffer[0], application_data_buffer_len); /* object end */ 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], &rpmdata); /* reply property */ 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; application_data[2].type.Real = 0.0; application_data_buffer_len = bacapp_encode_application_data(&application_data_buffer[0], &application_data[2]); apdu_len += 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); /* reply error */ 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]); ct_test(pTest, apdu_len != 0); /****** decode the packet ******/ test_len = rpm_ack_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &service_request, /* will point to the service request in the apdu */ &service_request_len); ct_test(pTest, test_len != -1); ct_test(pTest, test_invoke_id == invoke_id); 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); 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], service_request_len - len, &object_property, &array_index); ct_test(pTest, object_property == PROP_OBJECT_IDENTIFIER); ct_test(pTest, array_index == BACNET_ARRAY_ALL); len += test_len; /* what is the result? An error or a value? */ ct_test(pTest, decode_is_opening_tag_number(&service_request[len], 4)); len++; /* 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], service_request_len - len, &test_application_data); ct_test(pTest, test_len > 0); ct_test(pTest, bacapp_same_value(&application_data[0], &test_application_data)); len += test_len; 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], service_request_len - len, &object_property, &array_index); ct_test(pTest, test_len != -1); ct_test(pTest, object_property == PROP_OBJECT_TYPE); ct_test(pTest, array_index == BACNET_ARRAY_ALL); len += test_len; /* what is the result value? */ 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], service_request_len - len, &test_application_data); ct_test(pTest, test_len > 0); ct_test(pTest, bacapp_same_value(&application_data[1], &test_application_data)); len += test_len; ct_test(pTest, decode_is_closing_tag_number(&service_request[len], 4)); len++; /* see if there is another property */ /* this time we should fail */ 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], 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], 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], service_request_len - len, &object_property, &array_index); ct_test(pTest, test_len != -1); ct_test(pTest, object_property == PROP_PRESENT_VALUE); ct_test(pTest, array_index == BACNET_ARRAY_ALL); len += test_len; /* what is the result value? */ 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], service_request_len - len, &test_application_data); ct_test(pTest, test_len > 0); ct_test(pTest, bacapp_same_value(&application_data[2], &test_application_data)); len += test_len; 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], service_request_len - len, &object_property, &array_index); ct_test(pTest, test_len != -1); ct_test(pTest, object_property == PROP_DEADBAND); ct_test(pTest, array_index == BACNET_ARRAY_ALL); len += test_len; /* what is the result value? */ 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], service_request_len - len, &error_class, &error_code); ct_test(pTest, test_len != 0); ct_test(pTest, error_class == ERROR_CLASS_PROPERTY); ct_test(pTest, error_code == ERROR_CODE_UNKNOWN_PROPERTY); len += test_len; 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], 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], 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], service_request_len - len, &object_type, &object_instance); ct_test(pTest, test_len == 0); ct_test(pTest, len == service_request_len); }
void testWritePropertyTag( Test * pTest, BACNET_APPLICATION_DATA_VALUE * value) { BACNET_WRITE_PROPERTY_DATA wpdata = { 0 }; BACNET_WRITE_PROPERTY_DATA test_data = { 0 }; BACNET_APPLICATION_DATA_VALUE test_value; uint8_t apdu[480] = { 0 }; int len = 0; int apdu_len = 0; uint8_t invoke_id = 128; uint8_t test_invoke_id = 0; wpdata.application_data_len = bacapp_encode_application_data(&wpdata.application_data[0], value); len = wp_encode_apdu(&apdu[0], invoke_id, &wpdata); ct_test(pTest, len != 0); /* decode the data */ apdu_len = len; len = wp_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_data); ct_test(pTest, len != -1); ct_test(pTest, test_data.object_type == wpdata.object_type); ct_test(pTest, test_data.object_instance == wpdata.object_instance); 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, test_data.application_data_len, &test_value); ct_test(pTest, test_value.tag == value->tag); switch (test_value.tag) { case BACNET_APPLICATION_TAG_NULL: break; case BACNET_APPLICATION_TAG_BOOLEAN: 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); break; case BACNET_APPLICATION_TAG_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); 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.day == value->type.Date.day); ct_test(pTest, test_value.type.Date.wday == value->type.Date.wday); break; case BACNET_APPLICATION_TAG_TIME: 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 == 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 == value->type.Object_Id.instance); break; default: break; } }