1 |
|
/* -*- c-basic-offset: 8 -*- |
2 |
|
rdesktop: A Remote Desktop Protocol client. |
3 |
|
Copyright (C) Matthew Chapman 1999-2005 |
4 |
|
|
5 |
|
This program is free software; you can redistribute it and/or modify |
6 |
|
it under the terms of the GNU General Public License as published by |
7 |
|
the Free Software Foundation; either version 2 of the License, or |
8 |
|
(at your option) any later version. |
9 |
|
|
10 |
|
This program is distributed in the hope that it will be useful, |
11 |
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
|
GNU General Public License for more details. |
14 |
|
|
15 |
|
You should have received a copy of the GNU General Public License |
16 |
|
along with this program; if not, write to the Free Software |
17 |
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
18 |
|
*/ |
19 |
#define MAX_PARALLEL_DEVICES 1 |
#define MAX_PARALLEL_DEVICES 1 |
20 |
|
|
21 |
#define FILE_DEVICE_PARALLEL 0x22 |
#define FILE_DEVICE_PARALLEL 0x22 |
25 |
#include "rdesktop.h" |
#include "rdesktop.h" |
26 |
#include <unistd.h> |
#include <unistd.h> |
27 |
#include <fcntl.h> |
#include <fcntl.h> |
28 |
|
#include <sys/ioctl.h> |
29 |
|
#include <errno.h> |
30 |
|
|
31 |
extern RDPDR_DEVICE g_rdpdr_device[]; |
#if defined(__linux__) |
32 |
|
#include <linux/lp.h> |
33 |
PARALLEL_DEVICE * |
#endif |
|
get_parallel_data(HANDLE handle) |
|
|
{ |
|
|
int index; |
|
34 |
|
|
35 |
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; |
|
|
} |
|
36 |
|
|
37 |
|
|
38 |
/* Enumeration of devices from rdesktop.c */ |
/* Enumeration of devices from rdesktop.c */ |
48 |
char *pos2; |
char *pos2; |
49 |
int count = 0; |
int count = 0; |
50 |
|
|
51 |
// skip the first colon |
/* skip the first colon */ |
52 |
optarg++; |
optarg++; |
53 |
while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES) |
while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES) |
54 |
{ |
{ |
63 |
strcpy(g_rdpdr_device[*id].local_path, pos2); |
strcpy(g_rdpdr_device[*id].local_path, pos2); |
64 |
printf("PARALLEL %s to %s\n", optarg, pos2); |
printf("PARALLEL %s to %s\n", optarg, pos2); |
65 |
|
|
66 |
// set device type |
/* set device type */ |
67 |
g_rdpdr_device[*id].device_type = DEVICE_TYPE_PARALLEL; |
g_rdpdr_device[*id].device_type = DEVICE_TYPE_PARALLEL; |
68 |
g_rdpdr_device[*id].pdevice_data = (void *) ppar_info; |
g_rdpdr_device[*id].pdevice_data = (void *) ppar_info; |
69 |
|
g_rdpdr_device[*id].handle = 0; |
70 |
count++; |
count++; |
71 |
(*id)++; |
(*id)++; |
72 |
|
|
77 |
|
|
78 |
static NTSTATUS |
static NTSTATUS |
79 |
parallel_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, |
parallel_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, |
80 |
uint32 flags, char *filename, HANDLE * handle) |
uint32 flags, char *filename, NTHANDLE * handle) |
81 |
{ |
{ |
82 |
int parallel_fd; |
int parallel_fd; |
83 |
|
|
88 |
return STATUS_ACCESS_DENIED; |
return STATUS_ACCESS_DENIED; |
89 |
} |
} |
90 |
|
|
91 |
|
/* all read and writes should be non blocking */ |
92 |
|
if (fcntl(parallel_fd, F_SETFL, O_NONBLOCK) == -1) |
93 |
|
perror("fcntl"); |
94 |
|
|
95 |
|
#if defined(LPABORT) |
96 |
|
/* Retry on errors */ |
97 |
|
ioctl(parallel_fd, LPABORT, (int) 1); |
98 |
|
#endif |
99 |
|
|
100 |
g_rdpdr_device[device_id].handle = parallel_fd; |
g_rdpdr_device[device_id].handle = parallel_fd; |
101 |
|
|
102 |
*handle = parallel_fd; |
*handle = parallel_fd; |
103 |
|
|
|
/* all read and writes should be non blocking */ |
|
|
if (fcntl(*handle, F_SETFL, O_NONBLOCK) == -1) |
|
|
perror("fcntl"); |
|
|
|
|
104 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
105 |
} |
} |
106 |
|
|
107 |
static NTSTATUS |
static NTSTATUS |
108 |
parallel_close(HANDLE handle) |
parallel_close(NTHANDLE handle) |
109 |
{ |
{ |
110 |
g_rdpdr_device[get_device_index(handle)].handle = 0; |
int i = get_device_index(handle); |
111 |
|
if (i >= 0) |
112 |
|
g_rdpdr_device[i].handle = 0; |
113 |
close(handle); |
close(handle); |
114 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
115 |
} |
} |
116 |
|
|
117 |
NTSTATUS |
static NTSTATUS |
118 |
parallel_read(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
parallel_read(NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
119 |
{ |
{ |
120 |
*result = read(handle, data, length); |
*result = read(handle, data, length); |
121 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
122 |
} |
} |
123 |
|
|
124 |
static NTSTATUS |
static NTSTATUS |
125 |
parallel_write(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
parallel_write(NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
126 |
{ |
{ |
127 |
*result = write(handle, data, length); |
int rc = STATUS_SUCCESS; |
128 |
return STATUS_SUCCESS; |
|
129 |
|
int n = write(handle, data, length); |
130 |
|
if (n < 0) |
131 |
|
{ |
132 |
|
#if defined(LPGETSTATUS) |
133 |
|
int status; |
134 |
|
#endif |
135 |
|
|
136 |
|
*result = 0; |
137 |
|
switch (errno) |
138 |
|
{ |
139 |
|
case EAGAIN: |
140 |
|
rc = STATUS_DEVICE_OFF_LINE; |
141 |
|
case ENOSPC: |
142 |
|
rc = STATUS_DEVICE_PAPER_EMPTY; |
143 |
|
case EIO: |
144 |
|
rc = STATUS_DEVICE_OFF_LINE; |
145 |
|
default: |
146 |
|
rc = STATUS_DEVICE_POWERED_OFF; |
147 |
|
} |
148 |
|
#if defined(LPGETSTATUS) |
149 |
|
if (ioctl(handle, LPGETSTATUS, &status) == 0) |
150 |
|
{ |
151 |
|
/* coming soon: take care for the printer status */ |
152 |
|
printf("parallel_write: status = %d, errno = %d\n", status, errno); |
153 |
|
} |
154 |
|
#endif |
155 |
|
} |
156 |
|
*result = n; |
157 |
|
return rc; |
158 |
} |
} |
159 |
|
|
160 |
static NTSTATUS |
static NTSTATUS |
161 |
parallel_device_control(HANDLE handle, uint32 request, STREAM in, STREAM out) |
parallel_device_control(NTHANDLE handle, uint32 request, STREAM in, STREAM out) |
162 |
{ |
{ |
163 |
if ((request >> 16) != FILE_DEVICE_PARALLEL) |
if ((request >> 16) != FILE_DEVICE_PARALLEL) |
164 |
return STATUS_INVALID_PARAMETER; |
return STATUS_INVALID_PARAMETER; |