]> git.ipfire.org Git - thirdparty/hostap.git/blame - tests/hwsim/test_p2p_channel.py
tests: Add option for running test cases that take a long time
[thirdparty/hostap.git] / tests / hwsim / test_p2p_channel.py
CommitLineData
14776657
JM
1# P2P channel selection test cases
2# Copyright (c) 2014, Jouni Malinen <j@w1.fi>
3#
4# This software may be distributed under the terms of the BSD license.
5# See README for more details.
6
7import logging
8logger = logging.getLogger()
9import os
10import subprocess
11import time
12
13from test_p2p_grpform import go_neg_pin_authorized
14from test_p2p_grpform import check_grpform_results
15from test_p2p_grpform import remove_group
16
17def set_country(country):
18 subprocess.call(['sudo', 'iw', 'reg', 'set', country])
19 time.sleep(0.1)
20
21def test_p2p_channel_5ghz(dev):
22 """P2P group formation with 5 GHz preference"""
23 try:
24 set_country("US")
25 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
26 r_dev=dev[1], r_intent=0,
27 test_data=False)
28 check_grpform_results(i_res, r_res)
29 freq = int(i_res['freq'])
30 if freq < 5000:
31 raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
32 remove_group(dev[0], dev[1])
33 finally:
34 set_country("00")
35
36def test_p2p_channel_5ghz_no_vht(dev):
37 """P2P group formation with 5 GHz preference when VHT channels are disallowed"""
38 try:
39 set_country("US")
40 dev[0].request("P2P_SET disallow_freq 5180-5240")
41 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
42 r_dev=dev[1], r_intent=0,
43 test_data=False)
44 check_grpform_results(i_res, r_res)
45 freq = int(i_res['freq'])
46 if freq < 5000:
47 raise Exception("Unexpected channel %d MHz - did not follow 5 GHz preference" % freq)
48 remove_group(dev[0], dev[1])
49 finally:
50 set_country("00")
51 dev[0].request("P2P_SET disallow_freq ")
52
53def test_p2p_channel_random_social(dev):
54 """P2P group formation with 5 GHz preference but all 5 GHz channels disabled"""
55 try:
56 set_country("US")
57 dev[0].request("SET p2p_oper_channel 11")
58 dev[0].request("P2P_SET disallow_freq 5000-6000,2462")
59 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
60 r_dev=dev[1], r_intent=0,
61 test_data=False)
62 check_grpform_results(i_res, r_res)
63 freq = int(i_res['freq'])
64 if freq not in [ 2412, 2437, 2462 ]:
65 raise Exception("Unexpected channel %d MHz - did not pick random social channel" % freq)
66 remove_group(dev[0], dev[1])
67 finally:
68 set_country("00")
69 dev[0].request("P2P_SET disallow_freq ")
70
71def test_p2p_channel_random(dev):
72 """P2P group formation with 5 GHz preference but all 5 GHz channels and all social channels disabled"""
73 try:
74 set_country("US")
75 dev[0].request("SET p2p_oper_channel 11")
76 dev[0].request("P2P_SET disallow_freq 5000-6000,2412,2437,2462")
77 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
78 r_dev=dev[1], r_intent=0,
79 test_data=False)
80 check_grpform_results(i_res, r_res)
81 freq = int(i_res['freq'])
82 if freq > 2500 or freq in [ 2412, 2437, 2462 ]:
83 raise Exception("Unexpected channel %d MHz" % freq)
84 remove_group(dev[0], dev[1])
85 finally:
86 set_country("00")
87 dev[0].request("P2P_SET disallow_freq ")
88
89def test_p2p_channel_random_social_with_op_class_change(dev, apdev, params):
90 """P2P group formation using random social channel with oper class change needed"""
91 try:
92 set_country("US")
93 logger.info("Start group on 5 GHz")
94 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
95 r_dev=dev[1], r_intent=0,
96 test_data=False)
97 check_grpform_results(i_res, r_res)
98 freq = int(i_res['freq'])
99 if freq < 5000:
100 raise Exception("Unexpected channel %d MHz - did not pick 5 GHz preference" % freq)
101 remove_group(dev[0], dev[1])
102
103 logger.info("Disable 5 GHz and try to re-start group based on 5 GHz preference")
104 dev[0].request("SET p2p_oper_reg_class 115")
105 dev[0].request("SET p2p_oper_channel 36")
106 dev[0].request("P2P_SET disallow_freq 5000-6000")
107 [i_res, r_res] = go_neg_pin_authorized(i_dev=dev[0], i_intent=15,
108 r_dev=dev[1], r_intent=0,
109 test_data=False)
110 check_grpform_results(i_res, r_res)
111 freq = int(i_res['freq'])
112 if freq not in [ 2412, 2437, 2462 ]:
113 raise Exception("Unexpected channel %d MHz - did not pick random social channel" % freq)
114 remove_group(dev[0], dev[1])
115
116 try:
117 arg = [ "tshark",
118 "-r", os.path.join(params['logdir'], "hwsim0.pcapng"),
119 "-R", "wifi_p2p.public_action.subtype == 0",
120 "-V" ]
121 cmd = subprocess.Popen(arg, stdout=subprocess.PIPE,
122 stderr=open('/dev/null', 'w'))
123 except Exception, e:
124 logger.info("Could run run tshark check: " + str(e))
125 cmd = None
126 pass
127
128 if cmd:
129 last = None
130 for l in cmd.stdout.read().splitlines():
131 if "Operating Channel:" not in l:
132 continue
133 last = l
134 if last is None:
135 raise Exception("Could not find GO Negotiation Request")
136 if "Operating Class 81" not in last:
137 raise Exception("Unexpected operating class: " + last.strip())
138 finally:
139 set_country("00")
140 dev[0].request("P2P_SET disallow_freq ")
141 dev[0].request("SET p2p_oper_reg_class 81")
142 dev[0].request("SET p2p_oper_channel 11")