Exemplo n.º 1
0
void
led_reset()
{
	ledman_cmd(LEDMAN_CMD_RESET, LEDMAN_COM1_RX);
	ledman_cmd(LEDMAN_CMD_RESET, LEDMAN_NVRAM_2);
	ledman_cmd(LEDMAN_CMD_RESET, LEDMAN_VPN);
}
Exemplo n.º 2
0
void
led_flash()
{
	ledman_cmd(LEDMAN_CMD_FLASH, LEDMAN_COM1_RX);
	ledman_cmd(LEDMAN_CMD_FLASH, LEDMAN_NVRAM_2);
	ledman_cmd(LEDMAN_CMD_FLASH, LEDMAN_VPN);
}
Exemplo n.º 3
0
int main (void) {
	
	//static sigset_t sig_mask;
	//int sig_recieved;
   
	struct sigaction sa;

   //sigemptyset(&sig_mask);
   //sigaddset(&sig_mask, SIGUSR1);

	memset(&sa,0,sizeof(struct sigaction));//mcli add
	sa.sa_handler = (void *)userHandler1;
	//mcli del sa.sa_mask = 0; //dont block any signals while this one is working
	sa.sa_flags = SA_RESTART; //restart the signal
	sigaction(SIGUSR1,&sa,NULL);

	ledman_cmd(LEDMAN_CMD_ON, LEDMAN_VPN);
	
	while(1) {
		printf("Waiting for signal\n");
		//sigwait(&sig_mask,&sig_recieved);
		pause();
		printf("signal Recieved\n");
	}
}
Exemplo n.º 4
0
static _INLINE_ void transmit_chars(struct gbatxt_serial *info)
{
    volatile unsigned char	*uartp;

#if defined(CONFIG_LEDMAN)
    ledman_cmd(LEDMAN_CMD_SET, info->line ? LEDMAN_COM2_TX : LEDMAN_COM1_TX);
#endif

    uartp = (volatile unsigned char *) info->addr;

    if ((info->xmit_cnt <= 0) || info->tty->stopped) {
        info->imr &= ~MCFUART_UIR_TXREADY;
        uartp[MCFUART_UIMR] = info->imr;
        return;
    }

    while (uartp[MCFUART_USR] & MCFUART_USR_TXREADY) {
        uartp[MCFUART_UTB] = info->xmit_buf[info->xmit_tail++];
        info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
        info->stats.tx++;
        if (--info->xmit_cnt <= 0)
            break;
    }

    if (info->xmit_cnt < WAKEUP_CHARS)
        gbatxt_sched_event(info, RS_EVENT_WRITE_WAKEUP);
    return;
}
Exemplo n.º 5
0
static void led_pause(void)
{
	unsigned long start = time(0);

#if defined(CONFIG_LEDMAN) && defined(LEDMAN_CMD_SIGNAL)
	ledman_cmd(LEDMAN_CMD_ALT_ON, LEDMAN_ALL); /* all leds on */
	ledman_cmd(LEDMAN_CMD_ON | LEDMAN_CMD_ALTBIT, LEDMAN_ALL); /* all leds on */
	CHECK_FOR_SIG(100000);
	ledman_cmd(LEDMAN_CMD_OFF | LEDMAN_CMD_ALTBIT, LEDMAN_ALL); /* all leds off */
	CHECK_FOR_SIG(100000);
	ledman_cmd(LEDMAN_CMD_ON | LEDMAN_CMD_ALTBIT, cmd_list[current_cmd].led);
	CHECK_FOR_SIG(250000);
#endif

	while (time(0) - start < cmd_list[current_cmd].timeout) {
		CHECK_FOR_SIG(250000);
	}

	block_sig(1);
#if defined(CONFIG_LEDMAN) && defined(LEDMAN_CMD_SIGNAL)
	ledman_cmd(LEDMAN_CMD_ON | LEDMAN_CMD_ALTBIT, LEDMAN_ALL); /* all leds on */
#endif
	(*cmd_list[current_cmd].action)();
	block_sig(0);

	current_cmd = 0;

#if defined(CONFIG_LEDMAN) && defined(LEDMAN_CMD_SIGNAL)
skip_out:
	ledman_cmd(LEDMAN_CMD_RESET | LEDMAN_CMD_ALTBIT, LEDMAN_ALL);
	ledman_cmd(LEDMAN_CMD_ALT_OFF, LEDMAN_ALL); /* all leds on */
#endif
}
Exemplo n.º 6
0
void
led_nite()
{
	fd_set rfds;
	struct timeval tv;
	int n = 0;

	while (1) {
		tv.tv_sec = 0;
		tv.tv_usec = 100000;
		FD_ZERO(&rfds);
		FD_SET(ir_fd, &rfds);
		if (select(ir_fd + 1, &rfds, NULL, NULL, &tv) == 1)
			return;
		ledman_cmd(((1<<n) & 0x204) ? LEDMAN_CMD_ON : LEDMAN_CMD_OFF, LEDMAN_COM1_RX);
		ledman_cmd(((1<<n) & 0x108) ? LEDMAN_CMD_ON : LEDMAN_CMD_OFF, LEDMAN_NVRAM_2);
		ledman_cmd(((1<<n) & 0x090) ? LEDMAN_CMD_ON : LEDMAN_CMD_OFF, LEDMAN_VPN);
		n = (n + 1) % 12;
	}
}
Exemplo n.º 7
0
static _INLINE_ void receive_chars(struct gbatxt_serial *info, struct pt_regs *regs, unsigned short rx)
{
    volatile unsigned char	*uartp;
    struct tty_struct	*tty = info->tty;
    unsigned char		status, ch;

    if (!tty)
        return;

#if defined(CONFIG_LEDMAN)
    ledman_cmd(LEDMAN_CMD_SET, info->line ? LEDMAN_COM2_RX : LEDMAN_COM1_RX);
#endif

    uartp = (volatile unsigned char *) info->addr;

    while ((status = uartp[MCFUART_USR]) & MCFUART_USR_RXREADY) {

        if (tty->flip.count >= TTY_FLIPBUF_SIZE)
            break;

        ch = uartp[MCFUART_URB];
        info->stats.rx++;

#ifdef CONFIG_MAGIC_SYSRQ
        if (gbatxt_console_inited && (info->line == gbatxt_console_port)) {
            if (magic_sysrq_key(ch))
                continue;
        }
#endif

        tty->flip.count++;
        if (status & MCFUART_USR_RXERR)
            uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETERR;
        if (status & MCFUART_USR_RXBREAK) {
            info->stats.rxbreak++;
            *tty->flip.flag_buf_ptr++ = TTY_BREAK;
        } else if (status & MCFUART_USR_RXPARITY) {
            info->stats.rxparity++;
            *tty->flip.flag_buf_ptr++ = TTY_PARITY;
        } else if (status & MCFUART_USR_RXOVERRUN) {
            info->stats.rxoverrun++;
            *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
        } else if (status & MCFUART_USR_RXFRAMING) {
            info->stats.rxframing++;
            *tty->flip.flag_buf_ptr++ = TTY_FRAME;
        } else {
            *tty->flip.flag_buf_ptr++ = 0;
        }
        *tty->flip.char_buf_ptr++ = ch;
    }

    queue_task_irq_off(&tty->flip.tqueue, &tq_timer);
    return;
}
Exemplo n.º 8
0
int main (int argc, char *argv[])
{
  const table_t *cmd, *led;
  int alt = 0;
  const char* myname = argv[0];

  if (argc>=2 && strcmp(argv[1], "-a")==0) {
    argv++;
    argc--;
    alt = LEDMAN_CMD_ALTBIT;
  }
  if (argc != 3 ||
      !(cmd = find(cmds, argv[1])))
    usage(myname);
  if (cmd->value == LEDMAN_CMD_MODE) {
    ledman_cmd(cmd->value, argv[2]);
  }
  else {
    if (!(led = find(leds, argv[2])))
      usage(myname);
    ledman_cmd(cmd->value|alt, led->value);
  }
  return 0;
}
Exemplo n.º 9
0
static unsigned int
ipt_led_target(struct sk_buff **pskb,
	       unsigned int hooknum,
	       const struct net_device *in,
	       const struct net_device *out,
	       const void *targinfo,
	       void *userinfo)
{
	const struct ipt_led_info *ledinfo = targinfo;
	u_int32_t led;

	led = get_led(pskb, ledinfo);
#ifdef CONFIG_LEDMAN
	if (led < LEDMAN_MAX)
		ledman_cmd(LEDMAN_CMD_SET, led);
#endif

	return IPT_CONTINUE;
}
Exemplo n.º 10
0
int main(int argc, char **argv)
{
	/* command line options */
	int c;

	/* function-local options */
	int foreground = FALSE;
	char *pid_file = NULL;

	/* config file */
	char *configFile = NULL;

	/* config file parsing temp strings */
	char tmp[MAX_CONFIG_STRING_SIZE], *tmpstr;

	/* open a connection to the syslog daemon */
	openlog("pptpd", LOG_PID, PPTP_FACILITY);
	syslog(LOG_ERR, "MGR: Config file not found!");

	/* process command line options */
	while (1) {
		int option_index = 0;
#ifdef BCRELAY
		char *optstring = "b:c:de:fhil:o:p:s:t:T:vwC:Dk";
#else
		char *optstring = "c:de:fhil:o:p:s:t:T:vwC:Dk";
#endif

		static struct option long_options[] =
		{
#ifdef BCRELAY
			{"bcrelay", 1, 0, 0},
#endif
			{"conf", 1, 0, 'c'},
			{"debug", 0, 0, 'd'},
			{"ppp", 1, 0, 'e'},
			{"fg", 0, 0, 'f'},
			{"help", 0, 0, 'h'},
			{"noipparam", 0, 0, 'i'},
			{"listen", 1, 0, 'l'},
			{"option", 1, 0, 'o'},
			{"pidfile", 1, 0, 'p'},
			{"speed", 1, 0, 's'},
			{"stimeout", 1, 0, 't'},
			{"ptimeout", 1, 0, 'T'},
			{"version", 0, 0, 'v'},
			{"logwtmp", 0, 0, 'w'},
			{"connections", 1, 0, 'C'},
			{"delegate", 0, 0, 'D'},
			{"keep", 0, 0, 'k'},
			{0, 0, 0, 0}
		};

		c = getopt_long(argc, argv, optstring, long_options, &option_index);
		if (c == -1)
			break;
		/* convert long options to short form */
		if (c == 0)
#ifdef BCRELAY
			c = "bcdefhilopstvwCDk"[option_index];
#else
			c = "cdefhilopstvwCDk"[option_index];
#endif
		switch (c) {
#ifdef BCRELAY
		case 'b': /* --bcrelay */
			if (bcrelay) free(bcrelay);
			bcrelay = strdup(optarg);
			break;
#endif

		case 'l': /* --listen */
			tmpstr = lookup(optarg);
			if (!tmpstr) {
				syslog(LOG_ERR, "MGR: Invalid listening address: %s!", optarg);
				return 1;
			}
			if (bindaddr) free(bindaddr);
			bindaddr = strdup(tmpstr);
			break;

		case 'h': /* --help */
			showusage(argv[0]);
			return 0;

		case 'i': /* --noipparam */
			pptp_noipparam = TRUE;
			break;

		case 'e': /* --ppp */
			if (ppp_binary) free(ppp_binary);
			ppp_binary = strdup(optarg);
			break;

		case 'd': /* --debug */
			pptp_debug = TRUE;
			break;

		case 'f': /* --fg */
			foreground = TRUE;
			break;

		case 'v': /* --version */
			showversion();
			return 0;

		case 'w': /* --logwtmp */
		        pptp_logwtmp = TRUE;
			break;

		case 'C': /* --connections */
		        pptp_connections = atoi(optarg);
			break;

		case 'D': /* --delegate */
		        pptp_delegate = TRUE;
			break;

		case 'o': /* --option */
			if (pppdoptstr) free(pppdoptstr);
			pppdoptstr = strdup(optarg);
			break;

		case 'p': /* --pidfile */
			if (pid_file) free(pid_file);
			pid_file = strdup(optarg);
			break;

		case 's': /* --speed */
			if (speedstr) free(speedstr);
			speedstr = strdup(optarg);
			break;

		case 't': /* --stimeout */
			pptp_stimeout = atoi(optarg);
			break;

		case 'T': /* --stimeout */
			pptp_ptimeout = atoi(optarg);
			break;
		case 'k': /* --keep */
			keep_connections = 1;
			break;

		case 'c': /* --conf */
			{
				FILE *f;
				if (!(f = fopen(optarg, "r"))) {
					syslog(LOG_ERR, "MGR: Config file not found!");
					return 1;
				}
				fclose(f);
				if(configFile) free(configFile);
				configFile = strdup(optarg);
				break;
			}

		default:
			showusage(argv[0]);
			return 1;
		}
	}

	/* Now that we have all the command line args.. lets open the
	 * conf file and add anything else (remembering not to override
	 * anything since the command line has more privilages :-)
	 */

	if (!configFile)
		configFile = strdup(PPTPD_CONFIG_FILE_DEFAULT);

	if (read_config_file(configFile, CONNECTIONS_KEYWORD, tmp) > 0) {
		pptp_connections = atoi(tmp);
		if (pptp_connections <= 0)
			pptp_connections = CONNECTIONS_DEFAULT;
	}

	slot_init(pptp_connections);

	if (!pptp_debug && read_config_file(configFile, DEBUG_KEYWORD, tmp) > 0)
		pptp_debug = TRUE;

#ifdef BCRELAY
	if (!bcrelay && read_config_file(configFile, BCRELAY_KEYWORD, tmp) > 0) 
		bcrelay = strdup(tmp);
#endif

	if (!pptp_stimeout && read_config_file(configFile, STIMEOUT_KEYWORD, tmp) > 0) {
		pptp_stimeout = atoi(tmp);
		if (pptp_stimeout <= 0)
			pptp_stimeout = STIMEOUT_DEFAULT;
	}

	if (!pptp_ptimeout && read_config_file(configFile, PTIMEOUT_KEYWORD, tmp) > 0) {
		pptp_ptimeout = atoi(tmp);
		if (pptp_ptimeout <= 0)
			pptp_ptimeout = PTIMEOUT_DEFAULT;
	}

	if (!pptp_noipparam && read_config_file(configFile, NOIPPARAM_KEYWORD, tmp) > 0) {
		pptp_noipparam = TRUE;
	}

	if (!bindaddr && read_config_file(configFile, LISTEN_KEYWORD, tmp) > 0) {
		tmpstr = lookup(tmp);
		if(!tmpstr) {
			syslog(LOG_ERR, "MGR: Invalid listening address: %s!", tmp);
			return 1;
		}
		bindaddr = strdup(tmpstr);
	}

	if (!speedstr && read_config_file(configFile, SPEED_KEYWORD, tmp) > 0)
		speedstr = strdup(tmp);

	if (!pppdoptstr && read_config_file(configFile, PPPD_OPTION_KEYWORD, tmp) > 0) {
		pppdoptstr = strdup(tmp);
	}

	if (!ppp_binary && read_config_file(configFile, PPP_BINARY_KEYWORD, tmp) > 0) {
		ppp_binary = strdup(tmp);
	}

	if (!pptp_logwtmp && read_config_file(configFile, LOGWTMP_KEYWORD, tmp) > 0) {
		pptp_logwtmp = TRUE;
	}

	if (!pptp_delegate && read_config_file(configFile, DELEGATE_KEYWORD, tmp) > 0) {
		pptp_delegate = TRUE;
	}

	if (read_config_file(configFile, KEEP_KEYWORD, tmp) > 0) {
		keep_connections = TRUE;
	}

	if (!pid_file)
		pid_file = strdup((read_config_file(configFile, PIDFILE_KEYWORD,
					tmp) > 0) ? tmp : PIDFILE_DEFAULT);

	if (!pptp_delegate) {
		/* NOTE: remote then local, reason can be seen at the end of processIPStr */

		/* grab the remoteip string from the config file */
		if (read_config_file(configFile, REMOTEIP_KEYWORD, tmp) <= 0) {
			/* use "smart" defaults */
			strlcpy(tmp, DEFAULT_REMOTE_IP_LIST, sizeof(tmp));
		}
		processIPStr(REMOTE, tmp);
	
		/* grab the localip string from the config file */
		if (read_config_file(configFile, LOCALIP_KEYWORD, tmp) <= 0) {
			/* use "smart" defaults */
			strlcpy(tmp, DEFAULT_LOCAL_IP_LIST, sizeof(tmp));
		}
		processIPStr(LOCAL, tmp);
	}

	free(configFile);

	/* if not yet set, adopt default PPP binary path */
	if (!ppp_binary) ppp_binary = strdup(PPP_BINARY);
	/* check that the PPP binary is executable */
	if (access(ppp_binary, X_OK) < 0) {
		syslog(LOG_ERR, "MGR: PPP binary %s not executable",
		       ppp_binary);
		return 1;
	}
	/* check that the PPP options file is readable */
	if (pppdoptstr && access(pppdoptstr, R_OK) < 0) {
		syslog(LOG_ERR, "MGR: PPP options file %s not readable",
		       pppdoptstr);
		return 1;
	}
#ifdef BCRELAY
	/* check that the bcrelay binary is executable */
	if (bcrelay && access(BCRELAY_BIN, X_OK) < 0) {
		syslog(LOG_ERR, "MGR: bcrelay binary %s not executable", 
		       BCRELAY_BIN);
		return 1;
	}
#endif

	syslog(LOG_INFO, "accel-pptpd-%s compiled for pppd-%s\n",VERSION, "2.4.2");

	if (!foreground) {
#if HAVE_DAEMON
		closelog();
		freopen("/dev/null", "r", stdin);
		daemon(0, 0);
		/* returns to child only */
		/* pid will have changed */
		openlog("pptpd", LOG_PID, PPTP_FACILITY);
#else	/* !HAVE_DAEMON */
		my_daemon(argc, argv);
		/* returns to child if !HAVE_FORK
		 * never returns if HAVE_FORK (re-execs with -f)
		 */
#endif
	}

#ifdef BCRELAY
      if (bcrelay) {
             syslog(LOG_DEBUG, "CTRL: BCrelay incoming interface is %s", bcrelay);
             /* Launch BCrelay  */
#ifndef HAVE_FORK
             switch(bcrelayfork = vfork()){
#else
             switch(bcrelayfork = fork()){
#endif
             case -1:        /* fork() error */
                   syslog(LOG_ERR, "CTRL: Error forking to exec bcrelay");
                   _exit(1);

             case 0:         /* child */
                   syslog(LOG_DEBUG, "CTRL (BCrelay Launcher): Launching BCrelay with pid %i", bcrelayfork);
                   launch_bcrelay();
                   syslog(LOG_ERR, "CTRL (BCrelay Launcher): Failed to launch BCrelay.");
                   _exit(1);
             }
       } /* End bcrelay */
#endif

#ifdef CONFIG_NETtel
	/* turn the NETtel VPN LED on */
	ledman_cmd(LEDMAN_CMD_ON, LEDMAN_VPN);
#endif
	/* after we have our final pid... */
	log_pid(pid_file);

	/* manage connections until SIGTERM */
	pptp_manager(argc, argv);
	
#ifdef BCRELAY
	if (bcrelayfork > 0) {
		syslog(LOG_DEBUG, "CTRL: Closing child BCrelay with pid %i", bcrelayfork);
		kill(bcrelayfork, SIGTERM);
	}
#endif

	slot_free();
	return 0;
}

static void log_pid(char *pid_file) {
        FILE    *f;
        pid_t   pid;

        pid = getpid();
        if ((f = fopen(pid_file, "w")) == NULL) {
                syslog(LOG_ERR, "PPTPD: failed to open(%s), errno=%d\n",
                        pid_file, errno);
                return;
        }
        fprintf(f, "%d\n", pid);
        fclose(f);
}
Exemplo n.º 11
0
void userHandler1(void) {
	ledman_cmd(LEDMAN_CMD_OFF, LEDMAN_VPN);
	sleep(1);
	ledman_cmd(LEDMAN_CMD_ON, LEDMAN_VPN);
}
Exemplo n.º 12
0
static int shutdown_now(int rb_which)
{
    /**
     * Save us some entropy over this event
     */
    logd("entropy", NULL);

    /**
     * Write the current date/time to the RTC
     */
#ifdef CONFIG_USER_HWCLOCK_HWCLOCK
    system("hwclock --systohc --utc");
#elif defined(CONFIG_USER_RTC_M41T11) || defined (CONFIG_USER_RTC_DS1302)
    system("rtc -w");
#else
    /* We need to sleep for just a little to allow the CGI's to finish
     * The RTC commands above already take a little while, so
     * only sleep if we don't have any RTC command to run
     */
    sleep(1);
#endif

    /* Don't kill ourself */
    signal(SIGTERM,SIG_IGN);
    signal(SIGHUP,SIG_IGN);
    setpgrp();

    sync();

#ifdef CONFIG_USER_INIT_INIT
    /* Stop init from respawning daemons */
    kill(1, SIGTSTP);
#endif

    /* Send signals to every process _except_ pid 1 */
    kill(-1, SIGTERM);
    sleep(1);
    sync();

    kill(-1, SIGKILL);
    sleep(1);

#if defined(CONFIG_USER_MOUNT_UMOUNT) || defined (CONFIG_USER_BUSYBOX_UMOUNT)
    system("/bin/umount -a -r");
#endif

    sync();
#if !defined(__UC_LIBC__) && (LINUX_VERSION_CODE <= KERNEL_VERSION(2,2,11))
    {
        extern int bdflush(int func, long data);
        /* bdflush, kupdate not needed for kernels >2.2.11 */
        bdflush(1, 0);
        sync();
    }
#endif

#ifdef CONFIG_LEDMAN
    /* We want to turn off all LEDs, except the POWER LED,
     * so it is clear that we are shut down. Enable the ALT functionality
     * for the POWER LED and then turn all std LEDs off.
     */
    ledman_cmd(LEDMAN_CMD_ALT_ON, LEDMAN_POWER);
    ledman_cmd(LEDMAN_CMD_ON | LEDMAN_CMD_ALTBIT, LEDMAN_POWER);
    ledman_cmd(LEDMAN_CMD_OFF, LEDMAN_ALL);
#endif
#ifdef CONFIG_SNAPDOG
    /* Turn off user servicing of the watchdog */
    write(open("/dev/watchdog", O_WRONLY), "V", 1);
#endif

    init_reboot(rb_which);

    return -1; /* Shrug */
}