Skip to content

Mesh-api setters for eui64 and pskd #6025

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
Feb 8, 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
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class MeshInterfaceNanostack : public MeshInterface {
int8_t _network_interface_id;
/** Registered device ID */
int8_t _device_id;
uint8_t eui64[8];
uint8_t _eui64[8];
char ip_addr_str[40];
char mac_addr_str[24];
Semaphore connect_semaphore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,25 @@ class ThreadInterface : public MeshInterfaceNanostack {
ThreadInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }

nsapi_error_t initialize(NanostackRfPhy *phy);

/**
* \brief Sets the eui64 for the device configuration.
* By default this value is read from the radio driver.
* The value must be set before calling the connect function.
* */
void device_eui64_set(const 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
* The value must be set before calling the connect function.
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_PARAM in case of illegal parameters.
* \return MESH_ERROR_MEMORY in case of memory error.
* */

mesh_error_t device_pskd_set(const char *pskd);

virtual int connect();
virtual int disconnect();
private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "mesh_system.h"

MeshInterfaceNanostack::MeshInterfaceNanostack()
: phy(NULL), _network_interface_id(-1), _device_id(-1), eui64(),
: phy(NULL), _network_interface_id(-1), _device_id(-1), _eui64(),
ip_addr_str(), mac_addr_str(), connect_semaphore(0)
{
// Nothing to do
Expand Down Expand Up @@ -62,8 +62,13 @@ nsapi_error_t MeshInterfaceNanostack::register_phy()
return -1;
}
// Read mac address after registering the device.
phy->get_mac_address(eui64);
sprintf(mac_addr_str, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", eui64[0], eui64[1], eui64[2], eui64[3], eui64[4], eui64[5], eui64[6], eui64[7]);
const uint8_t empty_eui64[8] = {0,0,0,0,0,0,0,0};
// if not set by application then read from rf driver
if(!memcmp(_eui64, empty_eui64,8)) {
phy->get_mac_address(_eui64);
}

sprintf(mac_addr_str, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", _eui64[0], _eui64[1], _eui64[2], _eui64[3], _eui64[4], _eui64[5], _eui64[6], _eui64[7]);

nanostack_unlock();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ int ThreadInterface::connect()
nanostack_unlock();
return NSAPI_ERROR_DEVICE_ERROR;
}

// After the RF is up, we can seed the random from it.
randLIB_seed_random();

Expand Down Expand Up @@ -64,12 +63,9 @@ int ThreadInterface::disconnect()

mesh_error_t ThreadInterface::init()
{
if (eui64 == NULL) {
return MESH_ERROR_PARAM;
}
thread_tasklet_init();
__mesh_handler_set_callback(this);
thread_tasklet_device_config_set(eui64, NULL);
thread_tasklet_device_eui64_set(_eui64);
_network_interface_id = thread_tasklet_network_init(_device_id);

if (_network_interface_id == -2) {
Expand Down Expand Up @@ -111,6 +107,15 @@ mesh_error_t ThreadInterface::mesh_connect()
}
}

void ThreadInterface::device_eui64_set(const uint8_t *eui64)
{
memcpy(_eui64, eui64, 8);
}

mesh_error_t ThreadInterface::device_pskd_set(const char *pskd)
{
return (mesh_error_t)thread_tasklet_device_pskd_set(pskd);
}

mesh_error_t ThreadInterface::mesh_disconnect()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,17 @@ void thread_tasklet_init(void);
int8_t thread_tasklet_network_init(int8_t device_id);

/*
* \brief Set device configuration for thread network
* \param eui64 mac address of the registered rf device
* \brief Sets eui64 for the device configuration
* \param eui64 eui64 to be set
* \param pskd private shared key
*/
void thread_tasklet_device_config_set(uint8_t *eui64, char *pskd);
void thread_tasklet_device_eui64_set(const uint8_t *eui64);

/*
* \brief Sets PSKd for the device configuration
* \param pskd private shared key to be set
*/
uint8_t thread_tasklet_device_pskd_set(const char *pskd);

/*
* \brief Disconnect network interface.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,11 @@ void thread_tasklet_configure_and_connect_to_network(void)

// PSKd
const char PSKd[] = MBED_CONF_MBED_MESH_API_THREAD_PSKD;
MBED_ASSERT(sizeof(PSKd) > 5 && sizeof(PSKd) < 33);
if(device_configuration.PSKd_len==0) {
int ret = thread_tasklet_device_pskd_set(PSKd);
MBED_ASSERT(!ret);
}

char *dyn_buf = ns_dyn_mem_alloc(sizeof(PSKd));
strcpy(dyn_buf, PSKd);
ns_dyn_mem_free(device_configuration.PSKd_ptr);
device_configuration.PSKd_ptr = (uint8_t*)dyn_buf;
device_configuration.PSKd_len = sizeof(PSKd) - 1;

if (true == MBED_CONF_MBED_MESH_API_THREAD_USE_STATIC_LINK_CONFIG) {
read_link_configuration();
temp_link_config = &thread_tasklet_data_ptr->link_config;
Expand Down Expand Up @@ -436,12 +433,29 @@ int8_t thread_tasklet_network_init(int8_t device_id)
return arm_nwk_interface_lowpan_init(api, INTERFACE_NAME);
}

void thread_tasklet_device_config_set(uint8_t *eui64, char *pskd)
void thread_tasklet_device_eui64_set(const uint8_t *eui64)
{
(void) pskd; // this parameter is delivered via mbed configuration
memcpy(device_configuration.eui64, eui64, 8);
}

uint8_t thread_tasklet_device_pskd_set(const char *pskd)
{
int len = strlen(pskd);
if(len < 6 || len > 32) {
return MESH_ERROR_PARAM;
}
char *dyn_buf = ns_dyn_mem_alloc(strlen(pskd)+1);
if (!dyn_buf) {
return MESH_ERROR_MEMORY;
}
strcpy(dyn_buf, pskd);
ns_dyn_mem_free(device_configuration.PSKd_ptr);
device_configuration.PSKd_ptr = (uint8_t*)dyn_buf;
device_configuration.PSKd_len = strlen(pskd);
return 0;
}


int8_t thread_tasklet_data_poll_rate_set(uint32_t timeout)
{
int8_t status = -1;
Expand Down