Author: cgutman
Date: Fri Jan 13 22:38:28 2012
New Revision: 54944
URL:
http://svn.reactos.org/svn/reactos?rev=54944&view=rev
Log:
[TCPIP]
- Queue a work item from the ProtocolStatus handler so we can refresh the state from the
registry instead relying on hacks to track our state
Modified:
branches/wlan-bringup/drivers/network/tcpip/datalink/lan.c
branches/wlan-bringup/drivers/network/tcpip/include/ip.h
branches/wlan-bringup/drivers/network/tcpip/include/lan.h
branches/wlan-bringup/drivers/network/tcpip/tcpip/dispatch.c
branches/wlan-bringup/lib/drivers/ip/network/ip.c
Modified: branches/wlan-bringup/drivers/network/tcpip/datalink/lan.c
URL:
http://svn.reactos.org/svn/reactos/branches/wlan-bringup/drivers/network/tc…
==============================================================================
--- branches/wlan-bringup/drivers/network/tcpip/datalink/lan.c [iso-8859-1] (original)
+++ branches/wlan-bringup/drivers/network/tcpip/datalink/lan.c [iso-8859-1] Fri Jan 13
22:38:28 2012
@@ -23,6 +23,11 @@
UINT BytesTransferred;
BOOLEAN LegacyReceive;
} LAN_WQ_ITEM, *PLAN_WQ_ITEM;
+
+typedef struct _RECONFIGURE_CONTEXT {
+ ULONG State;
+ PLAN_ADAPTER Adapter;
+} RECONFIGURE_CONTEXT, *PRECONFIGURE_CONTEXT;
NDIS_HANDLE NdisProtocolHandle = (NDIS_HANDLE)NULL;
BOOLEAN ProtocolRegistered = FALSE;
@@ -571,6 +576,9 @@
ANSI_STRING RegistryDataA;
ULONG Unused;
NTSTATUS Status;
+ IP_ADDRESS DefaultMask, Router;
+
+ AddrInitIPv4(&DefaultMask, 0);
TcpipRegistryPath.MaximumLength = sizeof(WCHAR) * 150;
TcpipRegistryPath.Length = 0;
@@ -591,8 +599,7 @@
if (!NT_SUCCESS(Status))
{
- Interface->DhcpEnabled = TRUE;
- return TRUE;
+ return FALSE;
}
else
{
@@ -630,10 +637,12 @@
&RegistryDataU,
TRUE);
- AddrInitIPv4(&Interface->StaticUnicast,
inet_addr(RegistryDataA.Buffer));
+ AddrInitIPv4(&Interface->Unicast,
inet_addr(RegistryDataA.Buffer));
+
+ if (!AddrIsUnspecified(&Interface->Unicast))
+ IPAddInterfaceRoute(Interface);
RtlFreeAnsiString(&RegistryDataA);
-
}
Status = ZwQueryValueKey(ParameterHandle,
@@ -650,7 +659,7 @@
&RegistryDataU,
TRUE);
- AddrInitIPv4(&Interface->StaticNetmask,
inet_addr(RegistryDataA.Buffer));
+ AddrInitIPv4(&Interface->Netmask,
inet_addr(RegistryDataA.Buffer));
RtlFreeAnsiString(&RegistryDataA);
}
@@ -670,16 +679,13 @@
&RegistryDataU,
TRUE);
- AddrInitIPv4(&Interface->StaticRouter,
inet_addr(RegistryDataA.Buffer));
+ AddrInitIPv4(&Router, inet_addr(RegistryDataA.Buffer));
+
+ if (!AddrIsUnspecified(&Router))
+ RouterCreateRoute(&DefaultMask, &DefaultMask, &Router,
Interface, 1);
RtlFreeAnsiString(&RegistryDataA);
}
-
- Interface->DhcpEnabled = FALSE;
- }
- else
- {
- Interface->DhcpEnabled = TRUE;
}
ZwClose(ParameterHandle);
@@ -688,38 +694,27 @@
return TRUE;
}
-BOOLEAN ReconfigureAdapter(PLAN_ADAPTER Adapter, BOOLEAN FinishedReset)
-{
+BOOLEAN ReconfigureAdapter(PRECONFIGURE_CONTEXT Context)
+{
+ PLAN_ADAPTER Adapter = Context->Adapter;
PIP_INTERFACE Interface = Adapter->Context;
//NDIS_STATUS NdisStatus;
IP_ADDRESS DefaultMask;
/* Initalize the default unspecified address (0.0.0.0) */
AddrInitIPv4(&DefaultMask, 0);
- if (Adapter->State == LAN_STATE_STARTED && !FinishedReset)
+ if (Context->State == LAN_STATE_STARTED &&
+ !Context->Adapter->CompletingReset)
{
- /* Set the static IP configuration */
- if (!Interface->DhcpEnabled)
- {
- /* Reset the IP information */
- Interface->Unicast = Interface->StaticUnicast;
- Interface->Netmask = Interface->StaticNetmask;
-
- /* Compute the broadcast address */
- Interface->Broadcast.Type = IP_ADDRESS_V4;
- Interface->Broadcast.Address.IPv4Address =
Interface->Unicast.Address.IPv4Address |
-
~Interface->Netmask.Address.IPv4Address;
-
- /* Add the interface route for a static IP */
- if (!AddrIsUnspecified(&Interface->Unicast))
- IPAddInterfaceRoute(Interface);
-
- /* Add the default route */
- if (!AddrIsUnspecified(&Interface->StaticRouter))
- RouterCreateRoute(&DefaultMask, &DefaultMask,
&Interface->StaticRouter, Interface, 1);
- }
- }
- else if (!FinishedReset)
+ /* Read the IP configuration */
+ ReadIpConfiguration(Interface);
+
+ /* Compute the broadcast address */
+ Interface->Broadcast.Type = IP_ADDRESS_V4;
+ Interface->Broadcast.Address.IPv4Address =
Interface->Unicast.Address.IPv4Address |
+
~Interface->Netmask.Address.IPv4Address;
+ }
+ else if (!Context->Adapter->CompletingReset)
{
/* Clear IP configuration */
Interface->Unicast = DefaultMask;
@@ -732,9 +727,15 @@
/* Destroy all cached neighbors */
NBDestroyNeighborsForInterface(Interface);
}
+
+ Context->Adapter->CompletingReset = FALSE;
/* We're done here if the adapter isn't connected */
- if (Adapter->State != LAN_STATE_STARTED) return TRUE;
+ if (Context->State != LAN_STATE_STARTED)
+ {
+ Adapter->State = Context->State;
+ return TRUE;
+ }
/* NDIS Bug! */
#if 0
@@ -770,8 +771,21 @@
if (NdisStatus != NDIS_STATUS_SUCCESS)
return FALSE;
#endif
+
+ Adapter->State = Context->State;
return TRUE;
+}
+
+VOID ReconfigureAdapterWorker(PVOID Context)
+{
+ PRECONFIGURE_CONTEXT ReconfigureContext = Context;
+
+ /* Complete the reconfiguration asynchronously */
+ ReconfigureAdapter(ReconfigureContext);
+
+ /* Free the context */
+ ExFreePool(ReconfigureContext);
}
VOID NTAPI ProtocolStatus(
@@ -789,8 +803,15 @@
*/
{
PLAN_ADAPTER Adapter = BindingContext;
+ PRECONFIGURE_CONTEXT Context;
TI_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
+
+ Context = ExAllocatePool(NonPagedPool, sizeof(RECONFIGURE_CONTEXT));
+ if (!Context)
+ return;
+
+ Context->Adapter = Adapter;
switch(GeneralStatus)
{
@@ -798,36 +819,47 @@
DbgPrint("NDIS_STATUS_MEDIA_CONNECT\n");
if (Adapter->State == LAN_STATE_STARTED)
- break;
-
- Adapter->OldState = Adapter->State;
- Adapter->State = LAN_STATE_STARTED;
+ {
+ ExFreePool(Context);
+ return;
+ }
+
+ Context->State = LAN_STATE_STARTED;
break;
case NDIS_STATUS_MEDIA_DISCONNECT:
DbgPrint("NDIS_STATUS_MEDIA_DISCONNECT\n");
if (Adapter->State == LAN_STATE_STOPPED)
- break;
+ {
+ ExFreePool(Context);
+ return;
+ }
- Adapter->OldState = Adapter->State;
- Adapter->State = LAN_STATE_STOPPED;
+ Context->State = LAN_STATE_STOPPED;
break;
case NDIS_STATUS_RESET_START:
Adapter->OldState = Adapter->State;
Adapter->State = LAN_STATE_RESETTING;
/* Nothing else to do here */
- break;
+ ExFreePool(Context);
+ return;
case NDIS_STATUS_RESET_END:
- Adapter->State = Adapter->OldState;
+ Adapter->CompletingReset = TRUE;
+ Context->State = Adapter->OldState;
break;
default:
DbgPrint("Unhandled status: %x", GeneralStatus);
- break;
- }
+ ExFreePool(Context);
+ return;
+ }
+
+ /* Queue the work item */
+ if (!ChewCreate(ReconfigureAdapterWorker, Context))
+ ExFreePool(Context);
}
VOID NTAPI ProtocolStatusComplete(NDIS_HANDLE NdisBindingContext)
@@ -837,15 +869,7 @@
* BindingContext = Pointer to a device context (LAN_ADAPTER)
*/
{
- PLAN_ADAPTER Adapter = NdisBindingContext;
-
TI_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
-
- if (Adapter->State != LAN_STATE_RESETTING)
- {
- ReconfigureAdapter(Adapter,
- (Adapter->State == Adapter->OldState));
- }
}
NDIS_STATUS NTAPI
@@ -1361,14 +1385,7 @@
IPRegisterInterface(IF);
/* Set adapter state */
- Adapter->State = LAN_STATE_STARTED;
Adapter->Context = IF;
-
- /* Read adapter IP configuration */
- ReadIpConfiguration(IF);
-
- /* Configure the adapter */
- ReconfigureAdapter(Adapter, FALSE);
/* Set packet filter so we can send and receive packets */
NdisStatus = NDISCall(Adapter,
@@ -1383,6 +1400,9 @@
IPDestroyInterface(IF);
return FALSE;
}
+
+ /* Indicate media connect (our drivers are broken and don't do this) */
+ ProtocolStatus(Adapter, NDIS_STATUS_MEDIA_CONNECT, NULL, 0);
return TRUE;
}
Modified: branches/wlan-bringup/drivers/network/tcpip/include/ip.h
URL:
http://svn.reactos.org/svn/reactos/branches/wlan-bringup/drivers/network/tc…
==============================================================================
--- branches/wlan-bringup/drivers/network/tcpip/include/ip.h [iso-8859-1] (original)
+++ branches/wlan-bringup/drivers/network/tcpip/include/ip.h [iso-8859-1] Fri Jan 13
22:38:28 2012
@@ -156,12 +156,10 @@
UINT MinFrameSize; /* Minimum frame size in bytes */
UINT MTU; /* Maximum transmission unit */
UINT Speed; /* Link speed */
- IP_ADDRESS Unicast, StaticUnicast;/* Unicast address */
- IP_ADDRESS PointToPoint, StaticPointToPoint;/* Point to point address */
- IP_ADDRESS Netmask, StaticNetmask;/* Netmask */
+ IP_ADDRESS Unicast; /* Unicast address */
+ IP_ADDRESS PointToPoint; /* Point to point address */
+ IP_ADDRESS Netmask; /* Netmask */
IP_ADDRESS Broadcast; /* Broadcast */
- IP_ADDRESS StaticRouter; /* Static default route */
- BOOLEAN DhcpEnabled; /* DHCP enabled */
UNICODE_STRING Name; /* Adapter name (GUID) */
UNICODE_STRING Description; /* Adapter description (Human readable) */
PUCHAR Address; /* Pointer to interface address */
Modified: branches/wlan-bringup/drivers/network/tcpip/include/lan.h
URL:
http://svn.reactos.org/svn/reactos/branches/wlan-bringup/drivers/network/tc…
==============================================================================
--- branches/wlan-bringup/drivers/network/tcpip/include/lan.h [iso-8859-1] (original)
+++ branches/wlan-bringup/drivers/network/tcpip/include/lan.h [iso-8859-1] Fri Jan 13
22:38:28 2012
@@ -40,6 +40,7 @@
LIST_ENTRY ListEntry; /* Entry on list */
KSPIN_LOCK Lock; /* Lock for this structure */
UCHAR State, OldState; /* State of the adapter */
+ BOOLEAN CompletingReset; /* Reset is finishing */
KEVENT Event; /* Opening event */
PVOID Context; /* Upper layer context information */
NDIS_HANDLE NdisHandle; /* NDIS binding handle */
Modified: branches/wlan-bringup/drivers/network/tcpip/tcpip/dispatch.c
URL:
http://svn.reactos.org/svn/reactos/branches/wlan-bringup/drivers/network/tc…
==============================================================================
--- branches/wlan-bringup/drivers/network/tcpip/tcpip/dispatch.c [iso-8859-1] (original)
+++ branches/wlan-bringup/drivers/network/tcpip/tcpip/dispatch.c [iso-8859-1] Fri Jan 13
22:38:28 2012
@@ -1552,11 +1552,9 @@
IF->Unicast.Type = IP_ADDRESS_V4;
IF->Unicast.Address.IPv4Address = IpAddrChange->Address;
- IF->StaticUnicast = IF->Unicast;
IF->Netmask.Type = IP_ADDRESS_V4;
IF->Netmask.Address.IPv4Address = IpAddrChange->Netmask;
- IF->StaticNetmask = IF->Netmask;
IF->Broadcast.Type = IP_ADDRESS_V4;
IF->Broadcast.Address.IPv4Address =
@@ -1568,7 +1566,6 @@
TI_DbgPrint(MID_TRACE,("New Netmask : %x\n",
IF->Netmask.Address.IPv4Address));
- IF->DhcpEnabled = FALSE;
IPAddInterfaceRoute( IF );
IpAddrChange->Address = IF->Index;
@@ -1592,16 +1589,13 @@
IPRemoveInterfaceRoute( IF );
IF->Unicast.Type = IP_ADDRESS_V4;
IF->Unicast.Address.IPv4Address = 0;
- IF->StaticUnicast = IF->Unicast;
IF->Netmask.Type = IP_ADDRESS_V4;
IF->Netmask.Address.IPv4Address = 0;
- IF->StaticNetmask = IF->Netmask;
IF->Broadcast.Type = IP_ADDRESS_V4;
IF->Broadcast.Address.IPv4Address = 0;
- IF->DhcpEnabled = TRUE;
Status = STATUS_SUCCESS;
}
} EndFor(IF);
Modified: branches/wlan-bringup/lib/drivers/ip/network/ip.c
URL:
http://svn.reactos.org/svn/reactos/branches/wlan-bringup/lib/drivers/ip/net…
==============================================================================
--- branches/wlan-bringup/lib/drivers/ip/network/ip.c [iso-8859-1] (original)
+++ branches/wlan-bringup/lib/drivers/ip/network/ip.c [iso-8859-1] Fri Jan 13 22:38:28
2012
@@ -214,7 +214,6 @@
IF->PointToPoint.Type = IP_ADDRESS_V4;
IF->Netmask.Type = IP_ADDRESS_V4;
IF->Broadcast.Type = IP_ADDRESS_V4;
- IF->StaticRouter.Type = IP_ADDRESS_V4;
TcpipInitializeSpinLock(&IF->Lock);