Dependencies:   mbed

Dependents:   TCP

Committer:
slowness
Date:
Tue Sep 06 18:05:46 2011 +0000
Revision:
0:58c3d014a4e7

        

Who changed what in which revision?

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