1#   Copyright 2019 - The Android Open Source Project
2#
3#   Licensed under the Apache License, Version 2.0 (the "License");
4#   you may not use this file except in compliance with the License.
5#   You may obtain a copy of the License at
6#
7#       http://www.apache.org/licenses/LICENSE-2.0
8#
9#   Unless required by applicable law or agreed to in writing, software
10#   distributed under the License is distributed on an "AS IS" BASIS,
11#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12#   See the License for the specific language governing permissions and
13#   limitations under the License.
14
15from acts import utils
16
17from acts.controllers.ap_lib import hostapd_config
18from acts.controllers.ap_lib import hostapd_constants
19from acts.controllers.ap_lib import hostapd_utils
20
21
22def netgear_r7000(iface_wlan_2g=None,
23                  iface_wlan_5g=None,
24                  channel=None,
25                  security=None,
26                  ssid=None):
27    # TODO(b/143104825): Permit RIFS once it is supported
28    # TODO(b/144446076): Address non-whirlwind hardware capabilities.
29    """A simulated implementation of what a Netgear R7000 AP
30    Args:
31        iface_wlan_2g: The 2.4Ghz interface of the test AP.
32        iface_wlan_5g: The 5GHz interface of the test AP.
33        channel: What channel to use.
34        security: A security profile (None or WPA2).
35        ssid: The network name.
36    Returns:
37        A hostapd config.
38    Differences from real R7000:
39        2.4GHz:
40            Rates:
41                R7000:
42                    Supported: 1, 2, 5.5, 11, 18, 24, 36, 54
43                    Extended: 6, 9, 12, 48
44                Simulated:
45                    Supported: 1, 2, 5.5, 11, 6, 9, 12, 18
46                    Extended: 24, 36, 48,
47        5GHz:
48            VHT Capab:
49                R7000:
50                    SU Beamformer Supported,
51                    SU Beamformee Supported,
52                    Beamformee STS Capability: 3,
53                    Number of Sounding Dimensions: 3,
54                    VHT Link Adaptation: Both
55                Simulated:
56                    Above are not supported on Whirlwind.
57            VHT Operation Info:
58                R7000: Basic MCS Map (0x0000)
59                Simulated: Basic MCS Map (0xfffc)
60            VHT Tx Power Envelope:
61                R7000: Local Max Tx Pwr Constraint: 1.0 dBm
62                Simulated: Local Max Tx Pwr Constraint: 23.0 dBm
63        Both:
64            HT Capab:
65                A-MPDU
66                    R7000: MPDU Density 4
67                    Simulated: MPDU Density 8
68            HT Info:
69                R7000: RIFS Permitted
70                Simulated: RIFS Prohibited
71            RM Capabilities:
72                R7000:
73                    Beacon Table Measurement: Not Supported
74                    Statistic Measurement: Enabled
75                    AP Channel Report Capability: Enabled
76                Simulated:
77                    Beacon Table Measurement: Supported
78                    Statistic Measurement: Disabled
79                    AP Channel Report Capability: Disabled
80    """
81    # Verify interface and security
82    hostapd_utils.verify_interface(iface_wlan_2g,
83                                   hostapd_constants.INTERFACE_2G_LIST)
84    hostapd_utils.verify_interface(iface_wlan_5g,
85                                   hostapd_constants.INTERFACE_5G_LIST)
86    hostapd_utils.verify_security_mode(security,
87                                       [None, hostapd_constants.WPA2])
88    if security:
89        hostapd_utils.verify_cipher(security,
90                                    [hostapd_constants.WPA2_DEFAULT_CIPER])
91
92    # Common Parameters
93    rates = hostapd_constants.CCK_AND_OFDM_DATA_RATES
94    vht_channel_width = 80
95    n_capabilities = [
96        hostapd_constants.N_CAPABILITY_LDPC,
97        hostapd_constants.N_CAPABILITY_TX_STBC,
98        hostapd_constants.N_CAPABILITY_RX_STBC1,
99        hostapd_constants.N_CAPABILITY_MAX_AMSDU_7935,
100        hostapd_constants.N_CAPABILITY_SGI20,
101    ]
102    # Netgear IE
103    # WPS IE
104    # Epigram, Inc. IE
105    # Broadcom IE
106    vendor_elements = {
107        'vendor_elements':
108        'dd0600146c000000'
109        'dd310050f204104a00011010440001021047001066189606f1e967f9c0102048817a7'
110        '69e103c0001031049000600372a000120'
111        'dd1e00904c0408bf0cb259820feaff0000eaff0000c0050001000000c3020002'
112        'dd090010180200001c0000'
113    }
114    qbss = {'bss_load_update_period': 50, 'chan_util_avg_period': 600}
115
116    # 2.4GHz
117    if channel <= 11:
118        interface = iface_wlan_2g
119        rates.update(hostapd_constants.CCK_AND_OFDM_BASIC_RATES)
120        mode = hostapd_constants.MODE_11N_MIXED
121        obss_interval = 300
122        ac_capabilities = None
123
124    # 5GHz
125    else:
126        interface = iface_wlan_5g
127        rates.update(hostapd_constants.OFDM_ONLY_BASIC_RATES)
128        mode = hostapd_constants.MODE_11AC_MIXED
129        n_capabilities += [
130            hostapd_constants.N_CAPABILITY_SGI40,
131        ]
132
133        if hostapd_config.ht40_plus_allowed(channel):
134            n_capabilities.append(hostapd_constants.N_CAPABILITY_HT40_PLUS)
135        elif hostapd_config.ht40_minus_allowed(channel):
136            n_capabilities.append(hostapd_constants.N_CAPABILITY_HT40_MINUS)
137
138        obss_interval = None
139        ac_capabilities = [
140            hostapd_constants.AC_CAPABILITY_RXLDPC,
141            hostapd_constants.AC_CAPABILITY_SHORT_GI_80,
142            hostapd_constants.AC_CAPABILITY_TX_STBC_2BY1,
143            hostapd_constants.AC_CAPABILITY_RX_STBC_1,
144            hostapd_constants.AC_CAPABILITY_MAX_MPDU_11454,
145            hostapd_constants.AC_CAPABILITY_MAX_A_MPDU_LEN_EXP7
146        ]
147
148    additional_params = utils.merge_dicts(
149        rates, vendor_elements, qbss,
150        hostapd_constants.ENABLE_RRM_BEACON_REPORT,
151        hostapd_constants.ENABLE_RRM_NEIGHBOR_REPORT,
152        hostapd_constants.UAPSD_ENABLED)
153
154    config = hostapd_config.HostapdConfig(
155        ssid=ssid,
156        channel=channel,
157        hidden=False,
158        security=security,
159        interface=interface,
160        mode=mode,
161        force_wmm=True,
162        beacon_interval=100,
163        dtim_period=2,
164        short_preamble=False,
165        obss_interval=obss_interval,
166        n_capabilities=n_capabilities,
167        ac_capabilities=ac_capabilities,
168        vht_channel_width=vht_channel_width,
169        additional_parameters=additional_params)
170    return config
171
172
173def netgear_wndr3400(iface_wlan_2g=None,
174                     iface_wlan_5g=None,
175                     channel=None,
176                     security=None,
177                     ssid=None):
178    # TODO(b/143104825): Permit RIFS on 5GHz once it is supported
179    # TODO(b/144446076): Address non-whirlwind hardware capabilities.
180    """A simulated implementation of what a Netgear WNDR3400 AP
181    Args:
182        iface_wlan_2g: The 2.4Ghz interface of the test AP.
183        iface_wlan_5g: The 5GHz interface of the test AP.
184        channel: What channel to use.
185        security: A security profile (None or WPA2).
186        ssid: The network name.
187    Returns:
188        A hostapd config.
189    Differences from real WNDR3400:
190        2.4GHz:
191            Rates:
192                WNDR3400:
193                    Supported: 1, 2, 5.5, 11, 18, 24, 36, 54
194                    Extended: 6, 9, 12, 48
195                Simulated:
196                    Supported: 1, 2, 5.5, 11, 6, 9, 12, 18
197                    Extended: 24, 36, 48,
198        5GHz:
199            HT Info:
200                WNDR3400: RIFS Permitted
201                Simulated: RIFS Prohibited
202        Both:
203            HT Capab:
204                A-MPDU
205                    WNDR3400: MPDU Density 16
206                    Simulated: MPDU Density 8
207                Info
208                    WNDR3400: Green Field supported
209                    Simulated: Green Field not supported on Whirlwind.
210    """
211    # Verify interface and security
212    hostapd_utils.verify_interface(iface_wlan_2g,
213                                   hostapd_constants.INTERFACE_2G_LIST)
214    hostapd_utils.verify_interface(iface_wlan_5g,
215                                   hostapd_constants.INTERFACE_5G_LIST)
216    hostapd_utils.verify_security_mode(security,
217                                       [None, hostapd_constants.WPA2])
218    if security:
219        hostapd_utils.verify_cipher(security,
220                                    [hostapd_constants.WPA2_DEFAULT_CIPER])
221
222    # Common Parameters
223    rates = hostapd_constants.CCK_AND_OFDM_DATA_RATES
224    n_capabilities = [
225        hostapd_constants.N_CAPABILITY_SGI20,
226        hostapd_constants.N_CAPABILITY_SGI40,
227        hostapd_constants.N_CAPABILITY_TX_STBC,
228        hostapd_constants.N_CAPABILITY_MAX_AMSDU_7935,
229        hostapd_constants.N_CAPABILITY_DSSS_CCK_40
230    ]
231    # WPS IE
232    # Broadcom IE
233    vendor_elements = {
234        'vendor_elements':
235        'dd310050f204104a0001101044000102104700108c403eb883e7e225ab139828703ade'
236        'dc103c0001031049000600372a000120'
237        'dd090010180200f0040000'
238    }
239
240    # 2.4GHz
241    if channel <= 11:
242        interface = iface_wlan_2g
243        rates.update(hostapd_constants.CCK_AND_OFDM_BASIC_RATES)
244        obss_interval = 300
245        n_capabilities.append(hostapd_constants.N_CAPABILITY_DSSS_CCK_40)
246
247    # 5GHz
248    else:
249        interface = iface_wlan_5g
250        rates.update(hostapd_constants.OFDM_ONLY_BASIC_RATES)
251        obss_interval = None
252        n_capabilities.append(hostapd_constants.N_CAPABILITY_HT40_PLUS)
253
254    additional_params = utils.merge_dicts(rates, vendor_elements,
255                                          hostapd_constants.UAPSD_ENABLED)
256
257    config = hostapd_config.HostapdConfig(
258        ssid=ssid,
259        channel=channel,
260        hidden=False,
261        security=security,
262        interface=interface,
263        mode=hostapd_constants.MODE_11N_MIXED,
264        force_wmm=True,
265        beacon_interval=100,
266        dtim_period=2,
267        short_preamble=False,
268        obss_interval=obss_interval,
269        n_capabilities=n_capabilities,
270        additional_parameters=additional_params)
271
272    return config