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 |
|
|
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 |
|
|
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; |
g_rdpdr_device[device_id].handle = parallel_fd; |
92 |
|
|
93 |
*handle = parallel_fd; |
*handle = parallel_fd; |
94 |
|
|
|
/* all read and writes should be non blocking */ |
|
|
if (fcntl(*handle, F_SETFL, O_NONBLOCK) == -1) |
|
|
perror("fcntl"); |
|
|
|
|
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 |
g_rdpdr_device[get_device_index(handle)].handle = 0; |
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 |
} |
} |
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 |