2
0

02_network 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. #!/bin/sh
  2. #
  3. # Copyright (C) 2011-2015 OpenWrt.org
  4. #
  5. . /lib/functions/system.sh
  6. . /lib/functions/uci-defaults.sh
  7. . /lib/ar71xx.sh
  8. ar71xx_setup_interfaces()
  9. {
  10. local board="$1"
  11. case "$board" in
  12. airgatewaypro)
  13. ucidef_add_switch "switch0" \
  14. "0@eth0" "4:lan" "5:wan"
  15. ;;
  16. airrouter|\
  17. ap121|\
  18. ap121-mini|\
  19. ap96|\
  20. dir-600-a1|\
  21. dir-615-c1|\
  22. dir-615-e1|\
  23. dir-615-e4|\
  24. hiwifi-hc6361|\
  25. ja76pf|\
  26. mc-mac1200r|\
  27. minibox-v1|\
  28. mynet-n600|\
  29. oolite|\
  30. qihoo-c301|\
  31. rb-750|\
  32. rb-751|\
  33. som9331|\
  34. tew-632brp|\
  35. tew-712br|\
  36. tew-732br|\
  37. tl-mr3220|\
  38. tl-mr3220-v2|\
  39. tl-mr3420|\
  40. tl-wdr3320-v2|\
  41. tl-wdr3500|\
  42. tl-wr741nd-v4|\
  43. tl-wr841n-v11|\
  44. tl-wr841n-v9|\
  45. tl-wr842n-v3|\
  46. whr-g301n|\
  47. whr-hp-g300n|\
  48. whr-hp-gn|\
  49. wzr-hp-ag300h|\
  50. zbt-we1526)
  51. ucidef_set_interfaces_lan_wan "eth0" "eth1"
  52. ucidef_add_switch "switch0" \
  53. "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
  54. ;;
  55. alfa-ap120c|\
  56. all0305|\
  57. antminer-s1|\
  58. antminer-s3|\
  59. antrouter-r1|\
  60. ap121f|\
  61. aw-nr580|\
  62. bullet-m|\
  63. c-55|\
  64. cap4200ag|\
  65. cf-e380ac-v1|\
  66. cf-e380ac-v2|\
  67. eap120|\
  68. eap300v2|\
  69. eap7660d|\
  70. el-mini|\
  71. loco-m-xw|\
  72. mr12|\
  73. mr16|\
  74. mr1750|\
  75. mr1750v2|\
  76. mr18|\
  77. mr600|\
  78. mr600v2|\
  79. mr900|\
  80. mr900v2|\
  81. mynet-rext|\
  82. rb-411|\
  83. rb-411u|\
  84. rb-911g-2hpnd|\
  85. rb-911g-5hpacd|\
  86. rb-911g-5hpnd|\
  87. rb-912uag-2hpnd|\
  88. rb-912uag-5hpnd|\
  89. rb-sxt2n|\
  90. rb-sxt5n|\
  91. re450|\
  92. rocket-m-xw|\
  93. tl-mr10u|\
  94. tl-mr11u|\
  95. tl-mr12u|\
  96. tl-mr13u|\
  97. tl-mr3020|\
  98. tl-mr3040|\
  99. tl-mr3040-v2|\
  100. tl-wa701nd-v2|\
  101. tl-wa7210n-v2|\
  102. tl-wa750re|\
  103. tl-wa801nd-v2|\
  104. tl-wa830re-v2|\
  105. tl-wa850re|\
  106. tl-wa901nd|\
  107. tl-wa901nd-v2|\
  108. tl-wa901nd-v3|\
  109. tl-wa901nd-v4|\
  110. tl-wr703n|\
  111. tl-wr802n-v1|\
  112. tpe-r1100|\
  113. tube2h|\
  114. unifiac-lite|\
  115. wndap360|\
  116. wp543)
  117. ucidef_set_interface_lan "eth0"
  118. ;;
  119. a40|\
  120. a60|\
  121. alfa-ap96|\
  122. alfa-nx|\
  123. dr344|\
  124. gl-ar150|\
  125. gl-ar300m|\
  126. gl-domino|\
  127. gl-inet|\
  128. gl-mifi|\
  129. jwap003|\
  130. om2pv4|\
  131. om2p-hsv4|\
  132. pb42|\
  133. pb44|\
  134. rb-951ui-2hnd|\
  135. routerstation|\
  136. tl-wr710n|\
  137. tl-wr720n-v3|\
  138. tl-wr810n|\
  139. wpe72|\
  140. wrtnode2q)
  141. ucidef_set_interfaces_lan_wan "eth1" "eth0"
  142. ;;
  143. all0258n|\
  144. all0315n|\
  145. dlan-hotspot|\
  146. dlan-pro-500-wp|\
  147. ja76pf2|\
  148. rocket-m-ti|\
  149. ubnt-unifi-outdoor)
  150. ucidef_set_interface_lan "eth0 eth1"
  151. ;;
  152. wzr-hp-g300nh2)
  153. ucidef_add_switch "switch0" \
  154. "0@eth0" "1:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "2:wan"
  155. ;;
  156. ap132|\
  157. ap136|\
  158. ap152|\
  159. rb-750gl|\
  160. rb-751g|\
  161. rb-951g-2hnd|\
  162. wlr8100|\
  163. wzr-hp-g450h)
  164. ucidef_add_switch "switch0" \
  165. "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan"
  166. ;;
  167. ap135-020|\
  168. ap136-020|\
  169. bhr-4grv2|\
  170. tew-823dru|\
  171. tl-wr1043nd-v2|\
  172. wzr-450hp2)
  173. ucidef_set_interfaces_lan_wan "eth1" "eth0"
  174. ucidef_add_switch "switch0" \
  175. "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan" "6@eth0"
  176. ;;
  177. ap136-010|\
  178. ap147-010|\
  179. nbg6616|\
  180. nbg6716)
  181. ucidef_set_interfaces_lan_wan "eth0" "eth1"
  182. ucidef_add_switch "switch0" \
  183. "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "6@eth1"
  184. ;;
  185. ap143|\
  186. rb-433|\
  187. rb-433u)
  188. ucidef_set_interfaces_lan_wan "eth1" "eth0"
  189. ucidef_add_switch "switch0" \
  190. "1:lan" "2:lan" "5@eth1"
  191. ;;
  192. archer-c5|\
  193. archer-c7|\
  194. tl-wdr4900-v2)
  195. ucidef_set_interfaces_lan_wan "eth1" "eth0"
  196. ucidef_add_switch "switch0" \
  197. "0@eth1" "2:lan" "3:lan" "4:lan" "5:lan" "6@eth0" "1:wan"
  198. ;;
  199. arduino-yun|\
  200. dir-505-a1|\
  201. tl-wa801nd-v3)
  202. ucidef_set_interface_lan "eth1"
  203. ;;
  204. bsb)
  205. ucidef_set_interfaces_lan_wan "eth1" "eth0"
  206. ucidef_add_switch "switch0" \
  207. "0@eth1" "1:lan" "3:lan"
  208. ;;
  209. c-60)
  210. ucidef_add_switch "switch0" \
  211. "0@eth0" "3:wan" "4:lan"
  212. ;;
  213. cap324)
  214. ucidef_set_interface_lan "eth0" "dhcp"
  215. ;;
  216. cpe210|\
  217. cpe510|\
  218. wbs210|\
  219. wbs510)
  220. ucidef_add_switch "switch0" \
  221. "0@eth0" "5:lan" "4:wan"
  222. ;;
  223. cr3000)
  224. ucidef_set_interfaces_lan_wan "eth0" "eth1"
  225. ucidef_add_switch "switch0" \
  226. "0@eth0" "1:lan:1" "2:lan:4" "3:lan:3" "4:lan:2"
  227. ;;
  228. cr5000|\
  229. dgl-5500-a1|\
  230. dhp-1565-a1|\
  231. dir-825-c1|\
  232. dir-835-a1|\
  233. esr900|\
  234. mynet-n750|\
  235. sr3200|\
  236. wndr3700v4|\
  237. wndr4300)
  238. ucidef_add_switch "switch0" \
  239. "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
  240. ;;
  241. dap-2695-a1)
  242. ucidef_add_switch "switch0" "0@eth0" "2:lan" "3:wan" "6@eth1"
  243. ;;
  244. rb-941-2nd)
  245. ucidef_add_switch "switch0" \
  246. "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:wan:1"
  247. ;;
  248. db120|\
  249. rb-2011l|\
  250. rb-2011uas|\
  251. rb-2011uas-2hnd|\
  252. rb-2011uias|\
  253. rb-2011uias-2hnd)
  254. case "$board" in
  255. rb-2011uas*|\
  256. rb-2011uias|\
  257. rb-2011uias-2hnd)
  258. ucidef_add_switch "switch0" \
  259. "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan" "6:sfp"
  260. ;;
  261. *)
  262. ucidef_add_switch "switch0" \
  263. "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan"
  264. ;;
  265. esac
  266. ucidef_add_switch "switch1" \
  267. "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan" "5:lan"
  268. ;;
  269. dir-615-i1|\
  270. omy-g1|\
  271. r6100|\
  272. smart-300|\
  273. tl-mr3420-v2|\
  274. tl-wdr6500-v2|\
  275. tl-wr841n-v8|\
  276. tl-wr940n-v4|\
  277. tl-wr941nd-v5|\
  278. tl-wr941nd-v6|\
  279. wnr1000-v2|\
  280. wnr2000-v4|\
  281. wnr2200|\
  282. wnr612-v2|\
  283. wpn824n)
  284. ucidef_set_interfaces_lan_wan "eth1" "eth0"
  285. ucidef_add_switch "switch0" \
  286. "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4@eth1"
  287. ;;
  288. dir-825-b1|\
  289. nbg460n_550n_550nh|\
  290. tew-673gru|\
  291. wzr-hp-g300nh)
  292. ucidef_set_interfaces_lan_wan "eth0" "eth1"
  293. ucidef_add_switch "switch0" \
  294. "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0"
  295. ;;
  296. dlan-pro-1200-ac)
  297. ucidef_set_interface_lan "eth0"
  298. ucidef_add_switch "switch0" \
  299. "0@eth0" "2:lan" "3:lan" "4:lan"
  300. ucidef_add_switch_attr "switch0" "enable" "false"
  301. ;;
  302. el-m150)
  303. ucidef_set_interfaces_lan_wan "eth1" "eth0"
  304. ucidef_add_switch "switch0" \
  305. "0:lan" "1:lan" "3@eth1"
  306. ;;
  307. dir-869-a1|\
  308. epg5000|\
  309. esr1750|\
  310. tl-wr1043nd-v4)
  311. ucidef_add_switch "switch0" \
  312. "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan"
  313. ;;
  314. ew-dorin)
  315. ucidef_add_switch "switch0" \
  316. "0@eth0" "1:lan" "2:lan" "3:wan"
  317. ;;
  318. ew-dorin-router)
  319. ucidef_set_interfaces_lan_wan "eth0" "eth1"
  320. ucidef_add_switch "switch0" \
  321. "0@eth0" "2:lan" "3:lan"
  322. ;;
  323. dw33d|\
  324. f9k1115v2)
  325. ucidef_set_interfaces_lan_wan "eth1" "eth0"
  326. ucidef_add_switch "switch0" \
  327. "2:lan" "3:lan" "4:lan" "5:lan" "6@eth1" "0@eth0" "1:wan"
  328. ;;
  329. gl-ar300|\
  330. wnr2000-v3)
  331. ucidef_set_interfaces_lan_wan "eth1" "eth0"
  332. ucidef_add_switch "switch0" \
  333. "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan"
  334. ;;
  335. jwap230)
  336. ucidef_set_interfaces_lan_wan "eth0" "eth1"
  337. ucidef_add_switch "switch0" \
  338. "0@eth0" "1:lan" "5:wan" "6@eth1"
  339. ;;
  340. nanostation-m-xw)
  341. ucidef_add_switch "switch0" \
  342. "0@eth0" "5:lan" "1:wan"
  343. ;;
  344. onion-omega)
  345. ucidef_set_interface_lan "wlan0"
  346. ;;
  347. rb-435g)
  348. ucidef_set_interfaces_lan_wan "eth1" "eth0"
  349. ucidef_add_switch "switch0" \
  350. "0@eth1" "1:lan" "2:lan"
  351. ;;
  352. rb-450)
  353. ucidef_set_interfaces_lan_wan "eth1" "eth0"
  354. ucidef_add_switch "switch0" \
  355. "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "5@eth1"
  356. ;;
  357. rb-450g)
  358. ucidef_set_interfaces_lan_wan "eth1" "eth0"
  359. ucidef_add_switch "switch0" \
  360. "0@eth1" "1:lan:1" "2:lan:4" "3:lan:3" "4:lan:2"
  361. ;;
  362. routerstation-pro)
  363. ucidef_set_interfaces_lan_wan "eth1" "eth0"
  364. ucidef_add_switch "switch0" \
  365. "0@eth1" "2:lan:3" "3:lan:2" "4:lan:1"
  366. ;;
  367. rb-493g)
  368. ucidef_set_interfaces_lan_wan "eth0 eth1.1" "eth1.2"
  369. ucidef_add_switch "switch0" \
  370. "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan"
  371. ucidef_add_switch "switch1" \
  372. "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
  373. ;;
  374. tellstick-znet-lite)
  375. ucidef_set_interface_wan "eth0"
  376. ucidef_set_interface_raw "wlan" "wlan0" "dhcp"
  377. ;;
  378. tl-wdr4300|\
  379. tl-wr1041n-v2)
  380. ucidef_add_switch "switch0" \
  381. "0@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "1:wan"
  382. ;;
  383. tl-wpa8630)
  384. ucidef_add_switch "switch0" \
  385. "0@eth0" "2:lan:3" "3:lan:2" "4:lan:1" "5:lan:4"
  386. ;;
  387. tl-wr1043nd)
  388. ucidef_add_switch "switch0" \
  389. "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
  390. ;;
  391. tl-wr2543n)
  392. ucidef_add_switch "switch0" \
  393. "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
  394. ;;
  395. tl-wr841n-v1|\
  396. tl-wr941nd)
  397. ucidef_set_interface_raw "eth" "eth0"
  398. ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"
  399. ;;
  400. tl-wr741nd|\
  401. tl-wr841n-v7)
  402. ucidef_set_interfaces_lan_wan "eth0" "eth1"
  403. ucidef_add_switch "switch0" \
  404. "0@eth0" "1:lan:1" "2:lan:2" "3:lan:3" "4:lan:4"
  405. ;;
  406. tl-wr842n-v2)
  407. ucidef_set_interfaces_lan_wan "eth1" "eth0"
  408. ucidef_add_switch "switch0" \
  409. "0@eth1" "1:lan:4" "2:lan:1" "3:lan:2" "4:lan:3"
  410. ;;
  411. uap-pro|\
  412. wpj342)
  413. ucidef_add_switch "switch0" \
  414. "0@eth0" "1:lan" "2:wan"
  415. ;;
  416. unifiac-pro|\
  417. xd3200)
  418. ucidef_add_switch "switch0" \
  419. "0@eth0" "2:lan" "3:wan"
  420. ;;
  421. wndr3700|\
  422. wndr3700v2|\
  423. wndr3800|\
  424. wndr3800ch)
  425. ucidef_set_interfaces_lan_wan "eth0" "eth1"
  426. ucidef_add_switch "switch0" \
  427. "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "5@eth0"
  428. ucidef_add_switch_attr "switch0" "blinkrate" 2
  429. ucidef_add_switch_port_attr "switch0" 1 led 6
  430. ucidef_add_switch_port_attr "switch0" 2 led 9
  431. ucidef_add_switch_port_attr "switch0" 5 led 2
  432. ;;
  433. wpj344)
  434. ucidef_add_switch "switch0" \
  435. "0@eth0" "3:lan" "2:wan"
  436. ;;
  437. wpj558)
  438. ucidef_add_switch "switch0" \
  439. "5:lan" "1:wan" "6@eth0"
  440. ;;
  441. wrt160nl)
  442. ucidef_set_interfaces_lan_wan "eth0" "eth1"
  443. ucidef_add_switch "switch0" \
  444. "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4@eth0"
  445. ;;
  446. wzr-hp-g450h)
  447. ucidef_add_switch "switch0" \
  448. "0@eth0" "2:lan:1 3:lan:2 4:lan:3 5:lan:4" "1:wan"
  449. ;;
  450. z1)
  451. ucidef_set_interfaces_lan_wan "eth0" "eth1"
  452. ucidef_add_switch "switch0" \
  453. "0@eth0" "1:lan:1" "2:lan:2" "3:lan:3" "4:lan:4" "5:wan"
  454. ;;
  455. *)
  456. ucidef_set_interfaces_lan_wan "eth0" "eth1"
  457. ;;
  458. esac
  459. }
  460. ar71xx_setup_macs()
  461. {
  462. local board="$1"
  463. local lan_mac=""
  464. local wan_mac=""
  465. case $board in
  466. dgl-5500-a1|\
  467. dir-825-c1)
  468. wan_mac=$(mtd_get_mac_ascii nvram "wan_mac")
  469. ;;
  470. dhp-1565-a1|\
  471. dir-835-a1|\
  472. wndr3700v4|\
  473. wndr4300)
  474. lan_mac=$(mtd_get_mac_binary caldata 0)
  475. wan_mac=$(mtd_get_mac_binary caldata 6)
  476. ;;
  477. tl-wr1043nd-v4)
  478. lan_mac=$(mtd_get_mac_binary product-info 8)
  479. wan_mac=$(macaddr_add "$lan_mac" 1)
  480. ;;
  481. esr900)
  482. wan_mac=$(mtd_get_mac_ascii u-boot-env "wanaddr")
  483. ;;
  484. dir-869-a1|\
  485. mynet-n750)
  486. wan_mac=$(mtd_get_mac_ascii devdata "wanmac")
  487. ;;
  488. esac
  489. [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
  490. [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
  491. }
  492. board_config_update
  493. board=$(ar71xx_board_name)
  494. ar71xx_setup_interfaces $board
  495. ar71xx_setup_macs $board
  496. board_config_flush
  497. exit 0