ljchli
驱动牛犊
驱动牛犊
  • 注册日期2002-11-19
  • 最后登录2006-12-25
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1563回复:0

usb开发--ActivateConfiguration

楼主#
更多 发布于:2005-02-02 11:25
我在使用ActivateConfiguration()函数时,返回是成功的,但我的kusbpipe对象都没有打开,进一步测试发现,执行ActivateConfiguration()后,m_Lower中m_Lower.PipeArray().MaxInserted()值为:0x09,而m_Lower.InterfaceArray().MaxInserted()值为:0x00,即是m_Interface对象没有添加到InterfaceArray数组中,请各位大侠指点一下。我的部分源程序如下:Usb7C68Dev::Usb7C68Dev(PDEVICE_OBJECT Pdo, ULONG Unit) :
KPnpDevice(Pdo, NULL)
{
t << "Entering Usb7C68Dev::Usb7C68Dev (constructor)\n";


// Check constructor status
    if ( ! NT_SUCCESS(m_ConstructorStatus) )
{
   return;
}

// Remember our unit number
m_Unit = Unit;

// Initialize the lower device
m_Lower.Initialize(this, Pdo);

// Initialize the interface object.  The wizard generates code
// to support a single interface.  You may create and add additional
// interfaces.  By default, the wizard uses InterfaceNumber 0 (the
// first interface descriptor), ConfigurationValue 1 (the first
// configuration descriptor), and initial interface alternate
// setting of 0.  If your device has multiple interfaces or alternate
// settings for an interface, you can add additional KUsbInterface
// objects or adjust the parameters passed to this function.
m_Interface.Initialize(
m_Lower, //KUsbLowerDevice
0, //InterfaceNumber
1, //ConfigurationValue
0 //Initial Interface Alternate Setting
);

// Initialize each Pipe object
m_EndpIn1.Initialize(m_Lower, 0x81, 32);
m_EndpOut1.Initialize(m_Lower, 0x1, 32);
m_EndpIn2.Initialize(m_Lower, 0x82, 64);
m_EndpOut2.Initialize(m_Lower, 0x2, 64);
m_EndpIn4.Initialize(m_Lower, 0x84, 64);
m_EndpOut4.Initialize(m_Lower, 0x4, 64);
m_EndpIn6.Initialize(m_Lower, 0x86, 64);
m_EndpOut6.Initialize(m_Lower, 0x6, 64);
m_EndpIn8.Initialize(m_Lower, 0x88, 64);
m_EndpOut8.Initialize(m_Lower, 0x8, 64);

    // Inform the base class of the lower edge device object
SetLowerDevice(&m_Lower);

// Initialize the PnP Policy settings to the "standard" policy
SetPnpPolicy();

// TODO: Customize the PnP Policy for this device by setting
// flags in m_Policies.

// Initialize the Power Policy settings to the "standard" policy
SetPowerPolicy(TRUE);

// TODO: Customize the Power Policy for this device by setting
// flags in m_PowerPolicies.
pEvent=NULL;//外部共享事件指针
}

NTSTATUS Usb7C68Dev::OnStartDevice(KIrp I)
{
t << "Entering Usb7C68Dev::OnStartDevice\n";

NTSTATUS status = STATUS_UNSUCCESSFUL;

I.Information() = 0;
/*
//自己添加的代码
//==============================================================
// The default Pnp policy has already cleared the IRP with the lower device
USB_DEVICE_DESCRIPTOR desc;
status = m_Lower.GetDeviceDescriptor( &desc );
if ( !NT_SUCCESS(status) )
{
return status;
}

if(desc.idVendor!=0x04B4 || desc.idProduct!=0x8613)
{
return status;
}
PUSB_ENDPOINT_DESCRIPTOR pEndpoint;
PUSB_INTERFACE_DESCRIPTOR pInterface=NULL;
status=m_Lower.Preconfigure(1);
if(!NT_SUCCESS(status))
{
t << "m_Lower.Preconfigure() fail!...\n";
return status;
}
pInterface=m_Lower.LocateInterface(NULL,&pEndpoint);
if(pInterface==NULL)
{
t << "m_Lower.LocateInterface() fail!...\n";
return status;
}
status=m_Lower.PreconfigureInterface(pInterface);
if(!NT_SUCCESS(status))
{
t << "m_Lower.PreconfigureInterface() fail!...\n";
return status;
}
status=m_Lower.Configure();
if(!NT_SUCCESS(status))
{
t << "m_Lower.Configure() fail!...\n";
return status;
}
t << "UsbdPipeTypeBulk: "<<UsbdPipeTypeBulk<<EOL;
t << "UsbdPipeTypeControl: "<<UsbdPipeTypeControl<<EOL;
t << "UsbdPipeTypeInterrupt: "<<UsbdPipeTypeInterrupt<<EOL;
t << "UsbdPipeTypeIsochronous: "<<UsbdPipeTypeIsochronous<<EOL;
if(m_EndpIn1.IsOpen())
t << "m_EndpIn1.Type(): "<<m_EndpIn1.Type()<<EOL;
if(m_EndpIn2.IsOpen())
t << "m_EndpIn2.Type(): "<<m_EndpIn2.Type()<<EOL;
if(m_EndpIn4.IsOpen())
t << "m_EndpIn4.Type(): "<<m_EndpIn4.Type()<<EOL;
if(m_EndpIn6.IsOpen())
t << "m_EndpIn6.Type(): "<<m_EndpIn6.Type()<<EOL;
if(m_EndpIn8.IsOpen())
t << "m_EndpIn8.Type(): "<<m_EndpIn8.Type()<<EOL;

if(m_EndpOut1.IsOpen())
t << "m_EndpOut1.Type(): "<<m_EndpOut1.Type()<<EOL;
if(m_EndpOut2.IsOpen())
t << "m_EndpOut2.Type(): "<<m_EndpOut2.Type()<<EOL;
if(m_EndpOut4.IsOpen())
t << "m_EndpOut4.Type(): "<<m_EndpOut4.Type()<<EOL;
if(m_EndpOut6.IsOpen())
t << "m_EndpOut6.Type(): "<<m_EndpOut6.Type()<<EOL;
if(m_EndpOut8.IsOpen())
t << "m_EndpOut8.Type(): "<<m_EndpOut8.Type()<<EOL;

//Initialize the interrupt transfer object and
//Start an interrupt transfer
// if(!NT_SUCCESS(m_IntXfer.Initialize(&m_Lower,&m_EndpIn2)))
// t << "m_IntXfer.Initialize() Fail!...\n";
// if(!NT_SUCCESS(m_IntXfer.StartPolling(pIntBuff, IntBuffLen, OnInterrupt)))
// t << "m_IntXfer.StartPolling() Fail!...\n";
//===============================================================
*/
AC_STATUS acStatus = AC_SUCCESS;
//By default, the wizard passes a ConfigurationValue of 1 to
//ActivateConfiguration().  This corresponds to the first configuration
//that the device reports in its configuration descriptor.  If the device
//supports multiple configurations, pass the appropriate
//ConfigurationValue of the configuration to activate here.
acStatus = m_Lower.ActivateConfiguration(
1 // ConfigurationValue 1 (the first configuration)
);

t << "UsbdPipeTypeBulk: "<<UsbdPipeTypeBulk<<EOL;
t << "UsbdPipeTypeControl: "<<UsbdPipeTypeControl<<EOL;
t << "UsbdPipeTypeInterrupt: "<<UsbdPipeTypeInterrupt<<EOL;
t << "UsbdPipeTypeIsochronous: "<<UsbdPipeTypeIsochronous<<EOL;
if(m_EndpIn1.IsOpen())
t << "m_EndpIn1.Type(): "<<m_EndpIn1.Type()<<EOL;
if(m_EndpIn2.IsOpen())
t << "m_EndpIn2.Type(): "<<m_EndpIn2.Type()<<EOL;
if(m_EndpIn4.IsOpen())
t << "m_EndpIn4.Type(): "<<m_EndpIn4.Type()<<EOL;
if(m_EndpIn6.IsOpen())
t << "m_EndpIn6.Type(): "<<m_EndpIn6.Type()<<EOL;
if(m_EndpIn8.IsOpen())
t << "m_EndpIn8.Type(): "<<m_EndpIn8.Type()<<EOL;

if(m_EndpOut1.IsOpen())
t << "m_EndpOut1.Type(): "<<m_EndpOut1.Type()<<EOL;
if(m_EndpOut2.IsOpen())
t << "m_EndpOut2.Type(): "<<m_EndpOut2.Type()<<EOL;
if(m_EndpOut4.IsOpen())
t << "m_EndpOut4.Type(): "<<m_EndpOut4.Type()<<EOL;
if(m_EndpOut6.IsOpen())
t << "m_EndpOut6.Type(): "<<m_EndpOut6.Type()<<EOL;
if(m_EndpOut8.IsOpen())
t << "m_EndpOut8.Type(): "<<m_EndpOut8.Type()<<EOL;

switch (acStatus)
{
case AC_SUCCESS:
t << "USB Configuration OK\n";
status = STATUS_SUCCESS;
break;

case AC_COULD_NOT_LOCATE_INTERFACE:
t << "Could not locate interface\n";
break;

case AC_COULD_NOT_PRECONFIGURE_INTERFACE:
t << "Could not get configuration descriptor\n";
break;

case AC_CONFIGURATION_REQUEST_FAILED:
t << "Board did not accept configuration URB\n";
break;

case AC_FAILED_TO_INITIALIZE_INTERFACE_OBJECT:
t << "Failed to initialize interface object\n";
break;

case AC_FAILED_TO_GET_DESCRIPTOR:
t << "Failed to get device descriptor\n";
break;

case AC_FAILED_TO_OPEN_PIPE_OBJECT:
//NOTE: this may not be an error.  It could mean that
//the device has an endpoint for which a KUsbPipe object has
//not been instanced.  If the intention is to not use this endpoint,
//then it's likely not a problem.  
status = STATUS_SUCCESS;
t << "Failed to open pipe object\n";
break;

default:
t << "Unexpected error activating USB configuration\n";
break;
}

   return status;  // base class completes the IRP
}

游客

返回顶部