Dependents:   RTnoV3 RTnoV3_LED RTnoV3_Template RTnoV3_ADC ... more

Committer:
sherckuith
Date:
Sat Dec 31 11:25:27 2011 +0000
Revision:
0:479ce5546098
Ethernet

Who changed what in which revision?

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