From d4b3e73439d09ce859a9d821efc7e5742552f0aa Mon Sep 17 00:00:00 2001 From: skarg Date: Thu, 10 Aug 2006 20:17:18 +0000 Subject: [PATCH] Moved apdu decode into unit test where it was being used since it is being decoded in apdu.c in normal usage. --- bacnet-stack/iam.c | 40 +++++++++++++++--------------- bacnet-stack/iam.h | 8 +++--- bacnet-stack/rp.c | 62 +++++++++++++++++++++++----------------------- bacnet-stack/rp.h | 13 +++++----- 4 files changed, 61 insertions(+), 62 deletions(-) diff --git a/bacnet-stack/iam.c b/bacnet-stack/iam.c index bb0e27ae..c60b1e77 100755 --- a/bacnet-stack/iam.c +++ b/bacnet-stack/iam.c @@ -134,26 +134,6 @@ int iam_decode_service_request(uint8_t * apdu, return apdu_len; } -int iam_decode_apdu(uint8_t * apdu, - uint32_t * pDevice_id, - unsigned *pMax_apdu, int *pSegmentation, uint16_t * pVendor_id) -{ - int apdu_len = 0; /* total length of the apdu, return value */ - - /* valid data? */ - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST) - 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); - - return apdu_len; -} - int iam_send(uint8_t * buffer) { int pdu_len = 0; @@ -183,6 +163,26 @@ int iam_send(uint8_t * buffer) #include #include "ctest.h" +int iam_decode_apdu(uint8_t * apdu, + uint32_t * pDevice_id, + unsigned *pMax_apdu, int *pSegmentation, uint16_t * pVendor_id) +{ + int apdu_len = 0; /* total length of the apdu, return value */ + + /* valid data? */ + if (!apdu) + return -1; + /* optional checking - most likely was already done prior to this call */ + if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST) + 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); + + return apdu_len; +} + void testIAm(Test * pTest) { uint8_t apdu[480] = { 0 }; diff --git a/bacnet-stack/iam.h b/bacnet-stack/iam.h index 555436be..3c5674da 100644 --- a/bacnet-stack/iam.h +++ b/bacnet-stack/iam.h @@ -50,14 +50,14 @@ extern "C" { uint32_t * pDevice_id, unsigned *pMax_apdu, int *pSegmentation, uint16_t * pVendor_id); - int iam_decode_apdu(uint8_t * apdu, - uint32_t * pDevice_id, - unsigned *pMax_apdu, int *pSegmentation, uint16_t * pVendor_id); - int iam_send(uint8_t * buffer); #ifdef TEST #include "ctest.h" + int iam_decode_apdu(uint8_t * apdu, + uint32_t * pDevice_id, + unsigned *pMax_apdu, int *pSegmentation, uint16_t * pVendor_id); + void testIAm(Test * pTest); #endif diff --git a/bacnet-stack/rp.c b/bacnet-stack/rp.c index bdca480f..d26613d3 100644 --- a/bacnet-stack/rp.c +++ b/bacnet-stack/rp.c @@ -109,32 +109,6 @@ int rp_decode_service_request(uint8_t * apdu, return (int) len; } -int rp_decode_apdu(uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * data) -{ - int len = 0; - unsigned offset = 0; - - if (!apdu) - return -1; - /* optional checking - most likely was already done prior to this call */ - if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) - return -1; - /* apdu[1] = encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ - if (apdu[3] != SERVICE_CONFIRMED_READ_PROPERTY) - return -1; - offset = 4; - - if (apdu_len > offset) { - len = rp_decode_service_request(&apdu[offset], - apdu_len - offset, data); - } - - return len; -} - int rp_ack_encode_apdu(uint8_t * apdu, uint8_t invoke_id, BACNET_READ_PROPERTY_DATA * data) { @@ -213,6 +187,37 @@ int rp_ack_decode_service_request(uint8_t * apdu, int apdu_len, /* total length return len; } +#ifdef TEST +#include +#include +#include "ctest.h" + +int rp_decode_apdu(uint8_t * apdu, + unsigned apdu_len, + uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * data) +{ + int len = 0; + unsigned offset = 0; + + if (!apdu) + return -1; + /* optional checking - most likely was already done prior to this call */ + if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) + return -1; + /* apdu[1] = encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); */ + *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ + if (apdu[3] != SERVICE_CONFIRMED_READ_PROPERTY) + return -1; + offset = 4; + + if (apdu_len > offset) { + len = rp_decode_service_request(&apdu[offset], + apdu_len - offset, data); + } + + return len; +} + int rp_ack_decode_apdu(uint8_t * apdu, int apdu_len, /* total length of the apdu */ uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * data) { @@ -236,11 +241,6 @@ int rp_ack_decode_apdu(uint8_t * apdu, int apdu_len, /* total length of the a return len; } -#ifdef TEST -#include -#include -#include "ctest.h" - void testReadPropertyAck(Test * pTest) { uint8_t apdu[480] = { 0 }; diff --git a/bacnet-stack/rp.h b/bacnet-stack/rp.h index 64fd5ad8..4332ab18 100644 --- a/bacnet-stack/rp.h +++ b/bacnet-stack/rp.h @@ -58,22 +58,21 @@ extern "C" { int rp_decode_service_request(uint8_t * apdu, unsigned apdu_len, BACNET_READ_PROPERTY_DATA * data); - int rp_decode_apdu(uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * data); - int rp_ack_encode_apdu(uint8_t * apdu, uint8_t invoke_id, BACNET_READ_PROPERTY_DATA * data); int rp_ack_decode_service_request(uint8_t * apdu, int apdu_len, /* total length of the apdu */ BACNET_READ_PROPERTY_DATA * data); - int rp_ack_decode_apdu(uint8_t * apdu, int apdu_len, /* total length of the apdu */ - uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * data); - #ifdef TEST #include "ctest.h" + int rp_decode_apdu(uint8_t * apdu, + unsigned apdu_len, + uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * data); + + int rp_ack_decode_apdu(uint8_t * apdu, int apdu_len, /* total length of the apdu */ + uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * data); void test_ReadProperty(Test * pTest); void test_ReadPropertyAck(Test * pTest);