Beispiel #1
0
int main(int argc, char *argv[])
{
    static char		*cmdstr = NULL;
    struct cmd_set 		**cmd_set;
    static struct vfs_state vfs;
    int i;
    static char		*filename = NULL;

    /* make sure the vars that get altered (4th field) are in
       a fixed location or certain compilers complain */
    poptContext pc;
    struct poptOption long_options[] = {
        POPT_AUTOHELP
        {"file",	'f', POPT_ARG_STRING,	&filename, 0, },
        {"command",	'c', POPT_ARG_STRING,	&cmdstr, 0, "Execute specified list of commands" },
        POPT_COMMON_SAMBA
        POPT_TABLEEND
    };


    setlinebuf(stdout);

    pc = poptGetContext("vfstest", argc, (const char **) argv,
                        long_options, 0);

    while(poptGetNextOpt(pc) != -1);


    poptFreeContext(pc);

    /* TODO: check output */
    reload_services(False);

    /* the following functions are part of the Samba debugging
       facilities.  See lib/debug.c */
    setup_logging("vfstest", True);

    /* Load command lists */

    cmd_set = vfstest_command_list;

    while(*cmd_set) {
        add_command_set(*cmd_set);
        add_command_set(separator_command);
        cmd_set++;
    }

    /* some basic initialization stuff */
    sec_init();
    conn_init();
    vfs.conn = conn_new();
    string_set(&vfs.conn->user,"vfstest");
    for (i=0; i < 1024; i++)
        vfs.files[i] = NULL;

    /* some advanced initiliazation stuff */
    smbd_vfs_init(vfs.conn);

    /* Do we have a file input? */
    if (filename && filename[0]) {
        process_file(&vfs, filename);
        return 0;
    }

    /* Do anything specified with -c */
    if (cmdstr && cmdstr[0]) {
        char    *cmd;
        char    *p = cmdstr;

        while((cmd=next_command(&p)) != NULL) {
            process_cmd(&vfs, cmd);
        }

        return 0;
    }

    /* Loop around accepting commands */

    while(1) {
        pstring prompt;
        char *line;

        slprintf(prompt, sizeof(prompt) - 1, "vfstest $> ");

        line = smb_readline(prompt, NULL, completion_fn);

        if (line == NULL)
            break;

        if (line[0] != '\n')
            process_cmd(&vfs, line);
    }

    free(vfs.conn);
    return 0;
}
Beispiel #2
0
uint32 UPD765A::read_io8(uint32 addr)
{
	if(addr & 1) {
		// fdc data
		if((status & (S_RQM | S_DIO)) == (S_RQM | S_DIO)) {
			uint8 data;
			status &= ~S_RQM;
			
			switch(phase) {
			case PHASE_RESULT:
				data = *bufptr++;
#ifdef _FDC_DEBUG_LOG
				emu->out_debug_log("FDC: RESULT=%2x\n", data);
#endif
				if(--count) {
					status |= S_RQM;
				} else {
					// EPSON QC-10 CP/M Plus
					bool clear_irq = true;
					if((command & 0x1f) == 0x08) {
						for(int i = 0; i < 4; i++) {
							if(fdc[i].result) {
								clear_irq = false;
								break;
							}
						}
					}
					if(clear_irq) {
						set_irq(false);
					}
					shift_to_idle();
				}
				return data;
				
			case PHASE_READ:
				data = *bufptr++;
#ifdef _FDC_DEBUG_LOG
				emu->out_debug_log("FDC: READ=%2x\n", data);
#endif
				set_drq(false);
				if(--count) {
					REGISTER_DRQ_EVENT();
				} else {
					process_cmd(command & 0x1f);
				}
				fdc[hdu & DRIVE_MASK].access = true;
				return data;
			}
		}
		return 0xff;
	} else {
		// FIXME: dirty patch for PC-8801 Kimochi Disk 2
		if(phase_id != -1 && event_phase == PHASE_EXEC) {
			cancel_event(this, phase_id);
			phase_id = -1;
			phase = event_phase;
			process_cmd(command & 0x1f);
		}
		// fdc status
#ifdef _FDC_DEBUG_LOG
//		emu->out_debug_log(_T("FDC: STATUS=%2x\n"), seekstat | status);
#endif
		return seekstat | status;
	}
}
Beispiel #3
0
static void command_transfer_completed(void* user_data,
                                       unsigned int transferred)
{
        process_cmd((struct cmd_frame_t*) command_buffer);
}
Beispiel #4
0
void UPD765A::write_io8(uint32 addr, uint32 data)
{
	if(addr & 1) {
		// fdc data
		if((status & (S_RQM | S_DIO)) == S_RQM) {
			status &= ~S_RQM;
			
			switch(phase) {
			case PHASE_IDLE:
#ifdef _FDC_DEBUG_LOG
				switch(data & 0x1f) {
				case 0x02:
					emu->out_debug_log("FDC: CMD=%2x READ DIAGNOSTIC\n", data);
					break;
				case 0x03:
					emu->out_debug_log("FDC: CMD=%2x SPECIFY\n", data);
					break;
				case 0x04:
					emu->out_debug_log("FDC: CMD=%2x SENCE DEVSTAT\n", data);
					break;
				case 0x05:
				case 0x09:
					emu->out_debug_log("FDC: CMD=%2x WRITE DATA\n", data);
					break;
				case 0x06:
				case 0x0c:
					emu->out_debug_log("FDC: CMD=%2x READ DATA\n", data);
					break;
				case 0x07:
					emu->out_debug_log("FDC: CMD=%2x RECALIB\n", data);
					break;
				case 0x08:
					emu->out_debug_log("FDC: CMD=%2x SENCE INTSTAT\n", data);
					break;
				case 0x0a:
					emu->out_debug_log("FDC: CMD=%2x READ ID\n", data);
					break;
				case 0x0d:
					emu->out_debug_log("FDC: CMD=%2x WRITE ID\n", data);
					break;
				case 0x0f:
					emu->out_debug_log("FDC: CMD=%2x SEEK\n", data);
					break;
				case 0x11:
				case 0x19:
				case 0x1d:
					emu->out_debug_log("FDC: CMD=%2x SCAN\n", data);
					break;
				default:
					emu->out_debug_log("FDC: CMD=%2x INVALID\n", data);
					break;
				}
#endif
				command = data;
				process_cmd(command & 0x1f);
				break;
				
			case PHASE_CMD:
#ifdef _FDC_DEBUG_LOG
				emu->out_debug_log("FDC: PARAM=%2x\n", data);
#endif
				*bufptr++ = data;
				if(--count) {
					status |= S_RQM;
				} else {
					process_cmd(command & 0x1f);
				}
				break;
				
			case PHASE_WRITE:
#ifdef _FDC_DEBUG_LOG
				emu->out_debug_log("FDC: WRITE=%2x\n", data);
#endif
				*bufptr++ = data;
				set_drq(false);
				if(--count) {
					REGISTER_DRQ_EVENT();
				} else {
					process_cmd(command & 0x1f);
				}
				fdc[hdu & DRIVE_MASK].access = true;
				break;
				
			case PHASE_SCAN:
				if(data != 0xff) {
					if(((command & 0x1f) == 0x11 && *bufptr != data) ||
					   ((command & 0x1f) == 0x19 && *bufptr >  data) ||
					   ((command & 0x1f) == 0x1d && *bufptr <  data)) {
						result &= ~ST2_SH;
					}
				}
				bufptr++;
				set_drq(false);
				if(--count) {
					REGISTER_DRQ_EVENT();
				} else {
					cmd_scan();
				}
				fdc[hdu & DRIVE_MASK].access = true;
				break;
			}
		}
	}
}
Beispiel #5
0
void UPD765A::shift_to_exec()
{
	phase = PHASE_EXEC;
	process_cmd(command & 0x1f);
}
Beispiel #6
0
// Process all bytes in the UART RX ringbuffer ("rxbuf"). This function should be called in the
// main loop. It can be interrupted by a UART RX interrupt, so additional bytes can be added
// into the ringbuffer while this function is running.
void process_rxbuf(void)
{
	// Only process characters if the cmdbuf is clear to be overwritten.
	// If not, wait for the main loop to clear it by processing the user "send" command.	
	if (send_data_avail)
	{
		return;
	}
	
	while (rxbuf_count > 0)
	{
		char input;
		
		// get one char from the ringbuffer and reduce its size without interruption through the UART ISR
		cli();
		input = rxbuf[rxbuf_startpos];
		rxbuf_startpos = (rxbuf_startpos + 1) % RXBUF_LENGTH;
		rxbuf_count--;
		sei();
		
		// process character	
		if (uart_timeout == 0)
		{
			bytes_to_read = bytes_pos = 0;
		}
		
		if (bytes_to_read > bytes_pos)
		{
			if (input == 13)
			{
				bytes_to_read = bytes_pos;
			}
			else if (((input >= 48) && (input <= 57)) || ((input >= 65) && (input <= 70)) || ((input >= 97) && (input <= 102)))
			{
				cmdbuf[bytes_pos] = input;
				bytes_pos++;
				UART_PUTF("*** 0x%x\r\n", hex_to_byte(input));
			}
			else
			{
				UART_PUTS("*** Illegal character. Use only 0..9, a..f, A..F. ***\r\n");
			}
			
			if (bytes_pos == bytes_to_read)
			{
				cmdbuf[bytes_pos] = '\0';
				//led_dbg(1);
				process_cmd();
			}
		}	
		else if (input == 'h')
		{
			UART_PUTS("*** Help ***\r\n");
			UART_PUTS("h..............this help\r\n");
			UART_PUTS("rAA............read EEPROM at hex address AA\r\n");
			UART_PUTS("wAAXX..........write EEPROM at hex address AA to hex value XX\r\n");
			UART_PUTS("x..............enable writing to EEPROM\r\n");
			UART_PUTS("z..............disable writing to EEPROM\r\n");
			UART_PUTS("sKKTT{D}.......Use AES key KK to send a packet with MessageType TT, followed\r\n");
			UART_PUTS("               by all necessary extension header fields and message data D.\r\n");
			UART_PUTS("               Fields are: ReceiverID (RRRR), MessageGroup (GG), MessageID (MM)\r\n");
			UART_PUTS("               AckSenderID (SSSS), AckPacketCounter (PPPPPP), Error (EE).\r\n");
			UART_PUTS("               MessageData (DD) can be 0..17 bytes with bits moved to the left.\r\n");
			UART_PUTS("               End data with ENTER. SenderID, PacketCounter and CRC are automatically added.\r\n");
			UART_PUTS("sKK00RRRRGGMMDD...........Get\r\n");
			UART_PUTS("sKK01RRRRGGMMDD...........Set\r\n");
			UART_PUTS("sKK02RRRRGGMMDD...........SetGet\r\n");
			UART_PUTS("sKK08GGMMDD...............Status\r\n");
			UART_PUTS("sKK09SSSSPPPPPPEE.........Ack\r\n");
			UART_PUTS("sKK0ASSSSPPPPPPEEGGMMDD...AckStatus\r\n");
			UART_PUTS("cKKTT{D}{CRC}..Same as s..., but a CRC32 checksum of the command has to be appended.\r\n");
			UART_PUTS("               If it doesn't match, the command is ignored.\r\n");
		}
		else if (input == 'x')
		{
			enable_write_eeprom = true;
			UART_PUTS("*** Writing to EEPROM is now ENABLED. ***\r\n");
		}
		else if (input == 'z')
		{
			enable_write_eeprom = false;
			UART_PUTS("*** Writing to EEPROM is now DISABLED. ***\r\n");
		}
		else if (input == 'r')
		{
			UART_PUTS("*** Read from EEPROM. Enter address (2 characters). ***\r\n");
			cmdbuf[0] = 'r';
			bytes_to_read = 3;
			bytes_pos = 1;
		}
		else if (input == 'w')
		{
			UART_PUTS("*** Write to EEPROM. Enter address and data (4 characters). ***\r\n");
			cmdbuf[0] = 'w';
			bytes_to_read = 5;
			bytes_pos = 1;
		}
		else if (input == 's')
		{
			UART_PUTS("*** Enter data, finish with ENTER. ***\r\n");
			cmdbuf[0] = 's';
			bytes_to_read = 54; // 2 characters for key nr + 2 characters for MessageType + 16 characters for hdr.ext. + 2*17 characters for data
			bytes_pos = 1;
		}
		else if (input == 'c')
		{
			UART_PUTS("*** Enter data, finish with ENTER. ***\r\n");
			cmdbuf[0] = 'c';
			bytes_to_read = 62; // 2 characters for key nr + 2 characters for MessageType + 16 characters for hdr.ext. + 2*17 characters for data + 8 characters for CRC
			bytes_pos = 1;
		}
		else
		{
			UART_PUTS("*** Character ignored. Press h for help. ***\r\n");
		}
		
		// enable user timeout if waiting for further input
		uart_timeout = bytes_to_read == bytes_pos ? 0 : 255;
	}
}
Beispiel #7
0
static ssize_t sec_write(struct file *filp, const char __user *buf,
			size_t count, loff_t *f_pos)
{
	size_t size, c;
	ssize_t rv = 0;
	struct sec_status *ss = (struct sec_status *) filp->private_data;
	const char __user *ptr = buf;

	pr_debug("count: %d, cmd: %d\n", count, ss->cmd);

	if (mutex_lock_interruptible(&ss->lock))
		return -ERESTARTSYS;

	while (ss->cmd != SEC_CMD_NONE) {

		mutex_unlock(&ss->lock);

		if (filp->f_flags & O_NONBLOCK)
			return -EAGAIN;

		if (wait_event_interruptible(ss->writeq,
		    (ss->cmd == SEC_CMD_NONE)))
			return -ERESTARTSYS;

		if (mutex_lock_interruptible(&ss->lock))
			return -ERESTARTSYS;
	}

	while (count) {
		/*
		* The amount of data we are still expecting to receive before a
		* command can be processed.
		*/
		if (ss->data)
			size = ss->param.length  - (size_t)(ss->ip - ss->data);
		else
			size = sizeof(ss->param) -
					(size_t)(ss->ip - (u8 *)&ss->param);

		c = min(count, size);

		if (copy_from_user(ss->ip, ptr, c)) {
			rv = -EFAULT;
			break;
		}

		ss->ip += c;
		ptr += c;
		count -= c;
		size -= c;

		if (size == 0) {
			if (!ss->data) {
				size = ss->param.length;

				if (size < 0 || size > SEC_MAX_DATA_SIZE) {
					rv = -EFBIG;
					break;
				}

				if (size) {
					/*allocate the buffer*/
					ss->data = kmalloc(size, GFP_KERNEL);
					if (!ss->data) {
						rv = -ENOMEM;
						break;
					}
					/* Continue with the parameter data */
					ss->ip = ss->data;
					continue;
				}
			}
			/* all command data received, process... */
			rv = process_cmd(ss);
			break;
		}
	}

	if (rv < 0) {
		/* Command failed, wake up any pending writers */
		reset_status(ss);
		wake_up_interruptible(&ss->writeq);
	} else
		rv = ptr - buf;

	mutex_unlock(&ss->lock);
	pr_debug("rv: %d\n", rv);
	return rv;
}
Beispiel #8
0
int main( 
   int                 argc, 
   char **             argv )
{
   int                 s;
   struct stat         stbuf;
   struct tms          timer;
   struct timeval      start_time;

   globalPid = getpid();
   strcpy( progname, "ufdbgclient" );

   strcpy( serverName, "localhost" );
   portNum = UFDB_DAEMON_PORT;

   while ((s = getopt(argc, argv, "e:E:NChdrTvql:p:S:t:")) != EOF)
   {
      switch (s) {
      case 'd':
	 UFDBglobalDebug = 1;
	 break;
      case 'e':
	 connectionErrorBehaviour = denyORallow( optarg );	
         break;
      case 'E':
         strcpy( connectErrorRedirect, optarg );
	 break;
      case 'r':
	 debugRedirect = 1;
	 break;
      case 'l':
	 UFDBglobalLogDir = optarg;
	 if (stat( UFDBglobalLogDir, &stbuf ) != 0)
	 {
	    fprintf( stderr, "ufdbgclient: error in -l %s: %s\n", UFDBglobalLogDir, strerror(errno) );
	    exit( 1 );
	 }
	 if (!S_ISDIR(stbuf.st_mode))
	 {
	    fprintf( stderr, "ufdbgclient: %s is not a directory\n", UFDBglobalLogDir );
	    exit( 1 );
	 }
	 break;
      case 'N':
         ufdbGlobalSetLogging( 0 );
	 break;
      case 'C':
	 squidConcurrentInput = 1;
         break;
      case 'p':
         portNum = atoi( optarg );
	 if (portNum < 1)
	 {
	    fprintf( stderr, "ufdbgclient: port number must be > 0\n" );
	    exit( 1 );
	 }
	 break;
      case 'q':
	 be_quiet = 1;
         break;
      case 'v':
	 fprintf( stderr, "ufdbgclient: %s\n", VERSION );
	 exit( 0 );
	 break;
      case 'S':
         strcpy( serverName, optarg );
	 break;
      case 't':
	 timeout = atoi( optarg );
	 if (timeout < 2)
	    timeout = 2;
	 if (timeout > 200)
	    timeout = 200;
         break;
      case 'T':
	 fprintf( stderr, "-T option found.  Going into test mode.\n" );
	 noRedirects = 1;		/* Test mode means noRedirects */
	 break;
      case '?':
      case 'h':
      default:
         client_usage();
	 exit( 0 );
      }
   }

   ufdbSetGlobalErrorLogFile();
   signal( SIGPIPE, SIG_IGN );
   
   s = connect_to_server();

   /* 
    * process one query from the command line ?
    */
   if (optind < argc - 2)
   {
      if (s < 0)
      {
	 int  nbytes;
	 char line[1024];

	 if (connectionErrorBehaviour == UFDB_ALLOW)
	    strcpy( line, "\n" );
	 else
	    sprintf( line, "%s\n", connectErrorRedirect );
	 nbytes = strlen( line );
	 if (fwrite( line, nbytes, 1, stdout ))
	    ;
	 ufdbLogError( "cannot connect to port %d on server %s: %s", 
	               portNum, serverName, strerror(errno) );
	 exit( 1 );
      }
      process_cmd( s, argv[optind], argv[optind+1], argv[optind+2] );
      close( s );
      exit( 0 );
   }

   if (!be_quiet)
   {
      gettimeofday( &start_time, NULL );
      ufdbLogMessage( "ufdbgclient " VERSION " started" );
      UFDBtimerInit( &timer );
   }

   process_input( s );

   if (!be_quiet)
   {
      char cpuusagetxt[200];

      UFDBtimerStop( &timer );
      UFDBtimerPrintString( cpuusagetxt, &timer, "CPU times" );
      gettimeofday( &start_time, NULL );
      ufdbLogMessage( "ufdbgclient " VERSION " finished\n%s", cpuusagetxt );
   }

   close( s );

   exit( 0 );
}