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 belkin_f9k1001v5(iface_wlan_2g=None,
23                     channel=None,
24                     security=None,
25                     ssid=None):
26    # TODO(b/143104825): Permit RIFS once it is supported
27    """A simulated implementation of what a Belkin F9K1001v5 AP
28    Args:
29        iface_wlan_2g: The 2.4Ghz interface of the test AP.
30        channel: What channel to use.
31        security: A security profile (None or WPA2).
32        ssid: The network name.
33    Returns:
34        A hostapd config.
35    Differences from real F9K1001v5:
36        Rates:
37            F9K1001v5:
38                Supported: 1, 2, 5.5, 11, 18, 24, 36, 54
39                Extended: 6, 9, 12, 48
40            Simulated:
41                Supported: 1, 2, 5.5, 11, 6, 9, 12, 18
42                Extended: 24, 36, 48, 54
43        HT Info:
44            F9K1001v5:
45                RIFS: Permitted
46            Simulated:
47                RIFS: Prohibited
48        RSN Capabilities (w/ WPA2):
49            F9K1001v5:
50                RSN PTKSA Replay Counter Capab: 1
51            Simulated:
52                RSN PTKSA Replay Counter Capab: 16
53    """
54    if channel > 11:
55        raise ValueError('The Belkin F9k1001v5 does not support 5Ghz. '
56                         'Invalid channel (%s)' % channel)
57    # Verify interface and security
58    hostapd_utils.verify_interface(iface_wlan_2g,
59                                   hostapd_constants.INTERFACE_2G_LIST)
60    hostapd_utils.verify_security_mode(security,
61                                       [None, hostapd_constants.WPA2])
62    if security:
63        hostapd_utils.verify_cipher(security,
64                                    [hostapd_constants.WPA2_DEFAULT_CIPER])
65
66    n_capabilities = [
67        hostapd_constants.N_CAPABILITY_SGI20,
68        hostapd_constants.N_CAPABILITY_SGI40,
69        hostapd_constants.N_CAPABILITY_TX_STBC,
70        hostapd_constants.N_CAPABILITY_MAX_AMSDU_7935,
71        hostapd_constants.N_CAPABILITY_DSSS_CCK_40
72    ]
73
74    rates = additional_params = utils.merge_dicts(
75        hostapd_constants.CCK_AND_OFDM_BASIC_RATES,
76        hostapd_constants.CCK_AND_OFDM_DATA_RATES)
77
78    # Broadcom IE
79    # WPS IE
80    vendor_elements = {
81        'vendor_elements':
82        'dd090010180200100c0000'
83        'dd180050f204104a00011010440001021049000600372a000120'
84    }
85
86    additional_params = utils.merge_dicts(rates, vendor_elements)
87
88    config = hostapd_config.HostapdConfig(
89        ssid=ssid,
90        channel=channel,
91        hidden=False,
92        security=security,
93        interface=iface_wlan_2g,
94        mode=hostapd_constants.MODE_11N_MIXED,
95        force_wmm=True,
96        beacon_interval=100,
97        dtim_period=3,
98        short_preamble=False,
99        n_capabilities=n_capabilities,
100        additional_parameters=additional_params)
101
102    return config
103