sock_var.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. #ifndef _SYS_SOCK_VAR_H_
  2. #define _SYS_SOCK_VAR_H_
  3. /*
  4. * Copyright (C) 2001-2005 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
  23. * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. *
  34. * -
  35. * Portions Copyright (c) 1983, 1993 by
  36. * The Regents of the University of California. All rights reserved.
  37. *
  38. * Redistribution and use in source and binary forms, with or without
  39. * modification, are permitted provided that the following conditions
  40. * are met:
  41. * 1. Redistributions of source code must retain the above copyright
  42. * notice, this list of conditions and the following disclaimer.
  43. * 2. Redistributions in binary form must reproduce the above copyright
  44. * notice, this list of conditions and the following disclaimer in the
  45. * documentation and/or other materials provided with the distribution.
  46. * 3. Neither the name of the University nor the names of its contributors
  47. * may be used to endorse or promote products derived from this software
  48. * without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  51. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  53. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  54. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  55. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  56. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  57. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  58. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  59. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  60. * SUCH DAMAGE.
  61. */
  62. /*
  63. * $Log: sock_var.h,v $
  64. * Revision 1.9 2006/03/21 21:22:19 drsung
  65. * Enhancement made to TCP state machine. Now TCP options
  66. * are read from peer and at least the maximum segment size is stored.
  67. *
  68. * Revision 1.8 2005/08/02 17:46:49 haraldkipp
  69. * Major API documentation update.
  70. *
  71. * Revision 1.7 2005/06/05 16:48:25 haraldkipp
  72. * Additional parameter enables NutUdpInput() to avoid responding to UDP
  73. * broadcasts with ICMP unreachable messages. Fixes bug #1215192.
  74. *
  75. * Revision 1.6 2004/07/30 19:54:46 drsung
  76. * Some code of TCP stack redesigned. Round trip time calculation is now
  77. * supported. Fixed several bugs in TCP state machine. Now TCP connections
  78. * should be more reliable under heavy traffic or poor physical connections.
  79. *
  80. * Revision 1.5 2004/03/16 16:48:44 haraldkipp
  81. * Added Jan Dubiec's H8/300 port.
  82. *
  83. * Revision 1.4 2004/01/14 19:33:13 drsung
  84. * New TCP output buffer handling
  85. *
  86. * Revision 1.3 2003/11/24 21:00:21 drsung
  87. * Packet queue added for UDP sockets.
  88. *
  89. * Revision 1.2 2003/07/13 19:32:12 haraldkipp
  90. * Faster TCP transfers by changing receive buffer
  91. *
  92. * Revision 1.1.1.1 2003/05/09 14:41:22 haraldkipp
  93. * Initial using 3.2.1
  94. *
  95. * Revision 1.10 2003/02/04 18:00:53 harald
  96. * Version 3 released
  97. *
  98. * Revision 1.9 2002/09/03 17:50:18 harald
  99. * Configurable receive buffer size
  100. *
  101. * Revision 1.8 2002/08/16 17:54:19 harald
  102. * Count out of sequence drops
  103. *
  104. * Revision 1.7 2002/06/26 17:29:29 harald
  105. * First pre-release with 2.4 stack
  106. *
  107. */
  108. #include <sys/types.h>
  109. #include <dev/netbuf.h>
  110. /*!
  111. * \file sys/sock_var.h
  112. * \brief UDP and TCP socket interface definitions.
  113. */
  114. #ifdef __cplusplus
  115. extern "C" {
  116. #endif
  117. /*********************************************************************\
  118. * UDP
  119. \*********************************************************************/
  120. /*!
  121. * \addgroup xgUdpSocket
  122. */
  123. /*@{*/
  124. /*!
  125. * \brief UDP socket type.
  126. */
  127. typedef struct udp_socket UDPSOCKET;
  128. /*!
  129. * \brief UDP socket information structure.
  130. *
  131. * Applications should not rely on the content of this structure.
  132. * It may change without notice.
  133. */
  134. struct udp_socket {
  135. UDPSOCKET *so_next; /*!< \brief Link to next tcp socket structure. */
  136. u_short so_local_port; /*!< \brief Local port number in net byte order. */
  137. NETBUF *so_rx_nb; /*!< \brief Received, but not read by application. */
  138. HANDLE so_rx_rdy; /*!< \brief Receiver event queue. */
  139. u_short so_rx_cnt; /*!< \brief Number of data bytes in the receive buffer. */
  140. u_short so_rx_bsz; /*!< \brief Receive buffer size. */
  141. };
  142. /*@}*/
  143. extern void NutUdpInput(NETBUF *nb, ureg_t bcast);
  144. extern int NutUdpOutput(UDPSOCKET *sock, u_long dest, u_short port, NETBUF *nb);
  145. /*********************************************************************\
  146. * TCP
  147. \*********************************************************************/
  148. /*!
  149. * \addtogroup xgTcpSocket
  150. */
  151. /*@{*/
  152. /*!
  153. * \brief TCP socket type.
  154. */
  155. typedef struct tcp_socket TCPSOCKET;
  156. /*!
  157. * \brief TCP socket information structure.
  158. *
  159. * Applications should not rely on the content of this structure.
  160. * It may change without notice.
  161. */
  162. struct tcp_socket {
  163. TCPSOCKET *so_next; /*!< \brief Link to next tcp socket structure. */
  164. void *so_device; /*!< \brief Always zero. */
  165. u_char so_devtype; /*!< \brief Device type, always IFTYP_TCPSOCK. */
  166. int (*so_devread) (TCPSOCKET *, void *, int); /*!< \brief Read from device. */
  167. int (*so_devwrite) (TCPSOCKET *, CONST void *, int); /*!< \brief Write to device. */
  168. #ifdef __HARVARD_ARCH__
  169. int (*so_devwrite_P) (TCPSOCKET *, PGM_P, int); /*!< \brief Write to device. */
  170. #endif
  171. int (*so_devioctl) (TCPSOCKET *, int, void *); /*!< \brief Driver control function. */
  172. u_short so_devocnt; /*!< \brief Number of data bytes in output buffer. */
  173. u_char *so_devobuf; /*!< \brief Pointer to output buffer. */
  174. u_short so_devobsz; /*!< \brief Output buffer size. */
  175. volatile u_char so_state; /*!< \brief Connection state, see tcp_fsm.h */
  176. u_long so_local_addr; /*!< \brief Local IP address in net byte order. */
  177. u_short so_local_port; /*!< \brief Local port number in net byte order. */
  178. u_long so_remote_addr; /*!< \brief Remote IP address in net byte order. */
  179. u_short so_remote_port; /*!< \brief Remote port number in net byte order. */
  180. u_char so_tx_flags; /*!< \brief Flags used during transmissions - see below */
  181. u_long so_tx_isn; /*!< \brief Initial sequence number. */
  182. u_long so_tx_una; /*!< \brief Unacknowledged sequence number. */
  183. u_long so_tx_nxt; /*!< \brief Next sequence number to send. */
  184. u_long so_tx_wl1; /*!< \brief Sequence number of last window update. */
  185. u_long so_tx_wl2; /*!< \brief Acknowledged sequence of last window update. */
  186. u_short so_tx_win; /*!< \brief Peer's receive window. */
  187. u_char so_tx_dup; /*!< \brief Duplicate ACK counter. */
  188. NETBUF *so_tx_nbq; /*!< \brief Network buffers waiting to be acknowledged. */
  189. HANDLE so_tx_tq; /*!< \brief Threads waiting for transmit buffer space. */
  190. u_long so_rx_isn; /*!< \brief Initial sequence number of remote. */
  191. u_long so_rx_nxt; /*!< \brief Next sequence number to receive. */
  192. u_short so_rx_win; /*!< \brief Local receive window. */
  193. u_short so_rx_cnt; /*!< \brief Number of data bytes in the receive buffer. */
  194. u_short so_rx_bsz; /*!< \brief Receive buffer size. */
  195. u_short so_rd_cnt; /*!< \brief Number of bytes read from buffer top. */
  196. NETBUF *so_rx_buf; /*!< \brief Data waiting to be read by application. */
  197. HANDLE so_rx_tq; /*!< \brief Threads waiting for received data. */
  198. NETBUF *so_rx_nbq; /*!< \brief Network buffers received in advance. */
  199. u_short so_mss; /*!< \brief MSS, limited by remote option or MTU. */
  200. u_long so_rtt_seq; /*!< \brief Sequence number for RTT calculation. */
  201. u_short so_rtto; /*!< \brief Current retransmission timeout. */
  202. u_short so_retransmits; /*!< \brief Number of retransmits. */
  203. u_short so_time_wait; /*!< \brief Time wait counter. */
  204. u_short so_retran_time; /*!< \brief Retransmit time counter. */
  205. u_short so_last_error; /*!< \brief Last error code. */
  206. HANDLE so_pc_tq; /*!< \brief Listening thread. */
  207. HANDLE so_ac_tq; /*!< \brief Connecting thread. */
  208. u_long so_read_to; /*!< \brief Read timeout. */
  209. u_long so_write_to; /*!< \brief Write timeout. */
  210. u_long so_oos_drop; /*!< \brief Out of sequence dropped. */
  211. };
  212. /*
  213. * TCP send flags.
  214. */
  215. #define SO_FIN 0x01 /*!< \brief Socket transmit flag. Send FIN after all data has been transmitted. */
  216. #define SO_SYN 0x02 /*!< \brief Socket transmit flag. Send SYN first. */
  217. #define SO_FORCE 0x08 /*!< \brief Socket transmit flag. Force sending ACK. */
  218. #define SO_ACK 0x10 /*!< \brief Socket transmit flag. Send ACK. */
  219. /*@}*/
  220. #include <netinet/tcp_fsm.h>
  221. extern int NutTcpOutput(TCPSOCKET *sock, CONST u_char *data, u_short size);
  222. extern int NutTcpReject(NETBUF *nb);
  223. #ifdef __cplusplus
  224. }
  225. #endif
  226. #endif