Skip to content

Commit 754861d

Browse files
author
Mika Leppänen
committed
Added Wi-SUN Border Router class
1 parent 3ad3ebe commit 754861d

9 files changed

+345
-4
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed
8282
};
8383

8484
class Nanostack::MeshInterface : public Nanostack::Interface {
85+
public:
86+
char *get_interface_name(char *buf);
8587
protected:
8688
MeshInterface(NanostackRfPhy &phy) : Interface(phy) { }
8789
NanostackRfPhy &get_phy() const

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Nanostack::EthernetInterface : public Nanostack::Interface {
2929
bool blocking = true);
3030
virtual nsapi_error_t bringdown();
3131

32+
char *get_interface_name(char *buf);
3233
private:
3334
friend class Nanostack;
3435
friend class NanostackEthernetInterface;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Nanostack::PPPInterface : public Nanostack::Interface {
3232
typedef mbed::Callback<void (uint8_t up, int8_t device_id)> link_state_cb_t;
3333
virtual void set_link_state_changed_callback(link_state_cb_t link_state_cb);
3434

35+
char *get_interface_name(char *buf);
3536
private:
3637
friend class Nanostack;
3738
PPPInterface(NanostackPhy &phy) : Interface(phy), link_state_up(false), enet_tasklet_connected(false) {}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
* Copyright (c) 2020 ARM Limited. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Licensed under the Apache License, Version 2.0 (the License); you may
5+
* not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef WISUNBORDERROUTER_H
18+
#define WISUNBORDERROUTER_H
19+
20+
/** Wi-SUN Border Router class
21+
*
22+
* Class can be used to start, stop and configure Wi-SUN Border Router.
23+
*/
24+
class WisunBorderRouter {
25+
public:
26+
27+
/** Create WisunBorderRouter
28+
*
29+
* */
30+
WisunBorderRouter() { }
31+
32+
/**
33+
* \brief Start Wi-SUN Border Router
34+
*
35+
* Starts Wi-SUN Border Router and routing between the mesh and backbone interfaces. Network interfaces
36+
* must be initialized and connected before calling the start. Backbone interface can be either Ethernet
37+
* (EMAC) or Cellular.
38+
*
39+
* \param mesh_if Wi-SUN mesh network interface
40+
* \param backbone_if Backbone network interface
41+
* \return MESH_ERROR_NONE on success.
42+
* \return MESH_ERROR_UNKNOWN in case of failure.
43+
* */
44+
mesh_error_t start(NetworkInterface *mesh_if, NetworkInterface *backbone_if);
45+
46+
/**
47+
* \brief Start Wi-SUN Border Router
48+
*
49+
* Starts Wi-SUN Border Router and routing between the mesh and backbone interfaces. Mesh network interface
50+
* must be initialized and connected before calling the start. Backbone OnboardNetworkStack::Interface must
51+
* be brought up before calling the start. Backbone interface can be either Ethernet (EMAC) or Cellular (PPP).
52+
*
53+
* \param mesh_if Wi-SUN mesh network interface
54+
* \param backbone_if Backbone OnboardNetworkStack::Interface interface
55+
* \return MESH_ERROR_NONE on success.
56+
* \return MESH_ERROR_UNKNOWN in case of failure.
57+
* */
58+
mesh_error_t start(NetworkInterface *mesh_if, OnboardNetworkStack::Interface *backbone_if);
59+
60+
/**
61+
* \brief Stop Wi-SUN Border Router
62+
*
63+
* Stops Wi-SUN Border Router.
64+
*
65+
* */
66+
void stop();
67+
68+
/**
69+
* \brief Set Wi-SUN RPL DIO trickle parameters.
70+
*
71+
* Function stores new parameters to Border Router and uses them when mesh interface connect() is called
72+
* next time. If device is already connected to the Wi-SUN network then device will restart Wi-SUN network after
73+
* changing the RPL DIO trickle parameters. Mesh interface must be initialized before calling this
74+
* function.
75+
*
76+
* \param dio_interval_min DIO trickle timer Imin parameter. Use 0x00 to use leave parameter unchanged.
77+
* \param dio_interval_doublings DIO trickle timer Imax parameter as doublings of Imin. Use 0x00 to use leave parameter unchanged.
78+
* \param dio_redundancy_constant DIO trickle timer redundancy constant. Use 0xff to use leave parameter unchanged.
79+
* \return MESH_ERROR_NONE on success.
80+
* \return MESH_ERROR_UNKNOWN in case of failure.
81+
* */
82+
mesh_error_t set_rpl_parameters(uint8_t dio_interval_min, uint8_t dio_interval_doublings, uint8_t dio_redundancy_constant);
83+
84+
/**
85+
* \brief Get Wi-SUN RPL DIO trickle parameters.
86+
*
87+
* Function reads DIO trickle timer Imin, DIO trickle timer Imax and DIO trickle timer redundancy
88+
* constant from Border Router. Mesh interface must be initialized before calling this function.
89+
*
90+
* \param dio_interval_min DIO trickle timer Imin parameter.
91+
* \param dio_interval_doublings DIO trickle timer Imax parameter as doublings of Imin.
92+
* \param dio_redundancy_constant DIO trickle timer redundancy constant.
93+
* \return MESH_ERROR_NONE on success.
94+
* \return MESH_ERROR_UNKNOWN in case of failure.
95+
* */
96+
mesh_error_t get_rpl_parameters(uint8_t *dio_interval_min, uint8_t *dio_interval_doublings, uint8_t *dio_redundancy_constant);
97+
98+
/**
99+
* \brief Validate Wi-SUN RPL DIO trickle parameters.
100+
*
101+
* Function validates DIO trickle timer Imin, DIO trickle timer Imax and DIO trickle timer redundancy
102+
* constant. Function can be used to test that values that will be used on set function are valid.
103+
* Mesh interface must be initialized before the calling this function.
104+
*
105+
* \param dio_interval_min DIO trickle timer Imin parameter.
106+
* \param dio_interval_doublings DIO trickle timer Imax parameter as doublings of Imin.
107+
* \param dio_redundancy_constant DIO trickle timer redundancy constant.
108+
* \return MESH_ERROR_NONE on success.
109+
* \return MESH_ERROR_UNKNOWN in case of failure.
110+
* */
111+
mesh_error_t validate_rpl_parameters(uint8_t dio_interval_min, uint8_t dio_interval_doublings, uint8_t dio_redundancy_constant);
112+
113+
/**
114+
* \brief Set Wi-SUN PAN configuration parameters.
115+
*
116+
* Function stores new parameters to Border Router and uses them when mesh interface connect() is called
117+
* next time. If device is already connected to the Wi-SUN network then device will restart Wi-SUN network after
118+
* changing the PAN configuration parameters. Mesh interface must be initialized before calling this
119+
* function.
120+
*
121+
* \param pan_id PAN ID. 0xffff will generate the PAN ID on the mesh interface connect() call if not already generated.
122+
* \return MESH_ERROR_NONE on success.
123+
* \return MESH_ERROR_UNKNOWN in case of failure.
124+
* */
125+
mesh_error_t set_pan_configuration(uint16_t pan_id);
126+
127+
/**
128+
* \brief Get Wi-SUN PAN configuration parameters.
129+
*
130+
* Function reads PAN ID from Border Router. Mesh interface must be initialized before calling this function.
131+
*
132+
* \param pan_id PAN ID.
133+
* \return MESH_ERROR_NONE on success.
134+
* \return MESH_ERROR_UNKNOWN in case of failure.
135+
* */
136+
mesh_error_t get_pan_configuration(uint16_t *pan_id);
137+
138+
/**
139+
* \brief Validate Wi-SUN PAN configuration parameters.
140+
*
141+
* Function validates PAN ID. Function can be used to test that values that will be used on set function are valid.
142+
* Mesh interface must be initialized before calling this function.
143+
*
144+
* \param pan_id PAN ID.
145+
* \return MESH_ERROR_NONE on success.
146+
* \return MESH_ERROR_UNKNOWN in case of failure.
147+
* */
148+
mesh_error_t validate_pan_configuration(uint16_t pan_id);
149+
150+
private:
151+
int8_t _mesh_if_id = -1;
152+
153+
};
154+
155+
#endif

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ typedef enum {
6666
* Mesh channel function
6767
*/
6868
typedef enum {
69-
MESH_CHANNEL_FUNCTION_FIXED = 0x00,
70-
MESH_CHANNEL_FUNCTION_TR51CF,
71-
MESH_CHANNEL_FUNCTION_DH1CF,
72-
MESH_CHANNEL_FUNCTION_VENDOR_DEFINED
69+
MESH_CHANNEL_FUNCTION_FIXED = 0x00,
70+
MESH_CHANNEL_FUNCTION_TR51CF,
71+
MESH_CHANNEL_FUNCTION_DH1CF,
72+
MESH_CHANNEL_FUNCTION_VENDOR_DEFINED
7373
} mesh_channel_function_t;
7474

7575
/**

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ int InterfaceNanostack::disconnect()
124124
return _interface->bringdown();
125125
}
126126

127+
char *Nanostack::MeshInterface::get_interface_name(char *buf)
128+
{
129+
if (interface_id < 0) {
130+
return NULL;
131+
}
132+
sprintf(buf, "MES%d", interface_id);
133+
return buf;
134+
};
135+
127136
nsapi_error_t MeshInterfaceNanostack::initialize(NanostackRfPhy *phy)
128137
{
129138
if (_phy && phy && _phy != phy) {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,12 @@ nsapi_error_t Nanostack::EthernetInterface::bringdown()
120120
}
121121
return NSAPI_ERROR_OK;
122122
}
123+
124+
char *Nanostack::EthernetInterface::get_interface_name(char *buf)
125+
{
126+
if (interface_id < 0) {
127+
return NULL;
128+
}
129+
sprintf(buf, "ETH%d", interface_id);
130+
return buf;
131+
};

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@ void Nanostack::PPPInterface::set_link_state_changed_callback(link_state_cb_t ne
181181
link_state_cb = new_link_state_cb;
182182
}
183183

184+
char *Nanostack::PPPInterface::get_interface_name(char *buf)
185+
{
186+
if (interface_id < 0) {
187+
return NULL;
188+
}
189+
sprintf(buf, "PPP%d", interface_id);
190+
return buf;
191+
};
192+
184193
// GAH! no handles on the callback. Force a single interface
185194
static PPPPhy *single_phy;
186195

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
* Copyright (c) 2020 ARM Limited. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Licensed under the Apache License, Version 2.0 (the License); you may
5+
* not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "WisunInterface.h"
18+
#include "ns_trace.h"
19+
#include "WisunBorderRouter.h"
20+
#include "MeshInterfaceNanostack.h"
21+
22+
extern "C" {
23+
#include "ws_bbr_api.h"
24+
}
25+
26+
#define TRACE_GROUP "WSBR"
27+
28+
mesh_error_t WisunBorderRouter::start(NetworkInterface *mesh_if, NetworkInterface *backbone_if)
29+
{
30+
if (mesh_if == NULL || backbone_if == NULL) {
31+
return MESH_ERROR_PARAM;
32+
}
33+
34+
InterfaceNanostack *nano_mesh_if = reinterpret_cast<InterfaceNanostack *>(mesh_if);
35+
int8_t mesh_if_id = nano_mesh_if->get_interface_id();
36+
if (mesh_if_id < 0) {
37+
return MESH_ERROR_UNKNOWN;
38+
}
39+
_mesh_if_id = mesh_if_id;
40+
41+
char backbone_if_name[7] = {0};
42+
if (backbone_if->get_interface_name(backbone_if_name) == NULL) {
43+
return MESH_ERROR_UNKNOWN;
44+
}
45+
46+
if (strlen((char *) &backbone_if_name) < 4) {
47+
return MESH_ERROR_UNKNOWN;
48+
}
49+
50+
int backbone_if_id = atoi(&backbone_if_name[3]);
51+
if (backbone_if_id < 0) {
52+
return MESH_ERROR_UNKNOWN;
53+
}
54+
55+
int ret = ws_bbr_start(mesh_if_id, backbone_if_id);
56+
if (ret < 0) {
57+
return MESH_ERROR_UNKNOWN;
58+
}
59+
60+
return MESH_ERROR_NONE;
61+
}
62+
63+
mesh_error_t WisunBorderRouter::start(NetworkInterface *mesh_if, OnboardNetworkStack::Interface *backbone_if)
64+
{
65+
InterfaceNanostack *nano_mesh_if = reinterpret_cast<InterfaceNanostack *>(mesh_if);
66+
int8_t mesh_if_id = nano_mesh_if->get_interface_id();
67+
if (mesh_if_id < 0) {
68+
return MESH_ERROR_UNKNOWN;
69+
}
70+
_mesh_if_id = mesh_if_id;
71+
72+
Nanostack::Interface *nano_backbone_if = static_cast<Nanostack::Interface *>(backbone_if);
73+
int8_t backbone_if_id = nano_backbone_if->get_interface_id();
74+
if (backbone_if_id < 0) {
75+
return MESH_ERROR_UNKNOWN;
76+
}
77+
78+
int ret = ws_bbr_start(mesh_if_id, backbone_if_id);
79+
if (ret < 0) {
80+
return MESH_ERROR_UNKNOWN;
81+
}
82+
83+
return MESH_ERROR_NONE;
84+
}
85+
86+
void WisunBorderRouter::stop()
87+
{
88+
if (_mesh_if_id < 0) {
89+
return;
90+
}
91+
92+
ws_bbr_stop(_mesh_if_id);
93+
94+
_mesh_if_id = -1;
95+
}
96+
97+
mesh_error_t WisunBorderRouter::set_rpl_parameters(uint8_t dio_interval_min, uint8_t dio_interval_doublings, uint8_t dio_redundancy_constant)
98+
{
99+
int status = ws_bbr_rpl_parameters_set(_mesh_if_id, dio_interval_min, dio_interval_doublings, dio_redundancy_constant);
100+
if (status != 0) {
101+
return MESH_ERROR_UNKNOWN;
102+
}
103+
104+
return MESH_ERROR_NONE;
105+
}
106+
107+
mesh_error_t WisunBorderRouter::get_rpl_parameters(uint8_t *dio_interval_min, uint8_t *dio_interval_doublings, uint8_t *dio_redundancy_constant)
108+
{
109+
int status = ws_bbr_rpl_parameters_get(_mesh_if_id, dio_interval_min, dio_interval_doublings, dio_redundancy_constant);
110+
if (status != 0) {
111+
return MESH_ERROR_UNKNOWN;
112+
}
113+
114+
return MESH_ERROR_NONE;
115+
}
116+
117+
mesh_error_t WisunBorderRouter::validate_rpl_parameters(uint8_t dio_interval_min, uint8_t dio_interval_doublings, uint8_t dio_redundancy_constant)
118+
{
119+
int status = ws_bbr_rpl_parameters_validate(_mesh_if_id, dio_interval_min, dio_interval_doublings, dio_redundancy_constant);
120+
if (status != 0) {
121+
return MESH_ERROR_UNKNOWN;
122+
}
123+
124+
return MESH_ERROR_NONE;
125+
}
126+
127+
mesh_error_t WisunBorderRouter::set_pan_configuration(uint16_t pan_id)
128+
{
129+
int status = ws_bbr_pan_configuration_set(_mesh_if_id, pan_id);
130+
if (status != 0) {
131+
return MESH_ERROR_UNKNOWN;
132+
}
133+
134+
return MESH_ERROR_NONE;
135+
}
136+
137+
mesh_error_t WisunBorderRouter::get_pan_configuration(uint16_t *pan_id)
138+
{
139+
int status = ws_bbr_pan_configuration_get(_mesh_if_id, pan_id);
140+
if (status != 0) {
141+
return MESH_ERROR_UNKNOWN;
142+
}
143+
144+
return MESH_ERROR_NONE;
145+
}
146+
147+
mesh_error_t WisunBorderRouter::validate_pan_configuration(uint16_t pan_id)
148+
{
149+
int status = ws_bbr_pan_configuration_validate(_mesh_if_id, pan_id);
150+
if (status != 0) {
151+
return MESH_ERROR_UNKNOWN;
152+
}
153+
154+
return MESH_ERROR_NONE;
155+
}

0 commit comments

Comments
 (0)