1use fidl_fuchsia_wlan_ieee80211 as fidl_ieee80211;
6use fidl_fuchsia_wlan_sme as fidl_sme;
7use serde::{Deserialize, Serialize};
8
9#[derive(Serialize, Deserialize)]
10#[serde(remote = "fidl_sme::Protection")]
11pub(crate) enum ProtectionDef {
12 Unknown = 0,
13 Open = 1,
14 Wep = 2,
15 Wpa1 = 3,
16 Wpa1Wpa2PersonalTkipOnly = 4,
17 Wpa2PersonalTkipOnly = 5,
18 Wpa1Wpa2Personal = 6,
19 Wpa2Personal = 7,
20 Wpa2Wpa3Personal = 8,
21 Wpa3Personal = 9,
22 Wpa2Enterprise = 10,
23 Wpa3Enterprise = 11,
24 Owe = 12,
25 OpenOweTransition = 13,
26}
27
28#[derive(Serialize, Deserialize)]
31#[repr(u32)]
32pub(crate) enum ChannelBandwidthDef {
33 Cbw20 = 0,
34 Cbw40 = 1,
35 Cbw40Below = 2,
36 Cbw80 = 3,
37 Cbw160 = 4,
38 Cbw80P80 = 5,
39 Unknown = u32::MAX,
40}
41
42impl From<fidl_ieee80211::ChannelBandwidth> for ChannelBandwidthDef {
43 fn from(fidl_type: fidl_ieee80211::ChannelBandwidth) -> Self {
44 match fidl_type {
45 fidl_ieee80211::ChannelBandwidth::Cbw20 => Self::Cbw20,
46 fidl_ieee80211::ChannelBandwidth::Cbw40 => Self::Cbw40,
47 fidl_ieee80211::ChannelBandwidth::Cbw40Below => Self::Cbw40Below,
48 fidl_ieee80211::ChannelBandwidth::Cbw80 => Self::Cbw80,
49 fidl_ieee80211::ChannelBandwidth::Cbw160 => Self::Cbw160,
50 fidl_ieee80211::ChannelBandwidth::Cbw80P80 => Self::Cbw80P80,
51 fidl_ieee80211::ChannelBandwidthUnknown!() => Self::Unknown,
52 }
53 }
54}
55
56impl From<ChannelBandwidthDef> for fidl_ieee80211::ChannelBandwidth {
57 fn from(serde_type: ChannelBandwidthDef) -> Self {
58 match serde_type {
59 ChannelBandwidthDef::Cbw20 => Self::Cbw20,
60 ChannelBandwidthDef::Cbw40 => Self::Cbw40,
61 ChannelBandwidthDef::Cbw40Below => Self::Cbw40Below,
62 ChannelBandwidthDef::Cbw80 => Self::Cbw80,
63 ChannelBandwidthDef::Cbw160 => Self::Cbw160,
64 ChannelBandwidthDef::Cbw80P80 => Self::Cbw80P80,
65 ChannelBandwidthDef::Unknown => Self::unknown(),
66 }
67 }
68}
69
70#[derive(Serialize, Deserialize)]
71pub(crate) struct WlanChannelDef {
72 pub primary: u8,
73 pub cbw: ChannelBandwidthDef,
74 pub secondary80: u8,
75}
76
77impl From<fidl_ieee80211::ChannelNumber> for WlanChannelDef {
78 fn from(fidl_type: fidl_ieee80211::ChannelNumber) -> Self {
79 Self { primary: fidl_type.number, cbw: ChannelBandwidthDef::Cbw20, secondary80: 0 }
89 }
90}
91
92impl From<WlanChannelDef> for fidl_ieee80211::WlanChannel {
93 fn from(serde_type: WlanChannelDef) -> Self {
94 Self {
95 primary: serde_type.primary,
96 cbw: serde_type.cbw.into(),
97 secondary80: serde_type.secondary80,
98 }
99 }
100}
101
102#[derive(Serialize)]
103pub(crate) struct ServingApInfoDef {
104 pub bssid: [u8; 6],
105 pub ssid: Vec<u8>,
106 pub rssi_dbm: i8,
107 pub snr_db: i8,
108 pub channel: WlanChannelDef,
109 #[serde(with = "ProtectionDef")]
110 pub protection: fidl_sme::Protection,
111}
112
113impl From<fidl_sme::ServingApInfo> for ServingApInfoDef {
114 fn from(fidl_type: fidl_sme::ServingApInfo) -> Self {
115 Self {
116 bssid: fidl_type.bssid,
117 ssid: fidl_type.ssid,
118 rssi_dbm: fidl_type.rssi_dbm,
119 snr_db: fidl_type.snr_db,
120 channel: WlanChannelDef {
121 primary: fidl_type.primary.number,
122 cbw: fidl_type.bandwidth.into(),
123 secondary80: fidl_type.vht_secondary_80_channel.number,
124 },
125 protection: fidl_type.protection,
126 }
127 }
128}
129
130#[derive(Serialize)]
131#[serde(remote = "fidl_sme::Empty")]
132pub(crate) struct SmeEmptyDef;
133
134#[derive(Serialize)]
135pub(crate) enum ClientStatusResponseDef {
136 Connected(ServingApInfoDef),
137 Connecting(Vec<u8>),
138 Roaming(Vec<u8>),
139 #[serde(with = "SmeEmptyDef")]
140 Idle(fidl_sme::Empty),
141}
142
143impl From<fidl_sme::ClientStatusResponse> for ClientStatusResponseDef {
144 fn from(fidl_type: fidl_sme::ClientStatusResponse) -> Self {
145 match fidl_type {
146 fidl_sme::ClientStatusResponse::Connected(info) => Self::Connected(info.into()),
147 fidl_sme::ClientStatusResponse::Connecting(vec) => Self::Connecting(vec),
148 fidl_sme::ClientStatusResponse::Roaming(bssid) => Self::Roaming(bssid.to_vec()),
149 fidl_sme::ClientStatusResponse::Idle(empty) => Self::Idle(empty),
150 }
151 }
152}