阅读:2018回复:7
难道就没人写过 Bus Driver, 来谈谈吧
按说应该不难,但我的死活就是不行 :( :(
我是这样做的。 在 FDO 响应 PnP / IRP_MN_QUERY_DEVICE_RELATIONS 时,产生一个 PDO 对象(IoCreateDevice)。按道理,接下来我就能收到发给 PDO 的请求了(IRP_MN_QUERY_ID等等),但就是没反应。 我参考的主要例子是 serenum(因为我的背景与它最类似),代码基于 usb\\filter。 这里面有什么 trick 吗,请过来人指点! 更多背景见 http://www.driverdevelop.com/forum/html_43419.html?1055389104 http://www.driverdevelop.com/forum/html_43374.html?1055118697 [编辑 - 6/12/03 by jason.gao] |
|
|
沙发#
发布于:2003-06-12 14:26
凶第您选错对象了,我以前也跟您一样认为的。
您该看toaster里边的程序,里边才是一个Bus driver 的sourcecode ,写好了告诉我呀,我也想把一个设备挂在自己的虚拟总线上现在没搞懂也是,:《 |
|
|
板凳#
发布于:2003-06-12 14:41
谢谢!
哈哈,我也刚发现 toaster 是个好东东!准备研究一下。 不过,serenum也是的(只不过它不是一个纯 bus driver),我的情况就和它类似。查查 FILE_DEVICE_BUS_EXTENDER,里面与 总线相关的有好几个呢。可能从 toaster 开始简单一点。 呵呵,共同学习,感兴趣的都来发言呀,互相启发启发~~~~~ |
|
|
地板#
发布于:2003-06-12 14:45
入门文章,这里转过的,不过没图
Writing Bus Drivers for Windows 2000 [url]http://www.osr.com/ntinsider/1999/bus_driver/bus_driver.htm [/url] :) |
|
|
地下室#
发布于:2003-06-13 13:59
XX_AddDevice
--------------------------------------- { NTSTATUS status; PDEVICE_OBJECT filterDevObj = NULL; PAGED_CODE(); LOG_ENTER; LOG_ARG_P(driverObj); LOG_ARG_P(physicalDevObj); status = IoCreateDevice(driverObj, sizeof(DEVICE_EXTENSION), NULL, // name for this device FILE_DEVICE_BUS_EXTENDER, //!!?? FILE_DEVICE_UNKNOWN, FILE_AUTOGENERATED_DEVICE_NAME, // device characteristics FALSE, // not exclusive &filterDevObj); // our device object if (NT_SUCCESS(status)) { DEVICE_EXTENSION *devExt; ASSERT(filterDevObj); // Initialize device extension for new device object devExt = (DEVICE_EXTENSION *)filterDevObj->DeviceExtension; RtlZeroMemory(devExt, sizeof(DEVICE_EXTENSION)); devExt->signature = DEVICE_EXTENSION_SIGNATURE; devExt->state = STATE_INITIALIZED; devExt->thisDevObj = filterDevObj; devExt->physicalDevObj = physicalDevObj; #ifdef _AS_BUS devExt->isPDO = FALSE; #endif //_AS_BUS . . . } |
|
|
5楼#
发布于:2003-06-13 14:05
PnP / IRP_MN_QUERY_DEVICE_RELATIONS
------------------------------------------------ switch (IrpStack->Parameters.QueryDeviceRelations.Type) { case BusRelations: LOG_INFO(\"BusRelations\"); // The current number of PDOs in the device relations structure NumOfCurrentPDOs = (0 == Irp->IoStatus.Information) ? 0 : ((PDEVICE_RELATIONS) Irp->IoStatus.Information)->Count; LOG_VAR(NumOfCurrentPDOs); // we only have 1 child PDO length = sizeof(DEVICE_RELATIONS) + ((NumOfCurrentPDOs + 1) * sizeof (PDEVICE_OBJECT)); // use ExAllocatePool, DeviceRelations structure // will be freed by the OS rather than this driver. DeviceRelations = (PDEVICE_RELATIONS) ExAllocatePool(NonPagedPool, length); // If we can\'t allocate DeviceRelations structure, bail if (DeviceRelations == NULL) { ntStatus = STATUS_INSUFFICIENT_RESOURCES; LOG_WARN(\"STATUS_INSUFFICIENT_RESOURCES\"); Irp->IoStatus.Status = STATUS_UNSUCCESSFUL; break; } // Copy in the device objects so far if (NumOfCurrentPDOs) { RtlCopyMemory ( DeviceRelations->Objects, ((PDEVICE_RELATIONS) Irp->IoStatus.Information)->Objects, NumOfCurrentPDOs * sizeof (PDEVICE_OBJECT)); } DeviceRelations->Count = NumOfCurrentPDOs; if ((!FdoExt->childPDO) && (PdoCount<9)) { RtlInitUnicodeString (&PdoUniName, PdoName); PdoName [((sizeof(PdoName)/sizeof(WCHAR)) - 2)] = L\'0\' + PdoCount++; LOG_VAR_WS(PdoName); LOG_INFO(\"IoCreateDevice ...\"); ntStatus = IoCreateDevice( Fdo->DriverObject, sizeof(PDO_DEVICE_EXTENSION), &PdoUniName, FILE_DEVICE_UNKNOWN, //FILE_DEVICE_MOUSE, FILE_AUTOGENERATED_DEVICE_NAME, //0 FALSE, &FdoExt->childPDO ); LOG_VAR_X(ntStatus); LOG_VAR_P(FdoExt->childPDO); if(NT_SUCCESS(ntStatus)) { PPDO_DEVICE_EXTENSION pdoExt = FdoExt->childPDO->DeviceExtension; XX_PDO_InitDeviceExtension(FdoExt->childPDO, FdoExt); DeviceRelations->Objects[DeviceRelations->Count++] = FdoExt->childPDO; ObReferenceObject(FdoExt->childPDO); } } else { // Child PDO already exists, just return it LOG_INFO(\"Child PDO already exists\"); DeviceRelations->Objects[DeviceRelations->Count++] = FdoExt->childPDO; ObReferenceObject(FdoExt->childPDO); } LOG_VAR(DeviceRelations->Count); if (0 != Irp->IoStatus.Information) { ExFreePool ((PVOID) Irp->IoStatus.Information); } Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations; //ntStatus = Irp->IoStatus.Status = STATUS_SUCCESS; //??? Set up and pass the IRP further down the stack Irp->IoStatus.Status = STATUS_SUCCESS; IoSkipCurrentIrpStackLocation (Irp); ntStatus = IoCallDriver (FdoExt->topDevObj, Irp); LOG_INFO(\"after call IoCallDriver\"); LOG_VAR_X(Irp->IoStatus.Status); NumOfCurrentPDOs = (0 == Irp->IoStatus.Information) ? 0 : ((PDEVICE_RELATIONS) Irp->IoStatus.Information)->Count; LOG_VAR(NumOfCurrentPDOs); ntStatus = STATUS_SUCCESS; Irp->IoStatus.Status = ntStatus; break; |
|
|
6楼#
发布于:2003-06-16 11:50
这样修改就挂上去了吗:》
|
|
|
7楼#
发布于:2003-06-17 14:17
理论上是这样,但不知道上下层对它有什么影响。我已经仔细对比过Toaster Bus中这几处代码,真没看出我的代码和它有什么本质区别!总之,我绝望了 :)
我把另一个driver修改了一下,可以直接安装上去了,所以不想再研究这个 bus driver 了 :mad: [编辑 - 6/17/03 by jason.gao] |
|
|