/[rdesktop]/jpeg/rdesktop/trunk/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 /jpeg/rdesktop/trunk/serial.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 622 - (hide annotations)
Thu Mar 4 08:01:07 2004 UTC (20 years, 2 months ago) by n-ki
Original Path: sourceforge.net/trunk/rdesktop/serial.c
File MIME type: text/plain
File size: 15498 byte(s)
error handling, rts, figured out modemstatus and some constants - volker milde

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

  ViewVC Help
Powered by ViewVC 1.1.26