mediatek: bpi-r3-mini: persist WiFi and WAN MAC addresses
[openwrt/openwrt.git] / target / linux / mediatek / filogic / base-files / etc / hotplug.d / ieee80211 / 11_fix_wifi_mac
1 [ "$ACTION" == "add" ] || exit 0
2
3 PHYNBR=${DEVPATH##*/phy}
4
5 [ -n $PHYNBR ] || exit 0
6
7 . /lib/functions.sh
8 . /lib/functions/system.sh
9
10 board=$(board_name)
11
12 case "$board" in
13 acer,predator-w6)
14 key_path="/var/qcidata/data"
15 [ "$PHYNBR" = "0" ] && cat $key_path/2gMAC > /sys${DEVPATH}/macaddress
16 [ "$PHYNBR" = "1" ] && cat $key_path/6gMAC > /sys${DEVPATH}/macaddress
17 [ "$PHYNBR" = "2" ] && cat $key_path/5gMAC > /sys${DEVPATH}/macaddress
18 ;;
19 asus,rt-ax59u)
20 CI_UBIPART="UBI_DEV"
21 addr=$(mtd_get_mac_binary_ubi "Factory" 0x4)
22 # Originally, phy1 is phy0 mac with LA and 28th bits set. However, this would conflict
23 # addresses on multiple VIFs with the other radio when bit 28 is already set.
24 # Set LA and 28 bits and increment mac-address instead.
25 [ "$PHYNBR" = "1" ] && \
26 macaddr_setbit_la $(macaddr_setbit $(macaddr_add $addr 1) 28) > \
27 /sys${DEVPATH}/macaddress
28 ;;
29 asus,tuf-ax4200|\
30 asus,tuf-ax6000)
31 CI_UBIPART="UBI_DEV"
32 addr=$(mtd_get_mac_binary_ubi "Factory" 0x4)
33 # Originally, phy0 is phy1 mac with LA bit set. However, this would conflict
34 # addresses on multiple VIFs with the other radio. Set LA bit and increment
35 # mac-address instead.
36 [ "$PHYNBR" = "0" ] && macaddr_setbit_la $(macaddr_add $addr 1) > /sys${DEVPATH}/macaddress
37 [ "$PHYNBR" = "1" ] && echo "$addr" > /sys${DEVPATH}/macaddress
38 ;;
39 bananapi,bpi-r3|\
40 bananapi,bpi-r3-mini)
41 addr=$(cat /sys/class/net/eth0/address)
42 [ "$PHYNBR" = "0" ] && macaddr_add $addr 2 > /sys${DEVPATH}/macaddress
43 [ "$PHYNBR" = "1" ] && macaddr_add $addr 3 > /sys${DEVPATH}/macaddress
44 ;;
45 cetron,ct3003)
46 addr=$(mtd_get_mac_binary "art" 0)
47 [ "$PHYNBR" = "0" ] && macaddr_add $addr 1 > /sys${DEVPATH}/macaddress
48 [ "$PHYNBR" = "1" ] && macaddr_setbit_la $(macaddr_add $addr 2) > /sys${DEVPATH}/macaddress
49 ;;
50 cmcc,rax3000m)
51 case "$(cmdline_get_var root)" in
52 /dev/mmc*)
53 addr=$(mmc_get_mac_binary factory 0xa)
54 ;;
55 *)
56 addr=$(mtd_get_mac_binary factory 0xa)
57 ;;
58 esac
59 [ "$PHYNBR" = "1" ] && echo "$addr" > /sys${DEVPATH}/macaddress
60 ;;
61 comfast,cf-e393ax)
62 addr=$(mtd_get_mac_binary "Factory" 0x8000)
63 [ "$PHYNBR" = "1" ] && macaddr_add $addr 1 > /sys${DEVPATH}/macaddress
64 ;;
65 cudy,re3000-v1)
66 addr=$(mtd_get_mac_binary bdinfo 0xde00)
67 [ "$PHYNBR" = "0" ] && echo "$addr" > /sys${DEVPATH}/macaddress
68 [ "$PHYNBR" = "1" ] && macaddr_setbit_la $(macaddr_add $addr 1) > /sys${DEVPATH}/macaddress
69 ;;
70 cudy,wr3000-v1)
71 addr=$(mtd_get_mac_binary bdinfo 0xde00)
72 # Originally, phy0 is phy1 mac with LA bit set. However, this would conflict
73 # addresses on multiple VIFs with the other radio. Set LA bit and increment
74 # mac-address instead.
75 [ "$PHYNBR" = "0" ] && echo "$addr" > /sys${DEVPATH}/macaddress
76 [ "$PHYNBR" = "1" ] && macaddr_setbit_la $(macaddr_add $addr 1) > /sys${DEVPATH}/macaddress
77 ;;
78 dlink,aquila-pro-ai-m30-a1)
79 addr=$(mtd_get_mac_binary "Odm" 0x81)
80 [ "$PHYNBR" = "1" ] && macaddr_add $addr 3 > /sys${DEVPATH}/macaddress
81 ;;
82 glinet,gl-mt6000|\
83 glinet,gl-x3000|\
84 glinet,gl-xe3000)
85 addr=$(mmc_get_mac_binary factory 0x04)
86 [ "$PHYNBR" = "0" ] && echo "$addr" > /sys${DEVPATH}/macaddress
87 [ "$PHYNBR" = "1" ] && macaddr_add $addr 1 > /sys${DEVPATH}/macaddress
88 ;;
89 h3c,magic-nx30-pro)
90 addr=$(mtd_get_mac_ascii pdt_data_1 ethaddr)
91 [ "$PHYNBR" = "0" ] && macaddr_add $addr 2 > /sys${DEVPATH}/macaddress
92 [ "$PHYNBR" = "1" ] && macaddr_add $addr 3 > /sys${DEVPATH}/macaddress
93 ;;
94 jcg,q30-pro|\
95 netcore,n60)
96 # Originally, phy1 is phy0 mac with LA bit set. However, this would conflict
97 # addresses on multiple VIFs with the other radio. Use label mac to set LA bit.
98 [ "$PHYNBR" = "1" ] && macaddr_setbit_la $(get_mac_label) > /sys${DEVPATH}/macaddress
99 ;;
100 jdcloud,re-cp-03)
101 [ "$PHYNBR" = "1" ] && mmc_get_mac_binary factory 0xa > /sys${DEVPATH}/macaddress
102 ;;
103 mercusys,mr90x-v1)
104 addr=$(get_mac_binary "/tmp/tp_data/default-mac" 0)
105 [ "$PHYNBR" = "0" ] && echo "$addr" > /sys${DEVPATH}/macaddress
106 [ "$PHYNBR" = "1" ] && macaddr_add $addr -1 > /sys${DEVPATH}/macaddress
107 ;;
108 netgear,wax220)
109 hw_mac_addr=$(mtd_get_mac_ascii u-boot-env mac)
110 [ "$PHYNBR" = "0" ] && macaddr_add $hw_mac_addr 2 > /sys${DEVPATH}/macaddress
111 [ "$PHYNBR" = "1" ] && macaddr_add $hw_mac_addr 3 > /sys${DEVPATH}/macaddress
112 ;;
113 openembed,som7981)
114 [ "$PHYNBR" = "1" ] && cat /sys/class/net/eth0/address > /sys${DEVPATH}/macaddress
115 ;;
116 qihoo,360t7)
117 addr=$(mtd_get_mac_ascii factory lanMac)
118 [ "$PHYNBR" = "0" ] && macaddr_add $addr 2 > /sys${DEVPATH}/macaddress
119 [ "$PHYNBR" = "1" ] && macaddr_add $addr 3 > /sys${DEVPATH}/macaddress
120 ;;
121 smartrg,sdg-8612|\
122 smartrg,sdg-8614|\
123 smartrg,sdg-8622|\
124 smartrg,sdg-8632)
125 addr=$(mmc_get_mac_ascii mfginfo MFG_MAC)
126 [ "$PHYNBR" = "0" ] && macaddr_add $addr 2 > /sys${DEVPATH}/macaddress
127 [ "$PHYNBR" = "1" ] && macaddr_add $addr 3 > /sys${DEVPATH}/macaddress
128 [ "$PHYNBR" = "2" ] && macaddr_add $addr 4 > /sys${DEVPATH}/macaddress
129 ;;
130 tplink,tl-xdr4288|\
131 tplink,tl-xdr6086|\
132 tplink,tl-xdr6088)
133 [ "$PHYNBR" = "0" ] && get_mac_label > /sys${DEVPATH}/macaddress
134 ;;
135 ubnt,unifi-6-plus)
136 addr=$(mtd_get_mac_binary EEPROM 0x6)
137 [ "$PHYNBR" = "0" ] && echo "$addr" > /sys${DEVPATH}/macaddress
138 [ "$PHYNBR" = "1" ] && macaddr_add $addr 1 > /sys${DEVPATH}/macaddress
139 ;;
140 routerich,ax3000|\
141 zbtlink,zbt-z8102ax|\
142 zbtlink,zbt-z8103ax|\
143 zyxel,ex5601-t0|\
144 zyxel,ex5601-t0-ubootmod)
145 addr=$(mtd_get_mac_binary "Factory" 0x4)
146 [ "$PHYNBR" = "1" ] && macaddr_add $addr 1 > /sys${DEVPATH}/macaddress
147 ;;
148 zyxel,nwa50ax-pro)
149 hw_mac_addr="$(mtd_get_mac_binary mrd 0x1fff8)"
150 [ "$PHYNBR" = "0" ] && macaddr_add $hw_mac_addr 1 > /sys${DEVPATH}/macaddress
151 [ "$PHYNBR" = "1" ] && macaddr_add $hw_mac_addr 2 > /sys${DEVPATH}/macaddress
152 ;;
153 esac