|
|
1.1 root 1: /*++
2:
3: Copyright (c) 1990 Microsoft Corporation
4:
5: Module Name:
6:
7: packet.c
8:
9: Abstract:
10:
11:
12: Author:
13:
14:
15: Environment:
16:
17: Kernel mode only.
18:
19: Notes:
20:
21:
22: Future:
23:
24:
25:
26: Revision History:
27:
28: --*/
29:
30: #include "stdarg.h"
31: #include "ntddk.h"
32: #include "ntiologc.h"
33: #include "ndis.h"
34:
35: #include "debug.h"
36: #include "packet.h"
37:
38:
39:
40:
41:
42: NTSTATUS
43: PacketWrite(
44: IN PDEVICE_OBJECT DeviceObject,
45: IN PIRP Irp
46: )
47:
48: /*++
49:
50: Routine Description:
51:
52: This is the dispatch routine for create/open and close requests.
53: These requests complete successfully.
54:
55: Arguments:
56:
57: DeviceObject - Pointer to the device object.
58:
59: Irp - Pointer to the request packet.
60:
61: Return Value:
62:
63: Status is returned.
64:
65: --*/
66:
67: {
68:
69: // PIO_STACK_LOCATION IrpSp;
70: PDEVICE_EXTENSION DeviceExtension;
71: PLIST_ENTRY PacketListEntry;
72: PNDIS_PACKET pPacket;
73:
74: NDIS_STATUS Status;
75:
76: IF_LOUD(DbgPrint("Packet: SendAdapter\n");)
77:
78: DeviceExtension = DeviceObject->DeviceExtension;
79:
80: //
81: // Get a free packet from our list
82: //
83: PacketListEntry=ExInterlockedRemoveHeadList(&DeviceExtension->FreePacketList,
84: &DeviceExtension->FreePacketListSpinLock);
85:
86: if (PacketListEntry == NULL) {
87: //
88: // No free packets
89: //
90: Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
91: return STATUS_UNSUCCESSFUL;
92: }
93:
94:
95:
96: pPacket=CONTAINING_RECORD(PacketListEntry,NDIS_PACKET,ProtocolReserved);
97: RESERVED(pPacket)->Irp=Irp;
98:
99: //
100: // Attach the writes buffer to the packet
101: //
102: NdisChainBufferAtFront(pPacket,Irp->MdlAddress);
103:
104: IoMarkIrpPending(Irp);
105: Irp->IoStatus.Status = STATUS_PENDING;
106:
107: //
108: // Call the MAC
109: //
110: NdisSend(
111: &Status,
112: DeviceExtension->AdapterHandle,
113: pPacket);
114:
115:
116: if (Status != NDIS_STATUS_PENDING) {
117: //
118: // The send didn't pend so call the completion handler now
119: //
120: PacketSendComplete(
121: DeviceExtension,
122: pPacket,
123: Status
124: );
125:
126:
127: }
128:
129:
130:
131: return(STATUS_PENDING);
132:
133: }
134:
135:
136:
137: VOID
138: PacketSendComplete(
139: IN NDIS_HANDLE ProtocolBindingContext,
140: IN PNDIS_PACKET pPacket,
141: IN NDIS_STATUS Status
142: )
143:
144: {
145: PDEVICE_EXTENSION DeviceExtension;
146: PIRP Irp;
147:
148: IF_LOUD(DbgPrint("Packet: SendComplete\n");)
149:
150: DeviceExtension= (PDEVICE_EXTENSION)ProtocolBindingContext;
151: Irp=RESERVED(pPacket)->Irp;
152:
153: //
154: // recyle the packet
155: //
156: NdisReinitializePacket(pPacket);
157:
158: //
159: // Put the packet back on the free list
160: //
161: ExInterlockedInsertTailList(
162: &DeviceExtension->FreePacketList,
163: &RESERVED(pPacket)->ListElement,
164: &DeviceExtension->FreePacketListSpinLock);
165:
166:
167: Irp->IoStatus.Status = Status;
168: Irp->IoStatus.Information = 0;
169: IoCompleteRequest(Irp, IO_NO_INCREMENT);
170:
171: return;
172:
173: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.