• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#   Copyright 2017 - 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.controllers.ap_lib import hostapd_config
16from acts.controllers.ap_lib import hostapd_constants
17
18def create_ap_preset(profile_name='whirlwind',
19                     iface_wlan_2g=None,
20                     iface_wlan_5g=None,
21                     channel=None,
22                     dtim=2,
23                     frequency=None,
24                     security=None,
25                     ssid=None,
26                     hidden=False,
27                     vht_bandwidth=80,
28                     bss_settings=[]):
29    """AP preset config generator.  This a wrapper for hostapd_config but
30       but supplies the default settings for the preset that is selected.
31
32        You may specify channel or frequency, but not both.  Both options
33        are checked for validity (i.e. you can't specify an invalid channel
34        or a frequency that will not be accepted).
35
36    Args:
37        profile_name: The name of the device want the preset for.
38                      Options: whirlwind
39        channel: int, channel number.
40        dtim: int, DTIM value of the AP, default is 2.
41        frequency: int, frequency of channel.
42        security: Security, the secuirty settings to use.
43        ssid: string, The name of the ssid to brodcast.
44        vht_bandwidth: VHT bandwidth for 11ac operation.
45        bss_settings: The settings for all bss.
46        iface_wlan_2g: the wlan 2g interface name of the AP.
47        iface_wlan_5g: the wlan 5g interface name of the AP.
48
49    Returns: A hostapd_config object that can be used by the hostapd object.
50    """
51
52    if not iface_wlan_2g or not iface_wlan_5g:
53        raise ValueError('WLAN interface for 2G and/or 5G is missing.')
54
55    # The Onhub uses wlan0, wlan1 as the WAN interfaces, while the Gale uses
56    # wlan-2400mhz, wlan-5000mhz.
57    if iface_wlan_2g not in hostapd_constants.INTERFACE_2G_LIST or \
58       iface_wlan_5g not in hostapd_constants.INTERFACE_5G_LIST:
59        raise ValueError('Incorrect interface name was passed.')
60
61    force_wmm = None
62    force_wmm = None
63    beacon_interval = None
64    dtim_period = None
65    short_preamble = None
66    interface = None
67    mode = None
68    n_capabilities = None
69    ac_capabilities = None
70    if channel:
71        frequency = hostapd_config.get_frequency_for_channel(channel)
72    elif frequency:
73        channel = hostapd_config.get_channel_for_frequency(frequency)
74    else:
75        raise ValueError('Specify either frequency or channel.')
76
77    if (profile_name == 'whirlwind'):
78        force_wmm = True
79        beacon_interval = 100
80        short_preamble = True
81        if frequency < 5000:
82            interface = iface_wlan_2g
83            mode = hostapd_constants.MODE_11N_MIXED
84            n_capabilities = [
85                hostapd_constants.N_CAPABILITY_LDPC,
86                hostapd_constants.N_CAPABILITY_SGI20,
87                hostapd_constants.N_CAPABILITY_SGI40,
88                hostapd_constants.N_CAPABILITY_TX_STBC,
89                hostapd_constants.N_CAPABILITY_RX_STBC1,
90                hostapd_constants.N_CAPABILITY_DSSS_CCK_40
91            ]
92            config = hostapd_config.HostapdConfig(
93                ssid=ssid,
94                hidden=hidden,
95                security=security,
96                interface=interface,
97                mode=mode,
98                force_wmm=force_wmm,
99                beacon_interval=beacon_interval,
100                dtim_period=dtim_period,
101                short_preamble=short_preamble,
102                frequency=frequency,
103                n_capabilities=n_capabilities,
104                bss_settings=bss_settings)
105        else:
106            interface = iface_wlan_5g
107            mode = hostapd_constants.MODE_11AC_MIXED
108            if hostapd_config.ht40_plus_allowed(channel):
109                extended_channel = hostapd_constants.N_CAPABILITY_HT40_PLUS
110            elif hostapd_config.ht40_minus_allowed(channel):
111                extended_channel = hostapd_constants.N_CAPABILITY_HT40_MINUS
112            # Channel 165 operates in 20MHz with n or ac modes.
113            if channel == 165:
114                mode = hostapd_constants.MODE_11N_MIXED
115                extended_channel = hostapd_constants.N_CAPABILITY_HT20
116            # Define the n capability vector for 20 MHz and higher bandwidth
117            if vht_bandwidth >= 40:
118                n_capabilities = [
119                    hostapd_constants.N_CAPABILITY_LDPC, extended_channel,
120                    hostapd_constants.N_CAPABILITY_SGI20,
121                    hostapd_constants.N_CAPABILITY_SGI40,
122                    hostapd_constants.N_CAPABILITY_TX_STBC,
123                    hostapd_constants.N_CAPABILITY_RX_STBC1
124                ]
125            else:
126                n_capabilities = [
127                    hostapd_constants.N_CAPABILITY_LDPC,
128                    hostapd_constants.N_CAPABILITY_SGI20,
129                    hostapd_constants.N_CAPABILITY_SGI40,
130                    hostapd_constants.N_CAPABILITY_TX_STBC,
131                    hostapd_constants.N_CAPABILITY_RX_STBC1,
132                    hostapd_constants.N_CAPABILITY_HT20
133                ]
134            ac_capabilities = [
135                hostapd_constants.AC_CAPABILITY_MAX_MPDU_11454,
136                hostapd_constants.AC_CAPABILITY_RXLDPC,
137                hostapd_constants.AC_CAPABILITY_SHORT_GI_80,
138                hostapd_constants.AC_CAPABILITY_TX_STBC_2BY1,
139                hostapd_constants.AC_CAPABILITY_RX_STBC_1,
140                hostapd_constants.AC_CAPABILITY_MAX_A_MPDU_LEN_EXP7,
141                hostapd_constants.AC_CAPABILITY_RX_ANTENNA_PATTERN,
142                hostapd_constants.AC_CAPABILITY_TX_ANTENNA_PATTERN
143            ]
144            config = hostapd_config.HostapdConfig(
145                ssid=ssid,
146                hidden=hidden,
147                security=security,
148                interface=interface,
149                mode=mode,
150                force_wmm=force_wmm,
151                vht_channel_width=vht_bandwidth,
152                beacon_interval=beacon_interval,
153                dtim_period=dtim_period,
154                short_preamble=short_preamble,
155                frequency=frequency,
156                n_capabilities=n_capabilities,
157                ac_capabilities=ac_capabilities,
158                bss_settings=bss_settings)
159    else:
160        raise ValueError('Invalid ap model specified (%s)' % profile_name)
161    return config
162