Skip to content

Commit fc5c2fa

Browse files
committed
Add API to read Thread EUI-64
Previously get_mac_address on a ThreadInterface returned the EUI-64 reported by the radio driver. This was required for commissioning, but was inconsistent with other interfaces, and the API concept. 5.9.0 inadvertently changed this so that get_mac_address returned the actual MAC address used by the radio, which is a hash result of the EUI-64 for Thread. The original "return the EUI-64" form was somewhat faulty, as get_mac_address would not return the EUI-64 set by set_device_eui64() or another mechanism before connect() was called. Rather than revert to old behaviour, add a new API to get the device EUI-64 to ThreadInterface, alongside the existing set API.
1 parent 5d8570b commit fc5c2fa

File tree

4 files changed

+47
-14
lines changed

4 files changed

+47
-14
lines changed

features/nanostack/mbed-mesh-api/mbed-mesh-api/ThreadInterface.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ class ThreadInterface : public MeshInterfaceNanostack {
3030
*
3131
* Must initialize to initialize the mesh on a phy.
3232
*/
33-
ThreadInterface() : user_set_eui64(false) { }
33+
ThreadInterface() { }
3434

3535
/** Create an initialized ThreadInterface
3636
*
3737
*/
38-
ThreadInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy), user_set_eui64(false) { }
38+
ThreadInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
3939

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

47+
/**
48+
* \brief Reads the eui64 from the device configuration.
49+
* By default this value is read from the radio driver, but it may have
50+
* been set by device_eui64_set().
51+
* */
52+
void device_eui64_get(uint8_t *eui64);
53+
4754
/**
4855
* \brief sets the PSKd for the device configuration.
4956
* The default value is overwritten, which is defined in the mbed_lib.json file in the mesh-api
@@ -59,9 +66,6 @@ class ThreadInterface : public MeshInterfaceNanostack {
5966
virtual int disconnect();
6067
protected:
6168
Nanostack::ThreadInterface *get_interface() const;
62-
63-
private:
64-
bool user_set_eui64;
6569
};
6670

6771
#endif // THREADINTERFACE_H

features/nanostack/mbed-mesh-api/source/ThreadInterface.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Nanostack::ThreadInterface : public Nanostack::MeshInterface
1818
friend Nanostack;
1919
friend class ::ThreadInterface;
2020
private:
21-
ThreadInterface(NanostackRfPhy &phy) : MeshInterface(phy), user_eui64_set(false) { }
21+
ThreadInterface(NanostackRfPhy &phy) : MeshInterface(phy), eui64_set(false) { }
2222

2323
/*
2424
* \brief Initialization of the interface.
@@ -52,6 +52,11 @@ class Nanostack::ThreadInterface : public Nanostack::MeshInterface
5252
* */
5353
void device_eui64_set(const uint8_t *eui64);
5454

55+
/**
56+
* \brief Reads the eui64 from the device configuration.
57+
* */
58+
void device_eui64_get(uint8_t *eui64);
59+
5560
/**
5661
* \brief sets the PSKd for the device configuration.
5762
* The default value is overwritten, which is defined in the mbed_lib.json file in the mesh-api
@@ -63,7 +68,7 @@ class Nanostack::ThreadInterface : public Nanostack::MeshInterface
6368

6469
mesh_error_t device_pskd_set(const char *pskd);
6570

66-
bool user_eui64_set;
71+
bool eui64_set;
6772
};
6873

6974
Nanostack::ThreadInterface *ThreadInterface::get_interface() const
@@ -161,11 +166,7 @@ mesh_error_t Nanostack::ThreadInterface::init()
161166
{
162167
thread_tasklet_init();
163168
__mesh_handler_set_callback(this);
164-
if (!user_eui64_set) {
165-
uint8_t eui64[8];
166-
get_phy().get_mac_address(eui64);
167-
thread_tasklet_device_eui64_set(eui64);
168-
}
169+
device_eui64_get(NULL); // Ensure we've selected the EUI-64 - this does it
169170
interface_id = thread_tasklet_network_init(_device_id);
170171

171172
if (interface_id == -2) {
@@ -216,12 +217,30 @@ void ThreadInterface::device_eui64_set(const uint8_t *eui64)
216217
get_interface()->device_eui64_set(eui64);
217218
}
218219

220+
void ThreadInterface::device_eui64_get(uint8_t *eui64)
221+
{
222+
get_interface()->device_eui64_get(eui64);
223+
}
224+
219225
void Nanostack::ThreadInterface::device_eui64_set(const uint8_t *eui64)
220226
{
221-
user_eui64_set = true;
227+
eui64_set = true;
222228
thread_tasklet_device_eui64_set(eui64);
223229
}
224230

231+
void Nanostack::ThreadInterface::device_eui64_get(uint8_t *eui64)
232+
{
233+
if (!eui64_set) {
234+
uint8_t eui64_buf[8];
235+
get_phy().get_mac_address(eui64_buf);
236+
device_eui64_set(eui64_buf);
237+
}
238+
239+
if (eui64) {
240+
thread_tasklet_device_eui64_get(eui64);
241+
}
242+
}
243+
225244
mesh_error_t ThreadInterface::device_pskd_set(const char *pskd)
226245
{
227246
return get_interface()->device_pskd_set(pskd);

features/nanostack/mbed-mesh-api/source/include/thread_tasklet.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,15 @@ int8_t thread_tasklet_network_init(int8_t device_id);
5959
/*
6060
* \brief Sets eui64 for the device configuration
6161
* \param eui64 eui64 to be set
62-
* \param pskd private shared key
6362
*/
6463
void thread_tasklet_device_eui64_set(const uint8_t *eui64);
6564

65+
/*
66+
* \brief Gets eui64 from the device configuration
67+
* \param eui64 buffer for output eui64
68+
*/
69+
void thread_tasklet_device_eui64_get(uint8_t *eui64);
70+
6671
/*
6772
* \brief Sets PSKd for the device configuration
6873
* \param pskd private shared key to be set

features/nanostack/mbed-mesh-api/source/thread_tasklet.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ void thread_tasklet_device_eui64_set(const uint8_t *eui64)
474474
memcpy(device_configuration.eui64, eui64, 8);
475475
}
476476

477+
void thread_tasklet_device_eui64_get(uint8_t *eui64)
478+
{
479+
memcpy(eui64, device_configuration.eui64, 8);
480+
}
481+
477482
uint8_t thread_tasklet_device_pskd_set(const char *pskd)
478483
{
479484
int len = strlen(pskd);

0 commit comments

Comments
 (0)