diff --git a/crates/core/src/bc_protocol/connection/udpconn/discover.rs b/crates/core/src/bc_protocol/connection/udpconn/discover.rs index 8e259a4..8a57951 100644 --- a/crates/core/src/bc_protocol/connection/udpconn/discover.rs +++ b/crates/core/src/bc_protocol/connection/udpconn/discover.rs @@ -517,4 +517,27 @@ impl UdpDiscover { Err(e) => Err(e), } } + + pub fn send_client_disconnect(&self, socket: &UdpSocket) { + if let Ok(addr) = socket.peer_addr() { + let mut rng = thread_rng(); + let tid: u32 = (rng.gen::()) as u32; + let bcudp_msg = BcUdp::Discovery(UdpDiscovery { + tid, + payload: UdpXml { + c2d_disc: Some(C2dDisc { + cid: self.client_id, + did: self.camera_id, + }), + ..Default::default() + }, + }); + + let mut buf = vec![]; + let buf = bcudp_msg + .serialize(&mut buf) + .expect("Unable to serliaze udp disconnect"); + let _ = Self::retrying_send_to(socket, buf, addr); + } + } } diff --git a/crates/core/src/bc_protocol/connection/udpconn/mod.rs b/crates/core/src/bc_protocol/connection/udpconn/mod.rs index b3f33b6..6de04fd 100644 --- a/crates/core/src/bc_protocol/connection/udpconn/mod.rs +++ b/crates/core/src/bc_protocol/connection/udpconn/mod.rs @@ -131,6 +131,8 @@ impl UdpSource { } } error!("Udp read poll aborted"); + // We send client disconnect here + thread_discovery_result.send_client_disconnect(&thread_socket); }); let thread_aborter = aborter.clone(); diff --git a/crates/core/src/bc_protocol/connection/udpconn/transmit.rs b/crates/core/src/bc_protocol/connection/udpconn/transmit.rs index 2b3d19e..7aa801a 100644 --- a/crates/core/src/bc_protocol/connection/udpconn/transmit.rs +++ b/crates/core/src/bc_protocol/connection/udpconn/transmit.rs @@ -227,7 +227,6 @@ impl UdpTransmit { let bcudp_msg = BcUdp::deserialize(&buf[0..amount_recv])?; match bcudp_msg { BcUdp::Discovery(UdpDiscovery { - tid, payload: UdpXml { d2c_disc: Some(D2cDisc { cid, did }), @@ -238,22 +237,7 @@ impl UdpTransmit { && did == discovery_result.camera_id => { // Reply with C2D_Disc and end - let bcudp_msg = BcUdp::Discovery(UdpDiscovery { - tid, - payload: UdpXml { - c2d_disc: Some(C2dDisc { - cid: discovery_result.client_id, - did: discovery_result.camera_id, - }), - ..Default::default() - }, - }); - - let mut buf = vec![]; - bcudp_msg.serialize(&mut buf)?; - socket - .send(&buf) - .map_err(|e| TransmitError::SocketSend { err: e })?; + discovery_result.send_client_disconnect(socket); return Err(TransmitError::Disc); } BcUdp::Discovery(packet) => { diff --git a/dissector/udp.md b/dissector/udp.md index ce0ca93..519aef1 100644 --- a/dissector/udp.md +++ b/dissector/udp.md @@ -120,7 +120,7 @@ standard tcp bc connection **Udp Camera** -If the camera supports UDP the client will send this xml packet +If the camera supports UDP the client will send the following xml packet as a broadcast on 255.255.255.255 on port 2018/2015 **Known UID**