LwIP with PPP & Ethernet integration

Dependents:   NetworkingCoreLib

This is the mbed port of the LwIP stack: http://savannah.nongnu.org/projects/lwip/

It includes contributed content from NXP's port for LPCxxxx devices: http://www.lpcware.com/content/project/lightweight-ip-lwip-networking-stack

Licence

LwIP is licenced under the BSD licence:

Copyright (c) 2001-2004 Swedish Institute of Computer Science. 
All rights reserved. 
Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met: 
1. Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimer. 
2. Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation 
and/or other materials provided with the distribution. 
3. The name of the author may not be used to endorse or promote products 
derived from this software without specific prior written permission. 
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
OF SUCH DAMAGE.
Committer:
donatien
Date:
Thu May 24 15:53:48 2012 +0000
Revision:
0:8e01dca41002
Merge with Emilio's LwIp

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:8e01dca41002 1 /*
donatien 0:8e01dca41002 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
donatien 0:8e01dca41002 3 * All rights reserved.
donatien 0:8e01dca41002 4 *
donatien 0:8e01dca41002 5 * Redistribution and use in source and binary forms, with or without modification,
donatien 0:8e01dca41002 6 * are permitted provided that the following conditions are met:
donatien 0:8e01dca41002 7 *
donatien 0:8e01dca41002 8 * 1. Redistributions of source code must retain the above copyright notice,
donatien 0:8e01dca41002 9 * this list of conditions and the following disclaimer.
donatien 0:8e01dca41002 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
donatien 0:8e01dca41002 11 * this list of conditions and the following disclaimer in the documentation
donatien 0:8e01dca41002 12 * and/or other materials provided with the distribution.
donatien 0:8e01dca41002 13 * 3. The name of the author may not be used to endorse or promote products
donatien 0:8e01dca41002 14 * derived from this software without specific prior written permission.
donatien 0:8e01dca41002 15 *
donatien 0:8e01dca41002 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
donatien 0:8e01dca41002 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
donatien 0:8e01dca41002 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
donatien 0:8e01dca41002 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
donatien 0:8e01dca41002 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
donatien 0:8e01dca41002 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
donatien 0:8e01dca41002 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
donatien 0:8e01dca41002 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
donatien 0:8e01dca41002 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
donatien 0:8e01dca41002 25 * OF SUCH DAMAGE.
donatien 0:8e01dca41002 26 *
donatien 0:8e01dca41002 27 * This file is part of the lwIP TCP/IP stack.
donatien 0:8e01dca41002 28 *
donatien 0:8e01dca41002 29 * Author: Adam Dunkels <adam@sics.se>
donatien 0:8e01dca41002 30 *
donatien 0:8e01dca41002 31 */
donatien 0:8e01dca41002 32 #ifndef __LWIP_API_MSG_H__
donatien 0:8e01dca41002 33 #define __LWIP_API_MSG_H__
donatien 0:8e01dca41002 34
donatien 0:8e01dca41002 35 #include "lwip/opt.h"
donatien 0:8e01dca41002 36
donatien 0:8e01dca41002 37 #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
donatien 0:8e01dca41002 38
donatien 0:8e01dca41002 39 #include <stddef.h> /* for size_t */
donatien 0:8e01dca41002 40
donatien 0:8e01dca41002 41 #include "lwip/ip_addr.h"
donatien 0:8e01dca41002 42 #include "lwip/err.h"
donatien 0:8e01dca41002 43 #include "lwip/sys.h"
donatien 0:8e01dca41002 44 #include "lwip/igmp.h"
donatien 0:8e01dca41002 45 #include "lwip/api.h"
donatien 0:8e01dca41002 46
donatien 0:8e01dca41002 47 #ifdef __cplusplus
donatien 0:8e01dca41002 48 extern "C" {
donatien 0:8e01dca41002 49 #endif
donatien 0:8e01dca41002 50
donatien 0:8e01dca41002 51 /* For the netconn API, these values are use as a bitmask! */
donatien 0:8e01dca41002 52 #define NETCONN_SHUT_RD 1
donatien 0:8e01dca41002 53 #define NETCONN_SHUT_WR 2
donatien 0:8e01dca41002 54 #define NETCONN_SHUT_RDWR (NETCONN_SHUT_RD | NETCONN_SHUT_WR)
donatien 0:8e01dca41002 55
donatien 0:8e01dca41002 56 /* IP addresses and port numbers are expected to be in
donatien 0:8e01dca41002 57 * the same byte order as in the corresponding pcb.
donatien 0:8e01dca41002 58 */
donatien 0:8e01dca41002 59 /** This struct includes everything that is necessary to execute a function
donatien 0:8e01dca41002 60 for a netconn in another thread context (mainly used to process netconns
donatien 0:8e01dca41002 61 in the tcpip_thread context to be thread safe). */
donatien 0:8e01dca41002 62 struct api_msg_msg {
donatien 0:8e01dca41002 63 /** The netconn which to process - always needed: it includes the semaphore
donatien 0:8e01dca41002 64 which is used to block the application thread until the function finished. */
donatien 0:8e01dca41002 65 struct netconn *conn;
donatien 0:8e01dca41002 66 /** The return value of the function executed in tcpip_thread. */
donatien 0:8e01dca41002 67 err_t err;
donatien 0:8e01dca41002 68 /** Depending on the executed function, one of these union members is used */
donatien 0:8e01dca41002 69 union {
donatien 0:8e01dca41002 70 /** used for do_send */
donatien 0:8e01dca41002 71 struct netbuf *b;
donatien 0:8e01dca41002 72 /** used for do_newconn */
donatien 0:8e01dca41002 73 struct {
donatien 0:8e01dca41002 74 u8_t proto;
donatien 0:8e01dca41002 75 } n;
donatien 0:8e01dca41002 76 /** used for do_bind and do_connect */
donatien 0:8e01dca41002 77 struct {
donatien 0:8e01dca41002 78 ip_addr_t *ipaddr;
donatien 0:8e01dca41002 79 u16_t port;
donatien 0:8e01dca41002 80 } bc;
donatien 0:8e01dca41002 81 /** used for do_getaddr */
donatien 0:8e01dca41002 82 struct {
donatien 0:8e01dca41002 83 ip_addr_t *ipaddr;
donatien 0:8e01dca41002 84 u16_t *port;
donatien 0:8e01dca41002 85 u8_t local;
donatien 0:8e01dca41002 86 } ad;
donatien 0:8e01dca41002 87 /** used for do_write */
donatien 0:8e01dca41002 88 struct {
donatien 0:8e01dca41002 89 const void *dataptr;
donatien 0:8e01dca41002 90 size_t len;
donatien 0:8e01dca41002 91 u8_t apiflags;
donatien 0:8e01dca41002 92 } w;
donatien 0:8e01dca41002 93 /** used for do_recv */
donatien 0:8e01dca41002 94 struct {
donatien 0:8e01dca41002 95 u32_t len;
donatien 0:8e01dca41002 96 } r;
donatien 0:8e01dca41002 97 /** used for do_close (/shutdown) */
donatien 0:8e01dca41002 98 struct {
donatien 0:8e01dca41002 99 u8_t shut;
donatien 0:8e01dca41002 100 } sd;
donatien 0:8e01dca41002 101 #if LWIP_IGMP
donatien 0:8e01dca41002 102 /** used for do_join_leave_group */
donatien 0:8e01dca41002 103 struct {
donatien 0:8e01dca41002 104 ip_addr_t *multiaddr;
donatien 0:8e01dca41002 105 ip_addr_t *netif_addr;
donatien 0:8e01dca41002 106 enum netconn_igmp join_or_leave;
donatien 0:8e01dca41002 107 } jl;
donatien 0:8e01dca41002 108 #endif /* LWIP_IGMP */
donatien 0:8e01dca41002 109 #if TCP_LISTEN_BACKLOG
donatien 0:8e01dca41002 110 struct {
donatien 0:8e01dca41002 111 u8_t backlog;
donatien 0:8e01dca41002 112 } lb;
donatien 0:8e01dca41002 113 #endif /* TCP_LISTEN_BACKLOG */
donatien 0:8e01dca41002 114 } msg;
donatien 0:8e01dca41002 115 };
donatien 0:8e01dca41002 116
donatien 0:8e01dca41002 117 /** This struct contains a function to execute in another thread context and
donatien 0:8e01dca41002 118 a struct api_msg_msg that serves as an argument for this function.
donatien 0:8e01dca41002 119 This is passed to tcpip_apimsg to execute functions in tcpip_thread context. */
donatien 0:8e01dca41002 120 struct api_msg {
donatien 0:8e01dca41002 121 /** function to execute in tcpip_thread context */
donatien 0:8e01dca41002 122 void (* function)(struct api_msg_msg *msg);
donatien 0:8e01dca41002 123 /** arguments for this function */
donatien 0:8e01dca41002 124 struct api_msg_msg msg;
donatien 0:8e01dca41002 125 };
donatien 0:8e01dca41002 126
donatien 0:8e01dca41002 127 #if LWIP_DNS
donatien 0:8e01dca41002 128 /** As do_gethostbyname requires more arguments but doesn't require a netconn,
donatien 0:8e01dca41002 129 it has its own struct (to avoid struct api_msg getting bigger than necessary).
donatien 0:8e01dca41002 130 do_gethostbyname must be called using tcpip_callback instead of tcpip_apimsg
donatien 0:8e01dca41002 131 (see netconn_gethostbyname). */
donatien 0:8e01dca41002 132 struct dns_api_msg {
donatien 0:8e01dca41002 133 /** Hostname to query or dotted IP address string */
donatien 0:8e01dca41002 134 const char *name;
donatien 0:8e01dca41002 135 /** Rhe resolved address is stored here */
donatien 0:8e01dca41002 136 ip_addr_t *addr;
donatien 0:8e01dca41002 137 /** This semaphore is posted when the name is resolved, the application thread
donatien 0:8e01dca41002 138 should wait on it. */
donatien 0:8e01dca41002 139 sys_sem_t *sem;
donatien 0:8e01dca41002 140 /** Errors are given back here */
donatien 0:8e01dca41002 141 err_t *err;
donatien 0:8e01dca41002 142 };
donatien 0:8e01dca41002 143 #endif /* LWIP_DNS */
donatien 0:8e01dca41002 144
donatien 0:8e01dca41002 145 void do_newconn ( struct api_msg_msg *msg);
donatien 0:8e01dca41002 146 void do_delconn ( struct api_msg_msg *msg);
donatien 0:8e01dca41002 147 void do_bind ( struct api_msg_msg *msg);
donatien 0:8e01dca41002 148 void do_connect ( struct api_msg_msg *msg);
donatien 0:8e01dca41002 149 void do_disconnect ( struct api_msg_msg *msg);
donatien 0:8e01dca41002 150 void do_listen ( struct api_msg_msg *msg);
donatien 0:8e01dca41002 151 void do_send ( struct api_msg_msg *msg);
donatien 0:8e01dca41002 152 void do_recv ( struct api_msg_msg *msg);
donatien 0:8e01dca41002 153 void do_write ( struct api_msg_msg *msg);
donatien 0:8e01dca41002 154 void do_getaddr ( struct api_msg_msg *msg);
donatien 0:8e01dca41002 155 void do_close ( struct api_msg_msg *msg);
donatien 0:8e01dca41002 156 void do_shutdown ( struct api_msg_msg *msg);
donatien 0:8e01dca41002 157 #if LWIP_IGMP
donatien 0:8e01dca41002 158 void do_join_leave_group( struct api_msg_msg *msg);
donatien 0:8e01dca41002 159 #endif /* LWIP_IGMP */
donatien 0:8e01dca41002 160
donatien 0:8e01dca41002 161 #if LWIP_DNS
donatien 0:8e01dca41002 162 void do_gethostbyname(void *arg);
donatien 0:8e01dca41002 163 #endif /* LWIP_DNS */
donatien 0:8e01dca41002 164
donatien 0:8e01dca41002 165 struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback);
donatien 0:8e01dca41002 166 void netconn_free(struct netconn *conn);
donatien 0:8e01dca41002 167
donatien 0:8e01dca41002 168 #ifdef __cplusplus
donatien 0:8e01dca41002 169 }
donatien 0:8e01dca41002 170 #endif
donatien 0:8e01dca41002 171
donatien 0:8e01dca41002 172 #endif /* LWIP_NETCONN */
donatien 0:8e01dca41002 173
donatien 0:8e01dca41002 174 #endif /* __LWIP_API_MSG_H__ */