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.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
thread_joiner_application.h
00001 /* 00002 * Copyright (c) 2015-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 * Joiner application starts the commisioning and saves the Static configuration of thread network 00032 * to nvm to recover from restart. 00033 */ 00034 00035 00036 #ifndef THREAD_JOINER_APPLICATION_H_ 00037 #define THREAD_JOINER_APPLICATION_H_ 00038 #include <ns_types.h> 00039 00040 struct link_configuration; 00041 00042 #define TRACE_GROUP_THREAD_JOINER_APPLICATION "TjoA" 00043 00044 /** Initialise thread Joiner application. 00045 * 00046 * This instance needs to bee initialised once for each thread network interface. 00047 * if only one thread instance is supported this is needed to call only once. 00048 * 00049 * /param interface interface id of this thread instance. 00050 * /param device_configuration_ptr Device configuration settings for application provisioning. 00051 * /param default_configuration_ptr Default configuration used if not other configuration available. 00052 * 00053 */ 00054 int thread_joiner_application_init(int8_t interface_id, device_configuration_s *device_configuration_ptr, struct link_configuration *default_configuration_ptr); 00055 00056 /** Delete Joiner application. 00057 * 00058 * /param interface interface id of this thread instance. 00059 */ 00060 void thread_joiner_application_deinit(int8_t interface_id); 00061 00062 /** Get configuration 00063 * 00064 * /param interface interface id of this thread instance. 00065 * 00066 */ 00067 struct link_configuration *thread_joiner_application_get_config(int8_t interface_id); 00068 00069 uint64_t thread_joiner_application_active_timestamp_get(int8_t interface_id); 00070 uint8_t thread_joiner_application_security_policy_get(int8_t interface_id); 00071 void thread_joiner_application_active_timestamp_set(int8_t interface_id, uint64_t timestamp); 00072 uint8_t *thread_joiner_application_network_name_get(int8_t interface_id); 00073 uint8_t *thread_joiner_application_active_config_tlv_list_get(uint8_t interface_id, uint16_t *length); 00074 00075 uint8_t *thread_joiner_application_active_config_params_get(uint8_t interface_id, uint16_t *length); 00076 00077 /** Get device configuration 00078 * 00079 * /param interface interface id of this thread instance. 00080 * 00081 */ 00082 device_configuration_s *thread_joiner_application_get_device_config(int8_t interface_id); 00083 00084 /** Store link configuration settings to platform specific NVM. 00085 * 00086 * Note1. All platforms may not have support for NVM. 00087 * Note2. Store is asynchronous operation, this method makes a storing request that 00088 * will be completed in background. 00089 * 00090 * /param interface interface id of this thread instance. -1 if instance not initialized. 00091 * /param link_config Pointer to structure containing link configuration parameters 00092 * 00093 *\ return 0 if store request has been delivered to lower layers. 00094 *\ return -1 if store failed (store request not made) 00095 */ 00096 00097 uint8_t *thread_joiner_application_random_mac_get(int8_t interface_id); 00098 00099 uint8_t *thread_joiner_application_ml_eid_get(int8_t interface_id); 00100 00101 int thread_joiner_application_link_configuration_store(int8_t interface_id, link_configuration_s *link_config); 00102 00103 /** Delete link configuration from platform NVM 00104 * 00105 * Note1. All platforms may not have support for NVM. 00106 * Note2. Delete is asynchronous operation, this method makes a delete request that 00107 * will be completed on the background 00108 * 00109 * /param interface interface id of this thread instance. -1 if instance not initialized. 00110 * 00111 *\ return 0 if delete request has been delivered to lower layers. 00112 *\ return -1 if delete failed (delete request not made) 00113 */ 00114 int thread_joiner_application_link_configuration_delete(int8_t interface_id); 00115 00116 /** Check if link configuration settings should be loaded from NVM and make a read 00117 * request if settings needs to be loaded. 00118 * 00119 * /param interface interface id of this thread instance. 00120 * 00121 * /return true if read request is made, false otherwise 00122 */ 00123 bool thread_joiner_application_nvm_link_configuration_load(int8_t interface_id); 00124 00125 00126 /** Provisioning status of the device. 00127 * 00128 */ 00129 typedef enum { 00130 PROVISIONING_STATUS_NOT_DONE, 00131 PROVISIONING_STATUS_ONGOING, 00132 PROVISIONING_STATUS_REJECTED, 00133 PROVISIONING_STATUS_DONE, 00134 } thread_provisioning_status_e; 00135 00136 /** Set the provisioning status of the device. 00137 * 00138 * not done -> When commissioner attaches to network JOIN_APP.req is sent to commissioner 00139 * ongoing -> Waiting response to JOIN_APP.req message. 00140 * rejected -> Provisioning was attempted, but did not succeed. State will go back to not done after random period 00141 * done -> JOIN_APP.resp was received with accepted status. 00142 * 00143 * /param interface interface id of this thread instance. 00144 * /param status Current status of provisioning 00145 * 00146 */ 00147 int thread_joiner_application_provisioning_set(int8_t interface_id, thread_provisioning_status_e status); 00148 /** get the provisioning status of the device. 00149 * 00150 * /param interface interface id of this thread instance. 00151 * 00152 * /return true if application provisioning is done. 00153 */ 00154 thread_provisioning_status_e thread_joiner_application_provisioning_get(int8_t interface_id); 00155 00156 /** form thread network with randomized values. 00157 * 00158 * /param interface interface id of this thread instance. 00159 * /param commissioning_credentials_ptr commissioning credentials used to form the network 00160 * /param name_ptr ascii string for name of the network can be NULL 00161 * 00162 */ 00163 int thread_joiner_application_form_network(int8_t interface_id, uint8_t *commissioning_credentials_ptr, char *name_ptr); 00164 00165 /** Commissioning start. 00166 * 00167 * Start commissioning process to this network 00168 * 00169 * /param interface interface id of this thread instance. 00170 * 00171 */ 00172 int thread_joiner_application_pskd_commission_start(int8_t interface_id, uint8_t parent_address[16], uint16_t joiner_port, uint16_t panid, uint8_t xpanid[8], uint8_t channel, thread_commission_done_cb *done_cb); 00173 00174 /** One second ticker for delayed configurations. 00175 * 00176 * /param interface interface id of this thread instance. 00177 * 00178 */ 00179 void thread_joiner_application_seconds_timer(int8_t interface_id, uint32_t seconds); 00180 00181 /** Create new pending configuration. 00182 * 00183 * Cleans the previous pending configuration if it is present. 00184 * 00185 * /param interface interface id of this thread instance. 00186 * /param data_ptr Pointer to data that is included in the new pending set 00187 * /param data_len length of operational dataset that is used to generate the pending set 00188 * 00189 */ 00190 int thread_joiner_application_pending_config_create(int8_t interface_id, uint8_t *data_ptr, uint16_t data_len); 00191 00192 /** Checks if pending configuration is present. 00193 * 00194 * /param interface interface id of this thread instance. 00195 * 00196 */ 00197 bool thread_joiner_application_pending_config_exists(int8_t interface_id); 00198 /** get timestamp value of pending configuration. 00199 * 00200 * /param interface interface id of this thread instance. 00201 * 00202 */ 00203 uint64_t thread_joiner_application_pending_config_timestamp_get(int8_t interface_id); 00204 00205 /** Set pending timestamp value 00206 * 00207 * /param interface interface id of this thread instance. 00208 * /param timestamp timestamp value. 00209 * 00210 */ 00211 int thread_joiner_application_pending_config_timestamp_set(int8_t interface_id, uint64_t timestamp); 00212 00213 /** get pending timeout value. 00214 * 00215 * /param interface interface id of this thread instance. 00216 * 00217 * /return timeout in ms. 00218 * 00219 */ 00220 uint32_t thread_joiner_application_pending_config_timeout_get(int8_t interface_id); 00221 00222 /** Enable pending configuration. 00223 * 00224 * Pending configuration is taken in use after timeout. 00225 * 00226 * /param interface interface id of this thread instance. 00227 * /param timeout_in_ms Timeout value after which pending set is activated. 00228 * 00229 */ 00230 int thread_joiner_application_pending_config_enable(int8_t interface_id, uint32_t timeout_in_ms); 00231 00232 00233 /** delete pending configuration. 00234 * 00235 * Cleans the previous pending configuration if it is present. 00236 * 00237 * /param interface interface id of this thread instance. 00238 * 00239 */ 00240 void thread_joiner_application_pending_config_delete(int8_t interface_id); 00241 uint8_t *thread_joiner_application_pending_config_tlv_list_get(uint8_t interface_id, uint16_t *length); 00242 uint16_t thread_joiner_application_pending_config_length(uint8_t interface_id, uint8_t *req_tlv_ptr, uint8_t req_tlv_len, const uint8_t *ignored_tlv_ptr, uint8_t ignored_tlv_len); 00243 uint8_t *thread_joiner_application_pending_config_build(uint8_t interface_id, uint8_t *ptr, uint8_t *req_tlv_ptr, uint8_t req_tlv_len, const uint8_t *ignored_tlv_ptr, uint8_t ignored_tlv_len); 00244 void thread_joiner_application_pending_config_add_missing_fields(uint8_t interface_id); 00245 00246 /** 00247 * TODO still expirimental for Thread 1.1 00248 */ 00249 void thread_joiner_application_next_pending_config_save(int8_t interface_id); 00250 bool thread_joiner_application_next_pending_config_exists(int8_t interface_id); 00251 uint16_t thread_joiner_application_next_pending_config_length(int8_t interface_id); 00252 uint8_t *thread_joiner_application_next_pending_config_build(int8_t interface_id, uint8_t *ptr); 00253 void thread_joiner_application_next_pending_config_delete(int8_t interface_id); 00254 bool thread_joiner_application_pending_delay_timer_in_sync(int8_t interface_id); 00255 00256 00257 void thread_joiner_application_next_active_config_save(int8_t interface_id); 00258 bool thread_joiner_application_next_active_config_exists(int8_t interface_id); 00259 uint16_t thread_joiner_application_next_active_config_length(int8_t interface_id); 00260 uint8_t *thread_joiner_application_next_active_config_write(int8_t interface_id, uint8_t *ptr); 00261 void thread_joiner_application_next_active_config_delete(int8_t interface_id); 00262 00263 /**Activate old configuration. 00264 * 00265 * If we have old configuration that we can try to restore connectivity to old configuration is is started 00266 * 00267 * /param interface interface id of this thread instance. 00268 * 00269 */ 00270 int thread_joiner_application_old_config_activate(int8_t interface_id); 00271 00272 /**Delete old configuration. 00273 * 00274 * /param interface interface id of this thread instance. 00275 * 00276 */ 00277 void thread_joiner_application_old_config_delete(int8_t interface_id); 00278 00279 /**Create old configuration. 00280 * 00281 * If we have have an active configuration that we have to come back to then the active configuration can be saved 00282 * temporarily to old configuration 00283 * 00284 * /param interface interface id of this thread instance. 00285 * 00286 */ 00287 link_configuration_s *thread_joiner_application_old_config_create(int8_t interface_id); 00288 00289 /**Get old configuration. 00290 * 00291 * If we have have a saved old configuration then it can be retrieved 00292 * 00293 * /param interface interface id of this thread instance. 00294 * 00295 */ 00296 bool thread_joiner_application_old_config_exists(int8_t interface_id); 00297 00298 /** Saves the current configurations to NVM. 00299 * 00300 * /param interface interface id of this thread instance. 00301 * 00302 * /return 0 OK. 00303 * /return <0 Failure. 00304 * 00305 */ 00306 int thread_joiner_application_configuration_nvm_save(int8_t interface_id); 00307 00308 /** Update configuration from meshcop tlv message. 00309 * 00310 * /param interface interface id of this thread instance. 00311 * /param msg_ptr meshcop TLV message structure. 00312 * /param msg_len Length of message. 00313 * 00314 * /return 0 OK. 00315 * /return <0 Failure. 00316 * 00317 */ 00318 int thread_joiner_application_update_configuration(uint8_t interface_id, uint8_t *msg_ptr, uint16_t msg_len, bool include_missing_tlvs); 00319 00320 /** Calculate length of active/pending configuration dataset TLVs. 00321 * 00322 * /param link_configuration Link configuration used to build the message. 00323 * /param msg_ptr meshcop TLV message structure. 00324 * /param msg_len Length of message. 00325 * 00326 * /return length of the message. 00327 * /return <0 Failure. 00328 */ 00329 uint16_t thread_joiner_application_active_config_length(uint8_t interface_id, const uint8_t *req_tlv_ptr, uint8_t req_tlv_len, const uint8_t *ignored_tlv_ptr, uint8_t ignored_tlv_len); 00330 00331 /** build active/pending configuration dataset TLVs. 00332 * 00333 * /param link_configuration Link configuration used to build the message. 00334 * /param response_ptr meshcop TLV message structure. 00335 * /param tlv_list List of TLVs requested NULL if all wanted. 00336 * /param list_len length of tlv list. 00337 * 00338 * /return length of the message. 00339 * /return <0 Failure. 00340 */ 00341 00342 uint8_t *thread_joiner_application_active_config_write(uint8_t interface_id, uint8_t *ptr, const uint8_t *req_tlv_ptr, uint8_t req_tlv_len, const uint8_t *ignored_tlv_ptr, uint8_t ignored_tlv_len); 00343 00344 /** Calculate length of device configuration TLVs. 00345 * 00346 * /param device_configuration device configuration used to build the message. 00347 * 00348 * /return length of the message. 00349 * /return <0 Failure. 00350 */ 00351 int thread_joiner_application_device_configuration_length(device_configuration_s *device_configuration); 00352 00353 /** write device configuration TLVs. 00354 * 00355 * /param ptr pointer where to write message. 00356 * /param device_configuration device configuration used to build the message. 00357 * 00358 * /return length of the message. 00359 * /return <0 Failure. 00360 */ 00361 uint8_t *thread_joiner_application_device_configuration_build(uint8_t *ptr, device_configuration_s *device_configuration); 00362 00363 /** function to activate pending configuration if present 00364 */ 00365 void thread_joiner_pending_config_activate(int8_t interface_id); 00366 00367 /* MLE active configuration data set fields 00368 * 00369 */ 00370 extern const uint8_t mle_active_configuration_dataset_tlvs[]; 00371 00372 extern const uint8_t mle_pending_configuration_dataset_ignore_tlvs[]; 00373 00374 extern const uint8_t mle_active_configuration_dataset_ignore_tlvs[]; 00375 00376 uint8_t mle_active_configuration_dataset_tlvs_size(void); 00377 00378 uint8_t mle_active_configuration_dataset_ignore_tlvs_size(void); 00379 00380 uint8_t mle_pending_configuration_dataset_ignore_tlvs_size(void); 00381 00382 extern const uint8_t mle_pending_configuration_dataset_tlvs[]; 00383 00384 uint8_t mle_pending_configuration_dataset_tlvs_size(void); 00385 00386 extern const uint8_t pending_configuration_dataset_tlvs[]; 00387 00388 uint8_t pending_configuration_dataset_tlvs_size(void); 00389 00390 extern const uint8_t active_configuration_dataset_tlvs[]; 00391 00392 uint8_t active_configuration_dataset_tlvs_size(void); 00393 00394 extern const uint8_t entrust_dataset_tlvs[]; 00395 00396 uint8_t entrust_dataset_tlvs_size(void); 00397 00398 int joiner_application_security_done_cb(int8_t service_id, uint8_t address[16], uint8_t keyblock[40]); 00399 00400 int8_t thread_joiner_application_active_configuration_update(int8_t service_id, uint8_t *data_ptr, uint16_t data_len, const uint8_t *ignore_ptr, uint8_t ingore_len); 00401 00402 #endif /* THREAD_JOINER_APPLICATION_H_ */
Generated on Tue Jul 12 2022 13:54:58 by
1.7.2