sock_var.h

Go to the documentation of this file.
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 EGNITE SOFTWARE GMBH 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 EGNITE
00024  * SOFTWARE GMBH 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: sock_var.h,v $
00066  * Revision 1.13  2008/08/20 06:56:59  haraldkipp
00067  * Implemented IP demultiplexer.
00068  *
00069  * Revision 1.12  2008/08/11 07:00:27  haraldkipp
00070  * BSD types replaced by stdint types (feature request #1282721).
00071  *
00072  * Revision 1.11  2008/04/18 13:32:00  haraldkipp
00073  * Changed size parameter from u_short to int, which is easier to handle
00074  * for 32-bit targets. You need to recompile your ARM code. No impact on
00075  * AVR expected
00076  * I changed u_int to int at some places to avoid some warnings during
00077  * compilation of Nut/Net.
00078  * libs.
00079  *
00080  * Revision 1.10  2007/08/29 07:43:54  haraldkipp
00081  * Documentation updated and corrected.
00082  *
00083  * Revision 1.9  2006/03/21 21:22:19  drsung
00084  * Enhancement made to TCP state machine. Now TCP options
00085  * are read from peer and at least the maximum segment size is stored.
00086  *
00087  * Revision 1.8  2005/08/02 17:46:49  haraldkipp
00088  * Major API documentation update.
00089  *
00090  * Revision 1.7  2005/06/05 16:48:25  haraldkipp
00091  * Additional parameter enables NutUdpInput() to avoid responding to UDP
00092  * broadcasts with ICMP unreachable messages. Fixes bug #1215192.
00093  *
00094  * Revision 1.6  2004/07/30 19:54:46  drsung
00095  * Some code of TCP stack redesigned. Round trip time calculation is now
00096  * supported. Fixed several bugs in TCP state machine. Now TCP connections
00097  * should be more reliable under heavy traffic or poor physical connections.
00098  *
00099  * Revision 1.5  2004/03/16 16:48:44  haraldkipp
00100  * Added Jan Dubiec's H8/300 port.
00101  *
00102  * Revision 1.4  2004/01/14 19:33:13  drsung
00103  * New TCP output buffer handling
00104  *
00105  * Revision 1.3  2003/11/24 21:00:21  drsung
00106  * Packet queue added for UDP sockets.
00107  *
00108  * Revision 1.2  2003/07/13 19:32:12  haraldkipp
00109  * Faster TCP transfers by changing receive buffer
00110  *
00111  * Revision 1.1.1.1  2003/05/09 14:41:22  haraldkipp
00112  * Initial using 3.2.1
00113  *
00114  * Revision 1.10  2003/02/04 18:00:53  harald
00115  * Version 3 released
00116  *
00117  * Revision 1.9  2002/09/03 17:50:18  harald
00118  * Configurable receive buffer size
00119  *
00120  * Revision 1.8  2002/08/16 17:54:19  harald
00121  * Count out of sequence drops
00122  *
00123  * Revision 1.7  2002/06/26 17:29:29  harald
00124  * First pre-release with 2.4 stack
00125  *
00126  */
00127 
00128 #include <stdint.h>
00129 #include <sys/types.h>
00130 #include <sys/device.h>
00131 #include <dev/netbuf.h>
00132 
00138 #ifdef __cplusplus
00139 extern "C" {
00140 #endif
00141 
00142 /*********************************************************************\
00143  * UDP
00144 \*********************************************************************/
00145 
00150 
00154 typedef struct udp_socket UDPSOCKET;
00155 
00162 struct udp_socket {
00163     UDPSOCKET *so_next;     
00164     uint16_t so_local_port;  
00165     NETBUF  *so_rx_nb;      
00166     HANDLE  so_rx_rdy;      
00167     int     so_rx_cnt;      
00168     int     so_rx_bsz;      
00169 };
00170 
00173 extern int NutUdpInput(NUTDEVICE * dev, NETBUF *nb);
00174 extern int NutUdpOutput(UDPSOCKET *sock, uint32_t dest, uint16_t port, NETBUF *nb);
00175 
00176 
00177 /*********************************************************************\
00178  * TCP
00179 \*********************************************************************/
00180 
00185 
00189 typedef struct tcp_socket TCPSOCKET;
00190 
00197 struct tcp_socket {
00198     TCPSOCKET *so_next;     
00199     void *so_device;        
00200     uint8_t so_devtype;     
00201     int (*so_devread) (TCPSOCKET *, void *, int); 
00202     int (*so_devwrite) (TCPSOCKET *, CONST void *, int); 
00203 #ifdef __HARVARD_ARCH__
00204     int (*so_devwrite_P) (TCPSOCKET *, PGM_P, int); 
00205 #endif
00206     int (*so_devioctl) (TCPSOCKET *, int, void *); 
00208     uint16_t so_devocnt;     
00209     uint8_t *so_devobuf;     
00210     uint16_t so_devobsz;     
00212     volatile uint8_t  so_state;       
00213     uint32_t  so_local_addr;  
00214     uint16_t so_local_port;  
00215     uint32_t  so_remote_addr; 
00216     uint16_t so_remote_port; 
00218     uint8_t  so_tx_flags;    
00219     uint32_t  so_tx_isn;      
00220     uint32_t  so_tx_una;      
00221     uint32_t  so_tx_nxt;      
00222     uint32_t  so_tx_wl1;      
00223     uint32_t  so_tx_wl2;      
00224     uint16_t so_tx_win;      
00225     uint8_t  so_tx_dup;      
00226     NETBUF  *so_tx_nbq;     
00227     HANDLE  so_tx_tq;       
00229     uint32_t  so_rx_isn;      
00230     uint32_t  so_rx_nxt;      
00231     uint16_t so_rx_win;      
00232     int     so_rx_cnt;      
00233     int     so_rx_bsz;      
00234     int     so_rd_cnt;      
00235     NETBUF  *so_rx_buf;     
00236     HANDLE  so_rx_tq;       
00237     NETBUF  *so_rx_nbq;     
00239     uint16_t so_mss;         
00241     uint32_t  so_rtt_seq;     
00242     uint16_t so_rtto;        
00243     uint16_t so_retransmits; 
00244     uint16_t so_time_wait;   
00245     uint16_t so_retran_time; 
00246     uint16_t so_last_error;  
00247     HANDLE  so_pc_tq;       
00248     HANDLE  so_ac_tq;       
00250     uint32_t  so_read_to;     
00251     uint32_t  so_write_to;    
00252     uint32_t  so_oos_drop;    
00253 };
00254 
00255 /*
00256  * TCP send flags.
00257  */
00258 #define SO_FIN      0x01    
00259 #define SO_SYN      0x02    
00260 #define SO_FORCE    0x08    
00261 #define SO_ACK      0x10    
00264 
00265 #include <netinet/tcp_fsm.h>
00266 
00267 extern int NutTcpOutput(TCPSOCKET *sock, CONST uint8_t *data, uint16_t size);
00268 extern int NutTcpReject(NETBUF *nb);
00269 
00270 #ifdef __cplusplus
00271 }
00272 #endif
00273 
00274 #endif

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/