Skip to main content

bacnet_objects/network_port/
bip_config.rs

1//! Declared configuration for an unbound, flat application-level B/IP port.
2//! The B/IP mode is not configuration here: a registered owner publishes it.
3
4use crate::common;
5use crate::prelude::*;
6use bacnet_types::error::Error;
7
8/// Complete configured B/IP snapshot. Fixed-size addresses prevent malformed
9/// IPv4 values. Zero address/mask/gateway and one zero DNS address mean unknown
10/// or unconfigured; they do not describe an observed interface or route.
11#[derive(Clone, Debug, PartialEq, Eq)]
12pub struct BipPortConfig {
13    /// Caller-configured number; zero means unknown, 65535 is invalid.
14    pub network_number: u16,
15    /// Port APDU_Length (399), independent of Device Max_APDU_Length_Accepted.
16    /// Any Unsigned value >= 50 is permitted by the property clause.
17    pub apdu_length: u32,
18    /// Configured IPv4 address, in network byte order.
19    pub ip_address: [u8; 4],
20    /// Zero is allowed in this unbound configuration, independently of Port ID.
21    pub udp_port: u16,
22    /// Configured mask, with no assumed prefix or interface discovery.
23    pub subnet_mask: [u8; 4],
24    /// Configured gateway, with no assumed OS route.
25    pub default_gateway: [u8; 4],
26    /// At least one address; a zero address represents unavailable DNS.
27    pub dns_servers: Vec<[u8; 4]>,
28}
29
30impl Default for BipPortConfig {
31    fn default() -> Self {
32        Self {
33            network_number: 0,
34            // Declared B/IP capacity used by this library's transport profile.
35            // No active transport is discovered or verified by this object.
36            apdu_length: 1476,
37            ip_address: [0; 4],
38            udp_port: 47808,
39            subnet_mask: [0; 4],
40            default_gateway: [0; 4],
41            dns_servers: vec![[0; 4]],
42        }
43    }
44}
45
46impl BipPortConfig {
47    pub(super) fn validate(&self, instance: u32) -> Result<(), Error> {
48        // Local policy for the explicit flat B/IP application profile only.
49        if !(1..=255).contains(&instance)
50            || self.network_number == u16::MAX
51            || self.apdu_length < 50
52            || self.dns_servers.is_empty()
53        {
54            return Err(common::value_out_of_range_error());
55        }
56        Ok(())
57    }
58}