Nut/OS  4.10.3
API Reference
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$
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 __BEGIN_DECLS
00148 
00149 /*********************************************************************\
00150  * UDP
00151 \*********************************************************************/
00152 
00157 
00161 typedef struct udp_socket UDPSOCKET;
00162 
00169 struct udp_socket {
00170     UDPSOCKET *so_next;      
00171     uint16_t so_local_port;  
00172     NETBUF  *so_rx_nb;       
00173     HANDLE  so_rx_rdy;       
00174     int     so_rx_cnt;       
00175     int     so_rx_bsz;       
00177     uint16_t so_last_error;  
00178     uint32_t so_remote_addr; 
00179     uint16_t so_remote_port; 
00180 };
00181 
00184 extern int NutUdpInput(NUTDEVICE * dev, NETBUF *nb);
00185 extern int NutUdpOutput(UDPSOCKET *sock, uint32_t dest, uint16_t port, NETBUF *nb);
00186 
00187 
00188 /*********************************************************************\
00189  * TCP
00190 \*********************************************************************/
00191 
00196 
00200 typedef struct tcp_socket TCPSOCKET;
00201 
00208 struct tcp_socket {
00209     TCPSOCKET *so_next;     
00210     void *so_device;        
00211     uint8_t so_devtype;     
00212     int (*so_devread) (TCPSOCKET *, void *, int); 
00213     int (*so_devwrite) (TCPSOCKET *, CONST void *, int); 
00214 #ifdef __HARVARD_ARCH__
00215     int (*so_devwrite_P) (TCPSOCKET *, PGM_P, int); 
00216 #endif
00217     int (*so_devioctl) (TCPSOCKET *, int, void *); 
00219     uint16_t so_devocnt;     
00220     uint8_t *so_devobuf;     
00221     uint16_t so_devobsz;     
00223     volatile uint8_t  so_state;       
00224     uint32_t  so_local_addr;  
00225     uint16_t so_local_port;  
00226     uint32_t  so_remote_addr; 
00227     uint16_t so_remote_port; 
00229     uint8_t  so_tx_flags;    
00230     uint32_t  so_tx_isn;      
00231     uint32_t  so_tx_una;      
00232     uint32_t  so_tx_nxt;      
00233     uint32_t  so_tx_wl1;      
00234     uint32_t  so_tx_wl2;      
00235     uint16_t so_tx_win;      
00236     uint8_t  so_tx_dup;      
00237     NETBUF  *so_tx_nbq;     
00238     HANDLE  so_tx_tq;       
00240     uint32_t  so_rx_isn;      
00241     uint32_t  so_rx_nxt;      
00242     uint16_t so_rx_win;      
00243     int     so_rx_cnt;      
00244     int     so_rx_bsz;      
00245     int     so_rd_cnt;      
00246     int_fast8_t so_rx_apc;  
00247     NETBUF  *so_rx_buf;     
00248     HANDLE  so_rx_tq;       
00249     NETBUF  *so_rx_nbq;     
00251     uint16_t so_mss;         
00253     uint32_t  so_rtt_seq;     
00254     uint16_t so_rtto;        
00255     uint16_t so_retransmits; 
00256     uint16_t so_time_wait;   
00257     uint16_t so_retran_time; 
00258     uint16_t so_last_error;  
00259     HANDLE  so_pc_tq;       
00260     HANDLE  so_ac_tq;       
00262     uint32_t  so_read_to;     
00263     uint32_t  so_write_to;    
00264     uint32_t  so_oos_drop;    
00265 };
00266 
00267 /*
00268  * TCP send flags.
00269  */
00270 #define SO_FIN      0x01    
00271 #define SO_SYN      0x02    
00272 #define SO_FORCE    0x08    
00273 #define SO_ACK      0x10    
00276 
00277 #include <netinet/tcp_fsm.h>
00278 
00279 extern int NutTcpOutput(TCPSOCKET *sock, CONST uint8_t *data, uint16_t size);
00280 extern int NutTcpReject(NETBUF *nb);
00281 
00282 __END_DECLS
00283 
00284 #endif