/[rdesktop]/sourceforge.net/trunk/rdesktop/serial.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/serial.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 782 by astrand, Thu Oct 7 13:00:29 2004 UTC revision 801 by astrand, Tue Nov 23 13:29:12 2004 UTC
# Line 3  Line 3 
3  #include <termios.h>  #include <termios.h>
4  #include <strings.h>  #include <strings.h>
5  #include <sys/ioctl.h>  #include <sys/ioctl.h>
6    
7    #ifdef HAVE_SYS_MODEM_H
8    #include <sys/modem.h>
9    #endif
10    #ifdef HAVE_SYS_FILIO_H
11    #include <sys/filio.h>
12    #endif
13    #ifdef HAVE_SYS_STRTIO_H
14    #include <sys/strtio.h>
15    #endif
16    
17  #include "rdesktop.h"  #include "rdesktop.h"
18    
19    #ifdef WITH_DEBUG_SERIAL
20    #define DEBUG_SERIAL(args) printf args;
21    #else
22    #define DEBUG_SERIAL(args)
23    #endif
24    
25  #define FILE_DEVICE_SERIAL_PORT         0x1b  #define FILE_DEVICE_SERIAL_PORT         0x1b
26    
27  #define SERIAL_SET_BAUD_RATE            1  #define SERIAL_SET_BAUD_RATE            1
# Line 75  Line 92 
92  #define SERIAL_EV_EVENT2           0x1000       // Provider specific event 2  #define SERIAL_EV_EVENT2           0x1000       // Provider specific event 2
93    
94  /* Modem Status */  /* Modem Status */
95    #define SERIAL_MS_DTR 0x01
96    #define SERIAL_MS_RTS 0x02
97  #define SERIAL_MS_CTS 0x10  #define SERIAL_MS_CTS 0x10
98  #define SERIAL_MS_DSR 0x20  #define SERIAL_MS_DSR 0x20
99  #define SERIAL_MS_RNG 0x40  #define SERIAL_MS_RNG 0x40
100  #define SERIAL_MS_CAR 0x80  #define SERIAL_MS_CAR 0x80
101    
102    /* Handflow */
103    #define SERIAL_DTR_CONTROL      0x01
104    #define SERIAL_CTS_HANDSHAKE    0x08
105    #define SERIAL_ERROR_ABORT      0x80000000
106    
107    #define SERIAL_XON_HANDSHAKE    0x01
108    #define SERIAL_XOFF_HANDSHAKE   0x02
109    #define SERIAL_DSR_SENSITIVITY  0x40
110    
111    #define SERIAL_CHAR_EOF         0
112    #define SERIAL_CHAR_ERROR       1
113    #define SERIAL_CHAR_BREAK       2
114    #define SERIAL_CHAR_EVENT       3
115    #define SERIAL_CHAR_XON         4
116    #define SERIAL_CHAR_XOFF        5
117    
118  #ifndef CRTSCTS  #ifndef CRTSCTS
119  #define CRTSCTS 0  #define CRTSCTS 0
120  #endif  #endif
121    
122    /* FIONREAD should really do the same thing as TIOCINQ, where it is
123     * not available */
124    #ifndef TIOCINQ
125    #define TIOCINQ FIONREAD
126    #endif
127    
128  extern RDPDR_DEVICE g_rdpdr_device[];  extern RDPDR_DEVICE g_rdpdr_device[];
129    
# Line 189  get_termios(SERIAL_DEVICE * pser_inf, NT Line 229  get_termios(SERIAL_DEVICE * pser_inf, NT
229                          pser_inf->baud_rate = 115200;                          pser_inf->baud_rate = 115200;
230                          break;                          break;
231  #endif  #endif
232    #ifdef B230400
233                    case B230400:
234                            pser_inf->baud_rate = 230400;
235                            break;
236    #endif
237    #ifdef B460800
238                    case B460800:
239                            pser_inf->baud_rate = 460800;
240                            break;
241    #endif
242                  default:                  default:
243                          pser_inf->baud_rate = 0;                          pser_inf->baud_rate = 9600;
244                          break;                          break;
245          }          }
246    
# Line 218  get_termios(SERIAL_DEVICE * pser_inf, NT Line 268  get_termios(SERIAL_DEVICE * pser_inf, NT
268                          break;                          break;
269          }          }
270    
271          pser_inf->rts = (ptermios->c_cflag & CRTSCTS) ? 1 : 0;          if (ptermios->c_cflag & CRTSCTS)
272            {
273                    pser_inf->control = SERIAL_DTR_CONTROL | SERIAL_CTS_HANDSHAKE | SERIAL_ERROR_ABORT;
274            }
275            else
276            {
277                    pser_inf->control = SERIAL_DTR_CONTROL | SERIAL_ERROR_ABORT;
278            }
279    
280            pser_inf->xonoff = SERIAL_DSR_SENSITIVITY;
281            if (ptermios->c_iflag & IXON)
282                    pser_inf->xonoff |= SERIAL_XON_HANDSHAKE;
283    
284            if (ptermios->c_iflag & IXOFF)
285                    pser_inf->xonoff |= SERIAL_XOFF_HANDSHAKE;
286    
287            pser_inf->chars[SERIAL_CHAR_XON] = ptermios->c_cc[VSTART];
288            pser_inf->chars[SERIAL_CHAR_XOFF] = ptermios->c_cc[VSTOP];
289            pser_inf->chars[SERIAL_CHAR_EOF] = ptermios->c_cc[VEOF];
290            pser_inf->chars[SERIAL_CHAR_BREAK] = ptermios->c_cc[VINTR];
291            pser_inf->chars[SERIAL_CHAR_ERROR] = ptermios->c_cc[VKILL];
292    
293          return True;          return True;
294  }  }
# Line 310  set_termios(SERIAL_DEVICE * pser_inf, NT Line 380  set_termios(SERIAL_DEVICE * pser_inf, NT
380                          speed = B115200;                          speed = B115200;
381                          break;                          break;
382  #endif  #endif
383    #ifdef B230400
384                    case 230400:
385                            speed = B115200;
386                            break;
387    #endif
388    #ifdef B460800
389                    case 460800:
390                            speed = B115200;
391                            break;
392    #endif
393                  default:                  default:
394                          speed = B0;                          speed = B9600;
395                          break;                          break;
396          }          }
397    
398    #ifdef CBAUD
399            ptermios->c_cflag &= ~CBAUD;
400            ptermios->c_cflag |= speed;
401    #else
402          /* on systems with separate ispeed and ospeed, we can remember the speed          /* on systems with separate ispeed and ospeed, we can remember the speed
403             in ispeed while changing DTR with ospeed */             in ispeed while changing DTR with ospeed */
404          cfsetispeed(pser_inf->ptermios, speed);          cfsetispeed(pser_inf->ptermios, speed);
405          cfsetospeed(pser_inf->ptermios, pser_inf->dtr ? speed : 0);          cfsetospeed(pser_inf->ptermios, pser_inf->dtr ? speed : 0);
406    #endif
407    
408          ptermios->c_cflag &= ~(CSTOPB | PARENB | PARODD | CSIZE | CRTSCTS);          ptermios->c_cflag &= ~(CSTOPB | PARENB | PARODD | CSIZE | CRTSCTS);
409          switch (pser_inf->stop_bits)          switch (pser_inf->stop_bits)
# Line 326  set_termios(SERIAL_DEVICE * pser_inf, NT Line 411  set_termios(SERIAL_DEVICE * pser_inf, NT
411                  case STOP_BITS_2:                  case STOP_BITS_2:
412                          ptermios->c_cflag |= CSTOPB;                          ptermios->c_cflag |= CSTOPB;
413                          break;                          break;
414                    default:
415                            ptermios->c_cflag &= ~CSTOPB;
416                            break;
417          }          }
418    
419          switch (pser_inf->parity)          switch (pser_inf->parity)
# Line 336  set_termios(SERIAL_DEVICE * pser_inf, NT Line 424  set_termios(SERIAL_DEVICE * pser_inf, NT
424                  case ODD_PARITY:                  case ODD_PARITY:
425                          ptermios->c_cflag |= PARENB | PARODD;                          ptermios->c_cflag |= PARENB | PARODD;
426                          break;                          break;
427                    case NO_PARITY:
428                            ptermios->c_cflag &= ~(PARENB | PARODD);
429                            break;
430          }          }
431    
432          switch (pser_inf->word_length)          switch (pser_inf->word_length)
# Line 354  set_termios(SERIAL_DEVICE * pser_inf, NT Line 445  set_termios(SERIAL_DEVICE * pser_inf, NT
445                          break;                          break;
446          }          }
447    
448    #if 0
449          if (pser_inf->rts)          if (pser_inf->rts)
450                  ptermios->c_cflag |= CRTSCTS;                  ptermios->c_cflag |= CRTSCTS;
451            else
452                    ptermios->c_cflag &= ~CRTSCTS;
453    #endif
454    
455            if (pser_inf->control & SERIAL_CTS_HANDSHAKE)
456            {
457                    ptermios->c_cflag |= CRTSCTS;
458            }
459            else
460            {
461                    ptermios->c_cflag &= ~CRTSCTS;
462            }
463    
464    
465            if (pser_inf->xonoff & SERIAL_XON_HANDSHAKE)
466            {
467                    ptermios->c_iflag |= IXON | IMAXBEL;
468            }
469            if (pser_inf->xonoff & SERIAL_XOFF_HANDSHAKE)
470            {
471                    ptermios->c_iflag |= IXOFF | IMAXBEL;
472            }
473    
474            if ((pser_inf->xonoff & (SERIAL_XOFF_HANDSHAKE | SERIAL_XON_HANDSHAKE)) == 0)
475            {
476                    ptermios->c_iflag &= ~IXON;
477                    ptermios->c_iflag &= ~IXOFF;
478            }
479    
480            ptermios->c_cc[VSTART] = pser_inf->chars[SERIAL_CHAR_XON];
481            ptermios->c_cc[VSTOP] = pser_inf->chars[SERIAL_CHAR_XOFF];
482            ptermios->c_cc[VEOF] = pser_inf->chars[SERIAL_CHAR_EOF];
483            ptermios->c_cc[VINTR] = pser_inf->chars[SERIAL_CHAR_BREAK];
484            ptermios->c_cc[VKILL] = pser_inf->chars[SERIAL_CHAR_ERROR];
485    
486          tcsetattr(serial_fd, TCSANOW, ptermios);          tcsetattr(serial_fd, TCSANOW, ptermios);
487  }  }
# Line 434  serial_create(uint32 device_id, uint32 a Line 560  serial_create(uint32 device_id, uint32 a
560          g_rdpdr_device[device_id].handle = serial_fd;          g_rdpdr_device[device_id].handle = serial_fd;
561    
562          /* some sane information */          /* some sane information */
563          printf("INFO: SERIAL %s to %s\nINFO: speed %u baud, stop bits %u, parity %u, word length %u bits, dtr %u, rts %u\n", g_rdpdr_device[device_id].name, g_rdpdr_device[device_id].local_path, pser_inf->baud_rate, pser_inf->stop_bits, pser_inf->parity, pser_inf->word_length, pser_inf->dtr, pser_inf->rts);          DEBUG_SERIAL(("INFO: SERIAL %s to %s\nINFO: speed %u baud, stop bits %u, parity %u, word length %u bits, dtr %u, rts %u\n", g_rdpdr_device[device_id].name, g_rdpdr_device[device_id].local_path, pser_inf->baud_rate, pser_inf->stop_bits, pser_inf->parity, pser_inf->word_length, pser_inf->dtr, pser_inf->rts));
   
         printf("INFO: use stty to change settings\n");  
564    
 /*      ptermios->c_cflag = B115200 | CRTSCTS | CS8 | CLOCAL | CREAD;  
         ptermios->c_cflag |= CREAD;  
         ptermios->c_lflag |= ICANON;  
         ptermios->c_iflag = IGNPAR | ICRNL;  
   
         tcsetattr(serial_fd, TCSANOW, ptermios);  
 */  
565          pser_inf->ptermios->c_iflag &=          pser_inf->ptermios->c_iflag &=
566                  ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);                  ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
567          pser_inf->ptermios->c_oflag &= ~OPOST;          pser_inf->ptermios->c_oflag &= ~OPOST;
568          pser_inf->ptermios->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);          pser_inf->ptermios->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN | XCASE);
569          pser_inf->ptermios->c_cflag &= ~(CSIZE | PARENB);          pser_inf->ptermios->c_cflag &= ~(CSIZE | PARENB);
570          pser_inf->ptermios->c_cflag |= CS8;          pser_inf->ptermios->c_cflag |= CS8;
571    
572          tcsetattr(serial_fd, TCSANOW, pser_inf->ptermios);          tcsetattr(serial_fd, TCSANOW, pser_inf->ptermios);
573    
574            pser_inf->event_txempty = 0;
575            pser_inf->event_cts = 0;
576            pser_inf->event_dsr = 0;
577            pser_inf->event_rlsd = 0;
578            pser_inf->event_pending = 0;
579    
580          *handle = serial_fd;          *handle = serial_fd;
581    
582          /* all read and writes should be non blocking */          /* all read and writes should be non blocking */
583          if (fcntl(*handle, F_SETFL, O_NONBLOCK) == -1)          if (fcntl(*handle, F_SETFL, O_NONBLOCK) == -1)
584                  perror("fcntl");                  perror("fcntl");
585    
586            pser_inf->read_total_timeout_constant = 5;
587    
588          return STATUS_SUCCESS;          return STATUS_SUCCESS;
589  }  }
590    
# Line 468  serial_close(NTHANDLE handle) Line 594  serial_close(NTHANDLE handle)
594          int i = get_device_index(handle);          int i = get_device_index(handle);
595          if (i >= 0)          if (i >= 0)
596                  g_rdpdr_device[i].handle = 0;                  g_rdpdr_device[i].handle = 0;
597    
598            rdpdr_abort_io(handle, 0, STATUS_TIMEOUT);
599          close(handle);          close(handle);
600          return STATUS_SUCCESS;          return STATUS_SUCCESS;
601  }  }
# Line 478  serial_read(NTHANDLE handle, uint8 * dat Line 606  serial_read(NTHANDLE handle, uint8 * dat
606          long timeout;          long timeout;
607          SERIAL_DEVICE *pser_inf;          SERIAL_DEVICE *pser_inf;
608          struct termios *ptermios;          struct termios *ptermios;
609    #ifdef WITH_DEBUG_SERIAL
610            int bytes_inqueue;
611    #endif
612    
613    
614          timeout = 90;          timeout = 90;
615          pser_inf = get_serial_info(handle);          pser_inf = get_serial_info(handle);
# Line 511  serial_read(NTHANDLE handle, uint8 * dat Line 643  serial_read(NTHANDLE handle, uint8 * dat
643          }          }
644          tcsetattr(handle, TCSANOW, ptermios);          tcsetattr(handle, TCSANOW, ptermios);
645    
646    #ifdef WITH_DEBUG_SERIAL
647            ioctl(handle, TIOCINQ, &bytes_inqueue);
648            DEBUG_SERIAL(("serial_read inqueue: %d expected %d\n", bytes_inqueue, length));
649    #endif
650    
651          *result = read(handle, data, length);          *result = read(handle, data, length);
652    
653          //hexdump(data, *read);  #ifdef WITH_DEBUG_SERIAL
654            DEBUG_SERIAL(("serial_read Bytes %d\n", *result));
655            if (*result > 0)
656                    hexdump(data, *result);
657    #endif
658    
659          return STATUS_SUCCESS;          return STATUS_SUCCESS;
660  }  }
# Line 522  serial_read(NTHANDLE handle, uint8 * dat Line 662  serial_read(NTHANDLE handle, uint8 * dat
662  static NTSTATUS  static NTSTATUS
663  serial_write(NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)  serial_write(NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
664  {  {
665            SERIAL_DEVICE *pser_inf;
666    
667            pser_inf = get_serial_info(handle);
668    
669          *result = write(handle, data, length);          *result = write(handle, data, length);
670    
671            if (*result > 0)
672                    pser_inf->event_txempty = *result;
673    
674            DEBUG_SERIAL(("serial_write length %d, offset %d result %d\n", length, offset, *result));
675    
676          return STATUS_SUCCESS;          return STATUS_SUCCESS;
677  }  }
678    
679  static NTSTATUS  static NTSTATUS
680  serial_device_control(NTHANDLE handle, uint32 request, STREAM in, STREAM out)  serial_device_control(NTHANDLE handle, uint32 request, STREAM in, STREAM out)
681  {  {
 #if 0  
682          int flush_mask, purge_mask;          int flush_mask, purge_mask;
 #endif  
683          uint32 result, modemstate;          uint32 result, modemstate;
684          uint8 immediate;          uint8 immediate;
685          SERIAL_DEVICE *pser_inf;          SERIAL_DEVICE *pser_inf;
# Line 547  serial_device_control(NTHANDLE handle, u Line 695  serial_device_control(NTHANDLE handle, u
695          request >>= 2;          request >>= 2;
696          request &= 0xfff;          request &= 0xfff;
697    
         printf("SERIAL IOCTL %d\n", request);  
   
698          switch (request)          switch (request)
699          {          {
700                  case SERIAL_SET_BAUD_RATE:                  case SERIAL_SET_BAUD_RATE:
701                          in_uint32_le(in, pser_inf->baud_rate);                          in_uint32_le(in, pser_inf->baud_rate);
702                          set_termios(pser_inf, handle);                          set_termios(pser_inf, handle);
703                            DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_BAUD_RATE %d\n",
704                                          pser_inf->baud_rate));
705                          break;                          break;
706                  case SERIAL_GET_BAUD_RATE:                  case SERIAL_GET_BAUD_RATE:
707                          out_uint32_le(out, pser_inf->baud_rate);                          out_uint32_le(out, pser_inf->baud_rate);
708                            DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_BAUD_RATE %d\n",
709                                          pser_inf->baud_rate));
710                          break;                          break;
711                  case SERIAL_SET_QUEUE_SIZE:                  case SERIAL_SET_QUEUE_SIZE:
712                          in_uint32_le(in, pser_inf->queue_in_size);                          in_uint32_le(in, pser_inf->queue_in_size);
713                          in_uint32_le(in, pser_inf->queue_out_size);                          in_uint32_le(in, pser_inf->queue_out_size);
714                            DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_QUEUE_SIZE in %d out %d\n",
715                                          pser_inf->queue_in_size, pser_inf->queue_out_size));
716                          break;                          break;
717                  case SERIAL_SET_LINE_CONTROL:                  case SERIAL_SET_LINE_CONTROL:
718                          in_uint8(in, pser_inf->stop_bits);                          in_uint8(in, pser_inf->stop_bits);
719                          in_uint8(in, pser_inf->parity);                          in_uint8(in, pser_inf->parity);
720                          in_uint8(in, pser_inf->word_length);                          in_uint8(in, pser_inf->word_length);
721                          set_termios(pser_inf, handle);                          set_termios(pser_inf, handle);
722                            DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_LINE_CONTROL stop %d parity %d word %d\n", pser_inf->stop_bits, pser_inf->parity, pser_inf->word_length));
723                          break;                          break;
724                  case SERIAL_GET_LINE_CONTROL:                  case SERIAL_GET_LINE_CONTROL:
725                            DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_LINE_CONTROL\n"));
726                          out_uint8(out, pser_inf->stop_bits);                          out_uint8(out, pser_inf->stop_bits);
727                          out_uint8(out, pser_inf->parity);                          out_uint8(out, pser_inf->parity);
728                          out_uint8(out, pser_inf->word_length);                          out_uint8(out, pser_inf->word_length);
729                          break;                          break;
730                  case SERIAL_IMMEDIATE_CHAR:                  case SERIAL_IMMEDIATE_CHAR:
731                            DEBUG_SERIAL(("serial_ioctl -> SERIAL_IMMEDIATE_CHAR\n"));
732                          in_uint8(in, immediate);                          in_uint8(in, immediate);
733                          serial_write(handle, &immediate, 1, 0, &result);                          serial_write(handle, &immediate, 1, 0, &result);
734                          break;                          break;
735                  case SERIAL_CONFIG_SIZE:                  case SERIAL_CONFIG_SIZE:
736                            DEBUG_SERIAL(("serial_ioctl -> SERIAL_CONFIG_SIZE\n"));
737                          out_uint32_le(out, 0);                          out_uint32_le(out, 0);
738                          break;                          break;
739                  case SERIAL_GET_CHARS:                  case SERIAL_GET_CHARS:
740                          out_uint8s(out, 6);                          DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_CHARS\n"));
741                            out_uint8a(out, pser_inf->chars, 6);
742                          break;                          break;
743                  case SERIAL_SET_CHARS:                  case SERIAL_SET_CHARS:
744                          in_uint8s(in, 6);                          DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_CHARS\n"));
745                            in_uint8a(in, pser_inf->chars, 6);
746    #ifdef WITH_DEBUG_SERIAL
747                            hexdump(pser_inf->chars, 6);
748    #endif
749                            set_termios(pser_inf, handle);
750                          break;                          break;
751                  case SERIAL_GET_HANDFLOW:                  case SERIAL_GET_HANDFLOW:
752                          out_uint32_le(out, 0);                          DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_HANDFLOW\n"));
753                          out_uint32_le(out, 3);  /* Xon/Xoff */                          get_termios(pser_inf, handle);
754                          out_uint32_le(out, 0);                          out_uint32_le(out, pser_inf->control);
755                          out_uint32_le(out, 0);                          out_uint32_le(out, pser_inf->xonoff);   /* Xon/Xoff */
756                            out_uint32_le(out, pser_inf->onlimit);
757                            out_uint32_le(out, pser_inf->offlimit);
758                          break;                          break;
759                  case SERIAL_SET_HANDFLOW:                  case SERIAL_SET_HANDFLOW:
760                          in_uint8s(in, 16);                          in_uint32_le(in, pser_inf->control);
761                            in_uint32_le(in, pser_inf->xonoff);
762                            in_uint32_le(in, pser_inf->onlimit);
763                            in_uint32_le(in, pser_inf->offlimit);
764                            DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_HANDFLOW %x %x %x %x\n",
765                                          pser_inf->control, pser_inf->xonoff, pser_inf->onlimit,
766                                          pser_inf->onlimit));
767                            set_termios(pser_inf, handle);
768                          break;                          break;
769                  case SERIAL_SET_TIMEOUTS:                  case SERIAL_SET_TIMEOUTS:
770                          in_uint8s(in, 20);                          in_uint32(in, pser_inf->read_interval_timeout);
771                            in_uint32(in, pser_inf->read_total_timeout_multiplier);
772                            in_uint32(in, pser_inf->read_total_timeout_constant);
773                            in_uint32(in, pser_inf->write_total_timeout_multiplier);
774                            in_uint32(in, pser_inf->write_total_timeout_constant);
775                            DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_TIMEOUTS read timeout %d %d %d\n",
776                                          pser_inf->read_interval_timeout,
777                                          pser_inf->read_total_timeout_multiplier,
778                                          pser_inf->read_total_timeout_constant));
779                          break;                          break;
780                  case SERIAL_GET_TIMEOUTS:                  case SERIAL_GET_TIMEOUTS:
781                          out_uint8s(out, 20);                          DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_TIMEOUTS read timeout %d %d %d\n",
782                                          pser_inf->read_interval_timeout,
783                                          pser_inf->read_total_timeout_multiplier,
784                                          pser_inf->read_total_timeout_constant));
785    
786                            out_uint32(out, pser_inf->read_interval_timeout);
787                            out_uint32(out, pser_inf->read_total_timeout_multiplier);
788                            out_uint32(out, pser_inf->read_total_timeout_constant);
789                            out_uint32(out, pser_inf->write_total_timeout_multiplier);
790                            out_uint32(out, pser_inf->write_total_timeout_constant);
791                          break;                          break;
792                  case SERIAL_GET_WAIT_MASK:                  case SERIAL_GET_WAIT_MASK:
793                          out_uint32(out, pser_inf->wait_mask);                          DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_WAIT_MASK %X\n",
794                                          pser_inf->wait_mask); out_uint32(out, pser_inf->wait_mask));
795                          break;                          break;
796                  case SERIAL_SET_WAIT_MASK:                  case SERIAL_SET_WAIT_MASK:
797                          in_uint32(in, pser_inf->wait_mask);                          in_uint32(in, pser_inf->wait_mask);
798                            DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_WAIT_MASK %X\n",
799                                          pser_inf->wait_mask));
800                          break;                          break;
801                  case SERIAL_SET_DTR:                  case SERIAL_SET_DTR:
802                            DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_DTR\n"));
803                            ioctl(handle, TIOCMGET, &result);
804                            result |= TIOCM_DTR;
805                            ioctl(handle, TIOCMSET, &result);
806                          pser_inf->dtr = 1;                          pser_inf->dtr = 1;
                         set_termios(pser_inf, handle);  
807                          break;                          break;
808                  case SERIAL_CLR_DTR:                  case SERIAL_CLR_DTR:
809                            DEBUG_SERIAL(("serial_ioctl -> SERIAL_CLR_DTR\n"));
810                            ioctl(handle, TIOCMGET, &result);
811                            result &= ~TIOCM_DTR;
812                            ioctl(handle, TIOCMSET, &result);
813                          pser_inf->dtr = 0;                          pser_inf->dtr = 0;
                         set_termios(pser_inf, handle);  
814                          break;                          break;
815                  case SERIAL_SET_RTS:                  case SERIAL_SET_RTS:
816                            DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_RTS\n"));
817                            ioctl(handle, TIOCMGET, &result);
818                            result |= TIOCM_RTS;
819                            ioctl(handle, TIOCMSET, &result);
820                          pser_inf->rts = 1;                          pser_inf->rts = 1;
                         set_termios(pser_inf, handle);  
821                          break;                          break;
822                  case SERIAL_CLR_RTS:                  case SERIAL_CLR_RTS:
823                            DEBUG_SERIAL(("serial_ioctl -> SERIAL_CLR_RTS\n"));
824                            ioctl(handle, TIOCMGET, &result);
825                            result &= ~TIOCM_RTS;
826                            ioctl(handle, TIOCMSET, &result);
827                          pser_inf->rts = 0;                          pser_inf->rts = 0;
                         set_termios(pser_inf, handle);  
828                          break;                          break;
829                  case SERIAL_GET_MODEMSTATUS:                  case SERIAL_GET_MODEMSTATUS:
830                          modemstate = 0;                          modemstate = 0;
# Line 635  serial_device_control(NTHANDLE handle, u Line 838  serial_device_control(NTHANDLE handle, u
838                                  modemstate |= SERIAL_MS_RNG;                                  modemstate |= SERIAL_MS_RNG;
839                          if (result & TIOCM_CAR)                          if (result & TIOCM_CAR)
840                                  modemstate |= SERIAL_MS_CAR;                                  modemstate |= SERIAL_MS_CAR;
841                            if (result & TIOCM_DTR)
842                                    modemstate |= SERIAL_MS_DTR;
843                            if (result & TIOCM_RTS)
844                                    modemstate |= SERIAL_MS_RTS;
845  #endif  #endif
846                            DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_MODEMSTATUS %X\n", modemstate));
847                          out_uint32_le(out, modemstate);                          out_uint32_le(out, modemstate);
848                          break;                          break;
849                  case SERIAL_GET_COMMSTATUS:                  case SERIAL_GET_COMMSTATUS:
850                          out_uint32_le(out, 0);  /* Errors */                          out_uint32_le(out, 0);  /* Errors */
851                          out_uint32_le(out, 0);  /* Hold reasons */                          out_uint32_le(out, 0);  /* Hold reasons */
852                          out_uint32_le(out, 0);  /* Amount in in queue */  
853                          out_uint32_le(out, 0);  /* Amount in out queue */                          result = 0;
854                            ioctl(handle, TIOCINQ, &result);
855                            out_uint32_le(out, result);     /* Amount in in queue */
856                            if (result)
857                                    DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_COMMSTATUS in queue %d\n",
858                                                  result));
859    
860                            result = 0;
861                            ioctl(handle, TIOCOUTQ, &result);
862                            out_uint32_le(out, result);     /* Amount in out queue */
863                            if (result)
864                                    DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_COMMSTATUS out queue %d\n", result));
865    
866                          out_uint8(out, 0);      /* EofReceived */                          out_uint8(out, 0);      /* EofReceived */
867                          out_uint8(out, 0);      /* WaitForImmediate */                          out_uint8(out, 0);      /* WaitForImmediate */
868                          break;                          break;
 #if 0  
869                  case SERIAL_PURGE:                  case SERIAL_PURGE:
                         printf("SERIAL_PURGE\n");  
870                          in_uint32(in, purge_mask);                          in_uint32(in, purge_mask);
871                          if (purge_mask & 0x04)                          DEBUG_SERIAL(("serial_ioctl -> SERIAL_PURGE purge_mask %X\n", purge_mask));
872                            flush_mask = 0;
873                            if (purge_mask & SERIAL_PURGE_TXCLEAR)
874                                  flush_mask |= TCOFLUSH;                                  flush_mask |= TCOFLUSH;
875                          if (purge_mask & 0x08)                          if (purge_mask & SERIAL_PURGE_RXCLEAR)
876                                  flush_mask |= TCIFLUSH;                                  flush_mask |= TCIFLUSH;
877                          if (flush_mask != 0)                          if (flush_mask != 0)
878                                  tcflush(handle, flush_mask);                                  tcflush(handle, flush_mask);
879                          if (purge_mask & 0x01)                          if (purge_mask & SERIAL_PURGE_TXABORT)
880                                  rdpdr_abort_io(handle, 4, STATUS_CANCELLED);                                  rdpdr_abort_io(handle, 4, STATUS_CANCELLED);
881                          if (purge_mask & 0x02)                          if (purge_mask & SERIAL_PURGE_RXABORT)
882                                  rdpdr_abort_io(handle, 3, STATUS_CANCELLED);                                  rdpdr_abort_io(handle, 3, STATUS_CANCELLED);
883                          break;                          break;
884                  case SERIAL_WAIT_ON_MASK:                  case SERIAL_WAIT_ON_MASK:
885                          /* XXX implement me */                          DEBUG_SERIAL(("serial_ioctl -> SERIAL_WAIT_ON_MASK %X\n",
886                          out_uint32_le(out, pser_inf->wait_mask);                                        pser_inf->wait_mask));
887                            pser_inf->event_pending = 1;
888                            if (serial_get_event(handle, &result))
889                            {
890                                    DEBUG_SERIAL(("WAIT end  event = %x\n", result));
891                                    out_uint32_le(out, result);
892                                    break;
893                            }
894                            return STATUS_PENDING;
895                          break;                          break;
896                  case SERIAL_SET_BREAK_ON:                  case SERIAL_SET_BREAK_ON:
897                          tcsendbreak(serial_fd, 0);                          DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_BREAK_ON\n"));
898                            tcsendbreak(handle, 0);
899                          break;                          break;
900                  case SERIAL_RESET_DEVICE:                  case SERIAL_RESET_DEVICE:
901                            DEBUG_SERIAL(("serial_ioctl -> SERIAL_RESET_DEVICE\n"));
902                            break;
903                  case SERIAL_SET_BREAK_OFF:                  case SERIAL_SET_BREAK_OFF:
904                            DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_BREAK_OFF\n"));
905                            break;
906                  case SERIAL_SET_XOFF:                  case SERIAL_SET_XOFF:
907                            DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_XOFF\n"));
908                            break;
909                  case SERIAL_SET_XON:                  case SERIAL_SET_XON:
910                          /* ignore */                          DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_XON\n"));
911                            tcflow(handle, TCION);
912                          break;                          break;
 #endif  
913                  default:                  default:
914                          unimpl("SERIAL IOCTL %d\n", request);                          unimpl("SERIAL IOCTL %d\n", request);
915                          return STATUS_INVALID_PARAMETER;                          return STATUS_INVALID_PARAMETER;
# Line 683  serial_device_control(NTHANDLE handle, u Line 918  serial_device_control(NTHANDLE handle, u
918          return STATUS_SUCCESS;          return STATUS_SUCCESS;
919  }  }
920    
921    BOOL
922    serial_get_event(NTHANDLE handle, uint32 * result)
923    {
924            int index;
925            SERIAL_DEVICE *pser_inf;
926            int bytes;
927            BOOL ret = False;
928    
929            *result = 0;
930            index = get_device_index(handle);
931            if (index < 0)
932                    return False;
933    
934            pser_inf = (SERIAL_DEVICE *) g_rdpdr_device[index].pdevice_data;
935    
936    
937            ioctl(handle, TIOCINQ, &bytes);
938    
939            if (bytes > 0)
940            {
941                    DEBUG_SERIAL(("serial_get_event Bytes %d\n", bytes));
942                    if (bytes > pser_inf->event_rlsd)
943                    {
944                            pser_inf->event_rlsd = bytes;
945                            if (pser_inf->wait_mask & SERIAL_EV_RLSD)
946                            {
947                                    DEBUG_SERIAL(("Event -> SERIAL_EV_RLSD \n"));
948                                    *result |= SERIAL_EV_RLSD;
949                                    ret = True;
950                            }
951    
952                    }
953    
954                    if ((bytes > 1) && (pser_inf->wait_mask & SERIAL_EV_RXFLAG))
955                    {
956                            DEBUG_SERIAL(("Event -> SERIAL_EV_RXFLAG Bytes %d\n", bytes));
957                            *result |= SERIAL_EV_RXFLAG;
958                            ret = True;
959                    }
960                    if ((pser_inf->wait_mask & SERIAL_EV_RXCHAR))
961                    {
962                            DEBUG_SERIAL(("Event -> SERIAL_EV_RXCHAR Bytes %d\n", bytes));
963                            *result |= SERIAL_EV_RXCHAR;
964                            ret = True;
965                    }
966    
967            }
968            else
969            {
970                    pser_inf->event_rlsd = 0;
971            }
972    
973    
974            ioctl(handle, TIOCOUTQ, &bytes);
975            if ((bytes == 0)
976                && (pser_inf->event_txempty > 0) && (pser_inf->wait_mask & SERIAL_EV_TXEMPTY))
977            {
978    
979                    DEBUG_SERIAL(("Event -> SERIAL_EV_TXEMPTY\n"));
980                    *result |= SERIAL_EV_TXEMPTY;
981                    ret = True;
982            }
983            pser_inf->event_txempty = bytes;
984    
985    
986            ioctl(handle, TIOCMGET, &bytes);
987            if ((bytes & TIOCM_DSR) != pser_inf->event_dsr)
988            {
989                    pser_inf->event_dsr = bytes & TIOCM_DSR;
990                    if (pser_inf->wait_mask & SERIAL_EV_DSR)
991                    {
992                            DEBUG_SERIAL(("event -> SERIAL_EV_DSR %s\n",
993                                          (bytes & TIOCM_DSR) ? "ON" : "OFF"));
994                            *result |= SERIAL_EV_DSR;
995                            ret = True;
996                    }
997            }
998    
999            if ((bytes & TIOCM_CTS) != pser_inf->event_cts)
1000            {
1001                    pser_inf->event_cts = bytes & TIOCM_CTS;
1002                    if (pser_inf->wait_mask & SERIAL_EV_CTS)
1003                    {
1004                            DEBUG_SERIAL((" EVENT-> SERIAL_EV_CTS %s\n",
1005                                          (bytes & TIOCM_CTS) ? "ON" : "OFF"));
1006                            *result |= SERIAL_EV_CTS;
1007                            ret = True;
1008                    }
1009            }
1010    
1011            if (ret)
1012                    pser_inf->event_pending = 0;
1013    
1014            return ret;
1015    }
1016    
1017  /* Read timeout for a given file descripter (device) when adding fd's to select() */  /* Read timeout for a given file descripter (device) when adding fd's to select() */
1018  BOOL  BOOL
1019  serial_get_timeout(NTHANDLE handle, uint32 length, uint32 * timeout, uint32 * itv_timeout)  serial_get_timeout(NTHANDLE handle, uint32 length, uint32 * timeout, uint32 * itv_timeout)

Legend:
Removed from v.782  
changed lines
  Added in v.801

  ViewVC Help
Powered by ViewVC 1.1.26