Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 14792db

Browse files
Juha Heiskanenjuhhei01
authored andcommitted
Ws neighbor hoping storage init integrated to interface init.
Neighbor remove callback remove ws table and clean neigh cache. Change-Id: Id7276fa05e5d21e4397c1a89833abd7cf7e34203
1 parent ae7945d commit 14792db

File tree

4 files changed

+127
-17
lines changed

4 files changed

+127
-17
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18+
1819
#include <string.h>
1920
#include "nsconfig.h"
2021
#include "ns_types.h"
@@ -33,6 +34,7 @@
3334
#include "6LoWPAN/ws/ws_common_defines.h"
3435
#include "6LoWPAN/ws/ws_common.h"
3536
#include "6LoWPAN/ws/ws_bootstrap.h"
37+
#include "6LoWPAN/ws/ws_neighbour_class.h"
3638
#include "RPL/rpl_control.h"
3739
#include "RPL/rpl_data.h"
3840
#include "Common_Protocols/icmpv6.h"
@@ -43,6 +45,7 @@
4345
#include "6LoWPAN/ws/ws_llc.h"
4446
#include "6LoWPAN/lowpan_adaptation_interface.h"
4547
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
48+
#include "platform/topo_trace.h"
4649

4750
#include "net_rpl.h"
4851
#include "mac_api.h"
@@ -447,9 +450,28 @@ static void ws_bootstrap_asynch_confirm(struct protocol_interface_info_entry *in
447450

448451
static void ws_neighbor_entry_remove_notify(mac_neighbor_table_entry_t *entry_ptr, void *user_data)
449452
{
450-
//TODO Remove from MAC helper remove, ETX, WS Table entry
451-
(void) entry_ptr;
452-
(void) user_data;
453+
454+
protocol_interface_info_entry_t *cur = user_data;
455+
456+
// Sleepy host
457+
if (cur->lowpan_info & INTERFACE_NWK_CONF_MAC_RX_OFF_IDLE) {
458+
mac_data_poll_protocol_poll_mode_decrement(cur);
459+
}
460+
461+
//TODO State machine check here
462+
463+
if (entry_ptr->ffd_device) {
464+
protocol_6lowpan_release_short_link_address_from_neighcache(cur, entry_ptr->mac16);
465+
protocol_6lowpan_release_long_link_address_from_neighcache(cur, entry_ptr->mac64);
466+
}
467+
mac_helper_devicetable_remove(cur->mac_api, entry_ptr->index);
468+
469+
//Remove WS neighbor data
470+
ws_neighbour_class_entry_remove(&cur->ws_info->neighbor_storage, entry_ptr->index);
471+
topo_trace(TOPOLOGY_MLE, entry_ptr->ext64, TOPO_REMOVE);
472+
473+
//TODO Remove ETX neighbor
474+
//etx_neighbor_remove(interface_id, entry);
453475
}
454476

455477

@@ -463,11 +485,12 @@ static bool ws_neighbor_entry_nud_notify(mac_neighbor_table_entry_t *entry_ptr,
463485

464486
int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
465487
{
466-
(void) bootstrap_mode;
488+
int ret_val = 0;
467489

468-
protocol_interface_info_entry_t *cur;
469-
470-
cur = protocol_stack_interface_info_get_by_id(interface_id);
490+
ws_neighbour_class_t neigh_info;
491+
neigh_info.neigh_info_list = NULL;
492+
neigh_info.list_size = 0;
493+
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
471494
if (!cur) {
472495
return -1;
473496
}
@@ -483,7 +506,7 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
483506
}
484507

485508
switch (bootstrap_mode) {
486-
// case NET_6LOWPAN_SLEEPY_HOST:
509+
// case NET_6LOWPAN_SLEEPY_HOST:
487510
case NET_6LOWPAN_HOST:
488511
cur->bootsrap_mode = ARM_NWK_BOOTSRAP_MODE_6LoWPAN_HOST;
489512
break;
@@ -496,48 +519,64 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
496519
default:
497520
return -3;
498521
}
522+
523+
if (!ws_neighbour_class_alloc(&neigh_info, buffer.device_decription_table_size)) {
524+
ret_val = -1;
525+
goto init_fail;
526+
}
527+
499528
//Disable allways by default
500529
lowpan_adaptation_interface_mpx_register(interface_id, NULL, 0);
501530

502531
mac_neighbor_table_delete(cur->mac_parameters->mac_neighbor_table);
503532
cur->mac_parameters->mac_neighbor_table = mac_neighbor_table_create(buffer.device_decription_table_size, ws_neighbor_entry_remove_notify
504533
, ws_neighbor_entry_nud_notify, cur, WS_NEIGHBOR_NUD_TIMEOUT);
505534
if (!cur->mac_parameters->mac_neighbor_table) {
506-
return -4;
535+
ret_val = -1;
536+
goto init_fail;
507537
}
508538

509539
ws_llc_create(cur, &ws_bootstrap_asynch_ind, &ws_bootstrap_asynch_confirm);
510540

511541
mpx_api_t *mpx_api = ws_llc_mpx_api_get(cur);
512542
if (!mpx_api) {
513-
ws_llc_delete(cur);
514-
return -4;
543+
ret_val = -4;
544+
goto init_fail;
515545
}
516546

517547
if (ws_common_allocate_and_init(cur) < 0) {
518-
ws_llc_delete(cur);
519-
return -4;
548+
ret_val = -4;
549+
goto init_fail;
520550
}
521551

522552
if (ws_bootstrap_tasklet_init(cur) != 0) {
523-
ws_llc_delete(cur);
524-
return -4;
553+
ret_val = -4;
554+
goto init_fail;
525555
}
526556

527557
//Register MPXUser to adapatation layer
528558
if (lowpan_adaptation_interface_mpx_register(interface_id, mpx_api, MPX_LOWPAN_ENC_USER_ID) != 0) {
529-
ws_llc_delete(cur);
530-
return -4;
559+
ret_val = -4;
560+
goto init_fail;
531561
}
532562

533563

534564
cur->if_up = ws_bootstrap_up;
535565
cur->if_down = ws_bootstrap_down;
566+
cur->ws_info->neighbor_storage = neigh_info;
536567

537568
ws_bootstrap_configuration_reset(cur);
538569
addr_notification_register(ws_bootstrap_address_notification_cb);
539570

540571
return 0;
572+
573+
//Error handling and free memory
574+
init_fail:
575+
lowpan_adaptation_interface_mpx_register(interface_id, NULL, 0);
576+
mac_neighbor_table_delete(cur->mac_parameters->mac_neighbor_table);
577+
ws_neighbour_class_dealloc(&neigh_info);
578+
ws_llc_delete(cur);
579+
return ret_val;
541580
}
542581

543582
static void ws_bootstrap_mac_activate(protocol_interface_info_entry_t *cur, uint16_t channel, uint16_t panid, bool coordinator)

source/6LoWPAN/ws/ws_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
#ifndef WS_COMMON_H_
1818
#define WS_COMMON_H_
1919

20+
#include <6LoWPAN/ws/ws_neighbour_class.h>
2021
#include "ns_types.h"
2122
#include "fhss_api.h"
2223
#include "fhss_config.h"
2324
#include "6LoWPAN/ws/ws_common_defines.h"
2425

2526
struct ws_pan_information_s;
27+
struct ws_neighbour_class_s;
2628

2729
typedef struct parent_info_s {
2830
uint16_t pan_id; /**< PAN ID */
@@ -46,6 +48,7 @@ typedef struct ws_info_s {
4648

4749
struct ws_pan_information_s pan_configuration;
4850
ws_hoopping_schedule_t hopping_schdule;
51+
struct ws_neighbour_class_s neighbor_storage;
4952
struct fhss_timer *fhss_timer_ptr; // Platform adaptation for FHSS timers.
5053
} ws_info_t;
5154

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "nsconfig.h"
19+
#include <string.h>
20+
#include "ns_types.h"
21+
#include "ns_list.h"
22+
#include "ns_trace.h"
23+
#include "nsdynmemLIB.h"
24+
#include "6LoWPAN/ws/ws_neighbour_class.h"
25+
26+
bool ws_neighbour_class_alloc(ws_neighbour_class_t *class_data, uint8_t list_size)
27+
{
28+
29+
class_data->neigh_info_list = ns_dyn_mem_alloc(sizeof(ws_neighbour_class_entry_t) * list_size);
30+
if (!class_data->neigh_info_list) {
31+
return false;
32+
}
33+
34+
class_data->list_size = list_size;
35+
ws_neighbour_class_entry_t * list_ptr = class_data->neigh_info_list;
36+
for (uint8_t i = 0; i< list_size; i++) {
37+
memset(list_ptr, 0, sizeof(ws_neighbour_class_entry_t));
38+
list_ptr++;
39+
}
40+
return true;
41+
}
42+
43+
44+
void ws_neighbour_class_dealloc(ws_neighbour_class_t *class_data)
45+
{
46+
ns_dyn_mem_free(class_data->neigh_info_list);
47+
class_data->neigh_info_list = NULL;
48+
class_data->list_size = 0;
49+
}
50+
51+
ws_neighbour_class_entry_t * ws_neighbour_class_entry_get(ws_neighbour_class_t *class_data, uint8_t attribute_index)
52+
{
53+
if (!class_data->neigh_info_list || attribute_index >= class_data->list_size) {
54+
return NULL;
55+
}
56+
57+
ws_neighbour_class_entry_t *entry = class_data->neigh_info_list + attribute_index;
58+
return entry;
59+
}
60+
61+
void ws_neighbour_class_entry_remove(ws_neighbour_class_t *class_data, uint8_t attribute_index)
62+
{
63+
ws_neighbour_class_entry_t *entry = ws_neighbour_class_entry_get(class_data, attribute_index);
64+
if (entry) {
65+
memset(entry, 0, sizeof(ws_neighbour_class_entry_t));
66+
}
67+
}

sources.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ SRCS += \
2121
source/6LoWPAN/ws/ws_ie_lib.c \
2222
source/6LoWPAN/ws/ws_llc_data_service.c \
2323
source/6LoWPAN/ws/ws_mpx_header.c \
24+
source/6LoWPAN/ws/ws_neighbour_class.c \
2425
source/6LoWPAN/ws/ws_bootstrap.c \
2526
source/6LoWPAN/ws/ws_common.c \
2627
source/6LoWPAN/ws/ws_management_api.c \

0 commit comments

Comments
 (0)