1 |
asvitkine |
1.1 |
/* |
2 |
|
|
* b2ether driver -- derived from DDK packet driver sample |
3 |
|
|
* |
4 |
|
|
* Basilisk II (C) 1997-1999 Christian Bauer |
5 |
|
|
* |
6 |
|
|
* Windows platform specific code copyright (C) Lauri Pesonen |
7 |
|
|
* |
8 |
|
|
* This program is free software; you can redistribute it and/or modify |
9 |
|
|
* it under the terms of the GNU General Public License as published by |
10 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
11 |
|
|
* (at your option) any later version. |
12 |
|
|
* |
13 |
|
|
* This program is distributed in the hope that it will be useful, |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
* GNU General Public License for more details. |
17 |
|
|
* |
18 |
|
|
* You should have received a copy of the GNU General Public License |
19 |
|
|
* along with this program; if not, write to the Free Software |
20 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
|
|
*/ |
22 |
|
|
|
23 |
|
|
#include "ntddk.h" |
24 |
|
|
#include "ndis.h" |
25 |
|
|
#include "b2ether.h" |
26 |
|
|
|
27 |
|
|
NTSTATUS PacketOpen( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) |
28 |
|
|
{ |
29 |
|
|
POPEN_INSTANCE open; |
30 |
|
|
NTSTATUS status = STATUS_SUCCESS; |
31 |
|
|
|
32 |
|
|
// DebugPrint(("OpenAdapter\n")); |
33 |
|
|
|
34 |
|
|
if(DeviceObject == Globals.ControlDeviceObject) { |
35 |
|
|
Irp->IoStatus.Status = status; |
36 |
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT); |
37 |
|
|
return status; |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
open = DeviceObject->DeviceExtension; |
41 |
|
|
|
42 |
|
|
// DebugPrint(("AdapterName :%ws\n", open->AdapterName.Buffer)); |
43 |
|
|
|
44 |
|
|
IoIncrement(open); |
45 |
|
|
|
46 |
|
|
if(!open->Bound) { |
47 |
|
|
status = STATUS_DEVICE_NOT_READY; |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
Irp->IoStatus.Information = 0; |
51 |
|
|
Irp->IoStatus.Status = status; |
52 |
|
|
IoCompleteRequest (Irp, IO_NO_INCREMENT); |
53 |
|
|
IoDecrement(open); |
54 |
|
|
return status; |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
|
58 |
|
|
NTSTATUS PacketClose( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) |
59 |
|
|
{ |
60 |
|
|
POPEN_INSTANCE open; |
61 |
|
|
NTSTATUS status = STATUS_SUCCESS; |
62 |
|
|
|
63 |
|
|
// DebugPrint(("CloseAdapter \n")); |
64 |
|
|
|
65 |
|
|
if(DeviceObject == Globals.ControlDeviceObject) { |
66 |
|
|
Irp->IoStatus.Status = status; |
67 |
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT); |
68 |
|
|
return status; |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
open = DeviceObject->DeviceExtension; |
72 |
|
|
IoIncrement(open); |
73 |
|
|
Irp->IoStatus.Information = 0; |
74 |
|
|
Irp->IoStatus.Status = status; |
75 |
|
|
IoCompleteRequest (Irp, IO_NO_INCREMENT); |
76 |
|
|
IoDecrement(open); |
77 |
|
|
return status; |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
|
81 |
|
|
NTSTATUS PacketCleanup( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) |
82 |
|
|
{ |
83 |
|
|
POPEN_INSTANCE open; |
84 |
|
|
NTSTATUS status = STATUS_SUCCESS; |
85 |
|
|
|
86 |
|
|
// DebugPrint(("Packet: Cleanup\n")); |
87 |
|
|
|
88 |
|
|
if(DeviceObject == Globals.ControlDeviceObject) { |
89 |
|
|
Irp->IoStatus.Status = status; |
90 |
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT); |
91 |
|
|
return status; |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
open = DeviceObject->DeviceExtension; |
95 |
|
|
|
96 |
|
|
IoIncrement(open); |
97 |
|
|
|
98 |
|
|
PacketCancelReadIrps(DeviceObject); |
99 |
|
|
|
100 |
|
|
// Since the current implementation of NDIS doesn't |
101 |
|
|
// allow us to cancel requests pending at the |
102 |
|
|
// minport, we must wait here until they complete. |
103 |
|
|
|
104 |
|
|
IoDecrement(open); |
105 |
|
|
|
106 |
|
|
NdisWaitEvent(&open->CleanupEvent, 0); |
107 |
|
|
|
108 |
|
|
Irp->IoStatus.Information = 0; |
109 |
|
|
Irp->IoStatus.Status = status; |
110 |
|
|
IoCompleteRequest (Irp, IO_NO_INCREMENT); |
111 |
|
|
return status; |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
|
115 |
|
|
VOID |
116 |
|
|
PacketResetComplete( |
117 |
|
|
IN NDIS_HANDLE ProtocolBindingContext, |
118 |
|
|
IN NDIS_STATUS Status |
119 |
|
|
) |
120 |
|
|
{ |
121 |
|
|
POPEN_INSTANCE open; |
122 |
|
|
PIRP irp; |
123 |
|
|
|
124 |
|
|
PLIST_ENTRY resetListEntry; |
125 |
|
|
|
126 |
|
|
// DebugPrint(("PacketResetComplte\n")); |
127 |
|
|
|
128 |
|
|
open= (POPEN_INSTANCE)ProtocolBindingContext; |
129 |
|
|
|
130 |
|
|
resetListEntry=ExInterlockedRemoveHeadList( |
131 |
|
|
&open->ResetIrpList, |
132 |
|
|
&open->ResetQueueLock |
133 |
|
|
); |
134 |
|
|
|
135 |
|
|
#if DBG |
136 |
|
|
if (resetListEntry == NULL) { |
137 |
|
|
DbgBreakPoint(); |
138 |
|
|
return; |
139 |
|
|
} |
140 |
|
|
#endif |
141 |
|
|
|
142 |
|
|
irp=CONTAINING_RECORD(resetListEntry,IRP,Tail.Overlay.ListEntry); |
143 |
|
|
|
144 |
|
|
if(Status == NDIS_STATUS_SUCCESS) { |
145 |
|
|
irp->IoStatus.Status = STATUS_SUCCESS; |
146 |
|
|
} else { |
147 |
|
|
irp->IoStatus.Status = STATUS_UNSUCCESSFUL; |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
irp->IoStatus.Information = 0; |
151 |
|
|
IoCompleteRequest(irp, IO_NO_INCREMENT); |
152 |
|
|
IoDecrement(open); |
153 |
|
|
|
154 |
|
|
// DebugPrint(("PacketResetComplte exit\n")); |
155 |
|
|
} |