EthernetNetIf

Dependents:   XBee_WiFi_EA_LPC4088

Committer:
hmike
Date:
Wed Nov 19 12:00:42 2014 +0000
Revision:
0:62580107d20c
EthernetNetIf

Who changed what in which revision?

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