Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers fnet_ip6.h Source File

fnet_ip6.h

00001 /**************************************************************************
00002 *
00003 * Copyright 2011-2016 by Andrey Butok. FNET Community.
00004 * Copyright 2008-2010 by Andrey Butok. Freescale Semiconductor, Inc.
00005 *
00006 ***************************************************************************
00007 *
00008 *  Licensed under the Apache License, Version 2.0 (the "License"); you may
00009 *  not use this file except in compliance with the License.
00010 *  You may obtain a copy of the License at
00011 *
00012 *  http://www.apache.org/licenses/LICENSE-2.0
00013 *
00014 *  Unless required by applicable law or agreed to in writing, software
00015 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00016 *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00017 *  See the License for the specific language governing permissions and
00018 *  limitations under the License.
00019 *
00020 **********************************************************************/
00021 /*!
00022 * @brief IPv6 protocol API.
00023 *
00024 ***************************************************************************/
00025 
00026 #ifndef _FNET_IP6_H_
00027 
00028 #define _FNET_IP6_H_
00029 
00030 /*! @addtogroup fnet_socket */
00031 /*! @{ */
00032 
00033 /**************************************************************************/ /*!
00034  * @brief 128-bit IPv6 address type.
00035  ******************************************************************************/
00036 FNET_COMP_PACKED_BEGIN
00037 /* 128-bit IP6 address */
00038 typedef union
00039 {
00040     fnet_uint8_t   addr[16];
00041     fnet_uint16_t  addr16[8];
00042     fnet_uint32_t  addr32[4];
00043 } fnet_ip6_addr_t;
00044 FNET_COMP_PACKED_END
00045 
00046 /**************************************************************************/ /*!
00047  * @brief   Size of the string buffer that will contain
00048  *          null-terminated ASCII string of an IPv6 address
00049  *          in standard ":" notation.
00050  * @see fnet_inet_ntop
00051  * @showinitializer
00052  ******************************************************************************/
00053 #define FNET_IP6_ADDR_STR_SIZE       sizeof("abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd")
00054 
00055 /*! @} */
00056 
00057 /******************************************************************
00058 * Constants
00059 *******************************************************************/
00060 #define FNET_IP6_HEADSIZE        40u     /* IPv6 Header size.  */
00061 
00062 #define FNET_IP6_DEFAULT_MTU     1280u   /* Minimum IPv6 datagram size which    
00063                                          * must be supported by all IPv6 hosts */
00064 
00065 /****************************************************************
00066  *
00067  * Helpful macros.
00068  *
00069  *****************************************************************/
00070 #define FNET_IP6_ADDR_INIT(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16)      \
00071     {{ (a1), (a2), (a3), (a4), (a5), (a6), (a7), (a8), (a9), (a10), (a11), (a12), (a13), (a14), (a15), (a16) }}
00072 
00073 /*
00074  * Definition of some useful macros to handle IP6 addresses
00075  */
00076 #define FNET_IP6_ADDR_ANY_INIT                      FNET_IP6_ADDR_INIT(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
00077 #define FNET_IP6_ADDR_LOOPBACK_INIT                 FNET_IP6_ADDR_INIT(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01)
00078 #define FNET_IP6_ADDR_NODELOCAL_ALLNODES_INIT       FNET_IP6_ADDR_INIT(0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01)
00079 #define FNET_IP6_ADDR_INTFACELOCAL_ALLNODES_INIT    FNET_IP6_ADDR_INIT(0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01)
00080 #define FNET_IP6_ADDR_LINKLOCAL_ALLNODES_INIT       FNET_IP6_ADDR_INIT(0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01)
00081 #define FNET_IP6_ADDR_LINKLOCAL_ALLROUTERS_INIT     FNET_IP6_ADDR_INIT(0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02)
00082 #define FNET_IP6_ADDR_LINKLOCAL_ALLV2ROUTERS_INIT   FNET_IP6_ADDR_INIT(0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16)
00083 #define FNET_IP6_ADDR_LINKLOCAL_PREFIX_INIT         FNET_IP6_ADDR_INIT(0xFE, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
00084 
00085 extern const fnet_ip6_addr_t fnet_ip6_addr_any;
00086 extern const fnet_ip6_addr_t fnet_ip6_addr_loopback;
00087 extern const fnet_ip6_addr_t fnet_ip6_addr_nodelocal_allnodes;
00088 extern const fnet_ip6_addr_t fnet_ip6_addr_linklocal_allnodes;
00089 extern const fnet_ip6_addr_t fnet_ip6_addr_linklocal_allrouters;
00090 extern const fnet_ip6_addr_t fnet_ip6_addr_linklocal_allv2routers;
00091 extern const fnet_ip6_addr_t fnet_ip6_addr_linklocal_prefix;
00092 
00093 /* Equality. */
00094 #define FNET_IP6_ADDR_EQUAL(a, b)           \
00095     ((fnet_memcmp(&(a)->addr[0], &(b)->addr[0], sizeof(fnet_ip6_addr_t)) == 0)?FNET_TRUE:FNET_FALSE)
00096 
00097 /* Copying address. */
00098 #define FNET_IP6_ADDR_COPY(from_addr, to_addr)  \
00099     (fnet_memcpy(&(to_addr)->addr[0], &(from_addr)->addr[0], sizeof(fnet_ip6_addr_t)))
00100 
00101 /* Unspecified.*/
00102 #define FNET_IP6_ADDR_IS_UNSPECIFIED(a) \
00103     (((((a)->addr32[0]) == 0U) &&   \
00104       (((a)->addr32[1]) == 0U) &&   \
00105       (((a)->addr32[2]) == 0U) &&   \
00106       (((a)->addr32[3]) == 0U))?FNET_TRUE:FNET_FALSE)
00107 
00108 /* Loopback.*/
00109 #define FNET_IP6_ADDR_IS_LOOPBACK(a)    \
00110     ((((a)->addr32[0]) == 0U) &&    \
00111      (((a)->addr32[1]) == 0U) &&    \
00112      (((a)->addr32[2]) == 0U) &&    \
00113      (((a)->addr32[3]) == FNET_NTOHL(1U)))
00114 
00115 /* Multicast. */
00116 #define FNET_IP6_ADDR_IS_MULTICAST(a)   ((((a)->addr[0]) == 0xffU)?FNET_TRUE:FNET_FALSE)
00117 
00118 /* Unicast Scope.*/
00119 #define FNET_IP6_ADDR_IS_LINKLOCAL(a)   \
00120     ((((a)->addr[0]) == 0xfeU) && ((((a)->addr[1]) & 0xc0U) == 0x80U))
00121 #define FNET_IP6_ADDR_IS_SITELOCAL(a)   \
00122     ((((a)->addr[0]) == 0xfeU) && ((((a)->addr[1]) & 0xc0U) == 0xc0U))
00123 
00124 #endif  /* _FNET_IP6_H_ */