Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
api_msg.h
00001 /** 00002 * @file 00003 * netconn API lwIP internal implementations (do not use in application code) 00004 */ 00005 00006 /* 00007 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without modification, 00011 * are permitted provided that the following conditions are met: 00012 * 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. The name of the author may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00024 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00026 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00029 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00030 * OF SUCH DAMAGE. 00031 * 00032 * This file is part of the lwIP TCP/IP stack. 00033 * 00034 * Author: Adam Dunkels <adam@sics.se> 00035 * 00036 */ 00037 #ifndef LWIP_HDR_API_MSG_H 00038 #define LWIP_HDR_API_MSG_H 00039 00040 #include "lwip/opt.h" 00041 00042 #if LWIP_NETCONN || LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ 00043 /* Note: Netconn API is always available when sockets are enabled - 00044 * sockets are implemented on top of them */ 00045 00046 #include <stddef.h> /* for size_t */ 00047 00048 #include "lwip/ip_addr.h" 00049 #include "lwip/err.h" 00050 #include "lwip/sys.h" 00051 #include "lwip/igmp.h" 00052 #include "lwip/api.h" 00053 #include "lwip/priv/tcpip_priv.h" 00054 00055 #ifdef __cplusplus 00056 extern "C" { 00057 #endif 00058 00059 #if LWIP_MPU_COMPATIBLE 00060 #if LWIP_NETCONN_SEM_PER_THREAD 00061 #define API_MSG_M_DEF_SEM(m) *m 00062 #else 00063 #define API_MSG_M_DEF_SEM(m) API_MSG_M_DEF(m) 00064 #endif 00065 #else /* LWIP_MPU_COMPATIBLE */ 00066 #define API_MSG_M_DEF_SEM(m) API_MSG_M_DEF(m) 00067 #endif /* LWIP_MPU_COMPATIBLE */ 00068 00069 /* For the netconn API, these values are use as a bitmask! */ 00070 #define NETCONN_SHUT_RD 1 00071 #define NETCONN_SHUT_WR 2 00072 #define NETCONN_SHUT_RDWR (NETCONN_SHUT_RD | NETCONN_SHUT_WR) 00073 00074 /* IP addresses and port numbers are expected to be in 00075 * the same byte order as in the corresponding pcb. 00076 */ 00077 /** This struct includes everything that is necessary to execute a function 00078 for a netconn in another thread context (mainly used to process netconns 00079 in the tcpip_thread context to be thread safe). */ 00080 struct api_msg { 00081 /** The netconn which to process - always needed: it includes the semaphore 00082 which is used to block the application thread until the function finished. */ 00083 struct netconn *conn; 00084 /** The return value of the function executed in tcpip_thread. */ 00085 err_t err; 00086 /** Depending on the executed function, one of these union members is used */ 00087 union { 00088 /** used for lwip_netconn_do_send */ 00089 struct netbuf *b; 00090 /** used for lwip_netconn_do_newconn */ 00091 struct { 00092 u8_t proto; 00093 } n; 00094 /** used for lwip_netconn_do_bind and lwip_netconn_do_connect */ 00095 struct { 00096 API_MSG_M_DEF_C(ip_addr_t, ipaddr); 00097 u16_t port; 00098 } bc; 00099 /** used for lwip_netconn_do_getaddr */ 00100 struct { 00101 ip_addr_t API_MSG_M_DEF(ipaddr); 00102 u16_t API_MSG_M_DEF(port); 00103 u8_t local; 00104 } ad; 00105 /** used for lwip_netconn_do_write */ 00106 struct { 00107 const void *dataptr; 00108 size_t len; 00109 u8_t apiflags; 00110 #if LWIP_SO_SNDTIMEO 00111 u32_t time_started; 00112 #endif /* LWIP_SO_SNDTIMEO */ 00113 } w; 00114 /** used for lwip_netconn_do_recv */ 00115 struct { 00116 u32_t len; 00117 } r; 00118 #if LWIP_TCP 00119 /** used for lwip_netconn_do_close (/shutdown) */ 00120 struct { 00121 u8_t shut; 00122 #if LWIP_SO_SNDTIMEO || LWIP_SO_LINGER 00123 u32_t time_started; 00124 #else /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */ 00125 u8_t polls_left; 00126 #endif /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */ 00127 } sd; 00128 #endif /* LWIP_TCP */ 00129 #if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) 00130 /** used for lwip_netconn_do_join_leave_group */ 00131 struct { 00132 API_MSG_M_DEF_C(ip_addr_t, multiaddr); 00133 API_MSG_M_DEF_C(ip_addr_t, netif_addr); 00134 enum netconn_igmp join_or_leave; 00135 } jl; 00136 #endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */ 00137 #if TCP_LISTEN_BACKLOG 00138 struct { 00139 u8_t backlog; 00140 } lb; 00141 #endif /* TCP_LISTEN_BACKLOG */ 00142 } msg; 00143 #if LWIP_NETCONN_SEM_PER_THREAD 00144 sys_sem_t* op_completed_sem; 00145 #endif /* LWIP_NETCONN_SEM_PER_THREAD */ 00146 }; 00147 00148 #if LWIP_NETCONN_SEM_PER_THREAD 00149 #define LWIP_API_MSG_SEM(msg) ((msg)->op_completed_sem) 00150 #else /* LWIP_NETCONN_SEM_PER_THREAD */ 00151 #define LWIP_API_MSG_SEM(msg) (&(msg)->conn->op_completed) 00152 #endif /* LWIP_NETCONN_SEM_PER_THREAD */ 00153 00154 00155 #if LWIP_DNS 00156 /** As lwip_netconn_do_gethostbyname requires more arguments but doesn't require a netconn, 00157 it has its own struct (to avoid struct api_msg getting bigger than necessary). 00158 lwip_netconn_do_gethostbyname must be called using tcpip_callback instead of tcpip_apimsg 00159 (see netconn_gethostbyname). */ 00160 struct dns_api_msg { 00161 /** Hostname to query or dotted IP address string */ 00162 #if LWIP_MPU_COMPATIBLE 00163 char name[DNS_MAX_NAME_LENGTH]; 00164 #else /* LWIP_MPU_COMPATIBLE */ 00165 const char *name; 00166 #endif /* LWIP_MPU_COMPATIBLE */ 00167 /** The resolved address is stored here */ 00168 ip_addr_t API_MSG_M_DEF(addr); 00169 #if LWIP_IPV4 && LWIP_IPV6 00170 /** Type of resolve call */ 00171 u8_t dns_addrtype; 00172 #endif /* LWIP_IPV4 && LWIP_IPV6 */ 00173 /** This semaphore is posted when the name is resolved, the application thread 00174 should wait on it. */ 00175 sys_sem_t API_MSG_M_DEF_SEM(sem); 00176 /** Errors are given back here */ 00177 err_t API_MSG_M_DEF(err); 00178 }; 00179 #endif /* LWIP_DNS */ 00180 00181 #if LWIP_TCP 00182 extern u8_t netconn_aborted; 00183 #endif /* LWIP_TCP */ 00184 00185 void lwip_netconn_do_newconn (void *m); 00186 void lwip_netconn_do_delconn (void *m); 00187 void lwip_netconn_do_bind (void *m); 00188 void lwip_netconn_do_connect (void *m); 00189 void lwip_netconn_do_disconnect (void *m); 00190 void lwip_netconn_do_listen (void *m); 00191 void lwip_netconn_do_send (void *m); 00192 void lwip_netconn_do_recv (void *m); 00193 #if TCP_LISTEN_BACKLOG 00194 void lwip_netconn_do_accepted (void *m); 00195 #endif /* TCP_LISTEN_BACKLOG */ 00196 void lwip_netconn_do_write (void *m); 00197 void lwip_netconn_do_getaddr (void *m); 00198 void lwip_netconn_do_close (void *m); 00199 void lwip_netconn_do_shutdown (void *m); 00200 #if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) 00201 void lwip_netconn_do_join_leave_group(void *m); 00202 #endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */ 00203 00204 #if LWIP_DNS 00205 void lwip_netconn_do_gethostbyname(void *arg); 00206 #endif /* LWIP_DNS */ 00207 00208 struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback); 00209 void netconn_free(struct netconn *conn); 00210 00211 #ifdef __cplusplus 00212 } 00213 #endif 00214 00215 #endif /* LWIP_NETCONN || LWIP_SOCKET */ 00216 00217 #endif /* LWIP_HDR_API_MSG_H */
Generated on Tue Jul 12 2022 18:19:26 by
1.7.2