mirror of
https://github.com/espressif/openthread.git
synced 2026-09-05 16:50:05 +00:00
spinel-cli is now maintained in a separate repo. (#1742)
This commit is contained in:
@@ -34,13 +34,11 @@ DIST_SUBDIRS = \
|
||||
harness-automation \
|
||||
harness-thci \
|
||||
spi-hdlc-adapter \
|
||||
spinel-cli \
|
||||
$(NULL)
|
||||
|
||||
# Always build (e.g. for 'make all') these subdirectories.
|
||||
|
||||
SUBDIRS = \
|
||||
spinel-cli \
|
||||
$(NULL)
|
||||
|
||||
if OPENTHREAD_BUILD_TOOLS
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
include README.md
|
||||
include SNIFFER.md
|
||||
@@ -1,64 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2016, The OpenThread Authors.
|
||||
# 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
|
||||
|
||||
EXTRA_DIST = \
|
||||
spinel-cli.py \
|
||||
sniffer.py \
|
||||
test_spinel.py \
|
||||
$(NULL)
|
||||
|
||||
DIST_SUBDIRS = \
|
||||
spinel \
|
||||
$(NULL)
|
||||
|
||||
# Always build (e.g. for 'make all') these subdirectories.
|
||||
|
||||
SUBDIRS = \
|
||||
$(NULL)
|
||||
|
||||
# Always pretty (e.g. for 'make pretty') these subdirectories.
|
||||
|
||||
PRETTY_SUBDIRS = \
|
||||
$(NULL)
|
||||
|
||||
if OPENTHREAD_ENABLE_NCP
|
||||
|
||||
# List all essential script tests that MUST be run.
|
||||
|
||||
TESTS_ENVIRONMENT = \
|
||||
$(NULL)
|
||||
|
||||
TESTS = \
|
||||
test_spinel.py \
|
||||
$(NULL)
|
||||
|
||||
endif # OPENTHREAD_ENABLE_NCP
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||
@@ -1,364 +0,0 @@
|
||||
# Spinel CLI Reference
|
||||
|
||||
The Spinel CLI exposes the OpenThread configuration and management APIs
|
||||
running on an NCP build via a command line interface. Spinel CLI is primarily
|
||||
targeted for driving the automated continuous integration tests, and is
|
||||
suitable for manual experimentation with controlling OpenThread NCP instances.
|
||||
For a production grade host driver, see [wpantund]: https://github.com/openthread/wpantund.
|
||||
|
||||
Use the CLI to play with NCP builds of OpenThread on a Linux or Mac OS
|
||||
platform, including starting a basic tunnel interface to allow IPv6
|
||||
applications to run on the HOST and use the Thread network.
|
||||
|
||||
The power of this tool is three fold:
|
||||
|
||||
1. As a path to add testing of the NCP in simulation to continuous integration
|
||||
2. As a path to automated testing of testbeds running NCP firmware on hardware
|
||||
3. As a simple debugging tool for NCP builds of OpenThread
|
||||
|
||||
## System Requirements
|
||||
|
||||
| OS | Minimum Version |
|
||||
|--------|------------------|
|
||||
| Ubuntu | 14.04 Trusty |
|
||||
| Mac OS | 10.11 El Capitan |
|
||||
|
||||
| Language | Minimum Version |
|
||||
|----------|------------------|
|
||||
| Python | 2.7.10 |
|
||||
|
||||
### Package Installation
|
||||
|
||||
```
|
||||
# From openthread root
|
||||
cd tools/spinel-cli
|
||||
sudo python setup.py install
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### NAME
|
||||
spinel-cli.py - shell tool for controlling OpenThread NCP instances
|
||||
|
||||
### SYNOPSIS
|
||||
spinel-cli.py [-hupsnqv]
|
||||
|
||||
### DESCRIPTION
|
||||
|
||||
```
|
||||
-h, --help
|
||||
Show this help message and exit
|
||||
|
||||
-u <UART>, --uart=<UART>
|
||||
Open a serial connection to the OpenThread NCP device
|
||||
where <UART> is a device path such as "/dev/ttyUSB0".
|
||||
|
||||
-p <PIPE>, --pipe=<PIPE>
|
||||
Open a piped process connection to the OpenThread NCP device
|
||||
where <PIPE> is the command to start an emulator, such as
|
||||
"ot-ncp-ftd". Spinel-cli will communicate with the child process
|
||||
via stdin/stdout.
|
||||
|
||||
-s <SOCKET>, --socket=<SOCKET>
|
||||
Open a socket connection to the OpenThread NCP device
|
||||
where <SOCKET> is the port to open.
|
||||
This is useful for SPI configurations when used in conjunction
|
||||
with a spinel spi-driver daemon.
|
||||
Note: <SOCKET> will eventually map to hostname:port tuple.
|
||||
|
||||
-n NODEID, --nodeid=NODEID
|
||||
The unique nodeid for the HOST and NCP instance.
|
||||
|
||||
-q, --quiet
|
||||
Minimize debug and log output.
|
||||
|
||||
-v, --verbose
|
||||
Maximize debug and log output.
|
||||
```
|
||||
|
||||
## Quick Start
|
||||
|
||||
The spinel-cli tool provides an intuitive command line interface, including
|
||||
all the standard OpenThread CLI commands, plus full history accessible by
|
||||
pressing the up/down keys, or searchable via ^R. There are a few commands
|
||||
that spinel-cli provides as well that aren't part of the standard set
|
||||
documented in the command reference section.
|
||||
|
||||
```
|
||||
openthread$ cd tools/spinel-cli/
|
||||
spinel-cli$ ./spinel-cli.py
|
||||
Opening pipe to ../../examples/apps/ncp/ot-ncp-ftd 1
|
||||
spinel-cli > help
|
||||
|
||||
Available commands (type help <name> for more information):
|
||||
============================================================
|
||||
channel extaddr mode route
|
||||
child extpanid netdataregister router
|
||||
childtimeout h networkidtimeout routerupgradethreshold
|
||||
clear help networkname scan
|
||||
contextreusedelay history panid state
|
||||
counter ifconfig ping thread
|
||||
debug ipaddr prefix v
|
||||
debug-term keysequence q version
|
||||
eidcache leaderdata quit whitelist
|
||||
enabled leaderweight releaserouterid
|
||||
exit masterkey rloc16
|
||||
|
||||
spinel-cli > version
|
||||
OPENTHREAD/gd4d4e9d-dirty; Aug 11 2016 14:40:44
|
||||
Done
|
||||
spinel-cli > thread start
|
||||
Done
|
||||
spinel-cli > state
|
||||
leader
|
||||
Done
|
||||
spinel-cli >
|
||||
```
|
||||
|
||||
## Running the NCP Tests
|
||||
|
||||
The OpenThread automated test suite can be run against any of the following
|
||||
node types by passing the NODE_TYPE environment variable:
|
||||
|
||||
| NODE_TYPE | Description |
|
||||
|---------------|----------------------------------------------------|
|
||||
| sim (default) | Runs against ot-cli posix emulator |
|
||||
| ncp-sim | Runs against ot-ncp posix emulator with spinel-cli |
|
||||
| soc | Runs against CLI firmware on a device connected via /dev/ttyUSB<nodeid> |
|
||||
|
||||
### Manual run of NCP thread-cert test
|
||||
|
||||
```
|
||||
# From top-level of openthread tree
|
||||
./bootstrap
|
||||
./configure --with-examples=posix --enable-cli-app=all --enable-ncp-app=all --with-ncp-bus=uart
|
||||
make
|
||||
cd tests/scripts/thread-cert
|
||||
NODE_TYPE=ncp-sim top_builddir=../../.. python Cert_5_1_02_ChildAddressTimeout.py VERBOSE=1
|
||||
```
|
||||
|
||||
### Run entire NCP thread-cert suite
|
||||
|
||||
```
|
||||
# From top-level of openthread tree
|
||||
make distclean
|
||||
./bootstrap
|
||||
NODE_TYPE=ncp-sim BUILD_TARGET=posix-distcheck DISTCHECK_CONFIGURE_FLAGS="--with-examples=posix --enable-cli-app --enable-ncp-app=all --with-ncp-bus=uart --with-tests=all" make -f examples/Makefile-posix distcheck BuildJobs=10 VERBOSE=1
|
||||
```
|
||||
|
||||
## Command Reference
|
||||
|
||||
### OpenThread CLI Commands
|
||||
|
||||
The primary intent of spinel-cli is to support the exact syntax and output
|
||||
of the OpenThread CLI command set in order to seamlessly reapply the
|
||||
thread-cert automated test suite against NCP targets.
|
||||
|
||||
See [cli module][1] for more information on these commands.
|
||||
|
||||
[1]:../../src/cli/README.md
|
||||
|
||||
### Diagnostics CLI Commands
|
||||
|
||||
The Diagnostics module is enabled only when building OpenThread with
|
||||
the --enable-diag configure option.
|
||||
|
||||
See [diag module][2] for more information on these commands.
|
||||
|
||||
[2]:../../src/diag/README.md
|
||||
|
||||
|
||||
### NCP CLI Commands
|
||||
|
||||
These commands extend beyond the core OpenThread CLI, and are specific to
|
||||
the spinel-cli tool for the purposes of debugging, access to NCP-specific
|
||||
Spinel parameters, and support of advanced configurations.
|
||||
|
||||
* [help](#help)
|
||||
* [?](#help)
|
||||
* [v](#v)
|
||||
* [exit](#exit)
|
||||
* [quit](#quit)
|
||||
* [q](#quit)
|
||||
* [clear](#clear)
|
||||
* [history](#history)
|
||||
* [h](#history)
|
||||
* [debug](#debug)
|
||||
* [debug-term](#debug-term)
|
||||
* [ncp-tun](#ncp-tun)
|
||||
* [ncp-ml64](#ncp-ml64)
|
||||
* [ncp-ll64](#ncp-ll64)
|
||||
|
||||
|
||||
#### help
|
||||
|
||||
Display help all top-level commands supported by spinel-cli.
|
||||
|
||||
```bash
|
||||
spinel-cli > help
|
||||
|
||||
Available commands (type help <name> for more information):
|
||||
============================================================
|
||||
channel diag-start leaderdata quit
|
||||
child diag-stats leaderweight releaserouterid
|
||||
childtimeout diag-stop masterkey rloc16
|
||||
clear discover mode route
|
||||
contextreusedelay eidcache ncp-ll64 router
|
||||
counter exit ncp-ml64 routerupgradethreshold
|
||||
debug extaddr ncp-tun scan
|
||||
debug-term extpanid netdataregister state
|
||||
diag h networkidtimeout thread
|
||||
diag-channel help networkname tun
|
||||
diag-power history panid v
|
||||
diag-repeat ifconfig ping version
|
||||
diag-send ipaddr prefix whitelist
|
||||
diag-sleep keysequence q
|
||||
|
||||
```
|
||||
|
||||
#### help \<command\>
|
||||
|
||||
Display detailed help on a specific command.
|
||||
|
||||
```bash
|
||||
spinel-cli > help version
|
||||
|
||||
version
|
||||
|
||||
Print the build version information.
|
||||
|
||||
> version
|
||||
OPENTHREAD/gf4f2f04; Jul 1 2016 17:00:09
|
||||
Done
|
||||
```
|
||||
|
||||
#### v
|
||||
|
||||
Display version of spinel-cli tool.
|
||||
|
||||
```bash
|
||||
spinel-cli > v
|
||||
spinel-cli ver. 0.1.0
|
||||
Copyright (c) 2016 The OpenThread Authors.
|
||||
```
|
||||
|
||||
#### exit
|
||||
|
||||
Exit spinel-cli. CTRL+C is also okay.
|
||||
|
||||
#### quit
|
||||
|
||||
Exit spinel-cli. CTRL+C is also okay.
|
||||
|
||||
### clear
|
||||
|
||||
Clear screen.
|
||||
|
||||
#### history
|
||||
|
||||
Display history of most recent commands run.
|
||||
|
||||
```bash
|
||||
spinel-cli > history
|
||||
ping fd00::1
|
||||
quit
|
||||
help
|
||||
history
|
||||
```
|
||||
|
||||
#### debug
|
||||
|
||||
Get whether debug verbose output is enabled.
|
||||
|
||||
```bash
|
||||
spinel-cli > debug
|
||||
DEBUG_ENABLE = 0
|
||||
```
|
||||
|
||||
#### debug \<enabled\>
|
||||
|
||||
Set whether debug verbose output is enabled.
|
||||
|
||||
spinel-cli > debug
|
||||
DEBUG_ENABLE = 0
|
||||
|
||||
```bash
|
||||
spinel-cli > debug 1
|
||||
DEBUG_ENABLE = 1
|
||||
spinel-cli > version
|
||||
TX Pay: (3) ['81', '02', '02']
|
||||
RX Pay: (53) ['81', '06', '02', '4F', '50', '45', '4E', '54', '48', '52', '45', '41', '44', '2F', '67', '38', '62', '63', '34', '62', '31', '64', '2D', '64', '69', '72', '74', '79', '3B', '20', '41', '75', '67', '20', '33', '31', '20', '32', '30', '31', '36', '20', '31', '30', '3A', '34', '38', '3A', '35', '33', '00', '40', '33']
|
||||
OPENTHREAD/g8bc4b1d-dirty; Aug 31 2016 10:48:53
|
||||
Done
|
||||
```
|
||||
|
||||
#### debug-term
|
||||
|
||||
Get whether debug terminal title bar is enabled.
|
||||
|
||||
#### debug-term \<enabled\>
|
||||
|
||||
Set whether debug terminal title bar is enabled.
|
||||
|
||||
#### ncp-tun
|
||||
|
||||
Control sideband tunnel interface.
|
||||
|
||||
#### ncp-tun up
|
||||
|
||||
Bring up Thread TUN interface.
|
||||
|
||||
```bash
|
||||
spinel-cli > ncp-tun up
|
||||
Done
|
||||
```
|
||||
|
||||
#### ncp-tun down
|
||||
|
||||
Bring down Thread TUN interface.
|
||||
|
||||
```bash
|
||||
spinel-cli > ncp-tun down
|
||||
Done
|
||||
```
|
||||
|
||||
#### ncp-tun add \<ipaddr\>
|
||||
|
||||
Add an IPv6 address to the Thread TUN interface.
|
||||
|
||||
```bash
|
||||
spinel-cli > ncp-tun add 2001::dead:beef:cafe
|
||||
Done
|
||||
```
|
||||
|
||||
#### ncp-tun del \<ipaddr\>
|
||||
|
||||
Delete an IPv6 address from the Thread TUN interface.
|
||||
|
||||
```bash
|
||||
spinel-cli > ncp-tun del 2001::dead:beef:cafe
|
||||
Done
|
||||
```
|
||||
|
||||
#### ncp-tun ping \<ipaddr\> \[size\] \[count\] \[interval\]
|
||||
|
||||
Send an ICMPv6 Echo Request via a posix host system call.
|
||||
|
||||
```bash
|
||||
spinel-cli > ncp-tun ping fdde:ad00:beef:0:558:f56b:d688:799
|
||||
16 bytes from fdde:ad00:beef:0:558:f56b:d688:799: icmp_seq=1 hlim=64 time=28ms
|
||||
```
|
||||
|
||||
#### ncp-ml64
|
||||
|
||||
Return the Mesh Local 64-bit IPv6 address for the node.
|
||||
|
||||
```
|
||||
spinel-cli > ncp-ml64
|
||||
fdde:ad00:beef:0:558:f56b:d688:799
|
||||
Done
|
||||
```
|
||||
|
||||
#### ncp-ll64
|
||||
|
||||
Return the Link Local 64-bit IPv6 address for the node.
|
||||
@@ -1,108 +0,0 @@
|
||||
# Spinel Sniffer Reference
|
||||
|
||||
Any Spinel NCP node can be made into a promiscuous packet sniffer, and this
|
||||
tool both intializes a device into this mode and outputs a pcap stream that
|
||||
can be saved or piped directly into Wireshark.
|
||||
|
||||
## System Requirements
|
||||
|
||||
The tool has been tested on the following platforms:
|
||||
|
||||
| Platforms | Version |
|
||||
|-----------|------------------|
|
||||
| Ubuntu | 14.04 Trusty |
|
||||
| Mac OS | 10.11 El Capitan |
|
||||
|
||||
| Language | Version |
|
||||
|-----------|------------------|
|
||||
| Python | 2.7.10 |
|
||||
|
||||
### Package Installation
|
||||
|
||||
```
|
||||
sudo easy_install pip
|
||||
sudo pip install --user pyserial
|
||||
sudo pip install --user ipaddress
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### NAME
|
||||
sniffer.py - shell tool for controlling OpenThread NCP instances
|
||||
|
||||
### SYNOPSIS
|
||||
sniffer.py [-hupsnqvdxc]
|
||||
|
||||
### DESCRIPTION
|
||||
|
||||
```
|
||||
-h, --help
|
||||
Show this help message and exit
|
||||
|
||||
-u <UART>, --uart=<UART>
|
||||
Open a serial connection to the OpenThread NCP device
|
||||
where <UART> is a device path such as "/dev/ttyUSB0".
|
||||
|
||||
-p <PIPE>, --pipe=<PIPE>
|
||||
Open a piped process connection to the OpenThread NCP device
|
||||
where <PIPE> is the command to start an emulator, such as
|
||||
"ot-ncp-ftd". Spinel-cli will communicate with the child process
|
||||
via stdin/stdout.
|
||||
|
||||
-s <SOCKET>, --socket=<SOCKET>
|
||||
Open a socket connection to the OpenThread NCP device
|
||||
where <SOCKET> is the port to open.
|
||||
This is useful for SPI configurations when used in conjunction
|
||||
with a spinel spi-driver daemon.
|
||||
Note: <SOCKET> will eventually map to hostname:port tuple.
|
||||
|
||||
-n NODEID, --nodeid=<NODEID>
|
||||
The unique nodeid for the HOST and NCP instance.
|
||||
|
||||
-q, --quiet
|
||||
Minimize debug and log output.
|
||||
|
||||
-v, --verbose
|
||||
Maximize debug and log output.
|
||||
|
||||
-d <DEBUG_LEVEL>, --debug=<DEBUG_LEVEL>
|
||||
Set the debug level. Enabling debug output is typically coupled with -x.
|
||||
0: Supress all debug output. Required to stream to Wireshark.
|
||||
1: Show spinel property changes and values.
|
||||
2: Show spinel IPv6 packet bytes.
|
||||
3: Show spinel raw packet bytes (after HDLC decoding).
|
||||
4: Show spinel HDLC bytes.
|
||||
5: Show spinel raw stream bytes: all serial traffic to NCP.
|
||||
|
||||
-x, --hex
|
||||
Output packets as ASCII HEX rather than pcap.
|
||||
|
||||
-c, --channel
|
||||
Set the channel upon which to listen.
|
||||
```
|
||||
|
||||
## Quick Start
|
||||
|
||||
From openthread root:
|
||||
|
||||
```
|
||||
sudo ./tools/spinel-cli/sniffer.py -c 11 -n 1 -u /dev/ttyUSB0 | wireshark -k -i -
|
||||
```
|
||||
|
||||
This will connect to stock openthread ncp firmware over the given UART,
|
||||
make the node into a promiscuous mode sniffer on the given channel,
|
||||
open up wireshark, and start streaming packets into wireshark.
|
||||
|
||||
## Troubleshooting
|
||||
Q: sniffer.py throws ```ImportError: No module named dnet``` on OSX
|
||||
|
||||
A: install the libdnet package for OSX -
|
||||
```
|
||||
brew install --with-python libdnet
|
||||
mkdir -p /Users/YourUsernameHere/Library/Python/2.7/lib/python/site-packages
|
||||
touch /Users/YourUsernameHere/Library/Python/2.7/lib/python/site-packages/homebrew.pth
|
||||
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/YourUsernameHere/Library/Python/2.7/lib/python/site-packages/homebrew.pth
|
||||
```
|
||||
you may need to reinstall the scapy pip dependency listed above
|
||||
|
||||
you can read more about this issue here: http://stackoverflow.com/questions/26229057/scapy-installation-fails-on-osx-with-dnet-import-error
|
||||
@@ -1,62 +0,0 @@
|
||||
#!/usr/bin/env python -u
|
||||
#
|
||||
# Copyright (c) 2016, The OpenThread Authors.
|
||||
# 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.
|
||||
#
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name='spinel',
|
||||
version='1.0.0a1',
|
||||
description='A Python interface to the OpenThread Network Co-Processor (NCP)',
|
||||
url='https://github.com/openthread/openthread',
|
||||
author='The OpenThread Authors',
|
||||
author_email='[email protected]',
|
||||
license='BSD',
|
||||
classifiers=[
|
||||
'Development Status :: 3 - Alpha',
|
||||
'Intended Audience :: Developers',
|
||||
|
||||
'Operating System :: MacOS',
|
||||
'Operating System :: POSIX :: Linux',
|
||||
|
||||
'License :: OSI Approved :: BSD License',
|
||||
|
||||
'Topic :: System :: Networking',
|
||||
'Topic :: System :: Hardware :: Hardware Drivers',
|
||||
'Topic :: Software Development :: Embedded Systems',
|
||||
|
||||
'Programming Language :: Python :: 2.7',
|
||||
],
|
||||
keywords='openthread thread spinel ncp',
|
||||
packages=find_packages(),
|
||||
install_requires=[
|
||||
'pyserial',
|
||||
'ipaddress',
|
||||
'scapy==2.3.2'
|
||||
],
|
||||
scripts=['spinel-cli.py', 'sniffer.py']
|
||||
)
|
||||
@@ -1,154 +0,0 @@
|
||||
#!/usr/bin/env python -u
|
||||
#
|
||||
# Copyright (c) 2016, The OpenThread Authors.
|
||||
# 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.
|
||||
#
|
||||
"""
|
||||
Sniffer tool that outputs raw pcap.
|
||||
|
||||
Real-time stream to wireshark:
|
||||
./sniffer.py | wireshark -k -i -
|
||||
|
||||
Save stream to file or pipe:
|
||||
./sniffer.py > trace.pcap
|
||||
"""
|
||||
|
||||
import sys
|
||||
import optparse
|
||||
|
||||
import spinel.util as util
|
||||
import spinel.config as CONFIG
|
||||
from spinel.const import SPINEL
|
||||
from spinel.codec import WpanApi
|
||||
from spinel.stream import StreamOpen
|
||||
from spinel.pcap import PcapCodec
|
||||
|
||||
|
||||
# Nodeid is required to execute ot-ncp-ftd for its sim radio socket port.
|
||||
# This is maximum that works for MacOS.
|
||||
DEFAULT_NODEID = 34 # same as WELLKNOWN_NODE_ID
|
||||
DEFAULT_CHANNEL = 11
|
||||
|
||||
def parse_args():
|
||||
""" Parse command line arguments for this applications. """
|
||||
|
||||
args = sys.argv[1:]
|
||||
|
||||
opt_parser = optparse.OptionParser()
|
||||
opt_parser.add_option("-u", "--uart", action="store",
|
||||
dest="uart", type="string")
|
||||
opt_parser.add_option("-p", "--pipe", action="store",
|
||||
dest="pipe", type="string")
|
||||
opt_parser.add_option("-s", "--socket", action="store",
|
||||
dest="socket", type="string")
|
||||
opt_parser.add_option("-n", "--nodeid", action="store",
|
||||
dest="nodeid", type="string", default=str(DEFAULT_NODEID))
|
||||
|
||||
opt_parser.add_option("-q", "--quiet", action="store_true", dest="quiet")
|
||||
opt_parser.add_option("-v", "--verbose", action="store_false", dest="verbose")
|
||||
opt_parser.add_option("-d", "--debug", action="store",
|
||||
dest="debug", type="int", default=CONFIG.DEBUG_ENABLE)
|
||||
opt_parser.add_option("-x", "--hex", action="store_true", dest="hex")
|
||||
|
||||
opt_parser.add_option("-c", "--channel", action="store",
|
||||
dest="channel", type="int", default=DEFAULT_CHANNEL)
|
||||
|
||||
return opt_parser.parse_args(args)
|
||||
|
||||
def sniffer_init(wpan_api, options):
|
||||
"""" Send spinel commands to initialize sniffer node. """
|
||||
wpan_api.queue_register(SPINEL.HEADER_DEFAULT)
|
||||
wpan_api.queue_register(SPINEL.HEADER_ASYNC)
|
||||
|
||||
wpan_api.cmd_send(SPINEL.CMD_RESET)
|
||||
wpan_api.prop_set_value(SPINEL.PROP_PHY_ENABLED, 1)
|
||||
wpan_api.prop_set_value(SPINEL.PROP_MAC_FILTER_MODE, SPINEL.MAC_FILTER_MODE_MONITOR)
|
||||
wpan_api.prop_set_value(SPINEL.PROP_PHY_CHAN, options.channel)
|
||||
wpan_api.prop_set_value(SPINEL.PROP_MAC_15_4_PANID, 0xFFFF, 'H')
|
||||
wpan_api.prop_set_value(SPINEL.PROP_MAC_RAW_STREAM_ENABLED, 1)
|
||||
wpan_api.prop_set_value(SPINEL.PROP_NET_IF_UP, 1)
|
||||
|
||||
def main():
|
||||
""" Top-level main for sniffer host-side tool. """
|
||||
(options, remaining_args) = parse_args()
|
||||
|
||||
if options.debug:
|
||||
CONFIG.debug_set_level(options.debug)
|
||||
|
||||
# Set default stream to pipe
|
||||
stream_type = 'p'
|
||||
stream_descriptor = "../../examples/apps/ncp/ot-ncp-ftd "+options.nodeid
|
||||
|
||||
if options.uart:
|
||||
stream_type = 'u'
|
||||
stream_descriptor = options.uart
|
||||
elif options.socket:
|
||||
stream_type = 's'
|
||||
stream_descriptor = options.socket
|
||||
elif options.pipe:
|
||||
stream_type = 'p'
|
||||
stream_descriptor = options.pipe
|
||||
if options.nodeid:
|
||||
stream_descriptor += " "+str(options.nodeid)
|
||||
else:
|
||||
if len(remaining_args) > 0:
|
||||
stream_descriptor = " ".join(remaining_args)
|
||||
|
||||
stream = StreamOpen(stream_type, stream_descriptor, False)
|
||||
if stream is None: exit()
|
||||
wpan_api = WpanApi(stream, options.nodeid)
|
||||
sniffer_init(wpan_api, options)
|
||||
|
||||
pcap = PcapCodec()
|
||||
hdr = pcap.encode_header()
|
||||
if options.hex:
|
||||
hdr = util.hexify_str(hdr)+"\n"
|
||||
sys.stdout.write(hdr)
|
||||
sys.stdout.flush()
|
||||
|
||||
try:
|
||||
tid = SPINEL.HEADER_ASYNC
|
||||
prop_id = SPINEL.PROP_STREAM_RAW
|
||||
while True:
|
||||
result = wpan_api.queue_wait_for_prop(prop_id, tid)
|
||||
if result and result.prop == prop_id:
|
||||
length = wpan_api.parse_S(result.value)
|
||||
pkt = result.value[2:2+length]
|
||||
pkt = pcap.encode_frame(pkt)
|
||||
if options.hex:
|
||||
pkt = util.hexify_str(pkt)+"\n"
|
||||
sys.stdout.write(pkt)
|
||||
sys.stdout.flush()
|
||||
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
if wpan_api:
|
||||
wpan_api.stream.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,51 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2016, The OpenThread Authors.
|
||||
# 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
|
||||
|
||||
EXTRA_DIST = \
|
||||
__init__.py \
|
||||
codec.py \
|
||||
config.py \
|
||||
const.py \
|
||||
hdlc.py \
|
||||
stream.py \
|
||||
pcap.py \
|
||||
tun.py \
|
||||
util.py \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DIST += \
|
||||
tests.py \
|
||||
test_codec.py \
|
||||
test_hdlc.py \
|
||||
test_stream.py \
|
||||
test_sniffer.py \
|
||||
$(NULL)
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||
@@ -1,27 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2016, The OpenThread Authors.
|
||||
# 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.
|
||||
#
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,113 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2016, The OpenThread Authors.
|
||||
# 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.
|
||||
#
|
||||
""" Module-wide logging configuration for spinel package. """
|
||||
|
||||
import logging
|
||||
import logging.config
|
||||
|
||||
DEBUG_ENABLE = 0
|
||||
|
||||
DEBUG_TUN = 0
|
||||
DEBUG_HDLC = 0
|
||||
|
||||
DEBUG_STREAM_TX = 0
|
||||
DEBUG_STREAM_RX = 0
|
||||
|
||||
DEBUG_LOG_PKT = DEBUG_ENABLE
|
||||
DEBUG_LOG_SERIAL = DEBUG_ENABLE
|
||||
DEBUG_LOG_PROP = DEBUG_ENABLE
|
||||
DEBUG_CMD_RESPONSE = 0
|
||||
DEBUG_EXPERIMENTAL = 1
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
logging.config.dictConfig({
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
|
||||
'formatters': {
|
||||
'minimal': {
|
||||
'format': '%(message)s'
|
||||
},
|
||||
'standard': {
|
||||
'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
|
||||
},
|
||||
},
|
||||
'handlers': {
|
||||
'console': {
|
||||
#'level':'INFO',
|
||||
'level': 'DEBUG',
|
||||
'class': 'logging.StreamHandler',
|
||||
},
|
||||
#'syslog': {
|
||||
# 'level':'DEBUG',
|
||||
# 'class':'logging.handlers.SysLogHandler',
|
||||
# 'address': '/dev/log'
|
||||
#},
|
||||
},
|
||||
'loggers': {
|
||||
'spinel': {
|
||||
'handlers': ['console'], # ,'syslog'],
|
||||
'level': 'DEBUG',
|
||||
'propagate': True
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
def debug_set_level(level):
|
||||
""" Set logging level for spinel module. """
|
||||
global DEBUG_ENABLE, DEBUG_LOG_PROP
|
||||
global DEBUG_LOG_PKT, DEBUG_LOG_SERIAL
|
||||
global DEBUG_STREAM_RX, DEBUG_STREAM_TX, DEBUG_HDLC
|
||||
|
||||
# Defaut to all logging disabled
|
||||
|
||||
DEBUG_ENABLE = 0
|
||||
DEBUG_LOG_PROP = 0
|
||||
DEBUG_LOG_PKT = 0
|
||||
DEBUG_LOG_SERIAL = 0
|
||||
DEBUG_HDLC = 0
|
||||
DEBUG_STREAM_RX = 0
|
||||
DEBUG_STREAM_TX = 0
|
||||
|
||||
if level:
|
||||
DEBUG_ENABLE = level
|
||||
if level >= 1:
|
||||
DEBUG_LOG_PROP = 1
|
||||
if level >= 2:
|
||||
DEBUG_LOG_PKT = 1
|
||||
if level >= 3:
|
||||
DEBUG_LOG_SERIAL = 1
|
||||
if level >= 4:
|
||||
DEBUG_HDLC = 1
|
||||
if level >= 5:
|
||||
DEBUG_STREAM_RX = 1
|
||||
DEBUG_STREAM_TX = 1
|
||||
|
||||
print("DEBUG_ENABLE = " + str(DEBUG_ENABLE))
|
||||
@@ -1,417 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2016, The OpenThread Authors.
|
||||
# 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.
|
||||
#
|
||||
""" Module-wide constants for spinel package. """
|
||||
|
||||
class SPINEL(object):
|
||||
""" Singular class that contains all Spinel constants. """
|
||||
HEADER_ASYNC = 0x80
|
||||
HEADER_DEFAULT = 0x81
|
||||
HEADER_EVENT_HANDLER = 0x82
|
||||
|
||||
#=========================================
|
||||
# Spinel Commands: Host -> NCP
|
||||
#=========================================
|
||||
|
||||
CMD_NOOP = 0
|
||||
CMD_RESET = 1
|
||||
CMD_PROP_VALUE_GET = 2
|
||||
CMD_PROP_VALUE_SET = 3
|
||||
CMD_PROP_VALUE_INSERT = 4
|
||||
CMD_PROP_VALUE_REMOVE = 5
|
||||
|
||||
#=========================================
|
||||
# Spinel Command Responses: NCP -> Host
|
||||
#=========================================
|
||||
RSP_PROP_VALUE_IS = 6
|
||||
RSP_PROP_VALUE_INSERTED = 7
|
||||
RSP_PROP_VALUE_REMOVED = 8
|
||||
|
||||
CMD_NET_SAVE = 9
|
||||
CMD_NET_CLEAR = 10
|
||||
CMD_NET_RECALL = 11
|
||||
|
||||
RSP_HBO_OFFLOAD = 12
|
||||
RSP_HBO_RECLAIM = 13
|
||||
RSP_HBO_DROP = 14
|
||||
|
||||
CMD_HBO_OFFLOADED = 15
|
||||
CMD_HBO_RECLAIMED = 16
|
||||
CMD_HBO_DROPPED = 17
|
||||
|
||||
CMD_NEST__BEGIN = 15296
|
||||
CMD_NEST__END = 15360
|
||||
|
||||
CMD_VENDOR__BEGIN = 15360
|
||||
CMD_VENDOR__END = 16384
|
||||
|
||||
CMD_EXPERIMENTAL__BEGIN = 2000000
|
||||
CMD_EXPERIMENTAL__END = 2097152
|
||||
|
||||
#=========================================
|
||||
# Spinel Properties
|
||||
#=========================================
|
||||
|
||||
PROP_LAST_STATUS = 0 # < status [i]
|
||||
PROP_PROTOCOL_VERSION = 1 # < major, minor [i,i]
|
||||
PROP_NCP_VERSION = 2 # < version string [U]
|
||||
PROP_INTERFACE_TYPE = 3 # < [i]
|
||||
PROP_VENDOR_ID = 4 # < [i]
|
||||
PROP_CAPS = 5 # < capability list [A(i)]
|
||||
PROP_INTERFACE_COUNT = 6 # < Interface count [C]
|
||||
PROP_POWER_STATE = 7 # < PowerState [C]
|
||||
PROP_HWADDR = 8 # < PermEUI64 [E]
|
||||
PROP_LOCK = 9 # < PropLock [b]
|
||||
PROP_HBO_MEM_MAX = 10 # < Max offload mem [S]
|
||||
PROP_HBO_BLOCK_MAX = 11 # < Max offload block [S]
|
||||
|
||||
PROP_PHY__BEGIN = 0x20
|
||||
PROP_PHY_ENABLED = PROP_PHY__BEGIN + 0 # < [b]
|
||||
PROP_PHY_CHAN = PROP_PHY__BEGIN + 1 # < [C]
|
||||
PROP_PHY_CHAN_SUPPORTED = PROP_PHY__BEGIN + 2 # < [A(C)]
|
||||
PROP_PHY_FREQ = PROP_PHY__BEGIN + 3 # < kHz [L]
|
||||
PROP_PHY_CCA_THRESHOLD = PROP_PHY__BEGIN + 4 # < dBm [c]
|
||||
PROP_PHY_TX_POWER = PROP_PHY__BEGIN + 5 # < [c]
|
||||
PROP_PHY_RSSI = PROP_PHY__BEGIN + 6 # < dBm [c]
|
||||
PROP_PHY__END = 0x30
|
||||
|
||||
PROP_MAC__BEGIN = 0x30
|
||||
PROP_MAC_SCAN_STATE = PROP_MAC__BEGIN + 0 # < [C]
|
||||
PROP_MAC_SCAN_MASK = PROP_MAC__BEGIN + 1 # < [A(C)]
|
||||
PROP_MAC_SCAN_PERIOD = PROP_MAC__BEGIN + 2 # < ms-per-channel [S]
|
||||
# < chan,rssi,(laddr,saddr,panid,lqi),(proto,xtra) [Cct(ESSC)t(i)]
|
||||
PROP_MAC_SCAN_BEACON = PROP_MAC__BEGIN + 3
|
||||
PROP_MAC_15_4_LADDR = PROP_MAC__BEGIN + 4 # < [E]
|
||||
PROP_MAC_15_4_SADDR = PROP_MAC__BEGIN + 5 # < [S]
|
||||
PROP_MAC_15_4_PANID = PROP_MAC__BEGIN + 6 # < [S]
|
||||
PROP_MAC_RAW_STREAM_ENABLED = PROP_MAC__BEGIN + 7 # < [C]
|
||||
PROP_MAC_FILTER_MODE = PROP_MAC__BEGIN + 8 # < [C]
|
||||
PROP_MAC__END = 0x40
|
||||
|
||||
PROP_MAC_EXT__BEGIN = 0x1300
|
||||
# Format: `A(T(Ec))`
|
||||
# * `E`: EUI64 address of node
|
||||
# * `c`: Optional fixed RSSI. -127 means not set.
|
||||
PROP_MAC_WHITELIST = PROP_MAC_EXT__BEGIN + 0
|
||||
PROP_MAC_WHITELIST_ENABLED = PROP_MAC_EXT__BEGIN + 1 # < [b]
|
||||
PROP_MAC_EXT__END = 0x1400
|
||||
|
||||
PROP_NET__BEGIN = 0x40
|
||||
PROP_NET_SAVED = PROP_NET__BEGIN + 0 # < [b]
|
||||
PROP_NET_IF_UP = PROP_NET__BEGIN + 1 # < [b]
|
||||
PROP_NET_STACK_UP = PROP_NET__BEGIN + 2 # < [C]
|
||||
PROP_NET_ROLE = PROP_NET__BEGIN + 3 # < [C]
|
||||
PROP_NET_NETWORK_NAME = PROP_NET__BEGIN + 4 # < [U]
|
||||
PROP_NET_XPANID = PROP_NET__BEGIN + 5 # < [D]
|
||||
PROP_NET_MASTER_KEY = PROP_NET__BEGIN + 6 # < [D]
|
||||
PROP_NET_KEY_SEQUENCE_COUNTER = PROP_NET__BEGIN + 7 # < [L]
|
||||
PROP_NET_PARTITION_ID = PROP_NET__BEGIN + 8 # < [L]
|
||||
PROP_NET_KEY_SWITCH_GUARDTIME = PROP_NET__BEGIN + 10 # < [L]
|
||||
PROP_NET__END = 0x50
|
||||
|
||||
PROP_THREAD__BEGIN = 0x50
|
||||
PROP_THREAD_LEADER_ADDR = PROP_THREAD__BEGIN + 0 # < [6]
|
||||
PROP_THREAD_PARENT = PROP_THREAD__BEGIN + 1 # < LADDR, SADDR [ES]
|
||||
PROP_THREAD_CHILD_TABLE = PROP_THREAD__BEGIN + 2 # < [A(t(ES))]
|
||||
PROP_THREAD_LEADER_RID = PROP_THREAD__BEGIN + 3 # < [C]
|
||||
PROP_THREAD_LEADER_WEIGHT = PROP_THREAD__BEGIN + 4 # < [C]
|
||||
PROP_THREAD_LOCAL_LEADER_WEIGHT = PROP_THREAD__BEGIN + 5 # < [C]
|
||||
PROP_THREAD_NETWORK_DATA = PROP_THREAD__BEGIN + 6 # < [D]
|
||||
PROP_THREAD_NETWORK_DATA_VERSION = PROP_THREAD__BEGIN + 7 # < [S]
|
||||
PROP_THREAD_STABLE_NETWORK_DATA = PROP_THREAD__BEGIN + 8 # < [D]
|
||||
PROP_THREAD_STABLE_NETWORK_DATA_VERSION = PROP_THREAD__BEGIN + 9 # < [S]
|
||||
# < array(ipv6prefix,prefixlen,stable,flags) [A(t(6CbC))]
|
||||
PROP_THREAD_ON_MESH_NETS = PROP_THREAD__BEGIN + 10
|
||||
# < array(ipv6prefix,prefixlen,stable,flags) [A(t(6CbC))]
|
||||
PROP_THREAD_LOCAL_ROUTES = PROP_THREAD__BEGIN + 11
|
||||
PROP_THREAD_ASSISTING_PORTS = PROP_THREAD__BEGIN + 12 # < array(portn) [A(S)]
|
||||
PROP_THREAD_ALLOW_LOCAL_NET_DATA_CHANGE = PROP_THREAD__BEGIN + 13 # < [b]
|
||||
PROP_THREAD_MODE = PROP_THREAD__BEGIN + 14
|
||||
PROP_THREAD__END = 0x60
|
||||
|
||||
PROP_THREAD_EXT__BEGIN = 0x1500
|
||||
PROP_THREAD_CHILD_TIMEOUT = PROP_THREAD_EXT__BEGIN + 0 # < [L]
|
||||
PROP_THREAD_RLOC16 = PROP_THREAD_EXT__BEGIN + 1 # < [S]
|
||||
PROP_THREAD_ROUTER_UPGRADE_THRESHOLD = PROP_THREAD_EXT__BEGIN + 2 # < [C]
|
||||
PROP_THREAD_CONTEXT_REUSE_DELAY = PROP_THREAD_EXT__BEGIN + 3 # < [L]
|
||||
PROP_THREAD_NETWORK_ID_TIMEOUT = PROP_THREAD_EXT__BEGIN + 4 # < [b]
|
||||
PROP_THREAD_ACTIVE_ROUTER_IDS = PROP_THREAD_EXT__BEGIN + 5 # < [A(b)]
|
||||
PROP_THREAD_RLOC16_DEBUG_PASSTHRU = PROP_THREAD_EXT__BEGIN + 6 # < [b]
|
||||
PROP_THREAD_ROUTER_ROLE_ENABLED = PROP_THREAD_EXT__BEGIN + 7 # < [b]
|
||||
PROP_THREAD_ROUTER_DOWNGRADE_THRESHOLD = PROP_THREAD_EXT__BEGIN + 8 # < [C]
|
||||
PROP_THREAD_ROUTER_SELECTION_JITTER = PROP_THREAD_EXT__BEGIN + 9 # < [C]
|
||||
PROP_THREAD_PREFERRED_ROUTER_ID = PROP_THREAD_EXT__BEGIN + 10 # < [C]
|
||||
PROP_THREAD_NEIGHBOR_TABLE = PROP_THREAD_EXT__BEGIN + 11 # < [A(t(ESLCcCbLL))]
|
||||
PROP_THREAD_CHILD_COUNT_MAX = PROP_THREAD_EXT__BEGIN + 12 # < [C]
|
||||
|
||||
PROP_THREAD_EXT__END = 0x1600
|
||||
|
||||
PROP_MESHCOP_EXT__BEGIN = 0x1600
|
||||
PROP_MESHCOP_JOINER_ENABLE = PROP_MESHCOP_EXT__BEGIN + 0 # < [b]
|
||||
PROP_MESHCOP_JOINER_CREDENTIAL = PROP_MESHCOP_EXT__BEGIN + 1 # < [D]
|
||||
PROP_MESHCOP_JOINER_URL = PROP_MESHCOP_EXT__BEGIN + 2 # < [U]
|
||||
PROP_MESHCOP_BORDER_AGENT_ENABLE = PROP_MESHCOP_EXT__BEGIN + 3 # < [b]
|
||||
PROP_MESHCOP_EXT__END = 0x1700
|
||||
|
||||
PROP_IPV6__BEGIN = 0x60
|
||||
PROP_IPV6_LL_ADDR = PROP_IPV6__BEGIN + 0 # < [6]
|
||||
PROP_IPV6_ML_ADDR = PROP_IPV6__BEGIN + 1 # < [6C]
|
||||
PROP_IPV6_ML_PREFIX = PROP_IPV6__BEGIN + 2 # < [6C]
|
||||
# < array(ipv6addr,prefixlen,valid,preferred,flags) [A(t(6CLLC))]
|
||||
PROP_IPV6_ADDRESS_TABLE = PROP_IPV6__BEGIN + 3
|
||||
# < array(ipv6prefix,prefixlen,iface,flags) [A(t(6CCC))]
|
||||
PROP_IPV6_ROUTE_TABLE = PROP_IPV6__BEGIN + 4
|
||||
PROP_IPv6_ICMP_PING_OFFLOAD = PROP_IPV6__BEGIN + 5 # < [b]
|
||||
|
||||
PROP_STREAM__BEGIN = 0x70
|
||||
PROP_STREAM_DEBUG = PROP_STREAM__BEGIN + 0 # < [U]
|
||||
PROP_STREAM_RAW = PROP_STREAM__BEGIN + 1 # < [D]
|
||||
PROP_STREAM_NET = PROP_STREAM__BEGIN + 2 # < [D]
|
||||
PROP_STREAM_NET_INSECURE = PROP_STREAM__BEGIN + 3 # < [D]
|
||||
PROP_STREAM__END = 0x80
|
||||
|
||||
# UART Bitrate
|
||||
# Format: `L`
|
||||
PROP_UART_BITRATE = 0x100
|
||||
|
||||
# UART Software Flow Control
|
||||
# Format: `b`
|
||||
PROP_UART_XON_XOFF = 0x101
|
||||
|
||||
PROP_PIB_15_4__BEGIN = 1024
|
||||
PROP_PIB_15_4_PHY_CHANNELS_SUPPORTED = PROP_PIB_15_4__BEGIN + 0x01 # < [A(L)]
|
||||
PROP_PIB_15_4_MAC_PROMISCUOUS_MODE = PROP_PIB_15_4__BEGIN + 0x51 # < [b]
|
||||
PROP_PIB_15_4_MAC_SECURITY_ENABLED = PROP_PIB_15_4__BEGIN + 0x5d # < [b]
|
||||
PROP_PIB_15_4__END = 1280
|
||||
|
||||
PROP_CNTR__BEGIN = 1280
|
||||
|
||||
# Counter reset behavior
|
||||
# Format: `C`
|
||||
PROP_CNTR_RESET = PROP_CNTR__BEGIN + 0
|
||||
|
||||
# The total number of transmissions.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_TX_PKT_TOTAL = PROP_CNTR__BEGIN + 1
|
||||
|
||||
# The number of transmissions with ack request.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_TX_PKT_ACK_REQ = PROP_CNTR__BEGIN + 2
|
||||
|
||||
# The number of transmissions that were acked.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_TX_PKT_ACKED = PROP_CNTR__BEGIN + 3
|
||||
|
||||
# The number of transmissions without ack request.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_TX_PKT_NO_ACK_REQ = PROP_CNTR__BEGIN + 4
|
||||
|
||||
# The number of transmitted data.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_TX_PKT_DATA = PROP_CNTR__BEGIN + 5
|
||||
|
||||
# The number of transmitted data poll.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_TX_PKT_DATA_POLL = PROP_CNTR__BEGIN + 6
|
||||
|
||||
# The number of transmitted beacon.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_TX_PKT_BEACON = PROP_CNTR__BEGIN + 7
|
||||
|
||||
# The number of transmitted beacon request.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_TX_PKT_BEACON_REQ = PROP_CNTR__BEGIN + 8
|
||||
|
||||
# The number of transmitted other types of frames.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_TX_PKT_OTHER = PROP_CNTR__BEGIN + 9
|
||||
|
||||
# The number of retransmission times.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_TX_PKT_RETRY = PROP_CNTR__BEGIN + 10
|
||||
|
||||
# The number of CCA failure times.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_TX_ERR_CCA = PROP_CNTR__BEGIN + 11
|
||||
|
||||
# The total number of received packets.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_RX_PKT_TOTAL = PROP_CNTR__BEGIN + 100
|
||||
|
||||
# The number of received data.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_RX_PKT_DATA = PROP_CNTR__BEGIN + 101
|
||||
|
||||
# The number of received data poll.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_RX_PKT_DATA_POLL = PROP_CNTR__BEGIN + 102
|
||||
|
||||
# The number of received beacon.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_RX_PKT_BEACON = PROP_CNTR__BEGIN + 103
|
||||
|
||||
# The number of received beacon request.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_RX_PKT_BEACON_REQ = PROP_CNTR__BEGIN + 104
|
||||
|
||||
# The number of received other types of frames.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_RX_PKT_OTHER = PROP_CNTR__BEGIN + 105
|
||||
|
||||
# The number of received packets filtered by whitelist.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_RX_PKT_FILT_WL = PROP_CNTR__BEGIN + 106
|
||||
|
||||
# The number of received packets filtered by destination check.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_RX_PKT_FILT_DA = PROP_CNTR__BEGIN + 107
|
||||
|
||||
# The number of received packets that are empty.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_RX_ERR_EMPTY = PROP_CNTR__BEGIN + 108
|
||||
|
||||
# The number of received packets from an unknown neighbor.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_RX_ERR_UKWN_NBR = PROP_CNTR__BEGIN + 109
|
||||
|
||||
# The number of received packets whose source address is invalid.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_RX_ERR_NVLD_SADDR = PROP_CNTR__BEGIN + 110
|
||||
|
||||
# The number of received packets with a security error.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_RX_ERR_SECURITY = PROP_CNTR__BEGIN + 111
|
||||
|
||||
# The number of received packets with a checksum error.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_RX_ERR_BAD_FCS = PROP_CNTR__BEGIN + 112
|
||||
|
||||
# The number of received packets with other errors.
|
||||
# Format: `L` (Read-only) */
|
||||
PROP_CNTR_RX_ERR_OTHER = PROP_CNTR__BEGIN + 113
|
||||
|
||||
# The message buffer counter info
|
||||
# Format: `SSSSSSSSSSSSSSSS` (Read-only)
|
||||
# `S`, (TotalBuffers) The number of buffers in the pool.
|
||||
# `S`, (FreeBuffers) The number of free message buffers.
|
||||
# `S`, (6loSendMessages) The number of messages in the 6lo send queue.
|
||||
# `S`, (6loSendBuffers) The number of buffers in the 6lo send queue.
|
||||
# `S`, (6loReassemblyMessages) The number of messages in the 6LoWPAN reassembly queue.
|
||||
# `S`, (6loReassemblyBuffers) The number of buffers in the 6LoWPAN reassembly queue.
|
||||
# `S`, (Ip6Messages) The number of messages in the IPv6 send queue.
|
||||
# `S`, (Ip6Buffers) The number of buffers in the IPv6 send queue.
|
||||
# `S`, (MplMessages) The number of messages in the MPL send queue.
|
||||
# `S`, (MplBuffers) The number of buffers in the MPL send queue.
|
||||
# `S`, (MleMessages) The number of messages in the MLE send queue.
|
||||
# `S`, (MleBuffers) The number of buffers in the MLE send queue.
|
||||
# `S`, (ArpMessages) The number of messages in the ARP send queue.
|
||||
# `S`, (ArpBuffers) The number of buffers in the ARP send queue.
|
||||
# `S`, (CoapClientMessages) The number of messages in the CoAP client send queue.
|
||||
# `S` (CoapClientBuffers) The number of buffers in the CoAP client send queue.
|
||||
PROP_MSG_BUFFER_COUNTERS = PROP_CNTR__BEGIN + 400
|
||||
|
||||
#=========================================
|
||||
|
||||
MAC_FILTER_MDOE_NORMAL = 0
|
||||
MAC_FILTER_MODE_PROMISCUOUS = 1
|
||||
MAC_FILTER_MODE_MONITOR = 2
|
||||
|
||||
#=========================================
|
||||
|
||||
RSSI_OVERRIDE = 127
|
||||
|
||||
#=========================================
|
||||
|
||||
|
||||
class kThread(object):
|
||||
""" OpenThread constant class. """
|
||||
PrefixPreferenceOffset = 6
|
||||
PrefixPreferredFlag = 1 << 5
|
||||
PrefixSlaacFlag = 1 << 4
|
||||
PrefixDhcpFlag = 1 << 3
|
||||
PrefixConfigureFlag = 1 << 2
|
||||
PrefixDefaultRouteFlag = 1 << 1
|
||||
PrefixOnMeshFlag = 1 << 0
|
||||
|
||||
#=========================================
|
||||
|
||||
SPINEL_LAST_STATUS_MAP = {
|
||||
0: "STATUS_OK: Operation has completed successfully.",
|
||||
1: "STATUS_FAILURE: Operation has failed for some undefined reason.",
|
||||
2: "STATUS_UNIMPLEMENTED: The given operation has not been implemented.",
|
||||
3: "STATUS_INVALID_ARGUMENT: An argument to the given operation is invalid.",
|
||||
4: "STATUS_INVALID_STATE : The given operation is invalid for the current state of the device.",
|
||||
5: "STATUS_INVALID_COMMAND: The given command is not recognized.",
|
||||
6: "STATUS_INVALID_INTERFACE: The given Spinel interface is not supported.",
|
||||
7: "STATUS_INTERNAL_ERROR: An internal runtime error has occured.",
|
||||
8: "STATUS_SECURITY_ERROR: A security or authentication error has occured.",
|
||||
9: "STATUS_PARSE_ERROR: An error has occured while parsing the command.",
|
||||
10: "STATUS_IN_PROGRESS: The operation is in progress and will be completed asynchronously.",
|
||||
11: "STATUS_NOMEM: The operation has been prevented due to memory pressure.",
|
||||
12: "STATUS_BUSY: The device is currently performing a mutually exclusive operation.",
|
||||
13: "STATUS_PROPERTY_NOT_FOUND: The given property is not recognized.",
|
||||
14: "STATUS_PACKET_DROPPED: The packet was dropped.",
|
||||
15: "STATUS_EMPTY: The result of the operation is empty.",
|
||||
16: "STATUS_CMD_TOO_BIG: The command was too large to fit in the internal buffer.",
|
||||
17: "STATUS_NO_ACK: The packet was not acknowledged.",
|
||||
18: "STATUS_CCA_FAILURE: The packet was not sent due to a CCA failure.",
|
||||
19: "SPINEL_STATUS_ALREADY: The operation is already in progress.",
|
||||
20: "SPINEL_STATUS_ITEM_NOT_FOUND: The given item could not be found.",
|
||||
|
||||
104: "SPINEL_STATUS_JOIN_FAILURE",
|
||||
105: "SPINEL_STATUS_JOIN_SECURITY: The network key has been set incorrectly.",
|
||||
106: "SPINEL_STATUS_JOIN_NO_PEERS: The node was unable to find any other peers on the network.",
|
||||
107: "SPINEL_STATUS_JOIN_INCOMPATIBLE: The only potential peer nodes found are incompatible.",
|
||||
|
||||
112: "STATUS_RESET_POWER_ON",
|
||||
113: "STATUS_RESET_EXTERNAL",
|
||||
114: "STATUS_RESET_SOFTWARE",
|
||||
115: "STATUS_RESET_FAULT",
|
||||
116: "STATUS_RESET_CRASH",
|
||||
117: "STATUS_RESET_ASSERT",
|
||||
118: "STATUS_RESET_OTHER",
|
||||
119: "STATUS_RESET_UNKNOWN",
|
||||
120: "STATUS_RESET_WATCHDOG",
|
||||
|
||||
0x4000: "kThreadError_None",
|
||||
0x4001: "kThreadError_Failed",
|
||||
0x4002: "kThreadError_Drop",
|
||||
0x4003: "kThreadError_NoBufs",
|
||||
0x4004: "kThreadError_NoRoute",
|
||||
0x4005: "kThreadError_Busy",
|
||||
0x4006: "kThreadError_Parse",
|
||||
0x4007: "kThreadError_InvalidArgs",
|
||||
0x4008: "kThreadError_Security",
|
||||
0x4009: "kThreadError_AddressQuery",
|
||||
0x400A: "kThreadError_NoAddress",
|
||||
0x400B: "kThreadError_NotReceiving",
|
||||
0x400C: "kThreadError_Abort",
|
||||
0x400D: "kThreadError_NotImplemented",
|
||||
0x400E: "kThreadError_InvalidState",
|
||||
0x400F: "kThreadError_NoTasklets",
|
||||
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2016, The OpenThread Authors.
|
||||
# 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.
|
||||
#
|
||||
""" High-Level Data Link Control (HDLC) module. """
|
||||
|
||||
import logging
|
||||
|
||||
from struct import pack
|
||||
|
||||
import spinel.config as CONFIG
|
||||
from spinel.stream import IStream
|
||||
from spinel.util import hexify_int
|
||||
from spinel.util import hexify_bytes
|
||||
|
||||
HDLC_FLAG = 0x7e
|
||||
HDLC_ESCAPE = 0x7d
|
||||
|
||||
# RFC 1662 Appendix C
|
||||
|
||||
HDLC_FCS_INIT = 0xFFFF
|
||||
HDLC_FCS_POLY = 0x8408
|
||||
HDLC_FCS_GOOD = 0xF0B8
|
||||
|
||||
|
||||
class Hdlc(IStream):
|
||||
""" Utility class for HDLC encoding and decoding. """
|
||||
|
||||
def __init__(self, stream):
|
||||
self.stream = stream
|
||||
self.fcstab = self.mkfcstab()
|
||||
|
||||
@classmethod
|
||||
def mkfcstab(cls):
|
||||
""" Make a static lookup table for byte value to FCS16 result. """
|
||||
polynomial = HDLC_FCS_POLY
|
||||
|
||||
def valiter():
|
||||
""" Helper to yield FCS16 table entries for each byte value. """
|
||||
for byte in range(256):
|
||||
fcs = byte
|
||||
i = 8
|
||||
while i:
|
||||
fcs = (fcs >> 1) ^ polynomial if fcs & 1 else fcs >> 1
|
||||
i -= 1
|
||||
|
||||
yield fcs & 0xFFFF
|
||||
|
||||
return tuple(valiter())
|
||||
|
||||
def fcs16(self, byte, fcs):
|
||||
"""
|
||||
Return the next iteration of an fcs16 calculation
|
||||
given the next data byte and current fcs accumulator.
|
||||
"""
|
||||
fcs = (fcs >> 8) ^ self.fcstab[(fcs ^ byte) & 0xff]
|
||||
return fcs
|
||||
|
||||
def collect(self):
|
||||
""" Return the next valid packet to pass HDLC decoding on the stream. """
|
||||
fcs = HDLC_FCS_INIT
|
||||
packet = []
|
||||
raw = []
|
||||
|
||||
# Synchronize
|
||||
while 1:
|
||||
byte = self.stream.read()
|
||||
if CONFIG.DEBUG_HDLC:
|
||||
raw.append(byte)
|
||||
if byte == HDLC_FLAG:
|
||||
break
|
||||
|
||||
# Read packet, updating fcs, and escaping bytes as needed
|
||||
while 1:
|
||||
byte = self.stream.read()
|
||||
if CONFIG.DEBUG_HDLC:
|
||||
raw.append(byte)
|
||||
if byte == HDLC_FLAG:
|
||||
if len(packet) != 0:
|
||||
break
|
||||
else:
|
||||
# If multiple FLAG bytes in a row, keep looking for data.
|
||||
continue
|
||||
if byte == HDLC_ESCAPE:
|
||||
byte = self.stream.read()
|
||||
if CONFIG.DEBUG_HDLC:
|
||||
raw.append(byte)
|
||||
byte ^= 0x20
|
||||
packet.append(byte)
|
||||
fcs = self.fcs16(byte, fcs)
|
||||
|
||||
if CONFIG.DEBUG_HDLC:
|
||||
logging.debug("RX Hdlc: " + str(map(hexify_int, raw)))
|
||||
|
||||
if fcs != HDLC_FCS_GOOD:
|
||||
packet = None
|
||||
else:
|
||||
packet = packet[:-2] # remove FCS16 from end
|
||||
|
||||
return packet
|
||||
|
||||
@classmethod
|
||||
def encode_byte(cls, byte, packet=[]):
|
||||
""" HDLC encode and append a single byte to the given packet. """
|
||||
if (byte == HDLC_ESCAPE) or (byte == HDLC_FLAG):
|
||||
packet.append(HDLC_ESCAPE)
|
||||
packet.append(byte ^ 0x20)
|
||||
else:
|
||||
packet.append(byte)
|
||||
return packet
|
||||
|
||||
def encode(self, payload=""):
|
||||
""" Return the HDLC encoding of the given packet. """
|
||||
fcs = HDLC_FCS_INIT
|
||||
packet = []
|
||||
packet.append(HDLC_FLAG)
|
||||
for byte in payload:
|
||||
byte = ord(byte)
|
||||
fcs = self.fcs16(byte, fcs)
|
||||
packet = self.encode_byte(byte, packet)
|
||||
|
||||
fcs ^= 0xffff
|
||||
byte = fcs & 0xFF
|
||||
packet = self.encode_byte(byte, packet)
|
||||
byte = fcs >> 8
|
||||
packet = self.encode_byte(byte, packet)
|
||||
packet.append(HDLC_FLAG)
|
||||
packet = pack("%dB" % len(packet), *packet)
|
||||
|
||||
if CONFIG.DEBUG_HDLC:
|
||||
logging.debug("TX Hdlc: " + hexify_bytes(packet))
|
||||
return packet
|
||||
|
||||
def write(self, data):
|
||||
""" HDLC encode and write the given data to this stream. """
|
||||
pkt = self.encode(data)
|
||||
self.stream.write(pkt)
|
||||
|
||||
def read(self, _size=None):
|
||||
""" Read and HDLC decode the next packet from this stream. """
|
||||
pkt = self.collect()
|
||||
return pkt
|
||||
@@ -1,63 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2016, The OpenThread Authors.
|
||||
# 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.
|
||||
#
|
||||
""" Module to provide codec utilities for .pcap formatters. """
|
||||
|
||||
import struct
|
||||
from datetime import datetime
|
||||
|
||||
DLT_IEEE802_15_4 = 195
|
||||
PCAP_MAGIC_NUMBER = 0xa1b2c3d4
|
||||
PCAP_VERSION_MAJOR = 2
|
||||
PCAP_VERSION_MINOR = 4
|
||||
|
||||
|
||||
class PcapCodec(object):
|
||||
""" Utility class for .pcap formatters. """
|
||||
|
||||
@classmethod
|
||||
def encode_header(cls):
|
||||
""" Returns a pcap file header. """
|
||||
return struct.pack("<LHHLLLL",
|
||||
PCAP_MAGIC_NUMBER,
|
||||
PCAP_VERSION_MAJOR,
|
||||
PCAP_VERSION_MINOR,
|
||||
0, 0, 256,
|
||||
DLT_IEEE802_15_4)
|
||||
|
||||
@classmethod
|
||||
def encode_frame(cls, frame):
|
||||
""" Returns a pcap encapsulation of the given frame. """
|
||||
# write frame pcap header
|
||||
epoch = datetime(1970, 1, 1)
|
||||
d_time = datetime.utcnow() - epoch
|
||||
sec = d_time.days * 24 * 60 * 60 + d_time.seconds
|
||||
usec = d_time.microseconds
|
||||
length = len(frame)
|
||||
pcap_frame = struct.pack("<LLLL", sec, usec, length, length)
|
||||
pcap_frame += frame
|
||||
return pcap_frame
|
||||
@@ -1,174 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (c) 2016, The OpenThread Authors.
|
||||
# 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.
|
||||
#
|
||||
"""
|
||||
Module providing a generic stream interface.
|
||||
Also includes adapter implementations for serial, socket, and pipes.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
import logging
|
||||
import traceback
|
||||
|
||||
import subprocess
|
||||
import socket
|
||||
import serial
|
||||
|
||||
import spinel.util
|
||||
import spinel.config as CONFIG
|
||||
|
||||
|
||||
class IStream(object):
|
||||
""" Abstract base class for a generic Stream Interface. """
|
||||
|
||||
def read(self, size):
|
||||
""" Read an array of byte integers of the given size from the stream. """
|
||||
pass
|
||||
|
||||
def write(self, data):
|
||||
""" Write the given packed data to the stream. """
|
||||
pass
|
||||
|
||||
def close(self):
|
||||
""" Close the stream cleanly as needed. """
|
||||
pass
|
||||
|
||||
|
||||
class StreamSerial(IStream):
|
||||
""" An IStream interface implementation for serial devices. """
|
||||
|
||||
def __init__(self, dev, baudrate=115200):
|
||||
try:
|
||||
self.serial = serial.Serial(dev, baudrate)
|
||||
except:
|
||||
logging.error("Couldn't open " + dev)
|
||||
traceback.print_exc()
|
||||
|
||||
def write(self, data):
|
||||
self.serial.write(data)
|
||||
if CONFIG.DEBUG_STREAM_TX:
|
||||
logging.debug("TX Raw: " + str(map(spinel.util.hexify_chr, data)))
|
||||
|
||||
def read(self, size=1):
|
||||
pkt = self.serial.read(size)
|
||||
if CONFIG.DEBUG_STREAM_RX:
|
||||
logging.debug("RX Raw: " + str(map(spinel.util.hexify_chr, pkt)))
|
||||
return map(ord, pkt)[0]
|
||||
|
||||
|
||||
class StreamSocket(IStream):
|
||||
""" An IStream interface implementation over an internet socket. """
|
||||
|
||||
def __init__(self, hostname, port):
|
||||
# Open socket
|
||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.sock.connect((hostname, port))
|
||||
|
||||
def write(self, data):
|
||||
self.sock.send(data)
|
||||
if CONFIG.DEBUG_STREAM_TX:
|
||||
logging.debug("TX Raw: " + str(map(spinel.util.hexify_chr, data)))
|
||||
|
||||
def read(self, size=1):
|
||||
pkt = self.sock.recv(size)
|
||||
if CONFIG.DEBUG_STREAM_RX:
|
||||
logging.debug("RX Raw: " + str(map(spinel.util.hexify_chr, pkt)))
|
||||
return map(ord, pkt)[0]
|
||||
|
||||
|
||||
class StreamPipe(IStream):
|
||||
""" An IStream interface implementation to stdin/out of a piped process. """
|
||||
|
||||
def __init__(self, filename):
|
||||
""" Create a stream object from a piped system call """
|
||||
try:
|
||||
self.pipe = subprocess.Popen(filename, shell=True,
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=sys.stdout.fileno())
|
||||
except:
|
||||
logging.error("Couldn't open " + filename)
|
||||
traceback.print_exc()
|
||||
|
||||
def write(self, data):
|
||||
if CONFIG.DEBUG_STREAM_TX:
|
||||
logging.debug("TX Raw: (%d) %s",
|
||||
len(data), spinel.util.hexify_bytes(data))
|
||||
self.pipe.stdin.write(data)
|
||||
|
||||
def read(self, size=1):
|
||||
""" Blocking read on stream object """
|
||||
pkt = self.pipe.stdout.read(size)
|
||||
if CONFIG.DEBUG_STREAM_RX:
|
||||
logging.debug("RX Raw: " + str(map(spinel.util.hexify_chr, pkt)))
|
||||
return map(ord, pkt)[0]
|
||||
|
||||
def close(self):
|
||||
if self.pipe:
|
||||
self.pipe.kill()
|
||||
self.pipe = None
|
||||
|
||||
|
||||
def StreamOpen(stream_type, descriptor, verbose=True):
|
||||
"""
|
||||
Factory function that creates and opens a stream connection.
|
||||
|
||||
stream_type:
|
||||
'u' = uart (/dev/tty#)
|
||||
's' = socket (port #)
|
||||
'p' = pipe (stdin/stdout)
|
||||
|
||||
descriptor:
|
||||
uart - filename of device (/dev/tty#)
|
||||
socket - port to open connection to on localhost
|
||||
pipe - filename of command to execute and bind via stdin/stdout
|
||||
"""
|
||||
|
||||
if stream_type == 'p':
|
||||
if verbose:
|
||||
print("Opening pipe to " + str(descriptor))
|
||||
return StreamPipe(descriptor)
|
||||
|
||||
elif stream_type == 's':
|
||||
port = int(descriptor)
|
||||
hostname = "localhost"
|
||||
if verbose:
|
||||
print("Opening socket to " + hostname + ":" + str(port))
|
||||
return StreamSocket(hostname, port)
|
||||
|
||||
elif stream_type == 'u':
|
||||
dev = str(descriptor)
|
||||
baudrate = 115200
|
||||
if verbose:
|
||||
print("Opening serial to " + dev + " @ " + str(baudrate))
|
||||
return StreamSerial(dev, baudrate)
|
||||
|
||||
else:
|
||||
return None
|
||||
@@ -1,96 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2016, The OpenThread Authors.
|
||||
# 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.
|
||||
#
|
||||
""" Unittest for spinel.codec module. """
|
||||
|
||||
import time
|
||||
import unittest
|
||||
|
||||
from spinel.const import SPINEL
|
||||
from spinel.codec import WpanApi
|
||||
from spinel.test_stream import MockStream
|
||||
|
||||
|
||||
class TestCodec(unittest.TestCase):
|
||||
""" Unit TestCase class for spinel.codec.SpinelCodec class. """
|
||||
|
||||
# Tests parsing and format demuxing of various properties with canned
|
||||
# values.
|
||||
VECTOR = {
|
||||
SPINEL.PROP_MAC_15_4_PANID: 65535,
|
||||
SPINEL.PROP_NCP_VERSION: "OPENTHREAD",
|
||||
SPINEL.PROP_NET_ROLE: 0,
|
||||
SPINEL.PROP_NET_KEY_SEQUENCE_COUNTER: 5,
|
||||
SPINEL.PROP_NET_NETWORK_NAME: "OpenThread",
|
||||
SPINEL.PROP_THREAD_MODE: 0xF,
|
||||
}
|
||||
|
||||
def test_prop_get(self):
|
||||
""" Unit test of SpinelCodec.prop_get_value. """
|
||||
|
||||
mock_stream = MockStream({
|
||||
# Request: Response
|
||||
"810236": "810636ffff", # get panid = 65535
|
||||
"810243": "81064300", # get state = detached
|
||||
"81025e": "81065e0f", # mode = 0xF
|
||||
"810202": "8106024f50454e54485245414400", # get version
|
||||
"810247": "81064705000000", # get keysequence
|
||||
"810244": "8106444f70656e54687265616400", # get networkname
|
||||
})
|
||||
nodeid = 1
|
||||
use_hdlc = False
|
||||
wpan_api = WpanApi(mock_stream, nodeid, use_hdlc)
|
||||
|
||||
for prop_id, truth_value in self.VECTOR.iteritems():
|
||||
value = wpan_api.prop_get_value(prop_id)
|
||||
# print "value "+util.hexify_str(value)
|
||||
# print "truth "+util.hexify_str(truth_value)
|
||||
self.failUnless(value == truth_value)
|
||||
|
||||
def cb_test_callback(self, prop, value, tid):
|
||||
self.test_callback_pass = True
|
||||
|
||||
def test_callback(self):
|
||||
""" Unit test of WpanApi.callback_register. """
|
||||
|
||||
vector = [
|
||||
"800672340060000000000c3a40fe80000000000000020d6f00055715d3fddead00beef0000cd9bb7814c5619ea8100b0ca00000000267fc789" # PROP_STREAM_NET
|
||||
]
|
||||
|
||||
mock_stream = MockStream({})
|
||||
nodeid = 1
|
||||
use_hdlc = False
|
||||
wpan_api = WpanApi(mock_stream, nodeid, use_hdlc)
|
||||
|
||||
self.test_callback_pass = False
|
||||
wpan_api.callback_register(SPINEL.PROP_STREAM_NET, self.cb_test_callback)
|
||||
|
||||
for pkt in vector:
|
||||
mock_stream.write_child_hex(pkt)
|
||||
time.sleep(0.1)
|
||||
|
||||
self.failUnless(self.test_callback_pass)
|
||||
@@ -1,58 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2016, The OpenThread Authors.
|
||||
# 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.
|
||||
#
|
||||
"""
|
||||
Unittest for spinel.hdlc module.
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import binascii
|
||||
|
||||
from spinel.hdlc import Hdlc
|
||||
|
||||
class TestHdlc(unittest.TestCase):
|
||||
""" Unittest class for spinel.hdlc.Hdlc class. """
|
||||
|
||||
VECTOR = {
|
||||
# Data HDLC Encoded
|
||||
"810243": "7e810243d3d37e",
|
||||
"8103367e7d": "7e8103367d5e7d5d6af97e",
|
||||
}
|
||||
|
||||
def test_hdlc_encode(self):
|
||||
""" Unit test for Hdle.encode method. """
|
||||
hdlc = Hdlc(None)
|
||||
for in_hex, out_hex in self.VECTOR.iteritems():
|
||||
in_binary = binascii.unhexlify(in_hex)
|
||||
out_binary = hdlc.encode(in_binary)
|
||||
#print "inHex = "+binascii.hexlify(in_binary)
|
||||
#print "outHex = "+binascii.hexlify(out_binary)
|
||||
self.failUnless(out_hex == binascii.hexlify(out_binary))
|
||||
|
||||
def test_hdlc_decode(self):
|
||||
""" Unit test for Hdle.decode method. """
|
||||
pass
|
||||
@@ -1,66 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2016, The OpenThread Authors.
|
||||
# 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.
|
||||
#
|
||||
""" Unittest for spinel.codec module. """
|
||||
|
||||
import unittest
|
||||
|
||||
import spinel.util as util
|
||||
from spinel.const import SPINEL
|
||||
from spinel.codec import WpanApi
|
||||
from spinel.test_stream import MockStream
|
||||
|
||||
|
||||
class TestSniffer(unittest.TestCase):
|
||||
""" Unit TestCase class for sniffer relevant portions of spinel.codec.SpinelCodec. """
|
||||
|
||||
HEADER = "800671" # CMD_PROP_IS RAW_STREAM
|
||||
VECTOR = [
|
||||
# Some raw 6lo packets: ICMPv6EchoRequest to ff02::1, fe80::1, and MLE Advertisement
|
||||
"2d00499880fffffffffeff0d0100000001a7acdf3be9272c2d88765ff76f0bf08a7c3df0a78e9c1b23eb019c58740300800000",
|
||||
"3200699c81ffff0100000000000002feff0d030000000198e80cac00f8e0754e7542f5cb1171069f5c9689ef8d1d45a75e26b3f600800000",
|
||||
"450041d8980100ffffa8cb25ab2c32a0227f3b01f04d4c4d4cdc3b0015060000000000000001f226cce17968521d92904fec1adb0b94777030b944df65450bc955f05737e3901700800000"
|
||||
]
|
||||
|
||||
def test_prop_get(self):
|
||||
""" Unit test of SpinelCodec.prop_get_value. """
|
||||
|
||||
mock_stream = MockStream({})
|
||||
|
||||
nodeid = 1
|
||||
use_hdlc = False
|
||||
tid = SPINEL.HEADER_ASYNC
|
||||
prop_id = SPINEL.PROP_STREAM_RAW
|
||||
|
||||
wpan_api = WpanApi(mock_stream, nodeid, use_hdlc)
|
||||
wpan_api.queue_register(tid)
|
||||
|
||||
for truth in self.VECTOR:
|
||||
mock_stream.write_child_hex(self.HEADER+truth)
|
||||
result = wpan_api.queue_wait_for_prop(prop_id, tid)
|
||||
packet = util.hexify_str(result.value,"")
|
||||
self.failUnless(packet == truth)
|
||||
@@ -1,85 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (c) 2016, The OpenThread Authors.
|
||||
# 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.
|
||||
#
|
||||
"""
|
||||
Tests for spinel.stream and implementation of MockStream class.
|
||||
"""
|
||||
|
||||
import binascii
|
||||
import logging
|
||||
|
||||
import Queue
|
||||
|
||||
import spinel.util as util
|
||||
import spinel.config as CONFIG
|
||||
from spinel.stream import IStream
|
||||
|
||||
|
||||
class MockStream(IStream):
|
||||
""" A pluggable IStream class for mock testing input/output data flows. """
|
||||
|
||||
def __init__(self, vector):
|
||||
"""
|
||||
Pass a test vector as dictionary of hexstream outputs keyed on inputs.
|
||||
"""
|
||||
self.vector = vector
|
||||
self.rx_queue = Queue.Queue()
|
||||
self.response = None
|
||||
|
||||
def write(self, out_binary):
|
||||
""" Write to the MockStream, triggering a lookup for mock response. """
|
||||
if CONFIG.DEBUG_STREAM_TX:
|
||||
logging.debug("TX Raw: (%d) %s", len(out_binary),
|
||||
util.hexify_bytes(out_binary))
|
||||
out_hex = binascii.hexlify(out_binary)
|
||||
in_hex = self.vector[out_hex]
|
||||
self.rx_queue.put_nowait(binascii.unhexlify(in_hex))
|
||||
|
||||
def read(self, size=None):
|
||||
""" Blocking read from the MockStream. """
|
||||
if not self.response or len(self.response) == 0:
|
||||
self.response = self.rx_queue.get(True)
|
||||
|
||||
if size:
|
||||
in_binary = self.response[:size]
|
||||
self.response = self.response[size:]
|
||||
else:
|
||||
in_binary = self.response
|
||||
self.response = None
|
||||
|
||||
if CONFIG.DEBUG_STREAM_RX:
|
||||
logging.debug("RX Raw: " + util.hexify_bytes(in_binary))
|
||||
return in_binary
|
||||
|
||||
def write_child(self, out_binary):
|
||||
""" Mock asynchronous write from child process. """
|
||||
self.rx_queue.put_nowait(out_binary)
|
||||
|
||||
def write_child_hex(self, out_hex):
|
||||
""" Mock asynchronous write from child process. """
|
||||
self.write_child(binascii.unhexlify(out_hex))
|
||||
@@ -1,32 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (c) 2016, The OpenThread Authors.
|
||||
# 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.
|
||||
#
|
||||
|
||||
from spinel.test_hdlc import TestHdlc
|
||||
from spinel.test_codec import TestCodec
|
||||
from spinel.test_sniffer import TestSniffer
|
||||
@@ -1,159 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2016, The OpenThread Authors.
|
||||
# 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.
|
||||
#
|
||||
""" Utility class for creating TUN network interfaces on Linux and OSX. """
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import sys
|
||||
import struct
|
||||
import logging
|
||||
import threading
|
||||
import traceback
|
||||
import subprocess
|
||||
|
||||
if sys.platform == "linux" or sys.platform == "linux2":
|
||||
import fcntl
|
||||
|
||||
from select import select
|
||||
|
||||
import spinel.util as util
|
||||
import spinel.config as CONFIG
|
||||
|
||||
IFF_TUN = 0x0001
|
||||
IFF_TAP = 0x0002
|
||||
IFF_NO_PI = 0x1000
|
||||
IFF_TUNSETIFF = 0x400454ca
|
||||
IFF_TUNSETOWNER = IFF_TUNSETIFF + 2
|
||||
|
||||
class TunInterface(object):
|
||||
""" Utility class for creating a TUN network interface. """
|
||||
|
||||
def __init__(self, identifier):
|
||||
self.identifier = identifier
|
||||
self.ifname = "tun" + str(self.identifier)
|
||||
self.tun = None
|
||||
self.fd = None
|
||||
|
||||
platform = sys.platform
|
||||
if platform == "linux" or platform == "linux2":
|
||||
self.__init_linux()
|
||||
elif platform == "darwin":
|
||||
self.__init_osx()
|
||||
else:
|
||||
raise RuntimeError("Platform \"{}\" is not supported.".format(platform))
|
||||
|
||||
self.ifconfig("up")
|
||||
#self.ifconfig("inet6 add fd00::1/64")
|
||||
self.__start_tun_thread()
|
||||
|
||||
def __init_osx(self):
|
||||
logging.info("TUN: Starting osx " + self.ifname)
|
||||
filename = "/dev/" + self.ifname
|
||||
self.tun = os.open(filename, os.O_RDWR)
|
||||
self.fd = self.tun
|
||||
# trick osx to auto-assign a link local address
|
||||
self.addr_add("fe80::1")
|
||||
self.addr_del("fe80::1")
|
||||
|
||||
def __init_linux(self):
|
||||
logging.info("TUN: Starting linux " + self.ifname)
|
||||
self.tun = open("/dev/net/tun", "r+b")
|
||||
self.fd = self.tun.fileno()
|
||||
|
||||
ifr = struct.pack("16sH", self.ifname, IFF_TUN | IFF_NO_PI)
|
||||
fcntl.ioctl(self.tun, IFF_TUNSETIFF, ifr) # Name interface tun#
|
||||
fcntl.ioctl(self.tun, IFF_TUNSETOWNER, 1000) # Allow non-sudo access
|
||||
|
||||
def close(self):
|
||||
""" Close this tunnel interface. """
|
||||
if self.tun:
|
||||
os.close(self.fd)
|
||||
self.fd = None
|
||||
self.tun = None
|
||||
|
||||
@classmethod
|
||||
def command(cls, cmd):
|
||||
""" Utility to make a system call. """
|
||||
subprocess.check_call(cmd, shell=True)
|
||||
|
||||
def ifconfig(self, args):
|
||||
""" Bring interface up and/or assign addresses. """
|
||||
self.command('ifconfig ' + self.ifname + ' ' + args)
|
||||
|
||||
def ping6(self, args):
|
||||
""" Ping an address. """
|
||||
cmd = 'ping6 ' + args
|
||||
print(cmd)
|
||||
self.command(cmd)
|
||||
|
||||
def addr_add(self, addr):
|
||||
""" Add the given IPv6 address to the tunnel interface. """
|
||||
self.ifconfig('inet6 add ' + addr)
|
||||
|
||||
def addr_del(self, addr):
|
||||
""" Delete the given IPv6 address from the tunnel interface. """
|
||||
platform = sys.platform
|
||||
if platform == "linux" or platform == "linux2":
|
||||
self.ifconfig('inet6 del ' + addr)
|
||||
elif platform == "darwin":
|
||||
self.ifconfig('inet6 delete ' + addr)
|
||||
|
||||
def write(self, packet):
|
||||
#global gWpanApi
|
||||
#gWpanApi.ip_send(packet)
|
||||
# os.write(self.fd, packet) # Loop back
|
||||
if CONFIG.DEBUG_TUN:
|
||||
logging.debug("\nTUN: TX (" + str(len(packet)) +
|
||||
") " + util.hexify_str(packet))
|
||||
|
||||
def __run_tun_thread(self):
|
||||
while self.fd:
|
||||
try:
|
||||
ready_fd = select([self.fd], [], [])[0][0]
|
||||
if ready_fd == self.fd:
|
||||
packet = os.read(self.fd, 4000)
|
||||
if CONFIG.DEBUG_TUN:
|
||||
logging.debug("\nTUN: RX (" + str(len(packet)) + ") " +
|
||||
util.hexify_str(packet))
|
||||
self.write(packet)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
break
|
||||
|
||||
logging.info("TUN: exiting")
|
||||
if self.fd:
|
||||
os.close(self.fd)
|
||||
self.fd = None
|
||||
|
||||
def __start_tun_thread(self):
|
||||
"""Start reader thread"""
|
||||
self._reader_alive = True
|
||||
self.receiver_thread = threading.Thread(target=self.__run_tun_thread)
|
||||
self.receiver_thread.setDaemon(True)
|
||||
self.receiver_thread.start()
|
||||
@@ -1,48 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (c) 2016, The OpenThread Authors.
|
||||
# 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.
|
||||
#
|
||||
|
||||
def hexify_chr(s): return "%02X" % ord(s)
|
||||
def hexify_int(i): return "%02X" % i
|
||||
def hexify_bytes(data): return str(map(hexify_chr,data))
|
||||
def hexify_str(s,delim=':'):
|
||||
return delim.join(x.encode('hex') for x in s)
|
||||
|
||||
def pack_bytes(packet): return pack("%dB" % len(packet), *packet)
|
||||
def packed_to_array(packet): return map(ord, packet)
|
||||
|
||||
def asciify_int(i): return "%c" % (i)
|
||||
|
||||
def hex_to_bytes(s):
|
||||
result = ''
|
||||
for i in xrange(0, len(s), 2):
|
||||
(b1, b2) = s[i:i+2]
|
||||
hex = b1+b2
|
||||
v = int(hex, 16)
|
||||
result += chr(v)
|
||||
return result
|
||||
@@ -1,55 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (c) 2016, The OpenThread Authors.
|
||||
# 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.
|
||||
#
|
||||
""" Run all unittests for spinel module. """
|
||||
|
||||
import sys
|
||||
import optparse
|
||||
import unittest
|
||||
|
||||
import spinel.config as CONFIG
|
||||
from spinel.tests import *
|
||||
|
||||
def main():
|
||||
""" Run all unit tests for spinel module. """
|
||||
args = sys.argv[1:]
|
||||
|
||||
opt_parser = optparse.OptionParser()
|
||||
opt_parser.add_option("-d", "--debug", action="store",
|
||||
dest="debug", type="int", default=CONFIG.DEBUG_ENABLE)
|
||||
|
||||
(options, remaining_args) = opt_parser.parse_args(args)
|
||||
|
||||
if options.debug:
|
||||
CONFIG.debug_set_level(options.debug)
|
||||
|
||||
sys.argv[1:] = remaining_args
|
||||
unittest.main()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user