We now pass the "sufficiently rigged demo" test case.
#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
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]);
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;
}
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, '.');
{
}
+uint8_t use_net_r(void)
+{
+ return 1;
+}
+
+uint8_t use_net_w(void)
+{
+ return 1;
+}
}
}
+void netat_flush(void)
+{
+ while((status & 5) == 5)
+ data;
+}
void netat_poll(void)
{
return;
}
up = 1;
- while (poll && (st & 1))
+ while (poll && (status & 1))
netat_event();
}
extern void netat_poll(void);
extern void netat_outbyte(uint8_t);
extern uint8_t netat_ready(void);
+extern void netat_flush(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);
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
#ifdef CONFIG_NET
case F_SOCK:
- if (!is_netd()) {
+ if (use_net_w()) {
udata.u_count = sock_write(ino, flag);
break;
}
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) {
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)
}
}
-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);