From cbc62dd6c0a8c849a9e543a127fc4cc8349d91bc Mon Sep 17 00:00:00 2001 From: tbrennan3 Date: Thu, 27 Oct 2011 20:34:45 +0000 Subject: [PATCH] Extended the test for supported services for routed devices to the device's PROP_PROTOCOL_SERVICES_SUPPORTED. Support calling of Routed_Device_Service_Approval() with a NULL buffer if just testing for support. --- bacnet-stack/demo/object/gw_device.c | 22 ++++++++++++++++------ bacnet-stack/src/apdu.c | 20 ++++++++++++++++++-- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/bacnet-stack/demo/object/gw_device.c b/bacnet-stack/demo/object/gw_device.c index 78dbc67f..979a5221 100644 --- a/bacnet-stack/demo/object/gw_device.c +++ b/bacnet-stack/demo/object/gw_device.c @@ -604,8 +604,10 @@ void Routed_Device_Inc_Database_Revision( * @param service [in] The service being requested. * @param service_argument [in] An optional argument (eg, service type). * @param apdu_buff [in,out] The buffer where we will encode a Reject message. + * May be NULL if don't want an encoded response. * @param invoke_id [in] The invoke_id of the service request. * @return Length of bytes encoded in apdu_buff[] for a Reject message, + * just 1 if no apdu_buff was supplied and service is not supported, * else 0 if service is approved for the current device. */ int Routed_Device_Service_Approval( @@ -619,15 +621,23 @@ int Routed_Device_Service_Approval( { case SERVICE_CONFIRMED_REINITIALIZE_DEVICE: /* If not the gateway device, we don't support RD */ - if ( iCurrent_Device_Idx > 0 ) - len = reject_encode_apdu(apdu_buff, - invoke_id, REJECT_REASON_UNRECOGNIZED_SERVICE); + if ( iCurrent_Device_Idx > 0 ) { + if (apdu_buff != NULL) + len = reject_encode_apdu(apdu_buff, + invoke_id, REJECT_REASON_UNRECOGNIZED_SERVICE); + else + len = 1; /* Non-zero return */ + } break; case SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL: /* If not the gateway device, we don't support DCC */ - if ( iCurrent_Device_Idx > 0 ) - len = reject_encode_apdu(apdu_buff, - invoke_id, REJECT_REASON_UNRECOGNIZED_SERVICE); + if ( iCurrent_Device_Idx > 0 ) { + if (apdu_buff != NULL) + len = reject_encode_apdu(apdu_buff, + invoke_id, REJECT_REASON_UNRECOGNIZED_SERVICE); + else + len = 1; /* Non-zero return */ + } break; default: /* Everything else is a pass, at this time. */ diff --git a/bacnet-stack/src/apdu.c b/bacnet-stack/src/apdu.c index f8901a45..3844c80e 100644 --- a/bacnet-stack/src/apdu.c +++ b/bacnet-stack/src/apdu.c @@ -45,6 +45,13 @@ /** @file apdu.c Handles APDU services */ +extern int Routed_Device_Service_Approval( + BACNET_CONFIRMED_SERVICE service, + int service_argument, + uint8_t *apdu_buff, + uint8_t invoke_id ); + + /* APDU Timeout in Milliseconds */ static uint16_t Timeout_Milliseconds = 3000; /* Number of APDU Retries */ @@ -145,9 +152,18 @@ bool apdu_service_supported( /* is it a confirmed service? */ for (i = 0; i < MAX_BACNET_CONFIRMED_SERVICE; i++) { if (confirmed_service_supported[i] == service_supported) { - if (Confirmed_Function[i] != NULL) - status = true; found = true; + if (Confirmed_Function[i] != NULL) { +#if BAC_ROUTING + /* Check to see if the current Device supports this service. */ + int len = Routed_Device_Service_Approval( + service_supported, 0, NULL, 0); + if ( len > 0 ) + break; /* Not supported - return false */ +#endif + + status = true; + } break; } }