mirror of
https://github.com/espressif/openthread.git
synced 2026-07-30 07:37:46 +00:00
When commissioning, set ext addr based on factory-assigned IEEE EUI-64. (#584)
- Add CLI for printing the factory-assigned IEEE EUI-64. - Add otPlatRadioGetIeeeEui64() API.
This commit is contained in:
@@ -111,6 +111,17 @@ void setChannel(uint8_t channel)
|
||||
HWREG(RFCORE_XREG_FREQCTRL) = 11 + (channel - 11) * 5;
|
||||
}
|
||||
|
||||
void otPlatRadioGetIeeeEui64(otInstance *aInstance, uint8_t *aIeeeEui64)
|
||||
{
|
||||
uint8_t *eui64 = (uint8_t *)IEEE_EUI64;
|
||||
(void)aInstance;
|
||||
|
||||
for (uint8_t i = 0; i < OT_EXT_ADDRESS_SIZE; i++)
|
||||
{
|
||||
aIeeeEui64[i] = eui64[7 - i];
|
||||
}
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioSetPanId(otInstance *aInstance, uint16_t panid)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
|
||||
@@ -260,6 +260,19 @@ static inline void getExtAddress(const uint8_t *frame, otExtAddress *address)
|
||||
}
|
||||
}
|
||||
|
||||
void otPlatRadioGetIeeeEui64(otInstance *aInstance, uint8_t *aIeeeEui64)
|
||||
{
|
||||
(void)aInstance;
|
||||
aIeeeEui64[0] = 0x18;
|
||||
aIeeeEui64[1] = 0xb4;
|
||||
aIeeeEui64[2] = 0x30;
|
||||
aIeeeEui64[3] = 0x00;
|
||||
aIeeeEui64[4] = (NODE_ID >> 24) & 0xff;
|
||||
aIeeeEui64[5] = (NODE_ID >> 16) & 0xff;
|
||||
aIeeeEui64[6] = (NODE_ID >> 8) & 0xff;
|
||||
aIeeeEui64[7] = NODE_ID & 0xff;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioSetPanId(otInstance *aInstance, uint16_t panid)
|
||||
{
|
||||
ThreadError error = kThreadError_Busy;
|
||||
|
||||
@@ -144,6 +144,15 @@ typedef enum PhyState
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get the factory-assigned IEEE EUI-64 for this interface.
|
||||
*
|
||||
* @param[in] aInstance The OpenThread instance structure.
|
||||
* @param[out] aIeeeEui64 A pointer to where the factory-assigned IEEE EUI-64 will be placed.
|
||||
*
|
||||
*/
|
||||
void otPlatRadioGetIeeeEui64(otInstance *aInstance, uint8_t *aIeeeEui64);
|
||||
|
||||
/**
|
||||
* Set the PAN ID for address filtering.
|
||||
*
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
#include <common/encoding.hpp>
|
||||
#include <common/new.hpp>
|
||||
#include <net/ip6.hpp>
|
||||
#include <platform/radio.h>
|
||||
#include <platform/random.h>
|
||||
#include <platform/uart.h>
|
||||
|
||||
@@ -83,6 +84,7 @@ const struct Command Interpreter::sCommands[] =
|
||||
#endif
|
||||
{ "discover", &Interpreter::ProcessDiscover },
|
||||
{ "eidcache", &Interpreter::ProcessEidCache },
|
||||
{ "eui64", &Interpreter::ProcessEui64 },
|
||||
#ifdef OPENTHREAD_EXAMPLES_POSIX
|
||||
{ "exit", &Interpreter::ProcessExit },
|
||||
#endif
|
||||
@@ -546,6 +548,22 @@ exit:
|
||||
AppendResult(kThreadError_None);
|
||||
}
|
||||
|
||||
void Interpreter::ProcessEui64(int argc, char *argv[])
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
otExtAddress extAddress;
|
||||
|
||||
VerifyOrExit(argc == 0, error = kThreadError_Parse);
|
||||
|
||||
otPlatRadioGetIeeeEui64(mInstance, extAddress.m8);
|
||||
OutputBytes(extAddress.m8, OT_EXT_ADDRESS_SIZE);
|
||||
sServer->OutputFormat("\r\n");
|
||||
|
||||
exit:
|
||||
(void)argv;
|
||||
AppendResult(error);
|
||||
}
|
||||
|
||||
void Interpreter::ProcessExtAddress(int argc, char *argv[])
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
|
||||
@@ -153,6 +153,7 @@ private:
|
||||
#endif // OPENTHREAD_ENABLE_DIAG
|
||||
void ProcessDiscover(int argc, char *argv[]);
|
||||
void ProcessEidCache(int argc, char *argv[]);
|
||||
void ProcessEui64(int argc, char *argv[]);
|
||||
#ifdef OPENTHREAD_EXAMPLES_POSIX
|
||||
void ProcessExit(int argc, char *argv[]);
|
||||
#endif
|
||||
|
||||
@@ -44,6 +44,8 @@
|
||||
#include <common/encoding.hpp>
|
||||
#include <common/logging.hpp>
|
||||
#include <meshcop/joiner.hpp>
|
||||
#include <platform/radio.h>
|
||||
#include <platform/random.h>
|
||||
#include <thread/thread_netif.hpp>
|
||||
#include <thread/thread_uris.hpp>
|
||||
|
||||
@@ -65,6 +67,20 @@ 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;
|
||||
|
||||
// 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().SetExtAddress(extAddress);
|
||||
mNetif.GetMle().UpdateLinkLocalAddress();
|
||||
|
||||
SuccessOrExit(error = mNetif.GetDtls().SetPsk(reinterpret_cast<const uint8_t *>(aPSKd),
|
||||
static_cast<uint8_t>(strlen(aPSKd))));
|
||||
@@ -268,6 +284,7 @@ void Joiner::HandleJoinerEntrust(Coap::Header &aHeader, Message &aMessage, const
|
||||
ExtendedPanIdTlv extendedPanId;
|
||||
NetworkNameTlv networkName;
|
||||
ActiveTimestampTlv activeTimestamp;
|
||||
Mac::ExtAddress extAddress;
|
||||
|
||||
VerifyOrExit(aHeader.GetType() == Coap::Header::kTypeConfirmable &&
|
||||
aHeader.GetCode() == Coap::Header::kCodePost, error = kThreadError_Drop);
|
||||
@@ -296,6 +313,15 @@ void Joiner::HandleJoinerEntrust(Coap::Header &aHeader, Message &aMessage, const
|
||||
|
||||
otLogInfoMeshCoP("join success!\r\n");
|
||||
|
||||
// configure a random Extended Address
|
||||
for (size_t i = 0; i < sizeof(extAddress); i++)
|
||||
{
|
||||
extAddress.m8[i] = static_cast<uint8_t>(otPlatRandomGet());
|
||||
}
|
||||
|
||||
mNetif.GetMac().SetExtAddress(extAddress);
|
||||
mNetif.GetMle().UpdateLinkLocalAddress();
|
||||
|
||||
exit:
|
||||
(void)aMessageInfo;
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user