Added checking in with each device (in the BAC_ROUTING case) to see whether it supports RD or DCC.
Sends a Reject message if not supported. Added to the respective handlers.
This commit is contained in:
@@ -98,7 +98,6 @@ void handler_device_communication_control(
|
||||
BACNET_CHARACTER_STRING password;
|
||||
int len = 0;
|
||||
int pdu_len = 0;
|
||||
int bytes_sent = 0;
|
||||
BACNET_NPDU_DATA npdu_data;
|
||||
BACNET_ADDRESS my_address;
|
||||
|
||||
@@ -156,6 +155,15 @@ void handler_device_communication_control(
|
||||
"Sending Reject - undefined enumeration\n");
|
||||
#endif
|
||||
} else {
|
||||
#if BAC_ROUTING
|
||||
/* Check to see if the current Device supports this service. */
|
||||
len = Routed_Device_Service_Approval(
|
||||
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, (int) state,
|
||||
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id );
|
||||
if ( len > 0 )
|
||||
goto DCC_ABORT;
|
||||
#endif
|
||||
|
||||
if (characterstring_ansi_same(&password, My_Password)) {
|
||||
len =
|
||||
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
|
||||
@@ -181,17 +189,15 @@ void handler_device_communication_control(
|
||||
}
|
||||
DCC_ABORT:
|
||||
pdu_len += len;
|
||||
bytes_sent =
|
||||
len =
|
||||
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
|
||||
pdu_len);
|
||||
#if PRINT_ENABLED
|
||||
if (bytes_sent <= 0) {
|
||||
if (len <= 0) {
|
||||
fprintf(stderr,
|
||||
"DeviceCommunicationControl: " "Failed to send PDU (%s)!\n",
|
||||
strerror(errno));
|
||||
}
|
||||
#else
|
||||
bytes_sent = bytes_sent;
|
||||
#endif
|
||||
|
||||
return;
|
||||
|
||||
@@ -73,7 +73,6 @@ void handler_reinitialize_device(
|
||||
int len = 0;
|
||||
int pdu_len = 0;
|
||||
BACNET_NPDU_DATA npdu_data;
|
||||
int bytes_sent = 0;
|
||||
BACNET_ADDRESS my_address;
|
||||
|
||||
/* encode the NPDU portion of the packet */
|
||||
@@ -130,6 +129,15 @@ void handler_reinitialize_device(
|
||||
"ReinitializeDevice: Sending Reject - undefined enumeration\n");
|
||||
#endif
|
||||
} else {
|
||||
#if BAC_ROUTING
|
||||
/* Check to see if the current Device supports this service. */
|
||||
len = Routed_Device_Service_Approval(
|
||||
SERVICE_CONFIRMED_REINITIALIZE_DEVICE, (int) rd_data.state,
|
||||
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id );
|
||||
if ( len > 0 )
|
||||
goto RD_ABORT;
|
||||
#endif
|
||||
|
||||
if (Device_Reinitialize(&rd_data)) {
|
||||
len =
|
||||
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
|
||||
@@ -150,16 +158,14 @@ void handler_reinitialize_device(
|
||||
}
|
||||
RD_ABORT:
|
||||
pdu_len += len;
|
||||
bytes_sent =
|
||||
len =
|
||||
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
|
||||
pdu_len);
|
||||
#if PRINT_ENABLED
|
||||
if (bytes_sent <= 0) {
|
||||
if (len <= 0) {
|
||||
fprintf(stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n",
|
||||
strerror(errno));
|
||||
}
|
||||
#else
|
||||
bytes_sent = bytes_sent;
|
||||
#endif
|
||||
|
||||
return;
|
||||
|
||||
@@ -420,6 +420,11 @@ extern "C" {
|
||||
size_t length);
|
||||
void Routed_Device_Inc_Database_Revision(
|
||||
void);
|
||||
int Routed_Device_Service_Approval(
|
||||
BACNET_CONFIRMED_SERVICE service,
|
||||
int service_argument,
|
||||
uint8_t *apdu_buff,
|
||||
uint8_t invoke_id );
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -42,8 +42,8 @@
|
||||
#include "handlers.h"
|
||||
#include "datalink.h"
|
||||
#include "address.h"
|
||||
#include "reject.h"
|
||||
/* include the objects */
|
||||
#include "device.h"
|
||||
#include "ai.h"
|
||||
#include "ao.h"
|
||||
#include "av.h"
|
||||
@@ -595,3 +595,43 @@ void Routed_Device_Inc_Database_Revision(
|
||||
DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx];
|
||||
pDev->Database_Revision++;
|
||||
}
|
||||
|
||||
|
||||
/** Check to see if the current Device supports this service.
|
||||
* Presently checks for RD and DCC and only allows them if the current
|
||||
* device is the gateway device.
|
||||
*
|
||||
* @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.
|
||||
* @param invoke_id [in] The invoke_id of the service request.
|
||||
* @return Length of bytes encoded in apdu_buff[] for a Reject message,
|
||||
* else 0 if service is approved for the current device.
|
||||
*/
|
||||
int Routed_Device_Service_Approval(
|
||||
BACNET_CONFIRMED_SERVICE service,
|
||||
int service_argument,
|
||||
uint8_t *apdu_buff,
|
||||
uint8_t invoke_id )
|
||||
{
|
||||
int len = 0;
|
||||
switch(service)
|
||||
{
|
||||
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);
|
||||
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);
|
||||
break;
|
||||
default:
|
||||
/* Everything else is a pass, at this time. */
|
||||
break;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user