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 securifi_almond(iface_wlan_2g=None, channel=None, security=None,
23                    ssid=None):
24    """A simulated implementation of a Securifi Almond AP
25    Args:
26        iface_wlan_2g: The 2.4Ghz interface of the test AP.
27        channel: What channel to use.
28        security: A security profile (None or WPA2).
29        ssid: The network name.
30    Returns:
31        A hostapd config.
32    Differences from real Almond:
33            Rates:
34                Almond:
35                    Supported: 1, 2, 5.5, 11, 18, 24, 36, 54
36                    Extended: 6, 9, 12, 48
37                Simulated:
38                    Supported: 1, 2, 5.5, 11, 6, 9, 12, 18
39                    Extended: 24, 36, 48, 54
40            HT Capab:
41                A-MPDU
42                    Almond: MPDU Density 4
43                    Simulated: MPDU Density 8
44            RSN Capab (w/ WPA2):
45                Almond:
46                    RSN PTKSA Replay Counter Capab: 1
47                Simulated:
48                    RSN PTKSA Replay Counter Capab: 16
49    """
50    if channel > 11:
51        raise ValueError('The Securifi Almond does not support 5Ghz. '
52                         'Invalid channel (%s)' % channel)
53    # Verify interface and security
54    hostapd_utils.verify_interface(iface_wlan_2g,
55                                   hostapd_constants.INTERFACE_2G_LIST)
56    hostapd_utils.verify_security_mode(security,
57                                       [None, hostapd_constants.WPA2])
58    if security:
59        hostapd_utils.verify_cipher(security,
60                                    [hostapd_constants.WPA2_DEFAULT_CIPER])
61
62    n_capabilities = [
63        hostapd_constants.N_CAPABILITY_HT40_PLUS,
64        hostapd_constants.N_CAPABILITY_SGI20,
65        hostapd_constants.N_CAPABILITY_SGI40,
66        hostapd_constants.N_CAPABILITY_TX_STBC,
67        hostapd_constants.N_CAPABILITY_RX_STBC1,
68        hostapd_constants.N_CAPABILITY_DSSS_CCK_40
69    ]
70
71    rates = utils.merge_dicts(hostapd_constants.CCK_AND_OFDM_BASIC_RATES,
72                              hostapd_constants.CCK_AND_OFDM_DATA_RATES)
73
74    # Ralink Technology IE
75    # Country Information IE
76    # AP Channel Report IEs
77    vendor_elements = {
78        'vendor_elements':
79        'dd07000c4307000000'
80        '0706555320010b14'
81        '33082001020304050607'
82        '33082105060708090a0b'
83    }
84
85    qbss = {'bss_load_update_period': 50, 'chan_util_avg_period': 600}
86
87    additional_params = utils.merge_dicts(rates, vendor_elements, qbss)
88
89    config = hostapd_config.HostapdConfig(
90        ssid=ssid,
91        channel=channel,
92        hidden=False,
93        security=security,
94        interface=iface_wlan_2g,
95        mode=hostapd_constants.MODE_11N_MIXED,
96        force_wmm=True,
97        beacon_interval=100,
98        dtim_period=1,
99        short_preamble=True,
100        obss_interval=300,
101        n_capabilities=n_capabilities,
102        additional_parameters=additional_params)
103
104    return config