[commissioner] add GetNextJoinerInfo() function (#4179)

This commit is contained in:
huamenggg
2019-09-18 07:46:37 -07:00
committed by Jonathan Hui
parent bb56fa906a
commit 6d1981b112
4 changed files with 75 additions and 0 deletions
+28
View File
@@ -110,6 +110,21 @@ typedef struct otCommissioningDataset
bool mIsJoinerUdpPortSet : 1; ///< TRUE if Joiner UDP Port is set, FALSE otherwise.
} otCommissioningDataset;
#define OT_PSKD_MAX_SIZE 32 ///< Size of a Joiner PSKd (bytes)
/**
* This structure represents a Joiner Info.
*
*/
typedef struct otJoinerInfo
{
otExtAddress mEui64; ///< Joiner eui64
char mPsk[OT_PSKD_MAX_SIZE + 1]; ///< Joiner pskd
uint32_t mExpirationTime; ///< Joiner expiration time in msec
bool mAny : 1; /// TRUE if eui64 isn't set, FALSE otherwise.
} otJoinerInfo;
/**
* This function pointer is called whenever the commissioner state changes.
*
@@ -182,6 +197,19 @@ otError otCommissionerAddJoiner(otInstance * aInstance,
const char * aPSKd,
uint32_t aTimeout);
/**
* This method get joiner info at aIterator position.
*
* @param[in] aInstance A pointer to instance.
* @param[inout] aIterator A iterator to the index of the joiner.
* @param[out] aJoiner A reference to Joiner info.
*
* @retval OT_ERROR_NONE Successfully get the Joiner info.
* @retval OT_ERROR_NOT_FOUND Not found next Joiner.
*
*/
otError otCommissionerGetNextJoinerInfo(otInstance *aInstance, uint16_t &aIterator, otJoinerInfo &aJoiner);
/**
* This function removes a Joiner entry.
*
+7
View File
@@ -81,6 +81,13 @@ otError otCommissionerAddJoiner(otInstance *aInstance, const otExtAddress *aEui6
aTimeout);
}
otError otCommissionerGetNextJoinerInfo(otInstance *aInstance, uint16_t &aIterator, otJoinerInfo &aJoiner)
{
Instance &instance = *static_cast<Instance *>(aInstance);
return instance.Get<MeshCoP::Commissioner>().GetNextJoinerInfo(aIterator, aJoiner);
}
otError otCommissionerRemoveJoiner(otInstance *aInstance, const otExtAddress *aEui64)
{
Instance &instance = *static_cast<Instance *>(aInstance);
+28
View File
@@ -297,6 +297,34 @@ exit:
return error;
}
otError Commissioner::GetNextJoinerInfo(uint16_t &aIterator, otJoinerInfo &aJoiner) const
{
otError error = OT_ERROR_NONE;
size_t index;
for (index = aIterator; index < OT_ARRAY_LENGTH(mJoiners); index++)
{
if (!mJoiners[index].mValid)
{
continue;
}
memset(&aJoiner, 0, sizeof(aJoiner));
aJoiner.mAny = mJoiners[index].mAny;
aJoiner.mEui64 = mJoiners[index].mEui64;
strlcpy(aJoiner.mPsk, mJoiners[index].mPsk, sizeof(aJoiner.mPsk));
aJoiner.mExpirationTime = mJoiners[index].mExpirationTime - TimerMilli::GetNow();
aIterator = static_cast<uint16_t>(index) + 1;
ExitNow();
}
error = OT_ERROR_NOT_FOUND;
exit:
return error;
}
otError Commissioner::RemoveJoiner(const Mac::ExtAddress *aEui64, uint32_t aDelay)
{
otError error = OT_ERROR_NOT_FOUND;
+12
View File
@@ -109,6 +109,18 @@ public:
*/
otError AddJoiner(const Mac::ExtAddress *aEui64, const char *aPSKd, uint32_t aTimeout);
/**
* This method get joiner info at aIterator position.
*
* @param[inout] aIterator A iterator to the index of the joiner.
* @param[out] aJoiner A reference to Joiner info.
*
* @retval OT_ERROR_NONE Successfully get the Joiner info.
* @retval OT_ERROR_NOT_FOUND Not found next Joiner.
*
*/
otError GetNextJoinerInfo(uint16_t &aIterator, otJoinerInfo &aJoiner) const;
/**
* This method removes a Joiner entry.
*