Skip to content

Commit

Permalink
usb: move vendor/trezor/usbhid -> usb/lowlevel
Browse files Browse the repository at this point in the history
There is less and less sense for keeping usbhid and trezord-go as two github projects.
  • Loading branch information
karelbilek committed Jul 6, 2018
1 parent de17b6a commit cc90c6f
Show file tree
Hide file tree
Showing 69 changed files with 55 additions and 63 deletions.
8 changes: 1 addition & 7 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
name = "github.com/gorilla/mux"
version = "1.6.1"

[[constraint]]
branch = "master"
name = "github.com/trezor/usbhid"

[[constraint]]
name = "gopkg.in/natefinch/lumberjack.v2"
version = "2.1.0"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,6 @@ Server supports following API calls:

* (C) 2018 Karel Bilek, Jan Pochyla
* CORS Copyright (c) 2013 The Gorilla Handlers Authors, [BSD license](https://github.com/gorilla/handlers/blob/master/LICENSE)
* (c) 2017 Jason T. Harris (also see https://github.com/deadsy/libusb for comprehensive list)
* (C) 2017 Péter Szilágyi (also see https://github.com/karalabe/hid for comprehensive list)
* Licensed under LGPLv3
4 changes: 2 additions & 2 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
// and dealing with sessions, mutexes, ...
//
// USB package is not imported for efficiency
// reasons - USB package uses imports trezor/usbhid and
// usbhid uses cgo, so it takes about 25 seconds to build;
// reasons - USB package uses imports /usb/lowlevel and
// /usb/lowlevel uses cgo, so it takes about 25 seconds to build;
// so building just this package on its own
// takes less seconds when we dont import USB
// package and use abstract interfaces instead
Expand Down
14 changes: 7 additions & 7 deletions usb/hidapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"sync"
"sync/atomic"

"github.com/trezor/usbhid"
"github.com/trezor/trezord-go/usb/lowlevel"

"github.com/trezor/trezord-go/core"
"github.com/trezor/trezord-go/memorywriter"
Expand All @@ -36,7 +36,7 @@ func (b *HIDAPI) Enumerate() ([]Info, error) {
var infos []Info

b.mw.Println("hidapi - enumerate - low level")
devs := usbhid.HidEnumerate(0, 0)
devs := lowlevel.HidEnumerate(0, 0)

b.mw.Println("hidapi - enumerate - low level done")

Expand All @@ -58,7 +58,7 @@ func (b *HIDAPI) Has(path string) bool {

func (b *HIDAPI) Connect(path string) (Device, error) {
b.mw.Println("hidapi - connect - enumerate to find")
devs := usbhid.HidEnumerate(0, 0)
devs := lowlevel.HidEnumerate(0, 0)
b.mw.Println("hidapi - connect - enumerate done")

for _, dev := range devs { // enumerate all devices
Expand All @@ -84,22 +84,22 @@ func (b *HIDAPI) Connect(path string) (Device, error) {
return nil, ErrNotFound
}

func (b *HIDAPI) match(d *usbhid.HidDeviceInfo) bool {
func (b *HIDAPI) match(d *lowlevel.HidDeviceInfo) bool {
vid := d.VendorID
pid := d.ProductID
trezor1 := vid == core.VendorT1 && (pid == core.ProductT1Firmware)
trezor2 := vid == core.VendorT2 && (pid == core.ProductT2Firmware || pid == core.ProductT2Bootloader)
return (trezor1 || trezor2) && (d.Interface == hidIfaceNum || d.UsagePage == hidUsagePage)
}

func (b *HIDAPI) identify(dev *usbhid.HidDeviceInfo) string {
func (b *HIDAPI) identify(dev *lowlevel.HidDeviceInfo) string {
path := []byte(dev.Path)
digest := sha256.Sum256(path)
return hidapiPrefix + hex.EncodeToString(digest[:])
}

type HID struct {
dev *usbhid.HidDevice
dev *lowlevel.HidDevice
prepend bool // on windows, see detectPrepend

closed int32 // atomic
Expand Down Expand Up @@ -133,7 +133,7 @@ var unknownErrorMessage = "hidapi: unknown failure"
// or a newer one that is on id 0.
// The older one does not need prepending, the newer one does
// This makes difference only on windows
func detectPrepend(dev *usbhid.HidDevice) (bool, error) {
func detectPrepend(dev *lowlevel.HidDevice) (bool, error) {
buf := []byte{63}
for i := 0; i < 63; i++ {
buf = append(buf, 0xff)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2308,7 +2308,7 @@ static void usbi_log_str(struct libusb_context *ctx,
{
UNUSED(ctx);
UNUSED(level);
goUsbHidLog(str);
goLog(str);
}

void usbi_log_v(struct libusb_context *ctx, enum libusb_log_level level,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

// +build linux,cgo darwin,!ios,cgo windows,cgo

package usbhid
package lowlevel

/*
extern void goUsbHidLog(const char *s);
extern void goLog(const char *s);
#define ENABLE_LOGGING 1
#define ENABLE_DEBUG_LOGGING 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Copyright (c) 2017 Jason T. Harris
//-----------------------------------------------------------------------------

// Package libusb provides go wrappers for libusb-1.0
package usbhid
package lowlevel

/*
// +build linux,cgo darwin,!ios,cgo windows,cgo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package usbhid
package lowlevel

import (
"io"
Expand All @@ -12,8 +12,8 @@ func SetLogWriter(l io.Writer) {
writer = l
}

//export goUsbHidLog
func goUsbHidLog(s *C.char) {
//export goLog
func goLog(s *C.char) {
if writer != nil {
writer.Write([]byte(C.GoString(s)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// +build !ios
// +build linux darwin windows

package usbhid
package lowlevel

/*
#include <wchar.h>
Expand Down
Loading

0 comments on commit cc90c6f

Please sign in to comment.