ReactOS  0.4.15-dev-1184-g23e04ae
info.c
Go to the documentation of this file.
1 /*
2  * ReactOS Realtek 8139 Driver
3  *
4  * Copyright (C) 2013 Cameron Gutman
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  *
20  */
21 
22 #include "nic.h"
23 
24 #define NDEBUG
25 #include <debug.h>
26 
28 {
65 };
66 
68 NTAPI
70  IN NDIS_HANDLE MiniportAdapterContext,
71  IN NDIS_OID Oid,
72  IN PVOID InformationBuffer,
73  IN ULONG InformationBufferLength,
75  OUT PULONG BytesNeeded
76  )
77 {
78  PRTL_ADAPTER adapter = (PRTL_ADAPTER)MiniportAdapterContext;
79  ULONG genericUlong;
80  ULONG copyLength;
81  PVOID copySource;
83 
85  copySource = &genericUlong;
86  copyLength = sizeof(ULONG);
87 
88  NdisAcquireSpinLock(&adapter->Lock);
89 
90  switch (Oid)
91  {
93  copySource = (PVOID)&SupportedOidList;
94  copyLength = sizeof(SupportedOidList);
95  break;
96 
98  genericUlong = adapter->PacketFilter;
99  break;
100 
102  genericUlong = (ULONG)NdisHardwareStatusReady; //FIXME
103  break;
104 
107  {
108  static const NDIS_MEDIUM medium = NdisMedium802_3;
109  copySource = (PVOID)&medium;
110  copyLength = sizeof(medium);
111  break;
112  }
113 
119  genericUlong = MAXIMUM_FRAME_SIZE - sizeof(ETH_HEADER);
120  break;
121 
122  case OID_GEN_LINK_SPEED:
123  genericUlong = adapter->LinkSpeedMbps * 1000;
124  break;
125 
127  genericUlong = MAXIMUM_FRAME_SIZE;
128  break;
129 
131  genericUlong = RECEIVE_BUFFER_SIZE;
132  break;
133 
134  case OID_GEN_VENDOR_ID:
135  //
136  // The 3 bytes of the MAC address is the vendor ID
137  //
138  genericUlong = 0;
139  genericUlong |= (adapter->PermanentMacAddress[0] << 16);
140  genericUlong |= (adapter->PermanentMacAddress[1] << 8);
141  genericUlong |= (adapter->PermanentMacAddress[2] & 0xFF);
142  break;
143 
145  {
146  static UCHAR vendorDesc[] = "ReactOS Team";
147  copySource = vendorDesc;
148  copyLength = sizeof(vendorDesc);
149  break;
150  }
151 
153  genericUlong = DRIVER_VERSION;
154  break;
155 
157  {
158  static const USHORT driverVersion =
159  (NDIS_MINIPORT_MAJOR_VERSION << 8) + NDIS_MINIPORT_MINOR_VERSION;
160  copySource = (PVOID)&driverVersion;
161  copyLength = sizeof(driverVersion);
162  break;
163  }
164 
166  genericUlong = MAXIMUM_FRAME_SIZE;
167  break;
168 
170  NDIS_DbgPrint(MIN_TRACE, ("OID_GEN_PROTOCOL_OPTIONS is unimplemented\n"));
172  break;
173 
174  case OID_GEN_MAC_OPTIONS:
175  genericUlong = NDIS_MAC_OPTION_RECEIVE_SERIALIZED |
179  break;
180 
182  genericUlong = adapter->MediaState;
183  break;
184 
186  genericUlong = 1;
187  break;
188 
190  copySource = adapter->CurrentMacAddress;
191  copyLength = IEEE_802_ADDR_LENGTH;
192  break;
193 
195  copySource = adapter->PermanentMacAddress;
196  copyLength = IEEE_802_ADDR_LENGTH;
197  break;
198 
200  genericUlong = MAXIMUM_MULTICAST_ADDRESSES;
201  break;
202 
203  case OID_GEN_XMIT_OK:
204  genericUlong = adapter->TransmitOk;
205  break;
206 
207  case OID_GEN_RCV_OK:
208  genericUlong = adapter->ReceiveOk;
209  break;
210 
211  case OID_GEN_XMIT_ERROR:
212  genericUlong = adapter->TransmitError;
213  break;
214 
215  case OID_GEN_RCV_ERROR:
216  genericUlong = adapter->ReceiveError;
217  break;
218 
220  genericUlong = adapter->ReceiveNoBufferSpace;
221  break;
222 
224  genericUlong = adapter->ReceiveCrcError;
225  break;
226 
228  genericUlong = adapter->ReceiveAlignmentError;
229  break;
230 
232  genericUlong = adapter->TransmitOneCollision;
233  break;
234 
236  genericUlong = adapter->TransmitMoreCollisions;
237  break;
238 
239  default:
240  NDIS_DbgPrint(MIN_TRACE, ("Unknown OID\n"));
242  break;
243  }
244 
246  {
247  if (copyLength > InformationBufferLength)
248  {
249  *BytesNeeded = copyLength;
250  *BytesWritten = 0;
252  }
253  else
254  {
255  NdisMoveMemory(InformationBuffer, copySource, copyLength);
256  *BytesWritten = copyLength;
257  *BytesNeeded = copyLength;
258  }
259  }
260  else
261  {
262  *BytesWritten = 0;
263  *BytesNeeded = 0;
264  }
265 
266  NdisReleaseSpinLock(&adapter->Lock);
267 
268  NDIS_DbgPrint(MAX_TRACE, ("Query OID 0x%x: Completed with status 0x%x (%d, %d)\n",
269  Oid, status, *BytesWritten, *BytesNeeded));
270 
271  return status;
272 }
273 
275 NTAPI
277  IN NDIS_HANDLE MiniportAdapterContext,
278  IN NDIS_OID Oid,
279  IN PVOID InformationBuffer,
280  IN ULONG InformationBufferLength,
282  OUT PULONG BytesNeeded
283  )
284 {
285  PRTL_ADAPTER adapter = (PRTL_ADAPTER)MiniportAdapterContext;
286  ULONG genericUlong;
288 
290 
291  NdisAcquireSpinLock(&adapter->Lock);
292 
293  switch (Oid)
294  {
296  if (InformationBufferLength < sizeof(ULONG))
297  {
298  *BytesRead = 0;
299  *BytesNeeded = sizeof(ULONG);
301  break;
302  }
303 
304  NdisMoveMemory(&genericUlong, InformationBuffer, sizeof(ULONG));
305 
306  if (genericUlong &
313  {
314  *BytesRead = sizeof(ULONG);
315  *BytesNeeded = sizeof(ULONG);
317  break;
318  }
319 
320  adapter->PacketFilter = genericUlong;
321 
322  status = NICApplyPacketFilter(adapter);
324  {
325  NDIS_DbgPrint(MIN_TRACE, ("Failed to apply new packet filter\n"));
326  break;
327  }
328 
329  break;
330 
332  if (InformationBufferLength < sizeof(ULONG))
333  {
334  *BytesRead = 0;
335  *BytesNeeded = sizeof(ULONG);
337  break;
338  }
339 
340  NdisMoveMemory(&genericUlong, InformationBuffer, sizeof(ULONG));
341 
342  if (genericUlong > MAXIMUM_FRAME_SIZE - sizeof(ETH_HEADER))
343  {
345  }
346  else
347  {
348  // Ignore this...
349  }
350 
351  break;
352 
354  if (InformationBufferLength % IEEE_802_ADDR_LENGTH)
355  {
356  *BytesRead = 0;
357  *BytesNeeded = InformationBufferLength + (InformationBufferLength % IEEE_802_ADDR_LENGTH);
359  break;
360  }
361 
362  if (InformationBufferLength / 6 > MAXIMUM_MULTICAST_ADDRESSES)
363  {
365  *BytesRead = 0;
367  break;
368  }
369 
370  NdisMoveMemory(adapter->MulticastList, InformationBuffer, InformationBufferLength);
371 
372  // FIXME: Write to device
373 
374  break;
375 
376  default:
377  NDIS_DbgPrint(MIN_TRACE, ("Unknown OID\n"));
379  *BytesRead = 0;
380  *BytesNeeded = 0;
381  break;
382  }
383 
385  {
386  *BytesRead = InformationBufferLength;
387  *BytesNeeded = 0;
388  }
389 
390  NdisReleaseSpinLock(&adapter->Lock);
391 
392  return status;
393 }
#define IN
Definition: typedefs.h:39
#define MAXIMUM_MULTICAST_ADDRESSES
Definition: e1000hw.h:23
ULONG MediaState
Definition: nic.h:64
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesWritten
Definition: fltkernel.h:1293
ULONG TransmitMoreCollisions
Definition: nic.h:86
static ULONG
Definition: info.c:26
#define OID_GEN_VENDOR_DRIVER_VERSION
Definition: ntddndis.h:254
enum _NDIS_MEDIUM NDIS_MEDIUM
ULONG TransmitError
Definition: nic.h:81
#define DRIVER_VERSION
Definition: nic.h:22
#define OID_GEN_RECEIVE_BUFFER_SPACE
Definition: ntddndis.h:241
VOID EXPORT NdisReleaseSpinLock(IN PNDIS_SPIN_LOCK SpinLock)
Definition: control.c:239
NDIS_STATUS NTAPI NICApplyPacketFilter(IN PE1000_ADAPTER Adapter)
Definition: hardware.c:752
static ULONG SupportedOidList[]
Definition: info.c:27
#define OID_GEN_MAC_OPTIONS
Definition: ntddndis.h:251
#define OID_GEN_RCV_ERROR
Definition: ntddndis.h:270
ULONG NDIS_OID
Definition: ntddndis.h:230
#define OID_GEN_CURRENT_PACKET_FILTER
Definition: ntddndis.h:246
#define OID_GEN_RCV_CRC_ERROR
Definition: ntddndis.h:286
ULONG ReceiveError
Definition: nic.h:80
#define OID_GEN_HARDWARE_STATUS
Definition: ntddndis.h:234
#define OID_GEN_MEDIA_IN_USE
Definition: ntddndis.h:236
#define NDIS_MAC_OPTION_NO_LOOPBACK
Definition: ndis.h:685
ULONG LinkSpeedMbps
Definition: nic.h:63
int NDIS_STATUS
Definition: ntddndis.h:471
#define NDIS_STATUS_NOT_SUPPORTED
Definition: ndis.h:479
#define OID_GEN_PROTOCOL_OPTIONS
Definition: ntddndis.h:250
#define OID_802_3_MAXIMUM_LIST_SIZE
Definition: ntddndis.h:305
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define NDIS_MAC_OPTION_TRANSFERS_NOT_PEND
Definition: ndis.h:684
Definition: lan.h:33
ULONG TransmitOk
Definition: nic.h:79
#define OID_GEN_MEDIA_CONNECT_STATUS
Definition: ntddndis.h:252
#define NDIS_PACKET_TYPE_SOURCE_ROUTING
Definition: ndis.h:667
#define OID_GEN_TRANSMIT_BUFFER_SPACE
Definition: ntddndis.h:240
#define OID_GEN_MAXIMUM_LOOKAHEAD
Definition: ntddndis.h:237
#define NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA
Definition: ndis.h:682
#define OID_GEN_RCV_OK
Definition: ntddndis.h:268
#define NDIS_STATUS_INVALID_LENGTH
Definition: ndis.h:485
#define NDIS_PACKET_TYPE_GROUP
Definition: ndis.h:671
#define NDIS_STATUS_INVALID_DATA
Definition: ndis.h:486
ULONG ReceiveNoBufferSpace
Definition: nic.h:82
#define OID_GEN_SUPPORTED_LIST
Definition: ntddndis.h:233
#define OID_GEN_VENDOR_ID
Definition: ntddndis.h:244
#define NDIS_MAC_OPTION_RECEIVE_SERIALIZED
Definition: ndis.h:683
#define OID_GEN_VENDOR_DESCRIPTION
Definition: ntddndis.h:245
#define OID_GEN_XMIT_OK
Definition: ntddndis.h:267
#define OID_GEN_MAXIMUM_FRAME_SIZE
Definition: ntddndis.h:238
struct _ETH_HEADER ETH_HEADER
#define OID_GEN_MAXIMUM_TOTAL_SIZE
Definition: ntddndis.h:249
ULONG ReceiveOk
Definition: nic.h:78
VOID EXPORT NdisAcquireSpinLock(IN PNDIS_SPIN_LOCK SpinLock)
Definition: control.c:135
#define IEEE_802_ADDR_LENGTH
Definition: e1000hw.h:11
ULONG ReceiveCrcError
Definition: nic.h:83
#define NDIS_PACKET_TYPE_FUNCTIONAL
Definition: ndis.h:673
NDIS_SPIN_LOCK Lock
Definition: nic.h:38
#define OID_802_3_RCV_ERROR_ALIGNMENT
Definition: ntddndis.h:307
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
struct _RTL_ADAPTER::@1003 MulticastList[MAXIMUM_MULTICAST_ADDRESSES]
unsigned char UCHAR
Definition: xmlstorage.h:181
#define OID_802_3_XMIT_ONE_COLLISION
Definition: ntddndis.h:308
#define NDIS_PACKET_TYPE_SMT
Definition: ndis.h:669
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: info.c:232
static PVOID
Definition: info.c:26
#define OID_GEN_LINK_SPEED
Definition: ntddndis.h:239
struct _RTL_ADAPTER * PRTL_ADAPTER
#define OID_802_3_XMIT_MORE_COLLISIONS
Definition: ntddndis.h:309
ULONG ReceiveAlignmentError
Definition: nic.h:84
#define OID_802_3_MULTICAST_LIST
Definition: ntddndis.h:304
#define OID_GEN_MAXIMUM_SEND_PACKETS
Definition: ntddndis.h:253
#define MAX_TRACE
Definition: debug.h:16
#define OID_GEN_MEDIA_SUPPORTED
Definition: ntddndis.h:235
unsigned short USHORT
Definition: pedump.c:61
#define OID_GEN_XMIT_ERROR
Definition: ntddndis.h:269
#define OID_802_3_MAC_OPTIONS
Definition: ntddndis.h:306
#define OID_GEN_TRANSMIT_BLOCK_SIZE
Definition: ntddndis.h:242
#define NDIS_PACKET_TYPE_ALL_FUNCTIONAL
Definition: ndis.h:672
unsigned int * PULONG
Definition: retypes.h:1
UCHAR CurrentMacAddress[IEEE_802_ADDR_LENGTH]
Definition: nic.h:53
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
#define RECEIVE_BUFFER_SIZE
Definition: nic.h:20
#define OID_GEN_RECEIVE_BLOCK_SIZE
Definition: ntddndis.h:243
#define OUT
Definition: typedefs.h:40
unsigned int ULONG
Definition: retypes.h:1
#define MIN_TRACE
Definition: debug.h:14
ULONG PacketFilter
Definition: nic.h:67
#define OID_802_3_PERMANENT_ADDRESS
Definition: ntddndis.h:302
#define OID_802_3_CURRENT_ADDRESS
Definition: ntddndis.h:303
UCHAR PermanentMacAddress[IEEE_802_ADDR_LENGTH]
Definition: nic.h:52
#define NDIS_PACKET_TYPE_MAC_FRAME
Definition: ndis.h:674
#define MAXIMUM_FRAME_SIZE
Definition: nic.h:19
#define NdisMoveMemory(Destination, Source, Length)
Definition: ndis.h:3896
static SERVICE_STATUS status
Definition: service.c:31
ULONG TransmitOneCollision
Definition: nic.h:85
#define OID_GEN_CURRENT_LOOKAHEAD
Definition: ntddndis.h:247
#define OID_GEN_DRIVER_VERSION
Definition: ntddndis.h:248
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255
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: info.c:51
#define OID_GEN_RCV_NO_BUFFER
Definition: ntddndis.h:271
Definition: ps.c:97