Commit Graph

203 Commits

Author SHA1 Message Date
skarg d7ad240f05 The patch is to change the timeout from 10us to 0 so that we just do a poll for more receive data when there is already data queued. With this patch, the code seems to work just fine with 100Hz timer tick. Thank you, David Mosberger 2019-03-17 22:15:27 +00:00
skarg 2c7d5ea4aa Here is a patch for ports/linux/dlmstp.c that switches it to use CLOCK_MONOTONIC rather than real time for the condition variable. This makes the code robust against changes to real time (say, operator adjust time and moves it back by one year, now the timeout wont fire for a year...). Thank you, David Mosberger 2019-03-17 22:08:25 +00:00
skarg 0386af099f Merged revision(s) 3206 from branches/releases/bacnet-stack-0-8-0:
Removed case in MS/TP data expecting reply to not expect a ConfirmedRequest PDU reply. Bug #59. Thank you, Govind!
........
2018-12-13 17:50:25 +00:00
skarg 7d1550362b Merged revision(s) 3136 from branches/releases/bacnet-stack-0-8-0:
Replace Receive_Packet_Flag conditional variable with a semaphore and update the related library functions accordingly.
Analysis of the problem determined that the issue lay in the transfer of APDU packets between the FSM and the APDU packet handler thread.
The mechanism previously used by the FSM to notify the APDU packet handler thread that a packet was available for processing used a pthread conditional variable which packet handler thread was supposed to wait on before being signalled by the FSM.
However the packet handler thread has other tasks to perform and sometimes was not waiting on the conditional variable which it was signalled.
Unlike other synchronisation mechanisms such as semaphores, if the waiting task (the consumer) is not blocked on the conditional variable when the producer signals, then that signal is lost and the consumer is never signalled again, leading to a continual sequence of timeouts on the conditional variable.
This in turn led to the packet handler thread never being notified of a packet waiting to be processed thus causing the interface hang.
The main problem is that a conditional variable is supposed to be used with a mutex to prevent this behaviour occurring, but this mutex was not present (and in fact had been removed from the code, most likely because it was causing other synchronisation issues)
Further inspection revealed that this code was copied from another file but modified to remove the mutex which is an essential part of using a conditional variable for synchronisation. This then prevents the producer task being blocked until the consumer task is waiting on the conditional variable, thus leading to a race condition which is causing the issues seen.
The fix is to replace the conditional variable with a semaphore as this provides the required mechanism in this case.
Thank you Ian Smith at Abelon Systems Ltd. for the patch!

........
2017-06-25 18:08:36 +00:00
skarg 0b5a514cf7 Adds two new functions to the ring buffer implementation, one to walk the ring by getting a pointer to the next element in the ring, and the other to Pop (remove) a specified element from somewhere in the ring and then move any elements up towards the head to fill the gap left. With these new functions in place, the Linux MS/TP datalink MSTP_Get_Reply() has been updated to walk the ring buffer to try to find the matching reply. If it is found then it is processed in the same way as usual, and then removed from the ring.
When a packet is received which expects a reply a copy is stored in the PDU ring buffer so it can be matched with the reply. Unfortunately when the reply is received it is only checked against the first entry in the ring buffer. This can cause a failure if a second packet expecting a reply has been received while waiting for the first reply to arrive.
This is a known issue in the bacnet-stack open source stack, and there is a outstanding FIXME in the latest version of the source code:

        /* The ANSWER_DATA_REQUEST state is entered when a  */
        /* BACnet Data Expecting Reply, a Test_Request, or  */
        /* a proprietary frame that expects a reply is received. */
        /* FIXME: MSTP_Get_Reply waits for a matching reply, but
           if the next queued message doesn't match, then we
           sit here for Treply_delay doing nothing */

The fix for this is to check all the messages in the PDU queue to see if any of them match, and if one does then handle it in the normal way. Thank you to Ian Smith of Abelon Systems Ltd. for the patch!
2017-06-25 18:06:27 +00:00
skarg bd5ec637a6 Changes to clean up compile warnings 2017-02-14 15:21:39 +00:00
skarg 9699801f32 Added Wireshark 2.x extcap live capture for mstpcap on Linux. 2016-10-30 00:12:09 +00:00
skarg c9d152bf15 Merged revision(s) 3044 from branches/releases/bacnet-stack-0-8-0:
Added BACnet/IPv6 datalink layer and example BACnet/IPv4 to BACnet/IPv6 router.
BVLC6 layer is working on Linux port without BBMD features yet. Win32 is implemented, untested.
Tested during BACnet North American Plugfest 2016.
........
2016-10-01 20:23:03 +00:00
skarg 7462d448a5 Added some fixes to router demo 2016-07-01 14:28:14 +00:00
skarg 3362eecdff Added security for BACnet stack, based on the BACnet 2012 standard, clause 24.
Implemented the majority of functionalities presented in the standard, but there are several features that this patch currently lacks:
- Set-Master-Key message has a specific order of key adding and decoding which is not covered
- There is no general secure-apdu-handler function
- Checks for the type of keys used for signing/encryption of specific messages is not implemented
- The status of encrypted flag during the calculation of the signature is ambiguous
There is a Linux implementation using the OpenSSL library, with function prototypes broad enough to allow for different implementations.
Thank you, Nikola Jelić!
2016-04-20 17:00:51 +00:00
skarg 48d04c323f Removed check for NPDU Priority on MS/TP outgoing matching messages since the stack currently doesn't support passing the NDPU Priority through, and every outgoing message is NORMAL. This was causing Reply-Postponed, which is not a good thing for high priority messages. Thank you, Ettore Colicchio! 2015-12-02 20:20:33 +00:00
skarg ec581ace70 cleaned up warnings from BACnet Ethernet 8802.3 compile on Linux 2015-09-24 21:51:29 +00:00
skarg 07bf4eba3b Deprecated Ringbuf_Alloc, and replaced with Ringbuf_Data_Peek() and Ringbuf_Data_Put() functions. Ringbuf_Alloc() was not interrupt or thread safe. 2015-09-09 14:54:02 +00:00
skarg b4ad2c2729 Added Wireshark extcap command line parameter interface to mstpcap utility.
Tested with Wireshark on Windows (mostly working).
To use extcap, run Wireshark and go to the About-dialog.  Find a tab located there named "Folders". Locate the extcap search path. Copy the mstpcap.exe to that folder, which may not exist.
Restart Wireshark, and look for "BACnet MS/TP on COMx" interfaces.
Configure the interface to change baud rate.
Capture directly from the interface.
2015-07-14 20:31:32 +00:00
skarg 6cb014ee64 Changed the Linux BACnet/IP init to use NetMask.
The function was modified to calculate the broadcast address from IP and netmask instead of using SIOCGIFBRDADDR. In some cases it is possible that the ioctl is successful, but the returned address is 0 (e.g. search for Bcast: 0.0.0.0). For some reason in Linux the local loopback device answers from 0.0.0.0 address. So messages broadcast to that address are received from 127.0.0.1 which can possibly create a broadcast loop. This has nothing to do with NAT, but makes the stack more robust. Thank you, Sami Pietikäinen, for the contribution!
2015-02-24 21:55:31 +00:00
skarg 781da0b53b Fixed MSTP dropped packets on Linux by fixing usage of ptheads condition variable. Turns out that condition variables cannot be used on their own. They need to be paired with a shared state such as a flag variable protected by a mutex. 2014-11-15 22:03:17 +00:00
skarg aa124bc091 updated mstpsnap utility 2014-11-15 17:27:27 +00:00
skarg 66f52e438f added some more debug to RS485 on Linux 2014-11-02 05:29:42 +00:00
skarg 3fca74bcfb When MAC address length is zero, assume it is a broadcast. Updated the MS/TP to understand this. 2014-11-02 05:27:14 +00:00
skarg 92559791ba updated linux rs485 functional test to compile and run 2013-12-23 19:36:32 +00:00
skarg b3b3b8eca6 While trying to compile mstpsnap, Joe got a compile time failure. Adding fifo.c to the mstpsnap.mak file seems to have resolved GCC's complaint, and mstpsnap seems to be functioning. Thanks, Joe! 2013-10-31 16:24:05 +00:00
skarg 56b65e9694 indented using indent.sh script. 2013-10-29 01:55:49 +00:00
skarg 5f3cba01fe removed old example file since demo applications supersede it. 2013-07-12 16:42:20 +00:00
ekh 15fe7e56c2 Allow compilation of BACnet/IP demos in Cygwin in Windows 2013-05-10 19:24:26 +00:00
skarg ba3242aafd indented using indent.sh script to get uniform looking code for release 2013-03-13 22:17:13 +00:00
skarg 11897368d2 converted C++ comments using script 2013-03-13 22:13:28 +00:00
skarg cf882642a8 Changed Ringbuf API: Ringbuf_Pop_Front is now Ringbuf_Pop, and now it copies the buffer into parameter and returns boolean. Original method was not safe since it returned a pointer to the element but freed the buffer element. Changed Ringbuf_Get_Front to Ringbuf_Peek with no change in functionality, to make names more consistent.
Updated all the MS/TP datalink layer implementations that use Ringbuf library.
2013-01-08 20:48:34 +00:00
skarg 4c0599f104 cleaned up some warnings and errors when compiled for MS/TP on Linux 2012-12-16 04:42:22 +00:00
skarg 6facc07c74 Fixed 76800 setting for Linux rs-485. 2012-10-23 18:16:32 +00:00
skarg 2f1dad9e29 fixed compile error. 2012-09-27 22:03:19 +00:00
skarg 5aa78916ae Fixed Nikola Jelic's name in comments, originally written in Cyrillic script. 2012-09-27 19:24:50 +00:00
skarg 5920a624b3 Added 76800 baud support on Linux port of RS-485 driver. Thank you, Nikola Jelic! 2012-09-27 19:22:57 +00:00
vasyl-tkhir 2f73bcae44 BACnet router added. 2012-09-27 14:36:11 +00:00
skarg a51298876f changed public function from static in Linux port of BACnet/IP. 2012-05-22 19:29:00 +00:00
skarg 48e2c60ce2 indented to standard from script 2012-05-13 15:07:12 +00:00
skarg 9e8c2b0927 Added explicit datalink_cleanup to all demo applications.
Moved bip_cleanup() to port specific files.
This works better for bacnet-stack DLLs.
2012-02-10 22:12:15 +00:00
skarg 0f0c41d347 Added usleep for Tturnaround time before RS485 Transmit. Added tcdrain to wait for write to have written before returning. Thank you, Nikola Jelic! 2012-01-21 01:46:46 +00:00
skarg 087584e85e Corrected baud rate setting for mstpcap demo utility. Thank you, Michael D! 2011-11-26 16:32:17 +00:00
skarg 109bfed70d Updated makefile for mstpsnap. 2011-11-17 03:03:33 +00:00
skarg 81a3ec52e5 Updated file to correct compiler errors and warnings. 2011-11-17 03:02:51 +00:00
skarg 3641e7b40c Updated some Device_Init functions. 2011-10-04 15:57:40 +00:00
skarg 9f0dfeed1c Fixed Linux datalink call to Master Node FSM which was not doing immediate transitions, and could lose whole messages. Thank you, Nikola Jelic! 2011-09-02 14:35:16 +00:00
skarg 26b5fdd3d0 Returned Tusage_delay to the MS/TP state machines to fix excessive Reply-Posponed messages when received packet is decoupled from immediate handling. Some BACnet routers do not handle Reply-Postponed correctly and drop the subsequent valid reply.
Added Slave Node FSM to linux/win32 MS/TP layer.
Added PDU queue to Linux MS/TP datalink layer.
2011-08-24 12:33:20 +00:00
skarg 2f008a9a2b No need for sched_yield in master_fsm_task due to select in getting the byte. No need for Timer_Mutex since only one task ever uses timer functions. Thank you, Nikola Jelic! 2011-08-19 18:05:45 +00:00
skarg 7f109b0abe Corrected compile errors. 2011-08-19 17:40:29 +00:00
skarg 0fe647a678 removed Reader_Mutex, IOMutex, rs485_read_task and placed select inside of getting characters call to reduce CPU usage. 2011-08-19 16:33:07 +00:00
skarg 3e1cb1847f Indented project. 2011-08-17 02:27:11 +00:00
skarg b863996349 Added yield to lower CPU usage when no characters are arriving. 2011-05-10 22:00:32 +00:00
skarg e85ab0b49f Changed RS-485 in linux port to use FIFO instead of Ringbuffer. Added FIFO to library build. 2011-05-10 16:29:49 +00:00
skarg 1d4e487b29 Adjusted for linux builds without RS485 specific terminal I/O settings. 2011-05-10 15:52:52 +00:00