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::{Error, NegotiatedProtection, auth};
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    #[allow(clippy::result_large_err)] // TODO(https://fxbug.dev/401255153)
72    fn initiate_owe(&mut self, update_sink: &mut UpdateSink) -> Result<(), Error>;
73    #[allow(clippy::result_large_err)] // TODO(https://fxbug.dev/401255153)
74    fn on_owe_public_key_rx(
75        &mut self,
76        update_sink: &mut UpdateSink,
77        group: u16,
78        public_key: Vec<u8>,
79    ) -> Result<(), Error>;
80    fn get_auth_cfg(&self) -> &auth::Config;
81    fn get_auth_method(&self) -> auth::MethodName;
82}
83
84impl Supplicant for wlan_rsn::Supplicant {
85    fn start(&mut self, update_sink: &mut UpdateSink) -> Result<(), Error> {
86        wlan_rsn::Supplicant::start(self, update_sink)
87    }
88
89    fn reset(&mut self) {
90        wlan_rsn::Supplicant::reset(self)
91    }
92
93    fn on_eapol_frame(
94        &mut self,
95        update_sink: &mut UpdateSink,
96        frame: eapol::Frame<&[u8]>,
97    ) -> Result<(), Error> {
98        wlan_rsn::Supplicant::on_eapol_frame(self, update_sink, frame)
99    }
100
101    fn on_eapol_conf(
102        &mut self,
103        update_sink: &mut UpdateSink,
104        result: EapolResultCode,
105    ) -> Result<(), Error> {
106        wlan_rsn::Supplicant::on_eapol_conf(self, update_sink, result)
107    }
108
109    fn on_rsna_retransmission_timeout(
110        &mut self,
111        update_sink: &mut UpdateSink,
112    ) -> Result<(), Error> {
113        wlan_rsn::Supplicant::on_rsna_retransmission_timeout(self, update_sink)
114    }
115
116    fn on_rsna_response_timeout(&self) -> EstablishRsnaFailureReason {
117        EstablishRsnaFailureReason::RsnaResponseTimeout(wlan_rsn::Supplicant::incomplete_reason(
118            self,
119        ))
120    }
121
122    fn on_rsna_completion_timeout(&self) -> EstablishRsnaFailureReason {
123        EstablishRsnaFailureReason::RsnaCompletionTimeout(wlan_rsn::Supplicant::incomplete_reason(
124            self,
125        ))
126    }
127
128    fn on_pmk_available(
129        &mut self,
130        update_sink: &mut UpdateSink,
131        pmk: &[u8],
132        pmkid: &[u8],
133    ) -> Result<(), Error> {
134        wlan_rsn::Supplicant::on_pmk_available(self, update_sink, pmk, pmkid)
135    }
136
137    fn on_sae_handshake_ind(&mut self, update_sink: &mut UpdateSink) -> Result<(), Error> {
138        wlan_rsn::Supplicant::on_sae_handshake_ind(self, update_sink)
139    }
140
141    fn on_sae_frame_rx(
142        &mut self,
143        update_sink: &mut UpdateSink,
144        frame: SaeFrame,
145    ) -> Result<(), Error> {
146        wlan_rsn::Supplicant::on_sae_frame_rx(self, update_sink, frame)
147    }
148
149    fn on_sae_timeout(&mut self, update_sink: &mut UpdateSink, event_id: u64) -> Result<(), Error> {
150        wlan_rsn::Supplicant::on_sae_timeout(self, update_sink, event_id)
151    }
152
153    fn initiate_owe(&mut self, update_sink: &mut UpdateSink) -> Result<(), Error> {
154        wlan_rsn::Supplicant::initiate_owe(self, update_sink)
155    }
156
157    fn on_owe_public_key_rx(
158        &mut self,
159        update_sink: &mut UpdateSink,
160        group: u16,
161        public_key: Vec<u8>,
162    ) -> Result<(), Error> {
163        wlan_rsn::Supplicant::on_owe_public_key_rx(self, update_sink, group, public_key)
164    }
165
166    fn get_auth_cfg(&self) -> &auth::Config {
167        &self.auth_cfg
168    }
169
170    fn get_auth_method(&self) -> auth::MethodName {
171        self.auth_cfg.method_name()
172    }
173}