Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers net_short_address_extension.c Source File

net_short_address_extension.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2014-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  * \file net_short_address_extension.c
00019  * \brief Network Short address extension API for library model
00020  *
00021  */
00022 
00023 #include "nsconfig.h"
00024 #include "ns_types.h"
00025 #include "net_address_extension.h"
00026 #include "NWK_INTERFACE/Include/protocol.h"
00027 #include "6LoWPAN/Bootstraps/protocol_6lowpan.h"
00028 #include "6LoWPAN/MAC/mac_helper.h"
00029 
00030 static uint16_t net_ext_short_address = 0xfffe;
00031 static uint8_t net_ext_gen_new = 1;
00032 
00033 void net_ext_set_short_address_from_app(uint16_t short_id, uint8_t generate_dynamical_at_DAD)
00034 {
00035     protocol_interface_info_entry_t *cur = 0;
00036     cur = protocol_stack_interface_info_get(IF_6LoWPAN);
00037 
00038     net_ext_short_address = short_id;
00039     if (cur) {
00040         cur->lowpan_desired_short_address = short_id;
00041     }
00042     net_ext_gen_new = generate_dynamical_at_DAD;
00043 }
00044 
00045 uint8_t net_ext_DAD_event_generate(void)
00046 {
00047     if (net_ext_gen_new) {
00048         net_ext_short_address = 0xfffe;
00049     }
00050     return net_ext_gen_new;
00051 }
00052 
00053 void net_ext_reset_short_address_from_app(void)
00054 {
00055     protocol_interface_info_entry_t *cur = 0;
00056     cur = protocol_stack_interface_info_get(IF_6LoWPAN);
00057 
00058     if (cur && cur->mac_api) {
00059         protocol_6lowpan_allocate_mac16(cur);
00060         mac_helper_mac16_address_set(cur, 0xfffe);
00061     }
00062     net_ext_gen_new = 1;
00063 }
00064 
00065 uint16_t net_ext_get_short_address(void)
00066 {
00067     protocol_interface_info_entry_t *cur = 0;
00068     cur = protocol_stack_interface_info_get(IF_6LoWPAN);
00069     if (net_ext_short_address == 0xfffe) {
00070         if (cur) {
00071             net_ext_short_address = mac_helper_mac16_address_get(cur);
00072         }
00073     }
00074     return net_ext_short_address;
00075 }