use crate::FileId;
use binrw::prelude::*;
use modular_bitfield::prelude::*;
use smb_dtyp::Guid;
use smb_msg_derive::*;
#[smb_request_response(size = 12)]
pub struct OplockBreakMsg {
oplock_level: u8,
reserved: u8,
reserved: u32,
file_id: FileId,
}
#[smb_response(size = 44)]
pub struct LeaseBreakNotify {
new_epoch: u16,
ack_required: u32,
lease_key: Guid,
current_lease_state: LeaseState,
new_lease_state: LeaseState,
#[bw(calc = 0)]
#[br(assert(break_reason == 0))]
#[br(temp)]
break_reason: u32,
#[bw(calc = 0)]
#[br(assert(access_mask_hint == 0))]
#[br(temp)]
access_mask_hint: u32,
#[bw(calc = 0)]
#[br(assert(share_mask_hint == 0))]
#[br(temp)]
share_mask_hint: u32,
}
#[smb_message_binrw]
#[brw(repr(u8))]
pub enum OplockLevel {
None = 0,
II = 1,
Exclusive = 2,
}
#[smb_dtyp::mbitfield]
pub struct LeaseState {
pub read_caching: bool,
pub handle_caching: bool,
pub write_caching: bool,
#[skip]
__: B29,
}
pub type OplockBreakNotify = OplockBreakMsg;
pub type OplockBreakAck = OplockBreakMsg;
pub type OplockBreakResponse = OplockBreakMsg;
#[smb_request_response(size = 36)]
pub struct LeaseBreakAckResponse {
reserved: u16,
reserved: u32,
lease_key: Guid,
lease_state: LeaseState,
reserved: u64,
}
pub type LeaseBreakAck = LeaseBreakAckResponse;
pub type LeaseBreakResponse = LeaseBreakAckResponse;
#[cfg(test)]
mod tests {
use crate::*;
use super::*;
test_binrw_response! {
struct LeaseBreakNotify {
new_epoch: 2,
ack_required: 1,
lease_key: "70c8619e-165d-315e-d492-a01b0cbb3af2".parse().unwrap(),
current_lease_state: LeaseState::new()
.with_read_caching(true)
.with_handle_caching(true),
new_lease_state: LeaseState::new(),
} => "2c000200010000009e61c8705d165e31d492a01b0cbb3af20300000000000000000000000000000000000000"
}
test_binrw_response! {
struct LeaseBreakAck {
lease_key: "70c8619e-165d-315e-d492-a01b0cbb3af2".parse().unwrap(),
lease_state: LeaseState::new(),
} => "24000000000000009e61c8705d165e31d492a01b0cbb3af2000000000000000000000000"
}
test_binrw_response! {
struct LeaseBreakAckResponse {
lease_key: "70c8619e-165d-315e-d492-a01b0cbb3af2".parse().unwrap(),
lease_state: LeaseState::new(),
} => "24000000000000009e61c8705d165e31d492a01b0cbb3af2000000000000000000000000"
}
}