mirror of
https://github.com/espressif/openthread.git
synced 2026-08-30 22:09:54 +00:00
Add API to retrieve Leader Data information. (#231)
This commit is contained in:
@@ -452,6 +452,19 @@ typedef struct otEidCacheEntry
|
||||
bool mValid : 1; ///< Indicates whether or not the cache entry is valid
|
||||
} otEidCacheEntry;
|
||||
|
||||
/**
|
||||
* This structure represents the Thread Leader Data.
|
||||
*
|
||||
*/
|
||||
typedef struct otLeaderData
|
||||
{
|
||||
uint32_t mPartitionId; ///< Partition ID
|
||||
uint8_t mWeighting; ///< Leader Weight
|
||||
uint8_t mDataVersion; ///< Full Network Data Version
|
||||
uint8_t mStableDataVersion; ///< Stable Network Data Version
|
||||
uint8_t mLeaderRouterId; ///< Leader Router ID
|
||||
} otLeaderData;
|
||||
|
||||
/**
|
||||
* This structure represents the MAC layer counters.
|
||||
*/
|
||||
|
||||
@@ -929,6 +929,18 @@ otDeviceRole otGetDeviceRole(void);
|
||||
*/
|
||||
ThreadError otGetEidCacheEntry(uint8_t aIndex, otEidCacheEntry *aEntry);
|
||||
|
||||
/**
|
||||
* This function get the Thread Leader Data.
|
||||
*
|
||||
* @param[out] aLeaderData A pointer to where the leader data is placed.
|
||||
*
|
||||
* @retval kThreadError_None Successfully retrieved the leader data.
|
||||
* @retval kThreadError_Detached Not currently attached.
|
||||
* @retval kThreadError_InvalidArgs @p aLeaderData is NULL.
|
||||
*
|
||||
*/
|
||||
ThreadError otGetLeaderData(otLeaderData *aLeaderData);
|
||||
|
||||
/**
|
||||
* Get the Leader's Router ID.
|
||||
*
|
||||
|
||||
@@ -60,6 +60,7 @@ const struct Command Interpreter::sCommands[] =
|
||||
{ "extpanid", &ProcessExtPanId },
|
||||
{ "ipaddr", &ProcessIpAddr },
|
||||
{ "keysequence", &ProcessKeySequence },
|
||||
{ "leaderdata", &ProcessLeaderData },
|
||||
{ "leaderweight", &ProcessLeaderWeight },
|
||||
{ "masterkey", &ProcessMasterKey },
|
||||
{ "mode", &ProcessMode },
|
||||
@@ -490,6 +491,23 @@ exit:
|
||||
AppendResult(error);
|
||||
}
|
||||
|
||||
void Interpreter::ProcessLeaderData(int argc, char *argv[])
|
||||
{
|
||||
ThreadError error;
|
||||
otLeaderData leaderData;
|
||||
|
||||
SuccessOrExit(error = otGetLeaderData(&leaderData));
|
||||
|
||||
sServer->OutputFormat("Partition ID: %d\r\n", leaderData.mPartitionId);
|
||||
sServer->OutputFormat("Weighting: %d\r\n", leaderData.mWeighting);
|
||||
sServer->OutputFormat("Data Version: %d\r\n", leaderData.mDataVersion);
|
||||
sServer->OutputFormat("Stable Data Version: %d\r\n", leaderData.mStableDataVersion);
|
||||
sServer->OutputFormat("Leader Router ID: %d\r\n", leaderData.mLeaderRouterId);
|
||||
|
||||
exit:
|
||||
AppendResult(error);
|
||||
}
|
||||
|
||||
void Interpreter::ProcessLeaderWeight(int argc, char *argv[])
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
|
||||
@@ -100,6 +100,7 @@ private:
|
||||
static ThreadError ProcessIpAddrAdd(int argc, char *argv[]);
|
||||
static ThreadError ProcessIpAddrDel(int argc, char *argv[]);
|
||||
static void ProcessKeySequence(int argc, char *argv[]);
|
||||
static void ProcessLeaderData(int argc, char *argv[]);
|
||||
static void ProcessLeaderWeight(int argc, char *argv[]);
|
||||
static void ProcessMasterKey(int argc, char *argv[]);
|
||||
static void ProcessMode(int argc, char *argv[]);
|
||||
|
||||
@@ -535,6 +535,18 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError otGetLeaderData(otLeaderData *aLeaderData)
|
||||
{
|
||||
ThreadError error;
|
||||
|
||||
VerifyOrExit(aLeaderData != NULL, error = kThreadError_InvalidArgs);
|
||||
|
||||
error = sThreadNetif->GetMle().GetLeaderData(*aLeaderData);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
uint8_t otGetLeaderRouterId(void)
|
||||
{
|
||||
return sThreadNetif->GetMle().GetLeaderDataTlv().GetLeaderRouterId();
|
||||
|
||||
@@ -473,6 +473,24 @@ const LeaderDataTlv &Mle::GetLeaderDataTlv(void)
|
||||
return mLeaderData;
|
||||
}
|
||||
|
||||
ThreadError Mle::GetLeaderData(otLeaderData &aLeaderData)
|
||||
{
|
||||
const LeaderDataTlv &leaderData(GetLeaderDataTlv());
|
||||
ThreadError error = kThreadError_None;
|
||||
|
||||
VerifyOrExit(mDeviceState != kDeviceStateDisabled && mDeviceState != kDeviceStateDetached,
|
||||
error = kThreadError_Detached);
|
||||
|
||||
aLeaderData.mPartitionId = leaderData.GetPartitionId();
|
||||
aLeaderData.mWeighting = leaderData.GetWeighting();
|
||||
aLeaderData.mDataVersion = leaderData.GetDataVersion();
|
||||
aLeaderData.mStableDataVersion = leaderData.GetStableDataVersion();
|
||||
aLeaderData.mLeaderRouterId = leaderData.GetLeaderRouterId();
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void Mle::GenerateNonce(const Mac::ExtAddress &aMacAddr, uint32_t aFrameCounter, uint8_t aSecurityLevel,
|
||||
uint8_t *aNonce)
|
||||
{
|
||||
|
||||
@@ -540,6 +540,17 @@ public:
|
||||
*/
|
||||
const LeaderDataTlv &GetLeaderDataTlv(void);
|
||||
|
||||
/**
|
||||
* This method gets the Leader Data.
|
||||
*
|
||||
* @param[out] aLeaderData A reference to where the leader data is placed.
|
||||
*
|
||||
* @retval kThreadError_None Successfully retrieved the leader data.
|
||||
* @retval kThreadError_Detached Not currently attached.
|
||||
*
|
||||
*/
|
||||
ThreadError GetLeaderData(otLeaderData &aLeaderData);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* This method appends an MLE header to a message.
|
||||
|
||||
Reference in New Issue
Block a user