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