Skip to content

Commit 9ad4aa5

Browse files
authored
Merge pull request #13152 from debdeep-arm/add-wisun-interface-api
Add Wi-SUN Interface APIs
2 parents 22e9925 + ef38561 commit 9ad4aa5

File tree

4 files changed

+178
-0
lines changed

4 files changed

+178
-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+
* \returns 0 - x on success indicates number of entries written to the table_ptr.
206+
* \return <0 in case of errors.
207+
* */
208+
int 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.
@@ -424,6 +440,19 @@ class WisunInterface final : public MeshInterfaceNanostack {
424440
* */
425441
mesh_error_t read_mac_statistics(mesh_mac_statistics_t *statistics);
426442

443+
/**
444+
* \brief Get Wi-SUN Router information.
445+
*
446+
* Function reads RPL information from nanostack.
447+
* Mesh interface must be initialized before calling this function.
448+
*
449+
* \param info_ptr Structure given to stack where information will be stored
450+
*
451+
* \return MESH_ERROR_NONE on success.
452+
* \return MESH_ERROR_UNKNOWN in case of failure.
453+
* */
454+
mesh_error_t info_get(ws_rpl_info_t *info_ptr);
455+
427456
protected:
428457
Nanostack::WisunInterface *get_interface() const;
429458
nsapi_error_t do_initialize() override;

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,36 @@ 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+
int WisunBorderRouter::routing_table_get(ws_br_route_info_t *table_ptr, uint16_t table_len)
182+
{
183+
if (table_ptr == NULL) {
184+
return -1;
185+
}
186+
187+
return ws_bbr_routing_table_get(_mesh_if_id, (bbr_route_info_t *)table_ptr, table_len);
188+
}

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"
@@ -544,6 +546,60 @@ mesh_error_t WisunInterface::read_mac_statistics(mesh_mac_statistics_t *statisti
544546
return ret_val;
545547
}
546548

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

0 commit comments

Comments
 (0)