USB data streams on Linux

Source: Internet
Author: User
Article Title: USB data streams on Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

I have obtained a USB device similar to the encrypted "dog" to make it work normally in Linux. However, according to a small program named USB view, the Linux kernel cannot drive the USB device and the device is not found in the "Linux USB Working Devices" list, this means that only a few people are using this type of USB device.

In the Linux/proc/bus/usb/devices file, some information about the USB device is displayed:

T: Bus = 01 lev= 02 Prnt = 03 Port = 02 Cnt = 01 Dev # = 4 Spd = 1.5 MxCh = 0
D: Ver = 1.00 Cls = ff (vend.) Sub = 00 Prot = ff MxPS = 8 # Cfgs = 1
P: Vendor = 0d7a ProdID = 0001 Rev = 1.07
S: Manufacturer = Marx
S: Product = USB crypToken
C: * # Ifs = 1 Cfg # = 1 ASD = 80 MxPwr = 16mA
I: If # = 0 Alt = 0 # EPs = 0 Cls = ff (vend.) Sub = 00 Prot = ff Driver = (none)

By reading the documentation on the CD of the USB device, you can briefly understand the usage of the USB device. The product CD also provides a shared library that allows applications to use this USB device through the shared library. In addition, the product CD provides a small test program to show how different library methods work. This shared library allows you to directly access the device using libusb. That is to say, using this USB device does not require a kernel-level driver. However, the authorization agreement for this shared library does not allow a program that complies with the GPL protocol to use it. The above information cannot be used to drive the USB device. The following describes how to solve this problem by tracing the USB data stream on Linux.

 Solution

You can start with the latest 2.6 kernel to solve this problem. The kernel of version 2.6 can be obtained through many channels, which are not described here.

Inode exists in the drivers/usb/core/directory of the kernel source code structure tree. c. devices. c and devio. c. These three files work together to implement the usb fs file system. That is to say, Linux accesses the USB device through these three files. Inode. c is the main task of implementing a file system. It provides a variety of VFS code that can be used to create a virtual file system or virtual file. The devices. c file is used to create and read a file indicating the status of the usb device under/proc/bus/USB/devices. The devio. c file is used to control access to USB devices through the usb fs file system. To enable Linux to access USB devices, modify devices. c and devio. c.

 Implementation

1. Record access information

Explore USB data streams starting from recording access information for all USB devices. In user programs, to access a USB device through usb fs, you need to call ioctl () on the corresponding Device File ()

Command. Through further analysis of devices. c file, it is found that every execution of ioctl () will call the usbdev_ioctl () function. Therefore, it is a good solution to record the access information sent to the USB device. You can add a custom printk () function to each case statement to implement this function. The basic content is as follows:

...
Case USBDEVFS_CLAIMINTERFACE:
Printk ("CLAIMINTERFACE ");
Ret = proc_claiminterface (ps, (void _ user *) arg );
Break;
Case USBDEVFS_RELEASEINTERFACE:
Printk ("RELEASEINTERFACE ");
Ret = proc_releaseinterface (ps, (void _ user *) arg );
Break;

After compilation and installation, each usb fs access is recorded in the kernel log, which can be accessed through the dmesg command.

[1] [2] [3] Next page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.