blob: e25c2d05ce43c6e7200be6f82d86d17d1d9ed4fd [file] [log] [blame]
oliverschmidt8871bdd2005-03-13 21:33:57 +00001/*
2 * Copyright (c) 2001-2004, Adam Dunkels.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote
14 * products derived from this software without specific prior
15 * written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * This file is part of the uIP TCP/IP stack.
30 *
oliverschmidt03ad6a42005-05-13 00:01:56 +000031 * $Id: lancegs-drv.c,v 1.3 2005/05/13 00:01:56 oliverschmidt Exp $
oliverschmidt8871bdd2005-03-13 21:33:57 +000032 *
33 */
34
oliverschmidt03ad6a42005-05-13 00:01:56 +000035#include <string.h>
36
oliverschmidt8871bdd2005-03-13 21:33:57 +000037#include "packet-service.h"
38
39#include "lan91c96.h"
40
41#include "uip_arp.h"
42
43static void output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen);
44
oliverschmidt03ad6a42005-05-13 00:01:56 +000045/* 00:80:0F is the OUI of Standard Microsystems, A2:A2 just means Apple2 */
oliverschmidt8871bdd2005-03-13 21:33:57 +000046static const struct uip_eth_addr addr =
oliverschmidt03ad6a42005-05-13 00:01:56 +000047 {{0x00,0x80,0x0f,0xa2,0xa2,0x00}};
oliverschmidt8871bdd2005-03-13 21:33:57 +000048
49static const struct packet_service_state state =
50 {
51 PACKET_SERVICE_VERSION,
52 output
53 };
54
55EK_EVENTHANDLER(eventhandler, ev, data);
56EK_POLLHANDLER(pollhandler);
57EK_PROCESS(proc, PACKET_SERVICE_NAME ": LANceGS", EK_PRIO_NORMAL,
58 eventhandler, pollhandler, (void *)&state);
59
60/*---------------------------------------------------------------------------*/
61LOADER_INIT_FUNC(lancegs_drv_init, arg)
62{
63 arg_free(arg);
64 ek_service_start(PACKET_SERVICE_NAME, &proc);
65}
66/*---------------------------------------------------------------------------*/
67static void
68output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen)
69{
70 uip_arp_out();
71 lan91c96_send();
72}
73/*---------------------------------------------------------------------------*/
74EK_EVENTHANDLER(eventhandler, ev, data)
75{
76 switch(ev) {
77 case EK_EVENT_INIT:
78 case EK_EVENT_REPLACE:
oliverschmidt03ad6a42005-05-13 00:01:56 +000079 /* Don't overwrite LSB */
80 memcpy(&uip_ethaddr, &addr, 5);
oliverschmidt8871bdd2005-03-13 21:33:57 +000081 lan91c96_init();
82 break;
83 case EK_EVENT_REQUEST_REPLACE:
84 ek_replace((struct ek_proc *)data, NULL);
85 LOADER_UNLOAD();
86 break;
87 case EK_EVENT_REQUEST_EXIT:
88 ek_exit();
89 LOADER_UNLOAD();
90 break;
91 default:
92 break;
93 }
94}
95/*---------------------------------------------------------------------------*/
96EK_POLLHANDLER(pollhandler)
97{
98#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
99
100 /* Poll Ethernet device to see if there is a frame avaliable. */
101 uip_len = lan91c96_poll();
102 if(uip_len > 0) {
103 /* A frame was avaliable (and is now read into the uip_buf), so
104 we process it. */
105 if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
106 uip_arp_ipin();
107 uip_len -= sizeof(struct uip_eth_hdr);
108 tcpip_input();
109 } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
110 uip_arp_arpin();
111 /* If the above function invocation resulted in data that
112 should be sent out on the network, the global variable
113 uip_len is set to a value > 0. */
114 if(uip_len > 0) {
115 lan91c96_send();
116 }
117 }
118 }
119
120}
121/*---------------------------------------------------------------------------*/