Skip to content

Commit a1bad7c

Browse files
committed
Detach from device, if it doesn't speak IPP over USB protocol (see #52)
Some devices (so far, only HP-rebranded Samsung devices known to have such a defect) offer 7/1/4 interfaces, but actually provide no functionality behind these interfaces and respond with `HTTP 404 Not found` to all the HTTP requests sent to USB ipp-usb ignores such devices to let legacy/proprietary drivers a chance to work with them
1 parent c695533 commit a1bad7c

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

device.go

+15
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,21 @@ func NewDevice(desc UsbDeviceDesc) (*Device, error) {
131131
}
132132
}
133133

134+
// Skip the device, if it cannot do something useful
135+
//
136+
// Some devices (so far, only HP-rebranded Samsung devices
137+
// known to have such a defect) offer 7/1/4 interfaces, but
138+
// actually provide no functionality behind these interfaces
139+
// and respond with `HTTP 404 Not found` to all the HTTP
140+
// requests sent to USB
141+
//
142+
// ipp-usb ignores such devices to let a chance for
143+
// legacy/proprietary drivers to work with them
144+
if len(dnssdServices) == 0 {
145+
err = ErrUnusable
146+
goto ERROR
147+
}
148+
134149
// Advertise Web service. Assume it always exists
135150
dnssdServices.Add(DNSSdSvcInfo{Type: "_http._tcp", Port: dev.State.HTTPPort})
136151

err.go

+1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ var (
1818
ErrShutdown = errors.New("Shutdown requested")
1919
ErrBlackListed = errors.New("Device is blacklisted")
2020
ErrInitTimedOut = errors.New("Device initialization timed out")
21+
ErrUnusable = errors.New("Device doesn't implement print or scan service")
2122
)

pnp.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ const (
2626
)
2727

2828
// pnpRetryTime returns time of next retry of failed device initialization
29-
func pnpRetryTime() time.Time {
29+
func pnpRetryTime(err error) time.Time {
30+
if err == ErrBlackListed || err == ErrUnusable {
31+
// These errors are unrecoverable.
32+
// Forget about device for the next million hours :-)
33+
return time.Now().Add(time.Hour * 1e6)
34+
}
35+
3036
return time.Now().Add(DevInitRetryInterval)
3137
}
3238

@@ -74,7 +80,7 @@ loop:
7480
devByAddr[addr] = dev
7581
} else {
7682
Log.Error('!', "PNP %s: %s", addr, err)
77-
retryByAddr[addr] = pnpRetryTime()
83+
retryByAddr[addr] = pnpRetryTime(err)
7884
}
7985
}
8086

@@ -103,7 +109,7 @@ loop:
103109
delete(retryByAddr, addr)
104110
} else {
105111
Log.Error('!', "PNP %s: %s", addr, err)
106-
retryByAddr[addr] = pnpRetryTime()
112+
retryByAddr[addr] = pnpRetryTime(err)
107113
}
108114
}
109115
}

0 commit comments

Comments
 (0)