1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
4 * High-level network API defs File: net_api.h
6 * This module contains prototypes and constants for the
7 * network (TCP/IP) interface.
9 * Author: Mitch Lichtenberg (mpl@broadcom.com)
11 *********************************************************************
13 * Copyright 2000,2001,2002,2003
14 * Broadcom Corporation. All rights reserved.
16 * This software is furnished under license and may be used and
17 * copied only in accordance with the following terms and
18 * conditions. Subject to these conditions, you may download,
19 * copy, install, use, modify and distribute modified or unmodified
20 * copies of this software in source and/or binary form. No title
21 * or ownership is transferred hereby.
23 * 1) Any source code used, modified or distributed must reproduce
24 * and retain this copyright notice and list of conditions
25 * as they appear in the source file.
27 * 2) No right is granted to use any trade name, trademark, or
28 * logo of Broadcom Corporation. The "Broadcom Corporation"
29 * name may not be used to endorse or promote products derived
30 * from this software without the prior written permission of
31 * Broadcom Corporation.
33 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
34 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
35 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
37 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
38 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
39 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
40 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
41 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
42 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
43 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
44 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
45 * THE POSSIBILITY OF SUCH DAMAGE.
46 ********************************************************************* */
49 /* *********************************************************************
51 ********************************************************************* */
57 /* *********************************************************************
59 ********************************************************************* */
61 typedef struct dhcpreply_s
{
62 uint8_t dr_ipaddr
[IP_ADDR_LEN
];
63 uint8_t dr_netmask
[IP_ADDR_LEN
];
64 uint8_t dr_gateway
[IP_ADDR_LEN
];
65 uint8_t dr_nameserver
[IP_ADDR_LEN
];
66 uint8_t dr_dhcpserver
[IP_ADDR_LEN
];
67 uint8_t dr_bootserver
[IP_ADDR_LEN
];
78 int dhcp_bootrequest(dhcpreply_t
**reply
);
79 void dhcp_free_reply(dhcpreply_t
*reply
);
80 void dhcp_set_envvars(dhcpreply_t
*reply
);
82 /* *********************************************************************
84 ********************************************************************* */
87 int ip_init(char *,uint8_t *);
88 ebuf_t
*ip_alloc(void);
89 void ip_free(ebuf_t
*buf
);
90 int ip_send(ebuf_t
*buf
,uint8_t *destaddr
,uint8_t proto
);
91 uint16_t ip_chksum(uint16_t initchksum
,uint8_t *ptr
,int len
);
93 /* *********************************************************************
95 ********************************************************************* */
97 ebuf_t
*udp_alloc(void);
98 void udp_free(ebuf_t
*buf
);
100 int udp_socket(uint16_t port
);
101 int udp_bind(int portnum
,uint16_t port
);
102 int udp_connect(int portnum
,uint16_t port
);
103 void udp_close(int portnum
);
104 int udp_send(int portnum
,ebuf_t
*buf
,uint8_t *dest
);
105 ebuf_t
*udp_recv_with_timeout(int portnum
,int seconds
);
106 ebuf_t
*udp_recv(int portnum
);
108 /* *********************************************************************
110 ********************************************************************* */
113 #ifndef TCPFLG_NODELAY
114 #define TCPFLG_NODELAY 1 /* disable nagle */
115 #define TCPFLG_NBIO 2 /* non-blocking I/O */
117 #define TCPSTATUS_NOTCONN 0
118 #define TCPSTATUS_CONNECTING 1
119 #define TCPSTATUS_CONNECTED 2
121 int tcp_socket(void);
122 void tcp_destroy(int portnum
);
123 int tcp_connect(int s
,uint8_t *dest
,uint16_t port
);
124 int tcp_close(int s
);
125 int tcp_send(int s
,uint8_t *buf
,int len
);
126 int tcp_recv(int s
,uint8_t *buf
,int len
);
127 int tcp_bind(int s
,uint16_t port
);
128 int tcp_peeraddr(int s
,uint8_t *addr
,uint16_t *port
);
129 int tcp_listen(int s
,uint16_t port
);
130 int tcp_status(int s
,int *connflag
,int *rxready
,int *rxeof
);
131 int tcp_debug(int s
,int arg
);
132 int tcp_setflags(int s
,unsigned int flags
);
133 int tcp_getflags(int s
,unsigned int *flags
);
136 /* *********************************************************************
138 ********************************************************************* */
140 uint8_t *arp_lookup(uint8_t *destip
);
141 void arp_add(uint8_t *destip
,uint8_t *desthw
);
142 int arp_enumerate(int entrynum
,uint8_t *ipaddr
,uint8_t *hwaddr
);
143 int arp_delete(uint8_t *ipaddr
);
145 /* *********************************************************************
146 * Network Configuration
147 ********************************************************************* */
151 #define NET_NETMASK 1
152 #define NET_GATEWAY 2
153 #define NET_NAMESERVER 3
156 #define NET_HOSTNAME 6
158 #define NET_LOOPBACK 8
160 #define NET_DEVNAME 10
162 uint8_t *net_getparam(int param
);
163 int net_setparam(int param
,uint8_t *ptr
);
164 int net_init(char *devname
);
165 void net_uninit(void);
166 void net_setnetvars(void);
168 /* *********************************************************************
170 ********************************************************************* */
172 int dns_lookup(char *hostname
,uint8_t *ipaddr
);
174 /* *********************************************************************
176 ********************************************************************* */
178 int icmp_ping(uint8_t *dest
,int seq
,int len
);
180 /* *********************************************************************
182 ********************************************************************* */
184 extern int tftp_max_retries
;
185 extern int tftp_rrq_timeout
;
186 extern int tftp_recv_timeout
;