* Copyright (c) 2001,2003,2004 David H. Hovemeyer <daveho@cs.umd.edu>
* Copyright (c) 2003, Jeffrey K. Hollingsworth <hollings@cs.umd.edu>
* Copyright (c) 2004, Iulian Neamtiu <neamtiu@cs.umd.edu>
- * $Revision: 1.44 $
+ * $Revision: 1.45 $
*
* This is free software. You are permitted to use,
* redistribute, and modify it as specified in the file "COPYING".
#include <geekos/pci.h>
+#if 0
#include <geekos/ne2k.h>
#include <uip/uip.h>
#include <uip/uip_arp.h>
+#endif
-#include <geekos/ring_buffer.h>
+#include <geekos/socket.h>
+//#include <geekos/ring_buffer.h>
#define SPEAKER_PORT 0x61
#define TEST_NE2K 0
Init_Stubs();
-#if TEST_NE2K
+#ifdef TEST_NE2K
+ {
+ init_network();
+ uchar_t local_addr[4];
+ uchar_t remote_addr[4];
+
+ local_addr[0] = 10;
+ local_addr[1] = 0;
+ local_addr[2] = 2;
+ local_addr[3] = 20;
+
+ set_ip_addr(local_addr);
+
+ remote_addr[0] = 10;
+ remote_addr[1] = 0;
+ remote_addr[2] = 2;
+ remote_addr[3] = 21;
+
+
+ connect(remote_addr, 4301);
+ }
+#elif 0
Init_Ne2k(&Packet_Received);
uip_init();
uip_arp_init();
#include <geekos/socket.h>
#include <geekos/malloc.h>
-#include <palacios/vmm_types.h>
#include <geekos/ne2k.h>
#include <uip/uip.h>
#include <uip/uip_arp.h>
#include <geekos/vmm_stubs.h>
+#include <geekos/debug.h>
-#define NULL (void *)0
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
struct socket sockets[MAX_SOCKS];
-extern void* memcpy(void *dst, const void* src, int n);
int Packet_Received(struct NE2K_Packet_Info* info, uchar_t *pkt);
sockets[i].in_use = 0;
sockets[i].send_buf = NULL;
sockets[i].recv_buf = NULL;
+ sockets[i].state = CLOSED;
}
}
+
+
+
+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;
free_ring_buffer(sockets[sockfd].recv_buf);
sockets[sockfd].send_buf = NULL;
sockets[sockfd].recv_buf = NULL;
+ sockets[sockfd].state = CLOSED;
}
return 0;
}
uip_ipaddr(&ipaddr, ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3]);
+
+ sockets[sockfd].state = WAITING;
sockets[sockfd].con = uip_connect((uip_ipaddr_t *)&ip_addr, htons(port));
return -1;
}
+
+ PrintBoth("Connection start\n");
+
+ while(sockets[sockfd].state == WAITING) {
+ timer_int_handler(NULL);
+ }
+
+
+ PrintBoth("Connected\n");
+
+ if (sockets[sockfd].state != ESTABLISHED) {
+ release_socket_fd(sockfd);
+ return -1;
+ }
+
+
return sockfd;
}
}
// a series of utilities to handle conncetion states
-static void connected(int sockfd){
+static void connected(int sockfd) {
+ struct socket * sock = get_socket_from_fd(sockfd);
+
+ PrintBoth("Connected Interrupt\n");
+ sock->state = ESTABLISHED;
+
+ Wake_Up(&(sock->recv_wait_queue));
}
static void closed(int sockfd){
}
// not finished yet
-static void
-senddata(int sockfd){
+static void send_to_driver(int sockfd) {
+
+ PrintBoth("Sending data to driver\n");
+
+}
+
+
+
+int send(int sockfd, void * buf, uint_t len) {
struct socket * sock = get_socket_from_fd(sockfd);
- int mss = uip_mss();
- int pending_bytes = rb_data_len(sock->send_buf);
- int len = (mss < pending_bytes) ? mss: pending_bytes;
+ //int mss = uip_mss();
+ //int pending_bytes = rb_data_len(sock->send_buf);
+ //int len = (mss < pending_bytes) ? mss: pending_bytes;
int bytes_read = 0;
uchar_t * send_buf = uip_appdata;
if (bytes_read == 0) {
// no packet for send
- return;
+ return -1;
}
uip_send(send_buf, len);
+
+ return len;
}
//get the socket id by the local tcp port
-static int get_socket_from_port(ushort_t lport) {
+static int get_socket_from_port(ushort_t lport) {
int i;
sockfd = get_socket_from_port(uip_conn->lport);
+ PrintBoth("Appcall\n");
+
if (sockfd == -1) {
return;
uip_acked() ||
uip_connected() ||
uip_poll()) {
- senddata(sockfd);
+ send_to_driver(sockfd);
}
}