├── drivers ├── .gitignore ├── TARGET_NUCLEO_F429ZI │ └── .gitignore ├── stm-spirit1-rf-driver.lib ├── sal-stack-nanostack-slip.lib ├── TARGET_MCUXpresso_MCUS │ └── sal-nanostack-driver-k64f-eth.lib ├── rf_wrapper.h ├── eth_driver.h └── rf_wrapper.cpp ├── mbed-os.lib ├── images ├── br_role.png ├── structure.png └── BorderRouter.png ├── custom_targets.json ├── source ├── nanostack_heap_region.h ├── borderrouter_helpers.h ├── cfg_parser.h ├── cfg_parser.c ├── thread_bbr_ext.h ├── borderrouter_tasklet.h ├── thread_br_conn_handler.h ├── nanostack_heap_region.c ├── borderrouter_helpers.c ├── static_6lowpan_config.h ├── thread_br_conn_handler.c ├── wisun_certificates.h ├── mbedtls_wisun_config.h ├── mbedtls_thread_config.h ├── border_router_main.cpp ├── borderrouter_thread_tasklet.c ├── borderrouter_ws.c └── borderrouter_tasklet.c ├── CONTRIBUTING.md ├── .github └── ISSUE_TEMPLATE │ └── bug_report.md ├── configs ├── Thread_SLIP_Atmel_RF.json ├── Wisun_Stm_s2lp_RF_lab.json ├── Thread_Atmel_RF.json ├── 6lowpan_Spirit1_RF.json ├── Wisun_Stm_s2lp_RF.json ├── Wisun_Stm_s2lp_RF_cell.json └── 6lowpan_Atmel_RF.json ├── Jenkinsfile ├── mbed_app.json ├── LICENSE └── README.md /drivers/.gitignore: -------------------------------------------------------------------------------- 1 | stm-spirit1-rf-driver 2 | stm-spirit1-rf-driver/* 3 | -------------------------------------------------------------------------------- /mbed-os.lib: -------------------------------------------------------------------------------- 1 | https://github.com/ARMmbed/mbed-os/#26606218ad9d1ee1c8781aa73774fd7ea3a7658e 2 | 3 | -------------------------------------------------------------------------------- /images/br_role.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PelionIoT/nanostack-border-router/HEAD/images/br_role.png -------------------------------------------------------------------------------- /drivers/TARGET_NUCLEO_F429ZI/.gitignore: -------------------------------------------------------------------------------- 1 | sal-nanostack-driver-stm32-eth 2 | sal-nanostack-driver-stm32-eth/* 3 | -------------------------------------------------------------------------------- /images/structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PelionIoT/nanostack-border-router/HEAD/images/structure.png -------------------------------------------------------------------------------- /images/BorderRouter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PelionIoT/nanostack-border-router/HEAD/images/BorderRouter.png -------------------------------------------------------------------------------- /drivers/stm-spirit1-rf-driver.lib: -------------------------------------------------------------------------------- 1 | https://github.com/ARMmbed/stm-spirit1-rf-driver/#874f44bba39c9e7558be431111eac44005adf4fa 2 | -------------------------------------------------------------------------------- /drivers/sal-stack-nanostack-slip.lib: -------------------------------------------------------------------------------- 1 | https://github.com/ARMmbed/sal-stack-nanostack-slip/#9e3472988a09c19cba5eaab9a99f344201873adc 2 | -------------------------------------------------------------------------------- /drivers/TARGET_MCUXpresso_MCUS/sal-nanostack-driver-k64f-eth.lib: -------------------------------------------------------------------------------- 1 | https://github.com/ARMmbed/sal-nanostack-driver-k64f-eth/#ff449f25399250863e4186970e689177bfd1a883 2 | -------------------------------------------------------------------------------- /custom_targets.json: -------------------------------------------------------------------------------- 1 | { 2 | "DISCO_F769NI_STATIC_BR": { 3 | "inherits" : ["DISCO_F769NI"] 4 | }, 5 | "K64F_STATIC_BR": { 6 | "inherits" : ["K64F"] 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /drivers/rf_wrapper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017, Pelion and affiliates. 3 | */ 4 | 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | int8_t rf_device_register(void); 12 | void rf_read_mac_address(uint8_t *mac); 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | -------------------------------------------------------------------------------- /source/nanostack_heap_region.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Pelion and affiliates. 3 | */ 4 | 5 | #ifndef NANOSTACK_HEAP_REGION_H 6 | #define NANOSTACK_HEAP_REGION_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" 10 | { 11 | #endif 12 | 13 | void nanostack_heap_region_add(void); 14 | 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif /* NANOSTACK_HEAP_REGION_H */ 21 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Mbed OS 2 | 3 | Mbed OS is an open-source, device software platform for the Internet of Things. Contributions are an important part of the platform, and our goal is to make it as simple as possible to become a contributor. 4 | 5 | To encourage productive collaboration, as well as robust, consistent and maintainable code, we have a set of guidelines for [contributing to Mbed OS](https://os.mbed.com/docs/mbed-os/latest/contributing/index.html). 6 | -------------------------------------------------------------------------------- /source/borderrouter_helpers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018, Pelion and affiliates. 3 | */ 4 | 5 | 6 | #ifndef BORDERROUTER_HELPERS_H 7 | #define BORDERROUTER_HELPERS_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | 14 | char *print_ipv6(const void *addr_ptr); 15 | char *print_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len); 16 | void print_memory_stats(void); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif /* BORDERROUTER_HELPERS_H */ 23 | -------------------------------------------------------------------------------- /drivers/eth_driver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Pelion and affiliates. 3 | */ 4 | #ifndef ETH_DRIVER_H 5 | #define ETH_DRIVER_H 6 | 7 | /** 8 | * Initialize Ethernet PHY driver and register itself to MAC. 9 | * 10 | * Must follow C calling conventions. 11 | * 12 | * \param mac_ptr Pointer to EIU-48 address 13 | * \param app_ipv6_init_cb Callback to receive link status and interface id 14 | */ 15 | 16 | 17 | extern "C" void arm_eth_phy_device_register(uint8_t *mac_ptr, void (*app_ipv6_init_cb)(uint8_t, int8_t)); 18 | 19 | #endif -------------------------------------------------------------------------------- /source/cfg_parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017, Pelion and affiliates. 3 | */ 4 | #ifndef CFG_PARSER_H 5 | #define CFG_PARSER_H 6 | 7 | typedef struct conf_t { 8 | const char *name; 9 | const char *svalue; 10 | const int ivalue; 11 | } conf_t; 12 | 13 | #define STR_HELPER(x) #x 14 | #define STR(x) STR_HELPER(x) 15 | 16 | extern conf_t *global_config; 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | const char *cfg_string(conf_t *conf, const char *key, const char *default_value); 24 | int cfg_int(conf_t *conf, const char *key, int default_value); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | #endif /* CFG_PARSER_H */ 30 | -------------------------------------------------------------------------------- /source/cfg_parser.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017, Pelion and affiliates. 3 | */ 4 | 5 | #include 6 | #include "cfg_parser.h" 7 | 8 | const char *cfg_string(conf_t *conf, const char *key, const char *default_value) 9 | { 10 | for (; (conf && conf->name); conf++) { 11 | if (0 == strcmp(conf->name, key)) { 12 | return conf->svalue; 13 | } 14 | } 15 | return default_value; 16 | } 17 | 18 | int cfg_int(conf_t *conf, const char *key, int default_value) 19 | { 20 | for (; (conf && conf->name); conf++) { 21 | if (0 == strcmp(conf->name, key)) { 22 | return conf->ivalue; 23 | } 24 | } 25 | return default_value; 26 | } 27 | -------------------------------------------------------------------------------- /source/thread_bbr_ext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, Pelion and affiliates. 3 | */ 4 | 5 | #ifndef _THREAD_BBR_EXT_ 6 | #define _THREAD_BBR_EXT_ 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #if MBED_CONF_APP_THREAD_BBR_EXTENSION == 1 13 | 14 | #include "../../thread_bbr_extension/thread_bbr_extension.h" 15 | 16 | #else 17 | 18 | #define thread_bbr_extension_mesh_interface_updated_ntf(thread_interface_id); 19 | #define thread_bbr_extension_bb_interface_updated_ntf(bb_interface_id); 20 | #define thread_bbr_extension_start(thread_interface_id, bb_interface_id); 21 | 22 | #endif // MBED_CONF_APP_THREAD_BBR_EXTENSION 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | #endif /* _THREAD_BBR_EXT_ */ 28 | 29 | -------------------------------------------------------------------------------- /source/borderrouter_tasklet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018, Pelion and affiliates. 3 | */ 4 | 5 | 6 | #ifndef BORDERROUTER_TASKLET_H 7 | #define BORDERROUTER_TASKLET_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | 14 | /** 15 | * Initializes the backhaul driver. MUST be implemented by the application. 16 | */ 17 | void backhaul_driver_init(void (*backhaul_driver_status_cb)(uint8_t, int8_t)); 18 | 19 | /** 20 | * Trace application details 21 | */ 22 | void appl_info_trace(void); 23 | 24 | /** 25 | * Initializes the border router module: loads configuration and 26 | * initiates bootstrap for the RF 6LoWPAN and backhaul interfaces. 27 | */ 28 | void border_router_tasklet_start(void); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif /* BORDERROUTER_TASKLET_H */ 35 | -------------------------------------------------------------------------------- /source/thread_br_conn_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018, Pelion and affiliates. 3 | */ 4 | 5 | #ifndef thread_br_conn_handler_H_ 6 | #define thread_br_conn_handler_H_ 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #include "ns_types.h" 13 | 14 | void thread_br_conn_handler_init(void); 15 | void thread_br_conn_handler_thread_connection_update(bool status); 16 | void thread_br_conn_handler_ethernet_connection_update(bool status); 17 | 18 | // Tells that ethernet connection is ready and the prefix can be read and set. 19 | void thread_br_conn_handler_eth_ready(void); 20 | // Setters 21 | void thread_br_conn_handler_thread_interface_id_set(int8_t interfaceId); 22 | void thread_br_conn_handler_eth_interface_id_set(int8_t interfaceId); 23 | 24 | // Getters thread_br_conn_handler 25 | bool thread_br_conn_handler_eth_connection_status_get(void); 26 | bool thread_br_conn_handler_thread_connection_status_get(void); 27 | int8_t thread_br_conn_handler_thread_interface_id_get(void); 28 | int8_t thread_br_conn_handler_eth_interface_id_get(void); 29 | 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | #endif /* thread_br_conn_handler_H_ */ 35 | 36 | -------------------------------------------------------------------------------- /source/nanostack_heap_region.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Pelion and affiliates. 3 | */ 4 | 5 | #include "nsdynmemLIB.h" 6 | 7 | /* Enable nanostack extended heap only for specific targets and toolchains */ 8 | #if (MBED_CONF_APP_NANOSTACK_EXTENDED_HEAP == true) 9 | 10 | #if defined(TARGET_K64F) 11 | #define NANOSTACK_EXTENDED_HEAP_REGION_SIZE (60*1024) 12 | #endif 13 | 14 | #if defined(TARGET_NUCLEO_F429ZI) 15 | #define NANOSTACK_EXTENDED_HEAP_REGION_SIZE (60*1024) 16 | #endif 17 | 18 | #if defined(TARGET_DISCO_F769NI) 19 | #define NANOSTACK_EXTENDED_HEAP_REGION_SIZE (250*1024) 20 | #endif 21 | 22 | #if defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ASM__) || defined(__ICCARM__) 23 | // currently - no IAR suport 24 | #undef NANOSTACK_EXTENDED_HEAP_REGION_SIZE 25 | #endif 26 | 27 | #endif // MBED_CONF_APP_NANOSTACK_EXTENDED_HEAP 28 | 29 | 30 | #ifdef NANOSTACK_EXTENDED_HEAP_REGION_SIZE 31 | 32 | // Heap region for GCC_ARM, ARMCC and ARMCLANG 33 | static uint8_t nanostack_extended_heap_region[NANOSTACK_EXTENDED_HEAP_REGION_SIZE]; 34 | 35 | void nanostack_heap_region_add(void) 36 | { 37 | ns_dyn_mem_region_add(nanostack_extended_heap_region, NANOSTACK_EXTENDED_HEAP_REGION_SIZE); 38 | } 39 | 40 | #else // NANOSTACK_EXTENDED_HEAP_REGION_SIZE 41 | 42 | void nanostack_heap_region_add(void) 43 | { 44 | } 45 | 46 | #endif // NANOSTACK_EXTENDED_HEAP_REGION_SIZE 47 | -------------------------------------------------------------------------------- /source/borderrouter_helpers.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018, Pelion and affiliates. 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "ip6string.h" 10 | #include "ns_types.h" 11 | #include "common_functions.h" 12 | #include "ns_trace.h" 13 | #include "nsdynmemLIB.h" 14 | #define TRACE_GROUP "app" 15 | 16 | static char tmp_print_buffer[128] = {0}; 17 | 18 | char *print_ipv6(const void *addr_ptr) 19 | { 20 | ip6tos(addr_ptr, tmp_print_buffer); 21 | return tmp_print_buffer; 22 | } 23 | 24 | char *print_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len) 25 | { 26 | char *str = tmp_print_buffer; 27 | int retval; 28 | char tmp[40]; 29 | uint8_t addr[16] = {0}; 30 | 31 | if (prefix_len != 0) { 32 | if (prefix == NULL || prefix_len > 128) { 33 | return ""; 34 | } 35 | bitcopy(addr, prefix, prefix_len); 36 | } 37 | 38 | ip6tos(addr, tmp); 39 | retval = snprintf(str, 128, "%s/%u", tmp, prefix_len); 40 | if (retval <= 0) { 41 | return ""; 42 | } 43 | return str; 44 | } 45 | 46 | void print_memory_stats(void) 47 | { 48 | const mem_stat_t *heap_info = ns_dyn_mem_get_mem_stat(); 49 | if (heap_info) { 50 | tr_info( 51 | "Heap size: %lu, Reserved: %lu, Reserved max: %lu, Alloc fail: %lu" 52 | , (unsigned long)heap_info->heap_sector_size 53 | , (unsigned long)heap_info->heap_sector_allocated_bytes 54 | , (unsigned long)heap_info->heap_sector_allocated_bytes_max 55 | , (unsigned long)heap_info->heap_alloc_fail_cnt); 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /drivers/rf_wrapper.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018, Pelion and affiliates. 3 | */ 4 | 5 | #include "rf_wrapper.h" 6 | 7 | // Must be defined for next preprocessor tests to work 8 | #define ATMEL 0 9 | #define MCR20 1 10 | #define NCS36510 2 11 | #define SPIRIT1 3 12 | #define S2LP 4 13 | 14 | #if MBED_CONF_APP_RADIO_TYPE == ATMEL 15 | #include "NanostackRfPhyAtmel.h" 16 | NanostackRfPhyAtmel rf_phy(ATMEL_SPI_MOSI, ATMEL_SPI_MISO, ATMEL_SPI_SCLK, ATMEL_SPI_CS, 17 | ATMEL_SPI_RST, ATMEL_SPI_SLP, ATMEL_SPI_IRQ, ATMEL_I2C_SDA, ATMEL_I2C_SCL); 18 | #elif MBED_CONF_APP_RADIO_TYPE == MCR20 19 | #include "NanostackRfPhyMcr20a.h" 20 | NanostackRfPhyMcr20a rf_phy(MCR20A_SPI_MOSI, MCR20A_SPI_MISO, MCR20A_SPI_SCLK, MCR20A_SPI_CS, MCR20A_SPI_RST, MCR20A_SPI_IRQ); 21 | #elif MBED_CONF_APP_RADIO_TYPE == SPIRIT1 22 | #include "NanostackRfPhySpirit1.h" 23 | NanostackRfPhySpirit1 rf_phy(SPIRIT1_SPI_MOSI, SPIRIT1_SPI_MISO, SPIRIT1_SPI_SCLK, 24 | SPIRIT1_DEV_IRQ, SPIRIT1_DEV_CS, SPIRIT1_DEV_SDN, SPIRIT1_BRD_LED); 25 | #elif MBED_CONF_APP_RADIO_TYPE == S2LP 26 | #include "NanostackRfPhys2lp.h" 27 | NanostackRfPhys2lp rf_phy(S2LP_SPI_SDI, S2LP_SPI_SDO, S2LP_SPI_SCLK, S2LP_SPI_CS, S2LP_SPI_SDN, 28 | #ifdef TEST_GPIOS_ENABLED 29 | S2LP_SPI_TEST1, S2LP_SPI_TEST2, S2LP_SPI_TEST3, S2LP_SPI_TEST4, S2LP_SPI_TEST5, 30 | #endif //TEST_GPIOS_ENABLED 31 | S2LP_SPI_GPIO0, S2LP_SPI_GPIO1, S2LP_SPI_GPIO2, S2LP_SPI_GPIO3); 32 | #endif //MBED_CONF_APP_RADIO_TYPE 33 | 34 | extern "C" int8_t rf_device_register() 35 | { 36 | return rf_phy.rf_register(); 37 | } 38 | 39 | extern "C" void rf_read_mac_address(uint8_t *mac) 40 | { 41 | rf_phy.get_mac_address(mac); 42 | } 43 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: 'type: bug' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 28 | 29 | ### Description of defect 30 | 31 | 35 | 36 | 37 | #### Target(s) affected by this defect ? 38 | 39 | 40 | #### Toolchain(s) (name and version) displaying this defect ? 41 | 42 | 43 | #### What version of Mbed-os are you using (tag or sha) ? 44 | 53 | 54 | 55 | #### What version(s) of tools are you using. List all that apply (E.g. mbed-cli) 56 | 57 | 58 | #### How is this defect reproduced ? 59 | -------------------------------------------------------------------------------- /source/static_6lowpan_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2017, Pelion and affiliates. 3 | */ 4 | 5 | 6 | #ifndef STATIC_6LOWPAN_CONFIG 7 | #define STATIC_6LOWPAN_CONFIG 8 | 9 | #include "cfg_parser.h" 10 | 11 | static const char psk_key[16] = MBED_CONF_APP_PSK_KEY; 12 | static const char tls_psk_key[16] = MBED_CONF_APP_TLS_PSK_KEY; 13 | 14 | static conf_t mbed_config[] = { 15 | /* NAME, STRING_VALUE, INT_VALUE */ 16 | {"SECURITY_MODE", STR(MBED_CONF_APP_SECURITY_MODE), 0}, 17 | {"PANA_MODE", STR(MBED_CONF_APP_PANA_MODE), 0}, 18 | {"PSK_KEY", psk_key, 0}, 19 | {"PSK_KEY_ID", NULL, MBED_CONF_APP_PSK_KEY_ID}, 20 | {"PAN_ID", NULL, MBED_CONF_APP_PAN_ID}, 21 | {"NETWORK_ID", STR(MBED_CONF_APP_NETWORK_ID), 0}, 22 | {"PREFIX", STR(MBED_CONF_APP_PREFIX), 0}, 23 | {"BACKHAUL_PREFIX", STR(MBED_CONF_APP_BACKHAUL_PREFIX), 0}, 24 | {"BACKHAUL_DEFAULT_ROUTE", STR(MBED_CONF_APP_BACKHAUL_DEFAULT_ROUTE), 0}, 25 | {"BACKHAUL_NEXT_HOP", STR(MBED_CONF_APP_BACKHAUL_NEXT_HOP), 0}, 26 | {"RF_CHANNEL", NULL, MBED_CONF_APP_RF_CHANNEL}, 27 | {"RF_CHANNEL_PAGE", NULL, MBED_CONF_APP_RF_CHANNEL_PAGE}, 28 | {"RF_CHANNEL_MASK", NULL, MBED_CONF_APP_RF_CHANNEL_MASK}, 29 | {"RPL_INSTANCE_ID", NULL, MBED_CONF_APP_RPL_INSTANCE_ID}, 30 | {"RPL_IDOUBLINGS", NULL, MBED_CONF_APP_RPL_IDOUBLINGS}, 31 | {"RPL_K", NULL, MBED_CONF_APP_RPL_K}, 32 | {"RPL_MAX_RANK_INC", NULL, MBED_CONF_APP_RPL_MAX_RANK_INC}, 33 | {"RPL_MIN_HOP_RANK_INC", NULL, MBED_CONF_APP_RPL_MIN_HOP_RANK_INC}, 34 | {"RPL_IMIN", NULL, MBED_CONF_APP_RPL_IMIN}, 35 | {"RPL_DEFAULT_LIFETIME", NULL, MBED_CONF_APP_RPL_DEFAULT_LIFETIME}, 36 | {"RPL_LIFETIME_UNIT", NULL, MBED_CONF_APP_RPL_LIFETIME_UNIT}, 37 | {"RPL_PCS", NULL, MBED_CONF_APP_RPL_PCS}, 38 | {"RPL_OCP", NULL, MBED_CONF_APP_RPL_OCP}, 39 | {"RA_ROUTER_LIFETIME", NULL, MBED_CONF_APP_RA_ROUTER_LIFETIME}, 40 | {"BEACON_PROTOCOL_ID", NULL, MBED_CONF_APP_BEACON_PROTOCOL_ID}, 41 | {"TLS_PSK_KEY", tls_psk_key, 0}, 42 | {"TLS_PSK_KEY_ID", NULL, MBED_CONF_APP_TLS_PSK_KEY_ID}, 43 | {"BACKHAUL_DYNAMIC_BOOTSTRAP", NULL, MBED_CONF_APP_BACKHAUL_DYNAMIC_BOOTSTRAP}, 44 | {"SHORT_MAC_ADDRESS", NULL, MBED_CONF_APP_SHORT_MAC_ADDRESS}, 45 | {"MULTICAST_ADDR", STR(MBED_CONF_APP_MULTICAST_ADDR), 0}, 46 | {"PREFIX_FROM_BACKHAUL", NULL, MBED_CONF_APP_PREFIX_FROM_BACKHAUL}, 47 | /* Array must end on {NULL, NULL, 0} field */ 48 | {NULL, NULL, 0} 49 | }; 50 | conf_t *global_config = mbed_config; 51 | 52 | #endif //STATIC_6LOWPAN_CONFIG 53 | -------------------------------------------------------------------------------- /source/thread_br_conn_handler.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018, Pelion and affiliates. 3 | */ 4 | 5 | #include 6 | #include "net_interface.h" 7 | #include "mbed-trace/mbed_trace.h" 8 | #include "thread_bbr_api.h" 9 | #include "thread_border_router_api.h" 10 | #include "thread_br_conn_handler.h" 11 | #include "thread_dhcpv6_server.h" 12 | #include "borderrouter_helpers.h" 13 | #include "common_functions.h" 14 | #include "eventOS_event_timer.h" 15 | #include "thread_bbr_ext.h" 16 | #include "multicast_api.h" 17 | 18 | #define TRACE_GROUP "TBRH" 19 | 20 | typedef struct { 21 | 22 | int8_t thread_interface_id; 23 | int8_t eth_interface_id; 24 | bool eth_connection_ready; 25 | bool thread_connection_ready; 26 | } thread_br_handler_t; 27 | 28 | static thread_br_handler_t thread_br_handler; 29 | 30 | void thread_br_conn_handler_init(void) 31 | { 32 | thread_br_handler.thread_interface_id = -1; 33 | thread_br_handler.thread_connection_ready = 0; 34 | 35 | thread_br_handler.eth_interface_id = -1; 36 | thread_br_handler.eth_connection_ready = 0; 37 | } 38 | 39 | void thread_br_conn_handler_thread_connection_update(bool status) 40 | { 41 | thread_br_handler.thread_connection_ready = status; 42 | tr_debug("mesh0 connection status: %d", status); 43 | 44 | } 45 | 46 | void thread_br_conn_handler_ethernet_connection_update(bool status) 47 | { 48 | thread_br_handler.eth_connection_ready = status; 49 | tr_debug("Eth0 connection status: %d", status); 50 | 51 | } 52 | 53 | void thread_br_conn_handler_thread_interface_id_set(int8_t interfaceId) 54 | { 55 | thread_br_handler.thread_interface_id = interfaceId; 56 | thread_bbr_extension_mesh_interface_updated_ntf(thread_br_handler.thread_interface_id); 57 | if (thread_br_handler.thread_interface_id > -1 && thread_br_handler.eth_interface_id > -1) { 58 | thread_bbr_start(thread_br_handler.thread_interface_id, thread_br_handler.eth_interface_id); 59 | } 60 | } 61 | 62 | int8_t thread_br_conn_handler_thread_interface_id_get(void) 63 | { 64 | return thread_br_handler.thread_interface_id; 65 | } 66 | 67 | bool thread_br_conn_handler_eth_connection_status_get(void) 68 | { 69 | return thread_br_handler.eth_connection_ready; 70 | } 71 | 72 | bool thread_br_conn_handler_thread_connection_status_get(void) 73 | { 74 | return thread_br_handler.thread_connection_ready; 75 | } 76 | 77 | void thread_br_conn_handler_eth_interface_id_set(int8_t interfaceId) 78 | { 79 | thread_br_handler.eth_interface_id = interfaceId; 80 | thread_bbr_extension_bb_interface_updated_ntf(thread_br_handler.eth_interface_id); 81 | if (thread_br_handler.thread_interface_id > -1 && thread_br_handler.eth_interface_id > -1) { 82 | thread_bbr_start(thread_br_handler.thread_interface_id, thread_br_handler.eth_interface_id); 83 | } 84 | } 85 | 86 | int8_t thread_br_conn_handler_eth_interface_id_get(void) 87 | { 88 | return thread_br_handler.eth_interface_id; 89 | } 90 | -------------------------------------------------------------------------------- /configs/Thread_SLIP_Atmel_RF.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "radio-type":{ 4 | "help": "options are ATMEL, MCR20", 5 | "value": "ATMEL" 6 | }, 7 | "backhaul-driver": { 8 | "help": "options are ETH, SLIP, EMAC, CELL", 9 | "value": "SLIP" 10 | }, 11 | "mesh-mode": { 12 | "help": "Mesh networking mode. Options are LOWPAN_ND and THREAD", 13 | "value": "THREAD" 14 | }, 15 | "backhaul-mac-src": { 16 | "help": "Where to get EUI48 address. Options are BOARD, CONFIG", 17 | "value": "BOARD" 18 | }, 19 | "backhaul-mld": { 20 | "help": "Enable proxying Multicast Listener Discovery messages to backhaul network", 21 | "value": "false" 22 | }, 23 | "nanostack_extended_heap": { 24 | "help": "Add additional memory region to nanostack heap. Valid only for selected platforms. Region size may vary depending of the toolchain.", 25 | "value": false 26 | }, 27 | "backhaul-mac": "{0x02, 0x00, 0x00, 0x00, 0x00, 0x01}", 28 | "slip_hw_flow_control": "true", 29 | "slip_serial_baud_rate": "921600", 30 | "rf-channel": 22, 31 | "rf-channel-page": 0, 32 | "rf-channel-mask": "0x07fff800", 33 | "debug-trace": 1, 34 | "backhaul-dynamic-bootstrap": true, 35 | "backhaul-prefix": "\"fd00:300::\"", 36 | "backhaul-next-hop": "\"fe80::1\"", 37 | "backhaul-default-route": "\"::/0\"", 38 | "commissioning-dataset-timestamp": "0x00010000", 39 | "pan-id": "0x0700", 40 | "extended-pan-id": "{0xf1, 0xb5, 0xa1, 0xb2,0xc4, 0xd5, 0xa1, 0xbd }", 41 | "mesh-local-prefix": "{0xfd, 0x0, 0x0d, 0xb8, 0x0, 0x0, 0x0, 0x0}", 42 | "network-name": "\"Thread Network\"", 43 | "pskd": "\"ABCDEFGH\"", 44 | "pskc": "{0xc8, 0xa6, 0x2e, 0xae, 0xf3, 0x68, 0xf3, 0x46, 0xa9, 0x9e, 0x57, 0x85, 0x98, 0x9d, 0x1c, 0xd0}", 45 | "thread-master-key": "{0x10, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}", 46 | "thread-use-static-link-config": true, 47 | "thread-security-policy": 255, 48 | "LED": "NC", 49 | "SERIAL_TX": "NC", 50 | "SERIAL_RX": "NC", 51 | "SERIAL_CTS": "NC", 52 | "SERIAL_RTS": "NC" 53 | }, 54 | "macros": ["MBEDTLS_USER_CONFIG_FILE=\"source/mbedtls_thread_config.h\"", "ATMEL_SPI_RST=PTD4"], 55 | "target_overrides": { 56 | "*": { 57 | "target.network-default-interface-type": "ETHERNET", 58 | "nsapi.default-stack": "NANOSTACK", 59 | "mbed-trace.enable": 1, 60 | "nanostack.configuration": "thread_border_router", 61 | "platform.stdio-convert-newlines": true, 62 | "platform.stdio-baud-rate": 115200, 63 | "mbed-mesh-api.heap-size": 65535, 64 | "mbed-mesh-api.heap-stat-info": "&memory_heap_stat", 65 | "mbed-mesh-api.heap-stat-info-definition": "mem_stat_t memory_heap_stat;" 66 | }, 67 | "K64F": { 68 | "LED": "LED_GREEN", 69 | "SERIAL_TX": "PTE0", 70 | "SERIAL_RX": "PTE1", 71 | "SERIAL_CTS": "PTE2", 72 | "SERIAL_RTS": "PTE3" 73 | }, 74 | "K66F": { 75 | "LED": "LED_GREEN" 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | properties ([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [ 2 | [$class: 'StringParameterDefinition', name: 'mbed_os_revision', defaultValue: '', description: 'Revision of mbed-os to build. By default mbed-os.lib is used. To access mbed-os PR use format "pull/PR number/head"'], 3 | [$class: 'ChoiceParameterDefinition', name: 'profile', defaultValue: "debug", choices: ["debug", "develop", "release"], description: 'Select compilation profile from list: debug, develop or release.'] 4 | ]]]) 5 | 6 | if (params.mbed_os_revision == '') { 7 | echo 'Use mbed OS revision from mbed-os.lib' 8 | } else { 9 | echo "Use mbed OS revision ${params.mbed_os_revision}" 10 | if (params.mbed_os_revision.matches('pull/\\d+/head')) { 11 | echo "Revision is a Pull Request" 12 | } 13 | } 14 | 15 | echo "Use build profile: ${params.profile}" 16 | 17 | // List of targets to compile 18 | def targets = [ 19 | "K64F", 20 | "K66F", 21 | "DISCO_F769NI" 22 | ] 23 | 24 | // Map toolchains to CI labels 25 | def toolchains = [ 26 | ARM: "armc6", 27 | GCC_ARM: "arm-none-eabi-gcc" 28 | ] 29 | 30 | // Configurations 31 | def configurations = [ 32 | LOWPAN: "6lowpan_Atmel_RF.json", 33 | THREAD: "Thread_Atmel_RF.json", 34 | THREAD_SLIP: "Thread_SLIP_Atmel_RF.json", 35 | WI_SUN: "Wisun_Stm_s2lp_RF.json" 36 | ] 37 | 38 | def stepsForParallel = [:] 39 | 40 | // Jenkins pipeline does not support map.each, we need to use oldschool for loop 41 | for (int i = 0; i < targets.size(); i++) { 42 | for(int j = 0; j < toolchains.size(); j++) { 43 | for(int k = 0; k < configurations.size(); k++) { 44 | def target = targets.get(i) 45 | def toolchain = toolchains.keySet().asList().get(j) 46 | def compilerLabel = toolchains.get(toolchain) 47 | def configurationLabel = configurations.keySet().asList().get(k) 48 | def configurationFile = configurations.get(configurationLabel) 49 | def stepName = "${target} ${configurationLabel} ${toolchain}" 50 | // SLIP configuration exist only for K64F based Raspberry HAT 51 | if ((configurationLabel == "THREAD_SLIP") && target != "K64F") { 52 | continue; 53 | } 54 | stepsForParallel[stepName] = buildStep(target, compilerLabel, configurationFile, configurationLabel, toolchain) 55 | } 56 | } 57 | } 58 | 59 | timestamps { 60 | parallel stepsForParallel 61 | } 62 | 63 | def buildStep(target, compilerLabel, configurationFile, configurationLabel, toolchain) { 64 | return { 65 | stage ("${target}_${compilerLabel}_${configurationLabel}") { 66 | node ("${compilerLabel}") { 67 | deleteDir() 68 | dir("nanostack-border-router") { 69 | checkout scm 70 | execute("git clean -ffdx") 71 | execute("mbed deploy --protocol ssh") 72 | // Update mbed-os revision if requested 73 | if (params.mbed_os_revision != '') { 74 | dir ("mbed-os") { 75 | if (params.mbed_os_revision.matches('pull/\\d+/head')) { 76 | execute("git fetch origin ${params.mbed_os_revision}:_PR_") 77 | execute("git checkout _PR_") 78 | } else { 79 | execute ("git checkout ${params.mbed_os_revision}") 80 | } 81 | } 82 | } 83 | execute("mbed compile --build out/${configurationLabel}/${target}/${toolchain}/ -m ${target} -t ${toolchain} --app-config ./configs/${configurationFile} --profile ${params.profile}") 84 | } 85 | archive '**/nanostack-border-router.bin' 86 | } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /configs/Wisun_Stm_s2lp_RF_lab.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "radio-type":{ 4 | "help": "options are ATMEL, MCR20, SPIRIT1, S2LP", 5 | "value": "S2LP" 6 | }, 7 | "backhaul-driver": { 8 | "help": "options are ETH, SLIP, EMAC, CELL", 9 | "value": "EMAC" 10 | }, 11 | "mesh-mode": { 12 | "help": "Mesh networking mode. Options are LOWPAN_ND, LOWPAN_WS and THREAD", 13 | "value": "LOWPAN_WS" 14 | }, 15 | "backhaul-mac-src": { 16 | "help": "Where to get EUI48 address. Options are BOARD, CONFIG", 17 | "value": "BOARD" 18 | }, 19 | "backhaul-mld": { 20 | "help": "Enable proxying Multicast Listener Discovery messages to backhaul network", 21 | "value": "false" 22 | }, 23 | "nanostack_extended_heap": { 24 | "help": "Add additional memory region to nanostack heap. Valid only for selected platforms. Region size may vary depending of the toolchain.", 25 | "value": true 26 | }, 27 | "backhaul-mac": "{0x02, 0x00, 0x00, 0x00, 0x00, 0x01}", 28 | "debug-trace": "true", 29 | "backhaul-dynamic-bootstrap": true, 30 | "backhaul-prefix": "\"fd00:db8:ff1::\"", 31 | "backhaul-default-route": "\"::/0\"", 32 | "backhaul-next-hop": "\"fe80::1\"", 33 | "multicast-addr": "ff05::7", 34 | "LED": "NC", 35 | "SERIAL_TX": "NC", 36 | "SERIAL_RX": "NC", 37 | "SERIAL_CTS": "NC", 38 | "SERIAL_RTS": "NC", 39 | "uc-channel-function": 255, 40 | "bc-channel-function": 255, 41 | "regulatory-domain": 3, 42 | "operating-class": 255, 43 | "operating-mode": 255, 44 | "uc-fixed-channel": "0xffff", 45 | "bc-fixed-channel": "0xffff", 46 | "network-name": "\"ARM-WS-LAB-NWK\"", 47 | "certificate-header": { 48 | "help": "Certificate header", 49 | "value": "\"wisun_certificates.h\"" 50 | }, 51 | "root-certificate": { 52 | "help": "Root certificate in PEM format (must be a null terminated c-string)", 53 | "value": "WISUN_ROOT_CERTIFICATE" 54 | }, 55 | "own-certificate": { 56 | "help": "Own certificate in PEM format (must be a null terminated c-string)", 57 | "value": "WISUN_SERVER_CERTIFICATE" 58 | }, 59 | "own-certificate-key": { 60 | "help": "Own certificate's key in PEM format (must be a null terminated c-string)", 61 | "value": "WISUN_SERVER_KEY" 62 | } 63 | 64 | }, 65 | "macros": ["MBEDTLS_USER_CONFIG_FILE=\"source/mbedtls_wisun_config.h\""], 66 | "target_overrides": { 67 | "*": { 68 | "target.network-default-interface-type": "ETHERNET", 69 | "nsapi.default-stack": "NANOSTACK", 70 | "mbed-trace.enable": true, 71 | "nanostack.configuration": "ws_border_router", 72 | "platform.stdio-convert-newlines": true, 73 | "platform.stdio-baud-rate": 115200, 74 | "mbed-mesh-api.heap-size": 65535, 75 | "mbed-mesh-api.heap-stat-info": "&memory_heap_stat", 76 | "mbed-mesh-api.heap-stat-info-definition": "mem_stat_t memory_heap_stat;", 77 | "platform.stdio-buffered-serial": true 78 | }, 79 | "K64F": { 80 | "kinetis-emac.tx-ring-len":4, 81 | "kinetis-emac.rx-ring-len":4 82 | }, 83 | "K66F": { 84 | "kinetis-emac.tx-ring-len":4, 85 | "kinetis-emac.rx-ring-len":4 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /mbed_app.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "radio-type":{ 4 | "help": "options are ATMEL, MCR20, SPIRIT1", 5 | "value": "ATMEL" 6 | }, 7 | "backhaul-driver": { 8 | "help": "options are ETH, SLIP, EMAC", 9 | "value": "EMAC" 10 | }, 11 | "mesh-mode": { 12 | "help": "Mesh networking mode. Options are LOWPAN_ND and THREAD", 13 | "value": "LOWPAN_ND" 14 | }, 15 | "backhaul-mac-src": { 16 | "help": "Where to get EUI48 address. Options are BOARD, CONFIG", 17 | "value": "BOARD" 18 | }, 19 | "nanostack_extended_heap": { 20 | "help": "Add additional memory region to nanostack heap. Valid only for selected platforms. Region size may vary depending of the toolchain.", 21 | "value": false 22 | }, 23 | "backhaul-mac": "{0x02, 0x00, 0x00, 0x00, 0x00, 0x01}", 24 | "slip_hw_flow_control": "false", 25 | "slip_serial_baud_rate": "921600", 26 | "debug-trace": "false", 27 | "defined-BR-config": "true", 28 | "security-mode": "NONE", 29 | "psk-key-id": 1, 30 | "psk-key": "{0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf}", 31 | "pana-mode": "", 32 | "tls-psk-key": "{0xcf, 0xce, 0xcd, 0xcc, 0xcb, 0xca, 0xc9, 0xc8, 0xc7, 0xc6, 0xc5, 0xc4, 0xc3, 0xc2, 0xc1, 0xc0}", 33 | "tls-psk-key-id": 1, 34 | "pan-id": "0x0691", 35 | "network-id": "network000000000", 36 | "beacon-protocol-id": 4, 37 | "prefix": "fd00:db8::", 38 | "prefix-from-backhaul": true, 39 | "rf-channel": 12, 40 | "rf-channel-page": 0, 41 | "rf-channel-mask": "0x07fff800", 42 | "short-mac-address": "0xface", 43 | "backhaul-dynamic-bootstrap": true, 44 | "backhaul-prefix": "fd00:db8:ff1::", 45 | "backhaul-default-route": "::/0", 46 | "backhaul-next-hop": "fe80::1", 47 | "ra-router-lifetime": 1024, 48 | "rpl-instance-id": 1, 49 | "rpl-idoublings": 9, 50 | "rpl-imin": 12, 51 | "rpl-k": 10, 52 | "rpl-max-rank-inc": 2048, 53 | "rpl-min-hop-rank-inc": 128, 54 | "rpl-default-lifetime": 64, 55 | "rpl-lifetime-unit": 60, 56 | "rpl-pcs": 1, 57 | "rpl-ocp": 1, 58 | "multicast-addr": "ff05::7", 59 | "LED": "NC", 60 | "SERIAL_TX": "NC", 61 | "SERIAL_RX": "NC", 62 | "SERIAL_CTS": "NC", 63 | "SERIAL_RTS": "NC" 64 | }, 65 | "target_overrides": { 66 | "*": { 67 | "target.network-default-interface-type": "ETHERNET", 68 | "nsapi.default-stack": "NANOSTACK", 69 | "mbed-trace.enable": 1, 70 | "nanostack.configuration": "lowpan_border_router", 71 | "platform.stdio-convert-newlines": true, 72 | "platform.stdio-baud-rate": 115200, 73 | "mbed-mesh-api.heap-size": 40000, 74 | "mbed-mesh-api.heap-stat-info": "&memory_heap_stat", 75 | "mbed-mesh-api.heap-stat-info-definition": "mem_stat_t memory_heap_stat;" 76 | }, 77 | "K64F": { 78 | "LED": "LED_GREEN", 79 | "SERIAL_TX": "PTE0", 80 | "SERIAL_RX": "PTE1", 81 | "SERIAL_CTS": "PTE2", 82 | "SERIAL_RTS": "PTE3", 83 | "kinetis-emac.tx-ring-len":4, 84 | "kinetis-emac.rx-ring-len":4 85 | }, 86 | "K66F": { 87 | "LED": "LED_GREEN", 88 | "kinetis-emac.tx-ring-len":4, 89 | "kinetis-emac.rx-ring-len":4 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /source/wisun_certificates.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Pelion and affiliates. 3 | * SPDX-License-Identifier: Apache-2.0 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef WISUN_TEST_CERTIFICATES_H_ 19 | #define WISUN_TEST_CERTIFICATES_H_ 20 | 21 | const uint8_t WISUN_ROOT_CERTIFICATE[] = { 22 | "-----BEGIN CERTIFICATE-----\r\n" 23 | "MIIBLzCB1qADAgECAhQooDtB2DFWFsDlkVyeKLkkFq27vTAKBggqhkjOPQQDAjAN\r\n" 24 | "MQswCQYDVQQDEwJDQTAiGA8wMDAwMDEwMTAwMDAwMFoYDzk5OTkxMjMxMjM1OTU5\r\n" 25 | "WjANMQswCQYDVQQDEwJDQTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABG0ZABD+\r\n" 26 | "g8Nvc9KBpw/aHhoim9KrqzOYP5qTmZgS8uxM/eqeAJ6vrSivWFT2fxHuzXG+yfvs\r\n" 27 | "oPNgBJhv/YNhM9KjEDAOMAwGA1UdEwQFMAMBAf8wCgYIKoZIzj0EAwIDSAAwRQIg\r\n" 28 | "CK00/WNqrLzSt7QtustgbL+kibXBuWFeYBjU5yPbaHECIQD8aFwPt2/oXLOSa7gB\r\n" 29 | "9nwpA1rsmzCJLvb8ouxQ3uhXbg==\r\n" 30 | "-----END CERTIFICATE-----" 31 | }; 32 | 33 | const uint8_t WISUN_SERVER_CERTIFICATE[] = { 34 | "-----BEGIN CERTIFICATE-----\r\n" 35 | "MIIBbzCCARUCFHsX/aO/8skZ/3NAQrzQ957H/aNYMAoGCCqGSM49BAMCMA0xCzAJ\r\n" 36 | "BgNVBAMTAkNBMCIYDzAwMDAwMTAxMDAwMDAwWhgPOTk5OTEyMzEyMzU5NTlaMGMx\r\n" 37 | "CzAJBgNVBAYTAkZJMQ0wCwYDVQQIDARPdWx1MQ0wCwYDVQQHDARPdWx1MQ0wCwYD\r\n" 38 | "VQQKDAR0ZXN0MQ0wCwYDVQQDDAR0ZXN0MRgwFgYJKoZIhvcNAQkBFgl0ZXN0QHRl\r\n" 39 | "c3QwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQtbrqK+Z2gWz9rgvS4fgkWn1kb\r\n" 40 | "wERr15kFr7CmNM63gAmMyS08m5/sBYps5XUdIwF+Pz8uYmk4LpSl+o0OLkmaMAoG\r\n" 41 | "CCqGSM49BAMCA0gAMEUCIDknuOd/stYYgK3oztxspnKBHoOO8UcUB3PH2AfIq24e\r\n" 42 | "AiEA8OMJ44i3TKToinV1IATm81mqu+5pBqYu4RtX0E/xP88=\r\n" 43 | "-----END CERTIFICATE-----" 44 | }; 45 | 46 | const uint8_t WISUN_SERVER_KEY[] = { 47 | "-----BEGIN EC PRIVATE KEY-----\r\n" 48 | "MHcCAQEEIEvbJ9SG/qeud6z3oRb+sROxk6/HWHQWtcucDFq3grzooAoGCCqGSM49\r\n" 49 | "AwEHoUQDQgAELW66ivmdoFs/a4L0uH4JFp9ZG8BEa9eZBa+wpjTOt4AJjMktPJuf\r\n" 50 | "7AWKbOV1HSMBfj8/LmJpOC6UpfqNDi5Jmg==\r\n" 51 | "-----END EC PRIVATE KEY-----" 52 | }; 53 | 54 | const uint8_t WISUN_CLIENT_CERTIFICATE[] = { 55 | "-----BEGIN CERTIFICATE-----\r\n" 56 | "MIIBbzCCARUCFHsX/aO/8skZ/3NAQrzQ957H/aNZMAoGCCqGSM49BAMCMA0xCzAJ\r\n" 57 | "BgNVBAMTAkNBMCIYDzAwMDAwMTAxMDAwMDAwWhgPOTk5OTEyMzEyMzU5NTlaMGMx\r\n" 58 | "CzAJBgNVBAYTAkZJMQ0wCwYDVQQIDARPdWx1MQ0wCwYDVQQHDARPdWx1MQ0wCwYD\r\n" 59 | "VQQKDAR0ZXN0MQ0wCwYDVQQDDAR0ZXN0MRgwFgYJKoZIhvcNAQkBFgl0ZXN0QHRl\r\n" 60 | "c3QwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARIJ0hVdYmPsTFmY3glVAzE6dRE\r\n" 61 | "6Vp3rEUwqKqfMaJWvxd8EszaMP6PUwn4bprMkUPRmISTe8T17K8ZSRi8gun7MAoG\r\n" 62 | "CCqGSM49BAMCA0gAMEUCIQCtQwnVemwlIUoXeMZ1WE3JHj9XAIbxg2lweRJ91XaV\r\n" 63 | "VgIgDyft6+GF3u31VmTljTMAZZcCNRXDP0eNha+gB0TlGhY=\r\n" 64 | "-----END CERTIFICATE-----" 65 | }; 66 | 67 | const uint8_t WISUN_CLIENT_KEY[] = { 68 | "-----BEGIN EC PRIVATE KEY-----\r\n" 69 | "MHcCAQEEIOxOq1xL+Hv5hg6Zg41pVXpkjLTkZxXrBHJcExTUMAftoAoGCCqGSM49\r\n" 70 | "AwEHoUQDQgAESCdIVXWJj7ExZmN4JVQMxOnUROlad6xFMKiqnzGiVr8XfBLM2jD+\r\n" 71 | "j1MJ+G6azJFD0ZiEk3vE9eyvGUkYvILp+w==\r\n" 72 | "-----END EC PRIVATE KEY-----" 73 | }; 74 | 75 | #endif /* WISUN_TEST_CERTIFICATES_H_ */ 76 | -------------------------------------------------------------------------------- /configs/Thread_Atmel_RF.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "radio-type":{ 4 | "help": "options are ATMEL, MCR20", 5 | "value": "ATMEL" 6 | }, 7 | "backhaul-driver": { 8 | "help": "options are ETH, SLIP, EMAC, CELL", 9 | "value": "EMAC" 10 | }, 11 | "mesh-mode": { 12 | "help": "Mesh networking mode. Options are LOWPAN_ND and THREAD", 13 | "value": "THREAD" 14 | }, 15 | "backhaul-mac-src": { 16 | "help": "Where to get EUI48 address. Options are BOARD, CONFIG", 17 | "value": "BOARD" 18 | }, 19 | "backhaul-mld": { 20 | "help": "Enable proxying Multicast Listener Discovery messages to backhaul network", 21 | "value": "false" 22 | }, 23 | "nanostack_extended_heap": { 24 | "help": "Add additional memory region to nanostack heap. Valid only for selected platforms. Region size may vary depending of the toolchain.", 25 | "value": false 26 | }, 27 | "backhaul-mac": "{0x02, 0x00, 0x00, 0x00, 0x00, 0x01}", 28 | "rf-channel": 22, 29 | "rf-channel-page": 0, 30 | "rf-channel-mask": "0x07fff800", 31 | "debug-trace": 1, 32 | "backhaul-dynamic-bootstrap": true, 33 | "backhaul-prefix": "\"fd00:300::\"", 34 | "backhaul-next-hop": "\"fe80::1\"", 35 | "backhaul-default-route": "\"::/0\"", 36 | "commissioning-dataset-timestamp": "0x00010000", 37 | "pan-id": "0x0700", 38 | "extended-pan-id": "{0xf1, 0xb5, 0xa1, 0xb2,0xc4, 0xd5, 0xa1, 0xbd }", 39 | "mesh-local-prefix": "{0xfd, 0x0, 0x0d, 0xb8, 0x0,0x0, 0x0, 0x0}", 40 | "network-name": "\"Thread Network\"", 41 | "pskd": "\"ABCDEFGH\"", 42 | "pskc": "{0xc8, 0xa6, 0x2e, 0xae, 0xf3, 0x68, 0xf3, 0x46, 0xa9, 0x9e, 0x57, 0x85, 0x98, 0x9d, 0x1c, 0xd0}", 43 | "thread-master-key": "{0x10, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}", 44 | "thread-use-static-link-config": true, 45 | "thread-security-policy": 255, 46 | "LED": "NC", 47 | "SERIAL_TX": "NC", 48 | "SERIAL_RX": "NC", 49 | "SERIAL_CTS": "NC", 50 | "SERIAL_RTS": "NC" 51 | }, 52 | "macros": ["MBEDTLS_USER_CONFIG_FILE=\"source/mbedtls_thread_config.h\""], 53 | "target_overrides": { 54 | "*": { 55 | "target.network-default-interface-type": "ETHERNET", 56 | "nsapi.default-stack": "NANOSTACK", 57 | "mbed-trace.enable": 1, 58 | "nanostack.configuration": "thread_border_router", 59 | "platform.stdio-convert-newlines": true, 60 | "platform.stdio-baud-rate": 115200, 61 | "mbed-mesh-api.heap-size": 65535, 62 | "mbed-mesh-api.heap-stat-info": "&memory_heap_stat", 63 | "mbed-mesh-api.heap-stat-info-definition": "mem_stat_t memory_heap_stat;" 64 | }, 65 | "K64F": { 66 | "LED": "LED_GREEN", 67 | "SERIAL_TX": "PTE0", 68 | "SERIAL_RX": "PTE1", 69 | "SERIAL_CTS": "PTE2", 70 | "SERIAL_RTS": "PTE3", 71 | "kinetis-emac.tx-ring-len":4, 72 | "kinetis-emac.rx-ring-len":4 73 | }, 74 | "K66F": { 75 | "LED": "LED_GREEN", 76 | "kinetis-emac.tx-ring-len":4, 77 | "kinetis-emac.rx-ring-len":4 78 | }, 79 | "K64F_STATIC_BR": { 80 | "LED": "LED_GREEN", 81 | "SERIAL_TX": "PTE0", 82 | "SERIAL_RX": "PTE1", 83 | "SERIAL_CTS": "PTE2", 84 | "SERIAL_RTS": "PTE3", 85 | "kinetis-emac.tx-ring-len":4, 86 | "kinetis-emac.rx-ring-len":4, 87 | "rf-channel": 26, 88 | "debug-trace": true, 89 | "pan-id": "0xBAAB", 90 | "mbed-mesh-api.heap-size": 100000 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /configs/6lowpan_Spirit1_RF.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "radio-type":{ 4 | "help": "options are ATMEL, MCR20, SPIRIT1", 5 | "value": "SPIRIT1" 6 | }, 7 | "backhaul-driver": { 8 | "help": "options are ETH, SLIP, EMAC, CELL", 9 | "value": "EMAC" 10 | }, 11 | "mesh-mode": { 12 | "help": "Mesh networking mode. Options are LOWPAN_ND and THREAD", 13 | "value": "LOWPAN_ND" 14 | }, 15 | "backhaul-mac-src": { 16 | "help": "Where to get EUI48 address. Options are BOARD, CONFIG", 17 | "value": "BOARD" 18 | }, 19 | "backhaul-mld": { 20 | "help": "Enable proxying Multicast Listener Discovery messages to backhaul network", 21 | "value": "false" 22 | }, 23 | "nanostack_extended_heap": { 24 | "help": "Add additional memory region to nanostack heap. Valid only for selected platforms. Region size may vary depending of the toolchain.", 25 | "value": false 26 | }, 27 | "backhaul-mac": "{0x02, 0x00, 0x00, 0x00, 0x00, 0x01}", 28 | "slip_hw_flow_control": "false", 29 | "slip_serial_baud_rate": "921600", 30 | "debug-trace": "false", 31 | "defined-BR-config": "true", 32 | "security-mode": "PSK", 33 | "psk-key-id": 1, 34 | "psk-key": "{0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf}", 35 | "pana-mode": "", 36 | "tls-psk-key": "{0xcf, 0xce, 0xcd, 0xcc, 0xcb, 0xca, 0xc9, 0xc8, 0xc7, 0xc6, 0xc5, 0xc4, 0xc3, 0xc2, 0xc1, 0xc0}", 37 | "tls-psk-key-id": 1, 38 | "pan-id": "0x0691", 39 | "network-id": "network000000000", 40 | "beacon-protocol-id": 4, 41 | "prefix": "fd00:db8::", 42 | "prefix-from-backhaul": true, 43 | "rf-channel": 1, 44 | "rf-channel-page": 2, 45 | "rf-channel-mask": "(1<<1)", 46 | "short-mac-address": "0xface", 47 | "backhaul-dynamic-bootstrap": true, 48 | "backhaul-prefix": "fd00:db8:ff1::", 49 | "backhaul-default-route": "::/0", 50 | "backhaul-next-hop": "fe80::1", 51 | "ra-router-lifetime": 1024, 52 | "rpl-instance-id": 1, 53 | "rpl-idoublings": 9, 54 | "rpl-imin": 12, 55 | "rpl-k": 10, 56 | "rpl-max-rank-inc": 2048, 57 | "rpl-min-hop-rank-inc": 128, 58 | "rpl-default-lifetime": 64, 59 | "rpl-lifetime-unit": 60, 60 | "rpl-pcs": 1, 61 | "rpl-ocp": 1, 62 | "multicast-addr": "ff05::7", 63 | "LED": "NC", 64 | "SERIAL_TX": "NC", 65 | "SERIAL_RX": "NC", 66 | "SERIAL_CTS": "NC", 67 | "SERIAL_RTS": "NC" 68 | }, 69 | "target_overrides": { 70 | "*": { 71 | "spirit1.mac-address": "{0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7}", 72 | "target.network-default-interface-type": "ETHERNET", 73 | "nsapi.default-stack": "NANOSTACK", 74 | "mbed-trace.enable": 1, 75 | "nanostack.configuration": "lowpan_border_router", 76 | "platform.stdio-convert-newlines": true, 77 | "platform.stdio-baud-rate": 115200, 78 | "mbed-mesh-api.heap-size": 40000, 79 | "mbed-mesh-api.heap-stat-info": "&memory_heap_stat", 80 | "mbed-mesh-api.heap-stat-info-definition": "mem_stat_t memory_heap_stat;", 81 | "kinetis-emac.tx-ring-len":4, 82 | "kinetis-emac.rx-ring-len":4 83 | }, 84 | "NUCLEO_F429ZI": { 85 | "LED": "LED1", 86 | "SERIAL_TX": "SERIAL_TX", 87 | "SERIAL_RX": "SERIAL_RX", 88 | "SERIAL_CTS": "PD_11", 89 | "SERIAL_RTS": "PD_12" 90 | }, 91 | "K66F": { 92 | "LED": "LED_GREEN", 93 | "kinetis-emac.tx-ring-len":4, 94 | "kinetis-emac.rx-ring-len":4 95 | } 96 | }, 97 | "macros": ["SPIRIT1_SPI_MOSI=PB_5"] 98 | } 99 | -------------------------------------------------------------------------------- /configs/Wisun_Stm_s2lp_RF.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "radio-type":{ 4 | "help": "options are ATMEL, MCR20, SPIRIT1, S2LP", 5 | "value": "S2LP" 6 | }, 7 | "backhaul-driver": { 8 | "help": "options are ETH, SLIP, EMAC, CELL", 9 | "value": "EMAC" 10 | }, 11 | "mesh-mode": { 12 | "help": "Mesh networking mode. Options are LOWPAN_ND, LOWPAN_WS and THREAD", 13 | "value": "LOWPAN_WS" 14 | }, 15 | "backhaul-mac-src": { 16 | "help": "Where to get EUI48 address. Options are BOARD, CONFIG", 17 | "value": "BOARD" 18 | }, 19 | "backhaul-mld": { 20 | "help": "Enable proxying Multicast Listener Discovery messages to backhaul network", 21 | "value": "false" 22 | }, 23 | "nanostack_extended_heap": { 24 | "help": "Add additional memory region to nanostack heap. Valid only for selected platforms. Region size may vary depending of the toolchain.", 25 | "value": true 26 | }, 27 | "backhaul-mac": "{0x02, 0x00, 0x00, 0x00, 0x00, 0x01}", 28 | "debug-trace": "true", 29 | "backhaul-dynamic-bootstrap": true, 30 | "backhaul-prefix": "\"fd00:db8:ff1::\"", 31 | "backhaul-default-route": "\"::/0\"", 32 | "backhaul-next-hop": "\"fe80::1\"", 33 | "multicast-addr": "ff05::7", 34 | "LED": "NC", 35 | "SERIAL_TX": "NC", 36 | "SERIAL_RX": "NC", 37 | "SERIAL_CTS": "NC", 38 | "SERIAL_RTS": "NC", 39 | "uc-channel-function": 255, 40 | "bc-channel-function": 255, 41 | "regulatory-domain": 3, 42 | "operating-class": 255, 43 | "operating-mode": 255, 44 | "uc-fixed-channel": "0xffff", 45 | "bc-fixed-channel": "0xffff", 46 | "network-name": "\"Wi-SUN Network\"", 47 | "certificate-header": { 48 | "help": "Certificate header", 49 | "value": "\"wisun_certificates.h\"" 50 | }, 51 | "root-certificate": { 52 | "help": "Root certificate in PEM format (must be a null terminated c-string)", 53 | "value": "WISUN_ROOT_CERTIFICATE" 54 | }, 55 | "own-certificate": { 56 | "help": "Own certificate in PEM format (must be a null terminated c-string)", 57 | "value": "WISUN_SERVER_CERTIFICATE" 58 | }, 59 | "own-certificate-key": { 60 | "help": "Own certificate's key in PEM format (must be a null terminated c-string)", 61 | "value": "WISUN_SERVER_KEY" 62 | } 63 | 64 | }, 65 | "macros": ["MBEDTLS_USER_CONFIG_FILE=\"source/mbedtls_wisun_config.h\""], 66 | "target_overrides": { 67 | "*": { 68 | "target.network-default-interface-type": "ETHERNET", 69 | "nsapi.default-stack": "NANOSTACK", 70 | "mbed-trace.enable": 1, 71 | "nanostack.configuration": "ws_border_router", 72 | "platform.stdio-convert-newlines": true, 73 | "platform.stdio-baud-rate": 115200, 74 | "mbed-mesh-api.heap-size": 65535, 75 | "mbed-mesh-api.heap-stat-info": "&memory_heap_stat", 76 | "mbed-mesh-api.heap-stat-info-definition": "mem_stat_t memory_heap_stat;", 77 | "platform.stdio-buffered-serial": true 78 | }, 79 | "K64F": { 80 | "kinetis-emac.tx-ring-len":4, 81 | "kinetis-emac.rx-ring-len":4 82 | }, 83 | "K66F": { 84 | "kinetis-emac.tx-ring-len":4, 85 | "kinetis-emac.rx-ring-len":4 86 | }, 87 | "K64F_STATIC_BR": { 88 | "kinetis-emac.tx-ring-len":4, 89 | "kinetis-emac.rx-ring-len":4, 90 | "network-name": "\"ARM-WS-LAB-NWK\"", 91 | "mbed-mesh-api.heap-size": 100000 92 | }, 93 | "DISCO_F769NI_STATIC_BR": { 94 | "network-name": "\"ARM-WS-LAB-NWK\"", 95 | "mbed-mesh-api.heap-size": 100000 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /configs/Wisun_Stm_s2lp_RF_cell.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "radio-type":{ 4 | "help": "options are ATMEL, MCR20, SPIRIT1, S2LP", 5 | "value": "S2LP" 6 | }, 7 | "backhaul-driver": { 8 | "help": "options are ETH, SLIP, EMAC, CELL", 9 | "value": "CELL" 10 | }, 11 | "mesh-mode": { 12 | "help": "Mesh networking mode. Options are LOWPAN_ND, LOWPAN_WS and THREAD", 13 | "value": "LOWPAN_WS" 14 | }, 15 | "backhaul-mac-src": { 16 | "help": "Where to get EUI48 address. Options are BOARD, CONFIG", 17 | "value": "BOARD" 18 | }, 19 | "backhaul-mld": { 20 | "help": "Enable proxying Multicast Listener Discovery messages to backhaul network", 21 | "value": "false" 22 | }, 23 | "nanostack_extended_heap": { 24 | "help": "Add additional memory region to nanostack heap. Valid only for selected platforms. Region size may vary depending of the toolchain.", 25 | "value": true 26 | }, 27 | "backhaul-mac": "{0x02, 0x00, 0x00, 0x00, 0x00, 0x01}", 28 | "debug-trace": "true", 29 | "backhaul-dynamic-bootstrap": true, 30 | "backhaul-prefix": "\"fd00:db8:ff1::\"", 31 | "backhaul-default-route": "\"::/0\"", 32 | "backhaul-next-hop": "\"fe80::1\"", 33 | "multicast-addr": "ff05::7", 34 | "LED": "NC", 35 | "SERIAL_TX": "NC", 36 | "SERIAL_RX": "NC", 37 | "SERIAL_CTS": "NC", 38 | "SERIAL_RTS": "NC", 39 | "uc-channel-function": 255, 40 | "bc-channel-function": 255, 41 | "regulatory-domain": 3, 42 | "operating-class": 255, 43 | "operating-mode": 255, 44 | "uc-fixed-channel": "0xffff", 45 | "bc-fixed-channel": "0xffff", 46 | "network-name": "\"Wi-SUN Network\"", 47 | "certificate-header": { 48 | "help": "Certificate header", 49 | "value": "\"wisun_certificates.h\"" 50 | }, 51 | "root-certificate": { 52 | "help": "Root certificate in PEM format (must be a null terminated c-string)", 53 | "value": "WISUN_ROOT_CERTIFICATE" 54 | }, 55 | "own-certificate": { 56 | "help": "Own certificate in PEM format (must be a null terminated c-string)", 57 | "value": "WISUN_SERVER_CERTIFICATE" 58 | }, 59 | "own-certificate-key": { 60 | "help": "Own certificate's key in PEM format (must be a null terminated c-string)", 61 | "value": "WISUN_SERVER_KEY" 62 | } 63 | }, 64 | "macros": ["MBEDTLS_USER_CONFIG_FILE=\"source/mbedtls_wisun_config.h\""], 65 | "target_overrides": { 66 | "*": { 67 | "nsapi.default-stack": "NANOSTACK", 68 | "mbed-trace.enable": 1, 69 | "nanostack.configuration": "ws_border_router", 70 | "platform.stdio-convert-newlines": true, 71 | "platform.stdio-baud-rate": 115200, 72 | "mbed-mesh-api.heap-size": 65535, 73 | "mbed-mesh-api.heap-stat-info": "&memory_heap_stat", 74 | "mbed-mesh-api.heap-stat-info-definition": "mem_stat_t memory_heap_stat;", 75 | "platform.stdio-buffered-serial": true, 76 | "ppp.enabled": true, 77 | "ppp.ipv4-enabled": false, 78 | "ppp.ipv6-enabled": true, 79 | "nsapi.default-cellular-plmn": 0, 80 | "nsapi.default-cellular-sim-pin": null, 81 | "nsapi.default-cellular-apn": 0, 82 | "nsapi.default-cellular-username": 0, 83 | "nsapi.default-cellular-password": 0, 84 | "cellular.debug-at": false, 85 | "QUECTEL_EC2X.provide-default": true, 86 | "QUECTEL_EC2X.tx": "D1", 87 | "QUECTEL_EC2X.rx": "D0", 88 | "QUECTEL_EC2X.pwr": "D2", 89 | "QUECTEL_EC2X.rst": "D4" 90 | }, 91 | "K64F": { 92 | "kinetis-emac.tx-ring-len":4, 93 | "kinetis-emac.rx-ring-len":4 94 | }, 95 | "K66F": { 96 | "kinetis-emac.tx-ring-len":4, 97 | "kinetis-emac.rx-ring-len":4 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /configs/6lowpan_Atmel_RF.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "radio-type":{ 4 | "help": "options are ATMEL, MCR20, SPIRIT1", 5 | "value": "ATMEL" 6 | }, 7 | "backhaul-driver": { 8 | "help": "options are ETH, SLIP, EMAC, CELL", 9 | "value": "EMAC" 10 | }, 11 | "mesh-mode": { 12 | "help": "Mesh networking mode. Options are LOWPAN_ND and THREAD", 13 | "value": "LOWPAN_ND" 14 | }, 15 | "backhaul-mac-src": { 16 | "help": "Where to get EUI48 address. Options are BOARD, CONFIG", 17 | "value": "BOARD" 18 | }, 19 | "backhaul-mld": { 20 | "help": "Enable proxying Multicast Listener Discovery messages to backhaul network", 21 | "value": "false" 22 | }, 23 | "nanostack_extended_heap": { 24 | "help": "Add additional memory region to nanostack heap. Valid only for selected platforms. Region size may vary depending of the toolchain.", 25 | "value": false 26 | }, 27 | "backhaul-mac": "{0x02, 0x00, 0x00, 0x00, 0x00, 0x01}", 28 | "slip_hw_flow_control": "false", 29 | "slip_serial_baud_rate": "921600", 30 | "debug-trace": "false", 31 | "defined-BR-config": "true", 32 | "security-mode": "NONE", 33 | "psk-key-id": 1, 34 | "psk-key": "{0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf}", 35 | "pana-mode": "", 36 | "tls-psk-key": "{0xcf, 0xce, 0xcd, 0xcc, 0xcb, 0xca, 0xc9, 0xc8, 0xc7, 0xc6, 0xc5, 0xc4, 0xc3, 0xc2, 0xc1, 0xc0}", 37 | "tls-psk-key-id": 1, 38 | "pan-id": "0x0691", 39 | "network-id": "network000000000", 40 | "beacon-protocol-id": 4, 41 | "prefix": "fd00:db8::", 42 | "prefix-from-backhaul": true, 43 | "rf-channel": 12, 44 | "rf-channel-page": 0, 45 | "rf-channel-mask": "0x07fff800", 46 | "short-mac-address": "0xface", 47 | "backhaul-dynamic-bootstrap": true, 48 | "backhaul-prefix": "fd00:db8:ff1::", 49 | "backhaul-default-route": "::/0", 50 | "backhaul-next-hop": "fe80::1", 51 | "ra-router-lifetime": 1024, 52 | "rpl-instance-id": 1, 53 | "rpl-idoublings": 9, 54 | "rpl-imin": 12, 55 | "rpl-k": 10, 56 | "rpl-max-rank-inc": 2048, 57 | "rpl-min-hop-rank-inc": 128, 58 | "rpl-default-lifetime": 64, 59 | "rpl-lifetime-unit": 60, 60 | "rpl-pcs": 1, 61 | "rpl-ocp": 1, 62 | "multicast-addr": "ff05::7", 63 | "LED": "NC", 64 | "SERIAL_TX": "NC", 65 | "SERIAL_RX": "NC", 66 | "SERIAL_CTS": "NC", 67 | "SERIAL_RTS": "NC" 68 | }, 69 | "target_overrides": { 70 | "*": { 71 | "target.network-default-interface-type": "ETHERNET", 72 | "nsapi.default-stack": "NANOSTACK", 73 | "mbed-trace.enable": 1, 74 | "nanostack.configuration": "lowpan_border_router", 75 | "platform.stdio-convert-newlines": true, 76 | "platform.stdio-baud-rate": 115200, 77 | "mbed-mesh-api.heap-size": 40000, 78 | "mbed-mesh-api.heap-stat-info": "&memory_heap_stat", 79 | "mbed-mesh-api.heap-stat-info-definition": "mem_stat_t memory_heap_stat;" 80 | }, 81 | "K64F": { 82 | "LED": "LED_GREEN", 83 | "SERIAL_TX": "PTE0", 84 | "SERIAL_RX": "PTE1", 85 | "SERIAL_CTS": "PTE2", 86 | "SERIAL_RTS": "PTE3", 87 | "kinetis-emac.tx-ring-len":4, 88 | "kinetis-emac.rx-ring-len":4 89 | }, 90 | "K64F_STATIC_BR": { 91 | "LED": "LED_GREEN", 92 | "SERIAL_TX": "PTE0", 93 | "SERIAL_RX": "PTE1", 94 | "SERIAL_CTS": "PTE2", 95 | "SERIAL_RTS": "PTE3", 96 | "kinetis-emac.tx-ring-len":4, 97 | "kinetis-emac.rx-ring-len":4, 98 | "debug-trace": "true", 99 | "pan-id": "0xABBA", 100 | "rf-channel": 17, 101 | "mbed-mesh-api.heap-size": 100000 102 | }, 103 | "K66F": { 104 | "LED": "LED_GREEN", 105 | "kinetis-emac.tx-ring-len":4, 106 | "kinetis-emac.rx-ring-len":4 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /source/mbedtls_wisun_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, 2019, Pelion and affiliates. 3 | */ 4 | 5 | #ifndef MBEDTLS_WISUN_CONFIG_H_ 6 | #define MBEDTLS_WISUN_CONFIG_H_ 7 | 8 | #define MBEDTLS_ENTROPY_MAX_SOURCES 4 // save 320 bytes of RAM (default is 20 entropy source) 9 | #define MBEDTLS_SSL_IN_CONTENT_LEN 4096 // Use 4kB buffers for input instead of 16kB 10 | #define MBEDTLS_SSL_OUT_CONTENT_LEN 4096 // Use 4kB buffers for output instead of 16kB 11 | 12 | //#define MBEDTLS_DEBUG_C 13 | 14 | /* mbed TLS feature support */ 15 | #define MBEDTLS_ECP_NIST_OPTIM 16 | #define MBEDTLS_ECP_DP_SECP256R1_ENABLED 17 | #undef MBEDTLS_ECP_DP_SECP192R1_ENABLED 18 | #undef MBEDTLS_ECP_DP_SECP224R1_ENABLED 19 | #undef MBEDTLS_ECP_DP_SECP384R1_ENABLED 20 | #undef MBEDTLS_ECP_DP_SECP521R1_ENABLED 21 | #undef MBEDTLS_ECP_DP_SECP192K1_ENABLED 22 | #undef MBEDTLS_ECP_DP_SECP224K1_ENABLED 23 | #undef MBEDTLS_ECP_DP_SECP256K1_ENABLED 24 | #undef MBEDTLS_ECP_DP_BP256R1_ENABLED 25 | #undef MBEDTLS_ECP_DP_BP384R1_ENABLED 26 | #undef MBEDTLS_ECP_DP_BP512R1_ENABLED 27 | #undef MBEDTLS_ECP_DP_CURVE25519_ENABLED 28 | 29 | #ifdef MBEDTLS_SSL_TLS_C 30 | #define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH 31 | #define MBEDTLS_SSL_PROTO_TLS1_2 32 | #define MBEDTLS_SSL_EXPORT_KEYS 33 | #define MBEDTLS_SSL_ALL_ALERT_MESSAGES 34 | #endif 35 | 36 | /* mbed TLS modules */ 37 | #define MBEDTLS_BIGNUM_C 38 | #define MBEDTLS_CIPHER_C 39 | #define MBEDTLS_AES_C 40 | #define MBEDTLS_CCM_C 41 | #define MBEDTLS_CTR_DRBG_C 42 | #define MBEDTLS_ECP_C 43 | #define MBEDTLS_MD_C 44 | #define MBEDTLS_PK_C 45 | #define MBEDTLS_SHA256_C 46 | #ifdef MBEDTLS_SSL_TLS_C 47 | #define MBEDTLS_SSL_COOKIE_C 48 | #define MBEDTLS_SSL_CLI_C 49 | #define MBEDTLS_SSL_SRV_C 50 | #endif 51 | #define MBEDTLS_NIST_KW_C 52 | #define MBEDTLS_PEM_PARSE_C 53 | #define MBEDTLS_BASE64_C 54 | #define MBEDTLS_SHA1_C 55 | 56 | /* Save RAM at the expense of ROM */ 57 | #define MBEDTLS_AES_ROM_TABLES 58 | #define MBEDTLS_AES_FEWER_TABLES 59 | 60 | /* Save RAM by adjusting to our exact needs */ 61 | #define MBEDTLS_ECP_MAX_BITS 256 62 | #undef MBEDTLS_MPI_MAX_SIZE 63 | #define MBEDTLS_MPI_MAX_SIZE 128 // 256 bits is 32 bytes 64 | 65 | /* Save ROM and a few bytes of RAM by specifying our own ciphersuite list */ 66 | #define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 67 | 68 | /* Optimization. Remove all not needed stuff */ 69 | #define MBEDTLS_X509_USE_C 70 | #define MBEDTLS_X509_CRT_PARSE_C 71 | #undef MBEDTLS_SSL_SERVER_NAME_INDICATION 72 | #undef MBEDTLS_SELF_TEST 73 | #undef MBEDTLS_SSL_ENCRYPT_THEN_MAC 74 | #undef MBEDTLS_SSL_EXTENDED_MASTER_SECRET 75 | #define MBEDTLS_ASN1_PARSE_C 76 | #define MBEDTLS_ASN1_WRITE_C 77 | #define MBEDTLS_ECDH_C 78 | #define MBEDTLS_ECDSA_C 79 | #undef MBEDTLS_ERROR_C 80 | #define MBEDTLS_GCM_C 81 | #define MBEDTLS_OID_C 82 | #define MBEDTLS_PK_PARSE_C 83 | #define MBEDTLS_PK_WRITE_C 84 | #undef MBEDTLS_RSA_C 85 | #undef MBEDTLS_VERSION_C 86 | #undef MBEDTLS_CERTS_C 87 | #undef MBEDTLS_HMAC_DRBG_C 88 | #define MBEDTLS_CIPHER_MODE_CBC 89 | #undef MBEDTLS_CIPHER_PADDING_PKCS7 90 | #undef MBEDTLS_ECDSA_DETERMINISTIC 91 | #undef MBEDTLS_SSL_SESSION_TICKETS 92 | #undef MBEDTLS_VERSION_FEATURES 93 | #undef MBEDTLS_ERROR_STRERROR_DUMMY 94 | #undef MBEDTLS_SSL_ALPN 95 | #undef MBEDTLS_SSL_TICKET_C 96 | #undef MBEDTLS_HAVE_SSE2 97 | #undef MBEDTLS_PLATFORM_MEMORY 98 | #undef MBEDTLS_PLATFORM_NO_STD_FUNCTIONS 99 | #undef MBEDTLS_DEPRECATED_WARNING 100 | #undef MBEDTLS_DEPRECATED_REMOVED 101 | #undef MBEDTLS_CAMELLIA_SMALL_MEMORY 102 | #undef MBEDTLS_CIPHER_MODE_CFB 103 | #undef MBEDTLS_CIPHER_MODE_CTR 104 | #undef MBEDTLS_CIPHER_NULL_CIPHER 105 | #undef MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS 106 | #undef MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN 107 | #undef MBEDTLS_CIPHER_PADDING_ZEROS 108 | #define MBEDTLS_REMOVE_ARC4_CIPHERSUITES 109 | #undef MBEDTLS_ECP_DP_CURVE25519_ENABLED 110 | #define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED 111 | #undef MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED 112 | #define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED 113 | #undef MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED 114 | #undef MBEDTLS_KEY_EXCHANGE_RSA_ENABLED 115 | #undef MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED 116 | #undef MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED 117 | #define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED 118 | #undef MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED 119 | #undef MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED 120 | #undef MBEDTLS_PK_PARSE_EC_EXTENDED 121 | #undef MBEDTLS_GENPRIME 122 | #undef MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES 123 | #undef MBEDTLS_MEMORY_DEBUG 124 | #undef MBEDTLS_MEMORY_BACKTRACE 125 | #undef MBEDTLS_PK_RSA_ALT_SUPPORT 126 | #undef MBEDTLS_PKCS1_V15 127 | #undef MBEDTLS_PKCS1_V21 128 | #undef MBEDTLS_RSA_NO_CRT 129 | #undef MBEDTLS_SSL_AEAD_RANDOM_IV 130 | #undef MBEDTLS_RSA_NO_CRT 131 | #undef MBEDTLS_SSL_DEBUG_ALL 132 | #undef MBEDTLS_SSL_FALLBACK_SCSV 133 | #undef MBEDTLS_SSL_HW_RECORD_ACCEL 134 | #undef MBEDTLS_SSL_CBC_RECORD_SPLITTING 135 | #undef MBEDTLS_SSL_RENEGOTIATION 136 | #undef MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO 137 | #undef MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE 138 | #undef MBEDTLS_THREADING_ALT 139 | #undef MBEDTLS_THREADING_PTHREAD 140 | #undef MBEDTLS_X509_RSASSA_PSS_SUPPORT 141 | #undef MBEDTLS_AESNI_C 142 | #undef MBEDTLS_ARC4_C 143 | #undef MBEDTLS_CAMELLIA_C 144 | #undef MBEDTLS_DES_C 145 | #undef MBEDTLS_DHM_C 146 | #undef MBEDTLS_HAVEGE_C 147 | #undef MBEDTLS_MD5_C 148 | #undef MBEDTLS_MEMORY_BUFFER_ALLOC_C 149 | #undef MBEDTLS_PADLOCK_C 150 | #undef MBEDTLS_PEM_WRITE_C 151 | #undef MBEDTLS_PKCS5_C 152 | #undef MBEDTLS_PKCS11_C 153 | #undef MBEDTLS_PKCS12_C 154 | #undef MBEDTLS_PLATFORM_C 155 | #undef MBEDTLS_RIPEMD160_C 156 | #undef MBEDTLS_SSL_CACHE_C 157 | #undef MBEDTLS_THREADING_C 158 | #define MBEDTLS_X509_CREATE_C 159 | #define MBEDTLS_X509_CRT_WRITE_C 160 | #undef MBEDTLS_NET_C 161 | #undef MBEDTLS_TIMING_C 162 | #define MBEDTLS_NO_PLATFORM_ENTROPY 163 | 164 | // For MbedTLS 2.x support only (not needed in 3.x anymore) 165 | #define MBEDTLS_SSL_MAX_CONTENT_LEN 4096 // Use 4kB buffers for input and output instead of 16kB 166 | #undef MBEDTLS_SSL_DTLS_BADMAC_LIMIT 167 | #undef MBEDTLS_X509_CHECK_KEY_USAGE 168 | #undef MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE 169 | #undef MBEDTLS_ENABLE_WEAK_CIPHERSUITES 170 | #undef MBEDTLS_SSL_PROTO_TLS1 171 | #undef MBEDTLS_SSL_PROTO_TLS1_1 172 | #undef MBEDTLS_SSL_TRUNCATED_HMAC 173 | #undef MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3 174 | #undef MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION 175 | #undef MBEDTLS_MD2_C 176 | #undef MBEDTLS_MD4_C 177 | #undef MBEDTLS_BLOWFISH_C 178 | #undef MBEDTLS_XTEA_C 179 | #undef MBEDTLS_ZLIB_SUPPORT 180 | 181 | #endif /* MBEDTLS_WISUN_CONFIG_H */ 182 | 183 | -------------------------------------------------------------------------------- /source/mbedtls_thread_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2019, Pelion and affiliates. 3 | */ 4 | 5 | #ifndef MBEDTLS_THREAD_CONFIG_H_ 6 | #define MBEDTLS_THREAD_CONFIG_H_ 7 | 8 | /* mbed TLS feature support */ 9 | #define MBEDTLS_ECP_DP_SECP256R1_ENABLED 10 | #define MBEDTLS_ECP_NIST_OPTIM 11 | #define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED 12 | #define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH 13 | #define MBEDTLS_SSL_PROTO_TLS1_2 14 | #define MBEDTLS_SSL_PROTO_DTLS 15 | #define MBEDTLS_SSL_DTLS_ANTI_REPLAY 16 | #define MBEDTLS_SSL_DTLS_HELLO_VERIFY 17 | #define MBEDTLS_SSL_EXPORT_KEYS 18 | #define MBEDTLS_SSL_ALL_ALERT_MESSAGES 19 | #define MBEDTLS_SSL_IN_CONTENT_LEN 4096 // Use 4kB buffers for input instead of 16kB 20 | #define MBEDTLS_SSL_OUT_CONTENT_LEN 4096 // Use 4kB buffers for output instead of 16kB 21 | 22 | /* mbed TLS modules */ 23 | #define MBEDTLS_AES_C 24 | #define MBEDTLS_BIGNUM_C 25 | #define MBEDTLS_CCM_C 26 | #define MBEDTLS_CIPHER_C 27 | #define MBEDTLS_CTR_DRBG_C 28 | #define MBEDTLS_ECJPAKE_C 29 | #define MBEDTLS_ECP_C 30 | #define MBEDTLS_ENTROPY_C 31 | #define MBEDTLS_ENTROPY_MAX_SOURCES 4 32 | #define MBEDTLS_MD_C 33 | #define MBEDTLS_OID_C 34 | #define MBEDTLS_PK_C 35 | #define MBEDTLS_SHA256_C 36 | #define MBEDTLS_SSL_COOKIE_C 37 | #define MBEDTLS_SSL_CLI_C 38 | #define MBEDTLS_SSL_SRV_C 39 | #define MBEDTLS_SSL_TLS_C 40 | 41 | /* Undef these when building to embedded platform */ 42 | #undef MBEDTLS_NET_C 43 | #undef MBEDTLS_TIMING_C 44 | #undef MBEDTLS_HAVE_TIME 45 | #undef MBEDTLS_HAVE_TIME_DATE 46 | #define MBEDTLS_ENTROPY_HARDWARE_ALT 47 | 48 | /* Save RAM at the expense of ROM */ 49 | #define MBEDTLS_AES_ROM_TABLES 50 | #define MBEDTLS_AES_FEWER_TABLES 51 | 52 | /* Save RAM by adjusting to our exact needs */ 53 | #define MBEDTLS_ECP_MAX_BITS 256 54 | #undef MBEDTLS_MPI_MAX_SIZE 55 | #define MBEDTLS_MPI_MAX_SIZE 32 // 256 bits is 32 bytes 56 | 57 | /* Save ROM and a few bytes of RAM by specifying our own ciphersuite list */ 58 | #define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8 59 | 60 | /* Optimization. Remove all not needed stuff */ 61 | /* For type TYPE_THREAD_SLEEPY_END_DEVICE 62 | #undef MBEDTLS_X509_USE_C 63 | #undef MBEDTLS_X509_CRT_PARSE_C 64 | #undef MBEDTLS_ASN1_PARSE_C 65 | #undef MBEDTLS_ASN1_WRITE_C 66 | #undef MBEDTLS_ECDH_C 67 | #undef MBEDTLS_PK_PARSE_C 68 | #undef MBEDTLS_PK_WRITE_C 69 | #undef MBEDTLS_KEY_EXCHANGE_PSK_ENABLED 70 | #undef MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED 71 | #undef MBEDTLS_X509_CREATE_C 72 | #undef MBEDTLS_X509_CRT_WRITE_C 73 | */ 74 | 75 | /* For TYPE_THREAD_BORDER_ROUTER */ 76 | #define MBEDTLS_X509_USE_C 77 | #define MBEDTLS_X509_CRT_PARSE_C 78 | #define MBEDTLS_ASN1_PARSE_C 79 | #define MBEDTLS_ASN1_WRITE_C 80 | #define MBEDTLS_ECDH_C 81 | #define MBEDTLS_HMAC_DRBG_C 82 | #define MBEDTLS_PK_PARSE_C 83 | #define MBEDTLS_PK_WRITE_C 84 | #define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED 85 | #define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED 86 | #define MBEDTLS_X509_CREATE_C 87 | #define MBEDTLS_X509_CRT_WRITE_C 88 | 89 | #undef MBEDTLS_X509_CRL_PARSE_C 90 | #undef MBEDTLS_SSL_SERVER_NAME_INDICATION 91 | #undef MBEDTLS_SELF_TEST 92 | #undef MBEDTLS_SSL_ENCRYPT_THEN_MAC 93 | #undef MBEDTLS_SSL_EXTENDED_MASTER_SECRET 94 | #undef MBEDTLS_BASE64_C 95 | #undef MBEDTLS_DEBUG_C 96 | #undef MBEDTLS_ECDSA_C 97 | #undef MBEDTLS_ERROR_C 98 | #undef MBEDTLS_GCM_C 99 | #undef MBEDTLS_PEM_PARSE_C 100 | #undef MBEDTLS_RSA_C 101 | #undef MBEDTLS_VERSION_C 102 | #undef MBEDTLS_CERTS_C 103 | #undef MBEDTLS_HMAC_DRBG_C 104 | #undef MBEDTLS_CIPHER_MODE_CBC 105 | #undef MBEDTLS_CIPHER_PADDING_PKCS7 106 | #undef MBEDTLS_ECDSA_DETERMINISTIC 107 | #undef MBEDTLS_SSL_SESSION_TICKETS 108 | #undef MBEDTLS_VERSION_FEATURES 109 | #undef MBEDTLS_ERROR_STRERROR_DUMMY 110 | #undef MBEDTLS_SSL_ALPN 111 | #undef MBEDTLS_SSL_TICKET_C 112 | #undef MBEDTLS_HAVE_SSE2 113 | #undef MBEDTLS_PLATFORM_MEMORY 114 | #undef MBEDTLS_PLATFORM_NO_STD_FUNCTIONS 115 | #undef MBEDTLS_DEPRECATED_WARNING 116 | #undef MBEDTLS_DEPRECATED_REMOVED 117 | #undef MBEDTLS_CAMELLIA_SMALL_MEMORY 118 | #undef MBEDTLS_CIPHER_MODE_CFB 119 | #undef MBEDTLS_CIPHER_MODE_CTR 120 | #undef MBEDTLS_CIPHER_NULL_CIPHER 121 | #undef MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS 122 | #undef MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN 123 | #undef MBEDTLS_CIPHER_PADDING_ZEROS 124 | #define MBEDTLS_REMOVE_ARC4_CIPHERSUITES 125 | #undef MBEDTLS_ECP_DP_CURVE25519_ENABLED 126 | #undef MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED 127 | #undef MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED 128 | #undef MBEDTLS_KEY_EXCHANGE_RSA_ENABLED 129 | #undef MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED 130 | #undef MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED 131 | #undef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED 132 | #undef MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED 133 | #undef MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED 134 | #undef MBEDTLS_PK_PARSE_EC_EXTENDED 135 | #undef MBEDTLS_GENPRIME 136 | #undef MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES 137 | #undef MBEDTLS_MEMORY_DEBUG 138 | #undef MBEDTLS_MEMORY_BACKTRACE 139 | #undef MBEDTLS_PK_RSA_ALT_SUPPORT 140 | #undef MBEDTLS_PKCS1_V15 141 | #undef MBEDTLS_PKCS1_V21 142 | #undef MBEDTLS_RSA_NO_CRT 143 | #undef MBEDTLS_SSL_AEAD_RANDOM_IV 144 | #undef MBEDTLS_RSA_NO_CRT 145 | #undef MBEDTLS_SSL_DEBUG_ALL 146 | #undef MBEDTLS_SSL_FALLBACK_SCSV 147 | #undef MBEDTLS_SSL_HW_RECORD_ACCEL 148 | #undef MBEDTLS_SSL_CBC_RECORD_SPLITTING 149 | #undef MBEDTLS_SSL_RENEGOTIATION 150 | #undef MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO 151 | #undef MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE 152 | #undef MBEDTLS_THREADING_ALT 153 | #undef MBEDTLS_THREADING_PTHREAD 154 | #undef MBEDTLS_X509_RSASSA_PSS_SUPPORT 155 | #undef MBEDTLS_AESNI_C 156 | #undef MBEDTLS_ARC4_C 157 | #undef MBEDTLS_CAMELLIA_C 158 | #undef MBEDTLS_DES_C 159 | #undef MBEDTLS_DHM_C 160 | #undef MBEDTLS_HAVEGE_C 161 | #undef MBEDTLS_MD5_C 162 | #undef MBEDTLS_MEMORY_BUFFER_ALLOC_C 163 | #undef MBEDTLS_PADLOCK_C 164 | #undef MBEDTLS_PEM_WRITE_C 165 | #undef MBEDTLS_PKCS5_C 166 | #undef MBEDTLS_PKCS11_C 167 | #undef MBEDTLS_PKCS12_C 168 | #undef MBEDTLS_PLATFORM_C 169 | #undef MBEDTLS_RIPEMD160_C 170 | #undef MBEDTLS_SHA1_C 171 | #undef MBEDTLS_SSL_CACHE_C 172 | #undef MBEDTLS_THREADING_C 173 | #undef MBEDTLS_X509_CSR_PARSE_C 174 | #undef MBEDTLS_X509_CSR_WRITE_C 175 | #undef MBEDTLS_NET_C 176 | #undef MBEDTLS_TIMING_C 177 | #define MBEDTLS_NO_PLATFORM_ENTROPY 178 | 179 | // For MbedTLS 2.x support only (not needed in 3.x anymore) 180 | #define MBEDTLS_SSL_MAX_CONTENT_LEN 4096 // Use 4kB buffers for input and output instead of 16kB 181 | #undef MBEDTLS_SSL_DTLS_BADMAC_LIMIT 182 | #undef MBEDTLS_X509_CHECK_KEY_USAGE 183 | #undef MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE 184 | #undef MBEDTLS_ENABLE_WEAK_CIPHERSUITES 185 | #undef MBEDTLS_SSL_PROTO_TLS1 186 | #undef MBEDTLS_SSL_PROTO_TLS1_1 187 | #undef MBEDTLS_SSL_TRUNCATED_HMAC 188 | #undef MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3 189 | #undef MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION 190 | #undef MBEDTLS_MD2_C 191 | #undef MBEDTLS_MD4_C 192 | #undef MBEDTLS_BLOWFISH_C 193 | #undef MBEDTLS_XTEA_C 194 | #undef MBEDTLS_ZLIB_SUPPORT 195 | 196 | #endif /* MBEDTLS_CONFIG_H */ 197 | -------------------------------------------------------------------------------- /source/border_router_main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2020, Pelion and affiliates. 3 | */ 4 | 5 | #include 6 | 7 | 8 | #include "mbed.h" 9 | #include "borderrouter_tasklet.h" 10 | #include "drivers/eth_driver.h" 11 | #include "sal-stack-nanostack-slip/Slip.h" 12 | 13 | #include "Nanostack.h" 14 | #include "NanostackEthernetInterface.h" 15 | #include "MeshInterfaceNanostack.h" 16 | #include "EMACInterface.h" 17 | #include "EMAC.h" 18 | 19 | #undef ETH 20 | #undef SLIP 21 | #undef EMAC 22 | #undef CELL 23 | #define ETH 1 24 | #define SLIP 2 25 | #define EMAC 3 26 | #define CELL 4 27 | 28 | #if MBED_CONF_APP_BACKHAUL_DRIVER == CELL 29 | #include "NanostackPPPInterface.h" 30 | #include "PPPInterface.h" 31 | #include "PPP.h" 32 | #endif 33 | 34 | #ifdef MBED_CONF_APP_DEBUG_TRACE 35 | #if MBED_CONF_APP_DEBUG_TRACE == 1 36 | #define APP_TRACE_LEVEL TRACE_ACTIVE_LEVEL_DEBUG 37 | #else 38 | #define APP_TRACE_LEVEL TRACE_ACTIVE_LEVEL_INFO 39 | #endif 40 | #endif //MBED_CONF_APP_DEBUG_TRACE 41 | 42 | #include "ns_hal_init.h" 43 | #include "mesh_system.h" 44 | #include "cmsis_os.h" 45 | #include "arm_hal_interrupt.h" 46 | #include "nanostack_heap_region.h" 47 | 48 | #include "mbed_trace.h" 49 | #define TRACE_GROUP "app" 50 | 51 | #define BOARD 1 52 | #define CONFIG 2 53 | #if MBED_CONF_APP_BACKHAUL_MAC_SRC == BOARD 54 | static uint8_t mac[6]; 55 | #elif MBED_CONF_APP_BACKHAUL_MAC_SRC == CONFIG 56 | static const uint8_t mac[] = MBED_CONF_APP_BACKHAUL_MAC; 57 | #else 58 | #error "MAC address not defined" 59 | #endif 60 | 61 | static DigitalOut led1(MBED_CONF_APP_LED); 62 | 63 | static Ticker led_ticker; 64 | 65 | static void toggle_led1() 66 | { 67 | led1 = !led1; 68 | } 69 | 70 | /** 71 | * \brief Prints string to serial (adds CRLF). 72 | */ 73 | static void trace_printer(const char *str) 74 | { 75 | printf("%s\n", str); 76 | } 77 | 78 | #if MBED_CONF_APP_BACKHAUL_DRIVER == EMAC 79 | static void (*emac_actual_cb)(uint8_t, int8_t); 80 | static int8_t emac_driver_id; 81 | static void emac_link_cb(bool up) 82 | { 83 | if (emac_actual_cb) { 84 | emac_actual_cb(up, emac_driver_id); 85 | } 86 | } 87 | #endif 88 | 89 | /** 90 | * \brief Initializes the MAC backhaul driver. 91 | * This function is called by the border router module. 92 | */ 93 | void backhaul_driver_init(void (*backhaul_driver_status_cb)(uint8_t, int8_t)) 94 | { 95 | // Values allowed in "backhaul-driver" option 96 | #if MBED_CONF_APP_BACKHAUL_DRIVER == SLIP 97 | SlipMACDriver *pslipmacdriver; 98 | int8_t slipdrv_id = -1; 99 | #if defined(MBED_CONF_APP_SLIP_HW_FLOW_CONTROL) 100 | pslipmacdriver = new SlipMACDriver(SERIAL_TX, SERIAL_RX, SERIAL_RTS, SERIAL_CTS); 101 | #else 102 | pslipmacdriver = new SlipMACDriver(SERIAL_TX, SERIAL_RX); 103 | #endif 104 | 105 | if (pslipmacdriver == NULL) { 106 | tr_error("Unable to create SLIP driver"); 107 | return; 108 | } 109 | 110 | tr_info("Using SLIP backhaul driver..."); 111 | 112 | #ifdef MBED_CONF_APP_SLIP_SERIAL_BAUD_RATE 113 | slipdrv_id = pslipmacdriver->Slip_Init(mac, MBED_CONF_APP_SLIP_SERIAL_BAUD_RATE); 114 | #else 115 | tr_warning("baud rate for slip not defined"); 116 | #endif 117 | 118 | if (slipdrv_id >= 0) { 119 | backhaul_driver_status_cb(1, slipdrv_id); 120 | return; 121 | } 122 | 123 | tr_error("Backhaul driver init failed, retval = %d", slipdrv_id); 124 | #elif MBED_CONF_APP_BACKHAUL_DRIVER == EMAC 125 | #undef EMAC 126 | tr_info("Using EMAC backhaul driver..."); 127 | NetworkInterface *net = NetworkInterface::get_default_instance(); 128 | if (!net) { 129 | tr_error("Default network interface not found"); 130 | exit(1); 131 | } 132 | EMACInterface *emacif = net->emacInterface(); 133 | if (!emacif) { 134 | tr_error("Default interface is not EMAC-based"); 135 | exit(1); 136 | } 137 | EMAC &emac = emacif->get_emac(); 138 | Nanostack::EthernetInterface *ns_if; 139 | #if MBED_CONF_APP_BACKHAUL_MAC_SRC == BOARD 140 | /* Let the core code choose address - either from board or EMAC (for 141 | * ETH and SLIP we pass in the board address already in mac[]) */ 142 | nsapi_error_t err = Nanostack::get_instance().add_ethernet_interface(emac, true, &ns_if); 143 | if (err == NSAPI_ERROR_OK) { 144 | /* Read back what they chose into our mac[] */ 145 | ns_if->get_mac_address(mac); 146 | } 147 | #else 148 | nsapi_error_t err = Nanostack::get_instance().add_ethernet_interface(emac, true, &ns_if, mac); 149 | #endif 150 | if (err < 0) { 151 | tr_error("Backhaul driver init failed, retval = %d", err); 152 | } else { 153 | emac_actual_cb = backhaul_driver_status_cb; 154 | emac_driver_id = ns_if->get_driver_id(); 155 | emac.set_link_state_cb(emac_link_cb); 156 | } 157 | #elif MBED_CONF_APP_BACKHAUL_DRIVER == CELL 158 | tr_info("Using CELLULAR backhaul driver..."); 159 | /* Creates PPP service and onboard network stack already here for cellular 160 | * connection to be able to override the link state changed callback */ 161 | PPP *ppp = &PPP::get_default_instance(); 162 | if (!ppp) { 163 | tr_error("PPP not found"); 164 | exit(1); 165 | } 166 | OnboardNetworkStack *stack = &OnboardNetworkStack::get_default_instance(); 167 | if (!stack) { 168 | tr_error("Onboard network stack not found"); 169 | exit(1); 170 | } 171 | OnboardNetworkStack::Interface *interface; 172 | if (stack->add_ppp_interface(*ppp, true, &interface) != NSAPI_ERROR_OK) { 173 | tr_error("Cannot add PPP interface"); 174 | exit(1); 175 | } 176 | Nanostack::PPPInterface *ns_if = static_cast(interface); 177 | ns_if->set_link_state_changed_callback(backhaul_driver_status_cb); 178 | 179 | // Cellular interface configures it to PPP service and onboard stack created above 180 | CellularInterface *net = CellularInterface::get_default_instance(); 181 | if (!net) { 182 | tr_error("Default cellular interface not found"); 183 | exit(1); 184 | } 185 | net->set_default_parameters(); // from cellular nsapi .json configuration 186 | net->set_blocking(false); 187 | if (net->connect() != NSAPI_ERROR_OK) { 188 | tr_error("Connect failure"); 189 | exit(1); 190 | } 191 | #elif MBED_CONF_APP_BACKHAUL_DRIVER == ETH 192 | tr_info("Using ETH backhaul driver..."); 193 | arm_eth_phy_device_register(mac, backhaul_driver_status_cb); 194 | return; 195 | #else 196 | #error "Unsupported backhaul driver" 197 | #endif 198 | #undef ETH 199 | #undef SLIP 200 | #undef EMAC 201 | #undef CELL 202 | } 203 | 204 | 205 | void appl_info_trace(void) 206 | { 207 | tr_info("Starting NanoStack Border Router..."); 208 | tr_info("Build date: %s %s", __DATE__, __TIME__); 209 | #ifdef MBED_MAJOR_VERSION 210 | tr_info("Mbed OS: %d", MBED_VERSION); 211 | #endif 212 | 213 | #if defined(MBED_SYS_STATS_ENABLED) 214 | mbed_stats_sys_t stats; 215 | mbed_stats_sys_get(&stats); 216 | 217 | /* ARM = 1, GCC_ARM = 2, IAR = 3 */ 218 | tr_info("Compiler ID: %d", stats.compiler_id); 219 | /* Compiler versions: 220 | ARM: PVVbbbb (P = Major; VV = Minor; bbbb = build number) 221 | GCC: VVRRPP (VV = Version; RR = Revision; PP = Patch) 222 | IAR: VRRRPPP (V = Version; RRR = Revision; PPP = Patch) 223 | */ 224 | tr_info("Compiler Version: %d", stats.compiler_version); 225 | #endif 226 | } 227 | 228 | /** 229 | * \brief The entry point for this application. 230 | * Sets up the application and starts the border router module. 231 | */ 232 | int main() 233 | { 234 | mbed_trace_init(); // set up the tracing library 235 | mbed_trace_print_function_set(trace_printer); 236 | mbed_trace_config_set(TRACE_MODE_COLOR | APP_TRACE_LEVEL | TRACE_CARRIAGE_RETURN); 237 | 238 | // Have to let mesh_system do net_init_core in case we use 239 | // Nanostack::add_ethernet_interface() 240 | mesh_system_init(); 241 | 242 | nanostack_heap_region_add(); 243 | 244 | #if MBED_CONF_APP_BACKHAUL_MAC_SRC == BOARD 245 | mbed_mac_address((char *)mac); 246 | #endif 247 | 248 | if (MBED_CONF_APP_LED != NC) { 249 | led_ticker.attach_us(toggle_led1, 500000); 250 | } 251 | border_router_tasklet_start(); 252 | } 253 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, and 10 | distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright 13 | owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all other entities 16 | that control, are controlled by, or are under common control with that entity. 17 | For the purposes of this definition, "control" means (i) the power, direct or 18 | indirect, to cause the direction or management of such entity, whether by 19 | contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the 20 | outstanding shares, or (iii) beneficial ownership of such entity. 21 | 22 | "You" (or "Your") shall mean an individual or Legal Entity exercising 23 | permissions granted by this License. 24 | 25 | "Source" form shall mean the preferred form for making modifications, including 26 | but not limited to software source code, documentation source, and configuration 27 | files. 28 | 29 | "Object" form shall mean any form resulting from mechanical transformation or 30 | translation of a Source form, including but not limited to compiled object code, 31 | generated documentation, and conversions to other media types. 32 | 33 | "Work" shall mean the work of authorship, whether in Source or Object form, made 34 | available under the License, as indicated by a copyright notice that is included 35 | in or attached to the work (an example is provided in the Appendix below). 36 | 37 | "Derivative Works" shall mean any work, whether in Source or Object form, that 38 | is based on (or derived from) the Work and for which the editorial revisions, 39 | annotations, elaborations, or other modifications represent, as a whole, an 40 | original work of authorship. For the purposes of this License, Derivative Works 41 | shall not include works that remain separable from, or merely link (or bind by 42 | name) to the interfaces of, the Work and Derivative Works thereof. 43 | 44 | "Contribution" shall mean any work of authorship, including the original version 45 | of the Work and any modifications or additions to that Work or Derivative Works 46 | thereof, that is intentionally submitted to Licensor for inclusion in the Work 47 | by the copyright owner or by an individual or Legal Entity authorized to submit 48 | on behalf of the copyright owner. For the purposes of this definition, 49 | "submitted" means any form of electronic, verbal, or written communication sent 50 | to the Licensor or its representatives, including but not limited to 51 | communication on electronic mailing lists, source code control systems, and 52 | issue tracking systems that are managed by, or on behalf of, the Licensor for 53 | the purpose of discussing and improving the Work, but excluding communication 54 | that is conspicuously marked or otherwise designated in writing by the copyright 55 | owner as "Not a Contribution." 56 | 57 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf 58 | of whom a Contribution has been received by Licensor and subsequently 59 | incorporated within the Work. 60 | 61 | 2. Grant of Copyright License. 62 | 63 | Subject to the terms and conditions of this License, each Contributor hereby 64 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 65 | irrevocable copyright license to reproduce, prepare Derivative Works of, 66 | publicly display, publicly perform, sublicense, and distribute the Work and such 67 | Derivative Works in Source or Object form. 68 | 69 | 3. Grant of Patent License. 70 | 71 | Subject to the terms and conditions of this License, each Contributor hereby 72 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 73 | irrevocable (except as stated in this section) patent license to make, have 74 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where 75 | such license applies only to those patent claims licensable by such Contributor 76 | that are necessarily infringed by their Contribution(s) alone or by combination 77 | of their Contribution(s) with the Work to which such Contribution(s) was 78 | submitted. If You institute patent litigation against any entity (including a 79 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a 80 | Contribution incorporated within the Work constitutes direct or contributory 81 | patent infringement, then any patent licenses granted to You under this License 82 | for that Work shall terminate as of the date such litigation is filed. 83 | 84 | 4. Redistribution. 85 | 86 | You may reproduce and distribute copies of the Work or Derivative Works thereof 87 | in any medium, with or without modifications, and in Source or Object form, 88 | provided that You meet the following conditions: 89 | 90 | You must give any other recipients of the Work or Derivative Works a copy of 91 | this License; and 92 | You must cause any modified files to carry prominent notices stating that You 93 | changed the files; and 94 | You must retain, in the Source form of any Derivative Works that You distribute, 95 | all copyright, patent, trademark, and attribution notices from the Source form 96 | of the Work, excluding those notices that do not pertain to any part of the 97 | Derivative Works; and 98 | If the Work includes a "NOTICE" text file as part of its distribution, then any 99 | Derivative Works that You distribute must include a readable copy of the 100 | attribution notices contained within such NOTICE file, excluding those notices 101 | that do not pertain to any part of the Derivative Works, in at least one of the 102 | following places: within a NOTICE text file distributed as part of the 103 | Derivative Works; within the Source form or documentation, if provided along 104 | with the Derivative Works; or, within a display generated by the Derivative 105 | Works, if and wherever such third-party notices normally appear. The contents of 106 | the NOTICE file are for informational purposes only and do not modify the 107 | License. You may add Your own attribution notices within Derivative Works that 108 | You distribute, alongside or as an addendum to the NOTICE text from the Work, 109 | provided that such additional attribution notices cannot be construed as 110 | modifying the License. 111 | You may add Your own copyright statement to Your modifications and may provide 112 | additional or different license terms and conditions for use, reproduction, or 113 | distribution of Your modifications, or for any such Derivative Works as a whole, 114 | provided Your use, reproduction, and distribution of the Work otherwise complies 115 | with the conditions stated in this License. 116 | 117 | 5. Submission of Contributions. 118 | 119 | Unless You explicitly state otherwise, any Contribution intentionally submitted 120 | for inclusion in the Work by You to the Licensor shall be under the terms and 121 | conditions of this License, without any additional terms or conditions. 122 | Notwithstanding the above, nothing herein shall supersede or modify the terms of 123 | any separate license agreement you may have executed with Licensor regarding 124 | such Contributions. 125 | 126 | 6. Trademarks. 127 | 128 | This License does not grant permission to use the trade names, trademarks, 129 | service marks, or product names of the Licensor, except as required for 130 | reasonable and customary use in describing the origin of the Work and 131 | reproducing the content of the NOTICE file. 132 | 133 | 7. Disclaimer of Warranty. 134 | 135 | Unless required by applicable law or agreed to in writing, Licensor provides the 136 | Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, 137 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 138 | including, without limitation, any warranties or conditions of TITLE, 139 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are 140 | solely responsible for determining the appropriateness of using or 141 | redistributing the Work and assume any risks associated with Your exercise of 142 | permissions under this License. 143 | 144 | 8. Limitation of Liability. 145 | 146 | In no event and under no legal theory, whether in tort (including negligence), 147 | contract, or otherwise, unless required by applicable law (such as deliberate 148 | and grossly negligent acts) or agreed to in writing, shall any Contributor be 149 | liable to You for damages, including any direct, indirect, special, incidental, 150 | or consequential damages of any character arising as a result of this License or 151 | out of the use or inability to use the Work (including but not limited to 152 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or 153 | any and all other commercial damages or losses), even if such Contributor has 154 | been advised of the possibility of such damages. 155 | 156 | 9. Accepting Warranty or Additional Liability. 157 | 158 | While redistributing the Work or Derivative Works thereof, You may choose to 159 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or 160 | other liability obligations and/or rights consistent with this License. However, 161 | in accepting such obligations, You may act only on Your own behalf and on Your 162 | sole responsibility, not on behalf of any other Contributor, and only if You 163 | agree to indemnify, defend, and hold each Contributor harmless for any liability 164 | incurred by, or claims asserted against, such Contributor by reason of your 165 | accepting any such warranty or additional liability. 166 | -------------------------------------------------------------------------------- /source/borderrouter_thread_tasklet.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-2018, Pelion and affiliates. 3 | */ 4 | 5 | #define LOWPAN_ND 0 6 | #define THREAD 1 7 | #define LOWPAN_WS 2 8 | 9 | #if MBED_CONF_APP_MESH_MODE == THREAD 10 | 11 | #include 12 | #include 13 | #include 14 | #include "ns_types.h" 15 | #include "eventOS_event.h" 16 | #include "eventOS_event_timer.h" 17 | #include "eventOS_scheduler.h" 18 | #include "platform/arm_hal_timer.h" 19 | #include "borderrouter_tasklet.h" 20 | #include "borderrouter_helpers.h" 21 | #include "net_interface.h" 22 | #include "rf_wrapper.h" 23 | #include "nwk_stats_api.h" 24 | #include "ip6string.h" 25 | #include "ethernet_mac_api.h" 26 | #include "mac_api.h" 27 | #include "sw_mac.h" 28 | #include "mbed_interface.h" 29 | #include "common_functions.h" 30 | #include "thread_management_if.h" 31 | #include "thread_br_conn_handler.h" 32 | #include "randLIB.h" 33 | 34 | #include "ns_trace.h" 35 | #define TRACE_GROUP "brro" 36 | 37 | #define NR_BACKHAUL_INTERFACE_PHY_DRIVER_READY 2 38 | #define NR_BACKHAUL_INTERFACE_PHY_DOWN 3 39 | #define MESH_LINK_TIMEOUT 100 40 | #define MESH_METRIC 1000 41 | #define THREAD_MAX_CHILD_COUNT 32 42 | 43 | const uint8_t addr_unspecified[16] = {0}; 44 | static mac_api_t *api; 45 | static eth_mac_api_t *eth_mac_api; 46 | 47 | typedef enum { 48 | STATE_UNKNOWN, 49 | STATE_DISCONNECTED, 50 | STATE_LINK_READY, 51 | STATE_BOOTSTRAP, 52 | STATE_CONNECTED, 53 | STATE_MAX_VALUE 54 | } connection_state_e; 55 | 56 | typedef struct { 57 | int8_t prefix_len; 58 | uint8_t prefix[16]; 59 | uint8_t next_hop[16]; 60 | } route_info_t; 61 | 62 | /* Backhaul prefix */ 63 | static uint8_t backhaul_prefix[16] = {0}; 64 | 65 | /* Backhaul default route information */ 66 | static route_info_t backhaul_route; 67 | static int8_t br_tasklet_id = -1; 68 | 69 | /* Network statistics */ 70 | static nwk_stats_t nwk_stats; 71 | 72 | /* Function forward declarations */ 73 | 74 | static link_configuration_s *thread_link_configuration_get(link_configuration_s *link_configuration); 75 | static void network_interface_event_handler(arm_event_s *event); 76 | static void mesh_network_up(void); 77 | static void eth_network_data_init(void); 78 | static net_ipv6_mode_e backhaul_bootstrap_mode = NET_IPV6_BOOTSTRAP_STATIC; 79 | static void borderrouter_tasklet(arm_event_s *event); 80 | 81 | static void print_interface_addr(int id) 82 | { 83 | uint8_t address_buf[128]; 84 | int address_count = 0; 85 | char buf[128]; 86 | 87 | if (arm_net_address_list_get(id, 128, address_buf, &address_count) == 0) { 88 | uint8_t *t_buf = address_buf; 89 | for (int i = 0; i < address_count; ++i) { 90 | ip6tos(t_buf, buf); 91 | tr_info(" [%d] %s", i, buf); 92 | t_buf += 16; 93 | } 94 | } 95 | } 96 | 97 | static void eth_network_data_init() 98 | { 99 | memset(&backhaul_prefix[8], 0, 8); 100 | 101 | /* Bootstrap mode for the backhaul interface */ 102 | #if MBED_CONF_APP_BACKHAUL_DYNAMIC_BOOTSTRAP == 1 103 | backhaul_bootstrap_mode = NET_IPV6_BOOTSTRAP_AUTONOMOUS; 104 | tr_info("NET_IPV6_BOOTSTRAP_AUTONOMOUS"); 105 | 106 | #else 107 | tr_info("NET_IPV6_BOOTSTRAP_STATIC"); 108 | backhaul_bootstrap_mode = NET_IPV6_BOOTSTRAP_STATIC; 109 | // done like this so that prefix can be left out in the dynamic case. 110 | const char *param = MBED_CONF_APP_BACKHAUL_PREFIX; 111 | stoip6(param, strlen(param), backhaul_prefix); 112 | tr_info("backhaul_prefix: %s", print_ipv6(backhaul_prefix)); 113 | 114 | /* Backhaul route configuration*/ 115 | memset(&backhaul_route, 0, sizeof(backhaul_route)); 116 | #ifdef MBED_CONF_APP_BACKHAUL_NEXT_HOP 117 | param = MBED_CONF_APP_BACKHAUL_NEXT_HOP; 118 | stoip6(param, strlen(param), backhaul_route.next_hop); 119 | tr_info("next hop: %s", print_ipv6(backhaul_route.next_hop)); 120 | #endif 121 | param = MBED_CONF_APP_BACKHAUL_DEFAULT_ROUTE; 122 | char *prefix, route_buf[255] = {0}; 123 | /* copy the config value to a non-const buffer */ 124 | strncpy(route_buf, param, sizeof(route_buf) - 1); 125 | prefix = strtok(route_buf, "/"); 126 | backhaul_route.prefix_len = atoi(strtok(NULL, "/")); 127 | stoip6(prefix, strlen(prefix), backhaul_route.prefix); 128 | tr_info("backhaul route prefix: %s", print_ipv6(backhaul_route.prefix)); 129 | #endif 130 | } 131 | 132 | static int thread_interface_up(void) 133 | { 134 | int32_t val; 135 | device_configuration_s device_config; 136 | link_configuration_s link_setup; 137 | link_configuration_s *link_setup_ptr; 138 | int8_t thread_if_id = thread_br_conn_handler_thread_interface_id_get(); 139 | 140 | tr_info("thread_interface_up"); 141 | memset(&device_config, 0, sizeof(device_config)); 142 | 143 | const char *param = MBED_CONF_APP_PSKD; 144 | uint16_t len = strlen(param); 145 | MBED_ASSERT(len > 5 && len < 33); 146 | 147 | device_config.PSKd_ptr = malloc(len + 1); 148 | device_config.PSKd_len = len; 149 | memset(device_config.PSKd_ptr, 0, len + 1); 150 | memcpy(device_config.PSKd_ptr, param, len); 151 | 152 | link_setup_ptr = thread_link_configuration_get(&link_setup); 153 | val = thread_management_node_init(thread_if_id, NULL, &device_config, link_setup_ptr); 154 | 155 | if (val) { 156 | tr_error("Thread init error with code: %is\r\n", (int)val); 157 | return val; 158 | } 159 | 160 | // Additional thread configurations 161 | thread_management_set_link_timeout(thread_if_id, MESH_LINK_TIMEOUT); 162 | thread_management_max_child_count(thread_if_id, THREAD_MAX_CHILD_COUNT); 163 | 164 | val = arm_nwk_interface_up(thread_if_id); 165 | if (val != 0) { 166 | tr_error("mesh0 up Fail with code: %i\r\n", (int)val); 167 | return -1; 168 | } else { 169 | tr_info("mesh0 bootstrap ongoing..."); 170 | } 171 | return 0; 172 | } 173 | 174 | static link_configuration_s *thread_link_configuration_get(link_configuration_s *link_configuration) 175 | { 176 | #ifdef MBED_CONF_APP_THREAD_USE_STATIC_LINK_CONFIG 177 | #if (false == MBED_CONF_APP_THREAD_USE_STATIC_LINK_CONFIG) 178 | // NOT using static link configuration values, return NULL 179 | return NULL; 180 | #endif 181 | #endif 182 | 183 | memset(link_configuration, 0, sizeof(link_configuration_s)); 184 | 185 | MBED_ASSERT(strlen(MBED_CONF_APP_NETWORK_NAME) > 0 && strlen(MBED_CONF_APP_NETWORK_NAME) < 17); 186 | const uint8_t master_key[] = MBED_CONF_APP_THREAD_MASTER_KEY; 187 | MBED_ASSERT(sizeof(master_key) == 16); 188 | const uint8_t pskc[] = MBED_CONF_APP_PSKC; 189 | MBED_ASSERT(sizeof(pskc) == 16); 190 | 191 | const uint8_t extented_panid[] = MBED_CONF_APP_EXTENDED_PAN_ID; 192 | MBED_ASSERT(sizeof(extented_panid) == 8); 193 | const uint8_t mesh_local_prefix[] = MBED_CONF_APP_MESH_LOCAL_PREFIX; 194 | MBED_ASSERT(sizeof(mesh_local_prefix) == 8); 195 | 196 | memcpy(link_configuration->extented_pan_id, extented_panid, sizeof(extented_panid)); 197 | memcpy(link_configuration->mesh_local_ula_prefix, mesh_local_prefix, sizeof(mesh_local_prefix)); 198 | 199 | link_configuration->panId = MBED_CONF_APP_PAN_ID; 200 | tr_info("PAN ID %x", link_configuration->panId); 201 | memcpy(link_configuration->name, MBED_CONF_APP_NETWORK_NAME, strlen(MBED_CONF_APP_NETWORK_NAME)); 202 | link_configuration->timestamp = MBED_CONF_APP_COMMISSIONING_DATASET_TIMESTAMP; 203 | 204 | memcpy(link_configuration->PSKc, pskc, sizeof(pskc)); 205 | memcpy(link_configuration->master_key, master_key, sizeof(master_key)); 206 | link_configuration->securityPolicy = MBED_CONF_APP_THREAD_SECURITY_POLICY; 207 | 208 | link_configuration->rfChannel = MBED_CONF_APP_RF_CHANNEL; 209 | tr_info("RF channel %d", link_configuration->rfChannel); 210 | link_configuration->channel_page = MBED_CONF_APP_RF_CHANNEL_PAGE; 211 | uint32_t channel_mask = MBED_CONF_APP_RF_CHANNEL_MASK; 212 | common_write_32_bit(channel_mask, link_configuration->channel_mask); 213 | 214 | link_configuration->key_rotation = 3600; 215 | link_configuration->key_sequence = 0; 216 | 217 | return link_configuration; 218 | } 219 | 220 | // ethernet interface 221 | static void network_interface_event_handler(arm_event_s *event) 222 | { 223 | bool connectStatus = false; 224 | arm_nwk_interface_status_type_e status = (arm_nwk_interface_status_type_e)event->event_data; 225 | switch (status) { 226 | case (ARM_NWK_BOOTSTRAP_READY): { // Interface configured Bootstrap is ready 227 | 228 | connectStatus = true; 229 | tr_info("BR interface_id: %d", thread_br_conn_handler_eth_interface_id_get()); 230 | if (-1 != thread_br_conn_handler_eth_interface_id_get()) { 231 | // metric set to high priority 232 | if (0 != arm_net_interface_set_metric(thread_br_conn_handler_eth_interface_id_get(), 0)) { 233 | tr_warn("Failed to set metric for eth0."); 234 | } 235 | 236 | if (backhaul_bootstrap_mode == NET_IPV6_BOOTSTRAP_STATIC) { 237 | uint8_t *next_hop_ptr; 238 | if (memcmp(backhaul_route.next_hop, addr_unspecified, 16) == 0) { 239 | next_hop_ptr = NULL; 240 | } else { 241 | next_hop_ptr = backhaul_route.next_hop; 242 | } 243 | tr_debug("Default route prefix: %s/%d", print_ipv6(backhaul_route.prefix), 244 | backhaul_route.prefix_len); 245 | tr_debug("Default route next hop: %s", print_ipv6(backhaul_route.next_hop)); 246 | arm_net_route_add(backhaul_route.prefix, 247 | backhaul_route.prefix_len, 248 | next_hop_ptr, 0xffffffff, 128, 249 | thread_br_conn_handler_eth_interface_id_get()); 250 | } 251 | tr_info("Backhaul interface addresses:"); 252 | print_interface_addr(thread_br_conn_handler_eth_interface_id_get()); 253 | thread_br_conn_handler_ethernet_connection_update(connectStatus); 254 | } 255 | break; 256 | } 257 | case (ARM_NWK_RPL_INSTANCE_FLOODING_READY): // RPL instance have been flooded 258 | tr_info("\rRPL instance have been flooded\r\n"); 259 | break; 260 | case (ARM_NWK_SET_DOWN_COMPLETE): // Interface DOWN command successfully 261 | break; 262 | case (ARM_NWK_NWK_SCAN_FAIL): // Interface have not detect any valid network 263 | tr_warning("\rmesh0 haven't detect any valid nw\r\n"); 264 | break; 265 | case (ARM_NWK_IP_ADDRESS_ALLOCATION_FAIL): // IP address allocation fail(ND, DHCPv4 or DHCPv6) 266 | tr_error("\rNO GP address detected"); 267 | break; 268 | case (ARM_NWK_DUPLICATE_ADDRESS_DETECTED): // User specific GP16 was not valid 269 | tr_error("\rEthernet IPv6 Duplicate addr detected!\r\n"); 270 | break; 271 | case (ARM_NWK_AUHTENTICATION_START_FAIL): // No valid Authentication server detected behind access point ; 272 | tr_error("\rNo valid ath server detected behind AP\r\n"); 273 | break; 274 | case (ARM_NWK_AUHTENTICATION_FAIL): // Network authentication fail by Handshake 275 | tr_error("\rNetwork authentication fail"); 276 | break; 277 | case (ARM_NWK_NWK_CONNECTION_DOWN): // No connection between Access point or Default Router 278 | tr_warning("\rPrefix timeout\r\n"); 279 | break; 280 | case (ARM_NWK_NWK_PARENT_POLL_FAIL): // Sleepy host poll fail 3 time 281 | tr_warning("\rParent poll fail\r\n"); 282 | break; 283 | case (ARM_NWK_PHY_CONNECTION_DOWN): // Interface PHY cable off or serial port interface not respond anymore 284 | tr_error("\reth0 down\r\n"); 285 | break; 286 | default: 287 | tr_warning("\rUnkown nw if event (type: %02x, id: %02x, data: %02x)\r\n", event->event_type, event->event_id, (unsigned int)event->event_data); 288 | break; 289 | } 290 | } 291 | 292 | void thread_interface_event_handler(arm_event_s *event) 293 | { 294 | bool connectStatus = false; 295 | arm_nwk_interface_status_type_e status = (arm_nwk_interface_status_type_e)event->event_data; 296 | switch (status) { 297 | case (ARM_NWK_BOOTSTRAP_READY): { // Interface configured Bootstrap is ready 298 | connectStatus = true; 299 | tr_info("Thread bootstrap ready"); 300 | 301 | if (arm_net_interface_set_metric(thread_br_conn_handler_thread_interface_id_get(), MESH_METRIC) != 0) { 302 | tr_warn("Failed to set metric for mesh0."); 303 | } 304 | 305 | tr_info("RF interface addresses:"); 306 | print_interface_addr(thread_br_conn_handler_thread_interface_id_get()); 307 | 308 | break; 309 | } 310 | case (ARM_NWK_SET_DOWN_COMPLETE): 311 | tr_info("Thread interface down"); 312 | break; 313 | default: 314 | tr_warning("Unkown nw if event (type: %02x, id: %02x, data: %02x)\r\n", event->event_type, event->event_id, (unsigned int)event->event_data); 315 | break; 316 | } 317 | 318 | thread_br_conn_handler_thread_connection_update(connectStatus); 319 | } 320 | 321 | static void mesh_network_up() 322 | { 323 | tr_debug("Create Mesh Interface"); 324 | 325 | int status; 326 | int8_t thread_if_id; 327 | 328 | thread_if_id = arm_nwk_interface_lowpan_init(api, "ThreadInterface"); 329 | tr_info("thread_if_id: %d", thread_if_id); 330 | MBED_ASSERT(thread_if_id >= 0); 331 | 332 | if (thread_if_id < 0) { 333 | tr_error("arm_nwk_interface_lowpan_init() failed"); 334 | return; 335 | } 336 | 337 | status = arm_nwk_interface_configure_6lowpan_bootstrap_set( 338 | thread_if_id, 339 | NET_6LOWPAN_ROUTER, 340 | NET_6LOWPAN_THREAD); 341 | 342 | if (status < 0) { 343 | tr_error("arm_nwk_interface_configure_6lowpan_bootstrap_set() failed"); 344 | return; 345 | } 346 | 347 | thread_br_conn_handler_thread_interface_id_set(thread_if_id); 348 | 349 | status = thread_interface_up(); 350 | MBED_ASSERT(!status); 351 | if (status) { 352 | tr_error("thread_interface_up() failed: %d", status); 353 | } 354 | } 355 | 356 | void thread_rf_init() 357 | { 358 | mac_description_storage_size_t storage_sizes; 359 | storage_sizes.key_lookup_size = 1; 360 | storage_sizes.key_usage_size = 1; 361 | storage_sizes.device_decription_table_size = 32; 362 | storage_sizes.key_description_table_size = 6; 363 | 364 | int8_t rf_driver_id = rf_device_register(); 365 | MBED_ASSERT(rf_driver_id >= 0); 366 | if (rf_driver_id >= 0) { 367 | randLIB_seed_random(); 368 | 369 | if (!api) { 370 | api = ns_sw_mac_create(rf_driver_id, &storage_sizes); 371 | } 372 | } 373 | } 374 | 375 | void border_router_tasklet_start(void) 376 | { 377 | thread_rf_init(); 378 | protocol_stats_start(&nwk_stats); 379 | 380 | eventOS_event_handler_create( 381 | &borderrouter_tasklet, 382 | ARM_LIB_TASKLET_INIT_EVENT); 383 | } 384 | 385 | 386 | static void borderrouter_backhaul_phy_status_cb(uint8_t link_up, int8_t driver_id) 387 | { 388 | arm_event_s event = { 389 | .sender = br_tasklet_id, 390 | .receiver = br_tasklet_id, 391 | .priority = ARM_LIB_MED_PRIORITY_EVENT, 392 | .event_type = APPLICATION_EVENT, 393 | .event_id = NR_BACKHAUL_INTERFACE_PHY_DOWN, 394 | .event_data = driver_id 395 | }; 396 | 397 | if (link_up) { 398 | event.event_id = NR_BACKHAUL_INTERFACE_PHY_DRIVER_READY; 399 | } 400 | 401 | eventOS_event_send(&event); 402 | } 403 | 404 | static int backhaul_interface_up(int8_t driver_id) 405 | { 406 | int retval = -1; 407 | tr_debug("backhaul_interface_up: %i\n", driver_id); 408 | int8_t backhaul_if_id = thread_br_conn_handler_eth_interface_id_get(); 409 | if (backhaul_if_id != -1) { 410 | tr_debug("Border RouterInterface already at active state\n"); 411 | } else { 412 | 413 | if (!eth_mac_api) { 414 | eth_mac_api = ethernet_mac_create(driver_id); 415 | } 416 | 417 | backhaul_if_id = arm_nwk_interface_ethernet_init(eth_mac_api, "bh0"); 418 | 419 | MBED_ASSERT(backhaul_if_id >= 0); 420 | if (backhaul_if_id >= 0) { 421 | tr_debug("Backhaul interface ID: %d", backhaul_if_id); 422 | thread_br_conn_handler_eth_interface_id_set(backhaul_if_id); 423 | arm_nwk_interface_configure_ipv6_bootstrap_set( 424 | backhaul_if_id, backhaul_bootstrap_mode, backhaul_prefix); 425 | arm_nwk_interface_up(backhaul_if_id); 426 | retval = 0; 427 | } else { 428 | tr_debug("Could not init ethernet"); 429 | } 430 | } 431 | return retval; 432 | } 433 | 434 | static int backhaul_interface_down(void) 435 | { 436 | int retval = -1; 437 | if (thread_br_conn_handler_eth_interface_id_get() != -1) { 438 | arm_nwk_interface_down(thread_br_conn_handler_eth_interface_id_get()); 439 | thread_br_conn_handler_eth_interface_id_set(-1); 440 | thread_br_conn_handler_ethernet_connection_update(false); 441 | retval = 0; 442 | } else { 443 | tr_debug("Could not set eth down"); 444 | } 445 | return retval; 446 | } 447 | 448 | #if MBED_CONF_APP_DEBUG_TRACE 449 | static void print_interface_addresses(void) 450 | { 451 | tr_info("Backhaul interface addresses:"); 452 | print_interface_addr(thread_br_conn_handler_eth_interface_id_get()); 453 | 454 | tr_info("RF interface addresses:"); 455 | print_interface_addr(thread_br_conn_handler_thread_interface_id_get()); 456 | } 457 | #endif 458 | 459 | /** 460 | * \brief Border Router Main Tasklet 461 | * 462 | * Tasklet Handle next items: 463 | * 464 | * - EV_INIT event: Set Certificate Chain, RF Interface Boot UP, multicast Init 465 | * - SYSTEM_TIMER event: For RF interface Handshake purpose 466 | * 467 | */ 468 | static void borderrouter_tasklet(arm_event_s *event) 469 | { 470 | arm_library_event_type_e event_type; 471 | event_type = (arm_library_event_type_e)event->event_type; 472 | 473 | switch (event_type) { 474 | case ARM_LIB_NWK_INTERFACE_EVENT: 475 | 476 | if (event->event_id == thread_br_conn_handler_eth_interface_id_get()) { 477 | network_interface_event_handler(event); 478 | } else { 479 | thread_interface_event_handler(event); 480 | } 481 | 482 | break; 483 | // comes from the backhaul_driver_init. 484 | case APPLICATION_EVENT: 485 | if (event->event_id == NR_BACKHAUL_INTERFACE_PHY_DRIVER_READY) { 486 | int8_t net_backhaul_id = (int8_t) event->event_data; 487 | 488 | tr_debug("Backhaul driver ID: %d", net_backhaul_id); 489 | 490 | if (backhaul_interface_up(net_backhaul_id) != 0) { 491 | tr_debug("Backhaul bootstrap start failed"); 492 | } else { 493 | tr_debug("Backhaul bootstrap started"); 494 | } 495 | } else if (event->event_id == NR_BACKHAUL_INTERFACE_PHY_DOWN) { 496 | tr_debug("Backhaul driver ID: %d", (int8_t) event->event_data); 497 | if (backhaul_interface_down() != 0) { 498 | } else { 499 | tr_debug("Backhaul interface is down"); 500 | } 501 | } 502 | break; 503 | 504 | case ARM_LIB_TASKLET_INIT_EVENT: 505 | appl_info_trace(); 506 | br_tasklet_id = event->receiver; 507 | thread_br_conn_handler_init(); 508 | eth_network_data_init(); 509 | backhaul_driver_init(borderrouter_backhaul_phy_status_cb); 510 | mesh_network_up(); 511 | eventOS_event_timer_request(9, ARM_LIB_SYSTEM_TIMER_EVENT, br_tasklet_id, 20000); 512 | break; 513 | 514 | case ARM_LIB_SYSTEM_TIMER_EVENT: 515 | eventOS_event_timer_cancel(event->event_id, event->receiver); 516 | 517 | if (event->event_id == 9) { 518 | #if MBED_CONF_APP_DEBUG_TRACE 519 | arm_print_routing_table(); 520 | arm_print_neigh_cache(); 521 | print_memory_stats(); 522 | // Trace interface addresses. This trace can be removed if nanostack prints added/removed 523 | // addresses. 524 | print_interface_addresses(); 525 | #endif 526 | eventOS_event_timer_request(9, ARM_LIB_SYSTEM_TIMER_EVENT, br_tasklet_id, 20000); 527 | } 528 | break; 529 | 530 | default: 531 | break; 532 | } 533 | } 534 | 535 | #endif // MBED_CONF_APP_MESH_MODE 536 | 537 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Nanostack Border Router 2 | 3 | Nanostack Border Router is a generic Mbed border router implementation that provides the 6LoWPAN ND or Wi-SUN border router initialization logic. Pelion Device Management enabled border router for Wi-SUN can be found from repository [https://github.com/PelionIoT/pelion-border-router](https://github.com/PelionIoT/pelion-border-router). 4 | 5 | 6 | A border router is a network gateway between a wireless 6LoWPAN mesh network and a backhaul network. It controls and relays traffic between the two networks. In a typical setup, a 6LoWPAN border router is connected to another router in the backhaul network (over Ethernet, Cellular or a serial line) which in turn forwards traffic to and from the internet or a private company LAN, for instance. 7 | 8 | ![](images/br_role.png) 9 | 10 | ## Structure 11 | 12 | This application runs on Mbed OS and uses PHY drivers and Nanostack to form a border router. 13 | 14 | ![](images/structure.png) 15 | 16 | The code layout is organized like this: 17 | 18 | ``` 19 | configs/ Contains example configuration files 20 | drivers/ Contains PHY drivers 21 | mbed-os/ Contains Mbed OS, itself 22 | source/ Contains the application code 23 | mbed_app.json Build time configuration file 24 | ``` 25 | 26 | ## Building 27 | 28 | 1. Clone this repository. 29 | 1. Run `mbed deploy`. 30 | 1. Add connectivity driver, if not provided by Mbed OS. 31 | 1. Select target platform. 32 | 1. Select toolchain. 33 | 1. Configure. 34 | 1. Build. 35 | 36 | For example: 37 | 38 | ``` 39 | $ mbed deploy 40 | 41 | $ mbed target K64F 42 | OR 43 | $ mbed target DISCO_F769NI 44 | 45 | $ mbed toolchain GCC_ARM 46 | 47 | $ mbed compile 48 | ``` 49 | 50 | ### Adding connectivity driver 51 | 52 | This application requires the 802.15.4 RF driver to be provided for the networking stack. The driver can be either external, or provided by Mbed OS. 53 | 54 | You can add an external driver by calling: 55 | 56 | ``` 57 | mbed add 58 | ``` 59 | 60 | For example, STM Spirit1 RF driver is added by calling `mbed add stm-spirit1-rf-driver` 61 | 62 | ## Selecting the target platform 63 | 64 | The target platform is the hardware on which the border router runs. There are target platforms already available in Mbed OS. 65 | 66 | To write your own target, follow the instructions in [Adding target support to Mbed OS 5](https://os.mbed.com/docs/mbed-os/latest/porting/porting-targets.html). 67 | 68 | The border router requires an RF driver to be provided for Nanostack. Currently, there are the following drivers available in the Mbed OS: 69 | 70 | * [Atmel AT86RF233](https://github.com/ARMmbed/atmel-rf-driver). 71 | * [Atmel AT86RF212B](https://github.com/ARMmbed/atmel-rf-driver). 72 | * [NXP MCR20A](https://github.com/ARMmbed/mcr20a-rf-driver). 73 | * [STM-s2lp](https://github.com/ARMmbed/mbed-os/tree/master/components/802.15.4_RF). 74 | 75 | Following external driver can be added as described [above](#adding-connectivity-driver): 76 | 77 | * [STM Spirit1](https://github.com/ARMmbed/stm-spirit1-rf-driver). 78 | 79 | The backhaul is either SLIP, Ethernet or Cellular. For Ethernet either an Mbed OS "EMAC" driver can be used, or a native Nanostack driver. Currently, native Nanostack drivers exists for the following backhauls: 80 | 81 | * [K64F Ethernet](https://github.com/ARMmbed/sal-nanostack-driver-k64f-eth). 82 | * [SLIP driver](https://github.com/ARMmbed/sal-stack-nanostack-slip). 83 | 84 | The existing drivers are in the `drivers/` folder. More drivers can be linked in. 85 | 86 | See [Notes on different hardware](https://github.com/ARMmbed/mbed-os-example-mesh-minimal/blob/master/Hardware.md) to see known combinations that work. 87 | 88 | ## Configuring Nanostack Border Router 89 | 90 | Applications using Nanostack Border Router need to use a `.json` file for the configuration. You can find the example configurations in the `configs/` folder. 91 | 92 | ### The backhaul configuration options 93 | 94 | | Field | Description | 95 | |-------------------------------------|---------------------------------------------------------------| 96 | | `backhaul-dynamic-bootstrap` | Defines whether the manually configured backhaul prefix and default route are used, or whether they are learnt automatically via the IPv6 neighbor discovery. False means static and true means automatic configuration. | 97 | | `backhaul-prefix` | The IPv6 prefix (64 bits) assigned to and advertised on the backhaul interface. Example format: `fd00:1:2::` | 98 | | `backhaul-default-route` | The default route (prefix and prefix length) where packets should be forwarded on the backhaul device, default: `::/0`. Example format: `fd00:a1::/10` | 99 | | `backhaul-next-hop` | The next-hop value for the backhaul default route; should be a link-local address of a neighboring router, default: empty (on-link prefix). Example format: `fe80::1` | 100 | | `backhaul-mld` | Enable sending Multicast Listener Discovery reports to backhaul network when a new multicast listener is registered in mesh network. Values: true or false | 101 | 102 | ### 6LoWPAN ND border router options 103 | 104 | | Field | Description | 105 | |-------------------------------------|---------------------------------------------------------------| 106 | | `security-mode` | The 6LoWPAN mesh network traffic (link layer) can be protected with the Private Shared Key (PSK) security mode, allowed values: `NONE` and `PSK`. | 107 | | `psk-key` | A 16-bytes long private shared key to be used when the security mode is PSK. Example format (hexadecimal byte values separated by commas inside brackets): `{0x00, ..., 0x0f}` | 108 | | `multicast-addr` | Multicast forwarding is supported by default. This defines the multicast address to which the border router application forwards multicast packets (on the backhaul and RF interface). Example format: `ff05::5` | 109 | |`ra-router-lifetime`|Defines the router advertisement interval in seconds (default 1024 if left out).| 110 | |`beacon-protocol-id`|Is used to identify beacons. This should not be changed (default 4 if left out).| 111 | 112 | To learn more about 6LoWPAN and the configuration parameters, please read the [6LoWPAN overview](https://os.mbed.com/docs/latest/reference/mesh-tech.html). 113 | 114 | See [configs/6lowpan_Atmel_RF.json](configs/6lowpan_Atmel_RF.json) for an example configuration file. 115 | 116 | #### The routing protocol RPL (6LoWPAN ND) 117 | 118 | Nanostack Border Router uses [RPL](https://tools.ietf.org/html/rfc6550) as the routing protocol on the mesh network side (RF interface) when in 6LoWPAN-ND mode. Currently, only the `grounded/non-storing` operation mode is supported. 119 | 120 | Nanostack Border Router offers the following configuration options for RPL: 121 | 122 | | Field | Description | 123 | |-------------------------------------|---------------------------------------------------------------| 124 | | rpl-instance-id | The RPL instance ID value that identifies the RPL instance, default: 1 | 125 | | rpl-idoublings | RPL Trickle parameter: DIOIntervalDoublings value, default: 12 | 126 | | rpl-imin | RPL Trickle parameter: DIOIntervalMin value, default: 9 | 127 | | rpl-k | RPL Trickle parameter: the redundacy constant k, default: 10 | 128 | | rpl-max-rank-inc | Maximum rank increase value, default: 2048| 129 | | rpl-min-hop-rank-inc | Minimum rank increase value, default: 128 | 130 | | rpl-default-lifetime | Default lifetime for the RPL routes, default: 64 | 131 | | rpl-lifetime-unit | The value of the unit that describes the lifetime (in seconds), default: 60 | 132 | | rpl-pcs | The number of bits that may be allocated to the path control field. | 133 | | rpl-ocp | The Objective Function (OF) to use, values: 1=OF0 (default), 2=MRHOF | 134 | 135 | ### Wi-SUN configuration 136 | 137 | The Wi-SUN specific parameters are listed below. 138 | 139 | | Field | Description | 140 | |-------------------------------------|---------------------------------------------------------------| 141 | | `network-name` | Network name for Wi-SUN the network, MUST be same for all the devices in the network | 142 | | `regulatory-domain` | Defines regulatory domain, refer to [ws_management_api](https://github.com/ARMmbed/mbed-os/blob/master/features/nanostack/sal-stack-nanostack/nanostack/ws_management_api.h) for correct values for your region. | 143 | | `operating-class` | Defines operating class, limited by the regulatory domain | 144 | | `operating-mode` | Defines the operating mode, limited by the regulatory domain | 145 | | `uc-channel-function` | Unicast channel function | 146 | | `bc-channel-function` | Broadcast channel function | 147 | | `uc-fixed-channel` | Fixed channel for unicast | 148 | | `bc-fixed-channel` | Fixed channel for broadcast | 149 | | `uc-dwell-interval` | Unicast dwell interval. Range: 15-255 milliseconds | 150 | | `bc-interval` | Broadcast interval. Duration between broadcast dwell intervals. Range: 0-16777216 milliseconds | 151 | | `bc-dwell-interval` | Broadcast dwell interval. Range: 15-255 milliseconds | 152 | | `certificate-header` | Wi-SUN certificate header file | 153 | | `root-certificate` | Root certificate | 154 | | `own-certificate` | Own certificate | 155 | | `own-certificate-key` | Own certificate's key | 156 | 157 | Regulatory domain, operating class and operating mode are defined in the Wi-SUN PHY-specification. 158 | 159 | **Note:** The configuration examples are for testing purposes only; do not use them for production or expose them. 160 | 161 | #### Backhaul connectivity 162 | 163 | The Nanostack border router application can be connected to a backhaul network. This enables you to connect the devices in a 6LoWPAN mesh network to the internet or a private LAN. The application supports SLIP (IPv6 encapsulation over a serial line), Ethernet and Cellular backhaul connectivity: 164 | 165 | ``` 166 | "config": { 167 | "backhaul-driver": { 168 | "help": "options are ETH, SLIP, EMAC, CELL", 169 | "value": "EMAC" 170 | }, 171 | "backhaul-mac-src": { 172 | "help": "Where to get EUI48 address. Options are BOARD, CONFIG", 173 | "value": "BOARD" 174 | }, 175 | "backhaul-mac": "{0x02, 0x00, 0x00, 0x00, 0x00, 0x01}", 176 | "backhaul-dynamic-bootstrap": true, 177 | "backhaul-prefix": "\"fd00:300::\"", 178 | "backhaul-next-hop": "\"fe80::1\"", 179 | "backhaul-default-route": "\"::/0\"", 180 | ............. 181 | } 182 | ``` 183 | 184 | You can select your preferred option through the configuration file (field `backhaul-driver` in the `config` section). The value `SLIP` includes the SLIP driver, and the value `ETH` compiles the border router application with Nanostack native Ethernet backhaul support. `EMAC` uses the board's default Mbed OS network driver, which must be EMAC-based (derived from EMACInterface). `CELL` uses the boards's default Mbed OS cellular device or external cellular device that is configured to provide the default cellular device. 185 | 186 | You can define the MAC address on the backhaul interface manually (field `backhaul-mac-src` value `CONFIG`). Alternatively, you can use the MAC address provided by the development board (field `backhaul-mac-src` value `BOARD`). By default, the backhaul driver is set to `EMAC` and the MAC address source is `BOARD`. 187 | 188 | You can also set the backhaul bootstrap mode (field `backhaul-dynamic-bootstrap`). By default, the bootstrap mode is set to true, which means the autonomous mode. With the autonomous mode, the border router learns the prefix information automatically from an IPv6 gateway in the Ethernet/SLIP segment. When the parameter is set to false, it enables you to set up a manual configuration of `backhaul-prefix` and `backhaul-default-route`. 189 | 190 | If you use the static bootstrap mode, you need to configure a default route on the backhaul interface to properly forward packets between the backhaul and the 6LoWPAN mesh network. In addition to this, you need to set a backhaul prefix. The static mode creates a site-local IPv6 network from which packets cannot be routed outside. 191 | 192 | When using the autonomous mode in the 6LoWPAN ND configuration, you can set the `prefix-from-backhaul` option to `true` to use the same backhaul prefix on the mesh network side as well. This allows the mesh nodes to be directly connectable from the outside of the mesh network. 193 | 194 | For `CELL` backhaul, no configuration options for addresses are provided. Cellular backhaul device works always in autonomous mode and the border router learns the IPv6 prefix information from the cellular access. 195 | 196 | #### Note on the SLIP backhaul driver 197 | 198 | If you are using a K64F board, use the UART1 serial line of the board with the SLIP driver. See the `pins` section in the [mbed_app.json](./mbed_app.json) configuration file. To use a different UART line, replace the `SERIAL_TX` and `SERIAL_RX` values with correct TX/RX pin names. 199 | 200 | To use the hardware flow control, set the configuration field `slip_hw_flow_control` to true. By default, it is set to false. Before using hardware flow control, make sure the other end of your SLIP interface can handle the flow control. 201 | 202 | For the pin names of your desired UART line, refer to your development board's documentation. 203 | 204 | An example configuration for the SLIP driver: 205 | 206 | ``` 207 | "target_overrides": { 208 | "K64F": { 209 | "SERIAL_TX": "PTE0", 210 | "SERIAL_RX": "PTE1", 211 | "SERIAL_CTS": "PTE2", 212 | "SERIAL_RTS": "PTE3" 213 | } 214 | ``` 215 | 216 | #### Note on EMAC backhaul 217 | 218 | When `backhaul_driver` is set to `EMAC`, the border router uses the target's default network driver, as supplied by `NetworkInterface::get_default_instance`. This must be EMAC-based, derived from EMACInterface. If it is the same driver that a default-constructed `EthernetInterface` would use, so in principle it should work on any board where `EthernetInterface` works. 219 | 220 | To use a different interface, change the setting of `target.default-network-interface-type` in `mbed_app.json` to point to a different interface type, or add an overriding definition of `NetworkInterface::get_default_instance` to the application - this overrides any default supplied by the target board. 221 | 222 | To use Wi-Fi or other more complex EMAC drivers, necessary configuration parameters must be supplied, either using `mbed_app.json` or configuration in the `NetworkInterface::get_default_instance` override. Also, the driver must follow the guidelines of `EMACInterface` - the border router does not call the `EMACInterface`'s `connect` method, so the driver must work with only a `powerup` call to the `EMAC`. 223 | 224 | #### Note on CELL backhaul 225 | 226 | When `backhaul_driver` is set to `CELL`, the border router will use the target's default cellular device, as supplied by `CellularInterface::get_default_instance`. Cellular device must support IPv6 PPP connection mode. Board must supply the default Mbed OS cellular device or there must be an external cellular device that is configured to provide default cellular device to Mbed OS. 227 | 228 | ### Switching the RF shield 229 | 230 | By default, the application uses an Atmel AT86RF233/212B RF driver. You can alternatively use any RF driver provided in the `drivers/` folder or link in your own driver. You can set the configuration for the RF driver in the `json` file. 231 | 232 | To select the Atmel radio shield, use: 233 | 234 | ``` 235 | "radio-type":{ 236 | "help": "options are ATMEL, MCR20, SPIRIT1, S2LP", 237 | "value": "ATMEL" 238 | }, 239 | ``` 240 | 241 | To select the NXP radio shield, use: 242 | 243 | ``` 244 | "radio-type":{ 245 | "help": "options are ATMEL, MCR20, SPIRIT1, S2LP", 246 | "value": "MCR20" 247 | }, 248 | ``` 249 | 250 | To select the STM Spirit1 radio shield, use: 251 | 252 | ``` 253 | "radio-type":{ 254 | "help": "options are ATMEL, MCR20, SPIRIT1, S2LP", 255 | "value": "SPIRIT1" 256 | }, 257 | ``` 258 | 259 | To select the STM S2LP radio shield, use: 260 | 261 | ``` 262 | "radio-type":{ 263 | "help": "options are ATMEL, MCR20, SPIRIT1, S2LP", 264 | "value": "S2LP" 265 | }, 266 | ``` 267 | 268 | If you have chosen the STM Spirit1 Sub-1 GHz RF expansion board [X-NUCLEO-IDS01A4](https://github.com/ARMmbed/stm-spirit1-rf-driver), you need to configure its MAC address in the `mbed_app.json` file. For example: 269 | 270 | ```json 271 | "target_overrides": { 272 | "*": { 273 | "spirit1.mac-address": "{0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7}" 274 | }, 275 | } 276 | ``` 277 | 278 | **Note**: This MAC address must be unique within the 6LoWPAN mesh network. 279 | 280 | After changing the radio shield, recompile the application. 281 | 282 | #### Wi-SUN RF shield 283 | 284 | Currently, only one radio shield, the STM S2LP radio shield, supports Wi-SUN. 285 | 286 | 287 | ### Wi-SUN test configurations 288 | 289 | You can set the Border Router to fixed-channel mode by setting the channel function to fixed-channel, by defining the channel number and by setting the broadcast intervals: 290 | 291 | ``` 292 | "uc-channel-function": 0, 293 | "bc-channel-function": 0, 294 | "uc-fixed-channel": 11, 295 | "bc-fixed-channel": 11, 296 | "bc-dwell-interval": 255, 297 | "bc-interval": 1020, 298 | ``` 299 | 300 | You can set the EAPOL group transient key (GTK) to a predefined value by setting the GTK0: 301 | 302 | ``` 303 | "GTK0": "{0xBB, 0x06, 0x08, 0x57, 0x2C, 0xE1, 0x4D, 0x7B, 0xA2, 0xD1, 0x55, 0x49, 0x9C, 0xC8, 0x51, 0x9B}", 304 | ``` 305 | 306 | For the predefined GTK, the Wireshark IEEE 802.15.4 network decryption key can be calculated using SHA-256('Network name' || GTK0). 307 | 308 | ## File system support 309 | 310 | The application can use the file system as instructed in [Mbed OS storage documentation](https://os.mbed.com/docs/latest/reference/storage.html). The file system is not enabled by default due to a variety of possible configurations. 311 | 312 | File system activation happens by telling the file system the root path to Nanostack. To set the root path, use the function: 313 | 314 | `ns_file_system_set_root_path(root-path)` 315 | 316 | After you have set the root path, Wi-SUN stack reads the configuration settings from the file system. Wi-SUN stack writes the configuration back to the file system after the configuration changes. 317 | 318 | ## Running the border router application 319 | 320 | 1. Find the binary file `nanostack-border-router.bin` in the `BUILD` folder. 321 | 2. Copy the binary to the USB mass storage root of the development board. It is automatically flashed to the target MCU. When the flashing is complete, the board restarts itself. Press the **Reset** button of the development board if it does not restart automatically. 322 | 3. The program begins execution. 323 | 4. Open the [serial connection](#serial-connection-settings), for example PuTTY. 324 | 325 | ## Serial connection settings 326 | 327 | Serial connection settings for the Nanorouter are as follows: 328 | 329 | * Baud-rate = 115200. 330 | * Data bits = 8. 331 | * Stop bits = 1. 332 | 333 | If there is no input from the serial terminal, press the **Reset** button of the development board. 334 | 335 | In the PuTTY main screen, save the session, and click **Open**. This opens a console window showing debug messages from the application. If the console screen is blank, you may need to press the **Reset** button of the board to see the debug information. The serial output from the 6LoWPAN border router looks something like this in the console: 336 | 337 | ``` 338 | [INFO][app ]: Starting Nanostack border router... 339 | [INFO][brro]: NET_IPV6_BOOTSTRAP_AUTONOMOUS 340 | [INFO][app ]: Using ETH backhaul driver... 341 | [INFO][Eth ]: Ethernet cable is connected. 342 | [INFO][addr]: Tentative Address added to IF 1: fe80::ac41:dcff:fe37:72c4 343 | [INFO][addr]: DAD passed on IF 1: fe80::ac41:dcff:fe37:72c4 344 | [INFO][addr]: Tentative Address added to IF 1: 2001:999:21:9ce:ac41:dcff:fe37:72c4 345 | [INFO][addr]: DAD passed on IF 1: 2001:999:21:9ce:ac41:dcff:fe37:72c4 346 | [INFO][brro]: Backhaul bootstrap ready, IPv6 = 2001:999:21:9ce:ac41:dcff:fe37:72c4 347 | [INFO][brro]: Backhaul interface addresses: 348 | [INFO][brro]: [0] fe80::ac41:dcff:fe37:72c4 349 | [INFO][brro]: [1] 2001:999:21:9ce:ac41:dcff:fe37:72c4 350 | [INFO][addr]: Address added to IF 0: fe80::ff:fe00:face 351 | [INFO][br ]: BR nwk base ready for start 352 | [INFO][br ]: Refresh Contexts 353 | [INFO][br ]: Refresh Prefixs 354 | [INFO][addr]: Address added to IF 0: 2001:999:21:9ce:0:ff:fe00:face 355 | [INFO][addr]: Address added to IF 0: fe80::fec2:3d00:4:a0cd 356 | [INFO][brro]: RF bootstrap ready, IPv6 = 2001:999:21:9ce:0:ff:fe00:face 357 | [INFO][brro]: RF interface addresses: 358 | [INFO][brro]: [0] fe80::ff:fe00:face 359 | [INFO][brro]: [1] fe80::fec2:3d00:4:a0cd 360 | [INFO][brro]: [2] 2001:999:21:9ce:0:ff:fe00:face 361 | [INFO][brro]: 6LoWPAN Border Router Bootstrap Complete. 362 | ``` 363 | 364 | ## Known Issues 365 | 366 | - RF shield is using Serial Peripheral Interface (SPI) for communication. Some NUCLEO boards (like NUCLEO_F429ZI) may have a pin [conflict](https://os.mbed.com/teams/ST/wiki/Nucleo-144pins-ethernet-spi-conflict) when SPI is used. 367 | 368 | 369 | ## License and contributions 370 | 371 | The software is provided under Apache-2.0 license. Contributions to this project are accepted under the same license. Please see [contributing.md](CONTRIBUTING.md) for more info. 372 | 373 | This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide. 374 | -------------------------------------------------------------------------------- /source/borderrouter_ws.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2019, Pelion and affiliates. 3 | */ 4 | 5 | #define LOWPAN_ND 0 6 | #define THREAD 1 7 | #define LOWPAN_WS 2 8 | #if MBED_CONF_APP_MESH_MODE == LOWPAN_WS 9 | 10 | #include 11 | #include 12 | #include 13 | #include "eventOS_event.h" 14 | #include "eventOS_event_timer.h" 15 | #include "eventOS_scheduler.h" 16 | #include "platform/arm_hal_timer.h" 17 | #include "borderrouter_tasklet.h" 18 | #include "borderrouter_helpers.h" 19 | #include "net_interface.h" 20 | #include "rf_wrapper.h" 21 | #include "fhss_api.h" 22 | #include "fhss_config.h" 23 | #include "ws_management_api.h" 24 | #include "ws_bbr_api.h" 25 | #include "ip6string.h" 26 | #include "mac_api.h" 27 | #include "ethernet_mac_api.h" 28 | #include "sw_mac.h" 29 | #include "nwk_stats_api.h" 30 | #include "randLIB.h" 31 | #ifdef MBED_CONF_APP_CERTIFICATE_HEADER 32 | #include MBED_CONF_APP_CERTIFICATE_HEADER 33 | #endif 34 | #if defined(MBED_CONF_APP_GTK0) 35 | #include "net_ws_test.h" 36 | #endif 37 | 38 | #include "ns_trace.h" 39 | #define TRACE_GROUP "brro" 40 | 41 | #define NR_BACKHAUL_INTERFACE_PHY_DRIVER_READY 2 42 | #define NR_BACKHAUL_INTERFACE_PHY_DOWN 3 43 | #define MESH_LINK_TIMEOUT 100 44 | #define MESH_METRIC 1000 45 | 46 | #define WS_DEFAULT_REGULATORY_DOMAIN 255 47 | #define WS_DEFAULT_OPERATING_CLASS 255 48 | #define WS_DEFAULT_OPERATING_MODE 255 49 | #define WS_DEFAULT_UC_CHANNEL_FUNCTION 255 50 | #define WS_DEFAULT_BC_CHANNEL_FUNCTION 255 51 | #define WS_DEFAULT_UC_DWELL_INTERVAL 0 52 | #define WS_DEFAULT_BC_INTERVAL 0 53 | #define WS_DEFAULT_BC_DWELL_INTERVAL 0 54 | #define WS_DEFAULT_UC_FIXED_CHANNEL 0xffff 55 | #define WS_DEFAULT_BC_FIXED_CHANNEL 0xffff 56 | 57 | static mac_api_t *mac_api; 58 | static eth_mac_api_t *eth_mac_api; 59 | 60 | typedef enum { 61 | STATE_UNKNOWN, 62 | STATE_DISCONNECTED, 63 | STATE_LINK_READY, 64 | STATE_BOOTSTRAP, 65 | STATE_CONNECTED, 66 | STATE_MAX_VALUE 67 | } connection_state_e; 68 | 69 | typedef struct { 70 | int8_t prefix_len; 71 | uint8_t prefix[16]; 72 | uint8_t next_hop[16]; 73 | } route_info_t; 74 | 75 | typedef struct { 76 | int8_t ws_interface_id; 77 | int8_t net_interface_id; 78 | } ws_br_handler_t; 79 | 80 | static ws_br_handler_t ws_br_handler; 81 | 82 | /* Backhaul prefix */ 83 | static uint8_t backhaul_prefix[16] = {0}; 84 | 85 | /* Backhaul default route information */ 86 | static route_info_t backhaul_route; 87 | static int8_t br_tasklet_id = -1; 88 | 89 | /* Network statistics */ 90 | static nwk_stats_t nwk_stats; 91 | 92 | /* Function forward declarations */ 93 | 94 | static void network_interface_event_handler(arm_event_s *event); 95 | static void mesh_network_up(void); 96 | static void eth_network_data_init(void); 97 | static net_ipv6_mode_e backhaul_bootstrap_mode = NET_IPV6_BOOTSTRAP_STATIC; 98 | static void borderrouter_tasklet(arm_event_s *event); 99 | static int wisun_interface_up(void); 100 | static void wisun_interface_event_handler(arm_event_s *event); 101 | static void network_interface_event_handler(arm_event_s *event); 102 | static int backhaul_interface_down(void); 103 | static void borderrouter_backhaul_phy_status_cb(uint8_t link_up, int8_t driver_id); 104 | extern fhss_timer_t fhss_functions; 105 | 106 | typedef struct { 107 | char *network_name; 108 | uint8_t regulatory_domain; 109 | uint8_t operating_class; 110 | uint8_t operating_mode; 111 | uint8_t uc_channel_function; 112 | uint8_t bc_channel_function; 113 | uint8_t uc_dwell_interval; 114 | uint32_t bc_interval; 115 | uint8_t bc_dwell_interval; 116 | uint16_t uc_fixed_channel; 117 | uint16_t bc_fixed_channel; 118 | } ws_config_t; 119 | static ws_config_t ws_conf; 120 | 121 | static void mesh_network_up() 122 | { 123 | tr_debug("Create Mesh Interface"); 124 | 125 | int status; 126 | int8_t wisun_if_id = ws_br_handler.ws_interface_id; 127 | 128 | status = arm_nwk_interface_configure_6lowpan_bootstrap_set( 129 | wisun_if_id, 130 | NET_6LOWPAN_BORDER_ROUTER, 131 | NET_6LOWPAN_WS); 132 | 133 | if (status < 0) { 134 | tr_error("arm_nwk_interface_configure_6lowpan_bootstrap_set() failed"); 135 | return; 136 | } 137 | 138 | status = wisun_interface_up(); 139 | MBED_ASSERT(!status); 140 | if (status) { 141 | tr_error("wisun_interface_up() failed: %d", status); 142 | } 143 | } 144 | 145 | static void eth_network_data_init() 146 | { 147 | memset(&backhaul_prefix[8], 0, 8); 148 | 149 | /* Bootstrap mode for the backhaul interface */ 150 | #if MBED_CONF_APP_BACKHAUL_DYNAMIC_BOOTSTRAP == 1 151 | backhaul_bootstrap_mode = NET_IPV6_BOOTSTRAP_AUTONOMOUS; 152 | tr_info("NET_IPV6_BOOTSTRAP_AUTONOMOUS"); 153 | 154 | #else 155 | tr_info("NET_IPV6_BOOTSTRAP_STATIC"); 156 | backhaul_bootstrap_mode = NET_IPV6_BOOTSTRAP_STATIC; 157 | // done like this so that prefix can be left out in the dynamic case. 158 | const char *param = MBED_CONF_APP_BACKHAUL_PREFIX; 159 | stoip6(param, strlen(param), backhaul_prefix); 160 | tr_info("backhaul_prefix: %s", print_ipv6(backhaul_prefix)); 161 | 162 | /* Backhaul route configuration*/ 163 | memset(&backhaul_route, 0, sizeof(backhaul_route)); 164 | #ifdef MBED_CONF_APP_BACKHAUL_NEXT_HOP 165 | param = MBED_CONF_APP_BACKHAUL_NEXT_HOP; 166 | stoip6(param, strlen(param), backhaul_route.next_hop); 167 | tr_info("next hop: %s", print_ipv6(backhaul_route.next_hop)); 168 | #endif 169 | param = MBED_CONF_APP_BACKHAUL_DEFAULT_ROUTE; 170 | char *prefix, route_buf[255] = {0}; 171 | /* copy the config value to a non-const buffer */ 172 | strncpy(route_buf, param, sizeof(route_buf) - 1); 173 | prefix = strtok(route_buf, "/"); 174 | backhaul_route.prefix_len = atoi(strtok(NULL, "/")); 175 | stoip6(prefix, strlen(prefix), backhaul_route.prefix); 176 | tr_info("backhaul route prefix: %s", print_ipv6(backhaul_route.prefix)); 177 | #endif 178 | } 179 | 180 | void load_config(void) 181 | { 182 | ws_conf.network_name = malloc(sizeof(MBED_CONF_APP_NETWORK_NAME) + 1); 183 | strcpy(ws_conf.network_name, MBED_CONF_APP_NETWORK_NAME); 184 | #ifdef MBED_CONF_APP_REGULATORY_DOMAIN 185 | ws_conf.regulatory_domain = MBED_CONF_APP_REGULATORY_DOMAIN; 186 | #else 187 | ws_conf.regulatory_domain = WS_DEFAULT_REGULATORY_DOMAIN; 188 | #endif //MBED_CONF_APP_REGULATORY_DOMAIN 189 | #ifdef MBED_CONF_APP_OPERATING_CLASS 190 | ws_conf.operating_class = MBED_CONF_APP_OPERATING_CLASS; 191 | #else 192 | ws_conf.operating_class = WS_DEFAULT_OPERATING_CLASS; 193 | #endif //MBED_CONF_APP_OPERATING_CLASS 194 | #ifdef MBED_CONF_APP_OPERATING_MODE 195 | ws_conf.operating_mode = MBED_CONF_APP_OPERATING_MODE; 196 | #else 197 | ws_conf.operating_mode = WS_DEFAULT_OPERATING_MODE; 198 | #endif //MBED_CONF_APP_OPERATING_MODE 199 | #ifdef MBED_CONF_APP_UC_CHANNEL_FUNCTION 200 | ws_conf.uc_channel_function = MBED_CONF_APP_UC_CHANNEL_FUNCTION; 201 | #else 202 | ws_conf.uc_channel_function = WS_DEFAULT_UC_CHANNEL_FUNCTION; 203 | #endif //MBED_CONF_APP_UC_CHANNEL_FUNCTION 204 | #ifdef MBED_CONF_APP_BC_CHANNEL_FUNCTION 205 | ws_conf.bc_channel_function = MBED_CONF_APP_BC_CHANNEL_FUNCTION; 206 | #else 207 | ws_conf.bc_channel_function = WS_DEFAULT_BC_CHANNEL_FUNCTION; 208 | #endif //MBED_CONF_APP_UC_CHANNEL_FUNCTION 209 | #ifdef MBED_CONF_APP_UC_DWELL_INTERVAL 210 | ws_conf.uc_dwell_interval = MBED_CONF_APP_UC_DWELL_INTERVAL; 211 | #else 212 | ws_conf.uc_dwell_interval = WS_DEFAULT_UC_DWELL_INTERVAL; 213 | #endif //MBED_CONF_APP_UC_DWELL_INTERVAL 214 | #ifdef MBED_CONF_APP_BC_INTERVAL 215 | ws_conf.bc_interval = MBED_CONF_APP_BC_INTERVAL; 216 | #else 217 | ws_conf.bc_interval = WS_DEFAULT_BC_INTERVAL; 218 | #endif //MBED_CONF_APP_BC_INTERVAL 219 | #ifdef MBED_CONF_APP_BC_DWELL_INTERVAL 220 | ws_conf.bc_dwell_interval = MBED_CONF_APP_BC_DWELL_INTERVAL; 221 | #else 222 | ws_conf.bc_dwell_interval = WS_DEFAULT_BC_DWELL_INTERVAL; 223 | #endif //MBED_CONF_APP_BC_DWELL_INTERVAL 224 | // Using randomized fixed channel by default 225 | #ifdef MBED_CONF_APP_UC_FIXED_CHANNEL 226 | ws_conf.uc_fixed_channel = MBED_CONF_APP_UC_FIXED_CHANNEL; 227 | #else 228 | ws_conf.uc_fixed_channel = WS_DEFAULT_UC_FIXED_CHANNEL; 229 | #endif //MBED_CONF_APP_UC_FIXED_CHANNEL 230 | #ifdef MBED_CONF_APP_BC_FIXED_CHANNEL 231 | ws_conf.bc_fixed_channel = MBED_CONF_APP_BC_FIXED_CHANNEL; 232 | #else 233 | ws_conf.bc_fixed_channel = WS_DEFAULT_BC_FIXED_CHANNEL; 234 | #endif //MBED_CONF_APP_BC_FIXED_CHANNEL 235 | } 236 | 237 | void wisun_rf_init() 238 | { 239 | mac_description_storage_size_t storage_sizes; 240 | storage_sizes.device_decription_table_size = 32; 241 | storage_sizes.key_description_table_size = 4; 242 | storage_sizes.key_lookup_size = 1; 243 | storage_sizes.key_usage_size = 1; 244 | 245 | int8_t rf_driver_id = rf_device_register(); 246 | MBED_ASSERT(rf_driver_id >= 0); 247 | if (rf_driver_id >= 0) { 248 | randLIB_seed_random(); 249 | if (!mac_api) { 250 | mac_api = ns_sw_mac_create(rf_driver_id, &storage_sizes); 251 | } 252 | 253 | ws_br_handler.ws_interface_id = arm_nwk_interface_lowpan_init(mac_api, ws_conf.network_name); 254 | 255 | if (ws_br_handler.ws_interface_id < 0) { 256 | tr_error("Wi-SUN interface creation failed"); 257 | return; 258 | } 259 | 260 | if (ws_br_handler.ws_interface_id > -1 && 261 | ws_br_handler.net_interface_id > -1) { 262 | ws_bbr_start(ws_br_handler.ws_interface_id, ws_br_handler.net_interface_id); 263 | } 264 | } 265 | } 266 | 267 | 268 | static int wisun_interface_up(void) 269 | { 270 | int32_t ret; 271 | 272 | fhss_timer_t *fhss_timer_ptr = NULL; 273 | 274 | fhss_timer_ptr = &fhss_functions; 275 | 276 | ret = ws_management_node_init(ws_br_handler.ws_interface_id, ws_conf.regulatory_domain, ws_conf.network_name, fhss_timer_ptr); 277 | if (0 != ret) { 278 | tr_error("WS node init fail - code %"PRIi32"", ret); 279 | return -1; 280 | } 281 | 282 | if (ws_conf.uc_channel_function != WS_DEFAULT_UC_CHANNEL_FUNCTION) { 283 | ret = ws_management_fhss_unicast_channel_function_configure(ws_br_handler.ws_interface_id, ws_conf.uc_channel_function, ws_conf.uc_fixed_channel, ws_conf.uc_dwell_interval); 284 | if (ret != 0) { 285 | tr_error("Unicast channel function configuration failed %"PRIi32"", ret); 286 | return -1; 287 | } 288 | } 289 | if (ws_conf.bc_channel_function != WS_DEFAULT_BC_CHANNEL_FUNCTION || 290 | ws_conf.bc_dwell_interval != WS_DEFAULT_BC_DWELL_INTERVAL || 291 | ws_conf.bc_interval != WS_DEFAULT_BC_INTERVAL) { 292 | ret = ws_management_fhss_broadcast_channel_function_configure(ws_br_handler.ws_interface_id, ws_conf.bc_channel_function, ws_conf.bc_fixed_channel, ws_conf.bc_dwell_interval, ws_conf.bc_interval); 293 | if (ret != 0) { 294 | tr_error("Broadcast channel function configuration failed %"PRIi32"", ret); 295 | return -1; 296 | } 297 | } 298 | 299 | if (ws_conf.uc_dwell_interval != WS_DEFAULT_UC_DWELL_INTERVAL || 300 | ws_conf.bc_dwell_interval != WS_DEFAULT_BC_DWELL_INTERVAL || 301 | ws_conf.bc_interval != WS_DEFAULT_BC_INTERVAL) { 302 | ret = ws_management_fhss_timing_configure(ws_br_handler.ws_interface_id, ws_conf.uc_dwell_interval, ws_conf.bc_interval, ws_conf.bc_dwell_interval); 303 | if (ret != 0) { 304 | tr_error("fhss configuration failed %"PRIi32"", ret); 305 | return -1; 306 | } 307 | } 308 | if (ws_conf.regulatory_domain != WS_DEFAULT_REGULATORY_DOMAIN || 309 | ws_conf.operating_mode != WS_DEFAULT_OPERATING_MODE || 310 | ws_conf.operating_class != WS_DEFAULT_OPERATING_CLASS) { 311 | ret = ws_management_regulatory_domain_set(ws_br_handler.ws_interface_id, ws_conf.regulatory_domain, ws_conf.operating_class, ws_conf.operating_mode); 312 | if (ret != 0) { 313 | tr_error("Regulatory domain configuration failed %"PRIi32"", ret); 314 | return -1; 315 | } 316 | } 317 | 318 | #if defined(MBED_CONF_APP_GTK0) 319 | uint8_t gtk0_value[16] = MBED_CONF_APP_GTK0; 320 | uint8_t *gtks[4] = {gtk0_value, NULL, NULL, NULL}; 321 | ret = ws_test_gtk_set(ws_br_handler.ws_interface_id, gtks); 322 | if (ret != 0) { 323 | tr_error("Test GTK set failed %"PRIi32"", ret); 324 | return -1; 325 | } 326 | tr_info("Test GTK set: %s", trace_array(gtk0_value, 16)); 327 | #endif 328 | 329 | #if defined(MBED_CONF_APP_CERTIFICATE_HEADER) 330 | arm_certificate_chain_entry_s chain_info; 331 | memset(&chain_info, 0, sizeof(arm_certificate_chain_entry_s)); 332 | chain_info.cert_chain[0] = (const uint8_t *) MBED_CONF_APP_ROOT_CERTIFICATE; 333 | chain_info.cert_len[0] = strlen((const char *) MBED_CONF_APP_ROOT_CERTIFICATE) + 1; 334 | chain_info.cert_chain[1] = (const uint8_t *) MBED_CONF_APP_OWN_CERTIFICATE; 335 | chain_info.cert_len[1] = strlen((const char *) MBED_CONF_APP_OWN_CERTIFICATE) + 1; 336 | chain_info.key_chain[1] = (const uint8_t *) MBED_CONF_APP_OWN_CERTIFICATE_KEY; 337 | chain_info.chain_length = 2; 338 | arm_network_certificate_chain_set((const arm_certificate_chain_entry_s *) &chain_info); 339 | #endif 340 | ret = arm_nwk_interface_up(ws_br_handler.ws_interface_id); 341 | if (ret != 0) { 342 | tr_error("mesh0 up Fail with code: %"PRIi32"", ret); 343 | return ret; 344 | } 345 | tr_info("mesh0 bootstrap ongoing.."); 346 | return 0; 347 | } 348 | 349 | void border_router_tasklet_start(void) 350 | { 351 | ws_br_handler.ws_interface_id = -1; 352 | ws_br_handler.net_interface_id = -1; 353 | 354 | load_config(); 355 | wisun_rf_init(); 356 | protocol_stats_start(&nwk_stats); 357 | 358 | eventOS_event_handler_create( 359 | &borderrouter_tasklet, 360 | ARM_LIB_TASKLET_INIT_EVENT); 361 | } 362 | 363 | #undef ETH 364 | #undef SLIP 365 | #undef EMAC 366 | #undef CELL 367 | #define ETH 1 368 | #define SLIP 2 369 | #define EMAC 3 370 | #define CELL 4 371 | 372 | static int backhaul_interface_up(int8_t driver_id) 373 | { 374 | int retval = -1; 375 | tr_debug("backhaul_interface_up: %i", driver_id); 376 | if (ws_br_handler.net_interface_id != -1) { 377 | tr_debug("Border RouterInterface already at active state"); 378 | return retval; 379 | } 380 | 381 | if (!eth_mac_api) { 382 | eth_mac_api = ethernet_mac_create(driver_id); 383 | } 384 | 385 | #if MBED_CONF_APP_BACKHAUL_DRIVER == CELL 386 | if (eth_mac_api->iid64_get) { 387 | ws_br_handler.net_interface_id = arm_nwk_interface_ppp_init(eth_mac_api, "ppp0"); 388 | } else 389 | #endif 390 | { 391 | ws_br_handler.net_interface_id = arm_nwk_interface_ethernet_init(eth_mac_api, "bh0"); 392 | } 393 | 394 | MBED_ASSERT(ws_br_handler.net_interface_id >= 0); 395 | if (ws_br_handler.net_interface_id >= 0) { 396 | tr_debug("Backhaul interface ID: %d", ws_br_handler.net_interface_id); 397 | if (ws_br_handler.ws_interface_id > -1) { 398 | ws_bbr_start(ws_br_handler.ws_interface_id, ws_br_handler.net_interface_id); 399 | } 400 | arm_nwk_interface_configure_ipv6_bootstrap_set( 401 | ws_br_handler.net_interface_id, backhaul_bootstrap_mode, backhaul_prefix); 402 | arm_nwk_interface_up(ws_br_handler.net_interface_id); 403 | retval = 0; 404 | } else { 405 | tr_error("Could not init ethernet"); 406 | } 407 | 408 | return retval; 409 | } 410 | 411 | #undef ETH 412 | #undef SLIP 413 | #undef EMAC 414 | #undef CELL 415 | 416 | static int backhaul_interface_down(void) 417 | { 418 | int retval = -1; 419 | if (ws_br_handler.net_interface_id != -1) { 420 | arm_nwk_interface_down(ws_br_handler.net_interface_id); 421 | ws_br_handler.net_interface_id = -1; 422 | retval = 0; 423 | } else { 424 | tr_debug("Could not set eth down"); 425 | } 426 | return retval; 427 | } 428 | 429 | static void print_interface_addr(int id) 430 | { 431 | uint8_t address_buf[128]; 432 | int address_count = 0; 433 | char buf[128]; 434 | 435 | if (arm_net_address_list_get(id, 128, address_buf, &address_count) == 0) { 436 | uint8_t *t_buf = address_buf; 437 | for (int i = 0; i < address_count; ++i) { 438 | ip6tos(t_buf, buf); 439 | tr_info(" [%d] %s", i, buf); 440 | t_buf += 16; 441 | } 442 | } 443 | } 444 | 445 | #if MBED_CONF_APP_DEBUG_TRACE 446 | static void print_interface_addresses(void) 447 | { 448 | tr_info("Backhaul interface addresses:"); 449 | print_interface_addr(ws_br_handler.net_interface_id); 450 | 451 | tr_info("RF interface addresses:"); 452 | print_interface_addr(ws_br_handler.ws_interface_id); 453 | } 454 | #endif 455 | 456 | /** 457 | * \brief Border Router Main Tasklet 458 | * 459 | * Tasklet Handle next items: 460 | * 461 | * - EV_INIT event: Set Certificate Chain, RF Interface Boot UP, multicast Init 462 | * - SYSTEM_TIMER event: For RF interface Handshake purpose 463 | * 464 | */ 465 | static void borderrouter_tasklet(arm_event_s *event) 466 | { 467 | arm_library_event_type_e event_type; 468 | event_type = (arm_library_event_type_e)event->event_type; 469 | 470 | switch (event_type) { 471 | case ARM_LIB_NWK_INTERFACE_EVENT: 472 | 473 | if (event->event_id == ws_br_handler.net_interface_id) { 474 | network_interface_event_handler(event); 475 | } else { 476 | wisun_interface_event_handler(event); 477 | } 478 | 479 | break; 480 | // comes from the backhaul_driver_init. 481 | case APPLICATION_EVENT: 482 | if (event->event_id == NR_BACKHAUL_INTERFACE_PHY_DRIVER_READY) { 483 | int8_t net_backhaul_id = (int8_t) event->event_data; 484 | 485 | if (backhaul_interface_up(net_backhaul_id) != 0) { 486 | tr_debug("Backhaul bootstrap start failed"); 487 | } else { 488 | tr_debug("Backhaul bootstrap started"); 489 | } 490 | } else if (event->event_id == NR_BACKHAUL_INTERFACE_PHY_DOWN) { 491 | if (backhaul_interface_down() == 0) { 492 | tr_debug("Backhaul interface is down"); 493 | } 494 | } 495 | break; 496 | 497 | case ARM_LIB_TASKLET_INIT_EVENT: 498 | br_tasklet_id = event->receiver; 499 | eth_network_data_init(); 500 | backhaul_driver_init(borderrouter_backhaul_phy_status_cb); 501 | mesh_network_up(); 502 | eventOS_event_timer_request(9, ARM_LIB_SYSTEM_TIMER_EVENT, br_tasklet_id, 20000); 503 | break; 504 | 505 | case ARM_LIB_SYSTEM_TIMER_EVENT: 506 | eventOS_event_timer_cancel(event->event_id, event->receiver); 507 | 508 | if (event->event_id == 9) { 509 | #if MBED_CONF_APP_DEBUG_TRACE 510 | arm_print_routing_table(); 511 | arm_print_neigh_cache(); 512 | print_memory_stats(); 513 | // Trace interface addresses. This trace can be removed if nanostack prints added/removed 514 | // addresses. 515 | print_interface_addresses(); 516 | #endif 517 | eventOS_event_timer_request(9, ARM_LIB_SYSTEM_TIMER_EVENT, br_tasklet_id, 20000); 518 | } 519 | break; 520 | 521 | default: 522 | break; 523 | } 524 | } 525 | 526 | static void borderrouter_backhaul_phy_status_cb(uint8_t link_up, int8_t driver_id) 527 | { 528 | arm_event_s event = { 529 | .sender = br_tasklet_id, 530 | .receiver = br_tasklet_id, 531 | .priority = ARM_LIB_MED_PRIORITY_EVENT, 532 | .event_type = APPLICATION_EVENT, 533 | .event_data = driver_id 534 | }; 535 | 536 | if (link_up) { 537 | event.event_id = NR_BACKHAUL_INTERFACE_PHY_DRIVER_READY; 538 | } else { 539 | event.event_id = NR_BACKHAUL_INTERFACE_PHY_DOWN; 540 | } 541 | 542 | eventOS_event_send(&event); 543 | } 544 | 545 | // ethernet interface 546 | static void network_interface_event_handler(arm_event_s *event) 547 | { 548 | arm_nwk_interface_status_type_e status = (arm_nwk_interface_status_type_e)event->event_data; 549 | switch (status) { 550 | case (ARM_NWK_BOOTSTRAP_READY): { // Interface configured Bootstrap is ready 551 | 552 | tr_info("BR interface_id: %d", ws_br_handler.net_interface_id); 553 | if (-1 != ws_br_handler.net_interface_id) { 554 | // metric set to high priority 555 | if (0 != arm_net_interface_set_metric(ws_br_handler.net_interface_id, 0)) { 556 | tr_warn("Failed to set metric for eth0."); 557 | } 558 | 559 | if (backhaul_bootstrap_mode == NET_IPV6_BOOTSTRAP_STATIC) { 560 | uint8_t *next_hop_ptr; 561 | 562 | if (memcmp(backhaul_route.next_hop, (const uint8_t[16]) { 563 | 0 564 | }, 16) == 0) { 565 | next_hop_ptr = NULL; 566 | } else { 567 | next_hop_ptr = backhaul_route.next_hop; 568 | } 569 | tr_debug("Default route prefix: %s/%d", print_ipv6(backhaul_route.prefix), 570 | backhaul_route.prefix_len); 571 | tr_debug("Default route next hop: %s", print_ipv6(backhaul_route.next_hop)); 572 | arm_net_route_add(backhaul_route.prefix, 573 | backhaul_route.prefix_len, 574 | next_hop_ptr, 0xffffffff, 128, 575 | ws_br_handler.net_interface_id); 576 | } 577 | tr_info("Backhaul interface addresses:"); 578 | print_interface_addr(ws_br_handler.net_interface_id); 579 | } 580 | break; 581 | } 582 | case (ARM_NWK_RPL_INSTANCE_FLOODING_READY): // RPL instance have been flooded 583 | tr_info("RPL instance have been flooded"); 584 | break; 585 | case (ARM_NWK_SET_DOWN_COMPLETE): // Interface DOWN command successfully 586 | break; 587 | case (ARM_NWK_NWK_SCAN_FAIL): // Interface have not detect any valid network 588 | tr_warning("mesh0 haven't detect any valid nwk"); 589 | break; 590 | case (ARM_NWK_IP_ADDRESS_ALLOCATION_FAIL): // IP address allocation fail(ND, DHCPv4 or DHCPv6) 591 | tr_error("NO GP address detected"); 592 | break; 593 | case (ARM_NWK_DUPLICATE_ADDRESS_DETECTED): // User specific GP16 was not valid 594 | tr_error("Ethernet IPv6 Duplicate addr detected!"); 595 | break; 596 | case (ARM_NWK_AUHTENTICATION_START_FAIL): // No valid Authentication server detected behind access point ; 597 | tr_error("No valid ath server detected behind AP"); 598 | break; 599 | case (ARM_NWK_AUHTENTICATION_FAIL): // Network authentication fail by Handshake 600 | tr_error("Network authentication fail"); 601 | break; 602 | case (ARM_NWK_NWK_CONNECTION_DOWN): // No connection between Access point or Default Router 603 | tr_warning("Prefix timeout"); 604 | break; 605 | case (ARM_NWK_NWK_PARENT_POLL_FAIL): // Sleepy host poll fail 3 time 606 | tr_warning("Parent poll fail"); 607 | break; 608 | case (ARM_NWK_PHY_CONNECTION_DOWN): // Interface PHY cable off or serial port interface not respond anymore 609 | tr_error("eth0 down"); 610 | break; 611 | default: 612 | tr_warning("Unknown nwk if event (type: %02x, id: %02x, data: %02x)", event->event_type, event->event_id, (unsigned int)event->event_data); 613 | break; 614 | } 615 | } 616 | 617 | static void wisun_interface_event_handler(arm_event_s *event) 618 | { 619 | arm_nwk_interface_status_type_e status = (arm_nwk_interface_status_type_e)event->event_data; 620 | switch (status) { 621 | case (ARM_NWK_BOOTSTRAP_READY): { // Interface configured Bootstrap is ready 622 | tr_info("Wisun bootstrap ready"); 623 | 624 | if (arm_net_interface_set_metric(ws_br_handler.ws_interface_id, MESH_METRIC) != 0) { 625 | tr_warn("Failed to set metric for mesh0."); 626 | } 627 | 628 | tr_info("RF interface addresses:"); 629 | print_interface_addr(ws_br_handler.ws_interface_id); 630 | 631 | break; 632 | } 633 | case (ARM_NWK_SET_DOWN_COMPLETE): 634 | tr_info("Wisun interface down"); 635 | break; 636 | default: 637 | tr_warning("Unknown nwk if event (type: %02x, id: %02x, data: %02x)", event->event_type, event->event_id, (unsigned int)event->event_data); 638 | break; 639 | } 640 | 641 | } 642 | 643 | #endif 644 | -------------------------------------------------------------------------------- /source/borderrouter_tasklet.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-2018, Pelion and affiliates. 3 | */ 4 | 5 | #define LOWPAN_ND 0 6 | #define THREAD 1 7 | #define LOWPAN_WS 2 8 | #if MBED_CONF_APP_MESH_MODE == LOWPAN_ND 9 | 10 | #include 11 | #include 12 | #include "ns_types.h" 13 | #include "eventOS_event.h" 14 | #include "eventOS_event_timer.h" 15 | #include "eventOS_scheduler.h" 16 | #include "multicast_api.h" 17 | #include "whiteboard_api.h" 18 | #include "platform/arm_hal_timer.h" 19 | #include "borderrouter_tasklet.h" 20 | #include "borderrouter_helpers.h" 21 | #include "net_interface.h" 22 | #include "cfg_parser.h" 23 | #include "rf_wrapper.h" 24 | #include "nwk_stats_api.h" 25 | #include "net_interface.h" 26 | #include "ip6string.h" 27 | #include "net_rpl.h" 28 | #include "mac_api.h" 29 | #include "ethernet_mac_api.h" 30 | #include "sw_mac.h" 31 | 32 | #include "static_6lowpan_config.h" 33 | 34 | #include "ns_trace.h" 35 | #define TRACE_GROUP "brro" 36 | 37 | #define NR_BACKHAUL_INTERFACE_PHY_DRIVER_READY 2 38 | #define NR_BACKHAUL_INTERFACE_PHY_DOWN 3 39 | 40 | const uint8_t addr_unspecified[16] = {0}; 41 | static mac_api_t *api; 42 | static eth_mac_api_t *eth_mac_api; 43 | 44 | /* The border router tasklet runs in grounded/non-storing mode */ 45 | #define RPL_FLAGS RPL_GROUNDED | BR_DODAG_MOP_NON_STORING | RPL_DODAG_PREF(0) 46 | 47 | typedef enum interface_bootstrap_state { 48 | INTERFACE_IDLE_PHY_NOT_READY, 49 | INTERFACE_IDLE_STATE, 50 | INTERFACE_BOOTSTRAP_ACTIVE, 51 | INTERFACE_CONNECTED 52 | } interface_bootstrap_state_e; 53 | 54 | typedef struct { 55 | uint8_t DODAG_ID[16]; 56 | uint8_t rpl_instance_id; 57 | uint8_t rpl_setups; 58 | } rpl_setup_info_t; 59 | 60 | typedef struct { 61 | int8_t prefix_len; 62 | uint8_t prefix[16]; 63 | uint8_t next_hop[16]; 64 | } route_info_t; 65 | 66 | /* Border router channel list */ 67 | static channel_list_s channel_list; 68 | 69 | /* Channel masks for different RF types */ 70 | static const uint32_t channel_mask_0_2_4ghz = 0x07fff800; 71 | 72 | /* Border router settings */ 73 | static border_router_setup_s br; 74 | 75 | /* RPL routing settings */ 76 | static rpl_setup_info_t rpl_setup_info; 77 | 78 | /* DODAG configuration */ 79 | static dodag_config_t dodag_config; 80 | 81 | /* Backhaul prefix */ 82 | static uint8_t backhaul_prefix[16] = {0}; 83 | 84 | /* Backhaul default route information */ 85 | static route_info_t backhaul_route; 86 | 87 | /* Should prefix on the backhaul used for PAN as well? */ 88 | static uint8_t rf_prefix_from_backhaul = 0; 89 | 90 | static net_6lowpan_mode_e operating_mode = NET_6LOWPAN_BORDER_ROUTER; 91 | static net_6lowpan_mode_extension_e operating_mode_extension = NET_6LOWPAN_ND_WITH_MLE; 92 | static interface_bootstrap_state_e net_6lowpan_state = INTERFACE_IDLE_PHY_NOT_READY; 93 | static interface_bootstrap_state_e net_backhaul_state = INTERFACE_IDLE_PHY_NOT_READY; 94 | static net_ipv6_mode_e backhaul_bootstrap_mode = NET_IPV6_BOOTSTRAP_STATIC; 95 | 96 | static const uint8_t gp16_address_suffix[6] = {0x00, 0x00, 0x00, 0xff, 0xfe, 0x00}; 97 | 98 | static int8_t br_tasklet_id = -1; 99 | static int8_t net_6lowpan_id = -1; 100 | static int8_t backhaul_if_id = -1; 101 | 102 | /* Network statistics */ 103 | static nwk_stats_t nwk_stats; 104 | 105 | /* Link layer security information */ 106 | static net_6lowpan_link_layer_sec_mode_e link_security_mode; 107 | static net_link_layer_psk_security_info_s link_layer_psk; 108 | static net_tls_cipher_e pana_security_suite; 109 | 110 | static uint8_t multicast_addr[16] = {0}; 111 | 112 | /* Function forward declarations */ 113 | static void app_parse_network_event(arm_event_s *event); 114 | static void borderrouter_tasklet(arm_event_s *event); 115 | static void initialize_channel_list(uint32_t channel); 116 | static void start_6lowpan(const uint8_t *backhaul_address); 117 | static int8_t rf_interface_init(void); 118 | static void load_config(void); 119 | 120 | void border_router_tasklet_start(void) 121 | { 122 | /* initialize Radio module*/ 123 | net_6lowpan_id = rf_interface_init(); 124 | 125 | load_config(); 126 | 127 | protocol_stats_start(&nwk_stats); 128 | 129 | eventOS_event_handler_create( 130 | &borderrouter_tasklet, 131 | ARM_LIB_TASKLET_INIT_EVENT); 132 | } 133 | 134 | static void print_interface_addr(int id) 135 | { 136 | uint8_t address_buf[128]; 137 | int address_count = 0; 138 | char buf[128]; 139 | 140 | if (arm_net_address_list_get(id, 128, address_buf, &address_count) == 0) { 141 | uint8_t *t_buf = address_buf; 142 | for (int i = 0; i < address_count; ++i) { 143 | ip6tos(t_buf, buf); 144 | tr_info(" [%d] %s", i, buf); 145 | t_buf += 16; 146 | } 147 | } 148 | } 149 | 150 | static void initialize_channel_list(uint32_t channel) 151 | { 152 | const int_fast8_t word_index = channel / 32; 153 | const int_fast8_t bit_index = channel % 32; 154 | 155 | if (channel > 0) { 156 | /* Zero channel value means listen all channels */ 157 | memset(&channel_list.channel_mask, 0, sizeof(channel_list.channel_mask)); 158 | channel_list.channel_mask[word_index] |= ((uint32_t) 1 << bit_index); 159 | } 160 | } 161 | 162 | static void load_config(void) 163 | { 164 | const char *prefix, *psk; 165 | uint8_t nd_prefix[16]; 166 | 167 | prefix = cfg_string(global_config, "PREFIX", NULL); 168 | 169 | if (!prefix) { 170 | tr_error("No RF prefix in configuration!"); 171 | return; 172 | } 173 | 174 | stoip6(prefix, strlen(prefix), nd_prefix); 175 | 176 | prefix = cfg_string(global_config, "BACKHAUL_PREFIX", NULL); 177 | if (!prefix) { 178 | tr_error("No backhaul prefix in configuration!"); 179 | return; 180 | } 181 | 182 | stoip6(prefix, strlen(prefix), backhaul_prefix); 183 | memset(&backhaul_prefix[8], 0, 8); 184 | 185 | prefix = cfg_string(global_config, "MULTICAST_ADDR", NULL); 186 | if (!prefix) { 187 | tr_error("No multicast address in configuration!"); 188 | return; 189 | } 190 | 191 | stoip6(prefix, strlen(prefix), multicast_addr); 192 | 193 | /* Set up channel page and channgel mask */ 194 | memset(&channel_list, 0, sizeof(channel_list)); 195 | channel_list.channel_page = (channel_page_e)cfg_int(global_config, "RF_CHANNEL_PAGE", CHANNEL_PAGE_0); 196 | channel_list.channel_mask[0] = cfg_int(global_config, "RF_CHANNEL_MASK", channel_mask_0_2_4ghz); 197 | 198 | prefix = cfg_string(global_config, "NETWORK_ID", "NETWORK000000000"); 199 | memcpy(br.network_id, prefix, 16); 200 | 201 | br.mac_panid = cfg_int(global_config, "PAN_ID", 0x0691); 202 | tr_info("PANID: %x", br.mac_panid); 203 | br.mac_short_adr = cfg_int(global_config, "SHORT_MAC_ADDRESS", 0xffff); 204 | br.ra_life_time = cfg_int(global_config, "RA_ROUTER_LIFETIME", 1024); 205 | br.beacon_protocol_id = cfg_int(global_config, "BEACON_PROTOCOL_ID", 4); 206 | 207 | memcpy(br.lowpan_nd_prefix, nd_prefix, 8); 208 | br.abro_version_num = 0; 209 | 210 | /* RPL routing setup */ 211 | rpl_setup_info.rpl_instance_id = cfg_int(global_config, "RPL_INSTANCE_ID", 1); 212 | rpl_setup_info.rpl_setups = RPL_FLAGS; 213 | 214 | /* generate DODAG ID */ 215 | memcpy(rpl_setup_info.DODAG_ID, nd_prefix, 8); 216 | if (br.mac_short_adr < 0xfffe) { 217 | memcpy(&rpl_setup_info.DODAG_ID[8], gp16_address_suffix, 6); 218 | rpl_setup_info.DODAG_ID[14] = (br.mac_short_adr >> 8); 219 | rpl_setup_info.DODAG_ID[15] = br.mac_short_adr; 220 | } else { 221 | rf_read_mac_address(&rpl_setup_info.DODAG_ID[8]); 222 | rpl_setup_info.DODAG_ID[8] ^= 2; 223 | } 224 | 225 | /* DODAG configuration */ 226 | dodag_config.DAG_DIO_INT_DOUB = cfg_int(global_config, "RPL_IDOUBLINGS", 12); 227 | dodag_config.DAG_DIO_INT_MIN = cfg_int(global_config, "RPL_IMIN", 9); 228 | dodag_config.DAG_DIO_REDU = cfg_int(global_config, "RPL_K", 10); 229 | dodag_config.DAG_MAX_RANK_INC = cfg_int(global_config, "RPL_MAX_RANK_INC", 2048); 230 | dodag_config.DAG_MIN_HOP_RANK_INC = cfg_int(global_config, "RPL_MIN_HOP_RANK_INC", 128); 231 | dodag_config.LIFE_IN_SECONDS = cfg_int(global_config, "RPL_LIFETIME_UNIT", 64); 232 | dodag_config.LIFETIME_UNIT = cfg_int(global_config, "RPL_DEFAULT_LIFETIME", 60); 233 | dodag_config.DAG_SEC_PCS = cfg_int(global_config, "RPL_PCS", 1); 234 | dodag_config.DAG_OCP = cfg_int(global_config, "RPL_OCP", 1); 235 | 236 | bool dynamic_bootstrap = (net_ipv6_mode_e)cfg_int(global_config, "BACKHAUL_DYNAMIC_BOOTSTRAP", 0); 237 | 238 | if (dynamic_bootstrap == 1) { 239 | backhaul_bootstrap_mode = NET_IPV6_BOOTSTRAP_AUTONOMOUS; 240 | tr_info("NET_IPV6_BOOTSTRAP_AUTONOMOUS"); 241 | } else { 242 | tr_info("NET_IPV6_BOOTSTRAP_STATIC"); 243 | backhaul_bootstrap_mode = NET_IPV6_BOOTSTRAP_STATIC; 244 | } 245 | 246 | /* Bootstrap mode for the backhaul interface */ 247 | rf_prefix_from_backhaul = cfg_int(global_config, "PREFIX_FROM_BACKHAUL", 0); 248 | 249 | /* Backhaul default route */ 250 | memset(&backhaul_route, 0, sizeof(backhaul_route)); 251 | psk = cfg_string(global_config, "BACKHAUL_NEXT_HOP", NULL); 252 | 253 | if (psk) { 254 | stoip6(psk, strlen(psk), backhaul_route.next_hop); 255 | } 256 | 257 | psk = cfg_string(global_config, "BACKHAUL_DEFAULT_ROUTE", NULL); 258 | 259 | if (psk) { 260 | char *prefix, route_buf[255] = {0}; 261 | 262 | /* copy the config value to a non-const buffer */ 263 | strncpy(route_buf, psk, sizeof(route_buf) - 1); 264 | prefix = strtok(route_buf, "/"); 265 | backhaul_route.prefix_len = atoi(strtok(NULL, "/")); 266 | 267 | stoip6(prefix, strlen(prefix), backhaul_route.prefix); 268 | } 269 | 270 | prefix = cfg_string(global_config, "SECURITY_MODE", "NONE"); 271 | 272 | if (strcmp(prefix, "NONE") == 0) { 273 | link_security_mode = NET_SEC_MODE_NO_LINK_SECURITY; 274 | tr_warn("Security NOT enabled"); 275 | return; 276 | } 277 | 278 | psk = cfg_string(global_config, "PSK_KEY", NULL); 279 | 280 | if (!psk) { 281 | tr_error("No PSK set in configuration!"); 282 | return; 283 | } 284 | 285 | link_layer_psk.key_id = cfg_int(global_config, "PSK_KEY_ID", 1); 286 | memcpy(link_layer_psk.security_key, psk, 16); 287 | 288 | if (strcmp(prefix, "PSK") == 0) { 289 | tr_debug("Using PSK security mode, key ID = %d", link_layer_psk.key_id); 290 | link_security_mode = NET_SEC_MODE_PSK_LINK_SECURITY; 291 | } else if (strcmp(prefix, "PANA") == 0) { 292 | const char *mode = cfg_string(global_config, "PANA_MODE", "PSK"); 293 | link_security_mode = NET_SEC_MODE_PANA_LINK_SECURITY; 294 | if (strcmp(mode, "ECC") == 0) { 295 | pana_security_suite = NET_TLS_ECC_CIPHER; 296 | } else if (strcmp(mode, "ECC+PSK") == 0) { 297 | pana_security_suite = NET_TLS_PSK_AND_ECC_CIPHER; 298 | } else { 299 | pana_security_suite = NET_TLS_PSK_CIPHER; 300 | } 301 | } 302 | } 303 | 304 | static int8_t rf_interface_init(void) 305 | { 306 | static char phy_name[] = "mesh0"; 307 | int8_t rfid = -1; 308 | int8_t rf_phy_device_register_id = rf_device_register(); 309 | tr_debug("RF device ID: %d", rf_phy_device_register_id); 310 | 311 | if (rf_phy_device_register_id >= 0) { 312 | mac_description_storage_size_t storage_sizes; 313 | storage_sizes.device_decription_table_size = 32; 314 | storage_sizes.key_description_table_size = 3; 315 | storage_sizes.key_lookup_size = 1; 316 | storage_sizes.key_usage_size = 3; 317 | if (!api) { 318 | api = ns_sw_mac_create(rf_phy_device_register_id, &storage_sizes); 319 | } 320 | rfid = arm_nwk_interface_lowpan_init(api, phy_name); 321 | tr_debug("RF interface ID: %d", rfid); 322 | } 323 | 324 | return rfid; 325 | } 326 | 327 | static void borderrouter_backhaul_phy_status_cb(uint8_t link_up, int8_t driver_id) 328 | { 329 | arm_event_s event = { 330 | .sender = br_tasklet_id, 331 | .receiver = br_tasklet_id, 332 | .priority = ARM_LIB_MED_PRIORITY_EVENT, 333 | .event_type = APPLICATION_EVENT, 334 | .event_id = NR_BACKHAUL_INTERFACE_PHY_DOWN, 335 | .event_data = driver_id 336 | }; 337 | 338 | if (link_up) { 339 | event.event_id = NR_BACKHAUL_INTERFACE_PHY_DRIVER_READY; 340 | } 341 | 342 | eventOS_event_send(&event); 343 | } 344 | 345 | static int backhaul_interface_up(int8_t driver_id) 346 | { 347 | int retval = -1; 348 | if (backhaul_if_id != -1) { 349 | tr_debug("Border RouterInterface already at active state\n"); 350 | } else { 351 | if (!eth_mac_api) { 352 | eth_mac_api = ethernet_mac_create(driver_id); 353 | } 354 | 355 | backhaul_if_id = arm_nwk_interface_ethernet_init(eth_mac_api, "bh0"); 356 | 357 | if (backhaul_if_id >= 0) { 358 | tr_debug("Backhaul interface ID: %d", backhaul_if_id); 359 | if (memcmp(backhaul_prefix, addr_unspecified, 8) == 0) { 360 | memcpy(backhaul_prefix, rpl_setup_info.DODAG_ID, 8); 361 | } 362 | arm_nwk_interface_configure_ipv6_bootstrap_set( 363 | backhaul_if_id, backhaul_bootstrap_mode, backhaul_prefix); 364 | arm_nwk_interface_up(backhaul_if_id); 365 | retval = 0; 366 | } 367 | } 368 | return retval; 369 | } 370 | 371 | static int backhaul_interface_down(void) 372 | { 373 | int retval = -1; 374 | if (backhaul_if_id != -1) { 375 | arm_nwk_interface_down(backhaul_if_id); 376 | backhaul_if_id = -1; 377 | retval = 0; 378 | } 379 | return retval; 380 | } 381 | 382 | /** 383 | * \brief Border Router Main Tasklet 384 | * 385 | * Tasklet Handle next items: 386 | * 387 | * - EV_INIT event: Set Certificate Chain, RF Interface Boot UP, multicast Init 388 | * - SYSTEM_TIMER event: For RF interface Handshake purpose 389 | * 390 | */ 391 | static void borderrouter_tasklet(arm_event_s *event) 392 | { 393 | arm_library_event_type_e event_type; 394 | event_type = (arm_library_event_type_e)event->event_type; 395 | 396 | switch (event_type) { 397 | case ARM_LIB_NWK_INTERFACE_EVENT: 398 | app_parse_network_event(event); 399 | break; 400 | 401 | case APPLICATION_EVENT: 402 | if (event->event_id == NR_BACKHAUL_INTERFACE_PHY_DRIVER_READY) { 403 | int8_t net_backhaul_id = (int8_t) event->event_data; 404 | if (net_backhaul_state == INTERFACE_IDLE_PHY_NOT_READY) { 405 | net_backhaul_state = INTERFACE_IDLE_STATE; 406 | } 407 | 408 | tr_debug("Backhaul driver ID: %d", net_backhaul_id); 409 | 410 | if (backhaul_interface_up(net_backhaul_id) != 0) { 411 | tr_debug("Backhaul bootstrap start failed"); 412 | } else { 413 | tr_debug("Backhaul bootstrap started"); 414 | net_backhaul_state = INTERFACE_BOOTSTRAP_ACTIVE; 415 | } 416 | } else if (event->event_id == NR_BACKHAUL_INTERFACE_PHY_DOWN) { 417 | tr_debug("Backhaul driver ID: %d", (int8_t) event->event_data); 418 | if (backhaul_interface_down() != 0) { 419 | tr_error("Backhaul interface down failed"); 420 | } else { 421 | tr_debug("Backhaul interface is down"); 422 | backhaul_if_id = -1; 423 | net_backhaul_state = INTERFACE_IDLE_STATE; 424 | } 425 | } 426 | break; 427 | 428 | case ARM_LIB_TASKLET_INIT_EVENT: 429 | appl_info_trace(); 430 | br_tasklet_id = event->receiver; 431 | 432 | /* initialize the backhaul interface */ 433 | backhaul_driver_init(borderrouter_backhaul_phy_status_cb); 434 | 435 | if (net_6lowpan_id < 0) { 436 | tr_error("RF interface initialization failed"); 437 | return; 438 | } 439 | net_6lowpan_state = INTERFACE_IDLE_STATE; 440 | eventOS_event_timer_request(9, ARM_LIB_SYSTEM_TIMER_EVENT, br_tasklet_id, 20000); 441 | break; 442 | 443 | case ARM_LIB_SYSTEM_TIMER_EVENT: 444 | eventOS_event_timer_cancel(event->event_id, event->receiver); 445 | 446 | if (event->event_id == 9) { 447 | #ifdef MBED_CONF_APP_DEBUG_TRACE 448 | #if MBED_CONF_APP_DEBUG_TRACE == 1 449 | arm_print_routing_table(); 450 | arm_print_neigh_cache(); 451 | print_memory_stats(); 452 | #endif 453 | #endif 454 | eventOS_event_timer_request(9, ARM_LIB_SYSTEM_TIMER_EVENT, br_tasklet_id, 20000); 455 | } 456 | break; 457 | 458 | default: 459 | break; 460 | } 461 | } 462 | 463 | static void start_6lowpan(const uint8_t *backhaul_address) 464 | { 465 | uint8_t p[16] = {0}; 466 | 467 | if (arm_net_address_get(backhaul_if_id, ADDR_IPV6_GP, p) == 0) { 468 | uint32_t lifetime = 0xffffffff; // infinite 469 | uint8_t prefix_len = 0; 470 | uint8_t t_flags = 0; 471 | int8_t retval = -1; 472 | 473 | /* Channel list: listen to a channel (default: all channels) */ 474 | uint32_t channel = cfg_int(global_config, "RF_CHANNEL", 0); 475 | tr_info("RF channel: %d", (int)channel); 476 | initialize_channel_list(channel); 477 | 478 | // configure as border router and set the operation mode 479 | retval = arm_nwk_interface_configure_6lowpan_bootstrap_set(net_6lowpan_id, 480 | operating_mode, operating_mode_extension); 481 | 482 | if (retval < 0) { 483 | tr_error("Configuring 6LoWPAN bootstrap failed, retval = %d", retval); 484 | return; 485 | } 486 | 487 | retval = arm_nwk_link_layer_security_mode(net_6lowpan_id, link_security_mode, 5, &link_layer_psk); 488 | 489 | if (retval < 0) { 490 | tr_error("Failed to set link layer security mode, retval = %d", retval); 491 | return; 492 | } 493 | 494 | /* Should we use the backhaul prefix on the PAN as well? */ 495 | if (backhaul_address && rf_prefix_from_backhaul) { 496 | memcpy(br.lowpan_nd_prefix, p, 8); 497 | memcpy(rpl_setup_info.DODAG_ID, br.lowpan_nd_prefix, 8); 498 | } 499 | 500 | retval = arm_nwk_6lowpan_border_router_init(net_6lowpan_id, &br); 501 | 502 | if (retval < 0) { 503 | tr_error("Initializing 6LoWPAN border router failed, retval = %d", retval); 504 | return; 505 | } 506 | 507 | /* configure both /64 and /128 context prefixes */ 508 | retval = arm_nwk_6lowpan_border_router_context_update(net_6lowpan_id, ((1 << 4) | 0x03), 509 | 128, 0xffff, rpl_setup_info.DODAG_ID); 510 | 511 | if (retval < 0) { 512 | tr_error("Setting ND context failed, retval = %d", retval); 513 | return; 514 | } 515 | 516 | // configure the RPL routing protocol for the 6LoWPAN mesh network 517 | if (arm_nwk_6lowpan_rpl_dodag_init(net_6lowpan_id, rpl_setup_info.DODAG_ID, 518 | &dodag_config, rpl_setup_info.rpl_instance_id, 519 | rpl_setup_info.rpl_setups) == 0) { 520 | prefix_len = 64; 521 | t_flags = RPL_PREFIX_ROUTER_ADDRESS_FLAG; 522 | /* add "/64" prefix with the full BR address (DODAG ID) */ 523 | arm_nwk_6lowpan_rpl_dodag_prefix_update(net_6lowpan_id, rpl_setup_info.DODAG_ID, 524 | prefix_len, t_flags, lifetime); 525 | 526 | t_flags = 0; 527 | prefix_len = 0; 528 | /* add default route "::/0" */ 529 | arm_nwk_6lowpan_rpl_dodag_route_update(net_6lowpan_id, rpl_setup_info.DODAG_ID, 530 | prefix_len, t_flags, lifetime); 531 | } 532 | 533 | if (link_security_mode == NET_SEC_MODE_PANA_LINK_SECURITY) { 534 | uint8_t *psk = (uint8_t *)cfg_string(global_config, "TLS_PSK_KEY", NULL); 535 | 536 | if (!psk) { 537 | tr_error("No TLS PSK key set in configuration"); 538 | return; 539 | } 540 | 541 | if (arm_tls_add_psk_key(psk, cfg_int(global_config, "TLS_PSK_KEY_ID", 0)) != 0) { 542 | tr_error("No TLS PSK key ID set in configuration"); 543 | return; 544 | } 545 | 546 | retval = arm_pana_server_library_init(net_6lowpan_id, pana_security_suite, NULL, 120); 547 | 548 | if (retval) { 549 | tr_error("Failed to initialize PANA server library, retval = %d", retval); 550 | return; 551 | } 552 | } 553 | 554 | retval = arm_nwk_set_channel_list(net_6lowpan_id, &channel_list); 555 | 556 | if (retval) { 557 | tr_error("Failed to set channel list, retval = %d", retval); 558 | return; 559 | } 560 | 561 | retval = arm_nwk_interface_up(net_6lowpan_id); 562 | 563 | if (retval < 0) { 564 | tr_error("Failed to bring up the RF interface, retval = %d", retval); 565 | return; 566 | } 567 | 568 | /* mark the RF interface active */ 569 | net_6lowpan_state = INTERFACE_BOOTSTRAP_ACTIVE; 570 | 571 | multicast_set_parameters(10, 0, 20, 3, 75); 572 | multicast_add_address(multicast_addr, 1); 573 | } 574 | } 575 | 576 | /** 577 | * \brief Network state event handler. 578 | * \param event show network start response or current network state. 579 | * 580 | */ 581 | static void app_parse_network_event(arm_event_s *event) 582 | { 583 | switch ((arm_nwk_interface_status_type_e)event->event_data) { 584 | case ARM_NWK_BOOTSTRAP_READY: { 585 | bool gp_address_available; 586 | uint8_t p[16]; 587 | char buf[128]; 588 | if (0 == arm_net_address_get(event->event_id, ADDR_IPV6_GP, p)) { 589 | ip6tos(p, buf); 590 | gp_address_available = true; 591 | } else { 592 | gp_address_available = false; 593 | } 594 | 595 | if (backhaul_if_id == event->event_id) { 596 | 597 | if (gp_address_available) { 598 | tr_info("Backhaul bootstrap ready, IPv6 = %s", buf); 599 | } else { 600 | tr_info("Backhaul interface in ULA Mode"); 601 | } 602 | 603 | if (backhaul_bootstrap_mode == NET_IPV6_BOOTSTRAP_STATIC) { 604 | uint8_t *next_hop_ptr; 605 | int8_t retval; 606 | if (memcmp(backhaul_route.next_hop, addr_unspecified, 16) == 0) { 607 | tr_info("Next hop not defined"); 608 | next_hop_ptr = NULL; 609 | } else { 610 | next_hop_ptr = backhaul_route.next_hop; 611 | } 612 | 613 | tr_info("Backhaul default route:"); 614 | tr_info(" prefix: %s", print_ipv6_prefix(backhaul_route.prefix, backhaul_route.prefix_len)); 615 | tr_info(" next hop: %s", next_hop_ptr ? print_ipv6(backhaul_route.next_hop) : "on-link"); 616 | 617 | retval = arm_net_route_add(backhaul_route.prefix, backhaul_route.prefix_len, 618 | next_hop_ptr, 0xffffffff, 128, backhaul_if_id); 619 | 620 | if (retval < 0) { 621 | tr_error("Failed to add backhaul default route, retval = %d", retval); 622 | } 623 | } 624 | 625 | tr_info("Backhaul interface addresses:"); 626 | print_interface_addr(backhaul_if_id); 627 | 628 | net_backhaul_state = INTERFACE_CONNECTED; 629 | if (net_6lowpan_state == INTERFACE_IDLE_STATE) { 630 | //Start 6lowpan 631 | start_6lowpan(p); 632 | } 633 | } else { 634 | tr_info("RF bootstrap ready, IPv6 = %s", buf); 635 | arm_nwk_6lowpan_rpl_dodag_start(net_6lowpan_id); 636 | net_6lowpan_state = INTERFACE_CONNECTED; 637 | tr_info("RF interface addresses:"); 638 | print_interface_addr(net_6lowpan_id); 639 | tr_info("6LoWPAN Border Router Bootstrap Complete."); 640 | } 641 | } 642 | /* Network connection Ready */ 643 | break; 644 | case ARM_NWK_NWK_SCAN_FAIL: 645 | /* Link Layer Active Scan Fail, Stack is Already in Idle state */ 646 | break; 647 | case ARM_NWK_IP_ADDRESS_ALLOCATION_FAIL: 648 | /* No ND Router at current Channel Stack is Already at Idle state */ 649 | break; 650 | case ARM_NWK_NWK_CONNECTION_DOWN: 651 | /* Connection to Access point is lost wait for Scan Result */ 652 | break; 653 | case ARM_NWK_NWK_PARENT_POLL_FAIL: 654 | break; 655 | case ARM_NWK_AUHTENTICATION_FAIL: 656 | /* Network authentication fail */ 657 | break; 658 | case ARM_NWK_DUPLICATE_ADDRESS_DETECTED: 659 | if (backhaul_if_id == event->event_id) { 660 | tr_error("Backhaul DAD failed."); 661 | } 662 | break; 663 | default: 664 | /* Unknow event */ 665 | break; 666 | } 667 | } 668 | 669 | #endif // MBED_CONF_APP_MESH_MODE 670 | --------------------------------------------------------------------------------