From 288a47edea43d376455e17e3248a6297d96c4bb3 Mon Sep 17 00:00:00 2001 From: skarg Date: Tue, 14 Aug 2012 16:27:50 +0000 Subject: [PATCH] Added checks for DeviceCommunicationControl that were in src/apdu.c but are missing from this port. Thanks, Vu! --- bacnet-stack/ports/pic18f6720/apdu.c | 69 ++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/bacnet-stack/ports/pic18f6720/apdu.c b/bacnet-stack/ports/pic18f6720/apdu.c index e9cc5397..b0a2568a 100644 --- a/bacnet-stack/ports/pic18f6720/apdu.c +++ b/bacnet-stack/ports/pic18f6720/apdu.c @@ -102,6 +102,61 @@ uint16_t apdu_decode_confirmed_service_request( return len; } +/* When network communications are completely disabled, + only DeviceCommunicationControl and ReinitializeDevice APDUs + shall be processed and no messages shall be initiated. + When the initiation of communications is disabled, + all APDUs shall be processed and responses returned as + required... */ +static bool apdu_confirmed_dcc_disabled( + uint8_t service_choice) +{ + bool status = false; + + if (dcc_communication_disabled()) { + switch (service_choice) { + case SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL: + case SERVICE_CONFIRMED_REINITIALIZE_DEVICE: + break; + default: + status = true; + break; + } + } + + return status; +} + +/* When network communications are completely disabled, + only DeviceCommunicationControl and ReinitializeDevice APDUs + shall be processed and no messages shall be initiated. */ +/* If the request is valid and the 'Enable/Disable' parameter is + DISABLE_INITIATION, the responding BACnet-user shall + discontinue the initiation of messages except for I-Am + requests issued in accordance with the Who-Is service procedure.*/ +static bool apdu_unconfirmed_dcc_disabled( + uint8_t service_choice) +{ + bool status = false; + + if (dcc_communication_disabled()) { + /* there are no Unconfirmed messages that + can be processed in this state */ + status = true; + } else if (dcc_communication_initiation_disabled()) { + /* WhoIs will be processed and I-Am initiated as response. */ + switch (service_choice) { + case SERVICE_UNCONFIRMED_WHO_IS: + break; + default: + status = true; + break; + } + } + + return status; +} + void apdu_handler( BACNET_ADDRESS * src, uint8_t * apdu, /* APDU data */ @@ -120,6 +175,12 @@ void apdu_handler( len = apdu_decode_confirmed_service_request(&apdu[0], /* APDU data */ apdu_len, &service_data, &service_choice, &service_request, &service_request_len); + if (apdu_confirmed_dcc_disabled(service_choice)) { + /* When network communications are completely disabled, + only DeviceCommunicationControl and ReinitializeDevice APDUs + shall be processed and no messages shall be initiated. */ + break; + } if (service_choice == SERVICE_CONFIRMED_READ_PROPERTY) { handler_read_property(service_request, service_request_len, src, &service_data); @@ -143,6 +204,14 @@ void apdu_handler( service_choice = apdu[1]; service_request = &apdu[2]; service_request_len = apdu_len - 2; + if (apdu_unconfirmed_dcc_disabled(service_choice)) { + /* When network communications are disabled, + only DeviceCommunicationControl and ReinitializeDevice APDUs + shall be processed and no messages shall be initiated. + If communications have been initiation disabled, then + WhoIs may be processed. */ + break; + } if (service_choice == SERVICE_UNCONFIRMED_WHO_IS) { handler_who_is(service_request, service_request_len, src); }