goToMain / libosdp

Implementation of IEC 60839-11-5 OSDP (Open Supervised Device Protocol); provides a C library with support for C++, Rust and Python3
https://libosdp.sidcha.dev
Apache License 2.0
128 stars 69 forks source link

Packet Size Limits #177

Closed jason155392 closed 2 months ago

jason155392 commented 2 months ago

Describe the bug Based on section "5.6 Packet Size Limits" should the size of "buf" in the function "osdp_channel_receive" also be adjusted to 128 bytes? And should the "buffer" in the structure "osdp_rb" also be adjusted to 1440 bytes?

sidcha commented 2 months ago

There are three levels of buffering going on here: one at the kernel level, and then two at the PD level in LibOSDP. osdp_channel_receive reads one chunk of 64 bytes at a time but can do this upto 8 times before the ring buffer overflows (512 bytes). Then this ring buffer is drained into a 256 byte buffer which is length of one packet supported by LibOSDP.

In essence, the only thing that really matters is OSDP_PACKET_BUF_SIZE which is currently set to 256 and seems reasonable for most use cases. All other numbers are just implementation details.

If you think 256 is too small, we can increase it.

5.6 Packet Size Limits:

[..] and be able to tolerate message addressed to other devices having a total length not exceeding 1440 bytes.

To support this clause, we can be smart and look into the packet header to see if this message was sent for some other PD and then mark and skip that many bytes from the channel (it's not implemented yet, but can be done trivially). This is just to avoid having to allocate a 1.5 KB buffer for no real reason.