/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 755 - (hide annotations)
Tue Aug 24 21:37:25 2004 UTC (19 years, 10 months ago) by stargo
File MIME type: text/plain
File size: 15751 byte(s)
Applied serial-fixes from Huang Yushuo <huangys@xynetsoft.com>
Tested connection with ZOC and HyperTerm on Windows

1 matthewc 432 #include <unistd.h>
2     #include <fcntl.h>
3     #include <termios.h>
4 stargo 570 #include <strings.h>
5 matthewc 432 #include "rdesktop.h"
6    
7     #define FILE_DEVICE_SERIAL_PORT 0x1b
8    
9     #define SERIAL_SET_BAUD_RATE 1
10     #define SERIAL_SET_QUEUE_SIZE 2
11     #define SERIAL_SET_LINE_CONTROL 3
12     #define SERIAL_SET_BREAK_ON 4
13     #define SERIAL_SET_BREAK_OFF 5
14     #define SERIAL_IMMEDIATE_CHAR 6
15     #define SERIAL_SET_TIMEOUTS 7
16     #define SERIAL_GET_TIMEOUTS 8
17     #define SERIAL_SET_DTR 9
18     #define SERIAL_CLR_DTR 10
19     #define SERIAL_RESET_DEVICE 11
20     #define SERIAL_SET_RTS 12
21     #define SERIAL_CLR_RTS 13
22     #define SERIAL_SET_XOFF 14
23     #define SERIAL_SET_XON 15
24     #define SERIAL_GET_WAIT_MASK 16
25     #define SERIAL_SET_WAIT_MASK 17
26     #define SERIAL_WAIT_ON_MASK 18
27     #define SERIAL_PURGE 19
28     #define SERIAL_GET_BAUD_RATE 20
29     #define SERIAL_GET_LINE_CONTROL 21
30     #define SERIAL_GET_CHARS 22
31     #define SERIAL_SET_CHARS 23
32     #define SERIAL_GET_HANDFLOW 24
33     #define SERIAL_SET_HANDFLOW 25
34     #define SERIAL_GET_MODEMSTATUS 26
35     #define SERIAL_GET_COMMSTATUS 27
36     #define SERIAL_XOFF_COUNTER 28
37     #define SERIAL_GET_PROPERTIES 29
38     #define SERIAL_GET_DTRRTS 30
39     #define SERIAL_LSRMST_INSERT 31
40     #define SERIAL_CONFIG_SIZE 32
41     #define SERIAL_GET_COMMCONFIG 33
42     #define SERIAL_SET_COMMCONFIG 34
43     #define SERIAL_GET_STATS 35
44     #define SERIAL_CLEAR_STATS 36
45     #define SERIAL_GET_MODEM_CONTROL 37
46     #define SERIAL_SET_MODEM_CONTROL 38
47     #define SERIAL_SET_FIFO_CONTROL 39
48    
49     #define STOP_BITS_1 0
50     #define STOP_BITS_2 2
51    
52     #define NO_PARITY 0
53     #define ODD_PARITY 1
54     #define EVEN_PARITY 2
55    
56 n-ki 622 #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 stargo 686 #ifndef CRTSCTS
77     #define CRTSCTS 0
78     #endif
79 n-ki 622
80 stargo 686
81 astrand 580 extern RDPDR_DEVICE g_rdpdr_device[];
82 n-ki 569
83 astrand 665 static SERIAL_DEVICE *
84 n-ki 588 get_serial_info(HANDLE handle)
85 matthewc 432 {
86 astrand 580 int index;
87 matthewc 432
88 astrand 580 for (index = 0; index < RDPDR_MAX_DEVICES; index++)
89     {
90     if (handle == g_rdpdr_device[index].handle)
91     return (SERIAL_DEVICE *) g_rdpdr_device[index].pdevice_data;
92     }
93     return NULL;
94 n-ki 569 }
95 matthewc 432
96 astrand 665 static BOOL
97 astrand 580 get_termios(SERIAL_DEVICE * pser_inf, HANDLE serial_fd)
98 n-ki 569 {
99 astrand 580 speed_t speed;
100     struct termios *ptermios;
101 n-ki 569
102 astrand 580 ptermios = pser_inf->ptermios;
103 n-ki 569
104 astrand 580 if (tcgetattr(serial_fd, ptermios) == -1)
105     return False;
106 n-ki 569
107 astrand 580 speed = cfgetispeed(ptermios);
108     switch (speed)
109     {
110 stargo 545 #ifdef B75
111 astrand 580 case B75:
112     pser_inf->baud_rate = 75;
113     break;
114 stargo 545 #endif
115     #ifdef B110
116 astrand 580 case B110:
117     pser_inf->baud_rate = 110;
118     break;
119 stargo 545 #endif
120     #ifdef B134
121 astrand 580 case B134:
122     pser_inf->baud_rate = 134;
123     break;
124 stargo 545 #endif
125     #ifdef B150
126 astrand 580 case B150:
127     pser_inf->baud_rate = 150;
128     break;
129 stargo 545 #endif
130     #ifdef B300
131 astrand 580 case B300:
132     pser_inf->baud_rate = 300;
133     break;
134 stargo 545 #endif
135     #ifdef B600
136 astrand 580 case B600:
137     pser_inf->baud_rate = 600;
138     break;
139 stargo 545 #endif
140     #ifdef B1200
141 astrand 580 case B1200:
142     pser_inf->baud_rate = 1200;
143     break;
144 stargo 545 #endif
145     #ifdef B1800
146 astrand 580 case B1800:
147     pser_inf->baud_rate = 1800;
148     break;
149 stargo 545 #endif
150     #ifdef B2400
151 astrand 580 case B2400:
152     pser_inf->baud_rate = 2400;
153     break;
154 stargo 545 #endif
155     #ifdef B4800
156 astrand 580 case B4800:
157     pser_inf->baud_rate = 4800;
158     break;
159 stargo 545 #endif
160     #ifdef B9600
161 astrand 580 case B9600:
162     pser_inf->baud_rate = 9600;
163     break;
164 stargo 545 #endif
165     #ifdef B19200
166 astrand 580 case B19200:
167     pser_inf->baud_rate = 19200;
168     break;
169 stargo 545 #endif
170     #ifdef B38400
171 astrand 580 case B38400:
172     pser_inf->baud_rate = 38400;
173     break;
174 stargo 545 #endif
175     #ifdef B57600
176 astrand 580 case B57600:
177     pser_inf->baud_rate = 57600;
178     break;
179 stargo 545 #endif
180     #ifdef B115200
181 astrand 580 case B115200:
182     pser_inf->baud_rate = 115200;
183     break;
184 stargo 545 #endif
185 astrand 580 default:
186     pser_inf->baud_rate = 0;
187     break;
188     }
189 matthewc 432
190 astrand 580 speed = cfgetospeed(ptermios);
191     pser_inf->dtr = (speed == B0) ? 0 : 1;
192 matthewc 432
193 astrand 580 pser_inf->stop_bits = (ptermios->c_cflag & CSTOPB) ? STOP_BITS_2 : STOP_BITS_1;
194     pser_inf->parity =
195     (ptermios->
196     c_cflag & PARENB) ? ((ptermios->
197     c_cflag & PARODD) ? ODD_PARITY : EVEN_PARITY) : NO_PARITY;
198     switch (ptermios->c_cflag & CSIZE)
199     {
200     case CS5:
201     pser_inf->word_length = 5;
202     break;
203     case CS6:
204     pser_inf->word_length = 6;
205     break;
206     case CS7:
207     pser_inf->word_length = 7;
208     break;
209     default:
210     pser_inf->word_length = 8;
211     break;
212     }
213 matthewc 432
214 n-ki 622 pser_inf->rts = (ptermios->c_cflag & CRTSCTS) ? 1 : 0;
215    
216 astrand 580 return True;
217 matthewc 432 }
218    
219     static void
220 n-ki 588 set_termios(SERIAL_DEVICE * pser_inf, HANDLE serial_fd)
221 matthewc 432 {
222     speed_t speed;
223    
224 n-ki 588 struct termios *ptermios;
225    
226     ptermios = pser_inf->ptermios;
227    
228    
229     switch (pser_inf->baud_rate)
230 matthewc 432 {
231 stargo 545 #ifdef B75
232 astrand 580 case 75:
233     speed = B75;
234     break;
235 stargo 545 #endif
236     #ifdef B110
237 astrand 580 case 110:
238     speed = B110;
239     break;
240 stargo 545 #endif
241     #ifdef B134
242 astrand 580 case 134:
243     speed = B134;
244     break;
245 stargo 545 #endif
246     #ifdef B150
247 astrand 580 case 150:
248     speed = B150;
249     break;
250 stargo 545 #endif
251     #ifdef B300
252 astrand 580 case 300:
253     speed = B300;
254     break;
255 stargo 545 #endif
256     #ifdef B600
257 astrand 580 case 600:
258     speed = B600;
259     break;
260 stargo 545 #endif
261     #ifdef B1200
262 astrand 580 case 1200:
263     speed = B1200;
264     break;
265 stargo 545 #endif
266     #ifdef B1800
267 astrand 580 case 1800:
268     speed = B1800;
269     break;
270 stargo 545 #endif
271     #ifdef B2400
272 astrand 580 case 2400:
273     speed = B2400;
274     break;
275 stargo 545 #endif
276     #ifdef B4800
277 astrand 580 case 4800:
278     speed = B4800;
279     break;
280 stargo 545 #endif
281     #ifdef B9600
282 astrand 580 case 9600:
283     speed = B9600;
284     break;
285 stargo 545 #endif
286     #ifdef B19200
287 astrand 580 case 19200:
288     speed = B19200;
289     break;
290 stargo 545 #endif
291     #ifdef B38400
292 astrand 580 case 38400:
293     speed = B38400;
294     break;
295 stargo 545 #endif
296     #ifdef B57600
297 astrand 580 case 57600:
298     speed = B57600;
299     break;
300 stargo 545 #endif
301     #ifdef B115200
302 astrand 580 case 115200:
303     speed = B115200;
304     break;
305 stargo 545 #endif
306 astrand 580 default:
307     speed = B0;
308     break;
309 matthewc 432 }
310    
311     /* on systems with separate ispeed and ospeed, we can remember the speed
312     in ispeed while changing DTR with ospeed */
313 n-ki 588 cfsetispeed(pser_inf->ptermios, speed);
314     cfsetospeed(pser_inf->ptermios, pser_inf->dtr ? speed : 0);
315 matthewc 432
316 n-ki 622 ptermios->c_cflag &= ~(CSTOPB | PARENB | PARODD | CSIZE | CRTSCTS);
317 n-ki 588 switch (pser_inf->stop_bits)
318 matthewc 432 {
319     case STOP_BITS_2:
320 n-ki 588 ptermios->c_cflag |= CSTOPB;
321 matthewc 432 break;
322     }
323 n-ki 622
324 n-ki 588 switch (pser_inf->parity)
325 matthewc 432 {
326     case EVEN_PARITY:
327 n-ki 588 ptermios->c_cflag |= PARENB;
328 matthewc 432 break;
329     case ODD_PARITY:
330 n-ki 588 ptermios->c_cflag |= PARENB | PARODD;
331 matthewc 432 break;
332     }
333 n-ki 622
334 n-ki 588 switch (pser_inf->word_length)
335 matthewc 432 {
336 astrand 435 case 5:
337 n-ki 588 ptermios->c_cflag |= CS5;
338 astrand 435 break;
339     case 6:
340 n-ki 588 ptermios->c_cflag |= CS6;
341 astrand 435 break;
342     case 7:
343 n-ki 588 ptermios->c_cflag |= CS7;
344 astrand 435 break;
345     default:
346 n-ki 588 ptermios->c_cflag |= CS8;
347 astrand 435 break;
348 matthewc 432 }
349    
350 n-ki 622 if (pser_inf->rts)
351     ptermios->c_cflag |= CRTSCTS;
352    
353 n-ki 588 tcsetattr(serial_fd, TCSANOW, ptermios);
354 matthewc 432 }
355    
356 n-ki 569 /* Enumeration of devices from rdesktop.c */
357     /* returns numer of units found and initialized. */
358     /* optarg looks like ':com1=/dev/ttyS0' */
359     /* when it arrives to this function. */
360 n-ki 578 /* :com1=/dev/ttyS0,com2=/dev/ttyS1 */
361 n-ki 569 int
362 astrand 608 serial_enum_devices(uint32 * id, char *optarg)
363 matthewc 432 {
364 astrand 580 SERIAL_DEVICE *pser_inf;
365 matthewc 432
366 n-ki 578 char *pos = optarg;
367     char *pos2;
368     int count = 0;
369 matthewc 432
370 n-ki 578 // skip the first colon
371     optarg++;
372     while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES)
373     {
374 n-ki 569 // Init data structures for device
375     pser_inf = (SERIAL_DEVICE *) xmalloc(sizeof(SERIAL_DEVICE));
376     pser_inf->ptermios = (struct termios *) xmalloc(sizeof(struct termios));
377 stargo 755 memset(pser_inf->ptermios, 0, sizeof(struct termios));
378 n-ki 569 pser_inf->pold_termios = (struct termios *) xmalloc(sizeof(struct termios));
379 stargo 755 memset(pser_inf->pold_termios, 0, sizeof(struct termios));
380 n-ki 569
381 n-ki 578 pos2 = next_arg(optarg, '=');
382     strcpy(g_rdpdr_device[*id].name, optarg);
383 n-ki 569
384 n-ki 578 toupper_str(g_rdpdr_device[*id].name);
385 n-ki 569
386 n-ki 578 g_rdpdr_device[*id].local_path = xmalloc(strlen(pos2) + 1);
387     strcpy(g_rdpdr_device[*id].local_path, pos2);
388 astrand 580 printf("SERIAL %s to %s\n", g_rdpdr_device[*id].name,
389     g_rdpdr_device[*id].local_path);
390 n-ki 569 // set device type
391     g_rdpdr_device[*id].device_type = DEVICE_TYPE_SERIAL;
392     g_rdpdr_device[*id].pdevice_data = (void *) pser_inf;
393 n-ki 578 count++;
394 n-ki 569 (*id)++;
395    
396 n-ki 578 optarg = pos;
397 n-ki 569 }
398 n-ki 578 return count;
399 matthewc 432 }
400    
401 astrand 665 static NTSTATUS
402 astrand 580 serial_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition,
403     uint32 flags_and_attributes, char *filename, HANDLE * handle)
404 n-ki 569 {
405 astrand 580 HANDLE serial_fd;
406     SERIAL_DEVICE *pser_inf;
407     struct termios *ptermios;
408 n-ki 569
409 astrand 580 pser_inf = (SERIAL_DEVICE *) g_rdpdr_device[device_id].pdevice_data;
410     ptermios = pser_inf->ptermios;
411 stargo 755 serial_fd = open(g_rdpdr_device[device_id].local_path, O_RDWR | O_NOCTTY | O_NONBLOCK);
412 n-ki 569
413 astrand 580 if (serial_fd == -1)
414 n-ki 588 {
415     perror("open");
416 astrand 580 return STATUS_ACCESS_DENIED;
417 n-ki 588 }
418 n-ki 569
419 astrand 580 if (!get_termios(pser_inf, serial_fd))
420 n-ki 622 {
421     printf("INFO: SERIAL %s access denied\n", g_rdpdr_device[device_id].name);
422     fflush(stdout);
423 astrand 580 return STATUS_ACCESS_DENIED;
424 n-ki 622 }
425 n-ki 569
426 n-ki 578 // Store handle for later use
427 astrand 580 g_rdpdr_device[device_id].handle = serial_fd;
428 n-ki 569
429 n-ki 578 /* some sane information */
430 n-ki 622 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);
431    
432 astrand 580 printf("INFO: use stty to change settings\n");
433 n-ki 569
434 n-ki 588 /* ptermios->c_cflag = B115200 | CRTSCTS | CS8 | CLOCAL | CREAD;
435     ptermios->c_cflag |= CREAD;
436     ptermios->c_lflag |= ICANON;
437     ptermios->c_iflag = IGNPAR | ICRNL;
438 n-ki 569
439 n-ki 588 tcsetattr(serial_fd, TCSANOW, ptermios);
440     */
441 n-ki 592
442 stargo 755 cfmakeraw(pser_inf->ptermios);
443 astrand 580 *handle = serial_fd;
444 n-ki 592
445     /* all read and writes should be non blocking */
446     if (fcntl(*handle, F_SETFL, O_NONBLOCK) == -1)
447     perror("fcntl");
448    
449 astrand 580 return STATUS_SUCCESS;
450 n-ki 569 }
451    
452 matthewc 432 static NTSTATUS
453     serial_close(HANDLE handle)
454     {
455 n-ki 622 int i = get_device_index(handle);
456     if (i >= 0)
457     g_rdpdr_device[i].handle = 0;
458 n-ki 588 close(handle);
459 matthewc 432 return STATUS_SUCCESS;
460     }
461    
462 astrand 665 static NTSTATUS
463 astrand 580 serial_read(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
464 matthewc 432 {
465 astrand 580 long timeout;
466     SERIAL_DEVICE *pser_inf;
467     struct termios *ptermios;
468 n-ki 569
469 n-ki 592 timeout = 90;
470 astrand 580 pser_inf = get_serial_info(handle);
471     ptermios = pser_inf->ptermios;
472 n-ki 569
473 astrand 580 // Set timeouts kind of like the windows serial timeout parameters. Multiply timeout
474     // with requested read size
475     if (pser_inf->read_total_timeout_multiplier | pser_inf->read_total_timeout_constant)
476     {
477     timeout =
478     (pser_inf->read_total_timeout_multiplier * length +
479     pser_inf->read_total_timeout_constant + 99) / 100;
480     }
481     else if (pser_inf->read_interval_timeout)
482     {
483     timeout = (pser_inf->read_interval_timeout * length + 99) / 100;
484     }
485 n-ki 569
486 astrand 580 // If a timeout is set, do a blocking read, which times out after some time.
487     // It will make rdesktop less responsive, but it will improve serial performance, by not
488     // reading one character at a time.
489     if (timeout == 0)
490     {
491     ptermios->c_cc[VTIME] = 0;
492     ptermios->c_cc[VMIN] = 0;
493     }
494     else
495     {
496     ptermios->c_cc[VTIME] = timeout;
497     ptermios->c_cc[VMIN] = 1;
498     }
499     tcsetattr(handle, TCSANOW, ptermios);
500 n-ki 592
501    
502 astrand 580 *result = read(handle, data, length);
503 n-ki 592
504 n-ki 622 //hexdump(data, *read);
505    
506 astrand 580 return STATUS_SUCCESS;
507 matthewc 432 }
508    
509 astrand 665 static NTSTATUS
510 astrand 580 serial_write(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
511 matthewc 432 {
512 astrand 580 *result = write(handle, data, length);
513     return STATUS_SUCCESS;
514 matthewc 432 }
515    
516     static NTSTATUS
517     serial_device_control(HANDLE handle, uint32 request, STREAM in, STREAM out)
518     {
519 astrand 669 #if 0
520 n-ki 622 int flush_mask, purge_mask;
521 astrand 669 #endif
522 matthewc 432 uint32 result;
523     uint8 immediate;
524 n-ki 588 SERIAL_DEVICE *pser_inf;
525     struct termios *ptermios;
526 matthewc 432
527     if ((request >> 16) != FILE_DEVICE_SERIAL_PORT)
528     return STATUS_INVALID_PARAMETER;
529    
530 n-ki 588 pser_inf = get_serial_info(handle);
531     ptermios = pser_inf->ptermios;
532    
533 matthewc 432 /* extract operation */
534     request >>= 2;
535     request &= 0xfff;
536    
537     printf("SERIAL IOCTL %d\n", request);
538    
539     switch (request)
540     {
541     case SERIAL_SET_BAUD_RATE:
542 n-ki 588 in_uint32_le(in, pser_inf->baud_rate);
543     set_termios(pser_inf, handle);
544 matthewc 432 break;
545     case SERIAL_GET_BAUD_RATE:
546 n-ki 588 out_uint32_le(out, pser_inf->baud_rate);
547 matthewc 432 break;
548     case SERIAL_SET_QUEUE_SIZE:
549 n-ki 588 in_uint32_le(in, pser_inf->queue_in_size);
550     in_uint32_le(in, pser_inf->queue_out_size);
551 matthewc 432 break;
552     case SERIAL_SET_LINE_CONTROL:
553 n-ki 588 in_uint8(in, pser_inf->stop_bits);
554     in_uint8(in, pser_inf->parity);
555     in_uint8(in, pser_inf->word_length);
556     set_termios(pser_inf, handle);
557 matthewc 432 break;
558     case SERIAL_GET_LINE_CONTROL:
559 n-ki 588 out_uint8(out, pser_inf->stop_bits);
560     out_uint8(out, pser_inf->parity);
561     out_uint8(out, pser_inf->word_length);
562 matthewc 432 break;
563     case SERIAL_IMMEDIATE_CHAR:
564     in_uint8(in, immediate);
565 n-ki 569 serial_write(handle, &immediate, 1, 0, &result);
566 matthewc 432 break;
567     case SERIAL_CONFIG_SIZE:
568     out_uint32_le(out, 0);
569     break;
570     case SERIAL_GET_CHARS:
571     out_uint8s(out, 6);
572     break;
573     case SERIAL_SET_CHARS:
574     in_uint8s(in, 6);
575     break;
576     case SERIAL_GET_HANDFLOW:
577     out_uint32_le(out, 0);
578 astrand 435 out_uint32_le(out, 3); /* Xon/Xoff */
579 matthewc 432 out_uint32_le(out, 0);
580     out_uint32_le(out, 0);
581     break;
582     case SERIAL_SET_HANDFLOW:
583     in_uint8s(in, 16);
584     break;
585     case SERIAL_SET_TIMEOUTS:
586     in_uint8s(in, 20);
587     break;
588     case SERIAL_GET_TIMEOUTS:
589     out_uint8s(out, 20);
590     break;
591     case SERIAL_GET_WAIT_MASK:
592 n-ki 588 out_uint32(out, pser_inf->wait_mask);
593 matthewc 432 break;
594     case SERIAL_SET_WAIT_MASK:
595 n-ki 588 in_uint32(in, pser_inf->wait_mask);
596 matthewc 432 break;
597     case SERIAL_SET_DTR:
598 n-ki 588 pser_inf->dtr = 1;
599     set_termios(pser_inf, handle);
600 matthewc 432 break;
601     case SERIAL_CLR_DTR:
602 n-ki 588 pser_inf->dtr = 0;
603     set_termios(pser_inf, handle);
604 matthewc 432 break;
605 n-ki 622 case SERIAL_SET_RTS:
606     pser_inf->rts = 1;
607     set_termios(pser_inf, handle);
608 matthewc 432 break;
609 n-ki 622 case SERIAL_CLR_RTS:
610     pser_inf->rts = 0;
611     set_termios(pser_inf, handle);
612 matthewc 432 break;
613 n-ki 622 case SERIAL_GET_MODEMSTATUS:
614     out_uint32_le(out, 0); /* Errors */
615     break;
616     case SERIAL_GET_COMMSTATUS:
617     out_uint32_le(out, 0); /* Errors */
618     out_uint32_le(out, 0); /* Hold reasons */
619     out_uint32_le(out, 0); /* Amount in in queue */
620     out_uint32_le(out, 0); /* Amount in out queue */
621     out_uint8(out, 0); /* EofReceived */
622     out_uint8(out, 0); /* WaitForImmediate */
623     break;
624     #if 0
625 matthewc 432 case SERIAL_PURGE:
626 astrand 580 printf("SERIAL_PURGE\n");
627     in_uint32(in, purge_mask);
628     if (purge_mask & 0x04)
629     flush_mask |= TCOFLUSH;
630     if (purge_mask & 0x08)
631     flush_mask |= TCIFLUSH;
632     if (flush_mask != 0)
633     tcflush(handle, flush_mask);
634     if (purge_mask & 0x01)
635     rdpdr_abort_io(handle, 4, STATUS_CANCELLED);
636     if (purge_mask & 0x02)
637     rdpdr_abort_io(handle, 3, STATUS_CANCELLED);
638     break;
639 n-ki 622 case SERIAL_WAIT_ON_MASK:
640     /* XXX implement me */
641     out_uint32_le(out, pser_inf->wait_mask);
642     break;
643     case SERIAL_SET_BREAK_ON:
644     tcsendbreak(serial_fd, 0);
645     break;
646 matthewc 432 case SERIAL_RESET_DEVICE:
647     case SERIAL_SET_BREAK_OFF:
648     case SERIAL_SET_XOFF:
649     case SERIAL_SET_XON:
650     /* ignore */
651     break;
652     #endif
653     default:
654     unimpl("SERIAL IOCTL %d\n", request);
655     return STATUS_INVALID_PARAMETER;
656     }
657    
658     return STATUS_SUCCESS;
659     }
660    
661 n-ki 569 /* Read timeout for a given file descripter (device) when adding fd's to select() */
662     BOOL
663 n-ki 588 serial_get_timeout(HANDLE handle, uint32 length, uint32 * timeout, uint32 * itv_timeout)
664 n-ki 569 {
665 astrand 580 int index;
666     SERIAL_DEVICE *pser_inf;
667 n-ki 569
668 astrand 580 index = get_device_index(handle);
669 n-ki 622 if (index < 0)
670     return True;
671 n-ki 569
672 astrand 580 if (g_rdpdr_device[index].device_type != DEVICE_TYPE_SERIAL)
673     {
674     return False;
675     }
676 n-ki 569
677 astrand 580 pser_inf = (SERIAL_DEVICE *) g_rdpdr_device[index].pdevice_data;
678 n-ki 569
679 astrand 580 *timeout =
680     pser_inf->read_total_timeout_multiplier * length +
681     pser_inf->read_total_timeout_constant;
682     *itv_timeout = pser_inf->read_interval_timeout;
683     return True;
684 n-ki 569 }
685    
686 astrand 435 DEVICE_FNS serial_fns = {
687 matthewc 432 serial_create,
688     serial_close,
689     serial_read,
690     serial_write,
691     serial_device_control
692     };

  ViewVC Help
Powered by ViewVC 1.1.26