Add new spinel property THREAD_PREFERRED_ROUTER_ID and its set handler (#718)

This commit adds a new spinel property `THREAD_PREFERRED_ROUTER_ID`
(write-only) along with its set property handler function.
This commit is contained in:
Abtin Keshavarzian
2016-09-28 19:21:32 -07:00
committed by Jonathan Hui
parent d0763e7283
commit b962983f01
4 changed files with 63 additions and 5 deletions
+12 -2
View File
@@ -181,5 +181,15 @@ a re-attach process as an end-device.
* Type: Read-Write
* Packed-Encoding: `C`
Specifies the self imposed random delay in seconds a REED waits before
registering to become an Active Router.
Specifies the self imposed random delay in seconds a REED waits before
registering to become an Active Router.
### PROP 5386: PROP_THREAD_PREFERRED_ROUTER_ID
* Type: Write
* Packed-Encoding: `C`
Specifies the preferred Router Id. Upon becoming a router/leader the node
attempts to use this Router Id. If the preferred Router Id is not set or
if it can not be used, a randomly generated router id is picked. This
property can be set only when the device role is either detached or
disabled.
+42
View File
@@ -233,6 +233,7 @@ const NcpBase::SetPropertyHandlerEntry NcpBase::mSetPropertyHandlerTable[] =
{ SPINEL_PROP_THREAD_CONTEXT_REUSE_DELAY, &NcpBase::SetPropertyHandler_THREAD_CONTEXT_REUSE_DELAY },
{ SPINEL_PROP_NET_REQUIRE_JOIN_EXISTING, &NcpBase::SetPropertyHandler_NET_REQUIRE_JOIN_EXISTING },
{ SPINEL_PROP_THREAD_ROUTER_SELECTION_JITTER, &NcpBase::SetPropertyHandler_THREAD_ROUTER_SELECTION_JITTER },
{ SPINEL_PROP_THREAD_PREFERRED_ROUTER_ID, &NcpBase::SetPropertyHandler_THREAD_PREFERRED_ROUTER_ID },
#if OPENTHREAD_ENABLE_DIAG
{ SPINEL_PROP_NEST_STREAM_MFG, &NcpBase::SetPropertyHandler_NEST_STREAM_MFG },
@@ -3992,6 +3993,47 @@ ThreadError NcpBase::SetPropertyHandler_THREAD_ROUTER_SELECTION_JITTER(uint8_t h
return errorCode;
}
ThreadError NcpBase::SetPropertyHandler_THREAD_PREFERRED_ROUTER_ID(uint8_t header, spinel_prop_key_t key,
const uint8_t *value_ptr, uint16_t value_len)
{
uint8_t router_id = 0;
spinel_ssize_t parsedLength;
ThreadError errorCode = kThreadError_None;
parsedLength = spinel_datatype_unpack(
value_ptr,
value_len,
SPINEL_DATATYPE_UINT8_S,
&router_id
);
if (parsedLength > 0)
{
errorCode = otSetPreferredRouterId(mInstance, router_id);
if (errorCode == kThreadError_None)
{
errorCode = SendPropertyUpdate(
header,
SPINEL_CMD_PROP_VALUE_IS,
key,
SPINEL_DATATYPE_UINT8_S,
router_id
);
}
else
{
errorCode = SendLastStatus(header, ThreadErrorToSpinelStatus(errorCode));
}
}
else
{
errorCode = SendLastStatus(header, SPINEL_STATUS_PARSE_ERROR);
}
return errorCode;
}
ThreadError NcpBase::SetPropertyHandler_THREAD_CONTEXT_REUSE_DELAY(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len)
{
uint32_t i = 0;
+3 -3
View File
@@ -50,7 +50,7 @@ namespace Thread {
class NcpBase
{
public:
/**
* This constructor creates and initializes an NcpBase instance.
*
@@ -60,7 +60,7 @@ public:
NcpBase(otInstance *aInstance);
protected:
// The pointer to the OpenThread instance
otInstance* mInstance;
@@ -397,7 +397,7 @@ private:
ThreadError SetPropertyHandler_THREAD_ROUTER_SELECTION_JITTER(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len);
ThreadError SetPropertyHandler_THREAD_CONTEXT_REUSE_DELAY(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len);
ThreadError SetPropertyHandler_THREAD_NETWORK_ID_TIMEOUT(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len);
ThreadError SetPropertyHandler_THREAD_PREFERRED_ROUTER_ID(uint8_t header, spinel_prop_key_t key, const uint8_t *value_ptr, uint16_t value_len);
ThreadError SetPropertyHandler_THREAD_ASSISTING_PORTS(uint8_t header, spinel_prop_key_t key,
const uint8_t *value_ptr, uint16_t value_len);
+6
View File
@@ -529,6 +529,12 @@ typedef enum
SPINEL_PROP_THREAD_ROUTER_SELECTION_JITTER
= SPINEL_PROP_THREAD_EXT__BEGIN + 9,
/// Thread Preferred Router Id
/** Format: `C` - Write only
*/
SPINEL_PROP_THREAD_PREFERRED_ROUTER_ID
= SPINEL_PROP_THREAD_EXT__BEGIN + 10,
SPINEL_PROP_THREAD_EXT__END = 0x1600,
SPINEL_PROP_IPV6__BEGIN = 0x60,