EL4121 Embedded System / mbed-os

Dependents:   cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers thread_joiner_application.h Source File

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