]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/ibl.git/blob - src/driver/eth/netif.h
Initial c661x version
[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  *  Redistribution and use in source and binary forms, with or without 
13  *  modification, are permitted provided that the following conditions 
14  *  are met:
15  *
16  *    Redistributions of source code must retain the above copyright 
17  *    notice, this list of conditions and the following disclaimer.
18  *
19  *    Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the 
21  *    documentation and/or other materials provided with the   
22  *    distribution.
23  *
24  *    Neither the name of Texas Instruments Incorporated nor the names of
25  *    its contributors may be used to endorse or promote products derived
26  *    from this software without specific prior written permission.
27  *
28  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
29  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
30  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
32  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
33  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
34  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
37  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
38  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  *  \par
41 */
43 #ifndef __NETIF_H__
44 #define __NETIF_H__
46 /**
47  * @brief   This is the protocol identification field in the Ethernet
48  * header which identifies the packet as an IPv4 packet.
49  */
50 #define ETH_IP                  0x800
52 /**
53  * @brief   This is the protocol identification field in the Ethernet
54  * header which identifies the packet as an IPv4 packet.
55  */
56 #define ETH_ARP                  0x806
58 /**
59  * @brief   This is the protocol identification field in the IPv4 header
60  * which identifies the packet as an ICMP packet.
61  */
62 #define IPPROTO_ICMP            1
64 /**
65  * @brief   This is the protocol identification field in the IPv4 header
66  * which identifies the packet as a UDP packet.
67  */
68 #define IPPROTO_UDP             17
70 /**
71  * @brief   This is the ICMP Echo request type field which is present in the
72  * ICMP header. This is the only type handled in the ICMP Network Boot Module.
73  */
74 #define ICMP_ECHO_REQUEST_TYPE  8
76 /**
77  * @brief   This is the ICMP Echo reply type field which is present in the
78  * ICMP header. This is the reply packet generated in response to the REQ
79  * packet.
80  */
81 #define ICMP_ECHO_REPLY_TYPE    0
83 /**
84  * @brief   This is the BOOTP SERVER port to which BOOTP requests are sent
85  * by the BOOTP client module.
86  */
87 #define BOOTP_SERVER_PORT       67
89 /**
90  * @brief   This is the BOOTP Local port using which the BOOTP client will
91  * send requests.
92  */
93 #define BOOTP_CLIENT_PORT       68
95 /**
96  * @brief   This is the BOOTP OP definition for a BOOTP request
97  */
98 #define BOOTP_OP_REQUEST        1
100 /**
101  * @brief   This is the BOOTP OP definition for a BOOTP reply
102  */
103 #define BOOTP_OP_REPLY          2
105 /**
106  * @brief   This is the BOOTP HTYPE definition for Ethernet.
107  */
108 #define BOOTP_HTYPE_ETHERNET    1
110 /**
111  * @brief   This is the BOOTP Seed Timeout (in milliseconds) which is being used.
112  */
113 #define BOOTP_SEED_TIMEOUT      4000
115 /**
116  * @brief   This is the max. number of retries for which the BOOTP client
117  * will wait.
118  */
119 #define BOOTP_MAX_RETRIES      5
121 /**
122  * @brief   This is the default BOOTP subnet mask which is used if there
123  * is none present in the BOOTP options. 
124  */
125 #define BOOTP_DEFAULT_MASK      htonl(0xFFFFFF00)
127 /**
128  * @brief   This is the well defined TFTP Server port.
129  */
130 #define TFTP_SERVER_PORT       69
132 /**
133  * @brief   This is the maximum TFTP data size that is sent out.
134  */
135 #define TFTP_DATA_SIZE          512
137 /**
138  * @brief   This is the TFTP opcode for READ
139  */
140 #define TFTP_OPCODE_RRQ         1
142 /**
143  * @brief   This is the TFTP opcode for DATA
144  */
145 #define TFTP_OPCODE_DATA        3
147 /**
148  * @brief   This is the TFTP opcode for ACK
149  */
150 #define TFTP_OPCODE_ACK         4
152 /**
153  * @brief   This is the TFTP opcode for ERROR
154  */
155 #define TFTP_OPCODE_ERROR       5
157 /**
158  * @brief   This is the TFTP timeout (in milliseconds) used
159  * to send out periodic READ Requests if there is no response
160  * detected.
161  */
162 #define TFTP_TIMEOUT            1000
164 /**
165  * @brief   This is the TFTP Server timeout (in milliseconds)
166  * to detect the condition where the TFTP Server goes away in 
167  * the middle of the download.
168  */
169 #define TFTP_SERVER_TIMEOUT     60000
171 /**
172  * @brief   This is the maximum number of retransmits allowed
173  * in the TFTP Client after which an error is indicated.
174  */
175 #define MAX_TFTP_RETRANSMITS    5
177 /**
178  * @brief  This is the the ARP timeout (in milliseconds) used
179  *         to resend ARP requests.
180  */
181 #define ARP_TIMEOUT             1000
183 /***********************************************************************
184  ****************** STANDARD NETWORK HEADER DEFINITIONS ****************
185  ***********************************************************************/
187 #define ETHHDR_SIZE     14
188 typedef struct ETHHDR 
190     Uint8   DstMac[6];
191     Uint8   SrcMac[6];
192     Uint16  Type;
193 } ETHHDR;
195 #define IPHDR_SIZE      20
196 typedef struct IPHDR
198     Uint8    VerLen;
199     Uint8    Tos;
200     Uint16   TotalLen;
201     Uint16   Id;
202     Uint16   FlagOff;
203     Uint8    Ttl;
204     Uint8    Protocol;
205     Uint16   Checksum;
206     Uint32   IPSrc;
207     Uint32   IPDst;
208     Uint8    Options[1];
209 } IPHDR;
211 #define ARPHDR_SIZE     28
212 typedef struct ARPHDR
214     Uint16   HardType;
215     Uint16   ProtocolType;
216     Uint8    HardSize;
217     Uint8    ProtocolSize;
218     Uint16   Op;
219     Uint8    SrcAddr[6];
220     Uint8    IPSrc[4];
221     Uint8    DstAddr[6];
222     Uint8    IPDst[4];
223 } ARPHDR;
225 typedef struct PSEUDOHDR
227     IPN     IPSrc;
228     IPN     IPDst;
229     Uint16  Length;
230     Uint8   Null;
231     Uint8   Protocol;
232 } PSEUDOHDR;
234 #define UDPHDR_SIZE     8
235 typedef struct UDPHDR
237     Uint16   SrcPort;
238     Uint16   DstPort;
239     Uint16   Length;
240     Uint16   UDPChecksum;
241 }UDPHDR;
243 #define ICMPHDR_SIZE    4
244 typedef struct ICMPHDR
246     Uint8    Type;
247     Uint8    Code;
248     Uint16   Checksum;
249     Uint8    Data[1];
250 }ICMPHDR;
252 typedef struct BOOTPHDR
254     Uint8   op;
255     Uint8   htype;
256     Uint8   hlen;
257     Uint8   hops;
258     Uint32  xid;
259     Uint16  secs;
260     Uint16  unused;
261     Uint32  ciaddr;
262     Uint32  yiaddr;
263     Uint32  siaddr;
264     Uint32  giaddr;
265     Uint8   chaddr[16];
266     Uint8   sname[64];
267     Uint8   file[128];
268     Uint8   options[64];
269 } BOOTPHDR;
271 #define TFTPHEADER_SIZE 4
272 typedef struct TFTPHDR
274     Uint16   opcode;
275     Uint16   block;
276     Uint8    data[1];
277 }TFTPHDR;
279 /**
280  * @brief 
281  *  The structure describes the ROUTE Entry.
282  *
283  * @details
284  *  This structures describes the routing entry. This is used by the network
285  *  boot module to determine the next hop address. The next hop address might
286  *  not be the same as the destination IP address if there exists a default
287  *  gateway.
288  */
289 typedef struct RT_ENTRY
291     /**
292      * @brief  Flags which describe the routing entry.
293      */
294     Uint32  flags;
296     /**
297      * @brief  IP Address associated with the route
298      */
299     IPN     ip_addr;
301     /**
302      * @brief  Network Mask associated with the route
303      */
304     IPN     net_mask;
306     /**
307      * @brief  Network Address associated with the route
308      */
309     IPN     net_addr;
311     /**
312      * @brief  Next Hop Address associated with the route
313      */        
314     IPN     next_hop;
315 }RT_ENTRY;
317 /**
318  * @brief 
319  *  The structure describes the NET Master Control Block.
320  *
321  * @details
322  *  This is an *internal* structure used by the NET Core Module for storing
323  *  information. This structure should not be used or be accessed by the 
324  *  platform team.
325  */
326 typedef struct NET_MCB
328     /**
329      * @brief   This is the network device which is attached to the network
330      * boot module.
331      */
332     NET_DRV_DEVICE   net_device;
334     /**
335      * @brief   This is the receive packet which is passed to the driver 
336      * when the Net boot module invokes the receive API. The driver copies 
337      * data from its internal buffers to this buffer. The network boot module
338      * only operates on this buffer.
339      */
340     Uint8           rx_packet[NET_MAX_MTU];
342     /**
343      * @brief   This is the IP ID field which is globally incremented on
344      * every packet transmitted from the Network boot module.
345      */
346     Uint16          ipID;
348     /**
349      * @brief   This indicates the status of the transmission buffer and whether
350      * it is available to be used or not. This is manipulated by the alloc_tx
351      * and free_tx routines to ensure there is no corruption with respect to the
352      * internal buffers.
353      */
354     Uint32          txuse;
356     /**
357      * @brief   This flag indicates if there was an Error detected in the 
358      * NET Boot Module or not? This is then used to break out of the NET Boot
359      * Module Scheduler. If there is no error detected the flag is set to 0.
360      */
361     Int32           error_flag; 
363     /**
364      * @brief   This is the transmit packet which is used by the network
365      * module to send a packet to the driver.
366      */
367     Uint8           tx_packet[NET_MAX_MTU];
368     
369     
370     /**
371      *  @brief  This tracks the current read byte in the file 
372      */
373     Uint32          fileOffset; 
374     
375     
376 }NET_MCB;
378 /**********************************************************************
379  **************************** Extern Data *****************************
380  **********************************************************************/
381 extern NET_MCB   netmcb;
383 /**********************************************************************
384  **************************** Exported API ****************************
385  **********************************************************************/
386 extern void      net_init (void);
387 extern Uint8*    net_alloc_tx_packet(Int32 packet_len);
388 extern void      net_free_tx_packet (Uint8* ptr);
389 extern ETHHDR*   net_create_eth_header (Uint8* ptr_l3_hdr, Uint8* dst_mac, Uint16 protocol);
390 extern void      net_send_packet (ETHHDR* ptr_l2_hdr, Uint16 length);
392 /* ARP Module exported API. */
393 extern void      arp_init (void);
394 extern Int32     arp_receive (ARPHDR* ptr_arphdr, Int32 num_bytes);
395 extern void      arp_resolve (IPN dst_ip, IPHDR* ptr_iphdr, Uint16 l3_pkt_size);
397 /* IPv4 Module exported API. */
398 extern void      ip_init (void);
399 extern Int32     ip_receive (IPHDR* ptr_iphdr, Int32 num_bytes);
400 extern void      ip_send (IPHDR* ptr_iphdr, Uint16 size);
401 extern RT_ENTRY* ip_lookup_route (IPN ip_address);
403 /* UDP Module exported API. */
404 extern void     udp_init (void);
405 extern Int32    udp_receive (IPHDR* ptr_iphdr);
407 /* BOOTP Module exported API */
408 void bootp_init (void (*asyncComplete)(void *));
410 #ifdef INCLUDE_BLF_NET_ICMP
411 extern void      icmp_receive (IPHDR* ptr_iphdr);
412 #endif
414 #endif /* __NETIF_H__ */