From fafd47986239cc2f4dfbbae74b17555608806581 Mon Sep 17 00:00:00 2001 From: Yureka Date: Sat, 3 Aug 2024 23:07:07 +0200 Subject: [PATCH] fix protocol --- src/main.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index abd8f44..1d1a7c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -106,7 +106,7 @@ async fn run() -> Result<()> { data.put_bytes(0x00, 21); data.put(args.auth_token.as_bytes()); data.put_bytes(0x00, 81); - let initial_packet = make_iusb_packet(0x05, 0x01, 0x0000, 0x00, &data); + let initial_packet = make_iusb_packet(0x05, 0x01, 0x00, 0x00, 0x0000, 0x00000000, &data); //println!("SENT:\n{}", pretty_hex(&initial_packet)); write.write_all(&initial_packet).await?; @@ -125,7 +125,7 @@ async fn run() -> Result<()> { while let Some(mut packet) = stream.next().await.transpose()? { //println!("{}", pretty_hex(&packet)); - let seq_num = packet[24]; + let seq_num = u32::from_le_bytes(packet[24..28].try_into().unwrap()); let packet = &mut packet[32..]; let id = packet[4]; @@ -139,7 +139,7 @@ async fn run() -> Result<()> { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00 ]; - let packet = make_iusb_packet(0x80, 0x01, 0x0001, seq_num, resp.as_slice()); + let packet = make_iusb_packet(0x80, 0x01, 0x01, 0x00, 0x0000, seq_num, resp.as_slice()); //println!("SENT:\n{}", pretty_hex(&packet)); write.write_all(&packet).await?; write.flush().await?; @@ -170,7 +170,7 @@ async fn run() -> Result<()> { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, cmd_output.sense[2], cmd_output.sense[12], 0x00, 0x00, 0x00, 0x00, 0x00 ]; - let packet = make_iusb_packet(0x80, 0x01, 0x0001, seq_num, resp.as_slice()); + let packet = make_iusb_packet(0x80, 0x01, 0x01, 0x00, 0x0000, seq_num, resp.as_slice()); //println!("SENT:\n{}", pretty_hex(&packet)); write.write_all(&packet).await?; write.flush().await?; @@ -187,7 +187,7 @@ async fn run() -> Result<()> { resp.put(&resp_data[..]); //println!("responding\n{}", pretty_hex(&resp_data)); - let packet = make_iusb_packet(0x80, 0x01, 0x0001, seq_num, resp.as_slice()); + let packet = make_iusb_packet(0x80, 0x01, 0x01, 0x00, 0x0000, seq_num, resp.as_slice()); //println!("SENT:\n{}", pretty_hex(&packet)); write.write_all(&packet).await?; write.flush().await?; @@ -197,10 +197,12 @@ async fn run() -> Result<()> { } fn make_iusb_packet( + device_type: u8, + protocol: u8, device_number: u8, interface_number: u8, - client_data: u32, - seq_num: u8, + client_data: u16, + seq_num: u32, data: &[u8], ) -> Vec { let data_len: u32 = data.len().try_into().unwrap(); @@ -212,13 +214,15 @@ fn make_iusb_packet( packet.put_u8(0x20); // headers length packet.put_u8(0x00); // checksum (unused) packet.put_u32_le(data_len); // data length - packet.put_bytes(0x0, 1); // unknown + packet.put_u8(0); // server caps + packet.put_u8(device_type); + packet.put_u8(protocol); + packet.put_u8(0x80); // direction (TX) packet.put_u8(device_number); packet.put_u8(interface_number); - packet.put_u8(0x80); // direction (TX) - packet.put_u32_le(client_data); - packet.put_u8(seq_num); - packet.put_bytes(0x00, 7); // reserved + packet.put_u16_le(client_data); + packet.put_u32_le(seq_num); + packet.put_bytes(0x00, 4); // reserved packet.put(data);