This library is stripped down version of NetServices library. HTTP server and client function is NOT supported.

Dependents:   imu-daq-eth

Committer:
idinor
Date:
Wed Jul 20 11:45:39 2011 +0000
Revision:
0:dcf3c92487ca

        

Who changed what in which revision?

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