4 czerwca 2016

Podręczne narzędzia #4 (USB)

Dzisiejszy wpis pragnę poświęcić tematyce USB.

Z przedstawionych poniżej narzędzi korzystałem osobiście, pracując jako freelancer. Ich ocena jest subiektywna, oparta na moim prywatnym doświadczeniu. Dwa przykładowe zlecenia, jakie dotykały problemu zrozumienia protokołu USB:

  • Napisanie oprogramowania współpracującego z tanią chińską wagą, do której nie było dokumentacji. Musiałem przeprowadzić obserwację komunikacji wagi z dołączonym do niej chińskim programem demo, a następnie przygotować “wirtualny sterownik zastępczy” i zaimplementować komunikację w aplikacji, korzystając z tego sterownika.
  • Aplikację do pilota radiowego Remote Control X10.
Remote Control X10

Jednym słowem sniffer USB. Dostarcza bardzo wielu informacji o podłączonych urządzeniach i ich deskryptorach. Pozwala podglądać komunikację. Wersja bezpłatna posiada jednak pewne ograniczenia.

Przykładowy zrzut informacji o jednym z urządzeń peryferyjnych:

This device is part of a composite device.

Connection Information
 Port: 4
 Speed: Full Speed
 Device address: 2
 Open pipes: 3
 Connection status: Device connected

Device Descriptor
 USB version: 2.0
 Device class: 0x0 - (Defined at Interface level)
 Device subclass: 0x0 - Unknown
 Device protocol: 0x0 - Unknown
 Control pipe max size: 8 bytes
 Vendor ID: 0x46d (Logitech, Inc.)
 Product ID: 0xc52b (Unifying Receiver)
 Product version: 18.1
 Manufacturer: Not specified
 Product: Not specified
 Serial Number: Not specified
 Configurations: 1
 This device is part of a composite device.

Configuration Descriptor
 Number of interfaces: 1
 Configuration value: 0x1
 Attributes: , Bus powered
 Max power: 98 mA

Interface Descriptor: 1, Alternate setting: 0
 Number of endpoints: 1
 Interface class: 0x3 - Human Interface Device
 Interface subclass: 0x1 - Boot Interface Subclass
 Interface protocol: 0x2 - Mouse
 Endpoint address 0x2, Input, Interrupt, max packet size: 8 bytes, update interval: 2 1-millisecond frames
HID Descriptor
Usage Page: 1 (Generic Desktop Controls)
Usage: 2 (Mouse)
Collection
Report ID: 2
Usage: 1 (Pointer)
Collection
Usage Page: 9 (Buttons)
Usages (1-16): Button 1 (Primary), Button 2 (Secondary), Button 3 (Tertiary), Button 4, Button 5,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown
Logical Minimum: 0
Logical Maximum: 1
Report Count: 16
Report Size: 1
Input: 2 (Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position)

Usage Page: 1 (Generic Desktop Controls)
Logical Minimum: 63489
Logical Maximum: 2047
Report Size: 12
Report Count: 2
Usage: 48 (Direction-X)
Usage: 49 (Direction-Y)
Input: 6 (Data,Variable,Relative,No Wrap,Linear,Preferred State,No Null Position)

Logical Minimum: -127
Logical Maximum: 127
Report Size: 8
Report Count: 1
Usage: 56 (Wheel)
Input: 6 (Data,Variable,Relative,No Wrap,Linear,Preferred State,No Null Position)

Usage Page: 12 (Consumer)
Usage: 568 (AC Pan)
Report Count: 1
Input: 6 (Data,Variable,Relative,No Wrap,Linear,Preferred State,No Null Position)

End Collection
End Collection
Usage Page: 12 (Consumer)
Usage: 1 (Consumer Control)
Collection
Report ID: 3
Report Size: 16
Report Count: 2
Logical Minimum: 1
Logical Maximum: 652
Usages (1-652): Consumer Control, Numeric Key Pad, Programmable Buttons, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, +10, +100, AM/PM,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Power, Reset, Sleep, Sleep After, Sleep Mode,
Illumination, Function Buttons, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Menu, Menu Pick, Menu Up, Menu Down, Menu Left,
Menu Right, Menu Escape, Menu Value Increase, Menu Value Decrease, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Data on Screen, Closed Caption, Closed Caption Select,
VCR/TV, Broadcast Mode, Snapshot, Still, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Selection, Assign Selection, Mode Step, Recall Last,
Enter Channel, Order Movie, Channel, Media Selection, Media Select Computer,
Media Select TV, Media Select WWW, Media Select DVD, Media Select Telephone,
Media Select Program Guide, Media Select Video Phone, Media Select Games, Media Select Messages,
Media Select CD, Media Select VCR, Media Select Tuner, Quit, Help, Media Select Tape,
Media Select Cable, Media Select Satellite, Media Select Security, Media Select Home,
Media Select Call, Channel Increment, Channel Decrement, Media Select SAP,
Unknown, VCR Plus, Once, Daily, Weekly, Monthly, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Play,
Pause, Record, Fast Forward, Rewind, Scan Next Track, Scan Previous Track,
Stop, Eject, Random Play, Select Disc, Enter Disc, Repeat, Tracking, Track Normal,
Slow Tracking, Frame Forward, Frame Back, Mark, Clear Mark, Repeat from Mark,
Return to Mark, Search Mark Forward, Search Mark Backward, Counter Reset, Show Counter,
Tracking Increment, Tracking Decrement, Stop/Eject, Play/Pause, Play/Skip,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Volume,
Balance, Mute, Bass, Treble, Bass Boost, Surround Mode, Loudness, MPX, Volume Increment,
Volume Decrement, Unknown, Unknown, Unknown, Unknown, Unknown, Speed Select,
Playback Speed, Standard Play, Long Play, Extended Play, Slow, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Fan Enable,
Fan Speed, Light Enable, Light Illumination Level, Climate Control Enable,
Room Temperature, Security Enable, Fire Alarm, Police Alarm, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Balance Right, Balance Left,
Bass Increment, Bass Decrement, Treble Increment, Treble Decrement, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Speaker System, Channel Left, Channel Right, Channel Center, Channel Front,
Channel Center Front, Channel Side, Channel Surround, Channel Low Frequency Enhancement,
Channel Top, Channel Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Sub-Channel, Sub-Channel Increment, Sub-Channel Decrement, Alternative Audio Increment,
Alternative Audio Decrement, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Application Launch Buttons, AL Launch Button Configuration Tool,
AL Launch Button Configuration, AL Consumer Control Configuration, AL Word Processor,
AL Text Editor, AL Spreadsheet, AL Graphics Editor, AL Presentation App, AL Database App,
AL Email Reader, AL Newsreader, AL Voicemail, AL Contacts/Address Book, AL Calendar/Schedule,
AL Task/Project Manager, AL Log/Jounal/Timecard, AL Checkbook/Finance, AL Calculator,
AL A/V Capture/Playback, AL Local Machine Browser, AL LAN/Wan Browser, AL Internet Browser,
AL Remote Networking/ISP Connect, AL Network Conference, AL Network Chat, AL Telephony/Dialer,
AL Logon, AL Logoff, AL Logon/Logoff, AL Terminal Local/Screensaver, AL Control Panel,
AL Command Line Processor/Run, AL Process/Task Manager, AL Select Task/Application,
AL Next Task/Application, AL Previous Task/Application, AL Preemptive Halt Task/Application,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Generic GUI Application Controls, AC New, AC Open, AC CLose, AC Exit, AC Maximize,
AC Minimize, AC Save, AC Print, AC Properties, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, AC Undo, AC Copy, AC Cut, AC Paste, AC Select All,
AC Find, AC Find and Replace, AC Search, AC Go To, AC Home, AC Back, AC Forward,
AC Stop, AC Refresh, AC Previous Link, AC Next Link, Unknown, AC History, AC Subscriptions,
AC Zoom In, AC Zoom Out, AC Zoom, AC Full Screen View, AC Normal View, AC View Toggle,
AC Scroll Up, AC Scroll Down, AC Scroll, AC Pan Left, AC Pan Right, AC Pan,
AC New Window, AC Tile Horizontally, AC Tile Vertically, AC Format, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown
Input: 0 (Data,Array,Absolute,No Wrap,Linear,Preferred State,No Null Position)

End Collection
Usage Page: 1 (Generic Desktop Controls)
Usage: 128 (System Control)
Collection
Report ID: 4
Report Size: 2
Report Count: 1
Logical Minimum: 1
Logical Maximum: 3
Usage: 130 (System Sleep)
Usage: 129 (System Power Down)
Usage: 131 (System Wake Up)
Input: 96 (Data,Array,Absolute,No Wrap,Linear,No Preferred State,Null State)

Report Size: 6
Input: 3 (Constant,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position)

End Collection
Usage Page: 65468 (Vendor Specific)
Usage: 136 (Unknown)
Collection
Report ID: 8
Usages (1-255): Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown
Logical Minimum: 1
Logical Maximum: 255
Report Size: 8
Report Count: 1
Input: 0 (Data,Array,Absolute,No Wrap,Linear,Preferred State,No Null Position)

PCap do podsłuchiwania USB. Dzięki niemu wireshark wyświetli nam komunikację na USB.

USBPcap

Według mnie najciekawszy program w tym zestawieniu.

To narzędzie przygotowuje niskopoziomowy sterownik ( WinUSB (opens new window), libusb-win32, libusbK (opens new window)) pod wybrane przez nas urządzenie. Sterownika tego nie musimy podpisywać, wystarczy go zainstalować. Logikę komunikacji musimy zawrzeć w aplikacji, ale możemy “rozmawiać” z dowolnym urządzeniem USB. Gdybyśmy chcieli samemu przygotować sterownik, to czekałaby nas zabawa z Windows DDK (opens new window).

Zadig