Skip to content

Commit f827ffc

Browse files
author
Mika
committed
Added information API to Wi-SUN and border router
Added Gateway to Border router info Added new information API to Wi-SUN interface
1 parent 8f1f9d5 commit f827ffc

File tree

14 files changed

+155
-22
lines changed

14 files changed

+155
-22
lines changed

nanostack/ws_bbr_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
typedef struct bbr_information {
3737
/** Timestamp of the the device. Can be used as version number*/
3838
uint64_t timestamp;
39+
/** Default route Link Local address of north bound router*/
40+
uint8_t gateway[16];
3941
/** Border router dodag id */
4042
uint8_t dodag_id[16];
4143
/** Address prefix given to devices in network set to 0 if not available*/

nanostack/ws_management_api.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,24 @@ typedef struct ws_statistics {
102102
uint32_t asynch_rx_count;
103103
} ws_statistics_t;
104104

105+
/**
106+
* \brief Struct ws_info defines the Wi-SUN stack state.
107+
*/
108+
typedef struct ws_stack_info {
109+
/** Parent link local address */
110+
uint8_t parent[16];
111+
/** parent RSSI Out measured RSSI value calculated using EWMA specified by Wi-SUN from range of -174 (0) to +80 (254) dBm.*/
112+
uint8_t rsl_out;
113+
/** parent RSSI in measured RSSI value calculated using EWMA specified by Wi-SUN from range of -174 (0) to +80 (254) dBm.*/
114+
uint8_t rsl_in;
115+
/** ETX To border router */
116+
uint16_t routing_cost;
117+
/** Network PAN ID */
118+
uint16_t pan_id;
119+
/** Wi-SUN join state defined by Wi-SUN specification 1-5*/
120+
uint8_t join_state;
121+
} ws_stack_info_t;
122+
105123
/**
106124
* Initialize Wi-SUN stack.
107125
*
@@ -582,6 +600,20 @@ int ws_statistics_start(
582600
int ws_statistics_stop(
583601
int8_t interface_id);
584602

603+
/**
604+
* Get information from the stack state.
605+
* Parent information and link qualities with stack state info
606+
*
607+
* \param interface_id Network interface ID.
608+
* \param info_ptr Pointer to stored stack state.
609+
*
610+
* \return 0 Success.
611+
* \return <0 Failure.
612+
*/
613+
int ws_stack_info_get(
614+
int8_t interface_id,
615+
ws_stack_info_t *info_ptr);
616+
585617
#ifdef __cplusplus
586618
}
587619
#endif

source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
#include "Service_Libs/etx/etx.h"
7676
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
7777
#include "6LoWPAN/ws/ws_common.h"
78-
#include "6LoWPAN/ws/ws_bootstrap.h"
7978
#ifdef HAVE_WS
8079
#include "6LoWPAN/ws/ws_cfg_settings.h"
8180
#endif
@@ -517,7 +516,7 @@ uint16_t protocol_6lowpan_neighbor_priority_set(int8_t interface_id, addrtype_t
517516
}
518517

519518
if (new_primary) {
520-
ws_primary_parent_update(cur, entry);
519+
ws_common_primary_parent_update(cur, entry);
521520
}
522521
return 1;
523522
} else {
@@ -550,7 +549,7 @@ uint16_t protocol_6lowpan_neighbor_second_priority_set(int8_t interface_id, addr
550549
protocol_stats_update(STATS_ETX_2ND_PARENT, etx_entry->etx >> 4);
551550
}
552551
if (new_secondary) {
553-
ws_secondary_parent_update(cur);
552+
ws_common_secondary_parent_update(cur);
554553
}
555554
return 1;
556555
} else {

source/6LoWPAN/ws/ws_bbr_api.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,11 @@ int ws_bbr_info_get(int8_t interface_id, bbr_information_t *info_ptr)
807807
memcpy(info_ptr->IID, wisun_if_addr + 8, 8);
808808
}
809809

810+
ipv6_route_t *next_hop = ipv6_route_choose_next_hop(ADDR_6TO4, backbone_interface_id, NULL);
811+
if (next_hop) {
812+
memcpy(info_ptr->gateway, next_hop->info.next_hop_addr, 16);
813+
}
814+
810815
info_ptr->devices_in_network = ws_bbr_pan_size(cur);
811816
info_ptr->instance_id = current_instance_id;
812817
info_ptr->version = dodag_info.version_num;

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3304,33 +3304,32 @@ void ws_bootstrap_rpl_wait_process(protocol_interface_info_entry_t *cur)
33043304
return;
33053305
}
33063306

3307-
/*
3308-
3309-
static bool ws_bootstrap_state_configure(struct protocol_interface_info_entry *cur)
3307+
static bool ws_bootstrap_state_discovery(struct protocol_interface_info_entry *cur)
33103308
{
3311-
// Think about the state value
3312-
if (cur->nwk_bootstrap_state == ER_SCAN) {
3309+
if (cur->nwk_bootstrap_state == ER_ACTIVE_SCAN) {
33133310
return true;
33143311
}
33153312
return false;
33163313
}
33173314

3318-
*/
3319-
static bool ws_bootstrap_state_discovery(struct protocol_interface_info_entry *cur)
3315+
static bool ws_bootstrap_state_authenticate(struct protocol_interface_info_entry *cur)
33203316
{
3321-
if (cur->nwk_bootstrap_state == ER_ACTIVE_SCAN) {
3317+
// Think about the state value
3318+
if (cur->nwk_bootstrap_state == ER_PANA_AUTH) {
33223319
return true;
33233320
}
33243321
return false;
33253322
}
33263323

3327-
static bool ws_bootstrap_state_active(struct protocol_interface_info_entry *cur)
3324+
static bool ws_bootstrap_state_configure(struct protocol_interface_info_entry *cur)
33283325
{
3329-
if (cur->nwk_bootstrap_state == ER_BOOTSRAP_DONE) {
3326+
// Think about the state value
3327+
if (cur->nwk_bootstrap_state == ER_SCAN) {
33303328
return true;
33313329
}
33323330
return false;
33333331
}
3332+
33343333
static bool ws_bootstrap_state_wait_rpl(struct protocol_interface_info_entry *cur)
33353334
{
33363335
// Think about the state value
@@ -3340,6 +3339,14 @@ static bool ws_bootstrap_state_wait_rpl(struct protocol_interface_info_entry *cu
33403339
return false;
33413340
}
33423341

3342+
static bool ws_bootstrap_state_active(struct protocol_interface_info_entry *cur)
3343+
{
3344+
if (cur->nwk_bootstrap_state == ER_BOOTSRAP_DONE) {
3345+
return true;
3346+
}
3347+
return false;
3348+
}
3349+
33433350
static void ws_bootstrap_state_change(protocol_interface_info_entry_t *cur, icmp_state_t nwk_bootstrap_state)
33443351
{
33453352
cur->bootsrap_state_machine_cnt = 1;
@@ -3486,7 +3493,7 @@ void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t s
34863493

34873494
}
34883495

3489-
void ws_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor)
3496+
void ws_bootstrap_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor)
34903497
{
34913498
if (interface->ws_info) {
34923499
llc_neighbour_req_t neighbor_info;
@@ -3497,11 +3504,11 @@ void ws_primary_parent_update(protocol_interface_info_entry_t *interface, mac_ne
34973504
ws_bootsrap_create_ll_address(link_local_address, neighbor->mac64);
34983505
dhcp_client_server_address_update(interface->id, NULL, link_local_address);
34993506

3500-
ws_secondary_parent_update(interface);
3507+
ws_bootstrap_secondary_parent_update(interface);
35013508
}
35023509
}
35033510

3504-
void ws_secondary_parent_update(protocol_interface_info_entry_t *interface)
3511+
void ws_bootstrap_secondary_parent_update(protocol_interface_info_entry_t *interface)
35053512
{
35063513
if (interface->ws_info) {
35073514
ns_list_foreach(if_address_entry_t, address, &interface->ip_addresses) {
@@ -3512,4 +3519,40 @@ void ws_secondary_parent_update(protocol_interface_info_entry_t *interface)
35123519
}
35133520
}
35143521

3522+
int ws_bootstrap_get_info(protocol_interface_info_entry_t *cur, struct ws_stack_info *info_ptr)
3523+
{
3524+
3525+
ws_neighbor_class_entry_t *ws_neighbour = NULL;
3526+
3527+
memset(info_ptr, 0, sizeof(struct ws_stack_info));
3528+
mac_neighbor_table_entry_t *mac_parent = mac_neighbor_entry_get_priority(mac_neighbor_info(cur));
3529+
3530+
if (mac_parent) {
3531+
ws_neighbour = ws_neighbor_class_entry_get(&cur->ws_info->neighbor_storage, mac_parent->index);
3532+
3533+
memcpy(info_ptr->parent, ADDR_LINK_LOCAL_PREFIX, 8);
3534+
memcpy(info_ptr->parent + 8, mac_parent->mac64, 8);
3535+
info_ptr->parent[8] ^= 2;
3536+
}
3537+
if (ws_neighbour) {
3538+
info_ptr->rsl_in = ws_neighbour->rsl_in;
3539+
info_ptr->rsl_out = ws_neighbour->rsl_out;
3540+
info_ptr->routing_cost = ws_neighbour->routing_cost;
3541+
}
3542+
if (ws_bootstrap_state_discovery(cur)) {
3543+
info_ptr->join_state = 1;
3544+
} else if (ws_bootstrap_state_authenticate(cur)) {
3545+
info_ptr->join_state = 2;
3546+
} else if (ws_bootstrap_state_configure(cur)) {
3547+
info_ptr->join_state = 3;
3548+
} else if (ws_bootstrap_state_wait_rpl(cur)) {
3549+
info_ptr->join_state = 4;
3550+
} else if (ws_bootstrap_state_active(cur)) {
3551+
info_ptr->join_state = 5;
3552+
}
3553+
info_ptr->pan_id = cur->ws_info->network_pan_id;
3554+
3555+
return 0;
3556+
}
3557+
35153558
#endif //HAVE_WS

source/6LoWPAN/ws/ws_bootstrap.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct llc_neighbour_req;
3333
struct ws_us_ie;
3434
struct ws_bs_ie;
3535
struct ws_neighbor_class_entry;
36+
struct ws_stack_info;
3637

3738
int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode);
3839

@@ -65,9 +66,9 @@ void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t s
6566

6667
void ws_bootstrap_trickle_timer(protocol_interface_info_entry_t *cur, uint16_t ticks);
6768

68-
void ws_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor);
69+
void ws_bootstrap_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor);
6970

70-
void ws_secondary_parent_update(protocol_interface_info_entry_t *interface);
71+
void ws_bootstrap_secondary_parent_update(protocol_interface_info_entry_t *interface);
7172

7273
void ws_nud_entry_remove_active(protocol_interface_info_entry_t *cur, void *neighbor);
7374

@@ -91,15 +92,18 @@ struct ws_neighbor_class_entry *ws_bootstrap_eapol_tx_temporary_set(struct proto
9192

9293
void ws_bootstrap_eapol_tx_temporary_clear(struct protocol_interface_info_entry *interface);
9394

95+
int ws_bootstrap_get_info(protocol_interface_info_entry_t *cur, struct ws_stack_info *info_ptr);
96+
9497
#else
9598

9699
#define ws_bootstrap_init(interface_id, bootstrap_mode) (-1)
97100
#define ws_bootstrap_state_machine(cur)
98101
#define ws_bootstrap_restart(cur)
99102
#define ws_bootstrap_neighbor_remove(cur, ll_address)
100103
#define ws_bootstrap_aro_failure(cur, ll_address)
101-
#define ws_primary_parent_update(interface, neighbor)
102-
#define ws_secondary_parent_update(interface)
104+
#define ws_bootstrap_primary_parent_update(interface, neighbor)
105+
#define ws_bootstrap_secondary_parent_update(interface)
106+
#define ws_bootstrap_get_info(cur, info_ptr)
103107

104108
#endif //HAVE_WS
105109

source/6LoWPAN/ws/ws_common.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,4 +479,14 @@ uint32_t ws_common_network_size_estimate_get(protocol_interface_info_entry_t *cu
479479
return network_size_estimate;
480480
}
481481

482+
void ws_common_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor)
483+
{
484+
ws_bootstrap_primary_parent_update(interface, neighbor);
485+
}
486+
487+
void ws_common_secondary_parent_update(protocol_interface_info_entry_t *interface)
488+
{
489+
ws_bootstrap_secondary_parent_update(interface);
490+
}
491+
482492
#endif // HAVE_WS

source/6LoWPAN/ws/ws_common.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ uint32_t ws_common_datarate_get(protocol_interface_info_entry_t *cur);
151151

152152
uint32_t ws_common_network_size_estimate_get(protocol_interface_info_entry_t *cur);
153153

154+
void ws_common_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor);
155+
156+
void ws_common_secondary_parent_update(protocol_interface_info_entry_t *interface);
157+
154158
#define ws_info(cur) ((cur)->ws_info)
155159
#else
156160
#define ws_info(cur) ((ws_info_t *) NULL)
@@ -164,6 +168,9 @@ uint32_t ws_common_network_size_estimate_get(protocol_interface_info_entry_t *cu
164168
#define ws_common_latency_estimate_get(cur) 0
165169
#define ws_common_datarate_get(cur) 0
166170
#define ws_common_network_size_estimate_get(cur) 0
171+
#define ws_common_primary_parent_update(interface, neighbor)
172+
#define ws_common_secondary_parent_update(interface)
173+
167174

168175
#endif //HAVE_WS
169176
#endif //WS_COMMON_H_

source/6LoWPAN/ws/ws_empty_functions.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,4 +406,11 @@ void ns_time_api_system_time_callback_set(ns_time_api_system_time_callback callb
406406
(void) callback;
407407
}
408408

409+
int ws_state_info_get(int8_t interface_id, ws_stack_info_t *info_ptr)
410+
{
411+
(void) interface_id;
412+
(void) info_ptr;
413+
return -1;
414+
}
415+
409416
#endif // no HAVE_WS

source/6LoWPAN/ws/ws_management_api.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,4 +731,14 @@ int ws_management_timing_parameters_validate(
731731
return 0;
732732
}
733733

734+
int ws_stack_info_get(int8_t interface_id, ws_stack_info_t *info_ptr)
735+
{
736+
protocol_interface_info_entry_t *cur;
737+
cur = protocol_stack_interface_info_get_by_id(interface_id);
738+
if (!cur || !ws_info(cur) || !info_ptr) {
739+
return -1;
740+
}
741+
return ws_bootstrap_get_info(cur, info_ptr);
742+
}
743+
734744
#endif // HAVE_WS

source/Core/include/ns_address_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ extern const uint8_t ADDR_ALL_MPL_FORWARDERS[16]; // ff03::fc
142142
extern const uint8_t ADDR_ALL_DHCP_RELAY_AGENTS_AND_SERVERS[16]; // ff02::1:2
143143
extern const uint8_t ADDR_LOOPBACK[16]; // ::1
144144
extern const uint8_t ADDR_UNSPECIFIED[16]; // ::
145+
extern const uint8_t ADDR_6TO4[16]; // 2002::
145146

146147
/* Don't bother having another 8 zero bytes for this - reuse ADDR_UNSPECIFIED */
147148
#define ADDR_EUI64_ZERO ADDR_UNSPECIFIED

source/Core/ns_address_internal.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const uint8_t ADDR_ALL_DHCP_RELAY_AGENTS_AND_SERVERS[16] = { 0xff, 0x02, [13] =
8181
const uint8_t ADDR_IPV4_MAPPED_PREFIX[12] = { [10] = 0xff, 0xff };
8282
const uint8_t ADDR_LOOPBACK[16] = { [15] = 1 };
8383
const uint8_t ADDR_UNSPECIFIED[16] = { 0 }; /* Note a few bits of code check for pointer equality with ADDR_UNSPECIFIED */
84+
const uint8_t ADDR_6TO4[16] = { 0x20, 0x02 }; /*Can be used as global address*/
8485
#define ADDR_IPV4_COMPATIBLE ADDR_LOOPBACK /* First 96 bits match...*/
8586

8687
#define ADDR_MULTICAST_LINK_PREFIX ADDR_LINK_LOCAL_ALL_NODES /* ff02::xx */

test/nanostack/unittest/stub/ws_bootstrap_stub.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ void ws_bootstrap_configuration_trickle_reset(protocol_interface_info_entry_t *c
106106

107107
}
108108

109-
void ws_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor)
109+
void ws_bootstrap_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor)
110110
{
111111

112112
}
113113

114-
void ws_secondary_parent_update(protocol_interface_info_entry_t *interface)
114+
void ws_bootstrap_secondary_parent_update(protocol_interface_info_entry_t *interface)
115115
{
116116

117117
}
@@ -149,3 +149,7 @@ void ws_bootstrap_eapol_tx_temporary_clear(struct protocol_interface_info_entry
149149
{
150150

151151
}
152+
int ws_bootstrap_get_info(protocol_interface_info_entry_t *cur, struct ws_stack_info *info_ptr)
153+
{
154+
}
155+

test/nanostack/unittest/stub/ws_common_stub.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,11 @@ uint16_t ws_active_channel_count(uint32_t *channel_mask, uint16_t number_of_chan
102102
{
103103
return 35;
104104
}
105+
106+
void ws_common_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor)
107+
{
108+
}
109+
110+
void ws_common_secondary_parent_update(protocol_interface_info_entry_t *interface)
111+
{
112+
}

0 commit comments

Comments
 (0)