Files
bacnet_stack/src/bacnet/basic/service/h_whois.c
T
Steve Karg d50c190957 Issue 2 move folders and use deep path include file names to prevent collisions (#4)
* moving folders and files and adjust server demo build

* Fix Makefile for apps/server on Linux

* fix unit test source file folders

* fix datetime convert UTC functions. Add Code::Blocks project for datetime testing

* added some ignore extensions

* disable parallel make option

* fix build for abort, dcc, and epics apps

* fix build for dcc, epics, error, and getevent apps.

* Fixed building of all apps

* fix the ipv4 to ipv6 router app build

* Change indent style from Google to Webkit

* make pretty to re-format style

* removed common Makefile since we already had one and two was too many

* remove scripts from root folder that are no longer maintained or used

* remove mercurial EOL and ignore files for git repo

* remove .vscodeconfig files from repo

* tweak clang-format style

* clang-format src and apps with tweaked style

* added clang-tidy to fix readability if braces in src

* result of make tidy for src and apps

* fix clang-tidy mangling

* Added code::blocks project for BACnet server simulation

* added code::blocks linux project for WhoIs app

* update text files for EOL

* fix EOL in some files

* fixed make win32 apps for older gcc

* Removed Borland C++ Makefile in apps. Unable to maintain support for Borland C++ compiler.

* created codeblocks project for apps/epics for Windows

* fixing ports/xplained to work with new data structure.

* fix ports/xplained example for Atmel Studio compile

* fix ports/stm32f10x example for gcc Makefile compile

* fix ports/stm32f10x example for IAR EWARM compile

* fix ports/xplained timer callback

* fix ports/bdk_atxx_mspt build with subdirs

* fix ports/bdk_atxx_mspt build with subdirs

* updated git ignore for IAR build artifacts

* updated gitignore for non-tracked files and folders

* fixed bdk-atxx4-mstp port for Rowley Crossworks project file

* fixed bdk-atxx4-mstp port for GCC AVR Makefile

* fixed atmega168 port for IAR AVR and GCC AVR Makefile

* fixed at91sam7s port for IAR ARM and GCC ARM Makefile

* removed unmaintainable DOS, RTOS32, and atmega8 ports.  Updated rx62n (untested).

* changed arm7 to uip port
2019-12-13 15:19:10 -06:00

189 lines
7.1 KiB
C

/**************************************************************************
*
* Copyright (C) 2005 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "bacnet/config.h"
#include "bacnet/bacdef.h"
#include "bacnet/bacdcode.h"
#include "bacnet/whois.h"
#include "bacnet/iam.h"
#include "bacnet/basic/object/device.h"
#include "bacnet/basic/services.h"
#include "bacnet/basic/tsm/tsm.h"
/** @file h_whois.c Handles Who-Is requests. */
/** Handler for Who-Is requests, with broadcast I-Am response.
* @ingroup DMDDB
* @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 (ignored).
*/
void handler_who_is(
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(&Handler_Transmit_Buffer[0]);
} else if (len != BACNET_STATUS_ERROR) {
/* is my device id within the limits? */
if ((Device_Object_Instance_Number() >= (uint32_t)low_limit) &&
(Device_Object_Instance_Number() <= (uint32_t)high_limit)) {
Send_I_Am(&Handler_Transmit_Buffer[0]);
}
}
return;
}
/** Handler for Who-Is requests, with Unicast I-Am response (per Addendum
* 135-2004q).
* @ingroup DMDDB
* @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 that the
* response will be sent back to.
*/
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;
len = whois_decode_service_request(
service_request, service_len, &low_limit, &high_limit);
/* If no limits, then always respond */
if (len == 0) {
Send_I_Am_Unicast(&Handler_Transmit_Buffer[0], src);
} else if (len != BACNET_STATUS_ERROR) {
/* is my device id within the limits? */
if ((Device_Object_Instance_Number() >= (uint32_t)low_limit) &&
(Device_Object_Instance_Number() <= (uint32_t)high_limit)) {
Send_I_Am_Unicast(&Handler_Transmit_Buffer[0], src);
}
}
return;
}
#ifdef BAC_ROUTING /* was for BAC_ROUTING - delete in 2/2012 if still unused \
*/
/* EKH: I restored this to BAC_ROUTING (from DEPRECATED) because I found that
the server demo with the built-in
virtual Router did not insert the SADRs of the virtual devices on the virtual
network without it */
/** Local function to check Who-Is requests against our Device IDs.
* Will check the gateway (root Device) and all virtual routed
* Devices against the range and respond for each that matches.
*
* @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.
* @param is_unicast [in] True if should send unicast response(s)
* back to the src, else False if should broadcast
* response(s).
*/
static void check_who_is_for_routing(uint8_t *service_request,
uint16_t service_len,
BACNET_ADDRESS *src,
bool is_unicast)
{
int len = 0;
int32_t low_limit = 0;
int32_t high_limit = 0;
int32_t dev_instance;
int cursor = 0; /* Starting hint */
int my_list[2] = { 0, -1 }; /* Not really used, so dummy values */
BACNET_ADDRESS bcast_net;
len = whois_decode_service_request(
service_request, service_len, &low_limit, &high_limit);
if (len == BACNET_STATUS_ERROR) {
/* Invalid; just leave */
return;
}
/* Go through all devices, starting with the root gateway Device */
memset(&bcast_net, 0, sizeof(BACNET_ADDRESS));
bcast_net.net = BACNET_BROADCAST_NETWORK; /* That's all we have to set */
while (Routed_Device_GetNext(&bcast_net, my_list, &cursor)) {
dev_instance = Device_Object_Instance_Number();
/* If len == 0, no limits and always respond */
if ((len == 0) ||
((dev_instance >= low_limit) && (dev_instance <= high_limit))) {
if (is_unicast)
Send_I_Am_Unicast(&Handler_Transmit_Buffer[0], src);
else
Send_I_Am(&Handler_Transmit_Buffer[0]);
}
}
}
/** Handler for Who-Is requests in the virtual routing setup,
* with broadcast I-Am response(s).
* @ingroup DMDDB
* Will check the gateway (root Device) and all virtual routed
* Devices against the range and respond for each that matches.
*
* @ingroup DMDDB
* @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 (ignored).
*/
void handler_who_is_bcast_for_routing(
uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src)
{
check_who_is_for_routing(service_request, service_len, src, false);
}
/** Handler for Who-Is requests in the virtual routing setup,
* with unicast I-Am response(s) returned to the src.
* Will check the gateway (root Device) and all virtual routed
* Devices against the range and respond for each that matches.
*
* @ingroup DMDDB
* @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 that the
* response will be sent back to.
*/
void handler_who_is_unicast_for_routing(
uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src)
{
check_who_is_for_routing(service_request, service_len, src, true);
}
#endif /* BAC_ROUTING */