Skip to content

Implement Dynamic MAC Address Generation Based on Device Serial #3

@mihai-chiorean

Description

@mihai-chiorean

Description

The current implementation uses hardcoded MAC addresses (02:12:34:56:78:ca/cb) which can cause conflicts when multiple devices are on the same network.

Current Problem

# Current static MACs in usb-gadget.sh
echo "02:12:34:56:78:ca" > "$G/functions/$FUNC_NCM/dev_addr"
echo "02:12:34:56:78:cb" > "$G/functions/$FUNC_NCM/host_addr"

Proposed Solution

Generate locally-administered MAC addresses based on device serial number using SHA256 hashing, ensuring uniqueness while maintaining deterministic generation.

Implementation Details

  1. Extract device serial from /proc/cpuinfo or device-tree
  2. Generate hash-based MAC with locally-administered bit set
  3. Create different MACs for host and device interfaces
  4. Use the generate_mac() function from edgeos-flavor

Example Implementation

generate_mac() {
    local input="$1"
    local hash=$(echo -n "$input" | sha256sum | awk '{print $1}')
    local mac_base=${hash:0:12}
    local first_byte=${mac_base:0:2}
    local second_char=$(printf '%x' $((0x$first_byte & 0xfe | 0x02)))
    
    printf "%02x:%02x:%02x:%02x:%02x:%02x" \
       0x$second_char \
       0x${mac_base:2:2} \
       0x${mac_base:4:2} \
       0x${mac_base:6:2} \
       0x${mac_base:8:2} \
       0x${mac_base:10:2}
}

Acceptance Criteria

  • MAC addresses are unique per device
  • MACs are locally-administered (bit 1 of first octet = 1)
  • MACs persist across reboots for same device
  • Support multiple hardware platforms (RPi, Jetson, etc.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions