878f6443abd7f7954df61e54f016f02cdf7461fc
[openwrt/openwrt.git] / target / linux / ath79 / 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 . /lib/functions/k2t.sh
7
8 ath10kcal_patch_mac() {
9 local mac=$1
10
11 [ -z "$mac" ] && return
12
13 macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc oflag=seek_bytes bs=6 seek=6 count=1
14 }
15
16 ath10kcal_patch_mac_crc() {
17 local mac=$1
18 local mac_offset=6
19 local chksum_offset=2
20 local xor_mac
21 local xor_fw_mac
22 local xor_fw_chksum
23
24 xor_fw_mac=$(hexdump -v -n 6 -s $mac_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE)
25 xor_fw_mac="${xor_fw_mac:0:4} ${xor_fw_mac:4:4} ${xor_fw_mac:8:4}"
26
27 ath10kcal_patch_mac "$mac" && {
28 xor_mac=${mac//:/}
29 xor_mac="${xor_mac:0:4} ${xor_mac:4:4} ${xor_mac:8:4}"
30
31 xor_fw_chksum=$(hexdump -v -n 2 -s $chksum_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE)
32 xor_fw_chksum=$(xor $xor_fw_chksum $xor_fw_mac $xor_mac)
33
34 printf "%b" "\x${xor_fw_chksum:0:2}\x${xor_fw_chksum:2:2}" | \
35 dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=$chksum_offset count=2
36 }
37 }
38
39 board=$(board_name)
40
41 case "$FIRMWARE" in
42 "ath10k/cal-pci-0000:00:00.0.bin")
43 case $board in
44 comfast,cf-wr650ac-v1|\
45 comfast,cf-wr650ac-v2|\
46 yuncore,a770)
47 caldata_extract "art" 0x5000 0x844
48 ;;
49 devolo,dvl1200e|\
50 devolo,dvl1200i|\
51 devolo,dvl1750c|\
52 devolo,dvl1750e|\
53 devolo,dvl1750i|\
54 devolo,dvl1750x)
55 caldata_extract "art" 0x5000 0x844
56 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_binary art 0x0) -1)
57 ;;
58 dlink,dir-859-a1)
59 caldata_extract "art" 0x5000 0x844
60 ath10kcal_patch_mac $(mtd_get_mac_ascii devdata "wlan5mac")
61 ;;
62 elecom,wrc-1750ghbk2-i)
63 caldata_extract "art" 0x5000 0x844
64 ;;
65 engenius,ecb1750)
66 caldata_extract "art" 0x5000 0x844
67 ath10kcal_patch_mac $(mtd_get_mac_ascii u-boot-env athaddr)
68 ;;
69 engenius,epg5000|\
70 iodata,wn-ac1167dgr|\
71 iodata,wn-ac1600dgr2)
72 caldata_extract "art" 0x5000 0x844
73 ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_ascii u-boot-env ethaddr) +1)
74 ;;
75 engenius,ews511ap)
76 caldata_extract "art" 0x5000 0x844
77 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +1)
78 ;;
79 glinet,gl-ar750|\
80 glinet,gl-ar750s)
81 caldata_extract "art" 0x5000 0x844
82 ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary art 0x0) +1)
83 ;;
84 glinet,gl-x750)
85 caldata_extract "art" 0x5000 0x844
86 ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary art 0x0) +2)
87 ;;
88 nec,wg800hp)
89 caldata_extract "art" 0x5000 0x844
90 ath10kcal_patch_mac_crc $(mtd_get_mac_text board_data 0x880)
91 ;;
92 ocedo,koala|\
93 ocedo,ursus)
94 caldata_extract "art" 0x5000 0x844
95 ath10kcal_patch_mac $(mtd_get_mac_binary art 0xc)
96 ;;
97 openmesh,om5p-ac-v2)
98 caldata_extract "art" 0x5000 0x844
99 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +16)
100 ;;
101 qihoo,c301)
102 caldata_extract "radiocfg" 0x5000 0x844
103 ath10kcal_patch_mac_crc $(mtd_get_mac_ascii devdata wlan5mac)
104 ;;
105 tplink,archer-a7-v5|\
106 tplink,archer-c2-v3|\
107 tplink,archer-c7-v4|\
108 tplink,archer-c7-v5|\
109 tplink,archer-c25-v1)
110 caldata_extract "art" 0x5000 0x844
111 ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary info 0x8) -1)
112 ;;
113 tplink,archer-c5-v1|\
114 tplink,archer-c7-v2)
115 caldata_extract "art" 0x5000 0x844
116 ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary u-boot 0x1fc00) -1)
117 ;;
118 tplink,archer-d50-v1)
119 caldata_extract "art" 0x5000 0x844
120 ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary romfile 0xf100) +2)
121 ;;
122 tplink,re350k-v1)
123 caldata_extract "art" 0x5000 0x844
124 ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary config 0x10008) +2)
125 ;;
126 tplink,re355-v1|\
127 tplink,re450-v1)
128 caldata_extract "art" 0x5000 0x844
129 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) -2)
130 ;;
131 tplink,re450-v2)
132 caldata_extract "art" 0x5000 0x844
133 ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary info 0x8) +1)
134 ;;
135 ubnt,unifiac-lite|\
136 ubnt,unifiac-mesh|\
137 ubnt,unifiac-mesh-pro|\
138 ubnt,lap-120|\
139 ubnt,nanobeam-ac|\
140 ubnt,nanostation-ac|\
141 ubnt,nanostation-ac-loco|\
142 ubnt,unifiac-pro)
143 caldata_extract "EEPROM" 0x5000 0x844
144 ;;
145 esac
146 ;;
147 "ath10k/pre-cal-pci-0000:00:00.0.bin")
148 case $board in
149 comfast,cf-e313ac)
150 caldata_extract "art" 0x5000 0x2f20
151 ath10kcal_patch_mac_crc $(mtd_get_mac_binary art 0x6)
152 ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \
153 /lib/firmware/ath10k/QCA9888/hw2.0/board.bin
154 rm /lib/firmware/ath10k/QCA9888/hw2.0/board-2.bin
155 ;;
156 dlink,dir-842-c1|\
157 dlink,dir-842-c2|\
158 dlink,dir-842-c3|\
159 nec,wg1200cr)
160 caldata_extract "art" 0x5000 0x2f20
161 ath10kcal_patch_mac_crc $(mtd_get_mac_ascii devdata wlan5mac)
162 ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \
163 /lib/firmware/ath10k/QCA9888/hw2.0/board.bin
164 ;;
165 netgear,ex6400|\
166 netgear,ex7300)
167 caldata_extract "caldata" 0x5000 0x2f20
168 ath10kcal_patch_mac $(mtd_get_mac_binary caldata 0xc)
169 ;;
170 phicomm,k2t)
171 caldata_extract "art" 0x5000 0x2f20
172 ath10kcal_patch_mac_crc $(k2t_get_mac "5g_mac")
173 ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \
174 /lib/firmware/ath10k/QCA9888/hw2.0/board.bin
175 ;;
176 tplink,archer-c58-v1|\
177 tplink,archer-c59-v1|\
178 tplink,archer-c59-v2|\
179 tplink,archer-c60-v1|\
180 tplink,archer-c60-v2|\
181 tplink,archer-c6-v2)
182 caldata_extract "art" 0x5000 0x2f20
183 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_binary mac 0x8) -1)
184 ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \
185 /lib/firmware/ath10k/QCA9888/hw2.0/board.bin
186 ;;
187 esac
188 ;;
189 *)
190 exit 1
191 ;;
192 esac