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:
Mon Mar 04 09:02:42 2019 +0000
Revision:
92:7faf6dcb791f
Parent:
89:2f7ae1d76d7a
Child:
94:0c008659750c
Merge pull request #160 from ARMmbed/jenkinsconfig

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