Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenrequests.c
Go to the documentation of this file.
00001 /* 00002 * ReactOS AMD PCNet Driver 00003 * 00004 * Copyright (C) 2000 Casper Hornstroup <chorns@users.sourceforge.net> 00005 * Copyright (C) 2003 Vizzini <vizzini@plasmic.com> 00006 * Copyright (C) 2004 Filip Navara <navaraf@reactos.com> 00007 * 00008 * This program is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License along 00019 * with this program; if not, write to the Free Software Foundation, Inc., 00020 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00021 * 00022 * PROGRAMMERS: 00023 * Vizzini (vizzini@plasmic.com), 00024 * borrowed very heavily from the ReactOS ne2000 driver by 00025 * Casper S. Hornstrup (chorns@users.sourceforge.net) 00026 * REVISIONS: 00027 * 14-Sep-2003 vizzini - Created 00028 * 17-Oct-2004 navaraf - Add multicast support. 00029 * - Add media state detection support. 00030 * - Protect the adapter context with spinlock 00031 * and move code talking to card to inside 00032 * NdisMSynchronizeWithInterrupt calls where 00033 * necessary. 00034 */ 00035 00036 #include "pcnet.h" 00037 00038 #define NDEBUG 00039 #include <debug.h> 00040 00041 /* List of supported OIDs */ 00042 static ULONG MiniportOIDList[] = 00043 { 00044 OID_GEN_SUPPORTED_LIST, 00045 OID_GEN_HARDWARE_STATUS, 00046 OID_GEN_MEDIA_SUPPORTED, 00047 OID_GEN_MEDIA_IN_USE, 00048 OID_GEN_MAXIMUM_LOOKAHEAD, 00049 OID_GEN_MAXIMUM_FRAME_SIZE, 00050 OID_GEN_LINK_SPEED, 00051 OID_GEN_TRANSMIT_BUFFER_SPACE, 00052 OID_GEN_RECEIVE_BUFFER_SPACE, 00053 OID_GEN_TRANSMIT_BLOCK_SIZE, 00054 OID_GEN_RECEIVE_BLOCK_SIZE, 00055 OID_GEN_VENDOR_ID, 00056 OID_GEN_VENDOR_DESCRIPTION, 00057 OID_GEN_VENDOR_DRIVER_VERSION, 00058 OID_GEN_CURRENT_PACKET_FILTER, 00059 OID_GEN_CURRENT_LOOKAHEAD, 00060 OID_GEN_DRIVER_VERSION, 00061 OID_GEN_MAXIMUM_TOTAL_SIZE, 00062 OID_GEN_PROTOCOL_OPTIONS, 00063 OID_GEN_MAC_OPTIONS, 00064 OID_GEN_MEDIA_CONNECT_STATUS, 00065 OID_GEN_MAXIMUM_SEND_PACKETS, 00066 OID_GEN_XMIT_OK, 00067 OID_GEN_RCV_OK, 00068 OID_GEN_XMIT_ERROR, 00069 OID_GEN_RCV_ERROR, 00070 OID_GEN_RCV_NO_BUFFER, 00071 OID_GEN_RCV_CRC_ERROR, 00072 OID_802_3_PERMANENT_ADDRESS, 00073 OID_802_3_CURRENT_ADDRESS, 00074 OID_802_3_MULTICAST_LIST, 00075 OID_802_3_MAXIMUM_LIST_SIZE, 00076 OID_802_3_MAC_OPTIONS, 00077 OID_802_3_RCV_ERROR_ALIGNMENT, 00078 OID_802_3_XMIT_ONE_COLLISION, 00079 OID_802_3_XMIT_MORE_COLLISIONS 00080 }; 00081 00082 00083 NDIS_STATUS 00084 NTAPI 00085 MiniportQueryInformation( 00086 IN NDIS_HANDLE MiniportAdapterContext, 00087 IN NDIS_OID Oid, 00088 IN PVOID InformationBuffer, 00089 IN ULONG InformationBufferLength, 00090 OUT PULONG BytesWritten, 00091 OUT PULONG BytesNeeded) 00092 /* 00093 * FUNCTION: Query an OID from the driver 00094 * ARGUMENTS: 00095 * MiniportAdapterContext: context originally passed to NdisMSetAttributes 00096 * Oid: OID NDIS is querying 00097 * InformationBuffer: pointer to buffer into which to write the results of the query 00098 * InformationBufferLength: size in bytes of InformationBuffer 00099 * BytesWritten: number of bytes written into InformationBuffer in response to the query 00100 * BytesNeeded: number of bytes needed to answer the query 00101 * RETURNS: 00102 * NDIS_STATUS_SUCCESS on all queries 00103 * NOTES: 00104 * - Called by NDIS at DISPATCH_LEVEL 00105 * - If InformationBufferLength is insufficient to store the results, return the amount 00106 * needed in BytesNeeded and return NDIS_STATUS_INVALID_LENGTH 00107 * TODO: 00108 * - Update to verify input buffer & size and return insufficient buffer codes 00109 */ 00110 { 00111 NDIS_STATUS Status; 00112 PVOID CopyFrom; 00113 UINT CopySize; 00114 ULONG GenericULONG; 00115 PADAPTER Adapter = (PADAPTER)MiniportAdapterContext; 00116 00117 DPRINT("Called. OID 0x%x\n", Oid); 00118 00119 ASSERT(Adapter); 00120 00121 NdisAcquireSpinLock(&Adapter->Lock); 00122 00123 Status = NDIS_STATUS_SUCCESS; 00124 CopyFrom = (PVOID)&GenericULONG; 00125 CopySize = sizeof(ULONG); 00126 00127 switch (Oid) 00128 { 00129 case OID_GEN_SUPPORTED_LIST: 00130 { 00131 CopyFrom = (PVOID)&MiniportOIDList; 00132 CopySize = sizeof(MiniportOIDList); 00133 break; 00134 } 00135 00136 case OID_GEN_HARDWARE_STATUS: 00137 { 00138 GenericULONG = (ULONG)NdisHardwareStatusReady; 00139 break; 00140 } 00141 00142 case OID_GEN_MEDIA_SUPPORTED: 00143 case OID_GEN_MEDIA_IN_USE: 00144 { 00145 static const NDIS_MEDIUM Medium = NdisMedium802_3; 00146 CopyFrom = (PVOID)&Medium; 00147 CopySize = sizeof(NDIS_MEDIUM); 00148 break; 00149 } 00150 00151 case OID_GEN_CURRENT_LOOKAHEAD: 00152 case OID_GEN_MAXIMUM_LOOKAHEAD: 00153 { 00154 GenericULONG = 1500; 00155 break; 00156 } 00157 00158 case OID_GEN_MAXIMUM_FRAME_SIZE: 00159 { 00160 /* 00161 * The value returned by this OID must be equal to 00162 * OID_GEN_MAXIMUM_TOTAL_SIZE - sizeof(ETHERNET_HEADER) 00163 * where sizeof(ETHERNET_HEADER) is 14. 00164 */ 00165 GenericULONG = 1500; 00166 break; 00167 } 00168 00169 case OID_GEN_LINK_SPEED: 00170 { 00171 GenericULONG = Adapter->MediaSpeed * 10000; 00172 break; 00173 } 00174 00175 case OID_GEN_TRANSMIT_BUFFER_SPACE: 00176 { 00177 /* XXX fix me */ 00178 GenericULONG = BUFFER_SIZE; 00179 break; 00180 } 00181 00182 case OID_GEN_RECEIVE_BUFFER_SPACE: 00183 { 00184 /* XXX fix me */ 00185 GenericULONG = BUFFER_SIZE; 00186 break; 00187 } 00188 00189 case OID_GEN_TRANSMIT_BLOCK_SIZE: 00190 { 00191 GenericULONG = BUFFER_SIZE; 00192 break; 00193 } 00194 00195 case OID_GEN_RECEIVE_BLOCK_SIZE: 00196 { 00197 GenericULONG = BUFFER_SIZE; 00198 break; 00199 } 00200 00201 case OID_GEN_VENDOR_ID: 00202 { 00203 UCHAR *CharPtr = (UCHAR *)&GenericULONG; 00204 GenericULONG = 0; 00205 /* Read the first three bytes of the permanent MAC address */ 00206 NdisRawReadPortUchar(Adapter->PortOffset, CharPtr); 00207 NdisRawReadPortUchar(Adapter->PortOffset + 1, CharPtr + 1); 00208 NdisRawReadPortUchar(Adapter->PortOffset + 2, CharPtr + 2); 00209 break; 00210 } 00211 00212 case OID_GEN_VENDOR_DESCRIPTION: 00213 { 00214 static UCHAR VendorDesc[] = "ReactOS Team"; 00215 CopyFrom = VendorDesc; 00216 CopySize = sizeof(VendorDesc); 00217 break; 00218 } 00219 00220 case OID_GEN_VENDOR_DRIVER_VERSION: 00221 { 00222 /* XXX implement me */ 00223 GenericULONG = 1; 00224 break; 00225 } 00226 00227 case OID_GEN_CURRENT_PACKET_FILTER: 00228 { 00229 GenericULONG = Adapter->CurrentPacketFilter; 00230 break; 00231 } 00232 00233 case OID_GEN_DRIVER_VERSION: 00234 { 00235 /* NDIS version used by the driver. */ 00236 static const USHORT DriverVersion = 00237 (NDIS_MINIPORT_MAJOR_VERSION << 8) + NDIS_MINIPORT_MINOR_VERSION; 00238 CopyFrom = (PVOID)&DriverVersion; 00239 CopySize = sizeof(DriverVersion); 00240 break; 00241 } 00242 00243 case OID_GEN_MAXIMUM_TOTAL_SIZE: 00244 { 00245 /* See comment in OID_GEN_MAXIMUM_FRAME_SIZE. */ 00246 GenericULONG = 1514; 00247 break; 00248 } 00249 00250 case OID_GEN_PROTOCOL_OPTIONS: 00251 { 00252 DPRINT("OID_GEN_PROTOCOL_OPTIONS.\n"); 00253 Status = NDIS_STATUS_NOT_SUPPORTED; 00254 break; 00255 } 00256 00257 case OID_GEN_MAC_OPTIONS: 00258 { 00259 GenericULONG = NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA | 00260 NDIS_MAC_OPTION_RECEIVE_SERIALIZED | 00261 NDIS_MAC_OPTION_TRANSFERS_NOT_PEND | 00262 NDIS_MAC_OPTION_NO_LOOPBACK; 00263 break; 00264 } 00265 00266 case OID_GEN_MEDIA_CONNECT_STATUS: 00267 { 00268 GenericULONG = (ULONG)NdisMediaStateConnected; /* Adapter->MediaState */ 00269 break; 00270 } 00271 00272 case OID_GEN_MAXIMUM_SEND_PACKETS: 00273 { 00274 GenericULONG = 1; 00275 break; 00276 } 00277 00278 case OID_802_3_CURRENT_ADDRESS: 00279 case OID_802_3_PERMANENT_ADDRESS: 00280 { 00281 CopyFrom = (PVOID)&Adapter->InitializationBlockVirt->PADR; 00282 CopySize = 6; 00283 break; 00284 } 00285 00286 case OID_802_3_MAXIMUM_LIST_SIZE: 00287 { 00288 GenericULONG = MAX_MULTICAST_ADDRESSES; 00289 break; 00290 } 00291 00292 case OID_GEN_XMIT_OK: 00293 GenericULONG = Adapter->Statistics.XmtGoodFrames; 00294 break; 00295 00296 case OID_GEN_RCV_OK: 00297 GenericULONG = Adapter->Statistics.RcvGoodFrames; 00298 break; 00299 00300 case OID_GEN_XMIT_ERROR: 00301 GenericULONG = Adapter->Statistics.XmtRetryErrors + 00302 Adapter->Statistics.XmtLossesOfCarrier + 00303 Adapter->Statistics.XmtCollisions + 00304 Adapter->Statistics.XmtLateCollisions + 00305 Adapter->Statistics.XmtExcessiveDefferals + 00306 Adapter->Statistics.XmtBufferUnderflows + 00307 Adapter->Statistics.XmtBufferErrors; 00308 break; 00309 00310 case OID_GEN_RCV_ERROR: 00311 GenericULONG = Adapter->Statistics.RcvBufferErrors + 00312 Adapter->Statistics.RcvCrcErrors + 00313 Adapter->Statistics.RcvOverflowErrors + 00314 Adapter->Statistics.RcvFramingErrors; 00315 break; 00316 00317 case OID_GEN_RCV_NO_BUFFER: 00318 GenericULONG = Adapter->Statistics.RcvBufferErrors + 00319 Adapter->Statistics.RcvOverflowErrors; 00320 break; 00321 00322 case OID_GEN_RCV_CRC_ERROR: 00323 GenericULONG = Adapter->Statistics.RcvCrcErrors; 00324 break; 00325 00326 case OID_802_3_RCV_ERROR_ALIGNMENT: 00327 GenericULONG = Adapter->Statistics.RcvFramingErrors; 00328 break; 00329 00330 case OID_802_3_XMIT_ONE_COLLISION: 00331 GenericULONG = Adapter->Statistics.XmtOneRetry; 00332 break; 00333 00334 case OID_802_3_XMIT_MORE_COLLISIONS: 00335 GenericULONG = Adapter->Statistics.XmtMoreThanOneRetry; 00336 break; 00337 00338 default: 00339 { 00340 DPRINT1("Unknown OID\n"); 00341 Status = NDIS_STATUS_NOT_SUPPORTED; 00342 break; 00343 } 00344 } 00345 00346 if (Status == NDIS_STATUS_SUCCESS) 00347 { 00348 if (CopySize > InformationBufferLength) 00349 { 00350 *BytesNeeded = CopySize; 00351 *BytesWritten = 0; 00352 Status = NDIS_STATUS_INVALID_LENGTH; 00353 } 00354 else 00355 { 00356 NdisMoveMemory(InformationBuffer, CopyFrom, CopySize); 00357 *BytesWritten = CopySize; 00358 *BytesNeeded = CopySize; 00359 } 00360 } 00361 else 00362 { 00363 *BytesWritten = 0; 00364 *BytesNeeded = 0; 00365 } 00366 00367 NdisReleaseSpinLock(&Adapter->Lock); 00368 00369 DPRINT("Leaving. Status is 0x%x\n", Status); 00370 00371 return Status; 00372 } 00373 00374 NDIS_STATUS 00375 NTAPI 00376 MiniportSetInformation( 00377 IN NDIS_HANDLE MiniportAdapterContext, 00378 IN NDIS_OID Oid, 00379 IN PVOID InformationBuffer, 00380 IN ULONG InformationBufferLength, 00381 OUT PULONG BytesRead, 00382 OUT PULONG BytesNeeded) 00383 /* 00384 * FUNCTION: Set a miniport variable (OID) 00385 * ARGUMENTS: 00386 * MiniportAdapterContext: context originally passed into NdisMSetAttributes 00387 * Oid: the variable being set 00388 * InformationBuffer: the data to set the variable to 00389 * InformationBufferLength: number of bytes in InformationBuffer 00390 * BytesRead: number of bytes read by us out of the buffer 00391 * BytesNeeded: number of bytes required to satisfy the request if InformationBufferLength 00392 * is insufficient 00393 * RETURNS: 00394 * NDIS_STATUS_SUCCESS on all requests 00395 * NOTES: 00396 * - Called by NDIS at DISPATCH_LEVEL 00397 * - verify buffer space as mentioned in previous function notes 00398 */ 00399 { 00400 ULONG GenericULONG; 00401 NDIS_STATUS Status = NDIS_STATUS_SUCCESS; 00402 PADAPTER Adapter = (PADAPTER)MiniportAdapterContext; 00403 00404 ASSERT(Adapter); 00405 00406 DPRINT("Called, OID 0x%x\n", Oid); 00407 00408 NdisAcquireSpinLock(&Adapter->Lock); 00409 00410 switch (Oid) 00411 { 00412 case OID_GEN_CURRENT_PACKET_FILTER: 00413 { 00414 /* Verify length */ 00415 if (InformationBufferLength < sizeof(ULONG)) 00416 { 00417 *BytesRead = 0; 00418 *BytesNeeded = sizeof(ULONG); 00419 Status = NDIS_STATUS_INVALID_LENGTH; 00420 break; 00421 } 00422 00423 NdisMoveMemory(&GenericULONG, InformationBuffer, sizeof(ULONG)); 00424 00425 /* Check for properties the driver don't support */ 00426 if (GenericULONG & 00427 (NDIS_PACKET_TYPE_ALL_FUNCTIONAL | 00428 NDIS_PACKET_TYPE_FUNCTIONAL | 00429 NDIS_PACKET_TYPE_GROUP | 00430 NDIS_PACKET_TYPE_MAC_FRAME | 00431 NDIS_PACKET_TYPE_SMT | 00432 NDIS_PACKET_TYPE_SOURCE_ROUTING) 00433 ) 00434 { 00435 *BytesRead = sizeof(ULONG); 00436 *BytesNeeded = 0; 00437 Status = NDIS_STATUS_NOT_SUPPORTED; 00438 break; 00439 } 00440 00441 Adapter->CurrentPacketFilter = GenericULONG; 00442 00443 /* FIXME: Set filter on hardware */ 00444 00445 break; 00446 } 00447 00448 case OID_GEN_CURRENT_LOOKAHEAD: 00449 { 00450 /* Verify length */ 00451 if (InformationBufferLength < sizeof(ULONG)) 00452 { 00453 *BytesRead = 0; 00454 *BytesNeeded = sizeof(ULONG); 00455 Status = NDIS_STATUS_INVALID_LENGTH; 00456 break; 00457 } 00458 00459 NdisMoveMemory(&GenericULONG, InformationBuffer, sizeof(ULONG)); 00460 00461 if (GenericULONG > 1500) 00462 Status = NDIS_STATUS_INVALID_DATA; 00463 else 00464 Adapter->CurrentLookaheadSize = GenericULONG; 00465 00466 break; 00467 } 00468 00469 case OID_802_3_MULTICAST_LIST: 00470 { 00471 /* Verify length. Must be multiple of hardware address length */ 00472 if ((InformationBufferLength % 6) != 0) 00473 { 00474 *BytesRead = 0; 00475 *BytesNeeded = InformationBufferLength + (InformationBufferLength % 6); 00476 Status = NDIS_STATUS_INVALID_LENGTH; 00477 break; 00478 } 00479 00480 ASSERT((InformationBufferLength / 6) <= MAX_MULTICAST_ADDRESSES); 00481 00482 /* Set new multicast address list */ 00483 //NdisMoveMemory(Adapter->Addresses, InformationBuffer, InformationBufferLength); 00484 00485 /* Update hardware */ 00486 Status = MiSetMulticast(Adapter, InformationBuffer, InformationBufferLength / 6); 00487 00488 break; 00489 } 00490 00491 default: 00492 { 00493 DPRINT1("Invalid object ID (0x%X).\n", Oid); 00494 *BytesRead = 0; 00495 *BytesNeeded = 0; 00496 Status = NDIS_STATUS_NOT_SUPPORTED; 00497 break; 00498 } 00499 } 00500 00501 if (Status == NDIS_STATUS_SUCCESS) 00502 { 00503 *BytesRead = InformationBufferLength; 00504 *BytesNeeded = 0; 00505 } 00506 00507 NdisReleaseSpinLock(&Adapter->Lock); 00508 00509 DPRINT("Leaving. Status (0x%X).\n", Status); 00510 00511 return Status; 00512 } 00513 Generated on Sun May 27 2012 04:28:04 for ReactOS by
1.7.6.1
|