diff --git a/source/6LoWPAN/ws/ws_bootstrap.c b/source/6LoWPAN/ws/ws_bootstrap.c index 2d2663040ff..dce8cbd2a79 100644 --- a/source/6LoWPAN/ws/ws_bootstrap.c +++ b/source/6LoWPAN/ws/ws_bootstrap.c @@ -502,9 +502,39 @@ static void ws_bootstrap_primary_parent_set(struct protocol_interface_info_entry // Update LLC to follow updated fhss settings ws_bootstrap_llc_hopping_update(cur,&fhss_configuration); +} +static void ws_bootstrap_ll_address_validate(struct protocol_interface_info_entry *cur) +{ + // Configure EUI64 for MAC if missing + uint8_t mac64[8]; + if (!cur->mac_api) { + return; + } + + cur->mac_api->mac64_get(cur->mac_api,MAC_EXTENDED_DYNAMIC, mac64); + + if (memcmp(mac64, ADDR_UNSPECIFIED,8) == 0) { + cur->mac_api->mac64_get(cur->mac_api,MAC_EXTENDED_READ_ONLY, mac64); + } + + if (memcmp(mac64, ADDR_UNSPECIFIED,8) == 0) { + // Generate random mac because it was not available + randLIB_get_n_bytes_random(mac64, 8); + mac64[0] |= 2; //Set Local Bit + mac64[0] &= ~1; //Clear multicast bit + + tr_info("Generated random MAC %s", trace_array(mac64,8)); + } + mac_helper_mac64_set(cur, mac64); + + memcpy(cur->iid_eui64, mac64, 8); + /* Invert U/L Bit */ + cur->iid_eui64[0] ^= 2; + memcpy(cur->iid_slaac, cur->iid_eui64, 8); } + /* \return 0x0100 to 0xFFFF ETX value (8 bit fraction) * \return 0xFFFF address not associated * \return 0x0000 address unknown or other error @@ -590,6 +620,8 @@ static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur) // Save FHSS api cur->ws_info->fhss_api = ns_sw_mac_get_fhss_api(cur->mac_api); + ws_bootstrap_ll_address_validate(cur); + addr_interface_set_ll64(cur, NULL); cur->nwk_nd_re_scan_count = 0; //WS_interface_up(cur);