
Nanostack Border Router is a generic mbed border router implementation that provides the 6LoWPAN ND or Thread border router initialization logic.
Revision 82:3d9e3b7b3dcf, committed 2018-11-23
- Comitter:
- mbed_official
- Date:
- Fri Nov 23 14:45:35 2018 +0000
- Parent:
- 81:afdeda18ff0c
- Child:
- 83:02ef87f7c8fb
- Commit message:
- Merge pull request #147 from ARMmbed/br_update
Update Border router
.
Commit copied from https://github.com/ARMmbed/nanostack-border-router
Changed in this revision
--- a/Jenkinsfile Thu Nov 22 11:15:40 2018 +0000 +++ b/Jenkinsfile Fri Nov 23 14:45:35 2018 +0000 @@ -1,5 +1,6 @@ properties ([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [ - [$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"'] + [$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"'], + [$class: 'ChoiceParameterDefinition', name: 'profile', defaultValue: "debug", choices: ["debug", "develop", "release"], description: 'Select compilation profile from list: debug, develop or release.'] ]]]) if (params.mbed_os_revision == '') { @@ -11,6 +12,8 @@ } } +echo "Use build profile: ${params.profile}" + // List of targets to compile def targets = [ "K64F", @@ -77,7 +80,7 @@ } } } - execute("mbed compile --build out/${configurationLabel}/${target}/${toolchain}/ -m ${target} -t ${toolchain} --app-config ./configs/${configurationFile}") + execute("mbed compile --build out/${configurationLabel}/${target}/${toolchain}/ -m ${target} -t ${toolchain} --app-config ./configs/${configurationFile} --profile ${params.profile}") } archive '**/nanostack-border-router.bin' }
--- a/configs/6lowpan_Atmel_RF.json Thu Nov 22 11:15:40 2018 +0000 +++ b/configs/6lowpan_Atmel_RF.json Fri Nov 23 14:45:35 2018 +0000 @@ -68,14 +68,13 @@ }, "target_overrides": { "*": { - "target.features_add": ["NANOSTACK", "LOWPAN_BORDER_ROUTER", "COMMON_PAL"], - "target.features_remove": ["LWIP"], "target.network-default-interface-type": "ETHERNET", "nsapi.default-stack": "NANOSTACK", "mbed-trace.enable": 1, "nanostack.configuration": "lowpan_border_router", "platform.stdio-convert-newlines": true, - "platform.stdio-baud-rate": 115200 + "platform.stdio-baud-rate": 115200, + "mbed-mesh-api.use-malloc-for-heap": true }, "K64F": { "LED": "LED_GREEN",
--- a/configs/6lowpan_Spirit1_RF.json Thu Nov 22 11:15:40 2018 +0000 +++ b/configs/6lowpan_Spirit1_RF.json Fri Nov 23 14:45:35 2018 +0000 @@ -68,8 +68,6 @@ }, "target_overrides": { "*": { - "target.features_add": ["NANOSTACK", "LOWPAN_BORDER_ROUTER", "COMMON_PAL"], - "target.features_remove": ["LWIP"], "spirit1.mac-address": "{0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7}", "target.network-default-interface-type": "ETHERNET", "nsapi.default-stack": "NANOSTACK", @@ -78,7 +76,8 @@ "platform.stdio-convert-newlines": true, "platform.stdio-baud-rate": 115200, "kinetis-emac.tx-ring-len":4, - "kinetis-emac.rx-ring-len":4 + "kinetis-emac.rx-ring-len":4, + "mbed-mesh-api.use-malloc-for-heap": true }, "NUCLEO_F429ZI": { "LED": "LED1",
--- a/configs/Thread_Atmel_RF.json Thu Nov 22 11:15:40 2018 +0000 +++ b/configs/Thread_Atmel_RF.json Fri Nov 23 14:45:35 2018 +0000 @@ -52,8 +52,6 @@ "macros": ["MBEDTLS_USER_CONFIG_FILE=\"source/mbedtls_thread_config.h\""], "target_overrides": { "*": { - "target.features_add": ["NANOSTACK", "COMMON_PAL", "THREAD_BORDER_ROUTER"], - "target.features_remove": ["LWIP"], "target.network-default-interface-type": "ETHERNET", "nsapi.default-stack": "NANOSTACK", "mbed-trace.enable": 1,
--- a/configs/Thread_SLIP_Atmel_RF.json Thu Nov 22 11:15:40 2018 +0000 +++ b/configs/Thread_SLIP_Atmel_RF.json Fri Nov 23 14:45:35 2018 +0000 @@ -54,8 +54,6 @@ "macros": ["MBEDTLS_USER_CONFIG_FILE=\"source/mbedtls_thread_config.h\"", "ATMEL_SPI_RST=PTD4"], "target_overrides": { "*": { - "target.features_add": ["NANOSTACK", "COMMON_PAL", "THREAD_BORDER_ROUTER"], - "target.features_remove": ["LWIP"], "target.network-default-interface-type": "ETHERNET", "nsapi.default-stack": "NANOSTACK", "mbed-trace.enable": 1,
--- a/drivers/rf_wrapper.cpp Thu Nov 22 11:15:40 2018 +0000 +++ b/drivers/rf_wrapper.cpp Fri Nov 23 14:45:35 2018 +0000 @@ -8,7 +8,7 @@ #define ATMEL 0 #define MCR20 1 #define NCS36510 2 -#define SPIRIT1 3 +#define SPIRIT1 3 #if MBED_CONF_APP_RADIO_TYPE == ATMEL #include "NanostackRfPhyAtmel.h" @@ -20,7 +20,7 @@ #elif MBED_CONF_APP_RADIO_TYPE == SPIRIT1 #include "NanostackRfPhySpirit1.h" NanostackRfPhySpirit1 rf_phy(SPIRIT1_SPI_MOSI, SPIRIT1_SPI_MISO, SPIRIT1_SPI_SCLK, - SPIRIT1_DEV_IRQ, SPIRIT1_DEV_CS, SPIRIT1_DEV_SDN, SPIRIT1_BRD_LED); + SPIRIT1_DEV_IRQ, SPIRIT1_DEV_CS, SPIRIT1_DEV_SDN, SPIRIT1_BRD_LED); #endif //MBED_CONF_APP_RADIO_TYPE extern "C" int8_t rf_device_register()
--- a/mbed_app.json Thu Nov 22 11:15:40 2018 +0000 +++ b/mbed_app.json Fri Nov 23 14:45:35 2018 +0000 @@ -64,14 +64,13 @@ }, "target_overrides": { "*": { - "target.features_add": ["NANOSTACK", "LOWPAN_BORDER_ROUTER", "COMMON_PAL"], - "target.features_remove": ["LWIP"], "target.network-default-interface-type": "ETHERNET", "nsapi.default-stack": "NANOSTACK", "mbed-trace.enable": 1, "nanostack.configuration": "lowpan_border_router", "platform.stdio-convert-newlines": true, - "platform.stdio-baud-rate": 115200 + "platform.stdio-baud-rate": 115200, + "mbed-mesh-api.use-malloc-for-heap": true }, "K64F": { "LED": "LED_GREEN",
--- a/source/border_router_main.cpp Thu Nov 22 11:15:40 2018 +0000 +++ b/source/border_router_main.cpp Fri Nov 23 14:45:35 2018 +0000 @@ -84,7 +84,7 @@ #endif /** - * \brief Initializes the SLIP MAC backhaul driver. + * \brief Initializes the MAC backhaul driver. * This function is called by the border router module. */ void backhaul_driver_init(void (*backhaul_driver_status_cb)(uint8_t, int8_t)) @@ -161,6 +161,16 @@ #undef EMAC } + +void appl_info_trace(void) +{ + tr_info("Starting NanoStack Border Router..."); + tr_info("Build date: %s %s", __DATE__, __TIME__); +#ifdef MBED_MAJOR_VERSION + tr_info("Mbed OS version: %d.%d.%d\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); +#endif +} + /** * \brief The entry point for this application. * Sets up the application and starts the border router module.
--- a/source/borderrouter_helpers.c Thu Nov 22 11:15:40 2018 +0000 +++ b/source/borderrouter_helpers.c Fri Nov 23 14:45:35 2018 +0000 @@ -43,22 +43,16 @@ return str; } -void print_appl_info(void) -{ - tr_info("Starting NanoStack Border Router..."); - tr_info("Build date: %s %s", __DATE__, __TIME__); -} - void print_memory_stats(void) { const mem_stat_t *heap_info = ns_dyn_mem_get_mem_stat(); if (heap_info) { tr_info( "Heap size: %lu, Reserved: %lu, Reserved max: %lu, Alloc fail: %lu" - ,(unsigned long)heap_info->heap_sector_size - ,(unsigned long)heap_info->heap_sector_allocated_bytes - ,(unsigned long)heap_info->heap_sector_allocated_bytes_max - ,(unsigned long)heap_info->heap_alloc_fail_cnt); + , (unsigned long)heap_info->heap_sector_size + , (unsigned long)heap_info->heap_sector_allocated_bytes + , (unsigned long)heap_info->heap_sector_allocated_bytes_max + , (unsigned long)heap_info->heap_alloc_fail_cnt); } }
--- a/source/borderrouter_helpers.h Thu Nov 22 11:15:40 2018 +0000 +++ b/source/borderrouter_helpers.h Fri Nov 23 14:45:35 2018 +0000 @@ -13,7 +13,6 @@ char *print_ipv6(const void *addr_ptr); char *print_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len); -void print_appl_info(void); void print_memory_stats(void); #ifdef __cplusplus
--- a/source/borderrouter_tasklet.c Thu Nov 22 11:15:40 2018 +0000 +++ b/source/borderrouter_tasklet.c Fri Nov 23 14:45:35 2018 +0000 @@ -36,6 +36,7 @@ #define NR_BACKHAUL_INTERFACE_PHY_DRIVER_READY 2 #define NR_BACKHAUL_INTERFACE_PHY_DOWN 3 +const uint8_t addr_unspecified[16] = {0}; static mac_api_t *api; static eth_mac_api_t *eth_mac_api; @@ -329,17 +330,14 @@ .receiver = br_tasklet_id, .priority = ARM_LIB_MED_PRIORITY_EVENT, .event_type = APPLICATION_EVENT, + .event_id = NR_BACKHAUL_INTERFACE_PHY_DOWN, .event_data = driver_id }; if (link_up) { event.event_id = NR_BACKHAUL_INTERFACE_PHY_DRIVER_READY; - } else { - event.event_id = NR_BACKHAUL_INTERFACE_PHY_DOWN; } - tr_debug("Backhaul driver ID: %d", driver_id); - eventOS_event_send(&event); } @@ -357,7 +355,7 @@ if (backhaul_if_id >= 0) { tr_debug("Backhaul interface ID: %d", backhaul_if_id); - if (memcmp(backhaul_prefix, (const uint8_t[8]) { 0 }, 8) == 0) { + if (memcmp(backhaul_prefix, addr_unspecified, 8) == 0) { memcpy(backhaul_prefix, rpl_setup_info.DODAG_ID, 8); } arm_nwk_interface_configure_ipv6_bootstrap_set( @@ -406,6 +404,8 @@ net_backhaul_state = INTERFACE_IDLE_STATE; } + tr_debug("Backhaul driver ID: %d", net_backhaul_id); + if (backhaul_interface_up(net_backhaul_id) != 0) { tr_debug("Backhaul bootstrap start failed"); } else { @@ -413,6 +413,7 @@ net_backhaul_state = INTERFACE_BOOTSTRAP_ACTIVE; } } else if (event->event_id == NR_BACKHAUL_INTERFACE_PHY_DOWN) { + tr_debug("Backhaul driver ID: %d", (int8_t) event->event_data); if (backhaul_interface_down() != 0) { tr_error("Backhaul interface down failed"); } else { @@ -424,7 +425,7 @@ break; case ARM_LIB_TASKLET_INIT_EVENT: - print_appl_info(); + appl_info_trace(); br_tasklet_id = event->receiver; /* initialize the backhaul interface */ @@ -475,7 +476,7 @@ // configure as border router and set the operation mode retval = arm_nwk_interface_configure_6lowpan_bootstrap_set(net_6lowpan_id, - operating_mode, operating_mode_extension); + operating_mode, operating_mode_extension); if (retval < 0) { tr_error("Configuring 6LoWPAN bootstrap failed, retval = %d", retval); @@ -504,7 +505,7 @@ /* configure both /64 and /128 context prefixes */ retval = arm_nwk_6lowpan_border_router_context_update(net_6lowpan_id, ((1 << 4) | 0x03), - 128, 0xffff, rpl_setup_info.DODAG_ID); + 128, 0xffff, rpl_setup_info.DODAG_ID); if (retval < 0) { tr_error("Setting ND context failed, retval = %d", retval); @@ -599,14 +600,12 @@ } if (backhaul_bootstrap_mode == NET_IPV6_BOOTSTRAP_STATIC) { + uint8_t *next_hop_ptr; int8_t retval; - uint8_t *next_hop_ptr; - - if (memcmp(backhaul_route.next_hop, (const uint8_t[16]) {0}, 16) == 0) { + if (memcmp(backhaul_route.next_hop, addr_unspecified, 16) == 0) { tr_info("Next hop not defined"); next_hop_ptr = NULL; - } - else { + } else { next_hop_ptr = backhaul_route.next_hop; }
--- a/source/borderrouter_tasklet.h Thu Nov 22 11:15:40 2018 +0000 +++ b/source/borderrouter_tasklet.h Fri Nov 23 14:45:35 2018 +0000 @@ -17,6 +17,11 @@ void backhaul_driver_init(void (*backhaul_driver_status_cb)(uint8_t, int8_t)); /** +* Trace application details +*/ +void appl_info_trace(void); + +/** * Initializes the border router module: loads configuration and * initiates bootstrap for the RF 6LoWPAN and backhaul interfaces. */
--- a/source/borderrouter_thread_tasklet.c Thu Nov 22 11:15:40 2018 +0000 +++ b/source/borderrouter_thread_tasklet.c Fri Nov 23 14:45:35 2018 +0000 @@ -38,6 +38,7 @@ #define MESH_METRIC 1000 #define THREAD_MAX_CHILD_COUNT 32 +const uint8_t addr_unspecified[16] = {0}; static mac_api_t *api; static eth_mac_api_t *eth_mac_api; @@ -68,7 +69,7 @@ /* Function forward declarations */ -static link_configuration_s* thread_link_configuration_get(link_configuration_s *link_configuration); +static link_configuration_s *thread_link_configuration_get(link_configuration_s *link_configuration); static void network_interface_event_handler(arm_event_s *event); static void mesh_network_up(void); static void eth_network_data_init(void); @@ -168,12 +169,12 @@ return 0; } -static link_configuration_s* thread_link_configuration_get(link_configuration_s *link_configuration) +static link_configuration_s *thread_link_configuration_get(link_configuration_s *link_configuration) { #ifdef MBED_CONF_APP_THREAD_USE_STATIC_LINK_CONFIG #if (false == MBED_CONF_APP_THREAD_USE_STATIC_LINK_CONFIG) - // NOT using static link configuration values, return NULL - return NULL; + // NOT using static link configuration values, return NULL + return NULL; #endif #endif @@ -232,11 +233,9 @@ if (backhaul_bootstrap_mode == NET_IPV6_BOOTSTRAP_STATIC) { uint8_t *next_hop_ptr; - - if (memcmp(backhaul_route.next_hop, (const uint8_t[16]) {0}, 16) == 0) { + if (memcmp(backhaul_route.next_hop, addr_unspecified, 16) == 0) { next_hop_ptr = NULL; - } - else { + } else { next_hop_ptr = backhaul_route.next_hop; } tr_debug("Default route prefix: %s/%d", print_ipv6(backhaul_route.prefix), @@ -326,7 +325,7 @@ thread_if_id = arm_nwk_interface_lowpan_init(api, "ThreadInterface"); tr_info("thread_if_id: %d", thread_if_id); - MBED_ASSERT(thread_if_id>=0); + MBED_ASSERT(thread_if_id >= 0); if (thread_if_id < 0) { tr_error("arm_nwk_interface_lowpan_init() failed"); @@ -334,9 +333,9 @@ } status = arm_nwk_interface_configure_6lowpan_bootstrap_set( - thread_if_id, - NET_6LOWPAN_ROUTER, - NET_6LOWPAN_THREAD); + thread_if_id, + NET_6LOWPAN_ROUTER, + NET_6LOWPAN_THREAD); if (status < 0) { tr_error("arm_nwk_interface_configure_6lowpan_bootstrap_set() failed"); @@ -361,8 +360,8 @@ storage_sizes.key_description_table_size = 6; int8_t rf_driver_id = rf_device_register(); - MBED_ASSERT(rf_driver_id>=0); - if (rf_driver_id>=0) { + MBED_ASSERT(rf_driver_id >= 0); + if (rf_driver_id >= 0) { randLIB_seed_random(); if (!api) { @@ -389,17 +388,14 @@ .receiver = br_tasklet_id, .priority = ARM_LIB_MED_PRIORITY_EVENT, .event_type = APPLICATION_EVENT, + .event_id = NR_BACKHAUL_INTERFACE_PHY_DOWN, .event_data = driver_id }; if (link_up) { event.event_id = NR_BACKHAUL_INTERFACE_PHY_DRIVER_READY; - } else { - event.event_id = NR_BACKHAUL_INTERFACE_PHY_DOWN; } - tr_debug("Backhaul driver ID: %d", driver_id); - eventOS_event_send(&event); } @@ -426,8 +422,7 @@ backhaul_if_id, backhaul_bootstrap_mode, backhaul_prefix); arm_nwk_interface_up(backhaul_if_id); retval = 0; - } - else { + } else { tr_debug("Could not init ethernet"); } } @@ -442,8 +437,7 @@ thread_br_conn_handler_eth_interface_id_set(-1); thread_br_conn_handler_ethernet_connection_update(false); retval = 0; - } - else { + } else { tr_debug("Could not set eth down"); } return retval; @@ -489,12 +483,15 @@ if (event->event_id == NR_BACKHAUL_INTERFACE_PHY_DRIVER_READY) { int8_t net_backhaul_id = (int8_t) event->event_data; + tr_debug("Backhaul driver ID: %d", net_backhaul_id); + if (backhaul_interface_up(net_backhaul_id) != 0) { tr_debug("Backhaul bootstrap start failed"); } else { tr_debug("Backhaul bootstrap started"); } } else if (event->event_id == NR_BACKHAUL_INTERFACE_PHY_DOWN) { + tr_debug("Backhaul driver ID: %d", (int8_t) event->event_data); if (backhaul_interface_down() != 0) { } else { tr_debug("Backhaul interface is down"); @@ -503,7 +500,7 @@ break; case ARM_LIB_TASKLET_INIT_EVENT: - print_appl_info(); + appl_info_trace(); br_tasklet_id = event->receiver; thread_br_conn_handler_init(); eth_network_data_init();
--- a/source/thread_br_conn_handler.c Thu Nov 22 11:15:40 2018 +0000 +++ b/source/thread_br_conn_handler.c Fri Nov 23 14:45:35 2018 +0000 @@ -18,7 +18,7 @@ #define TRACE_GROUP "TBRH" typedef struct { - + int8_t thread_interface_id; int8_t eth_interface_id; bool eth_connection_ready; @@ -29,10 +29,10 @@ void thread_br_conn_handler_init(void) { - thread_br_handler.thread_interface_id = -1; + thread_br_handler.thread_interface_id = -1; thread_br_handler.thread_connection_ready = 0; - thread_br_handler.eth_interface_id = -1; + thread_br_handler.eth_interface_id = -1; thread_br_handler.eth_connection_ready = 0; } @@ -54,9 +54,8 @@ { thread_br_handler.thread_interface_id = interfaceId; thread_bbr_extension_mesh_interface_updated_ntf(thread_br_handler.thread_interface_id); - if (thread_br_handler.thread_interface_id > -1 && - thread_br_handler.eth_interface_id > -1) { - thread_bbr_start(thread_br_handler.thread_interface_id, thread_br_handler.eth_interface_id); + if (thread_br_handler.thread_interface_id > -1 && thread_br_handler.eth_interface_id > -1) { + thread_bbr_start(thread_br_handler.thread_interface_id, thread_br_handler.eth_interface_id); } } @@ -79,9 +78,8 @@ { thread_br_handler.eth_interface_id = interfaceId; thread_bbr_extension_bb_interface_updated_ntf(thread_br_handler.eth_interface_id); - if (thread_br_handler.thread_interface_id > -1 && - thread_br_handler.eth_interface_id > -1) { - thread_bbr_start(thread_br_handler.thread_interface_id, thread_br_handler.eth_interface_id); + if (thread_br_handler.thread_interface_id > -1 && thread_br_handler.eth_interface_id > -1) { + thread_bbr_start(thread_br_handler.thread_interface_id, thread_br_handler.eth_interface_id); } }
--- a/source/thread_br_conn_handler.h Thu Nov 22 11:15:40 2018 +0000 +++ b/source/thread_br_conn_handler.h Fri Nov 23 14:45:35 2018 +0000 @@ -21,7 +21,7 @@ void thread_br_conn_handler_thread_interface_id_set(int8_t interfaceId); void thread_br_conn_handler_eth_interface_id_set(int8_t interfaceId); -// Getters thread_br_conn_handler +// Getters thread_br_conn_handler bool thread_br_conn_handler_eth_connection_status_get(void); bool thread_br_conn_handler_thread_connection_status_get(void); int8_t thread_br_conn_handler_thread_interface_id_get(void);