]> Joshua Wise's Git repositories - netwatch.git/blame_incremental - net/net.c
initial checkin of RFB
[netwatch.git] / net / net.c
... / ...
CommitLineData
1#include <pci.h>
2#include <smram.h>
3#include <pci-bother.h>
4#include <output.h>
5#include <minilib.h>
6#include <lwip/init.h>
7#include "net.h"
8
9#include "lwip/opt.h"
10#include "lwip/def.h"
11#include "lwip/mem.h"
12#include "lwip/pbuf.h"
13#include "lwip/sys.h"
14#include <lwip/stats.h>
15#include <lwip/snmp.h>
16#include <lwip/dhcp.h>
17#include <lwip/tcp.h>
18#include "netif/etharp.h"
19#include "netif/ppp_oe.h"
20
21#include "rfb.h"
22
23static struct nic *_nic = 0x0;
24static struct netif _netif;
25
26extern struct pci_driver a3c90x_driver;
27
28void eth_poll()
29{
30 unsigned char pkt[1600];
31 int len;
32 struct pbuf *p, *q;
33 struct eth_hdr *ethhdr;
34 int pos = 0;
35 static int ticks = 0;
36
37 if (!_nic)
38 return;
39
40 smram_tseg_set_state(SMRAM_TSEG_OPEN);
41
42 if ((ticks % 1000) == 0) /* About a minute */
43 dhcp_coarse_tmr();
44 if ((ticks % 8) == 0) /* About 500msec*/
45 dhcp_fine_tmr();
46 if ((ticks % 4) == 0) /* About 250msec*/
47 tcp_tmr();
48 ticks++;
49
50 if (_nic->poll(_nic, 0))
51 {
52 _nic->packet = pkt;
53 _nic->poll(_nic, 1);
54
55 len = _nic->packetlen;
56
57 outputf("NIC: Packet: %d bytes", len);
58
59 p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
60 if (p == NULL)
61 {
62 outputf("NIC: out of memory for packet?");
63 LINK_STATS_INC(link.memerr);
64 LINK_STATS_INC(link.drop);
65 return;
66 }
67
68 for(q = p; q != NULL; q = q->next)
69 {
70 memcpy(q->payload, pkt+pos, q->len);
71 pos += q->len;
72 }
73
74 LINK_STATS_INC(link.recv);
75
76 ethhdr = p->payload;
77
78 switch (htons(ethhdr->type)) {
79 case ETHTYPE_IP:
80 case ETHTYPE_ARP:
81 if (_netif.input(p, &_netif) != ERR_OK)
82 {
83 LWIP_DEBUGF(NETIF_DEBUG, ("netdev_input: IP input error\n"));
84 pbuf_free(p);
85 }
86 break;
87
88 default:
89 outputf("Unhandled packet type %04x input", ethhdr->type);
90 pbuf_free(p);
91 break;
92 }
93 }
94}
95
96static err_t _transmit(struct netif *netif, struct pbuf *p)
97{
98 struct nic *nic = netif->state;
99 struct pbuf *q;
100 unsigned char pkt[1600];
101 unsigned int len = 0;
102
103 for(q = p; q != NULL; q = q->next)
104 {
105 memcpy(pkt + len, q->payload, q->len);
106 len += q->len;
107 }
108
109 outputf("NIC: Transmit packet: %d bytes", len);
110
111 nic->transmit(len, pkt);
112
113 LINK_STATS_INC(link.xmit);
114
115 return ERR_OK;
116}
117
118static err_t _init(struct netif *netif)
119{
120 struct nic *nic = netif->state;
121
122 LWIP_ASSERT("netif != NULL", (netif != NULL));
123
124#if LWIP_NETIF_HOSTNAME
125 netif->hostname = "netwatch";
126#endif
127
128 NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 100000000);
129
130 netif->name[0] = 'e';
131 netif->name[1] = 'n';
132 netif->output = etharp_output;
133 netif->linkoutput = _transmit;
134
135 memcpy(netif->hwaddr, nic->hwaddr, 6);
136 netif->mtu = 1500;
137 netif->hwaddr_len = ETHARP_HWADDR_LEN;
138 netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
139
140 return ERR_OK;
141}
142
143int eth_register(struct nic *nic)
144{
145 static struct ip_addr ipa = { 0 } , netmask = { 0 } , gw = { 0 };
146
147 if (_nic)
148 return -1;
149 netif_add(&_netif, &ipa, &netmask, &gw, (void*)nic, _init, ethernet_input);
150 netif_set_default(&_netif);
151 netif_set_up(&_netif);
152 dhcp_start(&_netif);
153 _nic = nic;
154 return 0;
155}
156
157void eth_init()
158{
159 extern void httpd_init();
160
161 /* Required for DMA to work. :( */
162 smram_tseg_set_state(SMRAM_TSEG_OPEN);
163 lwip_init();
164 httpd_init();
165/*
166 rfb_init();
167*/
168}
This page took 0.026488 seconds and 4 git commands to generate.