Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers icmpv6_prefix.c Source File

icmpv6_prefix.c

00001 /*
00002  * Copyright (c) 2015-2017, 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 "string.h"
00020 #include "ns_types.h"
00021 #include "ns_trace.h"
00022 #include "nsdynmemLIB.h"
00023 #include "ns_list.h"
00024 #include "Common_Protocols/icmpv6_prefix.h"
00025 #include "common_functions.h"
00026 
00027 /*
00028  * \file icmpv6_prefix.c
00029  * \brief Add short description about this file!!!
00030  *
00031  */
00032 prefix_entry_t *icmpv6_prefix_add(prefix_list_t *list, const uint8_t *prefixPtr, uint8_t prefix_len, uint32_t lifeTime, uint32_t prefTime, uint8_t flags)
00033 {
00034     prefix_entry_t *entry;
00035 
00036     entry = icmpv6_prefix_compare(list, prefixPtr, prefix_len);
00037     if (entry) {
00038         if (flags != 0xff) {
00039             entry->options = flags;
00040             entry->lifetime = lifeTime;
00041             entry->preftime = prefTime;
00042         }
00043         return entry;
00044     }
00045 
00046     entry = ns_dyn_mem_alloc(sizeof(prefix_entry_t));
00047     if (entry) {
00048         entry->prefix_len = prefix_len;
00049         entry->options = 0xff;
00050         entry->lifetime = lifeTime;
00051         entry->preftime = prefTime;
00052         memset(entry->prefix, 0, 16);
00053         bitcopy0(entry->prefix, prefixPtr, prefix_len);
00054         ns_list_add_to_end(list, entry);
00055     }
00056     return entry;
00057 }
00058 
00059 prefix_entry_t *icmpv6_prefix_compare(prefix_list_t *list, const uint8_t *addr, uint8_t prefix_len)
00060 {
00061     ns_list_foreach(prefix_entry_t, cur, list) {
00062         if (cur->prefix_len == prefix_len && bitsequal(cur->prefix, addr, prefix_len)) {
00063             return cur;
00064         }
00065     }
00066     return NULL;
00067 }
00068 
00069 
00070 void icmpv6_prefix_list_free(prefix_list_t *list)
00071 {
00072     ns_list_foreach_safe(prefix_entry_t, cur, list) {
00073         ns_list_remove(list, cur);
00074         ns_dyn_mem_free(cur);
00075     }
00076 }