openthread/ot/
border_agent.rs1use crate::prelude_internal::*;
6use num::FromPrimitive;
7
8#[derive(
12 Debug,
13 Copy,
14 Clone,
15 Eq,
16 Ord,
17 PartialOrd,
18 PartialEq,
19 num_derive::FromPrimitive,
20 num_derive::ToPrimitive,
21)]
22pub enum BorderAgentEphemeralKeyState {
23 Disabled = OT_BORDER_AGENT_STATE_DISABLED as isize,
25
26 Stopped = OT_BORDER_AGENT_STATE_STOPPED as isize,
28
29 Started = OT_BORDER_AGENT_STATE_STARTED as isize,
31
32 Connected = OT_BORDER_AGENT_STATE_CONNECTED as isize,
34
35 Accepted = OT_BORDER_AGENT_STATE_ACCEPTED as isize,
37}
38
39impl From<otBorderAgentEphemeralKeyState> for BorderAgentEphemeralKeyState {
40 fn from(x: otBorderAgentEphemeralKeyState) -> Self {
41 Self::from_u32(x)
42 .unwrap_or_else(|| panic!("Unknown otBorderAgentEphemeralKeyState value: {x}"))
43 }
44}
45
46impl From<BorderAgentEphemeralKeyState> for otBorderAgentEphemeralKeyState {
47 fn from(x: BorderAgentEphemeralKeyState) -> Self {
48 x as otBorderAgentEphemeralKeyState
49 }
50}
51
52pub trait BorderAgent {
56 fn border_agent_is_active(&self) -> bool;
59
60 fn border_agent_get_udp_port(&self) -> u16;
63}
64
65impl<T: BorderAgent + Boxable> BorderAgent for ot::Box<T> {
66 fn border_agent_is_active(&self) -> bool {
67 self.as_ref().border_agent_is_active()
68 }
69
70 fn border_agent_get_udp_port(&self) -> u16 {
71 self.as_ref().border_agent_get_udp_port()
72 }
73}
74
75impl BorderAgent for Instance {
76 fn border_agent_is_active(&self) -> bool {
77 unsafe { otBorderAgentIsActive(self.as_ot_ptr()) }
78 }
79
80 fn border_agent_get_udp_port(&self) -> u16 {
81 unsafe { otBorderAgentGetUdpPort(self.as_ot_ptr()) }
82 }
83}