4 |
|
|
5 |
#define IOCTL_PAR_QUERY_RAW_DEVICE_ID 0x0c |
#define IOCTL_PAR_QUERY_RAW_DEVICE_ID 0x0c |
6 |
|
|
|
#define PARALLELDEV0 "/dev/lp0" |
|
|
|
|
7 |
#include "rdesktop.h" |
#include "rdesktop.h" |
8 |
#include <unistd.h> |
#include <unistd.h> |
9 |
#include <fcntl.h> |
#include <fcntl.h> |
10 |
|
#include <sys/ioctl.h> |
11 |
|
#include <linux/lp.h> |
12 |
|
#include <errno.h> |
13 |
|
|
14 |
|
extern int errno; |
15 |
|
|
16 |
extern RDPDR_DEVICE g_rdpdr_device[]; |
extern RDPDR_DEVICE g_rdpdr_device[]; |
17 |
|
|
34 |
/* optarg looks like ':LPT1=/dev/lp0' */ |
/* optarg looks like ':LPT1=/dev/lp0' */ |
35 |
/* when it arrives to this function. */ |
/* when it arrives to this function. */ |
36 |
int |
int |
37 |
parallel_enum_devices(int *id, char *optarg) |
parallel_enum_devices(uint32 * id, char *optarg) |
38 |
{ |
{ |
|
//TODO: Read from configuration file? CUPS? |
|
39 |
PARALLEL_DEVICE *ppar_info; |
PARALLEL_DEVICE *ppar_info; |
40 |
|
|
41 |
char *pos = optarg; |
char *pos = optarg; |
60 |
// set device type |
// set device type |
61 |
g_rdpdr_device[*id].device_type = DEVICE_TYPE_PARALLEL; |
g_rdpdr_device[*id].device_type = DEVICE_TYPE_PARALLEL; |
62 |
g_rdpdr_device[*id].pdevice_data = (void *) ppar_info; |
g_rdpdr_device[*id].pdevice_data = (void *) ppar_info; |
63 |
|
g_rdpdr_device[*id].handle = 0; |
64 |
count++; |
count++; |
65 |
(*id)++; |
(*id)++; |
66 |
|
|
70 |
} |
} |
71 |
|
|
72 |
static NTSTATUS |
static NTSTATUS |
73 |
parallel_create(uint32 device_id, HANDLE * handle) |
parallel_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, |
74 |
|
uint32 flags, char *filename, HANDLE * handle) |
75 |
{ |
{ |
76 |
int parallel_fd; |
int parallel_fd; |
77 |
|
|
78 |
parallel_fd = open(PARALLELDEV0, O_WRONLY); |
parallel_fd = open(g_rdpdr_device[device_id].local_path, O_RDWR); |
79 |
if (parallel_fd == -1) |
if (parallel_fd == -1) |
80 |
|
{ |
81 |
|
perror("open"); |
82 |
return STATUS_ACCESS_DENIED; |
return STATUS_ACCESS_DENIED; |
83 |
|
} |
84 |
|
|
85 |
|
/* all read and writes should be non blocking */ |
86 |
|
if (fcntl(parallel_fd, F_SETFL, O_NONBLOCK) == -1) |
87 |
|
perror("fcntl"); |
88 |
|
|
89 |
|
ioctl(parallel_fd, LPABORT, (int) 1); |
90 |
|
|
91 |
|
g_rdpdr_device[device_id].handle = parallel_fd; |
92 |
|
|
93 |
*handle = parallel_fd; |
*handle = parallel_fd; |
94 |
|
|
95 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
96 |
} |
} |
97 |
|
|
98 |
static NTSTATUS |
static NTSTATUS |
99 |
parallel_close(HANDLE handle) |
parallel_close(HANDLE handle) |
100 |
{ |
{ |
101 |
|
int i = get_device_index(handle); |
102 |
|
if (i >= 0) |
103 |
|
g_rdpdr_device[i].handle = 0; |
104 |
close(handle); |
close(handle); |
105 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
106 |
} |
} |
107 |
|
|
108 |
|
NTSTATUS |
109 |
|
parallel_read(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
110 |
|
{ |
111 |
|
*result = read(handle, data, length); |
112 |
|
return STATUS_SUCCESS; |
113 |
|
} |
114 |
|
|
115 |
static NTSTATUS |
static NTSTATUS |
116 |
parallel_write(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
parallel_write(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
117 |
{ |
{ |
118 |
*result = write(handle, data, length); |
int rc = STATUS_SUCCESS; |
119 |
return STATUS_SUCCESS; |
|
120 |
|
int n = write(handle, data, length); |
121 |
|
if (n < 0) |
122 |
|
{ |
123 |
|
int status; |
124 |
|
|
125 |
|
*result = 0; |
126 |
|
switch (errno) |
127 |
|
{ |
128 |
|
case EAGAIN: |
129 |
|
rc = STATUS_DEVICE_OFF_LINE; |
130 |
|
case ENOSPC: |
131 |
|
rc = STATUS_DEVICE_PAPER_EMPTY; |
132 |
|
case EIO: |
133 |
|
rc = STATUS_DEVICE_OFF_LINE; |
134 |
|
default: |
135 |
|
rc = STATUS_DEVICE_POWERED_OFF; |
136 |
|
} |
137 |
|
if (ioctl(handle, LPGETSTATUS, &status) == 0) |
138 |
|
{ |
139 |
|
/* coming soon: take care for the printer status */ |
140 |
|
printf("parallel_write: status = %d, errno = %d\n", status, errno); |
141 |
|
} |
142 |
|
} |
143 |
|
*result = n; |
144 |
|
return rc; |
145 |
} |
} |
146 |
|
|
147 |
static NTSTATUS |
static NTSTATUS |
171 |
DEVICE_FNS parallel_fns = { |
DEVICE_FNS parallel_fns = { |
172 |
parallel_create, |
parallel_create, |
173 |
parallel_close, |
parallel_close, |
174 |
NULL, |
parallel_read, |
175 |
parallel_write, |
parallel_write, |
176 |
parallel_device_control |
parallel_device_control |
177 |
}; |
}; |