2
0

02_network 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. #!/bin/sh
  2. . /lib/functions.sh
  3. . /lib/ramips.sh
  4. . /lib/functions/uci-defaults.sh
  5. . /lib/functions/system.sh
  6. ramips_setup_rt3x5x_vlans()
  7. {
  8. if [ ! -x /sbin/swconfig ]; then
  9. # legacy default
  10. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  11. return
  12. fi
  13. local wanports=""
  14. local lanports=""
  15. for port in 5 4 3 2 1 0; do
  16. if [ `swconfig dev rt305x port $port get disable` = "1" ]; then
  17. continue
  18. fi
  19. if [ `swconfig dev rt305x port $port get lan` = "0" ]; then
  20. wanports="$port:wan $wanports"
  21. else
  22. lanports="$port:lan $lanports"
  23. fi
  24. done
  25. ucidef_add_switch "rt305x" $lanports $wanports "6t@eth0"
  26. }
  27. ramips_setup_interfaces()
  28. {
  29. local board="$1"
  30. case $board in
  31. 11acnas|\
  32. w2914nsv2)
  33. ucidef_add_switch "switch0" \
  34. "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4:wan:5" "6@eth0"
  35. ;;
  36. 3g150b|\
  37. 3g300m|\
  38. a5-v11|\
  39. all0256n|\
  40. all5002|\
  41. all5003|\
  42. broadway|\
  43. dcs-930|\
  44. dcs-930l-b1|\
  45. ht-tm02|\
  46. linkits7688 | \
  47. linkits7688d | \
  48. m2m|\
  49. microwrt|\
  50. mpr-a2|\
  51. ncs601w|\
  52. omega2 | \
  53. omega2p | \
  54. timecloud|\
  55. w150m|\
  56. widora-neo|\
  57. wnce2001|\
  58. zbt-cpe102|\
  59. zte-q7)
  60. ucidef_add_switch "switch0"
  61. ucidef_add_switch_attr "switch0" "enable" "false"
  62. ucidef_set_interface_lan "eth0"
  63. ;;
  64. mlw221|\
  65. mr-102n)
  66. ucidef_set_interface_lan "eth0.2"
  67. ;;
  68. 3g-6200n|\
  69. ac1200pro|\
  70. ai-br100|\
  71. d240|\
  72. db-wrt01|\
  73. dir-300-b7|\
  74. dir-320-b1|\
  75. dir-610-a1|\
  76. dir-615-h1|\
  77. firewrt|\
  78. hlk-rm04|\
  79. mac1200rv2|\
  80. miwifi-mini|\
  81. miwifi-nano|\
  82. mt7621|\
  83. mt7628|\
  84. mzk-750dhp|\
  85. mzk-w300nh2|\
  86. nixcore|\
  87. oy-0001|\
  88. pbr-m1|\
  89. psg1208|\
  90. psg1218|\
  91. sap-g3200u3|\
  92. sk-wb8|\
  93. vr500|\
  94. wf-2881|\
  95. witi|\
  96. wl-wn575a3|\
  97. wndr3700v5|\
  98. wt1520|\
  99. y1|\
  100. youku-yk1|\
  101. zbt-ape522ii|\
  102. zbt-we826|\
  103. zbt-wg2626|\
  104. zbt-wg3526|\
  105. zbt-wr8305rt)
  106. ucidef_add_switch "switch0" \
  107. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
  108. ;;
  109. whr-300hp2|\
  110. whr-600d|\
  111. wsr-1166|\
  112. wsr-600)
  113. ucidef_add_switch "switch0" \
  114. "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "4:wan:5" "6@eth0"
  115. ;;
  116. ar670w|\
  117. ar725w|\
  118. rt-n15|\
  119. wl-351)
  120. ucidef_add_switch "switch0" \
  121. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
  122. ;;
  123. asl26555|\
  124. rp-n53)
  125. ucidef_add_switch "switch0" \
  126. "1:lan" "2:lan" "3:lan" "4:lan" "6t@eth0"
  127. ;;
  128. atp-52b|\
  129. awm002-evb|\
  130. awm003-evb|\
  131. c20i|\
  132. dir-645|\
  133. f5d8235-v2|\
  134. gl-mt300a|\
  135. gl-mt300n|\
  136. gl-mt750|\
  137. hg255d|\
  138. jhr-n805r|\
  139. jhr-n825r|\
  140. jhr-n926r|\
  141. mzk-wdpr|\
  142. rb750gr3|\
  143. rt-n14u|\
  144. ubnt-erx|\
  145. ur-326n4g|\
  146. wrtnode|\
  147. wrtnode2p | \
  148. wrtnode2r | \
  149. wt3020|\
  150. zbt-wa05)
  151. ucidef_add_switch "switch0" \
  152. "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
  153. ;;
  154. awapn2403)
  155. ucidef_add_switch "switch0" \
  156. "0:lan" "1:wan" "6@eth0"
  157. ;;
  158. b2c|\
  159. nw718|\
  160. psr-680w|\
  161. sl-r7205|\
  162. ur-336un|\
  163. w502u|\
  164. wr6202)
  165. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  166. ;;
  167. br-6475nd)
  168. ucidef_add_switch "switch0" \
  169. "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
  170. ;;
  171. cf-wr800n|\
  172. ex2700)
  173. ucidef_add_switch "switch0" \
  174. "4:lan" "6t@eth0"
  175. ;;
  176. cy-swr1100)
  177. ucidef_add_switch "switch0" \
  178. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "9@eth0"
  179. ;;
  180. cs-qr10|\
  181. d105|\
  182. dch-m225|\
  183. hpm|\
  184. mzk-ex300np|\
  185. mzk-ex750np|\
  186. na930|\
  187. pbr-d1|\
  188. wli-tx4-ag300n|\
  189. wmr-300|\
  190. wn3000rpv3|\
  191. wrh-300cr)
  192. ucidef_set_interface_lan "eth0"
  193. ;;
  194. c50)
  195. ucidef_add_switch "switch0" \
  196. "1:lan:3" "2:lan:4" "3:lan:1" "4:lan:2" "0:wan" "6@eth0"
  197. ;;
  198. dir-860l-b1)
  199. ucidef_add_switch "switch0" \
  200. "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "0:wan" "6@eth0"
  201. ;;
  202. duzun-dm06)
  203. ucidef_add_switch "switch0" \
  204. "1:lan" "0:wan" "6@eth0"
  205. ;;
  206. e1700|\
  207. mt7620a_mt7530)
  208. ucidef_add_switch "switch1" \
  209. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
  210. ;;
  211. hc5*61|\
  212. y1s)
  213. ucidef_add_switch "switch0" \
  214. "1:lan" "2:lan" "3:lan" "4:lan" "5:lan" "0:wan" "6@eth0"
  215. ;;
  216. kn_rc|\
  217. kn_rf)
  218. ucidef_add_switch "switch0" \
  219. "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "6@eth0"
  220. ;;
  221. kng_rc)
  222. ucidef_add_switch "switch1" \
  223. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "7t@eth0"
  224. ;;
  225. mlwg2|\
  226. wizard8800|\
  227. wl-330n)
  228. ucidef_set_interface_lan "eth0.1"
  229. ;;
  230. mr200)
  231. ucidef_add_switch "switch0" \
  232. "0:lan" "1:lan" "2:lan" "3:lan" "6t@eth0"
  233. ucidef_set_interface_wan "usb0"
  234. ;;
  235. mzk-dp150n|\
  236. vocore)
  237. ucidef_add_switch "switch0" \
  238. "0:lan" "4:lan" "6t@eth0"
  239. ;;
  240. newifi-d1)
  241. ucidef_add_switch "switch0" \
  242. "1:lan:2" "2:lan:1" "4:wan" "6@eth0"
  243. ;;
  244. re6500)
  245. ucidef_add_switch "switch0" \
  246. "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "6@eth0"
  247. ;;
  248. rt-n56u)
  249. ucidef_add_switch "switch0" \
  250. "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "8@eth0"
  251. ;;
  252. tew-691gr|\
  253. tew-692gr|\
  254. wlr-6000)
  255. ucidef_add_switch "switch0" \
  256. "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "0@eth0"
  257. ;;
  258. vocore2)
  259. ucidef_add_switch "switch0" \
  260. "0:lan" "2:lan" "6t@eth0"
  261. ;;
  262. f5d8235-v1|\
  263. tew-714tru|\
  264. v11st-fe|\
  265. wzr-agl300nh)
  266. ucidef_add_switch "switch0" \
  267. "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
  268. ;;
  269. wcr-150gn)
  270. ucidef_add_switch "switch0" \
  271. "0:lan" "6t@eth0"
  272. ;;
  273. whr-1166d)
  274. ucidef_add_switch "switch0" \
  275. "0:lan" "1:lan" "2:lan" "3:lan" "5:wan" "6@eth0"
  276. ;;
  277. wizfi630a)
  278. ucidef_add_switch "switch0" \
  279. "1:lan" "2:lan" "0:wan" "6@eth0"
  280. ;;
  281. *)
  282. RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
  283. if [ -n "${RT3X5X}" ]; then
  284. ramips_setup_rt3x5x_vlans
  285. else
  286. ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
  287. fi
  288. ;;
  289. esac
  290. }
  291. ramips_setup_macs()
  292. {
  293. local board="$1"
  294. local lan_mac=""
  295. local wan_mac=""
  296. case $board in
  297. a5-v11|\
  298. ht-tm02)
  299. lan_mac=$(cat /sys/class/net/eth0/address)
  300. ;;
  301. all0239-3g|\
  302. carambola|\
  303. freestation5|\
  304. w502u|\
  305. wnce2001)
  306. wan_mac=$(mtd_get_mac_binary factory 46)
  307. ;;
  308. bc2|\
  309. broadway|\
  310. d105|\
  311. dir-300-b7|\
  312. dir-320-b1|\
  313. dir-620-a1|\
  314. esr-9753|\
  315. freestation5|\
  316. hlk-rm04|\
  317. mpr-a1|\
  318. psr-680w|\
  319. sl-r7205|\
  320. y1|\
  321. y1s)
  322. lan_mac=$(cat /sys/class/net/eth0/address)
  323. lan_mac=$(macaddr_setbit_la "$lan_mac")
  324. wan_mac=$(macaddr_add "$lan_mac" 1)
  325. ;;
  326. br-6475nd)
  327. lan_mac=$(cat /sys/class/net/eth0/address)
  328. wan_mac=$(mtd_get_mac_binary devdata 7)
  329. ;;
  330. cy-swr1100|\
  331. dch-m225)
  332. lan_mac=$(mtd_get_mac_ascii factory lanmac)
  333. ;;
  334. dir-645)
  335. lan_mac=$(mtd_get_mac_ascii nvram lanmac)
  336. wan_mac=$(mtd_get_mac_ascii nvram wanmac)
  337. ;;
  338. dir-860l-b1)
  339. lan_mac=$(mtd_get_mac_ascii factory lanmac)
  340. wan_mac=$(mtd_get_mac_ascii factory wanmac)
  341. ;;
  342. e1700)
  343. wan_mac=$(mtd_get_mac_ascii config WAN_MAC_ADDR)
  344. ;;
  345. hc5*61)
  346. lan_mac=`mtd_get_mac_ascii bdinfo "Vfac_mac "`
  347. [ -n "$lan_mac" ] || lan_mac=$(cat /sys/class/net/eth0/address)
  348. wan_mac=$(macaddr_add "$lan_mac" 1)
  349. ;;
  350. kn_rc|\
  351. kn_rf|\
  352. kng_rc)
  353. wan_mac=$(mtd_get_mac_binary factory 40)
  354. ;;
  355. linkits7688 | \
  356. linkits7688d)
  357. wan_mac=$(mtd_get_mac_binary factory 4)
  358. lan_mac=$(mtd_get_mac_binary factory 46)
  359. ;;
  360. mac1200rv2)
  361. lan_mac=$(mtd_get_mac_binary factory_info 13)
  362. wan_mac=$(macaddr_add "$lan_mac" 1)
  363. ;;
  364. miwifi-mini)
  365. wan_mac=$(cat /sys/class/net/eth0/address)
  366. lan_mac=$(macaddr_setbit_la "$wan_mac")
  367. ;;
  368. m3|\
  369. m4|\
  370. x5|\
  371. x8)
  372. lan_mac=$(cat /sys/class/net/eth0/address)
  373. lan_mac=$(macaddr_add "$lan_mac" -2)
  374. ;;
  375. newifi-d1)
  376. lan_mac=$(cat /sys/class/net/eth0/address)
  377. lan_mac=$(macaddr_add "$lan_mac" 2)
  378. ;;
  379. omega2|\
  380. omega2p)
  381. wan_mac=$(mtd_get_mac_binary factory 4)
  382. lan_mac=$(mtd_get_mac_binary factory 46)
  383. ;;
  384. oy-0001)
  385. lan_mac=$(mtd_get_mac_binary factory 40)
  386. wan_mac=$(mtd_get_mac_binary factory 46)
  387. ;;
  388. rt-n56u)
  389. lan_mac=$(cat /sys/class/net/eth0/address)
  390. lan_mac=$(macaddr_setbit_la "$lan_mac")
  391. wan_mac=$(mtd_get_mac_binary factory 32772)
  392. ;;
  393. sk-wb8)
  394. wan_mac=$(mtd_get_mac_binary factory 57350)
  395. ;;
  396. tew-691gr)
  397. wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 3)
  398. ;;
  399. tew-692gr)
  400. wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 4)" 1)
  401. ;;
  402. tiny-ac)
  403. lan_mac=$(mtd_get_mac_ascii u-boot-env LAN_MAC_ADDR)
  404. wan_mac=$(mtd_get_mac_ascii u-boot-env WAN_MAC_ADDR)
  405. ;;
  406. vr500)
  407. lan_mac=$(mtd_get_mac_binary factory 57344)
  408. wan_mac=$(mtd_get_mac_binary factory 57350)
  409. ;;
  410. w306r-v20)
  411. lan_mac=$(cat /sys/class/net/eth0/address)
  412. wan_mac=$(macaddr_add "$lan_mac" 5)
  413. ;;
  414. wcr-150gn)
  415. wan_mac=$(mtd_get_mac_binary factory 40)
  416. ;;
  417. whr-1166d|\
  418. whr-300hp2|\
  419. whr-600d|\
  420. wsr-600)
  421. wan_mac=$(mtd_get_mac_binary factory 4)
  422. lan_mac=$wan_mac
  423. ;;
  424. wizfi630a)
  425. lan_mac=$(mtd_get_mac_binary factory 4)
  426. wan_mac=$(mtd_get_mac_binary factory 40)
  427. ;;
  428. wlr-6000)
  429. wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 32772)" 2)
  430. ;;
  431. wsr-1166)
  432. local index="$(find_mtd_index "board_data")"
  433. wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)"
  434. lan_mac=$wan_mac
  435. ;;
  436. *)
  437. lan_mac=$(cat /sys/class/net/eth0/address)
  438. wan_mac=$(macaddr_add "$lan_mac" 1)
  439. ;;
  440. esac
  441. [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
  442. [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
  443. }
  444. board_config_update
  445. board=$(ramips_board_name)
  446. ramips_setup_interfaces $board
  447. ramips_setup_macs $board
  448. board_config_flush
  449. exit 0