Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/include/lwip/api.h need to be fixed.

0001 /*
0002  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
0003  * All rights reserved. 
0004  * 
0005  * Redistribution and use in source and binary forms, with or without modification, 
0006  * are permitted provided that the following conditions are met:
0007  *
0008  * 1. Redistributions of source code must retain the above copyright notice,
0009  *    this list of conditions and the following disclaimer.
0010  * 2. Redistributions in binary form must reproduce the above copyright notice,
0011  *    this list of conditions and the following disclaimer in the documentation
0012  *    and/or other materials provided with the distribution.
0013  * 3. The name of the author may not be used to endorse or promote products
0014  *    derived from this software without specific prior written permission. 
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
0017  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
0018  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
0019  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
0020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
0021  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
0024  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
0025  * OF SUCH DAMAGE.
0026  *
0027  * This file is part of the lwIP TCP/IP stack.
0028  * 
0029  * Author: Adam Dunkels <adam@sics.se>
0030  *
0031  */
0032 #ifndef __LWIP_API_H__
0033 #define __LWIP_API_H__
0034 
0035 #include "lwip/opt.h"
0036 
0037 #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
0038 
0039 #include <stddef.h>
0040 
0041 #include "lwip/netbuf.h"
0042 #include "lwip/sys.h"
0043 #include "lwip/ip_addr.h"
0044 #include "lwip/err.h"
0045 
0046 #ifdef __cplusplus
0047 extern "C" {
0048 #endif
0049 
0050 /* Throughout this file, IP addresses and port numbers are expected to be in
0051  * the same byte order as in the corresponding pcb.
0052  */
0053 
0054 /* Flags for netconn_write */
0055 #define NETCONN_NOFLAG 0x00
0056 #define NETCONN_NOCOPY 0x00 /* Only for source code compatibility */
0057 #define NETCONN_COPY   0x01
0058 #define NETCONN_MORE   0x02
0059 
0060 /* Helpers to process several netconn_types by the same code */
0061 #define NETCONNTYPE_GROUP(t)    (t&0xF0)
0062 #define NETCONNTYPE_DATAGRAM(t) (t&0xE0)
0063 
0064 enum netconn_type {
0065   NETCONN_INVALID    = 0,
0066   /* NETCONN_TCP Group */
0067   NETCONN_TCP        = 0x10,
0068   /* NETCONN_UDP Group */
0069   NETCONN_UDP        = 0x20,
0070   NETCONN_UDPLITE    = 0x21,
0071   NETCONN_UDPNOCHKSUM= 0x22,
0072   /* NETCONN_RAW Group */
0073   NETCONN_RAW        = 0x40
0074 };
0075 
0076 enum netconn_state {
0077   NETCONN_NONE,
0078   NETCONN_WRITE,
0079   NETCONN_LISTEN,
0080   NETCONN_CONNECT,
0081   NETCONN_CLOSE
0082 };
0083 
0084 enum netconn_evt {
0085   NETCONN_EVT_RCVPLUS,
0086   NETCONN_EVT_RCVMINUS,
0087   NETCONN_EVT_SENDPLUS,
0088   NETCONN_EVT_SENDMINUS
0089 };
0090 
0091 #if LWIP_IGMP
0092 enum netconn_igmp {
0093   NETCONN_JOIN,
0094   NETCONN_LEAVE
0095 };
0096 #endif /* LWIP_IGMP */
0097 
0098 /* forward-declare some structs to avoid to include their headers */
0099 struct ip_pcb;
0100 struct tcp_pcb;
0101 struct udp_pcb;
0102 struct raw_pcb;
0103 struct netconn;
0104 
0105 /** A callback prototype to inform about events for a netconn */
0106 typedef void (* netconn_callback)(struct netconn *, enum netconn_evt, u16_t len);
0107 
0108 /** A netconn descriptor */
0109 struct netconn {
0110   /** type of the netconn (TCP, UDP or RAW) */
0111   enum netconn_type type;
0112   /** current state of the netconn */
0113   enum netconn_state state;
0114   /** the lwIP internal protocol control block */
0115   union {
0116     struct ip_pcb  *ip;
0117     struct tcp_pcb *tcp;
0118     struct udp_pcb *udp;
0119     struct raw_pcb *raw;
0120   } pcb;
0121   /** the last error this netconn had */
0122   err_t err;
0123   /** sem that is used to synchroneously execute functions in the core context */
0124   sys_sem_t op_completed;
0125   /** mbox where received packets are stored until they are fetched
0126       by the netconn application thread (can grow quite big) */
0127   sys_mbox_t recvmbox;
0128   /** mbox where new connections are stored until processed
0129       by the application thread */
0130   sys_mbox_t acceptmbox;
0131   /** only used for socket layer */
0132   int socket;
0133 #if LWIP_SO_RCVTIMEO
0134   /** timeout to wait for new data to be received
0135       (or connections to arrive for listening netconns) */
0136   int recv_timeout;
0137 #endif /* LWIP_SO_RCVTIMEO */
0138 #if LWIP_SO_RCVBUF
0139   /** maximum amount of bytes queued in recvmbox */
0140   int recv_bufsize;
0141 #endif /* LWIP_SO_RCVBUF */
0142   s16_t recv_avail;
0143 #if LWIP_TCP
0144   /** TCP: when data passed to netconn_write doesn't fit into the send buffer,
0145       this temporarily stores the message. */
0146   struct api_msg_msg *write_msg;
0147   /** TCP: when data passed to netconn_write doesn't fit into the send buffer,
0148       this temporarily stores how much is already sent. */
0149   size_t write_offset;
0150 #if LWIP_TCPIP_CORE_LOCKING
0151   /** TCP: when data passed to netconn_write doesn't fit into the send buffer,
0152       this temporarily stores whether to wake up the original application task
0153       if data couldn't be sent in the first try. */
0154   u8_t write_delayed;
0155 #endif /* LWIP_TCPIP_CORE_LOCKING */
0156 #endif /* LWIP_TCP */
0157   /** A callback function that is informed about events for this netconn */
0158   netconn_callback callback;
0159 };
0160 
0161 /* Register an Network connection event */
0162 #define API_EVENT(c,e,l) if (c->callback) {         \
0163                            (*c->callback)(c, e, l); \
0164                          }
0165 
0166 /* Network connection functions: */
0167 #define netconn_new(t)                  netconn_new_with_proto_and_callback(t, 0, NULL)
0168 #define netconn_new_with_callback(t, c) netconn_new_with_proto_and_callback(t, 0, c)
0169 struct
0170 netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto,
0171                                    netconn_callback callback);
0172 err_t             netconn_delete  (struct netconn *conn);
0173 /** Get the type of a netconn (as enum netconn_type). */
0174 #define netconn_type(conn) (conn->type)
0175 
0176 err_t             netconn_getaddr (struct netconn *conn,
0177                                    struct ip_addr *addr,
0178                                    u16_t *port,
0179                                    u8_t local);
0180 #define netconn_peer(c,i,p) netconn_getaddr(c,i,p,0)
0181 #define netconn_addr(c,i,p) netconn_getaddr(c,i,p,1)
0182 
0183 err_t             netconn_bind    (struct netconn *conn,
0184                                    struct ip_addr *addr,
0185                                    u16_t port);
0186 err_t             netconn_connect (struct netconn *conn,
0187                                    struct ip_addr *addr,
0188                                    u16_t port);
0189 err_t             netconn_disconnect (struct netconn *conn);
0190 err_t             netconn_listen_with_backlog(struct netconn *conn, u8_t backlog);
0191 #define netconn_listen(conn) netconn_listen_with_backlog(conn, TCP_DEFAULT_LISTEN_BACKLOG)
0192 struct netconn *  netconn_accept  (struct netconn *conn);
0193 struct netbuf *   netconn_recv    (struct netconn *conn);
0194 err_t             netconn_sendto  (struct netconn *conn,
0195                                    struct netbuf *buf, struct ip_addr *addr, u16_t port);
0196 err_t             netconn_send    (struct netconn *conn,
0197                                    struct netbuf *buf);
0198 err_t             netconn_write   (struct netconn *conn,
0199                                    const void *dataptr, size_t size,
0200                                    u8_t apiflags);
0201 err_t             netconn_close   (struct netconn *conn);
0202 
0203 #if LWIP_IGMP
0204 err_t             netconn_join_leave_group (struct netconn *conn,
0205                                             struct ip_addr *multiaddr,
0206                                             struct ip_addr *interface,
0207                                             enum netconn_igmp join_or_leave);
0208 #endif /* LWIP_IGMP */
0209 #if LWIP_DNS
0210 err_t             netconn_gethostbyname(const char *name, struct ip_addr *addr);
0211 #endif /* LWIP_DNS */
0212 
0213 #define netconn_err(conn)          ((conn)->err)
0214 #define netconn_recv_bufsize(conn) ((conn)->recv_bufsize)
0215 
0216 #ifdef __cplusplus
0217 }
0218 #endif
0219 
0220 #endif /* LWIP_NETCONN */
0221 
0222 #endif /* __LWIP_API_H__ */