aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-09-16 17:48:26 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-09-16 17:48:26 -0700
commit990cb1bd14b4962df2487d3d9f891479e5b11f83 (patch)
treeeacd40b69700bd9cc569635d0d08e9d81aa71504
parent6ea4379b7185f462d379aee92aafad770603f930 (diff)
downloadlwip-990cb1bd14b4962df2487d3d9f891479e5b11f83.tar.gz
lwip-990cb1bd14b4962df2487d3d9f891479e5b11f83.tar.xz
lwip-990cb1bd14b4962df2487d3d9f891479e5b11f83.zip
lwip: now to the point we can make a TCP connection...
lwip is now functional enough that TCP and DNS seem to work. More tests still need to be done, though. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--com32/lib/vfprintf.c2
-rw-r--r--core/fs/pxe/dhcp_option.c8
-rw-r--r--core/fs/pxe/dnsresolv.c2
-rw-r--r--core/fs/pxe/pxe.c82
-rw-r--r--core/lwip/src/core/dns.c7
-rw-r--r--core/lwip/src/include/arch/cc.h6
-rw-r--r--core/lwip/src/include/lwipopts.h42
-rw-r--r--core/lwip/src/netif/undiif.c100
8 files changed, 198 insertions, 51 deletions
diff --git a/com32/lib/vfprintf.c b/com32/lib/vfprintf.c
index be084216..217a31cf 100644
--- a/com32/lib/vfprintf.c
+++ b/com32/lib/vfprintf.c
@@ -7,7 +7,7 @@
#include <stdarg.h>
#include <unistd.h>
-#define BUFFER_SIZE 32768
+#define BUFFER_SIZE 1024
int vfprintf(FILE * file, const char *format, va_list ap)
{
diff --git a/core/fs/pxe/dhcp_option.c b/core/fs/pxe/dhcp_option.c
index 7935f8ba..21a9f6ba 100644
--- a/core/fs/pxe/dhcp_option.c
+++ b/core/fs/pxe/dhcp_option.c
@@ -44,11 +44,15 @@ static void dns_servers(void *data, int opt_len)
* if you find you got no corret DNS server, you can add
* it here manually. BUT be carefull the DNS_MAX_SERVERS
*/
- if (i < DNS_MAX_SERVERS ) {
+ if (i < DNS_MAX_SERVERS)
dns_server[i++] = your_master_dns_server;
+ if (i < DNS_MAX_SERVERS)
dns_server[i++] = your_second_dns_server;
- }
#endif
+
+ /* Clear the rest of the dns_server array */
+ for (; i < DNS_MAX_SERVERS; i++)
+ dns_server[i] = 0;
}
static void local_domain(void *data, int opt_len)
diff --git a/core/fs/pxe/dnsresolv.c b/core/fs/pxe/dnsresolv.c
index 15560447..d04a121c 100644
--- a/core/fs/pxe/dnsresolv.c
+++ b/core/fs/pxe/dnsresolv.c
@@ -46,7 +46,7 @@ struct dnsrr {
} __attribute__ ((packed));
-uint32_t dns_server[DNS_MAX_SERVERS] = {0, };
+uint32_t dns_server[DNS_MAX_SERVERS];
/*
diff --git a/core/fs/pxe/pxe.c b/core/fs/pxe/pxe.c
index 3a3ce22b..e97fca14 100644
--- a/core/fs/pxe/pxe.c
+++ b/core/fs/pxe/pxe.c
@@ -8,6 +8,7 @@
#include "pxe.h"
#include "thread.h"
#include "lwip/api.h"
+#include "lwip/dns.h"
#define GPXE 1
@@ -353,7 +354,7 @@ static int pxe_get_cached_info(int type)
static __lowmem struct s_PXENV_GET_CACHED_INFO get_cached_info;
printf(" %02x", type);
- get_cached_info.Status = 0;
+ memset(&get_cached_info, 0, sizeof get_cached_info);
get_cached_info.PacketType = type;
get_cached_info.BufferSize = 8192;
get_cached_info.Buffer = FAR_PTR(trackbuf);
@@ -1404,6 +1405,7 @@ static void pxe_init(void)
* Initialize UDP stack
*
*/
+#if 0
static void udp_init(void)
{
int err;
@@ -1416,7 +1418,67 @@ static void udp_init(void)
kaboom();
}
}
-
+#endif
+
+static void lwip_test(void)
+{
+ err_t err;
+ struct ip_addr ip;
+ struct netconn *conn;
+ char header_buf[512];
+ int header_len;
+ static const char host_str[] = "www.zytor.com";
+ struct netbuf *buf;
+
+ /* Test the lwIP stack by trying to open a HTTP connection... */
+ printf("Starting lwIP test...\n");
+ err = netconn_gethostbyname(host_str, &ip);
+ printf("Gethostbyname: ip = %d.%d.%d.%d, err = %d\n",
+ ((uint8_t *)&ip)[0],
+ ((uint8_t *)&ip)[1],
+ ((uint8_t *)&ip)[2],
+ ((uint8_t *)&ip)[3],
+ err);
+
+ conn = netconn_new(NETCONN_TCP);
+ printf("netconn_new returned %p\n", conn);
+
+ err = netconn_connect(conn, &ip, 80);
+ printf("netconn_connect error %d\n", err);
+
+ header_len = snprintf(header_buf, sizeof header_buf,
+ "GET /lwip_test HTTP/1.0\r\n"
+ "Host: %s\r\n"
+ "\r\n",
+ host_str);
+
+ err = netconn_write(conn, header_buf, header_len, NETCONN_NOCOPY);
+ printf("netconn_write error %d\n", err);
+ for (;;) {
+ void *data;
+ char *p;
+ u16_t len;
+
+ buf = netconn_recv(conn);
+ if (!buf)
+ break;
+
+ netbuf_data(buf, &data, &len);
+
+ p = data;
+ while (len--)
+ putchar (*p++);
+
+ netbuf_delete(buf);
+ }
+
+ printf("\n[End transmission]\n");
+
+ netconn_disconnect(conn);
+
+ for(;;)
+ asm volatile("hlt");
+}
/*
* Network-specific initialization
@@ -1429,6 +1491,7 @@ static void network_init(void)
{
struct bootp_t *bp = (struct bootp_t *)trackbuf;
int pkt_len;
+ int i;
*LocalDomain = 0; /* No LocalDomain received */
@@ -1483,9 +1546,24 @@ static void network_init(void)
DHCPMagic = 0;
#if 1 /* new stuff */
+ printf("undi_tcpip_start...\n");
undi_tcpip_start((struct ip_addr *)&MyIP,
(struct ip_addr *)&net_mask,
(struct ip_addr *)&gate_way);
+
+ for (i = 0; i < DNS_MAX_SERVERS; i++) {
+ /* Transfer the DNS information to lwip */
+ printf("DNS server %d = %d.%d.%d.%d\n",
+ i,
+ ((uint8_t *)&dns_server[i])[0],
+ ((uint8_t *)&dns_server[i])[1],
+ ((uint8_t *)&dns_server[i])[2],
+ ((uint8_t *)&dns_server[i])[3]);
+ dns_setserver(i, (struct ip_addr *)&dns_server[i]);
+ }
+
+ printf("lwip_test...\n");
+ lwip_test();
#else
udp_init();
#endif
diff --git a/core/lwip/src/core/dns.c b/core/lwip/src/core/dns.c
index 62a2592e..a97fb50a 100644
--- a/core/lwip/src/core/dns.c
+++ b/core/lwip/src/core/dns.c
@@ -292,8 +292,13 @@ dns_init()
void
dns_setserver(u8_t numdns, struct ip_addr *dnsserver)
{
+ /*
+ * hpa: the lwip code has the dnsserver->addr != 0 test, but that would
+ * seem to indicate that there is no way to cancel a previously given
+ * DNS server...
+ */
if ((numdns < DNS_MAX_SERVERS) && (dns_pcb != NULL) &&
- (dnsserver != NULL) && (dnsserver->addr !=0 )) {
+ (dnsserver != NULL) /* && (dnsserver->addr !=0) */) {
dns_servers[numdns] = (*dnsserver);
}
}
diff --git a/core/lwip/src/include/arch/cc.h b/core/lwip/src/include/arch/cc.h
index a6f89310..9d139637 100644
--- a/core/lwip/src/include/arch/cc.h
+++ b/core/lwip/src/include/arch/cc.h
@@ -4,6 +4,7 @@
#include <klibc/compiler.h>
#include <inttypes.h>
#include <errno.h>
+#include <stdio.h>
#include "core.h"
#define BYTE_ORDER LITTLE_ENDIAN
@@ -22,8 +23,13 @@ typedef uintptr_t mem_ptr_t;
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_END
+#if 1
+#define LWIP_PLATFORM_DIAG(x) do { printf message; } while (0)
+#define LWIP_PLATFORM_ASSERT(x) do { printf("%s", (x)); kaboom(); } while (0)
+#else
#define LWIP_PLATFORM_DIAG(x) ((void)0) /* For now... */
#define LWIP_PLATFORM_ASSERT(x) kaboom()
+#endif
#define U16_F PRIu16
#define S16_F PRId16
diff --git a/core/lwip/src/include/lwipopts.h b/core/lwip/src/include/lwipopts.h
index 71f6d719..2b036ccd 100644
--- a/core/lwip/src/include/lwipopts.h
+++ b/core/lwip/src/include/lwipopts.h
@@ -1,30 +1,54 @@
#ifndef __LWIPOPTS_H__
#define __LWIPOPTS_H__
+#include <stdlib.h>
+
#define MEM_SIZE (1 << 18)
+#if 0
#define MEMP_OVERFLOW_CHECK 2 /* XXX: for debugging */
#define MEMP_SANITY_CHECK 1 /* XXX: for debugging */
+#else
+#define MEMP_OVERFLOW_CHECK 0 /* XXX: for debugging */
+#define MEMP_SANITY_CHECK 0 /* XXX: for debugging */
+#endif
#define MEM_USE_POOLS_TRY_BIGGER_POOL 1
-#define TCPIP_MBOX_SIZE 64
-#define TCPIP_THREAD_PRIO 0
-#define TCPIP_THREAD_STACKSIZE 16384
+#define TCPIP_MBOX_SIZE 64
+#define TCPIP_THREAD_PRIO 0
+#define TCPIP_THREAD_STACKSIZE 32768
+
+#define DEFAULT_UDP_RECVMBOX_SIZE 16
+#define DEFAULT_TCP_RECVMBOX_SIZE 16
+#define DEFAULT_ACCEPTMBOX_SIZE 4
+
+#define LWIP_SOCKET 0
-#define MEMP_NUM_TCP_PCB 64
-#define MEMP_NUM_TCP_SEG 256
-#define MEMP_NUM_REASSDATA 32
-#define MEMP_NUM_SYS_TIMEOUT 8
-#define ARP_TABLE_SIZE 16
-#define IP_REASS_MAX_PBUFS 32
+#define MEM_LIBC_MALLOC 1
+#define MEMP_MEM_MALLOC 1
+
+#define MEMP_NUM_TCP_PCB 64
+#define MEMP_NUM_TCP_SEG 256
+#define MEMP_NUM_REASSDATA 32
+#define MEMP_NUM_SYS_TIMEOUT 8
+#define MEMP_NUM_NETCONN 64
+#define MEMP_NUM_TCPIP_MSG_API 64
+#define MEMP_NUM_TCPIP_MSG_INPKT 64
+#define PBUF_POOL_SIZE 256
+#define ARP_TABLE_SIZE 16
+#define IP_REASS_MAX_PBUFS 32
+#define IP_REASS_MAXAGE 10
#define LWIP_NETIF_API 1
#define LWIP_DNS 1
+#define DNS_TABLE_SIZE 16
#define DNS_MAX_SERVERS 4
#define TCP_WND 32768
#define TCP_MSS 4096
#define TCP_SND_BUF 4096
+#define ETHARP_TRUST_IP_MAC 0
+
#define LWIP_PLATFORM_BYTESWAP 1
#endif /* __LWIPOPTS_H__ */
diff --git a/core/lwip/src/netif/undiif.c b/core/lwip/src/netif/undiif.c
index 5033eee9..e8f515a7 100644
--- a/core/lwip/src/netif/undiif.c
+++ b/core/lwip/src/netif/undiif.c
@@ -76,14 +76,38 @@ static struct netif undi_netif;
* @param netif the already initialized lwip network interface structure
* for this undiif
*/
+extern uint8_t pxe_irq_vector;
+extern void pxe_isr(void);
+
+/* XXX: move this somewhere sensible */
+static void install_irq_vector(uint8_t irq, void (*isr)(void))
+{
+ unsigned int vec;
+
+ if (irq < 8)
+ vec = irq + 0x08;
+ else if (irq < 16)
+ vec = (irq - 8) + 0x70;
+ else
+ return; /* ERROR */
+
+ *(uint32_t *)(vec << 2) = (uint32_t)isr;
+}
+
static void
low_level_init(struct netif *netif)
{
static __lowmem t_PXENV_UNDI_GET_INFORMATION undi_info;
+ static __lowmem t_PXENV_UNDI_OPEN undi_open;
+ int i;
/* struct undiif *undiif = netif->state; */
pxe_call(PXENV_UNDI_GET_INFORMATION, &undi_info);
+ printf("UNDI: baseio %04x int %d MTU %d type %d\n",
+ undi_info.BaseIo, undi_info.IntNumber, undi_info.MaxTranUnit,
+ undi_info.HwType);
+
/* set MAC hardware address length */
netif->hwaddr_len = undi_info.HwAddrLen;
@@ -93,11 +117,22 @@ low_level_init(struct netif *netif)
/* maximum transfer unit */
netif->mtu = undi_info.MaxTranUnit;
+ printf("UNDI: hw address");
+ for (i = 0; i < netif->hwaddr_len; i++)
+ printf("%c%02x", i ? ':' : ' ', (uint8_t)netif->hwaddr[i]);
+ putchar('\n');
+
/* device capabilities */
/* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
- /* Do whatever else is needed to initialize interface. */
+ /* Install the interrupt vector */
+ pxe_irq_vector = undi_info.IntNumber;
+ install_irq_vector(pxe_irq_vector, pxe_isr);
+
+ /* Open the UNDI stack - you'd think the BC would have done this... */
+ undi_open.PktFilter = 0x0003; /* FLTR_DIRECTED | FLTR_BRDCST */
+ pxe_call(PXENV_UNDI_OPEN, &undi_open);
}
/**
@@ -148,16 +183,17 @@ low_level_output(struct netif *netif, struct pbuf *p)
r += q->len;
}
+ //printf("undiif_output, len = %d ", r - pkt_buf);
+
do {
memset(&pxe, 0, sizeof pxe);
pxe.xmit.Protocol = 0; /* XXX: P_UNKNOWN: MAC layer */
pxe.xmit.XmitFlag = !memcmp(pkt_buf, eth_broadcast, sizeof eth_broadcast);
- pxe.xmit.DestAddr = FAR_PTR(pkt_buf);
+ pxe.xmit.DestAddr = FAR_PTR(&pxe.tbd); /* This is what gPXE does?? */
pxe.xmit.TBD = FAR_PTR(&pxe.tbd);
pxe.tbd.ImmedLength = r - pkt_buf;
pxe.tbd.Xmit = FAR_PTR(pkt_buf);
- pxe.tbd.DataBlkCount = 0;
pxe_call(PXENV_UNDI_TRANSMIT, &pxe.xmit);
} while (pxe.xmit.Status == PXENV_STATUS_OUT_OF_RESOURCES);
@@ -198,6 +234,8 @@ low_level_input(t_PXENV_UNDI_ISR *isr)
variable. */
len = isr->FrameLength;
+ //printf("undiif_input, len = %d\n", len);
+
#if ETH_PAD_SIZE
len += ETH_PAD_SIZE; /* allow room for Ethernet padding */
#endif
@@ -319,29 +357,9 @@ void undiif_input(t_PXENV_UNDI_ISR *isr)
* ERR_MEM if private data couldn't be allocated
* any other err_t on error
*/
-extern uint8_t pxe_irq_vector;
-extern void pxe_isr(void);
-
-/* XXX: move this somewhere sensible */
-static void install_irq_vector(uint8_t irq, void (*isr)(void))
-{
- unsigned int vec;
-
- if (irq < 8)
- vec = irq + 0x08;
- else if (irq < 16)
- vec = (irq - 8) + 0x70;
- else
- return; /* ERROR */
-
- *(uint32_t *)(vec << 2) = (uint32_t)isr;
-}
-
static err_t
undiif_init(struct netif *netif)
{
- static __lowmem t_PXENV_UNDI_GET_INFORMATION undi_info;
-
LWIP_ASSERT("netif != NULL", (netif != NULL));
#if LWIP_NETIF_HOSTNAME
@@ -349,16 +367,6 @@ undiif_init(struct netif *netif)
netif->hostname = "undi";
#endif /* LWIP_NETIF_HOSTNAME */
- pxe_call(PXENV_UNDI_GET_INFORMATION, &undi_info);
-
- printf("UNDI: baseio %04x int %d MTU %d type %d\n",
- undi_info.BaseIo, undi_info.IntNumber, undi_info.MaxTranUnit,
- undi_info.HwType);
-
- /* Install the interrupt vector */
- pxe_irq_vector = undi_info.IntNumber;
- install_irq_vector(pxe_irq_vector, pxe_isr);
-
/*
* Initialize the snmp variables and counters inside the struct netif.
* The last argument should be replaced with your link speed, in units
@@ -386,11 +394,33 @@ err_t undi_tcpip_start(struct ip_addr *ipaddr,
struct ip_addr *netmask,
struct ip_addr *gw)
{
+ err_t err;
+
// Start the TCP/IP thread & init stuff
tcpip_init(NULL, NULL);
// This should be done *after* the threading system and receive thread
// have both been started.
- return netifapi_netif_add(&undi_netif, ipaddr, netmask, gw, NULL,
- undiif_init, ethernet_input);
+ printf("undi_netif: ip %d.%d.%d.%d netmask %d.%d.%d.%d gw %d.%d.%d.%d\n",
+ ((uint8_t *)ipaddr)[0],
+ ((uint8_t *)ipaddr)[1],
+ ((uint8_t *)ipaddr)[2],
+ ((uint8_t *)ipaddr)[3],
+ ((uint8_t *)netmask)[0],
+ ((uint8_t *)netmask)[1],
+ ((uint8_t *)netmask)[2],
+ ((uint8_t *)netmask)[3],
+ ((uint8_t *)gw)[0],
+ ((uint8_t *)gw)[1],
+ ((uint8_t *)gw)[2],
+ ((uint8_t *)gw)[3]);
+ err = netifapi_netif_add(&undi_netif, ipaddr, netmask, gw, NULL,
+ undiif_init, ethernet_input);
+ if (err)
+ return err;
+
+ netif_set_up(&undi_netif);
+ netif_set_default(&undi_netif); /* Make this interface the default route */
+
+ return ERR_OK;
}