Fixed EOL, indent.
This commit is contained in:
+141
-125
@@ -56,18 +56,18 @@ static struct Address_Cache_Entry {
|
||||
|
||||
/* State flags for cache entries */
|
||||
|
||||
#define BAC_ADDR_IN_USE 1 /* Address cache entry in use */
|
||||
#define BAC_ADDR_BIND_REQ 2 /* Bind request outstanding for entry */
|
||||
#define BAC_ADDR_STATIC 4 /* Static address mapping - does not expire */
|
||||
#define BAC_ADDR_SHORT_TTL 8 /* Oppertunistaclly added address with short TTL */
|
||||
#define BAC_ADDR_RESERVED 128 /* Freed up but held for caller to fill */
|
||||
#define BAC_ADDR_IN_USE 1 /* Address cache entry in use */
|
||||
#define BAC_ADDR_BIND_REQ 2 /* Bind request outstanding for entry */
|
||||
#define BAC_ADDR_STATIC 4 /* Static address mapping - does not expire */
|
||||
#define BAC_ADDR_SHORT_TTL 8 /* Oppertunistaclly added address with short TTL */
|
||||
#define BAC_ADDR_RESERVED 128 /* Freed up but held for caller to fill */
|
||||
|
||||
#define BAC_ADDR_SECS_1HOUR 3600 /* 60x60 */
|
||||
#define BAC_ADDR_SECS_1DAY 86400 /* 60x60x24 */
|
||||
#define BAC_ADDR_SECS_1HOUR 3600 /* 60x60 */
|
||||
#define BAC_ADDR_SECS_1DAY 86400 /* 60x60x24 */
|
||||
|
||||
#define BAC_ADDR_LONG_TIME BAC_ADDR_SECS_1DAY
|
||||
#define BAC_ADDR_LONG_TIME BAC_ADDR_SECS_1DAY
|
||||
#define BAC_ADDR_SHORT_TIME BAC_ADDR_SECS_1HOUR
|
||||
#define BAC_ADDR_FOREVER 0xFFFFFFFF /* Permenant entry */
|
||||
#define BAC_ADDR_FOREVER 0xFFFFFFFF /* Permenant entry */
|
||||
|
||||
bool address_match(
|
||||
BACNET_ADDRESS * dest,
|
||||
@@ -108,11 +108,12 @@ bool address_match(
|
||||
void address_remove_device(
|
||||
uint32_t device_id)
|
||||
{
|
||||
struct Address_Cache_Entry *pMatch;
|
||||
struct Address_Cache_Entry *pMatch;
|
||||
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1]) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) && (pMatch->device_id == device_id)) {
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) &&
|
||||
(pMatch->device_id == device_id)) {
|
||||
pMatch->Flags = 0;
|
||||
break;
|
||||
}
|
||||
@@ -131,22 +132,24 @@ void address_remove_device(
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
struct Address_Cache_Entry * address_remove_oldest(
|
||||
struct Address_Cache_Entry *address_remove_oldest(
|
||||
void)
|
||||
{
|
||||
struct Address_Cache_Entry *pMatch;
|
||||
struct Address_Cache_Entry *pCandidate;
|
||||
uint32_t ulTime;
|
||||
struct Address_Cache_Entry *pMatch;
|
||||
struct Address_Cache_Entry *pCandidate;
|
||||
uint32_t ulTime;
|
||||
|
||||
pCandidate = NULL;
|
||||
ulTime = BAC_ADDR_FOREVER - 1; /* Longest possible non static time to live */
|
||||
|
||||
ulTime = BAC_ADDR_FOREVER - 1; /* Longest possible non static time to live */
|
||||
|
||||
/* First pass - try only in use and bound entries */
|
||||
|
||||
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1]) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ | BAC_ADDR_STATIC)) == BAC_ADDR_IN_USE) {
|
||||
if(pMatch->TimeToLive <= ulTime) { /* Shorter lived entry found */
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if ((pMatch->
|
||||
Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ |
|
||||
BAC_ADDR_STATIC)) == BAC_ADDR_IN_USE) {
|
||||
if (pMatch->TimeToLive <= ulTime) { /* Shorter lived entry found */
|
||||
ulTime = pMatch->TimeToLive;
|
||||
pCandidate = pMatch;
|
||||
}
|
||||
@@ -154,17 +157,20 @@ struct Address_Cache_Entry * address_remove_oldest(
|
||||
pMatch++;
|
||||
}
|
||||
|
||||
if(pCandidate != NULL) { /* Found something to free up */
|
||||
if (pCandidate != NULL) { /* Found something to free up */
|
||||
pCandidate->Flags = BAC_ADDR_RESERVED;
|
||||
pCandidate->TimeToLive = BAC_ADDR_SHORT_TIME; /* only reserve it for a short while */
|
||||
return(pCandidate);
|
||||
pCandidate->TimeToLive = BAC_ADDR_SHORT_TIME; /* only reserve it for a short while */
|
||||
return (pCandidate);
|
||||
}
|
||||
|
||||
|
||||
/* Second pass - try in use and un bound as last resort */
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1]) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ | BAC_ADDR_STATIC)) == (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) {
|
||||
if(pMatch->TimeToLive <= ulTime) { /* Shorter lived entry found */
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if ((pMatch->
|
||||
Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ |
|
||||
BAC_ADDR_STATIC)) ==
|
||||
(BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) {
|
||||
if (pMatch->TimeToLive <= ulTime) { /* Shorter lived entry found */
|
||||
ulTime = pMatch->TimeToLive;
|
||||
pCandidate = pMatch;
|
||||
}
|
||||
@@ -172,12 +178,12 @@ struct Address_Cache_Entry * address_remove_oldest(
|
||||
pMatch++;
|
||||
}
|
||||
|
||||
if(pCandidate != NULL) { /* Found something to free up */
|
||||
if (pCandidate != NULL) { /* Found something to free up */
|
||||
pCandidate->Flags = BAC_ADDR_RESERVED;
|
||||
pCandidate->TimeToLive = BAC_ADDR_SHORT_TIME; /* only reserve it for a short while */
|
||||
pCandidate->TimeToLive = BAC_ADDR_SHORT_TIME; /* only reserve it for a short while */
|
||||
}
|
||||
|
||||
return(pCandidate);
|
||||
|
||||
return (pCandidate);
|
||||
}
|
||||
|
||||
|
||||
@@ -255,7 +261,7 @@ void address_init(
|
||||
struct Address_Cache_Entry *pMatch;
|
||||
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
pMatch->Flags = 0;
|
||||
pMatch++;
|
||||
}
|
||||
@@ -278,16 +284,17 @@ void address_init_partial(
|
||||
struct Address_Cache_Entry *pMatch;
|
||||
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
if((pMatch->Flags & BAC_ADDR_IN_USE) != 0) { /* It's in use so let's check further */
|
||||
if(((pMatch->Flags & BAC_ADDR_BIND_REQ) != 0) || (pMatch->TimeToLive == 0))
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if ((pMatch->Flags & BAC_ADDR_IN_USE) != 0) { /* It's in use so let's check further */
|
||||
if (((pMatch->Flags & BAC_ADDR_BIND_REQ) != 0) ||
|
||||
(pMatch->TimeToLive == 0))
|
||||
pMatch->Flags = 0;
|
||||
}
|
||||
|
||||
if((pMatch->Flags & BAC_ADDR_RESERVED) != 0) { /* Reserved entries should be cleared */
|
||||
if ((pMatch->Flags & BAC_ADDR_RESERVED) != 0) { /* Reserved entries should be cleared */
|
||||
pMatch->Flags = 0;
|
||||
}
|
||||
|
||||
|
||||
pMatch++;
|
||||
}
|
||||
address_file_init(Address_Cache_Filename);
|
||||
@@ -306,27 +313,26 @@ void address_init_partial(
|
||||
void address_set_device_TTL(
|
||||
uint32_t device_id,
|
||||
uint32_t TimeOut,
|
||||
bool StaticFlag)
|
||||
bool StaticFlag)
|
||||
{
|
||||
struct Address_Cache_Entry *pMatch;
|
||||
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) && (pMatch->device_id == device_id)) {
|
||||
if((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { /* If bound then we have either static or normaal */
|
||||
if(StaticFlag) {
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) &&
|
||||
(pMatch->device_id == device_id)) {
|
||||
if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { /* If bound then we have either static or normaal */
|
||||
if (StaticFlag) {
|
||||
pMatch->Flags |= BAC_ADDR_STATIC;
|
||||
pMatch->TimeToLive = BAC_ADDR_FOREVER;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pMatch->Flags &= ~BAC_ADDR_STATIC;
|
||||
pMatch->TimeToLive = TimeOut;
|
||||
}
|
||||
} else {
|
||||
pMatch->TimeToLive = TimeOut; /* For unbound we can only set the time to live */
|
||||
}
|
||||
else {
|
||||
pMatch->TimeToLive = TimeOut; /* For unbound we can only set the time to live */
|
||||
}
|
||||
break; /* Exit now if found at all - bound or unbound */
|
||||
break; /* Exit now if found at all - bound or unbound */
|
||||
}
|
||||
pMatch++;
|
||||
}
|
||||
@@ -342,15 +348,15 @@ bool address_get_by_device(
|
||||
bool found = false; /* return value */
|
||||
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) &&
|
||||
(pMatch->device_id == device_id)) {
|
||||
if((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { /* If bound then fetch data */
|
||||
if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { /* If bound then fetch data */
|
||||
*src = pMatch->address;
|
||||
*max_apdu = pMatch->max_apdu;
|
||||
found = true; /* Prove we found it */
|
||||
found = true; /* Prove we found it */
|
||||
}
|
||||
break; /* Exit now if found at all - bound or unbound */
|
||||
break; /* Exit now if found at all - bound or unbound */
|
||||
}
|
||||
pMatch++;
|
||||
}
|
||||
@@ -368,8 +374,8 @@ bool address_get_device_id(
|
||||
bool found = false; /* return value */
|
||||
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == BAC_ADDR_IN_USE) { /* If bound */
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == BAC_ADDR_IN_USE) { /* If bound */
|
||||
if (bacnet_address_same(&pMatch->address, src)) {
|
||||
if (device_id) {
|
||||
*device_id = pMatch->device_id;
|
||||
@@ -391,48 +397,49 @@ void address_add(
|
||||
{
|
||||
bool found = false; /* return value */
|
||||
struct Address_Cache_Entry *pMatch;
|
||||
|
||||
|
||||
/* Note: Previously this function would ignore bind request
|
||||
marked entries and in fact would probably overwrite the first
|
||||
bind request entry blindly with the device info which may
|
||||
have nothing to do with that bind request. Now it honours the
|
||||
bind request if it exists */
|
||||
|
||||
|
||||
/* existing device or bind request outstanding - update address */
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) && (pMatch->device_id == device_id)) {
|
||||
pMatch->address = *src;
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) &&
|
||||
(pMatch->device_id == device_id)) {
|
||||
pMatch->address = *src;
|
||||
pMatch->max_apdu = max_apdu;
|
||||
|
||||
|
||||
/* Pick the right time to live */
|
||||
|
||||
if((pMatch->Flags & BAC_ADDR_BIND_REQ) != 0) /* Bind requested so long time */
|
||||
|
||||
if ((pMatch->Flags & BAC_ADDR_BIND_REQ) != 0) /* Bind requested so long time */
|
||||
pMatch->TimeToLive = BAC_ADDR_LONG_TIME;
|
||||
else if((pMatch->Flags & BAC_ADDR_STATIC) != 0) /* Static already so make sure it never expires */
|
||||
else if ((pMatch->Flags & BAC_ADDR_STATIC) != 0) /* Static already so make sure it never expires */
|
||||
pMatch->TimeToLive = BAC_ADDR_FOREVER;
|
||||
else if((pMatch->Flags & BAC_ADDR_SHORT_TTL) != 0) /* Opportunistic entry so leave on short fuse */
|
||||
else if ((pMatch->Flags & BAC_ADDR_SHORT_TTL) != 0) /* Opportunistic entry so leave on short fuse */
|
||||
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME;
|
||||
else
|
||||
pMatch->TimeToLive = BAC_ADDR_LONG_TIME; /* Renewing existing entry */
|
||||
|
||||
pMatch->Flags &= ~BAC_ADDR_BIND_REQ; /* Clear bind request flag just in case */
|
||||
pMatch->TimeToLive = BAC_ADDR_LONG_TIME; /* Renewing existing entry */
|
||||
|
||||
pMatch->Flags &= ~BAC_ADDR_BIND_REQ; /* Clear bind request flag just in case */
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
pMatch++;
|
||||
}
|
||||
|
||||
|
||||
/* new device - add to cache if there is room */
|
||||
if (!found) {
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if ((pMatch->Flags & BAC_ADDR_IN_USE) == 0) {
|
||||
pMatch->Flags = BAC_ADDR_IN_USE;
|
||||
pMatch->device_id = device_id;
|
||||
pMatch->max_apdu = max_apdu;
|
||||
pMatch->address = *src;
|
||||
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; /* Opportunistic entry so leave on short fuse */
|
||||
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; /* Opportunistic entry so leave on short fuse */
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@@ -443,14 +450,14 @@ void address_add(
|
||||
/* See if we can squeeze it in */
|
||||
if (!found) {
|
||||
pMatch = address_remove_oldest();
|
||||
if(pMatch != NULL) {
|
||||
if (pMatch != NULL) {
|
||||
pMatch->Flags = BAC_ADDR_IN_USE;
|
||||
pMatch->device_id = device_id;
|
||||
pMatch->max_apdu = max_apdu;
|
||||
pMatch->address = *src;
|
||||
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; /* Opportunistic entry so leave on short fuse */
|
||||
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; /* Opportunistic entry so leave on short fuse */
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -466,43 +473,44 @@ bool address_bind_request(
|
||||
|
||||
/* existing device - update address info if currently bound */
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) && (pMatch->device_id == device_id)) {
|
||||
if((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { /* Already bound */
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) &&
|
||||
(pMatch->device_id == device_id)) {
|
||||
if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { /* Already bound */
|
||||
found = true;
|
||||
*src = pMatch->address;
|
||||
*max_apdu = pMatch->max_apdu;
|
||||
if((pMatch->Flags & BAC_ADDR_SHORT_TTL) != 0) { /* Was picked up opportunistacilly */
|
||||
if ((pMatch->Flags & BAC_ADDR_SHORT_TTL) != 0) { /* Was picked up opportunistacilly */
|
||||
pMatch->Flags &= ~BAC_ADDR_SHORT_TTL; /* Convert to normal entry */
|
||||
pMatch->TimeToLive = BAC_ADDR_LONG_TIME; /* And give it a decent time to live */
|
||||
}
|
||||
}
|
||||
return(found); /* True if bound, false if bind request outstanding */
|
||||
return (found); /* True if bound, false if bind request outstanding */
|
||||
}
|
||||
pMatch++;
|
||||
}
|
||||
|
||||
/* Not there already so look for a free entry to put it in */
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE |BAC_ADDR_RESERVED)) == 0) {
|
||||
pMatch->Flags = BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ; /* In use and awaiting binding */
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_RESERVED)) == 0) {
|
||||
pMatch->Flags = BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ; /* In use and awaiting binding */
|
||||
pMatch->device_id = device_id;
|
||||
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; /* No point in leaving bind requests in for long haul */
|
||||
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; /* No point in leaving bind requests in for long haul */
|
||||
/* now would be a good time to do a Who-Is request */
|
||||
return(false);
|
||||
return (false);
|
||||
}
|
||||
pMatch++;
|
||||
}
|
||||
|
||||
/* No free entries, See if we can squeeze it in by dropping an existing one */
|
||||
pMatch = address_remove_oldest();
|
||||
if(pMatch != NULL) {
|
||||
if (pMatch != NULL) {
|
||||
pMatch->Flags = BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ;
|
||||
pMatch->device_id = device_id;
|
||||
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; /* No point in leaving bind requests in for long haul */
|
||||
pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; /* No point in leaving bind requests in for long haul */
|
||||
}
|
||||
return(false);
|
||||
return (false);
|
||||
}
|
||||
|
||||
|
||||
@@ -515,13 +523,14 @@ void address_add_binding(
|
||||
|
||||
/* existing device or bind request - update address */
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) && (pMatch->device_id == device_id)) {
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) &&
|
||||
(pMatch->device_id == device_id)) {
|
||||
pMatch->address = *src;
|
||||
pMatch->max_apdu = max_apdu;
|
||||
pMatch->Flags &= ~BAC_ADDR_BIND_REQ; /* Clear bind request flag in case it was set */
|
||||
if((pMatch->Flags & BAC_ADDR_STATIC) == 0) /* Only update TTL if not static */
|
||||
pMatch->TimeToLive = BAC_ADDR_LONG_TIME; /* and set it on a long fuse */
|
||||
pMatch->Flags &= ~BAC_ADDR_BIND_REQ; /* Clear bind request flag in case it was set */
|
||||
if ((pMatch->Flags & BAC_ADDR_STATIC) == 0) /* Only update TTL if not static */
|
||||
pMatch->TimeToLive = BAC_ADDR_LONG_TIME; /* and set it on a long fuse */
|
||||
break;
|
||||
}
|
||||
pMatch++;
|
||||
@@ -540,7 +549,8 @@ bool address_get_by_index(
|
||||
|
||||
if (index < MAX_ADDRESS_CACHE) {
|
||||
pMatch = &Address_Cache[index];
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == BAC_ADDR_IN_USE) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) ==
|
||||
BAC_ADDR_IN_USE) {
|
||||
*src = pMatch->address;
|
||||
*device_id = pMatch->device_id;
|
||||
*max_apdu = pMatch->max_apdu;
|
||||
@@ -558,10 +568,10 @@ unsigned address_count(
|
||||
unsigned count = 0; /* return value */
|
||||
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == BAC_ADDR_IN_USE) /* Only count bound entries */
|
||||
count++;
|
||||
|
||||
|
||||
pMatch++;
|
||||
}
|
||||
|
||||
@@ -576,37 +586,43 @@ unsigned address_count(
|
||||
int address_list_encode(
|
||||
uint8_t * apdu,
|
||||
unsigned apdu_len)
|
||||
|
||||
{
|
||||
int iLen = 0;
|
||||
struct Address_Cache_Entry *pMatch;
|
||||
struct Address_Cache_Entry *pMatch;
|
||||
BACNET_OCTET_STRING MAC_Address;
|
||||
|
||||
|
||||
/* FIXME: I really shouild check the length remaining here but it is
|
||||
fairly pointless until we have the true length remaining in
|
||||
the packet to work with as at the moment it is just MAX_APDU */
|
||||
|
||||
fairly pointless until we have the true length remaining in
|
||||
the packet to work with as at the moment it is just MAX_APDU */
|
||||
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == BAC_ADDR_IN_USE) {
|
||||
iLen += encode_application_object_id(&apdu[iLen], OBJECT_DEVICE, pMatch->device_id);
|
||||
iLen += encode_application_unsigned(&apdu[iLen], pMatch->address.net);
|
||||
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) ==
|
||||
BAC_ADDR_IN_USE) {
|
||||
iLen +=
|
||||
encode_application_object_id(&apdu[iLen], OBJECT_DEVICE,
|
||||
pMatch->device_id);
|
||||
iLen +=
|
||||
encode_application_unsigned(&apdu[iLen], pMatch->address.net);
|
||||
|
||||
/* pick the appropriate type of entry from the cache */
|
||||
|
||||
if(pMatch->address.len != 0) {
|
||||
octetstring_init(&MAC_Address, pMatch->address.adr, pMatch->address.len);
|
||||
iLen += encode_application_octet_string(&apdu[iLen], &MAC_Address);
|
||||
}
|
||||
else {
|
||||
octetstring_init(&MAC_Address, pMatch->address.mac, pMatch->address.mac_len);
|
||||
iLen += encode_application_octet_string(&apdu[iLen], &MAC_Address);
|
||||
|
||||
if (pMatch->address.len != 0) {
|
||||
octetstring_init(&MAC_Address, pMatch->address.adr,
|
||||
pMatch->address.len);
|
||||
iLen +=
|
||||
encode_application_octet_string(&apdu[iLen], &MAC_Address);
|
||||
} else {
|
||||
octetstring_init(&MAC_Address, pMatch->address.mac,
|
||||
pMatch->address.mac_len);
|
||||
iLen +=
|
||||
encode_application_octet_string(&apdu[iLen], &MAC_Address);
|
||||
}
|
||||
}
|
||||
pMatch++;
|
||||
}
|
||||
|
||||
return(iLen);
|
||||
return (iLen);
|
||||
}
|
||||
|
||||
|
||||
@@ -618,20 +634,20 @@ return(iLen);
|
||||
****************************************************************************/
|
||||
|
||||
void address_cache_timer(
|
||||
uint16_t uSeconds) /* Approximate number of seconds since last call to this function */
|
||||
{
|
||||
uint16_t uSeconds)
|
||||
{ /* Approximate number of seconds since last call to this function */
|
||||
struct Address_Cache_Entry *pMatch;
|
||||
|
||||
pMatch = Address_Cache;
|
||||
while(pMatch <= &Address_Cache[MAX_ADDRESS_CACHE-1] ) {
|
||||
if (((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_RESERVED)) != 0)
|
||||
&& ((pMatch->Flags & BAC_ADDR_STATIC) != 0)) { /* Check all entries holding a slot except statics */
|
||||
if(pMatch->TimeToLive >= uSeconds)
|
||||
while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) {
|
||||
if (((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_RESERVED)) != 0)
|
||||
&& ((pMatch->Flags & BAC_ADDR_STATIC) != 0)) { /* Check all entries holding a slot except statics */
|
||||
if (pMatch->TimeToLive >= uSeconds)
|
||||
pMatch->TimeToLive -= uSeconds;
|
||||
else
|
||||
pMatch->Flags = 0;
|
||||
}
|
||||
|
||||
pMatch->Flags = 0;
|
||||
}
|
||||
|
||||
pMatch++;
|
||||
}
|
||||
}
|
||||
|
||||
+24
-24
@@ -454,32 +454,32 @@ void apdu_handler(
|
||||
service_choice = apdu[2];
|
||||
len = 3;
|
||||
|
||||
/* FIXME: Currently special case for C_P_T but there are others which may
|
||||
need consideration such as ChangeList-Error, CreateObject-Error,
|
||||
WritePropertyMultiple-Error and VTClose_Error but they may be left as
|
||||
is for now until support for these services is added */
|
||||
/* FIXME: Currently special case for C_P_T but there are others which may
|
||||
need consideration such as ChangeList-Error, CreateObject-Error,
|
||||
WritePropertyMultiple-Error and VTClose_Error but they may be left as
|
||||
is for now until support for these services is added */
|
||||
|
||||
if(service_choice == SERVICE_CONFIRMED_PRIVATE_TRANSFER) { /* skip over opening tag 0 */
|
||||
if (decode_is_opening_tag_number(&apdu[len], 0)) {
|
||||
len++; /* a tag number of 0 is not extended so only one octet */
|
||||
}
|
||||
}
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
/* FIXME: we could validate that the tag is enumerated... */
|
||||
len += decode_enumerated(&apdu[len], len_value, &error_class);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
/* FIXME: we could validate that the tag is enumerated... */
|
||||
len += decode_enumerated(&apdu[len], len_value, &error_code);
|
||||
if (service_choice == SERVICE_CONFIRMED_PRIVATE_TRANSFER) { /* skip over opening tag 0 */
|
||||
if (decode_is_opening_tag_number(&apdu[len], 0)) {
|
||||
len++; /* a tag number of 0 is not extended so only one octet */
|
||||
}
|
||||
}
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
/* FIXME: we could validate that the tag is enumerated... */
|
||||
len += decode_enumerated(&apdu[len], len_value, &error_class);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
/* FIXME: we could validate that the tag is enumerated... */
|
||||
len += decode_enumerated(&apdu[len], len_value, &error_code);
|
||||
|
||||
if(service_choice == SERVICE_CONFIRMED_PRIVATE_TRANSFER) { /* skip over closing tag 0 */
|
||||
if (decode_is_closing_tag_number(&apdu[len], 0)) {
|
||||
len++; /* a tag number of 0 is not extended so only one octet */
|
||||
}
|
||||
}
|
||||
if (service_choice == SERVICE_CONFIRMED_PRIVATE_TRANSFER) { /* skip over closing tag 0 */
|
||||
if (decode_is_closing_tag_number(&apdu[len], 0)) {
|
||||
len++; /* a tag number of 0 is not extended so only one octet */
|
||||
}
|
||||
}
|
||||
if (service_choice < MAX_BACNET_CONFIRMED_SERVICE) {
|
||||
if (Error_Function[service_choice])
|
||||
Error_Function[service_choice] (src, invoke_id,
|
||||
|
||||
+182
-183
@@ -185,12 +185,16 @@ int bacapp_decode_data(
|
||||
#endif
|
||||
#if defined (BACAPP_REAL)
|
||||
case BACNET_APPLICATION_TAG_REAL:
|
||||
len = decode_real_safe(&apdu[0], len_value_type, &(value->type.Real));
|
||||
len =
|
||||
decode_real_safe(&apdu[0], len_value_type,
|
||||
&(value->type.Real));
|
||||
break;
|
||||
#endif
|
||||
#if defined (BACAPP_DOUBLE)
|
||||
case BACNET_APPLICATION_TAG_DOUBLE:
|
||||
len = decode_double_safe(&apdu[0], len_value_type, &(value->type.Double));
|
||||
len =
|
||||
decode_double_safe(&apdu[0], len_value_type,
|
||||
&(value->type.Double));
|
||||
break;
|
||||
#endif
|
||||
#if defined (BACAPP_OCTET_STRING)
|
||||
@@ -223,12 +227,16 @@ int bacapp_decode_data(
|
||||
#endif
|
||||
#if defined (BACAPP_DATE)
|
||||
case BACNET_APPLICATION_TAG_DATE:
|
||||
len = decode_date_safe(&apdu[0], len_value_type, &value->type.Date);
|
||||
len =
|
||||
decode_date_safe(&apdu[0], len_value_type,
|
||||
&value->type.Date);
|
||||
break;
|
||||
#endif
|
||||
#if defined (BACAPP_TIME)
|
||||
case BACNET_APPLICATION_TAG_TIME:
|
||||
len = decode_bacnet_time_safe(&apdu[0], len_value_type, &value->type.Time);
|
||||
len =
|
||||
decode_bacnet_time_safe(&apdu[0], len_value_type,
|
||||
&value->type.Time);
|
||||
break;
|
||||
#endif
|
||||
#if defined (BACAPP_OBJECT_ID)
|
||||
@@ -236,7 +244,9 @@ int bacapp_decode_data(
|
||||
{
|
||||
uint16_t object_type = 0;
|
||||
uint32_t instance = 0;
|
||||
len = decode_object_id_safe(&apdu[0], len_value_type, &object_type, &instance);
|
||||
len =
|
||||
decode_object_id_safe(&apdu[0], len_value_type,
|
||||
&object_type, &instance);
|
||||
value->type.Object_Id.type = object_type;
|
||||
value->type.Object_Id.instance = instance;
|
||||
}
|
||||
@@ -247,10 +257,10 @@ int bacapp_decode_data(
|
||||
}
|
||||
}
|
||||
|
||||
if ( len == 0 && tag_data_type != BACNET_APPLICATION_TAG_NULL && tag_data_type != BACNET_APPLICATION_TAG_BOOLEAN )
|
||||
{
|
||||
value->tag = MAX_BACNET_APPLICATION_TAG;
|
||||
}
|
||||
if (len == 0 && tag_data_type != BACNET_APPLICATION_TAG_NULL &&
|
||||
tag_data_type != BACNET_APPLICATION_TAG_BOOLEAN) {
|
||||
value->tag = MAX_BACNET_APPLICATION_TAG;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
@@ -298,50 +308,50 @@ int bacapp_decode_application_data(
|
||||
*/
|
||||
|
||||
bool bacapp_decode_application_data_safe(
|
||||
uint8_t * new_apdu,
|
||||
uint32_t new_apdu_len,
|
||||
uint8_t * new_apdu,
|
||||
uint32_t new_apdu_len,
|
||||
BACNET_APPLICATION_DATA_VALUE * value)
|
||||
{
|
||||
/* The static variables that store the apdu buffer between function calls */
|
||||
static uint8_t * apdu = NULL;
|
||||
static int32_t apdu_len_remaining = 0;
|
||||
static uint32_t apdu_len = 0;
|
||||
/* The static variables that store the apdu buffer between function calls */
|
||||
static uint8_t *apdu = NULL;
|
||||
static int32_t apdu_len_remaining = 0;
|
||||
static uint32_t apdu_len = 0;
|
||||
int len = 0;
|
||||
int tag_len = 0;
|
||||
uint8_t tag_number = 0;
|
||||
uint32_t len_value_type = 0;
|
||||
|
||||
bool ret = false;
|
||||
bool ret = false;
|
||||
|
||||
if ( new_apdu != NULL )
|
||||
{
|
||||
apdu = new_apdu;
|
||||
apdu_len_remaining = new_apdu_len;
|
||||
apdu_len = 0;
|
||||
}
|
||||
if (new_apdu != NULL) {
|
||||
apdu = new_apdu;
|
||||
apdu_len_remaining = new_apdu_len;
|
||||
apdu_len = 0;
|
||||
}
|
||||
|
||||
if (value && apdu_len_remaining > 0 && !IS_CONTEXT_SPECIFIC(apdu[apdu_len]) ) {
|
||||
if (value && apdu_len_remaining > 0 &&
|
||||
!IS_CONTEXT_SPECIFIC(apdu[apdu_len])) {
|
||||
value->context_specific = false;
|
||||
tag_len =
|
||||
decode_tag_number_and_value_safe(&apdu[apdu_len], apdu_len_remaining, &tag_number,
|
||||
&len_value_type);
|
||||
/* If tag_len is zero, then the tag information is truncated */
|
||||
decode_tag_number_and_value_safe(&apdu[apdu_len],
|
||||
apdu_len_remaining, &tag_number, &len_value_type);
|
||||
/* If tag_len is zero, then the tag information is truncated */
|
||||
if (tag_len) {
|
||||
apdu_len += tag_len;
|
||||
apdu_len_remaining -= tag_len;
|
||||
/* The tag is boolean then len_value_type is interpreted as value, not length, so dont bother
|
||||
** checking with apdu_len_remaining */
|
||||
if ( tag_number == BACNET_APPLICATION_TAG_BOOLEAN || len_value_type <= apdu_len_remaining )
|
||||
{
|
||||
value->tag = tag_number;
|
||||
len =
|
||||
bacapp_decode_data(&apdu[apdu_len], tag_number, len_value_type,
|
||||
value);
|
||||
apdu_len += len;
|
||||
apdu_len_remaining -= len;
|
||||
apdu_len += tag_len;
|
||||
apdu_len_remaining -= tag_len;
|
||||
/* The tag is boolean then len_value_type is interpreted as value, not length, so dont bother
|
||||
** checking with apdu_len_remaining */
|
||||
if (tag_number == BACNET_APPLICATION_TAG_BOOLEAN ||
|
||||
len_value_type <= apdu_len_remaining) {
|
||||
value->tag = tag_number;
|
||||
len =
|
||||
bacapp_decode_data(&apdu[apdu_len], tag_number,
|
||||
len_value_type, value);
|
||||
apdu_len += len;
|
||||
apdu_len_remaining -= len;
|
||||
|
||||
ret = true;
|
||||
}
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
value->next = NULL;
|
||||
}
|
||||
@@ -349,7 +359,7 @@ bool bacapp_decode_application_data_safe(
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int bacapp_encode_context_data_value(
|
||||
uint8_t * apdu,
|
||||
@@ -849,13 +859,13 @@ bool bacapp_print_value(
|
||||
case PROP_OBJECT_TYPE:
|
||||
if (value->type.Enumerated < MAX_ASHRAE_OBJECT_TYPE) {
|
||||
fprintf(stream, "%s",
|
||||
bactext_object_type_name(
|
||||
value->type.Enumerated));
|
||||
bactext_object_type_name(value->type.
|
||||
Enumerated));
|
||||
} else if (value->type.Enumerated < 128) {
|
||||
fprintf(stream, "reserved %u",
|
||||
fprintf(stream, "reserved %u",
|
||||
value->type.Enumerated);
|
||||
} else {
|
||||
fprintf(stream, "proprietary %u",
|
||||
fprintf(stream, "proprietary %u",
|
||||
value->type.Enumerated);
|
||||
}
|
||||
break;
|
||||
@@ -866,17 +876,17 @@ bool bacapp_print_value(
|
||||
case PROP_UNITS:
|
||||
if (value->type.Enumerated < 256) {
|
||||
fprintf(stream, "%s",
|
||||
bactext_engineering_unit_name(value->type.
|
||||
Enumerated));
|
||||
bactext_engineering_unit_name(value->
|
||||
type.Enumerated));
|
||||
} else {
|
||||
fprintf(stream, "proprietary %u",value->type.
|
||||
Enumerated);
|
||||
fprintf(stream, "proprietary %u",
|
||||
value->type.Enumerated);
|
||||
}
|
||||
break;
|
||||
case PROP_PRESENT_VALUE:
|
||||
fprintf(stream, "%s",
|
||||
bactext_binary_present_value_name(value->type.
|
||||
Enumerated));
|
||||
bactext_binary_present_value_name(value->
|
||||
type.Enumerated));
|
||||
break;
|
||||
case PROP_RELIABILITY:
|
||||
fprintf(stream, "%s",
|
||||
@@ -884,8 +894,8 @@ bool bacapp_print_value(
|
||||
break;
|
||||
case PROP_SYSTEM_STATUS:
|
||||
fprintf(stream, "%s",
|
||||
bactext_device_status_name(value->type.
|
||||
Enumerated));
|
||||
bactext_device_status_name(value->
|
||||
type.Enumerated));
|
||||
break;
|
||||
case PROP_SEGMENTATION_SUPPORTED:
|
||||
fprintf(stream, "%s",
|
||||
@@ -944,7 +954,7 @@ bool bacapp_print_value(
|
||||
value->type.Object_Id.type,
|
||||
value->type.Object_Id.instance);
|
||||
} else {
|
||||
fprintf(stream, "(proprietary %u, %u)",
|
||||
fprintf(stream, "(proprietary %u, %u)",
|
||||
value->type.Object_Id.type,
|
||||
value->type.Object_Id.instance);
|
||||
}
|
||||
@@ -1187,10 +1197,10 @@ bool bacapp_same_value(
|
||||
#endif
|
||||
#if defined (BACAPP_BIT_STRING)
|
||||
case BACNET_APPLICATION_TAG_BIT_STRING:
|
||||
status =
|
||||
bitstring_same(&value->type.Bit_String,
|
||||
&test_value->type.Bit_String);
|
||||
break;
|
||||
status =
|
||||
bitstring_same(&value->type.Bit_String,
|
||||
&test_value->type.Bit_String);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
@@ -1204,146 +1214,135 @@ bool bacapp_same_value(
|
||||
void testBACnetApplicationData_Safe(
|
||||
Test * pTest)
|
||||
{
|
||||
int i;
|
||||
uint8_t apdu[MAX_APDU];
|
||||
int len = 0;
|
||||
int apdu_len;
|
||||
int i;
|
||||
uint8_t apdu[MAX_APDU];
|
||||
int len = 0;
|
||||
int apdu_len;
|
||||
BACNET_APPLICATION_DATA_VALUE input_value[13];
|
||||
uint32_t len_segment[13];
|
||||
uint32_t single_length_segment;
|
||||
uint32_t len_segment[13];
|
||||
uint32_t single_length_segment;
|
||||
BACNET_APPLICATION_DATA_VALUE value;
|
||||
|
||||
|
||||
for ( i = 0;i < 13; i++)
|
||||
{
|
||||
input_value[i].tag = (BACNET_APPLICATION_TAG)i;
|
||||
input_value[i].context_specific = 0;
|
||||
input_value[i].context_tag = 0;
|
||||
input_value[i].next = NULL;
|
||||
switch(input_value[i].tag)
|
||||
{
|
||||
case BACNET_APPLICATION_TAG_NULL:
|
||||
/* NULL: no data */
|
||||
break;
|
||||
|
||||
case BACNET_APPLICATION_TAG_BOOLEAN:
|
||||
input_value[i].type.Boolean = true;
|
||||
break;
|
||||
|
||||
case BACNET_APPLICATION_TAG_UNSIGNED_INT:
|
||||
input_value[i].type.Unsigned_Int = 0xDEADBEEF;
|
||||
break;
|
||||
for (i = 0; i < 13; i++) {
|
||||
input_value[i].tag = (BACNET_APPLICATION_TAG) i;
|
||||
input_value[i].context_specific = 0;
|
||||
input_value[i].context_tag = 0;
|
||||
input_value[i].next = NULL;
|
||||
switch (input_value[i].tag) {
|
||||
case BACNET_APPLICATION_TAG_NULL:
|
||||
/* NULL: no data */
|
||||
break;
|
||||
|
||||
case BACNET_APPLICATION_TAG_SIGNED_INT:
|
||||
input_value[i].type.Signed_Int = 0x00C0FFEE;
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_REAL:
|
||||
input_value[i].type.Real = 3.141592654f;
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_DOUBLE:
|
||||
input_value[i].type.Double = 2.32323232323;
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_BOOLEAN:
|
||||
input_value[i].type.Boolean = true;
|
||||
break;
|
||||
|
||||
case BACNET_APPLICATION_TAG_OCTET_STRING:
|
||||
octetstring_init(&input_value[i].type.Octet_String, "This is a o-string", strlen("This is a o-string"));
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_UNSIGNED_INT:
|
||||
input_value[i].type.Unsigned_Int = 0xDEADBEEF;
|
||||
break;
|
||||
|
||||
case BACNET_APPLICATION_TAG_CHARACTER_STRING:
|
||||
characterstring_init_ansi(&input_value[i].type.Character_String, "Hello There!");
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_SIGNED_INT:
|
||||
input_value[i].type.Signed_Int = 0x00C0FFEE;
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_REAL:
|
||||
input_value[i].type.Real = 3.141592654f;
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_DOUBLE:
|
||||
input_value[i].type.Double = 2.32323232323;
|
||||
break;
|
||||
|
||||
case BACNET_APPLICATION_TAG_BIT_STRING:
|
||||
bitstring_init(&input_value[i].type.Bit_String);
|
||||
bitstring_set_bit(&input_value[i].type.Bit_String, 0, true);
|
||||
bitstring_set_bit(&input_value[i].type.Bit_String, 1, false);
|
||||
bitstring_set_bit(&input_value[i].type.Bit_String, 2, false);
|
||||
bitstring_set_bit(&input_value[i].type.Bit_String, 3, true);
|
||||
bitstring_set_bit(&input_value[i].type.Bit_String, 4, false);
|
||||
bitstring_set_bit(&input_value[i].type.Bit_String, 5, true);
|
||||
bitstring_set_bit(&input_value[i].type.Bit_String, 6, true);
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_OCTET_STRING:
|
||||
octetstring_init(&input_value[i].type.Octet_String,
|
||||
"This is a o-string", strlen("This is a o-string"));
|
||||
break;
|
||||
|
||||
case BACNET_APPLICATION_TAG_ENUMERATED:
|
||||
input_value[i].type.Enumerated = 0x0BADF00D;
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_CHARACTER_STRING:
|
||||
characterstring_init_ansi(&input_value[i].type.
|
||||
Character_String, "Hello There!");
|
||||
break;
|
||||
|
||||
case BACNET_APPLICATION_TAG_DATE:
|
||||
input_value[i].type.Date.day = 10;
|
||||
input_value[i].type.Date.month = 9;
|
||||
input_value[i].type.Date.wday = 3;
|
||||
input_value[i].type.Date.year = 1998;
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_BIT_STRING:
|
||||
bitstring_init(&input_value[i].type.Bit_String);
|
||||
bitstring_set_bit(&input_value[i].type.Bit_String, 0, true);
|
||||
bitstring_set_bit(&input_value[i].type.Bit_String, 1, false);
|
||||
bitstring_set_bit(&input_value[i].type.Bit_String, 2, false);
|
||||
bitstring_set_bit(&input_value[i].type.Bit_String, 3, true);
|
||||
bitstring_set_bit(&input_value[i].type.Bit_String, 4, false);
|
||||
bitstring_set_bit(&input_value[i].type.Bit_String, 5, true);
|
||||
bitstring_set_bit(&input_value[i].type.Bit_String, 6, true);
|
||||
break;
|
||||
|
||||
case BACNET_APPLICATION_TAG_TIME:
|
||||
input_value[i].type.Time.hour = 12;
|
||||
input_value[i].type.Time.hundredths = 56;
|
||||
input_value[i].type.Time.min = 20;
|
||||
input_value[i].type.Time.sec = 41;
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_ENUMERATED:
|
||||
input_value[i].type.Enumerated = 0x0BADF00D;
|
||||
break;
|
||||
|
||||
case BACNET_APPLICATION_TAG_OBJECT_ID:
|
||||
input_value[i].type.Object_Id.instance = 1234;
|
||||
input_value[i].type.Object_Id.type = 12;
|
||||
break;
|
||||
case BACNET_APPLICATION_TAG_DATE:
|
||||
input_value[i].type.Date.day = 10;
|
||||
input_value[i].type.Date.month = 9;
|
||||
input_value[i].type.Date.wday = 3;
|
||||
input_value[i].type.Date.year = 1998;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
single_length_segment = bacapp_encode_data(&apdu[len], &input_value[i]);;
|
||||
assert(single_length_segment > 0);
|
||||
/* len_segment is accumulated length */
|
||||
if ( i == 0 )
|
||||
{
|
||||
len_segment[i] = single_length_segment;
|
||||
}
|
||||
else
|
||||
{
|
||||
len_segment[i] = single_length_segment + len_segment[i-1];
|
||||
}
|
||||
len = len_segment[i];
|
||||
}
|
||||
/*
|
||||
** Start processing packets at processivly truncated lengths
|
||||
*/
|
||||
case BACNET_APPLICATION_TAG_TIME:
|
||||
input_value[i].type.Time.hour = 12;
|
||||
input_value[i].type.Time.hundredths = 56;
|
||||
input_value[i].type.Time.min = 20;
|
||||
input_value[i].type.Time.sec = 41;
|
||||
break;
|
||||
|
||||
for ( apdu_len = len; apdu_len >=0; apdu_len--)
|
||||
{
|
||||
bool status;
|
||||
bool expected_status;
|
||||
for ( i = 0;i < 14; i++)
|
||||
{
|
||||
if ( i == 13 )
|
||||
{
|
||||
expected_status = false;
|
||||
}
|
||||
else{
|
||||
case BACNET_APPLICATION_TAG_OBJECT_ID:
|
||||
input_value[i].type.Object_Id.instance = 1234;
|
||||
input_value[i].type.Object_Id.type = 12;
|
||||
break;
|
||||
|
||||
if ( apdu_len < len_segment[i] )
|
||||
{
|
||||
expected_status = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
expected_status = true;
|
||||
}
|
||||
}
|
||||
status = bacapp_decode_application_data_safe(i == 0?apdu:NULL, apdu_len, &value);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
single_length_segment =
|
||||
bacapp_encode_data(&apdu[len], &input_value[i]);;
|
||||
assert(single_length_segment > 0);
|
||||
/* len_segment is accumulated length */
|
||||
if (i == 0) {
|
||||
len_segment[i] = single_length_segment;
|
||||
} else {
|
||||
len_segment[i] = single_length_segment + len_segment[i - 1];
|
||||
}
|
||||
len = len_segment[i];
|
||||
}
|
||||
/*
|
||||
** Start processing packets at processivly truncated lengths
|
||||
*/
|
||||
|
||||
ct_test(pTest, status == expected_status);
|
||||
if ( status )
|
||||
{
|
||||
ct_test(pTest, value.tag == i);
|
||||
ct_test(pTest,
|
||||
bacapp_same_value(&input_value[i], &value));
|
||||
ct_test(pTest, !value.context_specific);
|
||||
ct_test(pTest, value.next == NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (apdu_len = len; apdu_len >= 0; apdu_len--) {
|
||||
bool status;
|
||||
bool expected_status;
|
||||
for (i = 0; i < 14; i++) {
|
||||
if (i == 13) {
|
||||
expected_status = false;
|
||||
} else {
|
||||
|
||||
if (apdu_len < len_segment[i]) {
|
||||
expected_status = false;
|
||||
} else {
|
||||
expected_status = true;
|
||||
}
|
||||
}
|
||||
status =
|
||||
bacapp_decode_application_data_safe(i == 0 ? apdu : NULL,
|
||||
apdu_len, &value);
|
||||
|
||||
ct_test(pTest, status == expected_status);
|
||||
if (status) {
|
||||
ct_test(pTest, value.tag == i);
|
||||
ct_test(pTest, bacapp_same_value(&input_value[i], &value));
|
||||
ct_test(pTest, !value.context_specific);
|
||||
ct_test(pTest, value.next == NULL);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1727,7 +1726,7 @@ int main(
|
||||
rc = ct_addTestFunction(pTest, testBACnetApplicationData_Safe);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void) ct_report(pTest);
|
||||
ct_destroy(pTest);
|
||||
|
||||
+68
-69
@@ -325,13 +325,13 @@ int decode_tag_number(
|
||||
/* Same as function above, but will safely fail is packet has been truncated */
|
||||
int decode_tag_number_safe(
|
||||
uint8_t * apdu,
|
||||
uint32_t apdu_len_remaining,
|
||||
uint32_t apdu_len_remaining,
|
||||
uint8_t * tag_number)
|
||||
{
|
||||
int len = 0; /* return value */
|
||||
|
||||
/* decode the tag number first */
|
||||
if ( apdu_len_remaining >= 1 ) {
|
||||
if (apdu_len_remaining >= 1) {
|
||||
if (IS_EXTENDED_TAG_NUMBER(apdu[0]) && apdu_len_remaining >= 2) {
|
||||
/* extended tag */
|
||||
if (tag_number) {
|
||||
@@ -414,16 +414,16 @@ int decode_tag_number_and_value(
|
||||
|
||||
/* Same as function above, but will safely fail is packet has been truncated */
|
||||
int decode_tag_number_and_value_safe(
|
||||
uint8_t * apdu,
|
||||
uint32_t apdu_len_remaining,
|
||||
uint8_t * tag_number,
|
||||
uint32_t * value)
|
||||
uint8_t * apdu,
|
||||
uint32_t apdu_len_remaining,
|
||||
uint8_t * tag_number,
|
||||
uint32_t * value)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
len = decode_tag_number_safe(&apdu[0], apdu_len_remaining, tag_number);
|
||||
|
||||
if ( len > 0 ) {
|
||||
if (len > 0) {
|
||||
apdu_len_remaining -= len;
|
||||
if (IS_EXTENDED_VALUE(apdu[0])) {
|
||||
/* tagged as uint32_t */
|
||||
@@ -450,8 +450,7 @@ int decode_tag_number_and_value_safe(
|
||||
*value = apdu[len];
|
||||
}
|
||||
len++;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* packet is truncated */
|
||||
len = 0;
|
||||
}
|
||||
@@ -477,7 +476,8 @@ bool decode_is_context_tag(
|
||||
uint8_t my_tag_number = 0;
|
||||
|
||||
decode_tag_number(apdu, &my_tag_number);
|
||||
return (bool) (IS_CONTEXT_SPECIFIC(*apdu) && (my_tag_number == tag_number));
|
||||
return (bool) (IS_CONTEXT_SPECIFIC(*apdu) &&
|
||||
(my_tag_number == tag_number));
|
||||
}
|
||||
|
||||
bool decode_is_context_tag_with_length(
|
||||
@@ -489,7 +489,8 @@ bool decode_is_context_tag_with_length(
|
||||
|
||||
*tag_length = decode_tag_number(apdu, &my_tag_number);
|
||||
|
||||
return (bool) (IS_CONTEXT_SPECIFIC(*apdu) && (my_tag_number == tag_number));
|
||||
return (bool) (IS_CONTEXT_SPECIFIC(*apdu) &&
|
||||
(my_tag_number == tag_number));
|
||||
}
|
||||
|
||||
/* from clause 20.2.1.3.2 Constructed Data */
|
||||
@@ -788,10 +789,9 @@ int decode_object_id_safe(
|
||||
uint16_t * object_type,
|
||||
uint32_t * instance)
|
||||
{
|
||||
if ( len_value != 4 ) {
|
||||
if (len_value != 4) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return decode_object_id(apdu, object_type, instance);
|
||||
}
|
||||
}
|
||||
@@ -845,7 +845,7 @@ int encode_context_object_id(
|
||||
|
||||
/* length of object id is 4 octets, as per 20.2.14 */
|
||||
|
||||
len = encode_tag(&apdu[0], tag_number, true, 4);
|
||||
len = encode_tag(&apdu[0], tag_number, true, 4);
|
||||
len += encode_bacnet_object_id(&apdu[len], object_type, instance);
|
||||
|
||||
return len;
|
||||
@@ -1181,7 +1181,7 @@ int encode_context_unsigned(
|
||||
uint32_t value)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
|
||||
/* length of unsigned is variable, as per 20.2.4 */
|
||||
if (value < 0x100) {
|
||||
len = 1;
|
||||
@@ -1193,7 +1193,7 @@ int encode_context_unsigned(
|
||||
len = 4;
|
||||
}
|
||||
|
||||
len = encode_tag(&apdu[0], tag_number, true, len);
|
||||
len = encode_tag(&apdu[0], tag_number, true, len);
|
||||
len += encode_bacnet_unsigned(&apdu[len], value);
|
||||
|
||||
return len;
|
||||
@@ -1303,7 +1303,7 @@ int encode_context_enumerated(
|
||||
len = 4;
|
||||
}
|
||||
|
||||
len = encode_tag(&apdu[0], tag_number, true, (uint32_t) len);
|
||||
len = encode_tag(&apdu[0], tag_number, true, (uint32_t) len);
|
||||
len += encode_bacnet_enumerated(&apdu[len], value);
|
||||
|
||||
return len;
|
||||
@@ -1424,7 +1424,7 @@ int encode_context_signed(
|
||||
len = 4;
|
||||
}
|
||||
|
||||
len = encode_tag(&apdu[0], tag_number, true, (uint32_t) len);
|
||||
len = encode_tag(&apdu[0], tag_number, true, (uint32_t) len);
|
||||
len += encode_bacnet_signed(&apdu[len], value);
|
||||
|
||||
return len;
|
||||
@@ -1456,7 +1456,7 @@ int encode_context_real(
|
||||
int len = 0;
|
||||
|
||||
/* length of double is 4 octets, as per 20.2.6 */
|
||||
len = encode_tag(&apdu[0], tag_number, true, 4);
|
||||
len = encode_tag(&apdu[0], tag_number, true, 4);
|
||||
len += encode_bacnet_real(value, &apdu[len]);
|
||||
return len;
|
||||
}
|
||||
@@ -1488,7 +1488,7 @@ int encode_context_double(
|
||||
int len = 0;
|
||||
|
||||
/* length of double is 8 octets, as per 20.2.7 */
|
||||
len = encode_tag(&apdu[0], tag_number, true, 8);
|
||||
len = encode_tag(&apdu[0], tag_number, true, 8);
|
||||
len += encode_bacnet_double(value, &apdu[len]);
|
||||
|
||||
return len;
|
||||
@@ -1535,7 +1535,7 @@ int encode_context_time(
|
||||
int len = 0; /* return value */
|
||||
|
||||
/* length of time is 4 octets, as per 20.2.13 */
|
||||
len = encode_tag(&apdu[0], tag_number, true, 4);
|
||||
len = encode_tag(&apdu[0], tag_number, true, 4);
|
||||
len += encode_bacnet_time(&apdu[len], btime);
|
||||
|
||||
return len;
|
||||
@@ -1561,16 +1561,13 @@ int decode_bacnet_time_safe(
|
||||
uint32_t len_value,
|
||||
BACNET_TIME * btime)
|
||||
{
|
||||
if ( len_value != 4 )
|
||||
{
|
||||
if (len_value != 4) {
|
||||
btime->hour = 0;
|
||||
btime->hundredths = 0;
|
||||
btime->min = 0;
|
||||
btime->sec = 0;
|
||||
return len_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return decode_bacnet_time(apdu, btime);
|
||||
}
|
||||
}
|
||||
@@ -1671,7 +1668,7 @@ int encode_context_date(
|
||||
int len = 0; /* return value */
|
||||
|
||||
/* length of date is 4 octets, as per 20.2.12 */
|
||||
len = encode_tag(&apdu[0], tag_number, true, 4);
|
||||
len = encode_tag(&apdu[0], tag_number, true, 4);
|
||||
len += encode_bacnet_date(&apdu[len], bdate);
|
||||
|
||||
return len;
|
||||
@@ -1697,14 +1694,13 @@ int decode_date_safe(
|
||||
uint32_t len_value,
|
||||
BACNET_DATE * bdate)
|
||||
{
|
||||
if ( len_value != 4 ) {
|
||||
if (len_value != 4) {
|
||||
bdate->day = 0;
|
||||
bdate->month = 0;
|
||||
bdate->wday = 0;
|
||||
bdate->year = 0;
|
||||
return len_value;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return decode_date(apdu, bdate);
|
||||
}
|
||||
}
|
||||
@@ -1872,8 +1868,7 @@ void testBACDCodeTags(
|
||||
&test_value);
|
||||
ct_test(pTest, tag_number == test_tag_number);
|
||||
ct_test(pTest, value == test_value);
|
||||
test_len =
|
||||
get_apdu_len(IS_EXTENDED_TAG_NUMBER(apdu[0]), value);
|
||||
test_len = get_apdu_len(IS_EXTENDED_TAG_NUMBER(apdu[0]), value);
|
||||
ct_test(pTest, len == test_len);
|
||||
/* stop at the the last value */
|
||||
if (value & BIT31) {
|
||||
@@ -2396,9 +2391,9 @@ void testUnsignedContextDecodes(
|
||||
ct_test(pTest, in == out);
|
||||
ct_test(pTest, outLen2 == -1);
|
||||
|
||||
inLen = encode_context_unsigned(apdu, large_context_tag, in);
|
||||
outLen = decode_context_unsigned(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_unsigned(apdu, large_context_tag-1, &out);
|
||||
inLen = encode_context_unsigned(apdu, large_context_tag, in);
|
||||
outLen = decode_context_unsigned(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_unsigned(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2412,9 +2407,9 @@ void testUnsignedContextDecodes(
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
|
||||
inLen = encode_context_unsigned(apdu, large_context_tag, in);
|
||||
outLen = decode_context_unsigned(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_unsigned(apdu, large_context_tag-1, &out);
|
||||
inLen = encode_context_unsigned(apdu, large_context_tag, in);
|
||||
outLen = decode_context_unsigned(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_unsigned(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2427,9 +2422,9 @@ void testUnsignedContextDecodes(
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
|
||||
inLen = encode_context_unsigned(apdu, large_context_tag, in);
|
||||
outLen = decode_context_unsigned(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_unsigned(apdu, large_context_tag-1, &out);
|
||||
inLen = encode_context_unsigned(apdu, large_context_tag, in);
|
||||
outLen = decode_context_unsigned(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_unsigned(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2442,9 +2437,9 @@ void testUnsignedContextDecodes(
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
|
||||
inLen = encode_context_unsigned(apdu, large_context_tag, in);
|
||||
outLen = decode_context_unsigned(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_unsigned(apdu, large_context_tag-1, &out);
|
||||
inLen = encode_context_unsigned(apdu, large_context_tag, in);
|
||||
outLen = decode_context_unsigned(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_unsigned(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2457,9 +2452,9 @@ void testUnsignedContextDecodes(
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
|
||||
inLen = encode_context_unsigned(apdu, large_context_tag, in);
|
||||
outLen = decode_context_unsigned(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_unsigned(apdu, large_context_tag-1, &out);
|
||||
inLen = encode_context_unsigned(apdu, large_context_tag, in);
|
||||
outLen = decode_context_unsigned(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_unsigned(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2493,7 +2488,7 @@ void testSignedContextDecodes(
|
||||
|
||||
inLen = encode_context_signed(apdu, large_context_tag, in);
|
||||
outLen = decode_context_signed(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_signed(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_signed(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2509,7 +2504,7 @@ void testSignedContextDecodes(
|
||||
|
||||
inLen = encode_context_signed(apdu, large_context_tag, in);
|
||||
outLen = decode_context_signed(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_signed(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_signed(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2525,7 +2520,7 @@ void testSignedContextDecodes(
|
||||
|
||||
inLen = encode_context_signed(apdu, large_context_tag, in);
|
||||
outLen = decode_context_signed(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_signed(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_signed(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2541,7 +2536,7 @@ void testSignedContextDecodes(
|
||||
|
||||
inLen = encode_context_signed(apdu, large_context_tag, in);
|
||||
outLen = decode_context_signed(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_signed(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_signed(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2557,7 +2552,7 @@ void testSignedContextDecodes(
|
||||
|
||||
inLen = encode_context_signed(apdu, large_context_tag, in);
|
||||
outLen = decode_context_signed(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_signed(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_signed(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2590,7 +2585,7 @@ void testEnumeratedContextDecodes(
|
||||
|
||||
inLen = encode_context_enumerated(apdu, large_context_tag, in);
|
||||
outLen = decode_context_enumerated(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_enumerated(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_enumerated(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2606,7 +2601,7 @@ void testEnumeratedContextDecodes(
|
||||
|
||||
inLen = encode_context_enumerated(apdu, large_context_tag, in);
|
||||
outLen = decode_context_enumerated(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_enumerated(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_enumerated(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2621,7 +2616,7 @@ void testEnumeratedContextDecodes(
|
||||
|
||||
inLen = encode_context_enumerated(apdu, large_context_tag, in);
|
||||
outLen = decode_context_enumerated(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_enumerated(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_enumerated(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2636,7 +2631,7 @@ void testEnumeratedContextDecodes(
|
||||
|
||||
inLen = encode_context_enumerated(apdu, large_context_tag, in);
|
||||
outLen = decode_context_enumerated(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_enumerated(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_enumerated(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2651,7 +2646,7 @@ void testEnumeratedContextDecodes(
|
||||
|
||||
inLen = encode_context_enumerated(apdu, large_context_tag, in);
|
||||
outLen = decode_context_enumerated(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_enumerated(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_enumerated(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2683,7 +2678,7 @@ void testFloatContextDecodes(
|
||||
|
||||
inLen = encode_context_real(apdu, large_context_tag, in);
|
||||
outLen = decode_context_real(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_real(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_real(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2699,7 +2694,7 @@ void testFloatContextDecodes(
|
||||
|
||||
inLen = encode_context_real(apdu, large_context_tag, in);
|
||||
outLen = decode_context_real(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_real(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_real(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2731,7 +2726,7 @@ void testDoubleContextDecodes(
|
||||
|
||||
inLen = encode_context_double(apdu, large_context_tag, in);
|
||||
outLen = decode_context_double(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_double(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_double(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2747,7 +2742,7 @@ void testDoubleContextDecodes(
|
||||
|
||||
inLen = encode_context_double(apdu, large_context_tag, in);
|
||||
outLen = decode_context_double(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_double(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_double(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in == out);
|
||||
@@ -2783,8 +2778,11 @@ static void testObjectIDContextDecodes(
|
||||
ct_test(pTest, outLen2 == -1);
|
||||
|
||||
inLen = encode_context_object_id(apdu, large_context_tag, in_type, in_id);
|
||||
outLen = decode_context_object_id(apdu, large_context_tag, &out_type, &out_id);
|
||||
outLen2 = decode_context_object_id(apdu, large_context_tag-1, &out_type, &out_id);
|
||||
outLen =
|
||||
decode_context_object_id(apdu, large_context_tag, &out_type, &out_id);
|
||||
outLen2 =
|
||||
decode_context_object_id(apdu, large_context_tag - 1, &out_type,
|
||||
&out_id);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in_type == out_type);
|
||||
@@ -2819,7 +2817,8 @@ static void testCharacterStringContextDecodes(
|
||||
|
||||
inLen = encode_context_character_string(apdu, large_context_tag, &in);
|
||||
outLen = decode_context_character_string(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_character_string(apdu, large_context_tag-1, &out);
|
||||
outLen2 =
|
||||
decode_context_character_string(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, outLen2 == -1);
|
||||
ct_test(pTest, inLen == outLen);
|
||||
@@ -2859,7 +2858,7 @@ void testBitStringContextDecodes(
|
||||
|
||||
inLen = encode_context_bitstring(apdu, large_context_tag, &in);
|
||||
outLen = decode_context_bitstring(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_bitstring(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_bitstring(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, outLen2 == -1);
|
||||
ct_test(pTest, inLen == outLen);
|
||||
@@ -2895,7 +2894,7 @@ void testOctetStringContextDecodes(
|
||||
|
||||
inLen = encode_context_octet_string(apdu, large_context_tag, &in);
|
||||
outLen = decode_context_octet_string(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_octet_string(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_octet_string(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, outLen2 == -1);
|
||||
ct_test(pTest, inLen == outLen);
|
||||
@@ -2934,7 +2933,7 @@ void testTimeContextDecodes(
|
||||
|
||||
inLen = encode_context_time(apdu, large_context_tag, &in);
|
||||
outLen = decode_context_bacnet_time(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_bacnet_time(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_bacnet_time(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, outLen2 == -1);
|
||||
ct_test(pTest, inLen == outLen);
|
||||
@@ -2978,7 +2977,7 @@ void testDateContextDecodes(
|
||||
/* Test large tags */
|
||||
inLen = encode_context_date(apdu, large_context_tag, &in);
|
||||
outLen = decode_context_date(apdu, large_context_tag, &out);
|
||||
outLen2 = decode_context_date(apdu, large_context_tag-1, &out);
|
||||
outLen2 = decode_context_date(apdu, large_context_tag - 1, &out);
|
||||
|
||||
ct_test(pTest, inLen == outLen);
|
||||
ct_test(pTest, in.day == out.day);
|
||||
|
||||
+12
-18
@@ -82,15 +82,12 @@ int decode_real_safe(
|
||||
uint32_t len_value,
|
||||
float *real_value)
|
||||
{
|
||||
if ( len_value != 4 )
|
||||
{
|
||||
*real_value = 0.0f;
|
||||
return len_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return decode_real(apdu, real_value);
|
||||
}
|
||||
if (len_value != 4) {
|
||||
*real_value = 0.0f;
|
||||
return len_value;
|
||||
} else {
|
||||
return decode_real(apdu, real_value);
|
||||
}
|
||||
}
|
||||
|
||||
int decode_context_real(
|
||||
@@ -181,15 +178,12 @@ int decode_double_safe(
|
||||
uint32_t len_value,
|
||||
double *double_value)
|
||||
{
|
||||
if ( len_value != 8 )
|
||||
{
|
||||
*double_value = 0.0;
|
||||
return len_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return decode_double(apdu, double_value);
|
||||
}
|
||||
if (len_value != 8) {
|
||||
*double_value = 0.0;
|
||||
return len_value;
|
||||
} else {
|
||||
return decode_double(apdu, double_value);
|
||||
}
|
||||
}
|
||||
|
||||
/* from clause 20.2.7 Encoding of a Double Precision Real Number Value */
|
||||
|
||||
+41
-42
@@ -197,28 +197,25 @@ bool bitstring_same(
|
||||
BACNET_BIT_STRING * bitstring1,
|
||||
BACNET_BIT_STRING * bitstring2)
|
||||
{
|
||||
int i = 0; /* loop counter */
|
||||
int i = 0; /* loop counter */
|
||||
|
||||
if (bitstring1 && bitstring1) {
|
||||
if ((bitstring1->bits_used == bitstring2->bits_used) &&
|
||||
(bitstring1->bits_used/8 <= MAX_BITSTRING_BYTES))
|
||||
{
|
||||
int bytes_used = bitstring1->bits_used/8;
|
||||
uint8_t compare_mask = 0xFF >> (8 - (bitstring1->bits_used%8));
|
||||
(bitstring1->bits_used / 8 <= MAX_BITSTRING_BYTES)) {
|
||||
int bytes_used = bitstring1->bits_used / 8;
|
||||
uint8_t compare_mask = 0xFF >> (8 - (bitstring1->bits_used % 8));
|
||||
|
||||
for (i = 0; i < bytes_used; i++) {
|
||||
if (bitstring1->value[i] != bitstring2->value[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( (bitstring1->value[bytes_used] & compare_mask) !=
|
||||
(bitstring2->value[bytes_used] & compare_mask) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
if ((bitstring1->value[bytes_used] & compare_mask) !=
|
||||
(bitstring2->value[bytes_used] & compare_mask)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -605,7 +602,7 @@ void testBitString(
|
||||
Test * pTest)
|
||||
{
|
||||
uint8_t bit = 0;
|
||||
int max_bit;
|
||||
int max_bit;
|
||||
BACNET_BIT_STRING bit_string;
|
||||
BACNET_BIT_STRING bit_string2;
|
||||
BACNET_BIT_STRING bit_string3;
|
||||
@@ -631,35 +628,36 @@ void testBitString(
|
||||
ct_test(pTest, bitstring_bit(&bit_string, bit) == false);
|
||||
}
|
||||
|
||||
/* test for compare equals*/
|
||||
srand(time(NULL));
|
||||
/* test for compare equals */
|
||||
srand(time(NULL));
|
||||
for (max_bit = 0; max_bit < (MAX_BITSTRING_BYTES * 8); max_bit++) {
|
||||
bitstring_init(&bit_string);
|
||||
bitstring_init(&bit_string2);
|
||||
for (bit = 0; bit < max_bit; bit++) {
|
||||
bool bit_value = rand() % 2;
|
||||
bitstring_set_bit(&bit_string, bit, bit_value);
|
||||
bitstring_set_bit(&bit_string2, bit, bit_value);
|
||||
}
|
||||
ct_test(pTest, bitstring_same(&bit_string, &bit_string2));
|
||||
}
|
||||
/* test for compare not equals*/
|
||||
bitstring_init(&bit_string);
|
||||
bitstring_init(&bit_string2);
|
||||
for (bit = 0; bit < max_bit; bit++) {
|
||||
bool bit_value = rand() % 2;
|
||||
bitstring_set_bit(&bit_string, bit, bit_value);
|
||||
bitstring_set_bit(&bit_string2, bit, bit_value);
|
||||
}
|
||||
ct_test(pTest, bitstring_same(&bit_string, &bit_string2));
|
||||
}
|
||||
/* test for compare not equals */
|
||||
for (max_bit = 1; max_bit < (MAX_BITSTRING_BYTES * 8); max_bit++) {
|
||||
bitstring_init(&bit_string);
|
||||
bitstring_init(&bit_string2);
|
||||
bitstring_init(&bit_string3);
|
||||
for (bit = 0; bit < max_bit; bit++) {
|
||||
bool bit_value = rand() % 2;
|
||||
bitstring_set_bit(&bit_string, bit, bit_value);
|
||||
bitstring_set_bit(&bit_string2, bit, bit_value);
|
||||
bitstring_set_bit(&bit_string3, bit, bit_value);
|
||||
}
|
||||
/* Set the first bit of bit_string2 and the last bit of bit_string3 to be different */
|
||||
bitstring_set_bit(&bit_string2, 0, !bitstring_bit(&bit_string, 0));
|
||||
bitstring_set_bit(&bit_string3, max_bit-1, !bitstring_bit(&bit_string, max_bit-1));
|
||||
ct_test(pTest, !bitstring_same(&bit_string, &bit_string2));
|
||||
ct_test(pTest, !bitstring_same(&bit_string, &bit_string3));
|
||||
}
|
||||
bitstring_init(&bit_string);
|
||||
bitstring_init(&bit_string2);
|
||||
bitstring_init(&bit_string3);
|
||||
for (bit = 0; bit < max_bit; bit++) {
|
||||
bool bit_value = rand() % 2;
|
||||
bitstring_set_bit(&bit_string, bit, bit_value);
|
||||
bitstring_set_bit(&bit_string2, bit, bit_value);
|
||||
bitstring_set_bit(&bit_string3, bit, bit_value);
|
||||
}
|
||||
/* Set the first bit of bit_string2 and the last bit of bit_string3 to be different */
|
||||
bitstring_set_bit(&bit_string2, 0, !bitstring_bit(&bit_string, 0));
|
||||
bitstring_set_bit(&bit_string3, max_bit - 1,
|
||||
!bitstring_bit(&bit_string, max_bit - 1));
|
||||
ct_test(pTest, !bitstring_same(&bit_string, &bit_string2));
|
||||
ct_test(pTest, !bitstring_same(&bit_string, &bit_string3));
|
||||
}
|
||||
}
|
||||
|
||||
void testCharacterString(
|
||||
@@ -772,7 +770,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);
|
||||
|
||||
+20
-26
@@ -251,9 +251,7 @@ bool bactext_object_type_index(
|
||||
const char *search_name,
|
||||
unsigned *found_index)
|
||||
{
|
||||
return indtext_by_istring(
|
||||
bacnet_object_type_names,
|
||||
search_name,
|
||||
return indtext_by_istring(bacnet_object_type_names, search_name,
|
||||
found_index);
|
||||
}
|
||||
|
||||
@@ -937,10 +935,7 @@ bool bactext_property_index(
|
||||
const char *search_name,
|
||||
unsigned *found_index)
|
||||
{
|
||||
return indtext_by_istring(
|
||||
bacnet_property_names,
|
||||
search_name,
|
||||
found_index);
|
||||
return indtext_by_istring(bacnet_property_names, search_name, found_index);
|
||||
}
|
||||
|
||||
INDTEXT_DATA bacnet_engineering_unit_names[] = {
|
||||
@@ -1348,9 +1343,7 @@ bool bactext_engineering_unit_index(
|
||||
const char *search_name,
|
||||
unsigned *found_index)
|
||||
{
|
||||
return indtext_by_istring(
|
||||
bacnet_engineering_unit_names,
|
||||
search_name,
|
||||
return indtext_by_istring(bacnet_engineering_unit_names, search_name,
|
||||
found_index);
|
||||
}
|
||||
|
||||
@@ -1729,13 +1722,20 @@ const char *bactext_day_of_week_name(
|
||||
|
||||
/* note: different than DayOfWeek bit string where 1=monday */
|
||||
INDTEXT_DATA bacnet_days_of_week_names[] = {
|
||||
{BACNET_DAYS_OF_WEEK_MONDAY, "Monday"},
|
||||
{BACNET_DAYS_OF_WEEK_TUESDAY, "Tuesday"},
|
||||
{BACNET_DAYS_OF_WEEK_WEDNESDAY, "Wednesday"},
|
||||
{BACNET_DAYS_OF_WEEK_THURSDAY, "Thursday"},
|
||||
{BACNET_DAYS_OF_WEEK_FRIDAY, "Friday"},
|
||||
{BACNET_DAYS_OF_WEEK_SATURDAY, "Saturday"},
|
||||
{BACNET_DAYS_OF_WEEK_SUNDAY, "Sunday"},
|
||||
{BACNET_DAYS_OF_WEEK_MONDAY, "Monday"}
|
||||
,
|
||||
{BACNET_DAYS_OF_WEEK_TUESDAY, "Tuesday"}
|
||||
,
|
||||
{BACNET_DAYS_OF_WEEK_WEDNESDAY, "Wednesday"}
|
||||
,
|
||||
{BACNET_DAYS_OF_WEEK_THURSDAY, "Thursday"}
|
||||
,
|
||||
{BACNET_DAYS_OF_WEEK_FRIDAY, "Friday"}
|
||||
,
|
||||
{BACNET_DAYS_OF_WEEK_SATURDAY, "Saturday"}
|
||||
,
|
||||
{BACNET_DAYS_OF_WEEK_SUNDAY, "Sunday"}
|
||||
,
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
@@ -1750,9 +1750,7 @@ bool bactext_days_of_week_index(
|
||||
const char *search_name,
|
||||
unsigned *found_index)
|
||||
{
|
||||
return indtext_by_istring(
|
||||
bacnet_days_of_week_names,
|
||||
search_name,
|
||||
return indtext_by_istring(bacnet_days_of_week_names, search_name,
|
||||
found_index);
|
||||
}
|
||||
|
||||
@@ -1777,9 +1775,7 @@ bool bactext_event_transition_index(
|
||||
const char *search_name,
|
||||
unsigned *found_index)
|
||||
{
|
||||
return indtext_by_istring(
|
||||
bacnet_event_transition_names,
|
||||
search_name,
|
||||
return indtext_by_istring(bacnet_event_transition_names, search_name,
|
||||
found_index);
|
||||
}
|
||||
|
||||
@@ -1823,9 +1819,7 @@ bool bactext_binary_present_value_index(
|
||||
const char *search_name,
|
||||
unsigned *found_index)
|
||||
{
|
||||
return indtext_by_istring(
|
||||
bacnet_binary_present_value_names,
|
||||
search_name,
|
||||
return indtext_by_istring(bacnet_binary_present_value_names, search_name,
|
||||
found_index);
|
||||
}
|
||||
|
||||
|
||||
+10
-8
@@ -546,11 +546,13 @@ static bool bvlc_create_bdt(
|
||||
for (i = 0; i < MAX_BBMD_ENTRIES; i++) {
|
||||
if (npdu_length >= 10) {
|
||||
BBMD_Table[i].valid = true;
|
||||
BBMD_Table[i].dest_address.s_addr = ntohl(*(long *)&npdu[pdu_offset]);
|
||||
BBMD_Table[i].dest_address.s_addr =
|
||||
ntohl(*(long *) &npdu[pdu_offset]);
|
||||
pdu_offset += 4;
|
||||
BBMD_Table[i].dest_port = ntohs(*(short *)&npdu[pdu_offset]);
|
||||
BBMD_Table[i].dest_port = ntohs(*(short *) &npdu[pdu_offset]);
|
||||
pdu_offset += 2;
|
||||
BBMD_Table[i].broadcast_mask.s_addr = ntohl(*(long *)&npdu[pdu_offset]);
|
||||
BBMD_Table[i].broadcast_mask.s_addr =
|
||||
ntohl(*(long *) &npdu[pdu_offset]);
|
||||
pdu_offset += 4;
|
||||
npdu_length -= 10;
|
||||
} else {
|
||||
@@ -584,9 +586,9 @@ static bool bvlc_register_foreign_device(
|
||||
status = true;
|
||||
FD_Table[i].time_to_live = time_to_live;
|
||||
/* Upon receipt of a BVLL Register-Foreign-Device message,
|
||||
a BBMD shall start a timer with a value equal to the
|
||||
Time-to-Live parameter supplied plus a fixed grace
|
||||
period of 30 seconds. */
|
||||
a BBMD shall start a timer with a value equal to the
|
||||
Time-to-Live parameter supplied plus a fixed grace
|
||||
period of 30 seconds. */
|
||||
FD_Table[i].seconds_remaining = time_to_live + 30;
|
||||
break;
|
||||
}
|
||||
@@ -673,8 +675,8 @@ static 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()))
|
||||
|
||||
@@ -63,6 +63,7 @@ static uint16_t Timer_Silence(
|
||||
{
|
||||
return SilenceTime;
|
||||
}
|
||||
|
||||
static void Timer_Silence_Reset(
|
||||
void)
|
||||
{
|
||||
|
||||
+139
-134
@@ -190,14 +190,14 @@ int event_notify_encode_service_request(
|
||||
|
||||
len =
|
||||
encode_context_bitstring(&apdu[apdu_len], 0,
|
||||
&data->notificationParams.changeOfBitstring.
|
||||
referencedBitString);
|
||||
&data->notificationParams.
|
||||
changeOfBitstring.referencedBitString);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
encode_context_bitstring(&apdu[apdu_len], 1,
|
||||
&data->notificationParams.changeOfBitstring.
|
||||
statusFlags);
|
||||
&data->notificationParams.
|
||||
changeOfBitstring.statusFlags);
|
||||
apdu_len += len;
|
||||
|
||||
len = encode_closing_tag(&apdu[apdu_len], 0);
|
||||
@@ -221,8 +221,8 @@ int event_notify_encode_service_request(
|
||||
|
||||
len =
|
||||
encode_context_bitstring(&apdu[apdu_len], 1,
|
||||
&data->notificationParams.changeOfState.
|
||||
statusFlags);
|
||||
&data->notificationParams.
|
||||
changeOfState.statusFlags);
|
||||
apdu_len += len;
|
||||
|
||||
len = encode_closing_tag(&apdu[apdu_len], 1);
|
||||
@@ -240,8 +240,8 @@ int event_notify_encode_service_request(
|
||||
case CHANGE_OF_VALUE_REAL:
|
||||
len =
|
||||
encode_context_real(&apdu[apdu_len], 1,
|
||||
data->notificationParams.changeOfValue.
|
||||
newValue.changeValue);
|
||||
data->notificationParams.
|
||||
changeOfValue.newValue.changeValue);
|
||||
apdu_len += len;
|
||||
break;
|
||||
|
||||
@@ -249,8 +249,8 @@ int event_notify_encode_service_request(
|
||||
len =
|
||||
encode_context_bitstring(&apdu[apdu_len],
|
||||
0,
|
||||
&data->notificationParams.changeOfValue.
|
||||
newValue.changedBits);
|
||||
&data->notificationParams.
|
||||
changeOfValue.newValue.changedBits);
|
||||
apdu_len += len;
|
||||
break;
|
||||
|
||||
@@ -263,8 +263,8 @@ int event_notify_encode_service_request(
|
||||
|
||||
len =
|
||||
encode_context_bitstring(&apdu[apdu_len], 1,
|
||||
&data->notificationParams.changeOfValue.
|
||||
statusFlags);
|
||||
&data->notificationParams.
|
||||
changeOfValue.statusFlags);
|
||||
apdu_len += len;
|
||||
|
||||
len = encode_closing_tag(&apdu[apdu_len], 2);
|
||||
@@ -278,20 +278,20 @@ int event_notify_encode_service_request(
|
||||
|
||||
len =
|
||||
encode_context_real(&apdu[apdu_len], 0,
|
||||
data->notificationParams.floatingLimit.
|
||||
referenceValue);
|
||||
data->notificationParams.
|
||||
floatingLimit.referenceValue);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
encode_context_bitstring(&apdu[apdu_len], 1,
|
||||
&data->notificationParams.floatingLimit.
|
||||
statusFlags);
|
||||
&data->notificationParams.
|
||||
floatingLimit.statusFlags);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
encode_context_real(&apdu[apdu_len], 2,
|
||||
data->notificationParams.floatingLimit.
|
||||
setPointValue);
|
||||
data->notificationParams.
|
||||
floatingLimit.setPointValue);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
@@ -310,8 +310,8 @@ int event_notify_encode_service_request(
|
||||
|
||||
len =
|
||||
encode_context_real(&apdu[apdu_len], 0,
|
||||
data->notificationParams.outOfRange.
|
||||
exceedingValue);
|
||||
data->notificationParams.
|
||||
outOfRange.exceedingValue);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
@@ -339,26 +339,26 @@ int event_notify_encode_service_request(
|
||||
|
||||
len =
|
||||
encode_context_enumerated(&apdu[apdu_len], 0,
|
||||
data->notificationParams.changeOfLifeSafety.
|
||||
newState);
|
||||
data->notificationParams.
|
||||
changeOfLifeSafety.newState);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
encode_context_enumerated(&apdu[apdu_len], 1,
|
||||
data->notificationParams.changeOfLifeSafety.
|
||||
newMode);
|
||||
data->notificationParams.
|
||||
changeOfLifeSafety.newMode);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
encode_context_bitstring(&apdu[apdu_len], 2,
|
||||
&data->notificationParams.changeOfLifeSafety.
|
||||
statusFlags);
|
||||
&data->notificationParams.
|
||||
changeOfLifeSafety.statusFlags);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
encode_context_enumerated(&apdu[apdu_len], 3,
|
||||
data->notificationParams.changeOfLifeSafety.
|
||||
operationExpected);
|
||||
data->notificationParams.
|
||||
changeOfLifeSafety.operationExpected);
|
||||
apdu_len += len;
|
||||
|
||||
len = encode_closing_tag(&apdu[apdu_len], 8);
|
||||
@@ -372,20 +372,20 @@ int event_notify_encode_service_request(
|
||||
len =
|
||||
bacapp_encode_context_device_obj_property_ref(&apdu
|
||||
[apdu_len], 0,
|
||||
&data->notificationParams.bufferReady.
|
||||
bufferProperty);
|
||||
&data->notificationParams.
|
||||
bufferReady.bufferProperty);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
encode_context_unsigned(&apdu[apdu_len], 1,
|
||||
data->notificationParams.bufferReady.
|
||||
previousNotification);
|
||||
data->notificationParams.
|
||||
bufferReady.previousNotification);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
encode_context_unsigned(&apdu[apdu_len], 2,
|
||||
data->notificationParams.bufferReady.
|
||||
currentNotification);
|
||||
data->notificationParams.
|
||||
bufferReady.currentNotification);
|
||||
apdu_len += len;
|
||||
|
||||
len = encode_closing_tag(&apdu[apdu_len], 10);
|
||||
@@ -397,20 +397,20 @@ int event_notify_encode_service_request(
|
||||
|
||||
len =
|
||||
encode_context_unsigned(&apdu[apdu_len], 0,
|
||||
data->notificationParams.unsignedRange.
|
||||
exceedingValue);
|
||||
data->notificationParams.
|
||||
unsignedRange.exceedingValue);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
encode_context_bitstring(&apdu[apdu_len], 1,
|
||||
&data->notificationParams.unsignedRange.
|
||||
statusFlags);
|
||||
&data->notificationParams.
|
||||
unsignedRange.statusFlags);
|
||||
apdu_len += len;
|
||||
|
||||
len =
|
||||
encode_context_unsigned(&apdu[apdu_len], 2,
|
||||
data->notificationParams.unsignedRange.
|
||||
exceededLimit);
|
||||
data->notificationParams.
|
||||
unsignedRange.exceededLimit);
|
||||
apdu_len += len;
|
||||
|
||||
len = encode_closing_tag(&apdu[apdu_len], 11);
|
||||
@@ -591,16 +591,18 @@ int event_notify_decode_service_request(
|
||||
case EVENT_CHANGE_OF_BITSTRING:
|
||||
if (-1 == (section_length =
|
||||
decode_context_bitstring(&apdu[len], 0,
|
||||
&data->notificationParams.
|
||||
changeOfBitstring.referencedBitString))) {
|
||||
&data->
|
||||
notificationParams.changeOfBitstring.
|
||||
referencedBitString))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_bitstring(&apdu[len], 1,
|
||||
&data->notificationParams.
|
||||
changeOfBitstring.statusFlags))) {
|
||||
&data->
|
||||
notificationParams.changeOfBitstring.
|
||||
statusFlags))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
@@ -611,16 +613,16 @@ int event_notify_decode_service_request(
|
||||
if (-1 == (section_length =
|
||||
bacapp_decode_context_property_state(&apdu
|
||||
[len], 0,
|
||||
&data->notificationParams.changeOfState.
|
||||
newState))) {
|
||||
&data->notificationParams.
|
||||
changeOfState.newState))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_bitstring(&apdu[len], 1,
|
||||
&data->notificationParams.changeOfState.
|
||||
statusFlags))) {
|
||||
&data->notificationParams.
|
||||
changeOfState.statusFlags))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
@@ -638,8 +640,9 @@ int event_notify_decode_service_request(
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_bitstring(&apdu[len], 0,
|
||||
&data->notificationParams.
|
||||
changeOfValue.newValue.changedBits))) {
|
||||
&data->
|
||||
notificationParams.changeOfValue.
|
||||
newValue.changedBits))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -650,8 +653,9 @@ int event_notify_decode_service_request(
|
||||
CHANGE_OF_VALUE_REAL)) {
|
||||
if (-1 == (section_length =
|
||||
decode_context_real(&apdu[len], 1,
|
||||
&data->notificationParams.
|
||||
changeOfValue.newValue.changeValue))) {
|
||||
&data->
|
||||
notificationParams.changeOfValue.
|
||||
newValue.changeValue))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -669,8 +673,8 @@ int event_notify_decode_service_request(
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_bitstring(&apdu[len], 1,
|
||||
&data->notificationParams.changeOfValue.
|
||||
statusFlags))) {
|
||||
&data->notificationParams.
|
||||
changeOfValue.statusFlags))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
@@ -679,31 +683,31 @@ int event_notify_decode_service_request(
|
||||
case EVENT_FLOATING_LIMIT:
|
||||
if (-1 == (section_length =
|
||||
decode_context_real(&apdu[len], 0,
|
||||
&data->notificationParams.floatingLimit.
|
||||
referenceValue))) {
|
||||
&data->notificationParams.
|
||||
floatingLimit.referenceValue))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_bitstring(&apdu[len], 1,
|
||||
&data->notificationParams.floatingLimit.
|
||||
statusFlags))) {
|
||||
&data->notificationParams.
|
||||
floatingLimit.statusFlags))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
if (-1 == (section_length =
|
||||
decode_context_real(&apdu[len], 2,
|
||||
&data->notificationParams.floatingLimit.
|
||||
setPointValue))) {
|
||||
&data->notificationParams.
|
||||
floatingLimit.setPointValue))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_real(&apdu[len], 3,
|
||||
&data->notificationParams.floatingLimit.
|
||||
errorLimit))) {
|
||||
&data->notificationParams.
|
||||
floatingLimit.errorLimit))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
@@ -712,31 +716,31 @@ int event_notify_decode_service_request(
|
||||
case EVENT_OUT_OF_RANGE:
|
||||
if (-1 == (section_length =
|
||||
decode_context_real(&apdu[len], 0,
|
||||
&data->notificationParams.outOfRange.
|
||||
exceedingValue))) {
|
||||
&data->notificationParams.
|
||||
outOfRange.exceedingValue))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_bitstring(&apdu[len], 1,
|
||||
&data->notificationParams.outOfRange.
|
||||
statusFlags))) {
|
||||
&data->notificationParams.
|
||||
outOfRange.statusFlags))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
if (-1 == (section_length =
|
||||
decode_context_real(&apdu[len], 2,
|
||||
&data->notificationParams.outOfRange.
|
||||
deadband))) {
|
||||
&data->notificationParams.
|
||||
outOfRange.deadband))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_real(&apdu[len], 3,
|
||||
&data->notificationParams.outOfRange.
|
||||
exceededLimit))) {
|
||||
&data->notificationParams.
|
||||
outOfRange.exceededLimit))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
@@ -764,8 +768,9 @@ int event_notify_decode_service_request(
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_bitstring(&apdu[len], 2,
|
||||
&data->notificationParams.
|
||||
changeOfLifeSafety.statusFlags))) {
|
||||
&data->
|
||||
notificationParams.changeOfLifeSafety.
|
||||
statusFlags))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
@@ -775,8 +780,8 @@ int event_notify_decode_service_request(
|
||||
&value))) {
|
||||
return -1;
|
||||
}
|
||||
data->notificationParams.changeOfLifeSafety.
|
||||
operationExpected =
|
||||
data->notificationParams.
|
||||
changeOfLifeSafety.operationExpected =
|
||||
(BACNET_LIFE_SAFETY_OPERATION) value;
|
||||
len += section_length;
|
||||
break;
|
||||
@@ -785,24 +790,24 @@ int event_notify_decode_service_request(
|
||||
if (-1 == (section_length =
|
||||
bacapp_decode_context_device_obj_property_ref
|
||||
(&apdu[len], 0,
|
||||
&data->notificationParams.bufferReady.
|
||||
bufferProperty))) {
|
||||
&data->notificationParams.
|
||||
bufferReady.bufferProperty))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_unsigned(&apdu[len], 1,
|
||||
&data->notificationParams.bufferReady.
|
||||
previousNotification))) {
|
||||
&data->notificationParams.
|
||||
bufferReady.previousNotification))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_unsigned(&apdu[len], 2,
|
||||
&data->notificationParams.bufferReady.
|
||||
currentNotification))) {
|
||||
&data->notificationParams.
|
||||
bufferReady.currentNotification))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
@@ -811,24 +816,24 @@ int event_notify_decode_service_request(
|
||||
case EVENT_UNSIGNED_RANGE:
|
||||
if (-1 == (section_length =
|
||||
decode_context_unsigned(&apdu[len], 0,
|
||||
&data->notificationParams.unsignedRange.
|
||||
exceedingValue))) {
|
||||
&data->notificationParams.
|
||||
unsignedRange.exceedingValue))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_bitstring(&apdu[len], 1,
|
||||
&data->notificationParams.unsignedRange.
|
||||
statusFlags))) {
|
||||
&data->notificationParams.
|
||||
unsignedRange.statusFlags))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
|
||||
if (-1 == (section_length =
|
||||
decode_context_unsigned(&apdu[len], 2,
|
||||
&data->notificationParams.unsignedRange.
|
||||
exceededLimit))) {
|
||||
&data->notificationParams.
|
||||
unsignedRange.exceededLimit))) {
|
||||
return -1;
|
||||
}
|
||||
len += section_length;
|
||||
@@ -1085,16 +1090,16 @@ void testEventEventState(
|
||||
|
||||
data.eventType = EVENT_CHANGE_OF_BITSTRING;
|
||||
|
||||
bitstring_init(&data.notificationParams.changeOfBitstring.
|
||||
referencedBitString);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfBitstring.
|
||||
referencedBitString, 0, true);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfBitstring.
|
||||
referencedBitString, 1, false);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfBitstring.
|
||||
referencedBitString, 2, true);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfBitstring.
|
||||
referencedBitString, 2, false);
|
||||
bitstring_init(&data.notificationParams.
|
||||
changeOfBitstring.referencedBitString);
|
||||
bitstring_set_bit(&data.notificationParams.
|
||||
changeOfBitstring.referencedBitString, 0, true);
|
||||
bitstring_set_bit(&data.notificationParams.
|
||||
changeOfBitstring.referencedBitString, 1, false);
|
||||
bitstring_set_bit(&data.notificationParams.
|
||||
changeOfBitstring.referencedBitString, 2, true);
|
||||
bitstring_set_bit(&data.notificationParams.
|
||||
changeOfBitstring.referencedBitString, 2, false);
|
||||
|
||||
bitstring_init(&data.notificationParams.changeOfBitstring.statusFlags);
|
||||
|
||||
@@ -1180,16 +1185,16 @@ void testEventEventState(
|
||||
|
||||
data.notificationParams.changeOfValue.tag = CHANGE_OF_VALUE_BITS;
|
||||
|
||||
bitstring_init(&data.notificationParams.changeOfValue.newValue.
|
||||
changedBits);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfValue.newValue.
|
||||
changedBits, 0, true);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfValue.newValue.
|
||||
changedBits, 1, false);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfValue.newValue.
|
||||
changedBits, 2, false);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfValue.newValue.
|
||||
changedBits, 3, false);
|
||||
bitstring_init(&data.notificationParams.changeOfValue.
|
||||
newValue.changedBits);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfValue.
|
||||
newValue.changedBits, 0, true);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfValue.
|
||||
newValue.changedBits, 1, false);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfValue.
|
||||
newValue.changedBits, 2, false);
|
||||
bitstring_set_bit(&data.notificationParams.changeOfValue.
|
||||
newValue.changedBits, 3, false);
|
||||
|
||||
memset(buffer, 0, MAX_APDU);
|
||||
inLen = event_notify_encode_service_request(&buffer[0], &data);
|
||||
@@ -1429,12 +1434,12 @@ void testEventEventState(
|
||||
data.notificationParams.bufferReady.currentNotification = 2345;
|
||||
data.notificationParams.bufferReady.bufferProperty.deviceIndentifier.type =
|
||||
OBJECT_DEVICE;
|
||||
data.notificationParams.bufferReady.bufferProperty.deviceIndentifier.
|
||||
instance = 500;
|
||||
data.notificationParams.bufferReady.bufferProperty.
|
||||
deviceIndentifier.instance = 500;
|
||||
data.notificationParams.bufferReady.bufferProperty.objectIdentifier.type =
|
||||
OBJECT_ANALOG_INPUT;
|
||||
data.notificationParams.bufferReady.bufferProperty.objectIdentifier.
|
||||
instance = 100;
|
||||
data.notificationParams.bufferReady.bufferProperty.
|
||||
objectIdentifier.instance = 100;
|
||||
data.notificationParams.bufferReady.bufferProperty.propertyIdentifier =
|
||||
PROP_PRESENT_VALUE;
|
||||
data.notificationParams.bufferReady.bufferProperty.arrayIndex = 0;
|
||||
@@ -1459,34 +1464,34 @@ void testEventEventState(
|
||||
|
||||
|
||||
ct_test(pTest,
|
||||
data.notificationParams.bufferReady.bufferProperty.deviceIndentifier.
|
||||
type ==
|
||||
data2.notificationParams.bufferReady.bufferProperty.deviceIndentifier.
|
||||
type);
|
||||
|
||||
ct_test(pTest,
|
||||
data.notificationParams.bufferReady.bufferProperty.deviceIndentifier.
|
||||
instance ==
|
||||
data2.notificationParams.bufferReady.bufferProperty.deviceIndentifier.
|
||||
instance);
|
||||
|
||||
ct_test(pTest,
|
||||
data.notificationParams.bufferReady.bufferProperty.objectIdentifier.
|
||||
instance ==
|
||||
data2.notificationParams.bufferReady.bufferProperty.objectIdentifier.
|
||||
instance);
|
||||
|
||||
ct_test(pTest,
|
||||
data.notificationParams.bufferReady.bufferProperty.objectIdentifier.
|
||||
type ==
|
||||
data2.notificationParams.bufferReady.bufferProperty.objectIdentifier.
|
||||
type);
|
||||
data.notificationParams.bufferReady.bufferProperty.
|
||||
deviceIndentifier.type ==
|
||||
data2.notificationParams.bufferReady.bufferProperty.
|
||||
deviceIndentifier.type);
|
||||
|
||||
ct_test(pTest,
|
||||
data.notificationParams.bufferReady.bufferProperty.
|
||||
propertyIdentifier ==
|
||||
deviceIndentifier.instance ==
|
||||
data2.notificationParams.bufferReady.bufferProperty.
|
||||
propertyIdentifier);
|
||||
deviceIndentifier.instance);
|
||||
|
||||
ct_test(pTest,
|
||||
data.notificationParams.bufferReady.bufferProperty.
|
||||
objectIdentifier.instance ==
|
||||
data2.notificationParams.bufferReady.bufferProperty.
|
||||
objectIdentifier.instance);
|
||||
|
||||
ct_test(pTest,
|
||||
data.notificationParams.bufferReady.bufferProperty.
|
||||
objectIdentifier.type ==
|
||||
data2.notificationParams.bufferReady.bufferProperty.
|
||||
objectIdentifier.type);
|
||||
|
||||
ct_test(pTest,
|
||||
data.notificationParams.bufferReady.
|
||||
bufferProperty.propertyIdentifier ==
|
||||
data2.notificationParams.bufferReady.
|
||||
bufferProperty.propertyIdentifier);
|
||||
|
||||
ct_test(pTest,
|
||||
data.notificationParams.bufferReady.bufferProperty.arrayIndex ==
|
||||
|
||||
+109
-89
@@ -55,9 +55,9 @@ int getevent_encode_apdu(
|
||||
/* encode optional parameter */
|
||||
if (lastReceivedObjectIdentifier) {
|
||||
len =
|
||||
encode_context_object_id(&apdu[apdu_len], 0,
|
||||
lastReceivedObjectIdentifier->type,
|
||||
lastReceivedObjectIdentifier->instance);
|
||||
encode_context_object_id(&apdu[apdu_len], 0,
|
||||
lastReceivedObjectIdentifier->type,
|
||||
lastReceivedObjectIdentifier->instance);
|
||||
apdu_len += len;
|
||||
}
|
||||
}
|
||||
@@ -78,12 +78,12 @@ int getevent_decode_service_request(
|
||||
/* Tag 0: Object ID - optional */
|
||||
if (!decode_is_context_tag(&apdu[len++], 0))
|
||||
return -1;
|
||||
len += decode_object_id(&apdu[len],
|
||||
&lastReceivedObjectIdentifier->type,
|
||||
len +=
|
||||
decode_object_id(&apdu[len], &lastReceivedObjectIdentifier->type,
|
||||
&lastReceivedObjectIdentifier->instance);
|
||||
}
|
||||
|
||||
return (int)len;
|
||||
|
||||
return (int) len;
|
||||
}
|
||||
|
||||
int getevent_ack_encode_apdu_init(
|
||||
@@ -102,7 +102,7 @@ int getevent_ack_encode_apdu_init(
|
||||
/* Tag 0: listOfEventSummaries */
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 0);
|
||||
}
|
||||
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
@@ -113,38 +113,45 @@ int getevent_ack_encode_apdu_data(
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
BACNET_GET_EVENT_INFORMATION_DATA *event_data;
|
||||
unsigned i = 0; /* counter */
|
||||
unsigned i = 0; /* counter */
|
||||
|
||||
if (apdu) {
|
||||
event_data = get_event_data;
|
||||
while (event_data) {
|
||||
/* Tag 0: objectIdentifier */
|
||||
apdu_len += encode_context_object_id(&apdu[apdu_len], 0,
|
||||
apdu_len +=
|
||||
encode_context_object_id(&apdu[apdu_len], 0,
|
||||
event_data->objectIdentifier.type,
|
||||
event_data->objectIdentifier.instance);
|
||||
/* Tag 1: eventState */
|
||||
apdu_len += encode_context_enumerated(&apdu[apdu_len], 1,
|
||||
apdu_len +=
|
||||
encode_context_enumerated(&apdu[apdu_len], 1,
|
||||
event_data->eventState);
|
||||
/* Tag 2: acknowledgedTransitions */
|
||||
apdu_len += encode_context_bitstring(&apdu[apdu_len], 2,
|
||||
apdu_len +=
|
||||
encode_context_bitstring(&apdu[apdu_len], 2,
|
||||
&event_data->acknowledgedTransitions);
|
||||
/* Tag 3: eventTimeStamps */
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 3);
|
||||
for (i = 0; i < 3; i++) {
|
||||
apdu_len += bacapp_encode_timestamp(&apdu[apdu_len],
|
||||
apdu_len +=
|
||||
bacapp_encode_timestamp(&apdu[apdu_len],
|
||||
&event_data->eventTimeStamps[i]);
|
||||
}
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 3);
|
||||
/* Tag 4: notifyType */
|
||||
apdu_len += encode_context_enumerated(&apdu[apdu_len], 4,
|
||||
apdu_len +=
|
||||
encode_context_enumerated(&apdu[apdu_len], 4,
|
||||
event_data->notifyType);
|
||||
/* Tag 5: eventEnable */
|
||||
apdu_len += encode_context_bitstring(&apdu[apdu_len], 5,
|
||||
apdu_len +=
|
||||
encode_context_bitstring(&apdu[apdu_len], 5,
|
||||
&event_data->eventEnable);
|
||||
/* Tag 6: eventPriorities */
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 6);
|
||||
for (i = 0; i < 3; i++) {
|
||||
apdu_len += encode_application_unsigned(&apdu[apdu_len],
|
||||
apdu_len +=
|
||||
encode_application_unsigned(&apdu[apdu_len],
|
||||
event_data->eventPriorities[i]);
|
||||
}
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 6);
|
||||
@@ -174,14 +181,14 @@ int getevent_ack_decode_service_request(
|
||||
uint8_t * apdu,
|
||||
int apdu_len, /* total length of the apdu */
|
||||
BACNET_GET_EVENT_INFORMATION_DATA * get_event_data,
|
||||
bool *moreEvents)
|
||||
bool * moreEvents)
|
||||
{
|
||||
uint8_t tag_number = 0;
|
||||
uint32_t len_value = 0;
|
||||
int len = 0; /* total length of decodes */
|
||||
uint32_t enum_value = 0; /* for decoding */
|
||||
BACNET_GET_EVENT_INFORMATION_DATA * event_data;
|
||||
unsigned i = 0; /* counter */
|
||||
uint32_t enum_value = 0; /* for decoding */
|
||||
BACNET_GET_EVENT_INFORMATION_DATA *event_data;
|
||||
unsigned i = 0; /* counter */
|
||||
|
||||
/* FIXME: check apdu_len against the len during decode */
|
||||
event_data = get_event_data;
|
||||
@@ -193,9 +200,11 @@ int getevent_ack_decode_service_request(
|
||||
while (event_data) {
|
||||
/* Tag 0: objectIdentifier */
|
||||
if (decode_is_context_tag(&apdu[len], 0)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len += decode_object_id(&apdu[len],
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
len +=
|
||||
decode_object_id(&apdu[len],
|
||||
&event_data->objectIdentifier.type,
|
||||
&event_data->objectIdentifier.instance);
|
||||
} else {
|
||||
@@ -203,88 +212,102 @@ int getevent_ack_decode_service_request(
|
||||
}
|
||||
/* Tag 1: eventState */
|
||||
if (decode_is_context_tag(&apdu[len], 1)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len += decode_enumerated(&apdu[len], len_value,
|
||||
&enum_value);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
len += decode_enumerated(&apdu[len], len_value, &enum_value);
|
||||
event_data->eventState = enum_value;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
/* Tag 2: acknowledgedTransitions */
|
||||
if (decode_is_context_tag(&apdu[len], 2)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len += decode_bitstring(&apdu[len], len_value,
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
len +=
|
||||
decode_bitstring(&apdu[len], len_value,
|
||||
&event_data->acknowledgedTransitions);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
/* Tag 3: eventTimeStamps */
|
||||
if (decode_is_opening_tag_number(&apdu[len], 3)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
for (i = 0; i < 3; i++) {
|
||||
len += bacapp_decode_timestamp(&apdu[len],
|
||||
len +=
|
||||
bacapp_decode_timestamp(&apdu[len],
|
||||
&event_data->eventTimeStamps[i]);
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
if (decode_is_closing_tag_number(&apdu[len], 3)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
/* Tag 4: notifyType */
|
||||
if (decode_is_context_tag(&apdu[len], 4)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len += decode_enumerated(&apdu[apdu_len], len_value,
|
||||
&enum_value);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
len +=
|
||||
decode_enumerated(&apdu[apdu_len], len_value, &enum_value);
|
||||
event_data->notifyType = enum_value;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
/* Tag 5: eventEnable */
|
||||
if (decode_is_context_tag(&apdu[len], 5)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len += decode_bitstring(&apdu[len], len_value,
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
len +=
|
||||
decode_bitstring(&apdu[len], len_value,
|
||||
&event_data->eventEnable);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
/* Tag 6: eventPriorities */
|
||||
if (decode_is_opening_tag_number(&apdu[len], 6)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
for (i = 0; i < 3; i++) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len += decode_unsigned(&apdu[len], len_value,
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
len +=
|
||||
decode_unsigned(&apdu[len], len_value,
|
||||
&event_data->eventPriorities[i]);
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
if (decode_is_closing_tag_number(&apdu[len], 6)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
if (decode_is_closing_tag_number(&apdu[len], 0)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
event_data->next = NULL;
|
||||
}
|
||||
event_data = event_data->next;
|
||||
event_data = event_data->next;
|
||||
}
|
||||
if (decode_is_context_tag(&apdu[len], 1)) {
|
||||
len += decode_tag_number_and_value(&apdu[len],
|
||||
&tag_number, &len_value);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value);
|
||||
*moreEvents = decode_boolean(len_value);
|
||||
} else {
|
||||
return -1;
|
||||
@@ -320,8 +343,9 @@ int getevent_decode_apdu(
|
||||
offset = 4;
|
||||
|
||||
if (apdu_len > offset) {
|
||||
len = getevent_decode_service_request(&apdu[offset],
|
||||
apdu_len - offset, lastReceivedObjectIdentifier);
|
||||
len =
|
||||
getevent_decode_service_request(&apdu[offset], apdu_len - offset,
|
||||
lastReceivedObjectIdentifier);
|
||||
}
|
||||
|
||||
return len;
|
||||
@@ -332,7 +356,7 @@ int getevent_ack_decode_apdu(
|
||||
int apdu_len, /* total length of the apdu */
|
||||
uint8_t * invoke_id,
|
||||
BACNET_GET_EVENT_INFORMATION_DATA * get_event_data,
|
||||
bool *moreEvents)
|
||||
bool * moreEvents)
|
||||
{
|
||||
int len = 0;
|
||||
int offset = 0;
|
||||
@@ -348,8 +372,8 @@ int getevent_ack_decode_apdu(
|
||||
offset = 3;
|
||||
if (apdu_len > offset) {
|
||||
len =
|
||||
getevent_ack_decode_service_request(&apdu[offset], apdu_len - offset,
|
||||
get_event_data, moreEvents);
|
||||
getevent_ack_decode_service_request(&apdu[offset],
|
||||
apdu_len - offset, get_event_data, moreEvents);
|
||||
}
|
||||
|
||||
return len;
|
||||
@@ -373,11 +397,11 @@ void testGetEventInformationAck(
|
||||
event_data.objectIdentifier.instance = 1;
|
||||
event_data.eventState = EVENT_STATE_NORMAL;
|
||||
bitstring_init(&event_data.acknowledgedTransitions);
|
||||
bitstring_set_bit(&event_data.acknowledgedTransitions,
|
||||
bitstring_set_bit(&event_data.acknowledgedTransitions,
|
||||
TRANSITION_TO_OFFNORMAL, false);
|
||||
bitstring_set_bit(&event_data.acknowledgedTransitions,
|
||||
TRANSITION_TO_FAULT, false);
|
||||
bitstring_set_bit(&event_data.acknowledgedTransitions,
|
||||
bitstring_set_bit(&event_data.acknowledgedTransitions, TRANSITION_TO_FAULT,
|
||||
false);
|
||||
bitstring_set_bit(&event_data.acknowledgedTransitions,
|
||||
TRANSITION_TO_NORMAL, false);
|
||||
for (i = 0; i < 3; i++) {
|
||||
event_data.eventTimeStamps[i].tag = TIME_STAMP_SEQUENCE;
|
||||
@@ -385,37 +409,33 @@ void testGetEventInformationAck(
|
||||
}
|
||||
event_data.notifyType = NOTIFY_ALARM;
|
||||
bitstring_init(&event_data.eventEnable);
|
||||
bitstring_set_bit(&event_data.eventEnable,
|
||||
TRANSITION_TO_OFFNORMAL, true);
|
||||
bitstring_set_bit(&event_data.eventEnable,
|
||||
TRANSITION_TO_FAULT, true);
|
||||
bitstring_set_bit(&event_data.eventEnable,
|
||||
TRANSITION_TO_NORMAL, true);
|
||||
bitstring_set_bit(&event_data.eventEnable, TRANSITION_TO_OFFNORMAL, true);
|
||||
bitstring_set_bit(&event_data.eventEnable, TRANSITION_TO_FAULT, true);
|
||||
bitstring_set_bit(&event_data.eventEnable, TRANSITION_TO_NORMAL, true);
|
||||
for (i = 0; i < 3; i++) {
|
||||
event_data.eventPriorities[i] = 1;
|
||||
}
|
||||
event_data.next = NULL;
|
||||
|
||||
len = getevent_ack_encode_apdu(&apdu[0], sizeof(apdu), invoke_id,
|
||||
len =
|
||||
getevent_ack_encode_apdu(&apdu[0], sizeof(apdu), invoke_id,
|
||||
&event_data, moreEvents);
|
||||
ct_test(pTest, len != 0);
|
||||
ct_test(pTest, len != -1);
|
||||
apdu_len = len;
|
||||
len = getevent_ack_decode_apdu(&apdu[0], apdu_len, /* total length of the apdu */
|
||||
len = getevent_ack_decode_apdu(&apdu[0], apdu_len, /* total length of the apdu */
|
||||
&test_invoke_id, &test_event_data, &test_moreEvents);
|
||||
ct_test(pTest, len != -1);
|
||||
ct_test(pTest, test_invoke_id == invoke_id);
|
||||
|
||||
ct_test(pTest,
|
||||
event_data.objectIdentifier.type ==
|
||||
ct_test(pTest,
|
||||
event_data.objectIdentifier.type ==
|
||||
test_event_data.objectIdentifier.type);
|
||||
ct_test(pTest,
|
||||
event_data.objectIdentifier.instance ==
|
||||
ct_test(pTest,
|
||||
event_data.objectIdentifier.instance ==
|
||||
test_event_data.objectIdentifier.instance);
|
||||
|
||||
ct_test(pTest,
|
||||
event_data.eventState ==
|
||||
test_event_data.eventState);
|
||||
ct_test(pTest, event_data.eventState == test_event_data.eventState);
|
||||
}
|
||||
|
||||
void testGetEventInformation(
|
||||
@@ -429,24 +449,24 @@ void testGetEventInformation(
|
||||
BACNET_OBJECT_ID lastReceivedObjectIdentifier;
|
||||
BACNET_OBJECT_ID test_lastReceivedObjectIdentifier;
|
||||
|
||||
lastReceivedObjectIdentifier.type = OBJECT_BINARY_INPUT;
|
||||
lastReceivedObjectIdentifier.type = OBJECT_BINARY_INPUT;
|
||||
lastReceivedObjectIdentifier.instance = 12345;
|
||||
len = getevent_encode_apdu(&apdu[0], invoke_id,
|
||||
len =
|
||||
getevent_encode_apdu(&apdu[0], invoke_id,
|
||||
&lastReceivedObjectIdentifier);
|
||||
ct_test(pTest, len != 0);
|
||||
apdu_len = len;
|
||||
|
||||
len = getevent_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
|
||||
len =
|
||||
getevent_decode_apdu(&apdu[0], apdu_len, &test_invoke_id,
|
||||
&test_lastReceivedObjectIdentifier);
|
||||
ct_test(pTest, len != -1);
|
||||
ct_test(pTest,
|
||||
test_invoke_id ==
|
||||
invoke_id);
|
||||
ct_test(pTest,
|
||||
test_lastReceivedObjectIdentifier.type ==
|
||||
ct_test(pTest, test_invoke_id == invoke_id);
|
||||
ct_test(pTest,
|
||||
test_lastReceivedObjectIdentifier.type ==
|
||||
lastReceivedObjectIdentifier.type);
|
||||
ct_test(pTest,
|
||||
test_lastReceivedObjectIdentifier.instance ==
|
||||
ct_test(pTest,
|
||||
test_lastReceivedObjectIdentifier.instance ==
|
||||
lastReceivedObjectIdentifier.instance);
|
||||
|
||||
return;
|
||||
@@ -473,5 +493,5 @@ int main(
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif /* TEST */
|
||||
|
||||
@@ -218,7 +218,7 @@ uint16_t MSTP_Create_Frame(
|
||||
crc8 = CRC_Calc_Header(buffer[3], crc8);
|
||||
buffer[4] = source;
|
||||
crc8 = CRC_Calc_Header(buffer[4], crc8);
|
||||
buffer[5] = data_len >> 8; /* MSB first */
|
||||
buffer[5] = data_len >> 8; /* MSB first */
|
||||
crc8 = CRC_Calc_Header(buffer[5], crc8);
|
||||
buffer[6] = data_len & 0xFF;
|
||||
crc8 = CRC_Calc_Header(buffer[6], crc8);
|
||||
@@ -236,9 +236,9 @@ uint16_t MSTP_Create_Frame(
|
||||
if (index > 8) {
|
||||
if ((index + 2) <= buffer_len) {
|
||||
crc16 = ~crc16;
|
||||
buffer[index] = crc16 & 0xFF; /* LSB first */
|
||||
buffer[index] = crc16 & 0xFF; /* LSB first */
|
||||
index++;
|
||||
buffer[index] = crc16 >> 8;
|
||||
buffer[index] = crc16 >> 8;
|
||||
index++;
|
||||
} else
|
||||
return 0;
|
||||
@@ -1211,6 +1211,7 @@ static uint16_t Timer_Silence(
|
||||
{
|
||||
return SilenceTime;
|
||||
}
|
||||
|
||||
static void Timer_Silence_Reset(
|
||||
void)
|
||||
{
|
||||
|
||||
@@ -87,10 +87,8 @@ int ptransfer_encode_apdu(
|
||||
apdu[2] = invoke_id;
|
||||
apdu[3] = SERVICE_CONFIRMED_PRIVATE_TRANSFER;
|
||||
apdu_len = 4;
|
||||
apdu_len = pt_encode_apdu(
|
||||
&apdu[apdu_len],
|
||||
MAX_APDU-apdu_len,
|
||||
private_data);
|
||||
apdu_len =
|
||||
pt_encode_apdu(&apdu[apdu_len], MAX_APDU - apdu_len, private_data);
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
@@ -106,10 +104,8 @@ int uptransfer_encode_apdu(
|
||||
apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST;
|
||||
apdu[1] = SERVICE_UNCONFIRMED_PRIVATE_TRANSFER;
|
||||
apdu_len = 2;
|
||||
apdu_len = pt_encode_apdu(
|
||||
&apdu[apdu_len],
|
||||
MAX_APDU-apdu_len,
|
||||
private_data);
|
||||
apdu_len =
|
||||
pt_encode_apdu(&apdu[apdu_len], MAX_APDU - apdu_len, private_data);
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
|
||||
+164
-86
@@ -64,58 +64,75 @@
|
||||
/*****************************************************************************
|
||||
* Build a ReadRange request packet. *
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
int rr_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
uint8_t invoke_id,
|
||||
BACNET_READ_RANGE_DATA * rrdata)
|
||||
{
|
||||
int apdu_len; /* total length of the apdu, return value */
|
||||
int apdu_len; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST;
|
||||
apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU);
|
||||
apdu[2] = invoke_id;
|
||||
apdu[3] = SERVICE_CONFIRMED_READ_RANGE; /* service choice */
|
||||
apdu[3] = SERVICE_CONFIRMED_READ_RANGE; /* service choice */
|
||||
apdu_len = 4;
|
||||
|
||||
apdu_len += encode_context_object_id(&apdu[apdu_len], 0, rrdata->object_type, rrdata->object_instance);
|
||||
apdu_len += encode_context_enumerated(&apdu[apdu_len], 1, rrdata->object_property);
|
||||
|
||||
|
||||
apdu_len +=
|
||||
encode_context_object_id(&apdu[apdu_len], 0, rrdata->object_type,
|
||||
rrdata->object_instance);
|
||||
apdu_len +=
|
||||
encode_context_enumerated(&apdu[apdu_len], 1,
|
||||
rrdata->object_property);
|
||||
|
||||
/* optional array index */
|
||||
|
||||
|
||||
if (rrdata->array_index != BACNET_ARRAY_ALL) {
|
||||
apdu_len += encode_context_unsigned(&apdu[apdu_len], 2, rrdata->array_index);
|
||||
apdu_len +=
|
||||
encode_context_unsigned(&apdu[apdu_len], 2,
|
||||
rrdata->array_index);
|
||||
}
|
||||
|
||||
/* Build the appropriate (optional) range parameter based on the request type */
|
||||
|
||||
|
||||
switch (rrdata->RequestType) {
|
||||
case RR_BY_POSITION:
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 3);
|
||||
apdu_len += encode_application_unsigned(&apdu[apdu_len], rrdata->Range.RefIndex);
|
||||
apdu_len += encode_application_signed(&apdu[apdu_len], rrdata->Count);
|
||||
apdu_len +=
|
||||
encode_application_unsigned(&apdu[apdu_len],
|
||||
rrdata->Range.RefIndex);
|
||||
apdu_len +=
|
||||
encode_application_signed(&apdu[apdu_len], rrdata->Count);
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 3);
|
||||
break;
|
||||
|
||||
case RR_BY_SEQUENCE:
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 6);
|
||||
apdu_len += encode_application_unsigned(&apdu[apdu_len], rrdata->Range.RefSeqNum);
|
||||
apdu_len += encode_application_signed(&apdu[apdu_len], rrdata->Count);
|
||||
apdu_len +=
|
||||
encode_application_unsigned(&apdu[apdu_len],
|
||||
rrdata->Range.RefSeqNum);
|
||||
apdu_len +=
|
||||
encode_application_signed(&apdu[apdu_len], rrdata->Count);
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 6);
|
||||
break;
|
||||
|
||||
case RR_BY_TIME:
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 7);
|
||||
apdu_len += encode_application_date(&apdu[apdu_len], &rrdata->Range.RefTime.date);
|
||||
apdu_len += encode_application_time(&apdu[apdu_len], &rrdata->Range.RefTime.time);
|
||||
apdu_len += encode_application_signed(&apdu[apdu_len], rrdata->Count);
|
||||
apdu_len +=
|
||||
encode_application_date(&apdu[apdu_len],
|
||||
&rrdata->Range.RefTime.date);
|
||||
apdu_len +=
|
||||
encode_application_time(&apdu[apdu_len],
|
||||
&rrdata->Range.RefTime.time);
|
||||
apdu_len +=
|
||||
encode_application_signed(&apdu[apdu_len], rrdata->Count);
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 7);
|
||||
break;
|
||||
|
||||
case RR_READ_ALL: /* to attempt a read of the whole array or list, omit the range parameter */
|
||||
case RR_READ_ALL: /* to attempt a read of the whole array or list, omit the range parameter */
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -139,7 +156,7 @@ int rr_decode_service_request(
|
||||
uint32_t len_value_type = 0;
|
||||
uint16_t type = 0; /* for decoding */
|
||||
uint32_t UnsignedTemp;
|
||||
|
||||
|
||||
/* check for value pointers */
|
||||
if (apdu_len && rrdata) {
|
||||
/* Tag 0: Object ID */
|
||||
@@ -148,23 +165,28 @@ int rr_decode_service_request(
|
||||
len += decode_object_id(&apdu[len], &type, &rrdata->object_instance);
|
||||
rrdata->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, &UnsignedTemp);
|
||||
rrdata->object_property = (BACNET_PROPERTY_ID) UnsignedTemp;
|
||||
/* Tag 2: Optional Array Index */
|
||||
rrdata->array_index = BACNET_ARRAY_ALL; /* Assuming this is the most common outcome... */
|
||||
rrdata->array_index = BACNET_ARRAY_ALL; /* Assuming this is the most common outcome... */
|
||||
if (len < apdu_len) {
|
||||
TagLen = decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
TagLen =
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
if (tag_number == 2) {
|
||||
len += TagLen;
|
||||
len += decode_unsigned(&apdu[len], len_value_type, &UnsignedTemp);
|
||||
len +=
|
||||
decode_unsigned(&apdu[len], len_value_type, &UnsignedTemp);
|
||||
rrdata->array_index = UnsignedTemp;
|
||||
}
|
||||
}
|
||||
/* And/or optional range selection- Tags 3, 6 and 7 */
|
||||
rrdata->RequestType = RR_READ_ALL; /* Assume the worst to cut out explicit checking later */
|
||||
rrdata->RequestType = RR_READ_ALL; /* Assume the worst to cut out explicit checking later */
|
||||
if (len < apdu_len) {
|
||||
/*
|
||||
* Note: We pick up the opening tag and then decode the parameter types we recognise.
|
||||
@@ -173,39 +195,74 @@ int rr_decode_service_request(
|
||||
* This is so that if we receive a tag we don't recognise, we don't try to decode it
|
||||
* blindly and make a mess of it.
|
||||
*/
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
switch(tag_number) {
|
||||
case 3: /* ReadRange by position */
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
switch (tag_number) {
|
||||
case 3: /* ReadRange by position */
|
||||
rrdata->RequestType = RR_BY_POSITION;
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
len += decode_unsigned(&apdu[len], len_value_type, &rrdata->Range.RefIndex);
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
len += decode_signed(&apdu[len], len_value_type, &rrdata->Count);
|
||||
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_unsigned(&apdu[len], len_value_type,
|
||||
&rrdata->Range.RefIndex);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
len +=
|
||||
decode_signed(&apdu[len], len_value_type,
|
||||
&rrdata->Count);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
break;
|
||||
|
||||
case 6: /* ReadRange by sequence number */
|
||||
|
||||
case 6: /* ReadRange by sequence number */
|
||||
rrdata->RequestType = RR_BY_SEQUENCE;
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
len += decode_unsigned(&apdu[len], len_value_type, &rrdata->Range.RefSeqNum);
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
len += decode_signed(&apdu[len], len_value_type, &rrdata->Count);
|
||||
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_unsigned(&apdu[len], len_value_type,
|
||||
&rrdata->Range.RefSeqNum);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
len +=
|
||||
decode_signed(&apdu[len], len_value_type,
|
||||
&rrdata->Count);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
break;
|
||||
|
||||
case 7: /* ReadRange by time stamp */
|
||||
case 7: /* ReadRange by time stamp */
|
||||
rrdata->RequestType = RR_BY_TIME;
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
len += decode_date(&apdu[len], &rrdata->Range.RefTime.date);
|
||||
len += decode_bacnet_time(&apdu[len], &rrdata->Range.RefTime.time);
|
||||
len += decode_unsigned(&apdu[len], len_value_type, &rrdata->Range.RefIndex);
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type);
|
||||
len += decode_signed(&apdu[len], len_value_type, &rrdata->Count);
|
||||
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_date(&apdu[len], &rrdata->Range.RefTime.date);
|
||||
len +=
|
||||
decode_bacnet_time(&apdu[len],
|
||||
&rrdata->Range.RefTime.time);
|
||||
len +=
|
||||
decode_unsigned(&apdu[len], len_value_type,
|
||||
&rrdata->Range.RefIndex);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
len +=
|
||||
decode_signed(&apdu[len], len_value_type,
|
||||
&rrdata->Count);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||
&len_value_type);
|
||||
break;
|
||||
|
||||
default: /* If we don't recognise the tag then we do nothing here and try to return
|
||||
* all elements of the array */
|
||||
default: /* If we don't recognise the tag then we do nothing here and try to return
|
||||
* all elements of the array */
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -226,7 +283,7 @@ int rr_decode_service_request(
|
||||
* -- type 'By Sequence Number' or 'By Time'
|
||||
* }
|
||||
*/
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Build a ReadRange response packet *
|
||||
*****************************************************************************/
|
||||
@@ -237,38 +294,49 @@ int rr_ack_encode_apdu(
|
||||
BACNET_READ_RANGE_DATA * rrdata)
|
||||
{
|
||||
int len = 0; /* length of each encoding */
|
||||
int apdu_len; /* total length of the apdu, return value */
|
||||
int apdu_len; /* total length of the apdu, return value */
|
||||
|
||||
if (apdu) {
|
||||
apdu[0] = PDU_TYPE_COMPLEX_ACK; /* complex ACK service */
|
||||
apdu[1] = invoke_id; /* original invoke id from request */
|
||||
apdu[0] = PDU_TYPE_COMPLEX_ACK; /* complex ACK service */
|
||||
apdu[1] = invoke_id; /* original invoke id from request */
|
||||
apdu[2] = SERVICE_CONFIRMED_READ_RANGE; /* service choice */
|
||||
apdu_len = 3;
|
||||
/* service ack follows */
|
||||
apdu_len += encode_context_object_id(&apdu[apdu_len], 0, rrdata->object_type, rrdata->object_instance);
|
||||
apdu_len += encode_context_enumerated(&apdu[apdu_len], 1, rrdata->object_property);
|
||||
apdu_len +=
|
||||
encode_context_object_id(&apdu[apdu_len], 0, rrdata->object_type,
|
||||
rrdata->object_instance);
|
||||
apdu_len +=
|
||||
encode_context_enumerated(&apdu[apdu_len], 1,
|
||||
rrdata->object_property);
|
||||
/* context 2 array index is optional */
|
||||
if (rrdata->array_index != BACNET_ARRAY_ALL) {
|
||||
apdu_len += encode_context_unsigned(&apdu[apdu_len], 2, rrdata->array_index);
|
||||
apdu_len +=
|
||||
encode_context_unsigned(&apdu[apdu_len], 2,
|
||||
rrdata->array_index);
|
||||
}
|
||||
/* Context 3 BACnet Result Flags */
|
||||
apdu_len += encode_context_bitstring(&apdu[apdu_len], 3, &rrdata->ResultFlags);
|
||||
apdu_len +=
|
||||
encode_context_bitstring(&apdu[apdu_len], 3, &rrdata->ResultFlags);
|
||||
/* Context 4 Item Count */
|
||||
apdu_len += encode_context_unsigned(&apdu[apdu_len], 4, rrdata->ItemCount);
|
||||
apdu_len +=
|
||||
encode_context_unsigned(&apdu[apdu_len], 4, rrdata->ItemCount);
|
||||
/* Context 5 Property list - reading the standard it looks like an empty list still
|
||||
* requires an opening and closing tag as the tagged parameter is not optional
|
||||
*/
|
||||
apdu_len += encode_opening_tag(&apdu[apdu_len], 5);
|
||||
if(rrdata->ItemCount != 0) {
|
||||
if (rrdata->ItemCount != 0) {
|
||||
for (len = 0; len < rrdata->application_data_len; len++) {
|
||||
apdu[apdu_len++] = rrdata->application_data[len];
|
||||
}
|
||||
}
|
||||
}
|
||||
apdu_len += encode_closing_tag(&apdu[apdu_len], 5);
|
||||
|
||||
if((rrdata->ItemCount != 0) && (rrdata->RequestType != RR_BY_POSITION) && (rrdata->RequestType != RR_READ_ALL)) {
|
||||
|
||||
if ((rrdata->ItemCount != 0) && (rrdata->RequestType != RR_BY_POSITION)
|
||||
&& (rrdata->RequestType != RR_READ_ALL)) {
|
||||
/* Context 6 Sequence number of first item */
|
||||
apdu_len += encode_context_unsigned(&apdu[apdu_len], 6, rrdata->FirstSequence);
|
||||
apdu_len +=
|
||||
encode_context_unsigned(&apdu[apdu_len], 6,
|
||||
rrdata->FirstSequence);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,68 +370,78 @@ int rr_ack_decode_service_request(
|
||||
rrdata->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);
|
||||
rrdata->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);
|
||||
rrdata->array_index = array_value;
|
||||
} else
|
||||
rrdata->array_index = BACNET_ARRAY_ALL;
|
||||
|
||||
|
||||
/* Tag 3: Result Flags */
|
||||
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 != 3)
|
||||
return -1;
|
||||
|
||||
len += decode_bitstring(&apdu[len], len_value_type, &rrdata->ResultFlags);
|
||||
|
||||
|
||||
/* Tag 4: Item count */
|
||||
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 != 4)
|
||||
return -1;
|
||||
|
||||
len += decode_unsigned(&apdu[len], len_value_type, &rrdata->ItemCount);
|
||||
|
||||
|
||||
if (decode_is_opening_tag_number(&apdu[len], 5)) {
|
||||
len++; /* a tag number of 5 is not extended so only one octet */
|
||||
len++; /* a tag number of 5 is not extended so only one octet */
|
||||
/* Setup the start position and length of the data returned from the request
|
||||
* don't decode the application tag number or its data here */
|
||||
rrdata->application_data = &apdu[len];
|
||||
start_len = len;
|
||||
while(len < apdu_len) {
|
||||
if(IS_CONTEXT_SPECIFIC(apdu[len]) && (decode_is_closing_tag_number(&apdu[len], 5))) {
|
||||
while (len < apdu_len) {
|
||||
if (IS_CONTEXT_SPECIFIC(apdu[len]) &&
|
||||
(decode_is_closing_tag_number(&apdu[len], 5))) {
|
||||
rrdata->application_data_len = len - start_len;
|
||||
len++; /* Step over single byte closing tag */
|
||||
len++; /* Step over single byte closing tag */
|
||||
break;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* Don't care about tag number, just skipping over anyway */
|
||||
len += decode_tag_number_and_value(&apdu[len], NULL, &len_value_type);
|
||||
len +=
|
||||
decode_tag_number_and_value(&apdu[len], NULL,
|
||||
&len_value_type);
|
||||
len += len_value_type; /* Skip over data value as well */
|
||||
if(len >= apdu_len) /* APDU is exhausted so we have failed to find closing tag */
|
||||
return(-1);
|
||||
if (len >= apdu_len) /* APDU is exhausted so we have failed to find closing tag */
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
if(len < apdu_len) { /* Still something left to look at? */
|
||||
}
|
||||
if (len < apdu_len) { /* Still something left to look at? */
|
||||
/* Tag 6: Item count */
|
||||
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 != 6)
|
||||
return -1;
|
||||
|
||||
len += decode_unsigned(&apdu[len], len_value_type, &rrdata->FirstSequence);
|
||||
len +=
|
||||
decode_unsigned(&apdu[len], len_value_type,
|
||||
&rrdata->FirstSequence);
|
||||
}
|
||||
|
||||
len = apdu_len; /* There should be nothing left to see here */
|
||||
len = apdu_len; /* There should be nothing left to see here */
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,17 +43,13 @@ void bacapp_timestamp_copy(
|
||||
dest->tag = src->tag;
|
||||
switch (src->tag) {
|
||||
case TIME_STAMP_TIME:
|
||||
datetime_copy_time(
|
||||
&dest->value.time,
|
||||
&src->value.time);
|
||||
datetime_copy_time(&dest->value.time, &src->value.time);
|
||||
break;
|
||||
case TIME_STAMP_SEQUENCE:
|
||||
dest->value.sequenceNum = src->value.sequenceNum;
|
||||
break;
|
||||
case TIME_STAMP_DATETIME:
|
||||
datetime_copy(
|
||||
&dest->value.dateTime,
|
||||
&src->value.dateTime);
|
||||
datetime_copy(&dest->value.dateTime, &src->value.dateTime);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -70,9 +66,7 @@ int bacapp_encode_timestamp(
|
||||
if (value && apdu) {
|
||||
switch (value->tag) {
|
||||
case TIME_STAMP_TIME:
|
||||
len =
|
||||
encode_context_time(&apdu[0], 0,
|
||||
&value->value.time);
|
||||
len = encode_context_time(&apdu[0], 0, &value->value.time);
|
||||
break;
|
||||
|
||||
case TIME_STAMP_SEQUENCE:
|
||||
@@ -93,7 +87,7 @@ int bacapp_encode_timestamp(
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
@@ -174,7 +168,7 @@ int bacapp_decode_timestamp(
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user