RobT fork of EthernetNetIf library

Fork of EthernetNetIf by Donatien Garnier

Committer:
donatien
Date:
Thu Aug 05 15:09:22 2010 +0000
Revision:
5:bc7df6da7589
Parent:
0:422060928e37

        

Who changed what in which revision?

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