From: Alan Cox Date: Thu, 9 Nov 2017 01:20:57 +0000 (+0000) Subject: netd: Futher fixes X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=02c6a541cb24090ab910c7d1e2dede1e3fa01dd9;p=FUZIX.git netd: Futher fixes With these applied you can ping and remotely interact with the stack but local interactions are not yet working (probably byte order) and also the close() functionality is a bit messed up. We need to a) break the mapping when the kernel asks us to move to closed b) do the flag test *outside* of the app callbacks (as we may be closing without any app callbacks happening) c) allow for events from uip on unmapped sockets (one the kernel closed), in which case we should reset if there is data arriving, and otherwise cycle through the close states and close in uip, then free up the broken mapping slot --- diff --git a/Applications/netd/Makefile.6809 b/Applications/netd/Makefile.6809 index d7efdd07..78d91fc7 100644 --- a/Applications/netd/Makefile.6809 +++ b/Applications/netd/Makefile.6809 @@ -6,6 +6,7 @@ AR = m6809-unknown-ar LINKER = lwlink CFLAGS = -I../../Library/include -I../../Library/include/6809 CFLAGS += -O0 -msoft-reg-count=0 -mfar-stack-param -fomit-frame-pointer +CFLAGS += -DNETD_BIG_ENDIAN LINKER_OPT = --format=raw -L../../Library/libs -lc6809 LIBGCCDIR = $(dir $(shell $(CC) -print-libgcc-file-name)) LINKER_OPT += -L$(LIBGCCDIR) -lgcc diff --git a/Applications/netd/Makefile.z80 b/Applications/netd/Makefile.z80 index 7af3113c..7a9f87f0 100644 --- a/Applications/netd/Makefile.z80 +++ b/Applications/netd/Makefile.z80 @@ -1,3 +1,43 @@ -all: +.SUFFIXES: .c .rel + +SRCS = netd.c uip.c uiplib.c timer.c clock-arch.c uip_arp.c telnet.c slip.c +SRCS += echoping.c dig.c gethostbyname.c httpd.c ping.c ntpdate.c + +OBJS = $(SRCS:.c=.rel) + +APPS = netd-slip telnet echoping dig httpd ping ntpdate + +OPTS = -O2 -DNETD_LITTLE_ENDIAN + +all: $(APPS) + +netd-slip: $(OBJS) + fcc -o netd netd.rel uip.rel uiplib.rel timer.rel clock-arch.rel \ + uip_arp.rel slip.rel + +$(OBJS): %.rel: %.c + +.c.rel: + fcc $(PLATFORM) $(OPTS) -c $< + +telnet: telnet.rel gethostbyname.rel + fcc -o $@ $^ + +echoping: echoping.rel + fcc -o $@ $^ + +dig: dig.rel + fcc -o $@ $^ + +httpd: httpd.rel + fcc -o $@ $^ + +ping: ping.rel gethostbyname.rel + fcc -o $@ $^ + +ntpdate: ntpdate.rel gethostbyname.rel + fcc -o $@ $^ + clean: + rm -f *.rel *.lst *.asm *.noi *.map *.lk *.sym *~ *.ihx *.bin diff --git a/Applications/netd/dig.c b/Applications/netd/dig.c index dd380854..e1680443 100644 --- a/Applications/netd/dig.c +++ b/Applications/netd/dig.c @@ -45,14 +45,15 @@ int send_question( char *name ){ struct header *p=( struct header *)buf; struct RRtail *t; + char *i = name; + char *o = buf + sizeof(struct header); + char *l = o++; + memset( p, 0, sizeof(buf) ); p->id = 42; /* "random" query ID */ p->cntl = 0x1; /* request a recursive query */ p->qdcount = 1; /* one question */ /* fill out name string */ - char *i = name; - char *o = buf + sizeof(struct header); - char *l = o++; while(1){ if( ! *i ) diff --git a/Applications/netd/fuzix-conf.h b/Applications/netd/fuzix-conf.h index 183095ea..cf23c193 100644 --- a/Applications/netd/fuzix-conf.h +++ b/Applications/netd/fuzix-conf.h @@ -16,7 +16,14 @@ typedef uint8_t uip_stats_t; #define UIP_CONF_LLH_LEN 14 -#define UIP_CONF_BYTE_ORDER UIP_BIG_ENDIAN + +#if defined(NETD_LITTLE_ENDIAN) +#define UIP_CONF_BYTE_ORDER UIP_LITTLE_ENDIAN +#elif defined(NETD_BIG_ENDIAN) +#define UIP_CONF_BYTE_ORDER UIP_BIG_ENDIAN +#else +#error "Must -D the correct endianness" +#endif #define UIP_CONF_ACTIVE_OPEN 1 diff --git a/Applications/netd/gethostbyname.c b/Applications/netd/gethostbyname.c index aa5a6627..188be6bd 100644 --- a/Applications/netd/gethostbyname.c +++ b/Applications/netd/gethostbyname.c @@ -54,16 +54,16 @@ static char buf[512]; /* packet buffer */ static int send_question( char *name ){ struct header *p=( struct header *)buf; struct RRtail *t; - + char *i = name; + char *o = buf + sizeof(struct header); + char *l = o++; + memset( p, 0, sizeof(buf) ); p->id = 42; /* "random" query ID */ p->cntl = 0x1; /* request a recursive query */ p->qdcount = 1; /* one question */ /* fill out name string */ - char *i = name; - char *o = buf + sizeof(struct header); - char *l = o++; - + while(1){ if( ! *i ) break; diff --git a/Applications/netd/httpd.c b/Applications/netd/httpd.c index 0a6d27be..8269d9df 100644 --- a/Applications/netd/httpd.c +++ b/Applications/netd/httpd.c @@ -32,7 +32,7 @@ my_open( int argc, char *argv[]){ exit(1); } - if( bind( lfd, &addr, sizeof(addr) ) ){ + if( bind( lfd, (struct sockaddr *)&addr, sizeof(addr) ) ){ perror("bind"); exit(1); } diff --git a/Applications/netd/netd.c b/Applications/netd/netd.c index 716fc006..36abe0ca 100644 --- a/Applications/netd/netd.c +++ b/Applications/netd/netd.c @@ -476,13 +476,13 @@ int dokernel( void ) if ( i < 0 ){ return 0; } - else if ( i == sizeof( sm ) && sm.sd.event & 127 ){ - /* debug + else if ( i == sizeof( sm ) && (sm.sd.event & 127)){ + /* debug*/ fprintf(stderr,"read size: %d ", i ); fprintf(stderr,"knet lcn: %d ", sm.sd.lcn ); fprintf(stderr,"event: %x ", sm.sd.event ); fprintf(stderr,"newstat: %x\n", sm.sd.newstate ); - */ + /**/ m = & map[sm.sd.lcn]; if ( sm.sd.event & NEV_STATE ){ ne.socket = sm.s.s_num; @@ -875,7 +875,6 @@ int main( int argc, char *argv[] ) /* initialize our map */ init_map(); - /* * Set up uIP */ @@ -908,14 +907,12 @@ int main( int argc, char *argv[] ) ethaddr.addr[5] = 0x05; uip_setethaddr(ethaddr); - parse_rcfile(); if( device_init() ){ exit_err( "cannot init net device\n"); } - while(1) { int a,b; a = dokernel(); diff --git a/Applications/netd/ntpdate.c b/Applications/netd/ntpdate.c index 7dd206f1..31826918 100644 --- a/Applications/netd/ntpdate.c +++ b/Applications/netd/ntpdate.c @@ -59,8 +59,8 @@ void pusage( void ){ /* sends query to remote */ void sendq( void ){ - memset( buf, 0, MAXBUF ); struct ntp_t *i = (struct ntp_t *)buf; + memset( buf, 0, MAXBUF ); i->lvm = 0xe3; write(fd, buf, 48); } diff --git a/Applications/netd/slip.c b/Applications/netd/slip.c index e45490b0..72c17cca 100644 --- a/Applications/netd/slip.c +++ b/Applications/netd/slip.c @@ -15,7 +15,7 @@ static int fd; /* fd of the tty */ static char ibuf[297]; -static char *iptr; +static char *iptr = ibuf; #define SLIP_END 0xC0 #define SLIP_ESC 0xDB @@ -47,6 +47,7 @@ static void slip_out(uint8_t c) static void slip_begin(void) { /* Should send an end mark if idle for a bit */ + slip_outbuf(SLIP_END); } static void slip_end(void) @@ -109,6 +110,7 @@ static int slip_recv( unsigned char *b, int len ) b[13] = 0x00; memcpy(b+14, ibuf, len); iptr = ibuf; + return len; } /* send packet to net device */ @@ -125,7 +127,7 @@ int device_send( char *sbuf, int len ) int device_read( char *buf, int len ) { if (slip_poll() == 0) - return 0; + return -1; return slip_recv(buf, len); } @@ -134,9 +136,9 @@ static struct termios t; int device_init(void) { /* FIXME: don't hard code */ - fd=open( "/dev/tty3", O_RDWR); + fd=open( "/dev/tty4", O_RDWR|O_NOCTTY); if( fd < 0 || tcgetattr(fd, &t) < 0) { - perror("/dev/tty3"); + perror("/dev/tty4"); return -1; } t.c_iflag = IGNBRK; @@ -148,7 +150,7 @@ int device_init(void) t.c_cc[VTIME] = 3; /* 0.3 seconds */ if (tcsetattr(fd, 0, &t) < 0) { - perror("/dev/tty3"); + perror("/dev/tty4"); return -1; } return 0;