Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions enumerator/enumerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type PortDetails struct {
IsUSB bool
VID string
PID string
MI string
SerialNumber string

// Manufacturer string
Expand Down
5 changes: 5 additions & 0 deletions enumerator/usb_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func parseUSBSysFS(usbDevicePath string, details *PortDetails) error {
if err != nil {
return err
}
mi, err := readLine(filepath.Join(usbDevicePath, "bInterfaceNumber"))
if err != nil {
return err
}
serial, err := readLine(filepath.Join(usbDevicePath, "serial"))
if err != nil {
return err
Expand All @@ -88,6 +92,7 @@ func parseUSBSysFS(usbDevicePath string, details *PortDetails) error {
details.IsUSB = true
details.VID = vid
details.PID = pid
details.MI = mi
details.SerialNumber = serial
//details.Manufacturer = manufacturer
//details.Product = product
Expand Down
18 changes: 10 additions & 8 deletions enumerator/usb_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,34 @@ import (
func parseDeviceID(deviceID string, details *PortDetails) {
// Windows stock USB-CDC driver
if len(deviceID) >= 3 && deviceID[:3] == "USB" {
re := regexp.MustCompile("VID_(....)&PID_(....)(\\\\(\\w+)$)?").FindAllStringSubmatch(deviceID, -1)
if re == nil || len(re[0]) < 2 {
re := regexp.MustCompile("VID_(....)&PID_(....)&MI_(..)(\\\\(\\w+)$)?").FindAllStringSubmatch(deviceID, -1)
if re == nil || len(re[0]) < 3 {
// Silently ignore unparsable strings
return
}
details.IsUSB = true
details.VID = re[0][1]
details.PID = re[0][2]
if len(re[0]) >= 4 {
details.SerialNumber = re[0][4]
details.MI = re[0][3]
if len(re[0]) >= 5 {
details.SerialNumber = re[0][5]
}
return
}

// FTDI driver
if len(deviceID) >= 7 && deviceID[:7] == "FTDIBUS" {
re := regexp.MustCompile("VID_(....)\\+PID_(....)(\\+(\\w+))?").FindAllStringSubmatch(deviceID, -1)
if re == nil || len(re[0]) < 2 {
re := regexp.MustCompile("VID_(....)\\+PID_(....)+MI_(..)(\\+(\\w+))?").FindAllStringSubmatch(deviceID, -1)
if re == nil || len(re[0]) < 3 {
// Silently ignore unparsable strings
return
}
details.IsUSB = true
details.VID = re[0][1]
details.PID = re[0][2]
if len(re[0]) >= 4 {
details.SerialNumber = re[0][4]
details.MI = re[0][3]
if len(re[0]) >= 5 {
details.SerialNumber = re[0][5]
}
return
}
Expand Down