Skip to content

Commit e014104

Browse files
committed
Allow ThreadInterface::device_eui64_get() before connect()
Perform necessary driver initialisation so that we can read the EUI-64 before connecting. Fixes #7391.
1 parent 3a238bd commit e014104

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,20 @@ int InterfaceNanostack::disconnect()
102102

103103
nsapi_error_t MeshInterfaceNanostack::initialize(NanostackRfPhy *phy)
104104
{
105-
if (_phy) {
105+
if (_phy && phy && _phy != phy) {
106106
error("Phy already set");
107107
return NSAPI_ERROR_IS_CONNECTED;
108108
}
109-
_phy = phy;
110-
return NSAPI_ERROR_OK;
109+
if (phy) {
110+
_phy = phy;
111+
}
112+
if (_phy) {
113+
return do_initialize();
114+
} else {
115+
return NSAPI_ERROR_PARAMETER;
116+
}
111117
}
112118

113-
114119
void Nanostack::Interface::network_handler(mesh_connection_status_t status)
115120
{
116121
if ((status == MESH_CONNECTED || status == MESH_CONNECTED_LOCAL ||
@@ -148,7 +153,9 @@ nsapi_error_t Nanostack::Interface::register_phy()
148153
{
149154
NanostackLockGuard lock;
150155

151-
_device_id = interface_phy.phy_register();
156+
if (_device_id < 0) {
157+
_device_id = interface_phy.phy_register();
158+
}
152159
if (_device_id < 0) {
153160
return NSAPI_ERROR_DEVICE_ERROR;
154161
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ void ThreadInterface::device_eui64_set(const uint8_t *eui64)
213213

214214
void ThreadInterface::device_eui64_get(uint8_t *eui64)
215215
{
216+
memset(eui64, 0, 8);
217+
if (!get_interface()) {
218+
return;
219+
}
216220
get_interface()->device_eui64_get(eui64);
217221
}
218222

@@ -226,6 +230,9 @@ void Nanostack::ThreadInterface::device_eui64_get(uint8_t *eui64)
226230
{
227231
if (!eui64_set) {
228232
uint8_t eui64_buf[8];
233+
if (register_phy() < 0) {
234+
return;
235+
}
229236
get_phy().get_mac_address(eui64_buf);
230237
device_eui64_set(eui64_buf);
231238
}

0 commit comments

Comments
 (0)