mbed Phone Platform

Dependencies:   ulaw mbed ConfigFile

Committer:
okini3939
Date:
Sun Dec 26 15:49:07 2010 +0000
Revision:
1:0f82c574096f

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okini3939 1:0f82c574096f 1 /*
okini3939 1:0f82c574096f 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
okini3939 1:0f82c574096f 3 * All rights reserved.
okini3939 1:0f82c574096f 4 *
okini3939 1:0f82c574096f 5 * Redistribution and use in source and binary forms, with or without modification,
okini3939 1:0f82c574096f 6 * are permitted provided that the following conditions are met:
okini3939 1:0f82c574096f 7 *
okini3939 1:0f82c574096f 8 * 1. Redistributions of source code must retain the above copyright notice,
okini3939 1:0f82c574096f 9 * this list of conditions and the following disclaimer.
okini3939 1:0f82c574096f 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
okini3939 1:0f82c574096f 11 * this list of conditions and the following disclaimer in the documentation
okini3939 1:0f82c574096f 12 * and/or other materials provided with the distribution.
okini3939 1:0f82c574096f 13 * 3. The name of the author may not be used to endorse or promote products
okini3939 1:0f82c574096f 14 * derived from this software without specific prior written permission.
okini3939 1:0f82c574096f 15 *
okini3939 1:0f82c574096f 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
okini3939 1:0f82c574096f 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
okini3939 1:0f82c574096f 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
okini3939 1:0f82c574096f 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
okini3939 1:0f82c574096f 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
okini3939 1:0f82c574096f 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
okini3939 1:0f82c574096f 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
okini3939 1:0f82c574096f 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
okini3939 1:0f82c574096f 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
okini3939 1:0f82c574096f 25 * OF SUCH DAMAGE.
okini3939 1:0f82c574096f 26 *
okini3939 1:0f82c574096f 27 * This file is part of the lwIP TCP/IP stack.
okini3939 1:0f82c574096f 28 *
okini3939 1:0f82c574096f 29 * Author: Adam Dunkels <adam@sics.se>
okini3939 1:0f82c574096f 30 *
okini3939 1:0f82c574096f 31 */
okini3939 1:0f82c574096f 32 #ifndef __LWIP_API_H__
okini3939 1:0f82c574096f 33 #define __LWIP_API_H__
okini3939 1:0f82c574096f 34
okini3939 1:0f82c574096f 35 #include "lwip/opt.h"
okini3939 1:0f82c574096f 36
okini3939 1:0f82c574096f 37 #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
okini3939 1:0f82c574096f 38
okini3939 1:0f82c574096f 39 #include <stddef.h> /* for size_t */
okini3939 1:0f82c574096f 40
okini3939 1:0f82c574096f 41 #include "lwip/netbuf.h"
okini3939 1:0f82c574096f 42 #include "lwip/sys.h"
okini3939 1:0f82c574096f 43 #include "lwip/ip_addr.h"
okini3939 1:0f82c574096f 44 #include "lwip/err.h"
okini3939 1:0f82c574096f 45
okini3939 1:0f82c574096f 46 #ifdef __cplusplus
okini3939 1:0f82c574096f 47 extern "C" {
okini3939 1:0f82c574096f 48 #endif
okini3939 1:0f82c574096f 49
okini3939 1:0f82c574096f 50 /* Throughout this file, IP addresses and port numbers are expected to be in
okini3939 1:0f82c574096f 51 * the same byte order as in the corresponding pcb.
okini3939 1:0f82c574096f 52 */
okini3939 1:0f82c574096f 53
okini3939 1:0f82c574096f 54 /* Flags for netconn_write (u8_t) */
okini3939 1:0f82c574096f 55 #define NETCONN_NOFLAG 0x00
okini3939 1:0f82c574096f 56 #define NETCONN_NOCOPY 0x00 /* Only for source code compatibility */
okini3939 1:0f82c574096f 57 #define NETCONN_COPY 0x01
okini3939 1:0f82c574096f 58 #define NETCONN_MORE 0x02
okini3939 1:0f82c574096f 59 #define NETCONN_DONTBLOCK 0x04
okini3939 1:0f82c574096f 60
okini3939 1:0f82c574096f 61 /* Flags for struct netconn.flags (u8_t) */
okini3939 1:0f82c574096f 62 /** TCP: when data passed to netconn_write doesn't fit into the send buffer,
okini3939 1:0f82c574096f 63 this temporarily stores whether to wake up the original application task
okini3939 1:0f82c574096f 64 if data couldn't be sent in the first try. */
okini3939 1:0f82c574096f 65 #define NETCONN_FLAG_WRITE_DELAYED 0x01
okini3939 1:0f82c574096f 66 /** Should this netconn avoid blocking? */
okini3939 1:0f82c574096f 67 #define NETCONN_FLAG_NON_BLOCKING 0x02
okini3939 1:0f82c574096f 68 /** Was the last connect action a non-blocking one? */
okini3939 1:0f82c574096f 69 #define NETCONN_FLAG_IN_NONBLOCKING_CONNECT 0x04
okini3939 1:0f82c574096f 70 /** If this is set, a TCP netconn must call netconn_recved() to update
okini3939 1:0f82c574096f 71 the TCP receive window (done automatically if not set). */
okini3939 1:0f82c574096f 72 #define NETCONN_FLAG_NO_AUTO_RECVED 0x08
okini3939 1:0f82c574096f 73 /** If a nonblocking write has been rejected before, poll_tcp needs to
okini3939 1:0f82c574096f 74 check if the netconn is writable again */
okini3939 1:0f82c574096f 75 #define NETCONN_FLAG_CHECK_WRITESPACE 0x10
okini3939 1:0f82c574096f 76
okini3939 1:0f82c574096f 77
okini3939 1:0f82c574096f 78 /* Helpers to process several netconn_types by the same code */
okini3939 1:0f82c574096f 79 #define NETCONNTYPE_GROUP(t) (t&0xF0)
okini3939 1:0f82c574096f 80 #define NETCONNTYPE_DATAGRAM(t) (t&0xE0)
okini3939 1:0f82c574096f 81
okini3939 1:0f82c574096f 82 /** Protocol family and type of the netconn */
okini3939 1:0f82c574096f 83 enum netconn_type {
okini3939 1:0f82c574096f 84 NETCONN_INVALID = 0,
okini3939 1:0f82c574096f 85 /* NETCONN_TCP Group */
okini3939 1:0f82c574096f 86 NETCONN_TCP = 0x10,
okini3939 1:0f82c574096f 87 /* NETCONN_UDP Group */
okini3939 1:0f82c574096f 88 NETCONN_UDP = 0x20,
okini3939 1:0f82c574096f 89 NETCONN_UDPLITE = 0x21,
okini3939 1:0f82c574096f 90 NETCONN_UDPNOCHKSUM= 0x22,
okini3939 1:0f82c574096f 91 /* NETCONN_RAW Group */
okini3939 1:0f82c574096f 92 NETCONN_RAW = 0x40
okini3939 1:0f82c574096f 93 };
okini3939 1:0f82c574096f 94
okini3939 1:0f82c574096f 95 /** Current state of the netconn. Non-TCP netconns are always
okini3939 1:0f82c574096f 96 * in state NETCONN_NONE! */
okini3939 1:0f82c574096f 97 enum netconn_state {
okini3939 1:0f82c574096f 98 NETCONN_NONE,
okini3939 1:0f82c574096f 99 NETCONN_WRITE,
okini3939 1:0f82c574096f 100 NETCONN_LISTEN,
okini3939 1:0f82c574096f 101 NETCONN_CONNECT,
okini3939 1:0f82c574096f 102 NETCONN_CLOSE
okini3939 1:0f82c574096f 103 };
okini3939 1:0f82c574096f 104
okini3939 1:0f82c574096f 105 /** Use to inform the callback function about changes */
okini3939 1:0f82c574096f 106 enum netconn_evt {
okini3939 1:0f82c574096f 107 NETCONN_EVT_RCVPLUS,
okini3939 1:0f82c574096f 108 NETCONN_EVT_RCVMINUS,
okini3939 1:0f82c574096f 109 NETCONN_EVT_SENDPLUS,
okini3939 1:0f82c574096f 110 NETCONN_EVT_SENDMINUS,
okini3939 1:0f82c574096f 111 NETCONN_EVT_ERROR
okini3939 1:0f82c574096f 112 };
okini3939 1:0f82c574096f 113
okini3939 1:0f82c574096f 114 #if LWIP_IGMP
okini3939 1:0f82c574096f 115 /** Used for netconn_join_leave_group() */
okini3939 1:0f82c574096f 116 enum netconn_igmp {
okini3939 1:0f82c574096f 117 NETCONN_JOIN,
okini3939 1:0f82c574096f 118 NETCONN_LEAVE
okini3939 1:0f82c574096f 119 };
okini3939 1:0f82c574096f 120 #endif /* LWIP_IGMP */
okini3939 1:0f82c574096f 121
okini3939 1:0f82c574096f 122 /* forward-declare some structs to avoid to include their headers */
okini3939 1:0f82c574096f 123 struct ip_pcb;
okini3939 1:0f82c574096f 124 struct tcp_pcb;
okini3939 1:0f82c574096f 125 struct udp_pcb;
okini3939 1:0f82c574096f 126 struct raw_pcb;
okini3939 1:0f82c574096f 127 struct netconn;
okini3939 1:0f82c574096f 128 struct api_msg_msg;
okini3939 1:0f82c574096f 129
okini3939 1:0f82c574096f 130 /** A callback prototype to inform about events for a netconn */
okini3939 1:0f82c574096f 131 typedef void (* netconn_callback)(struct netconn *, enum netconn_evt, u16_t len);
okini3939 1:0f82c574096f 132
okini3939 1:0f82c574096f 133 /** A netconn descriptor */
okini3939 1:0f82c574096f 134 struct netconn {
okini3939 1:0f82c574096f 135 /** type of the netconn (TCP, UDP or RAW) */
okini3939 1:0f82c574096f 136 enum netconn_type type;
okini3939 1:0f82c574096f 137 /** current state of the netconn */
okini3939 1:0f82c574096f 138 enum netconn_state state;
okini3939 1:0f82c574096f 139 /** the lwIP internal protocol control block */
okini3939 1:0f82c574096f 140 union {
okini3939 1:0f82c574096f 141 struct ip_pcb *ip;
okini3939 1:0f82c574096f 142 struct tcp_pcb *tcp;
okini3939 1:0f82c574096f 143 struct udp_pcb *udp;
okini3939 1:0f82c574096f 144 struct raw_pcb *raw;
okini3939 1:0f82c574096f 145 } pcb;
okini3939 1:0f82c574096f 146 /** the last error this netconn had */
okini3939 1:0f82c574096f 147 err_t last_err;
okini3939 1:0f82c574096f 148 /** sem that is used to synchroneously execute functions in the core context */
okini3939 1:0f82c574096f 149 sys_sem_t op_completed;
okini3939 1:0f82c574096f 150 /** mbox where received packets are stored until they are fetched
okini3939 1:0f82c574096f 151 by the netconn application thread (can grow quite big) */
okini3939 1:0f82c574096f 152 sys_mbox_t recvmbox;
okini3939 1:0f82c574096f 153 #if LWIP_TCP
okini3939 1:0f82c574096f 154 /** mbox where new connections are stored until processed
okini3939 1:0f82c574096f 155 by the application thread */
okini3939 1:0f82c574096f 156 sys_mbox_t acceptmbox;
okini3939 1:0f82c574096f 157 #endif /* LWIP_TCP */
okini3939 1:0f82c574096f 158 /** only used for socket layer */
okini3939 1:0f82c574096f 159 #if LWIP_SOCKET
okini3939 1:0f82c574096f 160 int socket;
okini3939 1:0f82c574096f 161 #endif /* LWIP_SOCKET */
okini3939 1:0f82c574096f 162 #if LWIP_SO_RCVTIMEO
okini3939 1:0f82c574096f 163 /** timeout to wait for new data to be received
okini3939 1:0f82c574096f 164 (or connections to arrive for listening netconns) */
okini3939 1:0f82c574096f 165 int recv_timeout;
okini3939 1:0f82c574096f 166 #endif /* LWIP_SO_RCVTIMEO */
okini3939 1:0f82c574096f 167 #if LWIP_SO_RCVBUF
okini3939 1:0f82c574096f 168 /** maximum amount of bytes queued in recvmbox
okini3939 1:0f82c574096f 169 not used for TCP: adjust TCP_WND instead! */
okini3939 1:0f82c574096f 170 int recv_bufsize;
okini3939 1:0f82c574096f 171 #endif /* LWIP_SO_RCVBUF */
okini3939 1:0f82c574096f 172 /** number of bytes currently in recvmbox to be received,
okini3939 1:0f82c574096f 173 tested against recv_bufsize to limit bytes on recvmbox
okini3939 1:0f82c574096f 174 for UDP and RAW
okini3939 1:0f82c574096f 175 @todo: should only be necessary with LWIP_SO_RCVBUF==1 */
okini3939 1:0f82c574096f 176 s16_t recv_avail;
okini3939 1:0f82c574096f 177 /** flags holding more netconn-internal state, see NETCONN_FLAG_* defines */
okini3939 1:0f82c574096f 178 u8_t flags;
okini3939 1:0f82c574096f 179 #if LWIP_TCP
okini3939 1:0f82c574096f 180 /** TCP: when data passed to netconn_write doesn't fit into the send buffer,
okini3939 1:0f82c574096f 181 this temporarily stores how much is already sent. */
okini3939 1:0f82c574096f 182 size_t write_offset;
okini3939 1:0f82c574096f 183 /** TCP: when data passed to netconn_write doesn't fit into the send buffer,
okini3939 1:0f82c574096f 184 this temporarily stores the message.
okini3939 1:0f82c574096f 185 Also used during connect and close. */
okini3939 1:0f82c574096f 186 struct api_msg_msg *current_msg;
okini3939 1:0f82c574096f 187 #endif /* LWIP_TCP */
okini3939 1:0f82c574096f 188 /** A callback function that is informed about events for this netconn */
okini3939 1:0f82c574096f 189 netconn_callback callback;
okini3939 1:0f82c574096f 190 };
okini3939 1:0f82c574096f 191
okini3939 1:0f82c574096f 192 /** Register an Network connection event */
okini3939 1:0f82c574096f 193 #define API_EVENT(c,e,l) if (c->callback) { \
okini3939 1:0f82c574096f 194 (*c->callback)(c, e, l); \
okini3939 1:0f82c574096f 195 }
okini3939 1:0f82c574096f 196
okini3939 1:0f82c574096f 197 /** Set conn->last_err to err but don't overwrite fatal errors */
okini3939 1:0f82c574096f 198 #define NETCONN_SET_SAFE_ERR(conn, err) do { \
okini3939 1:0f82c574096f 199 SYS_ARCH_DECL_PROTECT(lev); \
okini3939 1:0f82c574096f 200 SYS_ARCH_PROTECT(lev); \
okini3939 1:0f82c574096f 201 if (!ERR_IS_FATAL((conn)->last_err)) { \
okini3939 1:0f82c574096f 202 (conn)->last_err = err; \
okini3939 1:0f82c574096f 203 } \
okini3939 1:0f82c574096f 204 SYS_ARCH_UNPROTECT(lev); \
okini3939 1:0f82c574096f 205 } while(0);
okini3939 1:0f82c574096f 206
okini3939 1:0f82c574096f 207 /* Network connection functions: */
okini3939 1:0f82c574096f 208 #define netconn_new(t) netconn_new_with_proto_and_callback(t, 0, NULL)
okini3939 1:0f82c574096f 209 #define netconn_new_with_callback(t, c) netconn_new_with_proto_and_callback(t, 0, c)
okini3939 1:0f82c574096f 210 struct
okini3939 1:0f82c574096f 211 netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto,
okini3939 1:0f82c574096f 212 netconn_callback callback);
okini3939 1:0f82c574096f 213 err_t netconn_delete(struct netconn *conn);
okini3939 1:0f82c574096f 214 /** Get the type of a netconn (as enum netconn_type). */
okini3939 1:0f82c574096f 215 #define netconn_type(conn) (conn->type)
okini3939 1:0f82c574096f 216
okini3939 1:0f82c574096f 217 err_t netconn_getaddr(struct netconn *conn, ip_addr_t *addr,
okini3939 1:0f82c574096f 218 u16_t *port, u8_t local);
okini3939 1:0f82c574096f 219 #define netconn_peer(c,i,p) netconn_getaddr(c,i,p,0)
okini3939 1:0f82c574096f 220 #define netconn_addr(c,i,p) netconn_getaddr(c,i,p,1)
okini3939 1:0f82c574096f 221
okini3939 1:0f82c574096f 222 err_t netconn_bind(struct netconn *conn, ip_addr_t *addr, u16_t port);
okini3939 1:0f82c574096f 223 err_t netconn_connect(struct netconn *conn, ip_addr_t *addr, u16_t port);
okini3939 1:0f82c574096f 224 err_t netconn_disconnect (struct netconn *conn);
okini3939 1:0f82c574096f 225 err_t netconn_listen_with_backlog(struct netconn *conn, u8_t backlog);
okini3939 1:0f82c574096f 226 #define netconn_listen(conn) netconn_listen_with_backlog(conn, TCP_DEFAULT_LISTEN_BACKLOG)
okini3939 1:0f82c574096f 227 err_t netconn_accept(struct netconn *conn, struct netconn **new_conn);
okini3939 1:0f82c574096f 228 err_t netconn_recv(struct netconn *conn, struct netbuf **new_buf);
okini3939 1:0f82c574096f 229 err_t netconn_recv_tcp_pbuf(struct netconn *conn, struct pbuf **new_buf);
okini3939 1:0f82c574096f 230 void netconn_recved(struct netconn *conn, u32_t length);
okini3939 1:0f82c574096f 231 err_t netconn_sendto(struct netconn *conn, struct netbuf *buf,
okini3939 1:0f82c574096f 232 ip_addr_t *addr, u16_t port);
okini3939 1:0f82c574096f 233 err_t netconn_send(struct netconn *conn, struct netbuf *buf);
okini3939 1:0f82c574096f 234 err_t netconn_write(struct netconn *conn, const void *dataptr, size_t size,
okini3939 1:0f82c574096f 235 u8_t apiflags);
okini3939 1:0f82c574096f 236 err_t netconn_close(struct netconn *conn);
okini3939 1:0f82c574096f 237 err_t netconn_shutdown(struct netconn *conn, u8_t shut_rx, u8_t shut_tx);
okini3939 1:0f82c574096f 238
okini3939 1:0f82c574096f 239 #if LWIP_IGMP
okini3939 1:0f82c574096f 240 err_t netconn_join_leave_group(struct netconn *conn, ip_addr_t *multiaddr,
okini3939 1:0f82c574096f 241 ip_addr_t *netif_addr, enum netconn_igmp join_or_leave);
okini3939 1:0f82c574096f 242 #endif /* LWIP_IGMP */
okini3939 1:0f82c574096f 243 #if LWIP_DNS
okini3939 1:0f82c574096f 244 err_t netconn_gethostbyname(const char *name, ip_addr_t *addr);
okini3939 1:0f82c574096f 245 #endif /* LWIP_DNS */
okini3939 1:0f82c574096f 246
okini3939 1:0f82c574096f 247 #define netconn_err(conn) ((conn)->last_err)
okini3939 1:0f82c574096f 248 #define netconn_recv_bufsize(conn) ((conn)->recv_bufsize)
okini3939 1:0f82c574096f 249
okini3939 1:0f82c574096f 250 /** Set the blocking status of netconn calls (@todo: write/send is missing) */
okini3939 1:0f82c574096f 251 #define netconn_set_nonblocking(conn, val) do { if(val) { \
okini3939 1:0f82c574096f 252 (conn)->flags |= NETCONN_FLAG_NON_BLOCKING; \
okini3939 1:0f82c574096f 253 } else { \
okini3939 1:0f82c574096f 254 (conn)->flags &= ~ NETCONN_FLAG_NON_BLOCKING; }} while(0)
okini3939 1:0f82c574096f 255 /** Get the blocking status of netconn calls (@todo: write/send is missing) */
okini3939 1:0f82c574096f 256 #define netconn_is_nonblocking(conn) (((conn)->flags & NETCONN_FLAG_NON_BLOCKING) != 0)
okini3939 1:0f82c574096f 257
okini3939 1:0f82c574096f 258 /** TCP: Set the no-auto-recved status of netconn calls (see NETCONN_FLAG_NO_AUTO_RECVED) */
okini3939 1:0f82c574096f 259 #define netconn_set_noautorecved(conn, val) do { if(val) { \
okini3939 1:0f82c574096f 260 (conn)->flags |= NETCONN_FLAG_NO_AUTO_RECVED; \
okini3939 1:0f82c574096f 261 } else { \
okini3939 1:0f82c574096f 262 (conn)->flags &= ~ NETCONN_FLAG_NO_AUTO_RECVED; }} while(0)
okini3939 1:0f82c574096f 263 /** TCP: Get the no-auto-recved status of netconn calls (see NETCONN_FLAG_NO_AUTO_RECVED) */
okini3939 1:0f82c574096f 264 #define netconn_get_noautorecved(conn) (((conn)->flags & NETCONN_FLAG_NO_AUTO_RECVED) != 0)
okini3939 1:0f82c574096f 265
okini3939 1:0f82c574096f 266 #if LWIP_SO_RCVTIMEO
okini3939 1:0f82c574096f 267 /** Set the receive timeout in milliseconds */
okini3939 1:0f82c574096f 268 #define netconn_set_recvtimeout(conn, timeout) ((conn)->recv_timeout = (timeout))
okini3939 1:0f82c574096f 269 /** Get the receive timeout in milliseconds */
okini3939 1:0f82c574096f 270 #define netconn_get_recvtimeout(conn) ((conn)->recv_timeout)
okini3939 1:0f82c574096f 271 #endif /* LWIP_SO_RCVTIMEO */
okini3939 1:0f82c574096f 272 #if LWIP_SO_RCVBUF
okini3939 1:0f82c574096f 273 /** Set the receive buffer in bytes */
okini3939 1:0f82c574096f 274 #define netconn_set_recvbufsize(conn, recvbufsize) ((conn)->recv_bufsize = (recvbufsize))
okini3939 1:0f82c574096f 275 /** Get the receive buffer in bytes */
okini3939 1:0f82c574096f 276 #define netconn_get_recvbufsize(conn) ((conn)->recv_bufsize)
okini3939 1:0f82c574096f 277 #endif /* LWIP_SO_RCVBUF*/
okini3939 1:0f82c574096f 278
okini3939 1:0f82c574096f 279 #ifdef __cplusplus
okini3939 1:0f82c574096f 280 }
okini3939 1:0f82c574096f 281 #endif
okini3939 1:0f82c574096f 282
okini3939 1:0f82c574096f 283 #endif /* LWIP_NETCONN */
okini3939 1:0f82c574096f 284
okini3939 1:0f82c574096f 285 #endif /* __LWIP_API_H__ */