]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/ibl.git/blob - src/driver/eth/netif.h
Port makefiles to Linux (while still supporting Windows)
[keystone-rtos/ibl.git] / src / driver / eth / netif.h
1 /** 
2  *   @file  netif.h
3  *
4  *   @brief   
5  *      Internal header file used only by the NET Boot Module
6  *      This header file is not accessible by the DEVICE layers.
7  *
8  *  \par
9  *  NOTE:
10  *      (C) Copyright 2008, Texas Instruments, Inc.
11  *
12  *  \par
13  */
15 #ifndef __NETIF_H__
16 #define __NETIF_H__
18 /**
19  * @brief   This is the protocol identification field in the Ethernet
20  * header which identifies the packet as an IPv4 packet.
21  */
22 #define ETH_IP                  0x800
24 /**
25  * @brief   This is the protocol identification field in the Ethernet
26  * header which identifies the packet as an IPv4 packet.
27  */
28 #define ETH_ARP                  0x806
30 /**
31  * @brief   This is the protocol identification field in the IPv4 header
32  * which identifies the packet as an ICMP packet.
33  */
34 #define IPPROTO_ICMP            1
36 /**
37  * @brief   This is the protocol identification field in the IPv4 header
38  * which identifies the packet as a UDP packet.
39  */
40 #define IPPROTO_UDP             17
42 /**
43  * @brief   This is the ICMP Echo request type field which is present in the
44  * ICMP header. This is the only type handled in the ICMP Network Boot Module.
45  */
46 #define ICMP_ECHO_REQUEST_TYPE  8
48 /**
49  * @brief   This is the ICMP Echo reply type field which is present in the
50  * ICMP header. This is the reply packet generated in response to the REQ
51  * packet.
52  */
53 #define ICMP_ECHO_REPLY_TYPE    0
55 /**
56  * @brief   This is the BOOTP SERVER port to which BOOTP requests are sent
57  * by the BOOTP client module.
58  */
59 #define BOOTP_SERVER_PORT       67
61 /**
62  * @brief   This is the BOOTP Local port using which the BOOTP client will
63  * send requests.
64  */
65 #define BOOTP_CLIENT_PORT       68
67 /**
68  * @brief   This is the BOOTP OP definition for a BOOTP request
69  */
70 #define BOOTP_OP_REQUEST        1
72 /**
73  * @brief   This is the BOOTP OP definition for a BOOTP reply
74  */
75 #define BOOTP_OP_REPLY          2
77 /**
78  * @brief   This is the BOOTP HTYPE definition for Ethernet.
79  */
80 #define BOOTP_HTYPE_ETHERNET    1
82 /**
83  * @brief   This is the BOOTP Seed Timeout (in milliseconds) which is being used.
84  */
85 #define BOOTP_SEED_TIMEOUT      4000
87 /**
88  * @brief   This is the max. number of retries for which the BOOTP client
89  * will wait.
90  */
91 #define BOOTP_MAX_RETRIES      5
93 /**
94  * @brief   This is the default BOOTP subnet mask which is used if there
95  * is none present in the BOOTP options. 
96  */
97 #define BOOTP_DEFAULT_MASK      htonl(0xFFFFFF00)
99 /**
100  * @brief   This is the well defined TFTP Server port.
101  */
102 #define TFTP_SERVER_PORT       69
104 /**
105  * @brief   This is the maximum TFTP data size that is sent out.
106  */
107 #define TFTP_DATA_SIZE          512
109 /**
110  * @brief   This is the TFTP opcode for READ
111  */
112 #define TFTP_OPCODE_RRQ         1
114 /**
115  * @brief   This is the TFTP opcode for DATA
116  */
117 #define TFTP_OPCODE_DATA        3
119 /**
120  * @brief   This is the TFTP opcode for ACK
121  */
122 #define TFTP_OPCODE_ACK         4
124 /**
125  * @brief   This is the TFTP opcode for ERROR
126  */
127 #define TFTP_OPCODE_ERROR       5
129 /**
130  * @brief   This is the TFTP timeout (in milliseconds) used
131  * to send out periodic READ Requests if there is no response
132  * detected.
133  */
134 #define TFTP_TIMEOUT            1000
136 /**
137  * @brief   This is the TFTP Server timeout (in milliseconds)
138  * to detect the condition where the TFTP Server goes away in 
139  * the middle of the download.
140  */
141 #define TFTP_SERVER_TIMEOUT     60000
143 /**
144  * @brief   This is the maximum number of retransmits allowed
145  * in the TFTP Client after which an error is indicated.
146  */
147 #define MAX_TFTP_RETRANSMITS    5
149 /**
150  * @brief  This is the the ARP timeout (in milliseconds) used
151  *         to resend ARP requests.
152  */
153 #define ARP_TIMEOUT             1000
155 /***********************************************************************
156  ****************** STANDARD NETWORK HEADER DEFINITIONS ****************
157  ***********************************************************************/
159 #define ETHHDR_SIZE     14
160 typedef struct ETHHDR 
162     Uint8   DstMac[6];
163     Uint8   SrcMac[6];
164     Uint16  Type;
165 } ETHHDR;
167 #define IPHDR_SIZE      20
168 typedef struct IPHDR
170     Uint8    VerLen;
171     Uint8    Tos;
172     Uint16   TotalLen;
173     Uint16   Id;
174     Uint16   FlagOff;
175     Uint8    Ttl;
176     Uint8    Protocol;
177     Uint16   Checksum;
178     Uint32   IPSrc;
179     Uint32   IPDst;
180     Uint8    Options[1];
181 } IPHDR;
183 #define ARPHDR_SIZE     28
184 typedef struct ARPHDR
186     Uint16   HardType;
187     Uint16   ProtocolType;
188     Uint8    HardSize;
189     Uint8    ProtocolSize;
190     Uint16   Op;
191     Uint8    SrcAddr[6];
192     Uint8    IPSrc[4];
193     Uint8    DstAddr[6];
194     Uint8    IPDst[4];
195 } ARPHDR;
197 typedef struct PSEUDOHDR
199     IPN     IPSrc;
200     IPN     IPDst;
201     Uint16  Length;
202     Uint8   Null;
203     Uint8   Protocol;
204 } PSEUDOHDR;
206 #define UDPHDR_SIZE     8
207 typedef struct UDPHDR
209     Uint16   SrcPort;
210     Uint16   DstPort;
211     Uint16   Length;
212     Uint16   UDPChecksum;
213 }UDPHDR;
215 #define ICMPHDR_SIZE    4
216 typedef struct ICMPHDR
218     Uint8    Type;
219     Uint8    Code;
220     Uint16   Checksum;
221     Uint8    Data[1];
222 }ICMPHDR;
224 typedef struct BOOTPHDR
226     Uint8   op;
227     Uint8   htype;
228     Uint8   hlen;
229     Uint8   hops;
230     Uint32  xid;
231     Uint16  secs;
232     Uint16  unused;
233     Uint32  ciaddr;
234     Uint32  yiaddr;
235     Uint32  siaddr;
236     Uint32  giaddr;
237     Uint8   chaddr[16];
238     Uint8   sname[64];
239     Uint8   file[128];
240     Uint8   options[64];
241 } BOOTPHDR;
243 #define TFTPHEADER_SIZE 4
244 typedef struct TFTPHDR
246     Uint16   opcode;
247     Uint16   block;
248     Uint8    data[1];
249 }TFTPHDR;
251 /**
252  * @brief 
253  *  The structure describes the ROUTE Entry.
254  *
255  * @details
256  *  This structures describes the routing entry. This is used by the network
257  *  boot module to determine the next hop address. The next hop address might
258  *  not be the same as the destination IP address if there exists a default
259  *  gateway.
260  */
261 typedef struct RT_ENTRY
263     /**
264      * @brief  Flags which describe the routing entry.
265      */
266     Uint32  flags;
268     /**
269      * @brief  IP Address associated with the route
270      */
271     IPN     ip_addr;
273     /**
274      * @brief  Network Mask associated with the route
275      */
276     IPN     net_mask;
278     /**
279      * @brief  Network Address associated with the route
280      */
281     IPN     net_addr;
283     /**
284      * @brief  Next Hop Address associated with the route
285      */        
286     IPN     next_hop;
287 }RT_ENTRY;
289 /**
290  * @brief 
291  *  The structure describes the NET Master Control Block.
292  *
293  * @details
294  *  This is an *internal* structure used by the NET Core Module for storing
295  *  information. This structure should not be used or be accessed by the 
296  *  platform team.
297  */
298 typedef struct NET_MCB
300     /**
301      * @brief   This is the network device which is attached to the network
302      * boot module.
303      */
304     NET_DRV_DEVICE   net_device;
306     /**
307      * @brief   This is the receive packet which is passed to the driver 
308      * when the Net boot module invokes the receive API. The driver copies 
309      * data from its internal buffers to this buffer. The network boot module
310      * only operates on this buffer.
311      */
312     Uint8           rx_packet[NET_MAX_MTU];
314     /**
315      * @brief   This is the IP ID field which is globally incremented on
316      * every packet transmitted from the Network boot module.
317      */
318     Uint16          ipID;
320     /**
321      * @brief   This indicates the status of the transmission buffer and whether
322      * it is available to be used or not. This is manipulated by the alloc_tx
323      * and free_tx routines to ensure there is no corruption with respect to the
324      * internal buffers.
325      */
326     Uint32          txuse;
328     /**
329      * @brief   This flag indicates if there was an Error detected in the 
330      * NET Boot Module or not? This is then used to break out of the NET Boot
331      * Module Scheduler. If there is no error detected the flag is set to 0.
332      */
333     Int32           error_flag; 
335     /**
336      * @brief   This is the transmit packet which is used by the network
337      * module to send a packet to the driver.
338      */
339     Uint8           tx_packet[NET_MAX_MTU];
340     
341     
342     /**
343      *  @brief  This tracks the current read byte in the file 
344      */
345     Uint32          fileOffset; 
346     
347     
348 }NET_MCB;
350 /**********************************************************************
351  **************************** Extern Data *****************************
352  **********************************************************************/
353 extern NET_MCB   netmcb;
355 /**********************************************************************
356  **************************** Exported API ****************************
357  **********************************************************************/
358 extern void      net_init (void);
359 extern Uint8*    net_alloc_tx_packet(Int32 packet_len);
360 extern void      net_free_tx_packet (Uint8* ptr);
361 extern ETHHDR*   net_create_eth_header (Uint8* ptr_l3_hdr, Uint8* dst_mac, Uint16 protocol);
362 extern void      net_send_packet (ETHHDR* ptr_l2_hdr, Uint16 length);
364 /* ARP Module exported API. */
365 extern void      arp_init (void);
366 extern Int32     arp_receive (ARPHDR* ptr_arphdr, Int32 num_bytes);
367 extern void      arp_resolve (IPN dst_ip, IPHDR* ptr_iphdr, Uint16 l3_pkt_size);
369 /* IPv4 Module exported API. */
370 extern void      ip_init (void);
371 extern Int32     ip_receive (IPHDR* ptr_iphdr, Int32 num_bytes);
372 extern void      ip_send (IPHDR* ptr_iphdr, Uint16 size);
373 extern RT_ENTRY* ip_lookup_route (IPN ip_address);
375 /* UDP Module exported API. */
376 extern void     udp_init (void);
377 extern Int32    udp_receive (IPHDR* ptr_iphdr);
379 /* BOOTP Module exported API */
380 #ifdef INCLUDE_BLF_NET_BOOTP
381 extern void      bootp_init (void);
382 #endif
384 #ifdef INCLUDE_BLF_NET_ICMP
385 extern void      icmp_receive (IPHDR* ptr_iphdr);
386 #endif
388 #endif /* __NETIF_H__ */