TcpOption.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /** @file
  2. Tcp option's routine header file.
  3. Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef _TCP_OPTION_H_
  7. #define _TCP_OPTION_H_
  8. //
  9. // Supported TCP option types and their length.
  10. //
  11. #define TCP_OPTION_EOP 0 ///< End Of oPtion
  12. #define TCP_OPTION_NOP 1 ///< No-Option.
  13. #define TCP_OPTION_MSS 2 ///< Maximum Segment Size
  14. #define TCP_OPTION_WS 3 ///< Window scale
  15. #define TCP_OPTION_TS 8 ///< Timestamp
  16. #define TCP_OPTION_MSS_LEN 4 ///< Length of MSS option
  17. #define TCP_OPTION_WS_LEN 3 ///< Length of window scale option
  18. #define TCP_OPTION_TS_LEN 10 ///< Length of timestamp option
  19. #define TCP_OPTION_WS_ALIGNED_LEN 4 ///< Length of window scale option, aligned
  20. #define TCP_OPTION_TS_ALIGNED_LEN 12 ///< Length of timestamp option, aligned
  21. //
  22. // recommend format of timestamp window scale
  23. // option for fast process.
  24. //
  25. #define TCP_OPTION_TS_FAST ((TCP_OPTION_NOP << 24) |\
  26. (TCP_OPTION_NOP << 16) | \
  27. (TCP_OPTION_TS << 8) | \
  28. (TCP_OPTION_TS_LEN))
  29. #define TCP_OPTION_WS_FAST ((TCP_OPTION_NOP << 24) | \
  30. (TCP_OPTION_WS << 16) | \
  31. (TCP_OPTION_WS_LEN << 8))
  32. #define TCP_OPTION_MSS_FAST ((TCP_OPTION_MSS << 24) | (TCP_OPTION_MSS_LEN << 16))
  33. //
  34. // Other misc definitions
  35. //
  36. #define TCP_OPTION_RCVD_MSS 0x01
  37. #define TCP_OPTION_RCVD_WS 0x02
  38. #define TCP_OPTION_RCVD_TS 0x04
  39. #define TCP_OPTION_MAX_WS 14 ///< Maximum window scale value
  40. #define TCP_OPTION_MAX_WIN 0xffff ///< Max window size in TCP header
  41. ///
  42. /// The structure to store the parse option value.
  43. /// ParseOption only parses the options, doesn't process them.
  44. ///
  45. typedef struct _TCP_OPTION {
  46. UINT8 Flag; ///< Flag such as TCP_OPTION_RCVD_MSS
  47. UINT8 WndScale; ///< The WndScale received
  48. UINT16 Mss; ///< The Mss received
  49. UINT32 TSVal; ///< The TSVal field in a timestamp option
  50. UINT32 TSEcr; ///< The TSEcr field in a timestamp option
  51. } TCP_OPTION;
  52. /**
  53. Compute the window scale value according to the given buffer size.
  54. @param[in] Tcb Pointer to the TCP_CB of this TCP instance.
  55. @return The scale value.
  56. **/
  57. UINT8
  58. TcpComputeScale (
  59. IN TCP_CB *Tcb
  60. );
  61. /**
  62. Build the TCP option in three-way handshake.
  63. @param[in] Tcb Pointer to the TCP_CB of this TCP instance.
  64. @param[in] Nbuf Pointer to the buffer to store the options.
  65. @return The total length of the TCP option field.
  66. **/
  67. UINT16
  68. TcpSynBuildOption (
  69. IN TCP_CB *Tcb,
  70. IN NET_BUF *Nbuf
  71. );
  72. /**
  73. Build the TCP option in synchronized states.
  74. @param[in] Tcb Pointer to the TCP_CB of this TCP instance.
  75. @param[in] Nbuf Pointer to the buffer to store the options.
  76. @return The total length of the TCP option field.
  77. **/
  78. UINT16
  79. TcpBuildOption (
  80. IN TCP_CB *Tcb,
  81. IN NET_BUF *Nbuf
  82. );
  83. /**
  84. Parse the supported options.
  85. @param[in] Tcp Pointer to the TCP_CB of this TCP instance.
  86. @param[in, out] Option Pointer to the TCP_OPTION used to store the
  87. successfully pasrsed options.
  88. @retval 0 The options successfully pasrsed.
  89. @retval -1 Illegal option was found.
  90. **/
  91. INTN
  92. TcpParseOption (
  93. IN TCP_HEAD *Tcp,
  94. IN OUT TCP_OPTION *Option
  95. );
  96. #endif