1st improvement of serial.c (Modemstatus etc.)
PATCH 1/1 1st improvement of serial.c (Modemstatus etc.)
Hello,
as I promised I will send QEMU patches even if I don't know about QEMU's patch policy ... Here a more complex one:
serial.c (and vl.h):
(1) sending break
(2) outgoing modem state
(3) incomming modem state
(4) CHECK THIS: support to disable interrupts (a PC feature)
in vl.c (and vl.h):
(1) host serial implementation extended
(2) CHECK THIS: post-processing disabled
(3) the if/else cascade for -net was cleaned-up a little
This patch is sufficent for win2003 to detect and support a smartcard reader like towitoko chipdrive micro.
The driver has still missing features like parity error detection, modem status change interrupts and 16650 support!
Yours Jürgen
Index: vl.c
===================================================================
RCS file: /home/Cvsroot/qemu/vl.c,v
retrieving revision 1.1.1.1
vl.c +70 -13
@@ -1468,9 +1468,11 @@ tty.c_iflag &= ~(IGNBRK |BRKINT |PARMRK |ISTRIP |INLCR |IGNCR |ICRNL |IXON ); - tty.c_oflag |=OPOST ; +// TODO: OPOST clear or set ? +// tty.c_oflag |= OPOST; + tty.c_oflag =0 ; tty.c_lflag &= ~(ECHO |ECHONL |ICANON |IEXTEN |ISIG ); - tty.c_cflag &= ~(CSIZE |PARENB |PARODD |CRTSCTS ); + tty.c_cflag &= ~(CSIZE |PARENB |PARODD |CRTSCTS |CSTOPB );switch (data_bits) {default :case 8 :
@@ -1486,6 +1488,11 @@ tty.c_cflag |=CS5 ;break ; } + +if (stop_bits >1 ) + tty.c_cflag |=CSTOPB ; + tty.c_cflag |=CREAD |CLOCAL ; +switch (parity) {default :case 'N' :
@@ -1516,10 +1523,57 @@case CHR_IOCTL_SERIAL_SET_BREAK : {int enable = *(int *)arg; +#if defined(TIOCSBRK ) && !defined(_WIN32) +// Linux should use TIOCSBRK and TIOCCBRK +if (ioctl (s->fd_in, enable ?TIOCSBRK :TIOCCBRK ) ==0 ) +break ; +// don't care about pending interrupt ... +if (errno ==EINTR ) +break ; +perror ("CHR_IOCTL_SERIAL_SET_BREAK fallback to tcsendbreak()" ); +#endif +// here arg=1 is used and in the linux tty driver the code is: +// send_break(tty, arg ? arg*100 : 250); if (enable)tcsendbreak (s->fd_in,1 ); }break ; + +case CHR_IOCTL_SERIAL_SET_MSTAT : +#if defined(TIOCMBIS ) && !defined(_WIN32) + { +int tiomsk =TIOCM_DTR |TIOCM_RTS ; +int tiobit =0 ; +if ((*(int *)arg) &CHR_IOCTL_SERIAL_DTR ) tiobit |=TIOCM_DTR ; +if ((*(int *)arg) &CHR_IOCTL_SERIAL_RTS ) tiobit |=TIOCM_RTS ; + +if (tiobit !=0 ) +ioctl (s->fd_in,TIOCMBIS , &tiobit); +if (tiobit != tiomsk) { + tiobit = (~tiobit) & tiomsk; +ioctl (s->fd_in,TIOCMBIC , &tiobit); + } + } +#endif +break ; + +case CHR_IOCTL_SERIAL_GET_MSTAT : + { +int tiores =-1 ; +#if defined(TIOCMGET ) && !defined(_WIN32) +int tiobit; +if (ioctl (s->fd_in,TIOCMGET , &tiobit) ==0 ) { + tiores =0 ; +if (tiobit &TIOCM_CTS ) tiores |=CHR_IOCTL_SERIAL_CTS ; +if (tiobit &TIOCM_CAR ) tiores |=CHR_IOCTL_SERIAL_DCD ; +if (tiobit &TIOCM_RNG ) tiores |=CHR_IOCTL_SERIAL_RI ; +if (tiobit &TIOCM_DSR ) tiores |=CHR_IOCTL_SERIAL_DSR ; + } +#endif + *(int *)arg = tiores; + } +break ; +default :return -ENOTSUP ; }
@@ -2620,19 +2674,19 @@ nd->vlan = vlan; nb_nics++; ret =0 ; - }else -if (!strcmp (device,"none" )) { + } +else if (!strcmp (device,"none" )) {/* does nothing. It is needed to signal that no network cards are wanted */ ret =0 ; - } else + }#ifdef CONFIG_SLIRP -if (!strcmp (device,"user" )) { + else if (!strcmp(device, "user")) { ret =net_slirp_init (vlan); - } else + }#endif #ifndef _WIN32 -if (!strcmp (device,"tap" )) { + else if (!strcmp(device, "tap")) {char ifname[64 ];char setup_script[1024 ];int fd;
@@ -2648,8 +2702,8 @@ } ret =net_tap_init (vlan, ifname, setup_script); } - }else -if (!strcmp (device,"socket" )) { + } +else if (!strcmp (device,"socket" )) {if (get_param_value (buf,sizeof (buf),"fd" , p) >0 ) {int fd; fd =strtol (buf,NULL ,0 );
@@ -2666,8 +2720,9 @@fprintf (stderr,"Unknown socket options: %s\n" , p); return -1; } - } else + }#endif + else {fprintf (stderr,"Unknown network device: %s\n" , device);return -1 ;
@@ -3655,7 +3710,7 @@return 0 ; } -QEMUMachine *find_machine (const char *name) +static QEMUMachine *find_machine (const char *name) {QEMUMachine *m;
@@ -3669,7 +3724,7 @@/***********************************************************/ /* main execution loop */ -void gui_update (void *opaque) +static void gui_update (void *opaque) { display_state.dpy_refresh (&display_state);qemu_mod_timer (gui_timer,GUI_REFRESH_INTERVAL +qemu_get_clock (rt_clock));
@@ -3886,6 +3941,8 @@/* real time timers */ qemu_run_timers (&active_timers[QEMU_TIMER_REALTIME ],qemu_get_clock (rt_clock)); + +// TODO: add a timer to check serial lines for Modem-Status-Register changes }static CPUState *cur_cpu;
Index: vl.h
===================================================================
RCS file: /home/Cvsroot/qemu/vl.h,v
retrieving revision 1.1.1.1
vl.h +13 -0
@@ -219,8 +219,21 @@int stop_bits; } QEMUSerialSetParams; +// turn BREAK on/off #define CHR_IOCTL_SERIAL_SET_BREAK 2 +// set modemstatus 1:=DTR 2:=RTS (like the two lower bits in MCR) +#define CHR_IOCTL_SERIAL_SET_MSTAT 8 +#define CHR_IOCTL_SERIAL_DTR 0x01 +#define CHR_IOCTL_SERIAL_RTS 0x02 + +// get modemstatus 0x80:=DCD 0x40:=RI 0x20:=DSR 0x10:=CTS (see MSR) +#define CHR_IOCTL_SERIAL_GET_MSTAT 9 +#define CHR_IOCTL_SERIAL_DCD 0x80 +#define CHR_IOCTL_SERIAL_RI 0x40 +#define CHR_IOCTL_SERIAL_DSR 0x20 +#define CHR_IOCTL_SERIAL_CTS 0x10 +#define CHR_IOCTL_PP_READ_DATA 3#define CHR_IOCTL_PP_WRITE_DATA 4#define CHR_IOCTL_PP_READ_CONTROL 5
Index: hw/serial.c
===================================================================
RCS file: /home/Cvsroot/qemu/hw/serial.c,v
retrieving revision 1.1.1.1
serial.c +47 -9
156 lines not on this page · raw message