usbid

package
v0.0.0-...-5fbd3a7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2024 License: AGPL-3.0, Apache-2.0 Imports: 7 Imported by: 0

README

This Go package is a variant of usbid from https://github.com/google/gousb. It was written by the gousb maintainers and contributors and then adapted for use by LXD.

Main changes:

  • Doesn't load on import (reduced memory footprint).
  • Uses system-local USB database (to always match lsusb).
  • Doesn't import anything outside of built-in Go packages.
  • Doesn't use or indirectly rely on CGO as this code is often used in cross-built static binaries.

Most users will want to stick to the upstream google/gousb version instead. This fork is really meant for LXD's special use case and may be further trimmed down in the future.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Vendors stores the vendor and product ID mappings.
	Vendors map[ID]*Vendor

	// Classes stores the class, subclass and protocol mappings.
	Classes map[ClassCode]*Class
)

Functions

func Load

func Load()

Load reads the USB database from disk.

func ParseIDs

func ParseIDs(r io.Reader) (map[ID]*Vendor, map[ClassCode]*Class, error)

ParseIDs parses and returns mappings from the given reader. In general, this should not be necessary, as a set of mappings is already embedded in the library. If a new or specialized file is obtained, this can be used to retrieve the mappings, which can be stored in the global Vendors and Classes map.

Types

type Class

type Class struct {
	Name     string
	SubClass map[ClassCode]*SubClass
}

A Class contains the name of the class and mappings for each subclass.

func (Class) String

func (c Class) String() string

String returns the name of the class.

type ClassCode

type ClassCode uint8

ClassCode represents a USB-IF (Implementers Forum) class or subclass code.

const (
	ClassPerInterface       ClassCode = 0x00
	ClassAudio              ClassCode = 0x01
	ClassComm               ClassCode = 0x02
	ClassHID                ClassCode = 0x03
	ClassPhysical           ClassCode = 0x05
	ClassImage              ClassCode = 0x06
	ClassPTP                ClassCode = ClassImage // legacy name for image
	ClassPrinter            ClassCode = 0x07
	ClassMassStorage        ClassCode = 0x08
	ClassHub                ClassCode = 0x09
	ClassData               ClassCode = 0x0a
	ClassSmartCard          ClassCode = 0x0b
	ClassContentSecurity    ClassCode = 0x0d
	ClassVideo              ClassCode = 0x0e
	ClassPersonalHealthcare ClassCode = 0x0f
	ClassAudioVideo         ClassCode = 0x10
	ClassBillboard          ClassCode = 0x11
	ClassUSBTypeCBridge     ClassCode = 0x12
	ClassDiagnosticDevice   ClassCode = 0xdc
	ClassWireless           ClassCode = 0xe0
	ClassMiscellaneous      ClassCode = 0xef
	ClassApplication        ClassCode = 0xfe
	ClassVendorSpec         ClassCode = 0xff
)

Standard classes defined by USB spec, see https://www.usb.org/defined-class-codes

func (ClassCode) String

func (c ClassCode) String() string

type ID

type ID uint16

ID represents a vendor or product ID.

func (ID) String

func (id ID) String() string

String returns a hexadecimal ID.

type Product

type Product struct {
	Name      string
	Interface map[ID]string
}

A Product contains the name of the product (from a particular vendor) and the names of any interfaces that were specified.

func (Product) String

func (p Product) String() string

String returns the name of the product.

type Protocol

type Protocol uint8

Protocol is the interface class protocol, qualified by the values of interface class and subclass.

func (Protocol) String

func (p Protocol) String() string

type SubClass

type SubClass struct {
	Name     string
	Protocol map[Protocol]string
}

A SubClass contains the name of the subclass and any associated protocols.

func (SubClass) String

func (s SubClass) String() string

String returns the name of the SubClass.

type Vendor

type Vendor struct {
	Name    string
	Product map[ID]*Product
}

A Vendor contains the name of the vendor and mappings corresponding to all known products by their ID.

func (Vendor) String

func (v Vendor) String() string

String returns the name of the vendor.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL