1use fidl_fuchsia_wlan_policy as fidl_policy;
6use serde::Serialize;
7
8#[derive(Serialize)]
10pub enum WlanClientState {
11 ConnectionsDisabled,
12 ConnectionsEnabled,
13}
14
15impl From<fidl_policy::WlanClientState> for WlanClientState {
16 fn from(state: fidl_policy::WlanClientState) -> Self {
17 match state {
18 fidl_policy::WlanClientState::ConnectionsDisabled => Self::ConnectionsDisabled,
19 fidl_policy::WlanClientState::ConnectionsEnabled => Self::ConnectionsEnabled,
20 }
21 }
22}
23
24#[derive(Serialize)]
25pub enum ConnectionState {
26 Failed,
27 Disconnected,
28 Connecting,
29 Connected,
30}
31
32impl From<fidl_policy::ConnectionState> for ConnectionState {
33 fn from(state: fidl_policy::ConnectionState) -> Self {
34 match state {
35 fidl_policy::ConnectionState::Failed => Self::Failed,
36 fidl_policy::ConnectionState::Disconnected => Self::Disconnected,
37 fidl_policy::ConnectionState::Connecting => Self::Connecting,
38 fidl_policy::ConnectionState::Connected => Self::Connected,
39 }
40 }
41}
42
43#[derive(Serialize)]
44pub enum SecurityType {
45 None = 1,
46 Wep = 2,
47 Wpa = 3,
48 Wpa2 = 4,
49 Wpa3 = 5,
50}
51
52#[derive(Serialize)]
53pub enum DisconnectStatus {
54 TimedOut = 1,
55 CredentialsFailed = 2,
56 ConnectionStopped = 3,
57 ConnectionFailed = 4,
58}
59
60impl From<fidl_policy::DisconnectStatus> for DisconnectStatus {
61 fn from(status: fidl_policy::DisconnectStatus) -> Self {
62 match status {
63 fidl_policy::DisconnectStatus::TimedOut => Self::TimedOut,
64 fidl_policy::DisconnectStatus::CredentialsFailed => Self::CredentialsFailed,
65 fidl_policy::DisconnectStatus::ConnectionStopped => Self::ConnectionStopped,
66 fidl_policy::DisconnectStatus::ConnectionFailed => Self::ConnectionFailed,
67 }
68 }
69}
70
71#[derive(Serialize)]
72pub struct NetworkIdentifier {
73 pub ssid: String,
75 pub type_: SecurityType,
77}
78
79#[derive(Serialize)]
80pub struct NetworkState {
81 pub id: Option<NetworkIdentifier>,
83 pub state: Option<ConnectionState>,
85 pub status: Option<DisconnectStatus>,
87}
88
89impl From<fidl_policy::NetworkState> for NetworkState {
90 fn from(state: fidl_policy::NetworkState) -> Self {
91 NetworkState {
92 id: state.id.map(NetworkIdentifier::from),
93 state: state.state.map(ConnectionState::from),
94 status: state.status.map(DisconnectStatus::from),
95 }
96 }
97}
98
99#[derive(Serialize)]
100pub struct ClientStateSummary {
101 pub state: Option<WlanClientState>,
103
104 pub networks: Option<Vec<NetworkState>>,
106}
107
108impl From<fidl_policy::ClientStateSummary> for ClientStateSummary {
109 fn from(summary: fidl_policy::ClientStateSummary) -> ClientStateSummary {
110 ClientStateSummary {
111 state: summary.state.map(WlanClientState::from),
112 networks: summary
113 .networks
114 .map(|networks| networks.into_iter().map(|state| state.into()).collect()),
115 }
116 }
117}
118
119#[derive(Serialize)]
122pub enum Credential {
123 Password(String),
124 Psk(String),
125 None,
126 Unknown,
127}
128
129impl From<fidl_policy::Credential> for Credential {
130 fn from(credential: fidl_policy::Credential) -> Self {
131 match credential {
132 fidl_policy::Credential::Password(password) => {
133 Self::Password(String::from_utf8_lossy(&password).to_string())
134 }
135 fidl_policy::Credential::Psk(psk) => Self::Psk(hex::encode(psk)),
136 fidl_policy::Credential::None(_) => Self::None,
137 _ => Self::Unknown,
138 }
139 }
140}
141
142impl Credential {
143 fn get_type(&self) -> String {
144 match self {
145 Credential::Password(_) => "Password",
146 Credential::Psk(_) => "Psk",
147 Credential::None => "None",
148 Credential::Unknown => "Unknown",
149 }
150 .to_string()
151 }
152
153 fn into_value(self) -> String {
154 match self {
155 Credential::Password(password) => password,
156 Credential::Psk(psk) => psk,
157 _ => String::new(),
158 }
159 }
160}
161
162impl From<fidl_policy::NetworkIdentifier> for NetworkIdentifier {
163 fn from(id: fidl_policy::NetworkIdentifier) -> Self {
164 Self { ssid: String::from_utf8_lossy(&id.ssid).to_string(), type_: id.type_.into() }
165 }
166}
167
168impl From<fidl_policy::SecurityType> for SecurityType {
169 fn from(security: fidl_policy::SecurityType) -> Self {
170 match security {
171 fidl_policy::SecurityType::None => SecurityType::None,
172 fidl_policy::SecurityType::Wep => SecurityType::Wep,
173 fidl_policy::SecurityType::Wpa => SecurityType::Wpa,
174 fidl_policy::SecurityType::Wpa2 => SecurityType::Wpa2,
175 fidl_policy::SecurityType::Wpa3 => SecurityType::Wpa3,
176 }
177 }
178}
179
180#[derive(Serialize)]
184pub struct NetworkConfig {
185 pub ssid: Option<String>,
186 pub security_type: Option<SecurityType>,
187 pub credential_type: Option<String>,
188 pub credential_value: Option<String>,
189}
190
191impl From<fidl_policy::NetworkConfig> for NetworkConfig {
192 fn from(cfg: fidl_policy::NetworkConfig) -> Self {
193 let credential = cfg.credential.map(Credential::from);
194 NetworkConfig {
195 ssid: cfg.id.as_ref().map(|id| String::from_utf8_lossy(&id.ssid).to_string()),
196 security_type: cfg.id.map(|id| SecurityType::from(id.type_)),
197 credential_type: credential.as_ref().map(|credential| credential.get_type()),
198 credential_value: credential.map(|credential| credential.into_value()),
199 }
200 }
201}
202
203#[derive(Serialize)]
204pub enum OperatingState {
205 Failed,
206 Starting,
207 Active,
208}
209
210impl From<fidl_policy::OperatingState> for OperatingState {
211 fn from(state: fidl_policy::OperatingState) -> Self {
212 match state {
213 fidl_policy::OperatingState::Failed => OperatingState::Failed,
214 fidl_policy::OperatingState::Starting => OperatingState::Starting,
215 fidl_policy::OperatingState::Active => OperatingState::Active,
216 }
217 }
218}
219
220#[derive(Serialize)]
221pub enum ConnectivityMode {
222 LocalOnly,
223 Unrestricted,
224}
225
226impl From<fidl_policy::ConnectivityMode> for ConnectivityMode {
227 fn from(mode: fidl_policy::ConnectivityMode) -> Self {
228 match mode {
229 fidl_policy::ConnectivityMode::LocalOnly => ConnectivityMode::LocalOnly,
230 fidl_policy::ConnectivityMode::Unrestricted => ConnectivityMode::Unrestricted,
231 }
232 }
233}
234
235#[derive(Serialize)]
236pub enum OperatingBand {
237 Any,
238 Only24Ghz,
239 Only5Ghz,
240}
241
242impl From<fidl_policy::OperatingBand> for OperatingBand {
243 fn from(band: fidl_policy::OperatingBand) -> Self {
244 match band {
245 fidl_policy::OperatingBand::Any => OperatingBand::Any,
246 fidl_policy::OperatingBand::Only24Ghz => OperatingBand::Only24Ghz,
247 fidl_policy::OperatingBand::Only5Ghz => OperatingBand::Only5Ghz,
248 }
249 }
250}
251
252#[derive(Serialize)]
253pub struct ConnectedClientInformation {
254 count: Option<u8>,
255}
256
257impl From<fidl_policy::ConnectedClientInformation> for ConnectedClientInformation {
258 fn from(clients: fidl_policy::ConnectedClientInformation) -> Self {
259 ConnectedClientInformation { count: clients.count }
260 }
261}
262
263#[derive(Serialize)]
264pub struct AccessPointState {
265 state: Option<OperatingState>,
266 mode: Option<ConnectivityMode>,
267 band: Option<OperatingBand>,
268 frequency: Option<u32>,
269 clients: Option<ConnectedClientInformation>,
270 id: Option<NetworkIdentifier>,
271}
272
273impl From<fidl_policy::AccessPointState> for AccessPointState {
274 fn from(update: fidl_policy::AccessPointState) -> Self {
275 AccessPointState {
276 state: update.state.map(|state| OperatingState::from(state)),
277 mode: update.mode.map(|mode| ConnectivityMode::from(mode)),
278 band: update.band.map(|band| OperatingBand::from(band)),
279 frequency: update.frequency,
280 clients: update.clients.map(|clients| ConnectedClientInformation::from(clients)),
281 id: update.id.map(|id| NetworkIdentifier::from(id)),
282 }
283 }
284}