1 |
#define MAX_PARALLEL_DEVICES 1 |
2 |
|
3 |
#define FILE_DEVICE_PARALLEL 0x22 |
4 |
|
5 |
#define IOCTL_PAR_QUERY_RAW_DEVICE_ID 0x0c |
6 |
|
7 |
#include "rdesktop.h" |
8 |
#include <unistd.h> |
9 |
#include <fcntl.h> |
10 |
|
11 |
extern RDPDR_DEVICE g_rdpdr_device[]; |
12 |
|
13 |
PARALLEL_DEVICE * |
14 |
get_parallel_data(HANDLE handle) |
15 |
{ |
16 |
int index; |
17 |
|
18 |
for (index = 0; index < RDPDR_MAX_DEVICES; index++) |
19 |
{ |
20 |
if (handle == g_rdpdr_device[index].handle) |
21 |
return (PARALLEL_DEVICE *) g_rdpdr_device[index].pdevice_data; |
22 |
} |
23 |
return NULL; |
24 |
} |
25 |
|
26 |
|
27 |
/* Enumeration of devices from rdesktop.c */ |
28 |
/* returns numer of units found and initialized. */ |
29 |
/* optarg looks like ':LPT1=/dev/lp0' */ |
30 |
/* when it arrives to this function. */ |
31 |
int |
32 |
parallel_enum_devices(int *id, char *optarg) |
33 |
{ |
34 |
PARALLEL_DEVICE *ppar_info; |
35 |
|
36 |
char *pos = optarg; |
37 |
char *pos2; |
38 |
int count = 0; |
39 |
|
40 |
// skip the first colon |
41 |
optarg++; |
42 |
while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES) |
43 |
{ |
44 |
ppar_info = (PARALLEL_DEVICE *) xmalloc(sizeof(PARALLEL_DEVICE)); |
45 |
|
46 |
pos2 = next_arg(optarg, '='); |
47 |
strcpy(g_rdpdr_device[*id].name, optarg); |
48 |
|
49 |
toupper_str(g_rdpdr_device[*id].name); |
50 |
|
51 |
g_rdpdr_device[*id].local_path = xmalloc(strlen(pos2) + 1); |
52 |
strcpy(g_rdpdr_device[*id].local_path, pos2); |
53 |
printf("PARALLEL %s to %s\n", optarg, pos2); |
54 |
|
55 |
// set device type |
56 |
g_rdpdr_device[*id].device_type = DEVICE_TYPE_PARALLEL; |
57 |
g_rdpdr_device[*id].pdevice_data = (void *) ppar_info; |
58 |
count++; |
59 |
(*id)++; |
60 |
|
61 |
optarg = pos; |
62 |
} |
63 |
return count; |
64 |
} |
65 |
|
66 |
static NTSTATUS |
67 |
parallel_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, uint32 flags, |
68 |
char *filename, HANDLE * handle) |
69 |
{ |
70 |
int parallel_fd; |
71 |
|
72 |
parallel_fd = open(g_rdpdr_device[device_id].local_path, O_RDWR); |
73 |
if (parallel_fd == -1) { |
74 |
perror("open"); |
75 |
return STATUS_ACCESS_DENIED; |
76 |
} |
77 |
|
78 |
g_rdpdr_device[device_id].handle = parallel_fd; |
79 |
|
80 |
*handle = parallel_fd; |
81 |
return STATUS_SUCCESS; |
82 |
} |
83 |
|
84 |
static NTSTATUS |
85 |
parallel_close(HANDLE handle) |
86 |
{ |
87 |
g_rdpdr_device[get_device_index(handle)].handle = 0; |
88 |
close(handle); |
89 |
return STATUS_SUCCESS; |
90 |
} |
91 |
|
92 |
NTSTATUS |
93 |
parallel_read(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
94 |
{ |
95 |
*result = read(handle, data, length); |
96 |
return STATUS_SUCCESS; |
97 |
} |
98 |
|
99 |
static NTSTATUS |
100 |
parallel_write(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
101 |
{ |
102 |
*result = write(handle, data, length); |
103 |
return STATUS_SUCCESS; |
104 |
} |
105 |
|
106 |
static NTSTATUS |
107 |
parallel_device_control(HANDLE handle, uint32 request, STREAM in, STREAM out) |
108 |
{ |
109 |
if ((request >> 16) != FILE_DEVICE_PARALLEL) |
110 |
return STATUS_INVALID_PARAMETER; |
111 |
|
112 |
/* extract operation */ |
113 |
request >>= 2; |
114 |
request &= 0xfff; |
115 |
|
116 |
printf("PARALLEL IOCTL %d: ", request); |
117 |
|
118 |
switch (request) |
119 |
{ |
120 |
case IOCTL_PAR_QUERY_RAW_DEVICE_ID: |
121 |
|
122 |
default: |
123 |
|
124 |
printf("\n"); |
125 |
unimpl("UNKNOWN IOCTL %d\n", request); |
126 |
} |
127 |
return STATUS_SUCCESS; |
128 |
} |
129 |
|
130 |
DEVICE_FNS parallel_fns = { |
131 |
parallel_create, |
132 |
parallel_close, |
133 |
parallel_read, |
134 |
parallel_write, |
135 |
parallel_device_control |
136 |
}; |