From 699782e13d84a5b719ef0c6bbf6c1f6a731006ac Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 16 Jan 2016 19:35:50 +0000 Subject: [PATCH] net: knock out some remaining bugs and print the AT command properly We now pass the "sufficiently rigged demo" test case. --- Kernel/dev/net/net_at.c | 41 +++++++++++++++++++++++++++++------ Kernel/dev/z80pack/devatsim.c | 7 +++++- Kernel/include/net_at.h | 1 + Kernel/include/netdev.h | 5 +++-- Kernel/inode.c | 6 ++--- Kernel/syscall_net.c | 16 ++++---------- 6 files changed, 51 insertions(+), 25 deletions(-) diff --git a/Kernel/dev/net/net_at.c b/Kernel/dev/net/net_at.c index aa218d11..e7311faf 100644 --- a/Kernel/dev/net/net_at.c +++ b/Kernel/dev/net/net_at.c @@ -2,6 +2,7 @@ #include #include #include +#include /* * 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; +} diff --git a/Kernel/dev/z80pack/devatsim.c b/Kernel/dev/z80pack/devatsim.c index b4befbb0..f55283b0 100644 --- a/Kernel/dev/z80pack/devatsim.c +++ b/Kernel/dev/z80pack/devatsim.c @@ -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(); } diff --git a/Kernel/include/net_at.h b/Kernel/include/net_at.h index 1552897f..f0961a91 100644 --- a/Kernel/include/net_at.h +++ b/Kernel/include/net_at.h @@ -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); diff --git a/Kernel/include/netdev.h b/Kernel/include/netdev.h index fa773586..02320623 100644 --- a/Kernel/include/netdev.h +++ b/Kernel/include/netdev.h @@ -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); diff --git a/Kernel/inode.c b/Kernel/inode.c index db21fc10..ea7f89fc 100644 --- a/Kernel/inode.c +++ b/Kernel/inode.c @@ -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; } diff --git a/Kernel/syscall_net.c b/Kernel/syscall_net.c index c227dc2e..af297ec9 100644 --- a/Kernel/syscall_net.c +++ b/Kernel/syscall_net.c @@ -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); -- 2.34.1