02_network 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. #!/bin/sh
  2. . /lib/functions/system.sh
  3. . /lib/functions/uci-defaults.sh
  4. . /lib/functions/k2t.sh
  5. ath79_setup_interfaces()
  6. {
  7. local board="$1"
  8. case "$board" in
  9. avm,fritz300e|\
  10. ocedo,koala|\
  11. ocedo,raccoon|\
  12. pcs,cap324|\
  13. pisen,wmm003n|\
  14. pqi,air-pen|\
  15. tplink,re450-v2|\
  16. tplink,tl-mr10u|\
  17. tplink,tl-mr3020-v1|\
  18. tplink,tl-mr3040-v2|\
  19. tplink,tl-wa901nd-v2|\
  20. tplink,tl-wr703n|\
  21. ubnt,bullet-m|\
  22. ubnt,bullet-m-xw|\
  23. ubnt,lap-120|\
  24. ubnt,nanostation-ac-loco|\
  25. ubnt,rocket-m|\
  26. ubnt,unifiac-lite|\
  27. ubnt,unifiac-mesh|\
  28. ubnt,unifi|\
  29. wd,mynet-wifi-rangeextender|\
  30. winchannel,wb2000)
  31. ucidef_set_interface_lan "eth0"
  32. ;;
  33. avm,fritz4020|\
  34. tplink,archer-c58-v1|\
  35. tplink,archer-c59-v1)
  36. ucidef_set_interface_wan "eth0"
  37. ucidef_add_switch "switch0" \
  38. "0@eth1" "1:lan:1" "2:lan:4" "3:lan:3" "4:lan:2"
  39. ;;
  40. buffalo,bhr-4grv|\
  41. buffalo,wzr-hp-g450h)
  42. ucidef_add_switch "switch0" \
  43. "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan"
  44. ;;
  45. buffalo,bhr-4grv2)
  46. ucidef_add_switch "switch0" \
  47. "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "6@eth0"
  48. ;;
  49. buffalo,wzr-hp-ag300h)
  50. ucidef_set_interface_wan "eth1"
  51. ucidef_add_switch "switch0" \
  52. "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
  53. ;;
  54. buffalo,wzr-hp-g302h-a1a0)
  55. ucidef_add_switch "switch0" \
  56. "0@eth0" "1:lan:1" "3:lan:4" "4:lan:3" "5:lan:2" "2:wan"
  57. ;;
  58. dlink,dir-825-b1)
  59. ucidef_set_interface_wan "eth1"
  60. ucidef_add_switch "switch0" \
  61. "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0"
  62. ;;
  63. dlink,dir-825-c1|\
  64. dlink,dir-835-a1|\
  65. iodata,etg3-r|\
  66. iodata,wn-ac1167dgr|\
  67. iodata,wn-ac1600dgr2|\
  68. iodata,wn-ag300dgr|\
  69. pcs,cr5000)
  70. ucidef_add_switch "switch0" \
  71. "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
  72. ;;
  73. elecom,wrc-300ghbk2-i)
  74. ucidef_add_switch "switch0" \
  75. "0@eth0" "2:lan:4" "3:lan:3" "4:lan:2" "5:lan:1" "1:wan"
  76. ;;
  77. embeddedwireless,dorin)
  78. ucidef_add_switch "switch0" \
  79. "0@eth0" "1:wan" "2:lan:3" "3:lan:2"
  80. ;;
  81. etactica,eg200)
  82. ucidef_set_interface_lan "eth0" "dhcp"
  83. ;;
  84. glinet,ar150|\
  85. glinet,ar300m|\
  86. glinet,gl-x750)
  87. ucidef_set_interfaces_lan_wan "eth1" "eth0"
  88. ;;
  89. netgear,wndr3700|\
  90. netgear,wndr3700v2|\
  91. netgear,wndr3800)
  92. ucidef_set_interfaces_lan_wan "eth0" "eth1"
  93. ucidef_add_switch "switch0" \
  94. "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "5u@eth0"
  95. ucidef_add_switch_attr "switch0" "blinkrate" 2
  96. ucidef_add_switch_port_attr "switch0" 1 led 6
  97. ucidef_add_switch_port_attr "switch0" 2 led 9
  98. ucidef_add_switch_port_attr "switch0" 5 led 2
  99. ;;
  100. netgear,wnr612-v2|\
  101. on,n150r)
  102. ucidef_set_interface_wan "eth0"
  103. ucidef_add_switch "switch0" \
  104. "0@eth1" "1:lan" "2:lan" "3:lan:3" "4:lan:4"
  105. ;;
  106. pcs,cr3000)
  107. ucidef_add_switch "switch0" \
  108. "0@eth1" "1:lan:1" "2:lan:4" "3:lan:3" "4:lan:2"
  109. ucidef_set_interface_wan "eth0"
  110. ;;
  111. phicomm,k2t)
  112. ucidef_add_switch "switch0" \
  113. "0@eth0" "3:lan:1" "5:lan:2" "4:wan"
  114. ;;
  115. rosinson,wr818)
  116. ucidef_add_switch "switch0" \
  117. "0@eth0" "1:lan" "2:lan" "3:wan"
  118. ;;
  119. tplink,archer-c7-v1|\
  120. tplink,archer-c7-v2|\
  121. tplink,tl-wdr4900-v2)
  122. ucidef_add_switch "switch0" \
  123. "0@eth1" "2:lan" "3:lan" "4:lan" "5:lan" "6@eth0" "1:wan"
  124. ;;
  125. buffalo,whr-g301n|\
  126. tplink,tl-mr3220-v1|\
  127. tplink,tl-mr3420-v1|\
  128. tplink,tl-wr841-v7|\
  129. ubnt,airrouter)
  130. ucidef_set_interface_wan "eth0"
  131. ucidef_add_switch "switch0" \
  132. "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
  133. ;;
  134. tplink,archer-a7-v5|\
  135. tplink,tl-wdr3600|\
  136. tplink,tl-wdr4300)
  137. ucidef_add_switch "switch0" \
  138. "0@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "1:wan"
  139. ;;
  140. tplink,tl-wr1043nd-v1)
  141. ucidef_add_switch "switch0" \
  142. "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
  143. ;;
  144. tplink,tl-wr1043nd-v2|\
  145. tplink,tl-wr1043nd-v3)
  146. ucidef_add_switch "switch0" \
  147. "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan" "6@eth0"
  148. ;;
  149. tplink,tl-wr1043nd-v4)
  150. ucidef_add_switch "switch0" \
  151. "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan"
  152. ;;
  153. tplink,tl-wr2543-v1)
  154. ucidef_add_switch "switch0" \
  155. "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
  156. ;;
  157. tplink,tl-wr740n-v1|\
  158. tplink,tl-wr740n-v3|\
  159. tplink,tl-wr741-v1|\
  160. tplink,tl-wr743nd-v1|\
  161. tplink,tl-wr841-v5|\
  162. tplink,tl-wr941-v4)
  163. ucidef_set_interface_wan "eth0"
  164. ucidef_add_switch "switch0" \
  165. "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan"
  166. ;;
  167. tplink,tl-wr740nd-v4|\
  168. tplink,tl-wr741nd-v4|\
  169. tplink,tl-wr841-v9|\
  170. tplink,tl-wr841-v11)
  171. ucidef_set_interface_wan "eth0"
  172. ucidef_add_switch "switch0" \
  173. "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
  174. ;;
  175. tplink,tl-wr842n-v1|\
  176. tplink,tl-wr842n-v2)
  177. ucidef_set_interface_wan "eth0"
  178. ucidef_add_switch "switch0" \
  179. "0@eth1" "1:lan:4" "2:lan:1" "3:lan:2" "4:lan:3"
  180. ;;
  181. tplink,tl-wr941-v2)
  182. ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"
  183. ;;
  184. ubnt,routerstation)
  185. ucidef_set_interfaces_lan_wan "eth1" "eth0"
  186. ;;
  187. ubnt,routerstation-pro)
  188. ucidef_set_interface_wan "eth0"
  189. ucidef_add_switch "switch0" \
  190. "0@eth1" "2:lan:3" "3:lan:2" "4:lan:1"
  191. ;;
  192. ubnt,nanostation-ac|\
  193. ubnt,unifiac-mesh-pro|\
  194. ubnt,unifiac-pro)
  195. ucidef_add_switch "switch0" \
  196. "0@eth0" "2:lan" "3:wan"
  197. ;;
  198. *)
  199. ucidef_set_interfaces_lan_wan "eth0" "eth1"
  200. ;;
  201. esac
  202. }
  203. ath79_setup_macs()
  204. {
  205. local board="$1"
  206. case "$board" in
  207. avm,fritz300e)
  208. lan_mac=$(fritz_tffs -n maca -i $(find_mtd_part "tffs (1)"))
  209. ;;
  210. avm,fritz4020)
  211. lan_mac=$(fritz_tffs -n maca -i $(find_mtd_part "tffs (1)"))
  212. wan_mac=$(fritz_tffs -n macb -i $(find_mtd_part "tffs (1)"))
  213. ;;
  214. dlink,dir-825-b1)
  215. lan_mac=$(mtd_get_mac_text "caldata" 65440)
  216. wan_mac=$(mtd_get_mac_text "caldata" 65460)
  217. ;;
  218. dlink,dir-825-c1|\
  219. dlink,dir-835-a1)
  220. lan_mac=$(mtd_get_mac_text "mac" 4)
  221. wan_mac=$(mtd_get_mac_text "mac" 24)
  222. ;;
  223. elecom,wrc-300ghbk2-i)
  224. wan_mac=$(macaddr_add "$(mtd_get_mac_binary ART 4098)" -2)
  225. ;;
  226. iodata,etg3-r)
  227. lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
  228. wan_mac=$(macaddr_add "$lan_mac" -1)
  229. ;;
  230. iodata,wn-ac1167dgr|\
  231. iodata,wn-ac1600dgr2|\
  232. iodata,wn-ag300dgr)
  233. lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
  234. wan_mac=$(mtd_get_mac_ascii u-boot-env wanaddr)
  235. ;;
  236. netgear,wndr3700|\
  237. netgear,wndr3700v2|\
  238. netgear,wndr3800)
  239. lan_mac=$(macaddr_setbit_la "$(mtd_get_mac_binary art 0)")
  240. ;;
  241. phicomm,k2t)
  242. lan_mac=$(k2t_get_mac "lan_mac")
  243. wan_mac=$(k2t_get_mac "wan_mac")
  244. ;;
  245. rosinson,wr818)
  246. wan_mac=$(mtd_get_mac_binary factory 0)
  247. lan_mac=$(macaddr_setbit_la "$wan_mac")
  248. ;;
  249. tplink,tl-wr1043nd-v4)
  250. base_mac=$(mtd_get_mac_binary product-info 8)
  251. wan_mac=$(macaddr_add "$base_mac" 1)
  252. ;;
  253. tplink,tl-wr941-v2)
  254. base_mac=$(mtd_get_mac_binary u-boot 130048)
  255. wan_mac=$(macaddr_add "$base_mac" 1)
  256. ;;
  257. ubnt,routerstation|\
  258. ubnt,routerstation-pro)
  259. wan_mac=$(fconfig -s -r -d $(find_mtd_part "RedBoot config") -n ar7100_esa)
  260. lan_mac=$(macaddr_add "$wan_mac" 1)
  261. ;;
  262. wd,mynet-wifi-rangeextender)
  263. lan_mac=$(nvram get et0macaddr)
  264. ;;
  265. esac
  266. [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
  267. [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
  268. }
  269. board_config_update
  270. board=$(board_name)
  271. ath79_setup_interfaces $board
  272. ath79_setup_macs $board
  273. board_config_flush
  274. exit 0