22 |
#define IRP_MN_QUERY_DIRECTORY 0x01 |
#define IRP_MN_QUERY_DIRECTORY 0x01 |
23 |
#define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02 |
#define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02 |
24 |
|
|
|
//#define MAX_ASYNC_IO_REQUESTS 10 |
|
|
|
|
25 |
extern char hostname[16]; |
extern char hostname[16]; |
26 |
extern DEVICE_FNS serial_fns; |
extern DEVICE_FNS serial_fns; |
27 |
extern DEVICE_FNS printer_fns; |
extern DEVICE_FNS printer_fns; |
28 |
extern DEVICE_FNS parallel_fns; |
extern DEVICE_FNS parallel_fns; |
29 |
extern DEVICE_FNS disk_fns; |
extern DEVICE_FNS disk_fns; |
30 |
|
|
|
|
|
31 |
static VCHANNEL *rdpdr_channel; |
static VCHANNEL *rdpdr_channel; |
32 |
|
|
33 |
/* 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 */ |
37 |
/* Table with information about rdpdr devices */ |
/* Table with information about rdpdr devices */ |
38 |
RDPDR_DEVICE g_rdpdr_device[RDPDR_MAX_DEVICES]; |
RDPDR_DEVICE g_rdpdr_device[RDPDR_MAX_DEVICES]; |
39 |
|
|
|
#if 0 |
|
40 |
/* Used to store incoming io request, until they are ready to be completed */ |
/* Used to store incoming io request, until they are ready to be completed */ |
41 |
|
/* using a linked list ensures that they are processed in the right order, */ |
42 |
|
/* if multiple ios are being done on the same fd */ |
43 |
struct async_iorequest |
struct async_iorequest |
44 |
{ |
{ |
45 |
uint32 fd, major, minor, offset, device, id, length; |
uint32 fd, major, minor, offset, device, id, length, partial_len; |
46 |
long timeout, /* Total timeout */ |
long timeout, /* Total timeout */ |
47 |
itv_timeout; /* Interval timeout (between serial characters) */ |
itv_timeout; /* Interval timeout (between serial characters) */ |
48 |
uint8 *buffer; |
uint8 *buffer; |
49 |
DEVICE_FNS *fns; |
DEVICE_FNS *fns; |
50 |
} g_iorequest[MAX_ASYNC_IO_REQUESTS]; |
|
51 |
#endif |
struct async_iorequest *next; /* next element in list */ |
52 |
|
}; |
53 |
|
|
54 |
|
struct async_iorequest *g_iorequest; |
55 |
|
|
56 |
/* Return device_id for a given handle */ |
/* Return device_id for a given handle */ |
57 |
int |
int |
78 |
} |
} |
79 |
} |
} |
80 |
|
|
|
#if 0 |
|
81 |
/* 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 */ |
82 |
BOOL |
BOOL |
83 |
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, |
84 |
DEVICE_FNS * fns, long total_timeout, long interval_timeout, uint8 * buffer) |
DEVICE_FNS * fns, long total_timeout, long interval_timeout, uint8 * buffer) |
85 |
{ |
{ |
|
int i; |
|
86 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
87 |
|
|
88 |
for (i = 0; i < MAX_ASYNC_IO_REQUESTS; i++) |
if (g_iorequest == NULL) |
89 |
{ |
{ |
90 |
iorq = &g_iorequest[i]; |
g_iorequest = (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest)); |
91 |
|
g_iorequest->fd = 0; |
92 |
if (iorq->fd == 0) |
g_iorequest->next = NULL; |
93 |
{ |
} |
94 |
iorq->device = device; |
|
95 |
iorq->fd = file; |
iorq = g_iorequest; |
96 |
iorq->id = id; |
|
97 |
iorq->major = major; |
while (iorq->fd != 0) |
98 |
iorq->length = length; |
{ |
99 |
iorq->fns = fns; |
// create new element if needed |
100 |
iorq->timeout = total_timeout; |
if (iorq->next == NULL) |
101 |
iorq->itv_timeout = interval_timeout; |
{ |
102 |
iorq->buffer = buffer; |
iorq->next = |
103 |
return True; |
(struct async_iorequest *) xmalloc(sizeof(struct async_iorequest)); |
104 |
} |
iorq->next->fd = 0; |
105 |
} |
iorq->next->next = NULL; |
106 |
error("IO request table full. Increase MAX_ASYNC_IO_REQUESTS in rdpdr.c!\n"); |
} |
107 |
return False; |
iorq = iorq->next; |
108 |
|
} |
109 |
|
iorq->device = device; |
110 |
|
iorq->fd = file; |
111 |
|
iorq->id = id; |
112 |
|
iorq->major = major; |
113 |
|
iorq->length = length; |
114 |
|
iorq->partial_len = 0; |
115 |
|
iorq->fns = fns; |
116 |
|
iorq->timeout = total_timeout; |
117 |
|
iorq->itv_timeout = interval_timeout; |
118 |
|
iorq->buffer = buffer; |
119 |
|
return True; |
120 |
} |
} |
|
#endif |
|
121 |
|
|
122 |
void |
void |
123 |
rdpdr_send_connect(void) |
rdpdr_send_connect(void) |
300 |
case DEVICE_TYPE_SERIAL: |
case DEVICE_TYPE_SERIAL: |
301 |
|
|
302 |
fns = &serial_fns; |
fns = &serial_fns; |
303 |
/* should be async when aio is finished */ |
rw_blocking = False; |
|
/*rw_blocking = False; */ |
|
304 |
break; |
break; |
305 |
|
|
306 |
case DEVICE_TYPE_PARALLEL: |
case DEVICE_TYPE_PARALLEL: |
307 |
|
|
308 |
fns = ¶llel_fns; |
fns = ¶llel_fns; |
309 |
/* should be async when aio is finished */ |
rw_blocking = False; |
|
/*rw_blocking = False;*/ |
|
310 |
break; |
break; |
311 |
|
|
312 |
case DEVICE_TYPE_PRINTER: |
case DEVICE_TYPE_PRINTER: |
317 |
case DEVICE_TYPE_DISK: |
case DEVICE_TYPE_DISK: |
318 |
|
|
319 |
fns = &disk_fns; |
fns = &disk_fns; |
320 |
|
/*rw_blocking = False; */ |
321 |
break; |
break; |
322 |
|
|
323 |
case DEVICE_TYPE_SCARD: |
case DEVICE_TYPE_SCARD: |
383 |
#if WITH_DEBUG_RDP5 |
#if WITH_DEBUG_RDP5 |
384 |
DEBUG(("RDPDR IRP Read (length: %d, offset: %d)\n", length, offset)); |
DEBUG(("RDPDR IRP Read (length: %d, offset: %d)\n", length, offset)); |
385 |
#endif |
#endif |
386 |
// if (rw_blocking) // Complete read immediately |
if (rw_blocking) // Complete read immediately |
387 |
// { |
{ |
388 |
buffer = (uint8 *) xrealloc((void *) buffer, length); |
buffer = (uint8 *) xrealloc((void *) buffer, length); |
389 |
status = fns->read(file, buffer, length, offset, &result); |
status = fns->read(file, buffer, length, offset, &result); |
390 |
buffer_len = result; |
buffer_len = result; |
391 |
break; |
break; |
392 |
// } |
} |
393 |
|
|
|
#if 0 |
|
394 |
// Add request to table |
// Add request to table |
395 |
pst_buf = (uint8 *) xmalloc(length); |
pst_buf = (uint8 *) xmalloc(length); |
396 |
serial_get_timeout(file, length, &total_timeout, &interval_timeout); |
serial_get_timeout(file, length, &total_timeout, &interval_timeout); |
404 |
|
|
405 |
status = STATUS_CANCELLED; |
status = STATUS_CANCELLED; |
406 |
break; |
break; |
|
#endif |
|
407 |
case IRP_MJ_WRITE: |
case IRP_MJ_WRITE: |
408 |
|
|
409 |
buffer_len = 1; |
buffer_len = 1; |
420 |
#if WITH_DEBUG_RDP5 |
#if WITH_DEBUG_RDP5 |
421 |
DEBUG(("RDPDR IRP Write (length: %d)\n", result)); |
DEBUG(("RDPDR IRP Write (length: %d)\n", result)); |
422 |
#endif |
#endif |
423 |
// if (rw_blocking) // Complete immediately |
if (rw_blocking) // Complete immediately |
424 |
// { |
{ |
425 |
status = fns->write(file, s->p, length, offset, &result); |
status = fns->write(file, s->p, length, offset, &result); |
426 |
break; |
break; |
427 |
// } |
} |
428 |
#if 0 |
|
429 |
// Add to table |
// Add to table |
430 |
pst_buf = (uint8 *) xmalloc(length); |
pst_buf = (uint8 *) xmalloc(length); |
431 |
in_uint8a(s, pst_buf, length); |
in_uint8a(s, pst_buf, length); |
439 |
|
|
440 |
status = STATUS_CANCELLED; |
status = STATUS_CANCELLED; |
441 |
break; |
break; |
|
#endif |
|
442 |
|
|
443 |
case IRP_MJ_QUERY_INFORMATION: |
case IRP_MJ_QUERY_INFORMATION: |
444 |
|
|
682 |
return (rdpdr_channel != NULL); |
return (rdpdr_channel != NULL); |
683 |
} |
} |
684 |
|
|
|
#if 0 |
|
685 |
/* Add file descriptors of pending io request to select() */ |
/* Add file descriptors of pending io request to select() */ |
686 |
void |
void |
687 |
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, BOOL * timeout) |
688 |
{ |
{ |
|
int i; |
|
689 |
long select_timeout = 0; // Timeout value to be used for select() (in millisecons). |
long select_timeout = 0; // Timeout value to be used for select() (in millisecons). |
690 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
691 |
|
|
692 |
for (i = 0; i < MAX_ASYNC_IO_REQUESTS; i++) |
iorq = g_iorequest; |
693 |
|
while (iorq != NULL) |
694 |
{ |
{ |
695 |
iorq = &g_iorequest[i]; |
if (iorq->fd != 0) |
|
|
|
|
if (iorq->fd != 0) // Found a pending io request |
|
696 |
{ |
{ |
697 |
switch (iorq->major) |
switch (iorq->major) |
698 |
{ |
{ |
715 |
break; |
break; |
716 |
|
|
717 |
case IRP_MJ_WRITE: |
case IRP_MJ_WRITE: |
|
|
|
718 |
FD_SET(iorq->fd, wfds); |
FD_SET(iorq->fd, wfds); |
719 |
break; |
break; |
720 |
|
|
721 |
} |
} |
722 |
*n = MAX(*n, iorq->fd); |
*n = MAX(*n, iorq->fd); |
723 |
} |
} |
724 |
|
|
725 |
|
iorq = iorq->next; |
726 |
} |
} |
727 |
} |
} |
728 |
|
|
731 |
void |
void |
732 |
rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out) |
rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out) |
733 |
{ |
{ |
|
int i; |
|
734 |
NTSTATUS status; |
NTSTATUS status; |
735 |
uint32 result = 0, buffer_len = 0; |
uint32 result = 0; |
736 |
DEVICE_FNS *fns; |
DEVICE_FNS *fns; |
737 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
738 |
|
struct async_iorequest *prev; |
739 |
|
|
740 |
if (timed_out) |
if (timed_out) |
741 |
{ |
{ |
743 |
return; |
return; |
744 |
} |
} |
745 |
|
|
746 |
// Walk through array of pending io_rq's |
iorq = g_iorequest; |
747 |
for (i = 0; i < MAX_ASYNC_IO_REQUESTS; i++) |
prev = NULL; |
748 |
|
while (iorq != NULL) |
749 |
{ |
{ |
|
iorq = &g_iorequest[i]; |
|
750 |
|
|
751 |
if (iorq->fd != 0) |
if (iorq->fd != 0) |
752 |
{ |
{ |
753 |
switch (iorq->major) |
switch (iorq->major) |
754 |
{ |
{ |
|
|
|
755 |
case IRP_MJ_READ: |
case IRP_MJ_READ: |
|
|
|
756 |
if (FD_ISSET(iorq->fd, rfds)) |
if (FD_ISSET(iorq->fd, rfds)) |
757 |
{ |
{ |
758 |
// Read, and send data. |
/* Read the data */ |
759 |
fns = iorq->fns; |
fns = iorq->fns; |
760 |
status = fns->read(iorq->fd, iorq->buffer, |
|
761 |
iorq->length, 0, &result); |
/* never read larger chunks than 8k - chances are that it will block */ |
762 |
buffer_len = result; |
status = fns->read(iorq->fd, |
763 |
|
iorq->buffer + iorq->partial_len, |
764 |
rdpdr_send_completion(iorq->device, iorq->id, |
(iorq->length - |
765 |
status, result, iorq->buffer, |
iorq->partial_len) > |
766 |
buffer_len); |
8192 ? 8192 : (iorq->length - |
767 |
|
iorq-> |
768 |
|
partial_len), 0, |
769 |
|
&result); |
770 |
|
iorq->partial_len += result; |
771 |
#if WITH_DEBUG_RDP5 |
#if WITH_DEBUG_RDP5 |
772 |
DEBUG(("RDPDR: %d bytes of data read\n", result)); |
DEBUG(("RDPDR: %d bytes of data read\n", result)); |
773 |
#endif |
#endif |
774 |
xfree(iorq->buffer); |
/* only delete link if all data has been transfered */ |
775 |
iorq->fd = 0; |
if (iorq->partial_len == iorq->length) |
776 |
|
{ |
777 |
|
/* send the data */ |
778 |
|
status = STATUS_SUCCESS; |
779 |
|
rdpdr_send_completion(iorq->device, |
780 |
|
iorq->id, status, |
781 |
|
iorq->length, |
782 |
|
iorq->buffer, result); |
783 |
|
|
784 |
|
xfree(iorq->buffer); |
785 |
|
iorq->fd = 0; |
786 |
|
if (prev != NULL) |
787 |
|
{ |
788 |
|
prev->next = iorq->next; |
789 |
|
xfree(iorq); |
790 |
|
} |
791 |
|
else |
792 |
|
{ |
793 |
|
// Even if NULL |
794 |
|
g_iorequest = iorq->next; |
795 |
|
xfree(iorq); |
796 |
|
} |
797 |
|
} |
798 |
} |
} |
799 |
break; |
break; |
|
|
|
800 |
case IRP_MJ_WRITE: |
case IRP_MJ_WRITE: |
|
|
|
801 |
if (FD_ISSET(iorq->fd, wfds)) |
if (FD_ISSET(iorq->fd, wfds)) |
802 |
{ |
{ |
803 |
// Write data and send completion. |
/* Write data. */ |
804 |
fns = iorq->fns; |
fns = iorq->fns; |
|
status = fns->write(iorq->fd, iorq->buffer, |
|
|
iorq->length, 0, &result); |
|
|
rdpdr_send_completion(iorq->device, iorq->id, |
|
|
status, result, "", 1); |
|
805 |
|
|
806 |
xfree(iorq->buffer); |
/* never write larger chunks than 8k - chances are that it will block */ |
807 |
iorq->fd = 0; |
status = fns->write(iorq->fd, |
808 |
|
iorq->buffer + |
809 |
|
iorq->partial_len, |
810 |
|
(iorq->length - |
811 |
|
iorq->partial_len) > |
812 |
|
8192 ? 8192 : (iorq->length - |
813 |
|
iorq-> |
814 |
|
partial_len), 0, |
815 |
|
&result); |
816 |
|
iorq->partial_len += result; |
817 |
|
#if WITH_DEBUG_RDP5 |
818 |
|
DEBUG(("RDPDR: %d bytes of data written\n", |
819 |
|
result)); |
820 |
|
#endif |
821 |
|
/* only delete link if all data has been transfered */ |
822 |
|
if (iorq->partial_len == iorq->length) |
823 |
|
{ |
824 |
|
/* send a status success */ |
825 |
|
status = STATUS_SUCCESS; |
826 |
|
rdpdr_send_completion(iorq->device, |
827 |
|
iorq->id, status, |
828 |
|
iorq->length, "", 1); |
829 |
|
|
830 |
|
xfree(iorq->buffer); |
831 |
|
iorq->fd = 0; |
832 |
|
if (prev != NULL) |
833 |
|
{ |
834 |
|
prev->next = iorq->next; |
835 |
|
xfree(iorq); |
836 |
|
} |
837 |
|
else |
838 |
|
{ |
839 |
|
// Even if NULL |
840 |
|
g_iorequest = iorq->next; |
841 |
|
xfree(iorq); |
842 |
|
} |
843 |
|
} |
844 |
} |
} |
845 |
break; |
break; |
846 |
} |
} |
847 |
|
|
848 |
} |
} |
849 |
|
prev = iorq; |
850 |
|
iorq = iorq->next; |
851 |
} |
} |
852 |
|
|
853 |
} |
} |
854 |
|
|
855 |
/* Abort a pending io request for a given handle and major */ |
/* Abort a pending io request for a given handle and major */ |
857 |
rdpdr_abort_io(uint32 fd, uint32 major, NTSTATUS status) |
rdpdr_abort_io(uint32 fd, uint32 major, NTSTATUS status) |
858 |
{ |
{ |
859 |
uint32 result; |
uint32 result; |
|
int i; |
|
860 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
861 |
|
struct async_iorequest *prev; |
862 |
|
|
863 |
for (i = 0; i < MAX_ASYNC_IO_REQUESTS; i++) |
iorq = &g_iorequest; |
864 |
|
prev = NULL; |
865 |
|
while (iorq != NULL) |
866 |
{ |
{ |
|
iorq = &g_iorequest[i]; |
|
|
|
|
867 |
// 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. |
868 |
// Abort read should not abort a write io request. |
// Abort read should not abort a write io request. |
869 |
if ((iorq->fd == fd) && (major == 0 || iorq->major == major)) |
if ((iorq->fd == fd) && (major == 0 || iorq->major == major)) |
872 |
rdpdr_send_completion(iorq->device, iorq->id, status, result, "", 1); |
rdpdr_send_completion(iorq->device, iorq->id, status, result, "", 1); |
873 |
xfree(iorq->buffer); |
xfree(iorq->buffer); |
874 |
iorq->fd = 0; |
iorq->fd = 0; |
875 |
|
if (prev != NULL) |
876 |
|
{ |
877 |
|
prev->next = iorq->next; |
878 |
|
xfree(iorq); |
879 |
|
} |
880 |
|
else |
881 |
|
{ |
882 |
|
// Even if NULL |
883 |
|
g_iorequest = iorq->next; |
884 |
|
xfree(iorq); |
885 |
|
} |
886 |
return True; |
return True; |
887 |
} |
} |
888 |
|
|
889 |
|
prev = iorq; |
890 |
|
iorq = iorq->next; |
891 |
} |
} |
892 |
|
|
893 |
return False; |
return False; |
894 |
} |
} |
|
#endif |
|