Skip to content

Commit cc8bb45

Browse files
authored
Merge pull request #13084 from debdeep-arm/wisun-interface-api-add
[feature-wisun] Added Wi-SUN interface and Border Router API.
2 parents 782141b + 16e807e commit cc8bb45

File tree

4 files changed

+183
-0
lines changed

4 files changed

+183
-0
lines changed

features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunBorderRouter.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,37 @@
1717
#ifndef WISUNBORDERROUTER_H
1818
#define WISUNBORDERROUTER_H
1919

20+
/**
21+
* \brief Struct br_information Border router dynamic information.
22+
*/
23+
typedef struct ws_br_info {
24+
/** Address prefix given to devices in network set to 0 if not available*/
25+
uint8_t ipv6_prefix[8];
26+
/** IID of Border router */
27+
uint8_t ipv6_iid[8];
28+
/** Border router dodag id */
29+
uint8_t rpl_dodag_id[16];
30+
/** Border router instance identifier defined in RPL */
31+
uint8_t instance_id;
32+
/** RPL version number */
33+
uint8_t version;
34+
/** Timestamp of the the device. Can be used as version number*/
35+
uint64_t host_timestamp;
36+
/** Amount of devices in the network. */
37+
uint16_t device_count;
38+
} ws_br_info_t;
39+
40+
/**
41+
* \brief Struct br_route_info is parent child relation structure.
42+
*/
43+
typedef struct ws_br_route_info {
44+
/** IID of target device
45+
* Public IPv6 address can be formed by combining prefix + IID*/
46+
uint8_t target[8];
47+
/** IID of parent*/
48+
uint8_t parent[8];
49+
} ws_br_route_info_t;
50+
2051
/** Wi-SUN Border Router class
2152
*
2253
* Class can be used to start, stop and configure Wi-SUN Border Router.
@@ -147,6 +178,35 @@ class WisunBorderRouter {
147178
* */
148179
mesh_error_t validate_pan_configuration(uint16_t pan_id);
149180

181+
/**
182+
* \brief Get Wi-SUN Border Router information.
183+
*
184+
* Function reads RPL information from Border Router.
185+
* Mesh interface must be initialized before calling this function.
186+
*
187+
* \param info_ptr Structure given to stack where information will be stored
188+
*
189+
* \return MESH_ERROR_NONE on success.
190+
* \return MESH_ERROR_UNKNOWN in case of failure.
191+
* */
192+
mesh_error_t info_get(ws_br_info_t *info_ptr);
193+
194+
/**
195+
* \brief Get Wi-SUN neighbor table information.
196+
*
197+
* Function reads Routing Table information from Border Router.
198+
* Table is Parent child relation using the Global address IID of the devices.
199+
* To get the full IPv6 address of the device, IPv6 = Global Prefix + IID.
200+
* Mesh interface must be initialized before calling this function.
201+
*
202+
* \param table_ptr Application allocated memory block where routing table is written.
203+
* \param table_len Length of the table allocated by application given as amount of entries.
204+
*
205+
* \return MESH_ERROR_NONE on success.
206+
* \return MESH_ERROR_UNKNOWN in case of failure.
207+
* */
208+
mesh_error_t routing_table_get(ws_br_route_info_t *table_ptr, uint16_t table_len);
209+
150210
private:
151211
int8_t _mesh_if_id = -1;
152212

features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@
1919

2020
#include "MeshInterfaceNanostack.h"
2121

22+
/**
23+
* \brief Struct ws_rpl_info Wi-SUN router RPL information.
24+
*/
25+
typedef struct ws_rpl_info {
26+
/** Address prefix given to devices in network set to 0 if not available*/
27+
uint8_t ipv6_prefix[8];
28+
/** IID of router */
29+
uint8_t ipv6_iid[8];
30+
/** Router dodag id */
31+
uint8_t rpl_dodag_id[16];
32+
/** Router instance identifier */
33+
uint8_t instance_id;
34+
/** RPL version number */
35+
uint8_t version;
36+
} ws_rpl_info_t;
37+
2238
/** Wi-SUN mesh network interface class
2339
*
2440
* Configure Nanostack to use Wi-SUN protocol.
@@ -433,6 +449,19 @@ class WisunInterface : public MeshInterfaceNanostack {
433449
* */
434450
mesh_error_t read_mac_statistics(mesh_mac_statistics_t *statistics);
435451

452+
/**
453+
* \brief Get Wi-SUN Router information.
454+
*
455+
* Function reads RPL information from nanostack.
456+
* Mesh interface must be initialized before calling this function.
457+
*
458+
* \param info_ptr Structure given to stack where information will be stored
459+
*
460+
* \return MESH_ERROR_NONE on success.
461+
* \return MESH_ERROR_UNKNOWN in case of failure.
462+
* */
463+
mesh_error_t info_get(ws_rpl_info_t *info_ptr);
464+
436465
protected:
437466
Nanostack::WisunInterface *get_interface() const;
438467
virtual nsapi_error_t do_initialize();

features/nanostack/mbed-mesh-api/source/WisunBorderRouter.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,41 @@ mesh_error_t WisunBorderRouter::validate_pan_configuration(uint16_t pan_id)
153153

154154
return MESH_ERROR_NONE;
155155
}
156+
157+
mesh_error_t WisunBorderRouter::info_get(ws_br_info_t *info_ptr)
158+
{
159+
bbr_information_t bbr_info = {0};
160+
161+
if (info_ptr == NULL) {
162+
return MESH_ERROR_PARAM;
163+
}
164+
165+
int status = ws_bbr_info_get(_mesh_if_id, &bbr_info);
166+
if (status != 0) {
167+
return MESH_ERROR_UNKNOWN;
168+
}
169+
170+
info_ptr->device_count = bbr_info.devices_in_network;
171+
info_ptr->host_timestamp = bbr_info.timestamp;
172+
info_ptr->instance_id = bbr_info.instance_id;
173+
info_ptr->version = bbr_info.version;
174+
memcpy(info_ptr->rpl_dodag_id, bbr_info.dodag_id, 16);
175+
memcpy(info_ptr->ipv6_prefix, bbr_info.prefix, 8);
176+
memcpy(info_ptr->ipv6_iid, bbr_info.IID, 8);
177+
178+
return MESH_ERROR_NONE;
179+
}
180+
181+
mesh_error_t WisunBorderRouter::routing_table_get(ws_br_route_info_t *table_ptr, uint16_t table_len)
182+
{
183+
if (table_ptr == NULL) {
184+
return MESH_ERROR_PARAM;
185+
}
186+
187+
int status = ws_bbr_routing_table_get(_mesh_if_id, (bbr_route_info_t *)table_ptr, table_len);
188+
if (status != 0) {
189+
return MESH_ERROR_UNKNOWN;
190+
}
191+
192+
return MESH_ERROR_NONE;
193+
}

features/nanostack/mbed-mesh-api/source/WisunInterface.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "fhss_api.h"
2525
#include "fhss_config.h"
2626
#include "ws_management_api.h"
27+
#include "net_rpl.h"
28+
#include "net_interface.h"
2729

2830
#include "ns_trace.h"
2931
#define TRACE_GROUP "WSIn"
@@ -542,6 +544,60 @@ mesh_error_t WisunInterface::read_mac_statistics(mesh_mac_statistics_t *statisti
542544
return ret_val;
543545
}
544546

547+
mesh_error_t WisunInterface::info_get(ws_rpl_info_t *info_ptr)
548+
{
549+
if (info_ptr == NULL) {
550+
return MESH_ERROR_PARAM;
551+
}
552+
553+
rpl_dodag_info_t dodag_ptr = {0};
554+
uint8_t global_address[16] = {0};
555+
uint8_t rpl_instance_count;
556+
uint8_t instance_id_list[10];
557+
uint8_t instance_id = RPL_INSTANCE_LOCAL;
558+
uint8_t instance_id_new;
559+
uint8_t instance_index;
560+
rpl_instance_count = rpl_instance_list_read(&instance_id_list[0], sizeof(instance_id_list));
561+
562+
if (rpl_instance_count > 10) {
563+
return MESH_ERROR_UNKNOWN;
564+
}
565+
566+
/* Find lowest global instance ID (assumption: RPL instance with lowest instance ID has
567+
most generic routing rule and its rank should be indicated in beacon) */
568+
for (instance_index = 0; instance_index < rpl_instance_count; instance_index++) {
569+
instance_id_new = instance_id_list[instance_index];
570+
571+
if ((instance_id_new & RPL_INSTANCE_LOCAL) == RPL_INSTANCE_LOCAL) {
572+
break;
573+
} else {
574+
if (instance_id_new < instance_id) {
575+
instance_id = instance_id_new;
576+
}
577+
}
578+
}
579+
580+
if (instance_id == RPL_INSTANCE_LOCAL) {
581+
return MESH_ERROR_UNKNOWN;
582+
}
583+
584+
if (!rpl_read_dodag_info(&dodag_ptr, instance_id)) {
585+
return MESH_ERROR_UNKNOWN;
586+
}
587+
588+
if (arm_net_address_get(get_interface_id(), ADDR_IPV6_GP, global_address) != 0) {
589+
// No global prefix available, Nothing to do.
590+
}
591+
592+
info_ptr->instance_id = dodag_ptr.instance_id;
593+
info_ptr->version = dodag_ptr.version_num;
594+
memcpy(info_ptr->rpl_dodag_id, dodag_ptr.dodag_id, 16);
595+
memcpy(info_ptr->ipv6_prefix, global_address, 8);
596+
memcpy(info_ptr->ipv6_iid, global_address + 8, 8);
597+
598+
return MESH_ERROR_NONE;
599+
}
600+
545601
#define WISUN 0x2345
546602
#if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == WISUN && DEVICE_802_15_4_PHY
547603
MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance()

0 commit comments

Comments
 (0)