pub struct ClientSession<L: DataLinkLayer> { /* private fields */ }Expand description
A blocking client session over a framing sub-layer L.
Implementations§
Source§impl<L: DataLinkLayer> ClientSession<L>
impl<L: DataLinkLayer> ClientSession<L>
Sourcepub fn with_ciphering(
link: L,
tx_context: SecurityContext,
rx_context: SecurityContext,
) -> Self
pub fn with_ciphering( link: L, tx_context: SecurityContext, rx_context: SecurityContext, ) -> Self
Creates a session that protects request APDUs with global ciphering.
tx_context protects outbound requests (client system-title / counter);
rx_context removes protection from inbound responses (server
system-title). Both are typically derived from the AARQ/AARE exchange.
Sourcepub fn enable_gbt(&mut self, block_size: usize)
pub fn enable_gbt(&mut self, block_size: usize)
Enables general block transfer (IEC 62056-5-3 §9.3) for requests and
responses whose service qualifies (see gbt::applies_to_apdu) and
exceed block_size octets. Unconfirmed by default; see
Self::set_gbt_window for confirmed mode.
Sourcepub fn disable_gbt(&mut self)
pub fn disable_gbt(&mut self)
Disables general block transfer, restoring single-frame sends.
Sourcepub fn set_gbt_window(&mut self, window: u8)
pub fn set_gbt_window(&mut self, window: u8)
Sets the confirmed-mode window size for GBT (0 = unconfirmed). Has no effect unless GBT is enabled.
Sourcepub fn set_gbt_streaming(&mut self, enabled: bool)
pub fn set_gbt_streaming(&mut self, enabled: bool)
Enables or disables the streaming variant of GBT. Has no effect unless GBT is enabled.
Sourcepub fn builder(link: L) -> ClientSessionBuilder<L>
pub fn builder(link: L) -> ClientSessionBuilder<L>
Returns a builder for configuring this session’s timeouts and retries.
Sourcepub fn into_inner(self) -> L
pub fn into_inner(self) -> L
Returns the underlying framing layer.
Sourcepub fn config(&self) -> &SessionConfig
pub fn config(&self) -> &SessionConfig
Returns a reference to the current session configuration.
Sourcepub fn set_config(&mut self, config: SessionConfig)
pub fn set_config(&mut self, config: SessionConfig)
Updates the session configuration.
Sourcepub fn set_request_timeout(&mut self, timeout: Duration)
pub fn set_request_timeout(&mut self, timeout: Duration)
Sets the request timeout.
Sourcepub fn set_max_retries(&mut self, retries: u32)
pub fn set_max_retries(&mut self, retries: u32)
Sets the maximum number of retries.
Sourcepub fn set_retry_delay(&mut self, delay: Duration)
pub fn set_retry_delay(&mut self, delay: Duration)
Sets the retry delay.
Sourcepub fn state(&self) -> AssociationState
pub fn state(&self) -> AssociationState
Returns the current association state.
Sourcepub fn application_context(&self) -> u8
pub fn application_context(&self) -> u8
Returns the negotiated application context.
Sourcepub fn is_associated(&self) -> bool
pub fn is_associated(&self) -> bool
Returns true if the session is currently associated.
Sourcepub fn associate(
&mut self,
request: &AssociationRequest,
) -> Result<AssociationResponse, SessionError>
pub fn associate( &mut self, request: &AssociationRequest, ) -> Result<AssociationResponse, SessionError>
Opens an application association by exchanging AARQ / AARE. The ACSE APDUs are sent as-is (any ciphering is inside their user-information field).
On success, updates the session state to Associated and records the
negotiated application context and mechanism.
Sourcepub fn associate_no_security(
&mut self,
initiate_request: Vec<u8>,
) -> Result<AssociationResponse, SessionError>
pub fn associate_no_security( &mut self, initiate_request: Vec<u8>, ) -> Result<AssociationResponse, SessionError>
Convenience method: associates with no security (mechanism 0).
Sourcepub fn associate_lls(
&mut self,
password: Vec<u8>,
initiate_request: Vec<u8>,
) -> Result<AssociationResponse, SessionError>
pub fn associate_lls( &mut self, password: Vec<u8>, initiate_request: Vec<u8>, ) -> Result<AssociationResponse, SessionError>
Convenience method: associates with Low-Level Security (password).
Sourcepub fn associate_hls_sha1(
&mut self,
challenge: Vec<u8>,
initiate_request: Vec<u8>,
) -> Result<AssociationResponse, SessionError>
pub fn associate_hls_sha1( &mut self, challenge: Vec<u8>, initiate_request: Vec<u8>, ) -> Result<AssociationResponse, SessionError>
Convenience method: associates with High-Level Security (SHA-1).
Sourcepub fn associate_gmac(
&mut self,
client_system_title: Vec<u8>,
initiate_request: Vec<u8>,
) -> Result<AssociationResponse, SessionError>
pub fn associate_gmac( &mut self, client_system_title: Vec<u8>, initiate_request: Vec<u8>, ) -> Result<AssociationResponse, SessionError>
Convenience method: associates with GMAC (mechanism 5) and ciphering.
Sourcepub fn release(
&mut self,
request: &ReleaseRequest,
) -> Result<ReleaseResponse, SessionError>
pub fn release( &mut self, request: &ReleaseRequest, ) -> Result<ReleaseResponse, SessionError>
Gracefully releases the association by exchanging RLRQ / RLRE.
On success, resets the session state to Idle.
Sourcepub fn release_normal(&mut self) -> Result<ReleaseResponse, SessionError>
pub fn release_normal(&mut self) -> Result<ReleaseResponse, SessionError>
Convenience method: releases with normal reason.
Sourcepub fn send_raw(&mut self, apdu: &RawApdu) -> Result<RawApdu, SessionError>
pub fn send_raw(&mut self, apdu: &RawApdu) -> Result<RawApdu, SessionError>
Sends a raw APDU and receives a raw response without parsing.
This method bypasses the typed service layer and works directly with raw bytes, which is useful for:
- Manufacturer-specific APDUs
- Extension APDUs not defined in IEC 62056-5-3
- Testing and debugging
- Custom protocol extensions
If ciphering is configured, the raw APDU is protected/unprotected transparently.
Sourcepub fn send_raw_bytes(&mut self, data: &[u8]) -> Result<Vec<u8>, SessionError>
pub fn send_raw_bytes(&mut self, data: &[u8]) -> Result<Vec<u8>, SessionError>
Sends raw bytes and receives raw bytes without any parsing or protection.
This is the lowest-level send/receive method, bypassing even the raw APDU framing. Use for completely custom protocols.
Sourcepub fn make_raw_apdu(tag: u8, body: Vec<u8>) -> RawApdu
pub fn make_raw_apdu(tag: u8, body: Vec<u8>) -> RawApdu
Creates a raw APDU with the given tag and body.
Sourcepub fn parse_raw_apdu(bytes: &[u8]) -> Result<RawApdu, SessionError>
pub fn parse_raw_apdu(bytes: &[u8]) -> Result<RawApdu, SessionError>
Parses a raw APDU from bytes.
Sourcepub fn get(
&mut self,
class_id: u16,
instance: ObisCode,
attribute_id: i8,
) -> Result<GetResponse, SessionError>
pub fn get( &mut self, class_id: u16, instance: ObisCode, attribute_id: i8, ) -> Result<GetResponse, SessionError>
Reads one attribute (GET-REQUEST-NORMAL).
Sourcepub fn set(
&mut self,
class_id: u16,
instance: ObisCode,
attribute_id: i8,
value: CosemDataType,
) -> Result<SetResponse, SessionError>
pub fn set( &mut self, class_id: u16, instance: ObisCode, attribute_id: i8, value: CosemDataType, ) -> Result<SetResponse, SessionError>
Writes one attribute (SET-REQUEST-NORMAL).
Sourcepub fn action(
&mut self,
class_id: u16,
instance: ObisCode,
method_id: i8,
parameters: Option<CosemDataType>,
) -> Result<ActionResponse, SessionError>
pub fn action( &mut self, class_id: u16, instance: ObisCode, method_id: i8, parameters: Option<CosemDataType>, ) -> Result<ActionResponse, SessionError>
Invokes one method (ACTION-REQUEST-NORMAL).