From 3e3d34d97b7b687bac71d48269e7279d5ea0a6de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Wed, 13 Dec 2023 19:54:50 +0100 Subject: [PATCH] [TCPIP] Get max link speed, MTU and max packet size when adapter is connected --- drivers/network/tcpip/datalink/lan.c | 73 +++++++++++++--------------- drivers/network/tcpip/include/lan.h | 2 +- 2 files changed, 34 insertions(+), 41 deletions(-) diff --git a/drivers/network/tcpip/datalink/lan.c b/drivers/network/tcpip/datalink/lan.c index 0440c098f49..ccd0f555ef5 100644 --- a/drivers/network/tcpip/datalink/lan.c +++ b/drivers/network/tcpip/datalink/lan.c @@ -718,7 +718,7 @@ BOOLEAN ReconfigureAdapter(PRECONFIGURE_CONTEXT Context) { PLAN_ADAPTER Adapter = Context->Adapter; PIP_INTERFACE Interface = Adapter->Context; - //NDIS_STATUS NdisStatus; + NDIS_STATUS NdisStatus; IP_ADDRESS DefaultMask; /* Initialize the default unspecified address (0.0.0.0) */ @@ -754,48 +754,41 @@ BOOLEAN ReconfigureAdapter(PRECONFIGURE_CONTEXT Context) TCPUpdateInterfaceIPInformation(Interface); TCPUpdateInterfaceLinkStatus(Interface); - /* We're done here if the adapter isn't connected */ - if (Context->State != LAN_STATE_STARTED) + if (Context->State == LAN_STATE_STARTED) { - Adapter->State = Context->State; - return TRUE; + /* Get maximum link speed */ + NdisStatus = NDISCall(Adapter, + NdisRequestQueryInformation, + OID_GEN_LINK_SPEED, + &Interface->Speed, + sizeof(Interface->Speed)); + + if (!NT_SUCCESS(NdisStatus)) + Interface->Speed = IP_DEFAULT_LINK_SPEED; + + Adapter->Speed = Interface->Speed * 100L; + + /* Get maximum frame size */ + NdisStatus = NDISCall(Adapter, + NdisRequestQueryInformation, + OID_GEN_MAXIMUM_FRAME_SIZE, + &Adapter->MTU, + sizeof(Adapter->MTU)); + if (NdisStatus != NDIS_STATUS_SUCCESS) + return FALSE; + + Interface->MTU = Adapter->MTU; + + /* Get maximum packet size */ + NdisStatus = NDISCall(Adapter, + NdisRequestQueryInformation, + OID_GEN_MAXIMUM_TOTAL_SIZE, + &Adapter->MaxPacketSize, + sizeof(Adapter->MaxPacketSize)); + if (NdisStatus != NDIS_STATUS_SUCCESS) + return FALSE; } - /* NDIS Bug! */ -#if 0 - /* Get maximum link speed */ - NdisStatus = NDISCall(Adapter, - NdisRequestQueryInformation, - OID_GEN_LINK_SPEED, - &Interface->Speed, - sizeof(UINT)); - - if (!NT_SUCCESS(NdisStatus)) - Interface->Speed = IP_DEFAULT_LINK_SPEED; - - Adapter->Speed = Interface->Speed * 100L; - - /* Get maximum frame size */ - NdisStatus = NDISCall(Adapter, - NdisRequestQueryInformation, - OID_GEN_MAXIMUM_FRAME_SIZE, - &Adapter->MTU, - sizeof(UINT)); - if (NdisStatus != NDIS_STATUS_SUCCESS) - return FALSE; - - Interface->MTU = Adapter->MTU; - - /* Get maximum packet size */ - NdisStatus = NDISCall(Adapter, - NdisRequestQueryInformation, - OID_GEN_MAXIMUM_TOTAL_SIZE, - &Adapter->MaxPacketSize, - sizeof(UINT)); - if (NdisStatus != NDIS_STATUS_SUCCESS) - return FALSE; -#endif - Adapter->State = Context->State; return TRUE; diff --git a/drivers/network/tcpip/include/lan.h b/drivers/network/tcpip/include/lan.h index ab8f4bc5ba6..f99f588188e 100644 --- a/drivers/network/tcpip/include/lan.h +++ b/drivers/network/tcpip/include/lan.h @@ -52,7 +52,7 @@ typedef struct LAN_ADAPTER { UCHAR BCastCheck; /* Value to check against */ UCHAR BCastOffset; /* Offset in frame to check against */ UCHAR HeaderSize; /* Size of link-level header */ - USHORT MTU; /* Maximum Transfer Unit */ + UINT MTU; /* Maximum Transfer Unit */ UINT MinFrameSize; /* Minimum frame size in bytes */ UINT MaxPacketSize; /* Maximum packet size when sending */ UINT MaxSendPackets; /* Maximum number of packets per send */