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.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
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 #include "lwip/arch.h" 00043 #include "lwip/ip_addr.h" 00044 #include "lwip/err.h" 00045 #include "lwip/sys.h" 00046 #include "lwip/igmp.h" 00047 #include "lwip/api.h" 00048 #include "lwip/priv/tcpip_priv.h" 00049 00050 #ifdef __cplusplus 00051 extern "C" { 00052 #endif 00053 00054 #if LWIP_NETCONN || LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ 00055 /* Note: Netconn API is always available when sockets are enabled - 00056 * sockets are implemented on top of them */ 00057 00058 #if LWIP_MPU_COMPATIBLE 00059 #if LWIP_NETCONN_SEM_PER_THREAD 00060 #define API_MSG_M_DEF_SEM(m) *m 00061 #else 00062 #define API_MSG_M_DEF_SEM(m) API_MSG_M_DEF(m) 00063 #endif 00064 #else /* LWIP_MPU_COMPATIBLE */ 00065 #define API_MSG_M_DEF_SEM(m) API_MSG_M_DEF(m) 00066 #endif /* LWIP_MPU_COMPATIBLE */ 00067 00068 /* For the netconn API, these values are use as a bitmask! */ 00069 #define NETCONN_SHUT_RD 1 00070 #define NETCONN_SHUT_WR 2 00071 #define NETCONN_SHUT_RDWR (NETCONN_SHUT_RD | NETCONN_SHUT_WR) 00072 00073 /* IP addresses and port numbers are expected to be in 00074 * the same byte order as in the corresponding pcb. 00075 */ 00076 /** This struct includes everything that is necessary to execute a function 00077 for a netconn in another thread context (mainly used to process netconns 00078 in the tcpip_thread context to be thread safe). */ 00079 struct api_msg { 00080 /** The netconn which to process - always needed: it includes the semaphore 00081 which is used to block the application thread until the function finished. */ 00082 struct netconn *conn; 00083 /** The return value of the function executed in tcpip_thread. */ 00084 err_t err; 00085 /** Depending on the executed function, one of these union members is used */ 00086 union { 00087 /** used for lwip_netconn_do_send */ 00088 struct netbuf *b; 00089 /** used for lwip_netconn_do_newconn */ 00090 struct { 00091 u8_t proto; 00092 } n; 00093 /** used for lwip_netconn_do_bind and lwip_netconn_do_connect */ 00094 struct { 00095 API_MSG_M_DEF_C(ip_addr_t, ipaddr); 00096 u16_t port; 00097 u8_t if_idx; 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 /** current vector to write */ 00108 const struct netvector *vector; 00109 /** number of unwritten vectors */ 00110 u16_t vector_cnt; 00111 /** offset into current vector */ 00112 size_t vector_off; 00113 /** total length across vectors */ 00114 size_t len; 00115 /** offset into total length/output of bytes written when err == ERR_OK */ 00116 size_t offset; 00117 u8_t apiflags; 00118 #if LWIP_SO_SNDTIMEO 00119 u32_t time_started; 00120 #endif /* LWIP_SO_SNDTIMEO */ 00121 } w; 00122 /** used for lwip_netconn_do_recv */ 00123 struct { 00124 size_t len; 00125 } r; 00126 #if LWIP_TCP 00127 /** used for lwip_netconn_do_close (/shutdown) */ 00128 struct { 00129 u8_t shut; 00130 #if LWIP_SO_SNDTIMEO || LWIP_SO_LINGER 00131 u32_t time_started; 00132 #else /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */ 00133 u8_t polls_left; 00134 #endif /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */ 00135 } sd; 00136 #endif /* LWIP_TCP */ 00137 #if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) 00138 /** used for lwip_netconn_do_join_leave_group */ 00139 struct { 00140 API_MSG_M_DEF_C(ip_addr_t, multiaddr); 00141 API_MSG_M_DEF_C(ip_addr_t, netif_addr); 00142 u8_t if_idx; 00143 enum netconn_igmp join_or_leave; 00144 } jl; 00145 #endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */ 00146 #if TCP_LISTEN_BACKLOG 00147 struct { 00148 u8_t backlog; 00149 } lb; 00150 #endif /* TCP_LISTEN_BACKLOG */ 00151 } msg; 00152 #if LWIP_NETCONN_SEM_PER_THREAD 00153 sys_sem_t* op_completed_sem; 00154 #endif /* LWIP_NETCONN_SEM_PER_THREAD */ 00155 }; 00156 00157 #if LWIP_NETCONN_SEM_PER_THREAD 00158 #define LWIP_API_MSG_SEM(msg) ((msg)->op_completed_sem) 00159 #else /* LWIP_NETCONN_SEM_PER_THREAD */ 00160 #define LWIP_API_MSG_SEM(msg) (&(msg)->conn->op_completed) 00161 #endif /* LWIP_NETCONN_SEM_PER_THREAD */ 00162 00163 00164 #if LWIP_DNS 00165 /** As lwip_netconn_do_gethostbyname requires more arguments but doesn't require a netconn, 00166 it has its own struct (to avoid struct api_msg getting bigger than necessary). 00167 lwip_netconn_do_gethostbyname must be called using tcpip_callback instead of tcpip_apimsg 00168 (see netconn_gethostbyname). */ 00169 struct dns_api_msg { 00170 /** Hostname to query or dotted IP address string */ 00171 #if LWIP_MPU_COMPATIBLE 00172 char name[DNS_MAX_NAME_LENGTH]; 00173 #else /* LWIP_MPU_COMPATIBLE */ 00174 const char *name; 00175 #endif /* LWIP_MPU_COMPATIBLE */ 00176 /** The resolved address is stored here */ 00177 ip_addr_t API_MSG_M_DEF(addr); 00178 #if LWIP_IPV4 && LWIP_IPV6 00179 /** Type of resolve call */ 00180 u8_t dns_addrtype; 00181 #endif /* LWIP_IPV4 && LWIP_IPV6 */ 00182 /** This semaphore is posted when the name is resolved, the application thread 00183 should wait on it. */ 00184 sys_sem_t API_MSG_M_DEF_SEM(sem); 00185 /** Errors are given back here */ 00186 err_t API_MSG_M_DEF(err); 00187 }; 00188 #endif /* LWIP_DNS */ 00189 00190 #if LWIP_NETCONN_FULLDUPLEX 00191 int lwip_netconn_is_deallocated_msg(void *msg); 00192 #endif 00193 int lwip_netconn_is_err_msg(void *msg, err_t *err); 00194 void lwip_netconn_do_newconn (void *m); 00195 void lwip_netconn_do_delconn (void *m); 00196 void lwip_netconn_do_bind (void *m); 00197 void lwip_netconn_do_bind_if (void *m); 00198 void lwip_netconn_do_connect (void *m); 00199 void lwip_netconn_do_disconnect (void *m); 00200 void lwip_netconn_do_listen (void *m); 00201 void lwip_netconn_do_send (void *m); 00202 void lwip_netconn_do_recv (void *m); 00203 #if TCP_LISTEN_BACKLOG 00204 void lwip_netconn_do_accepted (void *m); 00205 #endif /* TCP_LISTEN_BACKLOG */ 00206 void lwip_netconn_do_write (void *m); 00207 void lwip_netconn_do_getaddr (void *m); 00208 void lwip_netconn_do_close (void *m); 00209 void lwip_netconn_do_shutdown (void *m); 00210 #if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) 00211 void lwip_netconn_do_join_leave_group(void *m); 00212 void lwip_netconn_do_join_leave_group_netif(void *m); 00213 #endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */ 00214 00215 #if LWIP_DNS 00216 void lwip_netconn_do_gethostbyname(void *arg); 00217 #endif /* LWIP_DNS */ 00218 00219 struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback); 00220 void netconn_free(struct netconn *conn); 00221 00222 #endif /* LWIP_NETCONN || LWIP_SOCKET */ 00223 00224 #if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */ 00225 00226 /* netifapi related lwIP internal definitions */ 00227 00228 #if LWIP_MPU_COMPATIBLE 00229 #define NETIFAPI_IPADDR_DEF(type, m) type m 00230 #else /* LWIP_MPU_COMPATIBLE */ 00231 #define NETIFAPI_IPADDR_DEF(type, m) const type * m 00232 #endif /* LWIP_MPU_COMPATIBLE */ 00233 00234 typedef void (*netifapi_void_fn)(struct netif *netif); 00235 typedef err_t (*netifapi_errt_fn)(struct netif *netif); 00236 00237 struct netifapi_msg { 00238 struct tcpip_api_call_data call; 00239 struct netif *netif; 00240 union { 00241 struct { 00242 #if LWIP_IPV4 00243 NETIFAPI_IPADDR_DEF(ip4_addr_t, ipaddr); 00244 NETIFAPI_IPADDR_DEF(ip4_addr_t, netmask); 00245 NETIFAPI_IPADDR_DEF(ip4_addr_t, gw); 00246 #endif /* LWIP_IPV4 */ 00247 void *state; 00248 netif_init_fn init; 00249 netif_input_fn input; 00250 } add; 00251 struct { 00252 netifapi_void_fn voidfunc; 00253 netifapi_errt_fn errtfunc; 00254 } common; 00255 struct { 00256 #if LWIP_MPU_COMPATIBLE 00257 char name[NETIF_NAMESIZE]; 00258 #else /* LWIP_MPU_COMPATIBLE */ 00259 char *name; 00260 #endif /* LWIP_MPU_COMPATIBLE */ 00261 u8_t index; 00262 } ifs; 00263 } msg; 00264 }; 00265 00266 #endif /* LWIP_NETIF_API */ 00267 00268 #ifdef __cplusplus 00269 } 00270 #endif 00271 00272 #endif /* LWIP_HDR_API_MSG_H */
Generated on Tue Jul 12 2022 13:54:01 by
