#
#TCPSTACK, uIP is used currently
#
-UIP=ON
+UIP=OFF
#
#LWIP, ON -- used, OFF -- not used
ifeq ($(LWIP),ON)
LWIP_OBJS := lwip/*.o
+ CC_LWIP_OPTS := -I$(PROJECT_ROOT)/include/lwip -I$(PROJECT_ROOT)/include/lwip/ipv4 -I$(PROJECT_ROOT)/include/libc -DLWIP_DEBUG
else
LWIP_OBJS :=
+ CC_LWIP_OPTS :=
endif
TCPSTACK_OBJS := $(UIP_C_OBJS) $(LWIP_OBJS)
# Compilation of kernel C source files
geekos/%.o : geekos/%.c
- $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) $< -o geekos/$*.o
+ $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) $(CC_LWIP_OPTS) $< -o geekos/$*.o
# Compilation of kernel assembly source files
#include <geekos/ktypes.h>
#include <geekos/defs.h>
+
+// to stop the compilation warnings
+extern void Print(const char* fmt, ...);
+extern void Set_Current_Attr(uchar_t attrib);
+
/*
* This struct reflects the contents of the stack when
* a C interrupt handler function is called.
#define NE2K_IRQ 11 /* Interrupt channel */
+
+/* Physical Address of Network Card */
+#define PHY_ADDR1 0x52
+#define PHY_ADDR2 0x54
+#define PHY_ADDR3 0x00
+#define PHY_ADDR4 0x12
+#define PHY_ADDR5 0x34
+#define PHY_ADDR6 0x58
+
+
struct NE2K_REGS {
uchar_t cr;
uchar_t isr;
#define GEEKOS_SOCKET_H
#include <geekos/ring_buffer.h>
-#include <uip/uip.h>
#include <geekos/kthread.h>
+#ifdef UIP
+#include <uip/uip.h>
+
typedef enum {WAITING, CLOSED, LISTEN, ESTABLISHED} sock_state_t;
void set_ip_addr(uchar_t addr[4]);
+#endif /* UIP */
+
#endif
#define TIMER_IRQ 0
-extern volatile ulong_t g_numTicks;
+extern volatile unsigned long g_numTicks;
typedef void (*timerCallback)(int, void*);
void Micro_Delay(int us);
-ulong_t clock_time(void); //return elipsed millisecs
+unsigned long clock_time(void); //return elipsed millisecs
#endif /* GEEKOS_TIMER_H */
char *strpbrk(const char *s, const char *accept);
char *strncat(char *s1, const char *s2, size_t limit);
int fprintf(FILE *file, char *fmt, ...);
-//int fflush(FILE *file);
+int fflush(FILE *file);
+int printf(char *fmt, ...);
/* Include some files for defining library routines */
#include <string.h>
-
-extern int fflush(FILE *file);
-extern int printf(char *fmt, ...);
-extern void abort (void);
-
+#include <geekos/debug.h>
/* Define platform endianness */
#ifndef BYTE_ORDER
//#include <stdio.h>
//#include <stdlib.h>
/* Plaform specific diagnostic output */
-#define LWIP_PLATFORM_DIAG(x) //do {printf x;} while(0)
+#define LWIP_PLATFORM_DIAG(x) do {PrintBoth x;} while(0)//do {printf x;} while(0)
#define LWIP_PLATFORM_ASSERT(x) do {printf("Assertion \"%s\" failed at line %d in %s\n", \
x, __LINE__, __FILE__); fflush(NULL); abort();} while(0)
#ifndef __LWIP_IP_ADDR_H__
#define __LWIP_IP_ADDR_H__
-#include "lwip/opt.h"
+#include <lwip/lwip/opt.h>
#ifdef __cplusplus
extern "C" {
* Include user defined options first. Anything not defined in these files
* will be set to standard values. Override anything you dont like!
*/
-#include "lwipopts.h"
+#include <lwip/lwipopts.h>
#include "lwip/debug.h"
/*
* TCP_WND: The size of a TCP window.
*/
#ifndef TCP_WND
-#define TCP_WND 2048
+#define TCP_WND 1024 //2048
#endif
/**
* LWIP_NETIF_API==1: Support netif api (in netifapi.c)
*/
#ifndef LWIP_NETIF_API
-#define LWIP_NETIF_API 0
+#define LWIP_NETIF_API 1
#endif
/**
*
* \hideinitializer
*/
-typedef unsigned char u8_t;
+//conflict with lwip
+//typedef unsigned char u8_t;
/**
* 16 bit datatype
*
* \hideinitializer
*/
-typedef unsigned short int u16_t;
+//confict with lwip
+//typedef unsigned short int u16_t;
/**
* Statistics datatype
#include <geekos/irq.h>
#include <geekos/malloc.h>
#include <geekos/string.h>
+
+#ifdef UIP
#include <uip/uip.h>
#include <uip/uip_arp.h>
+#endif
#define DEBUG 1
#define TX_START_BUFF 0x40
cr->ps = 0x01; /* Switch to reg page 1 */
Out_Byte(NE2K_CR, regs->cr);
- /* Set the physical address of the card to 52:54:00:12:34:58 */
- Out_Byte(NE2K_CR+0x01, 0x52);
- Out_Byte(NE2K_CR+0x02, 0x54);
- Out_Byte(NE2K_CR+0x03, 0x00);
- Out_Byte(NE2K_CR+0x04, 0x12);
- Out_Byte(NE2K_CR+0x05, 0x34);
- Out_Byte(NE2K_CR+0x06, 0x58);
+ /* Set the physical address of the card */
+ Out_Byte(NE2K_CR+0x01, PHY_ADDR1);
+ Out_Byte(NE2K_CR+0x02, PHY_ADDR2);
+ Out_Byte(NE2K_CR+0x03, PHY_ADDR3);
+ Out_Byte(NE2K_CR+0x04, PHY_ADDR4);
+ Out_Byte(NE2K_CR+0x05, PHY_ADDR5);
+ Out_Byte(NE2K_CR+0x06, PHY_ADDR6);
/* Set the multicast address register to all 1s; accepts all multicast packets */
uint_t i;
* an ARP packet, which is sent out instead. The original packet will need to be
* retransmitted at some point in the future.
*/
+#ifdef UIP
+
int NE2K_Transmit(uint_t size)
{
uip_arp_out();
return 0;
}
+#endif
+
int NE2K_Send_Packet(uchar_t *packet, uint_t size)
{
struct _CR * cr = (struct _CR*)&(regs->cr);
#include <geekos/net.h>
#include <geekos/socket.h>
#include <geekos/ne2k.h>
+#include <lwip/apps/ping.h>
+#include <lwip/lwip/sockets.h>
+#include <lwip/ipv4/lwip/ip_addr.h>
+#include <lwip/netif/ne2kif.h>
+#include <lwip/sys.h>
+#include <lwip/netifapi.h>
+#include <lwip/tcpip.h>
+#include <netif/etharp.h>
+#include <geekos/debug.h>
-void Init_Network() {
- init_socket_layer();
+
+static void
+tcpip_init_done(void *arg)
+{
+ sys_sem_t *sem;
+ sem = arg;
+ sys_sem_signal(*sem);
}
+void Init_Network() {
+
+ //temporay now we are using lwip sockets
+ // init_socket_layer();
+
+ struct ip_addr ipaddr, netmask, gateway;
+ sys_sem_t sem;
+ err_t err;
+
+ sem = sys_sem_new(0);
+
+#ifdef LWIP_DEBUG
+ PrintBoth("lwIP: before tcpip_init\n");
+#endif
+
+ tcpip_init(tcpip_init_done, &sem); //initial the whole lwip module
+#ifdef LWIP_DEBUG
+ PrintBoth("lwIP: After tcpip_init\n");
+#endif
+ sys_sem_wait(sem);
+ sys_sem_free(sem);
+
+ IP4_ADDR(&gateway, 192,168,1,1);
+ IP4_ADDR(&ipaddr, 192,168,1,2);
+ IP4_ADDR(&netmask, 255,255,255,0);
+
+ err = netifapi_netif_add(&ne2kif, &ipaddr, &netmask, &gateway,
+ NULL, ne2kif_init, ethernet_input);
+
+ if (err != ERR_OK){
+ PrintBoth("lwip: initial network failed! add netif error %d/n", err);
+ return;
+ }
+
+ netifapi_netif_set_default(&ne2kif);
+
+ //initial a network application
+ ping_init();
+}
+
+
+#if 0
void test_network() {
uchar_t local_addr[4];
local_addr[2] = 2;
local_addr[3] = 21;
- set_ip_addr(local_addr);
+// set_ip_addr(local_addr);
remote_addr[0] = 10;
remote_addr[1] = 0;
remote_addr[3] = 20;
- connect(remote_addr, 4301);
+ // connect(remote_addr, 4301);
}
+
+#endif
#include <geekos/socket.h>
#include <geekos/malloc.h>
#include <geekos/ne2k.h>
+
+#ifdef UIP
+
#include <uip/uip.h>
#include <uip/uip_arp.h>
+
#include <geekos/vmm_stubs.h>
#include <geekos/debug.h>
#include <geekos/timer.h>
-
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
#define MAX_SOCKS 1024
#endif /* UIP_APPCALL */
-
-
static int Packet_Received(struct NE2K_Packet_Info* info, uchar_t *pkt);
static void periodic_caller(int timer_id, void * arg);
void init_socket_layer() {
+
int i = 0;
bool iflag;
sockets[i].state = CLOSED;
}
-
-
//initiate uIP
uip_init();
uip_arp_init();
- //setup device driver
- Init_Ne2k(&Packet_Received);
+ //setup device driver
+ Init_Ne2k(&Packet_Received);
iflag = Begin_Int_Atomic();
Start_Timer(2, periodic_caller, NULL);
End_Int_Atomic(iflag);
-
}
-
-
-
void set_ip_addr(uchar_t addr[4]) {
uip_ipaddr_t ipaddr;
uip_ipaddr(ipaddr, addr[0], addr[1], addr[2], addr[3]); /* Local IP address */
uip_sethostaddr(ipaddr);
}
-
static int allocate_socket_fd() {
int i = 0;
}
-
static void periodic_caller(int timer_id, void * arg) {
int i;
//handle the periodic calls of uIP
return 0;
}
+
+
+#endif /* UIP */
#include <geekos/synch.h>
#include <geekos/timer.h>
+#include <geekos/debug.h>
+
/*
* NOTES:
* - The GeekOS mutex and condition variable APIs are based on those
KASSERT(!Interrupts_Enabled());
+ PrintBoth ("there\n");
+
if (timeEventCount == MAX_TIMER_EVENTS) {
return -1;
} else {
LOCK_TCPIP_CORE();
while (1) { /* MAIN Loop */
+
+ PrintBoth("In tcp_thread: main loop\n");
+
sys_mbox_fetch(mbox, (void *)&msg);
+
switch (msg->type) {
#if LWIP_NETCONN
case TCPIP_MSG_API:
# APIFILES: The files which implement the sequential and socket APIs.
APIFILES=$(LWIPDIR)/api/api_lib.c $(LWIPDIR)/api/api_msg.c $(LWIPDIR)/api/tcpip.c \
- $(LWIPDIR)/api/err.c $(LWIPDIR)/api/sockets.c $(LWIPDIR)/api/netbuf.c $(LWIPDIR)/api/netdb.c
+ $(LWIPDIR)/api/err.c $(LWIPDIR)/api/sockets.c $(LWIPDIR)/api/netbuf.c $(LWIPDIR)/api/netdb.c $(LWIPDIR)/api/netifapi.c
# NETIFFILES: Files implementing various generic network interface functions.'
-NETIFFILES=$(LWIPDIR)/netif/loopif.c \
- $(LWIPDIR)/netif/etharp.c
+NETIFFILES=$(LWIPDIR)/netif/loopif.c $(LWIPDIR)/netif/ne2kif.c $(LWIPDIR)/netif/etharp.c
# ARCHFILES: Architecture specific files.
ARCHFILES=$(LWIPDIR)/arch/sys_arch.c
+# APPFILES: Application files
+APPFILES=$(LWIPDIR)/apps/ping.c
+
# LWIPFILES: All the above.
-LWIPFILES=$(COREFILES) $(CORE4FILES) $(APIFILES) $(NETIFFILES) $(ARCHFILES)
+LWIPFILES=$(COREFILES) $(CORE4FILES) $(APIFILES) $(NETIFFILES) $(ARCHFILES) $(APPFILES)
LWIPFILESW=$(wildcard $(LWIPFILES))
LWIPOBJS=$(notdir $(LWIPFILESW:.c=.o))
if (TCP_SNDLOWAT > TCP_SND_BUF)
LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_SNDLOWAT must be less than or equal to TCP_SND_BUF.\n"));
if (TCP_WND > (PBUF_POOL_SIZE*PBUF_POOL_BUFSIZE))
- LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_WND is larger than space provided by PBUF_POOL_SIZE*PBUF_POOL_BUFSIZE\n"));
+ LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_WND is larger than space provided by PBUF_POOL_SIZE*PBUF_POOL_BUFSIZE: %d\n", (PBUF_POOL_SIZE*PBUF_POOL_BUFSIZE)));
if (TCP_WND < TCP_MSS)
LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_WND is smaller than MSS\n"));
#endif /* LWIP_TCP */