Skip to content

Add API to read Thread EUI-64 #7158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions features/nanostack/mbed-mesh-api/mbed-mesh-api/ThreadInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ class ThreadInterface : public MeshInterfaceNanostack {
*
* Must initialize to initialize the mesh on a phy.
*/
ThreadInterface() : user_set_eui64(false) { }
ThreadInterface() { }

/** Create an initialized ThreadInterface
*
*/
ThreadInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy), user_set_eui64(false) { }
ThreadInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }

/**
* \brief Sets the eui64 for the device configuration.
Expand All @@ -44,6 +44,13 @@ class ThreadInterface : public MeshInterfaceNanostack {
* */
void device_eui64_set(const uint8_t *eui64);

/**
* \brief Reads the eui64 from the device configuration.
* By default this value is read from the radio driver, but it may have
* been set by device_eui64_set().
* */
void device_eui64_get(uint8_t *eui64);

/**
* \brief sets the PSKd for the device configuration.
* The default value is overwritten, which is defined in the mbed_lib.json file in the mesh-api
Expand All @@ -59,9 +66,6 @@ class ThreadInterface : public MeshInterfaceNanostack {
virtual int disconnect();
protected:
Nanostack::ThreadInterface *get_interface() const;

private:
bool user_set_eui64;
};

#endif // THREADINTERFACE_H
35 changes: 27 additions & 8 deletions features/nanostack/mbed-mesh-api/source/ThreadInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Nanostack::ThreadInterface : public Nanostack::MeshInterface
friend Nanostack;
friend class ::ThreadInterface;
private:
ThreadInterface(NanostackRfPhy &phy) : MeshInterface(phy), user_eui64_set(false) { }
ThreadInterface(NanostackRfPhy &phy) : MeshInterface(phy), eui64_set(false) { }

/*
* \brief Initialization of the interface.
Expand Down Expand Up @@ -52,6 +52,11 @@ class Nanostack::ThreadInterface : public Nanostack::MeshInterface
* */
void device_eui64_set(const uint8_t *eui64);

/**
* \brief Reads the eui64 from the device configuration.
* */
void device_eui64_get(uint8_t *eui64);

/**
* \brief sets the PSKd for the device configuration.
* The default value is overwritten, which is defined in the mbed_lib.json file in the mesh-api
Expand All @@ -63,7 +68,7 @@ class Nanostack::ThreadInterface : public Nanostack::MeshInterface

mesh_error_t device_pskd_set(const char *pskd);

bool user_eui64_set;
bool eui64_set;
};

Nanostack::ThreadInterface *ThreadInterface::get_interface() const
Expand Down Expand Up @@ -161,11 +166,7 @@ mesh_error_t Nanostack::ThreadInterface::init()
{
thread_tasklet_init();
__mesh_handler_set_callback(this);
if (!user_eui64_set) {
uint8_t eui64[8];
get_phy().get_mac_address(eui64);
thread_tasklet_device_eui64_set(eui64);
}
device_eui64_get(NULL); // Ensure we've selected the EUI-64 - this does it
interface_id = thread_tasklet_network_init(_device_id);

if (interface_id == -2) {
Expand Down Expand Up @@ -216,12 +217,30 @@ void ThreadInterface::device_eui64_set(const uint8_t *eui64)
get_interface()->device_eui64_set(eui64);
}

void ThreadInterface::device_eui64_get(uint8_t *eui64)
{
get_interface()->device_eui64_get(eui64);
}

void Nanostack::ThreadInterface::device_eui64_set(const uint8_t *eui64)
{
user_eui64_set = true;
eui64_set = true;
thread_tasklet_device_eui64_set(eui64);
}

void Nanostack::ThreadInterface::device_eui64_get(uint8_t *eui64)
{
if (!eui64_set) {
uint8_t eui64_buf[8];
get_phy().get_mac_address(eui64_buf);
device_eui64_set(eui64_buf);
}

if (eui64) {
thread_tasklet_device_eui64_get(eui64);
}
}

mesh_error_t ThreadInterface::device_pskd_set(const char *pskd)
{
return get_interface()->device_pskd_set(pskd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ int8_t thread_tasklet_network_init(int8_t device_id);
/*
* \brief Sets eui64 for the device configuration
* \param eui64 eui64 to be set
* \param pskd private shared key
*/
void thread_tasklet_device_eui64_set(const uint8_t *eui64);

/*
* \brief Gets eui64 from the device configuration
* \param eui64 buffer for output eui64
*/
void thread_tasklet_device_eui64_get(uint8_t *eui64);

/*
* \brief Sets PSKd for the device configuration
* \param pskd private shared key to be set
Expand Down
5 changes: 5 additions & 0 deletions features/nanostack/mbed-mesh-api/source/thread_tasklet.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,11 @@ void thread_tasklet_device_eui64_set(const uint8_t *eui64)
memcpy(device_configuration.eui64, eui64, 8);
}

void thread_tasklet_device_eui64_get(uint8_t *eui64)
{
memcpy(eui64, device_configuration.eui64, 8);
}

uint8_t thread_tasklet_device_pskd_set(const char *pskd)
{
int len = strlen(pskd);
Expand Down