blob: b309db2d56bd72f10b409fcf8ca213e0c559fe04 [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 *
adamdunkels47691572004-08-09 22:23:29 +000032 * $Id: rtl8019-drv.c,v 1.4 2004/08/09 22:23:29 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);
adamdunkels47691572004-08-09 22:23:29 +000052EK_PROCESS(proc, PACKET_SERVICE_NAME ": RTL8019as", EK_PRIO_HIGH,
adamdunkelsd311bf12004-07-04 20:17:37 +000053 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{
adamdunkels47691572004-08-09 22:23:29 +000065 uip_arp_out();
adamdunkelsd311bf12004-07-04 20:17:37 +000066 RTL8019dev_send();
67}
68/*---------------------------------------------------------------------------*/
69EK_EVENTHANDLER(eventhandler, ev, data)
70{
71 switch(ev) {
72 case EK_EVENT_INIT:
adamdunkels47691572004-08-09 22:23:29 +000073 case EK_EVENT_REPLACE:
adamdunkelsd311bf12004-07-04 20:17:37 +000074 RTL8019dev_init();
75 break;
76 case EK_EVENT_REQUEST_REPLACE:
77 ek_replace((struct ek_proc *)data, NULL);
78 LOADER_UNLOAD();
79 break;
80 case EK_EVENT_REQUEST_EXIT:
adamdunkels47691572004-08-09 22:23:29 +000081 /* ek_exit();
82 LOADER_UNLOAD();*/
adamdunkelsd311bf12004-07-04 20:17:37 +000083 break;
84 default:
85 break;
86 }
87}
88/*---------------------------------------------------------------------------*/
89EK_POLLHANDLER(pollhandler)
90{
91#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
92
adamdunkels3023dee2003-07-04 10:54:51 +000093 /* Poll Ethernet device to see if there is a frame avaliable. */
94 uip_len = RTL8019dev_poll();
95 if(uip_len > 0) {
96 /* A frame was avaliable (and is now read into the uip_buf), so
adamdunkelsd311bf12004-07-04 20:17:37 +000097 we process it. */
98 if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
adamdunkels3023dee2003-07-04 10:54:51 +000099 uip_arp_ipin();
100 uip_len -= sizeof(struct uip_eth_hdr);
adamdunkelsd311bf12004-07-04 20:17:37 +0000101 tcpip_input();
102 } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
adamdunkels3023dee2003-07-04 10:54:51 +0000103 uip_arp_arpin();
104 /* If the above function invocation resulted in data that
adamdunkelsd311bf12004-07-04 20:17:37 +0000105 should be sent out on the network, the global variable
106 uip_len is set to a value > 0. */
adamdunkels3023dee2003-07-04 10:54:51 +0000107 if(uip_len > 0) {
108 RTL8019dev_send();
109 }
110 }
111 }
adamdunkels3023dee2003-07-04 10:54:51 +0000112
adamdunkels3023dee2003-07-04 10:54:51 +0000113}
adamdunkelsd311bf12004-07-04 20:17:37 +0000114/*---------------------------------------------------------------------------*/