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 |
extern RDPDR_DEVICE g_rdpdr_device[]; |
#if defined(__linux__) |
14 |
|
#include <linux/lp.h> |
15 |
|
#endif |
16 |
|
|
17 |
PARALLEL_DEVICE * |
extern int errno; |
|
get_parallel_data(HANDLE handle) |
|
|
{ |
|
|
int index; |
|
18 |
|
|
19 |
for (index = 0; index < RDPDR_MAX_DEVICES; index++) |
extern RDPDR_DEVICE g_rdpdr_device[]; |
|
{ |
|
|
if (handle == g_rdpdr_device[index].handle) |
|
|
return (PARALLEL_DEVICE *) g_rdpdr_device[index].pdevice_data; |
|
|
} |
|
|
return NULL; |
|
|
} |
|
20 |
|
|
21 |
|
|
22 |
/* Enumeration of devices from rdesktop.c */ |
/* Enumeration of devices from rdesktop.c */ |
24 |
/* optarg looks like ':LPT1=/dev/lp0' */ |
/* optarg looks like ':LPT1=/dev/lp0' */ |
25 |
/* when it arrives to this function. */ |
/* when it arrives to this function. */ |
26 |
int |
int |
27 |
parallel_enum_devices(int *id, char *optarg) |
parallel_enum_devices(uint32 * id, char *optarg) |
28 |
{ |
{ |
29 |
PARALLEL_DEVICE *ppar_info; |
PARALLEL_DEVICE *ppar_info; |
30 |
|
|
50 |
// set device type |
// set device type |
51 |
g_rdpdr_device[*id].device_type = DEVICE_TYPE_PARALLEL; |
g_rdpdr_device[*id].device_type = DEVICE_TYPE_PARALLEL; |
52 |
g_rdpdr_device[*id].pdevice_data = (void *) ppar_info; |
g_rdpdr_device[*id].pdevice_data = (void *) ppar_info; |
53 |
|
g_rdpdr_device[*id].handle = 0; |
54 |
count++; |
count++; |
55 |
(*id)++; |
(*id)++; |
56 |
|
|
61 |
|
|
62 |
static NTSTATUS |
static NTSTATUS |
63 |
parallel_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, |
parallel_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, |
64 |
uint32 flags, char *filename, HANDLE * handle) |
uint32 flags, char *filename, NTHANDLE * handle) |
65 |
{ |
{ |
66 |
int parallel_fd; |
int parallel_fd; |
67 |
|
|
72 |
return STATUS_ACCESS_DENIED; |
return STATUS_ACCESS_DENIED; |
73 |
} |
} |
74 |
|
|
75 |
|
/* all read and writes should be non blocking */ |
76 |
|
if (fcntl(parallel_fd, F_SETFL, O_NONBLOCK) == -1) |
77 |
|
perror("fcntl"); |
78 |
|
|
79 |
|
#if defined(LPABORT) |
80 |
|
/* Retry on errors */ |
81 |
|
ioctl(parallel_fd, LPABORT, (int) 1); |
82 |
|
#endif |
83 |
|
|
84 |
g_rdpdr_device[device_id].handle = parallel_fd; |
g_rdpdr_device[device_id].handle = parallel_fd; |
85 |
|
|
86 |
*handle = parallel_fd; |
*handle = parallel_fd; |
87 |
|
|
|
/* all read and writes should be non blocking */ |
|
|
if (fcntl(*handle, F_SETFL, O_NONBLOCK) == -1) |
|
|
perror("fcntl"); |
|
|
|
|
88 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
89 |
} |
} |
90 |
|
|
91 |
static NTSTATUS |
static NTSTATUS |
92 |
parallel_close(HANDLE handle) |
parallel_close(NTHANDLE handle) |
93 |
{ |
{ |
94 |
g_rdpdr_device[get_device_index(handle)].handle = 0; |
int i = get_device_index(handle); |
95 |
|
if (i >= 0) |
96 |
|
g_rdpdr_device[i].handle = 0; |
97 |
close(handle); |
close(handle); |
98 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
99 |
} |
} |
100 |
|
|
101 |
NTSTATUS |
static NTSTATUS |
102 |
parallel_read(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
parallel_read(NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
103 |
{ |
{ |
104 |
*result = read(handle, data, length); |
*result = read(handle, data, length); |
105 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
106 |
} |
} |
107 |
|
|
108 |
static NTSTATUS |
static NTSTATUS |
109 |
parallel_write(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
parallel_write(NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
110 |
{ |
{ |
111 |
*result = write(handle, data, length); |
int rc = STATUS_SUCCESS; |
112 |
return STATUS_SUCCESS; |
|
113 |
|
int n = write(handle, data, length); |
114 |
|
if (n < 0) |
115 |
|
{ |
116 |
|
#if defined(LPGETSTATUS) |
117 |
|
int status; |
118 |
|
#endif |
119 |
|
|
120 |
|
*result = 0; |
121 |
|
switch (errno) |
122 |
|
{ |
123 |
|
case EAGAIN: |
124 |
|
rc = STATUS_DEVICE_OFF_LINE; |
125 |
|
case ENOSPC: |
126 |
|
rc = STATUS_DEVICE_PAPER_EMPTY; |
127 |
|
case EIO: |
128 |
|
rc = STATUS_DEVICE_OFF_LINE; |
129 |
|
default: |
130 |
|
rc = STATUS_DEVICE_POWERED_OFF; |
131 |
|
} |
132 |
|
#if defined(LPGETSTATUS) |
133 |
|
if (ioctl(handle, LPGETSTATUS, &status) == 0) |
134 |
|
{ |
135 |
|
/* coming soon: take care for the printer status */ |
136 |
|
printf("parallel_write: status = %d, errno = %d\n", status, errno); |
137 |
|
} |
138 |
|
#endif |
139 |
|
} |
140 |
|
*result = n; |
141 |
|
return rc; |
142 |
} |
} |
143 |
|
|
144 |
static NTSTATUS |
static NTSTATUS |
145 |
parallel_device_control(HANDLE handle, uint32 request, STREAM in, STREAM out) |
parallel_device_control(NTHANDLE handle, uint32 request, STREAM in, STREAM out) |
146 |
{ |
{ |
147 |
if ((request >> 16) != FILE_DEVICE_PARALLEL) |
if ((request >> 16) != FILE_DEVICE_PARALLEL) |
148 |
return STATUS_INVALID_PARAMETER; |
return STATUS_INVALID_PARAMETER; |