ソースの整理中ですが、利用はできます。

Dependencies:   EthernetInterface HttpServer TextLCD mbed-rpc mbed-rtos mbed Socket lwip-eth lwip-sys lwip

Committer:
yueee_yt
Date:
Wed Mar 12 04:19:54 2014 +0000
Revision:
0:7766f6712673
???????????????

Who changed what in which revision?

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