#!/bin/sh
tplink_switch_preinit()
{

	local rsa=`cat /tmp/rsa_check/rsa_result `
	if [ "$rsa" == "PASS"  ]; then
		#tx_disable
		echo 465 > /sys/class/gpio/export
		echo out > /sys/class/gpio/gpio465/direction
		echo 0 > /sys/class/gpio/gpio465/value
		#set switch and phy power on
		swconfig dev switch0 set link_status on
	fi

	#sfp restart AN
	mtk-switch reg w 50e8  10
	mtk-switch reg w 5128  14813
	mtk-switch reg w 5020  31120008
	mtk-switch reg w 5008  1a0
	mtk-switch reg w 5000  1340
	mtk-switch reg w 50e8  0
	
	#change led mode
	local led_state=`uci get switch.led_set.enable`
	if [ "$led_state" == "on" ]; then
		mtk-switch phy cl45 w 0 0x1f 0x24 0xc001
		mtk-switch phy cl45 w 0 0x1f 0x25 0x3
		mtk-switch phy cl45 w 0 0x1f 0x26 0xc006
		mtk-switch phy cl45 w 0 0x1f 0x27 0x3c
		mtk-switch phy cl45 w 0 0x1f 0x21 0x800b
		mtk-switch phy cl45 w 0 0x1f 0x22 0x266
		mtk-switch phy cl45 w 0 0x1f 0x23 0x4cc
	fi

	#forward all lldp pkts to CPU only
	swconfig dev switch0 set lldp 1
}