V1

Dependents:   EthernetInterface

Fork of lwip by mbed official

Committer:
lemniskata
Date:
Thu Jun 13 20:00:31 2013 +0000
Revision:
11:c9233fe7de67
Parent:
0:51ac1d130fd4
V1

Who changed what in which revision?

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