BA
/
BaBoRo1
Embed:
(wiki syntax)
Show/hide line numbers
thread_bootstrap.h
00001 /* 00002 * Copyright (c) 2014-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_bootstrap.h 00032 * \brief Add short description about this file!!! 00033 * 00034 */ 00035 00036 #ifndef THREAD_BOOTSTRAP_H_ 00037 #define THREAD_BOOTSTRAP_H_ 00038 00039 #include "eventOS_event.h" 00040 #include "net_polling_api.h" 00041 #include "Service_Libs/mle_service/mle_service_api.h" 00042 00043 #define THREAD_NETWORK_ACTIVE_SCAN_COUNTER 3 00044 /** Thread Attach Retry limiters */ 00045 #define THREAD_CHILD_ID_REQUEST_MAX_RETRY_CNT 3 00046 #define THREAD_PARENT_REQUEST_MAX_RETRY_CNT 2 00047 #define THREAD_REQUEST_MAX_RETRY_CNT 3 00048 00049 #define THREAD_CHILD_ID_TIMEOUT (2 * 1000) /* 2 second */ 00050 00051 struct thread_info_s; 00052 struct protocol_interface_info_entry; 00053 struct thread_leader_data_s; 00054 struct link_configuration; 00055 struct mle_neigh_table_entry_t; 00056 struct mle_tlv_info_s; 00057 00058 typedef enum { 00059 CON_ERROR_POLL, 00060 CON_ERROR_LINK_TX_FAIL, 00061 CON_ERROR_NO_THREAD_NETWORK_AVAILABLE, 00062 CON_ERROR_NEIGHBOR_UNREACHABLE, 00063 CON_ERROR_NETWORK_KICK, 00064 CON_ERROR_NETWORK_REATTACH, 00065 CON_ERROR_PARTITION_MERGE, 00066 CON_ERROR_NETWORK_ATTACH_FAIL, 00067 CON_PARENT_CONNECT_DOWN 00068 } nwk_connect_error_types; 00069 00070 00071 typedef enum { 00072 THREAD_INIT_EVENT = 0, /**< Initialize Thread Tasklet*/ 00073 THREAD_CHILD_UPDATE, 00074 THREAD_BOOTSTRAP_RESET, 00075 THREAD_ATTACH_READY, 00076 THREAD_ATTACH_UPGRADE_REED, 00077 THREAD_ATTACH_DOWNGRADE_ROUTER, 00078 THREAD_ATTACH_ACTIVE_ROUTER, 00079 THREAD_ATTACH_ROUTER_ID_GET_FAIL, 00080 THREAD_ATTACH_ROUTER_ID_RELEASED, 00081 THREAD_CHILD_ID_REQUEST, 00082 THREAD_ANNOUNCE_ACTIVE 00083 00084 } thread_bootsrap_event_type_e; 00085 00086 typedef enum { 00087 THREAD_NORMAL_ATTACH = 0, 00088 THREAD_REATTACH, 00089 THREAD_REATTACH_REED, 00090 THREAD_PARTITION_MERGE, 00091 THREAD_ANY_ATTACH 00092 } thread_bootsrap_state_type_e; 00093 00094 #ifdef HAVE_THREAD 00095 00096 /** Reset bootstrap and start using new settings 00097 */ 00098 void thread_bootstrap_reset_restart(int8_t interface); 00099 00100 /* removes child id when becoming router*/ 00101 00102 uint8_t thread_mode_get_by_interface_ptr(struct protocol_interface_info_entry *cur); 00103 void thread_bootstrap_device_synch_finish(protocol_interface_info_entry_t *cur); 00104 int8_t thread_mle_class_init(int8_t interface_id); 00105 void thread_general_mle_receive_cb(int8_t interface_id, mle_message_t *mle_msg, mle_security_header_t *security_headers); 00106 int thread_bootstrap_reset_child_info(protocol_interface_info_entry_t *cur, struct mle_neigh_table_entry_t *child); 00107 void thread_bootstrap_ready(struct protocol_interface_info_entry *cur); 00108 int thread_bootstrap_reset(struct protocol_interface_info_entry *cur); 00109 void thread_clean_all_routers_from_neighbor_list(int8_t interface_id); 00110 bool thread_bootstrap_request_network_data(struct protocol_interface_info_entry *cur, struct thread_leader_data_s *leaderData, uint16_t short_address); 00111 bool thread_check_is_this_my_parent(struct protocol_interface_info_entry *cur, struct mle_neigh_table_entry_t *entry_temp); 00112 void thread_clean_old_16_bit_address_based_addresses(struct protocol_interface_info_entry *cur); 00113 int8_t thread_bootsrap_event_trig(thread_bootsrap_event_type_e event_type, int8_t Id, arm_library_event_priority_e priority); 00114 void thread_interface_init(struct protocol_interface_info_entry *cur); 00115 00116 /* 00117 * Thread bootstrap layer configurations 00118 */ 00119 int thread_configuration_mac_activate(protocol_interface_info_entry_t *cur, uint16_t channel, uint16_t panid, uint8_t *extended_random_mac); 00120 int thread_configuration_6lowpan_activate(protocol_interface_info_entry_t *cur ); 00121 int thread_configuration_mle_activate(protocol_interface_info_entry_t *cur); 00122 int thread_configuration_mle_disable(protocol_interface_info_entry_t *cur); 00123 int thread_configuration_thread_activate(protocol_interface_info_entry_t *cur, link_configuration_s *linkConfiguration ); 00124 int thread_link_configuration_activate(struct protocol_interface_info_entry *cur, struct link_configuration *linkConfiguration); 00125 int thread_parent_discover_start(int8_t interface_id, uint8_t *mac64 ); 00126 00127 bool thread_device_synch_timeout(int8_t interface_id, uint16_t msgId, bool usedAllRetries); 00128 bool thread_link_request_timeout(int8_t interface_id, uint16_t msgId, bool usedAllRetries); 00129 bool thread_instance_id_matches(struct protocol_interface_info_entry *cur, struct thread_leader_data_s *leaderData); 00130 int thread_leader_data_validation(struct protocol_interface_info_entry *cur, struct thread_leader_data_s *leaderData, struct mle_tlv_info_s *routeTlv); 00131 uint8_t thread_calculate_link_margin(int8_t dbm, uint8_t compLinkMarginFromParent); 00132 uint8_t thread_compute_link_margin(int8_t rssi); 00133 uint8_t thread_parent_margin_calc(uint8_t marginFromParent, uint8_t marginToParent); 00134 void thread_bootstrap_parent_network_data_request(struct protocol_interface_info_entry *cur, bool delay_request); 00135 void thread_generate_ml64_address(struct protocol_interface_info_entry *cur); 00136 void thread_delete_ml64_address(struct protocol_interface_info_entry *cur); 00137 void thread_delete_ml16_addresses(protocol_interface_info_entry_t *cur); 00138 void thread_generate_ml16_address(struct protocol_interface_info_entry *cur); 00139 int thread_bootstrap_tasklet_init(struct protocol_interface_info_entry *cur); 00140 void thread_bootstrap_stop(struct protocol_interface_info_entry *cur); 00141 void thread_interface_up(struct protocol_interface_info_entry *cur); 00142 void thread_bootstrap_state_machine(struct protocol_interface_info_entry *cur); 00143 void thread_bootsrap_device_synch_fail(struct protocol_interface_info_entry *cur); 00144 void thread_bootstrap_attached_downgrade_router(struct protocol_interface_info_entry *cur); 00145 void thread_bootstrap_attched_upgrade_reed(struct protocol_interface_info_entry *cur); 00146 void thread_bootstrap_attached_ready(struct protocol_interface_info_entry *cur); 00147 void thread_bootstrap_router_synch_ready(protocol_interface_info_entry_t *cur); 00148 void thread_bootstrap_attached_active_router(struct protocol_interface_info_entry *cur); 00149 void thread_bootstrap_router_id_get_fail(struct protocol_interface_info_entry *cur); 00150 void thread_bootstrap_router_id_release_ready(struct protocol_interface_info_entry *cur); 00151 int8_t thread_bootstrap_child_id_request(struct protocol_interface_info_entry *cur); 00152 void thread_bootstrap_child_update_trig(struct protocol_interface_info_entry *cur); 00153 void thread_bootstrap_connection_error(int8_t interface_id, nwk_connect_error_types errorType, uint8_t *LinkId); 00154 int8_t nwk_thread_host_control(struct protocol_interface_info_entry *cur, enum net_host_mode mode, uint32_t delay); 00155 void thread_bootstrap_routing_activate(protocol_interface_info_entry_t *cur); 00156 void thread_end_device_mode_set(protocol_interface_info_entry_t *cur, bool sleepy); 00157 int8_t thread_network_data_save_after_sync(protocol_interface_info_entry_t *cur, uint8_t address[16], thread_leader_data_t *leader_data, uint8_t *commission_tlv_ptr, uint16_t commission_tlv_len); 00158 int8_t thread_active_configuration_dataset_query_done(protocol_interface_info_entry_t *cur); 00159 int8_t thread_active_configuration_dataset_query_clean(protocol_interface_info_entry_t *cur); 00160 void thread_bootstrap_mac_activate(protocol_interface_info_entry_t *cur, uint16_t channel, uint16_t panid, bool coordinator); 00161 int thread_bootstrap_network_data_process(protocol_interface_info_entry_t *cur, uint8_t *network_data_ptr, uint16_t network_data_length); 00162 int thread_bootstrap_network_data_activate(protocol_interface_info_entry_t *cur); 00163 int thread_bootstrap_network_data_save(struct protocol_interface_info_entry *cur, thread_leader_data_t *leader_data, uint8_t* network_data_ptr, uint16_t network_data_len); 00164 void thread_bootstrap_network_prefixes_process(struct protocol_interface_info_entry *cur); 00165 void thread_bootstrap_network_data_update(protocol_interface_info_entry_t *cur); 00166 bool thread_bootstrap_link_create_check(protocol_interface_info_entry_t *interface, uint16_t short_address); 00167 bool thread_bootstrap_link_create_allowed(protocol_interface_info_entry_t *interface, uint16_t short_address, const uint8_t *src_addr); 00168 bool thread_bootstrap_should_register_address(protocol_interface_info_entry_t *cur); 00169 bool thread_tlv_request(int8_t interface_id, uint8_t *address, bool delayed_message, uint8_t *req_tlv, uint8_t req_len); 00170 void thread_bootstrap_clear_neighbor_entries(protocol_interface_info_entry_t *cur); 00171 void thread_bootstrap_dynamic_configuration_save(protocol_interface_info_entry_t *cur); 00172 void thread_bootstrap_update_ml16_address(protocol_interface_info_entry_t *cur, uint16_t mac16); 00173 void thread_bootstrap_pending_configuration_save(protocol_interface_info_entry_t *cur); 00174 void thread_bootstrap_all_nodes_address_generate(uint8_t multicast_address[16],uint8_t prefix[8], uint8_t scope); 00175 /** 00176 * Check advertisement or parent response is from a singleton partition and decide on accepting or dropping the packet 00177 * 00178 * \param cur protocol_interface_info_entry_t 00179 * \param heard_partition_routers number of routers in heard advertisement or parent response 00180 * \param heard_partition_leader_data leader data of the partition heard 00181 * \param routeTlv route TLV of heard advertisement or NULL if there the comparison is between parent responses 00182 * 00183 * return 2 merge has to be triggered based on the singleton partition rules or parent response should be accepted 00184 * return -2 no merge needs to be triggered or parent response can be dropped 00185 */ 00186 00187 int thread_bootstrap_partition_process(protocol_interface_info_entry_t *cur,uint8_t heard_partition_routers,thread_leader_data_t *heard_partition_leader_data, mle_tlv_info_t *routeTlv); 00188 00189 /* 00190 * Thread announcement control functions 00191 */ 00192 int thread_bootstrap_announce_send(protocol_interface_info_entry_t *cur, uint8_t channel_page, uint16_t channel, uint16_t panid, uint64_t timestamp, uint16_t active_channel); 00193 void thread_bootstrap_announcement_start(protocol_interface_info_entry_t *cur, uint8_t channel_page, uint16_t channel, uint8_t count, uint16_t period); 00194 void thread_bootstrap_temporary_attach(protocol_interface_info_entry_t *cur, uint8_t channel_page, uint16_t channel, uint16_t panid, uint64_t timestamp); 00195 00196 00197 #else 00198 #define thread_interface_up(cur) ((void) 0) 00199 #define thread_bootstrap_state_machine(cur) ((void)0) 00200 #define thread_bootstrap_child_update_trig(cur) ((void)0) 00201 #define thread_bootstrap_connection_error(interface_id, errorType, LinkId) ((void)0) 00202 #define thread_bootstrap_network_data_update(cur,force_stable_update, force_unstable_update) ((void)0) 00203 #define thread_bootstrap_network_data_changed(cur,force_stable_update,force_unstable_update) ((void)0) 00204 #define thread_bootstrap_dynamic_configuration_save(cur) ((void)0) 00205 00206 #endif // HAVE_THREAD 00207 00208 #endif /* THREAD_BOOTSTRAP_H_ */
Generated on Tue Jul 12 2022 12:22:24 by
