object/nc: Fix incorrect apdu_len calculation (#517)
* object/nc: Fix incorrect apdu_len calculation when encoding Recipient_List which had resulted in malformed APDU. * enabled unit testing on notification-class object example --------- Co-authored-by: Tomasz Kazimierz Motyl <butterfly_tm666@yahoo.com> Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
@@ -267,6 +267,7 @@ int Notification_Class_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata)
|
||||
break;
|
||||
}
|
||||
/* size fits, therefore, encode all entry of Recipient_List */
|
||||
apdu_len = 0;
|
||||
for (idx = 0; idx < NC_MAX_RECIPIENTS; idx++) {
|
||||
BACNET_DESTINATION *Destination;
|
||||
BACNET_RECIPIENT *Recipient;
|
||||
@@ -447,7 +448,11 @@ bool Notification_Class_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
status = true;
|
||||
break;
|
||||
|
||||
case PROP_OBJECT_IDENTIFIER:
|
||||
case PROP_OBJECT_NAME:
|
||||
case PROP_OBJECT_TYPE:
|
||||
case PROP_DESCRIPTION:
|
||||
case PROP_NOTIFICATION_CLASS:
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
|
||||
break;
|
||||
@@ -704,8 +709,7 @@ void Notification_Class_find_recipient(void)
|
||||
* the BACnetLIST all of the specified elements, or to neither add nor
|
||||
* update any elements at all.
|
||||
*/
|
||||
int Notification_Class_Add_List_Element(
|
||||
BACNET_LIST_ELEMENT_DATA * list_element)
|
||||
int Notification_Class_Add_List_Element(BACNET_LIST_ELEMENT_DATA *list_element)
|
||||
{
|
||||
NOTIFICATION_CLASS_INFO *notification = NULL;
|
||||
BACNET_DESTINATION recipient_list[NC_MAX_RECIPIENTS] = { 0 };
|
||||
@@ -755,8 +759,8 @@ int Notification_Class_Add_List_Element(
|
||||
application_data = list_element->application_data;
|
||||
application_data_len = list_element->application_data_len;
|
||||
while (application_data_len > 0) {
|
||||
len = bacnet_destination_decode(application_data,
|
||||
application_data_len, &recipient_list[index]);
|
||||
len = bacnet_destination_decode(
|
||||
application_data, application_data_len, &recipient_list[index]);
|
||||
if (len > 0) {
|
||||
new_element_count++;
|
||||
application_data_len -= len;
|
||||
@@ -793,7 +797,7 @@ int Notification_Class_Add_List_Element(
|
||||
same_element_count++;
|
||||
} else {
|
||||
added_element_count++;
|
||||
if ((added_element_count+element_count) > NC_MAX_RECIPIENTS) {
|
||||
if ((added_element_count + element_count) > NC_MAX_RECIPIENTS) {
|
||||
list_element->first_failed_element_number = 1 + i;
|
||||
list_element->error_class = ERROR_CLASS_RESOURCES;
|
||||
list_element->error_code =
|
||||
@@ -862,7 +866,7 @@ int Notification_Class_Add_List_Element(
|
||||
* a 'Result(-)' response primitive shall be issued.
|
||||
*/
|
||||
int Notification_Class_Remove_List_Element(
|
||||
BACNET_LIST_ELEMENT_DATA * list_element)
|
||||
BACNET_LIST_ELEMENT_DATA *list_element)
|
||||
{
|
||||
NOTIFICATION_CLASS_INFO *notification = NULL;
|
||||
uint32_t notify_index = 0;
|
||||
@@ -911,8 +915,8 @@ int Notification_Class_Remove_List_Element(
|
||||
application_data = list_element->application_data;
|
||||
application_data_len = list_element->application_data_len;
|
||||
while (application_data_len > 0) {
|
||||
len = bacnet_destination_decode(application_data,
|
||||
application_data_len, &recipient_list[index]);
|
||||
len = bacnet_destination_decode(
|
||||
application_data, application_data_len, &recipient_list[index]);
|
||||
if (len > 0) {
|
||||
remove_element_count++;
|
||||
application_data_len -= len;
|
||||
|
||||
Reference in New Issue
Block a user