YModem protocol learning

Posted by markjia on Sun, 03 May 2020 16:44:28 +0200

YModem transmission mode: YModem, YModem-1K, YModem-g.
In YModem-1k, the standard 128 byte transmission is replaced by 124 byte information fast transmission, and CRC teaching and research is used to ensure the accuracy of data transmission.
YModem-g cancels the CRC check code of the data, and after sending a data block information, it will not wait for the ACK signal of the acceptance degree egg, but directly transmits the next data block.
Generally speaking, it is YModem or YModem-1K.

1. Start frame format

SOH 00 FF filename[] filesize[] NULL[] CRCH CRCL

SOH 00 FF is the frame header, the middle is 128 bytes of data, and the tail is 16 bit CRC verification.
SOH: 0x01 indicates that the data frame contains 128 bytes
00: refers to the serial number of data frame. The starting frame is 00 and the first town is 01
FF: reverse frame number
Filename: followed by 00 means the end of the filename, such as foo.c, 66 6F 6F 2E 63 00
File size: the size of the file followed by 00 indicates the end of the file. For example, 1024Byte, 34 30 30 00, or 0x400
NULL: 128 bytes of data, excluding file name and file size, the remaining bytes are filled with 00
CRC: calculate data area only

2 data frame format

STX 01 FE data[1024] CRCH CRCL

STX:0x02 indicates that the data frame contains 1024 bytes of data
01: first frame data
Reverse of FE: 01
Data: 1024 bytes of data
CRC: verification code of 1024 byte data
If the last sound of the file data is between 128 and 1024, then Korean uses 1024 bytes of STX for transmission, but the remaining space is filled with 0x1A:

STX num -num data[] 1A...1A CRCH CRCL

If the file size is less than 128 bytes, the SOH data frame will be used for transmission, and the rest less than 128 bytes will be filled with 0x1A.

SOH 01 FE data[] 1A...1A CRCH CRCL

If the data of the last frame of the file is less than 128 bytes.

SOH num ~num data[] 1A...1A CRCH CRCL

3 end frame data structure

SOH128 byte data frame is also used for the ending frame data, and the structure is as follows:

SOH 00 ff NUM[128] CRCH CRCL

The end frame data is filled with 00.

4 file transfer process

Suppose there is a file foo.c with the size of 4196Byte and 0x1064 bytes. The transmission process is as follows:

Sender                                     receiving end
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   C   //Receiver sends uppercase lettersCStart transfer
SOH 00 FF "foo.c" 1064 NUL[118] CRCH CRCL>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   ACK  
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   C  //Received0After frame data, feedbackACK as well asCStart first frame transmission
STX 01 FE data[1024] CRCH CRCL>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   ACK
STX 02 FD data[1024] CRCH CRCL>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   ACK
STX 03 FC data[1024] CRCH CRCL>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   ACK
STX 04 FB data[1024] CRCH CRCL>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   ACK
SOH 05 FA data[100] 1A[28] CRCH CRCL>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   ACK
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<  NAK
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<  ACK
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<  C
SOH 00 FF NUL[128] CRCH CRCL>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<  ACK

Signal data and meaning are as follows

Symbol numerical value Meaning
SOH 0x01 128 byte data
STX 0x02 1024 bytes of data
EOT 0x04 End transfer
ACK 0x06 Respond
NAK 0x15 No response
CA 0x18 Transmission aborted
C 0x43 Request packet

CA abort transmission signal sent by sender

Topics: less REST