blob: 26026ff193cf60c305e75a56623e159d2f01c333 [file] [log] [blame]
Avinankumar Vellore Suriyakumar60ae5e02017-05-26 17:17:57 -07001#!/usr/bin/env python3.4
2#
3# Copyright 2017 - The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import logging
18import socket
19import sys
20
21from acts import base_test
22from acts.controllers.ap_lib import hostapd_ap_preset
23from acts.controllers.ap_lib import hostapd_bss_settings
24from acts.controllers.ap_lib import hostapd_constants
25from acts.controllers.ap_lib import hostapd_config
26from acts.controllers.ap_lib import hostapd_security
27
Avinankumar Vellore Suriyakumar60ae5e02017-05-26 17:17:57 -070028
Avinankumar Vellore Suriyakumarac3ad122017-08-21 15:24:12 -070029class SetupWifiNetworkTest(base_test.BaseTestClass):
Avinankumar Vellore Suriyakumar60ae5e02017-05-26 17:17:57 -070030 def wait_for_test_completion(self):
31 port = int(self.user_params["socket_port"])
32 timeout = float(self.user_params["socket_timeout_secs"])
33
34 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
35 sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
36
37 server_address = ('localhost', port)
38 logging.info("Starting server socket on localhost port %s", port)
39 sock.bind(('localhost', port))
40 sock.settimeout(timeout)
41 sock.listen(1)
42 logging.info("Waiting for client socket connection")
Avinankumar Vellore Suriyakumarac3ad122017-08-21 15:24:12 -070043 try:
Avinankumar Vellore Suriyakumar60ae5e02017-05-26 17:17:57 -070044 connection, client_address = sock.accept()
45 except socket.timeout:
46 logging.error("Did not receive signal. Shutting down AP")
47 except socket.error:
48 logging.error("Socket connection errored out. Shutting down AP")
49 finally:
50 connection.close()
51 sock.shutdown(socket.SHUT_RDWR)
52 sock.close()
53
Avinankumar Vellore Suriyakumarac3ad122017-08-21 15:24:12 -070054 def setup_ap(self):
Avinankumar Vellore Suriyakumar60ae5e02017-05-26 17:17:57 -070055 bss_settings = []
Avinankumar Vellore Suriyakumar60ae5e02017-05-26 17:17:57 -070056 self.access_point = self.access_points[0]
57 network_type = self.user_params["network_type"]
58 if (network_type == "2G"):
59 self.channel = hostapd_constants.AP_DEFAULT_CHANNEL_2G
60 else:
61 self.channel = hostapd_constants.AP_DEFAULT_CHANNEL_5G
62
63 self.ssid = self.user_params["ssid"]
Avinankumar Vellore Suriyakumar60ae5e02017-05-26 17:17:57 -070064 self.security = self.user_params["security"]
Avinankumar Vellore Suriyakumarac3ad122017-08-21 15:24:12 -070065 if self.security == "none":
66 self.config = hostapd_ap_preset.create_ap_preset(
67 channel=self.channel,
Avinankumar Vellore Suriyakumar60ae5e02017-05-26 17:17:57 -070068 ssid=self.ssid,
Avinankumar Vellore Suriyakumarac3ad122017-08-21 15:24:12 -070069 bss_settings=bss_settings,
70 profile_name='whirlwind')
71 else:
72 self.passphrase = self.user_params["passphrase"]
73 self.hostapd_security = hostapd_security.Security(
74 security_mode=self.security, password=self.passphrase)
75 self.config = hostapd_ap_preset.create_ap_preset(
Avinankumar Vellore Suriyakumar60ae5e02017-05-26 17:17:57 -070076 channel=self.channel,
77 ssid=self.ssid,
78 security=self.hostapd_security,
Avinankumar Vellore Suriyakumarac3ad122017-08-21 15:24:12 -070079 bss_settings=bss_settings,
Avinankumar Vellore Suriyakumar60ae5e02017-05-26 17:17:57 -070080 profile_name='whirlwind')
81 self.access_point.start_ap(self.config)
Avinankumar Vellore Suriyakumarac3ad122017-08-21 15:24:12 -070082
83 def test_set_up_single_ap(self):
84 req_params = [
85 "AccessPoint", "network_type", "ssid", "passphrase", "security",
86 "socket_port", "socket_timeout_secs"
87 ]
88 opt_params = []
89 self.unpack_userparams(
90 req_param_names=req_params, opt_param_names=opt_params)
91 # Setup the AP environment
92 self.setup_ap()
93 # AP enviroment created. Wait for client to teardown the environment
94 self.wait_for_test_completion()
95
96 def test_set_up_open_ap(self):
97 req_params = [
98 "AccessPoint", "network_type", "ssid", "security", "socket_port",
99 "socket_timeout_secs"
100 ]
101 opt_params = []
102 self.unpack_userparams(
103 req_param_names=req_params, opt_param_names=opt_params)
104 # Setup the AP environment
105 self.setup_ap()
Avinankumar Vellore Suriyakumar60ae5e02017-05-26 17:17:57 -0700106 # AP enviroment created. Wait for client to teardown the environment
107 self.wait_for_test_completion()