/[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 608 by astrand, Sun Feb 15 21:19:28 2004 UTC revision 622 by n-ki, Thu Mar 4 08:01:07 2004 UTC
# Line 53  Line 53 
53  #define ODD_PARITY                      1  #define ODD_PARITY                      1
54  #define EVEN_PARITY                     2  #define EVEN_PARITY                     2
55    
56    #define SERIAL_PURGE_TXABORT 0x00000001
57    #define SERIAL_PURGE_RXABORT 0x00000002
58    #define SERIAL_PURGE_TXCLEAR 0x00000004
59    #define SERIAL_PURGE_RXCLEAR 0x00000008
60    
61    /* SERIAL_WAIT_ON_MASK */
62    #define SERIAL_EV_RXCHAR           0x0001       // Any Character received
63    #define SERIAL_EV_RXFLAG           0x0002       // Received certain character
64    #define SERIAL_EV_TXEMPTY          0x0004       // Transmitt Queue Empty
65    #define SERIAL_EV_CTS              0x0008       // CTS changed state
66    #define SERIAL_EV_DSR              0x0010       // DSR changed state
67    #define SERIAL_EV_RLSD             0x0020       // RLSD changed state
68    #define SERIAL_EV_BREAK            0x0040       // BREAK received
69    #define SERIAL_EV_ERR              0x0080       // Line status error occurred
70    #define SERIAL_EV_RING             0x0100       // Ring signal detected
71    #define SERIAL_EV_PERR             0x0200       // Printer error occured
72    #define SERIAL_EV_RX80FULL         0x0400       // Receive buffer is 80 percent full
73    #define SERIAL_EV_EVENT1           0x0800       // Provider specific event 1
74    #define SERIAL_EV_EVENT2           0x1000       // Provider specific event 2
75    
76    
77  extern RDPDR_DEVICE g_rdpdr_device[];  extern RDPDR_DEVICE g_rdpdr_device[];
78    
79  SERIAL_DEVICE *  SERIAL_DEVICE *
# Line 186  get_termios(SERIAL_DEVICE * pser_inf, HA Line 207  get_termios(SERIAL_DEVICE * pser_inf, HA
207                          break;                          break;
208          }          }
209    
210            pser_inf->rts = (ptermios->c_cflag & CRTSCTS) ? 1 : 0;
211    
212          return True;          return True;
213  }  }
214    
# Line 286  set_termios(SERIAL_DEVICE * pser_inf, HA Line 309  set_termios(SERIAL_DEVICE * pser_inf, HA
309          cfsetispeed(pser_inf->ptermios, speed);          cfsetispeed(pser_inf->ptermios, speed);
310          cfsetospeed(pser_inf->ptermios, pser_inf->dtr ? speed : 0);          cfsetospeed(pser_inf->ptermios, pser_inf->dtr ? speed : 0);
311    
312          ptermios->c_cflag &= ~(CSTOPB | PARENB | PARODD | CSIZE);          ptermios->c_cflag &= ~(CSTOPB | PARENB | PARODD | CSIZE | CRTSCTS);
313          switch (pser_inf->stop_bits)          switch (pser_inf->stop_bits)
314          {          {
315                  case STOP_BITS_2:                  case STOP_BITS_2:
316                          ptermios->c_cflag |= CSTOPB;                          ptermios->c_cflag |= CSTOPB;
317                          break;                          break;
318          }          }
319    
320          switch (pser_inf->parity)          switch (pser_inf->parity)
321          {          {
322                  case EVEN_PARITY:                  case EVEN_PARITY:
# Line 302  set_termios(SERIAL_DEVICE * pser_inf, HA Line 326  set_termios(SERIAL_DEVICE * pser_inf, HA
326                          ptermios->c_cflag |= PARENB | PARODD;                          ptermios->c_cflag |= PARENB | PARODD;
327                          break;                          break;
328          }          }
329    
330          switch (pser_inf->word_length)          switch (pser_inf->word_length)
331          {          {
332                  case 5:                  case 5:
# Line 318  set_termios(SERIAL_DEVICE * pser_inf, HA Line 343  set_termios(SERIAL_DEVICE * pser_inf, HA
343                          break;                          break;
344          }          }
345    
346            if (pser_inf->rts)
347                    ptermios->c_cflag |= CRTSCTS;
348    
349          tcsetattr(serial_fd, TCSANOW, ptermios);          tcsetattr(serial_fd, TCSANOW, ptermios);
350  }  }
351    
# Line 383  serial_create(uint32 device_id, uint32 a Line 411  serial_create(uint32 device_id, uint32 a
411          }          }
412    
413          if (!get_termios(pser_inf, serial_fd))          if (!get_termios(pser_inf, serial_fd))
414            {
415                    printf("INFO: SERIAL %s access denied\n", g_rdpdr_device[device_id].name);
416                    fflush(stdout);
417                  return STATUS_ACCESS_DENIED;                  return STATUS_ACCESS_DENIED;
418            }
419    
420          // Store handle for later use          // Store handle for later use
421          g_rdpdr_device[device_id].handle = serial_fd;          g_rdpdr_device[device_id].handle = serial_fd;
422    
423          /* some sane information */          /* some sane information */
424          printf("INFO: SERIAL %s to %s\nINFO: speed %u baud, stop bits %u, parity %u, word length %u bits, dtr %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);          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);
425    
426          printf("INFO: use stty to change settings\n");          printf("INFO: use stty to change settings\n");
427    
428  /*      ptermios->c_cflag = B115200 | CRTSCTS | CS8 | CLOCAL | CREAD;  /*      ptermios->c_cflag = B115200 | CRTSCTS | CS8 | CLOCAL | CREAD;
# Line 412  serial_create(uint32 device_id, uint32 a Line 445  serial_create(uint32 device_id, uint32 a
445  static NTSTATUS  static NTSTATUS
446  serial_close(HANDLE handle)  serial_close(HANDLE handle)
447  {  {
448          g_rdpdr_device[get_device_index(handle)].handle = 0;          int i = get_device_index(handle);
449            if (i >= 0)
450                    g_rdpdr_device[i].handle = 0;
451          close(handle);          close(handle);
452          return STATUS_SUCCESS;          return STATUS_SUCCESS;
453  }  }
# Line 459  serial_read(HANDLE handle, uint8 * data, Line 494  serial_read(HANDLE handle, uint8 * data,
494    
495          *result = read(handle, data, length);          *result = read(handle, data, length);
496    
497            //hexdump(data, *read);
498    
499          return STATUS_SUCCESS;          return STATUS_SUCCESS;
500  }  }
501    
# Line 472  serial_write(HANDLE handle, uint8 * data Line 509  serial_write(HANDLE handle, uint8 * data
509  static NTSTATUS  static NTSTATUS
510  serial_device_control(HANDLE handle, uint32 request, STREAM in, STREAM out)  serial_device_control(HANDLE handle, uint32 request, STREAM in, STREAM out)
511  {  {
512            int flush_mask, purge_mask;
513          uint32 result;          uint32 result;
514          uint8 immediate;          uint8 immediate;
515          SERIAL_DEVICE *pser_inf;          SERIAL_DEVICE *pser_inf;
# Line 555  serial_device_control(HANDLE handle, uin Line 593  serial_device_control(HANDLE handle, uin
593                          pser_inf->dtr = 0;                          pser_inf->dtr = 0;
594                          set_termios(pser_inf, handle);                          set_termios(pser_inf, handle);
595                          break;                          break;
596  #if 0                  case SERIAL_SET_RTS:
597                  case SERIAL_WAIT_ON_MASK:                          pser_inf->rts = 1;
598                          /* XXX implement me */                          set_termios(pser_inf, handle);
599                          break;                          break;
600                  case SERIAL_SET_BREAK_ON:                  case SERIAL_CLR_RTS:
601                          tcsendbreak(serial_fd, 0);                          pser_inf->rts = 0;
602                            set_termios(pser_inf, handle);
603                            break;
604                    case SERIAL_GET_MODEMSTATUS:
605                            out_uint32_le(out, 0);  /* Errors */
606                            break;
607                    case SERIAL_GET_COMMSTATUS:
608                            out_uint32_le(out, 0);  /* Errors */
609                            out_uint32_le(out, 0);  /* Hold reasons */
610                            out_uint32_le(out, 0);  /* Amount in in queue */
611                            out_uint32_le(out, 0);  /* Amount in out queue */
612                            out_uint8(out, 0);      /* EofReceived */
613                            out_uint8(out, 0);      /* WaitForImmediate */
614                          break;                          break;
615    #if 0
616                  case SERIAL_PURGE:                  case SERIAL_PURGE:
   
617                          printf("SERIAL_PURGE\n");                          printf("SERIAL_PURGE\n");
618                          in_uint32(in, purge_mask);                          in_uint32(in, purge_mask);
619                          if (purge_mask & 0x04)                          if (purge_mask & 0x04)
# Line 577  serial_device_control(HANDLE handle, uin Line 627  serial_device_control(HANDLE handle, uin
627                          if (purge_mask & 0x02)                          if (purge_mask & 0x02)
628                                  rdpdr_abort_io(handle, 3, STATUS_CANCELLED);                                  rdpdr_abort_io(handle, 3, STATUS_CANCELLED);
629                          break;                          break;
630                    case SERIAL_WAIT_ON_MASK:
631                            /* XXX implement me */
632                            out_uint32_le(out, pser_inf->wait_mask);
633                            break;
634                    case SERIAL_SET_BREAK_ON:
635                            tcsendbreak(serial_fd, 0);
636                            break;
637                  case SERIAL_RESET_DEVICE:                  case SERIAL_RESET_DEVICE:
638                  case SERIAL_SET_BREAK_OFF:                  case SERIAL_SET_BREAK_OFF:
                 case SERIAL_SET_RTS:  
                 case SERIAL_CLR_RTS:  
639                  case SERIAL_SET_XOFF:                  case SERIAL_SET_XOFF:
640                  case SERIAL_SET_XON:                  case SERIAL_SET_XON:
641                          /* ignore */                          /* ignore */
642                          break;                          break;
643  #endif  #endif
   
644                  default:                  default:
645                          unimpl("SERIAL IOCTL %d\n", request);                          unimpl("SERIAL IOCTL %d\n", request);
646                          return STATUS_INVALID_PARAMETER;                          return STATUS_INVALID_PARAMETER;
# Line 604  serial_get_timeout(HANDLE handle, uint32 Line 657  serial_get_timeout(HANDLE handle, uint32
657          SERIAL_DEVICE *pser_inf;          SERIAL_DEVICE *pser_inf;
658    
659          index = get_device_index(handle);          index = get_device_index(handle);
660            if (index < 0)
661                    return True;
662    
663          if (g_rdpdr_device[index].device_type != DEVICE_TYPE_SERIAL)          if (g_rdpdr_device[index].device_type != DEVICE_TYPE_SERIAL)
664          {          {

Legend:
Removed from v.608  
changed lines
  Added in v.622

  ViewVC Help
Powered by ViewVC 1.1.26