Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of OmniWheels by
thread_meshcop_lib.h
00001 /* 00002 * Copyright (c) 2015-2017, 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_meshcop_lib.h 00032 * \brief Public API to handle the Thread management framework message parsing and building. 00033 * 00034 */ 00035 00036 #ifndef THREAD_MESHCOP_LIB_H_ 00037 #define THREAD_MESHCOP_LIB_H_ 00038 00039 #include "ns_types.h" 00040 00041 /** 00042 * TLV Types used in thread network 00043 */ 00044 /** 00045 * Network configuration TLV 00046 */ 00047 /** Channel TLV. */ 00048 #define MESHCOP_TLV_CHANNEL 0 00049 /** PANID TLV. */ 00050 #define MESHCOP_TLV_PANID 1 00051 /** Extended PANID TLV. */ 00052 #define MESHCOP_TLV_XPANID 2 00053 /** Network Name TLV. */ 00054 #define MESHCOP_TLV_NETWORK_NAME 3 00055 /** PSKc TLV. */ 00056 #define MESHCOP_TLV_PSKC 4 00057 /** Network Master key TLV. */ 00058 #define MESHCOP_TLV_NETWORK_MASTER_KEY 5 00059 /** Network Key Sequence TLV. */ 00060 #define MESHCOP_TLV_NETWORK_KEY_SEQUENCE 6 00061 /** Mesh Local Ula prefix TLV. */ 00062 #define MESHCOP_TLV_NETWORK_MESH_LOCAL_ULA 7 00063 00064 /** 00065 * Network management TLV 00066 */ 00067 /** Steering data TLV. */ 00068 #define MESHCOP_TLV_STEERING_DATA 8 00069 /** Border router locator TLV. */ 00070 #define MESHCOP_TLV_BORDER_ROUTER_LOCATOR 9 00071 /** Commissioner ID TLV. */ 00072 #define MESHCOP_TLV_COMMISSIONER_ID 10 00073 /** Commissioner session ID TLV. */ 00074 #define MESHCOP_TLV_COMMISSIONER_SESSION_ID 11 00075 /** Security Policy TLV. */ 00076 #define MESHCOP_TLV_SECURITY_POLICY 12 00077 /** GET TLV. */ 00078 #define MESHCOP_TLV_GET 13 00079 /** Active Timestamp TLV. */ 00080 #define MESHCOP_TLV_ACTIVE_TIME_STAMP 14 00081 /** Commissioner UDP port TLV. */ 00082 #define MESHCOP_TLV_COMMISSIONER_UDP_PORT 15 00083 /** state TLV. */ 00084 #define MESHCOP_TLV_STATE 16 00085 /** Joiner UDP port TLV. */ 00086 #define MESHCOP_TLV_JOINER_UDP_PORT 18 00087 00088 /** 00089 * Network management TLV specific bit defines 00090 */ 00091 #define MESHCOP_TLV_ACTIVE_TIME_STAMP_U_BIT 0x01 00092 00093 /** 00094 * Relay message TLV 00095 */ 00096 /** Joiner Encapsulation TLV. */ 00097 #define MESHCOP_TLV_JOINER_ENCAPSULATION 17 00098 /** Joiner UDP port TLV. */ 00099 #define MESHCOP_TLV_JOINER_UDP_PORT 18 00100 /** Joiner IID TLV. */ 00101 #define MESHCOP_TLV_JOINER_IID 19 00102 /** Joiner Router locator TLV. */ 00103 #define MESHCOP_TLV_JOINER_ROUTER_LOCATOR 20 00104 /** Key Exchange Key TLV. */ 00105 #define MESHCOP_TLV_JOINER_ROUTER_KEK 21 00106 00107 /** 00108 * Application provisioning TLVs 00109 */ 00110 /** Provisioning URL TLV. */ 00111 #define MESHCOP_TLV_PROVISIONING_URL 32 00112 /** Vendr Name TLV. */ 00113 #define MESHCOP_TLV_VENDOR_NAME 33 00114 /** Vendor Model TLV. */ 00115 #define MESHCOP_TLV_VENDOR_MODEL 34 00116 /** Vendor SW version TLV. */ 00117 #define MESHCOP_TLV_VENDOR_SW_VERSION 35 00118 /** Vendor Data TLV. */ 00119 #define MESHCOP_TLV_VENDOR_DATA 36 00120 /** Vendor Stack Version TLV. */ 00121 #define MESHCOP_TLV_VENDOR_STACK_VERSION 37 00122 00123 /** 00124 * Tunneling 00125 */ 00126 /** UDP encapsulation TLV. */ 00127 #define MESHCOP_TLV_UDP_ENCAPSULATION 48 00128 /** IPv6 address TLV. */ 00129 #define MESHCOP_TLV_IPV6_ADDRESS 49 00130 /** TMF Forwarding Port TLV. */ 00131 #define MESHCOP_TLV_TMF_FORWARDING_PORT 50 00132 00133 /** 00134 * Thread management interface TLVs 00135 */ 00136 /** Pending Timestamp TLV. */ 00137 #define MESHCOP_TLV_PENDING_TIMESTAMP 51 00138 /** Delay timer for pending configuration TLV. */ 00139 #define MESHCOP_TLV_DELAY_TIMER 52 00140 /** Channel mask TLV. */ 00141 #define MESHCOP_TLV_CHANNEL_MASK 53 00142 /** Count TLV. */ 00143 #define MESHCOP_TLV_COUNT 54 00144 /** Period TLV. */ 00145 #define MESHCOP_TLV_PERIOD 55 00146 /** Duration TLV. */ 00147 #define MESHCOP_TLV_DURATION 56 00148 /** Energy List TLV. */ 00149 #define MESHCOP_TLV_ENERGY_LIST 57 00150 00151 /** Discovery Request TLV. */ 00152 #define MESHCOP_TLV_DISCOVERY_REQUEST 128 00153 /** Discovery response TLV. */ 00154 #define MESHCOP_TLV_DISCOVERY_RESPONSE 129 00155 00156 /** 00157 * Write array TLV. 00158 * 00159 * \param ptr pointer for array where to write the TLV. 00160 * \param type Type of TLV. 00161 * \param length length of the data that is written in TLV. 00162 * \param data array for TLV value. 00163 * 00164 * \return pointer value for writing the next TLV. 00165 */ 00166 uint8_t *thread_meshcop_tlv_data_write(uint8_t *ptr, const uint8_t type, const uint16_t length, const uint8_t *data); 00167 00168 /** 00169 * Write header. 00170 * 00171 * \param ptr pointer for array where to write the TLV. 00172 * \param type Type of TLV. 00173 * \param length length of the data that is written in TLV. 00174 * 00175 * \return pointer value for writing the remaining bytes of network data. 00176 */ 00177 uint8_t *thread_meshcop_tlv_data_write_header(uint8_t *ptr, uint8_t type, uint16_t length); 00178 00179 /** 00180 * Write 1 byte length TLV. 00181 * 00182 * \param ptr pointer for array where to write the TLV. 00183 * \param type Type of TLV. 00184 * \param data value. 00185 * 00186 * \return pointer value for writing the next TLV. 00187 */ 00188 uint8_t *thread_meshcop_tlv_data_write_uint8(uint8_t *ptr, const uint8_t type, const uint8_t data); 00189 00190 /** 00191 * Write 2 byte length TLV. 00192 * 00193 * \param ptr pointer for array where to write the TLV. 00194 * \param type Type of TLV. 00195 * \param data value. 00196 * 00197 * \return pointer value for writing the next TLV. 00198 */ 00199 uint8_t *thread_meshcop_tlv_data_write_uint16(uint8_t *ptr, const uint8_t type, const uint16_t data); 00200 00201 /** 00202 * Write 4 byte length TLV. 00203 * 00204 * \param ptr pointer for array where to write the TLV. 00205 * \param type Type of TLV. 00206 * \param data value. 00207 * 00208 * \return pointer value for writing the next TLV. 00209 */ 00210 uint8_t *thread_meshcop_tlv_data_write_uint32(uint8_t *ptr, const uint8_t type, const uint32_t data); 00211 00212 /** 00213 * Write 8 byte length TLV. 00214 * 00215 * \param ptr pointer for array where to write the TLV. 00216 * \param type Type of TLV. 00217 * \param data value. 00218 * 00219 * \return pointer value for writing the next TLV. 00220 */ 00221 uint8_t *thread_meshcop_tlv_data_write_uint64(uint8_t *ptr, const uint8_t type, const uint64_t data); 00222 00223 /** 00224 * Check if TLV exists in the message. 00225 * 00226 * \param ptr Message buffer. 00227 * \param length Length of the message buffer to validate message. 00228 * \param type Type of TLV searched. 00229 * 00230 * \return true if TLV is found. 00231 * \return false if TLV does not exist. 00232 */ 00233 bool thread_meshcop_tlv_exist(const uint8_t *ptr, const uint16_t length, const uint8_t type); 00234 00235 /** 00236 * Find TLV from message. 00237 * 00238 * \param ptr Message buffer. 00239 * \param length Length of the message buffer to validate message. 00240 * \param type Type of TLV searched. 00241 * \param result_ptr Pointer value is given as result if length is positive. Can be NULL which only searches for the length. 00242 * 00243 * \return The length of the TLV data found 00244 * \return 0 if TLV is empty or no TLV found. 00245 * \return negative value indicates corrupted message. 00246 */ 00247 uint16_t thread_meshcop_tlv_find(const uint8_t *ptr, const uint16_t length, const uint8_t type, uint8_t **result_ptr); 00248 00249 /** 00250 * Get length of the TLV. 00251 * 00252 * \param ptr Message buffer. 00253 * \param length Length of the message buffer to validate message. 00254 * 00255 * \return The length of the TLV data found 00256 * \return 0 if TLV is empty. 00257 * \return negative value indicates corrupted message or no TLV present. 00258 */ 00259 int16_t thread_meshcop_tlv_length(const uint8_t *ptr, uint16_t length); 00260 00261 /** 00262 * Get length of the TLV including the type and length field. 00263 * 00264 * \param ptr Message buffer. 00265 * \param length Length of the message buffer to validate message. 00266 * 00267 * \return The length of the TLV data found 00268 * \return 0 if TLV is empty. 00269 * \return negative value indicates corrupted message or no TLV present. 00270 */ 00271 int16_t thread_meshcop_tlv_length_required(const uint8_t *ptr, uint16_t length); 00272 00273 /** 00274 * Go through TLV list in order. 00275 * 00276 * \param ptr Message buffer. 00277 * \param length Length of the message buffer to validate message. Length value modified to remaining value or 0 when no more TLVs present 00278 * 00279 * \return ptr to the next TLV 00280 * \return NULL if no TLV found. 00281 */ 00282 const uint8_t *thread_meshcop_tlv_get_next(const uint8_t *ptr, uint16_t *length); 00283 00284 /** 00285 * Validate that required TLVs are present in the buffer. 00286 * 00287 * \param ptr TLV message buffer. 00288 * \param length Length of the TLV message buffer. 00289 * \param required_tlv_ptr buffer where the IDs of TLVs that are must be present 00290 * \param required_tlv_len Amount of TLVs 00291 * 00292 * \return amount of TLVs present in the buffer. 00293 */ 00294 bool thread_meshcop_tlv_list_present(const uint8_t *ptr, uint16_t length, const uint8_t *required_tlv_ptr, uint8_t required_tlv_len); 00295 00296 /** 00297 * Get list of TLVS included in the buffer. 00298 * 00299 * \param ptr TLV message buffer. 00300 * \param length Length of the TLV message buffer. 00301 * \param result_ptr [OUT] buffer where the IDs of TLVs are written. can be NULL when counting amount of TLVs 00302 * \param result_len [OUT] Amount of TLVs written in buffer 00303 * 00304 * \return amount of TLVs present in the buffer. 00305 */ 00306 uint16_t thread_meshcop_tlv_list_generate(const uint8_t *ptr, uint16_t length,uint8_t *result_ptr, uint16_t *result_len); 00307 00308 /** 00309 * Remove TLV from list of TLVs. 00310 * 00311 * \param tlv_ptr pointer to TLV List buffer. 00312 * \param tlv_len Length of the TLV list buffer. 00313 * \param tlv_type TLV that is removed from the List 00314 * 00315 * \return amount of TLVs present in the buffer. 00316 */ 00317 uint16_t thread_meshcop_tlv_list_remove(uint8_t *tlv_ptr, uint16_t tlv_len, uint8_t tlv_type); 00318 00319 /** 00320 * Check if specific type is available in list of TLVs. 00321 * 00322 * \param list_ptr Pointer to TLV list buffer. 00323 * \param list_len Length of the TLV list buffer. 00324 * \param tlv_type TLV type to be find from the list 00325 * 00326 * \return true if type exists, false if type does not exist. 00327 */ 00328 bool thread_meshcop_tlv_list_type_available(const uint8_t *list_ptr, uint16_t list_len, uint8_t tlv_type); 00329 00330 /** 00331 * Find next TLV from message. 00332 * 00333 * \param tlv_ba TLV message buffer. 00334 * \param tlv_ba_length Length of the TLV message buffer. 00335 * \param tlv_id ID of the TLV to be searched. 00336 * \param found_tlv [IN] Pointer value is given as result if length is > 0. Can be NULL which only searches for the length. 00337 * \ [OUT] Pointer to previous TLV found 00338 * 00339 * \return The length of the TLV data found and found_tlv updated to point beginning of value field. 0 if TLV is not found. 00340 */ 00341 uint16_t thread_meshcop_tlv_find_next(uint8_t* tlv_ba, uint16_t tlv_ba_length, uint8_t tlv_id, uint8_t** found_tlv); 00342 00343 /** 00344 * Read 1 byte length TLV. 00345 * 00346 * \param ptr pointer TLV message array. 00347 * \param length length of TLV message array. 00348 * \param type Type of TLV. 00349 * \param data_ptr pointer to variable where the value is read. 00350 * 00351 * \return pointer length of TLV 1 if success. 0 means TLV not found or does not have any data. 00352 * \return Any other value indicates that TLV is not as expected. 00353 */ 00354 uint8_t thread_meshcop_tlv_data_get_uint8(const uint8_t *ptr, const uint16_t length, const uint8_t type, uint8_t *data_ptr); 00355 00356 /** 00357 * Read 2 byte length TLV. 00358 * 00359 * \param ptr pointer TLV message array. 00360 * \param length length of TLV message array. 00361 * \param type Type of TLV. 00362 * \param data_ptr pointer to variable where the value is read. 00363 * 00364 * \return pointer length of TLV 2 if success. 0 means TLV not found or does not have any data. 00365 * \return Any other value indicates that TLV is not as expected. 00366 */ 00367 uint8_t thread_meshcop_tlv_data_get_uint16(const uint8_t *ptr, const uint16_t length, const uint8_t type, uint16_t *data_ptr); 00368 00369 /** 00370 * Read 4 byte length TLV. 00371 * 00372 * \param ptr pointer TLV message array. 00373 * \param length length of TLV message array. 00374 * \param type Type of TLV. 00375 * \param data_ptr pointer to variable where the value is read. 00376 * 00377 * \return pointer length of TLV 4 if success. 0 means TLV not found or does not have any data. 00378 * \return Any other value indicates that TLV is not as expected. 00379 */ 00380 uint8_t thread_meshcop_tlv_data_get_uint32(const uint8_t *ptr, const uint16_t length, const uint8_t type, uint32_t *data_ptr); 00381 00382 /** 00383 * Read 8 byte length TLV. 00384 * 00385 * \param ptr pointer TLV message array. 00386 * \param length length of TLV message array. 00387 * \param type Type of TLV. 00388 * \param data_ptr pointer to variable where the value is read. 00389 * 00390 * \return pointer length of TLV 4 if success. 0 means TLV not found or does not have any data. 00391 * \return Any other value indicates that TLV is not as expected. 00392 */ 00393 uint8_t thread_meshcop_tlv_data_get_uint64(const uint8_t *ptr, const uint16_t length, const uint8_t type, uint64_t *data_ptr); 00394 00395 #endif /* THREAD_MESHCOP_LIB_H_ */
Generated on Fri Jul 22 2022 04:54:03 by
 1.7.2
 1.7.2 
    