Use ports 2015 and 2018 for UDP discovery
Also add remote discovery but it is disabled for now
This commit is contained in:
1 parent
643953845a
commit
7a5def551d
8 files changed
+565
-42
No files matched your search
@@ -10,6 +10,7 @@ aes = "0.6"
|
||||
cfb-mode = "0.6"
|
||||
cookie-factory = "0.3"
|
||||
err-derive = "0.2"
|
||||
lazy_static = "1.4"
|
||||
log = { version = "0.4" }
|
||||
md5 = "0.7"
|
||||
nom = "6.1.2"
|
||||
|
||||
@@ -63,7 +63,7 @@ pub enum Error {
|
||||
#[error(display = "This connection type in unsupported")]
|
||||
UnsupportedConnection,
|
||||
|
||||
#[error(display = "Camera Unconnected")]
|
||||
#[error(display = "Camera Not Findable")]
|
||||
ConnectionUnavaliable,
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ use crate::bc::model::*;
|
||||
use crate::bcudp;
|
||||
use crate::bcudp::{model::*, xml::*};
|
||||
use crate::RX_TIMEOUT;
|
||||
use lazy_static::lazy_static;
|
||||
use log::*;
|
||||
use rand::{seq::SliceRandom, thread_rng, Rng};
|
||||
use socket2::{Domain, Socket, Type};
|
||||
@@ -12,7 +13,7 @@ use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
use std::error::Error as StdErr; // Just need the traits
|
||||
use std::io::{BufRead, Error as IoError, Read, Write};
|
||||
use std::net::{SocketAddr, ToSocketAddrs, UdpSocket};
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr, ToSocketAddrs, UdpSocket};
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, AtomicU32, Ordering},
|
||||
mpsc::{channel, Receiver, Sender},
|
||||
@@ -26,11 +27,29 @@ type IoResult<T> = std::result::Result<T, IoError>;
|
||||
|
||||
const WAIT_TIME: Duration = Duration::from_millis(500);
|
||||
|
||||
// TODO: Path MTU discovery
|
||||
const MTU: u32 = 1350;
|
||||
|
||||
lazy_static! {
|
||||
static ref P2P_RELAY_HOSTNAMES: [&'static str; 10] = [
|
||||
"p2p.reolink.com",
|
||||
"p2p1.reolink.com",
|
||||
"p2p2.reolink.com",
|
||||
"p2p3.reolink.com",
|
||||
"p2p14.reolink.com",
|
||||
"p2p15.reolink.com",
|
||||
"p2p6.reolink.com",
|
||||
"p2p7.reolink.com",
|
||||
"p2p8.reolink.com",
|
||||
"p2p9.reolink.com",
|
||||
];
|
||||
}
|
||||
|
||||
pub struct UdpSource {
|
||||
socket: UdpSocket,
|
||||
address: SocketAddr,
|
||||
client_id: u32,
|
||||
camera_id: u32,
|
||||
client_id: i32,
|
||||
camera_id: i32,
|
||||
mtu: u32,
|
||||
outgoing: Arc<Mutex<HashMap<u32, QueuedMessage>>>,
|
||||
incoming: Arc<Mutex<HashMap<u32, QueuedMessage>>>,
|
||||
@@ -57,8 +76,8 @@ struct QueuedMessage {
|
||||
struct DiscoveryResult {
|
||||
socket: UdpSocket,
|
||||
address: SocketAddr,
|
||||
client_id: u32,
|
||||
camera_id: u32,
|
||||
client_id: i32,
|
||||
camera_id: i32,
|
||||
mtu: u32,
|
||||
}
|
||||
|
||||
@@ -106,19 +125,50 @@ impl UdpSource {
|
||||
buf: &[u8],
|
||||
addr: T,
|
||||
) -> IoResult<(usize, AbortHandle)> {
|
||||
let addr: SocketAddr = addr.to_socket_addrs()?.next().unwrap();
|
||||
let addr = addr.to_socket_addrs()?.next().ok_or_else(|| {
|
||||
IoError::new(std::io::ErrorKind::NotFound, Error::ConnectionUnavaliable)
|
||||
})?;
|
||||
Self::retrying_send_to_multi(socket, buf, &[addr])
|
||||
}
|
||||
|
||||
fn retrying_send_to_multi<T: ToSocketAddrs>(
|
||||
socket: &UdpSocket,
|
||||
buf: &[u8],
|
||||
addrs: &[T],
|
||||
) -> IoResult<(usize, AbortHandle)> {
|
||||
let handle = AbortHandle::new();
|
||||
let bytes_send = socket.send_to(&buf, &addr)?;
|
||||
|
||||
let addrs: Vec<SocketAddr> = addrs
|
||||
.iter()
|
||||
.map(|a| {
|
||||
a.to_socket_addrs()
|
||||
.ok()
|
||||
.and_then(|mut a_iter| a_iter.next())
|
||||
})
|
||||
.flatten()
|
||||
.collect();
|
||||
|
||||
let mut bytes_send = 0;
|
||||
for addr in addrs.iter() {
|
||||
bytes_send = socket.send_to(buf, &addr)?;
|
||||
}
|
||||
|
||||
let thread_buffer = buf.to_vec();
|
||||
let thread_handle = handle.clone();
|
||||
let thread_socket = socket.try_clone()?;
|
||||
let thread_addr = addr;
|
||||
let thread_addr: Vec<SocketAddr> = addrs;
|
||||
|
||||
const MAX_RETRIES: usize = 10;
|
||||
|
||||
std::thread::spawn(move || {
|
||||
std::thread::sleep(WAIT_TIME);
|
||||
while !thread_handle.is_aborted() {
|
||||
let _ = thread_socket.send_to(&thread_buffer[..], &thread_addr);
|
||||
for _ in 0..MAX_RETRIES {
|
||||
if thread_handle.is_aborted() {
|
||||
break;
|
||||
}
|
||||
for addr in thread_addr.iter() {
|
||||
let _ = thread_socket.send_to(&thread_buffer[..], &addr);
|
||||
}
|
||||
std::thread::sleep(WAIT_TIME);
|
||||
}
|
||||
});
|
||||
@@ -126,20 +176,19 @@ impl UdpSource {
|
||||
Ok((bytes_send, handle))
|
||||
}
|
||||
|
||||
fn discover_from_uuid(uid: &str, timeout: Duration) -> Result<DiscoveryResult> {
|
||||
let start_time = OffsetDateTime::now_utc();
|
||||
|
||||
let socket = Self::get_socket(timeout)?;
|
||||
|
||||
fn discover_from_uuid_local(
|
||||
uid: &str,
|
||||
socket: &UdpSocket,
|
||||
timeout: Duration,
|
||||
) -> Result<DiscoveryResult> {
|
||||
let mut rng = thread_rng();
|
||||
// If tid is too large it will overflow during encrypt so we just use a random u8
|
||||
let tid: u32 = (rng.gen::<u8>()) as u32;
|
||||
let client_id: u32 = rng.gen();
|
||||
let client_id: i32 = rng.gen();
|
||||
let local_addr = socket.local_addr()?;
|
||||
let port = local_addr.port();
|
||||
|
||||
// TODO: Path MTU discovery
|
||||
let mtu = 1350;
|
||||
let mtu = MTU;
|
||||
|
||||
let msg = BcUdp::Discovery(UdpDiscovery {
|
||||
tid,
|
||||
@@ -159,10 +208,14 @@ impl UdpSource {
|
||||
let mut buf = vec![];
|
||||
msg.serialize(&mut buf)?;
|
||||
|
||||
let (amount_sent, abort) =
|
||||
Self::retrying_send_to(&socket, &buf[..], "255.255.255.255:2018")?;
|
||||
let (amount_sent, abort) = Self::retrying_send_to_multi(
|
||||
socket,
|
||||
&buf[..],
|
||||
&["255.255.255.255:2015", "255.255.255.255:2018"],
|
||||
)?;
|
||||
assert_eq!(amount_sent, buf.len());
|
||||
|
||||
let start_time = OffsetDateTime::now_utc();
|
||||
let camera_address;
|
||||
let camera_id;
|
||||
loop {
|
||||
@@ -202,7 +255,7 @@ impl UdpSource {
|
||||
socket.connect(camera_address)?;
|
||||
|
||||
Ok(DiscoveryResult {
|
||||
socket,
|
||||
socket: socket.try_clone()?,
|
||||
address: camera_address,
|
||||
client_id,
|
||||
camera_id,
|
||||
@@ -210,8 +263,345 @@ impl UdpSource {
|
||||
})
|
||||
}
|
||||
|
||||
fn get_register(
|
||||
uid: &str,
|
||||
socket: &UdpSocket,
|
||||
timeout: Duration,
|
||||
tid: u32,
|
||||
// client_id: u32,
|
||||
) -> Result<M2cQr> {
|
||||
// let local_addr = socket.local_addr()?;
|
||||
// let local_port = local_addr.port();
|
||||
|
||||
let mtu = MTU;
|
||||
|
||||
for p2p_relay in P2P_RELAY_HOSTNAMES.iter() {
|
||||
let msg = BcUdp::Discovery(UdpDiscovery {
|
||||
tid,
|
||||
payload: UdpXml {
|
||||
c2m_q: Some(C2mQ {
|
||||
uid: uid.to_string(),
|
||||
os: "MAC".to_string(),
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
|
||||
let mut buf = vec![];
|
||||
msg.serialize(&mut buf)?;
|
||||
|
||||
let (amount_sent, abort) =
|
||||
Self::retrying_send_to(socket, &buf[..], format!("{}:9999", p2p_relay))?;
|
||||
assert_eq!(amount_sent, buf.len());
|
||||
|
||||
let start_time = OffsetDateTime::now_utc();
|
||||
loop {
|
||||
if (OffsetDateTime::now_utc() - start_time) <= timeout {
|
||||
let mut buf = vec![0; mtu as usize];
|
||||
if let Ok((bytes_read, _)) = socket.recv_from(&mut buf) {
|
||||
match BcUdp::deserialize(&buf[0..bytes_read]) {
|
||||
Ok(BcUdp::Discovery(UdpDiscovery {
|
||||
tid: _,
|
||||
payload:
|
||||
UdpXml {
|
||||
m2c_q_r: Some(m2c_q_r),
|
||||
..
|
||||
},
|
||||
})) => {
|
||||
abort.abort();
|
||||
return Ok(m2c_q_r);
|
||||
}
|
||||
Ok(smt) => debug!("Udp Discovery got this unexpected BcUdp {:?}", smt),
|
||||
Err(_) => debug!(
|
||||
"Udp Discovery got this unexpected binary: {:?}",
|
||||
&buf[0..bytes_read]
|
||||
),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
abort.abort();
|
||||
// This p2p server didn't have the data we need try another
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(Error::ConnectionUnavaliable)
|
||||
}
|
||||
|
||||
fn discover_from_uuid_remote(
|
||||
uid: &str,
|
||||
socket: &UdpSocket,
|
||||
timeout: Duration,
|
||||
) -> Result<DiscoveryResult> {
|
||||
let local_addr = socket.local_addr()?;
|
||||
let local_port = local_addr.port();
|
||||
|
||||
let mut rng = thread_rng();
|
||||
// If tid is too large it will overflow during encrypt so we just use a random u8
|
||||
let tid: u32 = (rng.gen::<u8>()) as u32;
|
||||
let mtu = MTU;
|
||||
let client_id: i32 = rng.gen();
|
||||
|
||||
let m2c_q_r = Self::get_register(uid, socket, timeout, tid)?;
|
||||
|
||||
let register_address = m2c_q_r.reg;
|
||||
let relay_address = m2c_q_r.relay;
|
||||
let log_address = m2c_q_r.log;
|
||||
let device_address = m2c_q_r.t;
|
||||
|
||||
debug!("Register address found: {:?}", register_address);
|
||||
debug!("Registering this address: {:?}", local_addr);
|
||||
|
||||
let local_family = if local_addr.ip().is_ipv4() { 4 } else { 6 };
|
||||
let msg = BcUdp::Discovery(UdpDiscovery {
|
||||
tid,
|
||||
payload: UdpXml {
|
||||
c2r_c: Some(C2rC {
|
||||
uid: uid.to_string(),
|
||||
cli: IpPort {
|
||||
ip: local_addr.ip().to_string(),
|
||||
port: local_port,
|
||||
},
|
||||
relay: relay_address,
|
||||
cid: client_id,
|
||||
family: local_family,
|
||||
debug: false,
|
||||
os: "MAC".to_string(),
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
|
||||
let mut buf = vec![];
|
||||
msg.serialize(&mut buf)?;
|
||||
|
||||
let (amount_sent, abort) = Self::retrying_send_to(
|
||||
socket,
|
||||
&buf[..],
|
||||
format!("{}:{}", register_address.ip, register_address.port),
|
||||
)?;
|
||||
assert_eq!(amount_sent, buf.len());
|
||||
|
||||
let device_sid;
|
||||
let dev_loc;
|
||||
let start_time = OffsetDateTime::now_utc();
|
||||
loop {
|
||||
if (OffsetDateTime::now_utc() - start_time) <= timeout {
|
||||
let mut buf = vec![0; mtu as usize];
|
||||
if let Ok((bytes_read, _)) = socket.recv_from(&mut buf) {
|
||||
match BcUdp::deserialize(&buf[0..bytes_read]) {
|
||||
// Got camera data from register
|
||||
Ok(BcUdp::Discovery(UdpDiscovery {
|
||||
tid: _,
|
||||
payload:
|
||||
UdpXml {
|
||||
r2c_t: Some(R2cT { dev, cid, sid, .. }),
|
||||
..
|
||||
},
|
||||
})) if cid == client_id => {
|
||||
abort.abort();
|
||||
// Make a local request to the camera with the dev info
|
||||
device_sid = sid;
|
||||
dev_loc = dev;
|
||||
break;
|
||||
}
|
||||
Ok(smt) => debug!("Udp Discovery got this unexpected BcUdp {:?}", smt),
|
||||
Err(_) => debug!(
|
||||
"Udp Discovery got this unexpected binary: {:?}",
|
||||
&buf[0..bytes_read]
|
||||
),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
abort.abort();
|
||||
return Err(Error::Timeout);
|
||||
}
|
||||
}
|
||||
|
||||
debug!("Register revealed address as SID: {:?}", device_sid);
|
||||
debug!("Register revealed address as IP: {:?}", dev_loc);
|
||||
|
||||
// ensure abort
|
||||
abort.abort();
|
||||
|
||||
let msg = BcUdp::Discovery(UdpDiscovery {
|
||||
tid,
|
||||
payload: UdpXml {
|
||||
c2d_t: Some(C2dT {
|
||||
sid: device_sid,
|
||||
cid: client_id,
|
||||
mtu,
|
||||
conn: "local".to_string(),
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
|
||||
let mut buf = vec![];
|
||||
msg.serialize(&mut buf)?;
|
||||
|
||||
let (amount_sent, abort) =
|
||||
Self::retrying_send_to(socket, &buf[..], format!("{}:{}", dev_loc.ip, dev_loc.port))?;
|
||||
assert_eq!(amount_sent, buf.len());
|
||||
|
||||
let device_id;
|
||||
let start_time = OffsetDateTime::now_utc();
|
||||
loop {
|
||||
if (OffsetDateTime::now_utc() - start_time) <= timeout {
|
||||
let mut buf = vec![0; mtu as usize];
|
||||
if let Ok((bytes_read, _)) = socket.recv_from(&mut buf) {
|
||||
match BcUdp::deserialize(&buf[0..bytes_read]) {
|
||||
// Got camera data from camera
|
||||
Ok(BcUdp::Discovery(UdpDiscovery {
|
||||
tid: _,
|
||||
payload:
|
||||
UdpXml {
|
||||
d2c_t: Some(D2cT { cid, did, .. }),
|
||||
..
|
||||
},
|
||||
})) if cid == client_id => {
|
||||
device_id = did;
|
||||
break;
|
||||
}
|
||||
// Got camera data from camera CFM
|
||||
Ok(BcUdp::Discovery(UdpDiscovery {
|
||||
tid: _,
|
||||
payload:
|
||||
UdpXml {
|
||||
d2c_cfm: Some(D2cCfm { cid, did, .. }),
|
||||
..
|
||||
},
|
||||
})) if cid == client_id => {
|
||||
device_id = did;
|
||||
break;
|
||||
}
|
||||
// Got camera data from camera disc
|
||||
Ok(BcUdp::Discovery(UdpDiscovery {
|
||||
tid: _,
|
||||
payload:
|
||||
UdpXml {
|
||||
d2c_disc: Some(D2cDisc { cid, did, .. }),
|
||||
..
|
||||
},
|
||||
})) if cid == client_id => {
|
||||
device_id = did;
|
||||
break;
|
||||
}
|
||||
Ok(smt) => debug!("Udp Discovery got this unexpected BcUdp {:?}", smt),
|
||||
Err(_) => debug!(
|
||||
"Udp Discovery got this unexpected binary: {:?}",
|
||||
&buf[0..bytes_read]
|
||||
),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
abort.abort();
|
||||
return Err(Error::Timeout);
|
||||
}
|
||||
}
|
||||
|
||||
debug!("Got device ID as: {:?}", device_id);
|
||||
|
||||
// Ensure aborted
|
||||
abort.abort();
|
||||
|
||||
// Announce to the log that we will connect locally
|
||||
let msg = BcUdp::Discovery(UdpDiscovery {
|
||||
tid,
|
||||
payload: UdpXml {
|
||||
c2r_cfm: Some(C2rCfm {
|
||||
sid: device_sid,
|
||||
cid: client_id,
|
||||
did: device_id,
|
||||
conn: "local".to_string(),
|
||||
rsp: 0,
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
|
||||
let mut buf = vec![];
|
||||
msg.serialize(&mut buf)?;
|
||||
|
||||
// Just let this retry to max limit as we don't get a reply
|
||||
let (amount_sent, _) = Self::retrying_send_to(
|
||||
socket,
|
||||
&buf[..],
|
||||
format!("{}:{}", log_address.ip, log_address.port),
|
||||
)?;
|
||||
assert_eq!(amount_sent, buf.len());
|
||||
|
||||
// Announce a map type connection (I think this means we could connect remotely)
|
||||
let msg = BcUdp::Discovery(UdpDiscovery {
|
||||
tid,
|
||||
payload: UdpXml {
|
||||
c2d_t: Some(C2dT {
|
||||
sid: device_sid,
|
||||
cid: client_id,
|
||||
mtu,
|
||||
conn: "map".to_string(),
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
|
||||
let mut buf = vec![];
|
||||
msg.serialize(&mut buf)?;
|
||||
|
||||
// Just let this retry to max limit as we don't get a reply
|
||||
let (amount_sent, _) = Self::retrying_send_to(
|
||||
socket,
|
||||
&buf[..],
|
||||
format!("{}:{}", device_address.ip, device_address.port),
|
||||
)?;
|
||||
assert_eq!(amount_sent, buf.len());
|
||||
|
||||
let camera_address: SocketAddr = format!("{}:{}", device_address.ip, device_address.port)
|
||||
.to_socket_addrs()?
|
||||
.next()
|
||||
.ok_or(Error::ConnectionUnavaliable)?;
|
||||
|
||||
Ok(DiscoveryResult {
|
||||
socket: socket.try_clone()?,
|
||||
address: camera_address,
|
||||
client_id,
|
||||
camera_id: device_id,
|
||||
mtu,
|
||||
})
|
||||
}
|
||||
|
||||
fn discover_from_uuid(
|
||||
uid: &str,
|
||||
timeout: Duration,
|
||||
allow_remote: bool,
|
||||
) -> Result<DiscoveryResult> {
|
||||
let socket = Self::get_socket(timeout)?;
|
||||
match Self::discover_from_uuid_local(uid, &socket, timeout) {
|
||||
Err(Error::Timeout) if allow_remote => {
|
||||
Self::discover_from_uuid_remote(uid, &socket, timeout)
|
||||
}
|
||||
Ok(result) => Ok(result),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
/// It is possible to contact the reolink servers using udp to
|
||||
/// learn the ip and port of the camera. By default I have turned
|
||||
/// this feature off with no way to enable it from the usual
|
||||
/// command line interface or config.
|
||||
///
|
||||
/// However it may prove neccesary one day to use it so it is here in the
|
||||
/// library and other programs may want to use it.
|
||||
pub fn new_allow_remote(uid: &str, timeout: Duration) -> Result<Self> {
|
||||
Self::new_with_remote(uid, timeout, true)
|
||||
}
|
||||
|
||||
pub fn new(uid: &str, timeout: Duration) -> Result<Self> {
|
||||
let discovery_result = Self::discover_from_uuid(uid, timeout)?;
|
||||
Self::new_with_remote(uid, timeout, false)
|
||||
}
|
||||
|
||||
fn new_with_remote(uid: &str, timeout: Duration, allow_remote: bool) -> Result<Self> {
|
||||
let discovery_result = Self::discover_from_uuid(uid, timeout, allow_remote)?;
|
||||
info!("UID {:?} found at {:?}", uid, discovery_result.address);
|
||||
|
||||
let me = UdpSource {
|
||||
@@ -260,7 +650,7 @@ impl UdpSource {
|
||||
|
||||
fn handle_ack(
|
||||
next_to_consume: u32,
|
||||
camera_id: u32,
|
||||
camera_id: i32,
|
||||
incoming: &mut HashMap<u32, QueuedMessage>,
|
||||
socket: &UdpSocket,
|
||||
) {
|
||||
|
||||
@@ -132,7 +132,7 @@ fn udp_disc(buf: &[u8]) -> IResult<&[u8], UdpDiscovery> {
|
||||
}
|
||||
|
||||
fn udp_ack(buf: &[u8]) -> IResult<&[u8], UdpAck> {
|
||||
let (buf, connection_id) = le_u32(buf)?;
|
||||
let (buf, connection_id) = le_i32(buf)?;
|
||||
let (buf, _unknown_a) = verify(le_u32, |&x| x == 0)(buf)?;
|
||||
let (buf, _unknown_b) = verify(le_u32, |&x| x == 0)(buf)?;
|
||||
let (buf, packet_id) = le_u32(buf)?;
|
||||
@@ -147,7 +147,7 @@ fn udp_ack(buf: &[u8]) -> IResult<&[u8], UdpAck> {
|
||||
}
|
||||
|
||||
fn udp_data(buf: &[u8]) -> IResult<&[u8], UdpData> {
|
||||
let (buf, connection_id) = le_u32(buf)?;
|
||||
let (buf, connection_id) = le_i32(buf)?;
|
||||
let (buf, _unknown_a) = verify(le_u32, |&x| x == 0)(buf)?;
|
||||
let (buf, packet_id) = le_u32(buf)?;
|
||||
let (buf, payload_size) = le_u32(buf)?;
|
||||
|
||||
@@ -45,7 +45,11 @@ pub struct UdpAck {
|
||||
/// When receiving from the camera it will be cid
|
||||
///
|
||||
/// When sending to the camera it should be did
|
||||
pub connection_id: u32,
|
||||
///
|
||||
/// We use i32 because when we send the connection id to the reolink
|
||||
/// register and then download the same connection id from the register_address
|
||||
/// it comes back in an xml that is encoded as i32 (i.e. can be negative string)
|
||||
pub connection_id: i32,
|
||||
// Unknown 4 bytes always 0
|
||||
/// The ID of the last data packet [`UdpData`]
|
||||
pub packet_id: u32,
|
||||
@@ -66,7 +70,11 @@ pub struct UdpData {
|
||||
/// When receiving from the camera it will be cid
|
||||
///
|
||||
/// When sending to the camera it should be did
|
||||
pub connection_id: u32,
|
||||
///
|
||||
/// We use i32 because when we send the connection id to the reolink
|
||||
/// register and then download the same connection id from the register_address
|
||||
/// it comes back in an xml that is encoded as i32 (i.e. can be negative string)
|
||||
pub connection_id: i32,
|
||||
// Unknown 4 bytes always 0
|
||||
/// The ID of the data packet
|
||||
pub packet_id: u32,
|
||||
|
||||
@@ -51,7 +51,7 @@ fn bcudp_disc<'a, W: 'a + Write>(
|
||||
fn bcudp_ack<'a, W: 'a + Write>(payload: &'a UdpAck) -> impl SerializeFn<W> + 'a {
|
||||
tuple((
|
||||
le_u32(MAGIC_HEADER_UDP_ACK),
|
||||
le_u32(payload.connection_id),
|
||||
le_i32(payload.connection_id),
|
||||
le_u32(0),
|
||||
le_u32(0),
|
||||
le_u32(payload.packet_id),
|
||||
@@ -66,7 +66,7 @@ fn bcudp_data<'a, W: 'a + Write>(
|
||||
) -> impl SerializeFn<W> + 'a {
|
||||
tuple((
|
||||
le_u32(MAGIC_HEADER_UDP_DATA),
|
||||
le_u32(payload.connection_id),
|
||||
le_i32(payload.connection_id),
|
||||
le_u32(0),
|
||||
le_u32(payload.packet_id),
|
||||
le_u32(binary_payload.len() as u32),
|
||||
|
||||
+135
-11
@@ -30,6 +30,24 @@ pub struct UdpXml {
|
||||
/// C2D_DISC xml Disconnect
|
||||
#[yaserde(rename = "C2D_DISC")]
|
||||
pub c2d_disc: Option<C2dDisc>,
|
||||
/// D2C_DISC xml Disconnect
|
||||
#[yaserde(rename = "D2C_DISC")]
|
||||
pub d2c_disc: Option<D2cDisc>,
|
||||
/// C2M_Q xml client to middle man query
|
||||
#[yaserde(rename = "C2M_Q")]
|
||||
pub c2m_q: Option<C2mQ>,
|
||||
/// M2C_Q_R xml middle man to client query reply
|
||||
#[yaserde(rename = "M2C_Q_R")]
|
||||
pub m2c_q_r: Option<M2cQr>,
|
||||
/// C2R_C xml client to register connect
|
||||
#[yaserde(rename = "C2R_C")]
|
||||
pub c2r_c: Option<C2rC>,
|
||||
/// R2C_T xml register to clinet with device ID etc
|
||||
#[yaserde(rename = "R2C_T")]
|
||||
pub r2c_t: Option<R2cT>,
|
||||
/// C2R_CFM xml client to register CFM
|
||||
#[yaserde(rename = "C2R_CFM")]
|
||||
pub c2r_cfm: Option<C2rCfm>,
|
||||
}
|
||||
|
||||
impl UdpXml {
|
||||
@@ -71,12 +89,12 @@ pub struct C2dC {
|
||||
/// Cli contains the udp port to communicate on
|
||||
pub cli: ClientList,
|
||||
/// The cid is the client ID
|
||||
pub cid: u32,
|
||||
pub cid: i32,
|
||||
/// Maximum transmission size,
|
||||
pub mtu: u32,
|
||||
/// Debug mode. Purpose unknown
|
||||
pub debug: bool,
|
||||
/// Os of the machine known values are `"MAC"`
|
||||
/// Os of the machine known values are `"MAC"`, `"WIN"`
|
||||
#[yaserde(rename = "p")]
|
||||
pub os: String,
|
||||
}
|
||||
@@ -99,9 +117,9 @@ pub struct D2cCr {
|
||||
/// Unknown
|
||||
pub rsp: u32,
|
||||
/// Client ID
|
||||
pub cid: u32,
|
||||
pub cid: i32,
|
||||
/// Camera ID
|
||||
pub did: u32,
|
||||
pub did: i32,
|
||||
}
|
||||
|
||||
/// Timer provided by D2C_C_R
|
||||
@@ -119,9 +137,18 @@ pub struct Timer {
|
||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||
pub struct C2dDisc {
|
||||
/// The client connection ID
|
||||
pub cid: u32,
|
||||
pub cid: i32,
|
||||
/// The camera connection ID
|
||||
pub did: u32,
|
||||
pub did: i32,
|
||||
}
|
||||
|
||||
/// D2C_DISC xml
|
||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||
pub struct D2cDisc {
|
||||
/// The client connection ID
|
||||
pub cid: i32,
|
||||
/// The camera connection ID
|
||||
pub did: i32,
|
||||
}
|
||||
|
||||
/// D2C_T xml
|
||||
@@ -132,9 +159,9 @@ pub struct D2cT {
|
||||
/// Type of connection observed values are `"local"`
|
||||
pub conn: String,
|
||||
/// The client connection ID
|
||||
pub cid: u32,
|
||||
pub cid: i32,
|
||||
/// The camera connection ID
|
||||
pub did: u32,
|
||||
pub did: i32,
|
||||
}
|
||||
|
||||
/// C2D_T xml
|
||||
@@ -145,12 +172,92 @@ pub struct C2dT {
|
||||
/// Type of connection observed values are `"local"`
|
||||
pub conn: String,
|
||||
/// The client connection ID
|
||||
pub cid: u32,
|
||||
pub cid: i32,
|
||||
/// Maximum size in bytes of a transmission
|
||||
pub mtu: u32,
|
||||
}
|
||||
|
||||
/// C2M_Q xml
|
||||
///
|
||||
/// This is from client to a reolink middle man server
|
||||
///
|
||||
/// It should be sent to a reolink p2p sever on port 9999
|
||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||
pub struct C2mQ {
|
||||
/// UID to look up
|
||||
pub uid: String,
|
||||
/// Os of the machine known values are `"MAC"`, `"WIN"`
|
||||
#[yaserde(rename = "p")]
|
||||
pub os: String,
|
||||
}
|
||||
|
||||
/// M2C_Q_R xml
|
||||
///
|
||||
/// This is from middle man reolink server to client
|
||||
///
|
||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||
pub struct M2cQr {
|
||||
/// The register server location
|
||||
pub reg: IpPort,
|
||||
/// The relay server location
|
||||
pub relay: IpPort,
|
||||
/// The log server location
|
||||
pub log: IpPort,
|
||||
/// The camera location
|
||||
pub t: IpPort,
|
||||
}
|
||||
|
||||
/// Used as part of M2C_Q_R to provide the host and port
|
||||
///
|
||||
/// of the register, relay and log servers
|
||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||
pub struct IpPort {
|
||||
/// Ip of the service
|
||||
pub ip: String,
|
||||
/// Port of the service
|
||||
pub port: u16,
|
||||
}
|
||||
|
||||
/// C2R_C xml
|
||||
///
|
||||
/// This is from client to the register reolink server
|
||||
///
|
||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||
pub struct C2rC {
|
||||
/// The UID to register connecition request with
|
||||
pub uid: String,
|
||||
/// The location of the client
|
||||
pub cli: IpPort,
|
||||
/// The location of the relay server
|
||||
pub relay: IpPort,
|
||||
/// The client id
|
||||
pub cid: i32,
|
||||
/// Debug setting. Unknown purpose observed values are `0`
|
||||
pub debug: bool,
|
||||
/// Inet family. Observed values `4`
|
||||
pub family: u8,
|
||||
/// Os of the machine known values are `"MAC"`, `"WIN"`
|
||||
#[yaserde(rename = "p")]
|
||||
pub os: String,
|
||||
}
|
||||
|
||||
/// R2C_T xml
|
||||
///
|
||||
/// This is from register reolink server to clinet with device ip and did etc
|
||||
///
|
||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||
pub struct R2cT {
|
||||
/// The location of the camera
|
||||
pub dev: IpPort,
|
||||
/// The client id
|
||||
pub cid: i32,
|
||||
/// The camera SID
|
||||
pub sid: u32,
|
||||
}
|
||||
|
||||
/// D2C_CFM xml
|
||||
///
|
||||
/// Device to client, with connection started from middle man server
|
||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||
pub struct D2cCfm {
|
||||
/// The camera SID
|
||||
@@ -160,9 +267,26 @@ pub struct D2cCfm {
|
||||
/// Unknown known values are `0`
|
||||
pub rsp: u32,
|
||||
/// The client connection ID
|
||||
pub cid: u32,
|
||||
pub cid: i32,
|
||||
/// The camera connection ID
|
||||
pub did: u32,
|
||||
pub did: i32,
|
||||
/// The time but only value that has been observed is `0
|
||||
pub time_r: u32,
|
||||
}
|
||||
|
||||
/// C2R_CFM xml
|
||||
///
|
||||
/// Client to register
|
||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||
pub struct C2rCfm {
|
||||
/// The camera SID
|
||||
pub sid: u32,
|
||||
/// Type of connection observed values are `"local"`
|
||||
pub conn: String,
|
||||
/// Unknown known values are `0`
|
||||
pub rsp: u32,
|
||||
/// The client connection ID
|
||||
pub cid: i32,
|
||||
/// The camera connection ID
|
||||
pub did: i32,
|
||||
}
|
||||
+1
-1
@@ -106,7 +106,7 @@ fn set_data_channel(appsink: &AppSink, tx: SyncSender<Vec<u8>>) {
|
||||
|
||||
// We know what format the data in the memory region has, since we requested
|
||||
// it by setting the appsink's caps. So what we do here is interpret the
|
||||
// memory region we mapped as an array of signed 16 bit integers.
|
||||
// memory region we mapped as an array of signed 8 bit integers.
|
||||
let samples = map.as_slice_of::<u8>().map_err(|_| {
|
||||
element_error!(
|
||||
appsink,
|
||||
|
||||
Reference in new issue
Block a user