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