uip_arch.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /**
  2. * \addtogroup uip
  3. * {@
  4. */
  5. /**
  6. * \defgroup uiparch Architecture specific uIP functions
  7. * @{
  8. *
  9. * The functions in the architecture specific module implement the IP
  10. * check sum and 32-bit additions.
  11. *
  12. * The IP checksum calculation is the most computationally expensive
  13. * operation in the TCP/IP stack and it therefore pays off to
  14. * implement this in efficient assembler. The purpose of the uip-arch
  15. * module is to let the checksum functions to be implemented in
  16. * architecture specific assembler.
  17. *
  18. */
  19. /**
  20. * \file
  21. * Declarations of architecture specific functions.
  22. * \author Adam Dunkels <adam@dunkels.com>
  23. */
  24. /*
  25. * Copyright (c) 2001, Adam Dunkels.
  26. * All rights reserved.
  27. *
  28. * Redistribution and use in source and binary forms, with or without
  29. * modification, are permitted provided that the following conditions
  30. * are met:
  31. * 1. Redistributions of source code must retain the above copyright
  32. * notice, this list of conditions and the following disclaimer.
  33. * 2. Redistributions in binary form must reproduce the above copyright
  34. * notice, this list of conditions and the following disclaimer in the
  35. * documentation and/or other materials provided with the distribution.
  36. * 3. The name of the author may not be used to endorse or promote
  37. * products derived from this software without specific prior
  38. * written permission.
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
  41. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  42. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  43. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  44. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  45. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  46. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  47. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  48. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  49. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  50. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  51. *
  52. * This file is part of the uIP TCP/IP stack.
  53. *
  54. * $Id: uip_arch.h,v 1.2 2006/06/07 09:15:19 adam Exp $
  55. *
  56. */
  57. #ifndef __UIP_ARCH_H__
  58. #define __UIP_ARCH_H__
  59. #include "uip.h"
  60. /**
  61. * Carry out a 32-bit addition.
  62. *
  63. * Because not all architectures for which uIP is intended has native
  64. * 32-bit arithmetic, uIP uses an external C function for doing the
  65. * required 32-bit additions in the TCP protocol processing. This
  66. * function should add the two arguments and place the result in the
  67. * global variable uip_acc32.
  68. *
  69. * \note The 32-bit integer pointed to by the op32 parameter and the
  70. * result in the uip_acc32 variable are in network byte order (big
  71. * endian).
  72. *
  73. * \param op32 A pointer to a 4-byte array representing a 32-bit
  74. * integer in network byte order (big endian).
  75. *
  76. * \param op16 A 16-bit integer in host byte order.
  77. */
  78. void uip_add32(u8_t *op32, u16_t op16);
  79. /**
  80. * Calculate the Internet checksum over a buffer.
  81. *
  82. * The Internet checksum is the one's complement of the one's
  83. * complement sum of all 16-bit words in the buffer.
  84. *
  85. * See RFC1071.
  86. *
  87. * \note This function is not called in the current version of uIP,
  88. * but future versions might make use of it.
  89. *
  90. * \param buf A pointer to the buffer over which the checksum is to be
  91. * computed.
  92. *
  93. * \param len The length of the buffer over which the checksum is to
  94. * be computed.
  95. *
  96. * \return The Internet checksum of the buffer.
  97. */
  98. u16_t uip_chksum(u16_t *buf, u16_t len);
  99. /**
  100. * Calculate the IP header checksum of the packet header in uip_buf.
  101. *
  102. * The IP header checksum is the Internet checksum of the 20 bytes of
  103. * the IP header.
  104. *
  105. * \return The IP header checksum of the IP header in the uip_buf
  106. * buffer.
  107. */
  108. u16_t uip_ipchksum(void);
  109. /**
  110. * Calculate the TCP checksum of the packet in uip_buf and uip_appdata.
  111. *
  112. * The TCP checksum is the Internet checksum of data contents of the
  113. * TCP segment, and a pseudo-header as defined in RFC793.
  114. *
  115. * \note The uip_appdata pointer that points to the packet data may
  116. * point anywhere in memory, so it is not possible to simply calculate
  117. * the Internet checksum of the contents of the uip_buf buffer.
  118. *
  119. * \return The TCP checksum of the TCP segment in uip_buf and pointed
  120. * to by uip_appdata.
  121. */
  122. u16_t uip_tcpchksum(void);
  123. u16_t uip_udpchksum(void);
  124. /** @} */
  125. /** @} */
  126. #endif /* __UIP_ARCH_H__ */