add limitation on some commissioner relative operations (#1670)

* add limitation on some commissioner relative operations

* update cert scripts to start commissioner rightly
This commit is contained in:
rongli
2017-04-28 22:03:20 -07:00
committed by Jonathan Hui
parent a6e11b1896
commit 41a38ce026
15 changed files with 78 additions and 34 deletions
+45 -29
View File
@@ -64,7 +64,7 @@ OTAPI ThreadError OTCALL otCommissionerStart(otInstance *aInstance);
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @retval kThreadError_None Successfully started the Commissioner role.
* @retval kThreadError_None Successfully stopped the Commissioner role.
*
*/
OTAPI ThreadError OTCALL otCommissionerStop(otInstance *aInstance);
@@ -80,6 +80,9 @@ OTAPI ThreadError OTCALL otCommissionerStop(otInstance *aInstance);
* @retval kThreadError_None Successfully added the Joiner.
* @retval kThreadError_NoBufs No buffers available to add the Joiner.
* @retval kThreadError_InvalidArgs @p aExtAddress or @p aPSKd is invalid.
* @retval kThreadError_InvalidState The commissioner is not active.
*
* @note Only use this after successfully started the Commissioner role by otCommissionerStart().
*
*/
OTAPI ThreadError OTCALL otCommissionerAddJoiner(otInstance *aInstance, const otExtAddress *aExtAddress,
@@ -91,9 +94,12 @@ OTAPI ThreadError OTCALL otCommissionerAddJoiner(otInstance *aInstance, const ot
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aExtAddress A pointer to the Joiner's extended address or NULL for any Joiner.
*
* @retval kThreadError_None Successfully added the Joiner.
* @retval kThreadError_None Successfully removed the Joiner.
* @retval kThreadError_NotFound The Joiner specified by @p aExtAddress was not found.
* @retval kThreadError_InvalidArgs @p aExtAddress is invalid.
* @retval kThreadError_InvalidState The commissioner is not active.
*
* @note Only use this after successfully started the Commissioner role by otCommissionerStart().
*
*/
OTAPI ThreadError OTCALL otCommissionerRemoveJoiner(otInstance *aIntsance, const otExtAddress *aExtAddress);
@@ -101,9 +107,10 @@ OTAPI ThreadError OTCALL otCommissionerRemoveJoiner(otInstance *aIntsance, const
/**
* This function sets the Provisioning URL.
*
* @param[in] aProvisioningUrl A pointer to the Provisioning URL (may be NULL).
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aProvisioningUrl A pointer to the Provisioning URL (may be NULL).
*
* @retval kThreadError_None Successfully added the Joiner.
* @retval kThreadError_None Successfully set the Provisioning URL.
* @retval kThreadError_InvalidArgs @p aProvisioningUrl is invalid.
*
*/
@@ -112,14 +119,17 @@ OTAPI ThreadError OTCALL otCommissionerSetProvisioningUrl(otInstance *aInstance,
/**
* This function sends an Announce Begin message.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aChannelMask The channel mask value.
* @param[in] aCount The number of energy measurements per channel.
* @param[in] aPeriod The time between energy measurements (milliseconds).
* @param[in] aAddress A pointer to the IPv6 destination.
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aChannelMask The channel mask value.
* @param[in] aCount The number of energy measurements per channel.
* @param[in] aPeriod The time between energy measurements (milliseconds).
* @param[in] aAddress A pointer to the IPv6 destination.
*
* @retval kThreadError_None Successfully enqueued the Announce Begin message.
* @retval kThreadError_NoBufs Insufficient buffers to generate an Announce Begin message.
* @retval kThreadError_None Successfully enqueued the Announce Begin message.
* @retval kThreadError_NoBufs Insufficient buffers to generate an Announce Begin message.
* @retval kThreadError_InvalidState The commissioner is not active.
*
* @note Only use this after successfully started the Commissioner role by otCommissionerStart().
*
*/
OTAPI ThreadError OTCALL otCommissionerAnnounceBegin(otInstance *aInstance, uint32_t aChannelMask, uint8_t aCount,
@@ -141,17 +151,20 @@ typedef void (OTCALL *otCommissionerEnergyReportCallback)(uint32_t aChannelMask,
/**
* This function sends an Energy Scan Query message.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aChannelMask The channel mask value.
* @param[in] aCount The number of energy measurements per channel.
* @param[in] aPeriod The time between energy measurements (milliseconds).
* @param[in] aScanDuration The scan duration for each energy measurement (milliseconds).
* @param[in] aAddress A pointer to the IPv6 destination.
* @param[in] aCallback A pointer to a function called on receiving an Energy Report message.
* @param[in] aContext A pointer to application-specific context.
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aChannelMask The channel mask value.
* @param[in] aCount The number of energy measurements per channel.
* @param[in] aPeriod The time between energy measurements (milliseconds).
* @param[in] aScanDuration The scan duration for each energy measurement (milliseconds).
* @param[in] aAddress A pointer to the IPv6 destination.
* @param[in] aCallback A pointer to a function called on receiving an Energy Report message.
* @param[in] aContext A pointer to application-specific context.
*
* @retval kThreadError_None Successfully enqueued the Energy Scan Query message.
* @retval kThreadError_NoBufs Insufficient buffers to generate an Energy Scan Query message.
* @retval kThreadError_None Successfully enqueued the Energy Scan Query message.
* @retval kThreadError_NoBufs Insufficient buffers to generate an Energy Scan Query message.
* @retval kThreadError_InvalidState The commissioner is not active.
*
* @note Only use this after successfully started the Commissioner role by otCommissionerStart().
*
*/
OTAPI ThreadError OTCALL otCommissionerEnergyScan(otInstance *aInstance, uint32_t aChannelMask, uint8_t aCount,
@@ -171,15 +184,18 @@ typedef void (OTCALL *otCommissionerPanIdConflictCallback)(uint16_t aPanId, uint
/**
* This function sends a PAN ID Query message.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aPanId The PAN ID to query.
* @param[in] aChannelMask The channel mask value.
* @param[in] aAddress A pointer to the IPv6 destination.
* @param[in] aCallback A pointer to a function called on receiving an Energy Report message.
* @param[in] aContext A pointer to application-specific context.
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aPanId The PAN ID to query.
* @param[in] aChannelMask The channel mask value.
* @param[in] aAddress A pointer to the IPv6 destination.
* @param[in] aCallback A pointer to a function called on receiving an Energy Report message.
* @param[in] aContext A pointer to application-specific context.
*
* @retval kThreadError_None Successfully enqueued the PAN ID Query message.
* @retval kThreadError_NoBufs Insufficient buffers to generate a PAN ID Query message.
* @retval kThreadError_None Successfully enqueued the PAN ID Query message.
* @retval kThreadError_NoBufs Insufficient buffers to generate a PAN ID Query message.
* @retval kThreadError_InvalidState The commissioner is not active.
*
* @note Only use this after successfully started the Commissioner role by otCommissionerStart().
*
*/
OTAPI ThreadError OTCALL otCommissionerPanIdQuery(otInstance *aInstance, uint16_t aPanId, uint32_t aChannelMask,
+3 -1
View File
@@ -76,7 +76,9 @@ ThreadError AnnounceBeginClient::SendRequest(uint32_t aChannelMask, uint8_t aCou
MeshCoP::PeriodTlv period;
Ip6::MessageInfo messageInfo;
Message *message;
Message *message = NULL;
VerifyOrExit(mNetif.GetCommissioner().GetState() == kCommissionerStateActive, error = kThreadError_InvalidState);
header.Init(aAddress.IsMulticast() ? kCoapTypeNonConfirmable : kCoapTypeConfirmable,
kCoapRequestPost);
+4 -2
View File
@@ -222,6 +222,8 @@ ThreadError Commissioner::AddJoiner(const Mac::ExtAddress *aExtAddress, const ch
{
ThreadError error = kThreadError_NoBufs;
VerifyOrExit(mState == kCommissionerStateActive, error = kThreadError_InvalidState);
otLogFuncEntryMsg("%llX, %s", (aExtAddress ? HostSwap64(*reinterpret_cast<const uint64_t *>(aExtAddress)) : 0), aPSKd);
VerifyOrExit(strlen(aPSKd) <= Dtls::kPskMaxLength, error = kThreadError_InvalidArgs);
RemoveJoiner(aExtAddress, 0); // remove imediately
@@ -263,6 +265,8 @@ ThreadError Commissioner::RemoveJoiner(const Mac::ExtAddress *aExtAddress, uint3
{
ThreadError error = kThreadError_NotFound;
VerifyOrExit(mState == kCommissionerStateActive, error = kThreadError_InvalidState);
otLogFuncEntryMsg("%llX", (aExtAddress ? HostSwap64(*reinterpret_cast<const uint64_t *>(aExtAddress)) : 0));
for (size_t i = 0; i < sizeof(mJoiners) / sizeof(mJoiners[0]); i++)
@@ -667,8 +671,6 @@ void Commissioner::HandleLeaderPetitionResponse(Coap::Header *aHeader, Message *
mTransmitAttempts = 0;
mTimer.Start(Timer::SecToMsec(kKeepAliveTimeout) / 2);
SendCommissionerSet();
exit:
if (retransmit)
+3 -1
View File
@@ -85,7 +85,9 @@ ThreadError EnergyScanClient::SendQuery(uint32_t aChannelMask, uint8_t aCount, u
MeshCoP::PeriodTlv period;
MeshCoP::ScanDurationTlv scanDuration;
Ip6::MessageInfo messageInfo;
Message *message;
Message *message = NULL;
VerifyOrExit(mNetif.GetCommissioner().GetState() == kCommissionerStateActive, error = kThreadError_InvalidState);
header.Init(aAddress.IsMulticast() ? kCoapTypeNonConfirmable : kCoapTypeConfirmable,
kCoapRequestPost);
+3 -1
View File
@@ -79,7 +79,9 @@ ThreadError PanIdQueryClient::SendQuery(uint16_t aPanId, uint32_t aChannelMask,
MeshCoP::ChannelMask0Tlv channelMask;
MeshCoP::PanIdTlv panId;
Ip6::MessageInfo messageInfo;
Message *message;
Message *message = NULL;
VerifyOrExit(mNetif.GetCommissioner().GetState() == kCommissionerStateActive, error = kThreadError_InvalidState);
header.Init(aAddress.IsMulticast() ? kCoapTypeNonConfirmable : kCoapTypeConfirmable,
kCoapRequestPost);
@@ -87,6 +87,8 @@ class Cert_9_2_7_DelayTimer(unittest.TestCase):
self.nodes[COMMISSIONER].start()
time.sleep(5)
self.assertEqual(self.nodes[COMMISSIONER].get_state(), 'router')
self.nodes[COMMISSIONER].commissioner_start()
time.sleep(3)
self.nodes[ROUTER].start()
time.sleep(10)
@@ -90,6 +90,8 @@ class Cert_9_2_09_PendingPartition(unittest.TestCase):
self.nodes[COMMISSIONER].start()
time.sleep(5)
self.assertEqual(self.nodes[COMMISSIONER].get_state(), 'router')
self.nodes[COMMISSIONER].commissioner_start()
time.sleep(3)
self.nodes[ROUTER1].start()
time.sleep(5)
@@ -96,6 +96,8 @@ class Cert_9_2_10_PendingPartition(unittest.TestCase):
self.nodes[COMMISSIONER].start()
time.sleep(5)
self.assertEqual(self.nodes[COMMISSIONER].get_state(), 'router')
self.nodes[COMMISSIONER].commissioner_start()
time.sleep(3)
self.nodes[ROUTER1].start()
time.sleep(5)
@@ -95,6 +95,8 @@ class Cert_9_2_11_MasterKey(unittest.TestCase):
self.nodes[COMMISSIONER].start()
time.sleep(5)
self.assertEqual(self.nodes[COMMISSIONER].get_state(), 'router')
self.nodes[COMMISSIONER].commissioner_start()
time.sleep(3)
self.nodes[ROUTER1].start()
time.sleep(5)
@@ -92,6 +92,8 @@ class Cert_9_2_12_Announce(unittest.TestCase):
self.nodes[LEADER1].start()
self.nodes[LEADER1].set_state('leader')
self.assertEqual(self.nodes[LEADER1].get_state(), 'leader')
self.nodes[LEADER1].commissioner_start()
time.sleep(3)
self.nodes[ROUTER1].start()
time.sleep(5)
@@ -80,6 +80,8 @@ class Cert_9_2_13_EnergyScan(unittest.TestCase):
self.nodes[COMMISSIONER].start()
time.sleep(5)
self.assertEqual(self.nodes[COMMISSIONER].get_state(), 'router')
self.nodes[COMMISSIONER].commissioner_start()
time.sleep(3)
self.nodes[ROUTER1].start()
time.sleep(5)
@@ -80,6 +80,8 @@ class Cert_9_2_14_PanIdQuery(unittest.TestCase):
self.nodes[COMMISSIONER].start()
time.sleep(5)
self.assertEqual(self.nodes[COMMISSIONER].get_state(), 'router')
self.nodes[COMMISSIONER].commissioner_start()
time.sleep(3)
self.nodes[ROUTER1].start()
time.sleep(5)
@@ -88,6 +88,8 @@ class Cert_9_2_15_PendingPartition(unittest.TestCase):
self.nodes[COMMISSIONER].start()
time.sleep(5)
self.assertEqual(self.nodes[COMMISSIONER].get_state(), 'router')
self.nodes[COMMISSIONER].commissioner_start()
time.sleep(3)
self.nodes[ROUTER1].start()
time.sleep(5)
@@ -89,6 +89,8 @@ class Cert_9_2_16_ActivePendingPartition(unittest.TestCase):
self.nodes[COMMISSIONER].start()
time.sleep(5)
self.assertEqual(self.nodes[COMMISSIONER].get_state(), 'router')
self.nodes[COMMISSIONER].commissioner_start()
time.sleep(3)
self.nodes[ROUTER1].start()
time.sleep(5)
@@ -104,6 +104,8 @@ class Cert_9_2_18_RollBackActiveTimestamp(unittest.TestCase):
self.nodes[COMMISSIONER].start()
time.sleep(5)
self.assertEqual(self.nodes[COMMISSIONER].get_state(), 'router')
self.nodes[COMMISSIONER].commissioner_start()
time.sleep(3)
self.nodes[ROUTER1].start()
time.sleep(5)