VirtualBox

source: vbox/trunk/src/VBox/RDP/client/parallel.c@ 33889

Last change on this file since 33889 was 33656, checked in by vboxsync, 14 years ago

*: rebrand Sun (L)GPL disclaimers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1/* -*- c-basic-offset: 8 -*-
2 rdesktop: A Remote Desktop Protocol client.
3 Copyright (C) Matthew Chapman 1999-2007
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
20/*
21 * Oracle GPL Disclaimer: For the avoidance of doubt, except that if any license choice
22 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
23 * the General Public License version 2 (GPLv2) at this time for any software where
24 * a choice of GPL license versions is made available with the language indicating
25 * that GPLv2 or any later version may be used, or where a choice of which version
26 * of the GPL is applied is otherwise unspecified.
27 */
28
29#define MAX_PARALLEL_DEVICES 1
30
31#define FILE_DEVICE_PARALLEL 0x22
32
33#define IOCTL_PAR_QUERY_RAW_DEVICE_ID 0x0c
34
35#include "rdesktop.h"
36#include <unistd.h>
37#include <fcntl.h>
38#include <sys/ioctl.h>
39#include <errno.h>
40
41#if defined(__linux__)
42#include <linux/lp.h>
43#endif
44
45extern RDPDR_DEVICE g_rdpdr_device[];
46
47
48/* Enumeration of devices from rdesktop.c */
49/* returns numer of units found and initialized. */
50/* optarg looks like ':LPT1=/dev/lp0' */
51/* when it arrives to this function. */
52int
53parallel_enum_devices(uint32 * id, char *optarg)
54{
55 PARALLEL_DEVICE *ppar_info;
56
57 char *pos = optarg;
58 char *pos2;
59 int count = 0;
60
61 /* skip the first colon */
62 optarg++;
63 while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES)
64 {
65 ppar_info = (PARALLEL_DEVICE *) xmalloc(sizeof(PARALLEL_DEVICE));
66
67 pos2 = next_arg(optarg, '=');
68 strcpy(g_rdpdr_device[*id].name, optarg);
69
70 toupper_str(g_rdpdr_device[*id].name);
71
72 g_rdpdr_device[*id].local_path = xmalloc(strlen(pos2) + 1);
73 strcpy(g_rdpdr_device[*id].local_path, pos2);
74 printf("PARALLEL %s to %s\n", optarg, pos2);
75
76 /* set device type */
77 g_rdpdr_device[*id].device_type = DEVICE_TYPE_PARALLEL;
78 g_rdpdr_device[*id].pdevice_data = (void *) ppar_info;
79 g_rdpdr_device[*id].handle = 0;
80 count++;
81 (*id)++;
82
83 optarg = pos;
84 }
85 return count;
86}
87
88static RD_NTSTATUS
89parallel_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition,
90 uint32 flags, char *filename, RD_NTHANDLE * handle)
91{
92 int parallel_fd;
93
94 parallel_fd = open(g_rdpdr_device[device_id].local_path, O_RDWR);
95 if (parallel_fd == -1)
96 {
97 perror("open");
98 return RD_STATUS_ACCESS_DENIED;
99 }
100
101 /* all read and writes should be non blocking */
102 if (fcntl(parallel_fd, F_SETFL, O_NONBLOCK) == -1)
103 perror("fcntl");
104
105#if defined(LPABORT)
106 /* Retry on errors */
107 ioctl(parallel_fd, LPABORT, (int) 1);
108#endif
109
110 g_rdpdr_device[device_id].handle = parallel_fd;
111
112 *handle = parallel_fd;
113
114 return RD_STATUS_SUCCESS;
115}
116
117static RD_NTSTATUS
118parallel_close(RD_NTHANDLE handle)
119{
120 int i = get_device_index(handle);
121 if (i >= 0)
122 g_rdpdr_device[i].handle = 0;
123 close(handle);
124 return RD_STATUS_SUCCESS;
125}
126
127static RD_NTSTATUS
128parallel_read(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
129{
130 *result = read(handle, data, length);
131 return RD_STATUS_SUCCESS;
132}
133
134static RD_NTSTATUS
135parallel_write(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result)
136{
137 int rc = RD_STATUS_SUCCESS;
138
139 int n = write(handle, data, length);
140 if (n < 0)
141 {
142#if defined(LPGETSTATUS)
143 int status;
144#endif
145
146 *result = 0;
147 switch (errno)
148 {
149 case EAGAIN:
150 rc = RD_STATUS_DEVICE_OFF_LINE;
151 case ENOSPC:
152 rc = RD_STATUS_DEVICE_PAPER_EMPTY;
153 case EIO:
154 rc = RD_STATUS_DEVICE_OFF_LINE;
155 default:
156 rc = RD_STATUS_DEVICE_POWERED_OFF;
157 }
158#if defined(LPGETSTATUS)
159 if (ioctl(handle, LPGETSTATUS, &status) == 0)
160 {
161 /* coming soon: take care for the printer status */
162 printf("parallel_write: status = %d, errno = %d\n", status, errno);
163 }
164#endif
165 }
166 *result = n;
167 return rc;
168}
169
170static RD_NTSTATUS
171parallel_device_control(RD_NTHANDLE handle, uint32 request, STREAM in, STREAM out)
172{
173 if ((request >> 16) != FILE_DEVICE_PARALLEL)
174 return RD_STATUS_INVALID_PARAMETER;
175
176 /* extract operation */
177 request >>= 2;
178 request &= 0xfff;
179
180 printf("PARALLEL IOCTL %d: ", request);
181
182 switch (request)
183 {
184 case IOCTL_PAR_QUERY_RAW_DEVICE_ID:
185
186 default:
187
188 printf("\n");
189 unimpl("UNKNOWN IOCTL %d\n", request);
190 }
191 return RD_STATUS_SUCCESS;
192}
193
194DEVICE_FNS parallel_fns = {
195 parallel_create,
196 parallel_close,
197 parallel_read,
198 parallel_write,
199 parallel_device_control
200};
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette