How spiceorg/usbredir works
Project type and purpose
• usbredir is an open‐source toolkit implementing a USB redirection protocol
• Provides:
– usbredirparser: a standalone C library to parse/serialize the usbredir protocol
– usbredirhost: a C library that bridges libusb (real USB) with usbredir frames
– usbredirserver: a TCP‐based server using usbredirhost
– usbredirtestclient: a small client that uses usbredirparser to talk over TCP
Main components of the system
A. External USB device
B. libusb (native USB I/O library)
C. usbredirhost library
– Reads/writes USB via libusb
– Delegates framing to usbredirparser
– Exposes transport read/write callbacks
D. usbredirparser library
– Core encoder/decoder for usb‐redirection‐protocol.txt
– Shared by host library and test client
E. usbredirserver executable
– Implements a TCP listener
– Hooks its socket I/O into usbredirhost’s transport callbacks
F. usbredirtestclient executable
– Opens a TCP socket to usbredirserver
– Uses usbredirparser to build/parse frames
Relationships and data flow
USB Device → libusb API → usbredirhost
usbredirhost ↔ usbredirparser (encode/decode)
usbredirhost.transport callbacks ↔ TCP network
TCP network ↔ { usbredirserver, usbredirtestclient }
Architectural patterns & design principles
• Layered separation:
1. Hardware abstraction (libusb)
2. Host logic (usbredirhost)
3. Protocol logic (usbredirparser)
4. Applications (server & test client)
• Single responsibility: parser library only handles framing; host library only handles USB/transport glue
• Reusability: parser is a common core for all clients/servers
Additional details to capture
• Under parser, note “usbredirparser/*.c, *.h”
• Under server and client, list their source directories
• File usb-redirection-protocol.txt as the protocol definition