Several zmodem code changes

This commit is contained in:
Michiel Broek 2006-03-04 12:40:49 +00:00
parent 9293010a0b
commit d2ebff86f1
4 changed files with 76 additions and 71 deletions

View File

@ -77,7 +77,7 @@ 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];
extern unsigned Baudrate; extern unsigned Baudrate;
extern int zmodem_requested; extern int zmodem_requested;
@ -171,7 +171,8 @@ void zsbhdr(int type, char *shdr)
register int n; register int n;
register unsigned short crc; register unsigned short crc;
Syslog('z', "zsbhdr: %s %lx", frametypes[type+FTOFFSET], rclhdr(shdr)); Crc32t = Txfcs32;
Syslog('z', "zsbh%s: %s %lx", Crc32t ? "32":"dr", frametypes[type+FTOFFSET], rclhdr(shdr));
BUFFER_CLEAR(); BUFFER_CLEAR();
@ -182,7 +183,7 @@ void zsbhdr(int type, char *shdr)
BUFFER_BYTE(ZPAD); BUFFER_BYTE(ZPAD);
BUFFER_BYTE(ZDLE); BUFFER_BYTE(ZDLE);
if ((Crc32t = Txfcs32)) if (Crc32t)
zsbh32(shdr, type); zsbh32(shdr, type);
else { else {
BUFFER_BYTE(ZBIN); BUFFER_BYTE(ZBIN);
@ -321,7 +322,10 @@ void zsda32(register char *buf, int length, int frameend)
crc = 0xFFFFFFFFL; crc = 0xFFFFFFFFL;
for (;--length >= 0; ++buf) { for (;--length >= 0; ++buf) {
c = *buf & 0377; c = *buf & 0377;
zsendline(*buf); if (c & 0140)
BUFFER_BYTE(lastsent = c);
else
zsendline(c);
crc = updcrc32(c, crc); crc = updcrc32(c, crc);
} }
BUFFER_BYTE(ZDLE); BUFFER_BYTE(ZDLE);
@ -332,11 +336,6 @@ void zsda32(register char *buf, int length, int frameend)
for (c=4; --c >= 0;) { for (c=4; --c >= 0;) {
zsendline((int)crc); crc >>= 8; zsendline((int)crc); crc >>= 8;
} }
// if (frameend == ZCRCW) {
// BUFFER_BYTE(XON);
// fflush(stdout);
// }
} }
@ -477,7 +476,6 @@ void garbitch(void)
int zgethdr(char *shdr) int zgethdr(char *shdr)
{ {
register int c, n, cancount, tmcount; register int c, n, cancount, tmcount;
// int Zrwindow = 1400;
int Zrwindow = 1024; int Zrwindow = 1024;
n = Zrwindow + Baudrate; n = Zrwindow + Baudrate;
@ -737,42 +735,65 @@ void zputhex(int c)
/* /*
* Send character c with ZMODEM escape sequence encoding. * Send character c with ZMODEM escape sequence encoding.
* Escape XON, XOFF. Escape CR following @ (Telenet net escape) * Escape XON, XOFF. Escape CR following @ (Telenet net escape)
*/ */
void zsendline(int c) void zsendline(int c)
{ {
/* Quick check for non control characters */ switch(zsendline_tab[(unsigned) (c&=0377)]) {
if (c & 0140) case 0: BUFFER_BYTE(lastsent = c);
BUFFER_BYTE(lastsent = c); break;
else { case 1: BUFFER_BYTE(ZDLE);
switch (c &= 0377) { c ^= 0100;
case ZDLE: BUFFER_BYTE(lastsent = c);
BUFFER_BYTE(ZDLE); break;
BUFFER_BYTE (lastsent = (c ^= 0100)); case 2: if ((lastsent & 0177) != '@') {
break; BUFFER_BYTE(lastsent = c);
case 015: } else {
case 0215: BUFFER_BYTE(ZDLE);
if (!Zctlesc && (lastsent & 0177) != '@') c ^= 0100;
goto sendit; BUFFER_BYTE(lastsent = c);
/* **** FALL THRU TO **** */ }
case 020: break;
case 021: }
case 023: }
case 0220:
case 0221:
case 0223:
BUFFER_BYTE(ZDLE); void zsendline_init(void)
c ^= 0100; {
sendit: int i;
BUFFER_BYTE(lastsent = c);
break; Syslog('z', "zendline_init() Zctlesc=%d", Zctlesc);
default:
if (Zctlesc && ! (c & 0140)) { for (i = 0; i < 256; i++) {
BUFFER_BYTE(ZDLE); if (i & 0140)
c ^= 0100; zsendline_tab[i] = 0;
else {
} switch(i) {
BUFFER_BYTE(lastsent = c); case ZDLE:
case XOFF: /* ^Q */
case XON: /* ^S */
case (XOFF | 0200):
case (XON | 0200):
zsendline_tab[i]=1;
break;
case 020: /* ^P */
case 0220:
zsendline_tab[i]=1;
break;
case 015:
case 0215:
if (Zctlesc)
zsendline_tab[i]=1;
else
zsendline_tab[i]=2;
break;
default:
if (Zctlesc)
zsendline_tab[i]=1;
else
zsendline_tab[i]=0;
}
} }
} }
} }

View File

@ -134,7 +134,7 @@ char Rxhdr[ZMAXHLEN]; /* Received header */
char Txhdr[ZMAXHLEN]; /* Transmitted header */ char Txhdr[ZMAXHLEN]; /* Transmitted header */
char Attn[ZATTNLEN+1]; /* Attention string rx sends to tx on err */ char Attn[ZATTNLEN+1]; /* Attention string rx sends to tx on err */
char *Altcan; /* Alternate canit string */ char *Altcan; /* Alternate canit string */
char Zsendmask[33]; /* Additional control characters to mask */ //char Zsendmask[33]; /* Additional control characters to mask */
int Zctlesc; int Zctlesc;
enum zm_type_enum { enum zm_type_enum {
@ -159,6 +159,7 @@ int zdlread(void);
void stohdr(int); void stohdr(int);
int rclhdr(register char *); int rclhdr(register char *);
char *protname(void); char *protname(void);
void zsendline_init(void);
void purgeline(int); void purgeline(int);
void canit(int); void canit(int);

View File

@ -88,6 +88,7 @@ int zmrcvfiles(int want1k, int wantg)
Syslog('+', "%s: start receive", protname()); Syslog('+', "%s: start receive", protname());
get_frame_buffer(); get_frame_buffer();
zsendline_init();
Rxtimeout = 10; Rxtimeout = 10;
if (secbuf == NULL) if (secbuf == NULL)

View File

@ -47,7 +47,6 @@ static int zfilbuf(void);
static int zsendfile(char*,int); static int zsendfile(char*,int);
static int zsendfdata(void); static int zsendfdata(void);
static int getinsync(int); static int getinsync(int);
void initzsendmsk(char *);
static FILE *in; static FILE *in;
static int Eofseen; /* EOF seen on input set by zfilbuf */ static int Eofseen; /* EOF seen on input set by zfilbuf */
@ -90,6 +89,7 @@ int zmsndfiles(down_list *lst, int try8)
Syslog('+', "Zmodem: start Zmodem%s send", try8 ? "-8K":""); Syslog('+', "Zmodem: start Zmodem%s send", try8 ? "-8K":"");
get_frame_buffer(); get_frame_buffer();
zsendline_init();
use8k = try8; use8k = try8;
protocol = ZM_ZMODEM; protocol = ZM_ZMODEM;
@ -263,13 +263,13 @@ int getzrxinit(void)
case ZRINIT: case ZRINIT:
Rxflags = 0377 & Rxhdr[ZF0]; Rxflags = 0377 & Rxhdr[ZF0];
Txfcs32 = (Wantfcs32 && (Rxflags & CANFC32)); Txfcs32 = (Wantfcs32 && (Rxflags & CANFC32));
// { {
// int old = Zctlesc; int old = Zctlesc;
Zctlesc |= Rxflags & TESCCTL; Zctlesc |= Rxflags & TESCCTL;
// /* update table - was initialised to not escape */ /* update table - was initialised to not escape */
// if (Zctlesc && !old) if (Zctlesc && !old)
// zsendline_init(); zsendline_init();
// } }
Rxbuflen = (0377 & Rxhdr[ZP0])+((0377 & Rxhdr[ZP1])<<8); Rxbuflen = (0377 & Rxhdr[ZP0])+((0377 & Rxhdr[ZP1])<<8);
if ( !(Rxflags & CANFDX)) if ( !(Rxflags & CANFDX))
@ -333,7 +333,6 @@ 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, 1 + strlen(Myattn), ZCRCW); zsdata(Myattn, 1 + strlen(Myattn), ZCRCW);
c = zgethdr(Rxhdr); c = zgethdr(Rxhdr);
switch (c) { switch (c) {
@ -504,7 +503,7 @@ gotack:
*/ */
if (TCHECK()) { if (TCHECK()) {
c = GETCHAR(1); c = GETCHAR(1);
Syslog('z', "zsendfdata(): check getchar(1)=%d", c); Syslog('z', "zsendfdata(): 1 check getchar(1)=%d %c", c, c);
if (c < 0) { if (c < 0) {
return c; return c;
} else switch (c) { } else switch (c) {
@ -557,6 +556,7 @@ to:
*/ */
if (TCHECK()) { if (TCHECK()) {
c = GETCHAR(1); c = GETCHAR(1);
Syslog('z', "zsendfdata(): 2 check getchar(1)=%d %c", c, c);
if (c < 0) { if (c < 0) {
return c; return c;
} else switch (c) { } else switch (c) {
@ -669,21 +669,3 @@ int getinsync(int flag)
} }
/*
* Set additional control chars to mask in Zsendmask
* according to bit array stored in char array at p
*/
void initzsendmsk(register char *p)
{
int c;
for (c = 0; c < 33; ++c) {
if (p[c>>3] & (1 << (c & 7))) {
Zsendmask[c] = 1;
Syslog('z', "Zmodem: Escaping %02o", c);
}
}
}