1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright 2024 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use fidl_fuchsia_wlan_fullmac::{self as fidl_fullmac, WlanFullmacImpl_Request};
use futures::StreamExt;

// Wrapper type for WlanFullmacImpl_Request types without the responder.
#[derive(Clone, Debug, PartialEq)]
pub enum FullmacRequest {
    Stop,
    Query,
    QueryMacSublayerSupport,
    QuerySecuritySupport,
    StartScan(fidl_fullmac::WlanFullmacImplStartScanRequest),
    Connect(fidl_fullmac::WlanFullmacImplConnectRequest),
    Reconnect(fidl_fullmac::WlanFullmacImplReconnectRequest),
    AuthResp(fidl_fullmac::WlanFullmacImplAuthRespRequest),
    Deauth(fidl_fullmac::WlanFullmacImplDeauthRequest),
    AssocResp(fidl_fullmac::WlanFullmacImplAssocRespRequest),
    Disassoc(fidl_fullmac::WlanFullmacImplDisassocRequest),
    Reset(fidl_fullmac::WlanFullmacImplResetRequest),
    StartBss(fidl_fullmac::WlanFullmacImplStartBssRequest),
    StopBss(fidl_fullmac::WlanFullmacImplStopBssRequest),
    SetKeys(fidl_fullmac::WlanFullmacImplSetKeysRequest),
    DelKeys(fidl_fullmac::WlanFullmacImplDelKeysRequest),
    EapolTx(fidl_fullmac::WlanFullmacImplEapolTxRequest),
    GetIfaceCounterStats,
    GetIfaceHistogramStats,
    SaeHandshakeResp(fidl_fullmac::WlanFullmacSaeHandshakeResp),
    SaeFrameTx(fidl_fullmac::WlanFullmacSaeFrame),
    WmmStatusReq,
    SetMulticastPromisc(bool),
    OnLinkStateChanged(bool),

    // Note: WlanFullmacImpl::Start has a channel as an argument, but we don't keep the channel
    // here.
    Start,
}

/// A wrapper around WlanFullmacImpl_RequestStream that records each handled request in its
/// |history|. Users of this type should not access |request_stream| directly; instead, use
/// RecordedRequestStream::handle_request.
pub struct RecordedRequestStream {
    request_stream: fidl_fullmac::WlanFullmacImpl_RequestStream,
    history: Vec<FullmacRequest>,
}

impl RecordedRequestStream {
    pub fn new(request_stream: fidl_fullmac::WlanFullmacImpl_RequestStream) -> Self {
        Self { request_stream, history: Vec::new() }
    }

    pub fn history(&self) -> &[FullmacRequest] {
        &self.history[..]
    }

    pub fn clear_history(&mut self) {
        self.history.clear();
    }

    /// Retrieves a single request from the request stream.
    /// This records the request type in its history (copying the request payload out if one
    /// exists) before returning it.
    pub async fn next(&mut self) -> fidl_fullmac::WlanFullmacImpl_Request {
        let request = self
            .request_stream
            .next()
            .await
            .unwrap()
            .expect("Could not get next request in fullmac request stream");
        match &request {
            WlanFullmacImpl_Request::Stop { .. } => self.history.push(FullmacRequest::Stop),
            WlanFullmacImpl_Request::Query { .. } => self.history.push(FullmacRequest::Query),
            WlanFullmacImpl_Request::QueryMacSublayerSupport { .. } => {
                self.history.push(FullmacRequest::QueryMacSublayerSupport)
            }
            WlanFullmacImpl_Request::QuerySecuritySupport { .. } => {
                self.history.push(FullmacRequest::QuerySecuritySupport)
            }
            WlanFullmacImpl_Request::StartScan { payload, .. } => {
                self.history.push(FullmacRequest::StartScan(payload.clone()))
            }
            WlanFullmacImpl_Request::Connect { payload, .. } => {
                self.history.push(FullmacRequest::Connect(payload.clone()))
            }
            WlanFullmacImpl_Request::Reconnect { payload, .. } => {
                self.history.push(FullmacRequest::Reconnect(payload.clone()))
            }
            WlanFullmacImpl_Request::AuthResp { payload, .. } => {
                self.history.push(FullmacRequest::AuthResp(payload.clone()))
            }
            WlanFullmacImpl_Request::Deauth { payload, .. } => {
                self.history.push(FullmacRequest::Deauth(payload.clone()))
            }
            WlanFullmacImpl_Request::AssocResp { payload, .. } => {
                self.history.push(FullmacRequest::AssocResp(payload.clone()))
            }
            WlanFullmacImpl_Request::Disassoc { payload, .. } => {
                self.history.push(FullmacRequest::Disassoc(payload.clone()))
            }
            WlanFullmacImpl_Request::Reset { payload, .. } => {
                self.history.push(FullmacRequest::Reset(payload.clone()))
            }
            WlanFullmacImpl_Request::StartBss { payload, .. } => {
                self.history.push(FullmacRequest::StartBss(payload.clone()))
            }
            WlanFullmacImpl_Request::StopBss { payload, .. } => {
                self.history.push(FullmacRequest::StopBss(payload.clone()))
            }
            WlanFullmacImpl_Request::SetKeys { payload, .. } => {
                self.history.push(FullmacRequest::SetKeys(payload.clone()))
            }
            WlanFullmacImpl_Request::DelKeys { payload, .. } => {
                self.history.push(FullmacRequest::DelKeys(payload.clone()))
            }
            WlanFullmacImpl_Request::EapolTx { payload, .. } => {
                self.history.push(FullmacRequest::EapolTx(payload.clone()))
            }
            WlanFullmacImpl_Request::GetIfaceCounterStats { .. } => {
                self.history.push(FullmacRequest::GetIfaceCounterStats)
            }
            WlanFullmacImpl_Request::GetIfaceHistogramStats { .. } => {
                self.history.push(FullmacRequest::GetIfaceHistogramStats)
            }
            WlanFullmacImpl_Request::SaeHandshakeResp { resp, .. } => {
                self.history.push(FullmacRequest::SaeHandshakeResp(resp.clone()))
            }
            WlanFullmacImpl_Request::SaeFrameTx { frame, .. } => {
                self.history.push(FullmacRequest::SaeFrameTx(frame.clone()))
            }
            WlanFullmacImpl_Request::WmmStatusReq { .. } => {
                self.history.push(FullmacRequest::WmmStatusReq)
            }
            WlanFullmacImpl_Request::SetMulticastPromisc { enable, .. } => {
                self.history.push(FullmacRequest::SetMulticastPromisc(*enable))
            }
            WlanFullmacImpl_Request::OnLinkStateChanged { online, .. } => {
                self.history.push(FullmacRequest::OnLinkStateChanged(*online))
            }
            WlanFullmacImpl_Request::Start { .. } => self.history.push(FullmacRequest::Start),

            _ => panic!("Unrecognized Fullmac request {:?}", request),
        }
        request
    }
}