Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers thread_network_data_lib.h Source File

thread_network_data_lib.h

00001 /*
00002  * Copyright (c) 2014-2018, Arm Limited and affiliates.
00003  * SPDX-License-Identifier: BSD-3-Clause
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holder nor the
00014  *    names of its contributors may be used to endorse or promote products
00015  *    derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 /*
00031  * \file thread_network_data_lib.h
00032  * \brief Add short description about this file!!!
00033  *
00034  */
00035 
00036 #ifndef THREAD_NETWOR_DATA_LIB_H_
00037 #define THREAD_NETWOR_DATA_LIB_H_
00038 #include "ns_types.h"
00039 
00040 /* Thread Network Data TLV types  */
00041 #define THREAD_NWK_DATA_TYPE_ROUTE (0 << 1)
00042 #define THREAD_NWK_DATA_TYPE_PREFIX (1 << 1)
00043 #define THREAD_NWK_DATA_TYPE_BORDER_ROUTER  (2 << 1)
00044 #define THREAD_NWK_DATA_TYPE_6LOWPAN_ID (3 << 1)
00045 #define THREAD_NWK_DATA_TYPE_COMMISSION_DATA (4 << 1)
00046 #define THREAD_NWK_DATA_TYPE_SERVICE_DATA (5 << 1)
00047 #define THREAD_NWK_DATA_TYPE_SERVER_DATA (6 << 1)
00048 
00049 #define THREAD_NWK_STABLE_DATA  0x01
00050 #define THREAD_NWK_DATA_TYPE_MASK  0xfe
00051 
00052 #define THREAD_NWK_CONTEXT_COMPRESS_ENABLED  0x10
00053 
00054 /* Bit shift for BorderRouterTLV (16-bit)*/
00055 #define THREAD_PRF_BIT_MOVE             14  /* Prf-bits */
00056 #define THREAD_P_PREFERRED_BIT_MOVE     13  /* P-bit */
00057 #define THREAD_P_SLAAC_BIT_MOVE         12  /* S-bit */
00058 #define THREAD_P_DHCP_BIT_MOVE          11  /* D-bit */
00059 #define THREAD_P_CONFIGURE_BIT_MOVE     10  /* C-bit */
00060 #define THREAD_P_DEF_ROUTE_BIT_MOVE     9   /* R-bit */
00061 #define THREAD_P_ON_MESH_BIT_MOVE       8   /* O-bit */
00062 #define THREAD_P_ND_DNS_BIT_MOVE        7   /* N-bit */
00063 #define THREAD_P_ND_RES_BIT_MOVE        6   /* First reserved bit */
00064 
00065 /* Bit shift for HasRouteTLV preference bit */
00066 #define THREAD_HAS_ROUTE_PRF_BIT_MOVE   6   /* Prf-bits */
00067 
00068 #define THREAD_TLV_NETWORK_NAME 3
00069 #define THREAD_TLV_COMMISSIONING_CREDENTIALS    4
00070 #define THREAD_TLV_COMMISSIONER_ID  10
00071 #define THREAD_TLV_COMMISSIONER_SESSION_ID  11
00072 #define THREAD_TLV_SECURITY_POLICY          12
00073 #define THREAD_TLV_COMMISSIONING_TIME_STAMP 14
00074 #define THREAD_TLV_JOINER_UDP_PORT          18
00075 #define THREAD_TLV_STEERING_DATA            8   //Optional
00076 #define THREAD_TLV_BORDER_ROUTER_LOCATOR    9           //optional
00077 
00078 typedef struct thread_network_data_tlv_buf_s {
00079     uint8_t   *dataPtr;  /** Allocated Pointer which need to be freed by library user  */
00080     uint8_t     length; /** Allocated Pointer data length  */
00081 } thread_network_data_tlv_buf_t;
00082 
00083 typedef struct thread_prefix_tlv_params_s {
00084     uint8_t   *routePrefixPtr;
00085     uint8_t     prefixLength;
00086 } thread_prefix_tlv_params_t;
00087 
00088 typedef struct thread_network_router_info_s {
00089     bool        stableData;
00090     uint16_t    router16BitSddress;
00091 } thread_network_router_info_s;
00092 
00093 typedef struct thread_network_context_info_s {
00094     bool stableData: 1;
00095     bool compress_supported: 1;
00096     unsigned cid: 4;
00097     uint8_t context_length;
00098 } thread_network_context_info_t;
00099 
00100 
00101 
00102 
00103 /**
00104  * Verify Network Data TLV data structure
00105  *
00106  * \param network_data_ptr pointer to Network Data TLV
00107  * \param network_data_length Data Length
00108  *
00109  * return 0, TLV  OK
00110  * return <0 TLV Malformed
00111  */
00112 int thread_network_data_malformed_check(uint8_t *network_data_ptr, uint16_t network_data_length);
00113 
00114 int thread_network_data_sub_tlv_malformed_check(uint8_t *network_data_ptr, uint8_t network_data_length);
00115 
00116 /**
00117  * Claculate Prefix bits to bytes count
00118  *
00119  * \param prefixLenInBits len in bits
00120  *
00121  * return Byte length
00122  */
00123 uint8_t prefixBits_to_bytes(uint8_t prefixLenInBits);
00124 
00125 uint8_t *thread_nd_commission_data_write_steering_data(uint8_t *ptr, const uint8_t *steeringData, uint8_t length);
00126 
00127 uint8_t *thread_nd_network_data_border_router_tlv_write(uint8_t *ptr, uint16_t routerId, uint16_t flags);
00128 
00129 uint8_t *thread_nd_network_data_has_route_tlv_write(uint8_t *ptr, uint16_t routerId, uint8_t prf);
00130 
00131 #endif /* THREAD_NETWOR_DATA_LIB_H_ */