Skip to content

Wi-SUN interface implementation. #8600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2018 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef WISUNINTERFACE_H
#define WISUNINTERFACE_H

#include "MeshInterfaceNanostack.h"

/** Wi-SUN mesh network interface class
*
* Configure Nanostack to use Wi-SUN protocol.
*/
class WisunInterface : public MeshInterfaceNanostack {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not WiSUNInterface? We have LoWPANNDInterface with full silly capitalisation for 6LoWPAN-ND. Seems inconsistent, but maybe there's another factor.

public:

/** Create an uninitialized WisunInterface
*
* Must initialize to initialize the mesh on a phy.
*/
WisunInterface() { }

/** Create an initialized WisunInterface
*
*/
WisunInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }

bool getRouterIpAddress(char *address, int8_t len);
protected:
Nanostack::WisunInterface *get_interface() const;
virtual nsapi_error_t do_initialize();
};

#endif
44 changes: 44 additions & 0 deletions features/nanostack/mbed-mesh-api/mbed_lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,50 @@
"thread-security-policy": {
"help": "Commissioning security policy bits [0-0xFF]",
"value": 255
},
"wisun-network-name": {
"help": "default network name for wisun network",
"value": "\"NETWORK_NAME\""
},
"wisun-regulatory-domain": {
"help": "Regulator domain.",
"value": "3"
},
"wisun-operating-class": {
"help": "Operating class.",
"value": "255"
},
"wisun-operating-mode": {
"help": "Operating mode.",
"value": "255"
},
"wisun-uc-channel-function": {
"help": "Unicast channel function.",
"value": "255"
},
"wisun-bc-channel-function": {
"help": "Broadcast channel function.",
"value": "255"
},
"wisun-uc-fixed-channel": {
"help": "Default fixed channel",
"value": "0xffff"
},
"wisun-bc-fixed-channel": {
"help": "Default fixed channel",
"value": "0xffff"
},
"wisun-bc-interval": {
"help": "Broadcast interval. Duration between broadcast dwell intervals. Range: 0-16777216 milliseconds",
"value": 0
},
"wisun-bc-dwell-interval": {
"help": "Broadcast dwell interval. Range: 15-255 milliseconds",
"value": 0
},
"wisun-uc-dwell-interval": {
"help": "Unicast dwell interval. Range: 15-255 milliseconds",
"value": 0
}
},
"target_overrides": {
Expand Down
16 changes: 16 additions & 0 deletions features/nanostack/mbed-mesh-api/source/LoWPANNDInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2018 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "LoWPANNDInterface.h"
#include "include/nd_tasklet.h"
#include "callback_handler.h"
Expand Down
16 changes: 16 additions & 0 deletions features/nanostack/mbed-mesh-api/source/ThreadInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2018 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "ThreadInterface.h"
#include "include/thread_tasklet.h"
#include "callback_handler.h"
Expand Down
185 changes: 185 additions & 0 deletions features/nanostack/mbed-mesh-api/source/WisunInterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/*
* Copyright (c) 2018 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "WisunInterface.h"
#include "include/wisun_tasklet.h"
#include "callback_handler.h"
#include "NanostackLockGuard.h"
#include "mesh_system.h"
#include "randLIB.h"

#include "ns_trace.h"
#define TRACE_GROUP "WSIn"

class Nanostack::WisunInterface : public Nanostack::MeshInterface {
public:
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
const char *netmask, const char *gw,
nsapi_ip_stack_t stack = IPV6_STACK,
bool blocking = true);
virtual nsapi_error_t bringdown();
virtual char *get_gateway(char *buf, nsapi_size_t buflen);

friend Nanostack;
friend class ::WisunInterface;
private:
WisunInterface(NanostackRfPhy &phy) : MeshInterface(phy) { }
mesh_error_t init();
mesh_error_t mesh_connect();
mesh_error_t mesh_disconnect();
};

Nanostack::WisunInterface *WisunInterface::get_interface() const
{
return static_cast<Nanostack::WisunInterface *>(_interface);
}

nsapi_error_t WisunInterface::do_initialize()
{
if (!_interface) {
_interface = new (nothrow) Nanostack::WisunInterface(*_phy);
if (!_interface) {
return NSAPI_ERROR_NO_MEMORY;
}
_interface->attach(_connection_status_cb);
}
return NSAPI_ERROR_OK;
}

nsapi_error_t Nanostack::WisunInterface::bringup(bool dhcp, const char *ip,
const char *netmask, const char *gw,
nsapi_ip_stack_t stack, bool blocking)
{
nanostack_lock();

if (register_phy() < 0) {
nanostack_unlock();
return NSAPI_ERROR_DEVICE_ERROR;
}

_blocking = blocking;

// After the RF is up, we can seed the random from it.
randLIB_seed_random();

mesh_error_t status = init();
if (status != MESH_ERROR_NONE) {
nanostack_unlock();
return map_mesh_error(status);
}

status = mesh_connect();
if (status != MESH_ERROR_NONE) {
nanostack_unlock();
return map_mesh_error(status);
}

// Release mutex before blocking
nanostack_unlock();

if (blocking) {
// wait connection for ever
int32_t count = connect_semaphore.wait(osWaitForever);

if (count <= 0) {
return NSAPI_ERROR_DHCP_FAILURE; // sort of...
}
}
return 0;

}

nsapi_error_t Nanostack::WisunInterface::bringdown()
{
NanostackLockGuard lock;

mesh_error_t status = mesh_disconnect();

return map_mesh_error(status);
}

mesh_error_t Nanostack::WisunInterface::init()
{
wisun_tasklet_init();
__mesh_handler_set_callback(this);
interface_id = wisun_tasklet_network_init(_device_id);

if (interface_id == -2) {
return MESH_ERROR_PARAM;
} else if (interface_id == -3) {
return MESH_ERROR_MEMORY;
} else if (interface_id < 0) {
return MESH_ERROR_UNKNOWN;
}
return MESH_ERROR_NONE;
}

mesh_error_t Nanostack::WisunInterface::mesh_connect()
{
int8_t status = -9; // init to unknown error
tr_debug("connect()");

status = wisun_tasklet_connect(&__mesh_handler_c_callback, interface_id);

if (status >= 0) {
return MESH_ERROR_NONE;
} else if (status == -1) {
return MESH_ERROR_PARAM;
} else if (status == -2) {
return MESH_ERROR_MEMORY;
} else if (status == -3) {
return MESH_ERROR_STATE;
} else {
return MESH_ERROR_UNKNOWN;
}
}

mesh_error_t Nanostack::WisunInterface::mesh_disconnect()
{
int8_t status = -1;

status = wisun_tasklet_disconnect(true);

if (status >= 0) {
return MESH_ERROR_NONE;
}

return MESH_ERROR_UNKNOWN;
}

char *Nanostack::WisunInterface::get_gateway(char *buf, nsapi_size_t buflen)
{
NanostackLockGuard lock;
if (wisun_tasklet_get_router_ip_address(buf, buflen) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_gateway is calling wisun_tasklet_get_router_ip_address and getRouterIpAddress is calling get_gateway?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is implemented just like LOWPANNDInterface.
and WisunInterface::getRouterIpAddress is a api for wisun

return buf;
}
return NULL;
}

bool WisunInterface::getRouterIpAddress(char *address, int8_t len)
{
return _interface->get_gateway(address, len);
}

#define WISUN 0x2345
#if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == WISUN && DEVICE_802_15_4_PHY
MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance()
{
static WisunInterface wisun(&NanostackRfPhy::get_default_instance());

return &wisun;
}
#endif
Loading