NetServices Stack source

Dependents:   HelloWorld ServoInterfaceBoardExample1 4180_Lab4

Committer:
donatien
Date:
Tue Jul 27 15:59:42 2010 +0000
Revision:
5:dd63a1e02b1b
Parent:
0:632c9925f013

        

Who changed what in which revision?

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