Skip to content

Commit f1f6426

Browse files
authored
Merge pull request #8600 from KariHaapalehto/wisuninterface_created
Wi-SUN interface implementation.
2 parents 5b42e28 + 6163e6f commit f1f6426

File tree

11 files changed

+1077
-1
lines changed

11 files changed

+1077
-1
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2018 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 WISUNINTERFACE_H
18+
#define WISUNINTERFACE_H
19+
20+
#include "MeshInterfaceNanostack.h"
21+
22+
/** Wi-SUN mesh network interface class
23+
*
24+
* Configure Nanostack to use Wi-SUN protocol.
25+
*/
26+
class WisunInterface : public MeshInterfaceNanostack {
27+
public:
28+
29+
/** Create an uninitialized WisunInterface
30+
*
31+
* Must initialize to initialize the mesh on a phy.
32+
*/
33+
WisunInterface() { }
34+
35+
/** Create an initialized WisunInterface
36+
*
37+
*/
38+
WisunInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
39+
40+
bool getRouterIpAddress(char *address, int8_t len);
41+
protected:
42+
Nanostack::WisunInterface *get_interface() const;
43+
virtual nsapi_error_t do_initialize();
44+
};
45+
46+
#endif

features/nanostack/mbed-mesh-api/mbed_lib.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,50 @@
108108
"thread-security-policy": {
109109
"help": "Commissioning security policy bits [0-0xFF]",
110110
"value": 255
111+
},
112+
"wisun-network-name": {
113+
"help": "default network name for wisun network",
114+
"value": "\"NETWORK_NAME\""
115+
},
116+
"wisun-regulatory-domain": {
117+
"help": "Regulator domain.",
118+
"value": "3"
119+
},
120+
"wisun-operating-class": {
121+
"help": "Operating class.",
122+
"value": "255"
123+
},
124+
"wisun-operating-mode": {
125+
"help": "Operating mode.",
126+
"value": "255"
127+
},
128+
"wisun-uc-channel-function": {
129+
"help": "Unicast channel function.",
130+
"value": "255"
131+
},
132+
"wisun-bc-channel-function": {
133+
"help": "Broadcast channel function.",
134+
"value": "255"
135+
},
136+
"wisun-uc-fixed-channel": {
137+
"help": "Default fixed channel",
138+
"value": "0xffff"
139+
},
140+
"wisun-bc-fixed-channel": {
141+
"help": "Default fixed channel",
142+
"value": "0xffff"
143+
},
144+
"wisun-bc-interval": {
145+
"help": "Broadcast interval. Duration between broadcast dwell intervals. Range: 0-16777216 milliseconds",
146+
"value": 0
147+
},
148+
"wisun-bc-dwell-interval": {
149+
"help": "Broadcast dwell interval. Range: 15-255 milliseconds",
150+
"value": 0
151+
},
152+
"wisun-uc-dwell-interval": {
153+
"help": "Unicast dwell interval. Range: 15-255 milliseconds",
154+
"value": 0
111155
}
112156
},
113157
"target_overrides": {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2018 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+
117
#include "LoWPANNDInterface.h"
218
#include "include/nd_tasklet.h"
319
#include "callback_handler.h"

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2018 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+
117
#include "ThreadInterface.h"
218
#include "include/thread_tasklet.h"
319
#include "callback_handler.h"
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
/*
2+
* Copyright (c) 2018 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 "include/wisun_tasklet.h"
19+
#include "callback_handler.h"
20+
#include "NanostackLockGuard.h"
21+
#include "mesh_system.h"
22+
#include "randLIB.h"
23+
24+
#include "ns_trace.h"
25+
#define TRACE_GROUP "WSIn"
26+
27+
class Nanostack::WisunInterface : public Nanostack::MeshInterface {
28+
public:
29+
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
30+
const char *netmask, const char *gw,
31+
nsapi_ip_stack_t stack = IPV6_STACK,
32+
bool blocking = true);
33+
virtual nsapi_error_t bringdown();
34+
virtual char *get_gateway(char *buf, nsapi_size_t buflen);
35+
36+
friend Nanostack;
37+
friend class ::WisunInterface;
38+
private:
39+
WisunInterface(NanostackRfPhy &phy) : MeshInterface(phy) { }
40+
mesh_error_t init();
41+
mesh_error_t mesh_connect();
42+
mesh_error_t mesh_disconnect();
43+
};
44+
45+
Nanostack::WisunInterface *WisunInterface::get_interface() const
46+
{
47+
return static_cast<Nanostack::WisunInterface *>(_interface);
48+
}
49+
50+
nsapi_error_t WisunInterface::do_initialize()
51+
{
52+
if (!_interface) {
53+
_interface = new (nothrow) Nanostack::WisunInterface(*_phy);
54+
if (!_interface) {
55+
return NSAPI_ERROR_NO_MEMORY;
56+
}
57+
_interface->attach(_connection_status_cb);
58+
}
59+
return NSAPI_ERROR_OK;
60+
}
61+
62+
nsapi_error_t Nanostack::WisunInterface::bringup(bool dhcp, const char *ip,
63+
const char *netmask, const char *gw,
64+
nsapi_ip_stack_t stack, bool blocking)
65+
{
66+
nanostack_lock();
67+
68+
if (register_phy() < 0) {
69+
nanostack_unlock();
70+
return NSAPI_ERROR_DEVICE_ERROR;
71+
}
72+
73+
_blocking = blocking;
74+
75+
// After the RF is up, we can seed the random from it.
76+
randLIB_seed_random();
77+
78+
mesh_error_t status = init();
79+
if (status != MESH_ERROR_NONE) {
80+
nanostack_unlock();
81+
return map_mesh_error(status);
82+
}
83+
84+
status = mesh_connect();
85+
if (status != MESH_ERROR_NONE) {
86+
nanostack_unlock();
87+
return map_mesh_error(status);
88+
}
89+
90+
// Release mutex before blocking
91+
nanostack_unlock();
92+
93+
if (blocking) {
94+
// wait connection for ever
95+
int32_t count = connect_semaphore.wait(osWaitForever);
96+
97+
if (count <= 0) {
98+
return NSAPI_ERROR_DHCP_FAILURE; // sort of...
99+
}
100+
}
101+
return 0;
102+
103+
}
104+
105+
nsapi_error_t Nanostack::WisunInterface::bringdown()
106+
{
107+
NanostackLockGuard lock;
108+
109+
mesh_error_t status = mesh_disconnect();
110+
111+
return map_mesh_error(status);
112+
}
113+
114+
mesh_error_t Nanostack::WisunInterface::init()
115+
{
116+
wisun_tasklet_init();
117+
__mesh_handler_set_callback(this);
118+
interface_id = wisun_tasklet_network_init(_device_id);
119+
120+
if (interface_id == -2) {
121+
return MESH_ERROR_PARAM;
122+
} else if (interface_id == -3) {
123+
return MESH_ERROR_MEMORY;
124+
} else if (interface_id < 0) {
125+
return MESH_ERROR_UNKNOWN;
126+
}
127+
return MESH_ERROR_NONE;
128+
}
129+
130+
mesh_error_t Nanostack::WisunInterface::mesh_connect()
131+
{
132+
int8_t status = -9; // init to unknown error
133+
tr_debug("connect()");
134+
135+
status = wisun_tasklet_connect(&__mesh_handler_c_callback, interface_id);
136+
137+
if (status >= 0) {
138+
return MESH_ERROR_NONE;
139+
} else if (status == -1) {
140+
return MESH_ERROR_PARAM;
141+
} else if (status == -2) {
142+
return MESH_ERROR_MEMORY;
143+
} else if (status == -3) {
144+
return MESH_ERROR_STATE;
145+
} else {
146+
return MESH_ERROR_UNKNOWN;
147+
}
148+
}
149+
150+
mesh_error_t Nanostack::WisunInterface::mesh_disconnect()
151+
{
152+
int8_t status = -1;
153+
154+
status = wisun_tasklet_disconnect(true);
155+
156+
if (status >= 0) {
157+
return MESH_ERROR_NONE;
158+
}
159+
160+
return MESH_ERROR_UNKNOWN;
161+
}
162+
163+
char *Nanostack::WisunInterface::get_gateway(char *buf, nsapi_size_t buflen)
164+
{
165+
NanostackLockGuard lock;
166+
if (wisun_tasklet_get_router_ip_address(buf, buflen) == 0) {
167+
return buf;
168+
}
169+
return NULL;
170+
}
171+
172+
bool WisunInterface::getRouterIpAddress(char *address, int8_t len)
173+
{
174+
return _interface->get_gateway(address, len);
175+
}
176+
177+
#define WISUN 0x2345
178+
#if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == WISUN && DEVICE_802_15_4_PHY
179+
MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance()
180+
{
181+
static WisunInterface wisun(&NanostackRfPhy::get_default_instance());
182+
183+
return &wisun;
184+
}
185+
#endif

0 commit comments

Comments
 (0)