[8404] | 1 | /* $Id: hmparport.cpp,v 1.19 2002-05-13 12:12:42 sandervl Exp $ */
|
---|
[7298] | 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>
|
---|
[7443] | 17 | #include "handlenames.h"
|
---|
[7298] | 18 | #include <heapstring.h>
|
---|
[7435] | 19 | #include <winioctl.h>
|
---|
[7298] | 20 | #include "hmdevice.h"
|
---|
| 21 | #include "hmparport.h"
|
---|
| 22 | #include "oslibdos.h"
|
---|
[8404] | 23 | #include "rmioctl.h"
|
---|
[7298] | 24 | #define DBG_LOCALLOG DBG_hmparport
|
---|
| 25 | #include "dbglocal.h"
|
---|
| 26 |
|
---|
| 27 |
|
---|
| 28 | #define MAGIC_PARPORT 0x4c505431
|
---|
| 29 |
|
---|
[7300] | 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
|
---|
[7298] | 49 |
|
---|
[7538] | 50 | // Hardwired parallel port configuration information.
|
---|
[8404] | 51 | // for the cases where real thing will fail
|
---|
[7538] | 52 | typedef struct tagParallelPortConfiguration
|
---|
| 53 | {
|
---|
| 54 | ULONG ulNumber;
|
---|
| 55 | ULONG ulPortBase;
|
---|
| 56 | ULONG ulPortSpan;
|
---|
[7542] | 57 | ULONG ulEcpPortBase;
|
---|
| 58 | ULONG ulEcpPortSpan;
|
---|
[7538] | 59 | } PARALLELPORTCONFIGURATION, *PPARALLELPORTCONFIGURATION;
|
---|
[7435] | 60 |
|
---|
[7542] | 61 | #define MAX_PARALLEL_PORTS_CONFIGURATION 3
|
---|
[21916] | 62 | static PARALLELPORTCONFIGURATION arrParallelPorts[MAX_PARALLEL_PORTS_CONFIGURATION] =
|
---|
[7542] | 63 | {
|
---|
| 64 | {1, 0x378, 8, 0x778, 3},
|
---|
| 65 | {2, 0x278, 8, 0x678, 3},
|
---|
| 66 | {3, 0x3bc, 8, 0x000, 0}
|
---|
[7538] | 67 | };
|
---|
[7435] | 68 |
|
---|
| 69 |
|
---|
[7298] | 70 | typedef struct _HMDEVPARPORTDATA
|
---|
| 71 | {
|
---|
| 72 | ULONG ulMagic;
|
---|
[21916] | 73 |
|
---|
[7298] | 74 | // Win32 Device Control Block
|
---|
[7301] | 75 | COMMCONFIG CommCfg;
|
---|
[21916] | 76 |
|
---|
[7538] | 77 | // hardware configuration block
|
---|
| 78 | PPARALLELPORTCONFIGURATION pHardwareConfiguration;
|
---|
[7298] | 79 | } HMDEVPARPORTDATA, *PHMDEVPARPORTDATA;
|
---|
| 80 |
|
---|
[7564] | 81 | //******************************************************************************
|
---|
| 82 | //******************************************************************************
|
---|
[7298] | 83 | static VOID *CreateDevData()
|
---|
| 84 | {
|
---|
[21916] | 85 | HFILE hfFileHandle = 0L;
|
---|
| 86 | UCHAR uchParms[2] = {0, RM_COMMAND_PHYS};
|
---|
| 87 | ULONG ulParmLen = 0;
|
---|
[8404] | 88 | UCHAR uchDataArea[MAX_ENUM_SIZE] = {0};
|
---|
[21916] | 89 | UCHAR uchDataArea2[MAX_RM_NODE_SIZE] = {0};
|
---|
| 90 | ULONG ulDataLen = 0;
|
---|
[8404] | 91 | int rc,portCount = 0;
|
---|
[21916] | 92 |
|
---|
[8404] | 93 | PRM_ENUMNODES_DATA enumData;
|
---|
| 94 | PNODEENTRY pNode;
|
---|
| 95 | RM_GETNODE_PARM inputData;
|
---|
| 96 | PRM_GETNODE_DATA poutputData;
|
---|
| 97 | PHMDEVPARPORTDATA pData;
|
---|
| 98 |
|
---|
| 99 | hfFileHandle = OSLibDosOpen("RESMGR$",
|
---|
| 100 | OSLIB_ACCESS_READWRITE |
|
---|
| 101 | OSLIB_ACCESS_SHAREDENYNONE);
|
---|
| 102 |
|
---|
| 103 | if (!hfFileHandle) {
|
---|
| 104 | dprintf(("HMDeviceParPortClass: Failed to open Resource Manager device %d\n", GetLastError()));
|
---|
[7298] | 105 | }
|
---|
[8404] | 106 | else
|
---|
[21916] | 107 | {
|
---|
[8404] | 108 | dprintf(("HMDeviceParPortClass: Succesfully opened Resource Manager"));
|
---|
| 109 |
|
---|
| 110 | ulParmLen = sizeof(uchParms); /* Length of input parameters */
|
---|
| 111 | ulDataLen = sizeof(uchDataArea); /* Length of data */
|
---|
| 112 |
|
---|
| 113 | rc = OSLibDosDevIOCtl(hfFileHandle, /* Handle to device */
|
---|
| 114 | CAT_RM,FUNC_RM_ENUM_NODES, uchParms, sizeof(uchParms),
|
---|
| 115 | &ulParmLen,
|
---|
[21916] | 116 | uchDataArea,
|
---|
| 117 | sizeof(uchDataArea),
|
---|
| 118 | &ulDataLen);
|
---|
| 119 |
|
---|
[8404] | 120 | if (rc)
|
---|
| 121 | {
|
---|
[21916] | 122 | dprintf(("HMDeviceParPortClass: Failed to get resource list (IOCTL)"));
|
---|
[8404] | 123 | goto resourceLoopEnd;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | enumData = (PRM_ENUMNODES_DATA)uchDataArea;
|
---|
[21916] | 127 |
|
---|
[8404] | 128 | inputData.RMHandle = enumData->NodeEntry[0].RMHandle;
|
---|
| 129 | inputData.Linaddr = (ULONG)&uchDataArea2[0];
|
---|
[21916] | 130 |
|
---|
[8404] | 131 | for (int i=0;i<enumData->NumEntries;i++)
|
---|
| 132 | {
|
---|
| 133 | ulParmLen = sizeof(inputData); /* Length of input parameters */
|
---|
| 134 | ulDataLen = sizeof(uchDataArea2); /* Length of data */
|
---|
[21916] | 135 |
|
---|
[8404] | 136 | rc = OSLibDosDevIOCtl(hfFileHandle, /* Handle to device */
|
---|
| 137 | CAT_RM,FUNC_RM_GET_NODEINFO,
|
---|
| 138 | &inputData, /* Input/Output parameter list */
|
---|
| 139 | sizeof(inputData), /* Maximum output parameter size */
|
---|
| 140 | &ulParmLen, /* Input: size of parameter list */
|
---|
| 141 | /* Output: size of parameters returned */
|
---|
| 142 | uchDataArea2, /* Input/Output data area */
|
---|
| 143 | sizeof(uchDataArea2), /* Maximum output data size */
|
---|
| 144 | &ulDataLen); /* Input: size of input data area */
|
---|
| 145 | /* Output: size of data returned */
|
---|
| 146 | if (rc)
|
---|
| 147 | {
|
---|
[21916] | 148 | dprintf(("HMDeviceParPortClass: Failed to get resource node (IOCTL)"));
|
---|
| 149 | break;
|
---|
[8404] | 150 | }
|
---|
| 151 | inputData.RMHandle = enumData->NodeEntry[i].RMHandle;
|
---|
| 152 | poutputData = (PRM_GETNODE_DATA) uchDataArea2;
|
---|
| 153 | // @@PF Ports always follow numbering i.e. LPT0,LPT1, etc so
|
---|
| 154 | // no sorting needed
|
---|
| 155 | if ( (poutputData->RMNode.pAdapterNode->AdaptDescriptName) &&
|
---|
| 156 | (lstrncmpiA(poutputData->RMNode.pAdapterNode->AdaptDescriptName,"PARALLEL",8) == 0) &&
|
---|
| 157 | (poutputData->RMNode.pResourceList->Resource[0].ResourceType == RS_TYPE_IO) )
|
---|
| 158 | {
|
---|
| 159 | if (!portCount) memset(arrParallelPorts,0,sizeof(arrParallelPorts));
|
---|
| 160 | arrParallelPorts[portCount].ulNumber = portCount;
|
---|
| 161 | arrParallelPorts[portCount].ulPortBase = poutputData->RMNode.pResourceList->Resource[0].IOResource.BaseIOPort;
|
---|
| 162 | arrParallelPorts[portCount].ulPortSpan = 8;
|
---|
| 163 | // @@PF Hack, but what to do no ECP info from Resource Manager!
|
---|
| 164 | if (arrParallelPorts[portCount].ulPortBase == 0x378)
|
---|
[21916] | 165 | {
|
---|
[8404] | 166 | arrParallelPorts[portCount].ulEcpPortBase = 0x778;
|
---|
| 167 | arrParallelPorts[portCount].ulEcpPortSpan = 3;
|
---|
| 168 | }
|
---|
[21916] | 169 | else
|
---|
[8404] | 170 | if (arrParallelPorts[portCount].ulPortBase == 0x278)
|
---|
[21916] | 171 | {
|
---|
[8404] | 172 | arrParallelPorts[portCount].ulEcpPortBase = 0x678;
|
---|
| 173 | arrParallelPorts[portCount].ulEcpPortSpan = 3;
|
---|
| 174 | }
|
---|
| 175 | else
|
---|
| 176 | arrParallelPorts[portCount].ulEcpPortBase = 0;
|
---|
| 177 |
|
---|
| 178 | arrParallelPorts[portCount].ulEcpPortSpan = 0;
|
---|
| 179 | dprintf(("HMDeviceParPortClass: Found and registered LPT%d with Base I/O: 0x%x",portCount,arrParallelPorts[portCount].ulPortBase));
|
---|
[21916] | 180 | portCount ++ ;
|
---|
[8404] | 181 | }
|
---|
| 182 | }
|
---|
| 183 | }
|
---|
| 184 | resourceLoopEnd:
|
---|
[21916] | 185 | OSLibDosClose(hfFileHandle);
|
---|
[8404] | 186 |
|
---|
| 187 | pData = new HMDEVPARPORTDATA();
|
---|
| 188 | if(NULL!=pData)
|
---|
| 189 | {
|
---|
| 190 | memset(pData,0,sizeof(HMDEVPARPORTDATA));
|
---|
| 191 | pData->ulMagic = MAGIC_PARPORT;
|
---|
| 192 | pData->CommCfg.dwSize = sizeof(COMMCONFIG);
|
---|
| 193 | pData->CommCfg.wVersion = 1;
|
---|
| 194 | pData->CommCfg.dwProviderSubType = PST_PARALLELPORT;
|
---|
| 195 | }
|
---|
[21916] | 196 |
|
---|
[8404] | 197 | return pData;
|
---|
[7298] | 198 | }
|
---|
[7564] | 199 | //******************************************************************************
|
---|
| 200 | //******************************************************************************
|
---|
[21916] | 201 | HMDeviceParPortClass::HMDeviceParPortClass(LPCSTR lpDeviceName) :
|
---|
[7542] | 202 | HMDeviceHandler(lpDeviceName)
|
---|
[7298] | 203 | {
|
---|
[7302] | 204 | dprintf(("HMDeviceParPortClass::HMDevParPortClass(%s)\n",
|
---|
| 205 | lpDeviceName));
|
---|
[21916] | 206 |
|
---|
[7482] | 207 | #ifndef DEVINFO_PRINTER
|
---|
| 208 | #define DEVINFO_PRINTER 0
|
---|
| 209 | #endif
|
---|
[21916] | 210 |
|
---|
[7482] | 211 | // first, we determine the number of parallel port devices available
|
---|
[21916] | 212 |
|
---|
[7542] | 213 | // PH 2001-12-04 Note:
|
---|
| 214 | // This call will not return any information about redirected LPT ports.
|
---|
| 215 | // We have a specific application requiring exactly this behaviour as it
|
---|
| 216 | // cannot talk to redirected LPTs anyway.
|
---|
| 217 | // For any change in this behaviour, we'd require a configuration switch.
|
---|
| 218 | bNumberOfParallelPorts = 0;
|
---|
| 219 | DWORD rc = OSLibDosDevConfig(&bNumberOfParallelPorts,
|
---|
[7482] | 220 | DEVINFO_PRINTER);
|
---|
| 221 | dprintf(("HMDeviceParPortClass: Parallel ports reported: %d\n",
|
---|
[7542] | 222 | bNumberOfParallelPorts));
|
---|
| 223 | if (0 == bNumberOfParallelPorts)
|
---|
[7482] | 224 | return;
|
---|
[21916] | 225 |
|
---|
[7298] | 226 | VOID *pData;
|
---|
[7482] | 227 | dprintf(("HMDeviceParPortClass: Registering LPTs with Handle Manager\n"));
|
---|
[21916] | 228 |
|
---|
[7298] | 229 | pData = CreateDevData();
|
---|
| 230 | if(pData!= NULL)
|
---|
| 231 | HMDeviceRegisterEx("LPT1", this, pData);
|
---|
[21916] | 232 |
|
---|
[7443] | 233 | // add symbolic links to the "real name" of the device
|
---|
[7542] | 234 | if (bNumberOfParallelPorts > 0)
|
---|
[7474] | 235 | {
|
---|
[7476] | 236 | // Note: \\.\LPTx: is invalid (NT4SP6)
|
---|
[7475] | 237 | PSZ pszLPT = strdup("\\\\.\\LPTx");
|
---|
[7538] | 238 | PSZ pszLPT2 = strdup("\\Device\\ParallelPort0");
|
---|
[7542] | 239 | for (char ch = '1'; ch <= '1' + (bNumberOfParallelPorts - 1); ch++)
|
---|
[7474] | 240 | {
|
---|
| 241 | pszLPT[7] = ch;
|
---|
[7538] | 242 | pszLPT2[20] = ch - 1; // \DeviceParallelPort0 -> LPT1
|
---|
[7474] | 243 | HandleNamesAddSymbolicLink(pszLPT, pszLPT+4);
|
---|
| 244 | HandleNamesAddSymbolicLink(pszLPT2, pszLPT+4);
|
---|
| 245 | }
|
---|
| 246 | free(pszLPT);
|
---|
| 247 | free(pszLPT2);
|
---|
[21916] | 248 |
|
---|
[7476] | 249 | // add "PRN" device
|
---|
| 250 | HandleNamesAddSymbolicLink("PRN", "LPT1");
|
---|
| 251 | HandleNamesAddSymbolicLink("PRN:", "LPT1");
|
---|
| 252 | HandleNamesAddSymbolicLink("\\\\.\\PRN", "LPT1");
|
---|
[7474] | 253 | }
|
---|
[7298] | 254 | }
|
---|
| 255 |
|
---|
| 256 | /*****************************************************************************
|
---|
| 257 | * Name : HMDeviceParPortClass::FindDevice
|
---|
| 258 | * Purpose : Checks if lpDeviceName belongs to this device class
|
---|
| 259 | * Parameters: LPCSTR lpClassDevName
|
---|
| 260 | * LPCSTR lpDeviceName
|
---|
| 261 | * int namelength
|
---|
| 262 | * Variables :
|
---|
| 263 | * Result : checks if name is COMx or COMx: (x=1..8)
|
---|
| 264 | * Remark :
|
---|
| 265 | * Status :
|
---|
| 266 | *
|
---|
| 267 | * Author : SvL
|
---|
| 268 | *****************************************************************************/
|
---|
| 269 | BOOL HMDeviceParPortClass::FindDevice(LPCSTR lpClassDevName, LPCSTR lpDeviceName, int namelength)
|
---|
| 270 | {
|
---|
[7542] | 271 | // Don't accept any name if no parallel ports have been detected
|
---|
| 272 | if (bNumberOfParallelPorts == 0)
|
---|
| 273 | return FALSE;
|
---|
[21916] | 274 |
|
---|
[7474] | 275 | // can be both, "LPT1" and "LPT1:"
|
---|
[7542] | 276 | if(namelength > 5)
|
---|
| 277 | return FALSE; //can't be lpt name
|
---|
[7298] | 278 |
|
---|
[7542] | 279 | //first 3 letters 'LPT'?
|
---|
| 280 | if(lstrncmpiA(lpDeviceName, lpClassDevName, 3) != 0)
|
---|
| 281 | return FALSE;
|
---|
[7298] | 282 |
|
---|
[7542] | 283 | if(namelength == 5 && lpDeviceName[4] != ':')
|
---|
| 284 | return FALSE;
|
---|
[21916] | 285 |
|
---|
[7542] | 286 | // can support up tp LPT9
|
---|
| 287 | if ( (lpDeviceName[3] >= '1') &&
|
---|
| 288 | (lpDeviceName[3] <= '1' + bNumberOfParallelPorts) )
|
---|
| 289 | {
|
---|
| 290 | return TRUE;
|
---|
| 291 | }
|
---|
| 292 |
|
---|
| 293 | return FALSE;
|
---|
[7298] | 294 | }
|
---|
[7564] | 295 | //******************************************************************************
|
---|
| 296 | //******************************************************************************
|
---|
[7549] | 297 | DWORD HMDeviceParPortClass::CreateFile(LPCSTR lpFileName,
|
---|
[7302] | 298 | PHMHANDLEDATA pHMHandleData,
|
---|
| 299 | PVOID lpSecurityAttributes,
|
---|
| 300 | PHMHANDLEDATA pHMHandleDataTemplate)
|
---|
[7298] | 301 | {
|
---|
[7302] | 302 | dprintf(("HMDeviceParPortClass::CreateFile(%s,%08xh,%08xh,%08xh)\n",
|
---|
| 303 | lpFileName,
|
---|
| 304 | pHMHandleData,
|
---|
| 305 | lpSecurityAttributes,
|
---|
| 306 | pHMHandleDataTemplate));
|
---|
[21916] | 307 |
|
---|
[7542] | 308 | char lptname[6];
|
---|
[7298] | 309 |
|
---|
| 310 | dprintf(("HMDeviceParPortClass: Parallel port %s open request\n", lpFileName));
|
---|
[21916] | 311 |
|
---|
[7542] | 312 | // Don't accept any name if no parallel ports have been detected
|
---|
| 313 | if (bNumberOfParallelPorts == 0)
|
---|
| 314 | {
|
---|
| 315 | return ERROR_DEV_NOT_EXIST;
|
---|
| 316 | }
|
---|
[21916] | 317 |
|
---|
[7474] | 318 | strcpy(lptname, lpFileName);
|
---|
| 319 | lptname[4] = 0; //get rid of : (if present) (eg LPT1:)
|
---|
[7298] | 320 |
|
---|
| 321 | //AH: TODO parse Win32 security handles
|
---|
| 322 | ULONG oldmode = SetErrorMode(SEM_FAILCRITICALERRORS);
|
---|
[7474] | 323 | pHMHandleData->hHMHandle = OSLibDosOpen(lptname,
|
---|
[7298] | 324 | OSLIB_ACCESS_READWRITE |
|
---|
| 325 | OSLIB_ACCESS_SHAREDENYREAD |
|
---|
| 326 | OSLIB_ACCESS_SHAREDENYWRITE);
|
---|
| 327 | SetErrorMode(oldmode);
|
---|
[21916] | 328 |
|
---|
[7474] | 329 | // check if handle could be opened properly
|
---|
| 330 | if (0 == pHMHandleData->hHMHandle)
|
---|
| 331 | {
|
---|
| 332 | return ERROR_ACCESS_DENIED; // signal failure
|
---|
| 333 | }
|
---|
[7538] | 334 | else
|
---|
[7298] | 335 | {
|
---|
| 336 | ULONG ulLen;
|
---|
| 337 | APIRET rc;
|
---|
| 338 | pHMHandleData->lpHandlerData = new HMDEVPARPORTDATA();
|
---|
[21916] | 339 |
|
---|
[7298] | 340 | // Init The handle instance with the default default device config
|
---|
| 341 | memcpy( pHMHandleData->lpHandlerData,
|
---|
| 342 | pHMHandleData->lpDeviceData,
|
---|
| 343 | sizeof(HMDEVPARPORTDATA));
|
---|
[21916] | 344 |
|
---|
[7538] | 345 | // determine which port was opened
|
---|
| 346 | ULONG ulPortNo = lptname[3] - '1';
|
---|
[21916] | 347 |
|
---|
[7538] | 348 | // safety check (device no 0..8 -> LPT1..9)
|
---|
[7542] | 349 | if (ulPortNo > MAX_PARALLEL_PORTS_CONFIGURATION)
|
---|
[7298] | 350 | {
|
---|
[7542] | 351 | HMDeviceParPortClass::CloseHandle(pHMHandleData);
|
---|
[7538] | 352 | return ERROR_DEV_NOT_EXIST;
|
---|
[7298] | 353 | }
|
---|
[21916] | 354 |
|
---|
[7538] | 355 | // and save the hardware information
|
---|
| 356 | PHMDEVPARPORTDATA pPPD = (PHMDEVPARPORTDATA)pHMHandleData->lpHandlerData;
|
---|
| 357 | pPPD->pHardwareConfiguration = &arrParallelPorts[ulPortNo];
|
---|
[21916] | 358 |
|
---|
[7538] | 359 | return NO_ERROR;
|
---|
[7298] | 360 | }
|
---|
| 361 | }
|
---|
| 362 |
|
---|
[7564] | 363 | /*****************************************************************************
|
---|
| 364 | * Name : DWORD HMDeviceParPortClass::GetFileType
|
---|
| 365 | * Purpose : determine the handle type
|
---|
| 366 | * Parameters: PHMHANDLEDATA pHMHandleData
|
---|
| 367 | * Variables :
|
---|
| 368 | * Result : API returncode
|
---|
| 369 | * Remark :
|
---|
| 370 | * Status :
|
---|
| 371 | *
|
---|
| 372 | * Author : SvL
|
---|
| 373 | *****************************************************************************/
|
---|
[7298] | 374 |
|
---|
[7564] | 375 | DWORD HMDeviceParPortClass::GetFileType(PHMHANDLEDATA pHMHandleData)
|
---|
| 376 | {
|
---|
| 377 | dprintf(("KERNEL32: HMDeviceParPortClass::GetFileType %s(%08x)\n",
|
---|
| 378 | lpHMDeviceName, pHMHandleData));
|
---|
| 379 |
|
---|
| 380 | return FILE_TYPE_PIPE; //this is what NT4 returns
|
---|
| 381 | }
|
---|
| 382 | //******************************************************************************
|
---|
| 383 | /* this is a handler method for calls to CloseHandle() */
|
---|
| 384 | //******************************************************************************
|
---|
[7298] | 385 | BOOL HMDeviceParPortClass::CloseHandle(PHMHANDLEDATA pHMHandleData)
|
---|
| 386 | {
|
---|
[7302] | 387 | dprintf(("HMDeviceParPortClass: Parallel port close request(%08xh)\n",
|
---|
[7538] | 388 | pHMHandleData));
|
---|
[21916] | 389 |
|
---|
| 390 | delete (PHMDEVPARPORTDATA)pHMHandleData->lpHandlerData;
|
---|
[7298] | 391 | return OSLibDosClose(pHMHandleData->hHMHandle);
|
---|
| 392 | }
|
---|
| 393 |
|
---|
| 394 |
|
---|
| 395 | /*****************************************************************************
|
---|
| 396 | * Name : BOOL HMDeviceParPortClass::WriteFile
|
---|
| 397 | * Purpose : write data to handle / device
|
---|
| 398 | * Parameters: PHMHANDLEDATA pHMHandleData,
|
---|
| 399 | * LPCVOID lpBuffer,
|
---|
| 400 | * DWORD nNumberOfBytesToWrite,
|
---|
| 401 | * LPDWORD lpNumberOfBytesWritten,
|
---|
| 402 | * LPOVERLAPPED lpOverlapped
|
---|
| 403 | * Variables :
|
---|
| 404 | * Result : Boolean
|
---|
| 405 | * Remark :
|
---|
| 406 | * Status :
|
---|
| 407 | *
|
---|
| 408 | * Author : SvL
|
---|
| 409 | *****************************************************************************/
|
---|
| 410 |
|
---|
| 411 | BOOL HMDeviceParPortClass::WriteFile(PHMHANDLEDATA pHMHandleData,
|
---|
[7302] | 412 | LPCVOID lpBuffer,
|
---|
| 413 | DWORD nNumberOfBytesToWrite,
|
---|
| 414 | LPDWORD lpNumberOfBytesWritten,
|
---|
[7549] | 415 | LPOVERLAPPED lpOverlapped,
|
---|
| 416 | LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
|
---|
[7298] | 417 | {
|
---|
| 418 | dprintf(("KERNEL32:HMDeviceParPortClass::WriteFile %s(%08x,%08x,%08x,%08x,%08x)",
|
---|
| 419 | lpHMDeviceName,
|
---|
| 420 | pHMHandleData->hHMHandle,
|
---|
| 421 | lpBuffer,
|
---|
| 422 | nNumberOfBytesToWrite,
|
---|
| 423 | lpNumberOfBytesWritten,
|
---|
| 424 | lpOverlapped));
|
---|
| 425 |
|
---|
| 426 | BOOL ret;
|
---|
| 427 | ULONG ulBytesWritten;
|
---|
| 428 |
|
---|
| 429 | if((pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && !lpOverlapped) {
|
---|
| 430 | dprintf(("FILE_FLAG_OVERLAPPED flag set, but lpOverlapped NULL!!"));
|
---|
| 431 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
| 432 | return FALSE;
|
---|
| 433 | }
|
---|
| 434 | if(!(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && lpOverlapped) {
|
---|
| 435 | dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
|
---|
| 436 | }
|
---|
[7550] | 437 | if(lpCompletionRoutine) {
|
---|
| 438 | dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
|
---|
| 439 | }
|
---|
[7298] | 440 |
|
---|
| 441 | ret = OSLibDosWrite(pHMHandleData->hHMHandle, (LPVOID)lpBuffer, nNumberOfBytesToWrite,
|
---|
| 442 | &ulBytesWritten);
|
---|
| 443 |
|
---|
| 444 | if(lpNumberOfBytesWritten) {
|
---|
| 445 | *lpNumberOfBytesWritten = (ret) ? ulBytesWritten : 0;
|
---|
| 446 | }
|
---|
| 447 | if(ret == FALSE) {
|
---|
| 448 | dprintf(("ERROR: WriteFile failed with rc %d", GetLastError()));
|
---|
| 449 | }
|
---|
| 450 |
|
---|
| 451 | return ret;
|
---|
| 452 | }
|
---|
| 453 |
|
---|
| 454 | /*****************************************************************************
|
---|
| 455 | * Name : BOOL HMDeviceParPortClass::ReadFile
|
---|
| 456 | * Purpose : read data from handle / device
|
---|
| 457 | * Parameters: PHMHANDLEDATA pHMHandleData,
|
---|
| 458 | * LPCVOID lpBuffer,
|
---|
| 459 | * DWORD nNumberOfBytesToRead,
|
---|
| 460 | * LPDWORD lpNumberOfBytesRead,
|
---|
| 461 | * LPOVERLAPPED lpOverlapped
|
---|
| 462 | * Variables :
|
---|
| 463 | * Result : Boolean
|
---|
| 464 | * Remark :
|
---|
| 465 | * Status :
|
---|
| 466 | *
|
---|
| 467 | * Author : SvL
|
---|
| 468 | *****************************************************************************/
|
---|
| 469 |
|
---|
| 470 | BOOL HMDeviceParPortClass::ReadFile(PHMHANDLEDATA pHMHandleData,
|
---|
[7302] | 471 | LPCVOID lpBuffer,
|
---|
| 472 | DWORD nNumberOfBytesToRead,
|
---|
| 473 | LPDWORD lpNumberOfBytesRead,
|
---|
[7549] | 474 | LPOVERLAPPED lpOverlapped,
|
---|
| 475 | LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
|
---|
[7298] | 476 | {
|
---|
| 477 | dprintf(("KERNEL32:HMDeviceParPortClass::ReadFile %s(%08x,%08x,%08x,%08x,%08x)",
|
---|
| 478 | lpHMDeviceName,
|
---|
| 479 | pHMHandleData->hHMHandle,
|
---|
| 480 | lpBuffer,
|
---|
| 481 | nNumberOfBytesToRead,
|
---|
| 482 | lpNumberOfBytesRead,
|
---|
| 483 | lpOverlapped));
|
---|
| 484 |
|
---|
| 485 | BOOL ret;
|
---|
| 486 | ULONG ulBytesRead;
|
---|
| 487 |
|
---|
| 488 | if((pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && !lpOverlapped) {
|
---|
| 489 | dprintf(("FILE_FLAG_OVERLAPPED flag set, but lpOverlapped NULL!!"));
|
---|
| 490 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
| 491 | return FALSE;
|
---|
| 492 | }
|
---|
| 493 | if(!(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && lpOverlapped) {
|
---|
| 494 | dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
|
---|
| 495 | }
|
---|
[7550] | 496 | if(lpCompletionRoutine) {
|
---|
| 497 | dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
|
---|
| 498 | }
|
---|
[7298] | 499 |
|
---|
| 500 | ret = OSLibDosRead(pHMHandleData->hHMHandle, (LPVOID)lpBuffer, nNumberOfBytesToRead,
|
---|
| 501 | &ulBytesRead);
|
---|
| 502 |
|
---|
| 503 | if(lpNumberOfBytesRead) {
|
---|
| 504 | *lpNumberOfBytesRead = (ret) ? ulBytesRead : 0;
|
---|
| 505 | }
|
---|
| 506 | if(ret == FALSE) {
|
---|
| 507 | dprintf(("ERROR: ReadFile failed with rc %d", GetLastError()));
|
---|
| 508 | }
|
---|
| 509 | return ret;
|
---|
| 510 | }
|
---|
[7564] | 511 | //******************************************************************************
|
---|
| 512 | //******************************************************************************
|
---|
[21916] | 513 | BOOL HMDeviceParPortClass::DeviceIoControl(PHMHANDLEDATA pHMHandleData,
|
---|
[7302] | 514 | DWORD dwIoControlCode,
|
---|
[21916] | 515 | LPVOID lpInBuffer,
|
---|
[7302] | 516 | DWORD nInBufferSize,
|
---|
[21916] | 517 | LPVOID lpOutBuffer,
|
---|
[7302] | 518 | DWORD nOutBufferSize,
|
---|
[21916] | 519 | LPDWORD lpBytesReturned,
|
---|
[7302] | 520 | LPOVERLAPPED lpOverlapped)
|
---|
[7301] | 521 | {
|
---|
| 522 | #ifdef DEBUG
|
---|
[21916] | 523 | const char *msg = NULL;
|
---|
[7301] | 524 |
|
---|
| 525 | switch(dwIoControlCode)
|
---|
| 526 | {
|
---|
[7435] | 527 | case IOCTL_INTERNAL_GET_PARALLEL_PORT_INFO:
|
---|
| 528 | msg = "IOCTL_INTERNAL_GET_PARALLEL_PORT_INFO";
|
---|
[7301] | 529 | break;
|
---|
[21916] | 530 |
|
---|
[7435] | 531 | case IOCTL_INTERNAL_GET_PARALLEL_PNP_INFO:
|
---|
| 532 | msg = "IOCTL_INTERNAL_GET_PARALLEL_PNP_INFO";
|
---|
| 533 | break;
|
---|
[7301] | 534 | }
|
---|
[21916] | 535 |
|
---|
[7301] | 536 | if(msg) {
|
---|
| 537 | dprintf(("HMDeviceParPortClass::DeviceIoControl %s %x %d %x %d %x %x", msg, lpInBuffer, nInBufferSize,
|
---|
| 538 | lpOutBuffer, nOutBufferSize, lpBytesReturned, lpOverlapped));
|
---|
| 539 | }
|
---|
| 540 | #endif
|
---|
| 541 |
|
---|
| 542 | switch(dwIoControlCode)
|
---|
| 543 | {
|
---|
[7435] | 544 | case IOCTL_INTERNAL_GET_PARALLEL_PORT_INFO:
|
---|
| 545 | {
|
---|
| 546 | PPARALLEL_PORT_INFORMATION pPPI = (PPARALLEL_PORT_INFORMATION)lpOutBuffer;
|
---|
[21916] | 547 |
|
---|
| 548 | if(nOutBufferSize < sizeof(PARALLEL_PORT_INFORMATION) || !pPPI)
|
---|
[7435] | 549 | {
|
---|
| 550 | SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
---|
| 551 | return FALSE;
|
---|
| 552 | }
|
---|
[21916] | 553 |
|
---|
[7435] | 554 | if(lpBytesReturned)
|
---|
| 555 | *lpBytesReturned = sizeof(PARALLEL_PORT_INFORMATION);
|
---|
[21916] | 556 |
|
---|
[7435] | 557 | // fill in the data values
|
---|
[7538] | 558 | PHMDEVPARPORTDATA pPPD = (PHMDEVPARPORTDATA)pHMHandleData->lpHandlerData;
|
---|
[21916] | 559 |
|
---|
[7538] | 560 | // @@@PH
|
---|
[7435] | 561 | // Specifies the bus relative base I/O address of the parallel port registers.
|
---|
[7538] | 562 | pPPI->OriginalController.LowPart = pPPD->pHardwareConfiguration->ulPortBase;
|
---|
| 563 | pPPI->OriginalController.HighPart = 0;
|
---|
[21916] | 564 |
|
---|
[7435] | 565 | // Pointer to the system-mapped base I/O location of the parallel port registers.
|
---|
[7538] | 566 | pPPI->Controller = NULL;
|
---|
[21916] | 567 |
|
---|
[7435] | 568 | // Specifies the size, in bytes, of the I/O space, allocated to the parallel port.
|
---|
[7538] | 569 | pPPI->SpanOfController = pPPD->pHardwareConfiguration->ulPortSpan;
|
---|
[21916] | 570 |
|
---|
[7435] | 571 | // Pointer to a callback routine that a kernel-mode driver can use to try to allocate the parallel port.
|
---|
| 572 | pPPI->TryAllocatePort = NULL;
|
---|
[21916] | 573 |
|
---|
[7435] | 574 | // Pointer to a callback routine that a kernel-mode driver can use to free the parallel port.
|
---|
| 575 | pPPI->FreePort = NULL;
|
---|
[21916] | 576 |
|
---|
[7435] | 577 | // 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.
|
---|
| 578 | pPPI->QueryNumWaiters = NULL;
|
---|
[21916] | 579 |
|
---|
[7435] | 580 | // Pointer to the device extension of parallel port.
|
---|
| 581 | pPPI->Context = NULL;
|
---|
[7301] | 582 |
|
---|
[7435] | 583 | return TRUE;
|
---|
| 584 | }
|
---|
[21916] | 585 |
|
---|
| 586 |
|
---|
[7435] | 587 | case IOCTL_INTERNAL_GET_PARALLEL_PNP_INFO:
|
---|
| 588 | {
|
---|
| 589 | PPARALLEL_PNP_INFORMATION pPPI = (PPARALLEL_PNP_INFORMATION)lpOutBuffer;
|
---|
[21916] | 590 |
|
---|
[7435] | 591 | if(nOutBufferSize < sizeof(PARALLEL_PNP_INFORMATION) || !pPPI)
|
---|
| 592 | {
|
---|
| 593 | SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
---|
| 594 | return FALSE;
|
---|
| 595 | }
|
---|
[21916] | 596 |
|
---|
[7435] | 597 | if(lpBytesReturned)
|
---|
| 598 | *lpBytesReturned = sizeof(PARALLEL_PNP_INFORMATION);
|
---|
[21916] | 599 |
|
---|
[7435] | 600 | // fill in the data values
|
---|
[7538] | 601 | PHMDEVPARPORTDATA pPPD = (PHMDEVPARPORTDATA)pHMHandleData->lpHandlerData;
|
---|
[21916] | 602 |
|
---|
[7538] | 603 | // @@@PH
|
---|
[21916] | 604 | // Specifies the base physical address that the system-supplied
|
---|
| 605 | // function driver for parallel ports uses to control the ECP
|
---|
[7538] | 606 | // operation of the parallel port.
|
---|
[7542] | 607 | pPPI->OriginalEcpController.LowPart = pPPD->pHardwareConfiguration->ulEcpPortBase;
|
---|
[7435] | 608 | pPPI->OriginalEcpController.HighPart = 0;
|
---|
[21916] | 609 |
|
---|
| 610 | // Pointer to the I/O port resource that is used to control the
|
---|
[7538] | 611 | // port in ECP mode.
|
---|
| 612 | pPPI->EcpController = NULL;
|
---|
[21916] | 613 |
|
---|
[7435] | 614 | // Specifies the size, in bytes, of the I/O port resource.
|
---|
[7542] | 615 | pPPI->SpanOfEcpController = pPPD->pHardwareConfiguration->ulEcpPortSpan;
|
---|
[21916] | 616 |
|
---|
[7435] | 617 | // Not used.
|
---|
| 618 | pPPI->PortNumber = 0;
|
---|
[21916] | 619 |
|
---|
[7435] | 620 | // Specifies the hardware capabilities of the parallel port. The following capabilities can be set using a bitwise OR of the following constants:
|
---|
| 621 | pPPI->HardwareCapabilities = 0;
|
---|
| 622 | // PPT_1284_3_PRESENT
|
---|
| 623 | // PPT_BYTE_PRESENT
|
---|
| 624 | // PPT_ECP_PRESENT
|
---|
| 625 | // PPT_EPP_32_PRESENT
|
---|
| 626 | // PPT_EPP_PRESENT
|
---|
| 627 | // PT_NO_HARDWARE_PRESENT
|
---|
[21916] | 628 |
|
---|
[7435] | 629 | // Pointer to a callback routine that a kernel-mode driver can use to change the operating mode of the parallel port.
|
---|
| 630 | pPPI->TrySetChipMode = 0;
|
---|
[21916] | 631 |
|
---|
[7435] | 632 | // Pointer to a callback routine that a kernel-mode driver can use to clear the operating mode of the parallel port.
|
---|
| 633 | pPPI->ClearChipMode = 0;
|
---|
[21916] | 634 |
|
---|
[7435] | 635 | // 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.
|
---|
| 636 | pPPI->FifoDepth = 0;
|
---|
[21916] | 637 |
|
---|
[7435] | 638 | // Specifies the FIFO word size, in bits, which is the number of bits handled in parallel.
|
---|
| 639 | pPPI->FifoWidth = 0;
|
---|
[21916] | 640 |
|
---|
[7435] | 641 | // Not used.
|
---|
| 642 | pPPI->EppControllerPhysicalAddress.LowPart = 0;
|
---|
| 643 | pPPI->EppControllerPhysicalAddress.HighPart = 0;
|
---|
[21916] | 644 |
|
---|
[7435] | 645 | // Not used.
|
---|
| 646 | pPPI->SpanOfEppController = 0;
|
---|
[21916] | 647 |
|
---|
[7435] | 648 | // 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
|
---|
| 649 | // parallel port. In Windows 2000, from zero to four devices can be simultaneously connected to a parallel port.
|
---|
| 650 | pPPI->Ieee1284_3DeviceCount = 0;
|
---|
[21916] | 651 |
|
---|
[7435] | 652 | // Pointer to a callback routine that a kernel-mode driver can use to try to select an IEEE 1284.3 device.
|
---|
| 653 | pPPI->TrySelectDevice = 0;
|
---|
[21916] | 654 |
|
---|
[7435] | 655 | // Pointer to a callback routine that a kernel-mode driver can use to deselect an IEEE 1284.3 device.
|
---|
| 656 | pPPI->DeselectDevice = 0;
|
---|
[21916] | 657 |
|
---|
[7435] | 658 | // Pointer to the device extension of a parallel port's function device object (FDO).
|
---|
| 659 | pPPI->Context = 0;
|
---|
[21916] | 660 |
|
---|
[7435] | 661 | // The current operating mode of the parallel port.
|
---|
| 662 | pPPI->CurrentMode = 0;
|
---|
[21916] | 663 |
|
---|
[7435] | 664 | // The symbolic link name of the parallel port.
|
---|
| 665 | pPPI->PortName = 0;
|
---|
[21916] | 666 |
|
---|
[7435] | 667 | return TRUE;
|
---|
| 668 | }
|
---|
[7301] | 669 | }
|
---|
| 670 | dprintf(("HMDeviceParPortClass::DeviceIoControl: unimplemented dwIoControlCode=%08lx\n", dwIoControlCode));
|
---|
| 671 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
---|
| 672 | return FALSE;
|
---|
| 673 | }
|
---|
[7564] | 674 | //******************************************************************************
|
---|
| 675 | //******************************************************************************
|
---|
[7301] | 676 |
|
---|
| 677 |
|
---|