Version of http://mbed.org/cookbook/NetServicesTribute with setting set the same for LPC2368

Dependents:   UDPSocketExample 24LCxx_I2CApp WeatherPlatform_pachube HvZServerLib ... more

Committer:
simon
Date:
Tue Nov 23 14:15:36 2010 +0000
Revision:
0:350011bf8be7
Experimental version for testing UDP

Who changed what in which revision?

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