Protocols

From Ninerpedia
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

XModem protocol

The XModem protocol transmits data in a sequence of blocks. Each block contains a part of the file to be transmitted.

Block Block Block ... Block

The last block may require padding if the number of remaining bytes does not suffice to fill the block.

Each block contains a sequence number. When a block with the same number as the previous one is received, the receiver accepts the block for the same position and sends back an ACK (0x06). This situation may have been caused by a previously lost ACK. If the block number is not the expected next one or a repetition of the recent one, the sequence is out of sync, and the receiver shall send a CAN (0x18) in order to terminate the protocol.

Sender sending Block Block ... Block EOT (04)
Receiver sending NAK (15) ACK (06) ACK (06) ... ACK (06) ACK (06)

The receiver has a timeout of 10 seconds, after which it transmits a NAK (0x15). The message sequence starts with the receiver sending the first timeout NAK to the sender, which may be sent immediately. All errors are retried for at most 10 times.

A NAK must be sent by the receiver if the block data are invalid.

Standard XModem

Each block is defined in this way (numbers tell the number of bytes for each field):

1 1 1 128 1
SOH (01) Number /Number Data bytes Checksum

The number is a sequence number which increases by one for each successive block. The first block starts at 1. The /Number field is the one's complement of the Number field and calculates as 255-Number. When the number reaches 256 it is reset to 0.

The checksum field contains the least significant byte of the sum of the data bytes of this block.

XModem/CRC

In this variant, a more powerful checksum algorithm is used, the CRC16 algorithm. In order to negotiate this variant for both sender and receiver, the receiver sends a "C" as the first message instead of the NAK.

Sender sending Block Block ... Block EOT
Receiver sending "C" (43) ACK ACK ... ACK ACK

If the sender does not support XModem/CRC it keeps silent, and the receiver shall retry for some time. After that it sends a NAK to switch back to normal XModem.

The blocks have this layout:

1 1 1 128 2
SOH Number /Number Data bytes CRC16

In general it is reasonable to have the sender start in CRC mode and wait for the receiver's first message.

XModem-1K

XModem-1K is a variation of XModem with 1K (1024) bytes for each data block. As a recommendation, XModem-1k should only be used with CRC, and most implementations enforce this.

1 1 1 1024 2
STX (02) Number /Number Data bytes CRC

The sender may switch between 128-byte and 1024-byte blocks after receiving an ACK from the receiver. The sender should start with 1K blocks and check for the receiver's response, either as NAK or ACK. Note that a sender does not switch if the previous response was a NAK.