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 actiontec_pk5000(iface_wlan_2g=None,
23                     channel=None,
24                     security=None,
25                     ssid=None):
26    """A simulated implementation of what a Actiontec PK5000 AP
27    Args:
28        iface_wlan_2g: The 2.4 interface of the test AP.
29        channel: What channel to use.  Only 2.4Ghz is supported for this profile
30        security: A security profile.  Must be none or WPA2 as this is what is
31            supported by the PK5000.
32        ssid: Network name
33    Returns:
34        A hostapd config
35
36    Differences from real pk5000:
37        Supported Rates IE:
38            PK5000: Supported: 1, 2, 5.5, 11
39                    Extended: 6, 9, 12, 18, 24, 36, 48, 54
40            Simulated: Supported: 1, 2, 5.5, 11, 6, 9, 12, 18
41                       Extended: 24, 36, 48, 54
42    """
43    if channel > 11:
44        # Technically this should be 14 but since the PK5000 is a US only AP,
45        # 11 is the highest allowable channel.
46        raise ValueError('The Actiontec PK5000 does not support 5Ghz. '
47                         'Invalid channel (%s)' % channel)
48    # Verify interface and security
49    hostapd_utils.verify_interface(iface_wlan_2g,
50                                   hostapd_constants.INTERFACE_2G_LIST)
51    hostapd_utils.verify_security_mode(security,
52                                       [None, hostapd_constants.WPA2])
53    if security:
54        hostapd_utils.verify_cipher(security,
55                                    [hostapd_constants.WPA2_DEFAULT_CIPER])
56
57    interface = iface_wlan_2g
58    short_preamble = False
59    force_wmm = False
60    beacon_interval = 100
61    dtim_period = 3
62    # Sets the basic rates and supported rates of the PK5000
63    additional_params = utils.merge_dicts(
64        hostapd_constants.CCK_AND_OFDM_BASIC_RATES,
65        hostapd_constants.CCK_AND_OFDM_DATA_RATES)
66
67    config = hostapd_config.HostapdConfig(
68        ssid=ssid,
69        channel=channel,
70        hidden=False,
71        security=security,
72        interface=interface,
73        mode=hostapd_constants.MODE_11G,
74        force_wmm=force_wmm,
75        beacon_interval=beacon_interval,
76        dtim_period=dtim_period,
77        short_preamble=short_preamble,
78        additional_parameters=additional_params)
79
80    return config
81
82
83def actiontec_mi424wr(iface_wlan_2g=None,
84                      channel=None,
85                      security=None,
86                      ssid=None):
87    # TODO(b/143104825): Permit RIFS once it is supported
88    """A simulated implementation of an Actiontec MI424WR AP.
89    Args:
90        iface_wlan_2g: The 2.4Ghz interface of the test AP.
91        channel: What channel to use (2.4Ghz or 5Ghz).
92        security: A security profile.
93        ssid: The network name.
94    Returns:
95        A hostapd config.
96
97    Differences from real MI424WR:
98        HT Capabilities:
99            MI424WR:
100                HT Rx STBC: Support for 1, 2, and 3
101            Simulated:
102                HT Rx STBC: Support for 1
103        HT Information:
104            MI424WR:
105                RIFS: Premitted
106            Simulated:
107                RIFS: Prohibited
108    """
109    if channel > 11:
110        raise ValueError('The Actiontec MI424WR does not support 5Ghz. '
111                         'Invalid channel (%s)' % channel)
112    # Verify interface and security
113    hostapd_utils.verify_interface(iface_wlan_2g,
114                                   hostapd_constants.INTERFACE_2G_LIST)
115    hostapd_utils.verify_security_mode(security,
116                                       [None, hostapd_constants.WPA2])
117    if security:
118        hostapd_utils.verify_cipher(security,
119                                    [hostapd_constants.WPA2_DEFAULT_CIPER])
120
121    n_capabilities = [
122        hostapd_constants.N_CAPABILITY_TX_STBC,
123        hostapd_constants.N_CAPABILITY_DSSS_CCK_40,
124        hostapd_constants.N_CAPABILITY_RX_STBC1
125    ]
126    rates = utils.merge_dicts(hostapd_constants.CCK_AND_OFDM_DATA_RATES,
127                              hostapd_constants.CCK_AND_OFDM_BASIC_RATES)
128    # Proprietary Atheros Communication: Adv Capability IE
129    # Proprietary Atheros Communication: Unknown IE
130    # Country Info: US Only IE
131    vendor_elements = {
132        'vendor_elements':
133        'dd0900037f01010000ff7f'
134        'dd0a00037f04010000000000'
135        '0706555320010b1b'
136    }
137
138    additional_params = utils.merge_dicts(rates, vendor_elements)
139
140    config = hostapd_config.HostapdConfig(
141        ssid=ssid,
142        channel=channel,
143        hidden=False,
144        security=security,
145        interface=iface_wlan_2g,
146        mode=hostapd_constants.MODE_11N_MIXED,
147        force_wmm=True,
148        beacon_interval=100,
149        dtim_period=1,
150        short_preamble=True,
151        n_capabilities=n_capabilities,
152        additional_parameters=additional_params)
153
154    return config
155