netd: Futher fixes
authorAlan Cox <alan@linux.intel.com>
Thu, 9 Nov 2017 01:20:57 +0000 (01:20 +0000)
committerAlan Cox <alan@linux.intel.com>
Thu, 9 Nov 2017 01:20:57 +0000 (01:20 +0000)
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

Applications/netd/Makefile.6809
Applications/netd/Makefile.z80
Applications/netd/dig.c
Applications/netd/fuzix-conf.h
Applications/netd/gethostbyname.c
Applications/netd/httpd.c
Applications/netd/netd.c
Applications/netd/ntpdate.c
Applications/netd/slip.c

index d7efdd0..78d91fc 100644 (file)
@@ -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
index 7af3113..7a9f87f 100644 (file)
@@ -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
index dd38085..e168044 100644 (file)
@@ -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 )
index 183095e..cf23c19 100644 (file)
@@ -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
 
index aa5a662..188be6b 100644 (file)
@@ -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;
index 0a6d27b..8269d9d 100644 (file)
@@ -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);
     }
index 716fc00..36abe0c 100644 (file)
@@ -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();
index 7dd206f..3182691 100644 (file)
@@ -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);
 }
index e45490b..72c17cc 100644 (file)
@@ -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;