Ejemplo n.º 1
0
void mainboard_romstage_entry(struct romstage_params *rp)
{
	struct pei_data pei_data;

	post_code(0x31);

	if (rp->power_state->prev_sleep_state != SLEEP_STATE_S3)
		google_chromeec_kbbacklight(100);

	printk(BIOS_INFO, "MLB: board version %s\n", samus_board_version());

	/* Ensure the EC and PD are in the right mode for recovery */
	google_chromeec_early_init();

	/* Initialize GPIOs */
	init_gpios(mainboard_gpio_config);

	/* Fill out PEI DATA */
	memset(&pei_data, 0, sizeof(pei_data));
	mainboard_fill_pei_data(&pei_data);
	mainboard_fill_spd_data(&pei_data);
	rp->pei_data = &pei_data;

	/* Initalize memory */
	romstage_common(rp);

	/* Bring SSD out of reset */
	set_gpio(SAMUS_GPIO_SSD_RESET_L, GPIO_OUT_HIGH);

	/*
	 * Enable PP3300_AUTOBAHN_EN after initial GPIO setup
	 * to prevent possible brownout.
	 */
	set_gpio(SAMUS_GPIO_PP3300_AUTOBAHN_EN, GPIO_OUT_HIGH);
}
Ejemplo n.º 2
0
int main()
{
	set_gpio(MGCARD_PORT,MGCARD_PORT_NUM,HIGH);				//mifate进入工作模式

	open_driver(MGCARD,O_RDONLY);						//打开磁条卡设备

	gettimeofday(&begintime, NULL);						//读取系统时间      

	while(1)
	{
		gettimeofday(&endtime, NULL );					//读取系统时间 

		if(read(Drivers[MGCARD].fd,buf,2112)!=-1)			//读取磁条卡信息
		{
			/*
			printf("\n");
			for(i = 753; i < 1035; i++){
				if(i%30 == 0)printf("\n");
				printf("%x   ",buf[i]);
			}
			*/
			covert_data(buf);					//转换磁条卡数据
			set_gpio(MGCARD_PORT,MGCARD_PORT_NUM,LOW);		//mifare进入低功耗模式
			return 0;
		}

		if((endtime.tv_sec-begintime.tv_sec) > 10)
		{
			printf("\n\nCharge overtime!\n\n");
			close(Drivers[MGCARD].fd);
			set_gpio(MGCARD_PORT,MGCARD_PORT_NUM,LOW);		//mifare进入低功耗模式
			return;
		}
	}
}
Ejemplo n.º 3
0
int gpio_main(int argc, char **argv)
{

	unsigned int gpio;
	unsigned int old_gpio = -1;
	unsigned int pin;

	if (argc != 3) {
		fprintf(stderr, "%s <poll | enable | disable> <pin>\n",
			argv[0]);
		exit(1);
	}

	pin = atoi(argv[2]);
	if (!strcmp(argv[1], "poll")) {
		while (1) {
			gpio = get_gpio(pin);
			if (gpio != old_gpio)
				fprintf(stdout, "%02X\n", gpio);
			old_gpio = gpio;
		}
	} else if (!strcmp(argv[1], "init")) {
		gpio = get_gpio(pin);
	} else if (!strcmp(argv[1], "enable")) {
		gpio = 1;
		set_gpio(pin, gpio);
	} else if (!strcmp(argv[1], "disable")) {
		gpio = 0;
		set_gpio(pin, gpio);
	}

	return 0;
}
Ejemplo n.º 4
0
static int enable_backlight(void)
{
	set_gpio(BOARD_LCD_POWER, 1);
	set_gpio(BOARD_BACK_LIGHT, 1);
	set_gpio(BOARD_TOUCH_POWER, 1);
	return 0;
}
Ejemplo n.º 5
0
static inline char spi_tx_rx( spi_connection_t *sc, char tx )
{
    /* wait for TX FIFO Level to become 0 */
    while( (get_ssp2( sc, SSSR_2 ) & TFL) )
        ;

    /* wait for TX FIFO not to be full */
    while( !(get_ssp2( sc, SSSR_2 ) & TNF) )
        ;

    /* turn on Chip Select */
    set_gpio( sc, GPCR2, get_gpio( sc, GPCR2 ) | PS11 );

    /* write TX to data register */
    set_ssp2( sc, SSDR_2, tx );

    /* turn off Chip Select */
    set_gpio( sc, GPSR2, get_gpio( sc, GPSR2 ) | PS11 );

    /* wait for TX FIFO not to be full */
    while( !(get_ssp2( sc, SSSR_2 ) & TNF) )
        ;

    /* wait for SSP2 port to become idle or RX FIFO not to be empty */
    while( (get_ssp2( sc, SSSR_2 ) & BSY) || !(get_ssp2( sc, SSSR_2 ) & RNE) )
        ;

    /* read RX from data register */
    return( (char) get_ssp2( sc, SSDR_2 ) );
}
Ejemplo n.º 6
0
int set_pwr_usb(int boolOn){
	int use_gpio, gpio_pin;

	switch(get_model()) {
		case MODEL_RTAC68U:
			if ((nvram_get_int("HW_ver") != 170) &&
			    (nvram_get_double("HW_ver") != 1.10) &&
			    (nvram_get_double("HW_ver") != 1.85) &&
			    (nvram_get_double("HW_ver") != 1.90) &&
			    (nvram_get_double("HW_ver") != 1.95) &&
			    (nvram_get_double("HW_ver") != 2.10) &&
			    (nvram_get_double("HW_ver") != 2.20))
				return 0;
			break;
	}

	if((gpio_pin = (use_gpio = nvram_get_int("pwr_usb_gpio"))&0xff) != 0xff){
		if(boolOn)
			set_gpio(gpio_pin, 1);
		else
			set_gpio(gpio_pin, 0);
	}

	if((gpio_pin = (use_gpio = nvram_get_int("pwr_usb_gpio2"))&0xff) != 0xff){
		if(boolOn)
			set_gpio(gpio_pin, 1);
		else
			set_gpio(gpio_pin, 0);
	}

	return 0;
}
Ejemplo n.º 7
0
void picker_setup(void){
    /*Picket between 2000, and 6600
     Arm between 1500 and 4000
     Arm Picks between 2800 and 3200
     */
    set_gpio(GPIOA,GPIO_Pin_4,MODE_ALT_FUNCTION); //Step Pulse (Mode 3 for pwm)
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_10);//Connect Pin to Timer
    set_gpio(GPIOA,GPIO_Pin_5,MODE_ALT_FUNCTION); //Step Pulse (Mode 3 for pwm)
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_10);//Connect Pin to Timer
    set_pwm_servo(60000,30000,30);
}
Ejemplo n.º 8
0
static void mainboard_disable_gpios(void)
{
#if IS_ENABLED(CONFIG_BOARD_GOOGLE_SAMUS)
	/* Put SSD in reset to prevent leak */
	set_gpio(BOARD_SSD_RESET_GPIO, 0);
	/* Disable LTE */
	set_gpio(BOARD_LTE_DISABLE_GPIO, 0);
#else
	set_gpio(BOARD_PP3300_CODEC_GPIO, 0);
#endif
	/* Prevent leak from standby rail to WLAN rail */
	set_gpio(BOARD_WLAN_DISABLE_GPIO, 0);
}
static void MACH_STM32F3_gpio_set(gpio_controller_t *gpio, uint8_t pin, uint8_t val)
{
	if(gpio->mode == ACTIVE_LOW)
	{
		if(val == GPIO_COMMON_HIGH)
			set_gpio(pin, GPIO_COMMON_LOW);
		else
			set_gpio(pin, GPIO_COMMON_HIGH);
	}
	else
	{
		set_gpio(pin, val);
	}
}
Ejemplo n.º 10
0
void stop_openvpnserver(void)
{
#if defined(HAVE_TMK) || defined(HAVE_BKM)
	char *gpiovpn = nvram_get("gpiovpn");
	if (gpiovpn != NULL) {
		set_gpio(atoi(gpiovpn), 0);
	}
#endif
	if (stop_process("openvpnserver", "OpenVPN daemon (Server)")) {
		eval("stopservice", "wshaper");
		eval("startservice", "wshaper");
		//remove ebtables rules on shutdown     
		system("/usr/sbin/ebtables -t nat -D POSTROUTING -o tap2 --pkttype-type multicast -j DROP");
		system("/usr/sbin/ebtables -t nat -D POSTROUTING -o tap2 -p ipv4 --ip-proto udp --ip-sport 67:68 --ip-dport 67:68 -j DROP");
		system("/usr/sbin/ebtables -t nat -D PREROUTING -i tap2 -p ipv4 --ip-proto udp --ip-sport 67:68 --ip-dport 67:68 -j DROP");
        unlink("/tmp/openvpn/ccd/DEFAULT");
		unlink("/tmp/openvpn/dh.pem");
		unlink("/tmp/openvpn/ca.crt");
		unlink("/tmp/openvpn/cert.pem");
		unlink("/tmp/openvpn/ca.crl");
		unlink("/tmp/openvpn/key.pem");
		unlink("/tmp/openvpn/ta.key");
		unlink("/tmp/openvpn/cert.p12");
		unlink("/tmp/openvpn/static.key");
		unlink("/tmp/openvpn/openvpn.conf");
		unlink("/tmp/openvpn/route-up.sh");
		unlink("/tmp/openvpn/route-down.sh");
	}

	return;
}
Ejemplo n.º 11
0
int dht11_read(int gpio, int* temp, int* rh) {
  unsigned int cs, expected_cs;
  int max_cycles = 100000, thresh;
  /* Get DHT11's attention. */
  set_gpio(gpio, 0);
  os_delay_us(20 * 1000);
  /* Switch GPIO pin to input and let it stabilize. */
  read_gpio_pin(gpio);
  os_delay_us(1);
  /* Starting with high, wait for first 80us of L. */
  await_change(gpio, &max_cycles);
  thresh = await_change(gpio, &max_cycles); /* First 80 us low. */
  /* Then 80us of H. */
  thresh += await_change(gpio, &max_cycles); /* Then 80 us high. */
  if (max_cycles <= 0) return 0;
  /* We use this to calibrate our delay: take average of the two
   * and further divide by half to get number of cycles that represent 40us. */
  thresh /= 4;
  /* Now read the data. */
  cs = (*rh = dht11_read_bits(gpio, 8, thresh, &max_cycles));
  cs += dht11_read_bits(gpio, 8, thresh, &max_cycles); /* Always 0. */
  cs += (*temp = dht11_read_bits(gpio, 8, thresh, &max_cycles));
  cs += dht11_read_bits(gpio, 8, thresh, &max_cycles); /* Always 0. */
  expected_cs = dht11_read_bits(gpio, 8, thresh, &max_cycles);
  /* printf("%d %d %d==%d %d %d\r\n", *temp, *rh, cs, expected_cs, thresh,
   * max_cycles); */
  return (max_cycles > 0 && cs == expected_cs);
}
Ejemplo n.º 12
0
int do_led_control(int which, int mode)
#endif
{
	int use_gpio, gpio_nr;
	int v = (mode == LED_OFF)? 0:1;

	// Did the user disable the leds?
	if ((mode == LED_ON) && (nvram_get_int("led_disable") == 1) && (which != LED_TURBO)
#ifdef RTCONFIG_QTN
		&& (which != BTN_QTN_RESET)
#endif
	)
	{
		return 0;
	}

	if (which < 0 || which >= LED_ID_MAX || mode < 0 || mode >= LED_FAN_MODE_MAX)
		return -1;

	get_gpio_values_once(0);
	use_gpio = led_gpio_table[which];
	gpio_nr = use_gpio & 0xFF;

#if defined(RTCONFIG_ETRON_XHCI_USB3_LED)
	if (which == LED_USB3 && nvram_match("led_usb3_gpio", "etron")) {
		char *onoff = "2";	/* LED OFF */

		if (mode == LED_ON || mode == FAN_ON || mode == HAVE_FAN_ON)
			onoff = "3";	/* LED ON */

		f_write_string("/sys/bus/pci/drivers/xhci_hcd/port_led", onoff, 0, 0);
		return 0;
	}
#endif

#if defined(RTAC56U) || defined(RTAC56S)
	if (which == LED_5G && nvram_match("5g_fail", "1"))
		return -1;
#endif

	if (use_gpio < 0 || gpio_nr == 0xFF)
		return -1;

	if (use_gpio & GPIO_ACTIVE_LOW)
		v ^= 1;

	if (mode == LED_OFF) {
		stop_bled(use_gpio);
	}

	set_gpio(gpio_nr, v);

	if (mode == LED_ON) {
		start_bled(use_gpio);
	}

	return 0;
}
Ejemplo n.º 13
0
void mainboard_smi_sleep(u8 slp_typ)
{
	/* Disable USB charging if required */
	switch (slp_typ) {
	case ACPI_S3:
		if (smm_get_gnvs()->s3u0 == 0)
			google_chromeec_set_usb_charge_mode(
				0, USB_CHARGE_MODE_DISABLED);
		if (smm_get_gnvs()->s3u1 == 0)
			google_chromeec_set_usb_charge_mode(
				1, USB_CHARGE_MODE_DISABLED);

		/* Prevent leak from standby rail to WLAN rail in S3. */
		set_gpio(GPIO_WLAN_DISABLE_L, 0);
		/* Disable LTE */
		set_gpio(GPIO_LTE_DISABLE_L, 0);

		/* Enable wake events */
		google_chromeec_set_wake_mask(MAINBOARD_EC_S3_WAKE_EVENTS);
		break;
	case ACPI_S5:
		if (smm_get_gnvs()->s5u0 == 0)
			google_chromeec_set_usb_charge_mode(
				0, USB_CHARGE_MODE_DISABLED);
		if (smm_get_gnvs()->s5u1 == 0)
			google_chromeec_set_usb_charge_mode(
				1, USB_CHARGE_MODE_DISABLED);

		/* Prevent leak from standby rail to WLAN rail in S5. */
		set_gpio(GPIO_WLAN_DISABLE_L, 0);
		/* Disable LTE */
		set_gpio(GPIO_LTE_DISABLE_L, 0);

		/* Enable wake events */
		google_chromeec_set_wake_mask(MAINBOARD_EC_S5_WAKE_EVENTS);
		break;
	}

	/* Disable SCI and SMI events */
	google_chromeec_set_smi_mask(0);
	google_chromeec_set_sci_mask(0);

	/* Clear pending events that may trigger immediate wake */
	while (google_chromeec_get_event() != 0);
}
Ejemplo n.º 14
0
static int enable_lcd(void)
{
	unsigned char buf[1];

	set_gpio(BOARD_LCD_RESET, 0);
	mdelay(1);
	set_gpio(BOARD_LCD_RESET, 1);
	mdelay(1);

	/* spi lcd init */
	kwh043st20_f01_spi_startup(1, 0, 5000000, SPI_MODE_0);

	/* backlight on */
	buf[0] = 0xf;
	i2c_write(0x24, 0x7, 1, buf, 1);
	buf[0] = 0x3f;
	i2c_write(0x24, 0x8, 1, buf, 1);
	return 0;
}
Ejemplo n.º 15
0
void set_io_out(u8* cmdbuf)
{
	CONFIG_SENSOR config_io_out;
	u8 i=0,j=0;
	
	config_io_out.type = SENSOR_TYPE_IO_OUT;
	config_io_out.num = cmdbuf[4];

	if (config_io_out.num == 0 && config_io_out.num > IO_OUT_NUM){
		return;
	}	

	for (i = 0, j = 0; j < config_io_out.num; j++,i += 3){
		config_io_out.seq_num[j] = cmdbuf[5+i];
		config_io_out.attr[j] = cmdbuf[6+i];

		switch(config_io_out.seq_num[j]){
			case 1:
				set_gpio(OUTPUT_1, GD_OUT,cmdbuf[7+i]);
				break;
			case 2:
				set_gpio(OUTPUT_2, GD_OUT,cmdbuf[7+i]);
				break;
			case 3:
				set_gpio(OUTPUT_3, GD_OUT,cmdbuf[7+i]);
				break;
			case 4:
				set_gpio(OUTPUT_4, GD_OUT,cmdbuf[7+i]);
				break;
			
			default:
				break;
		}
		
	}
		
	memcpy(&g_conf_info.con_sensor[SENSOR_TYPE_IO_OUT], &config_io_out, sizeof(CONFIG_SENSOR));

	config_save(&g_conf_info);

	
}
Ejemplo n.º 16
0
/* FUNCTION *******************************************************************
* Get the MCH/MCMC backplane IPMB address as 8 bit I2C address
*
*******************************************************************************/
unsigned char ipmb_get_addr(void)
{
    unsigned char ftest, stest;
    unsigned char addr = 0;

    /* Set Pin to 0 and save the Pin-State of the Address Pins */
    set_gpio(IPMB_ADR_GA_SEL_PORT, IPMB_ADR_GA_SEL_PIN);

    ftest = (((chk_gpio(IPMB_ADR_GA2_PORT, IPMB_ADR_GA2_PIN)<<2) |
              (chk_gpio(IPMB_ADR_GA1_PORT, IPMB_ADR_GA1_PIN)<<1) |
              (chk_gpio(IPMB_ADR_GA0_PORT, IPMB_ADR_GA0_PIN)<<0)) & 0x7);

    /* Set Pin to 1 and save the Pin-State of the Address Pins again */
    clr_gpio(IPMB_ADR_GA_SEL_PORT, IPMB_ADR_GA_SEL_PIN);

    stest = (((chk_gpio(IPMB_ADR_GA2_PORT, IPMB_ADR_GA2_PIN)<<2) |
              (chk_gpio(IPMB_ADR_GA1_PORT, IPMB_ADR_GA1_PIN)<<1) |
              (chk_gpio(IPMB_ADR_GA0_PORT, IPMB_ADR_GA0_PIN)<<0)) & 0x7);

    /* Check which Pins are unconnected and have changed the state while testing */
    if((ftest == 0x0) && (stest == 0x7))
    {
        addr = (unsigned char)(IPMB_ADDR_OFFSET);    /* MCH1 10h */
    }
    else if((ftest == 0x7) && (stest == 0x7))
    {
        addr = (unsigned char)(IPMB_ADDR_OFFSET + 0x02);    /* MCH2 12h */
    }
    else
    {
        /* If nothing matches take undefined IPMB address */
        addr = (unsigned char)(0x00);

    }

    set_gpio(IPMB_ADR_GA_SEL_PORT, IPMB_ADR_GA_SEL_PIN);

    return (addr & 0xFE);

}
Ejemplo n.º 17
0
static void set_fan_speed(int8_t speed)
{
    static int8_t last_speed=-1;

    if (speed == last_speed)
        return;

    printf("Setting fan speed to %d\n", speed);
    set_gpio(23, 1);
    set_gpio(15, 1);
    set_gpio(18, 1);
    switch (speed)
    {
        case 1:
            /* slowest */
            set_gpio(18, 0);
            break;
        case 2:
            set_gpio(23, 0);
            break;
        case 3:
            /* fastest */
            set_gpio(15, 0);
            break;
    }
    last_speed = speed;
}
Ejemplo n.º 18
0
bool init_fan_pins()
{
    printf("starting...\n");
    init_gpio(23);
    set_gpio_direction(23, "in");
    init_gpio(15);
    set_gpio_direction(15, "in");
    init_gpio(18);
    set_gpio_direction(18, "in");

    set_gpio_direction(23, "out");
    set_gpio(23, 1);
    set_gpio_direction(15, "out");
    set_gpio(15, 1);
    set_gpio_direction(18, "out");
    set_gpio(18, 1);

    init_gpio(25);
    set_gpio_direction(25, "out");
    set_gpio(25, 0);
    return true;
}
Ejemplo n.º 19
0
void write_number (int n) {
  // reinit
  clear();
  set_gpio(A, 1);
  set_gpio(B, 1);

  // Need to work down from largest power of two
  set_gpio(B, (n >> 7) & 1);
  tick();
  set_gpio(B, (n >> 6) & 1);
  tick();
  set_gpio(B, (n >> 5) & 1);
  tick();
  set_gpio(B, (n >> 4) & 1);
  tick();
  set_gpio(B, (n >> 3) & 1);
  tick();
  set_gpio(B, (n >> 2) & 1);
  tick();
  set_gpio(B, (n >> 1) & 1);
  tick();
  set_gpio(B, n & 1);
  tick();
}
Ejemplo n.º 20
0
void mainboard_smi_sleep(u8 slp_typ)
{
	/* Disable USB charging if required */
	switch (slp_typ) {
	case 3:
		set_power_led(SIO_GPIO_BLINK_GPIO10, LED_BLINK);

		/* Enable DCP mode */
		set_gpio(GPIO_USB_CTL_1, 0);
		break;
	case 5:
		set_power_led(SIO_GPIO_BLINK_GPIO10, LED_OFF);
		break;
	}
}
Ejemplo n.º 21
0
int main()
{	
	set_gpio('G',9,1);
	open_driver(PSAM1,O_RDWR);							//打开PSAM小卡设备

	if(Drivers[PSAM1].fd==-1)
	{
		printf("open device error\n");
		return;
	}

	coldreset();
	random_num();

	close(Drivers[PSAM1].fd);
}
Ejemplo n.º 22
0
ICACHE_FLASH_ATTR static v7_val_t GPIO_out(struct v7 *v7, v7_val_t this_obj,
                                           v7_val_t args) {
  v7_val_t pinv = v7_array_get(v7, args, 0);
  v7_val_t valv = v7_array_get(v7, args, 1);
  int pin, val;

  if (!v7_is_double(pinv)) {
    printf("non-numeric pin\n");
    return v7_create_undefined();
  }
  pin = v7_to_double(pinv);
  val = v7_is_true(v7, valv) ? 1 : 0;

  set_gpio(pin, val);

  return v7_create_undefined();
}
Ejemplo n.º 23
0
/*
 * Power Sequencing for SanDisk i100/i110 SSD
 *
 * Must be sequenced in this order with specified timing.
 *
 * 1. VCC_IO    : 30us - 100ms
 * 2. VCC_FLASH : 70us - 10ms
 * 3. VCCQ      : 70us - 10ms
 * 4. VDDC      : 30us - 100ms
 *
 * There is no feedback to know if the voltage has stabilized
 * so this implementation will use the max ramp times.  That
 * means it adds significantly to the boot time.
 */
static void issd_power_sequence(void)
{
	struct gpio_seq {
		int gpio;
		int wait_ms;
	} issd_gpio_seq[] = {
		{ 49, 100 },	/* VCC_IO:    GPIO 49, wait 100ms */
		{ 44, 10 },	/* VCC_FLASH: GPIO 44, wait 10ms */
		{ 17, 10 },	/* VCCQ:      GPIO 17, wait 10ms */
		{ 16, 100 },	/* VDDC:      GPIO 16, wait 100ms */
	};
	int step;

	for (step = 0; step < ARRAY_SIZE(issd_gpio_seq); step++) {
		set_gpio(issd_gpio_seq[step].gpio, 1);
		udelay(issd_gpio_seq[step].wait_ms * 1000);
	}
}
Ejemplo n.º 24
0
void set_led(uint8_t num, uint8_t val){
	if (num < 6){
		set_gpio(led_portmap[num], led_pinmap[num], !val);
	}
}
Ejemplo n.º 25
0
void period_check(int sig)
{
	FILE *fp;
	unsigned int val = 0;

#ifdef HAVE_RADIOOFF
	if (initses == 1 && nvram_match("radiooff_boot_off", "1")
	    && nvram_match("radiooff_button", "1")) {
		ses_mode = 1;
		initses = 0;
	}
#endif

	// time_t t;

	// time(&t);
	// DEBUG("resetbutton: now time=%d\n", t);

#if defined(HAVE_MAGICBOX) || defined(HAVE_FONERA) || defined(HAVE_WHRAG108) || defined(HAVE_GATEWORX) || defined(HAVE_STORM) || defined(HAVE_LS2) || defined(HAVE_CA8) || defined(HAVE_TW6600)  || defined(HAVE_LS5) || defined(HAVE_LSX) || defined(HAVE_WP54G) || defined(HAVE_NP28G) || defined(HAVE_SOLO51) || defined(HAVE_OPENRISC) || defined(HAVE_DANUBE) || defined(HAVE_WDR4900) || defined(HAVE_VENTANA)
	val = getbuttonstate();
#ifdef HAVE_WRK54G
	if (val)
		val = 0;
	else
		val = 1;
#endif
#ifndef HAVE_ALPHA
#ifdef HAVE_USR5453
	if (val)
		val = 0;
	else
		val = 1;
#endif
#endif

#else
	if (brand == ROUTER_BOARD_WCRGN) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_WHRG300N) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_HAMEA15) {
		val = get_gpio(0);
	} else if (brand == ROUTER_BOARD_ECB9750) {
		val = get_gpio(11) << 11;
	} else if (brand == ROUTER_BOARD_NEPTUNE) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_RT3352) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_WR5422) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_DIR600B) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_F5D8235) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_ASUS_RTN10PLUS) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_RT15N) {
		val = get_gpio(12) << 12;
	} else if (brand == ROUTER_BOARD_DIR615D) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_ESR6650) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_EAP9550) {
		val = get_gpio(0);
	} else if (brand == ROUTER_BOARD_ESR9752) {
		val = get_gpio(0);
	} else if (brand == ROUTER_BOARD_AR670W) {
		val = get_gpio(9) << 9;
	} else if (brand == ROUTER_BOARD_AR690W) {
		val = get_gpio(9) << 9;
	} else if (brand == ROUTER_BOARD_BR6574N) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_ACXNR22) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_TECHNAXX3G) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_WHR300HP2) {
		val = get_gpio(52) << 1;
	} else if (brand == ROUTER_BOARD_W502U) {
		val = get_gpio(10) << 10;
	} else if (brand == ROUTER_BOARD_GW2380) {
		val = get_gpio(240);
	} else if (brand == ROUTER_BOARD_GW2388) {
		val = get_gpio(240);
	} else {

		if ((fp = fopen(GPIO_FILE, "r"))) {
#ifdef HAVE_XSCALE
			fscanf(fp, "%d", &val);
#else			
			if (brand == ROUTER_NETGEAR_WGR614L)	//gpio 7 power led shared with reset button
			{
				set_gpio(7, 1);	//disable power led
				val = get_gpio(7) << 7;	//read and shift value
				set_gpio(7, 0);	//enable power led
			} else {
				fread(&val, 4, 1, fp);
			}

#endif
			fclose(fp);
		} else
			perror(GPIO_FILE);
	}
#endif
	DEBUG("resetbutton: GPIO = 0x%x\n", val);

	int gpio = 0;

	int state = 0;

#if defined(HAVE_XSCALE) || defined(HAVE_MAGICBOX) || defined(HAVE_FONERA) || defined(HAVE_WHRAG108) || defined(HAVE_GATEWORX) || defined(HAVE_STORM) || defined(HAVE_LS2) || defined(HAVE_CA8) || defined(HAVE_TW6600)  || defined(HAVE_LS5) || defined(HAVE_LSX) || defined(HAVE_WP54G) || defined(HAVE_NP28G) || defined(HAVE_SOLO51) || defined(HAVE_OPENRISC) || defined(HAVE_DANUBE) || defined(HAVE_UNIWIP) || defined(HAVE_VENTANA)
	state = val;
	int sesgpio = 0xfff;
	int wifigpio = 0xfff;
	int push;
	int pushwifi;
#ifdef HAVE_WZRG300NH
	sesgpio = 0x117;
	val |= get_gpio(23) << 23;	//aoss pushbutton
#elif defined(HAVE_WHR300HP2)
	sesgpio = 0x102;
	val |= get_gpio(53) << 2;	//aoss pushbutton
#elif defined(HAVE_NEPTUNE)
	sesgpio = 0x100;
	val |= get_gpio(0);	//aoss pushbutton
#elif defined(HAVE_HAMEA15)
//      sesgpio = 0x100;
//      val |= get_gpio(0);     //aoss pushbutton
#elif defined(HAVE_WCRGN)
	sesgpio = 0x100;
	val |= get_gpio(0);	//aoss pushbutton
#elif defined(HAVE_RT3352)
	sesgpio = 0x100;
	val |= get_gpio(0);	//aoss pushbutton
#elif defined(HAVE_WZRG300NH2)
	sesgpio = 0x10c;
	val |= get_gpio(12) << 12;	//aoss pushbutton
#elif defined(HAVE_WMBR_G300NH)
	sesgpio = 0x100;
	val |= get_gpio(0);	//aoss pushbutton
#elif defined(HAVE_WZRG450)
	sesgpio = 0x108;
	val |= get_gpio(8) << 8;	//aoss pushbutton
#elif defined(HAVE_DIR632)
	sesgpio = 0x10c;
	val |= get_gpio(12) << 12;	//aoss pushbutton
#elif defined(HAVE_WZRHPAG300NH)
	sesgpio = 0x105;
	val |= get_gpio(5) << 5;	//aoss pushbutton
#elif defined(HAVE_CARAMBOLA)
	sesgpio = 0xfff;

#elif defined(HAVE_HORNET)
	sesgpio = 0x00b;
	val |= get_gpio(11) << 11;	//aoss pushbutton
#elif defined(HAVE_RB2011)
//      sesgpio = 0x110;
//      val |= get_gpio(16) << 16;      //aoss pushbutton
#elif defined(HAVE_WDR4300)
//      sesgpio = 0x110;
//      val |= get_gpio(16) << 16;      //aoss pushbutton
#elif defined(HAVE_WNDR3700V4)
	sesgpio = 0x10f;
	val |= get_gpio(15) << 15;	//aoss pushbutton
#elif defined(HAVE_DIR825C1)
	sesgpio = 0x110;
	val |= get_gpio(16) << 16;	//aoss pushbutton
#elif defined(HAVE_WASP)
	sesgpio = 0x00b;
	val |= get_gpio(11) << 11;	//aoss pushbutton
#elif defined(HAVE_WNR2200)
//      sesgpio = 0x00b; //not yet supported
//      val |= get_gpio(37) << 37;      //aoss pushbutton
#elif defined(HAVE_WNR2000)
	sesgpio = 0x00b;
	val |= get_gpio(11) << 11;	//aoss pushbutton
#elif defined(HAVE_WDR2543)
	sesgpio = 0x10c;
	val |= get_gpio(12) << 12;	//aoss pushbutton
#elif defined(HAVE_WHRHPGN)
	sesgpio = 0x10c;
	val |= get_gpio(12) << 12;	//aoss pushbutton
#elif defined(HAVE_RT10N)
	sesgpio = 0x100;
	val |= get_gpio(0);	//aoss pushbutton
#elif defined(HAVE_RT15N)
	sesgpio = 0x100;
	val |= get_gpio(0);	//aoss pushbutton
#elif defined(HAVE_F5D8235)
	sesgpio = 0x100;
	val |= get_gpio(0);	//aoss pushbutton
#elif defined(HAVE_WR5422)
	sesgpio = 0x100;
	val |= get_gpio(0);	//aoss pushbutton
#elif defined(HAVE_DIR600)
	sesgpio = 0x100;
	val |= get_gpio(0);	//aoss pushbutton
#elif defined(HAVE_DIR615I)
	sesgpio = 0x110;
	val |= get_gpio(16) << 16;	//aoss pushbutton
#elif defined(HAVE_DIR615E)
	sesgpio = 0x10c;
	val |= get_gpio(12) << 12;	//aoss pushbutton
#elif defined(HAVE_WR1043)
	sesgpio = 0x107;
	val |= get_gpio(7) << 7;	//aoss pushbutton
#elif defined(HAVE_WR941)
	sesgpio = 0x107;
	val |= get_gpio(7) << 7;	//aoss pushbutton
#elif defined(HAVE_MR3020)
	sesgpio = 0xfff;
#elif defined(HAVE_WR741V4)
	sesgpio = 0x01a;
	val |= get_gpio(26) << 26;	//aoss pushbutton
#elif defined(HAVE_WR741)
	sesgpio = 0x10c;
	val |= get_gpio(12) << 12;	//aoss pushbutton
#elif defined(HAVE_WRT400)
	sesgpio = 0x103;
	val |= get_gpio(3) << 3;	//aoss pushbutton
#elif defined(HAVE_WNDR3700)
	sesgpio = 0x103;
	val |= get_gpio(3) << 3;	//aoss pushbutton
#elif defined(HAVE_DIR825)
	sesgpio = 0x108;
	val |= get_gpio(8) << 8;	//aoss pushbutton
#elif defined(HAVE_TG2521)
	sesgpio = 0x10c;
	val |= get_gpio(12) << 12;	//aoss pushbutton
#elif defined(HAVE_OPENRISC)
	sesgpio = 0x005;
	val |= get_gpio(5) << 5;	//aoss pushbutton
#endif
#ifdef HAVE_WRT160NL
	sesgpio = 0x107;
	val |= get_gpio(7) << 7;	//wps/ses pushbutton
#endif
#ifdef HAVE_TEW632BRP
	sesgpio = 0x10c;
	val |= get_gpio(12) << 12;	//wps/ses pushbutton
#endif
#else
	if (brand > 0xffff) {
		if ((brand & 0x000ff) != 0x000ff)
			gpio = 1 << (brand & 0x000ff);	// calculate gpio value.

		if ((brand & 0x00100) == 0)	// check reset button polarity: 0
			// normal, 1 inversed
			state = (val & gpio);
		else
			state = !(val & gpio);
	} else {

		if ((brand & 0x000f) != 0x000f)
			gpio = 1 << (brand & 0x000f);	// calculate gpio value.

		if ((brand & 0x0010) == 0)	// check reset button polarity: 0
			// normal, 1 inversed
			state = (val & gpio);
		else
			state = !(val & gpio);
	}
	/* 
	 * 1 byte router's SES (AOSS) button gpio number and polarity; Eko
	 * 25.nov.06
	 * 
	 * R R R P N N N N = 0xXX ----- - ------- | | gpio num | | | |--- SES -
	 * AOSS button polarity (0: normal, 1 inversed) | |-------- reserved for
	 * future use
	 * 
	 * 0xff = button disabled / not available 
	 */
	int push;
	int pushwifi;
	int sesgpio;
	int wifigpio = 0xfff;

	switch (brand) {
	case ROUTER_BUFFALO_WHRG54S:
	case ROUTER_BUFFALO_WZRRSG54:
	case ROUTER_BUFFALO_WLI_TX4_G54HP:
		sesgpio = 0x100;	// gpio 0, inversed
		break;
	case ROUTER_BUFFALO_WLA2G54C:
		sesgpio = 0x102;	// gpio 2, inversed
		break;
	case ROUTER_BUFFALO_WBR2G54S:
		sesgpio = 0x004;	// gpio 4, normal
		break;
	case ROUTER_BUFFALO_WZR600DHP2:
	case ROUTER_BUFFALO_WZR900DHP:
		sesgpio = 0x109;	// gpio 9, inversed
		break;
	case ROUTER_BUFFALO_WZR1750:
		sesgpio = 0x10c;	// gpio 12, inversed
		break;
	case ROUTER_D1800H:
		sesgpio = 0x10a;	// gpio 10, inversed
		break;
#ifndef HAVE_BUFFALO
	case ROUTER_ASUS_WL700GE:
		sesgpio = 0x004;	// gpio 4, normal
		break;
	case ROUTER_ASUS_RTN10PLUSD1:
		sesgpio = 0x114;	// gpio 20, inversed
		break;
	case ROUTER_ASUS_RTN10:
		sesgpio = 0x102;	// gpio 2, inversed
		break;
	case ROUTER_ASUS_RTN12:
	case ROUTER_NETGEAR_WNR2000V2:
		sesgpio = 0x100;	// gpio 0, inversed
		break;
	case ROUTER_LINKSYS_WTR54GS:
	case ROUTER_NETGEAR_WNDR4000:
		sesgpio = 0x102;	// gpio 2, inversed
		break;
	case ROUTER_WRT54G:
	case ROUTER_WRT54G_V8:
	case ROUTER_WRTSL54GS:
	case ROUTER_WRT150N:
	case ROUTER_WRT160N:
	case ROUTER_WRT300N:
	case ROUTER_WRT300NV11:
	case ROUTER_WRT610NV2:
	case ROUTER_ASKEY_RT220XD:	// not soldered
	case ROUTER_DYNEX_DX_NRUTER:
	case ROUTER_LINKSYS_E4200:
	case ROUTER_ASUS_RTN66:
		sesgpio = 0x104;	// gpio 4, inversed
		break;
	case ROUTER_ASUS_AC66U:
		sesgpio = 0x104;	// gpio 4, inversed
		break;
	case ROUTER_DLINK_DIR868:
	case ROUTER_ASUS_AC67U:
		wifigpio = 0x10f;
		sesgpio = 0x107;	// gpio 7, inversed
		break;
	case ROUTER_ASUS_AC56U:
		wifigpio = 0x107;	// gpio 7, inversed
		sesgpio = 0x10f;	// gpio 7, inversed
		break;
	case ROUTER_ASUS_WL500G_PRE:
		sesgpio = 0x004;	// gpio 4, normal
		break;
	case ROUTER_ASUS_WL550GE:
		sesgpio = 0x00f;	// gpio 15, normal
		break;
	case ROUTER_WRT310N:
	case ROUTER_WRT350N:
	case ROUTER_WRT610N:
	case ROUTER_ASUS_RTN16:
	case ROUTER_BELKIN_F7D3301:
	case ROUTER_BELKIN_F7D3302:
	case ROUTER_BELKIN_F7D4301:
	case ROUTER_BELKIN_F7D4302:
	case ROUTER_BELKIN_F5D8235V3:
	case ROUTER_LINKSYS_E3200:
		sesgpio = 0x108;	// gpio 8, inversed
		break;
	case ROUTER_ASUS_WL500W:
		sesgpio = 0x007;	// gpio 7, normal
		break;
	case ROUTER_DLINK_DIR330:
		sesgpio = 0x107;	// gpio 7, inversed
		break;
	case ROUTER_ASUS_WL520GUGC:
	case ROUTER_ASUS_WL500G_PRE_V2:
		sesgpio = 0x103;	// gpio 3, inversed
		break;
	case ROUTER_WAP54G_V3:
		sesgpio = 0x10e;	// gpio 14, inversed
		break;
	case ROUTER_NETGEAR_WNDR3300:
		sesgpio = 0x101;	// gpio 1, inversed
		break;
	case ROUTER_WRT54G_V81:
	case ROUTER_DLINK_DIR320:
	case ROUTER_WRT600N:
	case ROUTER_NETGEAR_WNDR3400:
	case ROUTER_NETGEAR_WNR3500L:
		sesgpio = 0x106;	// gpio 6, inversed
		break;
	case ROUTER_WRT320N:
	case ROUTER_WRT160NV3:
	case ROUTER_NETGEAR_WNDR4500:
	case ROUTER_NETGEAR_WNDR4500V2:
	case ROUTER_NETGEAR_R6300:
		sesgpio = 0x104;
		wifigpio = 0x105;
		break;
	case ROUTER_NETGEAR_R6250:
		sesgpio = 0x104;	
		wifigpio = 0x105;
		break;
	case ROUTER_NETGEAR_R6300V2:
		sesgpio = 0x104;	
		wifigpio = 0x105;
		break;
	case ROUTER_NETGEAR_R7000:
		sesgpio = 0x104;
		wifigpio = 0x105;
		break;
	case ROUTER_WRT310NV2:
		sesgpio = 0x105;	// gpio 5, inversed
		break;
	case ROUTER_LINKSYS_E800:
	case ROUTER_LINKSYS_E900:
	case ROUTER_LINKSYS_E1000V2:
	case ROUTER_LINKSYS_E1500:
	case ROUTER_LINKSYS_E1550:
	case ROUTER_LINKSYS_E2500:
		sesgpio = 0x109;	// gpio 9, inversed
		break;
	case ROUTER_LINKSYS_EA6500:
		sesgpio = 0x104;	// gpio 4, inversed
		break;
#endif
	default:
		sesgpio = 0xfff;	// gpio unknown, disabled
		wifigpio = 0xfff;	// gpio unknown, disabled
	}
#endif

	push = 1 << (sesgpio & 0x0ff);	// calculate push value from ses gpio 
	pushwifi = 1 << (wifigpio & 0x0ff);	// calculate push value from ses gpio 
	// 
	// 
	// 
	// pin no.

	/* 
	 * The value is zero during button-pushed. 
	 */
	if (state && nvram_match("resetbutton_enable", "1")) {
		DEBUG("resetbutton: mode=%d, count=%d\n", mode, count);

		if (mode == 0) {
			/* 
			 * We detect button pushed first time 
			 */
			alarmtimer(0, URGENT_INTERVAL);
			mode = 1;
		}
		{		/* Whenever it is pushed steady */
			if (++count > RESET_WAIT_COUNT) {
				if (check_action() != ACT_IDLE) {	// Don't execute during upgrading
					fprintf(stderr, "resetbutton: nothing to do...\n");
					alarmtimer(0, 0);	/* Stop the timer alarm */
					return;
				}
				if ((brand & 0x000f) != 0x000f) {
					printf("resetbutton: factory default.\n");
					dd_syslog(LOG_DEBUG, "Reset button: restoring factory defaults now!\n");
#if !defined(HAVE_XSCALE) && !defined(HAVE_MAGICBOX) && !defined(HAVE_FONERA) && !defined(HAVE_WHRAG108) && !defined(HAVE_GATEWORX) && !defined(HAVE_LS2) && !defined(HAVE_CA8) && !defined(HAVE_TW6600) && !defined(HAVE_LS5) && !defined(HAVE_LSX) && !defined(HAVE_SOLO51)
					led_control(LED_DIAG, LED_ON);
#elif defined(HAVE_WHRHPGN)  || defined(HAVE_WZRG300NH) || defined(HAVE_WZRHPAG300NH) || defined(HAVE_WZRG450)
					led_control(LED_DIAG, LED_ON);
#endif
					ACTION("ACT_HW_RESTORE");
					alarmtimer(0, 0);	/* Stop the timer alarm */
#ifdef HAVE_X86
					eval("mount", "/usr/local", "-o", "remount,rw");
					eval("rm", "-f", "/tmp/nvram/*");	// delete nvram
					// database
					eval("rm", "-f", "/tmp/nvram/.lock");	// delete
					// nvram
					// database
					eval("rm", "-f", "/usr/local/nvram/*");	// delete
					// nvram
					// database
					eval("mount", "/usr/local", "-o", "remount,ro");
#elif HAVE_RB500
					eval("rm", "-f", "/tmp/nvram/*");	// delete nvram
					// database
					eval("rm", "-f", "/tmp/nvram/.lock");	// delete
					// nvram
					// database
					eval("rm", "-f", "/etc/nvram/*");	// delete nvram
					// database
#elif HAVE_MAGICBOX
					eval("rm", "-f", "/tmp/nvram/*");	// delete nvram
					// database
					eval("rm", "-f", "/tmp/nvram/.lock");	// delete
					// nvram
					// database
					eval("erase", "nvram");
#else
#ifdef HAVE_BUFFALO_SA
					int region_sa = 0;
					if (nvram_default_match("region", "SA", ""))
						region_sa = 1;
#endif
					nvram_set("sv_restore_defaults", "1");
					nvram_commit();
					eval("killall", "ledtool");	// stop blinking on
					// nvram_commit
#if !defined(HAVE_XSCALE) && !defined(HAVE_MAGICBOX) && !defined(HAVE_FONERA) && !defined(HAVE_WHRAG108) && !defined(HAVE_GATEWORX) && !defined(HAVE_LS2) && !defined(HAVE_CA8) && !defined(HAVE_TW6600) && !defined(HAVE_LS5) && !defined(HAVE_LSX) && !defined(HAVE_SOLO51)
					led_control(LED_DIAG, LED_ON);	// turn diag led on,
					// so we know reset
					// was pressed and
					// we're restoring
					// defaults.
#elif defined(HAVE_WHRHPGN) || defined(HAVE_WZRG300NH) || defined(HAVE_WZRHPAG300NH) || defined(HAVE_WZRG450)
					led_control(LED_DIAG, LED_ON);
#endif
#ifdef HAVE_BUFFALO_SA
					nvram_set("sv_restore_defaults", "1");
					if (region_sa)
						nvram_set("region", "SA");
					nvram_commit();
#endif
#endif

					// nvram_set ("sv_restore_defaults", "1");
					// nvram_commit ();

					kill(1, SIGTERM);
				}
			}
		}
	} else if ((sesgpio != 0xfff)
		   && (((sesgpio & 0x100) == 0 && (val & push))
		       || ((sesgpio & 0x100) == 0x100 && !(val & push)))) {
		runStartup("/etc/config", ".sesbutton");
		runStartup("/jffs/etc/config", ".sesbutton");	// if available
		runStartup("/mmc/etc/config", ".sesbutton");	// if available
		runStartup("/tmp/etc/config", ".sesbutton");	// if available
		if (nvram_match("radiooff_button", "1")) {
			led_control(LED_SES, LED_FLASH);	// when pressed, blink white
			switch (ses_mode) {

			case 1:
				// SES (AOSS) led
#ifdef HAVE_RADIOOFF
#ifndef HAVE_BUFFALO
				dd_syslog(LOG_DEBUG, "SES / AOSS / EZ-setup button: turning radio(s) on\n");
#else
				dd_syslog(LOG_DEBUG, "AOSS button: turning radio(s) on\n");
#endif
#ifndef HAVE_ERC
				sysprintf("startservice radio_on");
#endif
#endif

				ses_mode = 0;
				break;
			case 2:

				// (AOSS) led
#ifdef HAVE_RADIOOFF
#ifndef HAVE_BUFFALO
				dd_syslog(LOG_DEBUG, "SES / AOSS / EZ-setup button: turning radio(s) off\n");
#else
				dd_syslog(LOG_DEBUG, "AOSS button: turning radio(s) off\n");
#endif
#ifndef HAVE_ERC
				sysprintf("startservice radio_off");
#endif
#endif

				ses_mode = 1;
				break;
			}

		}
#ifdef HAVE_AOSS
		else if (nvram_match("radiooff_button", "2")) {
			sysprintf("startservice aoss");
		}
#else
#endif

	} else if ((wifigpio != 0xfff)
		   && (((wifigpio & 0x100) == 0 && (val & pushwifi))
		       || ((wifigpio & 0x100) == 0x100 && !(val & pushwifi)))) {
		led_control(LED_WLAN, LED_FLASH);	// when pressed, blink white
		switch (wifi_mode) {
		case 1:
			dd_syslog(LOG_DEBUG, "Wifi button: turning radio(s) on\n");
			sysprintf("startservice radio_on");
			wifi_mode = 0;
			break;
		case 0:
			// (AOSS) led
			dd_syslog(LOG_DEBUG, "Wifi button: turning radio(s) off\n");
			sysprintf("startservice radio_off");
			wifi_mode = 1;
			break;
		}

	} else {

		/* 
		 * Although it's unpushed now, it had ever been pushed 
		 */
		if (mode == 1) {
			if (check_action() != ACT_IDLE) {	// Don't execute during upgrading
				fprintf(stderr, "resetbutton: nothing to do...\n");
				alarmtimer(0, 0);	/* Stop the timer alarm */
				return;
			}
			service_restart();
		}
	}
}
Ejemplo n.º 26
0
// used for various testing
static int rctest_main(int argc, char *argv[])
{
	int on;

	if (argc < 3) {
		_dprintf("test what?\n");
	}
	else if (strcmp(argv[1], "rc_service")==0) {
		notify_rc(argv[2]);
	}
	else if(strcmp(argv[1], "get_phy_status")==0) {
		int mask;
		mask = atoi(argv[2]);
		TRACE_PT("debug for phy_status %x\n", get_phy_status(mask));
	}
	else if(strcmp(argv[1], "get_phy_speed")==0) {
		int mask;
		mask = atoi(argv[2]);
		TRACE_PT("debug for phy_speed %x\n", get_phy_speed(mask));
	}
	else if(strcmp(argv[1], "set_phy_ctrl")==0) {
		int mask, ctrl;
		mask = atoi(argv[2]);
		ctrl = atoi(argv[3]);
		TRACE_PT("debug for phy_speed %x\n", set_phy_ctrl(mask, ctrl));
	}
	else if(strcmp(argv[1], "handle_notifications")==0) {
		handle_notifications();
	}
	else if(strcmp(argv[1], "check_action")==0) {
		_dprintf("check: %d\n", check_action());
	}
	else if(strcmp(argv[1], "nvramhex")==0) {
		int i;
		char *nv;

		nv = nvram_safe_get(argv[2]);

		_dprintf("nvram %s(%d): ", nv, strlen(nv));
		for(i=0;i<strlen(nv);i++) {
			_dprintf(" %x", (unsigned char)*(nv+i));
		}
		_dprintf("\n");
	}
	else {
		on = atoi(argv[2]);
		_dprintf("%s %d\n", argv[1], on);

		if (strcmp(argv[1], "vlan") == 0)
		{	
			if(on) start_vlan();
			else stop_vlan();
		}
		else if (strcmp(argv[1], "lan") == 0) {
			if(on) start_lan();
			else stop_lan();
		}
		else if (strcmp(argv[1], "wl") == 0) {
			if(on) 
			{
				start_wl();
				lanaccess_wl();
			}
		}
		else if (strcmp(argv[1], "wan") == 0) {
			if(on) start_wan();
			else stop_wan();
		}
		else if (strcmp(argv[1], "firewall") == 0) {
			//if(on) start_firewall();
			//else stop_firewall();
		}
		else if (strcmp(argv[1], "watchdog") == 0) {
			if(on) start_watchdog();
			else stop_watchdog();
		}
#ifdef RTCONFIG_FANCTRL
		else if (strcmp(argv[1], "phy_tempsense") == 0) {
			if(on) start_phy_tempsense();
			else stop_phy_tempsense();
		}
#endif
#ifdef RTCONFIG_BCMWL6
#ifdef RTCONFIG_PROXYSTA
		else if (strcmp(argv[1], "psta_monitor") == 0) {
			if(on) start_psta_monitor();
			else stop_psta_monitor();
		}
#endif
#endif
		else if (strcmp(argv[1], "qos") == 0) {//qos test
			if(on){
#ifdef RTCONFIG_RALINK
				if (module_loaded("hw_nat"))
				{
					modprobe_r("hw_nat");
					sleep(1);
#if 0
					system("echo 0 > /proc/sys/net/ipv4/conf/default/force_igmp_version");
					system("echo 0 > /proc/sys/net/ipv4/conf/all/force_igmp_version");
#endif
				}
#endif
				add_iQosRules(get_wan_ifname(0));
				start_iQos();
			}
			else 
			{
#ifdef RTCONFIG_RALINK
				if (nvram_get_int("hwnat") &&
					/* TODO: consider RTCONFIG_DUALWAN case */
//					!nvram_match("wan0_proto", "l2tp") &&
//					!nvram_match("wan0_proto", "pptp") &&
//					!(nvram_get_int("fw_pt_l2tp") || nvram_get_int("fw_pt_ipsec") &&
//					(nvram_match("wl0_radio", "0") || nvram_get_int("wl0_mrate_x")) &&
//					(nvram_match("wl1_radio", "0") || nvram_get_int("wl1_mrate_x")) &&
					!module_loaded("hw_nat"))
				{
#if 0
					system("echo 2 > /proc/sys/net/ipv4/conf/default/force_igmp_version");
					system("echo 2 > /proc/sys/net/ipv4/conf/all/force_igmp_version");
#endif
					modprobe("hw_nat");
					sleep(1);
				}
#endif
				stop_iQos();
				del_iQosRules();
			}
		}
#ifdef RTCONFIG_WEBDAV
		else if (strcmp(argv[1], "webdav") == 0) {
			if(on)
				start_webdav();
		}
#endif
		else if (strcmp(argv[1], "gpiow") == 0) {
			if(argc>=4) set_gpio(atoi(argv[2]), atoi(argv[3]));
		}
		else if (strcmp(argv[1], "gpior") == 0) {
			_dprintf("%d\n", get_gpio(atoi(argv[2])));
		}
		else if (strcmp(argv[1], "gpiod") == 0) {
			if(argc>=4) gpio_dir(atoi(argv[2]), atoi(argv[3]));
		}
		else if (strcmp(argv[1], "init_switch") == 0) {
			init_switch(on);
		}
		else if (strcmp(argv[1], "set_action") == 0) {
			set_action(on);
		}
		else if (strcmp(argv[1], "pwr_usb") == 0) {
			set_pwr_usb(atoi(argv[2]));
			_dprintf("done.\n");
		}
		else {
			printf("what?\n");
		}
	}
	return 0;
}
Ejemplo n.º 27
0
static void v2_set_dmz(u8 state) {
	set_gpio(DMZ_GPIO,state);
}
Ejemplo n.º 28
0
static void v2_set_diag(u8 state) {
	set_gpio(DIAG_GPIO,state);
}
Ejemplo n.º 29
0
void start_sysinit(void)
{
	char buf[PATH_MAX];
	struct stat tmp_stat;
	time_t tm = 0;

	mknod("/dev/mmc", S_IFBLK | 0660, makedev(126, 0));
	mknod("/dev/mmc0", S_IFBLK | 0660, makedev(126, 1));
	mknod("/dev/mmc1", S_IFBLK | 0660, makedev(126, 2));
	mknod("/dev/mmc2", S_IFBLK | 0660, makedev(126, 3));
	mknod("/dev/mmc3", S_IFBLK | 0660, makedev(126, 4));
	mknod("/dev/gpio", S_IFCHR | 0644, makedev(252, 0));

	/*
	 * Setup console 
	 */

	cprintf("sysinit() klogctl\n");
	klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel")));
	cprintf("sysinit() get router\n");

	/*
	 * load some netfilter stuff 
	 */

//    eval( "watchdog" );
	/*
	 * Set a sane date 
	 */

	stime(&tm);
	nvram_set("wl0_ifname", "ra0");
	insmod("rt2860v2_ap");
	insmod("RTPCI_ap");
	insmod("raeth");
#ifdef HAVE_WHR300HP2
	insmod("rt2880_wdt");


	FILE *in = fopen("/dev/mtdblock/2", "rb");
	unsigned char mac[32];
	if (in != NULL) {
		fseek(in, 4, SEEK_SET);
		fread(mac, 6, 1, in);
		fclose(in);
		unsigned int copy[6];
		int i;
		for (i = 0; i < 6; i++)
			copy[i] = mac[i] & 0xff;
		sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]);
		fprintf(stderr,"configure mac address to %s\n",mac);
		if (!strcmp(mac, "ff:ff:ff:ff:ff:ff"))
			eval("ifconfig", "eth0", "hw", "ether", "00:11:22:33:44:55");
		else
			eval("ifconfig", "eth0", "hw", "ether", mac);
	}

/*	system("swconfig dev eth0 set reset 1");
	system("swconfig dev eth0 set enable_vlan 1");
	system("swconfig dev eth0 vlan 1 set ports \"0 1 2 3 6t\"");
	system("swconfig dev eth0 vlan 2 set ports \"4 6t\"");
	system("swconfig dev eth0 set apply");*/
	
	//LAN/WAN ports as security mode
	sysprintf("switch reg w 2004 ff0003");
	sysprintf("switch reg w 2104 ff0003");
	sysprintf("switch reg w 2204 ff0003");
	sysprintf("switch reg w 2304 ff0003");
	sysprintf("switch reg w 2404 ff0003");
	sysprintf("switch reg w 2504 ff0003");
	//LAN/WAN ports as transparent port
	sysprintf("switch reg w 2010 810000c0");
	sysprintf("switch reg w 2110 810000c0");
	sysprintf("switch reg w 2210 810000c0");
	sysprintf("switch reg w 2310 810000c0");	
	sysprintf("switch reg w 2410 810000c0");
	sysprintf("switch reg w 2510 810000c0");
	//set CPU/P7 port as user port
	sysprintf("switch reg w 2610 81000000");
	sysprintf("switch reg w 2710 81000000");

	sysprintf("switch reg w 2604 20ff0003");// #port6, Egress VLAN Tag Attribution=tagged
	sysprintf("switch reg w 2704 20ff0003");// #port7, Egress VLAN Tag Attribution=tagged
	

	sysprintf("switch reg w 2014 10001");
	sysprintf("switch reg w 2114 10001");
	sysprintf("switch reg w 2214 10001");
	sysprintf("switch reg w 2314 10001");
	sysprintf("switch reg w 2414 10002");
	sysprintf("switch reg w 2514 10001");
	//VLAN member port
	sysprintf("switch vlan set 0 1 11110111");
	sysprintf("switch vlan set 1 2 00001011");
	sysprintf("switch clear");
	eval("ifconfig", "eth0", "up");
	
	eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD");
	eval("vconfig", "add", "eth0", "1");	//LAN
	eval("vconfig", "add", "eth0", "2");	//WAN

	struct ifreq ifr;
	int s;

	if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) {
		char eabuf[32];

		strncpy(ifr.ifr_name, "eth0", IFNAMSIZ);
		ioctl(s, SIOCGIFHWADDR, &ifr);
		nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf));
		close(s);
	}

#else

#if defined(HAVE_DIR600) && !defined(HAVE_ALL02310N)
	writeproc("/proc/rt3052/mii/ctrl", "write 0 0 0x3300");
	writeproc("/proc/rt3052/mii/ctrl", "write 1 0 0x3300");
	writeproc("/proc/rt3052/mii/ctrl", "write 2 0 0x3300");
	writeproc("/proc/rt3052/mii/ctrl", "write 3 0 0x3300");
#endif
#if defined(HAVE_RT10N) || defined(HAVE_F5D8235) || defined(HAVE_RT15N) || defined(HAVE_WCRGN) && !defined(HAVE_HAMEA15)
	FILE *in = fopen("/dev/mtdblock/2", "rb");
	unsigned char mac[32];
	if (in != NULL) {
		fseek(in, 4, SEEK_SET);
		fread(mac, 6, 1, in);
		fclose(in);
		unsigned int copy[6];
		int i;
		for (i = 0; i < 6; i++)
			copy[i] = mac[i] & 0xff;
		sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]);
		if (!strcmp(mac, "ff:ff:ff:ff:ff:ff"))
			eval("ifconfig", "eth2", "hw", "ether", "00:11:22:33:44:55");
		else
			eval("ifconfig", "eth2", "hw", "ether", mac);
	}
#endif
#ifdef HAVE_HAMEA15
	FILE *in = fopen("/dev/mtdblock/1", "rb");
	if (in != NULL) {
		unsigned char *config = malloc(65536);
		memset(config, 0, 65536);
		fread(config, 65536, 1, in);
		int len = strlen("WAN_MAC_ADDR=");
		int i;
		for (i = 0; i < 65535 - (len + 18); i++) {
			if (!strncmp(&config[i], "WAN_MAC_ADDR=", len)) {
				char *mac = &config[i + len];
				if (mac[0] == '"')
					mac++;
				mac[17] = 0;
				eval("ifconfig", "eth2", "hw", "ether", mac);
				nvram_set("et0macaddr_safe", mac);
				nvram_set("et0macaddr", mac);
				break;
			}
		}
		free(config);
		fclose(in);
	}
#endif
#if (defined(HAVE_DIR600) || defined(HAVE_AR670W) || defined(HAVE_EAP9550) || defined(HAVE_AR690W)) && !defined(HAVE_ALL02310N)

	FILE *in = fopen("/dev/mtdblock/1", "rb");
	if (in != NULL) {
		unsigned char *config = malloc(65536);
		memset(config, 0, 65536);
		fread(config, 65536, 1, in);
#if defined(HAVE_AR670W) || defined(HAVE_AR690W)
		int len = strlen("lanmac=");
#else
		int len = strlen("ethaddr=");
#endif
		int i;
		for (i = 0; i < 65535 - (18 + len); i++) {
#if defined(HAVE_AR670W) || defined(HAVE_AR690W)
			if (!strncmp(&config[i], "lanmac=", 7))
#else
			if (!strncmp(&config[i], "ethaddr=", 8))
#endif
			{
				char *mac = &config[i + len];
				if (mac[0] == '"')
					mac++;
				mac[17] = 0;
				eval("ifconfig", "eth2", "hw", "ether", mac);
				nvram_set("et0macaddr_safe", mac);
				nvram_set("et0macaddr", mac);
				break;
			}
		}
		free(config);
		fclose(in);
	}
#endif

	/* switch config */
	if (getRouterBrand() != ROUTER_BOARD_ECB9750 && getRouterBrand() != ROUTER_BOARD_TECHNAXX3G)	// lets load
	{
		eval("ifconfig", "eth2", "up");
#ifndef HAVE_EAP9550
		eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD");
		eval("vconfig", "add", "eth2", "1");	//LAN 

		eval("vconfig", "add", "eth2", "2");	//WAN
#ifdef HAVE_RT10N
		MAC_ADD(mac);
		eval("ifconfig", "vlan2", "hw", "ether", mac);
#endif
#endif

#if defined(HAVE_ALLNET11N) || defined(HAVE_ESR6650) || defined(HAVE_WR5422) || defined(HAVE_RT10N) || \
    defined(HAVE_ACXNR22) || defined(HAVE_W502U) || defined(HAVE_ESR9752) || defined(HAVE_ALL02310N)
		sysprintf("switch reg w 14 405555");
		sysprintf("switch reg w 50 2001");
		sysprintf("switch reg w 90 7f7f");
		sysprintf("switch reg w 98 7f3f");
		sysprintf("switch reg w e4 3f");
		sysprintf("switch reg w 40 1002");
		sysprintf("switch reg w 44 1001");
		sysprintf("switch reg w 48 1001");
		sysprintf("switch reg w 70 ffff417e");
#ifdef HAVE_ESR9752
		sysprintf("switch reg w c8 3f502b28");
#endif
#elif HAVE_AR670W
		sysprintf("mii_mgr -s -p 29 -r 23 -v 0x07c2");
		sysprintf("mii_mgr -s -p 29 -r 22 -v 0x8420");

		sysprintf("mii_mgr -s -p 29 -r 24 -v 0x1");
		sysprintf("mii_mgr -s -p 29 -r 25 -v 0x1");
		sysprintf("mii_mgr -s -p 29 -r 26 -v 0x1");
		sysprintf("mii_mgr -s -p 29 -r 27 -v 0x1");
		sysprintf("mii_mgr -s -p 29 -r 28 -v 0x2");
		sysprintf("mii_mgr -s -p 30 -r 9 -v 0x1089");
		sysprintf("mii_mgr -s -p 30 -r 1 -v 0x2f00");
		sysprintf("mii_mgr -s -p 30 -r 2 -v 0x0030");
#elif HAVE_AR690W
#elif HAVE_RT15N
#elif HAVE_BR6574N
#elif HAVE_F5D8235
		sysprintf("switch reg w 14 405555");
		sysprintf("switch reg w 50 2001");
		sysprintf("switch reg w 90 7f7f");
		sysprintf("switch reg w 98 7f40");
		sysprintf("switch reg w e4 20");
		sysprintf("switch reg w 40 1001");
		sysprintf("switch reg w 44 1001");
		sysprintf("switch reg w 48 1001");
		sysprintf("switch reg w 4c 1");
		sysprintf("switch reg w 70 ffffffff");
#elif HAVE_EAP9550
		sysprintf("switch reg w 14 5555");
		sysprintf("switch reg w 40 1001");
		sysprintf("switch reg w 44 1001");
		sysprintf("switch reg w 48 1001");
		sysprintf("switch reg w 4c 1");
		sysprintf("switch reg w 50 2001");
		sysprintf("switch reg w 70 ffffffff");
		sysprintf("switch reg w 90 7f7f");
		sysprintf("switch reg w 98 7f7f");
		sysprintf("switch reg w e4 7f");
#else
		sysprintf("switch reg w 14 405555");
		sysprintf("switch reg w 50 2001");
		sysprintf("switch reg w 90 7f7f");
		sysprintf("switch reg w 98 7f3f");
		sysprintf("switch reg w e4 3f");
		sysprintf("switch reg w 40 1001");
		sysprintf("switch reg w 44 1001");
		sysprintf("switch reg w 48 1002");
		sysprintf("switch reg w 70 ffff506f");
#endif
	}

	struct ifreq ifr;
	int s;

	if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) {
		char eabuf[32];

		strncpy(ifr.ifr_name, "eth2", IFNAMSIZ);
		ioctl(s, SIOCGIFHWADDR, &ifr);
		nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf));
		close(s);
	}
#endif
	led_control(LED_POWER, LED_ON);
	led_control(LED_SES, LED_OFF);
	led_control(LED_SES2, LED_OFF);
	led_control(LED_DIAG, LED_OFF);
	led_control(LED_BRIDGE, LED_OFF);
	led_control(LED_WLAN0, LED_OFF);
	led_control(LED_WLAN1, LED_OFF);
	led_control(LED_CONNECTED, LED_OFF);
#ifdef HAVE_WCRGN
	set_gpio(0,1);
	set_gpio(10,1);
#endif

	if (!nvram_match("disable_watchdog", "1")) {
		eval("watchdog");
	}
	return;
}
Ejemplo n.º 30
0
//Handle error reporting here, to spare r_main the complexity.
void md_err(MD_STATUS ret, const char * where){
	set_gpio(&P6, 2, 0);	
	printf("\r\n**i2cerr** ret=%02x at %s\r\n",ret,where);
	delay_ms(100);
}