Stripped down version of Segundos NetService library (http://mbed.org/users/segundo/libraries/NetServices ). I have removed all NetServices, and all functions which had been disabled. Use this version when you need only pure TCP or UDP functions - this library compiles faster.

Dependencies:   lwip lwip-sys

Dependents:   christmasLights device_server pop3demo device_server_udp ... more

Committer:
hlipka
Date:
Mon Jan 10 21:03:11 2011 +0000
Revision:
0:8b387bed54c2
initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 0:8b387bed54c2 1 /*
hlipka 0:8b387bed54c2 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
hlipka 0:8b387bed54c2 3 * All rights reserved.
hlipka 0:8b387bed54c2 4 *
hlipka 0:8b387bed54c2 5 * Redistribution and use in source and binary forms, with or without modification,
hlipka 0:8b387bed54c2 6 * are permitted provided that the following conditions are met:
hlipka 0:8b387bed54c2 7 *
hlipka 0:8b387bed54c2 8 * 1. Redistributions of source code must retain the above copyright notice,
hlipka 0:8b387bed54c2 9 * this list of conditions and the following disclaimer.
hlipka 0:8b387bed54c2 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
hlipka 0:8b387bed54c2 11 * this list of conditions and the following disclaimer in the documentation
hlipka 0:8b387bed54c2 12 * and/or other materials provided with the distribution.
hlipka 0:8b387bed54c2 13 * 3. The name of the author may not be used to endorse or promote products
hlipka 0:8b387bed54c2 14 * derived from this software without specific prior written permission.
hlipka 0:8b387bed54c2 15 *
hlipka 0:8b387bed54c2 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
hlipka 0:8b387bed54c2 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
hlipka 0:8b387bed54c2 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
hlipka 0:8b387bed54c2 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
hlipka 0:8b387bed54c2 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
hlipka 0:8b387bed54c2 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
hlipka 0:8b387bed54c2 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
hlipka 0:8b387bed54c2 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
hlipka 0:8b387bed54c2 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
hlipka 0:8b387bed54c2 25 * OF SUCH DAMAGE.
hlipka 0:8b387bed54c2 26 *
hlipka 0:8b387bed54c2 27 * This file is part of the lwIP TCP/IP stack.
hlipka 0:8b387bed54c2 28 *
hlipka 0:8b387bed54c2 29 * Author: Adam Dunkels <adam@sics.se>
hlipka 0:8b387bed54c2 30 *
hlipka 0:8b387bed54c2 31 */
hlipka 0:8b387bed54c2 32 #ifndef __LWIP_TCPIP_H__
hlipka 0:8b387bed54c2 33 #define __LWIP_TCPIP_H__
hlipka 0:8b387bed54c2 34
hlipka 0:8b387bed54c2 35 #include "lwip/opt.h"
hlipka 0:8b387bed54c2 36
hlipka 0:8b387bed54c2 37 #if !NO_SYS /* don't build if not configured for use in lwipopts.h */
hlipka 0:8b387bed54c2 38
hlipka 0:8b387bed54c2 39 #include "lwip/api_msg.h"
hlipka 0:8b387bed54c2 40 #include "lwip/netifapi.h"
hlipka 0:8b387bed54c2 41 #include "lwip/pbuf.h"
hlipka 0:8b387bed54c2 42 #include "lwip/api.h"
hlipka 0:8b387bed54c2 43 #include "lwip/sys.h"
hlipka 0:8b387bed54c2 44 #include "lwip/timers.h"
hlipka 0:8b387bed54c2 45 #include "lwip/netif.h"
hlipka 0:8b387bed54c2 46
hlipka 0:8b387bed54c2 47 #ifdef __cplusplus
hlipka 0:8b387bed54c2 48 extern "C" {
hlipka 0:8b387bed54c2 49 #endif
hlipka 0:8b387bed54c2 50
hlipka 0:8b387bed54c2 51 /** Define this to something that triggers a watchdog. This is called from
hlipka 0:8b387bed54c2 52 * tcpip_thread after processing a message. */
hlipka 0:8b387bed54c2 53 #ifndef LWIP_TCPIP_THREAD_ALIVE
hlipka 0:8b387bed54c2 54 #define LWIP_TCPIP_THREAD_ALIVE()
hlipka 0:8b387bed54c2 55 #endif
hlipka 0:8b387bed54c2 56
hlipka 0:8b387bed54c2 57 #if LWIP_TCPIP_CORE_LOCKING
hlipka 0:8b387bed54c2 58 /** The global semaphore to lock the stack. */
hlipka 0:8b387bed54c2 59 extern sys_mutex_t lock_tcpip_core;
hlipka 0:8b387bed54c2 60 #define LOCK_TCPIP_CORE() sys_mutex_lock(&lock_tcpip_core)
hlipka 0:8b387bed54c2 61 #define UNLOCK_TCPIP_CORE() sys_mutex_unlock(&lock_tcpip_core)
hlipka 0:8b387bed54c2 62 #define TCPIP_APIMSG(m) tcpip_apimsg_lock(m)
hlipka 0:8b387bed54c2 63 #define TCPIP_APIMSG_ACK(m)
hlipka 0:8b387bed54c2 64 #define TCPIP_NETIFAPI(m) tcpip_netifapi_lock(m)
hlipka 0:8b387bed54c2 65 #define TCPIP_NETIFAPI_ACK(m)
hlipka 0:8b387bed54c2 66 #else /* LWIP_TCPIP_CORE_LOCKING */
hlipka 0:8b387bed54c2 67 #define LOCK_TCPIP_CORE()
hlipka 0:8b387bed54c2 68 #define UNLOCK_TCPIP_CORE()
hlipka 0:8b387bed54c2 69 #define TCPIP_APIMSG(m) tcpip_apimsg(m)
hlipka 0:8b387bed54c2 70 #define TCPIP_APIMSG_ACK(m) sys_sem_signal(&m->conn->op_completed)
hlipka 0:8b387bed54c2 71 #define TCPIP_NETIFAPI(m) tcpip_netifapi(m)
hlipka 0:8b387bed54c2 72 #define TCPIP_NETIFAPI_ACK(m) sys_sem_signal(&m->sem)
hlipka 0:8b387bed54c2 73 #endif /* LWIP_TCPIP_CORE_LOCKING */
hlipka 0:8b387bed54c2 74
hlipka 0:8b387bed54c2 75 /** Function prototype for the init_done function passed to tcpip_init */
hlipka 0:8b387bed54c2 76 typedef void (*tcpip_init_done_fn)(void *arg);
hlipka 0:8b387bed54c2 77 /** Function prototype for functions passed to tcpip_callback() */
hlipka 0:8b387bed54c2 78 typedef void (*tcpip_callback_fn)(void *ctx);
hlipka 0:8b387bed54c2 79
hlipka 0:8b387bed54c2 80 void tcpip_init(tcpip_init_done_fn tcpip_init_done, void *arg);
hlipka 0:8b387bed54c2 81
hlipka 0:8b387bed54c2 82 #if LWIP_NETCONN
hlipka 0:8b387bed54c2 83 err_t tcpip_apimsg(struct api_msg *apimsg);
hlipka 0:8b387bed54c2 84 #if LWIP_TCPIP_CORE_LOCKING
hlipka 0:8b387bed54c2 85 err_t tcpip_apimsg_lock(struct api_msg *apimsg);
hlipka 0:8b387bed54c2 86 #endif /* LWIP_TCPIP_CORE_LOCKING */
hlipka 0:8b387bed54c2 87 #endif /* LWIP_NETCONN */
hlipka 0:8b387bed54c2 88
hlipka 0:8b387bed54c2 89 err_t tcpip_input(struct pbuf *p, struct netif *inp);
hlipka 0:8b387bed54c2 90
hlipka 0:8b387bed54c2 91 #if LWIP_NETIF_API
hlipka 0:8b387bed54c2 92 err_t tcpip_netifapi(struct netifapi_msg *netifapimsg);
hlipka 0:8b387bed54c2 93 #if LWIP_TCPIP_CORE_LOCKING
hlipka 0:8b387bed54c2 94 err_t tcpip_netifapi_lock(struct netifapi_msg *netifapimsg);
hlipka 0:8b387bed54c2 95 #endif /* LWIP_TCPIP_CORE_LOCKING */
hlipka 0:8b387bed54c2 96 #endif /* LWIP_NETIF_API */
hlipka 0:8b387bed54c2 97
hlipka 0:8b387bed54c2 98 err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block);
hlipka 0:8b387bed54c2 99 #define tcpip_callback(f, ctx) tcpip_callback_with_block(f, ctx, 1)
hlipka 0:8b387bed54c2 100
hlipka 0:8b387bed54c2 101 /* free pbufs or heap memory from another context without blocking */
hlipka 0:8b387bed54c2 102 err_t pbuf_free_callback(struct pbuf *p);
hlipka 0:8b387bed54c2 103 err_t mem_free_callback(void *m);
hlipka 0:8b387bed54c2 104
hlipka 0:8b387bed54c2 105 #if LWIP_TCPIP_TIMEOUT
hlipka 0:8b387bed54c2 106 err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg);
hlipka 0:8b387bed54c2 107 err_t tcpip_untimeout(sys_timeout_handler h, void *arg);
hlipka 0:8b387bed54c2 108 #endif /* LWIP_TCPIP_TIMEOUT */
hlipka 0:8b387bed54c2 109
hlipka 0:8b387bed54c2 110 enum tcpip_msg_type {
hlipka 0:8b387bed54c2 111 #if LWIP_NETCONN
hlipka 0:8b387bed54c2 112 TCPIP_MSG_API,
hlipka 0:8b387bed54c2 113 #endif /* LWIP_NETCONN */
hlipka 0:8b387bed54c2 114 TCPIP_MSG_INPKT,
hlipka 0:8b387bed54c2 115 #if LWIP_NETIF_API
hlipka 0:8b387bed54c2 116 TCPIP_MSG_NETIFAPI,
hlipka 0:8b387bed54c2 117 #endif /* LWIP_NETIF_API */
hlipka 0:8b387bed54c2 118 #if LWIP_TCPIP_TIMEOUT
hlipka 0:8b387bed54c2 119 TCPIP_MSG_TIMEOUT,
hlipka 0:8b387bed54c2 120 TCPIP_MSG_UNTIMEOUT,
hlipka 0:8b387bed54c2 121 #endif /* LWIP_TCPIP_TIMEOUT */
hlipka 0:8b387bed54c2 122 TCPIP_MSG_CALLBACK
hlipka 0:8b387bed54c2 123 };
hlipka 0:8b387bed54c2 124
hlipka 0:8b387bed54c2 125 struct tcpip_msg {
hlipka 0:8b387bed54c2 126 enum tcpip_msg_type type;
hlipka 0:8b387bed54c2 127 sys_sem_t *sem;
hlipka 0:8b387bed54c2 128 union {
hlipka 0:8b387bed54c2 129 #if LWIP_NETCONN
hlipka 0:8b387bed54c2 130 struct api_msg *apimsg;
hlipka 0:8b387bed54c2 131 #endif /* LWIP_NETCONN */
hlipka 0:8b387bed54c2 132 #if LWIP_NETIF_API
hlipka 0:8b387bed54c2 133 struct netifapi_msg *netifapimsg;
hlipka 0:8b387bed54c2 134 #endif /* LWIP_NETIF_API */
hlipka 0:8b387bed54c2 135 struct {
hlipka 0:8b387bed54c2 136 struct pbuf *p;
hlipka 0:8b387bed54c2 137 struct netif *netif;
hlipka 0:8b387bed54c2 138 } inp;
hlipka 0:8b387bed54c2 139 struct {
hlipka 0:8b387bed54c2 140 tcpip_callback_fn function;
hlipka 0:8b387bed54c2 141 void *ctx;
hlipka 0:8b387bed54c2 142 } cb;
hlipka 0:8b387bed54c2 143 #if LWIP_TCPIP_TIMEOUT
hlipka 0:8b387bed54c2 144 struct {
hlipka 0:8b387bed54c2 145 u32_t msecs;
hlipka 0:8b387bed54c2 146 sys_timeout_handler h;
hlipka 0:8b387bed54c2 147 void *arg;
hlipka 0:8b387bed54c2 148 } tmo;
hlipka 0:8b387bed54c2 149 #endif /* LWIP_TCPIP_TIMEOUT */
hlipka 0:8b387bed54c2 150 } msg;
hlipka 0:8b387bed54c2 151 };
hlipka 0:8b387bed54c2 152
hlipka 0:8b387bed54c2 153 #ifdef __cplusplus
hlipka 0:8b387bed54c2 154 }
hlipka 0:8b387bed54c2 155 #endif
hlipka 0:8b387bed54c2 156
hlipka 0:8b387bed54c2 157 #endif /* !NO_SYS */
hlipka 0:8b387bed54c2 158
hlipka 0:8b387bed54c2 159 #endif /* __LWIP_TCPIP_H__ */