diff --git a/src/bc/de.rs b/src/bc/de.rs index b0bcd99..47d6219 100644 --- a/src/bc/de.rs +++ b/src/bc/de.rs @@ -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(( diff --git a/src/bc/model.rs b/src/bc/model.rs index de842aa..f4e2ff0 100644 --- a/src/bc/model.rs +++ b/src/bc/model.rs @@ -81,7 +81,7 @@ pub enum EncryptionProtocol { #[derive(Debug)] pub struct BcContext { pub(super) in_bin_mode: HashSet, - // Arc because it is shared between context + // Arc> because it is shared between context // and connection for deserialisation and serialistion respectivly pub(super) encryption_protocol: Arc>, } diff --git a/src/bc/ser.rs b/src/bc/ser.rs index 230db00..e448d5d 100644 --- a/src/bc/ser.rs +++ b/src/bc/ser.rs @@ -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( } fn bc_header(header: &BcHeader) -> impl SerializeFn { - // 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(header: &BcHeader) -> impl SerializeFn { 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), )) diff --git a/src/bc_protocol.rs b/src/bc_protocol.rs index 63d4ae4..5ef8162 100644 --- a/src/bc_protocol.rs +++ b/src/bc_protocol.rs @@ -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 { diff --git a/src/bc_protocol/connection.rs b/src/bc_protocol/connection.rs index 3949c8f..cc783c9 100644 --- a/src/bc_protocol/connection.rs +++ b/src/bc_protocol/connection.rs @@ -21,7 +21,7 @@ pub struct BcConnection { connection: Arc>, subscribers: Arc>>>, rx_thread: Option>, - // Arc because it is shared between context + // Arc> because it is shared between context // and connection for deserialisation and serialistion respectivly encryption_protocol: Arc>, } @@ -165,7 +165,7 @@ impl<'a> BcSubscription<'a> { bc.serialize( &*self.conn.connection.lock().unwrap(), - self.conn.get_encrypted(), + &self.conn.get_encrypted(), )?; Ok(()) }