treewide: move calibration data extraction function to library
[openwrt/openwrt.git] / target / linux / ipq806x / base-files / etc / hotplug.d / firmware / 11-ath10k-caldata
1 #!/bin/sh
2
3 [ -e /lib/firmware/$FIRMWARE ] && exit 0
4
5 . /lib/functions/caldata.sh
6
7 ath10kcal_patch_mac_crc() {
8 local mac=$1
9 local mac_offset=6
10 local chksum_offset=2
11 local xor_mac
12 local xor_fw_mac
13 local xor_fw_chksum
14
15 [ -z "$mac" ] && return
16
17 xor_fw_mac=$(hexdump -v -n 6 -s $mac_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE)
18 xor_fw_mac="${xor_fw_mac:0:4} ${xor_fw_mac:4:4} ${xor_fw_mac:8:4}"
19
20 macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=6 count=6
21
22 xor_mac=${mac//:/}
23 xor_mac="${xor_mac:0:4} ${xor_mac:4:4} ${xor_mac:8:4}"
24
25 xor_fw_chksum=$(hexdump -v -n 2 -s $chksum_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE)
26 xor_fw_chksum=$(xor $xor_fw_chksum $xor_fw_mac $xor_mac)
27
28 printf "%b" "\x${xor_fw_chksum:0:2}\x${xor_fw_chksum:2:2}" | \
29 dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=$chksum_offset count=2
30 }
31
32 board=$(board_name)
33
34 case "$FIRMWARE" in
35 "ath10k/pre-cal-pci-0000:01:00.0.bin")
36 case $board in
37 buffalo,wxr-2533dhp)
38 caldata_extract "ART" 0x1000 0x2f20
39 ath10kcal_patch_mac_crc $(mtd_get_mac_binary ART 0x1e)
40 ;;
41 linksys,ea8500)
42 caldata_extract "art" 0x1000 0x2f20
43 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_ascii devinfo hw_mac_addr) +1)
44 ;;
45 nec,wg2600hp)
46 caldata_extract "ART" 0x1000 0x2f20
47 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_binary PRODUCTDATA 0xc) +1)
48 ;;
49 netgear,d7800 |\
50 netgear,r7500v2 |\
51 netgear,r7800)
52 caldata_extract "art" 0x1000 0x2f20
53 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_binary art 0x6) +1)
54 ;;
55 tplink,c2600)
56 caldata_extract "radio" 0x1000 0x2f20
57 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_binary default-mac 0x8) -1)
58 ;;
59 tplink,vr2600v)
60 caldata_extract "ART" 0x1000 0x2f20
61 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_binary default-mac 0x0) -1)
62 ;;
63 zyxel,nbg6817)
64 caldata_extract "0:ART" 0x1000 0x2f20
65 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_ascii 0:APPSBLENV ethaddr) +1)
66 ;;
67 esac
68 ;;
69 "ath10k/pre-cal-pci-0001:01:00.0.bin")
70 case $board in
71 buffalo,wxr-2533dhp)
72 caldata_extract "ART" 0x5000 0x2f20
73 ath10kcal_patch_mac_crc $(mtd_get_mac_binary ART 0x18)
74 ;;
75 linksys,ea8500)
76 caldata_extract "art" 0x5000 0x2f20
77 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_ascii devinfo hw_mac_addr) +2)
78 ;;
79 nec,wg2600hp)
80 caldata_extract "ART" 0x5000 0x2f20
81 ath10kcal_patch_mac_crc $(mtd_get_mac_binary PRODUCTDATA 0xc)
82 ;;
83 netgear,d7800 |\
84 netgear,r7500v2 |\
85 netgear,r7800)
86 caldata_extract "art" 0x5000 0x2f20
87 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_binary art 0x6) +2)
88 ;;
89 tplink,c2600)
90 caldata_extract "radio" 0x5000 0x2f20
91 ath10kcal_patch_mac_crc $(mtd_get_mac_binary default-mac 0x8)
92 ;;
93 tplink,vr2600v)
94 caldata_extract "ART" 0x5000 0x2f20
95 ath10kcal_patch_mac_crc $(mtd_get_mac_binary default-mac 0x0)
96 ;;
97 zyxel,nbg6817)
98 caldata_extract "0:ART" 0x5000 0x2f20
99 ath10kcal_patch_mac_crc $(mtd_get_mac_ascii 0:APPSBLENV ethaddr)
100 ;;
101 esac
102 ;;
103 *)
104 exit 1
105 ;;
106 esac