c# USB parsing of a _URB_BULK_OR_INTERRUPT_TRANSFER packet

本文关键字:OR INTERRUPT TRANSFER packet BULK URB parsing of USB | 更新日期: 2023-09-27 18:10:51

我正在使用以下代码解析http://msdn.microsoft.com/en-us/library/windows/hardware/ff540352(v=vs.85).aspx中定义的_URB_BULK_OR_INTERRUPT_TRANSFER数据包:

            //parse URB Packet
            /*
            _URB_HEADER {
            USHORT      Length;
            USHORT      Function;
            USBD_STATUS Status;
            PVOID       UsbdDeviceHandle;
            ULONG       UsbdFlags;
            }*/
            //start header parse
            UInt16 urb_length = rdr.ReadUInt16();
            UInt16 urb_function = rdr.ReadUInt16();
            UInt32 urb_status = rdr.ReadUInt32();
            rdr.ReadBytes(System.IntPtr.Size);
            UInt32 UsbdFlags = rdr.ReadUInt32();
            //end header parse
            //.. skip code to check if it a _URB_BULK_OR_INTERRUPT_TRANSFER 
            // but assuming it is parse it
            /*struct _URB_BULK_OR_INTERRUPT_TRANSFER {
            struct URB_HEADER  Hdr;//covered above
            USBD_PIPE_HANDLE    PipeHandle;
            ULONG               TransferFlags;
            ULONG               TransferBufferLength;
            PVOID               TransferBuffer;
            PMDL                TransferBufferMDL;
            struct URB  *UrbLink;
            struct URB_HCD_AREA  hca;
            }*/
            rdr.ReadBytes(System.IntPtr.Size);
            UInt32 TransferFlags = rdr.ReadUInt32();
            UInt32 TransferBufferLength = rdr.ReadUInt32();
            byte[] ptr_bytes = rdr.ReadBytes(System.IntPtr.Size);
            System.IntPtr ptr_transfer_buffer = new System.IntPtr(BitConverter.ToUInt32(ptr_bytes, 0));
            ptr_bytes = rdr.ReadBytes(System.IntPtr.Size);
            System.IntPtr mdl_transfer_buffer = new System.IntPtr(BitConverter.ToUInt32(ptr_bytes, 0))

在读取所有值时检查它们,大多数值在PMDL void指针之前似乎是合理的。这最终是一个大的负数,而不是0 (NULL)或有效地址。有人能告诉我为什么会发生这种事吗?谢谢。

c# USB parsing of a _URB_BULK_OR_INTERRUPT_TRANSFER packet

MDL对象是仅在内核模式下可用的内存描述符。由于用户/内核模式的分割,x86系统上超过2gb的虚拟地址(没有3GB的开关)位于内核虚拟地址空间中。

我不太明白你的问题…TransferBufferMDL用于DirectIO情况,而TransferBuffer用于Buffered IO。

所以这两个总是有一个是空的

希望这对你有帮助!