Skip to content

Commit

Permalink
Added generation of mac address if not set
Browse files Browse the repository at this point in the history
  • Loading branch information
Mika Tervonen committed Oct 26, 2018
1 parent 990f4f1 commit bf36b91
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bf36b91

Please sign in to comment.