1/* ********************************************************************* 2 * Broadcom Common Firmware Environment (CFE) 3 * 4 * High-level network API defs File: net_api.h 5 * 6 * This module contains prototypes and constants for the 7 * network (TCP/IP) interface. 8 * 9 * Author: Mitch Lichtenberg 10 * 11 ********************************************************************* 12 * 13 * Copyright 2000,2001,2002,2003 14 * Broadcom Corporation. All rights reserved. 15 * 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. 22 * 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. 26 * 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. 32 * 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 ********************************************************************* */ 47 48 49/* ********************************************************************* 50 * Constants 51 ********************************************************************* */ 52 53#ifndef IP_ADDR_LEN 54#define IP_ADDR_LEN 4 55#endif 56 57/* ********************************************************************* 58 * DHCP Protocol 59 ********************************************************************* */ 60 61typedef 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]; 68 char *dr_hostname; 69 char *dr_domainname; 70 char *dr_bootfile; 71 char *dr_rootpath; 72 char *dr_swapserver; 73 char *dr_script; 74 char *dr_options; 75} dhcpreply_t; 76 77 78int dhcp_bootrequest(dhcpreply_t **reply); 79void dhcp_free_reply(dhcpreply_t *reply); 80void dhcp_set_envvars(dhcpreply_t *reply); 81 82/* ********************************************************************* 83 * IP Layer 84 ********************************************************************* */ 85 86void ip_uninit(void); 87int ip_init(char *,uint8_t *); 88ebuf_t *ip_alloc(void); 89void ip_free(ebuf_t *buf); 90int ip_send(ebuf_t *buf,uint8_t *destaddr,uint8_t proto); 91uint16_t ip_chksum(uint16_t initchksum,uint8_t *ptr,int len); 92 93/* ********************************************************************* 94 * UDP Layer 95 ********************************************************************* */ 96 97ebuf_t *udp_alloc(void); 98void udp_free(ebuf_t *buf); 99 100int udp_socket(uint16_t port); 101int udp_bind(int portnum,uint16_t port); 102int udp_connect(int portnum,uint16_t port); 103void udp_close(int portnum); 104int udp_send(int portnum,ebuf_t *buf,uint8_t *dest); 105ebuf_t *udp_recv_with_timeout(int portnum,int ticks); 106ebuf_t *udp_recv(int portnum); 107 108/* ********************************************************************* 109 * TCP Layer 110 ********************************************************************* */ 111 112#if CFG_TCP 113#ifndef TCPFLG_NODELAY /* XXX should be kept in sync with net_tcp.h */ 114#define TCPFLG_NODELAY 1 /* disable nagle */ 115#define TCPFLG_NBIO 2 /* non-blocking I/O */ 116 117#define TCPSTATUS_NOTCONN 0 118#define TCPSTATUS_CONNECTING 1 119#define TCPSTATUS_CONNECTED 2 120#endif 121int tcp_socket(void); 122void tcp_destroy(int portnum); 123int tcp_connect(int s,uint8_t *dest,uint16_t port); 124int tcp_close(int s); 125int tcp_send(int s,hsaddr_t buf,int len); 126int tcp_recv(int s,hsaddr_t buf,int len); 127int tcp_bind(int s,uint16_t port); 128int tcp_peeraddr(int s,uint8_t *addr,uint16_t *port); 129int tcp_listen(int s,uint16_t port); 130int tcp_status(int s,int *connflag,int *rxready,int *rxeof); 131int tcp_debug(int s,int arg); 132int tcp_setflags(int s,unsigned int flags); 133int tcp_getflags(int s,unsigned int *flags); 134#endif 135 136/* ********************************************************************* 137 * ARP Layer 138 ********************************************************************* */ 139 140uint8_t *arp_lookup(uint8_t *destip); 141void arp_add(uint8_t *destip,uint8_t *desthw); 142int arp_enumerate(int entrynum,uint8_t *ipaddr,uint8_t *hwaddr); 143int arp_delete(uint8_t *ipaddr); 144 145/* ********************************************************************* 146 * Network Configuration 147 ********************************************************************* */ 148 149#ifndef NET_IPADDR 150#define NET_IPADDR 0 151#define NET_NETMASK 1 152#define NET_GATEWAY 2 153#define NET_NAMESERVER 3 154#define NET_HWADDR 4 155#define NET_DOMAIN 5 156#define NET_HOSTNAME 6 157#define NET_SPEED 7 158#define NET_LOOPBACK 8 159#endif 160#define NET_DEVNAME 10 161 162uint8_t *net_getparam(int param); 163int net_setparam(int param,uint8_t *ptr); 164int net_init(char *devname); 165void net_uninit(void); 166void net_setnetvars(void); 167 168/* ********************************************************************* 169 * DNS 170 ********************************************************************* */ 171 172int dns_lookup(char *hostname,uint8_t *ipaddr); 173 174/* ********************************************************************* 175 * ICMP 176 ********************************************************************* */ 177 178int icmp_ping(uint8_t *dest,int seq,int len); 179 180/* ********************************************************************* 181 * TFTP 182 ********************************************************************* */ 183 184extern int tftp_max_retries; 185extern int tftp_rrq_timeout; 186extern int tftp_recv_timeout; 187 188 189