mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #12898 from mikaleppanen/new_wisun_conf_param_
Add new configuration parameters to Wi-SUN network interface and Border Router classpull/12899/head
commit
ff024d2fa7
|
@ -76,6 +76,8 @@ protected:
|
|||
};
|
||||
|
||||
class Nanostack::MeshInterface : public Nanostack::Interface {
|
||||
public:
|
||||
char *get_interface_name(char *buf);
|
||||
protected:
|
||||
MeshInterface(NanostackRfPhy &phy) : Interface(phy) { }
|
||||
NanostackRfPhy &get_phy() const
|
||||
|
@ -163,6 +165,7 @@ protected:
|
|||
char mac_addr_str[24] {};
|
||||
mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
|
||||
bool _blocking = true;
|
||||
bool _configured = false;
|
||||
};
|
||||
|
||||
class MeshInterfaceNanostack : public InterfaceNanostack, public MeshInterface, private mbed::NonCopyable<MeshInterfaceNanostack> {
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
bool blocking = true) override;
|
||||
nsapi_error_t bringdown() override;
|
||||
|
||||
char *get_interface_name(char *buf);
|
||||
private:
|
||||
friend class Nanostack;
|
||||
friend class NanostackEthernetInterface;
|
||||
|
|
|
@ -32,6 +32,7 @@ public:
|
|||
typedef mbed::Callback<void (uint8_t up, int8_t device_id)> link_state_cb_t;
|
||||
void set_link_state_changed_callback(link_state_cb_t link_state_cb);
|
||||
|
||||
char *get_interface_name(char *buf);
|
||||
private:
|
||||
friend class Nanostack;
|
||||
PPPInterface(NanostackPPPPhy &phy) : Interface(phy) {}
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef WISUNBORDERROUTER_H
|
||||
#define WISUNBORDERROUTER_H
|
||||
|
||||
/** Wi-SUN Border Router class
|
||||
*
|
||||
* Class can be used to start, stop and configure Wi-SUN Border Router.
|
||||
*/
|
||||
class WisunBorderRouter {
|
||||
public:
|
||||
|
||||
/** Create WisunBorderRouter
|
||||
*
|
||||
* */
|
||||
WisunBorderRouter() { }
|
||||
|
||||
/**
|
||||
* \brief Start Wi-SUN Border Router
|
||||
*
|
||||
* Starts Wi-SUN Border Router and routing between the mesh and backbone interfaces. Network interfaces
|
||||
* must be initialized and connected before calling the start. Backbone interface can be either Ethernet
|
||||
* (EMAC) or Cellular.
|
||||
*
|
||||
* \param mesh_if Wi-SUN mesh network interface
|
||||
* \param backbone_if Backbone network interface
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t start(NetworkInterface *mesh_if, NetworkInterface *backbone_if);
|
||||
|
||||
/**
|
||||
* \brief Start Wi-SUN Border Router
|
||||
*
|
||||
* Starts Wi-SUN Border Router and routing between the mesh and backbone interfaces. Mesh network interface
|
||||
* must be initialized and connected before calling the start. Backbone OnboardNetworkStack::Interface must
|
||||
* be brought up before calling the start. Backbone interface can be either Ethernet (EMAC) or Cellular (PPP).
|
||||
*
|
||||
* \param mesh_if Wi-SUN mesh network interface
|
||||
* \param backbone_if Backbone OnboardNetworkStack::Interface interface
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t start(NetworkInterface *mesh_if, OnboardNetworkStack::Interface *backbone_if);
|
||||
|
||||
/**
|
||||
* \brief Stop Wi-SUN Border Router
|
||||
*
|
||||
* Stops Wi-SUN Border Router.
|
||||
*
|
||||
* */
|
||||
void stop();
|
||||
|
||||
/**
|
||||
* \brief Set Wi-SUN RPL DIO trickle parameters.
|
||||
*
|
||||
* Function stores new parameters to Border Router and uses them when mesh interface connect() is called
|
||||
* next time. If device is already connected to the Wi-SUN network then device will restart Wi-SUN network after
|
||||
* changing the RPL DIO trickle parameters. Mesh interface must be initialized before calling this
|
||||
* function.
|
||||
*
|
||||
* \param dio_interval_min DIO trickle timer Imin parameter. Use 0x00 to use leave parameter unchanged.
|
||||
* \param dio_interval_doublings DIO trickle timer Imax parameter as doublings of Imin. Use 0x00 to use leave parameter unchanged.
|
||||
* \param dio_redundancy_constant DIO trickle timer redundancy constant. 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_rpl_parameters(uint8_t dio_interval_min, uint8_t dio_interval_doublings, uint8_t dio_redundancy_constant);
|
||||
|
||||
/**
|
||||
* \brief Get Wi-SUN RPL DIO trickle parameters.
|
||||
*
|
||||
* Function reads DIO trickle timer Imin, DIO trickle timer Imax and DIO trickle timer redundancy
|
||||
* constant from Border Router. Mesh interface must be initialized before calling this function.
|
||||
*
|
||||
* \param dio_interval_min DIO trickle timer Imin parameter.
|
||||
* \param dio_interval_doublings DIO trickle timer Imax parameter as doublings of Imin.
|
||||
* \param dio_redundancy_constant DIO trickle timer redundancy constant.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t get_rpl_parameters(uint8_t *dio_interval_min, uint8_t *dio_interval_doublings, uint8_t *dio_redundancy_constant);
|
||||
|
||||
/**
|
||||
* \brief Validate Wi-SUN RPL DIO trickle parameters.
|
||||
*
|
||||
* Function validates DIO trickle timer Imin, DIO trickle timer Imax and DIO trickle timer redundancy
|
||||
* constant. Function can be used to test that values that will be used on set function are valid.
|
||||
* Mesh interface must be initialized before the calling this function.
|
||||
*
|
||||
* \param dio_interval_min DIO trickle timer Imin parameter.
|
||||
* \param dio_interval_doublings DIO trickle timer Imax parameter as doublings of Imin.
|
||||
* \param dio_redundancy_constant DIO trickle timer redundancy constant.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t validate_rpl_parameters(uint8_t dio_interval_min, uint8_t dio_interval_doublings, uint8_t dio_redundancy_constant);
|
||||
|
||||
/**
|
||||
* \brief Set Wi-SUN PAN configuration parameters.
|
||||
*
|
||||
* Function stores new parameters to Border Router and uses them when mesh interface connect() is called
|
||||
* next time. If device is already connected to the Wi-SUN network then device will restart Wi-SUN network after
|
||||
* changing the PAN configuration parameters. Mesh interface must be initialized before calling this
|
||||
* function.
|
||||
*
|
||||
* \param pan_id PAN ID. 0xffff will generate the PAN ID on the mesh interface connect() call if not already generated.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t set_pan_configuration(uint16_t pan_id);
|
||||
|
||||
/**
|
||||
* \brief Get Wi-SUN PAN configuration parameters.
|
||||
*
|
||||
* Function reads PAN ID from Border Router. Mesh interface must be initialized before calling this function.
|
||||
*
|
||||
* \param pan_id PAN ID.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t get_pan_configuration(uint16_t *pan_id);
|
||||
|
||||
/**
|
||||
* \brief Validate Wi-SUN PAN configuration parameters.
|
||||
*
|
||||
* Function validates PAN ID. Function can be used to test that values that will be used on set function are valid.
|
||||
* Mesh interface must be initialized before calling this function.
|
||||
*
|
||||
* \param pan_id PAN ID.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t validate_pan_configuration(uint16_t pan_id);
|
||||
|
||||
private:
|
||||
int8_t _mesh_if_id = -1;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
|
@ -43,6 +43,28 @@ public:
|
|||
* */
|
||||
mesh_error_t set_network_name(char *network_name);
|
||||
|
||||
/**
|
||||
* \brief Get Wi-SUN network name.
|
||||
*
|
||||
* Function reads network name from mbed-mesh-api.
|
||||
*
|
||||
* \param network_name Network name as NUL terminated string. Must have space for 33 characters (string and null terminator).
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t get_network_name(char *network_name);
|
||||
|
||||
/**
|
||||
* \brief Validate Wi-SUN network name.
|
||||
*
|
||||
* Function validates network name. Function can be used to test that values that will be used on set function are valid.
|
||||
*
|
||||
* \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 validate_network_name(char *network_name);
|
||||
|
||||
/**
|
||||
* \brief Set Wi-SUN network regulatory domain, operating class and operating mode.
|
||||
*
|
||||
|
@ -60,6 +82,252 @@ public:
|
|||
* */
|
||||
mesh_error_t set_network_regulatory_domain(uint8_t regulatory_domain = 0xff, uint8_t operating_class = 0xff, uint8_t operating_mode = 0xff);
|
||||
|
||||
/**
|
||||
* \brief Get Wi-SUN network regulatory domain, operating class and operating mode.
|
||||
*
|
||||
* Function reads regulatory_domain, operating_class and operating_mode from mbed-mesh-api.
|
||||
*
|
||||
* \param regulatory_domain Values defined in Wi-SUN PHY-specification.
|
||||
* \param operating_class Values defined in Wi-SUN PHY-specification.
|
||||
* \param operating_mode Values defined in Wi-SUN PHY-specification.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t get_network_regulatory_domain(uint8_t *regulatory_domain, uint8_t *operating_class, uint8_t *operating_mode);
|
||||
|
||||
/**
|
||||
* \brief Validate Wi-SUN network regulatory domain, operating class and operating mode.
|
||||
*
|
||||
* Function validates regulatory_domain, operating_class and operating_mode. Function can be used to test that values that will
|
||||
* be used on set function are valid.
|
||||
*
|
||||
* \param regulatory_domain Values defined in Wi-SUN PHY-specification.
|
||||
* \param operating_class Values defined in Wi-SUN PHY-specification.
|
||||
* \param operating_mode Values defined in Wi-SUN PHY-specification.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t validate_network_regulatory_domain(uint8_t regulatory_domain, uint8_t operating_class, uint8_t operating_mode);
|
||||
|
||||
/**
|
||||
* \brief Set Wi-SUN network size.
|
||||
*
|
||||
* 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 network size.
|
||||
*
|
||||
* Default value: medium
|
||||
* Small network size: less than hundred devices
|
||||
* Medium network size: hundreds of devices
|
||||
* Large network size: thousands of devices
|
||||
* Certificate: used on testing
|
||||
*
|
||||
* When network size is changed, it will override all or some of the following configuration values:
|
||||
* - Timing settings set by set_timing_parameters() of the Wi-SUN interface.
|
||||
* - RPL settings set by rpl_parameters_set() of the Border Router interface.
|
||||
*
|
||||
* When network size is changed, and if timing or RPL values should be other than defaults set by stack for the network size,
|
||||
* they need to set again using above function calls.
|
||||
*
|
||||
* \param network_size Network size in hundreds of devices (e.g. 1200 devices is 12), 0x00 for network size certificate.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t set_network_size(uint8_t network_size);
|
||||
|
||||
/**
|
||||
* \brief Get Wi-SUN network size.
|
||||
*
|
||||
* Function reads network size from mbed-mesh-api.
|
||||
*
|
||||
* \param network_size Network size in hundreds of devices, 0x00 for network size certificate.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t get_network_size(uint8_t *network_size);
|
||||
|
||||
/**
|
||||
* \brief Validate Wi-SUN network size.
|
||||
*
|
||||
* Function validates network size from mbed-mesh-api. Function can be used to test that values that will
|
||||
* be used on set function are valid.
|
||||
*
|
||||
* \param network_size Network size in hundreds of devices, 0x00 for network size certificate.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t validate_network_size(uint8_t network_size);
|
||||
|
||||
/**
|
||||
* \brief Set Wi-SUN FHSS channel mask
|
||||
*
|
||||
* 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 settings take effect right away.
|
||||
*
|
||||
* \param channel_mask Values defined in Wi-SUN management API. Channel mask bit field.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t set_channel_mask(uint32_t channel_mask[8]);
|
||||
|
||||
/**
|
||||
* \brief Get Wi-SUN FHSS channel mask
|
||||
*
|
||||
* Function reads FHSS channel mask from mbed-mesh-api.
|
||||
*
|
||||
* \param channel_mask Values defined in Wi-SUN management API. Channel mask bit field.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t get_channel_mask(uint32_t *channel_mask);
|
||||
|
||||
/**
|
||||
* \brief Validate Wi-SUN FHSS channel mask
|
||||
*
|
||||
* Function validates FHSS channel mask. Function can be used to test that values that will
|
||||
* be used on set function are valid.
|
||||
*
|
||||
* \param channel_mask Values defined in Wi-SUN management API. Channel mask bit field.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t validate_channel_mask(uint32_t channel_mask[8]);
|
||||
|
||||
/**
|
||||
* \brief Set Wi-SUN FHSS unicast channel function parameters
|
||||
*
|
||||
* 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 channel function, fixed channel or dwell interval.
|
||||
*
|
||||
* Function overwrites parameters defined by Mbed OS configuration.
|
||||
*
|
||||
* \param channel_function Channel function. Fixed, TR51CF, DH1CF or vendor defined.
|
||||
* \param fixed_channel Used channel when channel function is fixed channel. Use 0xffff when fixed channel function not on use.
|
||||
* \param dwell_interval Used dwell interval when channel function is TR51 or DH1. Use 0x00 to use leave parameter unchanged.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t set_unicast_channel_function(mesh_channel_function_t channel_function, uint16_t fixed_channel = 0xffff, uint8_t dwell_interval = 0x00);
|
||||
|
||||
/**
|
||||
* \brief Get Wi-SUN FHSS unicast channel function parameters
|
||||
*
|
||||
* Function reads FHSS unicast channel function parameters from mbed-mesh-api.
|
||||
*
|
||||
* \param channel_function Channel function. Fixed, TR51CF, DH1CF or vendor defined.
|
||||
* \param fixed_channel Used channel when channel function is fixed channel.
|
||||
* \param dwell_interval Used dwell interval when channel function is TR51 or DH1.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t get_unicast_channel_function(mesh_channel_function_t *channel_function, uint16_t *fixed_channel, uint8_t *dwell_interval);
|
||||
|
||||
/**
|
||||
* \brief Validate Wi-SUN FHSS unicast channel function parameters
|
||||
*
|
||||
* Function validates FHSS unicast channel function parameters. Function can be used to test that values that will
|
||||
* be used on set function are valid.
|
||||
*
|
||||
* \param channel_function Channel function. Fixed, TR51CF, DH1CF or vendor defined.
|
||||
* \param fixed_channel Used channel when channel function is fixed channel.
|
||||
* \param dwell_interval Used dwell interval when channel function is TR51 or DH1.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t validate_unicast_channel_function(mesh_channel_function_t channel_function, uint16_t fixed_channel, uint8_t dwell_interval);
|
||||
|
||||
/**
|
||||
* \brief Set Wi-SUN FHSS broadcast channel function parameters
|
||||
*
|
||||
* 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 channel function, fixed channel, dwell interval or broadcast_interval.
|
||||
*
|
||||
* Function overwrites parameters defined by Mbed OS configuration.
|
||||
*
|
||||
* \param channel_function Channel function. Fixed, TR51CF, DH1CF or vendor defined.
|
||||
* \param fixed_channel Used channel when channel function is fixed channel. Use 0xffff when fixed channel function not on use.
|
||||
* \param dwell_interval Used dwell interval when channel function is TR51 or DH1. Use 0x00 to use leave parameter unchanged.
|
||||
* \param broadcast_interval Used broadcast interval. Use 0x00 to use leave parameter unchanged.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t set_broadcast_channel_function(mesh_channel_function_t channel_function, uint16_t fixed_channel = 0xffff, uint8_t dwell_interval = 0x00, uint32_t broadcast_interval = 0x00);
|
||||
|
||||
/**
|
||||
* \brief Get Wi-SUN FHSS broadcast channel function parameters
|
||||
*
|
||||
* Function reads FHSS broadcast channel function parameters from mbed-mesh-api.
|
||||
*
|
||||
* \param channel_function Channel function. Fixed, TR51CF, DH1CF or vendor defined.
|
||||
* \param fixed_channel Used channel when channel function is fixed channel.
|
||||
* \param dwell_interval Used dwell interval when channel function is TR51 or DH1.
|
||||
* \param broadcast_interval Used broadcast interval.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t get_broadcast_channel_function(mesh_channel_function_t *channel_function, uint16_t *fixed_channel, uint8_t *dwell_interval, uint32_t *broadcast_interval);
|
||||
|
||||
/**
|
||||
* \brief Validate Wi-SUN FHSS broadcast channel function parameters
|
||||
*
|
||||
* Function validates FHSS broadcast channel function parameters from mbed-mesh-api. Function can be used to test that values that will
|
||||
* be used on set function are valid.
|
||||
*
|
||||
* \param channel_function Channel function. Fixed, TR51CF, DH1CF or vendor defined.
|
||||
* \param fixed_channel Used channel when channel function is fixed channel.
|
||||
* \param dwell_interval Used dwell interval when channel function is TR51 or DH1.
|
||||
* \param broadcast_interval Used broadcast interval.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t validate_broadcast_channel_function(mesh_channel_function_t channel_function, uint16_t fixed_channel, uint8_t dwell_interval, uint32_t broadcast_interval);
|
||||
|
||||
/**
|
||||
* \brief Set Wi-SUN timing parameters
|
||||
*
|
||||
* 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 settings take effect right away.
|
||||
*
|
||||
* \param disc_trickle_imin Discovery trickle Imin. Range 1-255 seconds. Use 0x00 to use leave parameter unchanged.
|
||||
* \param disc_trickle_imax Discovery trickle Imax. Range (2-2^8)*Imin. Use 0x00 to use leave parameter unchanged.
|
||||
* \param disc_trickle_k Discovery trickle k. Use 0x00 to use leave parameter unchanged.
|
||||
* \param pan_timeout PAN timeout; seconds; Range 60-15300 seconds. Use 0x00 to use leave parameter unchanged.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t set_timing_parameters(uint16_t disc_trickle_imin = 0x00, uint16_t disc_trickle_imax = 0x00, uint8_t disc_trickle_k = 0x00, uint16_t pan_timeout = 0x00);
|
||||
|
||||
/**
|
||||
* \brief Get Wi-SUN timing parameters
|
||||
*
|
||||
* Function reads timing parameters from mbed-mesh-api.
|
||||
*
|
||||
* \param disc_trickle_imin Discovery trickle Imin. Range 1-255 seconds.
|
||||
* \param disc_trickle_imax Discovery trickle Imax. Range (2-2^8)*Imin.
|
||||
* \param disc_trickle_k Discovery trickle k.
|
||||
* \param pan_timeout PAN timeout; seconds; Range 60-15300 seconds.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t get_timing_parameters(uint16_t *disc_trickle_imin, uint16_t *disc_trickle_imax, uint8_t *disc_trickle_k, uint16_t *pan_timeout);
|
||||
|
||||
/**
|
||||
* \brief Validates Wi-SUN timing parameters
|
||||
*
|
||||
* Function validates timing parameters. Function can be used to test that values that will be used on set
|
||||
* function are valid.
|
||||
*
|
||||
* \param disc_trickle_imin Discovery trickle Imin. Range 1-255 seconds.
|
||||
* \param disc_trickle_imax Discovery trickle Imax. Range (2-2^8)*Imin.
|
||||
* \param disc_trickle_k Discovery trickle k.
|
||||
* \param pan_timeout PAN timeout; seconds; Range 60-15300 seconds.
|
||||
* \return MESH_ERROR_NONE on success.
|
||||
* \return MESH_ERROR_UNKNOWN in case of failure.
|
||||
* */
|
||||
mesh_error_t validate_timing_parameters(uint16_t disc_trickle_imin, uint16_t disc_trickle_imax, uint8_t disc_trickle_k, uint16_t pan_timeout);
|
||||
|
||||
/**
|
||||
* \brief Set own certificate and private key reference to the Wi-SUN network.
|
||||
*
|
||||
|
@ -125,6 +393,7 @@ public:
|
|||
protected:
|
||||
Nanostack::WisunInterface *get_interface() const;
|
||||
nsapi_error_t do_initialize() override;
|
||||
virtual nsapi_error_t configure();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -64,6 +64,43 @@ typedef enum {
|
|||
MESH_DEVICE_TYPE_WISUN_BORDER_ROUTER /*<! Wi-SUN border router */
|
||||
} mesh_device_type_t;
|
||||
|
||||
/**
|
||||
* Mesh channel function
|
||||
*/
|
||||
typedef enum {
|
||||
MESH_CHANNEL_FUNCTION_FIXED = 0x00,
|
||||
MESH_CHANNEL_FUNCTION_TR51CF,
|
||||
MESH_CHANNEL_FUNCTION_DH1CF,
|
||||
MESH_CHANNEL_FUNCTION_VENDOR_DEFINED
|
||||
} mesh_channel_function_t;
|
||||
|
||||
/**
|
||||
* Mesh network statistics
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t rpl_total_memory; /*<! RPL current memory usage total. */
|
||||
uint16_t etx_1st_parent; /*<! Primary parent ETX. */
|
||||
uint16_t etx_2nd_parent; /*<! Secondary parent ETX. */
|
||||
uint32_t asynch_tx_count; /*<! Asynch TX counter */
|
||||
uint32_t asynch_rx_count; /*<! Asynch RX counter */
|
||||
} mesh_nw_statistics_t;
|
||||
|
||||
/**
|
||||
* Mesh physical layer statistics
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t mac_rx_count; /*<! MAC RX packet count. */
|
||||
uint32_t mac_tx_count; /*<! MAC TX packet count. */
|
||||
uint32_t mac_bc_rx_count; /*<! MAC broadcast RX packet count. */
|
||||
uint32_t mac_bc_tx_count; /*<! MAC broadcast TX packet count. */
|
||||
uint32_t mac_tx_bytes; /*<! MAC TX bytes count. */
|
||||
uint32_t mac_rx_bytes; /*<! MAC RX bytes count. */
|
||||
uint32_t mac_tx_failed_count; /*<! MAC TX failed count. */
|
||||
uint32_t mac_retry_count; /*<! MAC TX retry count. */
|
||||
uint32_t mac_cca_attempts_count; /*<! MAC CCA attempts count. */
|
||||
uint32_t mac_failed_cca_count; /*<! MAC failed CCA count. */
|
||||
} mesh_mac_statistics_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -92,6 +92,15 @@ int InterfaceNanostack::disconnect()
|
|||
return _interface->bringdown();
|
||||
}
|
||||
|
||||
char *Nanostack::MeshInterface::get_interface_name(char *buf)
|
||||
{
|
||||
if (interface_id < 0) {
|
||||
return NULL;
|
||||
}
|
||||
sprintf(buf, "MES%d", interface_id);
|
||||
return buf;
|
||||
};
|
||||
|
||||
nsapi_error_t MeshInterfaceNanostack::initialize(NanostackRfPhy *phy)
|
||||
{
|
||||
if (_phy && phy && _phy != phy) {
|
||||
|
|
|
@ -120,3 +120,12 @@ nsapi_error_t Nanostack::EthernetInterface::bringdown()
|
|||
}
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
char *Nanostack::EthernetInterface::get_interface_name(char *buf)
|
||||
{
|
||||
if (interface_id < 0) {
|
||||
return NULL;
|
||||
}
|
||||
sprintf(buf, "ETH%d", interface_id);
|
||||
return buf;
|
||||
};
|
||||
|
|
|
@ -181,6 +181,15 @@ void Nanostack::PPPInterface::set_link_state_changed_callback(link_state_cb_t ne
|
|||
link_state_cb = new_link_state_cb;
|
||||
}
|
||||
|
||||
char *Nanostack::PPPInterface::get_interface_name(char *buf)
|
||||
{
|
||||
if (interface_id < 0) {
|
||||
return NULL;
|
||||
}
|
||||
sprintf(buf, "PPP%d", interface_id);
|
||||
return buf;
|
||||
};
|
||||
|
||||
// GAH! no handles on the callback. Force a single interface
|
||||
static PPPPhy *single_phy;
|
||||
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "WisunInterface.h"
|
||||
#include "ns_trace.h"
|
||||
#include "WisunBorderRouter.h"
|
||||
#include "MeshInterfaceNanostack.h"
|
||||
|
||||
extern "C" {
|
||||
#include "ws_bbr_api.h"
|
||||
}
|
||||
|
||||
#define TRACE_GROUP "WSBR"
|
||||
|
||||
mesh_error_t WisunBorderRouter::start(NetworkInterface *mesh_if, NetworkInterface *backbone_if)
|
||||
{
|
||||
if (mesh_if == NULL || backbone_if == NULL) {
|
||||
return MESH_ERROR_PARAM;
|
||||
}
|
||||
|
||||
InterfaceNanostack *nano_mesh_if = reinterpret_cast<InterfaceNanostack *>(mesh_if);
|
||||
int8_t mesh_if_id = nano_mesh_if->get_interface_id();
|
||||
if (mesh_if_id < 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
_mesh_if_id = mesh_if_id;
|
||||
|
||||
char backbone_if_name[7] = {0};
|
||||
if (backbone_if->get_interface_name(backbone_if_name) == NULL) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
if (strlen((char *) &backbone_if_name) < 4) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
int backbone_if_id = atoi(&backbone_if_name[3]);
|
||||
if (backbone_if_id < 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
int ret = ws_bbr_start(mesh_if_id, backbone_if_id);
|
||||
if (ret < 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunBorderRouter::start(NetworkInterface *mesh_if, OnboardNetworkStack::Interface *backbone_if)
|
||||
{
|
||||
InterfaceNanostack *nano_mesh_if = reinterpret_cast<InterfaceNanostack *>(mesh_if);
|
||||
int8_t mesh_if_id = nano_mesh_if->get_interface_id();
|
||||
if (mesh_if_id < 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
_mesh_if_id = mesh_if_id;
|
||||
|
||||
Nanostack::Interface *nano_backbone_if = static_cast<Nanostack::Interface *>(backbone_if);
|
||||
int8_t backbone_if_id = nano_backbone_if->get_interface_id();
|
||||
if (backbone_if_id < 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
int ret = ws_bbr_start(mesh_if_id, backbone_if_id);
|
||||
if (ret < 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
void WisunBorderRouter::stop()
|
||||
{
|
||||
if (_mesh_if_id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
ws_bbr_stop(_mesh_if_id);
|
||||
|
||||
_mesh_if_id = -1;
|
||||
}
|
||||
|
||||
mesh_error_t WisunBorderRouter::set_rpl_parameters(uint8_t dio_interval_min, uint8_t dio_interval_doublings, uint8_t dio_redundancy_constant)
|
||||
{
|
||||
int status = ws_bbr_rpl_parameters_set(_mesh_if_id, dio_interval_min, dio_interval_doublings, dio_redundancy_constant);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunBorderRouter::get_rpl_parameters(uint8_t *dio_interval_min, uint8_t *dio_interval_doublings, uint8_t *dio_redundancy_constant)
|
||||
{
|
||||
int status = ws_bbr_rpl_parameters_get(_mesh_if_id, dio_interval_min, dio_interval_doublings, dio_redundancy_constant);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunBorderRouter::validate_rpl_parameters(uint8_t dio_interval_min, uint8_t dio_interval_doublings, uint8_t dio_redundancy_constant)
|
||||
{
|
||||
int status = ws_bbr_rpl_parameters_validate(_mesh_if_id, dio_interval_min, dio_interval_doublings, dio_redundancy_constant);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunBorderRouter::set_pan_configuration(uint16_t pan_id)
|
||||
{
|
||||
int status = ws_bbr_pan_configuration_set(_mesh_if_id, pan_id);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunBorderRouter::get_pan_configuration(uint16_t *pan_id)
|
||||
{
|
||||
int status = ws_bbr_pan_configuration_get(_mesh_if_id, pan_id);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunBorderRouter::validate_pan_configuration(uint16_t pan_id)
|
||||
{
|
||||
int status = ws_bbr_pan_configuration_validate(_mesh_if_id, pan_id);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
|
@ -21,6 +21,9 @@
|
|||
#include "NanostackLockGuard.h"
|
||||
#include "mesh_system.h"
|
||||
#include "randLIB.h"
|
||||
#include "fhss_api.h"
|
||||
#include "fhss_config.h"
|
||||
#include "ws_management_api.h"
|
||||
|
||||
#include "ns_trace.h"
|
||||
#define TRACE_GROUP "WSIn"
|
||||
|
@ -57,6 +60,63 @@ nsapi_error_t WisunInterface::do_initialize()
|
|||
}
|
||||
_interface->attach(_connection_status_cb);
|
||||
}
|
||||
|
||||
// Apply mbed configuration to Wi-SUN
|
||||
configure();
|
||||
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
nsapi_error_t WisunInterface::configure()
|
||||
{
|
||||
int status;
|
||||
|
||||
if (_configured) {
|
||||
// Already configured
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
_configured = true;
|
||||
#ifdef MBED_CONF_MBED_MESH_API_WISUN_NETWORK_NAME
|
||||
char network_name[] = {MBED_CONF_MBED_MESH_API_WISUN_NETWORK_NAME};
|
||||
status = set_network_name((char *) &network_name);
|
||||
if (status < 0) {
|
||||
tr_error("Failed to set network name!");
|
||||
return NSAPI_ERROR_PARAMETER;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (MBED_CONF_MBED_MESH_API_WISUN_REGULATORY_DOMAIN != 255) || (MBED_CONF_MBED_MESH_API_WISUN_OPERATING_CLASS != 255) || (MBED_CONF_MBED_MESH_API_WISUN_OPERATING_MODE != 255)
|
||||
status = set_network_regulatory_domain(MBED_CONF_MBED_MESH_API_WISUN_REGULATORY_DOMAIN,
|
||||
MBED_CONF_MBED_MESH_API_WISUN_OPERATING_CLASS,
|
||||
MBED_CONF_MBED_MESH_API_WISUN_OPERATING_MODE);
|
||||
if (status < 0) {
|
||||
tr_error("Failed to set regulatory domain!");
|
||||
return NSAPI_ERROR_PARAMETER;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (MBED_CONF_MBED_MESH_API_WISUN_UC_CHANNEL_FUNCTION != 255)
|
||||
status = set_unicast_channel_function(static_cast<mesh_channel_function_t>(MBED_CONF_MBED_MESH_API_WISUN_UC_CHANNEL_FUNCTION),
|
||||
MBED_CONF_MBED_MESH_API_WISUN_UC_FIXED_CHANNEL,
|
||||
MBED_CONF_MBED_MESH_API_WISUN_UC_DWELL_INTERVAL);
|
||||
if (status < 0) {
|
||||
tr_error("Failed to set unicast channel function configuration");
|
||||
return NSAPI_ERROR_PARAMETER;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (MBED_CONF_MBED_MESH_API_WISUN_BC_CHANNEL_FUNCTION != 255) || (MBED_CONF_MBED_MESH_API_WISUN_BC_DWELL_INTERVAL != 0) || (MBED_CONF_MBED_MESH_API_WISUN_BC_INTERVAL != 0)
|
||||
status = set_broadcast_channel_function(static_cast<mesh_channel_function_t>(MBED_CONF_MBED_MESH_API_WISUN_BC_CHANNEL_FUNCTION),
|
||||
MBED_CONF_MBED_MESH_API_WISUN_BC_FIXED_CHANNEL,
|
||||
MBED_CONF_MBED_MESH_API_WISUN_BC_DWELL_INTERVAL,
|
||||
MBED_CONF_MBED_MESH_API_WISUN_BC_INTERVAL);
|
||||
if (status < 0) {
|
||||
tr_error("Failed to set broadcast channel function configuration");
|
||||
return NSAPI_ERROR_PARAMETER;
|
||||
}
|
||||
#endif
|
||||
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
|
@ -180,26 +240,226 @@ bool WisunInterface::getRouterIpAddress(char *address, int8_t 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);
|
||||
int status = ws_management_network_name_set(get_interface_id(), network_name);
|
||||
if (status != 0) {
|
||||
ret_val = MESH_ERROR_UNKNOWN;
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::get_network_name(char *network_name)
|
||||
{
|
||||
int status = ws_management_network_name_get(get_interface_id(), network_name);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::validate_network_name(char *network_name)
|
||||
{
|
||||
int status = ws_management_network_name_validate(get_interface_id(), network_name);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
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);
|
||||
int status = ws_management_regulatory_domain_set(get_interface_id(), regulatory_domain, operating_class, operating_mode);
|
||||
if (status != 0) {
|
||||
ret_val = MESH_ERROR_UNKNOWN;
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::get_network_regulatory_domain(uint8_t *regulatory_domain, uint8_t *operating_class, uint8_t *operating_mode)
|
||||
{
|
||||
int status = ws_management_regulatory_domain_get(get_interface_id(), regulatory_domain, operating_class, operating_mode);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::validate_network_regulatory_domain(uint8_t regulatory_domain, uint8_t operating_class, uint8_t operating_mode)
|
||||
{
|
||||
int status = ws_management_regulatory_domain_validate(get_interface_id(), regulatory_domain, operating_class, operating_mode);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::set_network_size(uint8_t network_size)
|
||||
{
|
||||
if (network_size == 0xff) {
|
||||
// Size 0xff is internal API
|
||||
network_size = 0xfe;
|
||||
}
|
||||
|
||||
int status = ws_management_network_size_set(get_interface_id(), network_size);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::get_network_size(uint8_t *network_size)
|
||||
{
|
||||
int status = ws_management_network_size_get(get_interface_id(), network_size);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::validate_network_size(uint8_t network_size)
|
||||
{
|
||||
if (network_size == 0xff) {
|
||||
// Size 0xff is internal API
|
||||
network_size = 0xfe;
|
||||
}
|
||||
|
||||
int status = ws_management_network_size_validate(get_interface_id(), network_size);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::set_channel_mask(uint32_t channel_mask[8])
|
||||
{
|
||||
int status = ws_management_channel_mask_set(get_interface_id(), channel_mask);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::get_channel_mask(uint32_t *channel_mask)
|
||||
{
|
||||
int status = ws_management_channel_mask_get(get_interface_id(), channel_mask);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::validate_channel_mask(uint32_t channel_mask[8])
|
||||
{
|
||||
int status = ws_management_channel_mask_validate(get_interface_id(), channel_mask);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::set_unicast_channel_function(mesh_channel_function_t channel_function, uint16_t fixed_channel, uint8_t dwell_interval)
|
||||
{
|
||||
int status = ws_management_fhss_unicast_channel_function_configure(get_interface_id(), channel_function, fixed_channel, dwell_interval);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::get_unicast_channel_function(mesh_channel_function_t *channel_function, uint16_t *fixed_channel, uint8_t *dwell_interval)
|
||||
{
|
||||
uint8_t ch_function;
|
||||
int status = ws_management_fhss_unicast_channel_function_get(get_interface_id(), &ch_function, fixed_channel, dwell_interval);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
*channel_function = static_cast<mesh_channel_function_t>(ch_function);
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::validate_unicast_channel_function(mesh_channel_function_t channel_function, uint16_t fixed_channel, uint8_t dwell_interval)
|
||||
{
|
||||
int status = ws_management_fhss_unicast_channel_function_validate(get_interface_id(), channel_function, fixed_channel, dwell_interval);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::set_broadcast_channel_function(mesh_channel_function_t channel_function, uint16_t fixed_channel, uint8_t dwell_interval, uint32_t broadcast_interval)
|
||||
{
|
||||
int status = ws_management_fhss_broadcast_channel_function_configure(get_interface_id(), channel_function, fixed_channel, dwell_interval, broadcast_interval);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::get_broadcast_channel_function(mesh_channel_function_t *channel_function, uint16_t *fixed_channel, uint8_t *dwell_interval, uint32_t *broadcast_interval)
|
||||
{
|
||||
uint8_t ch_function;
|
||||
int status = ws_management_fhss_broadcast_channel_function_get(get_interface_id(), &ch_function, fixed_channel, dwell_interval, broadcast_interval);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
*channel_function = static_cast<mesh_channel_function_t>(ch_function);
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::validate_broadcast_channel_function(mesh_channel_function_t channel_function, uint16_t fixed_channel, uint8_t dwell_interval, uint32_t broadcast_interval)
|
||||
{
|
||||
int status = ws_management_fhss_broadcast_channel_function_validate(get_interface_id(), channel_function, fixed_channel, dwell_interval, broadcast_interval);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::set_timing_parameters(uint16_t disc_trickle_imin, uint16_t disc_trickle_imax, uint8_t disc_trickle_k, uint16_t pan_timeout)
|
||||
{
|
||||
int status = ws_management_timing_parameters_set(get_interface_id(), disc_trickle_imin, disc_trickle_imax, disc_trickle_k, pan_timeout);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::get_timing_parameters(uint16_t *disc_trickle_imin, uint16_t *disc_trickle_imax, uint8_t *disc_trickle_k, uint16_t *pan_timeout)
|
||||
{
|
||||
int status = ws_management_timing_parameters_get(get_interface_id(), disc_trickle_imin, disc_trickle_imax, disc_trickle_k, pan_timeout);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::validate_timing_parameters(uint16_t disc_trickle_imin, uint16_t disc_trickle_imax, uint8_t disc_trickle_k, uint16_t pan_timeout)
|
||||
{
|
||||
int status = ws_management_timing_parameters_validate(get_interface_id(), disc_trickle_imin, disc_trickle_imax, disc_trickle_k, pan_timeout);
|
||||
if (status != 0) {
|
||||
return MESH_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return MESH_ERROR_NONE;
|
||||
}
|
||||
|
||||
mesh_error_t WisunInterface::set_own_certificate(uint8_t *cert, uint16_t cert_len, uint8_t *cert_key, uint16_t cert_key_len)
|
||||
|
|
|
@ -79,28 +79,6 @@ 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
|
||||
*
|
||||
|
|
|
@ -71,20 +71,6 @@ 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;
|
||||
uint8_t uc_channel_function;
|
||||
uint8_t bc_channel_function;
|
||||
uint8_t uc_dwell_interval;
|
||||
uint32_t bc_interval;
|
||||
uint8_t bc_dwell_interval;
|
||||
uint16_t uc_fixed_channel;
|
||||
uint16_t bc_fixed_channel;
|
||||
} wisun_network_settings_t;
|
||||
|
||||
typedef struct {
|
||||
arm_certificate_entry_s arm_cert_entry;
|
||||
ns_list_link_t link; /*!< List link entry */
|
||||
|
@ -98,25 +84,9 @@ typedef struct {
|
|||
bool remove_trusted_certificates: 1;
|
||||
} wisun_certificates_t;
|
||||
|
||||
#define WS_NA 0xff // Not applicable value
|
||||
#define WS_DEFAULT 0x00 // Use default 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 = {
|
||||
.network_name = NULL,
|
||||
.regulatory_domain = MBED_CONF_MBED_MESH_API_WISUN_REGULATORY_DOMAIN,
|
||||
.rd_operating_class = MBED_CONF_MBED_MESH_API_WISUN_OPERATING_CLASS,
|
||||
.rd_operating_mode = MBED_CONF_MBED_MESH_API_WISUN_OPERATING_MODE,
|
||||
.uc_channel_function = MBED_CONF_MBED_MESH_API_WISUN_UC_CHANNEL_FUNCTION,
|
||||
.bc_channel_function = MBED_CONF_MBED_MESH_API_WISUN_BC_CHANNEL_FUNCTION,
|
||||
.uc_dwell_interval = MBED_CONF_MBED_MESH_API_WISUN_UC_DWELL_INTERVAL,
|
||||
.bc_interval = MBED_CONF_MBED_MESH_API_WISUN_BC_INTERVAL,
|
||||
.bc_dwell_interval = MBED_CONF_MBED_MESH_API_WISUN_BC_DWELL_INTERVAL,
|
||||
.uc_fixed_channel = MBED_CONF_MBED_MESH_API_WISUN_UC_FIXED_CHANNEL,
|
||||
.bc_fixed_channel = MBED_CONF_MBED_MESH_API_WISUN_BC_FIXED_CHANNEL
|
||||
};
|
||||
static mac_api_t *mac_api = NULL;
|
||||
|
||||
extern fhss_timer_t fhss_functions;
|
||||
|
@ -272,70 +242,32 @@ static void wisun_tasklet_configure_and_connect_to_network(void)
|
|||
return;
|
||||
}
|
||||
|
||||
char network_name[33];
|
||||
status = ws_management_network_name_get(wisun_tasklet_data_ptr->network_interface_id, (char *) &network_name);
|
||||
if (status < 0) {
|
||||
tr_error("Failed to read network name");
|
||||
return;
|
||||
}
|
||||
uint8_t regulatory_domain;
|
||||
uint8_t operating_class;
|
||||
uint8_t operating_mode;
|
||||
status = ws_management_regulatory_domain_get(wisun_tasklet_data_ptr->network_interface_id,
|
||||
®ulatory_domain,
|
||||
&operating_class,
|
||||
&operating_mode);
|
||||
if (status < 0) {
|
||||
tr_error("Failed to read regulatory domain");
|
||||
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,
|
||||
regulatory_domain,
|
||||
(char *) network_name,
|
||||
fhss_timer_ptr);
|
||||
if (status < 0) {
|
||||
tr_error("Failed to initialize WS");
|
||||
return;
|
||||
}
|
||||
|
||||
if (wisun_settings_str.uc_channel_function != WS_NA) {
|
||||
status = ws_management_fhss_unicast_channel_function_configure(wisun_tasklet_data_ptr->network_interface_id,
|
||||
wisun_settings_str.uc_channel_function,
|
||||
wisun_settings_str.uc_fixed_channel,
|
||||
wisun_settings_str.uc_dwell_interval);
|
||||
|
||||
if (status < 0) {
|
||||
tr_error("Failed to set unicast channel function configuration");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wisun_settings_str.bc_channel_function != WS_NA ||
|
||||
wisun_settings_str.bc_dwell_interval != WS_DEFAULT ||
|
||||
wisun_settings_str.bc_interval != WS_DEFAULT) {
|
||||
status = ws_management_fhss_broadcast_channel_function_configure(wisun_tasklet_data_ptr->network_interface_id,
|
||||
wisun_settings_str.bc_channel_function,
|
||||
wisun_settings_str.bc_fixed_channel,
|
||||
wisun_settings_str.bc_dwell_interval,
|
||||
wisun_settings_str.bc_interval);
|
||||
|
||||
if (status < 0) {
|
||||
tr_error("Failed to set broadcast channel function configuration");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (wisun_settings_str.uc_dwell_interval != WS_DEFAULT ||
|
||||
wisun_settings_str.bc_dwell_interval != WS_DEFAULT ||
|
||||
wisun_settings_str.bc_interval != WS_DEFAULT) {
|
||||
status = ws_management_fhss_timing_configure(wisun_tasklet_data_ptr->network_interface_id,
|
||||
wisun_settings_str.uc_dwell_interval,
|
||||
wisun_settings_str.bc_interval,
|
||||
wisun_settings_str.bc_dwell_interval);
|
||||
|
||||
if (status < 0) {
|
||||
tr_error("Failed to set fhss configuration");
|
||||
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_entry_s trusted_cert = {
|
||||
.cert = MBED_CONF_MBED_MESH_API_ROOT_CERTIFICATE,
|
||||
|
@ -590,57 +522,9 @@ int8_t wisun_tasklet_network_init(int8_t device_id)
|
|||
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 && wisun_tasklet_data_ptr->network_interface_id != INVALID_INTERFACE_ID) {
|
||||
|
|
Loading…
Reference in New Issue