ReactOS  0.4.14-dev-77-gd9e7c48
parallel.c File Reference
#include "rdesktop.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
Include dependency graph for parallel.c:

Go to the source code of this file.

Macros

#define MAX_PARALLEL_DEVICES   1
 
#define FILE_DEVICE_PARALLEL   0x22
 
#define IOCTL_PAR_QUERY_RAW_DEVICE_ID   0x0c
 

Functions

int parallel_enum_devices (RDPCLIENT *This, uint32 *id, char *optarg)
 
static NTSTATUS parallel_create (RDPCLIENT *This, uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, uint32 flags, char *filename, NTHANDLE *handle)
 
static NTSTATUS parallel_close (RDPCLIENT *This, NTHANDLE handle)
 
static NTSTATUS parallel_read (RDPCLIENT *This, NTHANDLE handle, uint8 *data, uint32 length, uint32 offset, uint32 *result)
 
static NTSTATUS parallel_write (RDPCLIENT *This, NTHANDLE handle, uint8 *data, uint32 length, uint32 offset, uint32 *result)
 
static NTSTATUS parallel_device_control (RDPCLIENT *This, NTHANDLE handle, uint32 request, STREAM in, STREAM out)
 

Variables

DEVICE_FNS parallel_fns
 

Macro Definition Documentation

◆ FILE_DEVICE_PARALLEL

#define FILE_DEVICE_PARALLEL   0x22

Definition at line 21 of file parallel.c.

◆ IOCTL_PAR_QUERY_RAW_DEVICE_ID

#define IOCTL_PAR_QUERY_RAW_DEVICE_ID   0x0c

Definition at line 23 of file parallel.c.

◆ MAX_PARALLEL_DEVICES

#define MAX_PARALLEL_DEVICES   1

Definition at line 19 of file parallel.c.

Function Documentation

◆ parallel_close()

static NTSTATUS parallel_close ( RDPCLIENT This,
NTHANDLE  handle 
)
static

Definition at line 105 of file parallel.c.

106 {
107  int i = get_device_index(This, handle);
108  if (i >= 0)
109  This->rdpdr_device[i].handle = 0;
110  close(handle);
111  return STATUS_SUCCESS;
112 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
int get_device_index(RD_NTHANDLE handle)
#define close
Definition: acwin.h:98
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ parallel_create()

static NTSTATUS parallel_create ( RDPCLIENT This,
uint32  device_id,
uint32  access,
uint32  share_mode,
uint32  disposition,
uint32  flags,
char filename,
NTHANDLE *  handle 
)
static

Definition at line 76 of file parallel.c.

78 {
79  int parallel_fd;
80 
81  parallel_fd = open(This->rdpdr_device[device_id].local_path, O_RDWR);
82  if (parallel_fd == -1)
83  {
84  perror("open");
85  return STATUS_ACCESS_DENIED;
86  }
87 
88  /* all read and writes should be non blocking */
89  if (fcntl(parallel_fd, F_SETFL, O_NONBLOCK) == -1)
90  perror("fcntl");
91 
92 #if defined(LPABORT)
93  /* Retry on errors */
94  ioctl(parallel_fd, LPABORT, (int) 1);
95 #endif
96 
97  This->rdpdr_device[device_id].handle = parallel_fd;
98 
99  *handle = parallel_fd;
100 
101  return STATUS_SUCCESS;
102 }
#define open
Definition: acwin.h:95
#define O_NONBLOCK
Definition: port.h:158
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
#define ioctl
Definition: wintirpc.h:60
#define LPABORT
Definition: parallel.h:57
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define O_RDWR
Definition: fcntl.h:36
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ parallel_device_control()

static NTSTATUS parallel_device_control ( RDPCLIENT This,
NTHANDLE  handle,
uint32  request,
STREAM  in,
STREAM  out 
)
static

Definition at line 158 of file parallel.c.

159 {
160  if ((request >> 16) != FILE_DEVICE_PARALLEL)
162 
163  /* extract operation */
164  request >>= 2;
165  request &= 0xfff;
166 
167  printf("PARALLEL IOCTL %d: ", request);
168 
169  switch (request)
170  {
172 
173  default:
174 
175  printf("\n");
176  unimpl("UNKNOWN IOCTL %d\n", request);
177  }
178  return STATUS_SUCCESS;
179 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define IOCTL_PAR_QUERY_RAW_DEVICE_ID
Definition: parallel.c:23
#define FILE_DEVICE_PARALLEL
Definition: parallel.c:21
Definition: tftpd.h:85
void unimpl(char *format,...)
Definition: uimain.c:801
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define printf
Definition: config.h:203

◆ parallel_enum_devices()

int parallel_enum_devices ( RDPCLIENT This,
uint32 id,
char optarg 
)

Definition at line 40 of file parallel.c.

41 {
42  PARALLEL_DEVICE *ppar_info;
43 
44  char *pos = optarg;
45  char *pos2;
46  int count = 0;
47 
48  /* skip the first colon */
49  optarg++;
50  while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES)
51  {
52  ppar_info = (PARALLEL_DEVICE *) xmalloc(sizeof(PARALLEL_DEVICE));
53 
54  pos2 = next_arg(optarg, '=');
55  strcpy(This->rdpdr_device[*id].name, optarg);
56 
57  toupper_str(This->rdpdr_device[*id].name);
58 
59  This->rdpdr_device[*id].local_path = xmalloc(strlen(pos2) + 1);
60  strcpy(This->rdpdr_device[*id].local_path, pos2);
61  printf("PARALLEL %s to %s\n", optarg, pos2);
62 
63  /* set device type */
64  This->rdpdr_device[*id].device_type = DEVICE_TYPE_PARALLEL;
65  This->rdpdr_device[*id].pdevice_data = (void *) ppar_info;
66  This->rdpdr_device[*id].handle = 0;
67  count++;
68  (*id)++;
69 
70  optarg = pos;
71  }
72  return count;
73 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define DEVICE_TYPE_PARALLEL
Definition: constants.h:486
void * xmalloc(int size)
Definition: uimain.c:747
#define RDPDR_MAX_DEVICES
Definition: constants.h:484
char * next_arg(char *src, char needle)
Definition: rdesktop.c:1174
const char * optarg
Definition: getopt.c:49
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
GLenum GLuint id
Definition: glext.h:5579
void toupper_str(char *p)
Definition: rdesktop.c:1223
#define printf
Definition: config.h:203

◆ parallel_read()

static NTSTATUS parallel_read ( RDPCLIENT This,
NTHANDLE  handle,
uint8 data,
uint32  length,
uint32  offset,
uint32 result 
)
static

Definition at line 115 of file parallel.c.

116 {
117  *result = read(handle, data, length);
118  return STATUS_SUCCESS;
119 }
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
return STATUS_SUCCESS
Definition: btrfs.c:2966
GLuint64EXT * result
Definition: glext.h:11304
_CRTIMP int __cdecl read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)

◆ parallel_write()

static NTSTATUS parallel_write ( RDPCLIENT This,
NTHANDLE  handle,
uint8 data,
uint32  length,
uint32  offset,
uint32 result 
)
static

Definition at line 122 of file parallel.c.

123 {
124  int rc = STATUS_SUCCESS;
125 
126  int n = write(handle, data, length);
127  if (n < 0)
128  {
129 #if defined(LPGETSTATUS)
130  int status;
131 #endif
132 
133  *result = 0;
134  switch (errno)
135  {
136  case EAGAIN:
138  case ENOSPC:
140  case EIO:
142  default:
144  }
145 #if defined(LPGETSTATUS)
146  if (ioctl(handle, LPGETSTATUS, &status) == 0)
147  {
148  /* coming soon: take care for the printer status */
149  printf("parallel_write: status = %d, errno = %d\n", status, errno);
150  }
151 #endif
152  }
153  *result = n;
154  return rc;
155 }
GLdouble n
Definition: glext.h:7729
int errno
#define write
Definition: acwin.h:97
#define STATUS_DEVICE_PAPER_EMPTY
Definition: ntstatus.h:182
#define STATUS_DEVICE_POWERED_OFF
Definition: ntstatus.h:183
#define ioctl
Definition: wintirpc.h:60
Definition: arc.h:49
Definition: arc.h:35
#define LPGETSTATUS
Definition: parallel.h:68
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define STATUS_DEVICE_OFF_LINE
Definition: ntstatus.h:184
Definition: arc.h:40
return STATUS_SUCCESS
Definition: btrfs.c:2966
GLuint64EXT * result
Definition: glext.h:11304
static SERVICE_STATUS status
Definition: service.c:31
#define printf
Definition: config.h:203
Definition: ps.c:97

Variable Documentation

◆ parallel_fns

DEVICE_FNS parallel_fns
Initial value:
= {
}
static NTSTATUS parallel_read(RDPCLIENT *This, NTHANDLE handle, uint8 *data, uint32 length, uint32 offset, uint32 *result)
Definition: parallel.c:115
static NTSTATUS parallel_create(RDPCLIENT *This, uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, uint32 flags, char *filename, NTHANDLE *handle)
Definition: parallel.c:76
static NTSTATUS parallel_device_control(RDPCLIENT *This, NTHANDLE handle, uint32 request, STREAM in, STREAM out)
Definition: parallel.c:158
static NTSTATUS parallel_write(RDPCLIENT *This, NTHANDLE handle, uint8 *data, uint32 length, uint32 offset, uint32 *result)
Definition: parallel.c:122
static NTSTATUS parallel_close(RDPCLIENT *This, NTHANDLE handle)
Definition: parallel.c:105

Definition at line 181 of file parallel.c.

Referenced by rdpdr_process_irp().