Пример #1
0
static void
autos3_monitor(void)
{
	struct pollfd poll_fd;
	srn_event_info_t srn_event;		/* contains suspend type */
	int fd, ret;

	fd = open(SRN, O_RDWR|O_EXCL|O_NDELAY);
	if (fd == -1) {
		logerror("Unable to open %s: %s", SRN, strerror(errno));
		thr_exit((void *) errno);
	}

	/*
	 * Tell device we want the special sauce
	 */
	ret = ioctl(fd, SRN_IOC_AUTOSX, NULL);
	if (ret == -1) {
		logerror("Ioctl SRN_IOC_AUTOSX failed: %s", strerror(errno));
		(void) close(fd);
		thr_exit((void *) errno);
	}
	poll_fd.fd = fd;
	/*CONSTCOND*/
	while (1) {
		poll_fd.revents = 0;
		poll_fd.events = POLLIN;
		if (poll(&poll_fd, 1, -1) < 0) {
			switch (errno) {
			case EINTR:
			case EAGAIN:
				continue;
			default:
				logerror("Poll error: %s", strerror(errno));
				(void) close(fd);
				thr_exit((void *) errno);
			}
		}

		ret = ioctl(fd, SRN_IOC_NEXTEVENT, &srn_event);
		if (ret == -1) {
			logerror("ioctl error: %s", strerror(errno));
			(void) close(fd);
			thr_exit((void *) errno);
		}
		switch (srn_event.ae_type) {
		case 3:			/* S3 */
			if (powerd_debug)
				logerror("ioctl returns type: %d",
				    srn_event.ae_type);
			break;
		default:
			logerror("Unsupported target state %d",
			    srn_event.ae_type);
			continue;
		}
		(void) poweroff("AutoS3", autoS3_cmd);
		continue;
	}
}
Пример #2
0
Файл: spi.c Проект: A-Paul/RIOT
void spi_init(spi_t bus)
{
    /* make sure given bus device is valid */
    assert(bus < SPI_NUMOF);

    /* initialize the buses lock */
    mutex_init(&locks[bus]);
    /* trigger pin initialization */
    spi_init_pins(bus);
    /* power on the bus temporarily */
    poweron(bus);

    /* make the base configuration: configure as SPI master, set CS inactive
     * state (for HWCS lines) and clear FIFO counters and disable FIFOs */
    dev(bus)->MCR = (SPI_MCR_MSTR_MASK | SPI_MCR_PCSIS_MASK |
                     SPI_MCR_CLR_RXF_MASK | SPI_MCR_CLR_TXF_MASK |
                     SPI_MCR_DIS_RXF_MASK | SPI_MCR_DIS_TXF_MASK |
                     SPI_MCR_DOZE_MASK | SPI_MCR_HALT_MASK);

    /* disable all DMA and interrupt requests */
    dev(bus)->RSER = 0;

    /* Wait for the hardware to acknowledge the halt command */
    while (dev(bus)->SR & SPI_SR_TXRXS_MASK) {}

    /* and power off the bus until it is actually used */
    poweroff(bus);
}
Пример #3
0
/*ARGSUSED*/
static void
power_button_monitor(void *arg)
{
	struct pollfd pfd;
	int events, ret;

	if (ioctl(pb_fd, PB_BEGIN_MONITOR, NULL) == -1) {
		logerror("Failed to monitor the power button.");
		thr_exit((void *) 0);
	}

	pfd.fd = pb_fd;
	pfd.events = POLLIN;

	/*CONSTCOND*/
	while (1) {
		if (poll(&pfd, 1, INFTIM) == -1) {
			logerror("Failed to poll for power button events.");
			thr_exit((void *) 0);
		}

		if (!(pfd.revents & POLLIN))
			continue;

		/*
		 * Monitor the power button, but only take action if
		 * gnome-power-manager is not running.
		 *
		 * ret greater than 0 means could not find process.
		 */
		ret = system("/usr/bin/pgrep -fx gnome-power-manager");

		if (ioctl(pfd.fd, PB_GET_EVENTS, &events) == -1) {
			logerror("Failed to get power button events.");
			thr_exit((void *) 0);
		}

		if ((ret > 0) && (events & PB_BUTTON_PRESS) &&
		    (poweroff(NULL, power_button_cmd) != 0)) {
			logerror("Power button is pressed, powering "
			    "down the system!");

			/*
			 * Send SIGPWR signal to the init process to
			 * shut down the system.
			 */
			if (kill(1, SIGPWR) == -1)
				(void) uadmin(A_SHUTDOWN, AD_POWEROFF, 0);
		}

		/*
		 * Clear any power button event that has happened
		 * meanwhile we were busy processing the last one.
		 */
		if (ioctl(pfd.fd, PB_GET_EVENTS, &events) == -1) {
			logerror("Failed to get power button events.");
			thr_exit((void *) 0);
		}
	}
}
Пример #4
0
static int cmd_poweroff(int argc, char *argv[])
{
	poweroff();

	/* Not reached */
	return 1;
}
Пример #5
0
Файл: spi.c Проект: adjih/RIOT
void spi_release(spi_t bus)
{
    /* disable and power off device */
    dev(bus)->CR1 = 0;
    poweroff(bus);
    /* and release lock... */
    mutex_unlock(&locks[bus]);
}
Пример #6
0
void spi_release(spi_t bus)
{
    /* disable device and put it back to sleep */
    dev(bus)->CTRLA.reg &= ~(SERCOM_SPI_CTRLA_ENABLE);
    while (dev(bus)->SYNCBUSY.reg & SERCOM_SPI_SYNCBUSY_ENABLE) {}
    poweroff(bus);
    /* release access to the device */
    mutex_unlock(&locks[bus]);
}
Пример #7
0
/*-------------------------------------------------------------------------*/
int external_send_raw(char* buf)
{
	ir_cmd_t cmd;
	int ret=1; // default: cmd failed

	DDD("SEND CMD '%s'",buf);

	if (!strcasecmp(buf,"Startup")) {
		// start vdr
		standby(0);
		ret=0;
	}
	else {
		if (!strcasecmp(buf,"Standby")) {
		    if (power_state) {
			standby(1);
			strcpy(cmd.name,"Power");
		    }
		    else {
		        DDD("already in standby. nothing to do.");
		        ret=0;
		    }
		}
		else if (!strcasecmp(buf,"Poweroff")) {
			poweroff();
			strcpy(cmd.name,"Power");
		}
		else if (!strcasecmp(buf,"Eject") && !power_state) {
			cdeject();
			strcpy(cmd.name,"Eject");
			ret=0; // works also in standby
		}
		else {
			strcpy(cmd.name,buf);
		}
		int shifted=0;
		kbdx_t * kbdx=find_named_key(cmd.name, &shifted);
		if (!kbdx)
			return 0;
		cmd.kbdx=kbdx;
		cmd.source=0;
		cmd.cmd=0;        // dummy
		cmd.device=0;
		cmd.shift=shifted;
		cmd.flags=0;
		cmd.repeat=0;
		cmd.timestamp=get_timestamp();

		cmd.flags=0;
		cmd.state=REEL_IR_STATE_REEL;
		put_code(cmd);
		if (power_state)
			ret=0;
	}
	return ret;
}
Пример #8
0
static void
wpishutdown(Ether *edev)
{
	Ctlr *ctlr;

	ctlr = edev->ctlr;
	if(ctlr->power)
		poweroff(ctlr);
	ctlr->broken = 0;
}
Пример #9
0
static void
wpiattach(Ether *edev)
{
	FWImage *fw;
	Ctlr *ctlr;
	char *err;

	ctlr = edev->ctlr;
	eqlock(ctlr);
	if(waserror()){
		print("#l%d: %s\n", edev->ctlrno, up->errstr);
		if(ctlr->power)
			poweroff(ctlr);
		qunlock(ctlr);
		nexterror();
	}
	if(ctlr->attached == 0){
		if((csr32r(ctlr, Gpc) & RfKill) == 0)
			error("wifi disabled by switch");

		if(ctlr->wifi == nil){
			ctlr->wifi = wifiattach(edev, transmit);
			ctlr->wifi->rates = wpirates;
		}

		if(ctlr->fw == nil){
			fw = readfirmware();
			print("#l%d: firmware: %ux, size: %ux+%ux+%ux+%ux+%ux\n",
				edev->ctlrno, fw->version,
				fw->main.text.size, fw->main.data.size,
				fw->init.text.size, fw->init.data.size,
				fw->boot.text.size);
			ctlr->fw = fw;
		}

		if((err = reset(ctlr)) != nil)
			error(err);
		if((err = boot(ctlr)) != nil)
			error(err);

		ctlr->bcastnodeid = -1;
		ctlr->bssnodeid = -1;
		ctlr->channel = 1;
		ctlr->aid = 0;

		setoptions(edev);

		ctlr->attached = 1;

		kproc("wpirecover", wpirecover, edev);
	}
	qunlock(ctlr);
	poperror();
}
Пример #10
0
Файл: spi.c Проект: A-Paul/RIOT
void spi_release(spi_t bus)
{
    /* Halt transfers */
    dev(bus)->MCR |= SPI_MCR_HALT_MASK;

    /* Wait for the module to acknowledge the stop */
    while (dev(bus)->SR & SPI_SR_TXRXS_MASK) {}

    /* Disable the module */
    poweroff(bus);
    mutex_unlock(&locks[bus]);
}
Пример #11
0
/*ARGSUSED*/
static void
power_button_monitor(void *arg)
{
	struct pollfd pfd;
	int events;

	if (ioctl(pb_fd, PB_BEGIN_MONITOR, NULL) == -1) {
		logerror("Failed to monitor the power button.");
		thr_exit((void *) 0);
	}

	pfd.fd = pb_fd;
	pfd.events = POLLIN;

	/*CONSTCOND*/
	while (1) {
		if (poll(&pfd, 1, INFTIM) == -1) {
			logerror("Failed to poll for power button events.");
			thr_exit((void *) 0);
		}

		if (!(pfd.revents & POLLIN))
			continue;

		if (ioctl(pfd.fd, PB_GET_EVENTS, &events) == -1) {
			logerror("Failed to get power button events.");
			thr_exit((void *) 0);
		}

		if ((events & PB_BUTTON_PRESS) &&
		    (poweroff(NULL, power_button_cmd) != 0)) {
			logerror("Power button is pressed, powering "
			    "down the system!");

			/*
			 * Send SIGPWR signal to the init process to
			 * shut down the system.
			 */
			if (kill(1, SIGPWR) == -1)
				(void) uadmin(A_SHUTDOWN, AD_POWEROFF, 0);
		}

		/*
		 * Clear any power button event that has happened
		 * meanwhile we were busy processing the last one.
		 */
		if (ioctl(pfd.fd, PB_GET_EVENTS, &events) == -1) {
			logerror("Failed to get power button events.");
			thr_exit((void *) 0);
		}
	}
}
Пример #12
0
__dead void arch_shutdown(int how)
{
	unsigned char unused_ch;
	/* Mask all interrupts, including the clock. */
	outb( INT_CTLMASK, ~0);

	/* Empty buffer */
	while(direct_read_char(&unused_ch))
		;

	if(kinfo.minix_panicing) {
		/* Printing is done synchronously over serial. */
		if (kinfo.do_serial_debug)
			reset();

		/* Print accumulated diagnostics buffer and reset. */
		direct_cls();
		direct_print("Minix panic. System diagnostics buffer:\n\n");
		direct_print(kmess.kmess_buf);
		direct_print("\nSystem has panicked, press any key to reboot");
		while (!direct_read_char(&unused_ch))
			;
		reset();
	}

	switch (how) {
		case RBT_HALT:
			/* Hang */
			for (; ; ) halt_cpu();
			NOT_REACHABLE;
			
		case RBT_POWEROFF:
			/* Power off if possible, hang otherwise */
			poweroff();
			NOT_REACHABLE;

		default:
		case RBT_DEFAULT:	
		case RBT_REBOOT:
		case RBT_RESET:
			/* Reset the system by forcing a processor shutdown. 
			 * First stop the BIOS memory test by setting a soft
			 * reset flag.
			 */
			reset();
			NOT_REACHABLE;
	}

	NOT_REACHABLE;
}
Пример #13
0
/**
 * The "poweroff" command
 *
 * @v argc		Argument count
 * @v argv		Argument list
 * @ret rc		Return status code
 */
static int poweroff_exec ( int argc, char **argv ) {
	struct poweroff_options opts;
	int rc;

	/* Parse options */
	if ( ( rc = parse_options ( argc, argv, &poweroff_cmd, &opts ) ) != 0 )
		return rc;

	/* Power off system */
	rc = poweroff();
	if ( rc != 0 )
		printf ( "Could not power off: %s\n", strerror ( rc ) );

	return rc;
}
Пример #14
0
Файл: spi.c Проект: adjih/RIOT
void spi_init(spi_t bus)
{
    assert(bus <= SPI_NUMOF);

    /* temporarily power on the device */
    poweron(bus);
    /* configure device to be a master and disable SSI operation mode */
    dev(bus)->CR1 = 0;
    /* configure system clock as SSI clock source */
    dev(bus)->CC = SSI_SS_IODIV;
    /* and power off the bus again */
    poweroff(bus);

    /* trigger SPI pin configuration */
    spi_init_pins(bus);
}
Пример #15
0
static int chromeec_process_one_event(void)
{
	uint8_t event = google_chromeec_get_event();

	/* Log this event */
	if (IS_ENABLED(CONFIG_ELOG_GSMI) && event)
		elog_add_event_byte(ELOG_TYPE_EC_EVENT, event);

	switch (event) {
	case EC_HOST_EVENT_LID_CLOSED:
		printk(BIOS_DEBUG, "LID CLOSED, SHUTDOWN\n");

		poweroff();
		break;
	}
	return !!event;
}
Пример #16
0
/* check, give feedback and start shutdown after one second */
static void process_shutdown(void)
{
	if (shutdown_timer == 0)
		DPRINTK(KERN_INFO "Shutdown requested...\n");

	shutdown_timer++;
	
	/* wait until the button was pressed for 1 second */
	if (shutdown_timer == HZ) {
#if defined (DEBUG) || defined(CONFIG_CHASSIS_LCD_LED)
		static char msg[] = "Shutting down...";
#endif
		DPRINTK(KERN_INFO "%s\n", msg);
		lcd_print(msg);
		poweroff();
	}
}
Пример #17
0
int load(char *path, long offset) {
    // check for reboot/poweroff
    if (strcasecmp(path, "reboot") == 0) {
        reboot();
    } else if (strcasecmp(path, "shutdown") == 0) {
        poweroff();
    } else {
        const char *ext = get_filename_ext(path);
        if (strcasecmp(ext, "bin") == 0
            || strcasecmp(ext, "dat") == 0) {
            return load_bin(path, offset);
        } else if (strcasecmp(ext, "3dsx") == 0) {
            return load_3dsx(path);
        } else {
            debug("Invalid file: %s\n", path);
            return -1;
        }
    }
    return 0;
}
Пример #18
0
int PortableTester::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QMainWindow::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: startFG(); break;
        case 1: buttonPressed((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 2: poweroff(); break;
        case 3: houseKeeping(); break;
        case 4: UnHide(); break;
        case 5: checkButton(); break;
        case 6: idleScreen(); break;
        case 7: slotAcceptUserLogin((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        default: ;
        }
        _id -= 8;
    }
    return _id;
}
Пример #19
0
__dead void
arch_shutdown(int how)
{

	if((how & RB_POWERDOWN) == RB_POWERDOWN) {
		/* Power off if possible, hang otherwise */
		poweroff();
		NOT_REACHABLE;
	}

	if(how & RB_HALT) {
		/* Hang */
		for (; ; ) halt_cpu();
		NOT_REACHABLE;
	}

	/* Reset the system */
	reset();
	NOT_REACHABLE;

	while (1);
}
Пример #20
0
static void
wpirecover(void *arg)
{
	Ether *edev;
	Ctlr *ctlr;

	edev = arg;
	ctlr = edev->ctlr;
	while(waserror())
		;
	for(;;){
		tsleep(&up->sleep, return0, 0, 4000);

		qlock(ctlr);
		for(;;){
			if(ctlr->broken == 0)
				break;

			if(ctlr->power)
				poweroff(ctlr);

			if((csr32r(ctlr, Gpc) & RfKill) == 0)
				break;

			if(reset(ctlr) != nil)
				break;
			if(boot(ctlr) != nil)
				break;

			ctlr->bcastnodeid = -1;
			ctlr->bssnodeid = -1;
			ctlr->aid = 0;
			rxon(edev, ctlr->wifi->bss);
			break;
		}
		qunlock(ctlr);
	}
}
Пример #21
0
__dead void
arch_shutdown(int how)
{
	switch (how) {
	case RBT_HALT:
		/* Hang */
		for (; ; ) halt_cpu();
		NOT_REACHABLE;

	case RBT_POWEROFF:
		/* Power off if possible, hang otherwise */
		poweroff();
		NOT_REACHABLE;

	default:
	case RBT_DEFAULT:
	case RBT_REBOOT:
	case RBT_RESET:
		/* Reset the system */
		reset();
		NOT_REACHABLE;
	}
	while (1);
}
void test_gprs(void)
{
  rt_bool_t res = RT_TRUE; 
  res = sysconfig(); if(!res) return;
  
  res = poweron(); if(!res) return;
  rt_thread_delay(2000);
  
  res = gprsinit(); if(!res) return;
  
  res = msgsend("abc"); if(!res) return;
  res = msgreaddata(); if(!res) return;
 
  res = gprsconnect(); if(!res) return;
  res = gprssend("abc"); if(!res) return;
  res = gprsread();   if(!res) return;
  
  res = gprstp(); if(!res) return;
  res = gprstpoff(); if(!res) return;
  
  res = closeconnect(); if(!res) return;
  
  poweroff(); 
}
Пример #23
0
void spi_init(spi_t bus)
{
    /* make sure given bus is good */
    assert(bus < SPI_NUMOF);

    /* initialize the device lock */
    mutex_init(&locks[bus]);

    /* configure pins and their muxes */
    spi_init_pins(bus);

    /* wake up device */
    poweron(bus);

    /* reset all device configuration */
    dev(bus)->CTRLA.reg |= SERCOM_SPI_CTRLA_SWRST;
    while ((dev(bus)->CTRLA.reg & SERCOM_SPI_CTRLA_SWRST) ||
           (dev(bus)->SYNCBUSY.reg & SERCOM_SPI_SYNCBUSY_SWRST));

    /* configure base clock: using GLK GEN 0 */
#if defined(CPU_FAM_SAMD21)
    GCLK->CLKCTRL.reg = (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 |
                         (SERCOM0_GCLK_ID_CORE + sercom_id(dev(bus))));
    while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY) {}
#elif defined(CPU_FAM_SAML21)
    GCLK->PCHCTRL[SERCOM0_GCLK_ID_CORE + sercom_id(dev(bus))].reg =
                                (GCLK_PCHCTRL_CHEN | GCLK_PCHCTRL_GEN_GCLK0);
#endif

    /* enable receiver and configure character size to 8-bit
     * no synchronization needed, as SERCOM device is not enabled */
    dev(bus)->CTRLB.reg = (SERCOM_SPI_CTRLB_CHSIZE(0) | SERCOM_SPI_CTRLB_RXEN);

    /* put device back to sleep */
    poweroff(bus);
}
Пример #24
0
int main(void)
{
	//检查配置文件,关闭系统
	int fd;
	ssize_t rd, wd;
	off_t sk;
	char ch, ch1 = '1', ch0 = '0';

	fd = open("config.txt", O_RDWR);
	if(fd < 0){
		printf("Open config.txt error.\n");
		exit(1);
	}

	rd = read(fd, &ch, 1);
	if(rd < 0){
		printf("Read config.txt error.\n");
		exit(1);
	}
	//配置文件内容为1时继续运行网络监听程序
	if (ch == ch1){
		initconfig();
		sk = lseek(fd, 0L, SEEK_SET);
		if(sk == -1){
			printf("Lseek error.\n");
			close(fd);
			exit(1);
		}
		wd = write(fd, &ch0, 1);
		if(wd < 0){
			printf("Write error.\n");
			close(fd);
			exit(1);
		}
		close(fd);
		runnet();
		return 0;
	}
	//配置文件内容为0时,关闭继电器,执行关机命令
	else if (ch == ch0){
		poweroff();
		sk = lseek(fd, 0L, SEEK_SET);
		if(sk == -1){
			printf("Lseek error.\n");
			close(fd);
			exit(1);
		}
		wd = write(fd, &ch1, 1);
	        if(wd < 0){
        		printf("Write error.\n");
			close(fd);
        		exit(1);
        	}
		if(system("poweroff") < 0){
			printf("Exec error.\n");
			close(fd);
			exit(1);
		}
		close(fd);
		return 0;
	}

	return 0;
}
Пример #25
0
static void
check_shutdown(time_t *now, hrtime_t *hr_now)
{
	int		tod_fd = -1;
	int		kbd, mouse, system, least_idle, idlecheck_time;
	int		next_time;
	int		s, f;
	struct tm	tmp_time;
	time_t		start_of_day, time_since_last_resume;
	time_t		wakeup_time;
	extern long	conskbd_idle_time(void);
	extern long	consms_idle_time(void);
	static int	warned_kbd, warned_ms; /* print error msg one time */

	if (!autoshutdown_en) {
		shutdown_time = 0;
		return;
	}

	(void) localtime_r(now, &tmp_time);
	tmp_time.tm_sec = 0;
	tmp_time.tm_min = 0;
	tmp_time.tm_hour = 0;
	start_of_day = mktime(&tmp_time);
	s = start_of_day + info->pd_start_time * 60;
	f = start_of_day + info->pd_finish_time * 60;
	if ((s < f && *now >= s && *now < f) ||
	    (s >= f && (*now < f || *now >= s))) {
		if ((mouse = (int)consms_idle_time()) < 0) {
			if (! warned_ms) {
				warned_ms = 1;
				logerror("powerd: failed to get "
				    "idle time for console mouse");
			}
			return;
		}
		if ((kbd = (int)conskbd_idle_time()) < 0) {
			if (! warned_kbd) {
				warned_kbd = 1;
				logerror("powerd: failed to get "
				    "idle time for console keyboard");
			}
			return;
		}

		system = last_system_activity(hr_now);
		/* who is the last to go idle */
		least_idle = MIN(system, MIN(kbd, mouse));

		/*
		 * Calculate time_since_last_resume and the next_time
		 * to auto suspend.
		 */
		start_calc = 1;
		time_since_last_resume = time(NULL) - last_resume;
		next_time = info->pd_idle_time * 60 -
				MIN(least_idle, time_since_last_resume);

#ifdef DEBUG
		fprintf(stderr, " check_shutdown: next_time=%d\n",
			next_time);
#endif

		/*
		 * If we have get the SIGTHAW signal at this point - our
		 * calculation of time_since_last_resume is wrong  so
		 * - we need to recalculate.
		 */
		while (start_calc == 0) {
			/* need to redo calculation */
			start_calc = 1;
			time_since_last_resume = time(NULL) - last_resume;
			next_time = info->pd_idle_time * 60 -
				MIN(least_idle, time_since_last_resume);
		}

		/*
		 * Only when everything else is idle, run the user's idlecheck
		 * script.
		 */
		if (next_time <= 0 && do_idlecheck) {
			got_sighup = 0;
			idlecheck_time = run_idlecheck();
			next_time = info->pd_idle_time * 60 -
				MIN(idlecheck_time, MIN(least_idle,
				time_since_last_resume));
			/*
			 * If we have caught SIGTHAW or SIGHUP, need to
			 * recalculate.
			 */
			while (start_calc == 0 || got_sighup == 1) {
				start_calc = 1;
				got_sighup = 0;
				idlecheck_time = run_idlecheck();
				time_since_last_resume = time(NULL) -
					last_resume;
				next_time = info->pd_idle_time * 60 -
					MIN(idlecheck_time, MIN(least_idle,
					time_since_last_resume));
			}
		}

		if (next_time <= 0) {
			if (is_ok2shutdown(now)) {
				/*
				 * Setup the autowakeup alarm.  Clear it
				 * right after poweroff, just in case if
				 * shutdown doesn't go through.
				 */
				if (info->pd_autoresume)
					tod_fd = open(TOD, O_RDWR);
				if (info->pd_autoresume && tod_fd != -1) {
					wakeup_time = (*now < f) ? f :
							(f + DAYS_TO_SECS);
					/*
					 * A software fix for hardware
					 * bug 1217415.
					 */
					if ((wakeup_time - *now) < 180) {
						logerror(
		"Since autowakeup time is less than 3 minutes away, "
		"autoshutdown will not occur.");
						shutdown_time = *now + 180;
						close(tod_fd);
						return;
					}
					if (ioctl(tod_fd, TOD_SET_ALARM,
							&wakeup_time) == -1) {
						logerror("Unable to program "
							"TOD alarm for "
							"autowakeup.");
						close(tod_fd);
						return;
					}
				}

				(void) poweroff("Autoshutdown",
				    autoshutdown_cmd);

				if (info->pd_autoresume && tod_fd != -1) {
					if (ioctl(tod_fd, TOD_CLEAR_ALARM,
							NULL) == -1)
						logerror("Unable to clear "
						    "alarm in TOD device.");
					close(tod_fd);
				}

				(void) time(now);
				/* wait at least 5 mins */
				shutdown_time = *now +
					((info->pd_idle_time * 60) > 300 ?
					(info->pd_idle_time * 60) : 300);
			} else {
				/* wait 5 mins */
				shutdown_time = *now + 300;
			}
		} else
			shutdown_time = *now + next_time;
	} else if (s < f && *now >= f) {
		shutdown_time = s + DAYS_TO_SECS;
	} else
		shutdown_time = s;
}
Пример #26
0
void run()
{
	WSADATA wsa;
	if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
	{
		printf("Init failed");
		exit(-1);
	}

	SOCKET server_fd;

	server_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

	if (server_fd == INVALID_SOCKET)
	{
		printf("Invalid socket");
		exit(-1);
	}

	struct sockaddr_in server_addr;
	int port = 56789;
	memset(&server_addr, 0, sizeof(struct sockaddr_in));
	server_addr.sin_family = AF_INET;
	server_addr.sin_addr.s_addr = INADDR_ANY;
	server_addr.sin_port = htons(port);

	if (bind(server_fd, (struct sockaddr*)&server_addr, sizeof(server_addr)) == SOCKET_ERROR)
	{
		printf("Socket bind error");
		exit(-1);
	}

	if (listen(server_fd, SOMAXCONN) == SOCKET_ERROR)
	{
		printf("Socket execute error");
		exit(-1);
	}

	char hostname[255];
	char *ip;
	char *local = "*";
	struct hostent *hostinfo;
	if (gethostname(hostname, sizeof(hostname)) == 0)
	{
		if ((hostinfo = gethostbyname(hostname)) != NULL)
		{
			ip = inet_ntoa(*(struct in_addr *)*hostinfo->h_addr_list);
		}
		else
		{			
			ip = local;
		}
	}
	else
	{
		ip = local;
	}

	printf("Server is listening on %s:%d\n", ip, port);
	char doccmd[BUF_SIZE];
	sprintf_s(doccmd, BUF_SIZE, "start http://%s:%d/", ip, port);
	//system(doccmd);

	while (true)
	{
		SOCKET client;
		struct sockaddr_in client_addr;
		memset(&client_addr, 0, sizeof(struct sockaddr_in));
		client = accept(server_fd, (struct sockaddr*)&client_addr, 0);
		if (client == INVALID_SOCKET)
		{
			printf("Invalid socket");
		}

		char request[BUF_SIZE];
		char htmlfile[255];

		int receive_rs = recv(client, request, sizeof(request), 0);
		struct req_head head = parse_request_head(request);
		printf("Request: %s\n", head.path);

		if (strcmp(head.path, "/next") == 0)
		{
			play_next();
			strcpy_s(htmlfile, "html/index.html");
		}
		else if (strcmp(head.path, "/prev") == 0)
		{
			play_prev();
			strcpy_s(htmlfile, "html/index.html");
		}
		else if (strcmp(head.path, "/play") == 0)
		{
			play();
			strcpy_s(htmlfile, "html/index.html");
		}
		else if (strcmp(head.path, "/up") == 0)
		{
			volume_up();
			strcpy_s(htmlfile, "html/index.html");
		}
		else if (strcmp(head.path, "/down") == 0)
		{
			volume_down();
			strcpy_s(htmlfile, "html/index.html");
		}
		else if (strcmp(head.path, "/mute") == 0)
		{
			mute();
			strcpy_s(htmlfile, "html/index.html");
		}
		else if (strcmp(head.path, "/shutdown") == 0)
		{
			poweroff();
			strcpy_s(htmlfile, "html/index.html");
		}
		else if (strcmp(head.path, "/") == 0)
		{
			strcpy_s(htmlfile, "html/index.html");
		}	
		else
		{
			strcpyn(htmlfile, head.path, 1, sizeof(head) - 1);
		}

		// 加载要显示的页面
		struct fbuf *html = load_file(htmlfile);
		//printf("Loading file: %s\n", htmlfile);

		char *content;
		if (html == NULL)
		{
			content = (char *)calloc(BUF_SIZE, sizeof(char));
			sprintf_s(content, BUF_SIZE, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: %d\r\n\r\n%s", 22, "<h1>404 NOT FOUND</h1>");
			send(client, content, strlen(content), 0);
		}
		else
		{
			size_t total_size = html->buf_size + 67;
			content = (char *)calloc(total_size, sizeof(char));
			sprintf_s(content, total_size, "HTTP/1.1 200 OK\r\nContent-Type: %s\r\nContent-Length: %d\r\n\r\n", html->mime, html->buf_size * sizeof(char));
			// send head
			send(client, content, strlen(content), 0);

			// send body
			send(client, html->buf, html->buf_size, 0);
		}
		
		free(content);
		free(html);

		closesocket(client);
	}

	closesocket(server_fd);
}
Пример #27
0
static int
wpiinit(Ether *edev)
{
	Ctlr *ctlr;
	char *err;
	uchar b[64];
	int i, j;
	Powergrp *g;

	ctlr = edev->ctlr;
	if((err = poweron(ctlr)) != nil)
		goto Err;
	if((csr32r(ctlr, EepromGp) & 0x6) == 0){
		err = "bad rom signature";
		goto Err;
	}
	/* Clear HW ownership of EEPROM. */
	csr32w(ctlr, EepromGp, csr32r(ctlr, EepromGp) & ~0x180);

	if((err = eepromread(ctlr, b, 1, 0x45)) != nil)
		goto Err;
	ctlr->eeprom.cap = b[0];
	if((err = eepromread(ctlr, b, 2, 0x35)) != nil)
		goto Err;
	ctlr->eeprom.rev = get16(b);
	if((err = eepromread(ctlr, b, 1, 0x4a)) != nil)
		goto Err;
	ctlr->eeprom.type = b[0];
	if((err = eepromread(ctlr, b, 4, 0x60)) != nil)
		goto Err;
	strncpy(ctlr->eeprom.regdom, (char*)b, 4);
	ctlr->eeprom.regdom[4] = '\0';

	print("wpi: %X %X %X %s\n", ctlr->eeprom.cap, ctlr->eeprom.rev, ctlr->eeprom.type, ctlr->eeprom.regdom);

	if((err = eepromread(ctlr, b, 6, 0x15)) != nil)
		goto Err;
	memmove(edev->ea, b, Eaddrlen);

	for(i = 0; i < nelem(bands); i++){
		if((err = eepromread(ctlr, b, 2*bands[i].nchan, bands[i].addr)) != nil)
			goto Err;
		for(j = 0; j < bands[i].nchan; j++){
			if(!(b[j*2] & 1))
				continue;
			ctlr->maxpwr[bands[i].chan[j]] = b[j*2+1];
		}
	}

	for(i = 0; i < nelem(ctlr->eeprom.pwrgrps); i++){
		if((err = eepromread(ctlr, b, 64, 0x100 + i*32)) != nil)
			goto Err;
		g = &ctlr->eeprom.pwrgrps[i];
		g->maxpwr = b[60];
		g->chan = b[61];
		g->temp = get16(b+62);
		for(j = 0; j < 5; j++){
			g->samples[j].index = b[j*4];
			g->samples[j].power = b[j*4+1];
		}
	}

	poweroff(ctlr);
	return 0;
Err:
	print("wpiinit: %s\n", err);
	poweroff(ctlr);
	return -1;
}
Пример #28
0
static void powerfail_interrupt(int code, void *x)
{
	printk(KERN_CRIT "POWERFAIL INTERRUPTION !\n");
	poweroff();
}
Пример #29
0
static char*
reset(Ctlr *ctlr)
{
	uchar rev;
	char *err;
	int i;

	if(ctlr->power)
		poweroff(ctlr);
	if((err = initring(ctlr)) != nil)
		return err;
	if((err = poweron(ctlr)) != nil)
		return err;

	/* Select VMAIN power source. */
	if((err = niclock(ctlr)) != nil)
		return err;
	prphwrite(ctlr, ApmgPs, (prphread(ctlr, ApmgPs) & ~PwrSrcMask) | PwrSrcVMain);
	nicunlock(ctlr);
	/* Spin until VMAIN gets selected. */
	for(i = 0; i < 5000; i++){
		if(csr32r(ctlr, GpioIn) & (1 << 9))
			break;
		delay(10);
	}

	/* Perform adapter initialization. */
	rev = ctlr->pdev->rid;
	if((rev & 0xc0) == 0x40)
		csr32w(ctlr, Cfg, csr32r(ctlr, Cfg) | AlmMb);
	else if(!(rev & 0x80))
		csr32w(ctlr, Cfg, csr32r(ctlr, Cfg) | AlmMm);

	if(ctlr->eeprom.cap == 0x80)
		csr32w(ctlr, Cfg, csr32r(ctlr, Cfg) | SkuMrc);

	if((ctlr->eeprom.rev & 0xf0) == 0xd0)
		csr32w(ctlr, Cfg, csr32r(ctlr, Cfg) | RevD);
	else
		csr32w(ctlr, Cfg, csr32r(ctlr, Cfg) & ~RevD);

	if(ctlr->eeprom.type > 1)
		csr32w(ctlr, Cfg, csr32r(ctlr, Cfg) | TypeB);

	/* Initialize RX ring. */
	if((err = niclock(ctlr)) != nil)
		return err;

	coherence();
	csr32w(ctlr, FhRxBase, PCIWADDR(ctlr->rx.p));
	csr32w(ctlr, FhRxRptrAddr, PCIWADDR(&ctlr->shared->next));
	csr32w(ctlr, FhRxWptr, 0);
	csr32w(ctlr, FhRxConfig,
		FhRxConfigDmaEna |
		FhRxConfigRdrbdEna |
		FhRxConfigWrstatusEna |
		FhRxConfigMaxfrag |
		(Nrxlog << FhRxConfigNrdbShift) |
		FhRxConfigIrqDstHost |
		(1 << FhRxConfigIrqRbthShift));
	USED(csr32r(ctlr, FhRssrTbl));
	csr32w(ctlr, FhRxWptr, (Nrx-1) & ~7);
	nicunlock(ctlr);

	/* Initialize TX rings. */
	if((err = niclock(ctlr)) != nil)
		return err;
	prphwrite(ctlr, AlmSchedMode, 2);
	prphwrite(ctlr, AlmSchedArastat, 1);
	prphwrite(ctlr, AlmSchedTxfact, 0x3f);
	prphwrite(ctlr, AlmSchedBP1, 0x10000);
	prphwrite(ctlr, AlmSchedBP2, 0x30002);
	prphwrite(ctlr, AlmSchedTxf4mf, 4);
	prphwrite(ctlr, AlmSchedTxf5mf, 5);
	csr32w(ctlr, FhTxBase, PCIWADDR(ctlr->shared));
	csr32w(ctlr, FhMsgConfig, 0xffff05a5);
	for(i = 0; i < 6; i++){
		csr32w(ctlr, FhCbbcCtrl+i*8, 0);
		csr32w(ctlr, FhCbbcBase+i*8, 0);
		csr32w(ctlr, FhTxConfig+i*32, 0x80200008);
	}
	nicunlock(ctlr);
	USED(csr32r(ctlr, FhTxBase));

	csr32w(ctlr, UcodeGp1Clr, UcodeGp1RfKill);
	csr32w(ctlr, UcodeGp1Clr, UcodeGp1CmdBlocked);

	ctlr->broken = 0;
	ctlr->wait.m = 0;
	ctlr->wait.w = 0;

	ctlr->ie = Idefmask;
	csr32w(ctlr, Imr, ctlr->ie);
	csr32w(ctlr, Isr, ~0);

	csr32w(ctlr, UcodeGp1Clr, UcodeGp1RfKill);
	csr32w(ctlr, UcodeGp1Clr, UcodeGp1RfKill);

	return nil;
}
Пример #30
0
void shell()
{
	char cmd[256];
	char string[256];
	char *user = kmalloc(24);
	memset(user, 0, strlen(user));

	printf(LNG_USER);
	scanf ("%23s",user);

	while (!strlen(user))
	{		
			printf(LNG_USER);
			scanf ("%s",user);
			printf(LNG_USER_R);
	}
	
	_kclear();
	aalogo();
	printf("\n\n\n\n");

        shell_mess = strlen (user) + 3;
        argc=1;

	for (;;)
	{
	    printf("%s~# ",user);
	    scanf("%254s",cmd);
        
            options (cmd);

		if (strcmp(argv[0], "help") == 0)
		{
			
			printf("Available commands:\n");
			help();
		}

		else if (strcmp(argv[0], "echo") == 0)
		{
			int c;

			for (c=1; c<argc; c++)
			  printf ("%s ", argv[c]);
			printf ("\n");
		}

		else if (strcmp(argv[0], "poweroff") == 0)
		{
			printf("Poweroff..\n");
			poweroff();
		}
		
		else if (strcmp(argv[0], "clear") == 0)
		{
			_kclear();
		}

		else if (strcmp (argv[0], "uname") == 0)
		{
			/*if (argv[2] != " ")
			{
				memmove(argv[2], argv[2]+6, strlen(argv[2]));
			}*/

			if (!(_kstrncmp(argv[1], "-a", 2)) || !(_kstrncmp(argv[1], "--all", 5)))
       		{
			printf("%s %s.%s%s #1 CEST 2009 %s\n",NAME,VERSION,PATCHLEVEL,EXTRAVERSION,cpu_vendor);
			}

			else if (!(_kstrncmp(argv[1], "-r", 2)) || !(_kstrncmp(argv[1], "--rev", 5)))
       		{
			printf("%s.%s%s\n",VERSION,PATCHLEVEL,EXTRAVERSION);
			}

			else if (!(_kstrncmp(argv[1], "-h", 2) ) || !(_kstrncmp(argv[1], "--help", 6)))
       		{
			 	uname_help();
			}
				
			else if (!(_kstrncmp(argv[1], "-i", 2)) || !(_kstrncmp(argv[1], "--info", 6)))
			{
				info();
			}

			if (!(_kstrncmp(argv[1], '\0', 1)))
			{
				printf("%s\n"
				       "For more info about this tool, please do 'uname --help'\n",NAME);
			}


		}

		else if (strcmp(argv[0], "cpuid") == 0)
		{
			struct cpuinfo_generic *sinfo = get_cpuid();

			printf ("----- CPUID Information -----\n");
			printf ("Vendor: %s\n", sinfo->cpu_vendor);
			printf ("Type: %s\n", sinfo->cpu_type);
			free (sinfo);
		}

		else if (strcmp(argv[0], "answer") == 0)
      		{
          		  printf("42\n");			  
			  outportb('4',0xe9);
        	}
		else if (strcmp(argv[0], "sleep") == 0)
		{
			int s;

			if (argv[1]) {
			  s = atoi(argv[1]);
			  if (s != -1)
			    sleep (s);
		 	} else printf ("Missing operand\n");
		}

        else if (strcmp(argv[0], "kmalloc") == 0)
        {
            printf("kmalloc try: ...\n");
            int *b;
            b = (int*) kmalloc(10*sizeof(int));
	    printf("Address obtained: %d\n", b);
            int i = 0;
            while(i<10){
                b[i] = i*2;
                i++;
            }
            i=0;
            while(i<10) {
                printf("b[%d] = %d\n",i, b[i]);
                i++;
            }
            printf("Address of a: %d\n", b);
	  printf("Navigating used list...\n");
          print_heap_list (kheap->used_list);
            free (b);

        }

        else if (strcmp(argv[0], "do_fault") == 0)
    	{  
             printf ("Genero un pagefault scrivendo 10 nella locazione 0xa0000000...\n");
             int *prova;
             prova = (int*)0xa0000000;
             *prova = 10;
              printf ("Contenuto della locazione 0xa0000000 dopo l'intervento dell'handler: %d\n", *prova);
        }

        /*else if (!(_kstrncmp(cmd,"try_heap",8))){
            try_alloc();
        }
        
        else if (!(_kstrncmp(cmd,"free",4))) {
          unsigned int ptr = 425548;
          free((unsigned int*)ptr);
          ptr = 437836;
          free((unsigned int*)ptr);
          ptr=446028;
          free((unsigned int*)ptr);
          printf("Navigating used list...\n");
          print_heap_list (kheap->used_list);
          printf("Navigating free list...\n");
          print_heap_list (kheap->free_list);
          printf("Navigating free nodes...\n");
          print_heap_list (kheap->free_nodes);
        }*/

        else if (strcmp(argv[0], "printmem") == 0) print_heap_list(kheap->used_list);        
	else if (strcmp(argv[0], "date") == 0) date();                
        else if (strcmp(argv[0], "aalogo") == 0) 
		aalogo();
        
        else if (strcmp(argv[0], "credits") == 0)
            {
                _kcolor('\011');
                _kputs("DreamOS Credits\n\n");                
                _kputs("Main Developers:\n");
                _kcolor('\012');
                printf("Shainer - Lisa\n"
                    "Finarfin - Ivan\n\n\n"            
                );
                _kcolor('\011');
                _kputs("Contributors:\n");
                _kcolor('\012');
                _kputs("Osiris\n"
                    "Celeron\n"
		    "Hamcha\n"
                    "m0nt0\n"
                    "and many others (3 or 4 :P)\n\n");
                _kcolor('\007');
            }
        else if (strlen(cmd)>0)
	    {
            printf(LNG_UNKNOWN_CMD " %s\n", argv[0]);            
        }

	memset(string+5, 0, strlen(string));
	memset(cmd, 0, strlen(cmd));

        for (--argc; argc>=0; argc--) {
	  free (argv[argc]);
        }

	}
}