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
impl RequestDispatcher
Sourcepub fn set_max_pdu(&mut self, max_pdu: usize)
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.
Sourcepub fn add(&mut self, object: Box<dyn InterfaceClass>)
pub fn add(&mut self, object: Box<dyn InterfaceClass>)
Registers an object.
Sourcepub fn set_association(&mut self, assoc: AssociationLn)
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.
Sourcepub fn restore_pending(&mut self, pending: PendingBlocks)
pub fn restore_pending(&mut self, pending: PendingBlocks)
Restores block-transfer state previously taken with Self::take_pending.
Sourcepub fn take_pending(&mut self) -> PendingBlocks
pub fn take_pending(&mut self) -> PendingBlocks
Takes block-transfer state so the host can persist it across requests.
Sourcepub fn association(&self) -> Option<&AssociationLn>
pub fn association(&self) -> Option<&AssociationLn>
Returns a reference to the current association, if any.
Sourcepub fn association_mut(&mut self) -> Option<&mut AssociationLn>
pub fn association_mut(&mut self) -> Option<&mut AssociationLn>
Returns a mutable reference to the current association, if any.
Sourcepub fn build_push_delivery_request(
&mut self,
push_setup: &PushSetup,
long_invoke_id_and_priority: u32,
) -> Result<PushDeliveryRequest, String>
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.
Sourcefn find(
&mut self,
class_id: u16,
instance: &ObisCode,
) -> Option<&mut Box<dyn InterfaceClass>>
fn find( &mut self, class_id: u16, instance: &ObisCode, ) -> Option<&mut Box<dyn InterfaceClass>>
Locates a registered object by class-id and logical name.
Sourcefn check_read(
&self,
class_id: u16,
instance: &ObisCode,
attribute_id: i8,
) -> bool
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).
Sourcefn check_write(
&self,
class_id: u16,
instance: &ObisCode,
attribute_id: i8,
) -> bool
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).
Sourcefn check_invoke(
&self,
class_id: u16,
instance: &ObisCode,
method_id: i8,
) -> bool
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).
Sourcefn read_attribute(&mut self, d: &AttributeDescriptor) -> GetDataResult
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.
Sourcefn write_attribute(
&mut self,
d: &AttributeDescriptor,
value: CosemDataType,
) -> u8
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.
Sourcefn invoke(
&mut self,
d: &MethodDescriptor,
params: Option<CosemDataType>,
) -> (u8, Option<GetDataResult>)
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.
Sourcepub fn dispatch(&mut self, request: &[u8]) -> Result<Vec<u8>, ServiceError>
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.
Sourcefn xdlms_services_allowed(&self, request: &[u8]) -> bool
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).
Sourcepub fn handle_aarq(&mut self, request: &[u8]) -> Vec<u8> ⓘ
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 →
initiateErrorConfirmedServiceError 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-pendinguntil thereply_to_HLS_authenticationACTION (pass 3/4) completes.
Requires an association to be configured via Self::set_association;
without one, only mechanism 0 (lowest) AARQs are accepted.
Sourcefn aarq_mechanism_matches_assoc(
requested: AuthMechanism,
required: AuthMechanism,
) -> bool
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.
Sourcepub fn handle_rlrq(&mut self, request: &[u8]) -> Vec<u8> ⓘ
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.
Sourcefn role_conformance(mechanism: AuthMechanism) -> u32
fn role_conformance(mechanism: AuthMechanism) -> u32
Role conformance advertised in AARE, matching C++ aare fill order.
Sourcefn negotiate_initiate_response(
ireq: Option<&InitiateRequest>,
mechanism: AuthMechanism,
) -> Vec<u8> ⓘ
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.
fn dispatch_get(&mut self, request: &[u8]) -> Result<Vec<u8>, ServiceError>
Sourcefn start_get_blocks(
&mut self,
invoke_id_and_priority: u8,
data: Vec<u8>,
) -> Vec<u8> ⓘ
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.
Sourcefn next_get_block(
&mut self,
invoke_id_and_priority: u8,
acked_block: u32,
) -> Vec<u8> ⓘ
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).
fn dispatch_set(&mut self, request: &[u8]) -> Vec<u8> ⓘ
Sourcefn accumulate_set_block(
&mut self,
invoke_id_and_priority: u8,
datablock: &DataBlockSa,
) -> Vec<u8> ⓘ
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.