Skip to main content

ClientSession

Struct ClientSession 

Source
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>

Source

pub fn new(link: L) -> Self

Creates a plaintext session (no APDU ciphering).

Source

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.

Source

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.

Source

pub fn disable_gbt(&mut self)

Disables general block transfer, restoring single-frame sends.

Source

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.

Source

pub fn set_gbt_streaming(&mut self, enabled: bool)

Enables or disables the streaming variant of GBT. Has no effect unless GBT is enabled.

Source

pub fn builder(link: L) -> ClientSessionBuilder<L>

Returns a builder for configuring this session’s timeouts and retries.

Source

pub fn into_inner(self) -> L

Returns the underlying framing layer.

Source

pub fn config(&self) -> &SessionConfig

Returns a reference to the current session configuration.

Source

pub fn set_config(&mut self, config: SessionConfig)

Updates the session configuration.

Source

pub fn set_request_timeout(&mut self, timeout: Duration)

Sets the request timeout.

Source

pub fn set_max_retries(&mut self, retries: u32)

Sets the maximum number of retries.

Source

pub fn set_retry_delay(&mut self, delay: Duration)

Sets the retry delay.

Source

pub fn state(&self) -> AssociationState

Returns the current association state.

Source

pub fn application_context(&self) -> u8

Returns the negotiated application context.

Source

pub fn mechanism(&self) -> Option<u8>

Returns the negotiated authentication mechanism, if any.

Source

pub fn is_associated(&self) -> bool

Returns true if the session is currently associated.

Source

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.

Source

pub fn associate_no_security( &mut self, initiate_request: Vec<u8>, ) -> Result<AssociationResponse, SessionError>

Convenience method: associates with no security (mechanism 0).

Source

pub fn associate_lls( &mut self, password: Vec<u8>, initiate_request: Vec<u8>, ) -> Result<AssociationResponse, SessionError>

Convenience method: associates with Low-Level Security (password).

Source

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).

Source

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.

Source

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.

Source

pub fn release_normal(&mut self) -> Result<ReleaseResponse, SessionError>

Convenience method: releases with normal reason.

Source

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.

Source

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.

Source

pub fn make_raw_apdu(tag: u8, body: Vec<u8>) -> RawApdu

Creates a raw APDU with the given tag and body.

Source

pub fn parse_raw_apdu(bytes: &[u8]) -> Result<RawApdu, SessionError>

Parses a raw APDU from bytes.

Source

pub fn get( &mut self, class_id: u16, instance: ObisCode, attribute_id: i8, ) -> Result<GetResponse, SessionError>

Reads one attribute (GET-REQUEST-NORMAL).

Source

pub fn set( &mut self, class_id: u16, instance: ObisCode, attribute_id: i8, value: CosemDataType, ) -> Result<SetResponse, SessionError>

Writes one attribute (SET-REQUEST-NORMAL).

Source

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).

Auto Trait Implementations§

§

impl<L> Freeze for ClientSession<L>
where L: Freeze,

§

impl<L> RefUnwindSafe for ClientSession<L>
where L: RefUnwindSafe,

§

impl<L> Send for ClientSession<L>
where L: Send,

§

impl<L> Sync for ClientSession<L>
where L: Sync,

§

impl<L> Unpin for ClientSession<L>
where L: Unpin,

§

impl<L> UnsafeUnpin for ClientSession<L>
where L: UnsafeUnpin,

§

impl<L> UnwindSafe for ClientSession<L>
where L: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more