diff --git a/src/sys/include/isa/ne2k.h b/src/sys/include/isa/ne2k.h index 354d35d..a4e86a3 100644 --- a/src/sys/include/isa/ne2k.h +++ b/src/sys/include/isa/ne2k.h @@ -41,6 +41,13 @@ unsigned short shorts[3]; /* force 2-byte alignment */ } ether_addr; + +struct nicBuffer { + struct nicBuffer *next; + int length; + char *buffer; + }; + #define RSR_FO 0x08 #define RSR_PRX 0x01 #define DEF_ENABLED 0x200 @@ -155,6 +162,9 @@ int NICtoPC(struct device *dev,void *packet,int length,int nic_addr); int PCtoNIC(struct device *dev,void *packet,int length); +struct nicBuffer *allocBuffer(int); +struct nicBuffer *getBuffer(); + #endif /*** diff --git a/src/sys/init/main.c b/src/sys/init/main.c index 96dc3c1..7a96c5e 100644 --- a/src/sys/init/main.c +++ b/src/sys/init/main.c @@ -24,6 +24,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. $Log$ + Revision 1.3 2004/04/15 12:53:08 reddawg + There Fixed + Revision 1.2 2004/04/15 12:38:25 reddawg Fixed to compile @@ -133,11 +136,9 @@ if (timeInit() != 0x0) { kpanic("Error: Initializing TIME\n"); } - /* if (ne2kInit(0x240) != 0x0) { kpanic("Error: Initializing NE2000\n"); } - */ enableUbixFS(); fdcInit(); //initHardDisk(); @@ -150,9 +151,10 @@ kprintf("Free Pages: [%i]\n",freePages); kprintf("MemoryMap: [0x%X]\n",vmmMemoryMap); kprintf("Starting Os\n"); - //netInit(); + netInit(); execThread(idleTask,(uInt32)(kmalloc(0x2000,sysID)+0x2000),0x0,"Idle Thread"); - execFile("init@sys",0x0,0x0,0x0); + //execFile("init@sys",0x0,0x0,0x0); + execFile("shell@sys",0x0,0x0,0x0); irqEnable(0x0); sched(); return(0x0); diff --git a/src/sys/isa/ne2k.c b/src/sys/isa/ne2k.c index 592386a..776abf9 100644 --- a/src/sys/isa/ne2k.c +++ b/src/sys/isa/ne2k.c @@ -24,6 +24,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. $Log$ + Revision 1.1.1.1 2004/04/15 12:07:09 reddawg + UbixOS v1.0 + Revision 1.15 2004/04/13 16:36:33 reddawg Changed our copyright, it is all now under a BSD-Style license @@ -49,8 +52,8 @@ static void getblock(struct device *dev,int page,size_t offset,size_t size,void *dst); static int dp_recv(struct device *); -uInt32 packetLength; -char *nicPacket; +static struct nicBuffer *ne2kBuffer = 0x0; + asm( ".globl ne2kISR \n" "ne2kISR: \n" @@ -69,8 +72,6 @@ ************************************************************************/ int ne2kInit(uInt32 ioAddr) { - - char *packet = 0x0; struct device *dev = (struct device *)kmalloc(sizeof(struct device),sysID); dev->ioAddr = 0x240; dev->irq = 3; @@ -113,120 +114,7 @@ outportByte(dev->ioAddr + NE_CMD, 0x0); outportByte(dev->ioAddr + NE_DCR, 0x29); - packet = (char *)kmalloc(256,sysID); - - packet[00] = 0x00; - packet[01] = 0xbd; - packet[02] = 0xe4; - packet[3] = 0x70; - packet[4] = 0x01; - packet[5] = 0x00; - packet[6] = 0x01; - packet[7] = 0x02; - packet[8] = 0x03; - packet[9] = 0x04; - packet[10] = 0x05; - packet[11] = 0x06; - packet[12] = 0x08; - packet[13] = 0x00; - packet[14] = 0x45; - packet[15] = 0x00; - packet[16] = 0x00; - packet[17] = 0x54; - packet[18] = 0xab; - packet[19] = 0x89; - packet[20] = 0x00; - packet[21] = 0x00; - packet[22] = 0x40; - packet[23] = 0x01; - packet[24] = 0x4d; - packet[25] = 0xcc; - packet[26] = 0xc0; - packet[27] = 0xa8; - packet[28] = 0x00; - packet[29] = 0x45; - packet[30] = 0xc0; - packet[31] = 0xa8; - packet[32] = 0x00; - packet[33] = 0x01; - packet[34] = 0x00; - packet[35] = 0x00; - packet[36] = 0x27; - packet[37] = 0x00; - packet[38] = 0x1d; - packet[39] = 0x71; - packet[40] = 0x00; - packet[41] = 0x0d; - packet[42] = 0x2c; - packet[43] = 0xa4; - packet[44] = 0x79; - packet[45] = 0x40; - packet[46] = 0x1f; - packet[47] = 0x9a; - packet[48] = 0x0b; - packet[49] = 0x00; - packet[50] = 0x08; - packet[51] = 0x09; - packet[52] = 0x0a; - packet[53] = 0x0b; - packet[54] = 0x0c; - packet[55] = 0x0d; - packet[56] = 0x0e; - packet[57] = 0x0f; - packet[58] = 0x10; - packet[59] = 0x11; - packet[60] = 0x12; - packet[61] = 0x13; - packet[62] = 0x14; - packet[63] = 0x15; - - packet[64] = 0x16; - packet[65] = 0x17; - packet[66] = 0x18; - packet[67] = 0x19; - packet[68] = 0x1a; - packet[69] = 0x1b; - packet[70] = 0x1c; - packet[71] = 0x1d; - packet[72] = 0x1e; - packet[73] = 0x1f; - packet[74] = 0x20; - packet[75] = 0x21; - packet[76] = 0x22; - packet[77] = 0x23; - packet[78] = 0x24; - packet[79] = 0x25; - packet[80] = 0x26; - packet[81] = 0x27; - packet[82] = 0x28; - packet[83] = 0x29; - packet[84] = 0x2a; - packet[85] = 0x2b; - packet[86] = 0x2c; - packet[87] = 0x2d; - packet[88] = 0x2e; - packet[89] = 0x2f; - packet[90] = 0x30; - packet[91] = 0x31; - packet[92] = 0x32; - packet[93] = 0x33; - packet[94] = 0x34; - packet[95] = 0x35; - packet[96] = 0x36; - packet[97] = 0x37; - - kprintf("A"); - if (PCtoNIC(dev,packet,98) == 0x0) { - kprintf("Error Sending To Nic\n"); - } - - packetLength = 0x0; - nicPacket = 0x0; - - kprintf("B"); kfree(dev); - kprintf("C"); - kfree(packet); kprintf("Initialized"); /* Return so we know everything went well */ return(0x0); @@ -416,9 +304,7 @@ static int dp_pkt2user(struct device *dev,int page,int length) { int last; - char *packet = 0x0; - - packet = (char *)kmalloc(512,sysID); + struct nicBuffer *tmpBuf = 0x0; last = page + (length - 1) / DP_PAGESIZE; @@ -426,122 +312,42 @@ kprintf("A"); } else { - NICtoPC(dev,packet,length,page * DP_PAGESIZE + sizeof(dp_rcvhdr_t)); - //getblock(dev,page,sizeof(dp_rcvhdr_t),length,packet); + tmpBuf = allocBuffer(length); + NICtoPC(dev,tmpBuf->buffer,length,page * DP_PAGESIZE + sizeof(dp_rcvhdr_t)); } - packetLength = length; - nicPacket = packet; - - //packet[29] = 0x45; - //packet[33] = 0x01; - /* - - packet[00] = 0x00; - packet[01] = 0xbd; - packet[02] = 0xe4; - packet[3] = 0x70; - packet[4] = 0x01; - packet[5] = 0x00; - packet[6] = 0x01; - packet[7] = 0x02; - packet[8] = 0x03; - packet[9] = 0x04; - packet[10] = 0x05; - packet[11] = 0x06; - packet[12] = 0x08; - packet[13] = 0x00; - packet[14] = 0x45; - packet[15] = 0x00; - packet[16] = 0x00; - packet[17] = 0x54; - packet[18] = 0xab; - - packet[19] = 0x89; - packet[20] = 0x00; - packet[21] = 0x00; - packet[22] = 0x40; - packet[23] = 0x01; - packet[24] = 0x4d; - packet[25] = 0xcc; - packet[26] = 0xc0; - packet[27] = 0xa8; - packet[28] = 0x00; - packet[29] = 0x45; - packet[30] = 0xc0; - packet[31] = 0xa8; - packet[32] = 0x00; - packet[33] = 0x01; - packet[34] = 0x00; - packet[35] = 0x00; - packet[36] += 0x08; - packet[37] = 0x00; - packet[38] = 0x1d; - packet[39] = 0x71; - packet[40] = 0x00; - - packet[41] = 0x0d; - packet[42] = 0x2c; - packet[43] = 0xa4; - packet[44] = 0x79; - packet[45] = 0x40; - packet[46] = 0x1f; - packet[47] = 0x9a; - packet[48] = 0x0b; - packet[49] = 0x00; - packet[50] = 0x08; - packet[51] = 0x09; - packet[52] = 0x0a; - packet[53] = 0x0b; - packet[54] = 0x0c; - packet[55] = 0x0d; - packet[56] = 0x0e; - packet[57] = 0x0f; - packet[58] = 0x10; - packet[59] = 0x11; - packet[60] = 0x12; - packet[61] = 0x13; - packet[62] = 0x14; - packet[63] = 0x15; - packet[64] = 0x16; - packet[65] = 0x17; - packet[66] = 0x18; - packet[67] = 0x19; - packet[68] = 0x1a; - packet[69] = 0x1b; - packet[70] = 0x1c; - packet[71] = 0x1d; - packet[72] = 0x1e; - packet[73] = 0x1f; - packet[74] = 0x20; - packet[75] = 0x21; - packet[76] = 0x22; - packet[77] = 0x23; - packet[78] = 0x24; - packet[79] = 0x25; - packet[80] = 0x26; - packet[81] = 0x27; - packet[82] = 0x28; - packet[83] = 0x29; - packet[84] = 0x2a; - packet[85] = 0x2b; - packet[86] = 0x2c; - packet[87] = 0x2d; - packet[88] = 0x2e; - packet[89] = 0x2f; - packet[90] = 0x30; - packet[91] = 0x31; - packet[92] = 0x32; - packet[93] = 0x33; - packet[94] = 0x34; - packet[95] = 0x35; - packet[96] = 0x36; - packet[97] = 0x37; - - PCtoNIC(dev,packet,length); - */ kprintf("."); return(OK); } +struct nicBuffer *allocBuffer(int length) { + struct nicBuffer *tmpBuf = 0x0; + if (ne2kBuffer == 0x0) { + ne2kBuffer = (struct nicBuffer *)kmalloc(sizeof(struct nicBuffer),sysID); + ne2kBuffer->next = 0x0; + ne2kBuffer->length = length; + ne2kBuffer->buffer = (char *)kmalloc(length,sysID); + return(ne2kBuffer); + } + else { + for (tmpBuf = ne2kBuffer;tmpBuf->next != 0x0;tmpBuf = tmpBuf->next); + tmpBuf->next = (struct nicBuffer *)kmalloc(sizeof(struct nicBuffer),sysID); + tmpBuf = tmpBuf->next; + tmpBuf->next = 0x0; + tmpBuf->length = length; + tmpBuf->buffer = (char *)kmalloc(length,sysID); + return(tmpBuf); + } + return(0x0); + } + +struct nicBuffer *getBuffer() { + struct nicBuffer *tmpBuf = 0x0; + tmpBuf = ne2kBuffer; + ne2kBuffer = ne2kBuffer->next; + return(tmpBuf); + } + /*** END ***/ diff --git a/src/sys/net/net/shell.c b/src/sys/net/net/shell.c index e7aac55..b388f5d 100644 --- a/src/sys/net/net/shell.c +++ b/src/sys/net/net/shell.c @@ -42,18 +42,8 @@ #include "net/api.h" #include "net/stats.h" -struct command { - struct netconn *conn; - Int8 (* exec)(struct command *); - uInt8 nargs; - char *args[10]; -}; - char *buffer = 0x0; -//#include -//#include - #define ESUCCESS 0 #define ESYNTAX -1 #define ETOOFEW -2 @@ -63,967 +53,31 @@ #define NCONNS 10 static struct netconn *conns[NCONNS]; -static char help_msg[] = "Avaliable commands:\n\ -open [IP address] [TCP port]: opens a TCP connection to the specified address.\n\ -lstn [TCP port]: sets up a server on the specified port.\n\ -acpt [connection #]: waits for an incoming connection request.\n\ -send [connection #] [message]: sends a message on a TCP connection.\n\ -udpc [local UDP port] [IP address] [remote port]: opens a UDP \"connection\".\n\ -udpl [local UDP port] [IP address] [remote port]: opens a UDP-Lite \"connection\".\n\ -udpn [local UDP port] [IP address] [remote port]: opens a UDP \"connection\" without checksums.\n\ -udpb [local port] [remote port]: opens a UDP broadcast \"connection\".\n\ -usnd [connection #] [message]: sends a message on a UDP connection.\n\ -recv [connection #]: recieves data on a TCP or UDP connection.\n\ -clos [connection #]: closes a TCP or UDP connection.\n\ -stat: prints out lwIP statistics.\n\ -quit: quits.\n"; - -static char *stat_msgs[] = { - "Link level * transmitted ", - " retransmitted ", - " * received ", - " forwarded ", - " * dropped ", - " * checksum errors ", - " * length errors ", - " * memory errors ", - " routing errors ", - " protocol errors ", - " option errors ", - " * misc errors ", - " cache hits ", - "IP * transmitted ", - " retransmitted ", - " * received ", - " * forwarded ", - " * dropped ", - " * checksum errors ", - " * length errors ", - " * memory errors ", - " * routing errors ", - " * protocol errors ", - " * option errors ", - " * misc errors ", - " cache hits ", - "ICMP * transmitted ", - " retransmitted ", - " * received ", - " forwarded ", - " * dropped ", - " * checksum errors ", - " length errors ", - " * memory errors ", - " routing errors ", - " * protocol errors ", - " option errors ", - " * misc errors ", - " cache hits ", - "UDP * transmitted ", - " retransmitted ", - " * received ", - " forwarded ", - " * dropped ", - " * checksum errors ", - " * length errors ", - " * memory errors ", - " * routing errors ", - " * protocol errors ", - " option errors ", - " * misc errors ", - " cache hits ", - "TCP * transmitted ", - " * retransmitted ", - " * received ", - " forwarded ", - " * dropped ", - " * checksum errors ", - " * length errors ", - " * memory errors ", - " * routing errors ", - " * protocol errors ", - " * option errors ", - " * misc errors ", - " * cache hits ", - "Pbufs * avaiable ", - " * used ", - " * high water mark ", - " * errors ", - " reclaimed ", - " pbuf_alloc() locked ", - " pbuf_refresh() locked ", - "Memory * avaliable ", - " * used ", - " * high water mark ", - " * errors ", - " * reclaimed ", - "Memp PBUF * avaliable ", - " * used ", - " * high water mark ", - " * errors ", - " * reclaimed ", - "UDP PCB * avaliable ", - " * used ", - " * high water mark ", - " * errors ", - " * reclaimed ", - "TCP PCB * avaliable ", - " * used ", - " * high water mark ", - " * errors ", - " * reclaimed ", - "TCP LISTEN * avaliable ", - " * used ", - " * high water mark ", - " * errors ", - " * reclaimed ", - "TCP SEG * avaliable ", - " * used ", - " * high water mark ", - " * errors ", - " * reclaimed ", - "Netbufs * avaliable ", - " * used ", - " * high water mark ", - " * errors ", - " * reclaimed ", - "Netconns * avaliable ", - " * used ", - " * high water mark ", - " * errors ", - " * reclaimed ", - "API msgs * avaliable ", - " * used ", - " * high water mark ", - " * errors ", - " * reclaimed ", - "TCPIP msgs * avaliable ", - " * used ", - " * high water mark ", - " * errors ", - " * reclaimed ", - "Timeouts * avaliable ", - " * used ", - " * high water mark ", - " * errors ", - " * reclaimed ", - "Semaphores * used ", - " * high water mark ", - " * errors ", - "Mailboxes * used ", - " * high water mark ", - " * errors " -}; -/*-----------------------------------------------------------------------------------*/ -static void -sendstr(const char *str, struct netconn *conn) -{ +static void sendstr(const char *str, struct netconn *conn) { netconn_write(conn, (void *)str, kstrlen(str), NETCONN_NOCOPY); -} -/*-----------------------------------------------------------------------------------*/ -static Int8 -com_open(struct command *com) -{ - struct ip_addr ipaddr; - uInt16 port; - int i; - err_t err; - - if(inet_aton(com->args[0], &ipaddr) == -1) { - //sendstr(strerror(errno), com->conn); - return ESYNTAX; - } - ipaddr.addr = 0xC0A80001; - port = strtol(com->args[1], NULL, 10); - - /* Find the first unused connection in conns. */ - for(i = 0; i < NCONNS && conns[i] != NULL; i++); - - if(i == NCONNS) { - sendstr("No more connections avaliable, sorry.\n", com->conn); - return ESUCCESS; } - sendstr("Opening connection to ", com->conn); - netconn_write(com->conn, com->args[0], kstrlen(com->args[0]), NETCONN_COPY); - sendstr(":", com->conn); - netconn_write(com->conn, com->args[1], kstrlen(com->args[1]), NETCONN_COPY); - sendstr("\n", com->conn); +static void prompt(struct netconn *conn) { + sendstr("uBixCube:@sys> ", conn); + } - conns[i] = netconn_new(NETCONN_TCP); - if(conns[i] == NULL) { - sendstr("Could not create connection identifier (out of memory).\n", com->conn); - return ESUCCESS; - } - err = netconn_connect(conns[i], &ipaddr, port); - if(err != ERR_OK) { - //fprintf(stderr, "error %s\n", lwip_strerr(err)); - sendstr("Could not connect to remote host: ", com->conn); -#ifdef LWIP_DEBUG - sendstr(lwip_strerr(err), com->conn); -#else - sendstr("(debugging must be turned on for error message to appear)", com->conn); -#endif /* LWIP_DEBUG */ - sendstr("\n", com->conn); - netconn_delete(conns[i]); - conns[i] = NULL; - return ESUCCESS; - } - - sendstr("Opened connection, connection identifier is ", com->conn); - sprintf(buffer, "%d\n", i); - netconn_write(com->conn, buffer, kstrlen(buffer), NETCONN_COPY); - - return ESUCCESS; -} -/*-----------------------------------------------------------------------------------*/ -static Int8 -com_lstn(struct command *com) -{ - uInt16 port; - int i; - err_t err; - - port = strtol(com->args[0], NULL, 10); - - /* Find the first unused connection in conns. */ - for(i = 0; i < NCONNS && conns[i] != NULL; i++); - - if(i == NCONNS) { - sendstr("No more connections avaliable, sorry.\n", com->conn); - return ESUCCESS; - } - - sendstr("Opening a listening connection on port ", com->conn); - netconn_write(com->conn, com->args[0], kstrlen(com->args[0]), NETCONN_COPY); - sendstr("\n", com->conn); - - conns[i] = netconn_new(NETCONN_TCP); - if(conns[i] == NULL) { - sendstr("Could not create connection identifier (out of memory).\n", com->conn); - return ESUCCESS; - } - - err = netconn_bind(conns[i], IP_ADDR_ANY, port); - if(err != ERR_OK) { - netconn_delete(conns[i]); - conns[i] = NULL; - sendstr("Could not bind: ", com->conn); -#ifdef LWIP_DEBUG - sendstr(lwip_strerr(err), com->conn); -#else - sendstr("(debugging must be turned on for error message to appear)", com->conn); -#endif /* LWIP_DEBUG */ - sendstr("\n", com->conn); - return ESUCCESS; - } - - err = netconn_listen(conns[i]); - if(err != ERR_OK) { - netconn_delete(conns[i]); - conns[i] = NULL; - sendstr("Could not listen: ", com->conn); -#ifdef LWIP_DEBUG - sendstr(lwip_strerr(err), com->conn); -#else - sendstr("(debugging must be turned on for error message to appear)", com->conn); -#endif /* LWIP_DEBUG */ - sendstr("\n", com->conn); - return ESUCCESS; - } - - sendstr("Opened connection, connection identifier is ", com->conn); - sprintf(buffer, "%d\n", i); - netconn_write(com->conn, buffer, kstrlen(buffer), NETCONN_COPY); - - return ESUCCESS; -} -/*-----------------------------------------------------------------------------------*/ -/*-----------------------------------------------------------------------------------*/ -static Int8 -com_clos(struct command *com) -{ - int i; - err_t err; - - i = strtol(com->args[0], NULL, 10); - - if(i > NCONNS) { - sendstr("Connection identifier too high.\n", com->conn); - return ESUCCESS; - } - if(conns[i] == NULL) { - sendstr("Connection identifier not in use.\n", com->conn); - return ESUCCESS; - } - - err = netconn_close(conns[i]); - if(err != ERR_OK) { - sendstr("Could not close connection: ", com->conn); -#ifdef LWIP_DEBUG - sendstr(lwip_strerr(err), com->conn); -#else - sendstr("(debugging must be turned on for error message to appear)", com->conn); -#endif /* LWIP_DEBUG */ - sendstr("\n", com->conn); - return ESUCCESS; - } - - sendstr("Connection closed.\n", com->conn); - netconn_delete(conns[i]); - conns[i] = NULL; - return ESUCCESS; -} -/*-----------------------------------------------------------------------------------*/ -static Int8 -com_acpt(struct command *com) -{ - int i, j; - - /* Find the first unused connection in conns. */ - for(j = 0; j < NCONNS && conns[j] != NULL; j++); - - if(j == NCONNS) { - sendstr("No more connections avaliable, sorry.\n", com->conn); - return ESUCCESS; - } - - i = strtol(com->args[0], NULL, 10); - - if(i > NCONNS) { - sendstr("Connection identifier too high.\n", com->conn); - return ESUCCESS; - } - if(conns[i] == NULL) { - sendstr("Connection identifier not in use.\n", com->conn); - return ESUCCESS; - } - - conns[j] = netconn_accept(conns[i]); - - if(conns[j] == NULL) { - sendstr("Could not accept connection: ", com->conn); -#ifdef LWIP_DEBUG - sendstr(lwip_strerr(netconn_err(conns[i])), com->conn); -#else - sendstr("(debugging must be turned on for error message to appear)", com->conn); -#endif /* LWIP_DEBUG */ - sendstr("\n", com->conn); - return ESUCCESS; - } - - sendstr("Accepted connection, connection identifier for new connection is ", com->conn); - sprintf(buffer, "%d\n", j); - netconn_write(com->conn, buffer, kstrlen(buffer), NETCONN_COPY); - - return ESUCCESS; -} -/*-----------------------------------------------------------------------------------*/ -static Int8 -com_stat(struct command *com) -{ - int i; - char buf[100]; - uInt16 len; - - for(i = 0; i < sizeof(struct stats_) / 2; i++) { - len = sprintf(buf, "%d", ((uInt16 *)&stats)[i]); - sendstr(stat_msgs[i], com->conn); - netconn_write(com->conn, buf, len, NETCONN_COPY); - sendstr("\n", com->conn); - } - - - return ESUCCESS; -} -/*-----------------------------------------------------------------------------------*/ -static Int8 -com_send(struct command *com) -{ - int i; - err_t err; - int len; - - i = strtol(com->args[0], NULL, 10); - - if(i > NCONNS) { - sendstr("Connection identifier too high.\n", com->conn); - return ESUCCESS; - } - - if(conns[i] == NULL) { - sendstr("Connection identifier not in use.\n", com->conn); - return ESUCCESS; - } - - len = kstrlen(com->args[1]); - com->args[1][len] = '\r'; - com->args[1][len + 1] = '\n'; - com->args[1][len + 2] = 0; - - err = netconn_write(conns[i], com->args[1], len + 3, NETCONN_COPY); - if(err != ERR_OK) { - sendstr("Could not send data: ", com->conn); -#ifdef LWIP_DEBUG - sendstr(lwip_strerr(err), com->conn); -#else - sendstr("(debugging must be turned on for error message to appear)", com->conn); -#endif /* LWIP_DEBUG */ - sendstr("\n", com->conn); - return ESUCCESS; - } - - sendstr("Data enqueued for sending.\n", com->conn); - return ESUCCESS; -} -/*-----------------------------------------------------------------------------------*/ -static Int8 -com_recv(struct command *com) -{ - int i; - err_t err; - struct netbuf *buf; - uInt16 len; - - i = strtol(com->args[0], NULL, 10); - - if(i > NCONNS) { - sendstr("Connection identifier too high.\n", com->conn); - return ESUCCESS; - } - - if(conns[i] == NULL) { - sendstr("Connection identifier not in use.\n", com->conn); - return ESUCCESS; - } - - buf = netconn_recv(conns[i]); - if(buf != NULL) { - - netbuf_copy(buf, buffer, 1024); - len = netbuf_len(buf); - sendstr("Reading from connection:\n", com->conn); - netconn_write(com->conn, buffer, len, NETCONN_COPY); - netbuf_delete(buf); - } else { - sendstr("EOF.\n", com->conn); - } - err = netconn_err(conns[i]); - if(err != ERR_OK) { - sendstr("Could not receive data: ", com->conn); -#ifdef LWIP_DEBUG - sendstr(lwip_strerr(err), com->conn); -#else - sendstr("(debugging must be turned on for error message to appear)", com->conn); -#endif /* LWIP_DEBUG */ - sendstr("\n", com->conn); - return ESUCCESS; - } - return ESUCCESS; -} -/*-----------------------------------------------------------------------------------*/ -static Int8 -com_udpc(struct command *com) -{ - struct ip_addr ipaddr; - uInt16 lport, rport; - int i; - err_t err; - - lport = strtol(com->args[0], NULL, 10); - if(inet_aton(com->args[1], &ipaddr) == -1) { - //sendstr(strerror(errno), com->conn); - return ESYNTAX; - } - ipaddr.addr = 0xC0A80001; - rport = strtol(com->args[2], NULL, 10); - - /* Find the first unused connection in conns. */ - for(i = 0; i < NCONNS && conns[i] != NULL; i++); - - if(i == NCONNS) { - sendstr("No more connections avaliable, sorry.\n", com->conn); - return ESUCCESS; - } - - sendstr("Setting up UDP connection from port ", com->conn); - netconn_write(com->conn, com->args[0], kstrlen(com->args[0]), NETCONN_COPY); - sendstr(" to ", com->conn); - netconn_write(com->conn, com->args[1], kstrlen(com->args[1]), NETCONN_COPY); - sendstr(":", com->conn); - netconn_write(com->conn, com->args[2], kstrlen(com->args[2]), NETCONN_COPY); - sendstr("\n", com->conn); - - conns[i] = netconn_new(NETCONN_UDP); - if(conns[i] == NULL) { - sendstr("Could not create connection identifier (out of memory).\n", com->conn); - return ESUCCESS; - } - - err = netconn_connect(conns[i], &ipaddr, rport); - if(err != ERR_OK) { - netconn_delete(conns[i]); - conns[i] = NULL; - sendstr("Could not connect to remote host: ", com->conn); -#ifdef LWIP_DEBUG - sendstr(lwip_strerr(err), com->conn); -#else - sendstr("(debugging must be turned on for error message to appear)", com->conn); -#endif /* LWIP_DEBUG */ - sendstr("\n", com->conn); - return ESUCCESS; - } - - err = netconn_bind(conns[i], IP_ADDR_ANY, lport); - if(err != ERR_OK) { - netconn_delete(conns[i]); - conns[i] = NULL; - sendstr("Could not bind: ", com->conn); -#ifdef LWIP_DEBUG - sendstr(lwip_strerr(err), com->conn); -#else - sendstr("(debugging must be turned on for error message to appear)", com->conn); -#endif /* LWIP_DEBUG */ - sendstr("\n", com->conn); - return ESUCCESS; - } - - sendstr("Connection set up, connection identifier is ", com->conn); - sprintf(buffer, "%d\n", i); - netconn_write(com->conn, buffer, kstrlen(buffer), NETCONN_COPY); - - return ESUCCESS; -} -/*-----------------------------------------------------------------------------------*/ -static Int8 -com_udpl(struct command *com) -{ - struct ip_addr ipaddr; - uInt16 lport, rport; - int i; - err_t err; - - lport = strtol(com->args[0], NULL, 10); - if(inet_aton(com->args[1], &ipaddr) == -1) { - //sendstr(strerror(errno), com->conn); - return ESYNTAX; - } - ipaddr.addr = 0xC0A80001; - rport = strtol(com->args[2], NULL, 10); - kprintf("RPORT: [%x]",rport); - - /* Find the first unused connection in conns. */ - for(i = 0; i < NCONNS && conns[i] != NULL; i++); - - if(i == NCONNS) { - sendstr("No more connections avaliable, sorry.\n", com->conn); - return ESUCCESS; - } - - sendstr("Setting up UDP-Lite connection from port ", com->conn); - netconn_write(com->conn, com->args[0], kstrlen(com->args[0]), NETCONN_COPY); - sendstr(" to ", com->conn); - netconn_write(com->conn, com->args[1], kstrlen(com->args[1]), NETCONN_COPY); - sendstr(":", com->conn); - netconn_write(com->conn, com->args[2], kstrlen(com->args[2]), NETCONN_COPY); - sendstr("\n", com->conn); - - conns[i] = netconn_new(NETCONN_UDPLITE); - if(conns[i] == NULL) { - sendstr("Could not create connection identifier (out of memory).\n", com->conn); - return ESUCCESS; - } - - err = netconn_connect(conns[i], &ipaddr, rport); - if(err != ERR_OK) { - netconn_delete(conns[i]); - conns[i] = NULL; - sendstr("Could not connect to remote host: ", com->conn); -#ifdef LWIP_DEBUG - sendstr(lwip_strerr(err), com->conn); -#else - sendstr("(debugging must be turned on for error message to appear)", com->conn); -#endif /* LWIP_DEBUG */ - sendstr("\n", com->conn); - return ESUCCESS; - } - - err = netconn_bind(conns[i], IP_ADDR_ANY, lport); - if(err != ERR_OK) { - netconn_delete(conns[i]); - conns[i] = NULL; - sendstr("Could not bind: ", com->conn); -#ifdef LWIP_DEBUG - sendstr(lwip_strerr(err), com->conn); -#else - sendstr("(debugging must be turned on for error message to appear)", com->conn); -#endif /* LWIP_DEBUG */ - sendstr("\n", com->conn); - return ESUCCESS; - } - - sendstr("Connection set up, connection identifier is ", com->conn); - sprintf(buffer, "%d\n", i); - netconn_write(com->conn, buffer, kstrlen(buffer), NETCONN_COPY); - - return ESUCCESS; -} -/*-----------------------------------------------------------------------------------*/ -static Int8 -com_udpn(struct command *com) -{ - struct ip_addr ipaddr; - uInt16 lport, rport; - int i; - err_t err; - - lport = strtol(com->args[0], NULL, 10); - if(inet_aton(com->args[1], &ipaddr) == -1) { - //sendstr(strerror(errno), com->conn); - return ESYNTAX; - } - ipaddr.addr = 0xC0A80001; - rport = strtol(com->args[2], NULL, 10); - - /* Find the first unused connection in conns. */ - for(i = 0; i < NCONNS && conns[i] != NULL; i++); - - if(i == NCONNS) { - sendstr("No more connections avaliable, sorry.\n", com->conn); - return ESUCCESS; - } - - sendstr("Setting up UDP connection without checksums from port ", com->conn); - netconn_write(com->conn, com->args[0], kstrlen(com->args[0]), NETCONN_COPY); - sendstr(" to ", com->conn); - netconn_write(com->conn, com->args[1], kstrlen(com->args[1]), NETCONN_COPY); - sendstr(":", com->conn); - netconn_write(com->conn, com->args[2], kstrlen(com->args[2]), NETCONN_COPY); - sendstr("\n", com->conn); - - conns[i] = netconn_new(NETCONN_UDPNOCHKSUM); - if(conns[i] == NULL) { - sendstr("Could not create connection identifier (out of memory).\n", com->conn); - return ESUCCESS; - } - - err = netconn_connect(conns[i], &ipaddr, rport); - if(err != ERR_OK) { - netconn_delete(conns[i]); - conns[i] = NULL; - sendstr("Could not connect to remote host: ", com->conn); -#ifdef LWIP_DEBUG - sendstr(lwip_strerr(err), com->conn); -#else - sendstr("(debugging must be turned on for error message to appear)", com->conn); -#endif /* LWIP_DEBUG */ - sendstr("\n", com->conn); - return ESUCCESS; - } - - err = netconn_bind(conns[i], IP_ADDR_ANY, lport); - if(err != ERR_OK) { - netconn_delete(conns[i]); - conns[i] = NULL; - sendstr("Could not bind: ", com->conn); -#ifdef LWIP_DEBUG - sendstr(lwip_strerr(err), com->conn); -#else - sendstr("(debugging must be turned on for error message to appear)", com->conn); -#endif /* LWIP_DEBUG */ - sendstr("\n", com->conn); - return ESUCCESS; - } - - sendstr("Connection set up, connection identifier is ", com->conn); - sprintf(buffer, "%d\n", i); - netconn_write(com->conn, buffer, kstrlen(buffer), NETCONN_COPY); - - return ESUCCESS; -} -/*-----------------------------------------------------------------------------------*/ -static Int8 -com_udpb(struct command *com) -{ - struct ip_addr ipaddr; - uInt16 lport, rport; - int i; - err_t err; - struct ip_addr bcaddr; - - lport = strtol(com->args[0], NULL, 10); - if(inet_aton(com->args[1], &ipaddr) == -1) { - //sendstr(strerror(errno), com->conn); - return ESYNTAX; - } - ipaddr.addr = 0xC0A80001; - rport = strtol(com->args[2], NULL, 10); - - /* Find the first unused connection in conns. */ - for(i = 0; i < NCONNS && conns[i] != NULL; i++); - - if(i == NCONNS) { - sendstr("No more connections avaliable, sorry.\n", com->conn); - return ESUCCESS; - } - - sendstr("Setting up UDP broadcast connection from port ", com->conn); - netconn_write(com->conn, com->args[0], kstrlen(com->args[0]), NETCONN_COPY); - sendstr(" to ", com->conn); - netconn_write(com->conn, com->args[1], kstrlen(com->args[1]), NETCONN_COPY); - sendstr("\n", com->conn); - - conns[i] = netconn_new(NETCONN_UDP); - if(conns[i] == NULL) { - sendstr("Could not create connection identifier (out of memory).\n", com->conn); - return ESUCCESS; - } - - err = netconn_connect(conns[i], &ipaddr, rport); - if(err != ERR_OK) { - netconn_delete(conns[i]); - conns[i] = NULL; - sendstr("Could not connect to remote host: ", com->conn); -#ifdef LWIP_DEBUG - sendstr(lwip_strerr(err), com->conn); -#else - sendstr("(debugging must be turned on for error message to appear)", com->conn); -#endif /* LWIP_DEBUG */ - sendstr("\n", com->conn); - return ESUCCESS; - } - - IP4_ADDR(&bcaddr, 255,255,255,255); - err = netconn_bind(conns[i], &bcaddr, lport); - if(err != ERR_OK) { - netconn_delete(conns[i]); - conns[i] = NULL; - sendstr("Could not bind: ", com->conn); -#ifdef LWIP_DEBUG - sendstr(lwip_strerr(err), com->conn); -#else - sendstr("(debugging must be turned on for error message to appear)", com->conn); -#endif /* LWIP_DEBUG */ - sendstr("\n", com->conn); - return ESUCCESS; - } - - sendstr("Connection set up, connection identifier is ", com->conn); - sprintf(buffer, "%d\n", i); - netconn_write(com->conn, buffer, kstrlen(buffer), NETCONN_COPY); - - return ESUCCESS; -} -/*-----------------------------------------------------------------------------------*/ -static Int8 -com_usnd(struct command *com) -{ - int i; - err_t err; - struct netbuf *buf; - char *mem; - - i = strtol(com->args[0], NULL, 10); - - if(i > NCONNS) { - sendstr("Connection identifier too high.\n", com->conn); - return ESUCCESS; - } - - if(conns[i] == NULL) { - sendstr("Connection identifier not in use.\n", com->conn); - return ESUCCESS; - } - - buf = netbuf_new(); - mem = netbuf_alloc(buf, kstrlen(com->args[1]) + 1); - if(mem == NULL) { - sendstr("Could not allocate memory for sending.\n", com->conn); - return ESUCCESS; - } - kstrncpy(mem, com->args[1], kstrlen(com->args[1]) + 1); - err = netconn_send(conns[i], buf); - netbuf_delete(buf); - if(err != ERR_OK) { - sendstr("Could not send data: ", com->conn); -#ifdef LWIP_DEBUG - sendstr(lwip_strerr(err), com->conn); -#else - sendstr("(debugging must be turned on for error message to appear)", com->conn); -#endif /* LWIP_DEBUG */ - sendstr("\n", com->conn); - return ESUCCESS; - } - - sendstr("Data sent.\n", com->conn); - return ESUCCESS; -} -/*-----------------------------------------------------------------------------------*/ -static Int8 -com_help(struct command *com) -{ - sendstr(help_msg, com->conn); - return ESUCCESS; -} -/*-----------------------------------------------------------------------------------*/ -static Int8 -parse_command(struct command *com, uInt32 len) -{ - uInt16 i; - uInt16 bufp; - - if(kstrncmp(buffer, "open", 4) == 0) { - com->exec = com_open; - com->nargs = 2; - } else if(kstrncmp(buffer, "lstn", 4) == 0) { - com->exec = com_lstn; - com->nargs = 1; - } else if(kstrncmp(buffer, "acpt", 4) == 0) { - com->exec = com_acpt; - com->nargs = 1; - } else if(kstrncmp(buffer, "clos", 4) == 0) { - com->exec = com_clos; - com->nargs = 1; - } else if(kstrncmp(buffer, "stat", 4) == 0) { - com->exec = com_stat; - com->nargs = 0; - } else if(kstrncmp(buffer, "send", 4) == 0) { - com->exec = com_send; - com->nargs = 2; - } else if(kstrncmp(buffer, "recv", 4) == 0) { - com->exec = com_recv; - com->nargs = 1; - } else if(kstrncmp(buffer, "udpc", 4) == 0) { - com->exec = com_udpc; - com->nargs = 3; - } else if(kstrncmp(buffer, "udpb", 4) == 0) { - com->exec = com_udpb; - com->nargs = 2; - } else if(kstrncmp(buffer, "udpl", 4) == 0) { - com->exec = com_udpl; - com->nargs = 3; - } else if(kstrncmp(buffer, "udpn", 4) == 0) { - com->exec = com_udpn; - com->nargs = 3; - } else if(kstrncmp(buffer, "usnd", 4) == 0) { - com->exec = com_usnd; - com->nargs = 2; - } else if(kstrncmp(buffer, "help", 4) == 0) { - com->exec = com_help; - com->nargs = 0; - } else if(kstrncmp(buffer, "quit", 4) == 0) { - kprintf("quit\n"); - return ECLOSED; - } else { - return ESYNTAX; - } - - if(com->nargs == 0) { - return ESUCCESS; - } - bufp = 0; - for(; bufp < len && buffer[bufp] != ' '; bufp++); - for(i = 0; i < 10; i++) { - for(; bufp < len && buffer[bufp] == ' '; bufp++); - if(buffer[bufp] == '\r' || - buffer[bufp] == '\n') { - buffer[bufp] = 0; - if(i < com->nargs - 1) { - return ETOOFEW; - } - if(i > com->nargs - 1) { - return ETOOMANY; - } - break; - } - if(bufp > len) { - return ETOOFEW; - } - com->args[i] = &buffer[bufp]; - for(; bufp < len && buffer[bufp] != ' ' && buffer[bufp] != '\r' && - buffer[bufp] != '\n'; bufp++) { - if(buffer[bufp] == '\\') { - buffer[bufp] = ' '; - } - } - if(bufp > len) { - return ESYNTAX; - } - buffer[bufp] = 0; - bufp++; - if(i == com->nargs - 1) { - break; - } - - } - - return ESUCCESS; -} -/*-----------------------------------------------------------------------------------*/ -static void -error(Int8 err, struct netconn *conn) -{ - switch(err) { - case ESYNTAX: - sendstr("## Syntax error\n", conn); - break; - case ETOOFEW: - sendstr("## Too few arguments to command given\n", conn); - break; - case ETOOMANY: - sendstr("## Too many arguments to command given\n", conn); - break; - } -} -/*-----------------------------------------------------------------------------------*/ -static void -prompt(struct netconn *conn) -{ - sendstr("> ", conn); -} -/*-----------------------------------------------------------------------------------*/ -static void -shell_main(struct netconn *conn) -{ +static void shell_main(struct netconn *conn) { struct netbuf *buf; uInt32 len; - struct command com; - Int8 err; int i; do { - buf = netconn_recv(conn); - if(buf != NULL) { + if (buf != NULL) { + buf = netconn_recv(conn); netbuf_copy(buf, buffer, 1024); len = netbuf_len(buf); netbuf_delete(buf); - if(len >= 4) { - if(buffer[0] != 0xff && - buffer[1] != 0xfe) { - err = parse_command(&com, len); - if(err == ESUCCESS) { - com.conn = conn; - err = com.exec(&com); - } - if(err != ESUCCESS) { - error(err, conn); - } - if(err == ECLOSED) { - kprintf("Closed\n"); - error(err, conn); - goto close; - } - } else { - sendstr("\n\n" - "lwIP simple interactive shell.\n" - "(c) Copyright 2001, Swedish Institute of Computer Science.\n" - "Written by Adam Dunkels.\n" - "For help, try the \"help\" command.\n", conn); - } - } + buffer[len-2] = '\0'; + kprintf("Buffer: [%s:%i]",buffer,len); } - if(buf != NULL) { + if (buf != NULL) { prompt(conn); - } + } } while(buf != NULL); kprintf("buf == NULL err %s\n", lwip_strerr(conn->err)); close: @@ -1034,23 +88,16 @@ netconn_delete(conns[i]); } conns[i] = NULL; + } } - -} -/*-----------------------------------------------------------------------------------*/ -static void -shell_thread(void *arg) -{ + +static void shell_thread(void *arg) { struct netconn *conn, *newconn; char *str = (char *)kmalloc(64,sysID); buffer = (char *)kmalloc(1024,sysID); - str[0] = 'a'; - str[1] = 'b'; - str[2] = 'c'; - conn = netconn_new(NETCONN_TCP); netconn_bind(conn, NULL, 23); netconn_listen(conn); @@ -1059,15 +106,14 @@ newconn = netconn_accept(conn); shell_main(newconn); netconn_delete(newconn); + } } -} -/*-----------------------------------------------------------------------------------*/ -void -shell_init(void) -{ + +void shell_init(void) { sys_thread_new(shell_thread, NULL); -} + } - - +/*** + END + ***/ diff --git a/src/sys/net/netif/ethernetif.c b/src/sys/net/netif/ethernetif.c index 0df8876..abd74b0 100644 --- a/src/sys/net/netif/ethernetif.c +++ b/src/sys/net/netif/ethernetif.c @@ -61,6 +61,8 @@ #define IFNAME0 'e' #define IFNAME1 'd' +struct nicBuffer *tmpBuf = 0x0; + struct ethernetif { struct eth_addr *ethaddr; /* Add whatever per-interface state that is needed here. */ @@ -109,15 +111,20 @@ static err_t low_level_output(struct ethernetif *ethernetif, struct pbuf *p) { struct pbuf *q; + char buf[1500]; + char *bufptr = 0x0; + dev->ioAddr = 0x240; dev->irq = 3; + bufptr = &buf[0]; - kprintf("Sending Data\n"); for(q = p; q != NULL; q = q->next) { - PCtoNIC(dev,q->payload,q->len); + bcopy(q->payload, bufptr, q->len); + bufptr += q->len; } - + PCtoNIC(dev,buf,p->tot_len); + kprintf("Sending Data[%i]\n",p->tot_len); return ERR_OK; } @@ -136,18 +143,9 @@ uInt16 len; char *bufptr; char *buf; - //char buf[1500]; - /* Obtain the size of the packet and put it into the "len" - variable. */ - //len = read(tapif->fd, buf, sizeof(buf)); - len = packetLength; - bufptr = nicPacket; - - /* if(((double)rand()/(double)RAND_MAX) < 0.1) { - printf("drop\n"); - return NULL; - }*/ + len = tmpBuf->length; + bufptr = tmpBuf->buffer; /* We allocate a pbuf chain of pbufs from the pool. */ @@ -197,10 +195,10 @@ /* Make room for Ethernet header. */ - if(pbuf_header(p, 14) != 0) { + if(pbuf_header(p, sizeof(struct eth_hdr)) != 0) { /* The pbuf_header() call shouldn't fail, but we allocate an extra pbuf just in case. */ - q = pbuf_alloc(PBUF_LINK, 14, PBUF_RAM); + q = pbuf_alloc(PBUF_LINK, sizeof(struct eth_hdr), PBUF_RAM); if(q == NULL) { return ERR_MEM; } @@ -216,6 +214,7 @@ if(ip_addr_isany(ipaddr) || ip_addr_isbroadcast(ipaddr, &(netif->netmask))) { dest = (struct eth_addr *)ðbroadcast; + kprintf("A"); } else if(ip_addr_ismulticast(ipaddr)) { /* Hash IP multicast address to MAC address. */ mcastaddr.addr[0] = 0x01; @@ -225,16 +224,18 @@ mcastaddr.addr[4] = ip4_addr3(ipaddr); mcastaddr.addr[5] = ip4_addr4(ipaddr); dest = &mcastaddr; + kprintf("B"); } else { - if(ip_addr_maskcmp(ipaddr, &(netif->ip_addr), &(netif->netmask))) { /* Use destination IP address if the destination is on the same subnet as we are. */ queryaddr = ipaddr; + kprintf("Word"); } else { /* Otherwise we use the default router as the address to send the Ethernet frame to. */ queryaddr = &(netif->gw); + kprintf("Word2"); } dest = arp_lookup(queryaddr); } @@ -354,10 +355,9 @@ netif = arg; while (1) { - if (packetLength > 0x0) { + tmpBuf = getBuffer(); + if (tmpBuf->length > 0x0) { ethernetif_input(netif); - nicPacket = 0x0; - packetLength = 0x0; } } }