X-Git-Url: http://git.openwrt.org/?a=blobdiff_plain;f=package%2Fbase-files%2Ffiles%2Flib%2Ffunctions%2Fsystem.sh;h=c9f8eb0c31467c569563873dbcbb61103f9ea5ff;hb=d4009d7985500b0f4ec26dee9b91bdeb3ea16da5;hp=9b9d03df7b06fb887b25e9c2895399e792705683;hpb=6ed3349308b24a6bac753643970a1f9f56ff6070;p=openwrt%2Fstaging%2Fwigyori.git diff --git a/package/base-files/files/lib/functions/system.sh b/package/base-files/files/lib/functions/system.sh index 9b9d03df7b..c9f8eb0c31 100644 --- a/package/base-files/files/lib/functions/system.sh +++ b/package/base-files/files/lib/functions/system.sh @@ -1,5 +1,7 @@ # Copyright (C) 2006-2013 OpenWrt.org +. /usr/share/libubox/jshn.sh + get_mac_binary() { local path="$1" local offset="$2" @@ -12,6 +14,44 @@ get_mac_binary() { hexdump -v -n 6 -s $offset -e '5/1 "%02x:" 1/1 "%02x"' $path 2>/dev/null } +get_mac_label_dt() { + local basepath="/proc/device-tree" + local macdevice="$(cat "$basepath/aliases/label-mac-device" 2>/dev/null)" + local macaddr + + [ -n "$macdevice" ] || return + + macaddr=$(get_mac_binary "$basepath/$macdevice/mac-address" 0 2>/dev/null) + [ -n "$macaddr" ] || macaddr=$(get_mac_binary "$basepath/$macdevice/local-mac-address" 0 2>/dev/null) + + echo $macaddr +} + +get_mac_label_json() { + local cfg="/etc/board.json" + local macaddr + + [ -s "$cfg" ] || return + + json_init + json_load "$(cat $cfg)" + if json_is_a system object; then + json_select system + json_get_var macaddr label_macaddr + json_select .. + fi + + echo $macaddr +} + +get_mac_label() { + local macaddr=$(get_mac_label_dt) + + [ -n "$macaddr" ] || macaddr=$(get_mac_label_json) + + echo $macaddr +} + find_mtd_chardev() { local INDEX=$(find_mtd_index "$1") local PREFIX=/dev/mtd @@ -40,7 +80,7 @@ mtd_get_mac_ascii() { mtd_get_mac_text() { local mtdname=$1 - local offset=$2 + local offset=$(($2)) local part local mac_dirty @@ -79,12 +119,7 @@ mtd_get_mac_binary_ubi() { local ubidev=$(nand_find_ubi $CI_UBIPART) local part=$(nand_find_volume $ubidev $1) - if [ -z "$part" ]; then - echo "mtd_get_mac_binary: ubi volume $mtdname not found!" >&2 - return - fi - - hexdump -v -n 6 -s $offset -e '5/1 "%02x:" 1/1 "%02x"' /dev/$part 2>/dev/null + get_mac_binary "/dev/$part" "$offset" } mtd_get_part_size() { @@ -105,10 +140,17 @@ macaddr_add() { local oui=${mac%:*:*:*} local nic=${mac#*:*:*:} - nic=$(printf "%06x" $((0x${nic//:/} + $val & 0xffffff)) | sed 's/^\(.\{2\}\)\(.\{2\}\)\(.\{2\}\)/\1:\2:\3/') + nic=$(printf "%06x" $((0x${nic//:/} + val & 0xffffff)) | sed 's/^\(.\{2\}\)\(.\{2\}\)\(.\{2\}\)/\1:\2:\3/') echo $oui:$nic } +macaddr_geteui() { + local mac=$1 + local sep=$2 + + echo ${mac:9:2}$sep${mac:12:2}$sep${mac:15:2} +} + macaddr_setbit_la() { local mac=$1