Dependents:   TimeZoneDemo EthernetJackTestCode MMEx_Challenge ntp_mem ... more

Committer:
segundo
Date:
Tue Nov 09 20:54:15 2010 +0000
Revision:
0:ac1725ba162c

        

Who changed what in which revision?

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