OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [include/] [net.h] - Blame information for rev 337

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 marcus.erl
/*
2
 *      LiMon Monitor (LiMon) - Network.
3
 *
4
 *      Copyright 1994 - 2000 Neil Russell.
5
 *      (See License)
6
 *
7
 *
8
 * History
9
 *      9/16/00   bor  adapted to TQM823L/STK8xxL board, RARP/TFTP boot added
10
 */
11
 
12
#ifndef __NET_H__
13
#define __NET_H__
14
 
15
 
16 140 julius
// TFTP running checksum defined here... tftp.h not in common include/ path
17
extern unsigned long TFTP_CHKSUM;
18
 
19 2 marcus.erl
/*
20
 *      The number of receive packet buffers, and the required packet buffer
21
 *      alignment in memory.
22
 *
23
 */
24
 
25
#define PKTBUFSRX       4
26
#define PKTALIGN        32
27
 
28
/****** from cpu_arch.h ************/
29
 
30
/* Byte swapping stuff (not needed on PPC). */
31
 
32
#define SWAP16(x)       (x)
33
#define SWAP16c(x)      (x)
34
#define SWAP32(x)       (x)
35
 
36
/****** end from cpu_arch.h **************/
37
 
38
typedef unsigned long           IPaddr_t;
39
 
40
 
41
 
42
/*
43
 * The current receive packet handler.  Called with a pointer to the
44
 * application packet, and a protocol type (PORT_BOOTPC or PORT_TFTP).
45
 * All other packets are dealt with without calling the handler.
46
 */
47
typedef void    rxhand_f(unsigned char *, unsigned, unsigned, unsigned);
48
 
49
/*
50
 *      A timeout handler.  Called after time interval has expired.
51
 */
52
typedef void    thand_f(void);
53
 
54
#ifdef CONFIG_NET_MULTI
55
 
56
#define NAMESIZE 16
57
 
58
enum eth_state_t {
59
        ETH_STATE_INIT,
60
        ETH_STATE_PASSIVE,
61
        ETH_STATE_ACTIVE
62
};
63
 
64
struct eth_device {
65
        char name[NAMESIZE];
66
        unsigned char enetaddr[6];
67
        int iobase;
68
        int state;
69
 
70
        int  (*init) (struct eth_device*, bd_t*);
71
        int  (*send) (struct eth_device*, volatile void* pachet, int length);
72
        int  (*recv) (struct eth_device*);
73
        void (*halt) (struct eth_device*);
74
 
75
        struct eth_device *next;
76
        void *priv;
77
};
78
 
79
extern int eth_initialize(bd_t *bis);           /* Initialize network subsystem */
80
extern int eth_register(struct eth_device* dev);/* Register network device      */
81
extern void eth_try_another(void);              /* Change the device            */
82
#endif
83
 
84
/**********************************************************************/
85
/*
86
 *      Protocol headers.
87
 */
88
 
89
/*
90
 *      Ethernet header
91
 */
92
typedef struct {
93
        unsigned char           et_dest[6];     /* Destination node             */
94
        unsigned char           et_src[6];      /* Source node                  */
95
        unsigned short          et_protlen;     /* Protocol or length           */
96
        unsigned char           et_dsap;        /* 802 DSAP                     */
97
        unsigned char           et_ssap;        /* 802 SSAP                     */
98
        unsigned char           et_ctl;         /* 802 control                  */
99
        unsigned char           et_snap1;       /* SNAP                         */
100
        unsigned char           et_snap2;
101
        unsigned char           et_snap3;
102
        unsigned short          et_prot;        /* 802 protocol                 */
103
} Ethernet_t;
104
 
105
#define ETHER_HDR_SIZE  14              /* Ethernet header size         */
106
#define E802_HDR_SIZE   22              /* 802 ethernet header size     */
107
#define PROT_IP         0x0800          /* IP protocol                  */
108
#define PROT_ARP        0x0806          /* IP ARP protocol              */
109
#define PROT_RARP       0x8035          /* IP ARP protocol              */
110
 
111
#define IPPROTO_ICMP     1      /* Internet Control Message Protocol    */
112
#define IPPROTO_UDP     17      /* User Datagram Protocol               */
113
 
114
/*
115
 *      Internet Protocol (IP) header.
116
 */
117
typedef struct {
118
        unsigned char           ip_hl_v;        /* header length and version    */
119
        unsigned char           ip_tos;         /* type of service              */
120
        unsigned short          ip_len;         /* total length                 */
121
        unsigned short          ip_id;          /* identification               */
122
        unsigned short          ip_off;         /* fragment offset field        */
123
        unsigned char           ip_ttl;         /* time to live                 */
124
        unsigned char           ip_p;           /* protocol                     */
125
        unsigned short          ip_sum;         /* checksum                     */
126
        IPaddr_t        ip_src;         /* Source IP address            */
127
        IPaddr_t        ip_dst;         /* Destination IP address       */
128
        unsigned short          udp_src;        /* UDP source port              */
129
        unsigned short          udp_dst;        /* UDP destination port         */
130
        unsigned short          udp_len;        /* Length of UDP packet         */
131
        unsigned short          udp_xsum;       /* Checksum                     */
132
} IP_t;
133
 
134
#define IP_HDR_SIZE_NO_UDP      (sizeof (IP_t) - 8)
135
#define IP_HDR_SIZE             (sizeof (IP_t))
136
 
137
 
138
/*
139
 *      Address Resolution Protocol (ARP) header.
140
 */
141
typedef struct
142
{
143 140 julius
        unsigned short          ar_hrd;         /* Format of hardware address*/
144
#   define ARP_ETHER        1                   /* Ethernet  hardware address*/
145
        unsigned short          ar_pro;         /* Format of protocol address*/
146
        unsigned char           ar_hln;         /* Length of hardware address*/
147
        unsigned char           ar_pln;         /* Length of protocol address*/
148
        unsigned short          ar_op;          /* Operation            */
149 2 marcus.erl
#   define ARPOP_REQUEST    1           /* Request  to resolve  address */
150
#   define ARPOP_REPLY      2           /* Response to previous request */
151
 
152
#   define RARPOP_REQUEST   3           /* Request  to resolve  address */
153
#   define RARPOP_REPLY     4           /* Response to previous request */
154
 
155
        /*
156
         * The remaining fields are variable in size, according to
157
         * the sizes above, and are defined as appropriate for
158
         * specific hardware/protocol combinations.
159
         */
160
        unsigned char           ar_data[0];
161
#if 0
162 140 julius
        unsigned char           ar_sha[];       /* Sender hardware address*/
163
        unsigned char           ar_spa[];       /* Sender protocol address*/
164
        unsigned char           ar_tha[];       /* Target hardware address*/
165
        unsigned char           ar_tpa[];       /* Target protocol address*/
166 2 marcus.erl
#endif /* 0 */
167
} ARP_t;
168
 
169
#define ARP_HDR_SIZE    (8+20)          /* Size assuming ethernet       */
170
 
171
/*
172
 * ICMP stuff (just enough to handle (host) redirect messages)
173
 */
174
#define ICMP_REDIRECT           5       /* Redirect (change route)      */
175
 
176
/* Codes for REDIRECT. */
177
#define ICMP_REDIR_NET          0        /* Redirect Net                 */
178
#define ICMP_REDIR_HOST         1       /* Redirect Host                */
179
 
180
typedef struct icmphdr {
181
        unsigned char           type;
182
        unsigned char           code;
183
        unsigned short          checksum;
184
        union {
185
                struct {
186
                        unsigned short  id;
187
                        unsigned short  sequence;
188
                } echo;
189
                unsigned long   gateway;
190
                struct {
191
                        unsigned short  __unused;
192
                        unsigned short  mtu;
193
                } frag;
194
        } un;
195
} ICMP_t;
196
 
197
 
198
 
199
/*
200
 * Maximum packet size; used to allocate packet storage.
201
 * TFTP packets can be 524 bytes + IP header + ethernet header.
202
 * Lets be conservative, and go for 38 * 16.  (Must also be
203
 * a multiple of 32 bytes).
204
 */
205
/*
206
 * AS.HARNOIS : Better to set PKTSIZE to maximum size because
207
 * traffic type is not always controlled
208
 * maximum packet size =  1518
209
 * maximum packet size and multiple of 32 bytes =  1536
210
 */
211
#define PKTSIZE                 1518
212
#define PKTSIZE_ALIGN           1536
213
/*#define PKTSIZE               608*/
214
 
215
/*
216
 * Maximum receive ring size; that is, the number of packets
217
 * we can buffer before overflow happens. Basically, this just
218
 * needs to be enough to prevent a packet being discarded while
219
 * we are processing the previous one.
220
 */
221
#define RINGSZ          4
222
#define RINGSZ_LOG2     2
223
 
224
/**********************************************************************/
225
/*
226
 *      Globals.
227
 */
228
 
229
/* net.c */
230
/** BOOTP EXTENTIONS **/
231
extern IPaddr_t         NetOurGatewayIP;        /* Our gateway IP addresse      */
232
extern IPaddr_t         NetOurSubnetMask;       /* Our subnet mask (0 = unknown)*/
233
extern IPaddr_t         NetOurDNSIP;     /* Our Domain Name Server (0 = unknown)*/
234
extern char             NetOurNISDomain[32];    /* Our NIS domain               */
235
extern char             NetOurHostName[32];     /* Our hostname                 */
236
extern char             NetOurRootPath[64];     /* Our root path                */
237
extern unsigned short           NetBootFileSize;        /* Our boot file size in blocks */
238
/** END OF BOOTP EXTENTIONS **/
239
extern unsigned long            NetBootFileXferSize;    /* size of bootfile in bytes    */
240
extern unsigned char            NetOurEther[6];         /* Our ethernet address         */
241
extern unsigned char            NetServerEther[6];      /* Boot server enet address     */
242
extern IPaddr_t         NetOurIP;               /* Our    IP addr (0 = unknown) */
243
extern IPaddr_t         NetServerIP;            /* Server IP addr (0 = unknown) */
244 140 julius
extern volatile unsigned char * NetTxPacket;            /* THE transmit packet          */
245 2 marcus.erl
extern volatile unsigned char * NetRxPackets[PKTBUFSRX];/* Receive packets              */
246
extern volatile unsigned char * NetRxPkt;               /* Current receive packet       */
247
extern int              NetRxPktLen;            /* Current rx packet length     */
248
extern unsigned         NetIPID;                /* IP ID (counting)             */
249
extern unsigned char            NetBcastAddr[6];        /* Ethernet boardcast address   */
250
 
251
extern int              NetState;               /* Network loop state           */
252
#define NETLOOP_CONTINUE        1
253
#define NETLOOP_RESTART         2
254
#define NETLOOP_SUCCESS         3
255
#define NETLOOP_FAIL            4
256
 
257
 
258
typedef enum { BOOTP, RARP, ARP, TFTP, DHCP } proto_t;
259
 
260
/* from net/net.c */
261
extern char     BootFile[128];                  /* Boot File name               */
262
 
263
/* Initialize the network adapter */
264
extern int      NetLoop(proto_t protocol);
265
 
266
/* Shutdown adapters and cleanup */
267
extern void     NetStop(void);
268
 
269
/* Load failed.  Start again. */
270
extern void     NetStartAgain(void);
271
 
272
/* Copy ethernet address */
273
extern void     NetCopyEther(volatile unsigned char *, unsigned char *);
274
 
275
/* Set ethernet header */
276
extern void     NetSetEther(volatile unsigned char *, unsigned char *, unsigned long);
277
 
278
/* Set IP header */
279
extern void     NetSetIP(volatile unsigned char *, IPaddr_t, int, int, int);
280
 
281
/* Checksum */
282
extern int      NetCksumOk(unsigned char *, int);       /* Return true if cksum OK      */
283
extern unsigned NetCksum(unsigned char *, int);         /* Calculate the checksum       */
284
 
285
/* Set callbacks */
286
extern void     NetSetHandler(rxhand_f *);      /* Set RX packet handler        */
287
extern void     NetSetTimeout(int, thand_f *);  /* Set timeout handler          */
288
 
289
/* Transmit "NetTxPacket" */
290
extern void     NetSendPacket(volatile unsigned char *, int);
291
 
292
/* Processes a received packet */
293
extern void     NetReceive(volatile unsigned char *, int);
294
 
295
/* Print an IP address on the console */
296
extern void     print_IPaddr (IPaddr_t);
297
 
298
/* Convert an IP address to a string */
299
extern void     ip_to_string (IPaddr_t x, char *s);
300
 
301
/* read an IP address from a environment variable */
302
extern IPaddr_t getenv_IPaddr (char *);
303
 
304
/* copy a filename (allow for "..." notation, limit length) */
305
extern void     copy_filename (unsigned char *dst, unsigned char *src, int size);
306
 
307
/* converts IP from unsigned long to string */
308
extern char         *inet_ntoa(unsigned long);
309
extern unsigned long inet_aton(const char *);
310
 
311
/**********************************************************************/
312
 
313
#endif /* __NET_H__ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.