JoelBender / bacpypes

BACpypes provides a BACnet application layer and network layer written in Python for daemons, scripting, and graphical interfaces.
MIT License
296 stars 128 forks source link

Max APDU not segmenting correct #498

Open KlausHammer opened 1 year ago

KlausHammer commented 1 year ago

Hi,

If i take the example code Sample4_RandomAnalogValueObject.py, and change RANDOM_OBJECT_COUNT = int(os.getenv('RANDOM_OBJECT_COUNT', 10)) to RANDOM_OBJECT_COUNT = int(os.getenv('RANDOM_OBJECT_COUNT', 400))

And in the .ini file set maxApduLengthAccepted to 480, YABE can see that the max APDU length is 480, but when i read the the DeviceObject, it does not look like the message is segmentet properly. image

From WireShark when a read request on object-list is requested, it first sends a total of 1481 bytes in message 1, image

and 543 bytes in message two. image

Should it not segment the message into multiple messages with a max length of 480 bytes? Or am i missing something? No matter what i change maxApduLengthAccepted to, it behaves the same.

Hope you can help!

KlausHammer commented 1 year ago

So after digging around in the code, it seems that the segmentation happens in appservice.py in the ServerSSM class on line 793: if (apdu.apduType == ComplexAckPDU.pduType):

If i manually change self.segmentSize = self.maxApduLengthAccepted

to self.segmentSize = 480

It now segments the apdu to a size of 485, so i now have 2 question.

  1. How do i provide the device_info information correctly to the ServerSSM class, so it can use the maxapdulengthaccepted defined in the deviceobject?
  2. How come it send 5 bytes more then the max APDU size. That explains why i received 1481 bytes before, when it should limited it to 1476 which is the max apdu size for BACnet.