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.
Fork of EthernetNetIf by
api_msg.h
00001 /* 00002 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without modification, 00006 * are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright notice, 00011 * this list of conditions and the following disclaimer in the documentation 00012 * and/or other materials provided with the distribution. 00013 * 3. The name of the author may not be used to endorse or promote products 00014 * derived from this software without specific prior written permission. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00017 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00018 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00019 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00020 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00021 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00022 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00023 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00024 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00025 * OF SUCH DAMAGE. 00026 * 00027 * This file is part of the lwIP TCP/IP stack. 00028 * 00029 * Author: Adam Dunkels <adam@sics.se> 00030 * 00031 */ 00032 #ifndef __LWIP_API_MSG_H__ 00033 #define __LWIP_API_MSG_H__ 00034 00035 #include "lwip/opt.h" 00036 00037 #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */ 00038 00039 #include <stddef.h> /* for size_t */ 00040 00041 #include "lwip/ip_addr.h" 00042 #include "lwip/err.h" 00043 #include "lwip/sys.h" 00044 #include "lwip/igmp.h" 00045 #include "lwip/api.h" 00046 00047 #ifdef __cplusplus 00048 extern "C" { 00049 #endif 00050 00051 #define NETCONN_SHUT_RD 1 00052 #define NETCONN_SHUT_WR 2 00053 #define NETCONN_SHUT_RDWR 3 00054 00055 /* IP addresses and port numbers are expected to be in 00056 * the same byte order as in the corresponding pcb. 00057 */ 00058 /** This struct includes everything that is necessary to execute a function 00059 for a netconn in another thread context (mainly used to process netconns 00060 in the tcpip_thread context to be thread safe). */ 00061 struct api_msg_msg { 00062 /** The netconn which to process - always needed: it includes the semaphore 00063 which is used to block the application thread until the function finished. */ 00064 struct netconn *conn; 00065 /** The return value of the function executed in tcpip_thread. */ 00066 err_t err; 00067 /** Depending on the executed function, one of these union members is used */ 00068 union { 00069 /** used for do_send */ 00070 struct netbuf *b; 00071 /** used for do_newconn */ 00072 struct { 00073 u8_t proto; 00074 } n; 00075 /** used for do_bind and do_connect */ 00076 struct { 00077 ip_addr_t *ipaddr; 00078 u16_t port; 00079 } bc; 00080 /** used for do_getaddr */ 00081 struct { 00082 ip_addr_t *ipaddr; 00083 u16_t *port; 00084 u8_t local; 00085 } ad; 00086 /** used for do_write */ 00087 struct { 00088 const void *dataptr; 00089 size_t len; 00090 u8_t apiflags; 00091 } w; 00092 /** used for do_recv */ 00093 struct { 00094 u32_t len; 00095 } r; 00096 /** used for do_close (/shutdown) */ 00097 struct { 00098 u8_t shut; 00099 } sd; 00100 #if LWIP_IGMP 00101 /** used for do_join_leave_group */ 00102 struct { 00103 ip_addr_t *multiaddr; 00104 ip_addr_t *netif_addr; 00105 enum netconn_igmp join_or_leave; 00106 } jl; 00107 #endif /* LWIP_IGMP */ 00108 #if TCP_LISTEN_BACKLOG 00109 struct { 00110 u8_t backlog; 00111 } lb; 00112 #endif /* TCP_LISTEN_BACKLOG */ 00113 } msg; 00114 }; 00115 00116 /** This struct contains a function to execute in another thread context and 00117 a struct api_msg_msg that serves as an argument for this function. 00118 This is passed to tcpip_apimsg to execute functions in tcpip_thread context. */ 00119 struct api_msg { 00120 /** function to execute in tcpip_thread context */ 00121 void (* function)(struct api_msg_msg *msg); 00122 /** arguments for this function */ 00123 struct api_msg_msg msg; 00124 }; 00125 00126 #if LWIP_DNS 00127 /** As do_gethostbyname requires more arguments but doesn't require a netconn, 00128 it has its own struct (to avoid struct api_msg getting bigger than necessary). 00129 do_gethostbyname must be called using tcpip_callback instead of tcpip_apimsg 00130 (see netconn_gethostbyname). */ 00131 struct dns_api_msg { 00132 /** Hostname to query or dotted IP address string */ 00133 const char *name; 00134 /** Rhe resolved address is stored here */ 00135 ip_addr_t *addr; 00136 /** This semaphore is posted when the name is resolved, the application thread 00137 should wait on it. */ 00138 sys_sem_t *sem; 00139 /** Errors are given back here */ 00140 err_t *err; 00141 }; 00142 #endif /* LWIP_DNS */ 00143 00144 void do_newconn ( struct api_msg_msg *msg); 00145 void do_delconn ( struct api_msg_msg *msg); 00146 void do_bind ( struct api_msg_msg *msg); 00147 void do_connect ( struct api_msg_msg *msg); 00148 void do_disconnect ( struct api_msg_msg *msg); 00149 void do_listen ( struct api_msg_msg *msg); 00150 void do_send ( struct api_msg_msg *msg); 00151 void do_recv ( struct api_msg_msg *msg); 00152 void do_write ( struct api_msg_msg *msg); 00153 void do_getaddr ( struct api_msg_msg *msg); 00154 void do_close ( struct api_msg_msg *msg); 00155 void do_shutdown ( struct api_msg_msg *msg); 00156 #if LWIP_IGMP 00157 void do_join_leave_group( struct api_msg_msg *msg); 00158 #endif /* LWIP_IGMP */ 00159 00160 #if LWIP_DNS 00161 void do_gethostbyname(void *arg); 00162 #endif /* LWIP_DNS */ 00163 00164 struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback); 00165 void netconn_free(struct netconn *conn); 00166 00167 #ifdef __cplusplus 00168 } 00169 #endif 00170 00171 #endif /* LWIP_NETCONN */ 00172 00173 #endif /* __LWIP_API_MSG_H__ */
Generated on Tue Jul 12 2022 18:06:13 by
