OpenCBM
libcommon/openclose.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version
5  * 2 of the License, or (at your option) any later version.
6  *
7  * Copyright 2004, 2007 Spiro Trikaliotis
8  *
9  */
10 
19 #include <wdm.h>
20 #include "cbm_driver.h"
21 #include "iec.h"
22 
46 NTSTATUS
47 cbm_createopenclose(IN PDEVICE_OBJECT Fdo, IN PIRP Irp)
48 {
49  PIO_STACK_LOCATION irpSp;
50  PDEVICE_EXTENSION pdx;
51  NTSTATUS ntStatus;
52 
53  FUNC_ENTER();
54 
55  // get the device extension
56 
57  pdx = Fdo->DeviceExtension;
58 
59  DBG_IRPPATH_PROCESS("create/open");
60 
61  // get the current IRP stack location
62 
63  irpSp = IoGetCurrentIrpStackLocation(Irp);
64 
65 
66  if (irpSp->MajorFunction == IRP_MJ_CREATE
67  && irpSp->Parameters.Create.Options & FILE_DIRECTORY_FILE)
68  {
69  // The caller wants to open a directory.
70  // As we do not support directories, fail that request!
71 
72  ntStatus = STATUS_NOT_A_DIRECTORY;
73  DBG_IRPPATH_COMPLETE("create/open");
74  QueueCompleteIrp(NULL, Irp, ntStatus, 0);
75  }
76  else
77  {
78  switch (irpSp->MajorFunction)
79  {
80  case IRP_MJ_CREATE:
82  break;
83 
84  case IRP_MJ_CLOSE:
86  break;
87 
88  default:
89  DBG_ERROR((DBG_PREFIX "UNKNOWN IRP->MAJORFUNCTION: %08x",
90  irpSp->MajorFunction));
91  break;
92  }
93 
94  // queue the IRP to be processed
95 
96  ntStatus = QueueStartPacket(&pdx->IrpQueue, Irp, FALSE, Fdo);
97  }
98 
99  FUNC_LEAVE_NTSTATUS(ntStatus);
100 }
101 
116 NTSTATUS
117 cbm_execute_createopen(IN PDEVICE_EXTENSION Pdx, IN PIRP Irp)
118 {
119  NTSTATUS ntStatus;
120 
121  FUNC_ENTER();
122 
123  DBG_ASSERT(Pdx != NULL);
124 
126 
127  DBG_IRPPATH_EXECUTE("create/open");
128 
129  if (Pdx->ParallelPortLock)
130  {
131  // as we keep the parallel port locked all the time,
132  // do not lock it now.
133  ntStatus = STATUS_SUCCESS;
134 
135  // \todo: try workaround: As the machine might have been
136  // suspended or hibernated without knowing it, test if
137  // all lines are exactly as expected. If not, lock und unlock
138  // the parallel port again
139 
141  {
142  DBG_PRINT((DBG_PREFIX "The cable state was wrong, try an UNLOCK/LOCK pair with a RESET to put cable in a known state"));
143 
144  cbm_unlock_parport(Pdx);
145  ntStatus = cbm_lock_parport(Pdx);
146  cbmiec_reset(Pdx);
147  }
148  }
149  else
150  {
151  // Try to allocate the parallel port
152 
153  ntStatus = cbm_lock_parport(Pdx);
154  }
155 
156  // We're done, complete the IRP
157 
158  DBG_IRPPATH_COMPLETE("create/open");
159 
160  QueueCompleteIrp(&Pdx->IrpQueue, Irp, ntStatus, 0);
161 
162  FUNC_LEAVE_NTSTATUS(ntStatus);
163 }
164 
179 NTSTATUS
180 cbm_execute_close(IN PDEVICE_EXTENSION Pdx, IN PIRP Irp)
181 {
182  NTSTATUS ntStatus;
183 
184  FUNC_ENTER();
185 
186  DBG_ASSERT(Pdx != NULL);
187 
189 
190  DBG_IRPPATH_PROCESS("close");
191 
192  if (Pdx->ParallelPortLock)
193  {
194  // release the bus (to be able to share it with other controllers)
195 
196  if (!Pdx->DoNotReleaseBus)
197  {
198  cbmiec_release_bus(Pdx);
199  }
200 
201  // as we keep the parallel port locked all the time,
202  // do not unlock it now.
203 
204  ntStatus = STATUS_SUCCESS;
205  }
206  else
207  {
208  // Unlock the parallel port
209 
210  ntStatus = cbm_unlock_parport(Pdx);
211  }
212 
213 
214  // Now, complete the IRP
215 
216  DBG_IRPPATH_COMPLETE("close");
217  QueueCompleteIrp(&Pdx->IrpQueue, Irp, ntStatus, 0);
218 
219  FUNC_LEAVE_NTSTATUS(ntStatus);
220 }
#define DBG_IRPPATH_PROCESS(_Where_)
Debug IRPPATH: Processing of the IRP.
Definition: debug.h:571
#define PERF_EVENT_CLOSE_QUEUE()
Definition: cbm_driver.h:55
NTSTATUS cbm_unlock_parport(IN PDEVICE_EXTENSION Pdx)
Unlock the parallel port for the driver.
Definition: lockunlock.c:128
#define PERF_EVENT_OPEN_EXECUTE()
Definition: cbm_driver.h:53
NTSTATUS cbm_execute_close(IN PDEVICE_EXTENSION Pdx, IN PIRP Irp)
Execute IRPs containing the IRP_MJ_CLOSE I/O function code.
NTSTATUS cbm_execute_createopen(IN PDEVICE_EXTENSION Pdx, IN PIRP Irp)
Execute IRPs containing the IRP_MJ_CREATEOPEN I/O function code.
Definitions for the libiec library.
NTSTATUS QueueStartPacket(PQUEUE Queue, PIRP Irp, BOOLEAN FastStart, PDEVICE_OBJECT Fdo)
Insert an IRP into a QUEUE object.
Definition: queue.c:467
#define PERF_EVENT_OPEN_QUEUE()
Definition: cbm_driver.h:51
#define PERF_EVENT_CLOSE_EXECUTE()
Definition: cbm_driver.h:57
VOID cbmiec_release_bus(IN PDEVICE_EXTENSION Pdx)
Release the IEC bus.
Definition: releasebus.c:38
#define DBG_ASSERT(_xxx)
Definition: debug.h:401
#define DBG_ERROR(_xxx)
Definition: debug.h:397
#define DBG_IRPPATH_COMPLETE(_Where_)
Debug IRPPATH: Completing of the IRP.
Definition: debug.h:574
NTSTATUS cbm_lock_parport(IN PDEVICE_EXTENSION Pdx)
Lock the parallel port for the driver.
Definition: lockunlock.c:39
NTSTATUS cbmiec_reset(IN PDEVICE_EXTENSION Pdx)
Send a RESET to the IEC bus.
Definition: reset.c:103
#define FUNC_ENTER()
Definition: debug.h:347
Definitions for the opencbm driver.
BOOLEAN cbmiec_is_cable_state_wrong(PDEVICE_EXTENSION Pdx)
@@@
Definition: checkcable.c:511
#define DBG_IRPPATH_EXECUTE(_Where_)
Debug IRPPATH: Executing of the IRP.
Definition: debug.h:580
#define DBG_PREFIX
Definition: debug.h:320
NTSTATUS QueueCompleteIrp(PQUEUE Queue, PIRP Irp, NTSTATUS StatusCode, ULONG_PTR Information)
Complete an IRP which is on a QUEUE.
Definition: queue.c:756
NTSTATUS cbm_createopenclose(IN PDEVICE_OBJECT Fdo, IN PIRP Irp)
Services IRPs containing the IRP_MJ_CREATE or IRP_MJ_CLOSE I/O function code.
#define DBG_PRINT(_xxx)
Definition: debug.h:403