ReactOS 0.4.15-dev-7953-g1f49173
requests.c
Go to the documentation of this file.
1/*
2 * ReactOS AMD PCNet Driver
3 *
4 * Copyright (C) 2000 Casper Hornstrup <chorns@users.sourceforge.net>
5 * Copyright (C) 2003 Vizzini <vizzini@plasmic.com>
6 * Copyright (C) 2004 Filip Navara <navaraf@reactos.com>
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 along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * PROGRAMMERS:
23 * Vizzini (vizzini@plasmic.com),
24 * borrowed very heavily from the ReactOS ne2000 driver by
25 * Casper S. Hornstrup (chorns@users.sourceforge.net)
26 * REVISIONS:
27 * 14-Sep-2003 vizzini - Created
28 * 17-Oct-2004 navaraf - Add multicast support.
29 * - Add media state detection support.
30 * - Protect the adapter context with spinlock
31 * and move code talking to card to inside
32 * NdisMSynchronizeWithInterrupt calls where
33 * necessary.
34 */
35
36#include "pcnet.h"
37
38#define NDEBUG
39#include <debug.h>
40
41/* List of supported OIDs */
43{
80};
81
82
86 IN NDIS_HANDLE MiniportAdapterContext,
87 IN NDIS_OID Oid,
88 IN PVOID InformationBuffer,
89 IN ULONG InformationBufferLength,
91 OUT PULONG BytesNeeded)
92/*
93 * FUNCTION: Query an OID from the driver
94 * ARGUMENTS:
95 * MiniportAdapterContext: context originally passed to NdisMSetAttributes
96 * Oid: OID NDIS is querying
97 * InformationBuffer: pointer to buffer into which to write the results of the query
98 * InformationBufferLength: size in bytes of InformationBuffer
99 * BytesWritten: number of bytes written into InformationBuffer in response to the query
100 * BytesNeeded: number of bytes needed to answer the query
101 * RETURNS:
102 * NDIS_STATUS_SUCCESS on all queries
103 * NOTES:
104 * - Called by NDIS at DISPATCH_LEVEL
105 * - If InformationBufferLength is insufficient to store the results, return the amount
106 * needed in BytesNeeded and return NDIS_STATUS_INVALID_LENGTH
107 * TODO:
108 * - Update to verify input buffer & size and return insufficient buffer codes
109 */
110{
112 PVOID CopyFrom;
113 UINT CopySize;
114 ULONG GenericULONG;
115 PADAPTER Adapter = (PADAPTER)MiniportAdapterContext;
116
117 DPRINT("Called. OID 0x%x\n", Oid);
118
119 ASSERT(Adapter);
120
121 NdisAcquireSpinLock(&Adapter->Lock);
122
124 CopyFrom = (PVOID)&GenericULONG;
125 CopySize = sizeof(ULONG);
126
127 switch (Oid)
128 {
130 {
131 CopyFrom = (PVOID)&MiniportOIDList;
132 CopySize = sizeof(MiniportOIDList);
133 break;
134 }
135
137 {
138 GenericULONG = (ULONG)NdisHardwareStatusReady;
139 break;
140 }
141
144 {
145 static const NDIS_MEDIUM Medium = NdisMedium802_3;
146 CopyFrom = (PVOID)&Medium;
147 CopySize = sizeof(NDIS_MEDIUM);
148 break;
149 }
150
153 {
154 GenericULONG = 1500;
155 break;
156 }
157
159 {
160 /*
161 * The value returned by this OID must be equal to
162 * OID_GEN_MAXIMUM_TOTAL_SIZE - sizeof(ETHERNET_HEADER)
163 * where sizeof(ETHERNET_HEADER) is 14.
164 */
165 GenericULONG = 1500;
166 break;
167 }
168
170 {
171 GenericULONG = Adapter->MediaSpeed * 10000;
172 break;
173 }
174
176 {
177 /* XXX fix me */
178 GenericULONG = BUFFER_SIZE;
179 break;
180 }
181
183 {
184 /* XXX fix me */
185 GenericULONG = BUFFER_SIZE;
186 break;
187 }
188
190 {
191 GenericULONG = BUFFER_SIZE;
192 break;
193 }
194
196 {
197 GenericULONG = BUFFER_SIZE;
198 break;
199 }
200
202 {
203 UCHAR *CharPtr = (UCHAR *)&GenericULONG;
204 GenericULONG = 0;
205 /* Read the first three bytes of the permanent MAC address */
206 NdisRawReadPortUchar(Adapter->PortOffset, CharPtr);
207 NdisRawReadPortUchar(Adapter->PortOffset + 1, CharPtr + 1);
208 NdisRawReadPortUchar(Adapter->PortOffset + 2, CharPtr + 2);
209 break;
210 }
211
213 {
214 static UCHAR VendorDesc[] = "ReactOS Team";
215 CopyFrom = VendorDesc;
216 CopySize = sizeof(VendorDesc);
217 break;
218 }
219
221 {
222 /* XXX implement me */
223 GenericULONG = 1;
224 break;
225 }
226
228 {
229 GenericULONG = Adapter->CurrentPacketFilter;
230 break;
231 }
232
234 {
235 /* NDIS version used by the driver. */
236 static const USHORT DriverVersion =
237 (NDIS_MINIPORT_MAJOR_VERSION << 8) + NDIS_MINIPORT_MINOR_VERSION;
238 CopyFrom = (PVOID)&DriverVersion;
239 CopySize = sizeof(DriverVersion);
240 break;
241 }
242
244 {
245 /* See comment in OID_GEN_MAXIMUM_FRAME_SIZE. */
246 GenericULONG = 1514;
247 break;
248 }
249
251 {
252 DPRINT("OID_GEN_PROTOCOL_OPTIONS.\n");
254 break;
255 }
256
258 {
263 break;
264 }
265
267 {
268 GenericULONG = (ULONG)NdisMediaStateConnected; /* Adapter->MediaState */
269 break;
270 }
271
273 {
274 GenericULONG = 1;
275 break;
276 }
277
280 {
281 CopyFrom = (PVOID)&Adapter->InitializationBlockVirt->PADR;
282 CopySize = 6;
283 break;
284 }
285
287 {
288 GenericULONG = MAX_MULTICAST_ADDRESSES;
289 break;
290 }
291
292 case OID_GEN_XMIT_OK:
293 GenericULONG = Adapter->Statistics.XmtGoodFrames;
294 break;
295
296 case OID_GEN_RCV_OK:
297 GenericULONG = Adapter->Statistics.RcvGoodFrames;
298 break;
299
301 GenericULONG = Adapter->Statistics.XmtRetryErrors +
303 Adapter->Statistics.XmtCollisions +
308 break;
309
311 GenericULONG = Adapter->Statistics.RcvBufferErrors +
312 Adapter->Statistics.RcvCrcErrors +
315 break;
316
318 GenericULONG = Adapter->Statistics.RcvBufferErrors +
320 break;
321
323 GenericULONG = Adapter->Statistics.RcvCrcErrors;
324 break;
325
327 GenericULONG = Adapter->Statistics.RcvFramingErrors;
328 break;
329
331 GenericULONG = Adapter->Statistics.XmtOneRetry;
332 break;
333
335 GenericULONG = Adapter->Statistics.XmtMoreThanOneRetry;
336 break;
337
338 default:
339 {
340 DPRINT1("Unknown OID\n");
342 break;
343 }
344 }
345
347 {
348 if (CopySize > InformationBufferLength)
349 {
350 *BytesNeeded = CopySize;
351 *BytesWritten = 0;
353 }
354 else
355 {
356 NdisMoveMemory(InformationBuffer, CopyFrom, CopySize);
357 *BytesWritten = CopySize;
358 *BytesNeeded = CopySize;
359 }
360 }
361 else
362 {
363 *BytesWritten = 0;
364 *BytesNeeded = 0;
365 }
366
367 NdisReleaseSpinLock(&Adapter->Lock);
368
369 DPRINT("Leaving. Status is 0x%x\n", Status);
370
371 return Status;
372}
373
375NTAPI
377 IN NDIS_HANDLE MiniportAdapterContext,
378 IN NDIS_OID Oid,
379 IN PVOID InformationBuffer,
380 IN ULONG InformationBufferLength,
382 OUT PULONG BytesNeeded)
383/*
384 * FUNCTION: Set a miniport variable (OID)
385 * ARGUMENTS:
386 * MiniportAdapterContext: context originally passed into NdisMSetAttributes
387 * Oid: the variable being set
388 * InformationBuffer: the data to set the variable to
389 * InformationBufferLength: number of bytes in InformationBuffer
390 * BytesRead: number of bytes read by us out of the buffer
391 * BytesNeeded: number of bytes required to satisfy the request if InformationBufferLength
392 * is insufficient
393 * RETURNS:
394 * NDIS_STATUS_SUCCESS on all requests
395 * NOTES:
396 * - Called by NDIS at DISPATCH_LEVEL
397 * - verify buffer space as mentioned in previous function notes
398 */
399{
400 ULONG GenericULONG;
402 PADAPTER Adapter = (PADAPTER)MiniportAdapterContext;
403
404 ASSERT(Adapter);
405
406 DPRINT("Called, OID 0x%x\n", Oid);
407
408 NdisAcquireSpinLock(&Adapter->Lock);
409
410 switch (Oid)
411 {
413 {
414 /* Verify length */
415 if (InformationBufferLength < sizeof(ULONG))
416 {
417 *BytesRead = 0;
418 *BytesNeeded = sizeof(ULONG);
420 break;
421 }
422
423 NdisMoveMemory(&GenericULONG, InformationBuffer, sizeof(ULONG));
424
425 /* Check for properties the driver don't support */
426 if (GenericULONG &
433 )
434 {
435 *BytesRead = sizeof(ULONG);
436 *BytesNeeded = 0;
438 break;
439 }
440
441 Adapter->CurrentPacketFilter = GenericULONG;
442
443 /* FIXME: Set filter on hardware */
444
445 break;
446 }
447
449 {
450 /* Verify length */
451 if (InformationBufferLength < sizeof(ULONG))
452 {
453 *BytesRead = 0;
454 *BytesNeeded = sizeof(ULONG);
456 break;
457 }
458
459 NdisMoveMemory(&GenericULONG, InformationBuffer, sizeof(ULONG));
460
461 if (GenericULONG > 1500)
463 else
464 Adapter->CurrentLookaheadSize = GenericULONG;
465
466 break;
467 }
468
470 {
471 /* Verify length. Must be multiple of hardware address length */
472 if ((InformationBufferLength % 6) != 0)
473 {
474 *BytesRead = 0;
475 *BytesNeeded = InformationBufferLength + (InformationBufferLength % 6);
477 break;
478 }
479
480 ASSERT((InformationBufferLength / 6) <= MAX_MULTICAST_ADDRESSES);
481
482 /* Set new multicast address list */
483 //NdisMoveMemory(Adapter->Addresses, InformationBuffer, InformationBufferLength);
484
485 /* Update hardware */
486 Status = MiSetMulticast(Adapter, InformationBuffer, InformationBufferLength / 6);
487
488 break;
489 }
490
491 default:
492 {
493 DPRINT1("Invalid object ID (0x%X).\n", Oid);
494 *BytesRead = 0;
495 *BytesNeeded = 0;
497 break;
498 }
499 }
500
502 {
503 *BytesRead = InformationBufferLength;
504 *BytesNeeded = 0;
505 }
506
507 NdisReleaseSpinLock(&Adapter->Lock);
508
509 DPRINT("Leaving. Status (0x%X).\n", Status);
510
511 return Status;
512}
#define DPRINT1
Definition: precomp.h:8
Status
Definition: gdiplustypes.h:25
#define ASSERT(a)
Definition: mode.c:44
#define BUFFER_SIZE
Definition: freeldrpage.c:26
#define NdisReleaseSpinLock(_SpinLock)
Definition: ndis.h:4115
unsigned int UINT
Definition: ndis.h:50
#define NDIS_STATUS_INVALID_DATA
Definition: ndis.h:486
#define NDIS_STATUS_NOT_SUPPORTED
Definition: ndis.h:479
#define NDIS_PACKET_TYPE_MAC_FRAME
Definition: ndis.h:674
#define NDIS_PACKET_TYPE_SOURCE_ROUTING
Definition: ndis.h:667
#define NdisRawReadPortUchar(Port, Data)
Definition: ndis.h:4173
#define NDIS_STATUS_INVALID_LENGTH
Definition: ndis.h:485
#define NDIS_PACKET_TYPE_ALL_FUNCTIONAL
Definition: ndis.h:672
#define NDIS_MAC_OPTION_TRANSFERS_NOT_PEND
Definition: ndis.h:684
#define NDIS_MAC_OPTION_RECEIVE_SERIALIZED
Definition: ndis.h:683
#define NDIS_PACKET_TYPE_FUNCTIONAL
Definition: ndis.h:673
#define NDIS_PACKET_TYPE_GROUP
Definition: ndis.h:671
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define NDIS_PACKET_TYPE_SMT
Definition: ndis.h:669
#define NDIS_MAC_OPTION_NO_LOOPBACK
Definition: ndis.h:685
#define NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA
Definition: ndis.h:682
#define NdisAcquireSpinLock(_SpinLock)
Definition: ndis.h:4106
#define NdisMoveMemory(Destination, Source, Length)
Definition: ndis.h:3896
enum _NDIS_MEDIUM NDIS_MEDIUM
#define OID_GEN_TRANSMIT_BLOCK_SIZE
Definition: ntddndis.h:242
#define OID_GEN_PROTOCOL_OPTIONS
Definition: ntddndis.h:250
#define OID_GEN_XMIT_OK
Definition: ntddndis.h:267
#define OID_GEN_MAXIMUM_TOTAL_SIZE
Definition: ntddndis.h:249
#define OID_GEN_XMIT_ERROR
Definition: ntddndis.h:269
#define OID_GEN_VENDOR_DRIVER_VERSION
Definition: ntddndis.h:254
#define OID_802_3_PERMANENT_ADDRESS
Definition: ntddndis.h:302
#define OID_GEN_LINK_SPEED
Definition: ntddndis.h:239
#define OID_GEN_VENDOR_ID
Definition: ntddndis.h:244
#define OID_GEN_CURRENT_PACKET_FILTER
Definition: ntddndis.h:246
@ NdisMediaStateConnected
Definition: ntddndis.h:470
#define OID_GEN_RCV_NO_BUFFER
Definition: ntddndis.h:271
#define OID_802_3_XMIT_ONE_COLLISION
Definition: ntddndis.h:308
#define OID_802_3_XMIT_MORE_COLLISIONS
Definition: ntddndis.h:309
#define OID_GEN_RECEIVE_BUFFER_SPACE
Definition: ntddndis.h:241
#define OID_802_3_MAXIMUM_LIST_SIZE
Definition: ntddndis.h:305
#define OID_GEN_DRIVER_VERSION
Definition: ntddndis.h:248
#define OID_802_3_MAC_OPTIONS
Definition: ntddndis.h:306
#define OID_802_3_CURRENT_ADDRESS
Definition: ntddndis.h:303
#define OID_802_3_MULTICAST_LIST
Definition: ntddndis.h:304
#define OID_GEN_TRANSMIT_BUFFER_SPACE
Definition: ntddndis.h:240
#define OID_GEN_MEDIA_SUPPORTED
Definition: ntddndis.h:235
@ NdisMedium802_3
Definition: ntddndis.h:188
#define OID_GEN_MAXIMUM_FRAME_SIZE
Definition: ntddndis.h:238
#define OID_GEN_RCV_CRC_ERROR
Definition: ntddndis.h:286
#define OID_GEN_MEDIA_IN_USE
Definition: ntddndis.h:236
#define OID_GEN_MEDIA_CONNECT_STATUS
Definition: ntddndis.h:252
#define OID_GEN_RCV_OK
Definition: ntddndis.h:268
#define OID_GEN_MAXIMUM_LOOKAHEAD
Definition: ntddndis.h:237
#define OID_802_3_RCV_ERROR_ALIGNMENT
Definition: ntddndis.h:307
int NDIS_STATUS
Definition: ntddndis.h:475
#define OID_GEN_RCV_ERROR
Definition: ntddndis.h:270
@ NdisHardwareStatusReady
Definition: ntddndis.h:450
#define OID_GEN_CURRENT_LOOKAHEAD
Definition: ntddndis.h:247
#define OID_GEN_MAC_OPTIONS
Definition: ntddndis.h:251
#define OID_GEN_VENDOR_DESCRIPTION
Definition: ntddndis.h:245
#define OID_GEN_SUPPORTED_LIST
Definition: ntddndis.h:233
ULONG NDIS_OID
Definition: ntddndis.h:230
#define OID_GEN_RECEIVE_BLOCK_SIZE
Definition: ntddndis.h:243
#define OID_GEN_MAXIMUM_SEND_PACKETS
Definition: ntddndis.h:253
#define OID_GEN_HARDWARE_STATUS
Definition: ntddndis.h:234
NDIS_STATUS NTAPI MiniportQueryInformation(_In_ NDIS_HANDLE MiniportAdapterContext, _In_ NDIS_OID Oid, _In_ PVOID InformationBuffer, _In_ ULONG InformationBufferLength, _Out_ PULONG BytesWritten, _Out_ PULONG BytesNeeded)
Definition: requests.c:973
NDIS_STATUS NTAPI MiniportSetInformation(_In_ NDIS_HANDLE MiniportAdapterContext, _In_ NDIS_OID Oid, _In_ PVOID InformationBuffer, _In_ ULONG InformationBufferLength, _Out_ PULONG BytesRead, _Out_ PULONG BytesNeeded)
Definition: requests.c:1282
static ULONG MiniportOIDList[]
Definition: requests.c:42
NDIS_STATUS NTAPI MiSetMulticast(PADAPTER Adapter, UCHAR *Addresses, UINT AddressCount)
Definition: pcnet.c:1262
struct _ADAPTER * PADAPTER
#define MAX_MULTICAST_ADDRESSES
Definition: pcnet.h:155
unsigned short USHORT
Definition: pedump.c:61
#define DPRINT
Definition: sndvol32.h:71
ULONG XmtCollisions
Definition: pcnet.h:42
ULONG XmtOneRetry
Definition: pcnet.h:47
ULONG RcvCrcErrors
Definition: pcnet.h:51
ULONG XmtLossesOfCarrier
Definition: pcnet.h:41
ULONG RcvBufferErrors
Definition: pcnet.h:50
ULONG XmtGoodFrames
Definition: pcnet.h:39
ULONG RcvFramingErrors
Definition: pcnet.h:53
ULONG XmtBufferUnderflows
Definition: pcnet.h:45
ULONG RcvOverflowErrors
Definition: pcnet.h:52
ULONG RcvGoodFrames
Definition: pcnet.h:49
ULONG XmtLateCollisions
Definition: pcnet.h:43
ULONG XmtMoreThanOneRetry
Definition: pcnet.h:48
ULONG XmtBufferErrors
Definition: pcnet.h:46
ULONG XmtExcessiveDeferrals
Definition: pcnet.h:44
ULONG XmtRetryErrors
Definition: pcnet.h:40
Definition: pcnet.h:58
NDIS_SPIN_LOCK Lock
Definition: pcnet.h:59
UINT MediaSpeed
Definition: pcnet.h:68
ADAPTER_STATS Statistics
Definition: pcnet.h:108
ULONG CurrentLookaheadSize
Definition: pcnet.h:73
ULONG CurrentPacketFilter
Definition: pcnet.h:72
PINITIALIZATION_BLOCK InitializationBlockVirt
Definition: pcnet.h:81
ULONG_PTR PortOffset
Definition: pcnet.h:65
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
Definition: wdfiotarget.h:960
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:870
unsigned char UCHAR
Definition: xmlstorage.h:181