refactored the decoding to be suitable for a service request
This commit is contained in:
+31
-10
@@ -67,7 +67,8 @@ int whois_encode_apdu(
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
int whois_decode_apdu(
|
||||
// decode the service request only
|
||||
int whois_decode_service_request(
|
||||
uint8_t *apdu,
|
||||
unsigned apdu_len,
|
||||
int32_t *pLow_limit,
|
||||
@@ -78,17 +79,9 @@ int whois_decode_apdu(
|
||||
uint32_t len_value = 0;
|
||||
unsigned int decoded_value = 0;
|
||||
|
||||
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_WHO_IS)
|
||||
return -1;
|
||||
// optional limits - must be used as a pair
|
||||
if (apdu_len > 2)
|
||||
if (apdu_len)
|
||||
{
|
||||
len = 2;
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
|
||||
if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT)
|
||||
return -1;
|
||||
@@ -112,6 +105,34 @@ int whois_decode_apdu(
|
||||
return len;
|
||||
}
|
||||
|
||||
int whois_decode_apdu(
|
||||
uint8_t *apdu,
|
||||
unsigned apdu_len,
|
||||
int32_t *pLow_limit,
|
||||
int32_t *pHigh_limit)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
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_WHO_IS)
|
||||
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);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -43,6 +43,12 @@ int whois_encode_apdu(
|
||||
int32_t low_limit,
|
||||
int32_t high_limit);
|
||||
|
||||
int whois_decode_service_request(
|
||||
uint8_t *apdu,
|
||||
unsigned apdu_len,
|
||||
int32_t *pLow_limit,
|
||||
int32_t *pHigh_limit);
|
||||
|
||||
int whois_decode_apdu(
|
||||
uint8_t *apdu,
|
||||
unsigned apdu_len,
|
||||
@@ -53,4 +59,5 @@ int whois_decode_apdu(
|
||||
void testWhoIs(Test * pTest);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user