func addEndpoints(conf *usb.InterfaceDescriptor) endpoints {
	var e endpoints
	e.in = &usb.EndpointDescriptor{}
	e.in.SetDefaults()
	e.in.Attributes = 0x03
	e.in.EndpointAddress = 0x81
	e.in.MaxPacketSize = 512
	e.in.Interval = 1
	e.out = &usb.EndpointDescriptor{}
	e.out.SetDefaults()
	e.out.Attributes = 0x03
	e.out.EndpointAddress = 0x01
	e.out.MaxPacketSize = 512
	e.out.Interval = 1
	conf.Endpoints = append(conf.Endpoints, e.out, e.in)
	return e
}
addEndpoints adds an input and output endpoint to conf, returns a endpoints instance to let
the caller determine their behavior.
package fidati
import (
	"bytes"
	"encoding/binary"
	"errors"
	"fmt"
	"github.com/f-secure-foundry/tamago/soc/imx6/usb"
	"github.com/gsora/fidati/internal/flog"
	"github.com/gsora/fidati/u2fhid"
)
const (
	hidRequestSetIdle           = 10
	hidRequestTypeGetDescriptor = 0x21
	descriptorTypeGetReport     = 0x22
)
type hidDescriptor struct {
	Length               uint8
	Type                 uint8
	bcdHID               uint16
	CountryCode          uint8
	NumDescriptors       uint8
	ReportDescriptorType uint8
	DescriptorLength     uint16
}
func (d *hidDescriptor) setDefaults() {
	d.Length = 0x09
	d.Type = 0x21
	d.bcdHID = 0x101
}
func (d *hidDescriptor) bytes() []byte {
	buf := new(bytes.Buffer)
	binary.Write(buf, binary.LittleEndian, d)
	return buf.Bytes()
}
func configureDevice(device *usb.Device, conf *usb.ConfigurationDescriptor, u2fHandler *u2fhid.Handler) error {
	device.Setup = hidSetup(device)
	id, err := addInterface(device, conf)
	if err != nil {
		return fmt.Errorf("cannot add U2F USB Interface, %w", err)
	}
	endpoints := addEndpoints(id)
	endpoints.in.Function = u2fHandler.Tx
	endpoints.out.Function = u2fHandler.Rx
	addHIDClassDescriptor(id)
	device.Qualifier = &usb.DeviceQualifierDescriptor{}
	device.Qualifier.SetDefaults()
	device.Qualifier.NumConfigurations = uint8(len(device.Configurations))
	return nil
}
func addInterface(device *usb.Device, conf *usb.ConfigurationDescriptor) (*usb.InterfaceDescriptor, error) {
	id := &usb.InterfaceDescriptor{}
	id.SetDefaults()
	id.NumEndpoints = 2
	id.InterfaceClass = 0x03
	id.InterfaceSubClass = 0x0
	id.InterfaceProtocol = 0x0
	var err error
	id.Interface, err = device.AddString("fidati interface descriptor")
	if err != nil {
		return nil, err
	}
	conf.AddInterface(id)
	return id, nil
}
type endpoints struct {
	in  *usb.EndpointDescriptor
	out *usb.EndpointDescriptor
}