danielmarschall / uuid_mac_utils

Creates and Interpretes UUIDs and MAC addresses
https://misc.daniel-marschall.de/tools/uuid_mac_decoder/
Apache License 2.0
2 stars 0 forks source link

Implement BARC address detection #1

Closed danielmarschall closed 4 months ago

danielmarschall commented 4 months ago

Prototype:

<?php

$mac = '8F:01:22:33:44:55';

$b0 = substr($mac,0,2);
    $n0 = substr($mac,0,1);
    $n1 = substr($mac,1,1);
$b1 = substr($mac,3,2);
    $n2 = substr($mac,3,1);
    $n3 = substr($mac,4,1);
$b2 = substr($mac,6,2);
    $n4 = substr($mac,6,1);
    $n5 = substr($mac,7,1);
$b3 = substr($mac,9,2);
    $n6 = substr($mac,9,1);
    $n7 = substr($mac,10,1);
$b4 = substr($mac,12,2);
    $n8 = substr($mac,12,1);
    $n9 = substr($mac,13,1);
$b5 = substr($mac,15,2);
    $n10= substr($mac,15,1);
    $n11= substr($mac,16,1);

echo "[$mac] MAC Address\n";
if (($n1 == 'E') || ($n1 == 'F')) { // Standard Assigned Identifier (SAI)
    // Information taken from this paper:
    // https://www.techrxiv.org/users/684395/articles/678862-link-layer-software-defined-addressing-using-block-address-registration-and-claiming-barc
    // DOI: 10.36227/techrxiv.19105118.v1
    if ($n1 == 'E') echo "[_E:__:__:__:__:__] Unicast SAI Address\n";
    else if ($n1 == 'F') echo "[_F:__:__:__:__:__] Multicast SAI Address\n";
    if ($n2 == "0") {
        echo "[__:{$n2}_:__:__:__:__] Standard = BARC (IEEE 802.1CQ)\n"; // Block Address Registration and Claiming (BARC)
        $size = hexdec($n0) & 0b11; // j,k=size
        // size=0 means N3=X3, N4=X4, ..., N11=X11
        // size=1 means N3=X3, N4=X4, ..., N10=X10, N11=a where a is 0 for Unicast and any for Multicast
        // size=2 means N3=X3, N4=X4, ..., N9=X9, N10..N11=a where a is 0 for Unicast and any for Multicast
        // size=3 means N3=X3, N4=X4, ..., N8=X8, N9..N11=a where a is 0 for Unicast and any for Multicast
        if ((hexdec($n0) >= 0) && (hexdec($n0) <= 3)) { // r,i=01
            if ($n1 == 'F') {
                /*
                when r=0, i=0 (N0=0b00xx=0x0-0x3) and m=1 (N1=F), the address is a Claimable Address Block Address (CABA) that identifies the associated CAB with i=1;
                */
                echo "[$n0$n1:__:__:__:__:__] Claimable Address Block Address (CABA) that identifies the associated Claimable Address Block (CAB) with i=1. CAB size is $size\n";
            } else if ($n1 == 'E') {
                /*
                when r=0, i=0 (N0=0b00xx=0x0-0x3) and m=0 (N1=E), the address is a temporary unicast address (TUA) for use in BARC messaging only.
                */
                echo "[$n0$n1:__:__:__:__:__] Temporary Unicast Address (TUA) for use in BARC messaging only\n";
            } else assert(false);
        } else if ((hexdec($n0) >= 4) && (hexdec($n0) <= 7)) { // r,i=01
            /*
            when r=0 and i=1 (N0=0b01xx=0x4-0x7), the address is a Claimable Address (CA) in a Claimable Address Block (CAB) of size jk;
            */
            echo "[{$n0}_:__:__:__:__:__] Claimable Address (CA) in a Claimable Address Block (CAB) of size $size\n";
        } else if ((hexdec($n0) >= 8) && (hexdec($n0) <= 0xF)) { // r=1
            /*
            when r=1 (N0=0b1xxx=0x8-0xF), the address is a Registrable Address (RA) in a Registrable Address Block (RAB);
            */
            echo "[{$n0}_:__:__:__:__:__] Registrable Address (RA) in a Registrable Address Block (RAB)\n";

/* not 100% sure about this interpretation, because the paper does not describe it:
        } else if ((hexdec($n0) >= 8) && (hexdec($n0) <= 0xB)) { // r,i=10
            if ($n1 == 'F') {
                echo "[$n0$n1:__:__:__:__:__] Registrable Address (RA), RAB size $size\n";
            } else if ($n1 == 'E') {
                echo "[$n0$n1:__:__:__:__:__] Undefined!\n";
            }
        } else if ((hexdec($n0) >= 0xC) && (hexdec($n0) <= 0xF)) { // r,i=11
            echo "[{$n0}_:__:__:__:__:__] Registrable Address Block (RAB), RAB size $size\n";
*/
        } else {
            assert(false);
        }
        echo "[__:_$n3:$n4$n5:__:__:__] Semantic Prefix\n";
        echo "[__:__:__:$n6$n7:$n8$n9:$n10$n11] Prefix Dependant Data\n";
    } else {
        echo "[__:{$n2}_:__:__:__:__] Unknown IEEE 802 Standard #$n2\n";
    }
} else {
    echo "Non-SAI Address\n";
}
danielmarschall commented 4 months ago

Fixed in SVN Rev 91