From d98194636c1cf2e7f8da756794dfcbcca73e5027 Mon Sep 17 00:00:00 2001 From: skarg Date: Fri, 19 Feb 2010 14:45:32 +0000 Subject: [PATCH] Changed default WhoIs to be Broadcast after seeing problems of unicast I-Am through some BACnet routers. Split out WhoIs into 2 handlers - one for unicast I-Am and one for Broadcast I-Am. Developer can choose which one to use for their default handler. --- bacnet-stack/demo/handler/h_whois.c | 39 ++++++++++++++++++++++++++--- bacnet-stack/demo/handler/s_iam.c | 2 +- bacnet-stack/include/handlers.h | 5 ++++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/bacnet-stack/demo/handler/h_whois.c b/bacnet-stack/demo/handler/h_whois.c index 4bed89db..94afa9ec 100644 --- a/bacnet-stack/demo/handler/h_whois.c +++ b/bacnet-stack/demo/handler/h_whois.c @@ -40,7 +40,6 @@ /** @file h_whois.c Handles Who-Is requests. */ /** Handler for Who-Is requests. - * @note: Now using Unicast to send I-Am response. * @param service_request [in] The received message to be handled. * @param service_len [in] Length of the service_request message. * @param src [in] The BACNET_ADDRESS of the message's source. @@ -59,7 +58,7 @@ void handler_who_is( whois_decode_service_request(service_request, service_len, &low_limit, &high_limit); if (len == 0) - Send_I_Am_Unicast(&Handler_Transmit_Buffer[0], src); + Send_I_Am(&Handler_Transmit_Buffer[0], src); else if (len != -1) { /* is my device id within the limits? */ if (((Device_Object_Instance_Number() >= (uint32_t) low_limit) && @@ -68,7 +67,41 @@ void handler_who_is( /* BACnet wildcard is the max instance number - everyone responds */ ((BACNET_MAX_INSTANCE >= (uint32_t) low_limit) && (BACNET_MAX_INSTANCE <= (uint32_t) high_limit))) - Send_I_Am_Unicast(&Handler_Transmit_Buffer[0], src); + Send_I_Am(&Handler_Transmit_Buffer[0], src); + } + + return; +} + +/** Handler for Who-Is requests - Unicast (per Addendum 135-2004q). + * @param service_request [in] The received message to be handled. + * @param service_len [in] Length of the service_request message. + * @param src [in] The BACNET_ADDRESS of the message's source. + */ +void handler_who_is_unicast( + uint8_t * service_request, + uint16_t service_len, + BACNET_ADDRESS * src) +{ + int len = 0; + int32_t low_limit = 0; + int32_t high_limit = 0; + + (void) src; + len = + whois_decode_service_request(service_request, service_len, &low_limit, + &high_limit); + if (len == 0) + Send_I_Am_Unicast(&Handler_Transmit_Buffer[0], src); + else if (len != -1) { + /* is my device id within the limits? */ + if (((Device_Object_Instance_Number() >= (uint32_t) low_limit) && + (Device_Object_Instance_Number() <= (uint32_t) high_limit)) + || + /* BACnet wildcard is the max instance number - everyone responds */ + ((BACNET_MAX_INSTANCE >= (uint32_t) low_limit) && + (BACNET_MAX_INSTANCE <= (uint32_t) high_limit))) + Send_I_Am_Unicast(&Handler_Transmit_Buffer[0], src); } return; diff --git a/bacnet-stack/demo/handler/s_iam.c b/bacnet-stack/demo/handler/s_iam.c index 1180b7fb..b0121b4e 100644 --- a/bacnet-stack/demo/handler/s_iam.c +++ b/bacnet-stack/demo/handler/s_iam.c @@ -107,7 +107,7 @@ void Send_I_Am( * If the src address is not given, the dest address will be * a broadcast address. * @param buffer [in,out] The buffer to use for building the message. - * @param src [in] The source address information, if any (may be NULL). + * @param src [in] The source address information. * @param dest [out] The destination address information. * @param npdu_data [out] The NPDU structure describing the message. * @return The length of the message in buffer[]. diff --git a/bacnet-stack/include/handlers.h b/bacnet-stack/include/handlers.h index 00b5b92f..54935b15 100644 --- a/bacnet-stack/include/handlers.h +++ b/bacnet-stack/include/handlers.h @@ -59,6 +59,11 @@ extern "C" { uint16_t service_len, BACNET_ADDRESS * src); + void handler_who_is_whois( + uint8_t * service_request, + uint16_t service_len, + BACNET_ADDRESS * src); + void handler_who_has( uint8_t * service_request, uint16_t service_len,