- Merge aicom-network-fixes up to r39995

svn path=/trunk/; revision=40004
This commit is contained in:
Cameron Gutman 2009-03-13 17:25:48 +00:00
parent 8ae1a88a0b
commit 3f46303c0e
5 changed files with 105 additions and 130 deletions

View file

@ -70,23 +70,20 @@ AfdGetInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp,
}
NTSTATUS NTAPI
AfdGetSockOrPeerName( PDEVICE_OBJECT DeviceObject, PIRP Irp,
PIO_STACK_LOCATION IrpSp, BOOLEAN Local ) {
AfdGetSockName( PDEVICE_OBJECT DeviceObject, PIRP Irp,
PIO_STACK_LOCATION IrpSp ) {
NTSTATUS Status = STATUS_SUCCESS;
PFILE_OBJECT FileObject = IrpSp->FileObject;
PAFD_FCB FCB = FileObject->FsContext;
PMDL Mdl = NULL, SysMdl = NULL;
PTDI_CONNECTION_INFORMATION ConnInfo = NULL;
PTRANSPORT_ADDRESS TransAddr = NULL;
HANDLE ProcHandle = NULL;
BOOLEAN UnlockSysMdl = FALSE;
PVOID UserSpace = NULL;
ULONG Length, InOutLength;
AFD_DbgPrint(MID_TRACE,("Called on %x\n", FCB));
PMDL Mdl = NULL;
if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
if( FCB->AddressFile.Object == NULL && FCB->Connection.Object == NULL ) {
return UnlockAndMaybeComplete( FCB, STATUS_INVALID_PARAMETER, Irp, 0,
NULL );
}
Mdl = IoAllocateMdl
( Irp->UserBuffer,
IrpSp->Parameters.DeviceIoControl.OutputBufferLength,
@ -103,124 +100,69 @@ AfdGetSockOrPeerName( PDEVICE_OBJECT DeviceObject, PIRP Irp,
} _SEH2_END;
if( NT_SUCCESS(Status) ) {
if( Local ) {
if( FCB->AddressFile.Object == NULL ) {
return UnlockAndMaybeComplete( FCB, STATUS_INVALID_PARAMETER, Irp, 0,
NULL );
}
Status = TdiQueryInformation
( FCB->Connection.Object ?
FCB->Connection.Object : FCB->AddressFile.Object,
( FCB->Connection.Object ? FCB->Connection.Object : FCB->AddressFile.Object,
TDI_QUERY_ADDRESS_INFO,
Mdl );
} else {
// what follows is fucked up shit.
// i'm not sure how to avoid it
// sorry
// -- arty
if( FCB->Connection.Object == NULL || (FCB->State != SOCKET_STATE_BOUND && FCB->State != SOCKET_STATE_CONNECTED) ) {
return UnlockAndMaybeComplete( FCB, STATUS_INVALID_PARAMETER, Irp, 0,
NULL );
}
if( NT_SUCCESS
( Status = TdiBuildNullConnectionInfo
( &ConnInfo,
FCB->RemoteAddress->Address[0].AddressType ) ) ) {
Length = TaLengthOfTransportAddress
(ConnInfo->RemoteAddress);
if (NT_SUCCESS(Status))
Status = ObOpenObjectByPointer
(PsGetCurrentProcess(),
0,
NULL,
PROCESS_ALL_ACCESS,
PsProcessType,
KernelMode,
&ProcHandle);
if (NT_SUCCESS(Status))
{
InOutLength =
PAGE_ROUND_UP(sizeof(TDI_CONNECTION_INFO));
Status = NtAllocateVirtualMemory
(ProcHandle,
(PVOID*)&UserSpace,
PAGE_SHIFT,
&InOutLength,
MEM_COMMIT,
PAGE_READWRITE);
}
if (NT_SUCCESS(Status))
{
ExFreePool(ConnInfo);
ConnInfo = (PTDI_CONNECTION_INFORMATION)UserSpace;
SysMdl = IoAllocateMdl
( UserSpace, Length, FALSE, FALSE, NULL );
}
else
{
ExFreePool(ConnInfo);
ConnInfo = NULL;
}
}
if( SysMdl ) {
_SEH2_TRY {
MmProbeAndLockPages( SysMdl, Irp->RequestorMode, IoModifyAccess );
UnlockSysMdl = TRUE;
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
Status = _SEH2_GetExceptionCode();
} _SEH2_END;
} else Status = STATUS_NO_MEMORY;
if( NT_SUCCESS(Status) ) {
Status = TdiQueryInformation
( FCB->Connection.Object,
TDI_QUERY_CONNECTION_INFO,
SysMdl );
}
if( NT_SUCCESS(Status) ) {
TransAddr =
(PTRANSPORT_ADDRESS)MmGetSystemAddressForMdlSafe( Mdl, NormalPagePriority );
if( TransAddr )
RtlCopyMemory( TransAddr, ConnInfo->RemoteAddress,
TaLengthOfTransportAddress
( ConnInfo->RemoteAddress ) );
else Status = STATUS_INSUFFICIENT_RESOURCES;
}
if (UnlockSysMdl)
MmUnlockPages( SysMdl );
if( SysMdl ) IoFreeMdl( SysMdl );
if( ConnInfo )
NtFreeVirtualMemory
( ProcHandle,
(PVOID)ConnInfo,
&InOutLength,
MEM_RELEASE );
if( ProcHandle ) NtClose(ProcHandle);
if( TransAddr ) MmUnmapLockedPages( TransAddr, Mdl );
MmUnlockPages( Mdl );
IoFreeMdl( Mdl );
}
}
} else {
Status = STATUS_INSUFFICIENT_RESOURCES;
}
AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
}
} else
Status = STATUS_INSUFFICIENT_RESOURCES;
return UnlockAndMaybeComplete( FCB, Status, Irp, 0, NULL );
}
NTSTATUS NTAPI
AfdGetPeerName( PDEVICE_OBJECT DeviceObject, PIRP Irp,
PIO_STACK_LOCATION IrpSp ) {
NTSTATUS Status = STATUS_SUCCESS;
PFILE_OBJECT FileObject = IrpSp->FileObject;
PAFD_FCB FCB = FileObject->FsContext;
PMDL Mdl = NULL;
PTDI_CONNECTION_INFORMATION ConnInfo = NULL;
if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
if (FCB->RemoteAddress == NULL || FCB->Connection.Object == NULL) {
return UnlockAndMaybeComplete( FCB, STATUS_INVALID_PARAMETER, Irp, 0, NULL );
}
if(NT_SUCCESS(Status = TdiBuildNullConnectionInfo
(&ConnInfo,
FCB->RemoteAddress->Address[0].AddressType)))
{
Mdl = IoAllocateMdl(ConnInfo,
sizeof(TDI_CONNECTION_INFORMATION) +
TaLengthOfTransportAddress(ConnInfo->RemoteAddress),
FALSE,
FALSE,
NULL);
if (Mdl)
{
_SEH2_TRY {
MmProbeAndLockPages(Mdl, Irp->RequestorMode, IoModifyAccess);
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
Status = _SEH2_GetExceptionCode();
} _SEH2_END;
if (NT_SUCCESS(Status))
{
Status = TdiQueryInformation(FCB->Connection.Object,
TDI_QUERY_CONNECTION_INFO,
Mdl);
if (NT_SUCCESS(Status))
{
RtlCopyMemory(Irp->UserBuffer, ConnInfo->RemoteAddress, TaLengthOfTransportAddress
(ConnInfo->RemoteAddress));
}
}
}
ExFreePool(ConnInfo);
}
return UnlockAndMaybeComplete( FCB, Status, Irp, 0, NULL );
}

View file

@ -413,10 +413,10 @@ AfdDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
return AfdDisconnect( DeviceObject, Irp, IrpSp );
case IOCTL_AFD_GET_SOCK_NAME:
return AfdGetSockOrPeerName( DeviceObject, Irp, IrpSp, TRUE );
return AfdGetSockName( DeviceObject, Irp, IrpSp );
case IOCTL_AFD_GET_PEER_NAME:
return AfdGetSockOrPeerName( DeviceObject, Irp, IrpSp, FALSE );
return AfdGetPeerName( DeviceObject, Irp, IrpSp );
case IOCTL_AFD_GET_TDI_HANDLES:
AFD_DbgPrint(MIN_TRACE, ("IOCTL_AFD_GET_TDI_HANDLES\n"));

View file

@ -237,8 +237,12 @@ AfdGetInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp,
PIO_STACK_LOCATION IrpSp );
NTSTATUS NTAPI
AfdGetSockOrPeerName( PDEVICE_OBJECT DeviceObject, PIRP Irp,
PIO_STACK_LOCATION IrpSp, BOOLEAN Local );
AfdGetSockName( PDEVICE_OBJECT DeviceObject, PIRP Irp,
PIO_STACK_LOCATION IrpSp );
NTSTATUS NTAPI
AfdGetPeerName( PDEVICE_OBJECT DeviceObject, PIRP Irp,
PIO_STACK_LOCATION IrpSp );
/* listen.c */
NTSTATUS AfdWaitForListen( PDEVICE_OBJECT DeviceObject, PIRP Irp,

View file

@ -830,6 +830,9 @@ MiniportInitialize(
PADAPTER Adapter = 0;
NDIS_STATUS Status = NDIS_STATUS_FAILURE;
BOOLEAN InterruptRegistered = FALSE;
NDIS_HANDLE ConfigurationHandle;
UINT *RegNetworkAddress = 0;
UINT RegNetworkAddressLength = 0;
ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
@ -924,6 +927,25 @@ MiniportInitialize(
/* set up the initialization block */
MiPrepareInitializationBlock(Adapter);
/* see if someone set a network address manually */
NdisOpenConfiguration(&Status, &ConfigurationHandle, WrapperConfigurationContext);
if (Status == NDIS_STATUS_SUCCESS)
{
NdisReadNetworkAddress(&Status, (PVOID *)&RegNetworkAddress, &RegNetworkAddressLength, ConfigurationHandle);
if(Status == NDIS_STATUS_SUCCESS && RegNetworkAddressLength == 6)
{
int i;
DPRINT("NdisReadNetworkAddress returned successfully, address %x:%x:%x:%x:%x:%x\n",
RegNetworkAddress[0], RegNetworkAddress[1], RegNetworkAddress[2], RegNetworkAddress[3],
RegNetworkAddress[4], RegNetworkAddress[5]);
for(i = 0; i < 6; i++)
Adapter->InitializationBlockVirt->PADR[i] = RegNetworkAddress[i];
}
NdisCloseConfiguration(ConfigurationHandle);
}
DPRINT("Interrupt registered successfully\n");
/* Initialize and start the chip */

View file

@ -713,6 +713,13 @@ NdisReadNetworkAddress(
*NetworkAddressLength = (UINT)((j/2)+0.5);
if (j == 0)
{
NDIS_DbgPrint(MIN_TRACE,("Empty NetworkAddress registry entry.\n"));
*Status = NDIS_STATUS_FAILURE;
return;
}
IntArray = ExAllocatePool(PagedPool, (*NetworkAddressLength)*sizeof(UINT));
if(!IntArray)
{