Embedded WebSockets Experiment

Dependencies:   mbed MD5

Committer:
nandgate
Date:
Tue Jul 26 05:30:53 2011 +0000
Revision:
0:6dee052a3fa4

        

Who changed what in which revision?

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