X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fgeekos%2Fsocket.c;h=8315a191a99f4021345f9b65ed610e9a7d71ab46;hb=b1a2026094d16135da97686e18fa99bfeeec70eb;hp=b18eaeb392538f47a4f2da587739b7d112d2509d;hpb=410089191febd4884a3a5a513052b0ae12aa7ebf;p=palacios.releases.git diff --git a/palacios/src/geekos/socket.c b/palacios/src/geekos/socket.c index b18eaeb..8315a19 100644 --- a/palacios/src/geekos/socket.c +++ b/palacios/src/geekos/socket.c @@ -6,13 +6,7 @@ #include #include #include -#include - - -// for some reason, there are compile warnings without these -extern void v3_init_queue(struct gen_queue * queue); -extern void v3_enqueue(struct gen_queue * queue, addr_t entry); -extern addr_t v3_dequeue(struct gen_queue * queue); +#include #define BUF ((struct uip_eth_hdr *)&uip_buf[0]) @@ -20,24 +14,16 @@ extern addr_t v3_dequeue(struct gen_queue * queue); struct socket sockets[MAX_SOCKS]; -struct gen_queue in_packets; - -struct sock_packet { - int size; - uchar_t *data; -}; int Packet_Received(struct NE2K_Packet_Info* info, uchar_t *pkt) ; void init_network() { int i = 0; - v3_init_queue(&in_packets); - for (i = 0; i < MAX_SOCKS; i++) { sockets[i].in_use = 0; - v3_init_queue(&(sockets[i].send_queue)); - v3_init_queue(&(sockets[i].recv_queue)); + init_queue(&(sockets[i].send_queue)); + init_queue(&(sockets[i].recv_queue)); } //initiate uIP @@ -66,7 +52,9 @@ static int allocate_socket_fd() { } static int release_socket_fd(int sockfd){ - sockets[sockfd].in_use = 0; + if (sockfd >= 0 && sockfd < MAX_SOCKS) + sockets[sockfd].in_use = 0; + return 0; } @@ -76,8 +64,6 @@ struct socket * get_socket_from_fd(int fd) { } - - int connect(const uchar_t ip_addr[4], ushort_t port) { int sockfd = -1; sockfd = allocate_socket_fd(); @@ -139,8 +125,15 @@ static void newdata(int sockfd){ // not finished yet static void senddata(int sockfd){ - uchar_t *bufptr; + /*uchar_t *bufptr; int len = 0; + addr_t pkt; + + struct sockets *sock = get_socket_from_fd(sockfd); + + pkt = dequeue(sock->send_queue); + if (pkt == 0) // no packet for send + return; bufptr = uip_appdata; @@ -148,7 +141,7 @@ senddata(int sockfd){ // memcpy(bufptr, data, len); } else { - } + }*/ //uip_send(uip_appdata,len); } @@ -208,70 +201,27 @@ socket_appcall(void) int Packet_Received(struct NE2K_Packet_Info* info, uchar_t *pkt) { - struct sock_packet next; int i; - - next.size = info->size; - next.data = (uchar_t *)VMM_Malloc(next.size); - - if (next.data == NULL) return 1; - - //uip_len = info->size; + uip_len = info->size; for(i = 0; i < info->size; i++) { - *((next.data)+i) = *(pkt+i); + uip_buf[i] = *(pkt+i); } Free(pkt); - - Disable_Interrupts(); - v3_enqueue(&in_packets, (addr_t)(&next)); - Enable_Interrupts(); - - //triger_receiver_interrupt(); - + if(BUF->type == htons(UIP_ETHTYPE_ARP)) { + uip_arp_arpin(); + if (uip_len > 0){ + //ethernet_devicedriver_send(); + NE2K_Transmit(uip_len); + } + } else { + uip_arp_ipin(); + uip_input(); + if(uip_len > 0) { + uip_arp_out(); + //ethernet_devicedriver_send(); + NE2K_Transmit(uip_len); + } + } return 0; } - - -void int_handler_packet_receive(struct Interrupt_State * state){ - //device driver got a incoming packet and enqueue that packet to the receive queue - struct sock_packet *next_packet; - addr_t pkt; - int i; - - while(1){ - //currently disable interrupt because no lock for the queue - Disable_Interrupts(); - pkt = v3_dequeue(&in_packets); - Enable_Interrupts(); - - if (pkt == 0) break; - - //there are new packets in the receiver queue - next_packet = (struct sock_packet *)pkt; - uip_len = next_packet->size; - - for(i = 0; i < uip_len; i++) { - uip_buf[i] = *((next_packet->data)+i); - } - - Free(next_packet->data); - Free(next_packet); - - if(BUF->type == htons(UIP_ETHTYPE_ARP)) { - uip_arp_arpin(); - if (uip_len > 0){ - //ethernet_devicedriver_send(); - NE2K_Transmit(uip_len); - } - } else { - uip_arp_ipin(); - uip_input(); - if(uip_len > 0) { - uip_arp_out(); - //ethernet_devicedriver_send(); - NE2K_Transmit(uip_len); - } - } - } -}