4 |
|
|
5 |
#define IOCTL_PAR_QUERY_RAW_DEVICE_ID 0x0c |
#define IOCTL_PAR_QUERY_RAW_DEVICE_ID 0x0c |
6 |
|
|
|
#define PARALLELDEV0 "/dev/lp0" |
|
|
|
|
7 |
#include "rdesktop.h" |
#include "rdesktop.h" |
8 |
#include <unistd.h> |
#include <unistd.h> |
9 |
#include <fcntl.h> |
#include <fcntl.h> |
10 |
|
|
11 |
extern RDPDR_DEVICE g_rdpdr_device[]; |
extern RDPDR_DEVICE g_rdpdr_device[]; |
12 |
|
|
13 |
PARALLEL_DEVICE * get_parallel_data(HANDLE handle) |
PARALLEL_DEVICE * |
14 |
|
get_parallel_data(HANDLE handle) |
15 |
{ |
{ |
16 |
int index; |
int index; |
17 |
|
|
29 |
/* optarg looks like ':LPT1=/dev/lp0' */ |
/* optarg looks like ':LPT1=/dev/lp0' */ |
30 |
/* when it arrives to this function. */ |
/* when it arrives to this function. */ |
31 |
int |
int |
32 |
parallel_enum_devices(int *id, char *optarg) |
parallel_enum_devices(uint32 * id, char *optarg) |
33 |
{ |
{ |
|
//TODO: Read from configuration file? CUPS? |
|
34 |
PARALLEL_DEVICE *ppar_info; |
PARALLEL_DEVICE *ppar_info; |
35 |
|
|
36 |
char *pos = optarg; |
char *pos = optarg; |
46 |
pos2 = next_arg(optarg, '='); |
pos2 = next_arg(optarg, '='); |
47 |
strcpy(g_rdpdr_device[*id].name, optarg); |
strcpy(g_rdpdr_device[*id].name, optarg); |
48 |
|
|
49 |
toupper(g_rdpdr_device[*id].name); |
toupper_str(g_rdpdr_device[*id].name); |
50 |
|
|
51 |
g_rdpdr_device[*id].local_path = xmalloc(strlen(pos2) + 1); |
g_rdpdr_device[*id].local_path = xmalloc(strlen(pos2) + 1); |
52 |
strcpy(g_rdpdr_device[*id].local_path, pos2); |
strcpy(g_rdpdr_device[*id].local_path, pos2); |
64 |
} |
} |
65 |
|
|
66 |
static NTSTATUS |
static NTSTATUS |
67 |
parallel_create(uint32 device_id, HANDLE * handle) |
parallel_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, |
68 |
|
uint32 flags, char *filename, HANDLE * handle) |
69 |
{ |
{ |
70 |
int parallel_fd; |
int parallel_fd; |
71 |
|
|
72 |
parallel_fd = open(PARALLELDEV0, O_WRONLY); |
parallel_fd = open(g_rdpdr_device[device_id].local_path, O_RDWR); |
73 |
if (parallel_fd == -1) |
if (parallel_fd == -1) |
74 |
|
{ |
75 |
|
perror("open"); |
76 |
return STATUS_ACCESS_DENIED; |
return STATUS_ACCESS_DENIED; |
77 |
|
} |
78 |
|
|
79 |
|
g_rdpdr_device[device_id].handle = parallel_fd; |
80 |
|
|
81 |
*handle = parallel_fd; |
*handle = parallel_fd; |
82 |
|
|
83 |
|
/* all read and writes should be non blocking */ |
84 |
|
if (fcntl(*handle, F_SETFL, O_NONBLOCK) == -1) |
85 |
|
perror("fcntl"); |
86 |
|
|
87 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
88 |
} |
} |
89 |
|
|
90 |
static NTSTATUS |
static NTSTATUS |
91 |
parallel_close(HANDLE handle) |
parallel_close(HANDLE handle) |
92 |
{ |
{ |
93 |
|
g_rdpdr_device[get_device_index(handle)].handle = 0; |
94 |
close(handle); |
close(handle); |
95 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
96 |
} |
} |
97 |
|
|
98 |
|
NTSTATUS |
99 |
|
parallel_read(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
100 |
|
{ |
101 |
|
*result = read(handle, data, length); |
102 |
|
return STATUS_SUCCESS; |
103 |
|
} |
104 |
|
|
105 |
static NTSTATUS |
static NTSTATUS |
106 |
parallel_write(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
parallel_write(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
107 |
{ |
{ |
136 |
DEVICE_FNS parallel_fns = { |
DEVICE_FNS parallel_fns = { |
137 |
parallel_create, |
parallel_create, |
138 |
parallel_close, |
parallel_close, |
139 |
NULL, |
parallel_read, |
140 |
parallel_write, |
parallel_write, |
141 |
parallel_device_control |
parallel_device_control |
142 |
}; |
}; |