Skip to content

Commit 70da193

Browse files
committed
mitm: pkt_debug(): change input from payload to full packet
1 parent 5f65bf1 commit 70da193

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/mitm.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,21 +189,21 @@ impl Packet {
189189
}
190190

191191
/// shows packet/message contents as pretty string for debug
192-
pub async fn pkt_debug(payload: &[u8]) -> Result<()> {
192+
pub async fn pkt_debug(pkt: &Packet) -> Result<()> {
193193
// don't run further if we are not in Debug mode
194194
if !log_enabled!(Level::Debug) {
195195
return Ok(());
196196
}
197197

198198
// message_id is the first 2 bytes of payload
199-
let message_id: i32 = u16::from_be_bytes(payload[0..=1].try_into()?).into();
199+
let message_id: i32 = u16::from_be_bytes(pkt.payload[0..=1].try_into()?).into();
200200

201201
// trying to obtain an Enum from message_id
202202
let control = protos::ControlMessageType::from_i32(message_id);
203203
debug!("message_id = {:04X}, {:?}", message_id, control);
204204

205205
// parsing data
206-
let data = &payload[2..]; // start of message data
206+
let data = &pkt.payload[2..]; // start of message data
207207
let message: &dyn MessageDyn = match control.unwrap_or(MESSAGE_UNEXPECTED_MESSAGE) {
208208
MESSAGE_AUTH_COMPLETE => &AuthResponse::parse_from_bytes(data)?,
209209
MESSAGE_SERVICE_DISCOVERY_REQUEST => &ServiceDiscoveryRequest::parse_from_bytes(data)?,
@@ -466,7 +466,7 @@ pub async fn proxy<A: Endpoint<A> + 'static>(
466466
if proxy_type == ProxyType::HeadUnit {
467467
// waiting for initial version frame (HU is starting transmission)
468468
let pkt = rxr.recv().await.ok_or("reader channel hung up")?;
469-
let _ = pkt_debug(&pkt.payload).await;
469+
let _ = pkt_debug(&pkt).await;
470470
// sending to the MD
471471
tx.send(pkt).await?;
472472
// waiting for MD reply
@@ -496,7 +496,7 @@ pub async fn proxy<A: Endpoint<A> + 'static>(
496496
pkt.transmit(&mut device).await?;
497497
// waiting for MD reply
498498
let pkt = rxr.recv().await.ok_or("reader channel hung up")?;
499-
let _ = pkt_debug(&pkt.payload).await;
499+
let _ = pkt_debug(&pkt).await;
500500
// sending reply back to the HU
501501
tx.send(pkt).await?;
502502

@@ -546,7 +546,7 @@ pub async fn proxy<A: Endpoint<A> + 'static>(
546546
if let Ok(mut pkt) = rxr.try_recv() {
547547
match pkt.decrypt_payload(&mut mem_buf, &mut server).await {
548548
Ok(_) => {
549-
let _ = pkt_debug(&pkt.payload).await;
549+
let _ = pkt_debug(&pkt).await;
550550
tx.send(pkt).await?;
551551
}
552552
Err(e) => error!("decrypt_payload: {:?}", e),

0 commit comments

Comments
 (0)