Linux USB 编程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6456167/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 04:42:04  来源:igfitidea点击:

Linux USB programming

clinuxusbkernel

提问by Jay

I am new to Linux kernel programming. I wish to develop a program to read USB drive information like its manufacturer name, capacity, etc. I know about descriptors and their attributes. But I don't understand how to enumerate USB drives connected to the system. I am looking for the function which initiates connection between kernel and USB port. How is it possible?

我是 Linux 内核编程的新手。我希望开发一个程序来读取 USB 驱动器信息,如制造商名称、容量等。我了解描述符及其属性。但我不明白如何枚举连接到系统的 USB 驱动器。我正在寻找在内核和 USB 端口之间启动连接的函数。这怎么可能?

采纳答案by Martin Beckett

You don't need to program the kernel as such - in fact to read the device info you don't even need a device driver.

您不需要像这样对内核进行编程 - 实际上要读取设备信息,您甚至不需要设备驱动程序。

The USB system is different in the newer 2.6 kernels so a lot of the online tutorials may be out of date - but start here http://www.linux-usb.org/

USB 系统在较新的 2.6 内核中有所不同,因此很多在线教程可能已经过时 - 但从这里开始http://www.linux-usb.org/

If you do want to write a USB device driver see this Linux journal tutorial

如果您确实想编写 USB 设备驱动程序,请参阅此Linux 期刊教程

回答by osgx

Do you really want to do a kernel programming? There is an lsusb utility, capable of reading "USB drive information like its manufacturer name", descriptors... It also can enumerate all usb devices.

你真的想做内核编程吗?有一个 lsusb 实用程序,能够读取“USB 驱动器信息,如其制造商名称”、描述符……它还可以枚举所有 USB 设备。

Sources of lsusbare e.g. here http://www.google.com/codesearch#VKTEFMx6wp0/lsusb.c

来源lsusb例如在这里http://www.google.com/codesearch#VKTEFMx6wp0/lsusb.c

If you are doing a writing an USB driver, which works in kernel mode, I suggest you read some existing usb driver and USB driver programming FAQ.

如果您正在编写一个在内核模式下工作的 USB 驱动程序,我建议您阅读一些现有的 USB 驱动程序和 USB 驱动程序编程常见问题解答。