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 <errno.h> |
12 |
|
|
13 |
|
#if defined(__linux__) |
14 |
|
#include <linux/lp.h> |
15 |
|
#endif |
16 |
|
|
17 |
|
extern int errno; |
18 |
|
|
19 |
extern RDPDR_DEVICE g_rdpdr_device[]; |
extern RDPDR_DEVICE g_rdpdr_device[]; |
20 |
|
|
21 |
PARALLEL_DEVICE * |
static PARALLEL_DEVICE * |
22 |
get_parallel_data(HANDLE handle) |
get_parallel_data(HANDLE handle) |
23 |
{ |
{ |
24 |
int index; |
int index; |
63 |
// set device type |
// set device type |
64 |
g_rdpdr_device[*id].device_type = DEVICE_TYPE_PARALLEL; |
g_rdpdr_device[*id].device_type = DEVICE_TYPE_PARALLEL; |
65 |
g_rdpdr_device[*id].pdevice_data = (void *) ppar_info; |
g_rdpdr_device[*id].pdevice_data = (void *) ppar_info; |
66 |
|
g_rdpdr_device[*id].handle = 0; |
67 |
count++; |
count++; |
68 |
(*id)++; |
(*id)++; |
69 |
|
|
85 |
return STATUS_ACCESS_DENIED; |
return STATUS_ACCESS_DENIED; |
86 |
} |
} |
87 |
|
|
88 |
|
/* all read and writes should be non blocking */ |
89 |
|
if (fcntl(parallel_fd, F_SETFL, O_NONBLOCK) == -1) |
90 |
|
perror("fcntl"); |
91 |
|
|
92 |
|
#if defined(LPABORT) |
93 |
|
/* Retry on errors */ |
94 |
|
ioctl(parallel_fd, LPABORT, (int) 1); |
95 |
|
#endif |
96 |
|
|
97 |
g_rdpdr_device[device_id].handle = parallel_fd; |
g_rdpdr_device[device_id].handle = parallel_fd; |
98 |
|
|
99 |
*handle = parallel_fd; |
*handle = parallel_fd; |
100 |
|
|
|
/* all read and writes should be non blocking */ |
|
|
if (fcntl(*handle, F_SETFL, O_NONBLOCK) == -1) |
|
|
perror("fcntl"); |
|
|
|
|
101 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
102 |
} |
} |
103 |
|
|
104 |
static NTSTATUS |
static NTSTATUS |
105 |
parallel_close(HANDLE handle) |
parallel_close(HANDLE handle) |
106 |
{ |
{ |
107 |
g_rdpdr_device[get_device_index(handle)].handle = 0; |
int i = get_device_index(handle); |
108 |
|
if (i >= 0) |
109 |
|
g_rdpdr_device[i].handle = 0; |
110 |
close(handle); |
close(handle); |
111 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
112 |
} |
} |
113 |
|
|
114 |
NTSTATUS |
static NTSTATUS |
115 |
parallel_read(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
parallel_read(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
116 |
{ |
{ |
117 |
*result = read(handle, data, length); |
*result = read(handle, data, length); |
121 |
static NTSTATUS |
static NTSTATUS |
122 |
parallel_write(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
parallel_write(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
123 |
{ |
{ |
124 |
*result = write(handle, data, length); |
int rc = STATUS_SUCCESS; |
125 |
return STATUS_SUCCESS; |
|
126 |
|
int n = write(handle, data, length); |
127 |
|
if (n < 0) |
128 |
|
{ |
129 |
|
int status; |
130 |
|
|
131 |
|
*result = 0; |
132 |
|
switch (errno) |
133 |
|
{ |
134 |
|
case EAGAIN: |
135 |
|
rc = STATUS_DEVICE_OFF_LINE; |
136 |
|
case ENOSPC: |
137 |
|
rc = STATUS_DEVICE_PAPER_EMPTY; |
138 |
|
case EIO: |
139 |
|
rc = STATUS_DEVICE_OFF_LINE; |
140 |
|
default: |
141 |
|
rc = STATUS_DEVICE_POWERED_OFF; |
142 |
|
} |
143 |
|
#if defined(LPGETSTATUS) |
144 |
|
if (ioctl(handle, LPGETSTATUS, &status) == 0) |
145 |
|
{ |
146 |
|
/* coming soon: take care for the printer status */ |
147 |
|
printf("parallel_write: status = %d, errno = %d\n", status, errno); |
148 |
|
} |
149 |
|
#endif |
150 |
|
} |
151 |
|
*result = n; |
152 |
|
return rc; |
153 |
} |
} |
154 |
|
|
155 |
static NTSTATUS |
static NTSTATUS |