diff --git a/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata index a218183..71fa1e6 100644 --- a/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata +++ b/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata @@ -1,5 +1,25 @@ #!/bin/sh +[ -e /lib/firmware/$FIRMWARE ] && exit 0 + +. /lib/ipq806x.sh +. /lib/functions.sh +. /lib/functions/system.sh + +# xor multiple hex values of the same length +xor() { + local ret="0x$1" + + shift 1 + while [[ "$1" ]]; do + local val="0x$1" + ret=$((${ret:-0} ^ ${val:-0})) + shift 1 + done + + printf "%02x" "$ret" +} + ath10kcal_die() { echo "ath10cal: " "$*" exit 1 @@ -30,39 +50,46 @@ ath10kcal_extract() { ath10kcal_patch_mac() { local mac=$1 + local mac_offset=6 + local chksum_offset=2 + local xor_mac + local xor_fw_mac + local xor_fw_chksum [ -z "$mac" ] && return - macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=6 count=6 -} + xor_mac="${mac:0:2}${mac:3:2} ${mac:6:2}${mac:9:2} ${mac:12:2}${mac:15:2}" + xor_fw_mac=$(hexdump -v -n 6 -s $mac_offset -e '/2 "%04x "' /lib/firmware/$FIRMWARE) -[ -e /lib/firmware/$FIRMWARE ] && exit 0 + xor_fw_chksum=$(hexdump -v -n 2 -s $chksum_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE) + xor_fw_chksum=$(xor $xor_fw_chksum $xor_fw_mac $xor_mac) -. /lib/ipq806x.sh -. /lib/functions.sh -. /lib/functions/system.sh + echo -ne \\x${xor_fw_chksum:0:2}\\x${xor_fw_chksum:2:2} | \ + dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=$chksum_offset count=2 -board=$(ipq806x_board_name) + macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=$mac_offset count=6 +} +board=$(ipq806x_board_name) case "$FIRMWARE" in "ath10k/cal-pci-0000:01:00.0.bin") case $board in c2600) ath10kcal_extract "radio" 4096 12064 -# ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary default-mac 8) -1) + ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary default-mac 8) -1) ;; ea8500) - hw_mac_addr=$(mtd_get_mac_ascii devinfo hw_mac_addr) ath10kcal_extract "art" 4096 12064 + ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_ascii devinfo hw_mac_addr) +1) ;; - r7500v2 |\ - r7800) + r7500v2 |\ + r7800) ath10kcal_extract "art" 4096 12064 ;; tew827dru) - hw_mac_addr=$(mtd_get_mac_ascii devinfo hw_mac_addr) ath10kcal_extract "ART" 4096 12064 + ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_ascii APPSBLENV wan_mac) + 1) ;; esac ;; @@ -70,19 +97,19 @@ case "$FIRMWARE" in case $board in c2600) ath10kcal_extract "radio" 20480 12064 -# ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary default-mac 8) -2) + ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary default-mac 8) -2) ;; ea8500) - hw_mac_addr=$(mtd_get_mac_ascii devinfo hw_mac_addr) ath10kcal_extract "art" 20480 12064 + ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_ascii devinfo hw_mac_addr) +2) ;; - r7500v2 |\ - r7800) + r7500v2 |\ + r7800) ath10kcal_extract "art" 20480 12064 ;; tew827dru) - hw_mac_addr=$(mtd_get_mac_ascii devinfo hw_mac_addr) ath10kcal_extract "ART" 20480 12064 + ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_ascii APPSBLENV wan_mac) + 2) ;; esac ;; diff --git a/target/linux/ipq806x/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac b/target/linux/ipq806x/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac deleted file mode 100644 index a3326ab..0000000 --- a/target/linux/ipq806x/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/ash - -[ "$ACTION" == "add" ] || exit 0 - -PHYNBR=${DEVPATH##*/phy} - -[ -n $PHYNBR ] || exit 0 - -. /lib/ipq806x.sh -. /lib/functions/system.sh - -board=$(ipq806x_board_name) - -case "$board" in - c2600) - echo $(macaddr_add $(mtd_get_mac_binary default-mac 8) $(($PHYNBR - 1)) ) > /sys${DEVPATH}/macaddress - ;; - ea8500) - echo $(macaddr_add $(mtd_get_mac_ascii devinfo hw_mac_addr) $(($PHYNBR + 1)) ) > /sys${DEVPATH}/macaddress - ;; - tew827dru) - echo $(macaddr_add $(mtd_get_mac_ascii APPSBLENV wan_mac) $(($PHYNBR + 1)) ) > /sys${DEVPATH}/macaddress - ;; - *) - ;; -esac