diff --git a/include/openthread/commissioner.h b/include/openthread/commissioner.h index 593eca2ac..cd3a97beb 100644 --- a/include/openthread/commissioner.h +++ b/include/openthread/commissioner.h @@ -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. * diff --git a/src/core/api/commissioner_api.cpp b/src/core/api/commissioner_api.cpp index b3417be9f..f5a093fb4 100644 --- a/src/core/api/commissioner_api.cpp +++ b/src/core/api/commissioner_api.cpp @@ -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(aInstance); + + return instance.Get().GetNextJoinerInfo(aIterator, aJoiner); +} + otError otCommissionerRemoveJoiner(otInstance *aInstance, const otExtAddress *aEui64) { Instance &instance = *static_cast(aInstance); diff --git a/src/core/meshcop/commissioner.cpp b/src/core/meshcop/commissioner.cpp index ddd15308c..aaedc23a9 100644 --- a/src/core/meshcop/commissioner.cpp +++ b/src/core/meshcop/commissioner.cpp @@ -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(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; diff --git a/src/core/meshcop/commissioner.hpp b/src/core/meshcop/commissioner.hpp index f332e85c7..7ff1e5854 100644 --- a/src/core/meshcop/commissioner.hpp +++ b/src/core/meshcop/commissioner.hpp @@ -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. *