Windows中的C程序访问总线上的内容
我有一个 Zigbee USB 加密狗,可插入 Windows 笔记本电脑上的 USB 端口。我需要能够捕获传入的数据包。
我正在尝试编写 ac 程序,通过监视与相应 USB 端口关联的总线来捕获传入数据包。
是否有一些 C 库可以促进这种监控?如果不是,我如何访问总线的内容?
I have a zigbee usb dongle that plugs into the usb port on my Windows laptop. I need to be able to capture the incoming packets.
I am trying to write a c program that will capture the incoming packets by monitoring the bus associated with the corresponding usb port.
Are there some c libraries that facilitate this monitoring? If not how can I access the contents of the bus?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这就是硬件驱动程序为您所做的事情:它直接监视低级硬件,然后以更方便的界面处理该数据并将其公开给用户级程序。
我认为 Telegesis 和 自适应提供 Windows 驱动程序供下载;无论 Zigbee 制造商是谁,都应该提供自己的驱动程序(如果这些驱动程序不兼容)。
或者 您可以编写自己的驱动程序,但这是一项非常困难且棘手的工作,不适合胆小的人。
This is what a hardware driver does for you: it monitors low-level hardware directly, and then processes and exposes that data to user-level programs in a more convenient interface.
I think Telegesis and Adaptive offer Windows drivers for download; whoever manufactured your Zigbee should provide drivers of their own, if those aren't compatible.
Or you could write your own driver, but that is a very difficult and tricky piece of work not for the faint of heart.
您可以使用 libusb 轻松读写 USB 数据包。通常我通过 python 包装器使用 libusb pyUSB
但是,您实际上有关于如何编码的文档吗/解码来自您特定加密狗的数据包格式?实际的 zigbee 数据包可能包含在某些您需要能够解码的专有协议中。
我还假设您的 USB 加密狗实际上是通过原始 USB 进行通信,而不是使用 FTDI 芯片通过 USB 创建虚拟串行端口。如果是这种情况,那么您不需要使用 USB,只需使用虚拟 COM 端口来传输串行数据即可。
You can easily read and write USB packets using libusb. Normally I use libusb via the python wrappers pyUSB
However, do you actually have documentation on how to encode/decode the packet formats coming from your particular dongle? The actual zigbee packets may be wrapped up in some proprietary protocol that you would need to be able to decode.
I am also assuming your USB dongle is actually communicating via raw USB, and not using an FTDI chip to create a virtual serial port over USB. If that was the case, then you don't need to muck with USB, just use the virtual COM port for serial data.
打开加密狗的外壳并查看所使用的芯片会很有用(只有在很容易打开并且您对此想法感到满意的情况下才这样做)。
如果您说它是基于 Texas Instruments 的:那么它可能正在运行 TI 的 Z-Stack 固件。如果是这种情况,则很有可能正在运行 Z-Stack Monitor 和 Test API(搜索文档代码 SWRA198)。您可以轻松编写 C/C++ 与之交互。
然而,您的第一个障碍是能够读/写设备。如果它有 FTDI 芯片,那就很容易了:它应该显示为虚拟通信端口,如上一篇文章中提到的。 CC2531 等芯片能够直接连接到 USB 总线。我对那个配置不熟悉。我有一个这样的加密狗,它们使用一些奇怪的德州仪器 USB 串行协议。但如果您获得正确的 Windows 驱动程序,它应该显示为常规通信端口供应用程序使用。
It would be useful to open case of the dongle and take a look at the chips used (only do so if it's easy to open and you're comfortable with the idea).
You say it's Texas Instruments based: then it's probably running TI's Z-Stack firmware. If that's the case there is a good chance it's running the Z-Stack Monitor and Test API (search for document code SWRA198). You can easily write C/C++ to interact with that.
However your first hurdle is to be able to read/write to the device. If it has a FTDI chip then that's going to be easy: it should appear as a virtual comm port as mentioned in a previous post. A chip like the CC2531 is capable of connecting directly to the USB bus. I'm not familiar with that configuration. I've got one such dongle and they use some weird Texas Instruments serial-over-USB protocol. But if you get the right Windows driver it should appear as a regular comm port for applications to use.