Dependents:   SNMPAgent HTTPServer think_speak_a cyassl-client ... more

Committer:
mamezu
Date:
Thu Dec 09 01:33:56 2010 +0000
Revision:
0:0f6c82fcde82

        

Who changed what in which revision?

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