1 |
/* -*- c-basic-offset: 8 -*- |
/* -*- c-basic-offset: 8 -*- |
2 |
rdesktop: A Remote Desktop Protocol client. |
rdesktop: A Remote Desktop Protocol client. |
3 |
Copyright (C) Matthew Chapman 1999-2004 |
Copyright (C) Matthew Chapman 1999-2008 |
4 |
|
|
5 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
6 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
60 |
extern DEVICE_FNS printer_fns; |
extern DEVICE_FNS printer_fns; |
61 |
extern DEVICE_FNS parallel_fns; |
extern DEVICE_FNS parallel_fns; |
62 |
extern DEVICE_FNS disk_fns; |
extern DEVICE_FNS disk_fns; |
63 |
|
#ifdef WITH_SCARD |
64 |
|
extern DEVICE_FNS scard_fns; |
65 |
|
#endif |
66 |
extern FILEINFO g_fileinfo[]; |
extern FILEINFO g_fileinfo[]; |
67 |
|
extern RD_BOOL g_notify_stamp; |
68 |
|
|
69 |
static VCHANNEL *rdpdr_channel; |
static VCHANNEL *rdpdr_channel; |
70 |
|
|
71 |
/* If select() times out, the request for the device with handle g_min_timeout_fd is aborted */ |
/* If select() times out, the request for the device with handle g_min_timeout_fd is aborted */ |
72 |
HANDLE g_min_timeout_fd; |
RD_NTHANDLE g_min_timeout_fd; |
73 |
uint32 g_num_devices; |
uint32 g_num_devices; |
74 |
|
|
75 |
/* Table with information about rdpdr devices */ |
/* Table with information about rdpdr devices */ |
94 |
|
|
95 |
/* Return device_id for a given handle */ |
/* Return device_id for a given handle */ |
96 |
int |
int |
97 |
get_device_index(HANDLE handle) |
get_device_index(RD_NTHANDLE handle) |
98 |
{ |
{ |
99 |
int i; |
int i; |
100 |
for (i = 0; i < RDPDR_MAX_DEVICES; i++) |
for (i = 0; i < RDPDR_MAX_DEVICES; i++) |
117 |
} |
} |
118 |
} |
} |
119 |
|
|
120 |
static BOOL |
static RD_BOOL |
121 |
rdpdr_handle_ok(int device, int handle) |
rdpdr_handle_ok(int device, int handle) |
122 |
{ |
{ |
123 |
switch (g_rdpdr_device[device].device_type) |
switch (g_rdpdr_device[device].device_type) |
138 |
} |
} |
139 |
|
|
140 |
/* Add a new io request to the table containing pending io requests so it won't block rdesktop */ |
/* Add a new io request to the table containing pending io requests so it won't block rdesktop */ |
141 |
static BOOL |
static RD_BOOL |
142 |
add_async_iorequest(uint32 device, uint32 file, uint32 id, uint32 major, uint32 length, |
add_async_iorequest(uint32 device, uint32 file, uint32 id, uint32 major, uint32 length, |
143 |
DEVICE_FNS * fns, uint32 total_timeout, uint32 interval_timeout, uint8 * buffer, |
DEVICE_FNS * fns, uint32 total_timeout, uint32 interval_timeout, uint8 * buffer, |
144 |
uint32 offset) |
uint32 offset) |
158 |
|
|
159 |
while (iorq->fd != 0) |
while (iorq->fd != 0) |
160 |
{ |
{ |
161 |
// create new element if needed |
/* create new element if needed */ |
162 |
if (iorq->next == NULL) |
if (iorq->next == NULL) |
163 |
{ |
{ |
164 |
iorq->next = |
iorq->next = |
231 |
int size, i; |
int size, i; |
232 |
PRINTER *printerinfo; |
PRINTER *printerinfo; |
233 |
|
|
234 |
size = 8; //static announce size |
size = 8; /* static announce size */ |
235 |
size += g_num_devices * 0x14; |
size += g_num_devices * 0x14; |
236 |
|
|
237 |
for (i = 0; i < g_num_devices; i++) |
for (i = 0; i < g_num_devices; i++) |
312 |
channel_send(s, rdpdr_channel); |
channel_send(s, rdpdr_channel); |
313 |
} |
} |
314 |
|
|
315 |
static void |
void |
316 |
rdpdr_send_completion(uint32 device, uint32 id, uint32 status, uint32 result, uint8 * buffer, |
rdpdr_send_completion(uint32 device, uint32 id, uint32 status, uint32 result, uint8 * buffer, |
317 |
uint32 length) |
uint32 length) |
318 |
{ |
{ |
319 |
uint8 magic[4] = "rDCI"; |
uint8 magic[4] = "rDCI"; |
320 |
STREAM s; |
STREAM s; |
321 |
|
|
322 |
|
#ifdef WITH_SCARD |
323 |
|
scard_lock(SCARD_LOCK_RDPDR); |
324 |
|
#endif |
325 |
s = channel_init(rdpdr_channel, 20 + length); |
s = channel_init(rdpdr_channel, 20 + length); |
326 |
out_uint8a(s, magic, 4); |
out_uint8a(s, magic, 4); |
327 |
out_uint32_le(s, device); |
out_uint32_le(s, device); |
330 |
out_uint32_le(s, result); |
out_uint32_le(s, result); |
331 |
out_uint8p(s, buffer, length); |
out_uint8p(s, buffer, length); |
332 |
s_mark_end(s); |
s_mark_end(s); |
333 |
/* JIF |
/* JIF */ |
334 |
hexdump(s->channel_hdr + 8, s->end - s->channel_hdr - 8); */ |
#ifdef WITH_DEBUG_RDP5 |
335 |
|
printf("--> rdpdr_send_completion\n"); |
336 |
|
/* hexdump(s->channel_hdr + 8, s->end - s->channel_hdr - 8); */ |
337 |
|
#endif |
338 |
channel_send(s, rdpdr_channel); |
channel_send(s, rdpdr_channel); |
339 |
|
#ifdef WITH_SCARD |
340 |
|
scard_unlock(SCARD_LOCK_RDPDR); |
341 |
|
#endif |
342 |
} |
} |
343 |
|
|
344 |
static void |
static void |
361 |
error_mode, |
error_mode, |
362 |
share_mode, disposition, total_timeout, interval_timeout, flags_and_attributes = 0; |
share_mode, disposition, total_timeout, interval_timeout, flags_and_attributes = 0; |
363 |
|
|
364 |
char filename[256]; |
char filename[PATH_MAX]; |
365 |
uint8 *buffer, *pst_buf; |
uint8 *buffer, *pst_buf; |
366 |
struct stream out; |
struct stream out; |
367 |
DEVICE_FNS *fns; |
DEVICE_FNS *fns; |
368 |
BOOL rw_blocking = True; |
RD_BOOL rw_blocking = True; |
369 |
NTSTATUS status = STATUS_INVALID_DEVICE_REQUEST; |
RD_NTSTATUS status = RD_STATUS_INVALID_DEVICE_REQUEST; |
370 |
|
|
371 |
in_uint32_le(s, device); |
in_uint32_le(s, device); |
372 |
in_uint32_le(s, file); |
in_uint32_le(s, file); |
404 |
break; |
break; |
405 |
|
|
406 |
case DEVICE_TYPE_SCARD: |
case DEVICE_TYPE_SCARD: |
407 |
|
#ifdef WITH_SCARD |
408 |
|
fns = &scard_fns; |
409 |
|
rw_blocking = False; |
410 |
|
break; |
411 |
|
#endif |
412 |
default: |
default: |
413 |
|
|
414 |
error("IRP for bad device %ld\n", device); |
error("IRP for bad device %ld\n", device); |
420 |
case IRP_MJ_CREATE: |
case IRP_MJ_CREATE: |
421 |
|
|
422 |
in_uint32_be(s, desired_access); |
in_uint32_be(s, desired_access); |
423 |
in_uint8s(s, 0x08); // unknown |
in_uint8s(s, 0x08); /* unknown */ |
424 |
in_uint32_le(s, error_mode); |
in_uint32_le(s, error_mode); |
425 |
in_uint32_le(s, share_mode); |
in_uint32_le(s, share_mode); |
426 |
in_uint32_le(s, disposition); |
in_uint32_le(s, disposition); |
429 |
|
|
430 |
if (length && (length / 2) < 256) |
if (length && (length / 2) < 256) |
431 |
{ |
{ |
432 |
rdp_in_unistr(s, filename, length); |
rdp_in_unistr(s, filename, sizeof(filename), length); |
433 |
convert_to_unix_filename(filename); |
convert_to_unix_filename(filename); |
434 |
} |
} |
435 |
else |
else |
439 |
|
|
440 |
if (!fns->create) |
if (!fns->create) |
441 |
{ |
{ |
442 |
status = STATUS_NOT_SUPPORTED; |
status = RD_STATUS_NOT_SUPPORTED; |
443 |
break; |
break; |
444 |
} |
} |
445 |
|
|
451 |
case IRP_MJ_CLOSE: |
case IRP_MJ_CLOSE: |
452 |
if (!fns->close) |
if (!fns->close) |
453 |
{ |
{ |
454 |
status = STATUS_NOT_SUPPORTED; |
status = RD_STATUS_NOT_SUPPORTED; |
455 |
break; |
break; |
456 |
} |
} |
457 |
|
|
462 |
|
|
463 |
if (!fns->read) |
if (!fns->read) |
464 |
{ |
{ |
465 |
status = STATUS_NOT_SUPPORTED; |
status = RD_STATUS_NOT_SUPPORTED; |
466 |
break; |
break; |
467 |
} |
} |
468 |
|
|
473 |
#endif |
#endif |
474 |
if (!rdpdr_handle_ok(device, file)) |
if (!rdpdr_handle_ok(device, file)) |
475 |
{ |
{ |
476 |
status = STATUS_INVALID_HANDLE; |
status = RD_STATUS_INVALID_HANDLE; |
477 |
break; |
break; |
478 |
} |
} |
479 |
|
|
480 |
if (rw_blocking) // Complete read immediately |
if (rw_blocking) /* Complete read immediately */ |
481 |
{ |
{ |
482 |
buffer = (uint8 *) xrealloc((void *) buffer, length); |
buffer = (uint8 *) xrealloc((void *) buffer, length); |
483 |
if (!buffer) |
if (!buffer) |
484 |
{ |
{ |
485 |
status = STATUS_CANCELLED; |
status = RD_STATUS_CANCELLED; |
486 |
break; |
break; |
487 |
} |
} |
488 |
status = fns->read(file, buffer, length, offset, &result); |
status = fns->read(file, buffer, length, offset, &result); |
490 |
break; |
break; |
491 |
} |
} |
492 |
|
|
493 |
// Add request to table |
/* Add request to table */ |
494 |
pst_buf = (uint8 *) xmalloc(length); |
pst_buf = (uint8 *) xmalloc(length); |
495 |
if (!pst_buf) |
if (!pst_buf) |
496 |
{ |
{ |
497 |
status = STATUS_CANCELLED; |
status = RD_STATUS_CANCELLED; |
498 |
break; |
break; |
499 |
} |
} |
500 |
serial_get_timeout(file, length, &total_timeout, &interval_timeout); |
serial_get_timeout(file, length, &total_timeout, &interval_timeout); |
502 |
(device, file, id, major, length, fns, total_timeout, interval_timeout, |
(device, file, id, major, length, fns, total_timeout, interval_timeout, |
503 |
pst_buf, offset)) |
pst_buf, offset)) |
504 |
{ |
{ |
505 |
status = STATUS_PENDING; |
status = RD_STATUS_PENDING; |
506 |
break; |
break; |
507 |
} |
} |
508 |
|
|
509 |
status = STATUS_CANCELLED; |
status = RD_STATUS_CANCELLED; |
510 |
break; |
break; |
511 |
case IRP_MJ_WRITE: |
case IRP_MJ_WRITE: |
512 |
|
|
514 |
|
|
515 |
if (!fns->write) |
if (!fns->write) |
516 |
{ |
{ |
517 |
status = STATUS_NOT_SUPPORTED; |
status = RD_STATUS_NOT_SUPPORTED; |
518 |
break; |
break; |
519 |
} |
} |
520 |
|
|
526 |
#endif |
#endif |
527 |
if (!rdpdr_handle_ok(device, file)) |
if (!rdpdr_handle_ok(device, file)) |
528 |
{ |
{ |
529 |
status = STATUS_INVALID_HANDLE; |
status = RD_STATUS_INVALID_HANDLE; |
530 |
break; |
break; |
531 |
} |
} |
532 |
|
|
533 |
if (rw_blocking) // Complete immediately |
if (rw_blocking) /* Complete immediately */ |
534 |
{ |
{ |
535 |
status = fns->write(file, s->p, length, offset, &result); |
status = fns->write(file, s->p, length, offset, &result); |
536 |
break; |
break; |
537 |
} |
} |
538 |
|
|
539 |
// Add to table |
/* Add to table */ |
540 |
pst_buf = (uint8 *) xmalloc(length); |
pst_buf = (uint8 *) xmalloc(length); |
541 |
if (!pst_buf) |
if (!pst_buf) |
542 |
{ |
{ |
543 |
status = STATUS_CANCELLED; |
status = RD_STATUS_CANCELLED; |
544 |
break; |
break; |
545 |
} |
} |
546 |
|
|
549 |
if (add_async_iorequest |
if (add_async_iorequest |
550 |
(device, file, id, major, length, fns, 0, 0, pst_buf, offset)) |
(device, file, id, major, length, fns, 0, 0, pst_buf, offset)) |
551 |
{ |
{ |
552 |
status = STATUS_PENDING; |
status = RD_STATUS_PENDING; |
553 |
break; |
break; |
554 |
} |
} |
555 |
|
|
556 |
status = STATUS_CANCELLED; |
status = RD_STATUS_CANCELLED; |
557 |
break; |
break; |
558 |
|
|
559 |
case IRP_MJ_QUERY_INFORMATION: |
case IRP_MJ_QUERY_INFORMATION: |
560 |
|
|
561 |
if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK) |
if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK) |
562 |
{ |
{ |
563 |
status = STATUS_INVALID_HANDLE; |
status = RD_STATUS_INVALID_HANDLE; |
564 |
break; |
break; |
565 |
} |
} |
566 |
in_uint32_le(s, info_level); |
in_uint32_le(s, info_level); |
576 |
|
|
577 |
if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK) |
if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK) |
578 |
{ |
{ |
579 |
status = STATUS_INVALID_HANDLE; |
status = RD_STATUS_INVALID_HANDLE; |
580 |
break; |
break; |
581 |
} |
} |
582 |
|
|
592 |
|
|
593 |
if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK) |
if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK) |
594 |
{ |
{ |
595 |
status = STATUS_INVALID_HANDLE; |
status = RD_STATUS_INVALID_HANDLE; |
596 |
break; |
break; |
597 |
} |
} |
598 |
|
|
608 |
|
|
609 |
if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK) |
if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK) |
610 |
{ |
{ |
611 |
status = STATUS_INVALID_HANDLE; |
status = RD_STATUS_INVALID_HANDLE; |
612 |
break; |
break; |
613 |
} |
} |
614 |
|
|
622 |
in_uint8s(s, 0x17); |
in_uint8s(s, 0x17); |
623 |
if (length && length < 2 * 255) |
if (length && length < 2 * 255) |
624 |
{ |
{ |
625 |
rdp_in_unistr(s, filename, length); |
rdp_in_unistr(s, filename, sizeof(filename), |
626 |
|
length); |
627 |
convert_to_unix_filename(filename); |
convert_to_unix_filename(filename); |
628 |
} |
} |
629 |
else |
else |
642 |
case IRP_MN_NOTIFY_CHANGE_DIRECTORY: |
case IRP_MN_NOTIFY_CHANGE_DIRECTORY: |
643 |
|
|
644 |
/* JIF |
/* JIF |
645 |
unimpl("IRP major=0x%x minor=0x%x: IRP_MN_NOTIFY_CHANGE_DIRECTORY\n", major, minor); */ |
unimpl("IRP major=0x%x minor=0x%x: IRP_MN_NOTIFY_CHANGE_DIRECTORY\n", major, minor); */ |
646 |
status = STATUS_PENDING; // Don't send completion packet |
|
647 |
|
in_uint32_le(s, info_level); /* notify mask */ |
648 |
|
|
649 |
|
status = disk_create_notify(file, info_level); |
650 |
|
result = 0; |
651 |
|
|
652 |
|
if (status == RD_STATUS_PENDING) |
653 |
|
add_async_iorequest(device, file, id, major, length, |
654 |
|
fns, 0, 0, NULL, 0); |
655 |
break; |
break; |
656 |
|
|
657 |
default: |
default: |
658 |
|
|
659 |
status = STATUS_INVALID_PARAMETER; |
status = RD_STATUS_INVALID_PARAMETER; |
660 |
/* JIF |
/* JIF */ |
661 |
unimpl("IRP major=0x%x minor=0x%x\n", major, minor); */ |
unimpl("IRP major=0x%x minor=0x%x\n", major, minor); |
662 |
} |
} |
663 |
break; |
break; |
664 |
|
|
666 |
|
|
667 |
if (!fns->device_control) |
if (!fns->device_control) |
668 |
{ |
{ |
669 |
status = STATUS_NOT_SUPPORTED; |
status = RD_STATUS_NOT_SUPPORTED; |
670 |
break; |
break; |
671 |
} |
} |
672 |
|
|
678 |
buffer = (uint8 *) xrealloc((void *) buffer, bytes_out + 0x14); |
buffer = (uint8 *) xrealloc((void *) buffer, bytes_out + 0x14); |
679 |
if (!buffer) |
if (!buffer) |
680 |
{ |
{ |
681 |
status = STATUS_CANCELLED; |
status = RD_STATUS_CANCELLED; |
682 |
break; |
break; |
683 |
} |
} |
684 |
|
|
685 |
out.data = out.p = buffer; |
out.data = out.p = buffer; |
686 |
out.size = sizeof(buffer); |
out.size = sizeof(buffer); |
687 |
|
|
688 |
|
#ifdef WITH_SCARD |
689 |
|
scardSetInfo(device, id, bytes_out + 0x14); |
690 |
|
#endif |
691 |
status = fns->device_control(file, request, s, &out); |
status = fns->device_control(file, request, s, &out); |
692 |
result = buffer_len = out.p - out.data; |
result = buffer_len = out.p - out.data; |
693 |
|
|
694 |
|
/* Serial SERIAL_WAIT_ON_MASK */ |
695 |
|
if (status == RD_STATUS_PENDING) |
696 |
|
{ |
697 |
|
if (add_async_iorequest |
698 |
|
(device, file, id, major, length, fns, 0, 0, NULL, 0)) |
699 |
|
{ |
700 |
|
status = RD_STATUS_PENDING; |
701 |
|
break; |
702 |
|
} |
703 |
|
} |
704 |
|
#ifdef WITH_SCARD |
705 |
|
else if (status == (RD_STATUS_PENDING | 0xC0000000)) |
706 |
|
status = RD_STATUS_PENDING; |
707 |
|
#endif |
708 |
break; |
break; |
709 |
|
|
710 |
|
|
712 |
|
|
713 |
if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK) |
if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK) |
714 |
{ |
{ |
715 |
status = STATUS_INVALID_HANDLE; |
status = RD_STATUS_INVALID_HANDLE; |
716 |
break; |
break; |
717 |
} |
} |
718 |
|
|
722 |
out.size = sizeof(buffer); |
out.size = sizeof(buffer); |
723 |
/* FIXME: Perhaps consider actually *do* |
/* FIXME: Perhaps consider actually *do* |
724 |
something here :-) */ |
something here :-) */ |
725 |
status = STATUS_SUCCESS; |
status = RD_STATUS_SUCCESS; |
726 |
result = buffer_len = out.p - out.data; |
result = buffer_len = out.p - out.data; |
727 |
break; |
break; |
728 |
|
|
731 |
break; |
break; |
732 |
} |
} |
733 |
|
|
734 |
if (status != STATUS_PENDING) |
if (status != RD_STATUS_PENDING) |
735 |
{ |
{ |
736 |
rdpdr_send_completion(device, id, status, result, buffer, buffer_len); |
rdpdr_send_completion(device, id, status, result, buffer, buffer_len); |
737 |
} |
} |
838 |
unimpl("RDPDR packet type %c%c%c%c\n", magic[0], magic[1], magic[2], magic[3]); |
unimpl("RDPDR packet type %c%c%c%c\n", magic[0], magic[1], magic[2], magic[3]); |
839 |
} |
} |
840 |
|
|
841 |
BOOL |
RD_BOOL |
842 |
rdpdr_init() |
rdpdr_init() |
843 |
{ |
{ |
844 |
if (g_num_devices > 0) |
if (g_num_devices > 0) |
854 |
|
|
855 |
/* Add file descriptors of pending io request to select() */ |
/* Add file descriptors of pending io request to select() */ |
856 |
void |
void |
857 |
rdpdr_add_fds(int *n, fd_set * rfds, fd_set * wfds, struct timeval *tv, BOOL * timeout) |
rdpdr_add_fds(int *n, fd_set * rfds, fd_set * wfds, struct timeval *tv, RD_BOOL * timeout) |
858 |
{ |
{ |
859 |
uint32 select_timeout = 0; // Timeout value to be used for select() (in millisecons). |
uint32 select_timeout = 0; /* Timeout value to be used for select() (in millisecons). */ |
860 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
861 |
char c; |
char c; |
862 |
|
|
873 |
reconnecting. FIXME: Real |
reconnecting. FIXME: Real |
874 |
support for reconnects. */ |
support for reconnects. */ |
875 |
|
|
|
if ((read(iorq->fd, &c, 0) != 0) && (errno == EBADF)) |
|
|
break; |
|
|
|
|
876 |
FD_SET(iorq->fd, rfds); |
FD_SET(iorq->fd, rfds); |
877 |
*n = MAX(*n, iorq->fd); |
*n = MAX(*n, iorq->fd); |
878 |
|
|
879 |
// Check if io request timeout is smaller than current (but not 0). |
/* Check if io request timeout is smaller than current (but not 0). */ |
880 |
if (iorq->timeout |
if (iorq->timeout |
881 |
&& (select_timeout == 0 |
&& (select_timeout == 0 |
882 |
|| iorq->timeout < select_timeout)) |
|| iorq->timeout < select_timeout)) |
883 |
{ |
{ |
884 |
// Set new timeout |
/* Set new timeout */ |
885 |
select_timeout = iorq->timeout; |
select_timeout = iorq->timeout; |
886 |
g_min_timeout_fd = iorq->fd; /* Remember fd */ |
g_min_timeout_fd = iorq->fd; /* Remember fd */ |
887 |
tv->tv_sec = select_timeout / 1000; |
tv->tv_sec = select_timeout / 1000; |
888 |
tv->tv_usec = (select_timeout % 1000) * 1000; |
tv->tv_usec = (select_timeout % 1000) * 1000; |
889 |
*timeout = True; |
*timeout = True; |
890 |
|
break; |
891 |
|
} |
892 |
|
if (iorq->itv_timeout && iorq->partial_len > 0 |
893 |
|
&& (select_timeout == 0 |
894 |
|
|| iorq->itv_timeout < select_timeout)) |
895 |
|
{ |
896 |
|
/* Set new timeout */ |
897 |
|
select_timeout = iorq->itv_timeout; |
898 |
|
g_min_timeout_fd = iorq->fd; /* Remember fd */ |
899 |
|
tv->tv_sec = select_timeout / 1000; |
900 |
|
tv->tv_usec = (select_timeout % 1000) * 1000; |
901 |
|
*timeout = True; |
902 |
|
break; |
903 |
} |
} |
|
|
|
904 |
break; |
break; |
905 |
|
|
906 |
case IRP_MJ_WRITE: |
case IRP_MJ_WRITE: |
912 |
*n = MAX(*n, iorq->fd); |
*n = MAX(*n, iorq->fd); |
913 |
break; |
break; |
914 |
|
|
915 |
|
case IRP_MJ_DEVICE_CONTROL: |
916 |
|
if (select_timeout > 5) |
917 |
|
select_timeout = 5; /* serial event queue */ |
918 |
|
break; |
919 |
|
|
920 |
} |
} |
921 |
|
|
922 |
} |
} |
941 |
} |
} |
942 |
else |
else |
943 |
{ |
{ |
944 |
// Even if NULL |
/* Even if NULL */ |
945 |
g_iorequest = iorq->next; |
g_iorequest = iorq->next; |
946 |
xfree(iorq); |
xfree(iorq); |
947 |
iorq = NULL; |
iorq = NULL; |
950 |
} |
} |
951 |
|
|
952 |
/* Check if select() returned with one of the rdpdr file descriptors, and complete io if it did */ |
/* Check if select() returned with one of the rdpdr file descriptors, and complete io if it did */ |
953 |
void |
static void |
954 |
rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out) |
_rdpdr_check_fds(fd_set * rfds, fd_set * wfds, RD_BOOL timed_out) |
955 |
{ |
{ |
956 |
NTSTATUS status; |
RD_NTSTATUS status; |
957 |
uint32 result = 0; |
uint32 result = 0; |
958 |
DEVICE_FNS *fns; |
DEVICE_FNS *fns; |
959 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
960 |
struct async_iorequest *prev; |
struct async_iorequest *prev; |
961 |
uint32 req_size = 0; |
uint32 req_size = 0; |
962 |
|
uint32 buffer_len; |
963 |
|
struct stream out; |
964 |
|
uint8 *buffer = NULL; |
965 |
|
|
966 |
|
|
967 |
if (timed_out) |
if (timed_out) |
968 |
{ |
{ |
969 |
rdpdr_abort_io(g_min_timeout_fd, 0, STATUS_TIMEOUT); |
/* check serial iv_timeout */ |
970 |
|
|
971 |
|
iorq = g_iorequest; |
972 |
|
prev = NULL; |
973 |
|
while (iorq != NULL) |
974 |
|
{ |
975 |
|
if (iorq->fd == g_min_timeout_fd) |
976 |
|
{ |
977 |
|
if ((iorq->partial_len > 0) && |
978 |
|
(g_rdpdr_device[iorq->device].device_type == |
979 |
|
DEVICE_TYPE_SERIAL)) |
980 |
|
{ |
981 |
|
|
982 |
|
/* iv_timeout between 2 chars, send partial_len */ |
983 |
|
/*printf("RDPDR: IVT total %u bytes read of %u\n", iorq->partial_len, iorq->length); */ |
984 |
|
rdpdr_send_completion(iorq->device, |
985 |
|
iorq->id, RD_STATUS_SUCCESS, |
986 |
|
iorq->partial_len, |
987 |
|
iorq->buffer, iorq->partial_len); |
988 |
|
iorq = rdpdr_remove_iorequest(prev, iorq); |
989 |
|
return; |
990 |
|
} |
991 |
|
else |
992 |
|
{ |
993 |
|
break; |
994 |
|
} |
995 |
|
|
996 |
|
} |
997 |
|
else |
998 |
|
{ |
999 |
|
break; |
1000 |
|
} |
1001 |
|
|
1002 |
|
|
1003 |
|
prev = iorq; |
1004 |
|
if (iorq) |
1005 |
|
iorq = iorq->next; |
1006 |
|
|
1007 |
|
} |
1008 |
|
|
1009 |
|
rdpdr_abort_io(g_min_timeout_fd, 0, RD_STATUS_TIMEOUT); |
1010 |
return; |
return; |
1011 |
} |
} |
1012 |
|
|
1033 |
iorq->buffer + iorq->partial_len, |
iorq->buffer + iorq->partial_len, |
1034 |
req_size, iorq->offset, &result); |
req_size, iorq->offset, &result); |
1035 |
|
|
1036 |
if (result > 0) |
if ((long) result > 0) |
1037 |
{ |
{ |
1038 |
iorq->partial_len += result; |
iorq->partial_len += result; |
1039 |
iorq->offset += result; |
iorq->offset += result; |
1075 |
iorq->partial_len, req_size, |
iorq->partial_len, req_size, |
1076 |
iorq->offset, &result); |
iorq->offset, &result); |
1077 |
|
|
1078 |
if (result > 0) |
if ((long) result > 0) |
1079 |
{ |
{ |
1080 |
iorq->partial_len += result; |
iorq->partial_len += result; |
1081 |
iorq->offset += result; |
iorq->offset += result; |
1102 |
} |
} |
1103 |
} |
} |
1104 |
break; |
break; |
1105 |
|
case IRP_MJ_DEVICE_CONTROL: |
1106 |
|
if (serial_get_event(iorq->fd, &result)) |
1107 |
|
{ |
1108 |
|
buffer = (uint8 *) xrealloc((void *) buffer, 0x14); |
1109 |
|
out.data = out.p = buffer; |
1110 |
|
out.size = sizeof(buffer); |
1111 |
|
out_uint32_le(&out, result); |
1112 |
|
result = buffer_len = out.p - out.data; |
1113 |
|
status = RD_STATUS_SUCCESS; |
1114 |
|
rdpdr_send_completion(iorq->device, iorq->id, |
1115 |
|
status, result, buffer, |
1116 |
|
buffer_len); |
1117 |
|
xfree(buffer); |
1118 |
|
iorq = rdpdr_remove_iorequest(prev, iorq); |
1119 |
|
} |
1120 |
|
|
1121 |
|
break; |
1122 |
} |
} |
1123 |
|
|
1124 |
} |
} |
1127 |
iorq = iorq->next; |
iorq = iorq->next; |
1128 |
} |
} |
1129 |
|
|
1130 |
|
/* Check notify */ |
1131 |
|
iorq = g_iorequest; |
1132 |
|
prev = NULL; |
1133 |
|
while (iorq != NULL) |
1134 |
|
{ |
1135 |
|
if (iorq->fd != 0) |
1136 |
|
{ |
1137 |
|
switch (iorq->major) |
1138 |
|
{ |
1139 |
|
|
1140 |
|
case IRP_MJ_DIRECTORY_CONTROL: |
1141 |
|
if (g_rdpdr_device[iorq->device].device_type == |
1142 |
|
DEVICE_TYPE_DISK) |
1143 |
|
{ |
1144 |
|
|
1145 |
|
if (g_notify_stamp) |
1146 |
|
{ |
1147 |
|
g_notify_stamp = False; |
1148 |
|
status = disk_check_notify(iorq->fd); |
1149 |
|
if (status != RD_STATUS_PENDING) |
1150 |
|
{ |
1151 |
|
rdpdr_send_completion(iorq->device, |
1152 |
|
iorq->id, |
1153 |
|
status, 0, |
1154 |
|
NULL, 0); |
1155 |
|
iorq = rdpdr_remove_iorequest(prev, |
1156 |
|
iorq); |
1157 |
|
} |
1158 |
|
} |
1159 |
|
} |
1160 |
|
break; |
1161 |
|
|
1162 |
|
|
1163 |
|
|
1164 |
|
} |
1165 |
|
} |
1166 |
|
|
1167 |
|
prev = iorq; |
1168 |
|
if (iorq) |
1169 |
|
iorq = iorq->next; |
1170 |
|
} |
1171 |
|
|
1172 |
|
} |
1173 |
|
|
1174 |
|
void |
1175 |
|
rdpdr_check_fds(fd_set * rfds, fd_set * wfds, RD_BOOL timed_out) |
1176 |
|
{ |
1177 |
|
fd_set dummy; |
1178 |
|
|
1179 |
|
|
1180 |
|
FD_ZERO(&dummy); |
1181 |
|
|
1182 |
|
|
1183 |
|
/* fist check event queue only, |
1184 |
|
any serial wait event must be done before read block will be sent |
1185 |
|
*/ |
1186 |
|
|
1187 |
|
_rdpdr_check_fds(&dummy, &dummy, False); |
1188 |
|
_rdpdr_check_fds(rfds, wfds, timed_out); |
1189 |
} |
} |
1190 |
|
|
1191 |
|
|
1192 |
/* Abort a pending io request for a given handle and major */ |
/* Abort a pending io request for a given handle and major */ |
1193 |
BOOL |
RD_BOOL |
1194 |
rdpdr_abort_io(uint32 fd, uint32 major, NTSTATUS status) |
rdpdr_abort_io(uint32 fd, uint32 major, RD_NTSTATUS status) |
1195 |
{ |
{ |
1196 |
uint32 result; |
uint32 result; |
1197 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
1201 |
prev = NULL; |
prev = NULL; |
1202 |
while (iorq != NULL) |
while (iorq != NULL) |
1203 |
{ |
{ |
1204 |
// Only remove from table when major is not set, or when correct major is supplied. |
/* Only remove from table when major is not set, or when correct major is supplied. |
1205 |
// Abort read should not abort a write io request. |
Abort read should not abort a write io request. */ |
1206 |
if ((iorq->fd == fd) && (major == 0 || iorq->major == major)) |
if ((iorq->fd == fd) && (major == 0 || iorq->major == major)) |
1207 |
{ |
{ |
1208 |
result = 0; |
result = 0; |