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