Committer:
mbed714
Date:
Sat Sep 18 23:05:49 2010 +0000
Revision:
0:d616ece2d859

        

Who changed what in which revision?

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