/*****************************************************************************/
/*
* lsusb.c -- lspci like utility for the USB bus
*
* Copyright (C) 1999, 2000, 2001, 2003
* Thomas Sailer (t.sailer@alumni.ethz.ch)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
*/
/*****************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <stdarg.h>
#include <usb.h>
#include "names.h"
#include "devtree.h"
#include "usbmisc.h"
#define _GNU_SOURCE
#include <getopt.h>
/* from USB 2.0 spec and updates */
#define USB_DT_DEVICE_QUALIFIER 0x06
#define USB_DT_OTHER_SPEED_CONFIG 0x07
#define USB_DT_OTG 0x09
#define USB_DT_DEBUG 0x0a
#define USB_DT_INTERFACE_ASSOCIATION 0x0b
/* convention suggested by common class spec */
#define USB_DT_CS_INTERFACE 0x24
#define USB_DT_CS_ENDPOINT 0x25
#define VERBLEVEL_DEFAULT 0 /* 0 gives lspci behaviour; 1, lsusb-0.9 */
#define CTRL_RETRIES 2
#define CTRL_TIMEOUT (5*1000) /* milliseconds */
static const char *procbususb = "/proc/bus/usb";
static unsigned int verblevel = VERBLEVEL_DEFAULT;
static int do_report_desc = 1;
static void dump_interface(struct usb_dev_handle *dev, struct usb_interface *interface);
static void dump_endpoint(struct usb_dev_handle *dev, struct usb_interface_descriptor *interface, struct usb_endpoint_descriptor *endpoint);
static void dump_audiocontrol_interface(struct usb_dev_handle *dev, unsigned char *buf);
static void dump_audiostreaming_interface(unsigned char *buf);
static void dump_midistreaming_interface(struct usb_dev_handle *dev, unsigned char *buf);
static char *dump_comm_descriptor(struct usb_dev_handle *dev, unsigned char *buf, char *indent);
static void dump_hid_device(struct usb_dev_handle *dev, struct usb_interface_descriptor *interface, unsigned char *buf);
static void dump_audiostreaming_endpoint(unsigned char *buf);
static void dump_midistreaming_endpoint(unsigned char *buf);
static void dump_hub(char *prefix, unsigned char *p, int has_tt);
static void dump_ccid_device(unsigned char *buf);
/* ---------------------------------------------------------------------- */
static unsigned int convert_le_u32 (const unsigned char *buf)
{
return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
}
/* ---------------------------------------------------------------------- */
/* workaround libusb API goofs: "byte" should never be sign extended;
* using "char" is trouble. Likewise, sizes should never be negative.
*/
static inline int typesafe_control_msg(usb_dev_handle *dev,
unsigned char requesttype, unsigned char request,
int value, int index,
unsigned char *bytes, unsigned size, int timeout)
{
return usb_control_msg(dev, requesttype, request, value, index,
(char *) bytes, (int) size, timeout);
}
#define usb_control_msg typesafe_control_msg
/* ---------------------------------------------------------------------- */
int lprintf(unsigned int vl, const char *format, ...)
{
va_list ap;
int r;
if (vl > verblevel)
return 0;
va_start(ap, format);
r = vfprintf(stderr, format, ap);
va_end(ap);
if (!vl)
exit(1);
return r;
}
/* ---------------------------------------------------------------------- */
static int get_string(struct usb_dev_handle *dev, char* buf, size_t size, u_int8_t id)
{
int ret;
if (id) {
ret = usb_get_string_simple(dev, id, buf, size);
if (ret <= 0) {
buf[0] = 0;
return 0;
}
else
return ret;
}
else {
buf[0] = 0;
return 0;
}
}
static int get_vendor_string(char *buf, size_t size, u_int16_t vid)
{
const char *cp;
if (size < 1)
return 0;
*buf = 0;
if (!(cp = names_vendor(vid)))
return 0;
return snprintf(buf, size, "%s", cp);
}
static int get_product_string(char *buf, size_t size, u_int16_t vid, u_int16_t pid)
{
const char *cp;
if (size < 1)
return 0;
*buf = 0;
if (!(cp = names_product(vid, pid)))
return 0;
return snprintf(buf, size, "%s", cp);
}
static int get_class_string(char *buf, size_t size, u_int8_t cls)
{
const char *cp;
if (size < 1)
return 0;
*buf = 0;
if (!(cp = names_class(cls)))
return 0;
return snprintf(buf, size, "%s", cp);
}
static int get_subclass_string(char *buf, size_t size, u_int8_t cls, u_int8_t subcls)
{
const char *cp;
if (size < 1)
return 0;
*buf = 0;
if (!(cp = names_subclass(cls, subcls)))
return 0;
return snprintf(buf, size, "%s", cp);
}
static int get_protocol_string(char *buf, size_t size, u_int8_t cls, u_int8_t subcls, u_int8_t proto)
{
const char *cp;
if (size < 1)
return 0;
*buf = 0;
if (!(cp = names_protocol(cls, subcls, proto)))
return 0;
return snprintf(buf, size, "%s", cp);
}
static int get_audioterminal_string(char *buf, size_t size, u_int16_t termt)
{
const char *cp;
if (size < 1)
return 0;
*buf = 0;
if (!(cp = names_audioterminal(termt)))
return 0;
return snprintf(buf, size, "%s", cp);
}
/* ---------------------------------------------------------------------- */
static void dump_bytes(unsigned char *buf, unsigned int len)
{
unsigned int i;
for (i = 0; i < len; i++)
printf(" %02x", buf[i]);
printf("\n");
}
static void dump_junk(unsigned char *buf, const char *indent, unsigned int len)
{
unsigned int i;
if (buf[0] <= len)
return;
printf("%sjunk at descriptor end:", indent);
for (i = len; i < buf[0]; i++)
printf(" %02x", buf[i]);
printf("\n");
}
/*
* General config descriptor dump
*/
static void dump_device(
struct usb_dev_handle *dev,
struct usb_device_descriptor *descriptor
)
{
char vendor[128], product[128];
char cls[128], subcls[128], proto[128];
char mfg[128], prod[128], serial[128];
get_vendor_string(vendor, sizeof(vendor), descriptor->idVendor);
get_product_string(product, sizeof(product), descriptor->idVendor, descriptor->idProduct);
get_class_string(cls, sizeof(cls), descriptor->bDeviceClass);
get_subclass_string(subcls, sizeof(subcls), descriptor->bDeviceClass, descriptor->bDeviceSubClass);
get_protocol_string(proto, sizeof(proto), descriptor->bDeviceClass, descriptor->bDeviceSubClass, descriptor->bDeviceProtocol);
get_string(dev, mfg, sizeof(mfg), descriptor->iManufacturer);
get_string(dev, prod, sizeof(prod), descriptor->iProduct);
get_string(dev, serial, sizeof(serial), descriptor->iSerialNumber);
printf("Device Descriptor:\n"
" bLength %5u\n"
" bDescriptorType %5u\n"
" bcdUSB %2x.%02x\n"
" bDeviceClass %5u %s\n"
" bDeviceSubClass %5u %s\n"
" bDeviceProtocol %5u %s\n"
" bMaxPacketSize0 %5u\n"
" idVendor 0x%04x %s\n"
" idProduct 0x%04x %s\n"
" bcdDevice %2x.%02x\n"
" iManufacturer %5u %s\n"
" iProduct %5u %s\n"
" iSerial %5u %s\n"
" bNumConfigurations %5u\n",
descriptor->bLength, descriptor->bDescriptorType, descriptor->bcdUSB >> 8, descriptor->bcdUSB & 0xff,
descriptor->bDeviceClass, cls, descriptor->bDeviceSubClass
没有合适的资源?快使用搜索试试~ 我知道了~
usbutils-0.70.rar_usbutils
共31个文件
c:5个
h:5个
in:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 143 浏览量
2022-09-20
18:42:34
上传
评论
收藏 156KB RAR 举报
温馨提示
usbutils-0.70 这个USB程序库是使用在一些嵌入试应用程式,支援 Linux 作业系统等等,很好的原始码.
资源推荐
资源详情
资源评论
收起资源包目录
usbutils-0.70.rar (31个子文件)
usbutils-0.70
usbutils-0.70
update-usbids.sh 755B
usbmodules.8 4KB
mkinstalldirs 729B
lsusb.8 2KB
usbmisc.h 1KB
devtree.h 3KB
config.h.in 4KB
depcomp 12KB
aclocal.m4 39KB
usb.ids 131KB
compile 4KB
Makefile.am 630B
usbmodules.c 14KB
usbmodules.h 1KB
configure.in 1KB
README 90B
Makefile.in 21KB
INSTALL 8KB
missing 10KB
names.h 2KB
install-sh 5KB
AUTHORS 88B
list.h 2KB
usbmisc.c 4KB
devtree.c 9KB
configure 192KB
NEWS 403B
ChangeLog 3KB
COPYING 18KB
lsusb.c 61KB
names.c 23KB
共 31 条
- 1
资源评论
APei
- 粉丝: 65
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功