Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Vista Drivers > How to make a USB control request in a timer callback...

Reply
Thread Tools Display Modes

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

 
 
sinosoidal
Guest
Posts: n/a

 
      12-29-2009
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,&CalibrationS tate);

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(&controlS etupPacket,
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
 
Reply With Quote
 
 
 
 
Don Burn
Guest
Posts: n/a

 
      12-29-2009
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" <> wrote in message
news:A709505F-3663-4800-8279-...
> 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,&CalibrationS tate);
>
> 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(&controlS etupPacket,
> 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
>
> __________ 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




 
Reply With Quote
 
sinosoidal
Guest
Posts: n/a

 
      12-30-2009
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(&controlS etupPacket,
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);
}

}


 
Reply With Quote
 
sinosoidal
Guest
Posts: n/a

 
      12-30-2009
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(&controlS etupPacket,
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);
}

}



 
Reply With Quote
 
sinosoidal
Guest
Posts: n/a

 
      12-30-2009
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(&controlS etupPacket,
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);
}

}


 
Reply With Quote
 
sinosoidal
Guest
Posts: n/a

 
      12-30-2009
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:

> 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" <> wrote in message
> news:A709505F-3663-4800-8279-...
> > 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,&CalibrationS tate);
> >
> > 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(&controlS etupPacket,
> > 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
> >
> > __________ 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
>
>
>
>
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Unable to unload driver in Win 7 Tim Roberts Windows Vista Drivers 2 12-08-2009 01:24 PM
How to contact Microsoft C.B. Windows Vista Hardware 23 03-12-2008 03:06 PM
Slow Vista startup Jedi940 Windows Vista Performance 1 01-13-2008 09:50 PM
User Account control problem, please help AC Windows Vista Administration 3 08-20-2007 12:41 AM
Stop Error 0x0000007b Louis LeBrun Windows Vista Installation 17 07-05-2006 10:00 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59