Bug fixes and making serde respect the status code to send
This commit is contained in:
5 files changed
+7
-25
No files matched your search
+1
-6
@@ -128,7 +128,7 @@ fn bc_modern_msg<'a, 'b>(
|
||||
match encryption_protocol_byte {
|
||||
0x00 => context.set_encrypted(EncryptionProtocol::Unencrypted),
|
||||
0x01 => context.set_encrypted(EncryptionProtocol::BCEncrypt),
|
||||
0x03 => context.set_encrypted(EncryptionProtocol::Aes(None)),
|
||||
0x02 => context.set_encrypted(EncryptionProtocol::Aes(None)),
|
||||
_ => return Err(Err::Error(make_error(buf, ErrorKind::MapRes))),
|
||||
}
|
||||
}
|
||||
@@ -189,11 +189,6 @@ fn bc_header(buf: &[u8]) -> IResult<&[u8], BcHeader> {
|
||||
let (buf, msg_num) = le_u16(buf)?;
|
||||
let (buf, (response_code, class)) = tuple((le_u16, le_u16))(buf)?;
|
||||
|
||||
// All modern messages are encrypted. In addition, it seems that the camera firmware checks
|
||||
// this field to see if some other messages should be encrypted. This is still somewhat fuzzy.
|
||||
// A copy of the source code for the camera would be very useful.
|
||||
let encrypted = response_code != 0;
|
||||
|
||||
let (buf, payload_offset) = cond(has_payload_offset(class), le_u32)(buf)?;
|
||||
|
||||
Ok((
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ pub enum EncryptionProtocol {
|
||||
#[derive(Debug)]
|
||||
pub struct BcContext {
|
||||
pub(super) in_bin_mode: HashSet<u32>,
|
||||
// Arc<AtomicEncryptionProtocol> because it is shared between context
|
||||
// Arc<Mutex<EncryptionProtocol>> because it is shared between context
|
||||
// and connection for deserialisation and serialistion respectivly
|
||||
pub(super) encryption_protocol: Arc<Mutex<EncryptionProtocol>>,
|
||||
}
|
||||
|
||||
+2
-15
@@ -26,11 +26,7 @@ impl Bc {
|
||||
// First serialize ext
|
||||
let (temp_buf, ext_len) = gen(
|
||||
opt_ref(&modern.extension, |ext| {
|
||||
bc_ext(
|
||||
self.meta.channel_id as u32,
|
||||
ext,
|
||||
encryption_protocol,
|
||||
)
|
||||
bc_ext(self.meta.channel_id as u32, ext, encryption_protocol)
|
||||
}),
|
||||
vec![],
|
||||
)?;
|
||||
@@ -106,14 +102,6 @@ fn bc_payload<W: Write>(
|
||||
}
|
||||
|
||||
fn bc_header<W: Write>(header: &BcHeader) -> impl SerializeFn<W> {
|
||||
// TODO this is actually a u16 "response code" in modern messages
|
||||
let (signaled_encryption, spare) = if header.class == 0x0000 {
|
||||
(0x00, 0x00)
|
||||
} else {
|
||||
// Client is always 01dc
|
||||
// Camera may reply with 01dd (encrypted) or 00dd (unencrypted)
|
||||
(0x01, 0xdc)
|
||||
};
|
||||
tuple((
|
||||
le_u32(MAGIC_HEADER),
|
||||
le_u32(header.msg_id),
|
||||
@@ -121,8 +109,7 @@ fn bc_header<W: Write>(header: &BcHeader) -> impl SerializeFn<W> {
|
||||
le_u8(header.channel_id),
|
||||
le_u8(header.stream_type),
|
||||
le_u16(header.msg_num),
|
||||
le_u8(signaled_encryption),
|
||||
le_u8(spare), // skipped byte
|
||||
le_u16(header.response_code),
|
||||
le_u16(header.class),
|
||||
opt(header.payload_offset, le_u32),
|
||||
))
|
||||
|
||||
+1
-1
@@ -159,7 +159,7 @@ impl BcCamera {
|
||||
channel_id: self.channel_id,
|
||||
msg_num: self.new_message_num(),
|
||||
stream_type: 0,
|
||||
response_code: 0x03dc,
|
||||
response_code: 0xdc03,
|
||||
class: 0x6514,
|
||||
},
|
||||
body: BcBody::LegacyMsg(LegacyMsg::LoginMsg {
|
||||
|
||||
@@ -21,7 +21,7 @@ pub struct BcConnection {
|
||||
connection: Arc<Mutex<TcpStream>>,
|
||||
subscribers: Arc<Mutex<BTreeMap<u32, Sender<Bc>>>>,
|
||||
rx_thread: Option<JoinHandle<()>>,
|
||||
// Arc<AtomicEncryptionProtocol> because it is shared between context
|
||||
// Arc<Mutex<EncryptionProtocol>> because it is shared between context
|
||||
// and connection for deserialisation and serialistion respectivly
|
||||
encryption_protocol: Arc<Mutex<EncryptionProtocol>>,
|
||||
}
|
||||
@@ -165,7 +165,7 @@ impl<'a> BcSubscription<'a> {
|
||||
|
||||
bc.serialize(
|
||||
&*self.conn.connection.lock().unwrap(),
|
||||
self.conn.get_encrypted(),
|
||||
&self.conn.get_encrypted(),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user