📄 xmodem.doc
字号:
and one using the new CRC protocol. An initial handshake was added tosolve this problem. The handshake allows a receiving program with CRCcapability to determine whether the sending program supports the CRCoption, and to switch it to CRC mode if it does. This handshake isdesigned so that it will work properly with programs which implementonly the original protocol. A description of this handshake ispresented in section 10.-------- 8. MESSAGE BLOCK LEVEL PROTOCOL, CRC MODE Each block of the transfer in CRC mode looks like:<SOH><blk #><255-blk #><--128 data bytes--><CRC hi><CRC lo> in which:<SOH> = 01 hex<blk #> = binary number, starts at 01 increments by 1, and wraps 0FFH to 00H (not to 01)<255-blk #> = ones complement of blk #.<CRC hi> = byte containing the 8 hi order coefficients of the CRC.<CRC lo> = byte containing the 8 lo order coefficients of the CRC. See the next section for CRC calculation.-------- 9. CRC CALCULATION---- 9A. FORMAL DEFINITION OF THE CRC CALCULATIONTo calculate the 16 bit CRC the message bits are considered to be thecoefficients of a polynomial. This message polynomial is firstmultiplied by X^16 and then divided by the generator polynomial(X^16 + X^12 + X^5 + 1) using modulo two arithemetic. The remainderleft after the division is the desired CRC. Since a message block inthe Modem Protocol is 128 bytes or 1024 bits, the message polynomialwill be of order X^1023. The hi order bit of the first byte of themessage block is the coefficient of X^1023 in the message polynomial.The lo order bit of the last byte of the message block is thecoefficient of X^0 in the message polynomial.---- 9B. EXAMPLE OF CRC CALCULATION WRITTEN IN C/*This function calculates the CRC used by the "Modem Protocol"The first argument is a pointer to the message block. The secondargument is the number of bytes in the message block. The messageblock used by the Modem Protocol contains 128 bytes.The function return value is an integer which contains the CRC. Thelo order 16 bits of this integer are the coefficients of the CRC. TheThe lo order bit is the lo order coefficient of the CRC.*/int calcrc(ptr, count) char *ptr; int count; { int crc, i; crc = 0; while(--count >= 0) { crc = crc ^ (int)*ptr++ << 8; for(i = 0; i < 8; ++i) if(crc & 0x8000) crc = crc << 1 ^ 0x1021; else crc = crc << 1; } return (crc & 0xFFFF); }-------- 10. FILE LEVEL PROTOCOL, CHANGES FOR COMPATIBILITY---- 10A. COMMON TO BOTH SENDER AND RECEIVER:The only change to the File Level Protocol for the CRC option is theinitial handshake which is used to determine if both the sending andthe receiving programs support the CRC mode. All Modem Programs shouldsupport the checksum mode for compatibility with older versions.A receiving program that wishes to receive in CRC mode implements themode setting handshake by sending a <C> in place of the initial <nak>.If the sending program supports CRC mode it will recognize the <C> andwill set itself into CRC mode, and respond by sending the first blockas if a <nak> had been received. If the sending program does notsupport CRC mode it will not respond to the <C> at all. After thereceiver has sent the <C> it will wait up to 3 seconds for the <soh>that starts the first block. If it receives a <soh> within 3 secondsit will assume the sender supports CRC mode and will proceed with thefile exchange in CRC mode. If no <soh> is received within 3 secondsthe receiver will switch to checksum mode, send a <nak>, and proceedin checksum mode. If the receiver wishes to use checksum mode itshould send an initial <nak> and the sending program should respond tothe <nak> as defined in the original Modem Protocol. After the modehas been set by the initial <C> or <nak> the protocol follows theoriginal Modem Protocol and is identical whether the checksum or CRCis being used.---- 10B. RECEIVE PROGRAM CONSIDERATIONS:There are at least 4 things that can go wrong with the mode settinghandshake. 1. the initial <C> can be garbled or lost. 2. the initial <soh> can be garbled. 3. the initial <C> can be changed to a <nak>. 4. the initial <nak> from a receiver which wants to receive in checksum can be changed to a <C>.The first problem can be solved if the receiver sends a second <C>after it times out the first time. This process can be repeatedseveral times. It must not be repeated a too many times before sendinga <nak> and switching to checksum mode or a sending program withoutCRC support may time out and abort. Repeating the <C> will also fixthe second problem if the sending program cooperates by responding asif a <nak> were received instead of ignoring the extra <C>.It is possible to fix problems 3 and 4 but probably not worth thetrouble since they will occur very infrequently. They could be fixedby switching modes in either the sending or the receiving programafter a large number of successive <nak>s. This solution would riskother problems however.---- 10C. SENDING PROGRAM CONSIDERATIONS.The sending program should start in the checksum mode. This willinsure compatibility with checksum only receiving programs. Anytime a<C> is received before the first <nak> or <ack> the sending programshould set itself into CRC mode and respond as if a <nak> werereceived. The sender should respond to additional <C>s as if they were<nak>s until the first <ack> is received. This will assist thereceiving program in determining the correct mode when the <soh> islost or garbled. After the first <ack> is received the sending programshould ignore <C>s.-------- 11. DATA FLOW EXAMPLES WITH CRC OPTION---- 11A. RECEIVER HAS CRC OPTION, SENDER DOESN'THere is a data flow example for the case where the receiver requeststransmission in the CRC mode but the sender does not support the CRCoption. This example also includes various transmission errors.<xx> represents the checksum byte.SENDER RECEIVER <--- <C> times out after 3 seconds, <--- <nak><soh> 01 FE -data- <xx> ---> <--- <ack><soh> 02 FD -data- <xx> ---> (data gets line hit) <--- <nak><soh> 02 FD -data- <xx> ---> <--- <ack><soh> 03 FC -data- <xx> ---> (ack gets garbaged) <--- <ack> times out after 10 seconds, <--- <nak><soh> 03 FC -data- <xx> ---> <--- <ack><eot> ---> <--- <ack>---- 11B. RECEIVER AND SENDER BOTH HAVE CRC OPTIONHere is a data flow example for the case where the receiver requeststransmission in the CRC mode and the sender supports the CRC option.This example also includes various transmission errors.<xxxx> represents the 2 CRC bytes.SENDER RECEIVER <--- <C><soh> 01 FE -data- <xxxx> ---> <--- <ack><soh> 02 FD -data- <xxxx> ---> (data gets line hit) <--- <nak><soh> 02 FD -data- <xxxx> ---> <--- <ack><soh> 03 FC -data- <xxxx> ---> (ack gets garbaged) <--- <ack> times out after 10 seconds, <--- <nak><soh> 03 FC -data- <xxxx> ---> <--- <ack><eot> ---> <--- <ack>-- Dave Ihnat Analysts International Corporation (312) 882-4673 ihnp4!aicchi!ignatz----------XMODEM SOURCES-------Ward's/CBBS at 312-849-1132XMODEM-CRC document 1/13/85 by John Byrns. Voice: 312-885-1105Dave Ihnat, Analysts International Corporation : 312-882-4673ihnp4!aicchi!ignatzProtocall docs are also available from:Chuck Forsberg WA7KGXtektronix!reed!omen!caf Omen Technology Inc "The High Reliability Software"17505-V Northwest Sauvie Island Road Portland OR 97231 Voice: 503-621-3406TeleGodzilla BBS: 621-3746 2400/1200 CIS:70007,2304 Genie:CAFSource:TCE022omen Any ACU 1200 1-503-621-3746 se:--se: link ord: Giznoid in:--in: uucpomen!/usr/spool/uucppublic/FILES lists all uucp-able files, updated hourly
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -