mirror of
https://github.com/reactos/reactos.git
synced 2025-04-26 08:30:21 +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 (Status != NDIS_STATUS_SUCCESS)
|
||||||
{
|
{
|
||||||
|
if (NetPnPEvent->Buffer) ExFreePool(NetPnPEvent->Buffer);
|
||||||
ExFreePool(NetPnPEvent);
|
ExFreePool(NetPnPEvent);
|
||||||
Irp->IoStatus.Status = Status;
|
Irp->IoStatus.Status = Status;
|
||||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||||
|
@ -2859,6 +2860,7 @@ NdisCompletePnPEvent(
|
||||||
}
|
}
|
||||||
else if (NdisStatus != NDIS_STATUS_SUCCESS)
|
else if (NdisStatus != NDIS_STATUS_SUCCESS)
|
||||||
{
|
{
|
||||||
|
if (NetPnPEvent->Buffer) ExFreePool(NetPnPEvent->Buffer);
|
||||||
ExFreePool(NetPnPEvent);
|
ExFreePool(NetPnPEvent);
|
||||||
Irp->IoStatus.Status = NdisStatus;
|
Irp->IoStatus.Status = NdisStatus;
|
||||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||||
|
@ -2868,6 +2870,7 @@ NdisCompletePnPEvent(
|
||||||
CurrentEntry = CurrentEntry->Flink;
|
CurrentEntry = CurrentEntry->Flink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (NetPnPEvent->Buffer) ExFreePool(NetPnPEvent->Buffer);
|
||||||
ExFreePool(NetPnPEvent);
|
ExFreePool(NetPnPEvent);
|
||||||
|
|
||||||
Irp->IoStatus.Status = NDIS_STATUS_SUCCESS;
|
Irp->IoStatus.Status = NDIS_STATUS_SUCCESS;
|
||||||
|
|
|
@ -37,27 +37,33 @@ ProSetupPnPEvent(
|
||||||
RtlZeroMemory(PnPEvent, sizeof(NET_PNP_EVENT));
|
RtlZeroMemory(PnPEvent, sizeof(NET_PNP_EVENT));
|
||||||
|
|
||||||
PnPEvent->NetEvent = EventCode;
|
PnPEvent->NetEvent = EventCode;
|
||||||
PnPEvent->Buffer = EventBuffer;
|
|
||||||
|
if (EventBuffer != NULL)
|
||||||
|
{
|
||||||
|
PnPEvent->Buffer = ExAllocatePool(PagedPool, EventBufferLength);
|
||||||
|
if (!PnPEvent->Buffer)
|
||||||
|
{
|
||||||
|
ExFreePool(PnPEvent);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
PnPEvent->BufferLength = EventBufferLength;
|
PnPEvent->BufferLength = EventBufferLength;
|
||||||
|
|
||||||
|
RtlCopyMemory(PnPEvent->Buffer, EventBuffer, PnPEvent->BufferLength);
|
||||||
|
}
|
||||||
|
|
||||||
return PnPEvent;
|
return PnPEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS
|
NDIS_STATUS
|
||||||
NTAPI
|
ProSendAndFreePnPEvent(
|
||||||
NdisIPnPQueryStopDevice(
|
PLOGICAL_ADAPTER Adapter,
|
||||||
IN PDEVICE_OBJECT DeviceObject,
|
PNET_PNP_EVENT PnPEvent,
|
||||||
PIRP Irp)
|
PIRP Irp)
|
||||||
{
|
{
|
||||||
PLIST_ENTRY CurrentEntry;
|
PLIST_ENTRY CurrentEntry;
|
||||||
PADAPTER_BINDING AdapterBinding;
|
|
||||||
PLOGICAL_ADAPTER Adapter = (PLOGICAL_ADAPTER)DeviceObject->DeviceExtension;
|
|
||||||
PNET_PNP_EVENT PnPEvent;
|
|
||||||
NDIS_STATUS Status;
|
NDIS_STATUS Status;
|
||||||
|
PADAPTER_BINDING AdapterBinding;
|
||||||
PnPEvent = ProSetupPnPEvent(NetEventQueryRemoveDevice, NULL, 0);
|
|
||||||
if (!PnPEvent)
|
|
||||||
return NDIS_STATUS_RESOURCES;
|
|
||||||
|
|
||||||
CurrentEntry = Adapter->ProtocolListHead.Flink;
|
CurrentEntry = Adapter->ProtocolListHead.Flink;
|
||||||
|
|
||||||
|
@ -79,7 +85,7 @@ NdisIPnPQueryStopDevice(
|
||||||
}
|
}
|
||||||
else if (Status != NDIS_STATUS_SUCCESS)
|
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);
|
ExFreePool(PnPEvent);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
@ -87,53 +93,81 @@ NdisIPnPQueryStopDevice(
|
||||||
CurrentEntry = CurrentEntry->Flink;
|
CurrentEntry = CurrentEntry->Flink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (PnPEvent->Buffer) ExFreePool(PnPEvent->Buffer);
|
||||||
ExFreePool(PnPEvent);
|
ExFreePool(PnPEvent);
|
||||||
|
|
||||||
return NDIS_STATUS_SUCCESS;
|
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
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
NdisIPnPCancelStopDevice(
|
NdisIPnPCancelStopDevice(
|
||||||
IN PDEVICE_OBJECT DeviceObject,
|
IN PDEVICE_OBJECT DeviceObject,
|
||||||
PIRP Irp)
|
PIRP Irp)
|
||||||
{
|
{
|
||||||
PLIST_ENTRY CurrentEntry;
|
|
||||||
PADAPTER_BINDING AdapterBinding;
|
|
||||||
PLOGICAL_ADAPTER Adapter = (PLOGICAL_ADAPTER)DeviceObject->DeviceExtension;
|
PLOGICAL_ADAPTER Adapter = (PLOGICAL_ADAPTER)DeviceObject->DeviceExtension;
|
||||||
PNET_PNP_EVENT PnPEvent;
|
PNET_PNP_EVENT PnPEvent;
|
||||||
NDIS_STATUS Status;
|
|
||||||
|
|
||||||
PnPEvent = ProSetupPnPEvent(NetEventCancelRemoveDevice, NULL, 0);
|
PnPEvent = ProSetupPnPEvent(NetEventCancelRemoveDevice, NULL, 0);
|
||||||
if (!PnPEvent)
|
if (!PnPEvent)
|
||||||
return NDIS_STATUS_RESOURCES;
|
return NDIS_STATUS_RESOURCES;
|
||||||
|
|
||||||
CurrentEntry = Adapter->ProtocolListHead.Flink;
|
return ProSendAndFreePnPEvent(Adapter, PnPEvent, Irp);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue