ncp: Network Control Processor (NCP) implementation (#31) (#45)

In addition to the "SoC/CLI" implementation that is already included,
OpenThread needs a Network Control Processor (NCP) implementation to
facilitate applications where the Host Controller is logically
separate from the controller that implements the Thread stack (Which
is the NCP). This task also necessitates the definition of the
protocol that the Host Controller and the NCP use to communicate with
each other.

This commit represents a functional starting point for both of these.
The initial name of the line protocol is "Spinel" (Named after the
[gemstone][1]). The long-term goal is to standardize the Spinel
protocol to be the official line protocol for host-to-NCP comunication
for Thread.

A [draft of the Spinel protocol document][2] is included in this
commit. At this point everything is subject to change, but as-is the
protocol has been demonstrated to work fairly well.

The NCP implementation in the has been tested and is working well
enough for basic connectivity, but it is far from complete. A Host
implementation is not yet provided in the tree, but will eventually be
included. A separate host implementation for Linux has been written
and is anticipated to be released as a separate project over the next
few weeks.

[1]: https://en.wikipedia.org/wiki/Spinel
[2]: https://github.com/openthread/openthread/blob/feature/ncp-spinel/src/ncp/PROTOCOL.md#spinel-host-controller-interface
This commit is contained in:
Robert Quattlebaum
2016-05-19 17:46:16 -07:00
committed by Jonathan Hui
parent d1b0fed201
commit 12a7060a85
18 changed files with 5726 additions and 2 deletions
+2
View File
@@ -33,6 +33,7 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
DIST_SUBDIRS = \
platform \
cli \
ncp \
$(NULL)
# Always build (e.g. for 'make all') these subdirectories.
@@ -40,6 +41,7 @@ DIST_SUBDIRS = \
SUBDIRS = \
platform \
cli \
ncp \
$(NULL)
# Always pretty (e.g. for 'make pretty') these subdirectories.
+53
View File
@@ -0,0 +1,53 @@
#
# Copyright (c) 2016, Nest Labs, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
bin_PROGRAMS = ncp
ncp_CPPFLAGS = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/core \
-I$(top_srcdir)/examples \
-I$(top_srcdir)/examples/platform/posix \
-I$(top_srcdir)/third_party \
$(OPENTHREAD_TARGET_DEFINES) \
$(NULL)
ncp_LDADD = \
$(top_builddir)/src/ncp/libopenthread-ncp.a \
$(top_builddir)/src/core/libopenthread.a \
$(top_builddir)/examples/platform/posix/libopenthread-posix.a \
$(top_builddir)/third_party/mbedtls/libmbedcrypto.a \
-lpthread \
$(NULL)
ncp_SOURCES = main.cpp
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
+78
View File
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2016, Nest Labs, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include <platform/posix/cmdline.h>
#include <ncp/ncp.hpp>
#include <platform/atomic.h>
#include <platform.h>
struct gengetopt_args_info args_info;
Thread::Ncp sNcp;
void otSignalTaskletPending(void)
{
}
int main(int argc, char *argv[])
{
uint32_t atomic_state;
memset(&args_info, 0, sizeof(args_info));
if (cmdline_parser(argc, argv, &args_info) != 0)
{
exit(1);
}
hwAlarmInit();
hwRadioInit();
hwRandomInit();
otInit();
sNcp.Start();
while (1)
{
otProcessNextTasklet();
atomic_state = otPlatAtomicBegin();
if (!otAreTaskletsPending())
{
hwSleep();
}
otPlatAtomicEnd(atomic_state);
}
return 0;
}