mirror of
https://github.com/espressif/openthread.git
synced 2026-07-26 22:09:05 +00:00
[commissioner] add GetNextJoinerInfo() function (#4179)
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user