Commit Graph

29 Commits

Author SHA1 Message Date
Steve Karg 80875add0a Fixed BACnet/IP initialization on a network interface where the system reports the interface's unicast IP address as being the same. (#1011) 2025-06-03 19:49:03 -05:00
Steve Karg 0c45b50574 Fixed bip cleanup to enable initializing interfaces after cleanup. (#949) 2025-03-25 08:40:18 -05:00
Steve Karg 7e725ce028 Bugfix/win32 build warnings (#936)
* Changed win32 port of localtime to use secure OS API functions when compiled with MSVC

* Changed all the sprintf to use snprintf instead in BSC tests to ensure null string endings.
2025-03-03 10:32:28 -06:00
Steve Karg 94b3809a58 Bugfix/confirmed handlers empty service request (#885)
* Added reject in all confirmed service handlers, except GetEventInformation, when confirmed services with zero length occur which rejects with required parameters are missing message.

* Refactored errno use in service using debug_perror. Changed debug_perror usage to debug_fprintf. 

* Updated file and function headers in basic/service modules.

* Changed NDPU priority on confirmed messages to use requested NDPU priority.

* Renamed debug_aprintf to debug_printf_stdout for clarity.

* Convert most debug_fprintf usage to debug_print to reduce text bloat in AVR build
2025-01-05 10:09:39 -06:00
Patrick Grimm b9de08cf60 Feature/router bsd (#821)
* fix router compile warnings declaration-after-statement overlength-strings

* router disable PRINT(debug_level)

* ports rename dlmstp_[linux|bsd] to dlmstp_port

* copy ports/linux/dlmstp_port.c ports/bsd/dlmstp_port.c

* copy ports/linux/dlmstp_port.c ports/bsd/dlmstp_port.c

* fix typedef in bip_get_local_address_ioctl

* copy ports/linux/dlmstp_port.c ports/bsd/dlmstp_port.c

* add bsd support for router app

* fix clang __attribute__ optimize dont work
clang O2/O3/Os are also not working

* fix pre-commit

* fix bsd SO_BINDTODEVICE is not available

* add brew install libconfig for app router and bsd

* fix BACDL_MSTP test on macOS

* remove old comments
2024-10-21 07:53:01 -05:00
Kari Argillander f806c5829b Run clang-format and enable CI check for it (#755)
* pre-commit: Update and enable clang-format check

There is newer version from clang-format so use that. We do not yet want
18 as that is little bit too new.

* Format some thing by hand which clang-format "breaks"

Clang-format will format some things little bit off in some cases.
Format some things by hand so we get cleaner end result.

* Run clang-format with

```
pre-commit run --all-files clang-format
```

We have already in previously checked places where clang-format does not
make good format and ignored those (hopefully most of the things).

---------

Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
2024-08-30 11:20:58 -05:00
Kari Argillander a2f1d6959d Make most of functions const correct (#714)
* Make most of the functions const correct

Used clang-tidy and sonarlint to help find places where const could
pretty easily applied. Also lot of hand work.

This commit does not yet touch handlers and typedefs of those.

* Fix Arduino uno handler_who_is() has extra parenthesis

For some reason there is extra parenthesis. Remove it this is more
likely buildable.

* Bugfix/bacapp: Fix uninitilized array_index

We have changed bacapp_snprintf_value() to be const correct. After that
we got

```
/home/runner/work/bacnet-stack/bacnet-stack/src/bacnet/bacapp.c:3183:27: warning: 4th function call argument is an uninitialized value [core.CallAndMessage]
                ret_val = bacapp_snprintf_weeklyschedule(
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
```

So analyzer could now spot that we do not actually initilize array_index
at all. Fix this by setting array_index to zero. Note that I actually do
not know if zeroing is right thing to do here. I choose zero as if this
has worked before it is most likely that it will work with zero value.

* cmake: Add and ignore Wwrite-strings compiler option

Wwrite-strings helps find places where const correctness is broken.

Example it will warn about these

```C

void func1(char* str);

func("test") /* "test" is const so we should not pass it to func1().

char* func2()
{
  return "test"; /* func2() should return const char*.
}
```

We still need to ignore it as not all are fixed but let's add it already
so we remember that it should be opened at some point.

---------

Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
2024-08-29 14:08:02 -05:00
Kari Argillander 9e0657424e Prepere repo so we can run auto formatters (#747)
* clang-format: Ignore javascript files

Ignore javascript files. Clang-format is not very good formatter for
javascript files anyway. If we ever need javascript formatter we should
use Prettier.

* clang-format: Ignore some lines in sources

Couple things get formatted really funky if we let clang-format format
those. Just ignore those locally.

* zephyr/tescase.yaml: Fix yaml syntax

pre-commit hook check-yaml did found out that there are two skips.
Remove another as this is not right syntax.

* Fix repo contains unicode replacement chars

When running pre-commit text-unicode-replacement-char it founds that
there is couple unicode replacemnt chars. Remove and replace these.

* Convert some tabs to spaces manually

We will soon auto format tabs to spaces. How ever it could not do couple
thing so fix those by hand first.

* Make files with shebang executables

It is good habit that if file has shebang then it is marked executable.
These where found with pre-commit check-shebang-scripts-are-executable
checker.

---------

Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
2024-08-23 17:58:41 -05:00
Kari Argillander 6271632944 Add and fix compiler warnings (#718)
* Add and remove compiler warning compile options

Add some new compiler warnings. Some of those does not build clean so
ignore them for now. This also helps if some user use those options so
we ignore those for them also.

Also remove following ignores as they do not produce any warnings:

  - Wno-attributes
  - Wno-long-long
  - Wno-implicit-fallthrough

* Fix -Wmissing-declarations compiler warnings

Fix new -Wmissing-declarations compiler warnings. I tried to look which
should be in headers and which should be static. Might be that some
statics should be in header as it is not easy to choose if something
should be exported or not.

* Fix -Wmissing-field-initializers compiler warnings

If we use { { 0 } } compiler thinks we might have mean that we only
meant initialize first member of struct or have forgotton to add second
one. We could do { { 0 }, 0 } but we can just do { 0 } which tells
compiler that hey just intialize this whole thing to zero.

* tests: Fix couple -Wfloat-conversion warnings

Add f prefix to floating point numbers to get some double to float
warnings away.

* ci: Make warnings as errors with cmake main build

To keep repo more clean from warnings use Werror flag when building main
project.

Windows should need -DCMAKE_C_FLAGS="/WX" but we have not ignore errors
for that yet so let's not yet take it in use.

* ci: Build also tests in matrix build

Enable also tests to be builded in our main matrix build. This way tests
will be builded also with clang and in future also with MSVC. We also
keep build very clean now as all warnings as catched.

With this we can also take out -Werror from compile_options as we add
that in CI. It is not good practice to keep that option always on. It
makes development lot harder. See example this blog post [1].

[1]: https://embeddedartistry.com/blog/2017/05/22/werror-is-not-your-friend/

* getevent: Deprecate getevent_encode_apdu()

Steve suggested that we should deprecate getevent_encode_apdu() [1].

Suggested-by: Steve Karg

[1]: https://github.com/bacnet-stack/bacnet-stack/pull/718#discussion_r1715821735

---------

Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
2024-08-13 16:32:44 -05:00
Kari Argillander cb243c36a8 Improve SPDX identifier coverage (#716)
* Change MIT license texts to SPDX-License-Identifier

SPDX-License-Identifier is much easier to understand and grep than
license text so use that instead.

* Change GPL exception license texts to SPDX-License-Identifier

SPDX-License-Identifier is much easier to understand and grep than
license text so use that instead.

* Change misc license texts to SPDX-License-Identifier

There are some external code in repo which are not licenses as most of
the stuff in this repo. We still want every file to have SPDX identifier
to easily grep licenses.

* Add currently used license files

Even though Bacnet-Stack is using SPDX identifiers we still need to give
those license files with source. For this reason add all license files
to license/ folder.

SPDX has also files which would make same thing but this is style which
example Linux kernel is using and it is quite clear so I choose that one
for now.

I choosed not yet bring CC-PDDC as that is not right license for those
files.

---------

Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
2024-08-12 15:33:02 -05:00
Steve Karg 52f3f08cb1 Bugfix/fix redundant compiler flags (#658)
* Improved GCC compiler flags in ARM, OS, and test builds. Removed redundant flags, and made them consistent across various builds.

* Fixed redundant redeclaration of various functions detected by change in compiler flags.

* Fixed string truncation warning in bip-init detected by change in compiler flags.

* Fixed some set-but-not-used variables by creating dummy functions instead of using macros.
2024-05-30 10:59:54 -05:00
Steve Karg bb276e2431 Refactored all the sprintf to use snprintf instead. (#628) 2024-04-27 12:41:45 -05:00
Steve Karg 89fa3cea77 Fixed the Network Port object subnet mask for IP example. (#573) 2024-02-13 14:15:59 -06:00
Steve Karg 75286cffe4 Bugfix/linux bip so bindtodevice error (#498)
* disable extraneous SO_BINDTODEVICE warning in Linux BIP

---------

Co-authored-by: Steve Karg <steve.karg@legrand.us>
2023-09-14 11:09:11 -05:00
Steve Karg 55b8b3d93c fix BACnet/IP on OS to bind broadcast to specific port (#489)
* Fixes #346 by binding the broadcast socket to the port specific broadcast address rather than INADDR_ANY or INADDR_BROADCAST. Added additional compile and environment options for those who might need them. 

* Changed the define USE_CLASSADDR to BACNET_IP_BROADCAST_USE_CLASSADDR to help manage namespaces.

* Added BACNET_IP_BROADCAST_BIND_ADDR environment variable to override the default broadcast binding address.

---------

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2023-09-10 10:24:18 -05:00
Steve Karg b91735af13 Bugfix/code clean using gcc warnings (#371)
* Enable extra GCC warnings to discover subtle bugs

* convert c++ comments to c comments

* cleanup pedantic compiler warnings

* Compile apps with GNU89 GNU99 GNU11 and GNU17

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2022-12-25 21:43:51 -06:00
Alexander Wells 5b30674215 Provide getter for broadcast BIP socket (#350) 2022-10-24 13:44:42 -05:00
Steve Karg 38d213b47c Feature/color objects color command (#302)
* added BACnetColorCommand and BACnetxyColor encoding and unit testing

* Added Color object and unit testing.

* Added Color Temperature object and Unit test

* Fix BVLC unit test warning.

* add port Makefile for extra types

* added RGB to and from CIE xy utility in sys folder, and add unit tests.

* added cmake-win32 target

* Change RP and RPM to use known property decoder.

Add color object RP and RPM decoding and printing
Fix RPM print for new reserved range above 4194303
Change default protocol-revision to 24 for Color object

* Integrate Color and Color Temperature objects into demo apps

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2022-07-13 09:54:36 -05:00
Mikhail Antropov 144017f861 BIP: add option - listen to broadcast on a separate socket (#293)
* BIP: add socket to listen to broadcast packets for Linux/Windows/BSD/Zephyr

* BIP: added BVLC broadcast handler to drop a packet when confirmed broadcast request is sent.

* https://sourceforge.net/p/bacnet/bugs/65/
2022-07-01 09:48:41 -05:00
Ondřej Hruška 0dec80fae7 Add functions to enable/disable debug logging (#280)
* Add "bip_debug_disable()"

* Add "bvlc_debug_disable()"

* Add setters for BIP_DL_Debug (BBMD registration debug logging)
2022-05-25 21:43:08 -05:00
Alexander Wells ca32676662 Add bip_get_socket (#210)
* Add function to get BIP socket

* Add bip_get_socket to all applicable ports
2022-01-10 10:15:54 -06:00
Steve Karg 63e4fa1f4b fixes #141 Linux BIP with no default gateway (#144)
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2020-12-21 13:07:24 -06:00
Steve Karg 762ffacc8e Bug#72 reading zero bytes in linux BIP. Thanks, Mikhail! (#132)
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2020-10-10 10:45:12 -05:00
Roy Schneider 764e0e8448 Feature/zeroing rx buffer remain (#90)
* Added zeroing rx buffer remain

* Added zeroing rx buffer remain

* Added safety margin for the rx-buffer in the different ports.

* Added safety margin for the receive buffer.

* Added DoxyGen comments.

* Fixed checking return value when calculating distance between opening and closing tag on multiple properties.
2020-05-24 09:19:52 -05:00
Steve Karg dbbcec3033 Feature/bacnet ipv4 default iface linux (#75)
* Added default IFACE for IPv4 on Linux

* fix potential leak of memory found by scan-build

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
2020-04-16 15:55:38 -05:00
Roy Schneider 8f13d59629 Feature/comments and buffer checks (#73)
* Added comments

* Replaced Goto construct

* Added apdu_len check

* Added comments

* Added string limit and reworked printable check

* Mainly comments

* Just comments

* Just comments

* decode service request returns now non zero on success

* eliminated warnings

* Added character string init with length check.

* Paranoic length check

* Comments and object index checking on read/write.

* Check name/desc strings before returning.

* Eliminated Goto
2020-04-16 10:38:49 -05:00
Steve Karg eedfa58a55 Feature/refactor bacnet ipv4 add unit tests (#64)
* refactor BACnet/IPv4 BVLC into encode-decode library with unit tests
Added Read-Broadcast-Distribution-Table encoding and unit test.
Added Read-Broadcast-Distribution-Table-Ack encoding and unit test.
Added Read-Foreign-Device-Table-Ack encoding and unit test.
Added some BDT/FDT diff copy functions with unit tests
Added some FDT add and delete entry functions with unit tests
Added some BDT set append and clear entry functions with unit tests
Added some BIPv4 address conversion functions with unit tests
Added non-BBMD handling unit test
Added basic unit test for BBMD handler
Added BBMD broadcast mask get set and unit tests
Added IPv6 maintenance timer.
Added ReadFDT app
Fixed ReadBDT app
Added Who-Is to Makefile for individual app build
Fixed debugging code blocks projects by swapping bip.c for h_bbmd.c module.
Ported BACnet/IPv4 to refactored BVLC for Linux, BSD, Windows
Fix datalink debug for DLENV module
Improve BIPv4 linux driver debug info
Added BDT mask functions
Reduce debug info clutter in Who-Is app by using environment option
Fix TTL seconds upper bounds addition
Fix CIDR prefix calculation on Linux BIPv4.
Convert BSD BIPv4 to BVLCv4
Fix CMake build for BIPv4 (Linux, BSD, Windows)
Added [U]nsigned to 0xBAC0 constants
Cleanup POSIX and Win32 API sockets
Remove unnecessary file scope variable initialization
Fix routed NPDU to depend on datalink; fix warning
Remove OS dependent network code from gateway
Enable BBMD client in library by default
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
Co-authored-by: Steve Karg <steve.karg@legrand.us>
2020-04-04 11:31:54 -05:00
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
Steve Karg a42e8f507c adjust root folder 2019-10-08 23:47:53 -05:00