mirror of
https://github.com/reactos/reactos.git
synced 2025-04-25 16:10:29 +00:00
- Implement handing for IRP_MN_SET_POWER and IRP_MN_QUERY_POWER (not plugged in yet)
- Allocate a buffer and copy data into it instead of using the buffer passed to us directly - Use a helper function to perform common operations which save lots of lines of duplicated code svn path=/trunk/; revision=40793
This commit is contained in:
parent
3065a6b84c
commit
0af940a81b
2 changed files with 81 additions and 44 deletions
|
@ -2838,6 +2838,7 @@ NdisCompletePnPEvent(
|
|||
|
||||
if (Status != NDIS_STATUS_SUCCESS)
|
||||
{
|
||||
if (NetPnPEvent->Buffer) ExFreePool(NetPnPEvent->Buffer);
|
||||
ExFreePool(NetPnPEvent);
|
||||
Irp->IoStatus.Status = Status;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
@ -2859,6 +2860,7 @@ NdisCompletePnPEvent(
|
|||
}
|
||||
else if (NdisStatus != NDIS_STATUS_SUCCESS)
|
||||
{
|
||||
if (NetPnPEvent->Buffer) ExFreePool(NetPnPEvent->Buffer);
|
||||
ExFreePool(NetPnPEvent);
|
||||
Irp->IoStatus.Status = NdisStatus;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
@ -2868,6 +2870,7 @@ NdisCompletePnPEvent(
|
|||
CurrentEntry = CurrentEntry->Flink;
|
||||
}
|
||||
|
||||
if (NetPnPEvent->Buffer) ExFreePool(NetPnPEvent->Buffer);
|
||||
ExFreePool(NetPnPEvent);
|
||||
|
||||
Irp->IoStatus.Status = NDIS_STATUS_SUCCESS;
|
||||
|
|
|
@ -37,27 +37,33 @@ ProSetupPnPEvent(
|
|||
RtlZeroMemory(PnPEvent, sizeof(NET_PNP_EVENT));
|
||||
|
||||
PnPEvent->NetEvent = EventCode;
|
||||
PnPEvent->Buffer = EventBuffer;
|
||||
PnPEvent->BufferLength = EventBufferLength;
|
||||
|
||||
if (EventBuffer != NULL)
|
||||
{
|
||||
PnPEvent->Buffer = ExAllocatePool(PagedPool, EventBufferLength);
|
||||
if (!PnPEvent->Buffer)
|
||||
{
|
||||
ExFreePool(PnPEvent);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PnPEvent->BufferLength = EventBufferLength;
|
||||
|
||||
RtlCopyMemory(PnPEvent->Buffer, EventBuffer, PnPEvent->BufferLength);
|
||||
}
|
||||
|
||||
return PnPEvent;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
NdisIPnPQueryStopDevice(
|
||||
IN PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp)
|
||||
NDIS_STATUS
|
||||
ProSendAndFreePnPEvent(
|
||||
PLOGICAL_ADAPTER Adapter,
|
||||
PNET_PNP_EVENT PnPEvent,
|
||||
PIRP Irp)
|
||||
{
|
||||
PLIST_ENTRY CurrentEntry;
|
||||
PADAPTER_BINDING AdapterBinding;
|
||||
PLOGICAL_ADAPTER Adapter = (PLOGICAL_ADAPTER)DeviceObject->DeviceExtension;
|
||||
PNET_PNP_EVENT PnPEvent;
|
||||
NDIS_STATUS Status;
|
||||
|
||||
PnPEvent = ProSetupPnPEvent(NetEventQueryRemoveDevice, NULL, 0);
|
||||
if (!PnPEvent)
|
||||
return NDIS_STATUS_RESOURCES;
|
||||
PADAPTER_BINDING AdapterBinding;
|
||||
|
||||
CurrentEntry = Adapter->ProtocolListHead.Flink;
|
||||
|
||||
|
@ -79,7 +85,7 @@ NdisIPnPQueryStopDevice(
|
|||
}
|
||||
else if (Status != NDIS_STATUS_SUCCESS)
|
||||
{
|
||||
/* One protocol failed so we can fail the query stop device IRP */
|
||||
if (PnPEvent->Buffer) ExFreePool(PnPEvent->Buffer);
|
||||
ExFreePool(PnPEvent);
|
||||
return Status;
|
||||
}
|
||||
|
@ -87,53 +93,81 @@ NdisIPnPQueryStopDevice(
|
|||
CurrentEntry = CurrentEntry->Flink;
|
||||
}
|
||||
|
||||
if (PnPEvent->Buffer) ExFreePool(PnPEvent->Buffer);
|
||||
ExFreePool(PnPEvent);
|
||||
|
||||
return NDIS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
NdisIPwrSetPower(
|
||||
IN PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp)
|
||||
{
|
||||
PLOGICAL_ADAPTER Adapter = (PLOGICAL_ADAPTER)DeviceObject->DeviceExtension;
|
||||
PNET_PNP_EVENT PnPEvent;
|
||||
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
|
||||
|
||||
ASSERT(Stack->Parameters.Power.Type == DevicePowerState);
|
||||
|
||||
PnPEvent = ProSetupPnPEvent(NetEventSetPower, &Stack->Parameters.Power.State, sizeof(NDIS_DEVICE_POWER_STATE));
|
||||
if (!PnPEvent)
|
||||
return NDIS_STATUS_RESOURCES;
|
||||
|
||||
return ProSendAndFreePnPEvent(Adapter, PnPEvent, Irp);
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
NdisIPwrQueryPower(
|
||||
IN PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp)
|
||||
{
|
||||
PLOGICAL_ADAPTER Adapter = (PLOGICAL_ADAPTER)DeviceObject->DeviceExtension;
|
||||
PNET_PNP_EVENT PnPEvent;
|
||||
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
|
||||
|
||||
ASSERT(Stack->Parameters.Power.Type == DevicePowerState);
|
||||
|
||||
PnPEvent = ProSetupPnPEvent(NetEventQueryPower, &Stack->Parameters.Power.State, sizeof(NDIS_DEVICE_POWER_STATE));
|
||||
if (!PnPEvent)
|
||||
return NDIS_STATUS_RESOURCES;
|
||||
|
||||
return ProSendAndFreePnPEvent(Adapter, PnPEvent, Irp);
|
||||
}
|
||||
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
NdisIPnPQueryStopDevice(
|
||||
IN PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp)
|
||||
{
|
||||
PLOGICAL_ADAPTER Adapter = (PLOGICAL_ADAPTER)DeviceObject->DeviceExtension;
|
||||
PNET_PNP_EVENT PnPEvent;
|
||||
|
||||
PnPEvent = ProSetupPnPEvent(NetEventQueryRemoveDevice, NULL, 0);
|
||||
if (!PnPEvent)
|
||||
return NDIS_STATUS_RESOURCES;
|
||||
|
||||
return ProSendAndFreePnPEvent(Adapter, PnPEvent, Irp);
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
NdisIPnPCancelStopDevice(
|
||||
IN PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp)
|
||||
{
|
||||
PLIST_ENTRY CurrentEntry;
|
||||
PADAPTER_BINDING AdapterBinding;
|
||||
PLOGICAL_ADAPTER Adapter = (PLOGICAL_ADAPTER)DeviceObject->DeviceExtension;
|
||||
PNET_PNP_EVENT PnPEvent;
|
||||
NDIS_STATUS Status;
|
||||
|
||||
PnPEvent = ProSetupPnPEvent(NetEventCancelRemoveDevice, NULL, 0);
|
||||
if (!PnPEvent)
|
||||
return NDIS_STATUS_RESOURCES;
|
||||
|
||||
CurrentEntry = Adapter->ProtocolListHead.Flink;
|
||||
|
||||
while (CurrentEntry != &Adapter->ProtocolListHead)
|
||||
{
|
||||
AdapterBinding = CONTAINING_RECORD(CurrentEntry, ADAPTER_BINDING, AdapterListEntry);
|
||||
|
||||
Status = (*AdapterBinding->ProtocolBinding->Chars.PnPEventHandler)(
|
||||
AdapterBinding->NdisOpenBlock.ProtocolBindingContext,
|
||||
PnPEvent);
|
||||
|
||||
if (Status == NDIS_STATUS_PENDING)
|
||||
{
|
||||
IoMarkIrpPending(Irp);
|
||||
PnPEvent->NdisReserved[0] = (ULONG_PTR)Irp;
|
||||
PnPEvent->NdisReserved[1] = (ULONG_PTR)CurrentEntry->Flink;
|
||||
return NDIS_STATUS_PENDING;
|
||||
}
|
||||
|
||||
ASSERT(Status == NDIS_STATUS_SUCCESS);
|
||||
|
||||
CurrentEntry = CurrentEntry->Flink;
|
||||
}
|
||||
|
||||
ExFreePool(PnPEvent);
|
||||
|
||||
return NDIS_STATUS_SUCCESS;
|
||||
return ProSendAndFreePnPEvent(Adapter, PnPEvent, Irp);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue