00001 #ifndef _SYS_SOCK_VAR_H_ 00002 #define _SYS_SOCK_VAR_H_ 00003 00004 /* 00005 * Copyright (C) 2001-2005 by egnite Software GmbH. All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * 1. Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * 2. Redistributions in binary form must reproduce the above copyright 00014 * notice, this list of conditions and the following disclaimer in the 00015 * documentation and/or other materials provided with the distribution. 00016 * 3. Neither the name of the copyright holders nor the names of 00017 * contributors may be used to endorse or promote products derived 00018 * from this software without specific prior written permission. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00021 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00022 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00023 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00024 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00025 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00026 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 00027 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 00028 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00029 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 00030 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00031 * SUCH DAMAGE. 00032 * 00033 * For additional information see http://www.ethernut.de/ 00034 * 00035 * - 00036 * Portions Copyright (c) 1983, 1993 by 00037 * The Regents of the University of California. All rights reserved. 00038 * 00039 * Redistribution and use in source and binary forms, with or without 00040 * modification, are permitted provided that the following conditions 00041 * are met: 00042 * 1. Redistributions of source code must retain the above copyright 00043 * notice, this list of conditions and the following disclaimer. 00044 * 2. Redistributions in binary form must reproduce the above copyright 00045 * notice, this list of conditions and the following disclaimer in the 00046 * documentation and/or other materials provided with the distribution. 00047 * 3. Neither the name of the University nor the names of its contributors 00048 * may be used to endorse or promote products derived from this software 00049 * without specific prior written permission. 00050 * 00051 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00052 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00053 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00054 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00055 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00056 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00057 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00058 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00059 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00060 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00061 * SUCH DAMAGE. 00062 */ 00063 00064 /* 00065 * $Log$ 00066 * Revision 1.14 2009/02/22 12:37:27 olereinhardt 00067 * Added NutUdpError and NutUdpSetSocketError to set and retrieve socket 00068 * errors. As udp sockets aren't connection oriented those errors will be 00069 * anounced asynchronously on the next NutUdpSend or NutUdpReceive 00070 * 00071 * Include "include/errno.h" instead of "include/net/errno.h" 00072 * 00073 * Revision 1.13 2008/08/20 06:56:59 haraldkipp 00074 * Implemented IP demultiplexer. 00075 * 00076 * Revision 1.12 2008/08/11 07:00:27 haraldkipp 00077 * BSD types replaced by stdint types (feature request #1282721). 00078 * 00079 * Revision 1.11 2008/04/18 13:32:00 haraldkipp 00080 * Changed size parameter from u_short to int, which is easier to handle 00081 * for 32-bit targets. You need to recompile your ARM code. No impact on 00082 * AVR expected 00083 * I changed u_int to int at some places to avoid some warnings during 00084 * compilation of Nut/Net. 00085 * libs. 00086 * 00087 * Revision 1.10 2007/08/29 07:43:54 haraldkipp 00088 * Documentation updated and corrected. 00089 * 00090 * Revision 1.9 2006/03/21 21:22:19 drsung 00091 * Enhancement made to TCP state machine. Now TCP options 00092 * are read from peer and at least the maximum segment size is stored. 00093 * 00094 * Revision 1.8 2005/08/02 17:46:49 haraldkipp 00095 * Major API documentation update. 00096 * 00097 * Revision 1.7 2005/06/05 16:48:25 haraldkipp 00098 * Additional parameter enables NutUdpInput() to avoid responding to UDP 00099 * broadcasts with ICMP unreachable messages. Fixes bug #1215192. 00100 * 00101 * Revision 1.6 2004/07/30 19:54:46 drsung 00102 * Some code of TCP stack redesigned. Round trip time calculation is now 00103 * supported. Fixed several bugs in TCP state machine. Now TCP connections 00104 * should be more reliable under heavy traffic or poor physical connections. 00105 * 00106 * Revision 1.5 2004/03/16 16:48:44 haraldkipp 00107 * Added Jan Dubiec's H8/300 port. 00108 * 00109 * Revision 1.4 2004/01/14 19:33:13 drsung 00110 * New TCP output buffer handling 00111 * 00112 * Revision 1.3 2003/11/24 21:00:21 drsung 00113 * Packet queue added for UDP sockets. 00114 * 00115 * Revision 1.2 2003/07/13 19:32:12 haraldkipp 00116 * Faster TCP transfers by changing receive buffer 00117 * 00118 * Revision 1.1.1.1 2003/05/09 14:41:22 haraldkipp 00119 * Initial using 3.2.1 00120 * 00121 * Revision 1.10 2003/02/04 18:00:53 harald 00122 * Version 3 released 00123 * 00124 * Revision 1.9 2002/09/03 17:50:18 harald 00125 * Configurable receive buffer size 00126 * 00127 * Revision 1.8 2002/08/16 17:54:19 harald 00128 * Count out of sequence drops 00129 * 00130 * Revision 1.7 2002/06/26 17:29:29 harald 00131 * First pre-release with 2.4 stack 00132 * 00133 */ 00134 00135 #include <compiler.h> 00136 #include <stdint.h> 00137 #include <sys/types.h> 00138 #include <sys/device.h> 00139 #include <dev/netbuf.h> 00140 00141 00147 /*********************************************************************\ 00148 * UDP 00149 \*********************************************************************/ 00150 00155 00159 typedef struct udp_socket UDPSOCKET; 00160 00167 struct udp_socket { 00168 UDPSOCKET *so_next; 00169 uint16_t so_local_port; 00170 NETBUF *so_rx_nb; 00171 HANDLE so_rx_rdy; 00172 int so_rx_cnt; 00173 int so_rx_bsz; 00175 uint16_t so_last_error; 00176 uint32_t so_remote_addr; 00177 uint16_t so_remote_port; 00178 }; 00179 00182 extern int NutUdpInput(NUTDEVICE * dev, NETBUF *nb); 00183 extern int NutUdpOutput(UDPSOCKET *sock, uint32_t dest, uint16_t port, NETBUF *nb); 00184 00185 00186 /*********************************************************************\ 00187 * TCP 00188 \*********************************************************************/ 00189 00194 00198 typedef struct tcp_socket TCPSOCKET; 00199 00206 struct tcp_socket { 00207 TCPSOCKET *so_next; 00208 void *so_device; 00209 uint8_t so_devtype; 00210 int (*so_devread) (TCPSOCKET *, void *, int); 00211 int (*so_devwrite) (TCPSOCKET *, const void *, int); 00212 #ifdef __HARVARD_ARCH__ 00213 int (*so_devwrite_P) (TCPSOCKET *, PGM_P, int); 00214 #endif 00215 int (*so_devioctl) (TCPSOCKET *, int, void *); 00217 uint16_t so_devocnt; 00218 uint8_t *so_devobuf; 00219 uint16_t so_devobsz; 00221 volatile uint8_t so_state; 00222 uint32_t so_local_addr; 00223 uint16_t so_local_port; 00224 uint32_t so_remote_addr; 00225 uint16_t so_remote_port; 00227 uint8_t so_tx_flags; 00228 uint32_t so_tx_isn; 00229 uint32_t so_tx_una; 00230 uint32_t so_tx_nxt; 00231 uint32_t so_tx_wl1; 00232 uint32_t so_tx_wl2; 00233 uint16_t so_tx_win; 00234 uint8_t so_tx_dup; 00235 NETBUF *so_tx_nbq; 00236 HANDLE so_tx_tq; 00238 uint32_t so_rx_isn; 00239 uint32_t so_rx_nxt; 00240 uint16_t so_rx_win; 00241 int so_rx_cnt; 00242 int so_rx_bsz; 00243 int so_rd_cnt; 00244 int_fast8_t so_rx_apc; 00245 NETBUF *so_rx_buf; 00246 HANDLE so_rx_tq; 00247 NETBUF *so_rx_nbq; 00249 uint16_t so_mss; 00251 uint32_t so_rtt_seq; 00252 uint16_t so_rtto; 00253 uint16_t so_retransmits; 00254 uint16_t so_time_wait; 00255 uint16_t so_retran_time; 00256 uint16_t so_last_error; 00257 HANDLE so_pc_tq; 00258 HANDLE so_ac_tq; 00260 uint32_t so_read_to; 00261 uint32_t so_write_to; 00262 uint32_t so_oos_drop; 00263 }; 00264 00265 /* 00266 * TCP send flags. 00267 */ 00268 #define SO_FIN 0x01 00269 #define SO_SYN 0x02 00270 #define SO_FORCE 0x08 00271 #define SO_ACK 0x10 00274 00275 #include <netinet/tcp_fsm.h> 00276 00277 extern int NutTcpOutput(TCPSOCKET *sock, const uint8_t *data, uint16_t size); 00278 extern int NutTcpReject(NETBUF *nb); 00279 00280 #endif