1 # P2P invitation test cases
2 # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
8 logger = logging.getLogger()
12 def test_p2p_go_invite(dev):
13 """P2P GO inviting a client to join"""
14 addr0 = dev[0].p2p_dev_addr()
15 addr1 = dev[1].p2p_dev_addr()
17 logger.info("Generate BSS table entry for old group")
18 # this adds more coverage to testing by forcing the GO to be found with an
19 # older entry in the BSS table and with that entry having a different
21 dev[0].p2p_start_go(freq=2422)
25 logger.info("Discover peer")
27 if not dev[0].discover_peer(addr1, social=True):
28 raise Exception("Peer " + addr1 + " not found")
30 logger.info("Start GO on non-social channel")
31 res = dev[0].p2p_start_go(freq=2417)
32 logger.debug("res: " + str(res))
34 logger.info("Invite peer to join the group")
35 dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1)
36 ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=10)
38 raise Exception("Timeout on invitation on peer")
39 ev = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=10)
41 raise Exception("Timeout on invitation on GO")
42 if "status=1" not in ev:
43 raise Exception("Unexpected invitation result")
45 logger.info("Join the group")
46 pin = dev[1].wps_read_pin()
47 dev[0].p2p_go_authorize_client(pin)
48 dev[1].p2p_connect_group(addr0, pin, timeout=60)
49 logger.info("Client connected")
50 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
52 logger.info("Terminate group")
54 dev[1].wait_go_ending_session()
56 def test_p2p_go_invite_auth(dev):
57 """P2P GO inviting a client to join (authorized invitation)"""
58 addr0 = dev[0].p2p_dev_addr()
59 addr1 = dev[1].p2p_dev_addr()
61 logger.info("Generate BSS table entry for old group")
62 # this adds more coverage to testing by forcing the GO to be found with an
63 # older entry in the BSS table and with that entry having a different
65 dev[0].p2p_start_go(freq=2432)
71 logger.info("Discover peer")
73 if not dev[0].discover_peer(addr1, social=True):
74 raise Exception("Peer " + addr1 + " not found")
76 if not dev[1].discover_peer(addr0, social=True):
77 raise Exception("Peer " + addr0 + " not found")
80 logger.info("Authorize invitation")
81 pin = dev[1].wps_read_pin()
82 dev[1].global_request("P2P_CONNECT " + addr0 + " " + pin + " join auth")
84 logger.info("Start GO on non-social channel")
85 res = dev[0].p2p_start_go(freq=2427)
86 logger.debug("res: " + str(res))
88 logger.info("Invite peer to join the group")
89 dev[0].p2p_go_authorize_client(pin)
90 dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1)
91 ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED",
92 "P2P-GROUP-STARTED"], timeout=20)
94 raise Exception("Timeout on invitation on peer")
95 if "P2P-INVITATION-RECEIVED" in ev:
96 raise Exception("Unexpected request to accept pre-authorized invitaton")
97 dev[1].group_form_result(ev)
100 logger.info("Client connected")
101 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])
103 logger.info("Terminate group")
104 dev[0].remove_group()
105 dev[1].wait_go_ending_session()
107 def test_p2p_go_invite_unknown(dev):
108 """P2P GO inviting a client that has not discovered the GO"""
110 addr0 = dev[0].p2p_dev_addr()
111 addr1 = dev[1].p2p_dev_addr()
114 if not dev[0].discover_peer(addr1, social=True):
115 raise Exception("Peer " + addr1 + " not found")
116 dev[1].global_request("P2P_FLUSH")
119 dev[0].p2p_start_go(freq=2412)
121 logger.info("Invite peer to join the group")
122 # Prevent peer entry from being added for testing coverage
123 if "OK" not in dev[1].global_request("P2P_SET peer_filter 00:11:22:33:44:55"):
124 raise Exception("Failed to set peer_filter")
125 dev[0].p2p_go_authorize_client("12345670")
126 dev[0].global_request("P2P_INVITE group=" + dev[0].group_ifname + " peer=" + addr1)
127 ev = dev[1].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=15)
129 raise Exception("Invitation Request not received")
130 ev = dev[0].wait_global_event(["P2P-INVITATION-RESULT"], timeout=15)
132 raise Exception("Invitation Response not received")
133 if "status=1" not in ev:
134 raise Exception("Unexpected invitation result: " + ev)
136 dev[1].global_request("P2P_SET peer_filter 00:00:00:00:00:00")
138 def test_p2p_cli_invite(dev):
139 """P2P Client inviting a device to join"""
140 addr0 = dev[0].p2p_dev_addr()
141 addr1 = dev[1].p2p_dev_addr()
142 addr2 = dev[2].p2p_dev_addr()
144 dev[0].p2p_start_go(freq=2412)
145 pin = dev[1].wps_read_pin()
146 dev[0].p2p_go_authorize_client(pin)
147 dev[1].p2p_connect_group(addr0, pin, timeout=60)
150 if not dev[1].discover_peer(addr2, social=True):
151 raise Exception("Peer " + addr2 + " not found")
153 if "OK" not in dev[1].global_request("P2P_INVITE group=" + dev[1].group_ifname + " peer=" + addr2):
154 raise Exception("Unexpected failure of P2P_INVITE to known peer")
155 ev = dev[2].wait_global_event(["P2P-INVITATION-RECEIVED"], timeout=10)
157 raise Exception("Timeout on invitation invited peer")
158 if "sa=" + addr1 not in ev:
159 raise Exception("Incorrect source address")
160 if "go_dev_addr=" + addr0 not in ev:
161 raise Exception("Incorrect GO address")
162 ev = dev[1].wait_global_event(["P2P-INVITATION-RESULT"], timeout=10)
164 raise Exception("Timeout on invitation on inviting client")
165 if "status=1" not in ev:
166 raise Exception("Unexpected invitation result")
168 pin = dev[2].wps_read_pin()
169 dev[0].p2p_go_authorize_client(pin)
170 dev[2].p2p_connect_group(addr0, pin, timeout=60)
172 if "FAIL" not in dev[1].global_request("P2P_INVITE group=" + dev[1].group_ifname + " peer=00:11:22:33:44:55"):
173 raise Exception("Unexpected success of P2P_INVITE to unknown peer")
175 dev[0].remove_group()
176 dev[1].wait_go_ending_session()
177 dev[2].wait_go_ending_session()
179 def test_p2p_invite_invalid(dev):
180 """Invalid parameters to P2P_INVITE"""
181 id = dev[0].add_network()
182 for cmd in [ "foo=bar",
183 "persistent=123 peer=foo",
185 "persistent=%d" % id,
187 "group=foo peer=foo",
188 "group=foo peer=00:11:22:33:44:55 go_dev_addr=foo" ]:
189 if "FAIL" not in dev[0].request("P2P_INVITE " + cmd):
190 raise Exception("Invalid P2P_INVITE accepted: " + cmd)