00001 /*-----------------------------------------------------------------------------------*/ 00002 /* 00003 * Copyright (c) 2001-2004, Adam Dunkels. 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 1. Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 2. Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * 3. The name of the author may not be used to endorse or promote 00015 * products derived from this software without specific prior 00016 * written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 00019 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00020 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00021 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 00022 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00023 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00024 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00026 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00027 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 * 00030 * This file is part of the uIP TCP/IP stack. 00031 * 00032 * $Id: rtl8019-drv.c,v 1.3 2010/10/19 18:29:04 adamdunkels Exp $ 00033 * 00034 */ 00035 00036 #include "contiki-net.h" 00037 #include "dev/rtl8019dev.h" 00038 #include "net/uip-neighbor.h" 00039 00040 #define BUF ((struct uip_eth_hdr *)&uip_buf[0]) 00041 00042 PROCESS(rtl8019_process, "RTL8019 driver"); 00043 00044 /*---------------------------------------------------------------------------*/ 00045 u8_t 00046 rtl8019_output(void) 00047 { 00048 uip_arp_out(); 00049 RTL8019dev_send(); 00050 00051 return 0; 00052 } 00053 /*---------------------------------------------------------------------------*/ 00054 static void 00055 pollhandler(void) 00056 { 00057 process_poll(&rtl8019_process); 00058 uip_len = RTL8019dev_poll(); 00059 00060 if(uip_len > 0) { 00061 #if UIP_CONF_IPV6 00062 if(BUF->type == uip_htons(UIP_ETHTYPE_IPV6)) { 00063 uip_neighbor_add(&IPBUF->srcipaddr, &BUF->src); 00064 tcpip_input(); 00065 } else 00066 #endif /* UIP_CONF_IPV6 */ 00067 if(BUF->type == uip_htons(UIP_ETHTYPE_IP)) { 00068 uip_len -= sizeof(struct uip_eth_hdr); 00069 tcpip_input(); 00070 } else if(BUF->type == uip_htons(UIP_ETHTYPE_ARP)) { 00071 uip_arp_arpin(); 00072 /* If the above function invocation resulted in data that 00073 should be sent out on the network, the global variable 00074 uip_len is set to a value > 0. */ 00075 if(uip_len > 0) { 00076 RTL8019dev_send(); 00077 } 00078 } 00079 } 00080 } 00081 /*---------------------------------------------------------------------------*/ 00082 PROCESS_THREAD(rtl8019_process, ev, data) 00083 { 00084 PROCESS_POLLHANDLER(pollhandler()); 00085 00086 PROCESS_BEGIN(); 00087 00088 RTL8019dev_init(); 00089 00090 tcpip_set_outputfunc(rtl8019_output); 00091 00092 process_poll(&rtl8019_process); 00093 00094 PROCESS_WAIT_UNTIL(ev == PROCESS_EVENT_EXIT); 00095 00096 RTL8019dev_exit(); 00097 00098 PROCESS_END(); 00099 } 00100 /*---------------------------------------------------------------------------*/