Port of LwIP performed by Ralf in 2010. Not recommended for use with recent mbed libraries, but good demos of raw LwIP possible

Dependents:   LwIP_raw_API_serverExample tiny-dtls

Committer:
RodColeman
Date:
Tue Sep 18 14:41:24 2012 +0000
Revision:
0:0791c1fece8e
[mbed] converted /Eth_TCP_Wei_Server/lwip

Who changed what in which revision?

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