Rtos API example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers api_msg.h Source File

api_msg.h

Go to the documentation of this file.
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 "lwip/arch.h"
00047 #include "lwip/ip_addr.h"
00048 #include "lwip/err.h"
00049 #include "lwip/sys.h"
00050 #include "lwip/igmp.h"
00051 #include "lwip/api.h"
00052 #include "lwip/priv/tcpip_priv.h"
00053 
00054 #ifdef __cplusplus
00055 extern "C" {
00056 #endif
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     } bc;
00098     /** used for lwip_netconn_do_getaddr */
00099     struct {
00100       ip_addr_t API_MSG_M_DEF(ipaddr);
00101       u16_t API_MSG_M_DEF(port);
00102       u8_t local;
00103     } ad;
00104     /** used for lwip_netconn_do_write */
00105     struct {
00106       const void *dataptr;
00107       size_t len;
00108       u8_t apiflags;
00109 #if LWIP_SO_SNDTIMEO
00110       u32_t time_started;
00111 #endif /* LWIP_SO_SNDTIMEO */
00112     } w;
00113     /** used for lwip_netconn_do_recv */
00114     struct {
00115       u32_t len;
00116     } r;
00117 #if LWIP_TCP
00118     /** used for lwip_netconn_do_close (/shutdown) */
00119     struct {
00120       u8_t shut;
00121 #if LWIP_SO_SNDTIMEO || LWIP_SO_LINGER
00122       u32_t time_started;
00123 #else /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */
00124       u8_t polls_left;
00125 #endif /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */
00126     } sd;
00127 #endif /* LWIP_TCP */
00128 #if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD)
00129     /** used for lwip_netconn_do_join_leave_group */
00130     struct {
00131       API_MSG_M_DEF_C(ip_addr_t, multiaddr);
00132       API_MSG_M_DEF_C(ip_addr_t, netif_addr);
00133       enum netconn_igmp join_or_leave;
00134     } jl;
00135 #endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */
00136 #if TCP_LISTEN_BACKLOG
00137     struct {
00138       u8_t backlog;
00139     } lb;
00140 #endif /* TCP_LISTEN_BACKLOG */
00141   } msg;
00142 #if LWIP_NETCONN_SEM_PER_THREAD
00143   sys_sem_t* op_completed_sem;
00144 #endif /* LWIP_NETCONN_SEM_PER_THREAD */
00145 };
00146 
00147 #if LWIP_NETCONN_SEM_PER_THREAD
00148 #define LWIP_API_MSG_SEM(msg)          ((msg)->op_completed_sem)
00149 #else /* LWIP_NETCONN_SEM_PER_THREAD */
00150 #define LWIP_API_MSG_SEM(msg)          (&(msg)->conn->op_completed)
00151 #endif /* LWIP_NETCONN_SEM_PER_THREAD */
00152 
00153 
00154 #if LWIP_DNS
00155 /** As lwip_netconn_do_gethostbyname requires more arguments but doesn't require a netconn,
00156     it has its own struct (to avoid struct api_msg getting bigger than necessary).
00157     lwip_netconn_do_gethostbyname must be called using tcpip_callback instead of tcpip_apimsg
00158     (see netconn_gethostbyname). */
00159 struct dns_api_msg {
00160   /** Hostname to query or dotted IP address string */
00161 #if LWIP_MPU_COMPATIBLE
00162   char name[DNS_MAX_NAME_LENGTH];
00163 #else /* LWIP_MPU_COMPATIBLE */
00164   const char *name;
00165 #endif /* LWIP_MPU_COMPATIBLE */
00166   /** The resolved address is stored here */
00167   ip_addr_t API_MSG_M_DEF(addr);
00168 #if LWIP_IPV4 && LWIP_IPV6
00169   /** Type of resolve call */
00170   u8_t dns_addrtype;
00171 #endif /* LWIP_IPV4 && LWIP_IPV6 */
00172   /** This semaphore is posted when the name is resolved, the application thread
00173       should wait on it. */
00174   sys_sem_t API_MSG_M_DEF_SEM(sem);
00175   /** Errors are given back here */
00176   err_t API_MSG_M_DEF(err);
00177 };
00178 #endif /* LWIP_DNS */
00179 
00180 #if LWIP_TCP
00181 extern u8_t netconn_aborted;
00182 #endif /* LWIP_TCP */
00183 
00184 void lwip_netconn_do_newconn         (void *m);
00185 void lwip_netconn_do_delconn         (void *m);
00186 void lwip_netconn_do_bind            (void *m);
00187 void lwip_netconn_do_connect         (void *m);
00188 void lwip_netconn_do_disconnect      (void *m);
00189 void lwip_netconn_do_listen          (void *m);
00190 void lwip_netconn_do_send            (void *m);
00191 void lwip_netconn_do_recv            (void *m);
00192 #if TCP_LISTEN_BACKLOG
00193 void lwip_netconn_do_accepted        (void *m);
00194 #endif /* TCP_LISTEN_BACKLOG */
00195 void lwip_netconn_do_write           (void *m);
00196 void lwip_netconn_do_getaddr         (void *m);
00197 void lwip_netconn_do_close           (void *m);
00198 void lwip_netconn_do_shutdown        (void *m);
00199 #if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD)
00200 void lwip_netconn_do_join_leave_group(void *m);
00201 #endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */
00202 
00203 #if LWIP_DNS
00204 void lwip_netconn_do_gethostbyname(void *arg);
00205 #endif /* LWIP_DNS */
00206 
00207 struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback);
00208 void netconn_free(struct netconn *conn);
00209 
00210 #ifdef __cplusplus
00211 }
00212 #endif
00213 
00214 #endif /* LWIP_NETCONN || LWIP_SOCKET */
00215 
00216 #endif /* LWIP_HDR_API_MSG_H */