diff --git a/lib/ymodem.c b/lib/ymodem.c index d44a80c..13c8e96 100644 --- a/lib/ymodem.c +++ b/lib/ymodem.c @@ -248,6 +248,7 @@ retry: rx->errors = 0; rx->seq = 1; + recv_bytes = 0; /* start to recv file contents */ fp = &rx->data[PACKET_HEADER]; for (;;) { @@ -311,7 +312,12 @@ retry: } if (rx->seq != rx->data[PACKET_SEQNO_INDEX]) { - put_byte(uart, NAK); + if (rx->data[PACKET_SEQNO_INDEX] == 0 && recv_bytes == 0) { /* YMODEM-1K only ? */ + put_byte(uart, ACK); + put_byte(uart, WANTCRC); + } else { + put_byte(uart, NAK); + } #ifdef YMODEM_DEBUG printf("data phase: seq mismatch %d, expected %d\n", rx->data[PACKET_SEQNO_INDEX], rx->seq); #endif diff --git a/lib/ymodem.h b/lib/ymodem.h index fc14516..d5faec5 100644 --- a/lib/ymodem.h +++ b/lib/ymodem.h @@ -26,6 +26,7 @@ extern "C" { #define NAK (0x15) /* negative acknowledge */ #define CA (0x18) /* two of these in succession aborts transfer */ #define WANTCRC (0x43) /* 'C' == 0x43, request 16-bit CRC */ +#define WANTG (0x47) /* 'G' == 0x47 */ #define ABORT1 (0x41) /* 'A' == 0x41, abort by user */ #define ABORT2 (0x61) /* 'a' == 0x61, abort by user */