/[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 801 by astrand, Tue Nov 23 13:29:12 2004 UTC revision 963 by astrand, Wed Aug 3 10:56:16 2005 UTC
# Line 1  Line 1 
1    /* -*- c-basic-offset: 8 -*-
2       rdesktop: A Remote Desktop Protocol client.
3    
4       Copyright (C) Matthew Chapman 1999-2005
5      
6       This program is free software; you can redistribute it and/or modify
7       it under the terms of the GNU General Public License as published by
8       the Free Software Foundation; either version 2 of the License, or
9       (at your option) any later version.
10      
11       This program is distributed in the hope that it will be useful,
12       but WITHOUT ANY WARRANTY; without even the implied warranty of
13       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14       GNU General Public License for more details.
15    
16       You should have received a copy of the GNU General Public License
17       along with this program; if not, write to the Free Software
18       Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19    */
20  #include <unistd.h>  #include <unistd.h>
21  #include <fcntl.h>  #include <fcntl.h>
22  #include <termios.h>  #include <termios.h>
# Line 77  Line 96 
96  #define SERIAL_PURGE_RXCLEAR 0x00000008  #define SERIAL_PURGE_RXCLEAR 0x00000008
97    
98  /* SERIAL_WAIT_ON_MASK */  /* SERIAL_WAIT_ON_MASK */
99  #define SERIAL_EV_RXCHAR           0x0001       // Any Character received  #define SERIAL_EV_RXCHAR           0x0001       /* Any Character received */
100  #define SERIAL_EV_RXFLAG           0x0002       // Received certain character  #define SERIAL_EV_RXFLAG           0x0002       /* Received certain character */
101  #define SERIAL_EV_TXEMPTY          0x0004       // Transmitt Queue Empty  #define SERIAL_EV_TXEMPTY          0x0004       /* Transmitt Queue Empty */
102  #define SERIAL_EV_CTS              0x0008       // CTS changed state  #define SERIAL_EV_CTS              0x0008       /* CTS changed state */
103  #define SERIAL_EV_DSR              0x0010       // DSR changed state  #define SERIAL_EV_DSR              0x0010       /* DSR changed state */
104  #define SERIAL_EV_RLSD             0x0020       // RLSD changed state  #define SERIAL_EV_RLSD             0x0020       /* RLSD changed state */
105  #define SERIAL_EV_BREAK            0x0040       // BREAK received  #define SERIAL_EV_BREAK            0x0040       /* BREAK received */
106  #define SERIAL_EV_ERR              0x0080       // Line status error occurred  #define SERIAL_EV_ERR              0x0080       /* Line status error occurred */
107  #define SERIAL_EV_RING             0x0100       // Ring signal detected  #define SERIAL_EV_RING             0x0100       /* Ring signal detected */
108  #define SERIAL_EV_PERR             0x0200       // Printer error occured  #define SERIAL_EV_PERR             0x0200       /* Printer error occured */
109  #define SERIAL_EV_RX80FULL         0x0400       // Receive buffer is 80 percent full  #define SERIAL_EV_RX80FULL         0x0400       /* Receive buffer is 80 percent full */
110  #define SERIAL_EV_EVENT1           0x0800       // Provider specific event 1  #define SERIAL_EV_EVENT1           0x0800       /* Provider specific event 1 */
111  #define SERIAL_EV_EVENT2           0x1000       // Provider specific event 2  #define SERIAL_EV_EVENT2           0x1000       /* Provider specific event 2 */
112    
113  /* Modem Status */  /* Modem Status */
114  #define SERIAL_MS_DTR 0x01  #define SERIAL_MS_DTR 0x01
# Line 121  Line 140 
140    
141  /* FIONREAD should really do the same thing as TIOCINQ, where it is  /* FIONREAD should really do the same thing as TIOCINQ, where it is
142   * not available */   * not available */
143  #ifndef TIOCINQ  #if !defined(TIOCINQ) && defined(FIONREAD)
144  #define TIOCINQ FIONREAD  #define TIOCINQ FIONREAD
145  #endif  #endif
146    #if !defined(TIOCOUTQ) && defined(FIONWRITE)
147    #define TIOCOUTQ FIONWRITE
148    #endif
149    
150  extern RDPDR_DEVICE g_rdpdr_device[];  extern RDPDR_DEVICE g_rdpdr_device[];
151    
# Line 500  serial_enum_devices(uint32 * id, char *o Line 522  serial_enum_devices(uint32 * id, char *o
522          char *pos2;          char *pos2;
523          int count = 0;          int count = 0;
524    
525          // skip the first colon          /* skip the first colon */
526          optarg++;          optarg++;
527          while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES)          while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES)
528          {          {
529                  // Init data structures for device                  /* Init data structures for device */
530                  pser_inf = (SERIAL_DEVICE *) xmalloc(sizeof(SERIAL_DEVICE));                  pser_inf = (SERIAL_DEVICE *) xmalloc(sizeof(SERIAL_DEVICE));
531                  pser_inf->ptermios = (struct termios *) xmalloc(sizeof(struct termios));                  pser_inf->ptermios = (struct termios *) xmalloc(sizeof(struct termios));
532                  memset(pser_inf->ptermios, 0, sizeof(struct termios));                  memset(pser_inf->ptermios, 0, sizeof(struct termios));
# Line 520  serial_enum_devices(uint32 * id, char *o Line 542  serial_enum_devices(uint32 * id, char *o
542                  strcpy(g_rdpdr_device[*id].local_path, pos2);                  strcpy(g_rdpdr_device[*id].local_path, pos2);
543                  printf("SERIAL %s to %s\n", g_rdpdr_device[*id].name,                  printf("SERIAL %s to %s\n", g_rdpdr_device[*id].name,
544                         g_rdpdr_device[*id].local_path);                         g_rdpdr_device[*id].local_path);
545                  // set device type                  /* set device type */
546                  g_rdpdr_device[*id].device_type = DEVICE_TYPE_SERIAL;                  g_rdpdr_device[*id].device_type = DEVICE_TYPE_SERIAL;
547                  g_rdpdr_device[*id].pdevice_data = (void *) pser_inf;                  g_rdpdr_device[*id].pdevice_data = (void *) pser_inf;
548                  count++;                  count++;
# Line 556  serial_create(uint32 device_id, uint32 a Line 578  serial_create(uint32 device_id, uint32 a
578                  return STATUS_ACCESS_DENIED;                  return STATUS_ACCESS_DENIED;
579          }          }
580    
581          // Store handle for later use          /* Store handle for later use */
582          g_rdpdr_device[device_id].handle = serial_fd;          g_rdpdr_device[device_id].handle = serial_fd;
583    
584          /* some sane information */          /* some sane information */
# Line 565  serial_create(uint32 device_id, uint32 a Line 587  serial_create(uint32 device_id, uint32 a
587          pser_inf->ptermios->c_iflag &=          pser_inf->ptermios->c_iflag &=
588                  ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);                  ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
589          pser_inf->ptermios->c_oflag &= ~OPOST;          pser_inf->ptermios->c_oflag &= ~OPOST;
590          pser_inf->ptermios->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN | XCASE);          pser_inf->ptermios->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
591          pser_inf->ptermios->c_cflag &= ~(CSIZE | PARENB);          pser_inf->ptermios->c_cflag &= ~(CSIZE | PARENB);
592          pser_inf->ptermios->c_cflag |= CS8;          pser_inf->ptermios->c_cflag |= CS8;
593    
# Line 615  serial_read(NTHANDLE handle, uint8 * dat Line 637  serial_read(NTHANDLE handle, uint8 * dat
637          pser_inf = get_serial_info(handle);          pser_inf = get_serial_info(handle);
638          ptermios = pser_inf->ptermios;          ptermios = pser_inf->ptermios;
639    
640          // Set timeouts kind of like the windows serial timeout parameters. Multiply timeout          /* Set timeouts kind of like the windows serial timeout parameters. Multiply timeout
641          // with requested read size             with requested read size */
642          if (pser_inf->read_total_timeout_multiplier | pser_inf->read_total_timeout_constant)          if (pser_inf->read_total_timeout_multiplier | pser_inf->read_total_timeout_constant)
643          {          {
644                  timeout =                  timeout =
# Line 628  serial_read(NTHANDLE handle, uint8 * dat Line 650  serial_read(NTHANDLE handle, uint8 * dat
650                  timeout = (pser_inf->read_interval_timeout * length + 99) / 100;                  timeout = (pser_inf->read_interval_timeout * length + 99) / 100;
651          }          }
652    
653          // If a timeout is set, do a blocking read, which times out after some time.          /* If a timeout is set, do a blocking read, which times out after some time.
654          // It will make rdesktop less responsive, but it will improve serial performance, by not             It will make rdesktop less responsive, but it will improve serial performance, by not
655          // reading one character at a time.             reading one character at a time. */
656          if (timeout == 0)          if (timeout == 0)
657          {          {
658                  ptermios->c_cc[VTIME] = 0;                  ptermios->c_cc[VTIME] = 0;
# Line 643  serial_read(NTHANDLE handle, uint8 * dat Line 665  serial_read(NTHANDLE handle, uint8 * dat
665          }          }
666          tcsetattr(handle, TCSANOW, ptermios);          tcsetattr(handle, TCSANOW, ptermios);
667    
668  #ifdef WITH_DEBUG_SERIAL  #if defined(WITH_DEBUG_SERIAL) && defined(TIOCINQ)
669          ioctl(handle, TIOCINQ, &bytes_inqueue);          ioctl(handle, TIOCINQ, &bytes_inqueue);
670          DEBUG_SERIAL(("serial_read inqueue: %d expected %d\n", bytes_inqueue, length));          DEBUG_SERIAL(("serial_read inqueue: %d expected %d\n", bytes_inqueue, length));
671  #endif  #endif
# Line 791  serial_device_control(NTHANDLE handle, u Line 813  serial_device_control(NTHANDLE handle, u
813                          break;                          break;
814                  case SERIAL_GET_WAIT_MASK:                  case SERIAL_GET_WAIT_MASK:
815                          DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_WAIT_MASK %X\n",                          DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_WAIT_MASK %X\n",
816                                        pser_inf->wait_mask); out_uint32(out, pser_inf->wait_mask));                                        pser_inf->wait_mask));
817                            out_uint32(out, pser_inf->wait_mask);
818                          break;                          break;
819                  case SERIAL_SET_WAIT_MASK:                  case SERIAL_SET_WAIT_MASK:
820                          in_uint32(in, pser_inf->wait_mask);                          in_uint32(in, pser_inf->wait_mask);
# Line 851  serial_device_control(NTHANDLE handle, u Line 874  serial_device_control(NTHANDLE handle, u
874                          out_uint32_le(out, 0);  /* Hold reasons */                          out_uint32_le(out, 0);  /* Hold reasons */
875    
876                          result = 0;                          result = 0;
877    #ifdef TIOCINQ
878                          ioctl(handle, TIOCINQ, &result);                          ioctl(handle, TIOCINQ, &result);
879    #endif
880                          out_uint32_le(out, result);     /* Amount in in queue */                          out_uint32_le(out, result);     /* Amount in in queue */
881                          if (result)                          if (result)
882                                  DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_COMMSTATUS in queue %d\n",                                  DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_COMMSTATUS in queue %d\n",
883                                                result));                                                result));
884    
885                          result = 0;                          result = 0;
886    #ifdef TIOCOUTQ
887                          ioctl(handle, TIOCOUTQ, &result);                          ioctl(handle, TIOCOUTQ, &result);
888    #endif
889                          out_uint32_le(out, result);     /* Amount in out queue */                          out_uint32_le(out, result);     /* Amount in out queue */
890                          if (result)                          if (result)
891                                  DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_COMMSTATUS out queue %d\n", result));                                  DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_COMMSTATUS out queue %d\n", result));
# Line 931  serial_get_event(NTHANDLE handle, uint32 Line 958  serial_get_event(NTHANDLE handle, uint32
958          if (index < 0)          if (index < 0)
959                  return False;                  return False;
960    
961    #ifdef TIOCINQ
962          pser_inf = (SERIAL_DEVICE *) g_rdpdr_device[index].pdevice_data;          pser_inf = (SERIAL_DEVICE *) g_rdpdr_device[index].pdevice_data;
963    
   
964          ioctl(handle, TIOCINQ, &bytes);          ioctl(handle, TIOCINQ, &bytes);
965    
966          if (bytes > 0)          if (bytes > 0)
# Line 969  serial_get_event(NTHANDLE handle, uint32 Line 996  serial_get_event(NTHANDLE handle, uint32
996          {          {
997                  pser_inf->event_rlsd = 0;                  pser_inf->event_rlsd = 0;
998          }          }
999    #endif
1000    
1001    #ifdef TIOCOUTQ
1002          ioctl(handle, TIOCOUTQ, &bytes);          ioctl(handle, TIOCOUTQ, &bytes);
1003          if ((bytes == 0)          if ((bytes == 0)
1004              && (pser_inf->event_txempty > 0) && (pser_inf->wait_mask & SERIAL_EV_TXEMPTY))              && (pser_inf->event_txempty > 0) && (pser_inf->wait_mask & SERIAL_EV_TXEMPTY))
# Line 981  serial_get_event(NTHANDLE handle, uint32 Line 1009  serial_get_event(NTHANDLE handle, uint32
1009                  ret = True;                  ret = True;
1010          }          }
1011          pser_inf->event_txempty = bytes;          pser_inf->event_txempty = bytes;
1012    #endif
1013    
1014          ioctl(handle, TIOCMGET, &bytes);          ioctl(handle, TIOCMGET, &bytes);
1015          if ((bytes & TIOCM_DSR) != pser_inf->event_dsr)          if ((bytes & TIOCM_DSR) != pser_inf->event_dsr)

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

  ViewVC Help
Powered by ViewVC 1.1.26