int main(void) { halInit(); chSysInit(); initLed(); dacInit(); initAdc(); initRelay(); cpu_io_init(); while (TRUE) { cpu_io_process(); /* DacCfg dac; setLeds( 1 ); dac.dac1 = 0; dac.dac2 = 0; dacSet( &dac ); chThdSleepMilliseconds( 3000 ); setLeds( 2 ); dac.dac1 = 2047; dac.dac2 = 2047; dacSet( &dac ); chThdSleepMilliseconds( 3000 ); setLeds( 4 ); dac.dac1 = 3063; dac.dac2 = 3063; dacSet( &dac ); chThdSleepMilliseconds( 3000 ); setLeds( 4 ); dac.dac1 = 4095; dac.dac2 = 4095; dacSet( &dac ); chThdSleepMilliseconds( 3000 ); */ } return 0; }
/********************************************************************** *%FUNCTION: main *%ARGUMENTS: * argc, argv -- usual suspects *%RETURNS: * EXIT_SUCCESS or EXIT_FAILURE *%DESCRIPTION: * Main program. Options: * -C ifname -- Use interface for PPPoE clients * -S ifname -- Use interface for PPPoE servers * -B ifname -- Use interface for both clients and servers * -n sessions -- Maximum of "n" sessions ***********************************************************************/ int pppoerelay_main(int argc, char *argv[]) { int opt; int nsess = DEFAULT_SESSIONS; struct sigaction sa; int beDaemon = 1; if (getuid() != geteuid() || getgid() != getegid()) { printf( "SECURITY WARNING: pppoe-relay will NOT run suid or sgid. Fix your installation.\n"); exit(1); } openlog("pppoe-relay", LOG_PID, LOG_DAEMON); while((opt = getopt(argc, argv, "hC:S:B:n:i:F")) != -1) { switch(opt) { case 'h': usage(argv[0]); break; case 'F': beDaemon = 0; break; case 'C': addInterface(optarg, 1, 0); break; case 'S': addInterface(optarg, 0, 1); break; case 'B': addInterface(optarg, 1, 1); break; case 'i': if (sscanf(optarg, "%u", &IdleTimeout) != 1) { printf( "Illegal argument to -i: should be -i timeout\n"); exit(EXIT_FAILURE); } CleanPeriod = IdleTimeout / TIMEOUT_DIVISOR; if (CleanPeriod < MIN_CLEAN_PERIOD) CleanPeriod = MIN_CLEAN_PERIOD; break; case 'n': if (sscanf(optarg, "%d", &nsess) != 1) { printf( "Illegal argument to -n: should be -n #sessions\n"); exit(EXIT_FAILURE); } if (nsess < 1 || nsess > 65534) { printf( "Illegal argument to -n: must range from 1 to 65534\n"); exit(EXIT_FAILURE); } break; default: usage(argv[0]); } } #ifdef USE_LINUX_PACKET #ifndef HAVE_STRUCT_SOCKADDR_LL printf( "The PPPoE relay does not work on Linux 2.0 kernels.\n"); exit(EXIT_FAILURE); #endif #endif /* Check that at least two interfaces were defined */ if (NumInterfaces < 2) { printf( "%s: Must define at least two interfaces\n", argv[0]); exit(EXIT_FAILURE); } /* Make a pipe for the cleaner */ if (pipe(CleanPipe) < 0) { fatalSys("pipe"); } /* Set up alarm handler */ sa.sa_handler = alarmHandler; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART; if (sigaction(SIGALRM, &sa, NULL) < 0) { fatalSys("sigaction"); } /* Allocate memory for sessions, etc. */ initRelay(nsess); /* Daemonize -- UNIX Network Programming, Vol. 1, Stevens */ if (beDaemon) { int i; i = fork(); if (i < 0) { fatalSys("fork"); } else if (i != 0) { /* parent */ exit(0); } setsid(); signal(SIGHUP, SIG_IGN); i = fork(); if (i < 0) { fatalSys("fork"); } else if (i != 0) { exit(0); } chdir("/"); closelog(); for (i=0; i<CLOSEFD; i++) { if (!keepDescriptor(i)) { close(i); } } /* We nuked our syslog descriptor... */ openlog("pppoe-relay", LOG_PID, LOG_DAEMON); } /* Kick off SIGALRM if there is an idle timeout */ if (IdleTimeout) alarm(1); /* Enter the relay loop */ relayLoop(); /* Shouldn't ever get here... */ return EXIT_FAILURE; }