use crate::common;
use bacnet_types::error::Error;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct BipPortConfig {
pub network_number: u16,
pub apdu_length: u32,
pub ip_address: [u8; 4],
pub udp_port: u16,
pub subnet_mask: [u8; 4],
pub default_gateway: [u8; 4],
pub dns_servers: Vec<[u8; 4]>,
}
impl Default for BipPortConfig {
fn default() -> Self {
Self {
network_number: 0,
apdu_length: 1476,
ip_address: [0; 4],
udp_port: 47808,
subnet_mask: [0; 4],
default_gateway: [0; 4],
dns_servers: vec![[0; 4]],
}
}
}
impl BipPortConfig {
pub(super) fn validate(&self, instance: u32) -> Result<(), Error> {
if !(1..=255).contains(&instance)
|| self.network_number == u16::MAX
|| self.apdu_length < 50
|| self.dns_servers.is_empty()
{
return Err(common::value_out_of_range_error());
}
Ok(())
}
}