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