From b86f709e151ee39ac86c1fffc616663bb5544aa1 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 15 Apr 2020 06:16:39 +1000 Subject: [PATCH] Fix ZMODEM transfers with systems that dont send for HEX headers. It seems many ZMODEM implementations dont check for this. --- src/ls_zmodem.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/ls_zmodem.c b/src/ls_zmodem.c index e4f3baf..e340964 100644 --- a/src/ls_zmodem.c +++ b/src/ls_zmodem.c @@ -207,7 +207,8 @@ int ls_zrecvhdr(byte *hdr, int *hlen, int timeout) rhBYTE, rhCRC, rhCR, - rhLF + rhLF, + rhXON } state = rhInit; static enum rhREADMODE { rm8BIT, @@ -368,7 +369,7 @@ int ls_zrecvhdr(byte *hdr, int *hlen, int timeout) state = rhBYTE; break; case rhBYTE: - DEBUG(('Z',2,"ls_zrecvhdr: rhBYTE: %02x",c)); + DEBUG(('Z',2,"ls_zrecvhdr: rhBYTE: %02x (%d)",c,got)); hdr[got] = c; if(++got == len) { state = rhCRC; @@ -435,6 +436,11 @@ int ls_zrecvhdr(byte *hdr, int *hlen, int timeout) break; case LF: case LF|0x80: /* Ok, UNIX-like EOL */ + state = rhXON; + break; + case XON: + case XON|0x80: + DEBUG(('Z',1,"ls_zrecvhdr: rhCR, got XON without CR/LF?")); return frametype; default: return LSZ_BADCRC; @@ -446,8 +452,27 @@ int ls_zrecvhdr(byte *hdr, int *hlen, int timeout) switch(c) { case LF: case LF|0x80: + state = rhXON; + break; + default: + return LSZ_BADCRC; + } + break; + case rhXON: + state = rhInit; + DEBUG(('Z',2,"ls_zrecvhdr: rhXON")); + switch(c) { + case ZPAD: + case ZPAD|0x80: + state = rhZPAD; + got = 0; + crcgot = 0; + break; + case XON: + case XON|0x80: return frametype; default: + DEBUG(('Z',2,"ls_zrecvdata: rhXON unexpcted %x (%c)",c,(char)c)); return LSZ_BADCRC; } break;