mirror of https://github.com/ARMmbed/mbed-os.git
nanostack mesh: fix coding style
parent
e1e20a64f9
commit
3aab38140a
|
@ -32,7 +32,10 @@ public:
|
|||
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
|
||||
virtual nsapi_connection_status_t get_connection_status() const;
|
||||
|
||||
void get_mac_address(uint8_t *buf) const { interface_phy.get_mac_address(buf); }
|
||||
void get_mac_address(uint8_t *buf) const
|
||||
{
|
||||
interface_phy.get_mac_address(buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Callback from C-layer
|
||||
|
@ -40,15 +43,24 @@ public:
|
|||
* */
|
||||
void network_handler(mesh_connection_status_t status);
|
||||
|
||||
int8_t get_interface_id() const { return interface_id; }
|
||||
int8_t get_driver_id() const { return _device_id; }
|
||||
int8_t get_interface_id() const
|
||||
{
|
||||
return interface_id;
|
||||
}
|
||||
int8_t get_driver_id() const
|
||||
{
|
||||
return _device_id;
|
||||
}
|
||||
|
||||
private:
|
||||
NanostackPhy &interface_phy;
|
||||
protected:
|
||||
Interface(NanostackPhy &phy);
|
||||
virtual nsapi_error_t register_phy();
|
||||
NanostackPhy &get_phy() const { return interface_phy; }
|
||||
NanostackPhy &get_phy() const
|
||||
{
|
||||
return interface_phy;
|
||||
}
|
||||
int8_t interface_id;
|
||||
int8_t _device_id;
|
||||
rtos::Semaphore connect_semaphore;
|
||||
|
@ -62,7 +74,10 @@ protected:
|
|||
class Nanostack::MeshInterface : public Nanostack::Interface {
|
||||
protected:
|
||||
MeshInterface(NanostackRfPhy &phy) : Interface(phy) { }
|
||||
NanostackRfPhy &get_phy() const { return static_cast<NanostackRfPhy &>(Interface::get_phy()); }
|
||||
NanostackRfPhy &get_phy() const
|
||||
{
|
||||
return static_cast<NanostackRfPhy &>(Interface::get_phy());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -116,12 +131,18 @@ public:
|
|||
/** Get the interface ID
|
||||
/return Interface identifier
|
||||
*/
|
||||
int8_t get_interface_id() const { return _interface->get_interface_id(); }
|
||||
int8_t get_interface_id() const
|
||||
{
|
||||
return _interface->get_interface_id();
|
||||
}
|
||||
|
||||
protected:
|
||||
InterfaceNanostack();
|
||||
virtual Nanostack *get_stack(void);
|
||||
Nanostack::Interface *get_interface() const { return _interface; }
|
||||
Nanostack::Interface *get_interface() const
|
||||
{
|
||||
return _interface;
|
||||
}
|
||||
virtual nsapi_error_t do_initialize() = 0;
|
||||
|
||||
Nanostack::Interface *_interface;
|
||||
|
@ -147,7 +168,10 @@ public:
|
|||
protected:
|
||||
MeshInterfaceNanostack() : _phy(NULL) { }
|
||||
MeshInterfaceNanostack(NanostackRfPhy *phy) : _phy(phy) { }
|
||||
Nanostack::MeshInterface *get_interface() const { return static_cast<Nanostack::MeshInterface *>(_interface); }
|
||||
Nanostack::MeshInterface *get_interface() const
|
||||
{
|
||||
return static_cast<Nanostack::MeshInterface *>(_interface);
|
||||
}
|
||||
NanostackRfPhy *_phy;
|
||||
};
|
||||
|
||||
|
|
|
@ -35,7 +35,10 @@ private:
|
|||
EthernetInterface(NanostackEthernetPhy &phy) : Interface(phy) {}
|
||||
nsapi_error_t initialize();
|
||||
protected:
|
||||
NanostackEthernetPhy &get_phy() const { return static_cast<NanostackEthernetPhy &>(Interface::get_phy()); }
|
||||
NanostackEthernetPhy &get_phy() const
|
||||
{
|
||||
return static_cast<NanostackEthernetPhy &>(Interface::get_phy());
|
||||
}
|
||||
};
|
||||
|
||||
/** Ethernet interface for Nanostack.
|
||||
|
@ -50,7 +53,10 @@ public:
|
|||
nsapi_error_t initialize(NanostackEthernetPhy *phy);
|
||||
|
||||
protected:
|
||||
Nanostack::EthernetInterface *get_interface() const { return static_cast<Nanostack::EthernetInterface *>(_interface); }
|
||||
Nanostack::EthernetInterface *get_interface() const
|
||||
{
|
||||
return static_cast<Nanostack::EthernetInterface *>(_interface);
|
||||
}
|
||||
virtual nsapi_error_t do_initialize();
|
||||
|
||||
};
|
||||
|
|
|
@ -8,8 +8,7 @@
|
|||
#include "ns_trace.h"
|
||||
#define TRACE_GROUP "nslp"
|
||||
|
||||
class Nanostack::LoWPANNDInterface : public Nanostack::MeshInterface
|
||||
{
|
||||
class Nanostack::LoWPANNDInterface : public Nanostack::MeshInterface {
|
||||
public:
|
||||
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
|
||||
const char *netmask, const char *gw,
|
||||
|
@ -29,7 +28,7 @@ private:
|
|||
|
||||
Nanostack::LoWPANNDInterface *LoWPANNDInterface::get_interface() const
|
||||
{
|
||||
return static_cast<Nanostack::LoWPANNDInterface*>(_interface);
|
||||
return static_cast<Nanostack::LoWPANNDInterface *>(_interface);
|
||||
}
|
||||
|
||||
nsapi_error_t LoWPANNDInterface::do_initialize()
|
||||
|
|
|
@ -69,7 +69,7 @@ void Nanostack::Interface::attach(
|
|||
}
|
||||
|
||||
Nanostack::Interface::Interface(NanostackPhy &phy) : interface_phy(phy), interface_id(-1), _device_id(-1),
|
||||
_connect_status(NSAPI_STATUS_DISCONNECTED), _previous_connection_status(NSAPI_STATUS_DISCONNECTED), _blocking(true)
|
||||
_connect_status(NSAPI_STATUS_DISCONNECTED), _previous_connection_status(NSAPI_STATUS_DISCONNECTED), _blocking(true)
|
||||
{
|
||||
mesh_system_init();
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ nsapi_error_t MeshInterfaceNanostack::initialize(NanostackRfPhy *phy)
|
|||
void Nanostack::Interface::network_handler(mesh_connection_status_t status)
|
||||
{
|
||||
if ((status == MESH_CONNECTED || status == MESH_CONNECTED_LOCAL ||
|
||||
status == MESH_CONNECTED_GLOBAL) && _blocking) {
|
||||
status == MESH_CONNECTED_GLOBAL) && _blocking) {
|
||||
connect_semaphore.release();
|
||||
}
|
||||
|
||||
|
@ -131,10 +131,10 @@ void Nanostack::Interface::network_handler(mesh_connection_status_t status)
|
|||
_connect_status = NSAPI_STATUS_LOCAL_UP;
|
||||
}
|
||||
if (arm_net_address_get(interface_id, ADDR_IPV6_GP, temp_ipv6_global) == 0
|
||||
&& (memcmp(temp_ipv6_global, temp_ipv6_local, 16) != 0)) {
|
||||
&& (memcmp(temp_ipv6_global, temp_ipv6_local, 16) != 0)) {
|
||||
_connect_status = NSAPI_STATUS_GLOBAL_UP;
|
||||
}
|
||||
} else if (status == MESH_CONNECTED_LOCAL ) {
|
||||
} else if (status == MESH_CONNECTED_LOCAL) {
|
||||
_connect_status = NSAPI_STATUS_LOCAL_UP;
|
||||
} else if (status == MESH_CONNECTED_GLOBAL) {
|
||||
_connect_status = NSAPI_STATUS_GLOBAL_UP;
|
||||
|
|
|
@ -8,16 +8,15 @@
|
|||
#include "arm_hal_phy.h"
|
||||
#include "EMAC.h"
|
||||
|
||||
class EMACPhy : public NanostackEthernetPhy
|
||||
{
|
||||
class EMACPhy : public NanostackEthernetPhy {
|
||||
public:
|
||||
EMACPhy(NanostackMemoryManager &mem, EMAC &m);
|
||||
virtual int8_t phy_register();
|
||||
virtual void get_mac_address(uint8_t *mac);
|
||||
virtual void set_mac_address(uint8_t *mac);
|
||||
|
||||
int8_t address_write(phy_address_type_e , uint8_t *);
|
||||
int8_t tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle,data_protocol_e data_flow);
|
||||
int8_t address_write(phy_address_type_e, uint8_t *);
|
||||
int8_t tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow);
|
||||
|
||||
void emac_phy_rx(emac_mem_buf_t *mem);
|
||||
|
||||
|
@ -34,65 +33,65 @@ static EMACPhy *single_phy;
|
|||
|
||||
extern "C"
|
||||
{
|
||||
static int8_t emac_phy_address_write(phy_address_type_e address_type, uint8_t *address_ptr)
|
||||
{
|
||||
return single_phy->address_write(address_type, address_ptr);
|
||||
}
|
||||
static int8_t emac_phy_address_write(phy_address_type_e address_type, uint8_t *address_ptr)
|
||||
{
|
||||
return single_phy->address_write(address_type, address_ptr);
|
||||
}
|
||||
|
||||
static int8_t emac_phy_interface_state_control(phy_interface_state_e, uint8_t)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
static int8_t emac_phy_interface_state_control(phy_interface_state_e, uint8_t)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int8_t emac_phy_tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle,data_protocol_e data_flow)
|
||||
{
|
||||
return single_phy->tx(data_ptr, data_len, tx_handle, data_flow);
|
||||
}
|
||||
static int8_t emac_phy_tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow)
|
||||
{
|
||||
return single_phy->tx(data_ptr, data_len, tx_handle, data_flow);
|
||||
}
|
||||
|
||||
EMACPhy::EMACPhy(NanostackMemoryManager &mem, EMAC &m) : memory_manager(mem), emac(m), device_id(-1)
|
||||
{
|
||||
/* Same default address logic as lwIP glue uses */
|
||||
EMACPhy::EMACPhy(NanostackMemoryManager &mem, EMAC &m) : memory_manager(mem), emac(m), device_id(-1)
|
||||
{
|
||||
/* Same default address logic as lwIP glue uses */
|
||||
#if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
|
||||
mac_addr[0] = MBED_MAC_ADDR_0;
|
||||
mac_addr[1] = MBED_MAC_ADDR_1;
|
||||
mac_addr[2] = MBED_MAC_ADDR_2;
|
||||
mac_addr[3] = MBED_MAC_ADDR_3;
|
||||
mac_addr[4] = MBED_MAC_ADDR_4;
|
||||
mac_addr[5] = MBED_MAC_ADDR_5;
|
||||
mac_addr[0] = MBED_MAC_ADDR_0;
|
||||
mac_addr[1] = MBED_MAC_ADDR_1;
|
||||
mac_addr[2] = MBED_MAC_ADDR_2;
|
||||
mac_addr[3] = MBED_MAC_ADDR_3;
|
||||
mac_addr[4] = MBED_MAC_ADDR_4;
|
||||
mac_addr[5] = MBED_MAC_ADDR_5;
|
||||
#else
|
||||
mbed_mac_address((char *) mac_addr);
|
||||
mbed_mac_address((char *) mac_addr);
|
||||
#endif
|
||||
/* We have a default MAC address, so do don't force them to supply one */
|
||||
/* They may or may not update hwaddr with their address */
|
||||
emac.get_hwaddr(mac_addr);
|
||||
}
|
||||
/* We have a default MAC address, so do don't force them to supply one */
|
||||
/* They may or may not update hwaddr with their address */
|
||||
emac.get_hwaddr(mac_addr);
|
||||
}
|
||||
|
||||
|
||||
void EMACPhy::emac_phy_rx(emac_mem_buf_t *mem)
|
||||
{
|
||||
const uint8_t *ptr = NULL;
|
||||
uint8_t *tmpbuf = NULL;
|
||||
uint32_t total_len;
|
||||
void EMACPhy::emac_phy_rx(emac_mem_buf_t *mem)
|
||||
{
|
||||
const uint8_t *ptr = NULL;
|
||||
uint8_t *tmpbuf = NULL;
|
||||
uint32_t total_len;
|
||||
|
||||
if (memory_manager.get_next(mem) == NULL) {
|
||||
// Easy contiguous case
|
||||
ptr = static_cast<const uint8_t*>(memory_manager.get_ptr(mem));
|
||||
total_len = memory_manager.get_len(mem);
|
||||
} else {
|
||||
// Nanostack can't accept chunked data - make temporary contiguous copy
|
||||
total_len = memory_manager.get_total_len(mem);
|
||||
ptr = tmpbuf = static_cast<uint8_t *>(ns_dyn_mem_temporary_alloc(total_len));
|
||||
if (tmpbuf) {
|
||||
memory_manager.copy_from_buf(tmpbuf, total_len, mem);
|
||||
if (memory_manager.get_next(mem) == NULL) {
|
||||
// Easy contiguous case
|
||||
ptr = static_cast<const uint8_t *>(memory_manager.get_ptr(mem));
|
||||
total_len = memory_manager.get_len(mem);
|
||||
} else {
|
||||
// Nanostack can't accept chunked data - make temporary contiguous copy
|
||||
total_len = memory_manager.get_total_len(mem);
|
||||
ptr = tmpbuf = static_cast<uint8_t *>(ns_dyn_mem_temporary_alloc(total_len));
|
||||
if (tmpbuf) {
|
||||
memory_manager.copy_from_buf(tmpbuf, total_len, mem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ptr && phy.phy_rx_cb) {
|
||||
phy.phy_rx_cb(ptr, total_len, 0xff, 0, device_id);
|
||||
if (ptr && phy.phy_rx_cb) {
|
||||
phy.phy_rx_cb(ptr, total_len, 0xff, 0, device_id);
|
||||
}
|
||||
ns_dyn_mem_free(tmpbuf);
|
||||
memory_manager.free(mem);
|
||||
}
|
||||
ns_dyn_mem_free(tmpbuf);
|
||||
memory_manager.free(mem);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
|
@ -106,7 +105,7 @@ int8_t EMACPhy::address_write(phy_address_type_e address_type, uint8_t *address_
|
|||
return 0;
|
||||
}
|
||||
|
||||
int8_t EMACPhy::tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle,data_protocol_e data_flow)
|
||||
int8_t EMACPhy::tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow)
|
||||
{
|
||||
emac_mem_buf_t *mem = memory_manager.alloc_pool(data_len, 0);
|
||||
if (!mem) {
|
||||
|
@ -126,7 +125,7 @@ int8_t EMACPhy::phy_register()
|
|||
|
||||
phy.PHY_MAC = mac_addr;
|
||||
phy.address_write = emac_phy_address_write;
|
||||
phy.driver_description = const_cast<char*>("ETH");
|
||||
phy.driver_description = const_cast<char *>("ETH");
|
||||
phy.link_type = PHY_LINK_ETHERNET_TYPE;
|
||||
phy.phy_MTU = 0;
|
||||
phy.phy_header_length = 0;
|
||||
|
@ -153,9 +152,9 @@ int8_t EMACPhy::phy_register()
|
|||
emac.set_all_multicast(true);
|
||||
|
||||
device_id = arm_net_phy_register(&phy);
|
||||
// driver_readiness_status_callback = driver_status_cb;
|
||||
// driver_readiness_status_callback = driver_status_cb;
|
||||
|
||||
if (device_id < 0){
|
||||
if (device_id < 0) {
|
||||
//tr_error("Ethernet Driver failed to register with Stack. RetCode=%i", eth_driver_enabled);
|
||||
//driver_readiness_status_callback(0, eth_interface_id);
|
||||
emac.power_down();
|
||||
|
@ -188,7 +187,7 @@ nsapi_error_t Nanostack::add_ethernet_interface(EMAC &emac, bool default_if, Nan
|
|||
}
|
||||
|
||||
if (mac_addr) {
|
||||
single_phy->set_mac_address(const_cast<uint8_t*>(mac_addr));
|
||||
single_phy->set_mac_address(const_cast<uint8_t *>(mac_addr));
|
||||
}
|
||||
|
||||
Nanostack::EthernetInterface *interface;
|
||||
|
|
|
@ -44,11 +44,11 @@ nsapi_error_t NanostackEthernetInterface::initialize(NanostackEthernetPhy *phy)
|
|||
}
|
||||
|
||||
return get_interface()->initialize();
|
||||
}
|
||||
}
|
||||
|
||||
nsapi_error_t Nanostack::EthernetInterface::bringup(bool dhcp, const char *ip,
|
||||
const char *netmask, const char *gw,
|
||||
nsapi_ip_stack_t stack, bool blocking)
|
||||
const char *netmask, const char *gw,
|
||||
nsapi_ip_stack_t stack, bool blocking)
|
||||
{
|
||||
if (stack == IPV4_STACK) {
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
#include "mbed_assert.h"
|
||||
#include "NanostackMemoryManager.h"
|
||||
|
||||
struct ns_stack_mem_t
|
||||
{
|
||||
struct ns_stack_mem_t {
|
||||
ns_stack_mem_t *next;
|
||||
void *payload;
|
||||
uint32_t len;
|
||||
|
|
|
@ -7,8 +7,7 @@
|
|||
#include "ns_trace.h"
|
||||
#define TRACE_GROUP "nsth"
|
||||
|
||||
class Nanostack::ThreadInterface : public Nanostack::MeshInterface
|
||||
{
|
||||
class Nanostack::ThreadInterface : public Nanostack::MeshInterface {
|
||||
public:
|
||||
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
|
||||
const char *netmask, const char *gw,
|
||||
|
@ -73,7 +72,7 @@ private:
|
|||
|
||||
Nanostack::ThreadInterface *ThreadInterface::get_interface() const
|
||||
{
|
||||
return static_cast<Nanostack::ThreadInterface*>(_interface);
|
||||
return static_cast<Nanostack::ThreadInterface *>(_interface);
|
||||
}
|
||||
|
||||
nsapi_error_t ThreadInterface::do_initialize()
|
||||
|
|
|
@ -189,7 +189,7 @@ static void enet_tasklet_poll_network_status(void *param)
|
|||
memcpy(tasklet_data_ptr->ip, temp_ipv6, 16);
|
||||
uint8_t temp_ipv6_local[16];
|
||||
if (arm_net_address_get(tasklet_data_ptr->network_interface_id, ADDR_IPV6_LL, temp_ipv6_local) == 0
|
||||
&& (memcmp(temp_ipv6, temp_ipv6_local, 16) != 0)) {
|
||||
&& (memcmp(temp_ipv6, temp_ipv6_local, 16) != 0)) {
|
||||
enet_tasklet_network_state_changed(MESH_CONNECTED_GLOBAL);
|
||||
} else {
|
||||
enet_tasklet_network_state_changed(MESH_CONNECTED_LOCAL);;
|
||||
|
@ -197,8 +197,9 @@ static void enet_tasklet_poll_network_status(void *param)
|
|||
}
|
||||
} else {
|
||||
if (tasklet_data_ptr->connection_status != MESH_DISCONNECTED &&
|
||||
tasklet_data_ptr->connection_status != MESH_BOOTSTRAP_STARTED)
|
||||
tasklet_data_ptr->connection_status != MESH_BOOTSTRAP_STARTED) {
|
||||
enet_tasklet_network_state_changed(MESH_DISCONNECTED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -242,7 +243,7 @@ int8_t enet_tasklet_connect(mesh_interface_cb callback, int8_t nwk_interface_id)
|
|||
|
||||
if (re_connecting == false) {
|
||||
tasklet_data_ptr->tasklet = eventOS_event_handler_create(&enet_tasklet_main,
|
||||
ARM_LIB_TASKLET_INIT_EVENT);
|
||||
ARM_LIB_TASKLET_INIT_EVENT);
|
||||
if (tasklet_data_ptr->tasklet < 0) {
|
||||
// -1 handler already used by other tasklet
|
||||
// -2 memory allocation failure
|
||||
|
|
|
@ -54,7 +54,7 @@ void mesh_system_init(void)
|
|||
{
|
||||
if (mesh_initialized == false) {
|
||||
#if MBED_CONF_MBED_MESH_API_USE_MALLOC_FOR_HEAP
|
||||
app_stack_heap = malloc(MBED_CONF_MBED_MESH_API_HEAP_SIZE+1);
|
||||
app_stack_heap = malloc(MBED_CONF_MBED_MESH_API_HEAP_SIZE + 1);
|
||||
MBED_ASSERT(app_stack_heap);
|
||||
#endif
|
||||
ns_hal_init(app_stack_heap, MBED_CONF_MBED_MESH_API_HEAP_SIZE,
|
||||
|
|
|
@ -214,7 +214,7 @@ void nd_tasklet_parse_network_event(arm_event_s *event)
|
|||
}
|
||||
|
||||
if (tasklet_data_ptr->tasklet_state != TASKLET_STATE_BOOTSTRAP_READY &&
|
||||
tasklet_data_ptr->network_interface_id != INVALID_INTERFACE_ID) {
|
||||
tasklet_data_ptr->network_interface_id != INVALID_INTERFACE_ID) {
|
||||
// Set 5s timer for new network scan
|
||||
eventOS_event_timer_request(TIMER_EVENT_START_BOOTSTRAP,
|
||||
ARM_LIB_SYSTEM_TIMER_EVENT,
|
||||
|
@ -268,15 +268,15 @@ void nd_tasklet_configure_and_connect_to_network(void)
|
|||
tasklet_data_ptr->network_interface_id, NULL);
|
||||
|
||||
arm_nwk_6lowpan_link_panid_filter_for_nwk_scan(
|
||||
tasklet_data_ptr->network_interface_id,
|
||||
MBED_CONF_MBED_MESH_API_6LOWPAN_ND_PANID_FILTER);
|
||||
tasklet_data_ptr->network_interface_id,
|
||||
MBED_CONF_MBED_MESH_API_6LOWPAN_ND_PANID_FILTER);
|
||||
|
||||
// Enable MPL by default
|
||||
const uint8_t all_mpl_forwarders[16] = {0xff, 0x03, [15]=0xfc};
|
||||
const uint8_t all_mpl_forwarders[16] = {0xff, 0x03, [15] = 0xfc};
|
||||
multicast_mpl_domain_subscribe(tasklet_data_ptr->network_interface_id,
|
||||
all_mpl_forwarders,
|
||||
MULTICAST_MPL_SEED_ID_DEFAULT,
|
||||
NULL);
|
||||
all_mpl_forwarders,
|
||||
MULTICAST_MPL_SEED_ID_DEFAULT,
|
||||
NULL);
|
||||
|
||||
status = arm_nwk_interface_up(tasklet_data_ptr->network_interface_id);
|
||||
if (status >= 0) {
|
||||
|
@ -327,7 +327,7 @@ void nd_tasklet_trace_bootstrap_info()
|
|||
tr_error("MAC Address read fail\n");
|
||||
} else {
|
||||
uint8_t temp[2];
|
||||
common_write_16_bit(app_link_address_info.mac_short,temp);
|
||||
common_write_16_bit(app_link_address_info.mac_short, temp);
|
||||
tr_debug("MAC 16-bit: %s", trace_array(temp, 2));
|
||||
common_write_16_bit(app_link_address_info.PANId, temp);
|
||||
tr_debug("PAN ID: %s", trace_array(temp, 2));
|
||||
|
@ -378,7 +378,7 @@ int8_t nd_tasklet_connect(mesh_interface_cb callback, int8_t nwk_interface_id)
|
|||
|
||||
if (re_connecting == false) {
|
||||
tasklet_data_ptr->tasklet = eventOS_event_handler_create(&nd_tasklet_main,
|
||||
ARM_LIB_TASKLET_INIT_EVENT);
|
||||
ARM_LIB_TASKLET_INIT_EVENT);
|
||||
if (tasklet_data_ptr->tasklet < 0) {
|
||||
// -1 handler already used by other tasklet
|
||||
// -2 memory allocation failure
|
||||
|
|
|
@ -218,7 +218,7 @@ void thread_tasklet_parse_network_event(arm_event_s *event)
|
|||
}
|
||||
|
||||
if (thread_tasklet_data_ptr->tasklet_state != TASKLET_STATE_BOOTSTRAP_READY &&
|
||||
thread_tasklet_data_ptr->nwk_if_id != INVALID_INTERFACE_ID) {
|
||||
thread_tasklet_data_ptr->nwk_if_id != INVALID_INTERFACE_ID) {
|
||||
// Set 5s timer for a new network scan
|
||||
eventOS_event_timer_request(TIMER_EVENT_START_BOOTSTRAP,
|
||||
ARM_LIB_SYSTEM_TIMER_EVENT,
|
||||
|
@ -246,23 +246,25 @@ void thread_tasklet_poll_network_status(void *param)
|
|||
}
|
||||
} else {
|
||||
if (thread_tasklet_data_ptr->connection_status != MESH_DISCONNECTED &&
|
||||
thread_tasklet_data_ptr->connection_status != MESH_BOOTSTRAP_STARTED)
|
||||
thread_tasklet_data_ptr->connection_status != MESH_BOOTSTRAP_STARTED) {
|
||||
thread_tasklet_network_state_changed(MESH_DISCONNECTED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void read_link_configuration() {
|
||||
void read_link_configuration()
|
||||
{
|
||||
|
||||
thread_tasklet_data_ptr->link_config.panId = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_PANID;
|
||||
TRACE_DETAIL("PANID %x", thread_tasklet_data_ptr->link_config.panId);
|
||||
|
||||
thread_tasklet_data_ptr->link_config.rfChannel = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_CHANNEL;
|
||||
TRACE_DETAIL("channel: %d", thread_tasklet_data_ptr->link_config.rfChannel);
|
||||
|
||||
|
||||
// Mesh prefix
|
||||
const uint8_t mesh_local_prefix[] = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_ML_PREFIX;
|
||||
MBED_ASSERT(sizeof(mesh_local_prefix) == 8);
|
||||
|
||||
|
||||
memcpy(thread_tasklet_data_ptr->link_config.mesh_local_ula_prefix, mesh_local_prefix, 8);
|
||||
TRACE_DETAIL("Mesh prefix: %s", trace_array(mesh_local_prefix, 8));
|
||||
|
||||
|
@ -279,14 +281,14 @@ void read_link_configuration() {
|
|||
thread_tasklet_data_ptr->link_config.key_rotation = 3600;
|
||||
thread_tasklet_data_ptr->link_config.key_sequence = 0;
|
||||
|
||||
thread_tasklet_data_ptr->link_config.securityPolicy = MBED_CONF_MBED_MESH_API_THREAD_SECURITY_POLICY;
|
||||
|
||||
thread_tasklet_data_ptr->link_config.securityPolicy = MBED_CONF_MBED_MESH_API_THREAD_SECURITY_POLICY;
|
||||
|
||||
// network name
|
||||
MBED_ASSERT(strlen(MBED_CONF_MBED_MESH_API_THREAD_CONFIG_NETWORK_NAME) > 0 && strlen(MBED_CONF_MBED_MESH_API_THREAD_CONFIG_NETWORK_NAME) < 17);
|
||||
memcpy(thread_tasklet_data_ptr->link_config.name, MBED_CONF_MBED_MESH_API_THREAD_CONFIG_NETWORK_NAME, strlen(MBED_CONF_MBED_MESH_API_THREAD_CONFIG_NETWORK_NAME));
|
||||
|
||||
|
||||
thread_tasklet_data_ptr->link_config.timestamp = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_COMMISSIONING_DATASET_TIMESTAMP;
|
||||
|
||||
|
||||
// extended pan-id
|
||||
const uint8_t extented_panid[] = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_EXTENDED_PANID;
|
||||
MBED_ASSERT(sizeof(extented_panid) == 8);
|
||||
|
@ -300,13 +302,12 @@ void read_link_configuration() {
|
|||
void thread_tasklet_configure_and_connect_to_network(void)
|
||||
{
|
||||
int8_t status;
|
||||
link_configuration_s* temp_link_config=NULL;
|
||||
link_configuration_s *temp_link_config = NULL;
|
||||
|
||||
|
||||
if (MBED_CONF_MBED_MESH_API_THREAD_DEVICE_TYPE == MESH_DEVICE_TYPE_THREAD_MINIMAL_END_DEVICE) {
|
||||
thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_HOST;
|
||||
}
|
||||
else if (MBED_CONF_MBED_MESH_API_THREAD_DEVICE_TYPE == MESH_DEVICE_TYPE_THREAD_SLEEPY_END_DEVICE) {
|
||||
thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_HOST;
|
||||
} else if (MBED_CONF_MBED_MESH_API_THREAD_DEVICE_TYPE == MESH_DEVICE_TYPE_THREAD_SLEEPY_END_DEVICE) {
|
||||
thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_SLEEPY_HOST;
|
||||
} else {
|
||||
thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_ROUTER;
|
||||
|
@ -316,16 +317,16 @@ void thread_tasklet_configure_and_connect_to_network(void)
|
|||
thread_tasklet_data_ptr->nwk_if_id,
|
||||
thread_tasklet_data_ptr->operating_mode,
|
||||
NET_6LOWPAN_THREAD);
|
||||
|
||||
|
||||
thread_tasklet_data_ptr->channel_list.channel_page = (channel_page_e)MBED_CONF_MBED_MESH_API_THREAD_CONFIG_CHANNEL_PAGE;
|
||||
thread_tasklet_data_ptr->channel_list.channel_mask[0] = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_CHANNEL_MASK;
|
||||
|
||||
|
||||
TRACE_DETAIL("channel page: %d", thread_tasklet_data_ptr->channel_list.channel_page);
|
||||
TRACE_DETAIL("channel mask: 0x%.8lx", thread_tasklet_data_ptr->channel_list.channel_mask[0]);
|
||||
|
||||
// PSKd
|
||||
const char PSKd[] = MBED_CONF_MBED_MESH_API_THREAD_PSKD;
|
||||
if(device_configuration.PSKd_len==0) {
|
||||
if (device_configuration.PSKd_len == 0) {
|
||||
int ret = thread_tasklet_device_pskd_set(PSKd);
|
||||
MBED_ASSERT(!ret);
|
||||
}
|
||||
|
@ -334,11 +335,11 @@ void thread_tasklet_configure_and_connect_to_network(void)
|
|||
read_link_configuration();
|
||||
temp_link_config = &thread_tasklet_data_ptr->link_config;
|
||||
}
|
||||
|
||||
|
||||
thread_management_node_init(thread_tasklet_data_ptr->nwk_if_id,
|
||||
&thread_tasklet_data_ptr->channel_list,
|
||||
&device_configuration,
|
||||
temp_link_config);
|
||||
&thread_tasklet_data_ptr->channel_list,
|
||||
&device_configuration,
|
||||
temp_link_config);
|
||||
|
||||
status = arm_nwk_interface_up(thread_tasklet_data_ptr->nwk_if_id);
|
||||
|
||||
|
@ -382,7 +383,7 @@ void thread_tasklet_trace_bootstrap_info()
|
|||
tr_error("MAC Address read fail\n");
|
||||
} else {
|
||||
uint8_t temp[2];
|
||||
common_write_16_bit(app_link_address_info.mac_short,temp);
|
||||
common_write_16_bit(app_link_address_info.mac_short, temp);
|
||||
tr_debug("MAC 16-bit: %s", trace_array(temp, 2));
|
||||
common_write_16_bit(app_link_address_info.PANId, temp);
|
||||
tr_debug("PAN ID: %s", trace_array(temp, 2));
|
||||
|
@ -414,12 +415,12 @@ int8_t thread_tasklet_connect(mesh_interface_cb callback, int8_t nwk_interface_i
|
|||
|
||||
if (re_connecting == false) {
|
||||
thread_tasklet_data_ptr->tasklet = eventOS_event_handler_create(&thread_tasklet_main,
|
||||
ARM_LIB_TASKLET_INIT_EVENT);
|
||||
ARM_LIB_TASKLET_INIT_EVENT);
|
||||
if (thread_tasklet_data_ptr->tasklet < 0) {
|
||||
// -1 handler already used by other tasklet
|
||||
// -2 memory allocation failure
|
||||
return thread_tasklet_data_ptr->tasklet;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
thread_tasklet_data_ptr->tasklet = tasklet;
|
||||
mesh_system_send_connect_event(thread_tasklet_data_ptr->tasklet);
|
||||
|
@ -486,16 +487,16 @@ void thread_tasklet_device_eui64_get(uint8_t *eui64)
|
|||
uint8_t thread_tasklet_device_pskd_set(const char *pskd)
|
||||
{
|
||||
int len = strlen(pskd);
|
||||
if(len < 6 || len > 32) {
|
||||
if (len < 6 || len > 32) {
|
||||
return MESH_ERROR_PARAM;
|
||||
}
|
||||
char *dyn_buf = ns_dyn_mem_alloc(strlen(pskd)+1);
|
||||
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_ptr = (uint8_t *)dyn_buf;
|
||||
device_configuration.PSKd_len = strlen(pskd);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue