wlan_sme/client/
rsn.rs

1// Copyright 2019 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use crate::client::EstablishRsnaFailureReason;
6use fidl_fuchsia_wlan_mlme::{EapolResultCode, SaeFrame};
7use wlan_rsn::rsna::UpdateSink;
8use wlan_rsn::{auth, Error, NegotiatedProtection};
9
10#[derive(Debug)]
11pub struct Rsna {
12    pub negotiated_protection: NegotiatedProtection,
13    pub supplicant: Box<dyn Supplicant>,
14}
15
16impl PartialEq for Rsna {
17    fn eq(&self, other: &Self) -> bool {
18        self.negotiated_protection == other.negotiated_protection
19    }
20}
21
22pub trait Supplicant: std::fmt::Debug + std::marker::Send {
23    #[allow(clippy::result_large_err)] // TODO(https://fxbug.dev/401255153)
24    /// Starts the Supplicant. A Supplicant must be started after its creation and everytime it
25    /// was reset.
26    fn start(&mut self, update_sink: &mut UpdateSink) -> Result<(), Error>;
27    /// Resets all established Security Associations and invalidates all derived keys in this
28    /// ESSSA. The Supplicant must be reset or destroyed when the underlying 802.11 association
29    /// terminates. The replay counter is also reset.
30    fn reset(&mut self);
31    #[allow(clippy::result_large_err)] // TODO(https://fxbug.dev/401255153)
32    /// Entry point for all incoming EAPOL frames. Incoming frames can be corrupted, invalid or
33    /// of unsupported types; the Supplicant will filter and drop all unexpected frames.
34    /// Outbound EAPOL frames, status and key updates will be pushed into the `update_sink`.
35    /// The method will return an `Error` if the frame was invalid.
36    fn on_eapol_frame(
37        &mut self,
38        update_sink: &mut UpdateSink,
39        frame: eapol::Frame<&[u8]>,
40    ) -> Result<(), Error>;
41    #[allow(clippy::result_large_err)] // TODO(https://fxbug.dev/401255153)
42    fn on_eapol_conf(
43        &mut self,
44        update_sink: &mut UpdateSink,
45        result: EapolResultCode,
46    ) -> Result<(), Error>;
47    #[allow(clippy::result_large_err)] // TODO(https://fxbug.dev/401255153)
48    fn on_rsna_retransmission_timeout(&mut self, update_sink: &mut UpdateSink)
49        -> Result<(), Error>;
50    fn on_rsna_response_timeout(&self) -> EstablishRsnaFailureReason;
51    fn on_rsna_completion_timeout(&self) -> EstablishRsnaFailureReason;
52    // TODO(https://fxbug.dev/335283785): Remove or explain unused code.
53    #[allow(clippy::result_large_err)] // TODO(https://fxbug.dev/401255153)
54    #[allow(dead_code)]
55    fn on_pmk_available(
56        &mut self,
57        update_sink: &mut UpdateSink,
58        pmk: &[u8],
59        pmkid: &[u8],
60    ) -> Result<(), Error>;
61    #[allow(clippy::result_large_err)] // TODO(https://fxbug.dev/401255153)
62    fn on_sae_handshake_ind(&mut self, update_sink: &mut UpdateSink) -> Result<(), Error>;
63    #[allow(clippy::result_large_err)] // TODO(https://fxbug.dev/401255153)
64    fn on_sae_frame_rx(
65        &mut self,
66        update_sink: &mut UpdateSink,
67        frame: SaeFrame,
68    ) -> Result<(), Error>;
69    #[allow(clippy::result_large_err)] // TODO(https://fxbug.dev/401255153)
70    fn on_sae_timeout(&mut self, update_sink: &mut UpdateSink, event_id: u64) -> Result<(), Error>;
71    fn get_auth_cfg(&self) -> &auth::Config;
72    fn get_auth_method(&self) -> auth::MethodName;
73}
74
75impl Supplicant for wlan_rsn::Supplicant {
76    fn start(&mut self, update_sink: &mut UpdateSink) -> Result<(), Error> {
77        wlan_rsn::Supplicant::start(self, update_sink)
78    }
79
80    fn reset(&mut self) {
81        wlan_rsn::Supplicant::reset(self)
82    }
83
84    fn on_eapol_frame(
85        &mut self,
86        update_sink: &mut UpdateSink,
87        frame: eapol::Frame<&[u8]>,
88    ) -> Result<(), Error> {
89        wlan_rsn::Supplicant::on_eapol_frame(self, update_sink, frame)
90    }
91
92    fn on_eapol_conf(
93        &mut self,
94        update_sink: &mut UpdateSink,
95        result: EapolResultCode,
96    ) -> Result<(), Error> {
97        wlan_rsn::Supplicant::on_eapol_conf(self, update_sink, result)
98    }
99
100    fn on_rsna_retransmission_timeout(
101        &mut self,
102        update_sink: &mut UpdateSink,
103    ) -> Result<(), Error> {
104        wlan_rsn::Supplicant::on_rsna_retransmission_timeout(self, update_sink)
105    }
106
107    fn on_rsna_response_timeout(&self) -> EstablishRsnaFailureReason {
108        EstablishRsnaFailureReason::RsnaResponseTimeout(wlan_rsn::Supplicant::incomplete_reason(
109            self,
110        ))
111    }
112
113    fn on_rsna_completion_timeout(&self) -> EstablishRsnaFailureReason {
114        EstablishRsnaFailureReason::RsnaCompletionTimeout(wlan_rsn::Supplicant::incomplete_reason(
115            self,
116        ))
117    }
118
119    fn on_pmk_available(
120        &mut self,
121        update_sink: &mut UpdateSink,
122        pmk: &[u8],
123        pmkid: &[u8],
124    ) -> Result<(), Error> {
125        wlan_rsn::Supplicant::on_pmk_available(self, update_sink, pmk, pmkid)
126    }
127
128    fn on_sae_handshake_ind(&mut self, update_sink: &mut UpdateSink) -> Result<(), Error> {
129        wlan_rsn::Supplicant::on_sae_handshake_ind(self, update_sink)
130    }
131
132    fn on_sae_frame_rx(
133        &mut self,
134        update_sink: &mut UpdateSink,
135        frame: SaeFrame,
136    ) -> Result<(), Error> {
137        wlan_rsn::Supplicant::on_sae_frame_rx(self, update_sink, frame)
138    }
139
140    fn on_sae_timeout(&mut self, update_sink: &mut UpdateSink, event_id: u64) -> Result<(), Error> {
141        wlan_rsn::Supplicant::on_sae_timeout(self, update_sink, event_id)
142    }
143
144    fn get_auth_cfg(&self) -> &auth::Config {
145        &self.auth_cfg
146    }
147
148    fn get_auth_method(&self) -> auth::MethodName {
149        self.auth_cfg.method_name()
150    }
151}