2014-10-16 155 views
1

我正在使用libusb,我需要爲我正在使用的硬件獲取設備類特定描述符。如何使用libusb獲取設備類特定描述符

我沒有找到任何可以幫助我的功能,有沒有人有關於如何做到這一點的線索?

謝謝。

+0

你在這裏提到了libusb文檔 - > http://www.libusb.org/? – iqstatic 2014-10-16 12:52:25

+0

是的,我看到了。 – 2014-10-16 12:57:40

+0

有一個函數'int libusb_get_device_descriptor(libusb_device * dev,struct libusb_device_descriptor * desc)'這可以解決你的目的,我想。什麼是預期的輸出? – iqstatic 2014-10-16 13:03:00

回答

1

我在檢查獲取類特定描述符的方法時遇到過相同的情況,並且看到這個問題沒有答案。

libusb沒有任何API或數據結構來檢索類特定描述符。這可能是因爲libusb僅用於解決基本的USB規範。要使用libusb獲取類特定的描述符詳細信息,每個描述符中都添加了幾個額外的字段。

領域:從複製libusb.h

/** Extra descriptors. If libusb encounters unknown endpoint descriptors, 
* it will store them here, should you wish to parse them. */ 
const unsigned char *extra; 

/** Length of the extra descriptors, in bytes. */ 
int extra_length; 

兩個 「額外」 和 「extra_length」 在libusb_endpoint_descriptor,libusb_interface_descriptor,libusb_config_descriptor加入。您必須根據您的類代碼(在配置級別或接口級別描述符中)手動解碼此內容。

您可以參考usbutils包中的lsusb.c以更好地理解解碼。

0

如果libusb沒有獲取所需數據的專用函數,則應該可以使用libusb_control_transfer函數(或該函數的異步版本)來獲取它。 USB描述符全部通過控制傳輸獲取,因此您可以使用該功能進行適當的控制傳輸。