Exemple #1
0
void deny_access()
{
	/* 
	 * Store the failed attemps in the EEPROM
	 * in order to prevent circumventing the security by unplugging the
	 * AVR's supply wires...
	 * (Same applies to the remaining wait time, see later.)
	 */
	eeprom_write_byte(WRONG_TRIES, eeprom_read_byte(WRONG_TRIES) + 1);
	
	avr_lcd_clear();
	avr_lcd_puts("Access denied!");
	
	char buf[16];
	snprintf(buf, 16, "%d of %d tries", eeprom_read_byte(WRONG_TRIES), MAX_WRONG_TRIES);
	avr_lcd_set_cursor_pos(AVR_LCD_LINE1 + 0);
	avr_lcd_puts(buf);

	_delay_ms(2000);

	if (eeprom_read_byte(WRONG_TRIES) >= MAX_WRONG_TRIES)
	{
		eeprom_write_word(WAIT_TIMER, LOCKDOWN_WAIT);
		lock_device();
	}	
}
Exemple #2
0
/**
 * Opens connection to device and initiates protocol layer.
 */
GSM_Error GSM_OpenConnection(GSM_StateMachine *s)
{
	GSM_Error error;

	if (s->CurrentConfig->LockDevice) {
		error = lock_device(s, s->CurrentConfig->Device, &(s->LockFile));
		if (error != ERR_NONE) return error;
	}

	/* Irda devices can set now model to some specific and
	 * we don't have to make auto detection later */
	error=s->Device.Functions->OpenDevice(s);
	if (error!=ERR_NONE) {
		if (s->LockFile != NULL)
			unlock_device(s, &(s->LockFile));
		return error;
	}

	s->opened = TRUE;

	error=s->Protocol.Functions->Initialise(s);
	if (error!=ERR_NONE) return error;

	return ERR_NONE;
}
Exemple #3
0
int main()
{
	/* Initialize the peripheria */
	avr_lcd_init();

	DDRD =  B00001111;
	PORTD = B11110000;
	
	DDRC =  B00000001;
	PORTC = B00000000;
	
	/* 
	 * Check if there was some trickery. lock_device() only locks actually
	 * if there's a number of remaining wait time seconds greater than 0.
	 */
	lock_device();
	
	/* 
	 * Accumulate the user's keystrokes in this buffer
	 */
	char keystrokes[sizeof(code)];
	
	wait_for_passcode();
	
	while (1)
	{
		uint8_t row, col;
		if (scan_kb_matrix(&row, &col))
		{
			char c = chars[row][col];
			
			if (c == 'C') /* Clear/Cancel/Correct */
			{
				wait_for_passcode();
			}
			else if (c == '#') /* Enter/OK */
			{
				/* Memcmp returns zero upon equality */
				if (memcmp(code, keystrokes, cursor) || cursor != sizeof(code))
				{
					deny_access();
				}
				else
				{
					grant_access();
				}

				wait_for_passcode();
			}
			else
			{
				keystrokes[cursor++] = c;
				avr_lcd_putc('*');
			}
		}
	}
	
	return 0;
}
Exemple #4
0
/* if a device is dead, use this function to unregister from
   device list.  */
int unregister_device(int i)
{
	IDEV *p;
	if (dev_list.dev[i].active == 0)
		return -1;

	/* 1. clear flags */
	if (clear_in_use_flag_for_device(i))
		return -2;

	p = dev_list.dev[i].idev;

	/* I don't know if it is ok or not. */
	/* TOFIX: how to free a structure with mutex ? */
	lock_device(p);
	idev_lock(p);
	idev_unlock(p);
	unlock_device(p);

	/* 2. shut down daemon thread */
	if (pthread_cancel(dev_list.dev[i].idev->thread_id))
		dm_log(NULL, "\n[VITAL ERROR] thread cancel failed. going on.\n");

	/* 3. remove device structure */
	dev_list.dev_total--;

	dev_list.dev[i].active = 0;
	dev_list.dev[i].during_test = 0;

	idev_release(p);
	dev_list.dev[i].idev = NULL;

	dm_log(NULL, "REMOVED device index %d.", i);

	/* done */
	return 0;
}
static THREAD_FUNC TapeWriteThread(void *dummy)
{
int status;
size_t blen, remain, want, put, nrec;
char *ptr;
OLD_MSGQ_MSG *obuf;
static char *fid = "TapeWriteThread";

    blen = Params->bfact * IDA_BUFSIZ; /* IDA10 OK */
    MUTEX_LOCK(&mp);
        ioerr = 0;
    MUTEX_UNLOCK(&mp);

    while (1) {

        obuf = msgq_get(&Q->obuf, OLD_MSGQ_WAITFOREVER);
        if (!msgq_chkmsg2(fid, obuf)) {
            util_log(1, "%s: corrupt message received", fid);
            ispd_die(MY_MOD_ID + 1);
        }
        nrec = *((size_t *) obuf->data);
        util_log(1, "dumping %ld records to %s", nrec, Params->odev);

        ptr = obuf->data + sizeof(size_t);
        remain = nrec * IDA_BUFSIZ; /* IDA10 OK */

        while (remain > 0) {
            want = remain > blen ? blen : remain;
            nrec = want / IDA_BUFSIZ; /* IDA10 OK */
            do {
                lock_device();
                    put = mtio_write(tp, ptr, want);
                    if (put == want) {
                        MUTEX_LOCK(&Status->lock);
                            Status->output.nrec += nrec;
                            status = Status->output.state;
                        MUTEX_UNLOCK(&Status->lock);
                        ptr += put;
                        if (ioerr) {
                            clear_alarm(ISP_ALARM_IOERR);
                            ioerr = 0;
                        }
                    } else {
                        if (put != 0) {
                            if (++ioerr == 1) {
                                set_alarm(ISP_ALARM_IOERR);
                                util_log(1, "%s: %s",
                                    Params->odev, syserrmsg(errno)
                                );
                            }
                            MUTEX_LOCK(&Status->lock);
                                ++Status->output.err;
                            MUTEX_UNLOCK(&Status->lock);
                            eject_tape(0);
                        }
                    }
                release_device();
                if (put != want) {
                    if (shutting_down()) {
                        complete_shutdown();
                        THREAD_EXIT(0);
                    } else {
                        sleep(5);
                    }
                }
            } while (put != want);
            remain -= put;
        }
        util_log(1, "tape dump completed OK");

        if (shutting_down()) {
            complete_shutdown();
            THREAD_EXIT(0);
        }

        MUTEX_LOCK(&mp);
            if (eject_flag) eject_tape(0);
            eject_flag = 0;
        MUTEX_UNLOCK(&mp);

        msgq_put(&Heap->obuf, obuf);
    }
}
Exemple #6
0
int
main(int argc, const char **argv)
{
	const char *sysname, *speed;
	char sysfile[FILENAME_MAX];
	char deblogname[FILENAME_MAX];
	FILE *f;
	header_p sys, ich, p;
	int i;

	initlog("call");

	if (0 == strcmp(argv[0], "-h")) usage();
	if (argc < 4 || argc > 5) usage();

	gmodem=-1;
	atexit(cleanup);

	sysname = strlwr( dstrdup( argv[1] ));
	if (!strchr(argv[2], '/'))
		snprintf(tty, sizeof(tty), "/dev/%s", argv[2]);
	else
		strcpy(tty, argv[2]);

	speed = argv[3];

	maxtry = 1;
	if (argc > 4)
		maxtry = atoi(argv[4]);

	minireadstat();
	sprintf(deblogname, "%s/" DEBUGLOG_FILE, logdir);
	if(debuglevel>0) {
		deblogfile = fopen(deblogname, "w");
		if (!deblogfile) {
			printf("Ich kann das Logfile nicht oeffnen. "
				"Probiere /dev/null...\n");
			deblogfile = fopen("/dev/null", "w");
			if (!deblogfile) {
				printf("Hmm... - /dev/null "
					"nicht schreibbar??\n");
				return 10;
			}
		}
	} else {
		deblogfile = fopen("/dev/null", "w");
		if (!deblogfile) {
			printf("Arghl! - kann /dev/null "
				"nicht zum Schreiben oeffnen!\n\n");
			return 10;
		}
	}
	sprintf(sysfile, "%s/%s", systemedir, sysname);
	f = fopen(sysfile, "r");
	if (!f) {
		perror(sysfile);
		newlog(ERRLOG, "File <%s> not readable: %s",
			sysfile, strerror(errno));
		return 1;
	}
	sys = rd_para(f);
	fclose(f);

	ich = get_myself();

	for (i=maxtry; i; i--) {
	   if (lock_device(1, tty)) break;
	   fputs(" ... unser Modem ist belegt\n", stderr);
	   sleep(60);
	}
	if (!i) {
		newlog(ERRLOG, "Cannot lock device: %s", tty);
		return 9;
	}

#ifdef LEAVE_CTRL_TTY
	/*
	 * Bisheriges Controlling-TTY verlassen, damit "modem" das neue
	 * wird.
	 */
#ifdef BSD
	setpgrp(0, getpid());	/* set process group id to process id */
#ifdef SIGTTOU
	signal(SIGTTOU, SIG_IGN);
#endif
#ifdef SIGTTIN
	signal(SIGTTIN, SIG_IGN);
#endif
#ifdef SIGTSTP
	signal(SIGTSTP, SIG_IGN);
#endif
#else	/* !BSD */
#if !defined(USE_SETSID) && !defined(USE_SETPGRP)
#error Controlling TTY kann nicht verlassen werden: definieren Sie eine Methode dazu
#endif /* !BSD und keine SysV-Methode definiert */

#ifdef USE_SETSID
#error	Dies funktioniert nicht!
	setsid();
#endif /* USE_SETSID */
#ifdef USE_SETPGRP
	setpgrp();
#endif /* USE_SETPGRP */
#endif /* !BSD */
#endif /* LEAVE_CTRL_TTY */

	gmodem = open(tty,
#if !defined(__NetBSD__)
			O_RDWR | O_NDELAY
#else
			O_RDWR
#endif
		); DMLOG("open modem");
	if (gmodem < 0) {
		newlog(ERRLOG,
			"Can not access device %s: %s", tty, strerror(errno));
		return 10;
	}
#if !defined(__NetBSD__)
	else {
		/* Nonblock abschalten */
		int n;
		n=fcntl(gmodem, F_GETFL, 0);
		(void)fcntl(gmodem, F_SETFL, n & ~O_NDELAY);
	}
#endif
	save_linesettings(gmodem); DMLOG("saving modem parameters");
	set_rawmode(gmodem); DMLOG("set modem to rawmode");
	set_local(gmodem, 1);
	set_speed(gmodem, speed); DMLOG("set modem speed");
#ifdef TIOCSCTTY
	ioctl(gmodem, TIOCSCTTY, NULL);
#endif

	files = 0;
	online_start = 0;
	fprintf(stderr, "Netcall bei %s [%s]\n", sysname, tty);

	fclose(stdin);
	fclose(stdout);
	dup(gmodem); dup(gmodem); DMLOG("dup modem 2x to stdin and stdout");

	if (setjmp(timeout)) {
		newlog(ERRLOG, "ABBRUCH: Timeout");
		lock_device(0, tty);
		anrufdauer();
		if (files) aufraeumen();

		return 11;
	}
	if (setjmp(nocarrier)) {
		if (!auflegen) {
			newlog(ERRLOG, "ABBRUCH: Gegenstelle hat aufgelegt");
		}
		lock_device(0, tty);
		anrufdauer();
		if (files) aufraeumen();

		return auflegen ? 0 : 12;
	}
	signal(SIGHUP, handle_nocarrier);
	signal(SIGALRM, handle_timeout);
	setup_dial_info(ortsnetz, g_int_prefix, g_ovst, NULL);

	p = find(HD_TEL, sys);
	if (!p) {
		newlog(ERRLOG,
			"Keine Telefonnummer fuer %s gefunden",
			sysname);
		return 2;
	}

	anruf(sys, ich, gmodem, maxtry);

	if (online_start) {
		anrufdauer();
	} else {
		fprintf(stderr, "Keine Verbindung hergestellt.\n");
	}

	lock_device(0, tty);
	/* Device ist freigegeben, aber wir warten noch auf das Ende
	   der Importphase, bevor wir zurueckkehren. */
	wait(NULL);
	return 0;
}