diff --git a/usb/config.go b/usb/config.go index 24793ab..95a0669 100644 --- a/usb/config.go +++ b/usb/config.go @@ -86,7 +86,7 @@ type InterfaceSetup struct { // IfClass is the USB-IF subclass code, as defined by the USB spec. IfSubClass Class // IfProtocol is USB protocol code, as defined by the USB spe.c - IfProtocol uint8 + IfProtocol Protocol // Endpoints has the list of endpoints available on this interface with // this alternate setting. Endpoints []EndpointInfo diff --git a/usb/constants.go b/usb/constants.go index c5f8486..6ecbfe2 100644 --- a/usb/constants.go +++ b/usb/constants.go @@ -19,6 +19,7 @@ package usb import "C" import "strconv" +// Class represents a USB-IF class or subclass code. type Class uint8 const ( @@ -58,6 +59,14 @@ func (c Class) String() string { return strconv.Itoa(int(c)) } +// Protocol is the interface class protocol, qualified by the values +// of interface class and subclass. +type Protocol uint8 + +func (p Protocol) String() string { + return strconv.Itoa(int(p)) +} + type DescriptorType uint8 const ( diff --git a/usb/descriptor.go b/usb/descriptor.go index 796ae3d..4911d4e 100644 --- a/usb/descriptor.go +++ b/usb/descriptor.go @@ -29,9 +29,9 @@ type Descriptor struct { Product ID // The Product identifier // Protocol information - Class Class // The class of this device - SubClass Class // The sub-class (within the class) of this device - Protocol uint8 // The protocol (within the sub-class) of this device + Class Class // The class of this device + SubClass Class // The sub-class (within the class) of this device + Protocol Protocol // The protocol (within the sub-class) of this device // Configuration information Configs []ConfigInfo diff --git a/usb/libusb.go b/usb/libusb.go index 4b7b13a..e7c6dd3 100644 --- a/usb/libusb.go +++ b/usb/libusb.go @@ -245,7 +245,7 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*Descriptor, error) { Alternate: uint8(alt.bAlternateSetting), IfClass: Class(alt.bInterfaceClass), IfSubClass: Class(alt.bInterfaceSubClass), - IfProtocol: uint8(alt.bInterfaceProtocol), + IfProtocol: Protocol(alt.bInterfaceProtocol), } var ends []C.struct_libusb_endpoint_descriptor *(*reflect.SliceHeader)(unsafe.Pointer(&ends)) = reflect.SliceHeader{ @@ -278,7 +278,7 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*Descriptor, error) { Product: ID(desc.idProduct), Class: Class(desc.bDeviceClass), SubClass: Class(desc.bDeviceSubClass), - Protocol: uint8(desc.bDeviceProtocol), + Protocol: Protocol(desc.bDeviceProtocol), Configs: cfgs, }, nil } diff --git a/usbid/describe.go b/usbid/describe.go index 1f6c850..c3dbc8c 100644 --- a/usbid/describe.go +++ b/usbid/describe.go @@ -58,7 +58,7 @@ func Describe(val interface{}) string { func Classify(val interface{}) string { var ( class, sub usb.Class - proto uint8 + proto usb.Protocol ) switch val := val.(type) { case *usb.Descriptor: diff --git a/usbid/parse.go b/usbid/parse.go index e5a7b38..4550b72 100644 --- a/usbid/parse.go +++ b/usbid/parse.go @@ -63,7 +63,7 @@ func (c Class) String() string { // A SubClass contains the name of the subclass and any associated protocols. type SubClass struct { Name string - Protocol map[uint8]string + Protocol map[usb.Protocol]string } // String returns the name of the SubClass. @@ -186,9 +186,9 @@ func ParseIDs(r io.Reader) (map[usb.ID]*Vendor, map[usb.Class]*Class, error) { } if subclass.Protocol == nil { - subclass.Protocol = make(map[uint8]string) + subclass.Protocol = make(map[usb.Protocol]string) } - subclass.Protocol[uint8(id)] = name + subclass.Protocol[usb.Protocol(id)] = name default: return fmt.Errorf("too many levels of nesting for class") diff --git a/usbid/testdata_test.go b/usbid/testdata_test.go index 7b6f0fe..a401a7a 100644 --- a/usbid/testdata_test.go +++ b/usbid/testdata_test.go @@ -64,7 +64,7 @@ var ( 0x01: {Name: "Direct Line"}, 0x02: { Name: "Abstract (modem)", - Protocol: map[uint8]string{ + Protocol: map[usb.Protocol]string{ 0x00: "None", 0x01: "AT-commands (v.25ter)", 0x02: "AT-commands (PCCA101)",