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