Merge pull request #11181 from artokin/mbed_wisun_api_update

mbed-mesh-api: Add new API for Wi-SUN configuration
pull/11369/head
Martin Kojtal 2019-08-28 13:50:13 +02:00 committed by GitHub
commit d6304e322c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 537 additions and 18 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016 ARM Limited. All rights reserved.
* Copyright (c) 2016-2019 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
@ -132,9 +132,19 @@ public:
*/
virtual nsapi_error_t set_blocking(bool blocking);
/** Set file system root path.
*
* Set file system root path that stack will use to write and read its data.
* Setting root_path to NULL will disable file system usage.
*
* @param root_path Address to NUL-terminated root-path string or NULL to disable file system usage.
* @return MESH_ERROR_NONE on success, MESH_ERROR_MEMORY in case of memory failure, MESH_ERROR_UNKNOWN in case of other error.
*/
virtual nsapi_error_t set_file_system_root_path(const char *root_path);
/** Get the interface ID
/return Interface identifier
*/
* @return Interface identifier
*/
int8_t get_interface_id() const
{
return _interface->get_interface_id();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 ARM Limited. All rights reserved.
* Copyright (c) 2018-2019 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
@ -37,6 +37,99 @@ public:
*/
WisunInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
/**
* \brief Set Wi-SUN network name.
*
* Function stores new network name to mbed-mesh-api and uses it when connect() is called next time.
* If device is already connected to the Wi-SUN network then device will restart network discovery after
* changing the network name.
*
* Function overwrites network name defined by Mbed OS configuration.
*
* \param network_name Network name as NUL terminated string. Can't exceed 32 characters and can't be NULL.
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_UNKNOWN in case of failure.
* */
mesh_error_t set_network_name(char *network_name);
/**
* \brief Set Wi-SUN network regulatory domain, operating class and operating mode.
*
* Function stores new parameters to mbed-mesh-api and uses them when connect() is called next time.
* If device is already connected to the Wi-SUN network then device will restart network discovery after
* changing the regulatory_domain, operating_class or operating_mode.
*
* Function overwrites parameters defined by Mbed OS configuration.
*
* \param regulatory_domain Values defined in Wi-SUN PHY-specification. Use 0xff to use leave parameter unchanged.
* \param operating_class Values defined in Wi-SUN PHY-specification. Use 0xff to use leave parameter unchanged.
* \param operating_mode Values defined in Wi-SUN PHY-specification. Use 0xff to use leave parameter unchanged.
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_UNKNOWN in case of failure.
* */
mesh_error_t set_network_regulatory_domain(uint8_t regulatory_domain = 0xff, uint8_t operating_class = 0xff, uint8_t operating_mode = 0xff);
/**
* \brief Set own certificate and private key reference to the Wi-SUN network.
*
* Function can be called several times if intermediate certificates are used. Then each call to the function
* adds a certificate reference to own certificate chain. Certificates are in bottom up order i.e. the top certificate is given last.
*
* Function must be called before connecting the device i.e before call to connect() method.
* Function will not copy certificate or key, therefore addresses must remain valid.
*
* \param cert Certificate address.
* \param cert_len Certificate length in bytes.
* \param cert_key Certificate key address.
* \param cert_key_len Certificate key length in bytes.
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_STATE if method is called after calling connect().
* \return MESH_ERROR_MEMORY in case of memory allocation failure.
* */
mesh_error_t set_own_certificate(uint8_t *cert, uint16_t cert_len, uint8_t *cert_key = NULL, uint16_t cert_key_len = 0);
/**
* \brief Remove own certificates from the Wi-SUN network.
*
* Function must be called before connecting the device i.e before call to connect() method.
*
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_STATE if method is called after calling connect().
* */
mesh_error_t remove_own_certificates(void);
/**
* \brief Set trusted certificate reference to the Wi-SUN network.
*
* Function can be called several times. Certificates are in bottom up order i.e. the top certificate is given last.
*
* Function must be called before connecting the device i.e before call to connect() method.
* Function will not copy certificate, therefore addresses must remain valid.
*
* \param cert Certificate address.
* \param cert_len Certificate length in bytes.
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_STATE if method is called after calling connect().
* \return MESH_ERROR_MEMORY in case of memory allocation failure.
* */
mesh_error_t set_trusted_certificate(uint8_t *cert, uint16_t cert_len);
/**
* \brief Remove trusted certificates from the Wi-SUN network.
*
* Function must be called before connecting the device i.e before call to connect() method.
*
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_STATE if method is called after calling connect().
* */
mesh_error_t remove_trusted_certificates(void);
/**
* \brief Get router IP address
*
* \param address
* \param len
* */
bool getRouterIpAddress(char *address, int8_t len);
protected:
Nanostack::WisunInterface *get_interface() const;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016 ARM Limited. All rights reserved.
* Copyright (c) 2016-2019 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
@ -217,6 +217,19 @@ nsapi_error_t InterfaceNanostack::set_blocking(bool blocking)
return NSAPI_ERROR_OK;
}
nsapi_error_t InterfaceNanostack::set_file_system_root_path(const char *root_path)
{
int status = mesh_system_set_file_system_root_path(root_path);
if (status == 0) {
return MESH_ERROR_NONE;
} else if (status == -2) {
return MESH_ERROR_MEMORY;
}
return MESH_ERROR_UNKNOWN;
}
#if !DEVICE_802_15_4_PHY
MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance()
{

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 ARM Limited. All rights reserved.
* Copyright (c) 2018-2019 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
@ -171,6 +171,82 @@ bool WisunInterface::getRouterIpAddress(char *address, int8_t len)
return _interface->get_gateway(address, len);
}
mesh_error_t WisunInterface::set_network_name(char *network_name)
{
mesh_error_t ret_val = MESH_ERROR_NONE;
int status = wisun_tasklet_set_network_name(get_interface_id(), network_name);
if (status != 0) {
ret_val = MESH_ERROR_UNKNOWN;
}
return ret_val;
}
mesh_error_t WisunInterface::set_network_regulatory_domain(uint8_t regulatory_domain, uint8_t operating_class, uint8_t operating_mode)
{
mesh_error_t ret_val = MESH_ERROR_NONE;
int status = wisun_tasklet_set_regulatory_domain(get_interface_id(), regulatory_domain, operating_class, operating_mode);
if (status != 0) {
ret_val = MESH_ERROR_UNKNOWN;
}
return ret_val;
}
mesh_error_t WisunInterface::set_own_certificate(uint8_t *cert, uint16_t cert_len, uint8_t *cert_key, uint16_t cert_key_len)
{
mesh_error_t ret_val = MESH_ERROR_NONE;
int status = wisun_tasklet_set_own_certificate(cert, cert_len, cert_key, cert_key_len);
if (status == -1) {
ret_val = MESH_ERROR_MEMORY;
} else if (status == -2) {
ret_val = MESH_ERROR_STATE;
}
return ret_val;
}
mesh_error_t WisunInterface::remove_own_certificates(void)
{
mesh_error_t ret_val = MESH_ERROR_NONE;
int status = wisun_tasklet_remove_own_certificates();
if (status == -1) {
ret_val = MESH_ERROR_MEMORY;
} else if (status == -2) {
ret_val = MESH_ERROR_STATE;
}
return ret_val;
}
mesh_error_t WisunInterface::set_trusted_certificate(uint8_t *cert, uint16_t cert_len)
{
mesh_error_t ret_val = MESH_ERROR_NONE;
int status = wisun_tasklet_set_trusted_certificate(cert, cert_len);
if (status == -1) {
ret_val = MESH_ERROR_MEMORY;
} else if (status == -2) {
ret_val = MESH_ERROR_STATE;
}
return ret_val;
}
mesh_error_t WisunInterface::remove_trusted_certificates(void)
{
mesh_error_t ret_val = MESH_ERROR_NONE;
int status = wisun_tasklet_remove_trusted_certificates();
if (status == -1) {
ret_val = MESH_ERROR_MEMORY;
} else if (status == -2) {
ret_val = MESH_ERROR_STATE;
}
return ret_val;
}
#define WISUN 0x2345
#if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == WISUN && DEVICE_802_15_4_PHY
MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance()

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All rights reserved.
* Copyright (c) 2015-2019 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
@ -38,6 +38,8 @@ enum {
*/
void mesh_system_send_connect_event(uint8_t receiver);
int mesh_system_set_file_system_root_path(const char *root_path);
/*
* \brief Initialize mesh system.
* Memory pool, timers, traces and support are initialized.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 ARM Limited
* Copyright (c) 2018-2019 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -64,6 +64,9 @@ void wisun_tasklet_init(void);
*
* \param device_id registered physical device
* \return interface ID that can be used to communication with this interface
* \return -1 in case of MAC initialization fails
* \return -2 in case of error in parameters
* \return -3 in case of memory allocation error
*/
int8_t wisun_tasklet_network_init(int8_t device_id);
@ -76,6 +79,66 @@ int8_t wisun_tasklet_network_init(int8_t device_id);
*/
int8_t wisun_tasklet_disconnect(bool send_cb);
/*
* \brief Set Wi-SUN network name
*
* \param nwk_interface_id to use for networking
* \param network_name_ptr Address of the new network name. Can't be NULL.
* \return 0 if network name stored successfully
* \return < 0 in case of errors
*/
int wisun_tasklet_set_network_name(int8_t nwk_interface_id, char *network_name_ptr);
/*
* \brief Set Wi-SUN network regulatory domain
*
* \param nwk_interface_id to use for networking
* \param regulatory_domain
* \param operating_class
* \param operating_mode
* \return 0 if regulatory domain is set successfully.
* \return < 0 in case of errors
*/
int wisun_tasklet_set_regulatory_domain(int8_t nwk_interface_id, uint8_t regulatory_domain, uint8_t operating_class, uint8_t operating_mode);
/*
* \brief Set own certificate to Wi-SUN network
*
* \param cert to use for networking
* \param cert_len
* \param cert_key
* \param cert_key_len
* \return 0 if certificate stored successfully
* \return < 0 in case of errors
*/
int wisun_tasklet_set_own_certificate(uint8_t *cert, uint16_t cert_len, uint8_t *cert_key, uint16_t cert_key_len);
/*
* \brief Remove own certificate from Wi-SUN network
*
* \return 0 if certificates removed successfully
* \return < 0 in case of errors
*/
int wisun_tasklet_remove_own_certificates(void);
/*
* \brief Set trusted certificate to Wi-SUN network
*
* \param cert to use for networking
* \param cert_len
* \return 0 if certificate stored successfully
* \return < 0 in case of errors
*/
int wisun_tasklet_set_trusted_certificate(uint8_t *cert, uint16_t cert_len);
/*
* \brief Remove trusted certificate from Wi-SUN network
*
* \return 0 if certificates removed successfully
* \return < 0 in case of errors
*/
int wisun_tasklet_remove_trusted_certificates(void);
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All rights reserved.
* Copyright (c) 2015-2019 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
@ -25,6 +25,7 @@
#include "include/mesh_system.h"
#include "mbed_assert.h"
#include "mbed_error.h"
#include "ns_file_system.h"
// For tracing we need to define flag, have include and define group
#define HAVE_DEBUG 1
#include "ns_trace.h"
@ -77,3 +78,8 @@ void mesh_system_send_connect_event(uint8_t receiver)
};
eventOS_event_send(&event);
}
int mesh_system_set_file_system_root_path(const char *root_path)
{
return ns_file_system_set_root_path(root_path);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 ARM Limited. All rights reserved.
* Copyright (c) 2018-2019 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
@ -27,6 +27,8 @@
#include "multicast_api.h"
#include "mac_api.h"
#include "sw_mac.h"
#include "ns_list.h"
#include "net_interface.h"
#include "ws_management_api.h" //ws_management_node_init
#ifdef MBED_CONF_MBED_MESH_API_CERTIFICATE_HEADER
#if !defined(MBED_CONF_MBED_MESH_API_ROOT_CERTIFICATE) || !defined(MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE) || \
@ -68,11 +70,34 @@ typedef struct {
int8_t network_interface_id;
} wisun_tasklet_data_str_t;
typedef struct {
char *network_name;
uint8_t regulatory_domain;
uint8_t rd_operating_class;
uint8_t rd_operating_mode;
} wisun_network_settings_t;
typedef struct {
arm_certificate_entry_s arm_cert_entry;
ns_list_link_t link; /*!< List link entry */
} wisun_certificate_entry_t;
typedef NS_LIST_HEAD(wisun_certificate_entry_t, link) cert_list_t;
typedef struct {
cert_list_t own_certificates_list;
cert_list_t trusted_certificates_list;
bool remove_own_certificates: 1;
bool remove_trusted_certificates: 1;
} wisun_certificates_t;
#define WS_NA 0xff // Not applicable value
/* Tasklet data */
static wisun_tasklet_data_str_t *wisun_tasklet_data_ptr = NULL;
static wisun_certificates_t *wisun_certificates_ptr = NULL;
static wisun_network_settings_t wisun_settings_str = {NULL, WS_NA, WS_NA, WS_NA};
static mac_api_t *mac_api = NULL;
static char *network_name = MBED_CONF_MBED_MESH_API_WISUN_NETWORK_NAME;
extern fhss_timer_t fhss_functions;
/* private function prototypes */
@ -80,6 +105,9 @@ static void wisun_tasklet_main(arm_event_s *event);
static void wisun_tasklet_network_state_changed(mesh_connection_status_t status);
static void wisun_tasklet_parse_network_event(arm_event_s *event);
static void wisun_tasklet_configure_and_connect_to_network(void);
static void wisun_tasklet_clear_stored_certificates(void) ;
static int wisun_tasklet_store_certificate_data(const uint8_t *cert, uint16_t cert_len, const uint8_t *cert_key, uint16_t cert_key_len, bool remove_own, bool remove_trusted, bool trusted_cert);
static int wisun_tasklet_add_stored_certificates(void) ;
/*
* \brief A function which will be eventually called by NanoStack OS when ever the OS has an event to deliver.
@ -201,7 +229,7 @@ static void wisun_tasklet_parse_network_event(arm_event_s *event)
*/
static void wisun_tasklet_configure_and_connect_to_network(void)
{
int8_t status;
int status;
fhss_timer_t *fhss_timer_ptr = &fhss_functions;
wisun_tasklet_data_ptr->operating_mode = NET_6LOWPAN_ROUTER;
@ -212,10 +240,33 @@ static void wisun_tasklet_configure_and_connect_to_network(void)
wisun_tasklet_data_ptr->operating_mode,
wisun_tasklet_data_ptr->operating_mode_extension);
ws_management_node_init(wisun_tasklet_data_ptr->network_interface_id,
MBED_CONF_MBED_MESH_API_WISUN_REGULATORY_DOMAIN,
network_name,
fhss_timer_ptr);
if (wisun_tasklet_add_stored_certificates() != 0) {
tr_error("Can't set Wi-SUN certificates");
return;
}
status = ws_management_node_init(wisun_tasklet_data_ptr->network_interface_id,
MBED_CONF_MBED_MESH_API_WISUN_REGULATORY_DOMAIN,
wisun_settings_str.network_name,
fhss_timer_ptr);
if (status < 0) {
tr_error("Failed to initialize WS");
return;
}
if (wisun_settings_str.regulatory_domain != WS_NA ||
wisun_settings_str.rd_operating_class != WS_NA ||
wisun_settings_str.rd_operating_mode != WS_NA) {
status = ws_management_regulatory_domain_set(wisun_tasklet_data_ptr->network_interface_id,
wisun_settings_str.regulatory_domain,
wisun_settings_str.rd_operating_class,
wisun_settings_str.rd_operating_mode);
if (status < 0) {
tr_error("Failed to set regulatory domain!");
return;
}
}
#if defined(MBED_CONF_MBED_MESH_API_CERTIFICATE_HEADER)
arm_certificate_chain_entry_s chain_info;
@ -251,6 +302,118 @@ static void wisun_tasklet_network_state_changed(mesh_connection_status_t status)
}
}
static int wisun_tasklet_store_certificate_data(const uint8_t *cert, uint16_t cert_len, const uint8_t *cert_key, uint16_t cert_key_len, bool remove_own, bool remove_trusted, bool trusted_cert)
{
if (wisun_certificates_ptr == NULL) {
wisun_certificates_ptr = (wisun_certificates_t *)ns_dyn_mem_alloc(sizeof(wisun_certificates_t));
if (!wisun_certificates_ptr) {
return -1;
}
ns_list_init(&wisun_certificates_ptr->own_certificates_list);
ns_list_init(&wisun_certificates_ptr->trusted_certificates_list);
wisun_certificates_ptr->remove_own_certificates = false;
wisun_certificates_ptr->remove_trusted_certificates = false;
}
if (remove_own) {
wisun_certificates_ptr->remove_own_certificates = true;
return 0;
}
if (remove_trusted) {
wisun_certificates_ptr->remove_trusted_certificates = true;
return 0;
}
wisun_certificate_entry_t *ws_cert_entry_store = (wisun_certificate_entry_t *)ns_dyn_mem_alloc(sizeof(wisun_certificate_entry_t));
if (!ws_cert_entry_store) {
wisun_tasklet_clear_stored_certificates();
return -1;
}
ws_cert_entry_store->arm_cert_entry.cert = cert;
ws_cert_entry_store->arm_cert_entry.cert_len = cert_len;
if (cert_key) {
ws_cert_entry_store->arm_cert_entry.key = cert_key;
ws_cert_entry_store->arm_cert_entry.key_len = cert_key_len;
} else {
ws_cert_entry_store->arm_cert_entry.key = NULL;
ws_cert_entry_store->arm_cert_entry.key_len = 0;
}
if (trusted_cert) {
ns_list_add_to_end(&wisun_certificates_ptr->trusted_certificates_list, ws_cert_entry_store);
} else {
ns_list_add_to_end(&wisun_certificates_ptr->own_certificates_list, ws_cert_entry_store);
}
return 0;
}
static void wisun_tasklet_clear_stored_certificates(void)
{
if (!wisun_certificates_ptr) {
return;
}
ns_list_foreach_safe(wisun_certificate_entry_t, trusted_cert_entry, &wisun_certificates_ptr->trusted_certificates_list) {
ns_list_remove(&wisun_certificates_ptr->trusted_certificates_list, trusted_cert_entry);
ns_dyn_mem_free(trusted_cert_entry);
}
ns_list_foreach_safe(wisun_certificate_entry_t, own_cert_entry, &wisun_certificates_ptr->own_certificates_list) {
ns_list_remove(&wisun_certificates_ptr->own_certificates_list, own_cert_entry);
ns_dyn_mem_free(own_cert_entry);
}
ns_dyn_mem_free(wisun_certificates_ptr);
wisun_certificates_ptr = NULL;
}
static int wisun_tasklet_add_stored_certificates(void)
{
int8_t status = 0;
if (wisun_certificates_ptr == NULL) {
// certificates not updated
return 0;
}
if (wisun_certificates_ptr->remove_own_certificates) {
status = arm_network_own_certificates_remove();
if (status != 0) {
goto CERTIFICATE_SET_END;
}
}
if (wisun_certificates_ptr->remove_trusted_certificates) {
status = arm_network_trusted_certificates_remove();
if (status != 0) {
goto CERTIFICATE_SET_END;
}
}
ns_list_foreach(wisun_certificate_entry_t, cert_entry, &wisun_certificates_ptr->trusted_certificates_list) {
status = arm_network_trusted_certificate_add(&cert_entry->arm_cert_entry);
if (status != 0) {
goto CERTIFICATE_SET_END;
}
}
ns_list_foreach(wisun_certificate_entry_t, cert_entry, &wisun_certificates_ptr->own_certificates_list) {
status = arm_network_own_certificate_add(&cert_entry->arm_cert_entry);
if (status != 0) {
goto CERTIFICATE_SET_END;
}
}
CERTIFICATE_SET_END:
wisun_tasklet_clear_stored_certificates();
return status;
}
/* Public functions */
int8_t wisun_tasklet_get_router_ip_address(char *address, int8_t len)
{
@ -267,7 +430,7 @@ int8_t wisun_tasklet_get_router_ip_address(char *address, int8_t len)
int8_t wisun_tasklet_connect(mesh_interface_cb callback, int8_t nwk_interface_id)
{
int8_t re_connecting = true;
bool re_connecting = true;
int8_t tasklet_id = wisun_tasklet_data_ptr->tasklet;
if (wisun_tasklet_data_ptr->network_interface_id != INVALID_INTERFACE_ID) {
@ -318,7 +481,8 @@ int8_t wisun_tasklet_disconnect(bool send_cb)
void wisun_tasklet_init(void)
{
if (wisun_tasklet_data_ptr == NULL) {
wisun_tasklet_data_ptr = ns_dyn_mem_alloc(sizeof(wisun_tasklet_data_str_t));
wisun_tasklet_data_ptr = (wisun_tasklet_data_str_t *)ns_dyn_mem_alloc(sizeof(wisun_tasklet_data_str_t));
// allocation not validated, in case of failure execution stops here
memset(wisun_tasklet_data_ptr, 0, sizeof(wisun_tasklet_data_str_t));
wisun_tasklet_data_ptr->tasklet_state = TASKLET_STATE_CREATED;
wisun_tasklet_data_ptr->network_interface_id = INVALID_INTERFACE_ID;
@ -336,5 +500,97 @@ int8_t wisun_tasklet_network_init(int8_t device_id)
if (!mac_api) {
mac_api = ns_sw_mac_create(device_id, &storage_sizes);
}
if (!wisun_settings_str.network_name) {
// No network name set by API, use network name from configuration
int wisun_network_name_len = sizeof(MBED_CONF_MBED_MESH_API_WISUN_NETWORK_NAME);
wisun_settings_str.network_name = (char *)ns_dyn_mem_alloc(wisun_network_name_len);
if (!wisun_settings_str.network_name) {
return -3;
}
strncpy(wisun_settings_str.network_name, MBED_CONF_MBED_MESH_API_WISUN_NETWORK_NAME, wisun_network_name_len);
}
return arm_nwk_interface_lowpan_init(mac_api, INTERFACE_NAME);
}
int wisun_tasklet_set_network_name(int8_t nwk_interface_id, char *network_name_ptr)
{
if (!network_name_ptr || strlen(network_name_ptr) > 32) {
return -1;
}
// save the network name to have support for disconnect/connect
ns_dyn_mem_free(wisun_settings_str.network_name);
wisun_settings_str.network_name = (char *)ns_dyn_mem_alloc(strlen(network_name_ptr) + 1);
if (!wisun_settings_str.network_name) {
return -2;
}
strcpy(wisun_settings_str.network_name, network_name_ptr);
if (wisun_tasklet_data_ptr && wisun_tasklet_data_ptr->tasklet_state == TASKLET_STATE_BOOTSTRAP_READY) {
// interface is up, try to change name dynamically
return ws_management_network_name_set(nwk_interface_id, wisun_settings_str.network_name);
}
return 0;
}
int wisun_tasklet_set_regulatory_domain(int8_t nwk_interface_id, uint8_t regulatory_domain, uint8_t operating_class, uint8_t operating_mode)
{
int status = 0;
wisun_settings_str.regulatory_domain = regulatory_domain;
wisun_settings_str.rd_operating_class = operating_class;
wisun_settings_str.rd_operating_mode = operating_mode;
if (wisun_tasklet_data_ptr && wisun_tasklet_data_ptr->tasklet_state == TASKLET_STATE_BOOTSTRAP_READY) {
status = ws_management_regulatory_domain_set(nwk_interface_id, regulatory_domain, operating_class, operating_mode);
}
return status;
}
int wisun_tasklet_set_own_certificate(uint8_t *cert, uint16_t cert_len, uint8_t *cert_key, uint16_t cert_key_len)
{
if (wisun_tasklet_data_ptr) {
// this API can be only used before first connect()
tr_err("Already connected");
return -2;
}
return wisun_tasklet_store_certificate_data(cert, cert_len, cert_key, cert_key_len, false, false, false);
}
int wisun_tasklet_remove_own_certificates(void)
{
if (wisun_tasklet_data_ptr) {
// this API can be only used before first connect()
tr_err("Already connected");
return -2;
}
return wisun_tasklet_store_certificate_data(NULL, 0, NULL, 0, true, false, false);
}
int wisun_tasklet_remove_trusted_certificates(void)
{
if (wisun_tasklet_data_ptr) {
// this API can be only used before first connect()
tr_err("Already connected");
return -2;
}
return wisun_tasklet_store_certificate_data(NULL, 0, NULL, 0, false, true, false);
}
int wisun_tasklet_set_trusted_certificate(uint8_t *cert, uint16_t cert_len)
{
if (wisun_tasklet_data_ptr) {
// this API can be only used before first connect()
tr_err("Already connected");
return -2;
}
return wisun_tasklet_store_certificate_data(cert, cert_len, NULL, 0, false, false, true);
}