ZG2100 Network interface source

Committer:
donatien
Date:
Fri Aug 06 10:23:41 2010 +0000
Revision:
1:3a7c15057192
Parent:
0:b802fc31f1db

        

Who changed what in which revision?

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