Skip to content

Commit

Permalink
Advertise _BBPP-ipp-usb._tcp for each handled device (see #28)
Browse files Browse the repository at this point in the history
    For each device that ipp-usb handles, a service with the
    name in the form _BBPP-ipp-usb._tcp, where BB and PP are
    USB bus/port numbers in hex, is advertised

    The purpose of this change is to let legacy drivers to easily
    detect that device is handled by the ipp-usb, to avoid possible
    conflicts

    See discussion at #28
  • Loading branch information
alexpevzner committed May 2, 2021
1 parent d38fc75 commit e6c3c39
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package main

import (
"context"
"fmt"
"net"
"net/http"
"time"
Expand Down Expand Up @@ -132,6 +133,18 @@ func NewDevice(desc UsbDeviceDesc) (*Device, error) {
// Advertise Web service. Assume it always exists
dnssdServices.Add(DNSSdSvcInfo{Type: "_http._tcp", Port: dev.State.HTTPPort})

// Advertise "_BBPP-ipp-usb._tcp" service, where BB and PP are bus and
// port numbers in hex, so legacy drivers can easily check if device
// is handled by the ipp-usb
//
// See the following for details:
// https://github.com/OpenPrinting/ipp-usb/issues/28
dnssdServices.Add(DNSSdSvcInfo{
Type: fmt.Sprintf("_%.2x%.2x-ipp-usb._tcp",
desc.Bus,
info.PortNum),
})

// Enable handling incoming requests
dev.UsbTransport.SetDeadline(time.Time{})
dev.HTTPProxy.Enable()
Expand Down
1 change: 1 addition & 0 deletions usbcommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ type UsbDeviceInfo struct {
SerialNumber string // Device serial number
Manufacturer string // Manufacturer name
ProductName string // Product name
PortNum int // USB port number

// Precomputed fields
MfgAndProduct string // Product with Manufacturer prefix, if needed
Expand Down
2 changes: 2 additions & 0 deletions usbio_libusb.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ func (devhandle *UsbDevHandle) UsbDeviceInfo() (UsbDeviceInfo, error) {
}
}

info.PortNum = int(C.libusb_get_port_number(dev))

info.FixUp()

return info, nil
Expand Down

0 comments on commit e6c3c39

Please sign in to comment.