Some zmodem fixes

This commit is contained in:
Michiel Broek 2006-02-20 09:55:23 +00:00
parent 2f779324e2
commit 8a8306083a
4 changed files with 57 additions and 32 deletions

View File

@ -23,6 +23,9 @@ v0.83.13 13-Feb-2006
mbsebbs: mbsebbs:
Writes LINES and COLUMNS environment into data.msg so that the Writes LINES and COLUMNS environment into data.msg so that the
joe editor can use that. joe editor can use that.
Changed zmodem transmitter timeout to 60 seconds and changed
the zmodem init fase so that clients that don't start automatic
have a chance to start the transfer.
mbcico: mbcico:
Added real error message for failed outgoing IP connections. Added real error message for failed outgoing IP connections.

View File

@ -50,7 +50,7 @@
* *
*/ */
static void zputhex(int); static void zputhex(int, char *);
static void zsbh32(char*, int); static void zsbh32(char*, int);
static void zsda32(char*, int, int); static void zsda32(char*, int, int);
static int zrdat32(char*,int); static int zrdat32(char*,int);
@ -74,10 +74,10 @@ static inline void zsendline_s(const char *, int);
* Original zm.c timing was in tenths of seconds, but our current ttyio driver * Original zm.c timing was in tenths of seconds, but our current ttyio driver
* does timing in whole seconds. * does timing in whole seconds.
*/ */
int Rxtimeout = 10; /* Seconds to wait for something */ int Rxtimeout = 10; /* Seconds to wait for something, receiver */
char *txbuf=NULL; char *txbuf=NULL;
static int lastsent; /* Last char we sent */ static int lastsent; /* Last char we sent */
static int Not8bit; /* Seven bits seen on header */ static int Not8bit; /* Seven bits seen on header */
static char zsendline_tab[256]; static char zsendline_tab[256];
@ -199,41 +199,47 @@ void zsbh32(char *shdr, int type)
/* /*
* Send ZMODEM HEX header hdr of type type * Send ZMODEM HEX header hdr of type type
*/ */
void zshhdr(int type, register char *shdr) void zshhdr(int type, char *shdr)
{ {
register int n; register int n;
register unsigned short crc; register unsigned short crc;
char s[30];
size_t len;
Syslog('z', "zshhdr: %s %lx", frametypes[type+FTOFFSET], rclhdr(shdr)); Syslog('z', "zshhdr: %s %lx", frametypes[type+FTOFFSET], rclhdr(shdr));
PUTCHAR(ZPAD); s[0]=ZPAD;
PUTCHAR(ZPAD); s[1]=ZPAD;
PUTCHAR(ZDLE); s[2]=ZDLE;
PUTCHAR(ZHEX); s[3]=ZHEX;
zputhex(type & 0x7f); zputhex(type & 0x7f, s+4);
len = 6;
Crc32t = 0; Crc32t = 0;
crc = updcrc16((type & 0x7f), 0); crc = updcrc16((type & 0x7f), 0);
for (n=4; --n >= 0; ++shdr) { for (n=4; --n >= 0; ++shdr) {
zputhex(*shdr); zputhex(*shdr, s+len);
len += 2;
crc = updcrc16((0377 & *shdr), crc); crc = updcrc16((0377 & *shdr), crc);
} }
crc = updcrc16(0,updcrc16(0,crc)); crc = updcrc16(0,updcrc16(0,crc));
zputhex(((int)(crc>>8))); zputhex((int)(crc>>8), s+len);
zputhex(crc); zputhex((int)(crc & 0xff), s+len+2);
len += 4;
/* /*
* Make it printable on remote machine * Make it printable on remote machine
*/ */
PUTCHAR(015); s[len++]=015;
PUTCHAR(0212); s[len++]=0212;
/* /*
* Uncork the remote in case a fake XOFF has stopped data flow * Uncork the remote in case a fake XOFF has stopped data flow
*/ */
if (type != ZFIN && type != ZACK) if (type != ZFIN && type != ZACK)
PUTCHAR(021); s[len++]=021;
PUT(s, len);
fflush(stdout); fflush(stdout);
} }
@ -247,11 +253,10 @@ void zsdata(register char *buf, int length, int frameend)
{ {
register unsigned short crc; register unsigned short crc;
Syslog('z', "zsdata: %d %s", length, Zendnames[(frameend-ZCRCE)&3]);
if (Crc32t) if (Crc32t)
zsda32(buf, length, frameend); zsda32(buf, length, frameend);
else { else {
Syslog('z', "zsdata: %d %s", length, Zendnames[(frameend-ZCRCE)&3]);
crc = 0; crc = 0;
for (;--length >= 0; ++buf) { for (;--length >= 0; ++buf) {
zsendline(*buf); zsendline(*buf);
@ -276,8 +281,10 @@ void zsdata(register char *buf, int length, int frameend)
void zsda32(register char *buf, int length, int frameend) void zsda32(register char *buf, int length, int frameend)
{ {
register int c; int c, i;
register unsigned int crc; unsigned int crc;
Syslog('z', "zsdat32: %d %s", length, Zendnames[(frameend-ZCRCE)&3]);
crc = 0xFFFFFFFFL; crc = 0xFFFFFFFFL;
zsendline_s(buf, length); zsendline_s(buf, length);
@ -290,8 +297,12 @@ void zsda32(register char *buf, int length, int frameend)
crc = updcrc32(frameend, crc); crc = updcrc32(frameend, crc);
crc = ~crc; crc = ~crc;
for (c=4; --c >= 0;) { for (i=4; --i >= 0;) {
zsendline((int)crc); c = (int) crc;
if (c & 0140)
PUTCHAR(lastsent = c);
else
zsendline(c);
crc >>= 8; crc >>= 8;
} }
@ -679,12 +690,13 @@ int zrhhdr(char *shdr)
/* /*
* Send a byte as two hex digits * Send a byte as two hex digits
*/ */
void zputhex(register int c) void zputhex(int c, char *pos)
{ {
static char digits[] = "0123456789abcdef"; static char digits[] = "0123456789abcdef";
PUTCHAR(digits[(c&0xF0)>>4]); Syslog('z', "zputhex: %02x", c);
PUTCHAR(digits[(c)&0xF]); pos[0] = digits[(c & 0xF0) >> 4];
pos[1] = digits[c & 0xF];
} }
@ -813,6 +825,7 @@ int zgethex(void)
register int c; register int c;
c = zgeth1(); c = zgeth1();
Syslog('z', "zgethex: %02x", c);
return c; return c;
} }

View File

@ -72,6 +72,7 @@ static int getfree(void);
extern unsigned int rcvdbytes; extern unsigned int rcvdbytes;
extern int zmodem_requested; extern int zmodem_requested;
extern int Rxtimeout;
@ -86,6 +87,7 @@ int zmrcvfiles(int want1k, int wantg)
Syslog('+', "%s: start receive", protname()); Syslog('+', "%s: start receive", protname());
Rxtimeout = 10;
zsendline_init(); zsendline_init();
if (secbuf == NULL) if (secbuf == NULL)
secbuf = malloc(MAXBLOCK+1); secbuf = malloc(MAXBLOCK+1);

View File

@ -75,7 +75,7 @@ struct timezone tz;
static int use8k = FALSE; static int use8k = FALSE;
extern unsigned int sentbytes; extern unsigned int sentbytes;
extern int Rxhlen; extern int Rxhlen;
extern int Rxtimeout;
extern char *txbuf; extern char *txbuf;
extern char *frametypes[]; extern char *frametypes[];
@ -91,6 +91,7 @@ int zmsndfiles(down_list *lst, int try8)
use8k = try8; use8k = try8;
protocol = ZM_ZMODEM; protocol = ZM_ZMODEM;
zsendline_init(); zsendline_init();
Rxtimeout = 60;
if ((rc = initsend())) { if ((rc = initsend())) {
if (txbuf) if (txbuf)
@ -239,11 +240,13 @@ static int sendzfile(char *rn)
*/ */
int getzrxinit(void) int getzrxinit(void)
{ {
int n; int n, timeouts = 0;
int old_timeout = Rxtimeout;
Rxtimeout = 10;
for (n = 10; --n >= 0; ) {
Syslog('z', "getzrxinit n=%d", n);
Syslog('z', "getzrxinit");
for (n=10; --n>=0; ) {
switch (zgethdr(Rxhdr)) { switch (zgethdr(Rxhdr)) {
case ZCHALLENGE: /* Echo receiver's challenge numbr */ case ZCHALLENGE: /* Echo receiver's challenge numbr */
stohdr(Rxpos); stohdr(Rxpos);
@ -286,10 +289,13 @@ int getzrxinit(void)
Syslog('z', "Txwindow = %u Txwspac = %d", Txwindow, Txwspac); Syslog('z', "Txwindow = %u Txwspac = %d", Txwindow, Txwspac);
Lztrans = 0; Lztrans = 0;
Rxtimeout = old_timeout;
return (sendzsinit()); return (sendzsinit());
case ZCAN: case ZCAN:
case TIMEOUT: case TIMEOUT:
if (timeouts++==0)
continue;
return TERROR; return TERROR;
case HANGUP: case HANGUP:
return HANGUP; return HANGUP;
@ -322,7 +328,8 @@ int sendzsinit(void)
Txhdr[ZF0] |= TESCCTL; zshhdr(ZSINIT, Txhdr); Txhdr[ZF0] |= TESCCTL; zshhdr(ZSINIT, Txhdr);
} else } else
zsbhdr(ZSINIT, Txhdr); zsbhdr(ZSINIT, Txhdr);
zsdata(Myattn, ZATTNLEN, ZCRCW); // zsdata(Myattn, ZATTNLEN, ZCRCW);
zsdata(Myattn, 1 + strlen(Myattn), ZCRCW);
c = zgethdr(Rxhdr); c = zgethdr(Rxhdr);
switch (c) { switch (c) {
case ZCAN: return TERROR; case ZCAN: return TERROR;