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