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 |
|
|
|
28 |
|
|
NTSTATUS PacketWrite( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) |
29 |
|
|
{ |
30 |
|
|
POPEN_INSTANCE open; |
31 |
|
|
PNDIS_PACKET pPacket; |
32 |
|
|
NDIS_STATUS Status; |
33 |
|
|
|
34 |
|
|
// DebugPrint(("SendAdapter\n")); |
35 |
|
|
|
36 |
|
|
open = DeviceObject->DeviceExtension; |
37 |
|
|
|
38 |
|
|
IoIncrement(open); |
39 |
|
|
|
40 |
|
|
if(!open->Bound) { |
41 |
|
|
Irp->IoStatus.Status = STATUS_UNSUCCESSFUL; |
42 |
|
|
IoCompleteRequest (Irp, IO_NO_INCREMENT); |
43 |
|
|
IoDecrement(open); |
44 |
|
|
return STATUS_UNSUCCESSFUL; |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
NdisAllocatePacket( &Status, &pPacket, open->PacketPool ); |
48 |
|
|
|
49 |
|
|
if (Status != NDIS_STATUS_SUCCESS) { |
50 |
|
|
Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES; |
51 |
|
|
IoCompleteRequest (Irp, IO_NO_INCREMENT); |
52 |
|
|
IoDecrement(open); |
53 |
|
|
return STATUS_INSUFFICIENT_RESOURCES; |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
RESERVED(pPacket)->Irp=Irp; |
57 |
|
|
|
58 |
|
|
NdisChainBufferAtFront(pPacket,Irp->MdlAddress); |
59 |
|
|
|
60 |
|
|
// Important: Since we have marked the IRP pending, we must return |
61 |
|
|
// STATUS_PENDING even we happen to complete the IRP synchronously. |
62 |
|
|
|
63 |
|
|
IoMarkIrpPending(Irp); |
64 |
|
|
|
65 |
|
|
NdisSend( &Status, open->AdapterHandle, pPacket ); |
66 |
|
|
|
67 |
|
|
if (Status != NDIS_STATUS_PENDING) { |
68 |
|
|
PacketSendComplete( open, pPacket, Status ); |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
return STATUS_PENDING; |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
VOID |
75 |
|
|
PacketSendComplete( |
76 |
|
|
IN NDIS_HANDLE ProtocolBindingContext, |
77 |
|
|
IN PNDIS_PACKET pPacket, |
78 |
|
|
IN NDIS_STATUS Status |
79 |
|
|
) |
80 |
|
|
{ |
81 |
|
|
PIRP irp; |
82 |
|
|
PIO_STACK_LOCATION irpSp; |
83 |
|
|
|
84 |
|
|
// DebugPrint(("Packet: SendComplete :%x\n", Status)); |
85 |
|
|
|
86 |
|
|
irp = RESERVED(pPacket)->Irp; |
87 |
|
|
irpSp = IoGetCurrentIrpStackLocation(irp); |
88 |
|
|
|
89 |
|
|
NdisFreePacket(pPacket); |
90 |
|
|
|
91 |
|
|
if(Status == NDIS_STATUS_SUCCESS) { |
92 |
|
|
irp->IoStatus.Information = irpSp->Parameters.Write.Length; |
93 |
|
|
irp->IoStatus.Status = STATUS_SUCCESS; |
94 |
|
|
} else { |
95 |
|
|
irp->IoStatus.Information = 0; |
96 |
|
|
irp->IoStatus.Status = STATUS_UNSUCCESSFUL; |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
IoCompleteRequest(irp, IO_NO_INCREMENT); |
100 |
|
|
IoDecrement((POPEN_INSTANCE)ProtocolBindingContext); |
101 |
|
|
} |