/libdb/uIP/uip_arch.h

https://github.com/devkitPro/libogc · C Header · 170 lines · 54 code · 23 blank · 93 comment · 2 complexity · d02965f74dca57a1bd3002c1e47358ae MD5 · raw file

  1. /**
  2. * \defgroup uiparch Architecture specific uIP functions
  3. * @{
  4. *
  5. * The functions in the architecture specific module implement the IP
  6. * check sum and 32-bit additions.
  7. *
  8. * The IP checksum calculation is the most computationally expensive
  9. * operation in the TCP/IP stack and it therefore pays off to
  10. * implement this in efficient assembler. The purpose of the uip-arch
  11. * module is to let the checksum functions to be implemented in
  12. * architecture specific assembler.
  13. *
  14. */
  15. /**
  16. * \file
  17. * Declarations of architecture specific functions.
  18. * \author Adam Dunkels <adam@dunkels.com>
  19. */
  20. /*
  21. * Copyright (c) 2001, Adam Dunkels.
  22. * All rights reserved.
  23. *
  24. * Redistribution and use in source and binary forms, with or without
  25. * modification, are permitted provided that the following conditions
  26. * are met:
  27. * 1. Redistributions of source code must retain the above copyright
  28. * notice, this list of conditions and the following disclaimer.
  29. * 2. Redistributions in binary form must reproduce the above copyright
  30. * notice, this list of conditions and the following disclaimer in the
  31. * documentation and/or other materials provided with the distribution.
  32. * 3. The name of the author may not be used to endorse or promote
  33. * products derived from this software without specific prior
  34. * written permission.
  35. *
  36. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
  37. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  38. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  39. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  40. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  41. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  42. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  43. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  44. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  45. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  46. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47. *
  48. * This file is part of the uIP TCP/IP stack.
  49. *
  50. *
  51. */
  52. #ifndef __UIP_ARCH_H__
  53. #define __UIP_ARCH_H__
  54. #include "uip.h"
  55. #define UIP_MIN(x,y) (x)<(y)?(x):(y)
  56. #define MEM_ALIGNMENT 4
  57. #define MEM_ALIGN(mem) ((void*)(((u32_t)(mem)+MEM_ALIGNMENT-1)&~(u32_t)(MEM_ALIGNMENT-1)))
  58. #define MEM_ALIGN_SIZE(size) (((size)+MEM_ALIGNMENT-1)&~(u32_t)(MEM_ALIGNMENT-1))
  59. #define PACK_STRUCT_STRUCT __attribute__((packed))
  60. #define PACK_STRUCT_FIELD(x) x
  61. #define PACK_STRUCT_BEGIN
  62. #define PACK_STRUCT_END
  63. #ifndef htons
  64. #define htons(x) (x)
  65. #endif
  66. #ifndef ntohs
  67. #define ntohs(x) (x)
  68. #endif
  69. #ifndef htonl
  70. #define htonl(x) (x)
  71. #endif
  72. #ifndef ntohl
  73. #define ntohl(x) (x)
  74. #endif
  75. struct uip_pbuf;
  76. struct uip_ip_addr;
  77. /**
  78. * Calculate the Internet checksum over a buffer.
  79. *
  80. * The Internet checksum is the one's complement of the one's
  81. * complement sum of all 16-bit words in the buffer.
  82. *
  83. * See RFC1071.
  84. *
  85. * \note This function is not called in the current version of uIP,
  86. * but future versions might make use of it.
  87. *
  88. * \param buf A pointer to the buffer over which the checksum is to be
  89. * computed.
  90. *
  91. * \param len The length of the buffer over which the checksum is to
  92. * be computed.
  93. *
  94. * \return The Internet checksum of the buffer.
  95. */
  96. u16_t uip_chksum(u16_t *buf, u32_t len);
  97. /**
  98. * Calculate the IP header checksum of the packet header in uip_buf.
  99. *
  100. * The IP header checksum is the Internet checksum of the 20 bytes of
  101. * the IP header.
  102. *
  103. * \return The IP header checksum of the IP header in the uip_buf
  104. * buffer.
  105. */
  106. u16_t uip_ipchksum(void *dataptr,u16_t len);
  107. u16_t uip_ipchksum_pbuf(struct uip_pbuf *p);
  108. /**
  109. * Calculate the TCP checksum of the packet in uip_buf and uip_appdata.
  110. *
  111. * The TCP checksum is the Internet checksum of data contents of the
  112. * TCP segment, and a pseudo-header as defined in RFC793.
  113. *
  114. * \note The uip_appdata pointer that points to the packet data may
  115. * point anywhere in memory, so it is not possible to simply calculate
  116. * the Internet checksum of the contents of the uip_buf buffer.
  117. *
  118. * \return The TCP checksum of the TCP segment in uip_buf and pointed
  119. * to by uip_appdata.
  120. */
  121. u16_t uip_chksum_pseudo(struct uip_pbuf *p,struct uip_ip_addr *src,struct uip_ip_addr *dst,u8_t proto,u16_t proto_len);
  122. extern void tcpip_tmr_needed(void);
  123. #define tcp_tmr_needed tcpip_tmr_needed
  124. #if UIP_LIBC_MEMFUNCREPLACE
  125. static __inline__ void uip_memcpy(void *dest,const void *src,s32_t len)
  126. {
  127. u8_t *dest0 = (u8_t*)dest;
  128. u8_t *src0 = (u8_t*)src;
  129. while(len--) {
  130. *dest0++ = *src0++;
  131. }
  132. }
  133. static __inline__ void uip_memset(void *dest,s32_t c,s32_t len)
  134. {
  135. u8_t *dest0 = (u8_t*)dest;
  136. while(len--) {
  137. *dest0++ = (s8_t)c;
  138. }
  139. }
  140. #define UIP_MEMCPY uip_memcpy
  141. #define UIP_MEMSET uip_memset
  142. #else
  143. #define UIP_MEMCPY memcpy
  144. #define UIP_MEMSET memset
  145. #endif
  146. /** @} */
  147. #endif /* __UIP_ARCH_H__ */