fix protocol
This commit is contained in:
parent
a1ec0384e7
commit
fafd479862
28
src/main.rs
28
src/main.rs
|
@ -106,7 +106,7 @@ async fn run() -> Result<()> {
|
||||||
data.put_bytes(0x00, 21);
|
data.put_bytes(0x00, 21);
|
||||||
data.put(args.auth_token.as_bytes());
|
data.put(args.auth_token.as_bytes());
|
||||||
data.put_bytes(0x00, 81);
|
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));
|
//println!("SENT:\n{}", pretty_hex(&initial_packet));
|
||||||
write.write_all(&initial_packet).await?;
|
write.write_all(&initial_packet).await?;
|
||||||
|
@ -125,7 +125,7 @@ async fn run() -> Result<()> {
|
||||||
while let Some(mut packet) = stream.next().await.transpose()? {
|
while let Some(mut packet) = stream.next().await.transpose()? {
|
||||||
//println!("{}", pretty_hex(&packet));
|
//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 packet = &mut packet[32..];
|
||||||
let id = packet[4];
|
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, 0x01, 0x03, 0x30,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00
|
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));
|
//println!("SENT:\n{}", pretty_hex(&packet));
|
||||||
write.write_all(&packet).await?;
|
write.write_all(&packet).await?;
|
||||||
write.flush().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, 0x01, cmd_output.sense[2], cmd_output.sense[12],
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00
|
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));
|
//println!("SENT:\n{}", pretty_hex(&packet));
|
||||||
write.write_all(&packet).await?;
|
write.write_all(&packet).await?;
|
||||||
write.flush().await?;
|
write.flush().await?;
|
||||||
|
@ -187,7 +187,7 @@ async fn run() -> Result<()> {
|
||||||
resp.put(&resp_data[..]);
|
resp.put(&resp_data[..]);
|
||||||
|
|
||||||
//println!("responding\n{}", pretty_hex(&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));
|
//println!("SENT:\n{}", pretty_hex(&packet));
|
||||||
write.write_all(&packet).await?;
|
write.write_all(&packet).await?;
|
||||||
write.flush().await?;
|
write.flush().await?;
|
||||||
|
@ -197,10 +197,12 @@ async fn run() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_iusb_packet(
|
fn make_iusb_packet(
|
||||||
|
device_type: u8,
|
||||||
|
protocol: u8,
|
||||||
device_number: u8,
|
device_number: u8,
|
||||||
interface_number: u8,
|
interface_number: u8,
|
||||||
client_data: u32,
|
client_data: u16,
|
||||||
seq_num: u8,
|
seq_num: u32,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
) -> Vec<u8> {
|
) -> Vec<u8> {
|
||||||
let data_len: u32 = data.len().try_into().unwrap();
|
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(0x20); // headers length
|
||||||
packet.put_u8(0x00); // checksum (unused)
|
packet.put_u8(0x00); // checksum (unused)
|
||||||
packet.put_u32_le(data_len); // data length
|
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(device_number);
|
||||||
packet.put_u8(interface_number);
|
packet.put_u8(interface_number);
|
||||||
packet.put_u8(0x80); // direction (TX)
|
packet.put_u16_le(client_data);
|
||||||
packet.put_u32_le(client_data);
|
packet.put_u32_le(seq_num);
|
||||||
packet.put_u8(seq_num);
|
packet.put_bytes(0x00, 4); // reserved
|
||||||
packet.put_bytes(0x00, 7); // reserved
|
|
||||||
|
|
||||||
packet.put(data);
|
packet.put(data);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue