Skip to main content

RequestDispatcher

Struct RequestDispatcher 

Source
pub struct RequestDispatcher {
    objects: Vec<Box<dyn InterfaceClass>>,
    max_pdu: usize,
    pending_get: Option<PendingGet>,
    pending_set: Option<PendingSet>,
    association: Option<AssociationLn>,
}
Expand description

A collection of COSEM objects that answers GET/SET/ACTION requests.

Fields§

§objects: Vec<Box<dyn InterfaceClass>>§max_pdu: usize§pending_get: Option<PendingGet>§pending_set: Option<PendingSet>§association: Option<AssociationLn>

Current association for access rights checking (IEC 62056-5-3, 5.3.7). When set, GET/SET/ACTION are checked against the association’s object_list.

Implementations§

Source§

impl RequestDispatcher

Source

pub fn new() -> Self

Creates an empty dispatcher with the default block size.

Source

pub fn set_max_pdu(&mut self, max_pdu: usize)

Sets the maximum block-transfer payload size (octets). Results larger than this are delivered in GET-RESPONSE-WITH-DATABLOCK blocks.

Source

pub fn add(&mut self, object: Box<dyn InterfaceClass>)

Registers an object.

Source

pub fn set_association(&mut self, assoc: AssociationLn)

Sets the current association for access rights checking. When an association is set, all GET/SET/ACTION requests are checked against the association’s object_list access_rights.

Source

pub fn restore_pending(&mut self, pending: PendingBlocks)

Restores block-transfer state previously taken with Self::take_pending.

Source

pub fn take_pending(&mut self) -> PendingBlocks

Takes block-transfer state so the host can persist it across requests.

Source

pub fn association(&self) -> Option<&AssociationLn>

Returns a reference to the current association, if any.

Source

pub fn association_mut(&mut self) -> Option<&mut AssociationLn>

Returns a mutable reference to the current association, if any.

Source

pub fn build_push_delivery_request( &mut self, push_setup: &PushSetup, long_invoke_id_and_priority: u32, ) -> Result<PushDeliveryRequest, String>

Assembles a PushDeliveryRequest for push_setup’s ACTION method 1 (push): reads each object in push_object_list from this dispatcher’s registry, wraps the values in a DataNotification (an Array when more than one object is listed), and pairs it with the destination and client SAP from push_setup.

Mirrors the reference implementation’s push_build_notification_body / push_try_schedule_delivery: the host is expected to call this from the push ACTION handler (this dispatcher owns the object registry that PushSetup itself does not hold) and then deliver body over the configured transport.

Source

fn find( &mut self, class_id: u16, instance: &ObisCode, ) -> Option<&mut Box<dyn InterfaceClass>>

Locates a registered object by class-id and logical name.

Source

fn check_read( &self, class_id: u16, instance: &ObisCode, attribute_id: i8, ) -> bool

Checks whether a read is allowed for the given object and attribute. Returns true if no association is set (unrestricted access).

Source

fn check_write( &self, class_id: u16, instance: &ObisCode, attribute_id: i8, ) -> bool

Checks whether a write is allowed for the given object and attribute. Returns true if no association is set (unrestricted access).

Source

fn check_invoke( &self, class_id: u16, instance: &ObisCode, method_id: i8, ) -> bool

Checks whether a method invocation is allowed. Returns true if no association is set (unrestricted access).

Source

fn read_attribute(&mut self, d: &AttributeDescriptor) -> GetDataResult

Reads one attribute, returning its value or a data-access-result code. Checks access rights from the current association’s object_list.

Source

fn write_attribute( &mut self, d: &AttributeDescriptor, value: CosemDataType, ) -> u8

Writes one attribute, returning a data-access-result code. Checks access rights from the current association’s object_list.

Source

fn invoke( &mut self, d: &MethodDescriptor, params: Option<CosemDataType>, ) -> (u8, Option<GetDataResult>)

Invokes one method, returning the action-result and optional return data. Checks method access rights from the current association’s object_list.

Source

pub fn dispatch(&mut self, request: &[u8]) -> Result<Vec<u8>, ServiceError>

Dispatches one request APDU to the addressed object and returns the encoded response APDU. Malformed or unsupported requests yield an EXCEPTION-RESPONSE. An AARQ is answered with an AARE via Self::handle_aarq.

Source

fn xdlms_services_allowed(&self, request: &[u8]) -> bool

xDLMS GET/SET/ACTION are allowed only when associated. While HLS is pending, only reply_to_HLS_authentication (Association LN method 1) is accepted — everything else yields EXCEPTION-RESPONSE (C++ hls_pending gate / Yellow Book APPL_OPEN HLS pass 3).

Source

pub fn handle_aarq(&mut self, request: &[u8]) -> Vec<u8> ⓘ

Validates an AARQ against the configured association and answers with an AARE carrying a structured ACSE diagnostic (IEC 62056-5-3 §7.3.5):

  • unsupported application context → application-context-name-not-supported;
  • ciphering / title-bound HLS without an 8-octet calling-AP-title → calling-AP-title-not-recognized;
  • bad InitiateRequest parameters → initiateError ConfirmedServiceError in the user-information (DLMS version / conformance / PDU size);
  • missing, unknown, or mismatching authentication → authentication-required / -mechanism-name-not-recognised / authentication-failure;
  • LLS: the calling-authentication-value is compared with the association’s secret;
  • HLS: the CtoS challenge is stored, a random StoC is generated and returned, and the association is left association-pending until the reply_to_HLS_authentication ACTION (pass 3/4) completes.

Requires an association to be configured via Self::set_association; without one, only mechanism 0 (lowest) AARQs are accepted.

Source

fn aarq_mechanism_matches_assoc( requested: AuthMechanism, required: AuthMechanism, ) -> bool

Manufacturer-specific HIGH-level authentication advertises mechanism 2 (HlsManufacturer); СПОДЭС Configurator associations are configured as HLS-GMAC (5). Accept that pairing for AARQ, then finish the handshake with GMAC.

Source

pub fn handle_rlrq(&mut self, request: &[u8]) -> Vec<u8> ⓘ

Answers an RLRQ with RLRE (IEC 62056-5-3 §7.3.6) and clears any configured association state back to non-associated. A malformed RLRQ is still answered with a normal-release RLRE, since releasing is best-effort.

Source

fn role_conformance(mechanism: AuthMechanism) -> u32

Role conformance advertised in AARE, matching C++ aare fill order.

Source

fn negotiate_initiate_response( ireq: Option<&InitiateRequest>, mechanism: AuthMechanism, ) -> Vec<u8> ⓘ

Builds the negotiated InitiateResponse: role conformance is ANDed with the client’s proposal and the PDU size capped by the client’s maximum.

Source

fn dispatch_get(&mut self, request: &[u8]) -> Result<Vec<u8>, ServiceError>

Source

fn start_get_blocks( &mut self, invoke_id_and_priority: u8, data: Vec<u8>, ) -> Vec<u8> ⓘ

Stores a segmented GET result and returns the first datablock response.

Source

fn next_get_block( &mut self, invoke_id_and_priority: u8, acked_block: u32, ) -> Vec<u8> ⓘ

Returns the datablock following acked_block (0 for the first).

Source

fn dispatch_set(&mut self, request: &[u8]) -> Vec<u8> ⓘ

Source

fn accumulate_set_block( &mut self, invoke_id_and_priority: u8, datablock: &DataBlockSa, ) -> Vec<u8> ⓘ

Appends one SET datablock; on the last block, decodes and writes the value.

Source

fn dispatch_action(&mut self, request: &[u8]) -> Result<Vec<u8>, ServiceError>

Trait Implementations§

Source§

impl Default for RequestDispatcher

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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
§

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

§

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.

§

impl<T> Instrument for T

§

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

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

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.

§

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

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

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