Fix ActualLength=0 for OUT transfers in BuildRetSubmit

This commit is contained in:
2026-02-19 00:14:19 +01:00
parent 3579924883
commit d3100e584d
4 changed files with 20 additions and 23 deletions
+12 -8
View File
@@ -372,7 +372,7 @@ func (s *Server) handleCmdSubmit(r io.Reader, hdr *URBHeader, retChan chan<- []b
status = -32 // -EPIPE
n = 0
}
resp, err := BuildRetSubmit(hdr.SeqNum, hdr.DevID, hdr.Direction, hdr.Endpoint, status, buf[:n])
resp, err := BuildRetSubmit(hdr.SeqNum, hdr.DevID, hdr.Direction, hdr.Endpoint, status, uint32(n), buf[:n])
if err != nil {
return err
}
@@ -387,6 +387,7 @@ func (s *Server) handleCmdSubmit(r io.Reader, hdr *URBHeader, retChan chan<- []b
wIndex := binary.LittleEndian.Uint16(body.Setup[4:6])
var status int32
var actualLength uint32
// Intercept standard USB requests that require special usbdevfs ioctls.
// Raw control transfers via USBDEVFS_CONTROL don't update kernel state.
@@ -415,7 +416,7 @@ func (s *Server) handleCmdSubmit(r io.Reader, hdr *URBHeader, retChan chan<- []b
if buf == nil {
buf = make([]byte, 0)
}
_, err := s.handle.ControlTransfer(
n, err := s.handle.ControlTransfer(
bmRequestType, bRequest, wValue, wIndex,
binary.LittleEndian.Uint16(body.Setup[6:8]),
5000, buf,
@@ -424,13 +425,14 @@ func (s *Server) handleCmdSubmit(r io.Reader, hdr *URBHeader, retChan chan<- []b
log.Printf("[usbip-server] CTRL OUT seq=%d failed: %v", hdr.SeqNum, err)
status = -32 // -EPIPE
} else {
log.Printf("[usbip-server] CTRL OUT seq=%d OK (bmReqType=0x%02x bReq=0x%02x wVal=0x%04x)",
hdr.SeqNum, bmRequestType, bRequest, wValue)
actualLength = uint32(n)
log.Printf("[usbip-server] CTRL OUT seq=%d OK actualLength=%d (bmReqType=0x%02x bReq=0x%02x wVal=0x%04x)",
hdr.SeqNum, n, bmRequestType, bRequest, wValue)
}
}
log.Printf("[usbip-server] CTRL OUT seq=%d → response status=%d", hdr.SeqNum, status)
resp, err := BuildRetSubmit(hdr.SeqNum, hdr.DevID, hdr.Direction, hdr.Endpoint, status, nil)
log.Printf("[usbip-server] CTRL OUT seq=%d → response status=%d actualLength=%d", hdr.SeqNum, status, actualLength)
resp, err := BuildRetSubmit(hdr.SeqNum, hdr.DevID, hdr.Direction, hdr.Endpoint, status, actualLength, nil)
if err != nil {
return err
}
@@ -468,7 +470,7 @@ func (s *Server) handleCmdSubmit(r io.Reader, hdr *URBHeader, retChan chan<- []b
})
if err != nil {
log.Printf("[usbip-server] SubmitURB(ep=0x%02x, type=%d, len=%d) FAILED: %v", ep, urbType, len(buf), err)
resp, _ := BuildRetSubmit(hdr.SeqNum, hdr.DevID, hdr.Direction, hdr.Endpoint, -32, nil)
resp, _ := BuildRetSubmit(hdr.SeqNum, hdr.DevID, hdr.Direction, hdr.Endpoint, -32, 0, nil)
retChan <- resp
return nil
}
@@ -535,7 +537,7 @@ func (s *Server) handleISOSubmit(hdr *URBHeader, body *CmdSubmitBody, transferBu
if err != nil {
log.Printf("[usbip-server] ISO submit FAILED: %v", err)
// Submit failed - send error response
resp, _ := BuildRetSubmit(hdr.SeqNum, hdr.DevID, hdr.Direction, hdr.Endpoint, -32, nil)
resp, _ := BuildRetSubmit(hdr.SeqNum, hdr.DevID, hdr.Direction, hdr.Endpoint, -32, 0, nil)
retChan <- resp
return nil
}
@@ -653,6 +655,7 @@ func (s *Server) reapLoop(retChan chan<- []byte, done <-chan struct{}) {
pending.direction,
pending.endpoint,
urbInfo.Status,
uint32(urbInfo.ActualLength),
data,
)
}
@@ -708,6 +711,7 @@ func (s *Server) buildISOResponse(urbInfo *usb.ReapedURBInfo, pending *pendingUR
pending.direction,
pending.endpoint,
urbInfo.Status,
uint32(urbInfo.ActualLength),
packedData,
uint32(urbInfo.StartFrame),
pending.numPackets,