Add Hash MAC address get cli (#611)

- move Hash Mac address calculation from joiner.cpp to mac.cpp

- add hashmacaddr cli
This commit is contained in:
Shu Chen
2016-09-16 05:43:44 -07:00
committed by Jonathan Hui
parent c100be7ccb
commit 0d54e51ebe
8 changed files with 84 additions and 10 deletions
+12
View File
@@ -511,6 +511,18 @@ void otSetExtendedPanId(otInstance *aInstance, const uint8_t *aExtendedPanId);
*/
void otGetFactoryAssignedIeeeEui64(otInstance *aInstance, otExtAddress *aEui64);
/**
* Get the Hash Mac Address.
*
* Hash Mac Address is the first 64 bits of the result of computing SHA-256 over factory-assigned
* IEEE EUI-64, which is used as IEEE 802.15.4 Extended Address during commissioning process.
*
* @param[in] aInstance A pointer to the OpenThread instance.
* @param[out] aHashMacAddress A pointer to where the Hash Mac Address is placed.
*
*/
void otGetHashMacAddress(otInstance *aInstance, otExtAddress *aHashMacAddress);
/**
* This function returns a pointer to the Leader's RLOC.
*
+22
View File
@@ -17,8 +17,10 @@ OpenThread test scripts use the CLI to execute test cases.
* [dataset](#dataset)
* [discover](#discover)
* [eidcache](#eidcache)
* [eui64](#eui64)
* [extaddr](#extaddr)
* [extpanid](#extpanid)
* [hashmacaddr](#hashmacaddr)
* [ifconfig](#ifconfig)
* [ipaddr](#ipaddr)
* [keysequence](#keysequence)
@@ -552,6 +554,16 @@ fdde:ad00:beef:0:110a:e041:8399:17cd 6000
Done
```
### eui64
Get the factory-assigned IEEE EUI-64.
```bash
> eui64
0615aae900124b00
Done
```
### extaddr
Get the IEEE 802.15.4 Extended Address.
@@ -591,6 +603,16 @@ Set the Thread Extended PAN ID value.
Done
```
### hashmacaddr
Get the HashMac address.
```bash
> hashmacaddr
e0b220eb7d8dda7e
Done
```
### ifconfig up
Bring up the IPv6 interface.
+17
View File
@@ -89,6 +89,7 @@ const struct Command Interpreter::sCommands[] =
#endif
{ "extaddr", &Interpreter::ProcessExtAddress },
{ "extpanid", &Interpreter::ProcessExtPanId },
{ "hashmacaddr", &Interpreter::ProcessHashMacAddress },
{ "ifconfig", &Interpreter::ProcessIfconfig },
{ "ipaddr", &Interpreter::ProcessIpAddr },
#if OPENTHREAD_ENABLE_JOINER
@@ -617,6 +618,22 @@ exit:
AppendResult(error);
}
void Interpreter::ProcessHashMacAddress(int argc, char *argv[])
{
ThreadError error = kThreadError_None;
otExtAddress hashMacAddress;
VerifyOrExit(argc == 0, error = kThreadError_Parse);
otGetHashMacAddress(mInstance, &hashMacAddress);
OutputBytes(hashMacAddress.m8, OT_EXT_ADDRESS_SIZE);
sServer->OutputFormat("\r\n");
exit:
(void)argv;
AppendResult(error);
}
void Interpreter::ProcessIfconfig(int argc, char *argv[])
{
ThreadError error = kThreadError_None;
+1
View File
@@ -159,6 +159,7 @@ private:
#endif
void ProcessExtAddress(int argc, char *argv[]);
void ProcessExtPanId(int argc, char *argv[]);
void ProcessHashMacAddress(int argc, char *argv[]);
void ProcessIfconfig(int argc, char *argv[]);
void ProcessIpAddr(int argc, char *argv[]);
ThreadError ProcessIpAddrAdd(int argc, char *argv[]);
+14
View File
@@ -43,6 +43,7 @@
#include <common/debug.hpp>
#include <common/logging.hpp>
#include <crypto/aes_ccm.hpp>
#include <crypto/sha256.hpp>
#include <mac/mac.hpp>
#include <mac/mac_frame.hpp>
#include <platform/random.h>
@@ -299,6 +300,19 @@ exit:
return error;
}
void Mac::GetHashMacAddress(ExtAddress *aHashMacAddress)
{
Crypto::Sha256 sha256;
uint8_t buf[Crypto::Sha256::kHashSize];
otPlatRadioGetIeeeEui64(NULL, buf);
sha256.Start();
sha256.Update(buf, OT_EXT_ADDRESS_SIZE);
sha256.Finish(buf);
memcpy(aHashMacAddress->m8, buf, OT_EXT_ADDRESS_SIZE);
}
ShortAddress Mac::GetShortAddress(void) const
{
return mShortAddress;
+11
View File
@@ -290,6 +290,17 @@ public:
*/
ThreadError SetExtAddress(const ExtAddress &aExtAddress);
/**
* This method gets the Hash Mac Address.
*
* Hash Mac Address is the first 64 bits of the result of computing SHA-256 over factory-assigned
* IEEE EUI-64, which is used as IEEE 802.15.4 Extended Address during commissioning process.
*
* @param[out] aHashMacAddress A pointer to where the Hash Mac Address is placed.
*
*/
void GetHashMacAddress(ExtAddress *aHashMacAddress);
/**
* This method returns the IEEE 802.15.4 Short Address.
*
+2 -10
View File
@@ -67,18 +67,10 @@ Joiner::Joiner(ThreadNetif &aNetif):
ThreadError Joiner::Start(const char *aPSKd)
{
ThreadError error;
union
{
Mac::ExtAddress extAddress;
uint8_t buf[Crypto::Sha256::kHashSize];
};
Crypto::Sha256 sha256;
Mac::ExtAddress extAddress;
// use extended address based on factory-assigned IEEE EUI-64
otPlatRadioGetIeeeEui64(NULL, buf);
sha256.Start();
sha256.Update(buf, OT_EXT_ADDRESS_SIZE);
sha256.Finish(buf);
mNetif.GetMac().GetHashMacAddress(&extAddress);
mNetif.GetMac().SetExtAddress(extAddress);
mNetif.GetMle().UpdateLinkLocalAddress();
+5
View File
@@ -181,6 +181,11 @@ void otGetFactoryAssignedIeeeEui64(otInstance *aInstance, otExtAddress *aEui64)
otPlatRadioGetIeeeEui64(aInstance, aEui64->m8);
}
void otGetHashMacAddress(otInstance *, otExtAddress *aHashMacAddress)
{
sThreadNetif->GetMac().GetHashMacAddress(static_cast<Mac::ExtAddress *>(aHashMacAddress));
}
ThreadError otGetLeaderRloc(otInstance *, otIp6Address *aAddress)
{
ThreadError error;