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
net_rpl.c
00001 /* 00002 * Copyright (c) 2014-2019, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #include "nsconfig.h" 00019 #include "ns_types.h" 00020 #include <string.h> 00021 00022 #include "Core/include/ns_address_internal.h" 00023 #include "NWK_INTERFACE/Include/protocol.h" 00024 #include "6LoWPAN/Bootstraps/protocol_6lowpan.h" 00025 #include "RPL/rpl_protocol.h" 00026 #include "RPL/rpl_control.h" 00027 #include "RPL/rpl_data.h" 00028 00029 #include "net_rpl.h" 00030 00031 #ifdef HAVE_RPL 00032 00033 /** 00034 * \file net_rpl.c 00035 * \brief Router and Border Router RPL API. 00036 * 00037 * Rough backwards compatibility being roughly preserved with old RPL system 00038 */ 00039 00040 int8_t arm_nwk_6lowpan_rpl_dodag_init(int8_t interface_id, const uint8_t *dodag_id, const dodag_config_t *config, uint8_t instance_id, uint8_t flags) 00041 { 00042 (void)interface_id; 00043 00044 #ifdef HAVE_RPL_ROOT 00045 if (protocol_6lowpan_rpl_root_dodag) { 00046 return -1; 00047 } 00048 rpl_dodag_conf_t new_conf; 00049 new_conf.default_lifetime = config->LIFE_IN_SECONDS; 00050 new_conf.lifetime_unit = config->LIFETIME_UNIT; 00051 new_conf.dag_max_rank_increase = config->DAG_MAX_RANK_INC; 00052 new_conf.min_hop_rank_increase = config->DAG_MIN_HOP_RANK_INC; 00053 new_conf.dio_interval_min = config->DAG_DIO_INT_MIN; 00054 new_conf.dio_interval_doublings = config->DAG_DIO_INT_DOUB; 00055 new_conf.dio_redundancy_constant = config->DAG_DIO_REDU; 00056 new_conf.objective_code_point = config->DAG_OCP; 00057 new_conf.authentication = config->DAG_SEC_PCS & 8; 00058 new_conf.path_control_size = config->DAG_SEC_PCS & 7; 00059 rpl_data_init_root(); 00060 protocol_6lowpan_rpl_root_dodag = rpl_control_create_dodag_root(protocol_6lowpan_rpl_domain, instance_id, dodag_id, &new_conf, new_conf.min_hop_rank_increase, flags); 00061 if (!protocol_6lowpan_rpl_root_dodag) { 00062 return -2; 00063 } 00064 00065 /* Something of a hack - if we're root of a non-storing DODAG, disable hard 00066 * memory limits, and relax soft memory limit. Soft memory limit doesn't 00067 * really matter if we're just a border router - we won't have anything 00068 * freeable to keep under it anyway - but if there's another DODAG we may 00069 * find ourselves struggling to join it if RPL memory is full of our own 00070 * root storage. 00071 */ 00072 if ((flags & RPL_MODE_MASK) == RPL_MODE_NON_STORING) { 00073 rpl_control_set_memory_limits(64 * 1024, 0); 00074 } 00075 return 0; 00076 #else // !HAVE_RPL_ROOT 00077 (void)dodag_id; 00078 (void)config; 00079 (void)instance_id; 00080 (void)flags; 00081 00082 return -1; 00083 #endif 00084 } 00085 00086 int8_t arm_nwk_6lowpan_rpl_memory_limit_set(size_t soft_limit, size_t hard_limit) 00087 { 00088 if (hard_limit != 0 && soft_limit > hard_limit) { 00089 return -1; 00090 } 00091 00092 rpl_control_set_memory_limits(soft_limit, hard_limit); 00093 return 0; 00094 } 00095 00096 int8_t arm_nwk_6lowpan_rpl_dodag_remove(int8_t interface_id) 00097 { 00098 protocol_interface_info_entry_t *cur; 00099 cur = protocol_stack_interface_info_get_by_id(interface_id); 00100 if (!cur || !cur->rpl_domain) { 00101 return -1; 00102 } 00103 if (!protocol_6lowpan_rpl_root_dodag) { 00104 return -1; 00105 } 00106 rpl_control_delete_dodag_root(cur->rpl_domain, protocol_6lowpan_rpl_root_dodag); 00107 return -1; 00108 } 00109 00110 int8_t arm_nwk_6lowpan_rpl_dodag_start(int8_t interface_id) 00111 { 00112 protocol_interface_info_entry_t *cur; 00113 cur = protocol_stack_interface_info_get_by_id(interface_id); 00114 if (!cur || !cur->rpl_domain) { 00115 return -1; 00116 } 00117 rpl_control_force_leaf(cur->rpl_domain, false); 00118 return 0; 00119 } 00120 00121 int8_t arm_nwk_6lowpan_rpl_dodag_route_update(int8_t interface_id, uint8_t *route_ptr, uint8_t prefix_len, uint8_t flags, uint32_t lifetime) 00122 { 00123 (void)interface_id; 00124 00125 if (prefix_len && !route_ptr) { 00126 return -2; 00127 } 00128 if (!protocol_6lowpan_rpl_root_dodag) { 00129 return -1; 00130 } 00131 rpl_control_update_dodag_route(protocol_6lowpan_rpl_root_dodag, route_ptr, prefix_len, flags, lifetime, false); 00132 return 0; 00133 } 00134 00135 int8_t arm_nwk_6lowpan_rpl_dodag_prefix_update(int8_t interface_id, uint8_t *prefix_ptr, uint8_t prefix_len, uint8_t flags, uint32_t lifetime) 00136 { 00137 (void)interface_id; 00138 00139 if (prefix_len && !prefix_ptr) { 00140 return -2; 00141 } 00142 if (!protocol_6lowpan_rpl_root_dodag) { 00143 return -1; 00144 } 00145 rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, prefix_ptr, prefix_len, flags, lifetime, lifetime, false); 00146 return 0; 00147 } 00148 00149 00150 int8_t arm_nwk_6lowpan_rpl_dodag_poison(int8_t interface_id) 00151 { 00152 protocol_interface_info_entry_t *cur; 00153 cur = protocol_stack_interface_info_get_by_id(interface_id); 00154 if (!cur || !cur->rpl_domain) { 00155 return -1; 00156 } 00157 rpl_control_poison(cur->rpl_domain, 3 /* arbitrary poison count */); 00158 /* Make sure we send no more adverts after poison */ 00159 rpl_control_force_leaf(cur->rpl_domain, true); 00160 return 0; 00161 } 00162 00163 int8_t arm_nwk_6lowpan_rpl_dodag_dao_trig(int8_t interface_id) 00164 { 00165 /* New code version - specifying interface ID makes no sense - fudge to let it increase main RPL root */ 00166 protocol_interface_info_entry_t *cur; 00167 cur = protocol_stack_interface_info_get_by_id(interface_id); 00168 if (!cur || !cur->rpl_domain || cur->rpl_domain != protocol_6lowpan_rpl_domain || !protocol_6lowpan_rpl_root_dodag) { 00169 return -1; 00170 } 00171 00172 rpl_control_increment_dtsn(protocol_6lowpan_rpl_root_dodag); 00173 00174 return 0; 00175 } 00176 00177 int8_t arm_nwk_6lowpan_rpl_dodag_version_increment(int8_t interface_id) 00178 { 00179 /* New code version - specifying interface ID makes no sense - fudge to let it increase main RPL root */ 00180 protocol_interface_info_entry_t *cur; 00181 cur = protocol_stack_interface_info_get_by_id(interface_id); 00182 if (!cur || !cur->rpl_domain || cur->rpl_domain != protocol_6lowpan_rpl_domain || !protocol_6lowpan_rpl_root_dodag) { 00183 return -1; 00184 } 00185 00186 rpl_control_increment_dodag_version(protocol_6lowpan_rpl_root_dodag); 00187 00188 return 0; 00189 } 00190 00191 int8_t arm_nwk_6lowpan_rpl_dodag_pref_set(int8_t interface_id, uint8_t preference) 00192 { 00193 /* New code version - specifying interface ID makes no sense - fudge to let it increase main RPL root */ 00194 protocol_interface_info_entry_t *cur; 00195 cur = protocol_stack_interface_info_get_by_id(interface_id); 00196 if (!cur || !cur->rpl_domain || cur->rpl_domain != protocol_6lowpan_rpl_domain || !protocol_6lowpan_rpl_root_dodag) { 00197 return -1; 00198 } 00199 00200 if (preference > RPL_DODAG_PREF_MASK) { 00201 return -2; 00202 } 00203 00204 rpl_control_set_dodag_pref(protocol_6lowpan_rpl_root_dodag, preference); 00205 00206 return 0; 00207 } 00208 00209 uint8_t rpl_instance_list_read(uint8_t *buffer_ptr, uint8_t buffer_size) 00210 { 00211 uint8_t ret_val = 0; 00212 struct rpl_instance *instance = NULL; 00213 00214 if (!protocol_6lowpan_rpl_domain) { 00215 return 0; 00216 } 00217 00218 while (buffer_size) { 00219 instance = rpl_control_enumerate_instances(protocol_6lowpan_rpl_domain, instance); 00220 if (!instance) { 00221 break; 00222 } 00223 rpl_dodag_info_t dodag_info; 00224 if (rpl_control_read_dodag_info(instance, &dodag_info)) { 00225 /* First the instance ID */ 00226 *buffer_ptr++ = dodag_info.instance_id; 00227 buffer_size--; 00228 /* Then, if local, the DODAG ID */ 00229 if (rpl_instance_id_is_local(dodag_info.instance_id)) { 00230 if (buffer_size < 16) { 00231 break; 00232 } 00233 memcpy(buffer_ptr, dodag_info.dodag_id, 16); 00234 buffer_ptr += 16; 00235 buffer_size -= 16; 00236 } 00237 ret_val++; 00238 } 00239 } 00240 00241 return ret_val; 00242 } 00243 00244 uint8_t rpl_read_dodag_info(rpl_dodag_info_t *dodag_ptr, uint8_t instance_id) 00245 { 00246 if (!protocol_6lowpan_rpl_domain) { 00247 return 0; 00248 } 00249 00250 struct rpl_instance *instance = rpl_control_lookup_instance(protocol_6lowpan_rpl_domain, instance_id, dodag_ptr->dodag_id); 00251 if (!instance) { 00252 return 0; 00253 } 00254 return rpl_control_read_dodag_info(instance, dodag_ptr); 00255 } 00256 00257 00258 #else /* HAVE_RPL */ 00259 00260 int8_t arm_nwk_6lowpan_rpl_dodag_init(int8_t interface_id, const uint8_t *dodag_id, const dodag_config_t *config, uint8_t instance_id, uint8_t flags) 00261 { 00262 (void)interface_id; 00263 (void)dodag_id; 00264 (void)config; 00265 (void)instance_id; 00266 (void)flags; 00267 return -1; 00268 } 00269 00270 int8_t arm_nwk_6lowpan_rpl_dodag_remove(int8_t interface_id) 00271 { 00272 (void)interface_id; 00273 return -1; 00274 } 00275 00276 int8_t arm_nwk_6lowpan_rpl_dodag_start(int8_t interface_id) 00277 { 00278 (void)interface_id; 00279 return -1; 00280 } 00281 00282 int8_t arm_nwk_6lowpan_rpl_dodag_prefix_update(int8_t interface_id, uint8_t *prefix_ptr, uint8_t prefix_len, uint8_t flags, uint32_t lifetime) 00283 { 00284 (void)interface_id; 00285 (void)prefix_ptr; 00286 (void)prefix_len; 00287 (void)flags; 00288 (void)lifetime; 00289 return -1; 00290 } 00291 00292 int8_t arm_nwk_6lowpan_rpl_dodag_route_update(int8_t interface_id, uint8_t *route_ptr, uint8_t prefix_len, uint8_t flags, uint32_t lifetime) 00293 { 00294 (void)interface_id; 00295 (void)route_ptr; 00296 (void)prefix_len; 00297 (void)flags; 00298 (void)lifetime; 00299 return -1; 00300 } 00301 00302 int8_t arm_nwk_6lowpan_rpl_dodag_poison(int8_t interface_id) 00303 { 00304 (void)interface_id; 00305 return -1; 00306 } 00307 00308 int8_t arm_nwk_6lowpan_rpl_dodag_dao_trig(int8_t interface_id) 00309 { 00310 (void)interface_id; 00311 return -1; 00312 } 00313 00314 int8_t arm_nwk_6lowpan_rpl_dodag_version_increment(int8_t interface_id) 00315 { 00316 (void)interface_id; 00317 return -1; 00318 } 00319 00320 uint8_t rpl_instance_list_read(uint8_t *cache_ptr, uint8_t cache_size) 00321 { 00322 (void)cache_ptr; 00323 (void)cache_size; 00324 return 0; 00325 } 00326 00327 uint8_t rpl_read_dodag_info(rpl_dodag_info_t *dodag_ptr, uint8_t instance_id) 00328 { 00329 (void)dodag_ptr; 00330 (void)instance_id; 00331 return 0; 00332 } 00333 00334 int8_t arm_nwk_6lowpan_rpl_dodag_pref_set(int8_t interface_id, uint8_t preference) 00335 { 00336 (void) interface_id; 00337 (void) preference; 00338 return 0; 00339 } 00340 #endif /* HAVE_RPL */
Generated on Tue Jul 12 2022 13:54:37 by
1.7.2