Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to make a USB control request in a timer callback...

68 views
Skip to first unread message

sinosoidal

unread,
Dec 29, 2009, 11:38:01 AM12/29/09
to
Hi,

I'm trying to make the following in a timer callback:

VOID
DpxMttCalibrationStateEvtTimerFunction(
IN WDFTIMER Timer
)
{
NTSTATUS status = STATUS_SUCCESS;
PDEVICE_EXTENSION devContext =
GetDeviceContext(WdfTimerGetParentObject(Timer));

UCHAR CalibrationState;

status = DpxMttGetCalibrationState(devContext,&CalibrationState);

if (status==STATUS_SUCCESS)
{
if (devContext->Context.State.Calibrated==0)
{
if (CalibrationState==1)
devContext->Context.State.Calibrated = 1;
else
devContext->Context.State.Calibrated = 0;
}
}
else
{
devContext->Context.State.Calibrated = 0;
}
}


where

NTSTATUS
DpxMttGetCalibrationState(
IN PDEVICE_EXTENSION devContext,
OUT PUCHAR CalibrationState
)
{
NTSTATUS status = STATUS_SUCCESS;
WDF_MEMORY_DESCRIPTOR memDesc;
WDF_USB_CONTROL_SETUP_PACKET controlSetupPacket;
ULONG bytesTransferred = 0;

WDF_USB_CONTROL_SETUP_PACKET_INIT_VENDOR(&controlSetupPacket,
BmRequestDeviceToHost,
BmRequestToDevice,
0x03,
0,
0);

WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&memDesc,
CalibrationState,
sizeof(UCHAR));

status = WdfUsbTargetDeviceSendControlTransferSynchronously(
devContext->UsbDevice,
NULL, // Optional WDFREQUEST
NULL, //
PWDF_REQUEST_SEND_OPTIONS
&controlSetupPacket,
&memDesc,
&bytesTransferred
);

return status;
}

But this always results in a blue screen! why?

The same happens when I put it on the usb frame arrival callback.

The only place it worked in know was in device io control events handler.

I need to do this inside the kernel without being triggered from outside.

Any tips?

thanks,

Nuno

Don Burn

unread,
Dec 29, 2009, 11:45:16 AM12/29/09
to
You are issuing a call that can only be used at PASSIVE_LEVEL at
DISPATCH_LEVEL. The EvtTimerFunc is a DPC routine that runs at
DISPATCH_LEVEL. Use a WDF work item from the EvtTimerFunc to get a
function running at PASSIVE.


--
Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

"sinosoidal" <sinos...@discussions.microsoft.com> wrote in message
news:A709505F-3663-4800...@microsoft.com...

> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 4725 (20091229) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4725 (20091229) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


sinosoidal

unread,
Dec 30, 2009, 7:59:01 AM12/30/09
to
Hi Don,

I have followed your suggestions and have made the following but it fails to
create the work item with the error:

c0200212

which i'm not sure what it really means because it doesnt appear in ntstatus.h

Ayn tips?

Thanks,

Nuno

VOID
ReadWriteWorkItem(
IN WDFWORKITEM WorkItem
)
{
PWORKITEM_CONTEXT pItemContext;
NTSTATUS status;

pItemContext = GetWorkItemContext(WorkItem);

status = DpxMttGetCalibrationState(pItemContext->DevContext);

if (!NT_SUCCESS(status))
{
//UsbSamp_DbgPrint(1, ("ResetPipe failed 0x%x\n", status));
}

WdfObjectDelete(WorkItem);

return;
}

NTSTATUS
QueuePassiveLevelCallback(
IN PDEVICE_EXTENSION devContext


)
{
NTSTATUS status = STATUS_SUCCESS;

PWORKITEM_CONTEXT context;
WDF_OBJECT_ATTRIBUTES attributes;
WDF_WORKITEM_CONFIG workitemConfig;
WDFWORKITEM hWorkItem;

WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
WDF_OBJECT_ATTRIBUTES_SET_CONTEXT_TYPE(&attributes, WORKITEM_CONTEXT);
attributes.ParentObject = devContext->Device;

WDF_WORKITEM_CONFIG_INIT(&workitemConfig, ReadWriteWorkItem);

status = WdfWorkItemCreate( &workitemConfig,
&attributes,
&hWorkItem);


if (!NT_SUCCESS(status))
{
DebugPrint(("Failed to create work item %x\n", status));
return status;
}

context = GetWorkItemContext(hWorkItem);

context->DevContext = devContext;

//
// Execute this work item.
//
WdfWorkItemEnqueue(hWorkItem);

return STATUS_SUCCESS;
}

NTSTATUS
DpxMttGetCalibrationState(
IN PDEVICE_EXTENSION devContext


)
{
NTSTATUS status = STATUS_SUCCESS;
WDF_MEMORY_DESCRIPTOR memDesc;
WDF_USB_CONTROL_SETUP_PACKET controlSetupPacket;
ULONG bytesTransferred = 0;

UCHAR calibrationState;

WDF_USB_CONTROL_SETUP_PACKET_INIT_VENDOR(&controlSetupPacket,
BmRequestDeviceToHost,
BmRequestToDevice,
0x03,
0,
0);

WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&memDesc,
&calibrationState,
sizeof(UCHAR));

status = WdfUsbTargetDeviceSendControlTransferSynchronously(
devContext->UsbDevice,
NULL, // Optional WDFREQUEST
NULL, //
PWDF_REQUEST_SEND_OPTIONS
&controlSetupPacket,
&memDesc,
&bytesTransferred
);

if (status==STATUS_SUCCESS)
{
if (calibrationState==1)


devContext->Context.State.Calibrated = 1;
else
devContext->Context.State.Calibrated = 0;
}
else
{
devContext->Context.State.Calibrated = 0;
}

return status;
}


VOID
DpxMttFrameArrivalEvtTimerFunction(


IN WDFTIMER Timer
)
{
NTSTATUS status = STATUS_SUCCESS;
PDEVICE_EXTENSION devContext =
GetDeviceContext(WdfTimerGetParentObject(Timer));

//
// Check is the device is calibrated
//

UCHAR CalibrationState;

if (devContext->Context.State.Calibrated==0)
{
QueuePassiveLevelCallback(devContext);
}

}


sinosoidal

unread,
Dec 30, 2009, 7:58:01 AM12/30/09
to
Hi Don,

I have followed your suggestions and have made the following but it fails to
create the work item with the error:

c0200212

which i'm not sure what it really means because it doesnt appear in ntstatus.h

Ayn tips?

Thanks,

Nuno

VOID
ReadWriteWorkItem(
IN WDFWORKITEM WorkItem
)
{
PWORKITEM_CONTEXT pItemContext;
NTSTATUS status;

pItemContext = GetWorkItemContext(WorkItem);

status = DpxMttGetCalibrationState(pItemContext->DevContext);

if (!NT_SUCCESS(status))
{
//UsbSamp_DbgPrint(1, ("ResetPipe failed 0x%x\n", status));
}

WdfObjectDelete(WorkItem);

return;
}

NTSTATUS
QueuePassiveLevelCallback(
IN PDEVICE_EXTENSION devContext

)
{
NTSTATUS status = STATUS_SUCCESS;

PWORKITEM_CONTEXT context;
WDF_OBJECT_ATTRIBUTES attributes;
WDF_WORKITEM_CONFIG workitemConfig;
WDFWORKITEM hWorkItem;

WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
WDF_OBJECT_ATTRIBUTES_SET_CONTEXT_TYPE(&attributes, WORKITEM_CONTEXT);
attributes.ParentObject = devContext->Device;

WDF_WORKITEM_CONFIG_INIT(&workitemConfig, ReadWriteWorkItem);

status = WdfWorkItemCreate( &workitemConfig,
&attributes,
&hWorkItem);


if (!NT_SUCCESS(status))
{
DebugPrint(("Failed to create work item %x\n", status));
return status;
}

context = GetWorkItemContext(hWorkItem);

context->DevContext = devContext;

//
// Execute this work item.
//
WdfWorkItemEnqueue(hWorkItem);

return STATUS_SUCCESS;
}

NTSTATUS
DpxMttGetCalibrationState(
IN PDEVICE_EXTENSION devContext

)
{
NTSTATUS status = STATUS_SUCCESS;
WDF_MEMORY_DESCRIPTOR memDesc;
WDF_USB_CONTROL_SETUP_PACKET controlSetupPacket;
ULONG bytesTransferred = 0;

UCHAR calibrationState;

WDF_USB_CONTROL_SETUP_PACKET_INIT_VENDOR(&controlSetupPacket,
BmRequestDeviceToHost,
BmRequestToDevice,
0x03,
0,
0);

WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&memDesc,
&calibrationState,
sizeof(UCHAR));

status = WdfUsbTargetDeviceSendControlTransferSynchronously(
devContext->UsbDevice,
NULL, // Optional WDFREQUEST
NULL, //
PWDF_REQUEST_SEND_OPTIONS
&controlSetupPacket,
&memDesc,
&bytesTransferred
);

if (status==STATUS_SUCCESS)
{
if (calibrationState==1)


devContext->Context.State.Calibrated = 1;
else
devContext->Context.State.Calibrated = 0;
}
else
{
devContext->Context.State.Calibrated = 0;
}

return status;
}


VOID
DpxMttFrameArrivalEvtTimerFunction(


IN WDFTIMER Timer
)
{
NTSTATUS status = STATUS_SUCCESS;
PDEVICE_EXTENSION devContext =
GetDeviceContext(WdfTimerGetParentObject(Timer));

//

sinosoidal

unread,
Dec 30, 2009, 7:58:01 AM12/30/09
to
Hi Don,

I have followed your suggestions and have made the following but it fails to
create the work item with the error:

c0200212

which i'm not sure what it really means because it doesnt appear in ntstatus.h

Ayn tips?

Thanks,

Nuno

VOID
ReadWriteWorkItem(
IN WDFWORKITEM WorkItem
)
{
PWORKITEM_CONTEXT pItemContext;
NTSTATUS status;

pItemContext = GetWorkItemContext(WorkItem);

status = DpxMttGetCalibrationState(pItemContext->DevContext);

if (!NT_SUCCESS(status))
{
//UsbSamp_DbgPrint(1, ("ResetPipe failed 0x%x\n", status));
}

WdfObjectDelete(WorkItem);

return;
}

NTSTATUS
QueuePassiveLevelCallback(
IN PDEVICE_EXTENSION devContext

)
{
NTSTATUS status = STATUS_SUCCESS;

PWORKITEM_CONTEXT context;
WDF_OBJECT_ATTRIBUTES attributes;
WDF_WORKITEM_CONFIG workitemConfig;
WDFWORKITEM hWorkItem;

WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
WDF_OBJECT_ATTRIBUTES_SET_CONTEXT_TYPE(&attributes, WORKITEM_CONTEXT);
attributes.ParentObject = devContext->Device;

WDF_WORKITEM_CONFIG_INIT(&workitemConfig, ReadWriteWorkItem);

status = WdfWorkItemCreate( &workitemConfig,
&attributes,
&hWorkItem);


if (!NT_SUCCESS(status))
{
DebugPrint(("Failed to create work item %x\n", status));
return status;
}

context = GetWorkItemContext(hWorkItem);

context->DevContext = devContext;

//
// Execute this work item.
//
WdfWorkItemEnqueue(hWorkItem);

return STATUS_SUCCESS;
}

NTSTATUS
DpxMttGetCalibrationState(
IN PDEVICE_EXTENSION devContext

)
{
NTSTATUS status = STATUS_SUCCESS;
WDF_MEMORY_DESCRIPTOR memDesc;
WDF_USB_CONTROL_SETUP_PACKET controlSetupPacket;
ULONG bytesTransferred = 0;

UCHAR calibrationState;

WDF_USB_CONTROL_SETUP_PACKET_INIT_VENDOR(&controlSetupPacket,
BmRequestDeviceToHost,
BmRequestToDevice,
0x03,
0,
0);

WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&memDesc,
&calibrationState,
sizeof(UCHAR));

status = WdfUsbTargetDeviceSendControlTransferSynchronously(
devContext->UsbDevice,
NULL, // Optional WDFREQUEST
NULL, //
PWDF_REQUEST_SEND_OPTIONS
&controlSetupPacket,
&memDesc,
&bytesTransferred
);

if (status==STATUS_SUCCESS)
{
if (calibrationState==1)


devContext->Context.State.Calibrated = 1;
else
devContext->Context.State.Calibrated = 0;
}
else
{
devContext->Context.State.Calibrated = 0;
}

return status;
}


VOID
DpxMttFrameArrivalEvtTimerFunction(


IN WDFTIMER Timer
)
{
NTSTATUS status = STATUS_SUCCESS;
PDEVICE_EXTENSION devContext =
GetDeviceContext(WdfTimerGetParentObject(Timer));

//

sinosoidal

unread,
Dec 30, 2009, 11:27:01 AM12/30/09
to
Hi Don,

I have another problem now.

I now have a work item and i passed to the work item context a pointer to my
device context in which i have the pointer to wdfusbdevice.

The problem is that by the time I try to assign the devContext to my work
item context, the wdfusbdevice pointer is null and inside the callback is
also null and then I cant make call the usb control transfer function.

How do I sort this out?

In my last 3 repeated posts i have the code which i'm using now...

Any tips?

Thanks,

Nuno

"Don Burn" wrote:

> .
>

0 new messages