source: trunk/src/kernel32/hmparport.cpp@ 7549

Last change on this file since 7549 was 7549, checked in by sandervl, 24 years ago

preliminary changes for new overlapped io framework

File size: 26.0 KB
Line 
1/* $Id: hmparport.cpp,v 1.16 2001-12-05 14:16:04 sandervl Exp $ */
2
3/*
4 * Project Odin Software License can be found in LICENSE.TXT
5 *
6 * Win32 Parallel Port device access class
7 *
8 * 2001 Patrick Haller <patrick.haller@innotek.de>
9 *
10 */
11
12
13
14#include <os2win.h>
15#include <string.h>
16#include <handlemanager.h>
17#include "handlenames.h"
18#include <heapstring.h>
19#include <winioctl.h>
20#include "hmdevice.h"
21#include "hmparport.h"
22#include "oslibdos.h"
23
24#define DBG_LOCALLOG DBG_hmparport
25#include "dbglocal.h"
26
27
28#define MAGIC_PARPORT 0x4c505431
29
30#define IOCTL_PRINTER 0x0005
31#define PRT_QUERYJOBHANDLE 0x0021
32#define PRT_SETFRAMECTL 0x0042
33#define PRT_SETINFINITERETRY 0x0044
34#define PRT_INITPRINTER 0x0046
35#define PRT_ACTIVATEFONT 0x0048
36#define PRT_SETPRINTJOBTITLE 0x004D
37#define PRT_SETIRQTIMEOUT 0x004E
38#define PRT_SETCOMMMODE 0x0052
39#define PRT_SETDATAXFERMODE 0x0053
40#define PRT_GETFRAMECTL 0x0062
41#define PRT_GETINFINITERETRY 0x0064
42#define PRT_GETPRINTERSTATUS 0x0066
43#define PRT_QUERYACTIVEFONT 0x0069
44#define PRT_VERIFYFONT 0x006A
45#define PRT_QUERYIRQTIMEOUT 0x006E
46#define PRT_QUERYCOMMMODE 0x0072
47#define PRT_QUERYDATAXFERMODE 0x0073
48#define PRT_QUERDEVICEID 0x0074
49
50
51#if 0
52#pragma pack(1)
53typedef struct _DCBINFO
54{
55 USHORT usWriteTimeout; /* Time period used for Write Timeout processing. */
56 USHORT usReadTimeout; /* Time period used for Read Timeout processing. */
57 BYTE fbCtlHndShake; /* HandShake Control flag. */
58 BYTE fbFlowReplace; /* Flow Control flag. */
59 BYTE fbTimeOut; /* Timeout flag. */
60 BYTE bErrorReplacementChar; /* Error Replacement Character. */
61 BYTE bBreakReplacementChar; /* Break Replacement Character. */
62 BYTE bXONChar; /* Character XON. */
63 BYTE bXOFFChar; /* Character XOFF. */
64} DCBINFO;
65typedef DCBINFO *PDCBINFO;
66
67
68typedef struct _RXQUEUE
69{
70 USHORT cch; /* Number of characters in the queue. */
71 USHORT cb; /* Size of receive/transmit queue. */
72} RXQUEUE;
73
74typedef RXQUEUE *PRXQUEUE;
75
76
77typedef struct _MODEMSTATUS
78{
79 BYTE fbModemOn; /* Modem Control Signals ON Mask. */
80 BYTE fbModemOff; /* Modem Control Signals OFF Mask. */
81} MODEMSTATUS;
82
83typedef MODEMSTATUS *PMODEMSTATUS;
84
85
86#pragma pack()
87
88
89#endif
90
91
92// Hardwired parallel port configuration information.
93// @@@PH better query the Resource Manager
94typedef struct tagParallelPortConfiguration
95{
96 ULONG ulNumber;
97 ULONG ulPortBase;
98 ULONG ulPortSpan;
99 ULONG ulEcpPortBase;
100 ULONG ulEcpPortSpan;
101} PARALLELPORTCONFIGURATION, *PPARALLELPORTCONFIGURATION;
102
103#define MAX_PARALLEL_PORTS_CONFIGURATION 3
104static PARALLELPORTCONFIGURATION arrParallelPorts[MAX_PARALLEL_PORTS_CONFIGURATION] =
105{
106 {1, 0x378, 8, 0x778, 3},
107 {2, 0x278, 8, 0x678, 3},
108 {3, 0x3bc, 8, 0x000, 0}
109};
110
111
112typedef struct _HMDEVPARPORTDATA
113{
114 ULONG ulMagic;
115
116 // Win32 Device Control Block
117 COMMCONFIG CommCfg;
118
119 // hardware configuration block
120 PPARALLELPORTCONFIGURATION pHardwareConfiguration;
121} HMDEVPARPORTDATA, *PHMDEVPARPORTDATA;
122
123static VOID *CreateDevData()
124{
125 PHMDEVPARPORTDATA pData;
126 pData = new HMDEVPARPORTDATA();
127 if(NULL!=pData)
128 {
129 memset(pData,0,sizeof(HMDEVPARPORTDATA));
130 pData->ulMagic = MAGIC_PARPORT;
131 pData->CommCfg.dwSize = sizeof(COMMCONFIG);
132 pData->CommCfg.wVersion = 1;
133 pData->CommCfg.dwProviderSubType = PST_PARALLELPORT;
134 }
135 return pData;
136}
137
138
139HMDeviceParPortClass::HMDeviceParPortClass(LPCSTR lpDeviceName) :
140 HMDeviceHandler(lpDeviceName)
141{
142 dprintf(("HMDeviceParPortClass::HMDevParPortClass(%s)\n",
143 lpDeviceName));
144
145#ifndef DEVINFO_PRINTER
146#define DEVINFO_PRINTER 0
147#endif
148
149 // first, we determine the number of parallel port devices available
150
151 // PH 2001-12-04 Note:
152 // This call will not return any information about redirected LPT ports.
153 // We have a specific application requiring exactly this behaviour as it
154 // cannot talk to redirected LPTs anyway.
155 // For any change in this behaviour, we'd require a configuration switch.
156 bNumberOfParallelPorts = 0;
157 DWORD rc = OSLibDosDevConfig(&bNumberOfParallelPorts,
158 DEVINFO_PRINTER);
159 dprintf(("HMDeviceParPortClass: Parallel ports reported: %d\n",
160 bNumberOfParallelPorts));
161 if (0 == bNumberOfParallelPorts)
162 return;
163
164 VOID *pData;
165 dprintf(("HMDeviceParPortClass: Registering LPTs with Handle Manager\n"));
166
167 pData = CreateDevData();
168 if(pData!= NULL)
169 HMDeviceRegisterEx("LPT1", this, pData);
170
171 // add symbolic links to the "real name" of the device
172 if (bNumberOfParallelPorts > 0)
173 {
174 // Note: \\.\LPTx: is invalid (NT4SP6)
175 PSZ pszLPT = strdup("\\\\.\\LPTx");
176 PSZ pszLPT2 = strdup("\\Device\\ParallelPort0");
177 for (char ch = '1'; ch <= '1' + (bNumberOfParallelPorts - 1); ch++)
178 {
179 pszLPT[7] = ch;
180 pszLPT2[20] = ch - 1; // \DeviceParallelPort0 -> LPT1
181 HandleNamesAddSymbolicLink(pszLPT, pszLPT+4);
182 HandleNamesAddSymbolicLink(pszLPT2, pszLPT+4);
183 }
184 free(pszLPT);
185 free(pszLPT2);
186
187 // add "PRN" device
188 HandleNamesAddSymbolicLink("PRN", "LPT1");
189 HandleNamesAddSymbolicLink("PRN:", "LPT1");
190 HandleNamesAddSymbolicLink("\\\\.\\PRN", "LPT1");
191 }
192}
193
194/*****************************************************************************
195 * Name : HMDeviceParPortClass::FindDevice
196 * Purpose : Checks if lpDeviceName belongs to this device class
197 * Parameters: LPCSTR lpClassDevName
198 * LPCSTR lpDeviceName
199 * int namelength
200 * Variables :
201 * Result : checks if name is COMx or COMx: (x=1..8)
202 * Remark :
203 * Status :
204 *
205 * Author : SvL
206 *****************************************************************************/
207BOOL HMDeviceParPortClass::FindDevice(LPCSTR lpClassDevName, LPCSTR lpDeviceName, int namelength)
208{
209 // Don't accept any name if no parallel ports have been detected
210 if (bNumberOfParallelPorts == 0)
211 return FALSE;
212
213 // can be both, "LPT1" and "LPT1:"
214 if(namelength > 5)
215 return FALSE; //can't be lpt name
216
217 //first 3 letters 'LPT'?
218 if(lstrncmpiA(lpDeviceName, lpClassDevName, 3) != 0)
219 return FALSE;
220
221 if(namelength == 5 && lpDeviceName[4] != ':')
222 return FALSE;
223
224 // can support up tp LPT9
225 if ( (lpDeviceName[3] >= '1') &&
226 (lpDeviceName[3] <= '1' + bNumberOfParallelPorts) )
227 {
228 return TRUE;
229 }
230
231 return FALSE;
232}
233
234DWORD HMDeviceParPortClass::CreateFile(LPCSTR lpFileName,
235 PHMHANDLEDATA pHMHandleData,
236 PVOID lpSecurityAttributes,
237 PHMHANDLEDATA pHMHandleDataTemplate)
238{
239 dprintf(("HMDeviceParPortClass::CreateFile(%s,%08xh,%08xh,%08xh)\n",
240 lpFileName,
241 pHMHandleData,
242 lpSecurityAttributes,
243 pHMHandleDataTemplate));
244
245 char lptname[6];
246
247 dprintf(("HMDeviceParPortClass: Parallel port %s open request\n", lpFileName));
248
249 // Don't accept any name if no parallel ports have been detected
250 if (bNumberOfParallelPorts == 0)
251 {
252 return ERROR_DEV_NOT_EXIST;
253 }
254
255 strcpy(lptname, lpFileName);
256 lptname[4] = 0; //get rid of : (if present) (eg LPT1:)
257
258 //AH: TODO parse Win32 security handles
259 ULONG oldmode = SetErrorMode(SEM_FAILCRITICALERRORS);
260 pHMHandleData->hHMHandle = OSLibDosOpen(lptname,
261 OSLIB_ACCESS_READWRITE |
262 OSLIB_ACCESS_SHAREDENYREAD |
263 OSLIB_ACCESS_SHAREDENYWRITE);
264 SetErrorMode(oldmode);
265
266 // check if handle could be opened properly
267 if (0 == pHMHandleData->hHMHandle)
268 {
269 return ERROR_ACCESS_DENIED; // signal failure
270 }
271 else
272 {
273 ULONG ulLen;
274 APIRET rc;
275 pHMHandleData->lpHandlerData = new HMDEVPARPORTDATA();
276
277 // Init The handle instance with the default default device config
278 memcpy( pHMHandleData->lpHandlerData,
279 pHMHandleData->lpDeviceData,
280 sizeof(HMDEVPARPORTDATA));
281
282 // determine which port was opened
283 ULONG ulPortNo = lptname[3] - '1';
284
285 // safety check (device no 0..8 -> LPT1..9)
286 if (ulPortNo > MAX_PARALLEL_PORTS_CONFIGURATION)
287 {
288 HMDeviceParPortClass::CloseHandle(pHMHandleData);
289 return ERROR_DEV_NOT_EXIST;
290 }
291
292 // and save the hardware information
293 PHMDEVPARPORTDATA pPPD = (PHMDEVPARPORTDATA)pHMHandleData->lpHandlerData;
294 pPPD->pHardwareConfiguration = &arrParallelPorts[ulPortNo];
295
296 return NO_ERROR;
297 }
298}
299
300
301 /* this is a handler method for calls to CloseHandle() */
302BOOL HMDeviceParPortClass::CloseHandle(PHMHANDLEDATA pHMHandleData)
303{
304 dprintf(("HMDeviceParPortClass: Parallel port close request(%08xh)\n",
305 pHMHandleData));
306
307 delete pHMHandleData->lpHandlerData;
308 return OSLibDosClose(pHMHandleData->hHMHandle);
309}
310
311
312/*****************************************************************************
313 * Name : BOOL HMDeviceParPortClass::WriteFile
314 * Purpose : write data to handle / device
315 * Parameters: PHMHANDLEDATA pHMHandleData,
316 * LPCVOID lpBuffer,
317 * DWORD nNumberOfBytesToWrite,
318 * LPDWORD lpNumberOfBytesWritten,
319 * LPOVERLAPPED lpOverlapped
320 * Variables :
321 * Result : Boolean
322 * Remark :
323 * Status :
324 *
325 * Author : SvL
326 *****************************************************************************/
327
328BOOL HMDeviceParPortClass::WriteFile(PHMHANDLEDATA pHMHandleData,
329 LPCVOID lpBuffer,
330 DWORD nNumberOfBytesToWrite,
331 LPDWORD lpNumberOfBytesWritten,
332 LPOVERLAPPED lpOverlapped,
333 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
334{
335 dprintf(("KERNEL32:HMDeviceParPortClass::WriteFile %s(%08x,%08x,%08x,%08x,%08x)",
336 lpHMDeviceName,
337 pHMHandleData->hHMHandle,
338 lpBuffer,
339 nNumberOfBytesToWrite,
340 lpNumberOfBytesWritten,
341 lpOverlapped));
342
343 BOOL ret;
344 ULONG ulBytesWritten;
345
346 if((pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && !lpOverlapped) {
347 dprintf(("FILE_FLAG_OVERLAPPED flag set, but lpOverlapped NULL!!"));
348 SetLastError(ERROR_INVALID_PARAMETER);
349 return FALSE;
350 }
351 if(!(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && lpOverlapped) {
352 dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
353 }
354
355 ret = OSLibDosWrite(pHMHandleData->hHMHandle, (LPVOID)lpBuffer, nNumberOfBytesToWrite,
356 &ulBytesWritten);
357
358 if(lpNumberOfBytesWritten) {
359 *lpNumberOfBytesWritten = (ret) ? ulBytesWritten : 0;
360 }
361 if(ret == FALSE) {
362 dprintf(("ERROR: WriteFile failed with rc %d", GetLastError()));
363 }
364
365 return ret;
366}
367
368/*****************************************************************************
369 * Name : BOOL HMDeviceParPortClass::ReadFile
370 * Purpose : read data from handle / device
371 * Parameters: PHMHANDLEDATA pHMHandleData,
372 * LPCVOID lpBuffer,
373 * DWORD nNumberOfBytesToRead,
374 * LPDWORD lpNumberOfBytesRead,
375 * LPOVERLAPPED lpOverlapped
376 * Variables :
377 * Result : Boolean
378 * Remark :
379 * Status :
380 *
381 * Author : SvL
382 *****************************************************************************/
383
384BOOL HMDeviceParPortClass::ReadFile(PHMHANDLEDATA pHMHandleData,
385 LPCVOID lpBuffer,
386 DWORD nNumberOfBytesToRead,
387 LPDWORD lpNumberOfBytesRead,
388 LPOVERLAPPED lpOverlapped,
389 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
390{
391 dprintf(("KERNEL32:HMDeviceParPortClass::ReadFile %s(%08x,%08x,%08x,%08x,%08x)",
392 lpHMDeviceName,
393 pHMHandleData->hHMHandle,
394 lpBuffer,
395 nNumberOfBytesToRead,
396 lpNumberOfBytesRead,
397 lpOverlapped));
398
399 BOOL ret;
400 ULONG ulBytesRead;
401
402 if((pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && !lpOverlapped) {
403 dprintf(("FILE_FLAG_OVERLAPPED flag set, but lpOverlapped NULL!!"));
404 SetLastError(ERROR_INVALID_PARAMETER);
405 return FALSE;
406 }
407 if(!(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && lpOverlapped) {
408 dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
409 }
410
411 ret = OSLibDosRead(pHMHandleData->hHMHandle, (LPVOID)lpBuffer, nNumberOfBytesToRead,
412 &ulBytesRead);
413
414 if(lpNumberOfBytesRead) {
415 *lpNumberOfBytesRead = (ret) ? ulBytesRead : 0;
416 }
417 if(ret == FALSE) {
418 dprintf(("ERROR: ReadFile failed with rc %d", GetLastError()));
419 }
420 return ret;
421}
422
423BOOL HMDeviceParPortClass::GetCommProperties( PHMHANDLEDATA pHMHandleData,
424 LPCOMMPROP lpcmmp)
425{
426 dprintf(("HMDeviceParPortClass::GetCommProperties(%08xh, %08xh)\n",
427 pHMHandleData,
428 lpcmmp));
429
430 APIRET rc;
431 ULONG ulLen;
432 int i;
433
434#if 0
435 USHORT COMErr;
436 EXTBAUDGET BaudInfo;
437 ulLen = sizeof(EXTBAUDGET);
438 rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
439 IOCTL_ASYNC,
440 ASYNC_EXTGETBAUDRATE,
441 0,0,0,
442 &BaudInfo,ulLen,&ulLen);
443#endif
444 rc = NO_ERROR;
445
446 memset(lpcmmp,0,sizeof(COMMPROP));
447 lpcmmp->wPacketLength = sizeof(COMMPROP);
448 lpcmmp->wPacketVersion = 1; //???
449 lpcmmp->dwProvSubType = PST_PARALLELPORT;
450
451#if 0
452 lpcmmp->dwServiceMask = SP_SERIALCOMM;
453 for(i=0;i<BaudTableSize && BaudInfo.ulMaxBaud <= BaudTable[i].dwBaudRate;i++);
454 lpcmmp->dwMaxBaud = BaudTable[i].dwBaudFlag;
455 lpcmmp->dwProvCapabilities = PCF_DTRDSR | PCF_PARITY_CHECK |
456 PCF_RTSCTS | PCF_SETXCHAR |
457 PCF_XONXOFF;
458 lpcmmp->dwSettableParams = SP_BAUD | SP_DATABITS |
459 SP_HANDSHAKEING | SP_PARITY |
460 SP_PARITY_CHECK | SP_STOPBIT;
461 lpcmmp->dwSettableBaud = 0;
462 for(i=0;i<BaudTableSize;i++)
463 {
464 if ( (BaudTable[i].dwBaudRate>=BaudInfo.ulMinBaud) &&
465 (BaudTable[i].dwBaudRate<=BaudInfo.ulMaxBaud) )
466 lpcmmp->dwSettableBaud |= BaudTable[i].dwBaudFlag;
467 }
468 lpcmmp->dwSettableBaud |= BAUD_USER;
469 lpcmmp->wSettableData = DATABITS_5 | DATABITS_6 | DATABITS_7 | DATABITS_8;
470 lpcmmp->wSettableStopParity = STOPBITS_10 | STOPBITS_15 | STOPBITS_20 |
471 PARITY_NONE | PARITY_ODD | PARITY_EVEN |
472 PARITY_MARK | PARITY_SPACE;
473#endif
474
475 return(rc==0);
476}
477
478BOOL HMDeviceParPortClass::ClearCommError( PHMHANDLEDATA pHMHandleData,
479 LPDWORD lpdwErrors,
480 LPCOMSTAT lpcst)
481{
482 dprintf(("HMDeviceParPortClass::ClearCommError(%08xh,%08xh,%08xh)\n",
483 pHMHandleData,
484 lpdwErrors,
485 lpcst));
486
487 APIRET rc;
488 ULONG ulLen;
489 USHORT COMErr;
490
491 ulLen = sizeof(USHORT);
492
493 *lpdwErrors = 0;
494 rc = NO_ERROR;
495
496#if 0
497 // ParPort: CE_DNS, CE_OOP CE_PTO
498
499 rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
500 IOCTL_ASYNC,
501 ASYNC_GETCOMMERROR,
502 0,0,0,
503 &COMErr,2,&ulLen);
504 *lpdwErrors |= (COMErr & 0x0001)?CE_OVERRUN:0;
505 *lpdwErrors |= (COMErr & 0x0002)?CE_RXOVER:0;
506 *lpdwErrors |= (COMErr & 0x0004)?CE_RXPARITY:0;
507 *lpdwErrors |= (COMErr & 0x0008)?CE_FRAME:0;
508
509 if(lpcst)
510 {
511 UCHAR ucStatus;
512 RXQUEUE qInfo;
513 ulLen = 1;
514 rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
515 IOCTL_ASYNC,
516 ASYNC_GETCOMMSTATUS,
517 0,0,0,
518 &ucStatus,ulLen,&ulLen);
519 if(!rc)
520 {
521 lpcst->fCtsHold = ((ucStatus & 0x01)>0);
522 lpcst->fDsrHold = ((ucStatus & 0x02)>0);
523 lpcst->fRlsdHold = FALSE;//(ucStatus & 0x04)>0);
524 lpcst->fXoffHold = ((ucStatus & 0x08)>0);
525 lpcst->fXoffSend = ((ucStatus & 0x10)>0);
526 lpcst->fEof = ((ucStatus & 0x20)>0);// Is break = Eof ??
527 lpcst->fTxim = ((ucStatus & 0x40)>0);
528
529 ulLen = sizeof(qInfo);
530 rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
531 IOCTL_ASYNC,
532 ASYNC_GETINQUECOUNT,
533 0,0,0,
534 &qInfo,ulLen,&ulLen);
535 if(!rc)
536 {
537 lpcst->cbInQue = qInfo.cch;
538 rc = OSLibDosDevIOCtl( pHMHandleData->hHMHandle,
539 IOCTL_ASYNC,
540 ASYNC_GETOUTQUECOUNT,
541 0,0,0,
542 &qInfo,ulLen,&ulLen);
543 if(!rc)
544 lpcst->cbOutQue = qInfo.cch;
545 }
546 }
547 }
548#endif
549
550 return(rc==NO_ERROR);
551}
552
553
554BOOL HMDeviceParPortClass::DeviceIoControl(PHMHANDLEDATA pHMHandleData,
555 DWORD dwIoControlCode,
556 LPVOID lpInBuffer,
557 DWORD nInBufferSize,
558 LPVOID lpOutBuffer,
559 DWORD nOutBufferSize,
560 LPDWORD lpBytesReturned,
561 LPOVERLAPPED lpOverlapped)
562{
563#ifdef DEBUG
564 char *msg = NULL;
565
566 switch(dwIoControlCode)
567 {
568 case IOCTL_INTERNAL_GET_PARALLEL_PORT_INFO:
569 msg = "IOCTL_INTERNAL_GET_PARALLEL_PORT_INFO";
570 break;
571
572 case IOCTL_INTERNAL_GET_PARALLEL_PNP_INFO:
573 msg = "IOCTL_INTERNAL_GET_PARALLEL_PNP_INFO";
574 break;
575 }
576
577 if(msg) {
578 dprintf(("HMDeviceParPortClass::DeviceIoControl %s %x %d %x %d %x %x", msg, lpInBuffer, nInBufferSize,
579 lpOutBuffer, nOutBufferSize, lpBytesReturned, lpOverlapped));
580 }
581#endif
582
583 switch(dwIoControlCode)
584 {
585 case IOCTL_INTERNAL_GET_PARALLEL_PORT_INFO:
586 {
587 PPARALLEL_PORT_INFORMATION pPPI = (PPARALLEL_PORT_INFORMATION)lpOutBuffer;
588
589 if(nOutBufferSize < sizeof(PARALLEL_PORT_INFORMATION) || !pPPI)
590 {
591 SetLastError(ERROR_INSUFFICIENT_BUFFER);
592 return FALSE;
593 }
594
595 if(lpBytesReturned)
596 *lpBytesReturned = sizeof(PARALLEL_PORT_INFORMATION);
597
598 // fill in the data values
599 PHMDEVPARPORTDATA pPPD = (PHMDEVPARPORTDATA)pHMHandleData->lpHandlerData;
600
601 // @@@PH
602 // Specifies the bus relative base I/O address of the parallel port registers.
603 pPPI->OriginalController.LowPart = pPPD->pHardwareConfiguration->ulPortBase;
604 pPPI->OriginalController.HighPart = 0;
605
606 // Pointer to the system-mapped base I/O location of the parallel port registers.
607 pPPI->Controller = NULL;
608
609 // Specifies the size, in bytes, of the I/O space, allocated to the parallel port.
610 pPPI->SpanOfController = pPPD->pHardwareConfiguration->ulPortSpan;
611
612 // Pointer to a callback routine that a kernel-mode driver can use to try to allocate the parallel port.
613 pPPI->TryAllocatePort = NULL;
614
615 // Pointer to a callback routine that a kernel-mode driver can use to free the parallel port.
616 pPPI->FreePort = NULL;
617
618 // Pointer to a callback routine that a kernel-mode driver can use to determine the number of requests on the work queue of the parallel port.
619 pPPI->QueryNumWaiters = NULL;
620
621 // Pointer to the device extension of parallel port.
622 pPPI->Context = NULL;
623
624 return TRUE;
625 }
626
627
628 case IOCTL_INTERNAL_GET_PARALLEL_PNP_INFO:
629 {
630 PPARALLEL_PNP_INFORMATION pPPI = (PPARALLEL_PNP_INFORMATION)lpOutBuffer;
631
632 if(nOutBufferSize < sizeof(PARALLEL_PNP_INFORMATION) || !pPPI)
633 {
634 SetLastError(ERROR_INSUFFICIENT_BUFFER);
635 return FALSE;
636 }
637
638 if(lpBytesReturned)
639 *lpBytesReturned = sizeof(PARALLEL_PNP_INFORMATION);
640
641 // fill in the data values
642 PHMDEVPARPORTDATA pPPD = (PHMDEVPARPORTDATA)pHMHandleData->lpHandlerData;
643
644 // @@@PH
645 // Specifies the base physical address that the system-supplied
646 // function driver for parallel ports uses to control the ECP
647 // operation of the parallel port.
648 pPPI->OriginalEcpController.LowPart = pPPD->pHardwareConfiguration->ulEcpPortBase;
649 pPPI->OriginalEcpController.HighPart = 0;
650
651 // Pointer to the I/O port resource that is used to control the
652 // port in ECP mode.
653 pPPI->EcpController = NULL;
654
655 // Specifies the size, in bytes, of the I/O port resource.
656 pPPI->SpanOfEcpController = pPPD->pHardwareConfiguration->ulEcpPortSpan;
657
658 // Not used.
659 pPPI->PortNumber = 0;
660
661 // Specifies the hardware capabilities of the parallel port. The following capabilities can be set using a bitwise OR of the following constants:
662 pPPI->HardwareCapabilities = 0;
663 // PPT_1284_3_PRESENT
664 // PPT_BYTE_PRESENT
665 // PPT_ECP_PRESENT
666 // PPT_EPP_32_PRESENT
667 // PPT_EPP_PRESENT
668 // PT_NO_HARDWARE_PRESENT
669
670 // Pointer to a callback routine that a kernel-mode driver can use to change the operating mode of the parallel port.
671 pPPI->TrySetChipMode = 0;
672
673 // Pointer to a callback routine that a kernel-mode driver can use to clear the operating mode of the parallel port.
674 pPPI->ClearChipMode = 0;
675
676 // Specifies the size, in words, of the hardware first in/first out (FIFO) buffer. The FIFO word size, in bits, is the value of FifoWidth.
677 pPPI->FifoDepth = 0;
678
679 // Specifies the FIFO word size, in bits, which is the number of bits handled in parallel.
680 pPPI->FifoWidth = 0;
681
682 // Not used.
683 pPPI->EppControllerPhysicalAddress.LowPart = 0;
684 pPPI->EppControllerPhysicalAddress.HighPart = 0;
685
686 // Not used.
687 pPPI->SpanOfEppController = 0;
688
689 // Specifies the number of daisy-chain devices currently attached to a parallel port. In Microsoftÿ Windowsÿ XP, from zero to two devices can be simultaneously connected to a
690 // parallel port. In Windows 2000, from zero to four devices can be simultaneously connected to a parallel port.
691 pPPI->Ieee1284_3DeviceCount = 0;
692
693 // Pointer to a callback routine that a kernel-mode driver can use to try to select an IEEE 1284.3 device.
694 pPPI->TrySelectDevice = 0;
695
696 // Pointer to a callback routine that a kernel-mode driver can use to deselect an IEEE 1284.3 device.
697 pPPI->DeselectDevice = 0;
698
699 // Pointer to the device extension of a parallel port's function device object (FDO).
700 pPPI->Context = 0;
701
702 // The current operating mode of the parallel port.
703 pPPI->CurrentMode = 0;
704
705 // The symbolic link name of the parallel port.
706 pPPI->PortName = 0;
707
708 return TRUE;
709 }
710 }
711 dprintf(("HMDeviceParPortClass::DeviceIoControl: unimplemented dwIoControlCode=%08lx\n", dwIoControlCode));
712 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
713 return FALSE;
714}
715
716
717BOOL HMDeviceParPortClass::SetDefaultCommConfig( PHMHANDLEDATA pHMHandleData,
718 LPCOMMCONFIG lpCC,
719 DWORD dwSize)
720{
721 dprintf(("HMDeviceParPortClass::SetDefaultCommConfig(%08xh,%08xh,%08xh)\n",
722 pHMHandleData,
723 lpCC,
724 dwSize));
725
726 PHMDEVPARPORTDATA pDevData = (PHMDEVPARPORTDATA)pHMHandleData->lpDeviceData;
727 if((NULL==pDevData) || (pDevData->ulMagic != MAGIC_PARPORT) )
728 {
729 SetLastError(ERROR_INVALID_HANDLE);
730 return FALSE;
731 }
732 memset(&pDevData->CommCfg,0, sizeof(COMMCONFIG));
733 memcpy(&pDevData->CommCfg,lpCC,dwSize>sizeof(COMMCONFIG)?sizeof(COMMCONFIG):dwSize);
734
735 return(TRUE);
736}
737
738
739BOOL HMDeviceParPortClass::GetDefaultCommConfig( PHMHANDLEDATA pHMHandleData,
740 LPCOMMCONFIG lpCC,
741 LPDWORD lpdwSize)
742{
743 dprintf(("HMDeviceParPortClass::GetDefaultCommConfig(%08xh,%08xh,%08xh)\n",
744 pHMHandleData,
745 lpCC,
746 lpdwSize));
747
748
749 PHMDEVPARPORTDATA pDevData = (PHMDEVPARPORTDATA)pHMHandleData->lpDeviceData;
750
751 if( O32_IsBadWritePtr(lpCC,sizeof(COMMCONFIG)) ||
752 *lpdwSize< sizeof(COMMCONFIG) )
753 {
754 SetLastError(ERROR_INSUFFICIENT_BUFFER);
755 *lpdwSize= sizeof(COMMCONFIG);
756 return FALSE;
757 }
758
759 if((NULL==pDevData) || (pDevData->ulMagic != MAGIC_PARPORT) )
760 {
761 SetLastError(ERROR_INVALID_HANDLE);
762 return FALSE;
763 }
764
765 memcpy(lpCC,&pDevData->CommCfg,sizeof(COMMCONFIG));
766 *lpdwSize = sizeof(COMMCONFIG);
767 return(TRUE);
768}
769
770
771BOOL HMDeviceParPortClass::SetCommConfig( PHMHANDLEDATA pHMHandleData,
772 LPCOMMCONFIG lpCC,
773 DWORD dwSize )
774{
775 dprintf(("HMDeviceParPortClass::SetCommConfig not implemented"));
776
777 return(TRUE);
778}
779
780
781BOOL HMDeviceParPortClass::GetCommConfig( PHMHANDLEDATA pHMHandleData,
782 LPCOMMCONFIG lpCC,
783 LPDWORD lpdwSize )
784{
785 PHMDEVPARPORTDATA pDevData = (PHMDEVPARPORTDATA)pHMHandleData->lpHandlerData;
786
787 dprintf(("HMDeviceParPortClass::GetCommConfig(%08xh,%08xh,%08xh)\n",
788 pHMHandleData,
789 lpCC,
790 lpdwSize));
791
792 if( O32_IsBadWritePtr(lpCC,sizeof(COMMCONFIG)) ||
793 *lpdwSize< sizeof(COMMCONFIG) )
794 {
795 SetLastError(ERROR_INSUFFICIENT_BUFFER);
796 *lpdwSize= sizeof(COMMCONFIG);
797 return FALSE;
798 }
799
800 if((NULL==pDevData) || (pDevData->ulMagic != MAGIC_PARPORT) )
801 {
802 SetLastError(ERROR_INVALID_HANDLE);
803 return FALSE;
804 }
805
806 memcpy(lpCC,&pDevData->CommCfg,sizeof(COMMCONFIG));
807 *lpdwSize = sizeof(COMMCONFIG);
808 return(TRUE);
809}
Note: See TracBrowser for help on using the repository browser.