NetServices Stack source

Dependents:   HelloWorld ServoInterfaceBoardExample1 4180_Lab4

Committer:
donatien
Date:
Fri Jun 11 16:05:15 2010 +0000
Revision:
0:632c9925f013
Child:
5:dd63a1e02b1b

        

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 0:632c9925f013 51 /* IP addresses and port numbers are expected to be in
donatien 0:632c9925f013 52 * the same byte order as in the corresponding pcb.
donatien 0:632c9925f013 53 */
donatien 0:632c9925f013 54 /** This struct includes everything that is necessary to execute a function
donatien 0:632c9925f013 55 for a netconn in another thread context (mainly used to process netconns
donatien 0:632c9925f013 56 in the tcpip_thread context to be thread safe). */
donatien 0:632c9925f013 57 struct api_msg_msg {
donatien 0:632c9925f013 58 /** The netconn which to process - always needed: it includes the semaphore
donatien 0:632c9925f013 59 which is used to block the application thread until the function finished. */
donatien 0:632c9925f013 60 struct netconn *conn;
donatien 0:632c9925f013 61 /** The return value of the function executed in tcpip_thread. */
donatien 0:632c9925f013 62 err_t err;
donatien 0:632c9925f013 63 /** Depending on the executed function, one of these union members is used */
donatien 0:632c9925f013 64 union {
donatien 0:632c9925f013 65 /** used for do_send */
donatien 0:632c9925f013 66 struct netbuf *b;
donatien 0:632c9925f013 67 /** used for do_newconn */
donatien 0:632c9925f013 68 struct {
donatien 0:632c9925f013 69 u8_t proto;
donatien 0:632c9925f013 70 } n;
donatien 0:632c9925f013 71 /** used for do_bind and do_connect */
donatien 0:632c9925f013 72 struct {
donatien 0:632c9925f013 73 ip_addr_t *ipaddr;
donatien 0:632c9925f013 74 u16_t port;
donatien 0:632c9925f013 75 } bc;
donatien 0:632c9925f013 76 /** used for do_getaddr */
donatien 0:632c9925f013 77 struct {
donatien 0:632c9925f013 78 ip_addr_t *ipaddr;
donatien 0:632c9925f013 79 u16_t *port;
donatien 0:632c9925f013 80 u8_t local;
donatien 0:632c9925f013 81 } ad;
donatien 0:632c9925f013 82 /** used for do_write */
donatien 0:632c9925f013 83 struct {
donatien 0:632c9925f013 84 const void *dataptr;
donatien 0:632c9925f013 85 size_t len;
donatien 0:632c9925f013 86 u8_t apiflags;
donatien 0:632c9925f013 87 } w;
donatien 0:632c9925f013 88 /** used for do_recv */
donatien 0:632c9925f013 89 struct {
donatien 0:632c9925f013 90 u32_t len;
donatien 0:632c9925f013 91 } r;
donatien 0:632c9925f013 92 #if LWIP_IGMP
donatien 0:632c9925f013 93 /** used for do_join_leave_group */
donatien 0:632c9925f013 94 struct {
donatien 0:632c9925f013 95 ip_addr_t *multiaddr;
donatien 0:632c9925f013 96 ip_addr_t *netif_addr;
donatien 0:632c9925f013 97 enum netconn_igmp join_or_leave;
donatien 0:632c9925f013 98 } jl;
donatien 0:632c9925f013 99 #endif /* LWIP_IGMP */
donatien 0:632c9925f013 100 #if TCP_LISTEN_BACKLOG
donatien 0:632c9925f013 101 struct {
donatien 0:632c9925f013 102 u8_t backlog;
donatien 0:632c9925f013 103 } lb;
donatien 0:632c9925f013 104 #endif /* TCP_LISTEN_BACKLOG */
donatien 0:632c9925f013 105 } msg;
donatien 0:632c9925f013 106 };
donatien 0:632c9925f013 107
donatien 0:632c9925f013 108 /** This struct contains a function to execute in another thread context and
donatien 0:632c9925f013 109 a struct api_msg_msg that serves as an argument for this function.
donatien 0:632c9925f013 110 This is passed to tcpip_apimsg to execute functions in tcpip_thread context. */
donatien 0:632c9925f013 111 struct api_msg {
donatien 0:632c9925f013 112 /** function to execute in tcpip_thread context */
donatien 0:632c9925f013 113 void (* function)(struct api_msg_msg *msg);
donatien 0:632c9925f013 114 /** arguments for this function */
donatien 0:632c9925f013 115 struct api_msg_msg msg;
donatien 0:632c9925f013 116 };
donatien 0:632c9925f013 117
donatien 0:632c9925f013 118 #if LWIP_DNS
donatien 0:632c9925f013 119 /** As do_gethostbyname requires more arguments but doesn't require a netconn,
donatien 0:632c9925f013 120 it has its own struct (to avoid struct api_msg getting bigger than necessary).
donatien 0:632c9925f013 121 do_gethostbyname must be called using tcpip_callback instead of tcpip_apimsg
donatien 0:632c9925f013 122 (see netconn_gethostbyname). */
donatien 0:632c9925f013 123 struct dns_api_msg {
donatien 0:632c9925f013 124 /** Hostname to query or dotted IP address string */
donatien 0:632c9925f013 125 const char *name;
donatien 0:632c9925f013 126 /** Rhe resolved address is stored here */
donatien 0:632c9925f013 127 ip_addr_t *addr;
donatien 0:632c9925f013 128 /** This semaphore is posted when the name is resolved, the application thread
donatien 0:632c9925f013 129 should wait on it. */
donatien 0:632c9925f013 130 sys_sem_t *sem;
donatien 0:632c9925f013 131 /** Errors are given back here */
donatien 0:632c9925f013 132 err_t *err;
donatien 0:632c9925f013 133 };
donatien 0:632c9925f013 134 #endif /* LWIP_DNS */
donatien 0:632c9925f013 135
donatien 0:632c9925f013 136 void do_newconn ( struct api_msg_msg *msg);
donatien 0:632c9925f013 137 void do_delconn ( struct api_msg_msg *msg);
donatien 0:632c9925f013 138 void do_bind ( struct api_msg_msg *msg);
donatien 0:632c9925f013 139 void do_connect ( struct api_msg_msg *msg);
donatien 0:632c9925f013 140 void do_disconnect ( struct api_msg_msg *msg);
donatien 0:632c9925f013 141 void do_listen ( struct api_msg_msg *msg);
donatien 0:632c9925f013 142 void do_send ( struct api_msg_msg *msg);
donatien 0:632c9925f013 143 void do_recv ( struct api_msg_msg *msg);
donatien 0:632c9925f013 144 void do_write ( struct api_msg_msg *msg);
donatien 0:632c9925f013 145 void do_getaddr ( struct api_msg_msg *msg);
donatien 0:632c9925f013 146 void do_close ( struct api_msg_msg *msg);
donatien 0:632c9925f013 147 #if LWIP_IGMP
donatien 0:632c9925f013 148 void do_join_leave_group( struct api_msg_msg *msg);
donatien 0:632c9925f013 149 #endif /* LWIP_IGMP */
donatien 0:632c9925f013 150
donatien 0:632c9925f013 151 #if LWIP_DNS
donatien 0:632c9925f013 152 void do_gethostbyname(void *arg);
donatien 0:632c9925f013 153 #endif /* LWIP_DNS */
donatien 0:632c9925f013 154
donatien 0:632c9925f013 155 struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback);
donatien 0:632c9925f013 156 void netconn_free(struct netconn *conn);
donatien 0:632c9925f013 157
donatien 0:632c9925f013 158 #ifdef __cplusplus
donatien 0:632c9925f013 159 }
donatien 0:632c9925f013 160 #endif
donatien 0:632c9925f013 161
donatien 0:632c9925f013 162 #endif /* LWIP_NETCONN */
donatien 0:632c9925f013 163
donatien 0:632c9925f013 164 #endif /* __LWIP_API_MSG_H__ */