testing of combination of LCS and LAN

Dependencies:   mbed

Committer:
damir
Date:
Wed Jan 14 13:29:55 2015 +0000
Revision:
0:a7a6a692162f
Test of LAN

Who changed what in which revision?

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