added logging

This commit is contained in:
duffyduck 2026-02-18 23:33:07 +01:00
parent 219214c0a6
commit 0202cb4a7f
3 changed files with 31 additions and 0 deletions

Binary file not shown.

Binary file not shown.

View File

@ -336,6 +336,26 @@ func (s *Server) handleCmdSubmit(r io.Reader, hdr *URBHeader, retChan chan<- []b
endpoint := uint8(hdr.Endpoint)
urbType := s.getURBType(endpoint)
dirStr := "OUT"
if hdr.Direction == DirIn {
dirStr = "IN"
}
// Log all transfers for debugging
if endpoint == 0 {
bmReqType := body.Setup[0]
bReq := body.Setup[1]
wVal := binary.LittleEndian.Uint16(body.Setup[2:4])
wIdx := binary.LittleEndian.Uint16(body.Setup[4:6])
wLen := binary.LittleEndian.Uint16(body.Setup[6:8])
log.Printf("[usbip-server] CTRL %s seq=%d bmReqType=0x%02x bReq=0x%02x wVal=0x%04x wIdx=0x%04x wLen=%d bufLen=%d",
dirStr, hdr.SeqNum, bmReqType, bReq, wVal, wIdx, wLen, body.TransferBufferLen)
} else {
typeNames := map[uint8]string{0: "ISO", 1: "INT", 2: "CTRL", 3: "BULK"}
log.Printf("[usbip-server] EP%d %s seq=%d type=%s bufLen=%d numPkts=%d",
endpoint, dirStr, hdr.SeqNum, typeNames[urbType], body.TransferBufferLen, numPackets)
}
// Handle control transfers specially (endpoint 0)
if endpoint == 0 && hdr.Direction == DirIn {
buf := make([]byte, body.TransferBufferLen)
@ -348,6 +368,7 @@ func (s *Server) handleCmdSubmit(r io.Reader, hdr *URBHeader, retChan chan<- []b
)
var status int32
if err != nil {
log.Printf("[usbip-server] CTRL IN failed: %v", err)
status = -32 // -EPIPE
n = 0
}
@ -441,6 +462,7 @@ func (s *Server) handleCmdSubmit(r io.Reader, hdr *URBHeader, retChan chan<- []b
UserContext: uintptr(hdr.SeqNum),
})
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)
retChan <- resp
return nil
@ -494,6 +516,9 @@ func (s *Server) handleISOSubmit(hdr *URBHeader, body *CmdSubmitBody, transferBu
}
// Submit ISO URB
log.Printf("[usbip-server] ISO submit: ep=0x%02x dir=%d pkts=%d totalBuf=%d",
ep, hdr.Direction, numPackets, totalBufLen)
urb, isoMem, err := s.handle.SubmitISOURB(&usb.SubmitISOURBParams{
Endpoint: ep,
Flags: 0x02, // URB_ISO_ASAP
@ -503,6 +528,7 @@ func (s *Server) handleISOSubmit(hdr *URBHeader, body *CmdSubmitBody, transferBu
UserContext: uintptr(hdr.SeqNum),
})
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)
retChan <- resp
@ -601,6 +627,11 @@ func (s *Server) reapLoop(retChan chan<- []byte, done <-chan struct{}) {
continue
}
if urbInfo.Status != 0 {
log.Printf("[usbip-server] URB completed: seq=%d ep=%d status=%d actual=%d iso=%v",
pending.seqNum, pending.endpoint, urbInfo.Status, urbInfo.ActualLength, pending.isISO)
}
var resp []byte
if pending.isISO {
resp, err = s.buildISOResponse(urbInfo, pending)