diff --git a/lib/src/lib.rs b/lib/src/lib.rs index ac25d99..a816641 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -326,23 +326,14 @@ pub async fn handle_urb_loop { - if response_tx.send(bytes).await.is_err() { - break Err(std::io::Error::other("Response channel closed")); - } - } - Err(e) => warn!("Failed to serialize response for devid mismatch: {e}"), - } - continue; + break Err(std::io::Error::other("devid mismatch")); } // Validate endpoint number (must be 0-15 per USB spec). @@ -575,29 +566,15 @@ pub async fn handle_urb_loop { trace!("Got USBIP_CMD_UNLINK for seqnum={unlink_seqnum:10x?}"); - // Validate devid matches the imported device. - // On mismatch, respond with status 0 ("not found"), matching - // the Linux kernel's stub_recv_cmd_unlink() which returns 0 - // when the target URB doesn't exist. + // Validate devid matches the imported device. The Linux + // kernel's valid_request() in stub_rx.c performs this same + // check and tears down the connection on mismatch. if header.devid != expected_devid { warn!( - "UNLINK devid mismatch: got {:#x}, expected {:#x}", + "UNLINK devid mismatch: got {:#x}, expected {:#x} — closing connection", header.devid, expected_devid ); - header.command = USBIP_RET_UNLINK.into(); - let res = UsbIpResponse::UsbIpRetUnlink { - header: header.clone(), - status: 0, - }; - match res.to_bytes() { - Ok(bytes) => { - if response_tx.send(bytes).await.is_err() { - break Err(std::io::Error::other("Response channel closed")); - } - } - Err(e) => warn!("Failed to serialize UNLINK devid mismatch response: {e}"), - } - continue; + break Err(std::io::Error::other("devid mismatch")); } header.command = USBIP_RET_UNLINK.into();