Changeset 36354


Ignore:
Timestamp:
2013-04-17T17:37:36+02:00 (5 years ago)
Author:
nbd
Message:

mac80211: rework mac address allocation

If the first byte is available in the address mask, use only that one -
set the local bit and xor it with the id << 2. This ensures that there
are no hardware BSSID & BSSID-mask conflicts with devices that have
almost the same MAC address with just a small offset. The MAC address
conflict has been observed in a deployment with some devices from the
same batch when running with multiple interfaces.

If only some bits of the last byte are available, xor the id onto the
last MAC address byte (relevant mostly for Ralink devices).

In other cases (should not happen at this point), use the previous MAC
address offset calculation but without the local bit.

Signed-off-by: Felix Fietkau <nbd@…>

Backport of r36353

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/attitude_adjustment/package/mac80211/files/lib/wifi/mac80211.sh

    r35781 r36354  
    274274 
    275275mac80211_generate_mac() { 
    276         local off="$1" 
    277         local mac="$2" 
     276        local id="$1" 
     277        local ref="$2" 
    278278        local mask="$3" 
    279         local oIFS="$IFS"; IFS=":"; set -- $mac; IFS="$oIFS" 
    280  
    281         local b2mask=0x00 
    282         [ $off -gt 0 ] && 
    283                 [ "$mask" = "00:00:00:00:00:00" -o $(( 0x${mask%%:*} & 0x2 )) -gt 0 ] && b2mask=0x02 
    284  
    285         printf "%02x:%s:%s:%s:%02x:%02x" \ 
    286                 $(( 0x$1 | $b2mask )) $2 $3 $4 \ 
    287                 $(( (0x$5 + ($off / 0x100)) % 0x100 )) \ 
    288                 $(( (0x$6 + $off) % 0x100 )) 
     279 
     280        [ "$mask" = "00:00:00:00:00:00" ] && mask="ff:ff:ff:ff:ff:ff"; 
     281        local oIFS="$IFS"; IFS=":"; set -- $mask; IFS="$oIFS" 
     282 
     283        local mask1=$1 
     284        local mask6=$6 
     285 
     286        local oIFS="$IFS"; IFS=":"; set -- $ref; IFS="$oIFS" 
     287        [ "$((0x$mask1))" -gt 0 ] && { 
     288                b1=$(((0x$1 | 0x2) ^ ($id << 2))) 
     289                printf "%02x:%s:%s:%s:%s:%s" $b1 $2 $3 $4 $5 $6 
     290                return 
     291        } 
     292 
     293        [ "$((0x$mask6))" -lt 255 ] && { 
     294                printf "%s:%s:%s:%s:%s:%02x" $1 $2 $3 $4 $5 $(( 0x$6 ^ $id )) 
     295                return 
     296        } 
     297 
     298        off2=$(( (0x$6 + $id) / 0x100 )) 
     299        printf "%s:%s:%s:%s:%02x:%02x" \ 
     300                $1 $2 $3 $4 \ 
     301                $(( (0x$5 + $off2) % 0x100 )) \ 
     302                $(( (0x$6 + $id) % 0x100 )) 
    289303} 
    290304 
Note: See TracChangeset for help on using the changeset viewer.