Commit Graph

51 Commits

Author SHA1 Message Date
Valerio De Benedetto
0234a563c1 Fixes to potential buffer overflows on received data 2024-02-08 11:31:48 +01:00
Valerio De Benedetto
dde2653cb8 WIP buffer overflow on received data 2024-02-08 10:00:50 +01:00
Ali Moallem
8518842709 Fix callback argument in nanomodbus.c 2023-12-06 10:09:46 +03:30
Hossein.M
8aca15dfc9 Add argument for callbacks structure 2023-12-06 10:03:29 +03:30
Valerio De Benedetto
7550fe9587 Fixes after FC23 merge 2023-08-14 20:50:49 +02:00
maxlemo
e3b13ccdd1 adds fc23 server code 2023-08-02 11:11:14 -04:00
maxlemo
5991219763 add fc23 2023-08-02 10:57:17 -04:00
Vyacheslav Verkhovin
8dafc721fa Add registers count checking for file_read and file_write operations
MODBUS Application Protocol Specification does not require it explicitly
but without this checking PDU of a request or response may exceed 253 bytes.
2023-07-14 00:54:49 +07:00
Valerio De Benedetto
bd302660b6 Merge remote-tracking branch 'arhiv6/file_record' 2023-07-13 09:04:27 +02:00
Valerio De Benedetto
e3456986b5 Using VLA where possible 2023-07-11 14:07:55 +02:00
Arne Hoch
b884081eff FIX incorrect calculation of payload bytes 2023-07-11 13:52:42 +02:00
Vyacheslav Verkhovin
d391300654 Fixed function handle_read_file_record() logic according to specification
According to MODBUS specification we must finish checking all checks
before starting processing subrequests.
2023-07-06 19:43:20 +07:00
Valerio De Benedetto
ae6a93c963 Changes for SDCC 3.9.0 compatibility, part 2 2023-07-06 08:14:25 +02:00
Valerio De Benedetto
a08d59c5f0 Changes for SDCC 3.9.0 compatibility 2023-07-03 16:47:26 +02:00
Valerio De Benedetto
2e36f024bc Various fixes 2023-06-30 10:49:05 +02:00
Vyacheslav Verkhovin
e5b51cc4e7 Add File Records functions
Add both File Records functions (0x14 Read and 0x15 Write) for Client
and Server roles. Also, add a little tests and example.

Resolves: [#1] and [#24]
2023-06-30 10:11:32 +07:00
Valerio De Benedetto
2da601fd80 RTU unit_id in server callbacks 2023-06-26 13:18:24 +02:00
Valerio De Benedetto
44f3191735 Minor fixes 2023-06-01 18:29:23 +02:00
Valerio De Benedetto
0d6a5274f3 Various fixes 2023-05-25 12:16:17 +02:00
Valerio De Benedetto
f8f8fd00b1 Handling foreign RTU messages 2023-05-16 16:38:04 +02:00
Jan Weiß
f7dfbd94ab Fix Clang static analyser nit: zero out nmbs_bitfield structs. 2023-04-17 18:44:59 +02:00
Valerio De Benedetto
920d25858d Rename of DEBUG() macro to NMBS_DEBUG_PRINT() 2023-03-15 15:12:33 +01:00
Valerio De Benedetto
8493fc5267 Refactoring of NMBS_*_DISABLED defines 2023-03-15 15:08:18 +01:00
Valerio De Benedetto
f70fbd5260 Endianness-independent code 2023-03-13 12:30:32 +01:00
Valerio De Benedetto
98814d2a66 Formatting 2022-12-28 15:05:56 +01:00
Valerio De Benedetto
c654babb52 clang-tidy 2022-12-28 15:02:51 +01:00
Valerio De Benedetto
f2b6ddda71 Fix to data pointer type of raw_pdu functions 2022-12-28 14:10:06 +01:00
Antonio Aguilera
fa02201710 Fix Wswitch-enum and Wcast-qual compiler warnings
The function nmbs_strerror does not handle the error code
NMBS_ERROR_INVALID_UNIT_ID inside the switch statement, which triggers
the GCC/Clang Wswitch-enum warning. Adding a new case inside the switch
statement solves this warning.

There is a cast from a const void pointer to an uint8_t pointer inside
the function nmbs_send_raw_pdu, which triggers the GCC/Clang Wcast-qual
warning. Adding the missing const qualifier solves this warning.
2022-12-27 20:42:36 +01:00
jonath.re@gmail.com
70c75cb2db Convert get_ and put_ to functions
This shaves off about 1 kB of flash usage from my client application.
It is also more type safe, which is nice.
2022-07-29 12:19:42 +02:00
Valerio De Benedetto
fd101fe77f Various fixes to NMBS_SERVER_* defines handling 2022-07-25 15:17:47 +02:00
Valerio De Benedetto
c12ba4b8a3 Merge branch 'callback-arg'
# Conflicts:
#	nanomodbus.c
#	nanomodbus.h
2022-07-25 12:59:40 +02:00
Valerio De Benedetto
5b685c9d97 Minor fixes 2022-07-25 12:47:11 +02:00
jonath.re@gmail.com
80fa8ef4ae Send platform argument to nmbs_callbacks
This is useful for the same reasons as the arg is useful in the platform callbacks.
2022-07-22 19:19:04 +02:00
jonath.re@gmail.com
17aa0ca226 Support disabling individual server callbacks
This helps reduce code size for systems that do not implement the full
set of function codes supported by the library.
2022-07-22 17:14:32 +02:00
Valerio De Benedetto
10b9a0c13b NMBS_ERROR_INVALID_TCP_MBAP on invalid transaction ID 2022-06-26 11:10:29 +02:00
Valerio De Benedetto
037de71d9b Returning NMBS_ERROR_INVALID_UNIT_ID in case of invalid unit ID in response 2022-06-26 11:08:16 +02:00
jonath.re@gmail.com
f22b06082e Expose the function that calculates CRC
Having access to this function is useful in a variety of cases:

- hand-crafting PDUs for unit tests
- implementing extensions of the protocol
- reusing the code for other purposes (e.g. firmware integrity check)
2022-06-25 17:17:34 +02:00
Valerio De Benedetto
ca0dd3bab3 Merge remote-tracking branch 'jonathangjertsen/update-helper-names' 2022-06-11 16:16:19 +02:00
Jonathan Reichelt Gjertsen
4393c4a8a0 Update names of helper functions to show whether they call send or put_1/put_2
I think this makes the code easier to read, since you can tell whether each
function call will actually `send` some bytes over the wire, or if it will
just `put` some bytes into the buffer.
2022-06-07 20:09:17 +02:00
Jonathan Reichelt Gjertsen
249c4f3919 Sometimes it's useful to turn NMBS_DEBUG on, but the output is a bit of a mess if the read/write callbacks also log to the same channel. Moving the DEBUG statements in recv_msg_footer and send_msg_footer to the start of the function makes the output a bit cleaner, although it's not perfect.
Example output before this change:

```
NMBS req -> fc 16   a 12326 q 2     b 4     regs 4660 43981 transmitted[13] = { f7, 10, 30, 26, 00, 02, 04, 12, 34, ab, cd, c2, 04, }

received[1] = { 0xf7, }
received[1] = { 0x10, }
NMBS res <- fc 16   received[4] = { 0x30, 0x26, 00, 0x2, }
a 12326     q 2received[2] = { 0xbb, 0x95, }

NMBS req -> fc 3    a 12326 q 2 transmitted[8] = { f7, 03, 30, 26, 00, 02, 3e, 56, }

received[1] = { 0xf7, }
received[1] = { 0x3, }
NMBS res <- fc 3    received[1] = { 0x4, }
b 4 received[4] = { 0x12, 0x34, 0xab, 0xcd, }
regs 466043981received[2] = { 0x96, 0x2f, }
```

after:

```
NMBS req -> fc 16   a 12326 q 2     b 4     regs 4660 43981
transmitted[13] = { f7, 10, 30, 26, 00, 02, 04, 12, 34, ab, cd, c2, 04, }
received[1] = { 0xf7, }
received[1] = { 0x10, }
NMBS res <- fc 16   received[4] = { 0x30, 0x26, 00, 0x2, }
a 12326     q 2
received[2] = { 0xbb, 0x95, }
NMBS req -> fc 3    a 12326 q 2
transmitted[8] = { f7, 03, 30, 26, 00, 02, 3e, 56, }
received[1] = { 0xf7, }
received[1] = { 0x3, }
NMBS res <- fc 3    received[1] = { 0x4, }
b 4 received[4] = { 0x12, 0x34, 0xab, 0xcd, }
regs 466043981
received[2] = { 0x96, 0x2f, }
```
2022-06-07 19:52:40 +02:00
Valerio De Benedetto
53da24091b Added __AVR_ARCH__ endianness check 2022-06-02 22:39:30 +02:00
Valerio De Benedetto
7e6ce4f4fd Fixes 2022-06-02 21:58:21 +02:00
Valerio De Benedetto
83fb04392b Fixes to integer types 2022-06-02 11:52:10 +02:00
Valerio De Benedetto
b6fee48160 Switch to multibyte transport read/write funcs, removed sleep 2022-06-02 10:53:32 +02:00
Valerio De Benedetto
271f689771 Added NMBS_ERROR_CRC and NMBS_ERROR_INVALID_TCP_MBAP nmbs_error 2022-05-12 19:28:50 +02:00
Valerio De Benedetto
3904a6c52f Swapped RTU CRC byte order 2022-05-12 18:59:21 +02:00
Valerio De Benedetto
9d2918b3bb Switch to MIT license 2022-04-30 13:03:36 +02:00
Valerio De Benedetto
8fc65aa2cf Fixed wrong size field in MBAP header 2022-04-26 00:05:13 +02:00
Valerio De Benedetto
5358abde7b Support to NMBS_CLIENT_DISABLED and NMBS_SERVER_DISABLED defines 2022-04-24 13:53:40 +02:00
Valerio De Benedetto
ee6dd565d4 Added license headers 2022-01-25 16:35:19 +01:00