Ethernetwebsoc

Dependencies:   C12832_lcd LM75B WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip

Committer:
GordonSin
Date:
Fri May 31 04:09:54 2013 +0000
Revision:
0:0ed2a7c7190c
31/5/2013;

Who changed what in which revision?

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