blob: 217a59545c8290972a4b50f9a37fbc9aa70ec7a9 [file] [log] [blame]
adamdunkelsd311bf12004-07-04 20:17:37 +00001/*-----------------------------------------------------------------------------------*/
adamdunkels3023dee2003-07-04 10:54:51 +00002/*
adamdunkelsd311bf12004-07-04 20:17:37 +00003 * Copyright (c) 2001-2004, Adam Dunkels.
adamdunkels3023dee2003-07-04 10:54:51 +00004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
adamdunkelsd311bf12004-07-04 20:17:37 +000014 * 3. The name of the author may not be used to endorse or promote
adamdunkels3023dee2003-07-04 10:54:51 +000015 * products derived from this software without specific prior
16 * written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * This file is part of the uIP TCP/IP stack.
31 *
adamdunkelsd311bf12004-07-04 20:17:37 +000032 * $Id: rtl8019-drv.c,v 1.3 2004/07/04 20:17:38 adamdunkels Exp $
adamdunkels3023dee2003-07-04 10:54:51 +000033 *
34 */
35
adamdunkelsd311bf12004-07-04 20:17:37 +000036#include "packet-service.h"
adamdunkels3023dee2003-07-04 10:54:51 +000037
adamdunkels3023dee2003-07-04 10:54:51 +000038#include "rtl8019dev.h"
39
adamdunkelsd311bf12004-07-04 20:17:37 +000040#include "uip_arp.h"
adamdunkels3023dee2003-07-04 10:54:51 +000041
adamdunkelsd311bf12004-07-04 20:17:37 +000042static void output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen);
adamdunkels3023dee2003-07-04 10:54:51 +000043
adamdunkelsd311bf12004-07-04 20:17:37 +000044static const struct packet_service_state state =
45 {
46 PACKET_SERVICE_VERSION,
47 output
48 };
adamdunkels3023dee2003-07-04 10:54:51 +000049
adamdunkelsd311bf12004-07-04 20:17:37 +000050EK_EVENTHANDLER(eventhandler, ev, data);
51EK_POLLHANDLER(pollhandler);
52EK_PROCESS(proc, PACKET_SERVICE_NAME, EK_PRIO_NORMAL,
53 eventhandler, pollhandler, (void *)&state);
adamdunkels3023dee2003-07-04 10:54:51 +000054
adamdunkelsd311bf12004-07-04 20:17:37 +000055/*---------------------------------------------------------------------------*/
56LOADER_INIT_FUNC(rtl8019_drv_init, arg)
adamdunkels3023dee2003-07-04 10:54:51 +000057{
adamdunkelsd311bf12004-07-04 20:17:37 +000058 arg_free(arg);
59 ek_service_start(PACKET_SERVICE_NAME, &proc);
adamdunkels3023dee2003-07-04 10:54:51 +000060}
adamdunkelsd311bf12004-07-04 20:17:37 +000061/*---------------------------------------------------------------------------*/
adamdunkels3023dee2003-07-04 10:54:51 +000062static void
adamdunkelsd311bf12004-07-04 20:17:37 +000063output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen)
adamdunkels3023dee2003-07-04 10:54:51 +000064{
adamdunkelsd311bf12004-07-04 20:17:37 +000065 RTL8019dev_send();
66}
67/*---------------------------------------------------------------------------*/
68EK_EVENTHANDLER(eventhandler, ev, data)
69{
70 switch(ev) {
71 case EK_EVENT_INIT:
72 RTL8019dev_init();
73 break;
74 case EK_EVENT_REQUEST_REPLACE:
75 ek_replace((struct ek_proc *)data, NULL);
76 LOADER_UNLOAD();
77 break;
78 case EK_EVENT_REQUEST_EXIT:
79 ek_exit();
80 LOADER_UNLOAD();
81 break;
82 default:
83 break;
84 }
85}
86/*---------------------------------------------------------------------------*/
87EK_POLLHANDLER(pollhandler)
88{
89#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
90
adamdunkels3023dee2003-07-04 10:54:51 +000091 /* Poll Ethernet device to see if there is a frame avaliable. */
92 uip_len = RTL8019dev_poll();
93 if(uip_len > 0) {
94 /* A frame was avaliable (and is now read into the uip_buf), so
adamdunkelsd311bf12004-07-04 20:17:37 +000095 we process it. */
96 if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
adamdunkels3023dee2003-07-04 10:54:51 +000097 uip_arp_ipin();
98 uip_len -= sizeof(struct uip_eth_hdr);
adamdunkelsd311bf12004-07-04 20:17:37 +000099 tcpip_input();
100 } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
adamdunkels3023dee2003-07-04 10:54:51 +0000101 uip_arp_arpin();
102 /* If the above function invocation resulted in data that
adamdunkelsd311bf12004-07-04 20:17:37 +0000103 should be sent out on the network, the global variable
104 uip_len is set to a value > 0. */
adamdunkels3023dee2003-07-04 10:54:51 +0000105 if(uip_len > 0) {
106 RTL8019dev_send();
107 }
108 }
109 }
adamdunkels3023dee2003-07-04 10:54:51 +0000110
adamdunkels3023dee2003-07-04 10:54:51 +0000111}
adamdunkelsd311bf12004-07-04 20:17:37 +0000112/*---------------------------------------------------------------------------*/