Skip to content

Commit bf36b91

Browse files
author
Mika Tervonen
committed
Added generation of mac address if not set
1 parent 990f4f1 commit bf36b91

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,39 @@ static void ws_bootstrap_primary_parent_set(struct protocol_interface_info_entry
502502

503503
// Update LLC to follow updated fhss settings
504504
ws_bootstrap_llc_hopping_update(cur,&fhss_configuration);
505+
}
505506

507+
static void ws_bootstrap_ll_address_validate(struct protocol_interface_info_entry *cur)
508+
{
509+
// Configure EUI64 for MAC if missing
510+
uint8_t mac64[8];
511+
if (!cur->mac_api) {
512+
return;
513+
}
514+
515+
cur->mac_api->mac64_get(cur->mac_api,MAC_EXTENDED_DYNAMIC, mac64);
516+
517+
if (memcmp(mac64, ADDR_UNSPECIFIED,8) == 0) {
518+
cur->mac_api->mac64_get(cur->mac_api,MAC_EXTENDED_READ_ONLY, mac64);
519+
}
520+
521+
if (memcmp(mac64, ADDR_UNSPECIFIED,8) == 0) {
522+
// Generate random mac because it was not available
523+
randLIB_get_n_bytes_random(mac64, 8);
524+
mac64[0] |= 2; //Set Local Bit
525+
mac64[0] &= ~1; //Clear multicast bit
526+
527+
tr_info("Generated random MAC %s", trace_array(mac64,8));
528+
}
529+
mac_helper_mac64_set(cur, mac64);
530+
531+
memcpy(cur->iid_eui64, mac64, 8);
532+
/* Invert U/L Bit */
533+
cur->iid_eui64[0] ^= 2;
534+
memcpy(cur->iid_slaac, cur->iid_eui64, 8);
506535

507536
}
537+
508538
/* \return 0x0100 to 0xFFFF ETX value (8 bit fraction)
509539
* \return 0xFFFF address not associated
510540
* \return 0x0000 address unknown or other error
@@ -590,6 +620,8 @@ static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur)
590620
// Save FHSS api
591621
cur->ws_info->fhss_api = ns_sw_mac_get_fhss_api(cur->mac_api);
592622

623+
ws_bootstrap_ll_address_validate(cur);
624+
593625
addr_interface_set_ll64(cur, NULL);
594626
cur->nwk_nd_re_scan_count = 0;
595627
//WS_interface_up(cur);

0 commit comments

Comments
 (0)