net: knock out some remaining bugs and print the AT command properly
authorAlan Cox <alan@linux.intel.com>
Sat, 16 Jan 2016 19:35:50 +0000 (19:35 +0000)
committerAlan Cox <alan@linux.intel.com>
Sat, 16 Jan 2016 19:35:50 +0000 (19:35 +0000)
We now pass the "sufficiently rigged demo" test case.

Kernel/dev/net/net_at.c
Kernel/dev/z80pack/devatsim.c
Kernel/include/net_at.h
Kernel/include/netdev.h
Kernel/inode.c
Kernel/syscall_net.c

index aa218d1..e7311fa 100644 (file)
@@ -2,6 +2,7 @@
 #include <kdata.h>
 #include <netdev.h>
 #include <net_at.h>
+#include <printf.h>
 
 /*
  *     Implement a one socket TCP model for interfaces that provide only AT
@@ -16,19 +17,35 @@ static void netat_write(const char *p, uint16_t len)
     netat_outbyte(*p++);
 }
 
-static void netat_write_u8ch(uint8_t v, char c)
+/* Borrowed from libc */
+static const char *_uitoa(uint16_t i)
 {
-  used(v);
-  /* FIXME: number out */
-  netat_outbyte(c);
+  static char buf[8];
+  char *p = buf + sizeof(buf);
+  int c;
+
+  *--p = '\0';
+  do {
+    c = i % 10;
+    i /= 10;
+    *--p = '0' + c;
+  } while(i);
+  return p;
 }
 
 static void netat_write_u16ch(uint16_t v, char c)
 {
-  used(v);
+  const char *p = _uitoa(v);
+  while(*p)
+    netat_outbyte(*p++);
   netat_outbyte(c);
 }
 
+static void netat_write_u8ch(uint8_t v, char c)
+{
+  netat_write_u16ch(v, c);
+}
+
 static void wakeup_all(void)
 {
   wakeup(&sockets[0]);
@@ -58,7 +75,7 @@ void netat_event(void)
   uint8_t ch;
   if (at_state == 4) {
     sockets[0].s_iflag |= SI_DATA;
-    wakeup(&sockets[0].s_data);
+    wakeup(&sockets[0].s_iflag);
     netat_nowake();
     return;
   }
@@ -134,7 +151,8 @@ int net_connect(struct socket *s)
 
   n = ntohl(n);
 
-  /* Pity drivewire won't talk addresses and ports as a hex block ! */
+  /* Pity AT command sets won't talk addresses and ports as a hex block ! */
+  netat_flush();
   netat_write("ATD ", 4);
   netat_write_u8ch(n >> 24, '.');
   netat_write_u8ch(n >> 16, '.');
@@ -218,3 +236,12 @@ void netdev_init(void)
 {
 }
 
+uint8_t use_net_r(void)
+{
+  return 1;
+}
+
+uint8_t use_net_w(void)
+{
+  return 1;
+}
index b4befbb..f55283b 100644 (file)
@@ -46,6 +46,11 @@ static void netat_drop(void)
     }
 }
 
+void netat_flush(void)
+{
+  while((status & 5) == 5)
+    data;
+}
 
 void netat_poll(void)
 {
@@ -55,7 +60,7 @@ void netat_poll(void)
     return;
   }
   up = 1;
-  while (poll && (st & 1))
+  while (poll && (status & 1))
       netat_event();
 }
 
index 1552897..f0961a9 100644 (file)
@@ -8,3 +8,4 @@ extern uint8_t netat_byte(void);
 extern void netat_poll(void);
 extern void netat_outbyte(uint8_t);
 extern uint8_t netat_ready(void);
+extern void netat_flush(void);
index fa77358..0232062 100644 (file)
@@ -107,8 +107,9 @@ extern arg_t _recvfrom(void);
 
 /* Hooks for inode.c into the networking */
 extern void sock_close(inoptr ino);
-extern int netd_sock_read(inoptr ino, uint8_t flag);
-extern int is_netd(void);
+extern int sock_read(inoptr ino, uint8_t flag);
+extern uint8_t use_net_r(void);
+extern uint8_t use_net_w(void);
 extern int sock_write(inoptr ino, uint8_t flag);
 extern bool issocket(inoptr ino);
 
index db21fc1..ea7f89f 100644 (file)
@@ -38,8 +38,8 @@ void readi(inoptr ino, uint8_t flag)
 
         case F_SOCK:
 #ifdef CONFIG_NET
-                if (is_netd()) {
-                        udata.u_count = netd_sock_read(ino, flag);
+                if (use_net_r()) {
+                        udata.u_count = sock_read(ino, flag);
                         return;
                 }
 #endif
@@ -150,7 +150,7 @@ void writei(inoptr ino, uint8_t flag)
 
 #ifdef CONFIG_NET
        case F_SOCK:
-               if (!is_netd()) {
+               if (use_net_w()) {
                        udata.u_count = sock_write(ino, flag);
                        break;
                }
index c227dc2..af297ec 100644 (file)
@@ -20,18 +20,10 @@ bool issocket(inoptr ino)
        return 0;
 }
 
-/* This and netd_sock_read need a lot more thought and probably a
-   restructure. Problem is that for small boxes some kind of pipe like
-   disk cache queue for sockets is the right answer, but not for offload */
-
-int is_netd(void)
-{
-       return 1;
-}
-
 int sock_write(inoptr ino, uint8_t flag)
 {
        struct socket *s = &sockets[ino->c_node.i_nlink];
+       int r;
 
        /* FIXME: IRQ protection */
        while(1) {
@@ -44,14 +36,14 @@ int sock_write(inoptr ino, uint8_t flag)
                                udata.u_error = EINVAL;
                        return -1;
                }
-               switch(net_write(s, flag)) {
+               switch(r = net_write(s, flag)) {
                        case -2:
                                s->s_iflag |= SI_THROTTLE;
                                break;
                        case -1:
                                return -1;
                        default:
-                               return udata.u_count;
+                               return r;
                }
                if (s->s_iflag == SI_THROTTLE &&
                        psleep_flags(&s->s_iflag, flag) == -1)
@@ -59,7 +51,7 @@ int sock_write(inoptr ino, uint8_t flag)
        }
 }
 
-int netd_sock_read(inoptr ino, uint8_t flag)
+int sock_read(inoptr ino, uint8_t flag)
 {
        struct socket *s = &sockets[ino->c_node.i_nlink];
        return net_read(s, flag);