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
130 stars 69 forks source link

Command FILE_TRANSFER (0x7C) sending frame larger than reader max buffer size #102

Closed etorresmn closed 1 year ago

etorresmn commented 1 year ago

When sending the command OSDP_CMD_FILE_TX after previously had registered a file transfer operation with osdp_file_register_ops the frame sent to the PD is larger than the max capacity of the buffer indicated by PDCAP.

For a reader with the following reported capability: osdp: CP: DEBUG: Reports capability 'ReceiveBufferSize' (194/1)

Expected behavior: The expected behavior is to send a FILETRANSFER frame with size of fragment field value <= (194 - frame header), something like FF 53 00 F2 00 05 7C 01 B4 AF 03 00 00 00 00 00 AF 00 0E 83 03

Observed behavior: A command frame of size 0xF2 (242) and fragment size of DF (223) is sent which is bigger than the reader's receive buffer size FF 53 00 F2 00 05 7C 01 B4 AF 03 00 00 00 00 00 DF 00 0E 83 03

After sending this frame the reader does not reply and a timeout happens, most probably because the frame is received incomplete by the reader and discarded

The issue is reproducible 100% of the times

Here is a log with additional prints intended for debugging

osdp: CP: INFO : Setup complete; PDs:1 Channels:1 - libosdp-2.2.0 master (ec9558e)
FF 53 00 08 00 04 60 EB AA 
Size: 9
Received: FF FF 53 80 08 00 04 40 59 AC 
FF 53 00 09 00 05 61 00 F0 51 
Size: 10
Received: FF FF 53 80 14 00 05 45 5C 26 23 14 10 00 03 08 CC 04 00 04 3A 41 
osdp: CP: DEBUG: CMD: ID(61) REPLY: PDID(45)
FF 53 00 09 00 06 62 00 F3 5D 
Size: 10
Received: FF FF 53 80 29 00 06 46 03 01 01 04 04 01 05 02 01 06 00 00 07 00 00 08 01 00 09 01 01 0A C2 01 
Received: 0E 00 00 0F 00 00 10 01 00 80 F1 
osdp: CP: DEBUG: Reports capability 'CardDataFormat' (1/1)
osdp: CP: DEBUG: Reports capability 'LEDControl' (4/1)
osdp: CP: DEBUG: Reports capability 'AudibleControl' (2/1)
osdp: CP: DEBUG: Reports capability 'TextOutput' (0/0)
osdp: CP: DEBUG: Reports capability 'TimeKeeping' (0/0)
osdp: CP: DEBUG: Reports capability 'CheckCharacter' (1/0)
osdp: CP: DEBUG: Reports capability 'CommunicationSecurity' (1/1)
osdp: CP: DEBUG: Reports capability 'ReceiveBufferSize' (194/1)
osdp: CP: DEBUG: Reports capability 'Biometric' (0/0)
osdp: CP: DEBUG: CMD: CAP(62) REPLY: PDCAP(46)
FF 53 00 08 00 07 60 B8 FF 
Size: 9
Received: FF FF 53 80 08 00 07 40 0A F9 
FF 53 00 08 00 05 60 DA 99 
Size: 9
Received: FF FF 53 80 08 00 05 40 68 9F 
FF 53 00 08 00 06 60 89 CC 
Size: 9
Received: FF FF 53 80 08 00 06 40 3B CA 
FF 53 00 08 00 07 60 B8 FF 
Size: 9
Received: FF FF 53 80 08 00 07 40 0A F9 
FF 53 00 08 00 05 60 DA 99 
Size: 9
Received: FF FF 53 80 08 00 05 40 68 9F 
FF 53 00 08 00 06 60 89 CC 
Size: 9
Received: FF FF 53 80 08 00 06 40 3B CA 
FF 53 00 08 00 07 60 B8 FF 
Size: 9
Received: FF FF 53 80 08 00 07 40 0A F9 
FF 53 00 08 00 05 60 DA 99 
Size: 9
Received: FF FF 53 80 08 00 05 40 68 9F 
FF 53 00 08 00 06 60 89 CC 
Size: 9
Received: FF FF 53 80 08 00 06 40 3B CA 
FF 53 00 08 00 07 60 B8 FF 
Size: 9
Received: FF FF 53 80 08 00 07 40 0A F9 
Registering FILE TX operations
Starting file transfer!
osdp: FOP: INFO : TX_init: Starting file transfer of size: 241588
FF 53 00 F2 00 05 7C 01 B4 AF 03 00 00 00 00 00 DF 00 0E 83 03 AF AF 1F 83 03 AF A6 0A 14 57 57 4D 4E 7D 49 30 32 3C 81 8E 9E B2 DC CE 31 00 03 AF 8F 0D DF 2B E0 EB 88 25 D0 A4 FA FB 35 00 9D 64 23 6F 5A D6 68 2F E0 47 9C 4C 7F 3A 7C 2A 18 17 6F 9E 23 10 D7 74 B4 94 8F 13 89 2D 1C 2E 78 29 CC DF 77 0B 58 F0 1A 73 4B 3E 1C F5 69 64 BF 3C 43 F6 90 FA D5 7D 2A A7 17 61 58 81 68 0A 03 1B 74 56 5B 22 65 82 80 A2 E0 43 7D 9F C9 B3 04 68 3F F1 CB 51 90 AE 69 CE FF 9C 15 B0 76 7F 0D DF 63 26 3F 3E 64 0C 3A C7 23 83 B9 48 1B 69 6F 8E 48 72 88 A0 7A D0 CD 1C 63 97 64 E9 00 6B 9C 39 C8 0A D1 79 41 81 44 99 F5 43 28 E7 E2 D4 71 D1 1D BD AE 94 A3 DC 2A D3 86 C2 0B BB FB 0B 49 7D 25 D0 95 75 35 85 D1 98 7A 48 59 BD 3F 38 40 A8 75 ED 
Size: 243
Received: 
Received: 
Received: 
Received: 
osdp: CP: ERROR: Response timeout for CMD(7c)
sidcha commented 1 year ago

That is not surprising, pd->peer_rx_size is not used by both sides. Will take a look at this later this weekend.