PageRenderTime 60ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/platform/FNET/fnet_stack/stack/fnet_ip6.h

https://gitlab.com/fuggles/ucos
C Header | 167 lines | 71 code | 25 blank | 71 comment | 16 complexity | 1604080a37a217740764b8908193eb51 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0
  1. /**************************************************************************
  2. *
  3. * Copyright 2011-2015 by Andrey Butok. FNET Community.
  4. * Copyright 2008-2010 by Andrey Butok. Freescale Semiconductor, Inc.
  5. *
  6. ***************************************************************************
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License Version 3
  9. * or later (the "LGPL").
  10. *
  11. * As a special exception, the copyright holders of the FNET project give you
  12. * permission to link the FNET sources with independent modules to produce an
  13. * executable, regardless of the license terms of these independent modules,
  14. * and to copy and distribute the resulting executable under terms of your
  15. * choice, provided that you also meet, for each linked independent module,
  16. * the terms and conditions of the license of that module.
  17. * An independent module is a module which is not derived from or based
  18. * on this library.
  19. * If you modify the FNET sources, you may extend this exception
  20. * to your version of the FNET sources, but you are not obligated
  21. * to do so. If you do not wish to do so, delete this
  22. * exception statement from your version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  27. *
  28. * You should have received a copy of the GNU General Public License
  29. * and the GNU Lesser General Public License along with this program.
  30. * If not, see <http://www.gnu.org/licenses/>.
  31. *
  32. **********************************************************************/ /*!
  33. *
  34. * @file fnet_ip6.h
  35. *
  36. * @author Andrey Butok
  37. *
  38. * @brief IPv6 protocol API.
  39. *
  40. ***************************************************************************/
  41. #ifndef _FNET_IP6_H_
  42. #define _FNET_IP6_H_
  43. #include "fnet.h"
  44. /*! @addtogroup fnet_socket */
  45. /*! @{ */
  46. /**************************************************************************/ /*!
  47. * @brief 128-bit IPv6 address type.
  48. ******************************************************************************/
  49. FNET_COMP_PACKED_BEGIN
  50. typedef struct
  51. {
  52. union
  53. {
  54. unsigned char addr[16];
  55. unsigned short addr16[8];
  56. unsigned long addr32[4];
  57. }; /* 128-bit IP6 address */
  58. } fnet_ip6_addr_t;
  59. FNET_COMP_PACKED_END
  60. /**************************************************************************/ /*!
  61. * @brief Size of the string buffer that will contain
  62. * null-terminated ASCII string of an IPv6 address
  63. * in standard ":" notation.
  64. * @see fnet_inet_ntop
  65. * @showinitializer
  66. ******************************************************************************/
  67. #define FNET_IP6_ADDR_STR_SIZE sizeof("abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd")
  68. /*! @} */
  69. /******************************************************************
  70. * Constants
  71. *******************************************************************/
  72. #define FNET_IP6_HEADSIZE 40u /* */
  73. #define FNET_IP6_DEFAULT_MTU 1280u /* Minimum IPv6 datagram size which
  74. * must be supported by all IPv6 hosts */
  75. /****************************************************************
  76. *
  77. * Helpful macros.
  78. *
  79. *****************************************************************/
  80. #define FNET_IP6_ADDR_INIT(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16) \
  81. {{{ (a1), (a2), (a3), (a4), (a5), (a6), (a7), (a8), \
  82. (a9), (a10), (a11), (a12), (a13), (a14), (a15), (a16) }}}
  83. /*
  84. * Definition of some useful macros to handle IP6 addresses (BSD-like)
  85. */
  86. #define FNET_IP6_ADDR_ANY_INIT \
  87. {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  88. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
  89. #define FNET_IP6_ADDR_LOOPBACK_INIT \
  90. {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  91. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
  92. #define FNET_IP6_ADDR_NODELOCAL_ALLNODES_INIT \
  93. {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  94. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
  95. #define FNET_IP6_ADDR_INTFACELOCAL_ALLNODES_INIT \
  96. {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  97. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
  98. #define FNET_IP6_ADDR_LINKLOCAL_ALLNODES_INIT \
  99. {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  100. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
  101. #define FNET_IP6_ADDR_LINKLOCAL_ALLROUTERS_INIT \
  102. {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  103. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}
  104. #define FNET_IP6_ADDR_LINKLOCAL_ALLV2ROUTERS_INIT \
  105. {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  106. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16 }}}
  107. #define FNET_IP6_ADDR_LINKLOCAL_PREFIX_INIT \
  108. {{{ 0xFE,0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  109. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
  110. extern const fnet_ip6_addr_t fnet_ip6_addr_any;
  111. extern const fnet_ip6_addr_t fnet_ip6_addr_loopback;
  112. extern const fnet_ip6_addr_t fnet_ip6_addr_nodelocal_allnodes;
  113. extern const fnet_ip6_addr_t fnet_ip6_addr_linklocal_allnodes;
  114. extern const fnet_ip6_addr_t fnet_ip6_addr_linklocal_allrouters;
  115. extern const fnet_ip6_addr_t fnet_ip6_addr_linklocal_allv2routers;
  116. extern const fnet_ip6_addr_t fnet_ip6_addr_linklocal_prefix;
  117. /* Equality. */
  118. #define FNET_IP6_ADDR_EQUAL(a, b) \
  119. (fnet_memcmp(&(a)->addr[0], &(b)->addr[0], sizeof(fnet_ip6_addr_t)) == 0U)
  120. /* Copying address. */
  121. #define FNET_IP6_ADDR_COPY(from_addr, to_addr) \
  122. (fnet_memcpy(&(to_addr)->addr[0], &(from_addr)->addr[0], sizeof(fnet_ip6_addr_t)))
  123. /* Unspecified.*/
  124. #define FNET_IP6_ADDR_IS_UNSPECIFIED(a) \
  125. ((((a)->addr32[0]) == 0U) && \
  126. (((a)->addr32[1]) == 0U) && \
  127. (((a)->addr32[2]) == 0U) && \
  128. (((a)->addr32[3]) == 0U))
  129. /* Loopback.*/
  130. #define FNET_IP6_ADDR_IS_LOOPBACK(a) \
  131. ((((a)->addr32[0]) == 0U) && \
  132. (((a)->addr32[1]) == 0U) && \
  133. (((a)->addr32[2]) == 0U) && \
  134. (((a)->addr32[3]) == FNET_NTOHL(1U)))
  135. /* Multicast. */
  136. #define FNET_IP6_ADDR_IS_MULTICAST(a) ((a)->addr[0] == 0xffU)
  137. /* Unicast Scope.*/
  138. #define FNET_IP6_ADDR_IS_LINKLOCAL(a) \
  139. (((a)->addr[0] == 0xfeU) && (((a)->addr[1] & 0xc0U) == 0x80U))
  140. #define FNET_IP6_ADDR_IS_SITELOCAL(a) \
  141. (((a)->addr[0] == 0xfeU) && (((a)->addr[1] & 0xc0U) == 0xc0U))
  142. #endif /* _FNET_IP6_H_ */