Nanostack Border Router is a generic mbed border router implementation that provides the 6LoWPAN ND or Thread border router initialization logic.

Committer:
mbed_official
Date:
Thu Mar 14 16:02:36 2019 +0000
Revision:
94:0c008659750c
Parent:
92:7faf6dcb791f
Child:
95:930ccc91b349
Added Wi-SUN certificates and updated mbed TLS configuration

Added Wi-SUN certificates. Added mbed TLS configuration for Wi-SUN.
Enabled MBEDTLS_AES_FEWER_TABLES on both Thread and Wi-SUN configuration.

.
Commit copied from https://github.com/ARMmbed/nanostack-border-router

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 89:2f7ae1d76d7a 1 /*
mbed_official 89:2f7ae1d76d7a 2 * Copyright (c) 2019 ARM Limited. All rights reserved.
mbed_official 89:2f7ae1d76d7a 3 */
mbed_official 89:2f7ae1d76d7a 4
mbed_official 89:2f7ae1d76d7a 5 #define LOWPAN_ND 0
mbed_official 89:2f7ae1d76d7a 6 #define THREAD 1
mbed_official 89:2f7ae1d76d7a 7 #define LOWPAN_WS 2
mbed_official 89:2f7ae1d76d7a 8 #if MBED_CONF_APP_MESH_MODE == LOWPAN_WS
mbed_official 89:2f7ae1d76d7a 9
mbed_official 89:2f7ae1d76d7a 10 #include <string.h>
mbed_official 89:2f7ae1d76d7a 11 #include <stdlib.h>
mbed_official 89:2f7ae1d76d7a 12 #include <mbed_assert.h>
mbed_official 89:2f7ae1d76d7a 13 #include "eventOS_event.h"
mbed_official 89:2f7ae1d76d7a 14 #include "eventOS_event_timer.h"
mbed_official 89:2f7ae1d76d7a 15 #include "eventOS_scheduler.h"
mbed_official 89:2f7ae1d76d7a 16 #include "platform/arm_hal_timer.h"
mbed_official 89:2f7ae1d76d7a 17 #include "borderrouter_tasklet.h"
mbed_official 89:2f7ae1d76d7a 18 #include "borderrouter_helpers.h"
mbed_official 89:2f7ae1d76d7a 19 #include "net_interface.h"
mbed_official 89:2f7ae1d76d7a 20 #include "rf_wrapper.h"
mbed_official 89:2f7ae1d76d7a 21 #include "fhss_api.h"
mbed_official 89:2f7ae1d76d7a 22 #include "fhss_config.h"
mbed_official 89:2f7ae1d76d7a 23 #include "ws_management_api.h"
mbed_official 89:2f7ae1d76d7a 24 #include "ws_bbr_api.h"
mbed_official 89:2f7ae1d76d7a 25 #include "ip6string.h"
mbed_official 89:2f7ae1d76d7a 26 #include "mac_api.h"
mbed_official 89:2f7ae1d76d7a 27 #include "ethernet_mac_api.h"
mbed_official 89:2f7ae1d76d7a 28 #include "sw_mac.h"
mbed_official 89:2f7ae1d76d7a 29 #include "nwk_stats_api.h"
mbed_official 89:2f7ae1d76d7a 30 #include "randLIB.h"
mbed_official 94:0c008659750c 31 #ifdef MBED_CONF_APP_CERTIFICATE_HEADER
mbed_official 94:0c008659750c 32 #include MBED_CONF_APP_CERTIFICATE_HEADER
mbed_official 94:0c008659750c 33 #endif
mbed_official 89:2f7ae1d76d7a 34
mbed_official 89:2f7ae1d76d7a 35 #include "ns_trace.h"
mbed_official 89:2f7ae1d76d7a 36 #define TRACE_GROUP "brro"
mbed_official 89:2f7ae1d76d7a 37
mbed_official 89:2f7ae1d76d7a 38 #define NR_BACKHAUL_INTERFACE_PHY_DRIVER_READY 2
mbed_official 89:2f7ae1d76d7a 39 #define NR_BACKHAUL_INTERFACE_PHY_DOWN 3
mbed_official 89:2f7ae1d76d7a 40 #define MESH_LINK_TIMEOUT 100
mbed_official 89:2f7ae1d76d7a 41 #define MESH_METRIC 1000
mbed_official 89:2f7ae1d76d7a 42
mbed_official 89:2f7ae1d76d7a 43 #define WS_DEFAULT_REGULATORY_DOMAIN 255
mbed_official 89:2f7ae1d76d7a 44 #define WS_DEFAULT_OPERATING_CLASS 255
mbed_official 89:2f7ae1d76d7a 45 #define WS_DEFAULT_OPERATING_MODE 255
mbed_official 89:2f7ae1d76d7a 46 #define WS_DEFAULT_UC_CHANNEL_FUNCTION 255
mbed_official 89:2f7ae1d76d7a 47 #define WS_DEFAULT_BC_CHANNEL_FUNCTION 255
mbed_official 89:2f7ae1d76d7a 48 #define WS_DEFAULT_UC_DWELL_INTERVAL 0
mbed_official 89:2f7ae1d76d7a 49 #define WS_DEFAULT_BC_INTERVAL 0
mbed_official 89:2f7ae1d76d7a 50 #define WS_DEFAULT_BC_DWELL_INTERVAL 0
mbed_official 89:2f7ae1d76d7a 51 #define WS_DEFAULT_UC_FIXED_CHANNEL 0xffff
mbed_official 89:2f7ae1d76d7a 52 #define WS_DEFAULT_BC_FIXED_CHANNEL 0xffff
mbed_official 89:2f7ae1d76d7a 53
mbed_official 89:2f7ae1d76d7a 54 static mac_api_t *mac_api;
mbed_official 89:2f7ae1d76d7a 55 static eth_mac_api_t *eth_mac_api;
mbed_official 89:2f7ae1d76d7a 56
mbed_official 89:2f7ae1d76d7a 57 typedef enum {
mbed_official 89:2f7ae1d76d7a 58 STATE_UNKNOWN,
mbed_official 89:2f7ae1d76d7a 59 STATE_DISCONNECTED,
mbed_official 89:2f7ae1d76d7a 60 STATE_LINK_READY,
mbed_official 89:2f7ae1d76d7a 61 STATE_BOOTSTRAP,
mbed_official 89:2f7ae1d76d7a 62 STATE_CONNECTED,
mbed_official 89:2f7ae1d76d7a 63 STATE_MAX_VALUE
mbed_official 89:2f7ae1d76d7a 64 } connection_state_e;
mbed_official 89:2f7ae1d76d7a 65
mbed_official 89:2f7ae1d76d7a 66 typedef struct {
mbed_official 89:2f7ae1d76d7a 67 int8_t prefix_len;
mbed_official 89:2f7ae1d76d7a 68 uint8_t prefix[16];
mbed_official 89:2f7ae1d76d7a 69 uint8_t next_hop[16];
mbed_official 89:2f7ae1d76d7a 70 } route_info_t;
mbed_official 89:2f7ae1d76d7a 71
mbed_official 89:2f7ae1d76d7a 72 typedef struct {
mbed_official 89:2f7ae1d76d7a 73 int8_t ws_interface_id;
mbed_official 89:2f7ae1d76d7a 74 int8_t eth_interface_id;
mbed_official 89:2f7ae1d76d7a 75 } ws_br_handler_t;
mbed_official 89:2f7ae1d76d7a 76
mbed_official 89:2f7ae1d76d7a 77 static ws_br_handler_t ws_br_handler;
mbed_official 89:2f7ae1d76d7a 78
mbed_official 89:2f7ae1d76d7a 79 /* Backhaul prefix */
mbed_official 89:2f7ae1d76d7a 80 static uint8_t backhaul_prefix[16] = {0};
mbed_official 89:2f7ae1d76d7a 81
mbed_official 89:2f7ae1d76d7a 82 /* Backhaul default route information */
mbed_official 89:2f7ae1d76d7a 83 static route_info_t backhaul_route;
mbed_official 89:2f7ae1d76d7a 84 static int8_t br_tasklet_id = -1;
mbed_official 89:2f7ae1d76d7a 85
mbed_official 89:2f7ae1d76d7a 86 /* Network statistics */
mbed_official 89:2f7ae1d76d7a 87 static nwk_stats_t nwk_stats;
mbed_official 89:2f7ae1d76d7a 88
mbed_official 89:2f7ae1d76d7a 89 /* Function forward declarations */
mbed_official 89:2f7ae1d76d7a 90
mbed_official 89:2f7ae1d76d7a 91 static void network_interface_event_handler(arm_event_s *event);
mbed_official 89:2f7ae1d76d7a 92 static void mesh_network_up(void);
mbed_official 89:2f7ae1d76d7a 93 static void eth_network_data_init(void);
mbed_official 89:2f7ae1d76d7a 94 static net_ipv6_mode_e backhaul_bootstrap_mode = NET_IPV6_BOOTSTRAP_STATIC;
mbed_official 89:2f7ae1d76d7a 95 static void borderrouter_tasklet(arm_event_s *event);
mbed_official 89:2f7ae1d76d7a 96 static int wisun_interface_up(void);
mbed_official 89:2f7ae1d76d7a 97 static void wisun_interface_event_handler(arm_event_s *event);
mbed_official 89:2f7ae1d76d7a 98 static void network_interface_event_handler(arm_event_s *event);
mbed_official 89:2f7ae1d76d7a 99 static int backhaul_interface_down(void);
mbed_official 89:2f7ae1d76d7a 100 static void borderrouter_backhaul_phy_status_cb(uint8_t link_up, int8_t driver_id);
mbed_official 89:2f7ae1d76d7a 101 extern fhss_timer_t fhss_functions;
mbed_official 89:2f7ae1d76d7a 102
mbed_official 89:2f7ae1d76d7a 103 typedef struct {
mbed_official 89:2f7ae1d76d7a 104 char *network_name;
mbed_official 89:2f7ae1d76d7a 105 uint8_t regulatory_domain;
mbed_official 89:2f7ae1d76d7a 106 uint8_t operating_class;
mbed_official 89:2f7ae1d76d7a 107 uint8_t operating_mode;
mbed_official 89:2f7ae1d76d7a 108 uint8_t uc_channel_function;
mbed_official 89:2f7ae1d76d7a 109 uint8_t bc_channel_function;
mbed_official 89:2f7ae1d76d7a 110 uint8_t uc_dwell_interval;
mbed_official 89:2f7ae1d76d7a 111 uint32_t bc_interval;
mbed_official 89:2f7ae1d76d7a 112 uint8_t bc_dwell_interval;
mbed_official 89:2f7ae1d76d7a 113 uint16_t uc_fixed_channel;
mbed_official 89:2f7ae1d76d7a 114 uint16_t bc_fixed_channel;
mbed_official 89:2f7ae1d76d7a 115 } ws_config_t;
mbed_official 89:2f7ae1d76d7a 116 static ws_config_t ws_conf;
mbed_official 89:2f7ae1d76d7a 117
mbed_official 89:2f7ae1d76d7a 118 static void mesh_network_up()
mbed_official 89:2f7ae1d76d7a 119 {
mbed_official 89:2f7ae1d76d7a 120 tr_debug("Create Mesh Interface");
mbed_official 89:2f7ae1d76d7a 121
mbed_official 89:2f7ae1d76d7a 122 int status;
mbed_official 89:2f7ae1d76d7a 123 int8_t wisun_if_id = ws_br_handler.ws_interface_id;
mbed_official 89:2f7ae1d76d7a 124
mbed_official 89:2f7ae1d76d7a 125 status = arm_nwk_interface_configure_6lowpan_bootstrap_set(
mbed_official 89:2f7ae1d76d7a 126 wisun_if_id,
mbed_official 89:2f7ae1d76d7a 127 NET_6LOWPAN_BORDER_ROUTER,
mbed_official 89:2f7ae1d76d7a 128 NET_6LOWPAN_WS);
mbed_official 89:2f7ae1d76d7a 129
mbed_official 89:2f7ae1d76d7a 130 if (status < 0) {
mbed_official 89:2f7ae1d76d7a 131 tr_error("arm_nwk_interface_configure_6lowpan_bootstrap_set() failed");
mbed_official 89:2f7ae1d76d7a 132 return;
mbed_official 89:2f7ae1d76d7a 133 }
mbed_official 89:2f7ae1d76d7a 134
mbed_official 89:2f7ae1d76d7a 135 status = wisun_interface_up();
mbed_official 89:2f7ae1d76d7a 136 MBED_ASSERT(!status);
mbed_official 89:2f7ae1d76d7a 137 if (status) {
mbed_official 89:2f7ae1d76d7a 138 tr_error("wisun_interface_up() failed: %d", status);
mbed_official 89:2f7ae1d76d7a 139 }
mbed_official 89:2f7ae1d76d7a 140 }
mbed_official 89:2f7ae1d76d7a 141
mbed_official 89:2f7ae1d76d7a 142 static void eth_network_data_init()
mbed_official 89:2f7ae1d76d7a 143 {
mbed_official 89:2f7ae1d76d7a 144 memset(&backhaul_prefix[8], 0, 8);
mbed_official 89:2f7ae1d76d7a 145
mbed_official 89:2f7ae1d76d7a 146 /* Bootstrap mode for the backhaul interface */
mbed_official 89:2f7ae1d76d7a 147 #if MBED_CONF_APP_BACKHAUL_DYNAMIC_BOOTSTRAP == 1
mbed_official 89:2f7ae1d76d7a 148 backhaul_bootstrap_mode = NET_IPV6_BOOTSTRAP_AUTONOMOUS;
mbed_official 89:2f7ae1d76d7a 149 tr_info("NET_IPV6_BOOTSTRAP_AUTONOMOUS");
mbed_official 89:2f7ae1d76d7a 150
mbed_official 89:2f7ae1d76d7a 151 #else
mbed_official 89:2f7ae1d76d7a 152 tr_info("NET_IPV6_BOOTSTRAP_STATIC");
mbed_official 89:2f7ae1d76d7a 153 backhaul_bootstrap_mode = NET_IPV6_BOOTSTRAP_STATIC;
mbed_official 89:2f7ae1d76d7a 154 // done like this so that prefix can be left out in the dynamic case.
mbed_official 89:2f7ae1d76d7a 155 const char *param = MBED_CONF_APP_BACKHAUL_PREFIX;
mbed_official 89:2f7ae1d76d7a 156 stoip6(param, strlen(param), backhaul_prefix);
mbed_official 89:2f7ae1d76d7a 157 tr_info("backhaul_prefix: %s", print_ipv6(backhaul_prefix));
mbed_official 89:2f7ae1d76d7a 158
mbed_official 89:2f7ae1d76d7a 159 /* Backhaul route configuration*/
mbed_official 89:2f7ae1d76d7a 160 memset(&backhaul_route, 0, sizeof(backhaul_route));
mbed_official 89:2f7ae1d76d7a 161 #ifdef MBED_CONF_APP_BACKHAUL_NEXT_HOP
mbed_official 89:2f7ae1d76d7a 162 param = MBED_CONF_APP_BACKHAUL_NEXT_HOP;
mbed_official 89:2f7ae1d76d7a 163 stoip6(param, strlen(param), backhaul_route.next_hop);
mbed_official 89:2f7ae1d76d7a 164 tr_info("next hop: %s", print_ipv6(backhaul_route.next_hop));
mbed_official 89:2f7ae1d76d7a 165 #endif
mbed_official 89:2f7ae1d76d7a 166 param = MBED_CONF_APP_BACKHAUL_DEFAULT_ROUTE;
mbed_official 89:2f7ae1d76d7a 167 char *prefix, route_buf[255] = {0};
mbed_official 89:2f7ae1d76d7a 168 /* copy the config value to a non-const buffer */
mbed_official 89:2f7ae1d76d7a 169 strncpy(route_buf, param, sizeof(route_buf) - 1);
mbed_official 89:2f7ae1d76d7a 170 prefix = strtok(route_buf, "/");
mbed_official 89:2f7ae1d76d7a 171 backhaul_route.prefix_len = atoi(strtok(NULL, "/"));
mbed_official 89:2f7ae1d76d7a 172 stoip6(prefix, strlen(prefix), backhaul_route.prefix);
mbed_official 89:2f7ae1d76d7a 173 tr_info("backhaul route prefix: %s", print_ipv6(backhaul_route.prefix));
mbed_official 89:2f7ae1d76d7a 174 #endif
mbed_official 89:2f7ae1d76d7a 175 }
mbed_official 89:2f7ae1d76d7a 176
mbed_official 89:2f7ae1d76d7a 177 void load_config(void)
mbed_official 89:2f7ae1d76d7a 178 {
mbed_official 89:2f7ae1d76d7a 179 ws_conf.network_name = malloc(sizeof(MBED_CONF_APP_NETWORK_NAME) + 1);
mbed_official 89:2f7ae1d76d7a 180 strcpy(ws_conf.network_name, MBED_CONF_APP_NETWORK_NAME);
mbed_official 89:2f7ae1d76d7a 181 #ifdef MBED_CONF_APP_REGULATORY_DOMAIN
mbed_official 89:2f7ae1d76d7a 182 ws_conf.regulatory_domain = MBED_CONF_APP_REGULATORY_DOMAIN;
mbed_official 89:2f7ae1d76d7a 183 #else
mbed_official 89:2f7ae1d76d7a 184 ws_conf.regulatory_domain = WS_DEFAULT_REGULATORY_DOMAIN;
mbed_official 89:2f7ae1d76d7a 185 #endif //MBED_CONF_APP_REGULATORY_DOMAIN
mbed_official 89:2f7ae1d76d7a 186 #ifdef MBED_CONF_APP_OPERATING_CLASS
mbed_official 89:2f7ae1d76d7a 187 ws_conf.operating_class = MBED_CONF_APP_OPERATING_CLASS;
mbed_official 89:2f7ae1d76d7a 188 #else
mbed_official 89:2f7ae1d76d7a 189 ws_conf.operating_class = WS_DEFAULT_OPERATING_CLASS;
mbed_official 89:2f7ae1d76d7a 190 #endif //MBED_CONF_APP_OPERATING_CLASS
mbed_official 89:2f7ae1d76d7a 191 #ifdef MBED_CONF_APP_OPERATING_MODE
mbed_official 89:2f7ae1d76d7a 192 ws_conf.operating_mode = MBED_CONF_APP_OPERATING_MODE;
mbed_official 89:2f7ae1d76d7a 193 #else
mbed_official 89:2f7ae1d76d7a 194 ws_conf.operating_mode = WS_DEFAULT_OPERATING_MODE;
mbed_official 89:2f7ae1d76d7a 195 #endif //MBED_CONF_APP_OPERATING_MODE
mbed_official 89:2f7ae1d76d7a 196 #ifdef MBED_CONF_APP_UC_CHANNEL_FUNCTION
mbed_official 89:2f7ae1d76d7a 197 ws_conf.uc_channel_function = MBED_CONF_APP_UC_CHANNEL_FUNCTION;
mbed_official 89:2f7ae1d76d7a 198 #else
mbed_official 89:2f7ae1d76d7a 199 ws_conf.uc_channel_function = WS_DEFAULT_UC_CHANNEL_FUNCTION;
mbed_official 89:2f7ae1d76d7a 200 #endif //MBED_CONF_APP_UC_CHANNEL_FUNCTION
mbed_official 89:2f7ae1d76d7a 201 #ifdef MBED_CONF_APP_BC_CHANNEL_FUNCTION
mbed_official 89:2f7ae1d76d7a 202 ws_conf.bc_channel_function = MBED_CONF_APP_BC_CHANNEL_FUNCTION;
mbed_official 89:2f7ae1d76d7a 203 #else
mbed_official 89:2f7ae1d76d7a 204 ws_conf.bc_channel_function = WS_DEFAULT_BC_CHANNEL_FUNCTION;
mbed_official 89:2f7ae1d76d7a 205 #endif //MBED_CONF_APP_UC_CHANNEL_FUNCTION
mbed_official 89:2f7ae1d76d7a 206 #ifdef MBED_CONF_APP_UC_DWELL_INTERVAL
mbed_official 89:2f7ae1d76d7a 207 ws_conf.uc_dwell_interval = MBED_CONF_APP_UC_DWELL_INTERVAL;
mbed_official 89:2f7ae1d76d7a 208 #else
mbed_official 89:2f7ae1d76d7a 209 ws_conf.uc_dwell_interval = WS_DEFAULT_UC_DWELL_INTERVAL;
mbed_official 89:2f7ae1d76d7a 210 #endif //MBED_CONF_APP_UC_DWELL_INTERVAL
mbed_official 89:2f7ae1d76d7a 211 #ifdef MBED_CONF_APP_BC_INTERVAL
mbed_official 89:2f7ae1d76d7a 212 ws_conf.bc_interval = MBED_CONF_APP_BC_INTERVAL;
mbed_official 89:2f7ae1d76d7a 213 #else
mbed_official 89:2f7ae1d76d7a 214 ws_conf.bc_interval = WS_DEFAULT_BC_INTERVAL;
mbed_official 89:2f7ae1d76d7a 215 #endif //MBED_CONF_APP_BC_INTERVAL
mbed_official 89:2f7ae1d76d7a 216 #ifdef MBED_CONF_APP_BC_DWELL_INTERVAL
mbed_official 89:2f7ae1d76d7a 217 ws_conf.bc_dwell_interval = MBED_CONF_APP_BC_DWELL_INTERVAL;
mbed_official 89:2f7ae1d76d7a 218 #else
mbed_official 89:2f7ae1d76d7a 219 ws_conf.bc_dwell_interval = WS_DEFAULT_BC_DWELL_INTERVAL;
mbed_official 89:2f7ae1d76d7a 220 #endif //MBED_CONF_APP_BC_DWELL_INTERVAL
mbed_official 89:2f7ae1d76d7a 221 // Using randomized fixed channel by default
mbed_official 89:2f7ae1d76d7a 222 #ifdef MBED_CONF_APP_UC_FIXED_CHANNEL
mbed_official 89:2f7ae1d76d7a 223 ws_conf.uc_fixed_channel = MBED_CONF_APP_UC_FIXED_CHANNEL;
mbed_official 89:2f7ae1d76d7a 224 #else
mbed_official 89:2f7ae1d76d7a 225 ws_conf.uc_fixed_channel = WS_DEFAULT_UC_FIXED_CHANNEL;
mbed_official 89:2f7ae1d76d7a 226 #endif //MBED_CONF_APP_UC_FIXED_CHANNEL
mbed_official 89:2f7ae1d76d7a 227 #ifdef MBED_CONF_APP_BC_FIXED_CHANNEL
mbed_official 89:2f7ae1d76d7a 228 ws_conf.bc_fixed_channel = MBED_CONF_APP_BC_FIXED_CHANNEL;
mbed_official 89:2f7ae1d76d7a 229 #else
mbed_official 89:2f7ae1d76d7a 230 ws_conf.bc_fixed_channel = WS_DEFAULT_BC_FIXED_CHANNEL;
mbed_official 89:2f7ae1d76d7a 231 #endif //MBED_CONF_APP_BC_FIXED_CHANNEL
mbed_official 89:2f7ae1d76d7a 232 }
mbed_official 89:2f7ae1d76d7a 233
mbed_official 89:2f7ae1d76d7a 234 void wisun_rf_init()
mbed_official 89:2f7ae1d76d7a 235 {
mbed_official 89:2f7ae1d76d7a 236 mac_description_storage_size_t storage_sizes;
mbed_official 89:2f7ae1d76d7a 237 storage_sizes.device_decription_table_size = 32;
mbed_official 89:2f7ae1d76d7a 238 storage_sizes.key_description_table_size = 4;
mbed_official 89:2f7ae1d76d7a 239 storage_sizes.key_lookup_size = 1;
mbed_official 89:2f7ae1d76d7a 240 storage_sizes.key_usage_size = 1;
mbed_official 89:2f7ae1d76d7a 241
mbed_official 89:2f7ae1d76d7a 242 int8_t rf_driver_id = rf_device_register();
mbed_official 89:2f7ae1d76d7a 243 MBED_ASSERT(rf_driver_id >= 0);
mbed_official 89:2f7ae1d76d7a 244 if (rf_driver_id >= 0) {
mbed_official 89:2f7ae1d76d7a 245 randLIB_seed_random();
mbed_official 89:2f7ae1d76d7a 246 if (!mac_api) {
mbed_official 89:2f7ae1d76d7a 247 mac_api = ns_sw_mac_create(rf_driver_id, &storage_sizes);
mbed_official 89:2f7ae1d76d7a 248 }
mbed_official 89:2f7ae1d76d7a 249
mbed_official 89:2f7ae1d76d7a 250 ws_br_handler.ws_interface_id = arm_nwk_interface_lowpan_init(mac_api, ws_conf.network_name);
mbed_official 89:2f7ae1d76d7a 251
mbed_official 89:2f7ae1d76d7a 252 if (ws_br_handler.ws_interface_id < 0) {
mbed_official 89:2f7ae1d76d7a 253 tr_error("Wi-SUN interface creation failed");
mbed_official 89:2f7ae1d76d7a 254 return;
mbed_official 89:2f7ae1d76d7a 255 }
mbed_official 89:2f7ae1d76d7a 256
mbed_official 89:2f7ae1d76d7a 257 if (ws_br_handler.ws_interface_id > -1 &&
mbed_official 89:2f7ae1d76d7a 258 ws_br_handler.eth_interface_id > -1) {
mbed_official 89:2f7ae1d76d7a 259 ws_bbr_start(ws_br_handler.ws_interface_id, ws_br_handler.eth_interface_id);
mbed_official 89:2f7ae1d76d7a 260 }
mbed_official 89:2f7ae1d76d7a 261 }
mbed_official 89:2f7ae1d76d7a 262 }
mbed_official 89:2f7ae1d76d7a 263
mbed_official 89:2f7ae1d76d7a 264
mbed_official 89:2f7ae1d76d7a 265 static int wisun_interface_up(void)
mbed_official 89:2f7ae1d76d7a 266 {
mbed_official 89:2f7ae1d76d7a 267 int32_t ret;
mbed_official 89:2f7ae1d76d7a 268
mbed_official 89:2f7ae1d76d7a 269 fhss_timer_t *fhss_timer_ptr = NULL;
mbed_official 89:2f7ae1d76d7a 270
mbed_official 89:2f7ae1d76d7a 271 fhss_timer_ptr = &fhss_functions;
mbed_official 89:2f7ae1d76d7a 272
mbed_official 89:2f7ae1d76d7a 273 ret = ws_management_node_init(ws_br_handler.ws_interface_id, ws_conf.regulatory_domain, ws_conf.network_name, fhss_timer_ptr);
mbed_official 89:2f7ae1d76d7a 274 if (0 != ret) {
mbed_official 89:2f7ae1d76d7a 275 tr_error("WS node init fail - code %"PRIi32"", ret);
mbed_official 89:2f7ae1d76d7a 276 return -1;
mbed_official 89:2f7ae1d76d7a 277 }
mbed_official 89:2f7ae1d76d7a 278
mbed_official 89:2f7ae1d76d7a 279 if (ws_conf.uc_channel_function != WS_DEFAULT_UC_CHANNEL_FUNCTION) {
mbed_official 89:2f7ae1d76d7a 280 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);
mbed_official 89:2f7ae1d76d7a 281 if (ret != 0) {
mbed_official 89:2f7ae1d76d7a 282 tr_error("Unicast channel function configuration failed %"PRIi32"", ret);
mbed_official 89:2f7ae1d76d7a 283 return -1;
mbed_official 89:2f7ae1d76d7a 284 }
mbed_official 89:2f7ae1d76d7a 285 }
mbed_official 89:2f7ae1d76d7a 286 if (ws_conf.bc_channel_function != WS_DEFAULT_BC_CHANNEL_FUNCTION ||
mbed_official 89:2f7ae1d76d7a 287 ws_conf.bc_dwell_interval != WS_DEFAULT_BC_DWELL_INTERVAL ||
mbed_official 89:2f7ae1d76d7a 288 ws_conf.bc_interval != WS_DEFAULT_BC_INTERVAL) {
mbed_official 89:2f7ae1d76d7a 289 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);
mbed_official 89:2f7ae1d76d7a 290 if (ret != 0) {
mbed_official 89:2f7ae1d76d7a 291 tr_error("Broadcast channel function configuration failed %"PRIi32"", ret);
mbed_official 89:2f7ae1d76d7a 292 return -1;
mbed_official 89:2f7ae1d76d7a 293 }
mbed_official 89:2f7ae1d76d7a 294 }
mbed_official 89:2f7ae1d76d7a 295
mbed_official 89:2f7ae1d76d7a 296 if (ws_conf.uc_dwell_interval != WS_DEFAULT_UC_DWELL_INTERVAL ||
mbed_official 89:2f7ae1d76d7a 297 ws_conf.bc_dwell_interval != WS_DEFAULT_BC_DWELL_INTERVAL ||
mbed_official 89:2f7ae1d76d7a 298 ws_conf.bc_interval != WS_DEFAULT_BC_INTERVAL) {
mbed_official 89:2f7ae1d76d7a 299 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);
mbed_official 89:2f7ae1d76d7a 300 if (ret != 0) {
mbed_official 89:2f7ae1d76d7a 301 tr_error("fhss configuration failed %"PRIi32"", ret);
mbed_official 89:2f7ae1d76d7a 302 return -1;
mbed_official 89:2f7ae1d76d7a 303 }
mbed_official 89:2f7ae1d76d7a 304 }
mbed_official 89:2f7ae1d76d7a 305 if (ws_conf.regulatory_domain != WS_DEFAULT_REGULATORY_DOMAIN ||
mbed_official 89:2f7ae1d76d7a 306 ws_conf.operating_mode != WS_DEFAULT_OPERATING_MODE ||
mbed_official 89:2f7ae1d76d7a 307 ws_conf.operating_class != WS_DEFAULT_OPERATING_CLASS) {
mbed_official 89:2f7ae1d76d7a 308 ret = ws_management_regulatory_domain_set(ws_br_handler.ws_interface_id, ws_conf.regulatory_domain, ws_conf.operating_class, ws_conf.operating_mode);
mbed_official 89:2f7ae1d76d7a 309 if (ret != 0) {
mbed_official 89:2f7ae1d76d7a 310 tr_error("Regulatory domain configuration failed %"PRIi32"", ret);
mbed_official 89:2f7ae1d76d7a 311 return -1;
mbed_official 89:2f7ae1d76d7a 312 }
mbed_official 89:2f7ae1d76d7a 313 }
mbed_official 89:2f7ae1d76d7a 314
mbed_official 94:0c008659750c 315 #if defined(MBED_CONF_APP_CERTIFICATE_HEADER)
mbed_official 94:0c008659750c 316 arm_certificate_chain_entry_s chain_info;
mbed_official 94:0c008659750c 317 memset(&chain_info, 0, sizeof(arm_certificate_chain_entry_s));
mbed_official 94:0c008659750c 318 chain_info.cert_chain[0] = (const uint8_t *) MBED_CONF_APP_ROOT_CERTIFICATE;
mbed_official 94:0c008659750c 319 chain_info.cert_len[0] = strlen((const char *) MBED_CONF_APP_ROOT_CERTIFICATE);
mbed_official 94:0c008659750c 320 chain_info.cert_chain[1] = (const uint8_t *) MBED_CONF_APP_OWN_CERTIFICATE;
mbed_official 94:0c008659750c 321 chain_info.cert_len[1] = strlen((const char *) MBED_CONF_APP_OWN_CERTIFICATE);
mbed_official 94:0c008659750c 322 chain_info.key_chain[1] = (const uint8_t *) MBED_CONF_APP_OWN_CERTIFICATE_KEY;
mbed_official 94:0c008659750c 323 chain_info.chain_length = 2;
mbed_official 94:0c008659750c 324 arm_network_certificate_chain_set((const arm_certificate_chain_entry_s *) &chain_info);
mbed_official 94:0c008659750c 325 #endif
mbed_official 89:2f7ae1d76d7a 326 ret = arm_nwk_interface_up(ws_br_handler.ws_interface_id);
mbed_official 89:2f7ae1d76d7a 327 if (ret != 0) {
mbed_official 89:2f7ae1d76d7a 328 tr_error("mesh0 up Fail with code: %"PRIi32"", ret);
mbed_official 89:2f7ae1d76d7a 329 return ret;
mbed_official 89:2f7ae1d76d7a 330 }
mbed_official 89:2f7ae1d76d7a 331 tr_info("mesh0 bootstrap ongoing..");
mbed_official 89:2f7ae1d76d7a 332 return 0;
mbed_official 89:2f7ae1d76d7a 333 }
mbed_official 89:2f7ae1d76d7a 334
mbed_official 89:2f7ae1d76d7a 335 void border_router_tasklet_start(void)
mbed_official 89:2f7ae1d76d7a 336 {
mbed_official 89:2f7ae1d76d7a 337 ws_br_handler.ws_interface_id = -1;
mbed_official 89:2f7ae1d76d7a 338 ws_br_handler.eth_interface_id = -1;
mbed_official 89:2f7ae1d76d7a 339
mbed_official 89:2f7ae1d76d7a 340 load_config();
mbed_official 89:2f7ae1d76d7a 341 wisun_rf_init();
mbed_official 89:2f7ae1d76d7a 342 protocol_stats_start(&nwk_stats);
mbed_official 89:2f7ae1d76d7a 343
mbed_official 89:2f7ae1d76d7a 344 eventOS_event_handler_create(
mbed_official 89:2f7ae1d76d7a 345 &borderrouter_tasklet,
mbed_official 89:2f7ae1d76d7a 346 ARM_LIB_TASKLET_INIT_EVENT);
mbed_official 89:2f7ae1d76d7a 347 }
mbed_official 89:2f7ae1d76d7a 348
mbed_official 89:2f7ae1d76d7a 349 static int backhaul_interface_up(int8_t driver_id)
mbed_official 89:2f7ae1d76d7a 350 {
mbed_official 89:2f7ae1d76d7a 351 int retval = -1;
mbed_official 89:2f7ae1d76d7a 352 tr_debug("backhaul_interface_up: %i", driver_id);
mbed_official 89:2f7ae1d76d7a 353 if (ws_br_handler.eth_interface_id != -1) {
mbed_official 89:2f7ae1d76d7a 354 tr_debug("Border RouterInterface already at active state");
mbed_official 89:2f7ae1d76d7a 355 return retval;
mbed_official 89:2f7ae1d76d7a 356 }
mbed_official 89:2f7ae1d76d7a 357
mbed_official 89:2f7ae1d76d7a 358 if (!eth_mac_api) {
mbed_official 89:2f7ae1d76d7a 359 eth_mac_api = ethernet_mac_create(driver_id);
mbed_official 89:2f7ae1d76d7a 360 }
mbed_official 89:2f7ae1d76d7a 361
mbed_official 89:2f7ae1d76d7a 362 ws_br_handler.eth_interface_id = arm_nwk_interface_ethernet_init(eth_mac_api, "bh0");
mbed_official 89:2f7ae1d76d7a 363
mbed_official 89:2f7ae1d76d7a 364 MBED_ASSERT(ws_br_handler.eth_interface_id >= 0);
mbed_official 89:2f7ae1d76d7a 365 if (ws_br_handler.eth_interface_id >= 0) {
mbed_official 89:2f7ae1d76d7a 366 tr_debug("Backhaul interface ID: %d", ws_br_handler.eth_interface_id);
mbed_official 89:2f7ae1d76d7a 367 if (ws_br_handler.ws_interface_id > -1) {
mbed_official 89:2f7ae1d76d7a 368 ws_bbr_start(ws_br_handler.ws_interface_id, ws_br_handler.eth_interface_id);
mbed_official 89:2f7ae1d76d7a 369 }
mbed_official 89:2f7ae1d76d7a 370 arm_nwk_interface_configure_ipv6_bootstrap_set(
mbed_official 89:2f7ae1d76d7a 371 ws_br_handler.eth_interface_id, backhaul_bootstrap_mode, backhaul_prefix);
mbed_official 89:2f7ae1d76d7a 372 arm_nwk_interface_up(ws_br_handler.eth_interface_id);
mbed_official 89:2f7ae1d76d7a 373 retval = 0;
mbed_official 89:2f7ae1d76d7a 374 } else {
mbed_official 89:2f7ae1d76d7a 375 tr_error("Could not init ethernet");
mbed_official 89:2f7ae1d76d7a 376 }
mbed_official 89:2f7ae1d76d7a 377
mbed_official 89:2f7ae1d76d7a 378 return retval;
mbed_official 89:2f7ae1d76d7a 379 }
mbed_official 89:2f7ae1d76d7a 380
mbed_official 89:2f7ae1d76d7a 381 static int backhaul_interface_down(void)
mbed_official 89:2f7ae1d76d7a 382 {
mbed_official 89:2f7ae1d76d7a 383 int retval = -1;
mbed_official 89:2f7ae1d76d7a 384 if (ws_br_handler.eth_interface_id != -1) {
mbed_official 89:2f7ae1d76d7a 385 arm_nwk_interface_down(ws_br_handler.eth_interface_id);
mbed_official 89:2f7ae1d76d7a 386 ws_br_handler.eth_interface_id = -1;
mbed_official 89:2f7ae1d76d7a 387 retval = 0;
mbed_official 89:2f7ae1d76d7a 388 } else {
mbed_official 89:2f7ae1d76d7a 389 tr_debug("Could not set eth down");
mbed_official 89:2f7ae1d76d7a 390 }
mbed_official 89:2f7ae1d76d7a 391 return retval;
mbed_official 89:2f7ae1d76d7a 392 }
mbed_official 89:2f7ae1d76d7a 393
mbed_official 89:2f7ae1d76d7a 394 static void print_interface_addr(int id)
mbed_official 89:2f7ae1d76d7a 395 {
mbed_official 89:2f7ae1d76d7a 396 uint8_t address_buf[128];
mbed_official 89:2f7ae1d76d7a 397 int address_count = 0;
mbed_official 89:2f7ae1d76d7a 398 char buf[128];
mbed_official 89:2f7ae1d76d7a 399
mbed_official 89:2f7ae1d76d7a 400 if (arm_net_address_list_get(id, 128, address_buf, &address_count) == 0) {
mbed_official 89:2f7ae1d76d7a 401 uint8_t *t_buf = address_buf;
mbed_official 89:2f7ae1d76d7a 402 for (int i = 0; i < address_count; ++i) {
mbed_official 89:2f7ae1d76d7a 403 ip6tos(t_buf, buf);
mbed_official 89:2f7ae1d76d7a 404 tr_info(" [%d] %s", i, buf);
mbed_official 89:2f7ae1d76d7a 405 t_buf += 16;
mbed_official 89:2f7ae1d76d7a 406 }
mbed_official 89:2f7ae1d76d7a 407 }
mbed_official 89:2f7ae1d76d7a 408 }
mbed_official 89:2f7ae1d76d7a 409
mbed_official 89:2f7ae1d76d7a 410 #if MBED_CONF_APP_DEBUG_TRACE
mbed_official 89:2f7ae1d76d7a 411 static void print_interface_addresses(void)
mbed_official 89:2f7ae1d76d7a 412 {
mbed_official 89:2f7ae1d76d7a 413 tr_info("Backhaul interface addresses:");
mbed_official 89:2f7ae1d76d7a 414 print_interface_addr(ws_br_handler.eth_interface_id);
mbed_official 89:2f7ae1d76d7a 415
mbed_official 89:2f7ae1d76d7a 416 tr_info("RF interface addresses:");
mbed_official 89:2f7ae1d76d7a 417 print_interface_addr(ws_br_handler.ws_interface_id);
mbed_official 89:2f7ae1d76d7a 418 }
mbed_official 89:2f7ae1d76d7a 419 #endif
mbed_official 89:2f7ae1d76d7a 420
mbed_official 89:2f7ae1d76d7a 421 /**
mbed_official 89:2f7ae1d76d7a 422 * \brief Border Router Main Tasklet
mbed_official 89:2f7ae1d76d7a 423 *
mbed_official 89:2f7ae1d76d7a 424 * Tasklet Handle next items:
mbed_official 89:2f7ae1d76d7a 425 *
mbed_official 89:2f7ae1d76d7a 426 * - EV_INIT event: Set Certificate Chain, RF Interface Boot UP, multicast Init
mbed_official 89:2f7ae1d76d7a 427 * - SYSTEM_TIMER event: For RF interface Handshake purpose
mbed_official 89:2f7ae1d76d7a 428 *
mbed_official 89:2f7ae1d76d7a 429 */
mbed_official 89:2f7ae1d76d7a 430 static void borderrouter_tasklet(arm_event_s *event)
mbed_official 89:2f7ae1d76d7a 431 {
mbed_official 89:2f7ae1d76d7a 432 arm_library_event_type_e event_type;
mbed_official 89:2f7ae1d76d7a 433 event_type = (arm_library_event_type_e)event->event_type;
mbed_official 89:2f7ae1d76d7a 434
mbed_official 89:2f7ae1d76d7a 435 switch (event_type) {
mbed_official 89:2f7ae1d76d7a 436 case ARM_LIB_NWK_INTERFACE_EVENT:
mbed_official 89:2f7ae1d76d7a 437
mbed_official 89:2f7ae1d76d7a 438 if (event->event_id == ws_br_handler.eth_interface_id) {
mbed_official 89:2f7ae1d76d7a 439 network_interface_event_handler(event);
mbed_official 89:2f7ae1d76d7a 440 } else {
mbed_official 89:2f7ae1d76d7a 441 wisun_interface_event_handler(event);
mbed_official 89:2f7ae1d76d7a 442 }
mbed_official 89:2f7ae1d76d7a 443
mbed_official 89:2f7ae1d76d7a 444 break;
mbed_official 89:2f7ae1d76d7a 445 // comes from the backhaul_driver_init.
mbed_official 89:2f7ae1d76d7a 446 case APPLICATION_EVENT:
mbed_official 89:2f7ae1d76d7a 447 if (event->event_id == NR_BACKHAUL_INTERFACE_PHY_DRIVER_READY) {
mbed_official 89:2f7ae1d76d7a 448 int8_t net_backhaul_id = (int8_t) event->event_data;
mbed_official 89:2f7ae1d76d7a 449
mbed_official 89:2f7ae1d76d7a 450 if (backhaul_interface_up(net_backhaul_id) != 0) {
mbed_official 89:2f7ae1d76d7a 451 tr_debug("Backhaul bootstrap start failed");
mbed_official 89:2f7ae1d76d7a 452 } else {
mbed_official 89:2f7ae1d76d7a 453 tr_debug("Backhaul bootstrap started");
mbed_official 89:2f7ae1d76d7a 454 }
mbed_official 89:2f7ae1d76d7a 455 } else if (event->event_id == NR_BACKHAUL_INTERFACE_PHY_DOWN) {
mbed_official 89:2f7ae1d76d7a 456 if (backhaul_interface_down() == 0) {
mbed_official 89:2f7ae1d76d7a 457 tr_debug("Backhaul interface is down");
mbed_official 89:2f7ae1d76d7a 458 }
mbed_official 89:2f7ae1d76d7a 459 }
mbed_official 89:2f7ae1d76d7a 460 break;
mbed_official 89:2f7ae1d76d7a 461
mbed_official 89:2f7ae1d76d7a 462 case ARM_LIB_TASKLET_INIT_EVENT:
mbed_official 89:2f7ae1d76d7a 463 br_tasklet_id = event->receiver;
mbed_official 89:2f7ae1d76d7a 464 eth_network_data_init();
mbed_official 89:2f7ae1d76d7a 465 backhaul_driver_init(borderrouter_backhaul_phy_status_cb);
mbed_official 89:2f7ae1d76d7a 466 mesh_network_up();
mbed_official 89:2f7ae1d76d7a 467 eventOS_event_timer_request(9, ARM_LIB_SYSTEM_TIMER_EVENT, br_tasklet_id, 20000);
mbed_official 89:2f7ae1d76d7a 468 break;
mbed_official 89:2f7ae1d76d7a 469
mbed_official 89:2f7ae1d76d7a 470 case ARM_LIB_SYSTEM_TIMER_EVENT:
mbed_official 89:2f7ae1d76d7a 471 eventOS_event_timer_cancel(event->event_id, event->receiver);
mbed_official 89:2f7ae1d76d7a 472
mbed_official 89:2f7ae1d76d7a 473 if (event->event_id == 9) {
mbed_official 89:2f7ae1d76d7a 474 #if MBED_CONF_APP_DEBUG_TRACE
mbed_official 89:2f7ae1d76d7a 475 arm_print_routing_table();
mbed_official 89:2f7ae1d76d7a 476 arm_print_neigh_cache();
mbed_official 89:2f7ae1d76d7a 477 print_memory_stats();
mbed_official 89:2f7ae1d76d7a 478 // Trace interface addresses. This trace can be removed if nanostack prints added/removed
mbed_official 89:2f7ae1d76d7a 479 // addresses.
mbed_official 89:2f7ae1d76d7a 480 print_interface_addresses();
mbed_official 89:2f7ae1d76d7a 481 #endif
mbed_official 89:2f7ae1d76d7a 482 eventOS_event_timer_request(9, ARM_LIB_SYSTEM_TIMER_EVENT, br_tasklet_id, 20000);
mbed_official 89:2f7ae1d76d7a 483 }
mbed_official 89:2f7ae1d76d7a 484 break;
mbed_official 89:2f7ae1d76d7a 485
mbed_official 89:2f7ae1d76d7a 486 default:
mbed_official 89:2f7ae1d76d7a 487 break;
mbed_official 89:2f7ae1d76d7a 488 }
mbed_official 89:2f7ae1d76d7a 489 }
mbed_official 89:2f7ae1d76d7a 490
mbed_official 89:2f7ae1d76d7a 491 static void borderrouter_backhaul_phy_status_cb(uint8_t link_up, int8_t driver_id)
mbed_official 89:2f7ae1d76d7a 492 {
mbed_official 89:2f7ae1d76d7a 493 arm_event_s event = {
mbed_official 89:2f7ae1d76d7a 494 .sender = br_tasklet_id,
mbed_official 89:2f7ae1d76d7a 495 .receiver = br_tasklet_id,
mbed_official 89:2f7ae1d76d7a 496 .priority = ARM_LIB_MED_PRIORITY_EVENT,
mbed_official 89:2f7ae1d76d7a 497 .event_type = APPLICATION_EVENT,
mbed_official 89:2f7ae1d76d7a 498 .event_data = driver_id
mbed_official 89:2f7ae1d76d7a 499 };
mbed_official 89:2f7ae1d76d7a 500
mbed_official 89:2f7ae1d76d7a 501 if (link_up) {
mbed_official 89:2f7ae1d76d7a 502 event.event_id = NR_BACKHAUL_INTERFACE_PHY_DRIVER_READY;
mbed_official 89:2f7ae1d76d7a 503 } else {
mbed_official 89:2f7ae1d76d7a 504 event.event_id = NR_BACKHAUL_INTERFACE_PHY_DOWN;
mbed_official 89:2f7ae1d76d7a 505 }
mbed_official 89:2f7ae1d76d7a 506
mbed_official 89:2f7ae1d76d7a 507 eventOS_event_send(&event);
mbed_official 89:2f7ae1d76d7a 508 }
mbed_official 89:2f7ae1d76d7a 509
mbed_official 89:2f7ae1d76d7a 510 // ethernet interface
mbed_official 89:2f7ae1d76d7a 511 static void network_interface_event_handler(arm_event_s *event)
mbed_official 89:2f7ae1d76d7a 512 {
mbed_official 89:2f7ae1d76d7a 513 arm_nwk_interface_status_type_e status = (arm_nwk_interface_status_type_e)event->event_data;
mbed_official 89:2f7ae1d76d7a 514 switch (status) {
mbed_official 89:2f7ae1d76d7a 515 case (ARM_NWK_BOOTSTRAP_READY): { // Interface configured Bootstrap is ready
mbed_official 89:2f7ae1d76d7a 516
mbed_official 89:2f7ae1d76d7a 517 tr_info("BR interface_id: %d", ws_br_handler.eth_interface_id);
mbed_official 89:2f7ae1d76d7a 518 if (-1 != ws_br_handler.eth_interface_id) {
mbed_official 89:2f7ae1d76d7a 519 // metric set to high priority
mbed_official 89:2f7ae1d76d7a 520 if (0 != arm_net_interface_set_metric(ws_br_handler.eth_interface_id, 0)) {
mbed_official 89:2f7ae1d76d7a 521 tr_warn("Failed to set metric for eth0.");
mbed_official 89:2f7ae1d76d7a 522 }
mbed_official 89:2f7ae1d76d7a 523
mbed_official 89:2f7ae1d76d7a 524 if (backhaul_bootstrap_mode == NET_IPV6_BOOTSTRAP_STATIC) {
mbed_official 89:2f7ae1d76d7a 525 uint8_t *next_hop_ptr;
mbed_official 89:2f7ae1d76d7a 526
mbed_official 89:2f7ae1d76d7a 527 if (memcmp(backhaul_route.next_hop, (const uint8_t[16]) {
mbed_official 89:2f7ae1d76d7a 528 0
mbed_official 89:2f7ae1d76d7a 529 }, 16) == 0) {
mbed_official 89:2f7ae1d76d7a 530 next_hop_ptr = NULL;
mbed_official 89:2f7ae1d76d7a 531 } else {
mbed_official 89:2f7ae1d76d7a 532 next_hop_ptr = backhaul_route.next_hop;
mbed_official 89:2f7ae1d76d7a 533 }
mbed_official 89:2f7ae1d76d7a 534 tr_debug("Default route prefix: %s/%d", print_ipv6(backhaul_route.prefix),
mbed_official 89:2f7ae1d76d7a 535 backhaul_route.prefix_len);
mbed_official 89:2f7ae1d76d7a 536 tr_debug("Default route next hop: %s", print_ipv6(backhaul_route.next_hop));
mbed_official 89:2f7ae1d76d7a 537 arm_net_route_add(backhaul_route.prefix,
mbed_official 89:2f7ae1d76d7a 538 backhaul_route.prefix_len,
mbed_official 89:2f7ae1d76d7a 539 next_hop_ptr, 0xffffffff, 128,
mbed_official 89:2f7ae1d76d7a 540 ws_br_handler.eth_interface_id);
mbed_official 89:2f7ae1d76d7a 541 }
mbed_official 89:2f7ae1d76d7a 542 tr_info("Backhaul interface addresses:");
mbed_official 89:2f7ae1d76d7a 543 print_interface_addr(ws_br_handler.eth_interface_id);
mbed_official 89:2f7ae1d76d7a 544 }
mbed_official 89:2f7ae1d76d7a 545 break;
mbed_official 89:2f7ae1d76d7a 546 }
mbed_official 89:2f7ae1d76d7a 547 case (ARM_NWK_RPL_INSTANCE_FLOODING_READY): // RPL instance have been flooded
mbed_official 89:2f7ae1d76d7a 548 tr_info("RPL instance have been flooded");
mbed_official 89:2f7ae1d76d7a 549 break;
mbed_official 89:2f7ae1d76d7a 550 case (ARM_NWK_SET_DOWN_COMPLETE): // Interface DOWN command successfully
mbed_official 89:2f7ae1d76d7a 551 break;
mbed_official 89:2f7ae1d76d7a 552 case (ARM_NWK_NWK_SCAN_FAIL): // Interface have not detect any valid network
mbed_official 89:2f7ae1d76d7a 553 tr_warning("mesh0 haven't detect any valid nwk");
mbed_official 89:2f7ae1d76d7a 554 break;
mbed_official 89:2f7ae1d76d7a 555 case (ARM_NWK_IP_ADDRESS_ALLOCATION_FAIL): // IP address allocation fail(ND, DHCPv4 or DHCPv6)
mbed_official 89:2f7ae1d76d7a 556 tr_error("NO GP address detected");
mbed_official 89:2f7ae1d76d7a 557 break;
mbed_official 89:2f7ae1d76d7a 558 case (ARM_NWK_DUPLICATE_ADDRESS_DETECTED): // User specific GP16 was not valid
mbed_official 89:2f7ae1d76d7a 559 tr_error("Ethernet IPv6 Duplicate addr detected!");
mbed_official 89:2f7ae1d76d7a 560 break;
mbed_official 89:2f7ae1d76d7a 561 case (ARM_NWK_AUHTENTICATION_START_FAIL): // No valid Authentication server detected behind access point ;
mbed_official 89:2f7ae1d76d7a 562 tr_error("No valid ath server detected behind AP");
mbed_official 89:2f7ae1d76d7a 563 break;
mbed_official 89:2f7ae1d76d7a 564 case (ARM_NWK_AUHTENTICATION_FAIL): // Network authentication fail by Handshake
mbed_official 89:2f7ae1d76d7a 565 tr_error("Network authentication fail");
mbed_official 89:2f7ae1d76d7a 566 break;
mbed_official 89:2f7ae1d76d7a 567 case (ARM_NWK_NWK_CONNECTION_DOWN): // No connection between Access point or Default Router
mbed_official 89:2f7ae1d76d7a 568 tr_warning("Prefix timeout");
mbed_official 89:2f7ae1d76d7a 569 break;
mbed_official 89:2f7ae1d76d7a 570 case (ARM_NWK_NWK_PARENT_POLL_FAIL): // Sleepy host poll fail 3 time
mbed_official 89:2f7ae1d76d7a 571 tr_warning("Parent poll fail");
mbed_official 89:2f7ae1d76d7a 572 break;
mbed_official 89:2f7ae1d76d7a 573 case (ARM_NWK_PHY_CONNECTION_DOWN): // Interface PHY cable off or serial port interface not respond anymore
mbed_official 89:2f7ae1d76d7a 574 tr_error("eth0 down");
mbed_official 89:2f7ae1d76d7a 575 break;
mbed_official 89:2f7ae1d76d7a 576 default:
mbed_official 89:2f7ae1d76d7a 577 tr_warning("Unknown nwk if event (type: %02x, id: %02x, data: %02x)", event->event_type, event->event_id, (unsigned int)event->event_data);
mbed_official 89:2f7ae1d76d7a 578 break;
mbed_official 89:2f7ae1d76d7a 579 }
mbed_official 89:2f7ae1d76d7a 580 }
mbed_official 89:2f7ae1d76d7a 581
mbed_official 89:2f7ae1d76d7a 582 static void wisun_interface_event_handler(arm_event_s *event)
mbed_official 89:2f7ae1d76d7a 583 {
mbed_official 89:2f7ae1d76d7a 584 arm_nwk_interface_status_type_e status = (arm_nwk_interface_status_type_e)event->event_data;
mbed_official 89:2f7ae1d76d7a 585 switch (status) {
mbed_official 89:2f7ae1d76d7a 586 case (ARM_NWK_BOOTSTRAP_READY): { // Interface configured Bootstrap is ready
mbed_official 89:2f7ae1d76d7a 587 tr_info("Wisun bootstrap ready");
mbed_official 89:2f7ae1d76d7a 588
mbed_official 89:2f7ae1d76d7a 589 if (arm_net_interface_set_metric(ws_br_handler.ws_interface_id, MESH_METRIC) != 0) {
mbed_official 89:2f7ae1d76d7a 590 tr_warn("Failed to set metric for mesh0.");
mbed_official 89:2f7ae1d76d7a 591 }
mbed_official 89:2f7ae1d76d7a 592
mbed_official 89:2f7ae1d76d7a 593 tr_info("RF interface addresses:");
mbed_official 89:2f7ae1d76d7a 594 print_interface_addr(ws_br_handler.ws_interface_id);
mbed_official 89:2f7ae1d76d7a 595
mbed_official 89:2f7ae1d76d7a 596 break;
mbed_official 89:2f7ae1d76d7a 597 }
mbed_official 89:2f7ae1d76d7a 598 case (ARM_NWK_SET_DOWN_COMPLETE):
mbed_official 89:2f7ae1d76d7a 599 tr_info("Wisun interface down");
mbed_official 89:2f7ae1d76d7a 600 break;
mbed_official 89:2f7ae1d76d7a 601 default:
mbed_official 89:2f7ae1d76d7a 602 tr_warning("Unknown nwk if event (type: %02x, id: %02x, data: %02x)", event->event_type, event->event_id, (unsigned int)event->event_data);
mbed_official 89:2f7ae1d76d7a 603 break;
mbed_official 89:2f7ae1d76d7a 604 }
mbed_official 89:2f7ae1d76d7a 605
mbed_official 89:2f7ae1d76d7a 606 }
mbed_official 89:2f7ae1d76d7a 607
mbed_official 89:2f7ae1d76d7a 608 #endif