blob: f4c897aeed47cf70f895044d7511aae69e8c2e9e [file] [log] [blame]
Etan Cohenfc5f3732017-06-02 17:31:52 -07001#!/usr/bin/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 time
18
Etan Cohen38c3d5a2017-07-28 10:02:48 -070019from acts import asserts
Etan Cohenf02703c2017-08-24 11:11:44 -070020from acts.test_decorators import test_tracker_info
Etan Cohenfc5f3732017-06-02 17:31:52 -070021from acts.test_utils.net import connectivity_const as cconsts
22from acts.test_utils.wifi.aware import aware_const as aconsts
23from acts.test_utils.wifi.aware import aware_test_utils as autils
24from acts.test_utils.wifi.aware.AwareBaseTest import AwareBaseTest
25
26
27class DataPathTest(AwareBaseTest):
Etan Cohenbfb149f2017-06-06 10:13:17 -070028 """Set of tests for Wi-Fi Aware data-path."""
Etan Cohenfc5f3732017-06-02 17:31:52 -070029
30 # configuration parameters used by tests
31 ENCR_TYPE_OPEN = 0
32 ENCR_TYPE_PASSPHRASE = 1
Etan Cohen058aaba2017-06-05 17:01:54 -070033 ENCR_TYPE_PMK = 2
Etan Cohenfc5f3732017-06-02 17:31:52 -070034
35 PASSPHRASE = "This is some random passphrase - very very secure!!"
Etan Cohen6ace4582017-06-05 17:21:55 -070036 PASSPHRASE_MIN = "01234567"
37 PASSPHRASE_MAX = "012345678901234567890123456789012345678901234567890123456789012"
Etan Cohen058aaba2017-06-05 17:01:54 -070038 PMK = "ODU0YjE3YzdmNDJiNWI4NTQ2NDJjNDI3M2VkZTQyZGU="
Etan Cohen85adc452017-06-06 08:32:08 -070039 PASSPHRASE2 = "This is some random passphrase - very very secure - but diff!!"
Etan Cohen23b92292017-07-11 11:09:06 -070040 PMK2 = "MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI="
Etan Cohenfc5f3732017-06-02 17:31:52 -070041
42 PING_MSG = "ping"
43
44 # message re-transmit counter (increases reliability in open-environment)
45 # Note: reliability of message transmission is tested elsewhere
46 MSG_RETX_COUNT = 5 # hard-coded max value, internal API
47
Etan Cohenba8a53f2017-06-05 12:55:02 -070048 # number of second to 'reasonably' wait to make sure that devices synchronize
49 # with each other - useful for OOB test cases, where the OOB discovery would
50 # take some time
51 WAIT_FOR_CLUSTER = 5
52
Etan Cohenfc5f3732017-06-02 17:31:52 -070053 def __init__(self, controllers):
54 AwareBaseTest.__init__(self, controllers)
55
56 def create_config(self, dtype):
57 """Create a base configuration based on input parameters.
58
59 Args:
60 dtype: Publish or Subscribe discovery type
61
62 Returns:
63 Discovery configuration object.
64 """
65 config = {}
66 config[aconsts.DISCOVERY_KEY_DISCOVERY_TYPE] = dtype
67 config[aconsts.DISCOVERY_KEY_SERVICE_NAME] = "GoogleTestServiceDataPath"
68 return config
69
70 def request_network(self, dut, ns):
71 """Request a Wi-Fi Aware network.
72
73 Args:
74 dut: Device
75 ns: Network specifier
76 Returns: the request key
77 """
78 network_req = {"TransportType": 5, "NetworkSpecifier": ns}
79 return dut.droid.connectivityRequestWifiAwareNetwork(network_req)
80
Etan Cohen204df172017-11-09 12:05:36 -080081 def set_up_discovery(self, ptype, stype, get_peer_id, pub_on_both=False,
82 pub_on_both_same=True):
Etan Cohenbc80da12017-06-06 09:26:02 -070083 """Set up discovery sessions and wait for service discovery.
Etan Cohenfc5f3732017-06-02 17:31:52 -070084
85 Args:
86 ptype: Publish discovery type
87 stype: Subscribe discovery type
Etan Cohenbc80da12017-06-06 09:26:02 -070088 get_peer_id: Send a message across to get the peer's id
Etan Cohen204df172017-11-09 12:05:36 -080089 pub_on_both: If True then set up a publisher on both devices. The second
90 publisher isn't used (existing to test use-case).
91 pub_on_both_same: If True then the second publish uses an identical
92 service name, otherwise a different service name.
Etan Cohenfc5f3732017-06-02 17:31:52 -070093 """
94 p_dut = self.android_devices[0]
95 p_dut.pretty_name = "Publisher"
96 s_dut = self.android_devices[1]
97 s_dut.pretty_name = "Subscriber"
98
99 # Publisher+Subscriber: attach and wait for confirmation
100 p_id = p_dut.droid.wifiAwareAttach()
101 autils.wait_for_event(p_dut, aconsts.EVENT_CB_ON_ATTACHED)
Etan Cohen76ff8012017-06-16 13:13:44 -0700102 time.sleep(self.device_startup_offset)
Etan Cohenfc5f3732017-06-02 17:31:52 -0700103 s_id = s_dut.droid.wifiAwareAttach()
104 autils.wait_for_event(s_dut, aconsts.EVENT_CB_ON_ATTACHED)
105
106 # Publisher: start publish and wait for confirmation
107 p_disc_id = p_dut.droid.wifiAwarePublish(p_id, self.create_config(ptype))
108 autils.wait_for_event(p_dut, aconsts.SESSION_CB_ON_PUBLISH_STARTED)
109
Etan Cohen204df172017-11-09 12:05:36 -0800110 # Optionally set up a publish session on the Subscriber device
111 if pub_on_both:
112 p2_config = self.create_config(ptype)
113 if not pub_on_both_same:
114 p2_config[aconsts.DISCOVERY_KEY_SERVICE_NAME] = (
115 p2_config[aconsts.DISCOVERY_KEY_SERVICE_NAME] + "-XYZXYZ")
116 s_dut.droid.wifiAwarePublish(s_id, p2_config)
117 autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_PUBLISH_STARTED)
118
Etan Cohenfc5f3732017-06-02 17:31:52 -0700119 # Subscriber: start subscribe and wait for confirmation
120 s_disc_id = s_dut.droid.wifiAwareSubscribe(s_id, self.create_config(stype))
121 autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED)
122
123 # Subscriber: wait for service discovery
124 discovery_event = autils.wait_for_event(
125 s_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)
126 peer_id_on_sub = discovery_event["data"][aconsts.SESSION_CB_KEY_PEER_ID]
127
Etan Cohenbc80da12017-06-06 09:26:02 -0700128 peer_id_on_pub = None
129 if get_peer_id: # only need message to receive peer ID
Etan Cohenfc5f3732017-06-02 17:31:52 -0700130 # Subscriber: send message to peer (Publisher - so it knows our address)
131 s_dut.droid.wifiAwareSendMessage(s_disc_id, peer_id_on_sub,
132 self.get_next_msg_id(), self.PING_MSG,
133 self.MSG_RETX_COUNT)
134 autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_MESSAGE_SENT)
135
136 # Publisher: wait for received message
137 pub_rx_msg_event = autils.wait_for_event(
138 p_dut, aconsts.SESSION_CB_ON_MESSAGE_RECEIVED)
139 peer_id_on_pub = pub_rx_msg_event["data"][aconsts.SESSION_CB_KEY_PEER_ID]
140
Etan Cohenbc80da12017-06-06 09:26:02 -0700141 return (p_dut, s_dut, p_id, s_id, p_disc_id, s_disc_id, peer_id_on_sub,
142 peer_id_on_pub)
143
144 def run_ib_data_path_test(self,
145 ptype,
146 stype,
147 encr_type,
148 use_peer_id,
Etan Cohen204df172017-11-09 12:05:36 -0800149 passphrase_to_use=None,
150 pub_on_both=False,
Etan Cohen7922a312018-01-23 13:34:55 -0800151 pub_on_both_same=True,
152 expect_failure=False):
Etan Cohenbc80da12017-06-06 09:26:02 -0700153 """Runs the in-band data-path tests.
154
155 Args:
156 ptype: Publish discovery type
157 stype: Subscribe discovery type
158 encr_type: Encryption type, one of ENCR_TYPE_*
159 use_peer_id: On Responder (publisher): True to use peer ID, False to
160 accept any request
161 passphrase_to_use: The passphrase to use if encr_type=ENCR_TYPE_PASSPHRASE
162 If None then use self.PASSPHRASE
Etan Cohen204df172017-11-09 12:05:36 -0800163 pub_on_both: If True then set up a publisher on both devices. The second
164 publisher isn't used (existing to test use-case).
165 pub_on_both_same: If True then the second publish uses an identical
166 service name, otherwise a different service name.
Etan Cohen7922a312018-01-23 13:34:55 -0800167 expect_failure: If True then don't expect NDP formation, otherwise expect
168 NDP setup to succeed.
Etan Cohenbc80da12017-06-06 09:26:02 -0700169 """
170 (p_dut, s_dut, p_id, s_id, p_disc_id, s_disc_id, peer_id_on_sub,
Etan Cohen204df172017-11-09 12:05:36 -0800171 peer_id_on_pub) = self.set_up_discovery(ptype, stype, use_peer_id,
172 pub_on_both=pub_on_both,
173 pub_on_both_same=pub_on_both_same)
Etan Cohenbc80da12017-06-06 09:26:02 -0700174
Etan Cohen23b92292017-07-11 11:09:06 -0700175 passphrase = None
176 pmk = None
Etan Cohen058aaba2017-06-05 17:01:54 -0700177 if encr_type == self.ENCR_TYPE_PASSPHRASE:
Etan Cohen204df172017-11-09 12:05:36 -0800178 passphrase = (
179 self.PASSPHRASE if passphrase_to_use == None else passphrase_to_use)
Etan Cohen058aaba2017-06-05 17:01:54 -0700180 elif encr_type == self.ENCR_TYPE_PMK:
Etan Cohen23b92292017-07-11 11:09:06 -0700181 pmk = self.PMK
Etan Cohen058aaba2017-06-05 17:01:54 -0700182
Etan Cohenfc5f3732017-06-02 17:31:52 -0700183 # Publisher: request network
184 p_req_key = self.request_network(
185 p_dut,
Etan Cohen058aaba2017-06-05 17:01:54 -0700186 p_dut.droid.wifiAwareCreateNetworkSpecifier(p_disc_id, peer_id_on_pub if
Etan Cohen23b92292017-07-11 11:09:06 -0700187 use_peer_id else None, passphrase, pmk))
Etan Cohenfc5f3732017-06-02 17:31:52 -0700188
189 # Subscriber: request network
190 s_req_key = self.request_network(
191 s_dut,
Etan Cohen058aaba2017-06-05 17:01:54 -0700192 s_dut.droid.wifiAwareCreateNetworkSpecifier(s_disc_id, peer_id_on_sub,
Etan Cohen23b92292017-07-11 11:09:06 -0700193 passphrase, pmk))
Etan Cohenfc5f3732017-06-02 17:31:52 -0700194
Etan Cohen7922a312018-01-23 13:34:55 -0800195 if expect_failure:
196 # Publisher & Subscriber: fail on network formation
197 time.sleep(autils.EVENT_NDP_TIMEOUT)
198 autils.fail_on_event_with_keys(p_dut, cconsts.EVENT_NETWORK_CALLBACK, 0,
199 (cconsts.NETWORK_CB_KEY_ID, p_req_key))
200 autils.fail_on_event_with_keys(s_dut, cconsts.EVENT_NETWORK_CALLBACK, 0,
201 (cconsts.NETWORK_CB_KEY_ID, s_req_key))
202 else:
203 # Publisher & Subscriber: wait for network formation
204 p_net_event = autils.wait_for_event_with_keys(
205 p_dut, cconsts.EVENT_NETWORK_CALLBACK,
206 autils.EVENT_NDP_TIMEOUT,
207 (cconsts.NETWORK_CB_KEY_EVENT,
208 cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
209 (cconsts.NETWORK_CB_KEY_ID, p_req_key))
210 s_net_event = autils.wait_for_event_with_keys(
211 s_dut, cconsts.EVENT_NETWORK_CALLBACK,
212 autils.EVENT_NDP_TIMEOUT,
213 (cconsts.NETWORK_CB_KEY_EVENT,
214 cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
215 (cconsts.NETWORK_CB_KEY_ID, s_req_key))
Etan Cohenfc5f3732017-06-02 17:31:52 -0700216
Etan Cohen7922a312018-01-23 13:34:55 -0800217 p_aware_if = p_net_event["data"][cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
218 s_aware_if = s_net_event["data"][cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
219 self.log.info("Interface names: p=%s, s=%s", p_aware_if, s_aware_if)
Etan Cohenfc5f3732017-06-02 17:31:52 -0700220
Etan Cohen7922a312018-01-23 13:34:55 -0800221 p_ipv6 = \
222 p_dut.droid.connectivityGetLinkLocalIpv6Address(p_aware_if).split("%")[0]
223 s_ipv6 = \
224 s_dut.droid.connectivityGetLinkLocalIpv6Address(s_aware_if).split("%")[0]
225 self.log.info("Interface addresses (IPv6): p=%s, s=%s", p_ipv6, s_ipv6)
Etan Cohenfc5f3732017-06-02 17:31:52 -0700226
Etan Cohen7922a312018-01-23 13:34:55 -0800227 # TODO: possibly send messages back and forth, prefer to use netcat/nc
Etan Cohenfc5f3732017-06-02 17:31:52 -0700228
Etan Cohen7922a312018-01-23 13:34:55 -0800229 # terminate sessions and wait for ON_LOST callbacks
230 p_dut.droid.wifiAwareDestroy(p_id)
231 s_dut.droid.wifiAwareDestroy(s_id)
Etan Cohence202292017-06-05 13:55:54 -0700232
Etan Cohen7922a312018-01-23 13:34:55 -0800233 autils.wait_for_event_with_keys(
234 p_dut, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_NDP_TIMEOUT,
235 (cconsts.NETWORK_CB_KEY_EVENT,
236 cconsts.NETWORK_CB_LOST), (cconsts.NETWORK_CB_KEY_ID, p_req_key))
237 autils.wait_for_event_with_keys(
238 s_dut, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_NDP_TIMEOUT,
239 (cconsts.NETWORK_CB_KEY_EVENT,
240 cconsts.NETWORK_CB_LOST), (cconsts.NETWORK_CB_KEY_ID, s_req_key))
Etan Cohence202292017-06-05 13:55:54 -0700241
Etan Cohenfc5f3732017-06-02 17:31:52 -0700242 # clean-up
243 p_dut.droid.connectivityUnregisterNetworkCallback(p_req_key)
244 s_dut.droid.connectivityUnregisterNetworkCallback(s_req_key)
245
Etan Cohen35653522017-11-09 13:47:20 -0800246 def run_oob_data_path_test(self, encr_type, use_peer_id,
Etan Cohen7922a312018-01-23 13:34:55 -0800247 setup_discovery_sessions=False, expect_failure=False):
Etan Cohenba8a53f2017-06-05 12:55:02 -0700248 """Runs the out-of-band data-path tests.
249
250 Args:
251 encr_type: Encryption type, one of ENCR_TYPE_*
252 use_peer_id: On Responder: True to use peer ID, False to accept any
253 request
Etan Cohen35653522017-11-09 13:47:20 -0800254 setup_discovery_sessions: If True also set up a (spurious) discovery
255 session (pub on both sides, sub on Responder side). Validates a corner
256 case.
Etan Cohen7922a312018-01-23 13:34:55 -0800257 expect_failure: If True then don't expect NDP formation, otherwise expect
258 NDP setup to succeed.
Etan Cohenba8a53f2017-06-05 12:55:02 -0700259 """
260 init_dut = self.android_devices[0]
261 init_dut.pretty_name = "Initiator"
262 resp_dut = self.android_devices[1]
263 resp_dut.pretty_name = "Responder"
264
Etan Cohenbfb149f2017-06-06 10:13:17 -0700265 # Initiator+Responder: attach and wait for confirmation & identity
Etan Cohenba8a53f2017-06-05 12:55:02 -0700266 init_id = init_dut.droid.wifiAwareAttach(True)
267 autils.wait_for_event(init_dut, aconsts.EVENT_CB_ON_ATTACHED)
268 init_ident_event = autils.wait_for_event(
269 init_dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
270 init_mac = init_ident_event["data"]["mac"]
Etan Cohen76ff8012017-06-16 13:13:44 -0700271 time.sleep(self.device_startup_offset)
Etan Cohenba8a53f2017-06-05 12:55:02 -0700272 resp_id = resp_dut.droid.wifiAwareAttach(True)
273 autils.wait_for_event(resp_dut, aconsts.EVENT_CB_ON_ATTACHED)
274 resp_ident_event = autils.wait_for_event(
275 resp_dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
276 resp_mac = resp_ident_event["data"]["mac"]
277
278 # wait for for devices to synchronize with each other - there are no other
279 # mechanisms to make sure this happens for OOB discovery (except retrying
280 # to execute the data-path request)
281 time.sleep(self.WAIT_FOR_CLUSTER)
282
Etan Cohen35653522017-11-09 13:47:20 -0800283 if setup_discovery_sessions:
284 init_dut.droid.wifiAwarePublish(init_id, self.create_config(
285 aconsts.PUBLISH_TYPE_UNSOLICITED))
286 autils.wait_for_event(init_dut, aconsts.SESSION_CB_ON_PUBLISH_STARTED)
287 resp_dut.droid.wifiAwarePublish(resp_id, self.create_config(
288 aconsts.PUBLISH_TYPE_UNSOLICITED))
289 autils.wait_for_event(resp_dut, aconsts.SESSION_CB_ON_PUBLISH_STARTED)
290 resp_dut.droid.wifiAwareSubscribe(resp_id, self.create_config(
291 aconsts.SUBSCRIBE_TYPE_PASSIVE))
292 autils.wait_for_event(resp_dut, aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED)
293 autils.wait_for_event(resp_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)
294
Etan Cohen23b92292017-07-11 11:09:06 -0700295 passphrase = None
296 pmk = None
Etan Cohen058aaba2017-06-05 17:01:54 -0700297 if encr_type == self.ENCR_TYPE_PASSPHRASE:
Etan Cohen23b92292017-07-11 11:09:06 -0700298 passphrase = self.PASSPHRASE
Etan Cohen058aaba2017-06-05 17:01:54 -0700299 elif encr_type == self.ENCR_TYPE_PMK:
Etan Cohen23b92292017-07-11 11:09:06 -0700300 pmk = self.PMK
Etan Cohen058aaba2017-06-05 17:01:54 -0700301
Etan Cohenba8a53f2017-06-05 12:55:02 -0700302 # Responder: request network
303 resp_req_key = self.request_network(
304 resp_dut,
305 resp_dut.droid.wifiAwareCreateNetworkSpecifierOob(
306 resp_id, aconsts.DATA_PATH_RESPONDER, init_mac
Etan Cohen23b92292017-07-11 11:09:06 -0700307 if use_peer_id else None, passphrase, pmk))
Etan Cohenba8a53f2017-06-05 12:55:02 -0700308
309 # Initiator: request network
310 init_req_key = self.request_network(
311 init_dut,
312 init_dut.droid.wifiAwareCreateNetworkSpecifierOob(
Etan Cohen23b92292017-07-11 11:09:06 -0700313 init_id, aconsts.DATA_PATH_INITIATOR, resp_mac, passphrase, pmk))
Etan Cohenba8a53f2017-06-05 12:55:02 -0700314
Etan Cohen7922a312018-01-23 13:34:55 -0800315 if expect_failure:
316 # Initiator & Responder: fail on network formation
317 time.sleep(autils.EVENT_NDP_TIMEOUT)
318 autils.fail_on_event_with_keys(resp_dut, cconsts.EVENT_NETWORK_CALLBACK,
319 0,
320 (cconsts.NETWORK_CB_KEY_ID, resp_req_key))
321 autils.fail_on_event_with_keys(init_dut, cconsts.EVENT_NETWORK_CALLBACK,
322 0,
323 (cconsts.NETWORK_CB_KEY_ID, init_req_key))
324 else:
325 # Initiator & Responder: wait for network formation
326 init_net_event = autils.wait_for_event_with_keys(
327 init_dut, cconsts.EVENT_NETWORK_CALLBACK,
328 autils.EVENT_NDP_TIMEOUT,
329 (cconsts.NETWORK_CB_KEY_EVENT,
330 cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
331 (cconsts.NETWORK_CB_KEY_ID, init_req_key))
332 resp_net_event = autils.wait_for_event_with_keys(
333 resp_dut, cconsts.EVENT_NETWORK_CALLBACK,
334 autils.EVENT_NDP_TIMEOUT,
335 (cconsts.NETWORK_CB_KEY_EVENT,
336 cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
337 (cconsts.NETWORK_CB_KEY_ID, resp_req_key))
Etan Cohenba8a53f2017-06-05 12:55:02 -0700338
Etan Cohen7922a312018-01-23 13:34:55 -0800339 init_aware_if = init_net_event["data"][
340 cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
341 resp_aware_if = resp_net_event["data"][
342 cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
343 self.log.info("Interface names: I=%s, R=%s", init_aware_if, resp_aware_if)
Etan Cohenba8a53f2017-06-05 12:55:02 -0700344
Etan Cohen7922a312018-01-23 13:34:55 -0800345 init_ipv6 = init_dut.droid.connectivityGetLinkLocalIpv6Address(
346 init_aware_if).split("%")[0]
347 resp_ipv6 = resp_dut.droid.connectivityGetLinkLocalIpv6Address(
348 resp_aware_if).split("%")[0]
349 self.log.info("Interface addresses (IPv6): I=%s, R=%s", init_ipv6,
350 resp_ipv6)
Etan Cohenba8a53f2017-06-05 12:55:02 -0700351
Etan Cohen7922a312018-01-23 13:34:55 -0800352 # TODO: possibly send messages back and forth, prefer to use netcat/nc
Etan Cohenba8a53f2017-06-05 12:55:02 -0700353
Etan Cohen7922a312018-01-23 13:34:55 -0800354 # terminate sessions and wait for ON_LOST callbacks
355 init_dut.droid.wifiAwareDestroy(init_id)
356 resp_dut.droid.wifiAwareDestroy(resp_id)
Etan Cohence202292017-06-05 13:55:54 -0700357
Etan Cohen7922a312018-01-23 13:34:55 -0800358 autils.wait_for_event_with_keys(
359 init_dut, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_NDP_TIMEOUT,
360 (cconsts.NETWORK_CB_KEY_EVENT,
361 cconsts.NETWORK_CB_LOST), (cconsts.NETWORK_CB_KEY_ID, init_req_key))
362 autils.wait_for_event_with_keys(
363 resp_dut, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_NDP_TIMEOUT,
364 (cconsts.NETWORK_CB_KEY_EVENT,
365 cconsts.NETWORK_CB_LOST), (cconsts.NETWORK_CB_KEY_ID, resp_req_key))
Etan Cohence202292017-06-05 13:55:54 -0700366
Etan Cohenba8a53f2017-06-05 12:55:02 -0700367 # clean-up
368 resp_dut.droid.connectivityUnregisterNetworkCallback(resp_req_key)
369 init_dut.droid.connectivityUnregisterNetworkCallback(init_req_key)
370
Etan Cohenbc80da12017-06-06 09:26:02 -0700371 def run_mismatched_ib_data_path_test(self, pub_mismatch, sub_mismatch):
372 """Runs the negative in-band data-path tests: mismatched peer ID.
373
374 Args:
375 pub_mismatch: Mismatch the publisher's ID
376 sub_mismatch: Mismatch the subscriber's ID
377 """
378 (p_dut, s_dut, p_id, s_id, p_disc_id, s_disc_id,
379 peer_id_on_sub, peer_id_on_pub) = self.set_up_discovery(
380 aconsts.PUBLISH_TYPE_UNSOLICITED, aconsts.SUBSCRIBE_TYPE_PASSIVE, True)
381
382 if pub_mismatch:
383 peer_id_on_pub = peer_id_on_pub -1
384 if sub_mismatch:
385 peer_id_on_sub = peer_id_on_sub - 1
386
387 # Publisher: request network
388 p_req_key = self.request_network(
389 p_dut,
390 p_dut.droid.wifiAwareCreateNetworkSpecifier(p_disc_id, peer_id_on_pub,
391 None))
392
393 # Subscriber: request network
394 s_req_key = self.request_network(
395 s_dut,
396 s_dut.droid.wifiAwareCreateNetworkSpecifier(s_disc_id, peer_id_on_sub,
397 None))
398
399 # Publisher & Subscriber: fail on network formation
Etan Cohene47ec432017-06-21 10:42:16 -0700400 time.sleep(autils.EVENT_NDP_TIMEOUT)
Etan Cohen38c3d5a2017-07-28 10:02:48 -0700401 autils.fail_on_event_with_keys(p_dut, cconsts.EVENT_NETWORK_CALLBACK, 0,
402 (cconsts.NETWORK_CB_KEY_ID, p_req_key))
403 autils.fail_on_event_with_keys(s_dut, cconsts.EVENT_NETWORK_CALLBACK, 0,
404 (cconsts.NETWORK_CB_KEY_ID, s_req_key))
Etan Cohenbc80da12017-06-06 09:26:02 -0700405
406 # clean-up
407 p_dut.droid.connectivityUnregisterNetworkCallback(p_req_key)
408 s_dut.droid.connectivityUnregisterNetworkCallback(s_req_key)
409
Etan Cohen85adc452017-06-06 08:32:08 -0700410 def run_mismatched_oob_data_path_test(self,
411 init_mismatch_mac=False,
412 resp_mismatch_mac=False,
413 init_encr_type=ENCR_TYPE_OPEN,
414 resp_encr_type=ENCR_TYPE_OPEN):
415 """Runs the negative out-of-band data-path tests: mismatched information
416 between Responder and Initiator.
417
418 Args:
419 init_mismatch_mac: True to mismatch the Initiator MAC address
420 resp_mismatch_mac: True to mismatch the Responder MAC address
421 init_encr_type: Encryption type of Initiator - ENCR_TYPE_*
422 resp_encr_type: Encryption type of Responder - ENCR_TYPE_*
423 """
424 init_dut = self.android_devices[0]
425 init_dut.pretty_name = "Initiator"
426 resp_dut = self.android_devices[1]
427 resp_dut.pretty_name = "Responder"
428
Etan Cohenbfb149f2017-06-06 10:13:17 -0700429 # Initiator+Responder: attach and wait for confirmation & identity
Etan Cohen85adc452017-06-06 08:32:08 -0700430 init_id = init_dut.droid.wifiAwareAttach(True)
431 autils.wait_for_event(init_dut, aconsts.EVENT_CB_ON_ATTACHED)
432 init_ident_event = autils.wait_for_event(
433 init_dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
434 init_mac = init_ident_event["data"]["mac"]
Etan Cohen76ff8012017-06-16 13:13:44 -0700435 time.sleep(self.device_startup_offset)
Etan Cohen85adc452017-06-06 08:32:08 -0700436 resp_id = resp_dut.droid.wifiAwareAttach(True)
437 autils.wait_for_event(resp_dut, aconsts.EVENT_CB_ON_ATTACHED)
438 resp_ident_event = autils.wait_for_event(
439 resp_dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
440 resp_mac = resp_ident_event["data"]["mac"]
441
442 if init_mismatch_mac: # assumes legit ones don't start with "00"
443 init_mac = "00" + init_mac[2:]
444 if resp_mismatch_mac:
445 resp_mac = "00" + resp_mac[2:]
446
447 # wait for for devices to synchronize with each other - there are no other
448 # mechanisms to make sure this happens for OOB discovery (except retrying
449 # to execute the data-path request)
450 time.sleep(self.WAIT_FOR_CLUSTER)
451
452 # set up separate keys: even if types are the same we want a mismatch
Etan Cohen23b92292017-07-11 11:09:06 -0700453 init_passphrase = None
454 init_pmk = None
Etan Cohen85adc452017-06-06 08:32:08 -0700455 if init_encr_type == self.ENCR_TYPE_PASSPHRASE:
Etan Cohen23b92292017-07-11 11:09:06 -0700456 init_passphrase = self.PASSPHRASE
Etan Cohen85adc452017-06-06 08:32:08 -0700457 elif init_encr_type == self.ENCR_TYPE_PMK:
Etan Cohen23b92292017-07-11 11:09:06 -0700458 init_pmk = self.PMK
Etan Cohen85adc452017-06-06 08:32:08 -0700459
Etan Cohen23b92292017-07-11 11:09:06 -0700460 resp_passphrase = None
461 resp_pmk = None
Etan Cohen85adc452017-06-06 08:32:08 -0700462 if resp_encr_type == self.ENCR_TYPE_PASSPHRASE:
Etan Cohen23b92292017-07-11 11:09:06 -0700463 resp_passphrase = self.PASSPHRASE2
Etan Cohen85adc452017-06-06 08:32:08 -0700464 elif resp_encr_type == self.ENCR_TYPE_PMK:
Etan Cohen23b92292017-07-11 11:09:06 -0700465 resp_pmk = self.PMK2
Etan Cohen85adc452017-06-06 08:32:08 -0700466
467 # Responder: request network
468 resp_req_key = self.request_network(
469 resp_dut,
470 resp_dut.droid.wifiAwareCreateNetworkSpecifierOob(
Etan Cohen23b92292017-07-11 11:09:06 -0700471 resp_id, aconsts.DATA_PATH_RESPONDER, init_mac, resp_passphrase,
472 resp_pmk))
Etan Cohen85adc452017-06-06 08:32:08 -0700473
474 # Initiator: request network
475 init_req_key = self.request_network(
476 init_dut,
477 init_dut.droid.wifiAwareCreateNetworkSpecifierOob(
Etan Cohen23b92292017-07-11 11:09:06 -0700478 init_id, aconsts.DATA_PATH_INITIATOR, resp_mac, init_passphrase,
479 init_pmk))
Etan Cohen85adc452017-06-06 08:32:08 -0700480
481 # Initiator & Responder: fail on network formation
Etan Cohene47ec432017-06-21 10:42:16 -0700482 time.sleep(autils.EVENT_NDP_TIMEOUT)
Etan Cohen38c3d5a2017-07-28 10:02:48 -0700483 autils.fail_on_event_with_keys(init_dut, cconsts.EVENT_NETWORK_CALLBACK, 0,
484 (cconsts.NETWORK_CB_KEY_ID, init_req_key))
485 autils.fail_on_event_with_keys(resp_dut, cconsts.EVENT_NETWORK_CALLBACK, 0,
486 (cconsts.NETWORK_CB_KEY_ID, resp_req_key))
Etan Cohen85adc452017-06-06 08:32:08 -0700487
488 # clean-up
489 resp_dut.droid.connectivityUnregisterNetworkCallback(resp_req_key)
490 init_dut.droid.connectivityUnregisterNetworkCallback(init_req_key)
491
Etan Cohenba8a53f2017-06-05 12:55:02 -0700492
Etan Cohenfc5f3732017-06-02 17:31:52 -0700493 #######################################
494 # Positive In-Band (IB) tests key:
495 #
496 # names is: test_ib_<pub_type>_<sub_type>_<encr_type>_<peer_spec>
497 # where:
498 #
499 # pub_type: Type of publish discovery session: unsolicited or solicited.
500 # sub_type: Type of subscribe discovery session: passive or active.
501 # encr_type: Encription type: open, passphrase
502 # peer_spec: Peer specification method: any or specific
503 #
504 # Note: In-Band means using Wi-Fi Aware for discovery and referring to the
505 # peer using the Aware-provided peer handle (as opposed to a MAC address).
506 #######################################
507
Etan Cohen185b3cf2017-08-22 14:10:10 -0700508 @test_tracker_info(uuid="fa30bedc-d1de-4440-bf25-ec00d10555af")
Etan Cohenfc5f3732017-06-02 17:31:52 -0700509 def test_ib_unsolicited_passive_open_specific(self):
510 """Data-path: in-band, unsolicited/passive, open encryption, specific peer
511
512 Verifies end-to-end discovery + data-path creation.
513 """
514 self.run_ib_data_path_test(
515 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
516 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
517 encr_type=self.ENCR_TYPE_OPEN,
518 use_peer_id=True)
519
Etan Cohen185b3cf2017-08-22 14:10:10 -0700520 @test_tracker_info(uuid="57fc9d53-32ae-470f-a8b1-2fe37893687d")
Etan Cohenfc5f3732017-06-02 17:31:52 -0700521 def test_ib_unsolicited_passive_open_any(self):
522 """Data-path: in-band, unsolicited/passive, open encryption, any peer
523
524 Verifies end-to-end discovery + data-path creation.
525 """
526 self.run_ib_data_path_test(
527 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
528 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
529 encr_type=self.ENCR_TYPE_OPEN,
530 use_peer_id=False)
531
Etan Cohen185b3cf2017-08-22 14:10:10 -0700532 @test_tracker_info(uuid="93b2a23d-8579-448a-936c-7812929464cf")
Etan Cohenfc5f3732017-06-02 17:31:52 -0700533 def test_ib_unsolicited_passive_passphrase_specific(self):
534 """Data-path: in-band, unsolicited/passive, passphrase, specific peer
535
536 Verifies end-to-end discovery + data-path creation.
537 """
538 self.run_ib_data_path_test(
539 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
540 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
541 encr_type=self.ENCR_TYPE_PASSPHRASE,
542 use_peer_id=True)
543
Etan Cohen185b3cf2017-08-22 14:10:10 -0700544 @test_tracker_info(uuid="1736126f-a0ff-4712-acc4-f89b4eef5716")
Etan Cohenfc5f3732017-06-02 17:31:52 -0700545 def test_ib_unsolicited_passive_passphrase_any(self):
546 """Data-path: in-band, unsolicited/passive, passphrase, any peer
547
548 Verifies end-to-end discovery + data-path creation.
549 """
550 self.run_ib_data_path_test(
551 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
552 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
553 encr_type=self.ENCR_TYPE_PASSPHRASE,
554 use_peer_id=False)
555
Etan Cohen185b3cf2017-08-22 14:10:10 -0700556 @test_tracker_info(uuid="b9353d5b-3f77-46bf-bfd9-65d56a7c939a")
Etan Cohen058aaba2017-06-05 17:01:54 -0700557 def test_ib_unsolicited_passive_pmk_specific(self):
558 """Data-path: in-band, unsolicited/passive, PMK, specific peer
559
560 Verifies end-to-end discovery + data-path creation.
561 """
562 self.run_ib_data_path_test(
563 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
564 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
565 encr_type=self.ENCR_TYPE_PMK,
566 use_peer_id=True)
567
Etan Cohen185b3cf2017-08-22 14:10:10 -0700568 @test_tracker_info(uuid="06f3b2ab-4a10-4398-83a4-6a23851b1662")
Etan Cohen058aaba2017-06-05 17:01:54 -0700569 def test_ib_unsolicited_passive_pmk_any(self):
570 """Data-path: in-band, unsolicited/passive, PMK, any peer
571
572 Verifies end-to-end discovery + data-path creation.
573 """
574 self.run_ib_data_path_test(
575 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
576 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
577 encr_type=self.ENCR_TYPE_PMK,
578 use_peer_id=False)
579
Etan Cohen185b3cf2017-08-22 14:10:10 -0700580 @test_tracker_info(uuid="0ed7d8b3-a69e-46ba-aeb7-13e507ecf290")
Etan Cohenfc5f3732017-06-02 17:31:52 -0700581 def test_ib_solicited_active_open_specific(self):
Etan Cohenba8a53f2017-06-05 12:55:02 -0700582 """Data-path: in-band, solicited/active, open encryption, specific peer
Etan Cohenfc5f3732017-06-02 17:31:52 -0700583
Etan Cohenba8a53f2017-06-05 12:55:02 -0700584 Verifies end-to-end discovery + data-path creation.
585 """
586 self.run_ib_data_path_test(
587 ptype=aconsts.PUBLISH_TYPE_SOLICITED,
588 stype=aconsts.SUBSCRIBE_TYPE_ACTIVE,
589 encr_type=self.ENCR_TYPE_OPEN,
590 use_peer_id=True)
Etan Cohenfc5f3732017-06-02 17:31:52 -0700591
Etan Cohen185b3cf2017-08-22 14:10:10 -0700592 @test_tracker_info(uuid="c7ba6d28-5ef6-45d9-95d5-583ad6d981f3")
Etan Cohenfc5f3732017-06-02 17:31:52 -0700593 def test_ib_solicited_active_open_any(self):
Etan Cohenba8a53f2017-06-05 12:55:02 -0700594 """Data-path: in-band, solicited/active, open encryption, any peer
Etan Cohenfc5f3732017-06-02 17:31:52 -0700595
Etan Cohenba8a53f2017-06-05 12:55:02 -0700596 Verifies end-to-end discovery + data-path creation.
597 """
598 self.run_ib_data_path_test(
599 ptype=aconsts.PUBLISH_TYPE_SOLICITED,
600 stype=aconsts.SUBSCRIBE_TYPE_ACTIVE,
601 encr_type=self.ENCR_TYPE_OPEN,
602 use_peer_id=False)
Etan Cohenfc5f3732017-06-02 17:31:52 -0700603
Etan Cohen185b3cf2017-08-22 14:10:10 -0700604 @test_tracker_info(uuid="388cea99-0e2e-49ea-b00e-f3e56b6236e5")
Etan Cohenfc5f3732017-06-02 17:31:52 -0700605 def test_ib_solicited_active_passphrase_specific(self):
Etan Cohenba8a53f2017-06-05 12:55:02 -0700606 """Data-path: in-band, solicited/active, passphrase, specific peer
Etan Cohenfc5f3732017-06-02 17:31:52 -0700607
Etan Cohenba8a53f2017-06-05 12:55:02 -0700608 Verifies end-to-end discovery + data-path creation.
609 """
610 self.run_ib_data_path_test(
611 ptype=aconsts.PUBLISH_TYPE_SOLICITED,
612 stype=aconsts.SUBSCRIBE_TYPE_ACTIVE,
613 encr_type=self.ENCR_TYPE_PASSPHRASE,
614 use_peer_id=True)
Etan Cohenfc5f3732017-06-02 17:31:52 -0700615
Etan Cohen185b3cf2017-08-22 14:10:10 -0700616 @test_tracker_info(uuid="fcd3e28a-5eab-4169-8a0c-dc7204dcdc13")
Etan Cohenfc5f3732017-06-02 17:31:52 -0700617 def test_ib_solicited_active_passphrase_any(self):
Etan Cohenba8a53f2017-06-05 12:55:02 -0700618 """Data-path: in-band, solicited/active, passphrase, any peer
Etan Cohenfc5f3732017-06-02 17:31:52 -0700619
Etan Cohenba8a53f2017-06-05 12:55:02 -0700620 Verifies end-to-end discovery + data-path creation.
621 """
622 self.run_ib_data_path_test(
623 ptype=aconsts.PUBLISH_TYPE_SOLICITED,
624 stype=aconsts.SUBSCRIBE_TYPE_ACTIVE,
625 encr_type=self.ENCR_TYPE_PASSPHRASE,
626 use_peer_id=False)
Etan Cohenfc5f3732017-06-02 17:31:52 -0700627
Etan Cohen185b3cf2017-08-22 14:10:10 -0700628 @test_tracker_info(uuid="9d4eaad7-ba53-4a06-8ce0-e308daea3309")
Etan Cohen058aaba2017-06-05 17:01:54 -0700629 def test_ib_solicited_active_pmk_specific(self):
630 """Data-path: in-band, solicited/active, PMK, specific peer
631
632 Verifies end-to-end discovery + data-path creation.
633 """
634 self.run_ib_data_path_test(
635 ptype=aconsts.PUBLISH_TYPE_SOLICITED,
636 stype=aconsts.SUBSCRIBE_TYPE_ACTIVE,
637 encr_type=self.ENCR_TYPE_PMK,
638 use_peer_id=True)
639
Etan Cohen185b3cf2017-08-22 14:10:10 -0700640 @test_tracker_info(uuid="129d850e-c312-4137-a67b-05ae95fe66cc")
Etan Cohen058aaba2017-06-05 17:01:54 -0700641 def test_ib_solicited_active_pmk_any(self):
642 """Data-path: in-band, solicited/active, PMK, any peer
643
644 Verifies end-to-end discovery + data-path creation.
645 """
646 self.run_ib_data_path_test(
647 ptype=aconsts.PUBLISH_TYPE_SOLICITED,
648 stype=aconsts.SUBSCRIBE_TYPE_ACTIVE,
649 encr_type=self.ENCR_TYPE_PMK,
650 use_peer_id=False)
651
Etan Cohenba8a53f2017-06-05 12:55:02 -0700652 #######################################
Etan Cohen204df172017-11-09 12:05:36 -0800653 # Positive In-Band (IB) with a publish session running on the subscriber
654 # tests key:
655 #
656 # names is: test_ib_extra_pub_<same|diff>_<pub_type>_<sub_type>
657 # _<encr_type>_<peer_spec>
658 # where:
659 #
660 # same|diff: Whether the extra publish session (on the subscriber) is the same
661 # or different from the primary session.
662 # pub_type: Type of publish discovery session: unsolicited or solicited.
663 # sub_type: Type of subscribe discovery session: passive or active.
664 # encr_type: Encription type: open, passphrase
665 # peer_spec: Peer specification method: any or specific
666 #
667 # Note: In-Band means using Wi-Fi Aware for discovery and referring to the
668 # peer using the Aware-provided peer handle (as opposed to a MAC address).
669 #######################################
670
671 def test_ib_extra_pub_same_unsolicited_passive_open_specific(self):
672 """Data-path: in-band, unsolicited/passive, open encryption, specific peer.
673
674 Configuration contains a publisher (for the same service) running on *both*
675 devices.
676
677 Verifies end-to-end discovery + data-path creation.
678 """
679 self.run_ib_data_path_test(
680 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
681 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
682 encr_type=self.ENCR_TYPE_OPEN,
683 use_peer_id=True,
684 pub_on_both=True,
685 pub_on_both_same=True)
686
687 def test_ib_extra_pub_same_unsolicited_passive_open_any(self):
688 """Data-path: in-band, unsolicited/passive, open encryption, any peer.
689
690 Configuration contains a publisher (for the same service) running on *both*
691 devices.
692
693 Verifies end-to-end discovery + data-path creation.
694 """
695 self.run_ib_data_path_test(
696 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
697 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
698 encr_type=self.ENCR_TYPE_OPEN,
699 use_peer_id=False,
700 pub_on_both=True,
701 pub_on_both_same=True)
702
703 def test_ib_extra_pub_diff_unsolicited_passive_open_specific(self):
704 """Data-path: in-band, unsolicited/passive, open encryption, specific peer.
705
706 Configuration contains a publisher (for a different service) running on
707 *both* devices.
708
709 Verifies end-to-end discovery + data-path creation.
710 """
711 self.run_ib_data_path_test(
712 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
713 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
714 encr_type=self.ENCR_TYPE_OPEN,
715 use_peer_id=True,
716 pub_on_both=True,
717 pub_on_both_same=False)
718
719 def test_ib_extra_pub_diff_unsolicited_passive_open_any(self):
720 """Data-path: in-band, unsolicited/passive, open encryption, any peer.
721
722 Configuration contains a publisher (for a different service) running on
723 *both* devices.
724
725 Verifies end-to-end discovery + data-path creation.
726 """
727 self.run_ib_data_path_test(
728 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
729 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
730 encr_type=self.ENCR_TYPE_OPEN,
731 use_peer_id=False,
732 pub_on_both=True,
733 pub_on_both_same=False)
734
735 #######################################
Etan Cohenba8a53f2017-06-05 12:55:02 -0700736 # Positive Out-of-Band (OOB) tests key:
737 #
738 # names is: test_oob_<encr_type>_<peer_spec>
739 # where:
740 #
741 # encr_type: Encription type: open, passphrase
742 # peer_spec: Peer specification method: any or specific
743 #
Etan Cohen35653522017-11-09 13:47:20 -0800744 # Optionally set up an extra discovery session to test coexistence. If so
745 # add "ib_coex" to test name.
746 #
Etan Cohenba8a53f2017-06-05 12:55:02 -0700747 # Note: Out-of-Band means using a non-Wi-Fi Aware mechanism for discovery and
748 # exchange of MAC addresses and then Wi-Fi Aware for data-path.
749 #######################################
750
Etan Cohen185b3cf2017-08-22 14:10:10 -0700751 @test_tracker_info(uuid="7db17d8c-1dce-4084-b695-215bbcfe7d41")
Etan Cohenba8a53f2017-06-05 12:55:02 -0700752 def test_oob_open_specific(self):
753 """Data-path: out-of-band, open encryption, specific peer
754
755 Verifies end-to-end discovery + data-path creation.
756 """
757 self.run_oob_data_path_test(
758 encr_type=self.ENCR_TYPE_OPEN,
759 use_peer_id=True)
760
Etan Cohen185b3cf2017-08-22 14:10:10 -0700761 @test_tracker_info(uuid="ad416d89-cb95-4a07-8d29-ee213117450b")
Etan Cohenba8a53f2017-06-05 12:55:02 -0700762 def test_oob_open_any(self):
763 """Data-path: out-of-band, open encryption, any peer
764
765 Verifies end-to-end discovery + data-path creation.
766 """
767 self.run_oob_data_path_test(
768 encr_type=self.ENCR_TYPE_OPEN,
769 use_peer_id=False)
770
Etan Cohen185b3cf2017-08-22 14:10:10 -0700771 @test_tracker_info(uuid="74937a3a-d524-43e2-8979-4449271cab52")
Etan Cohenba8a53f2017-06-05 12:55:02 -0700772 def test_oob_passphrase_specific(self):
773 """Data-path: out-of-band, passphrase, specific peer
774
775 Verifies end-to-end discovery + data-path creation.
776 """
777 self.run_oob_data_path_test(
778 encr_type=self.ENCR_TYPE_PASSPHRASE,
779 use_peer_id=True)
780
Etan Cohen185b3cf2017-08-22 14:10:10 -0700781 @test_tracker_info(uuid="afcbdc7e-d3a9-465b-b1da-ce2e42e3941e")
Etan Cohenba8a53f2017-06-05 12:55:02 -0700782 def test_oob_passphrase_any(self):
783 """Data-path: out-of-band, passphrase, any peer
784
785 Verifies end-to-end discovery + data-path creation.
786 """
787 self.run_oob_data_path_test(
788 encr_type=self.ENCR_TYPE_PASSPHRASE,
789 use_peer_id=False)
Etan Cohen058aaba2017-06-05 17:01:54 -0700790
Etan Cohen185b3cf2017-08-22 14:10:10 -0700791 @test_tracker_info(uuid="0d095031-160a-4537-aab5-41b6ad5d55f8")
Etan Cohen058aaba2017-06-05 17:01:54 -0700792 def test_oob_pmk_specific(self):
793 """Data-path: out-of-band, PMK, specific peer
794
795 Verifies end-to-end discovery + data-path creation.
796 """
797 self.run_oob_data_path_test(
798 encr_type=self.ENCR_TYPE_PMK,
799 use_peer_id=True)
800
Etan Cohen185b3cf2017-08-22 14:10:10 -0700801 @test_tracker_info(uuid="e45477bd-66cc-4eb7-88dd-4518c8aa2a74")
Etan Cohen058aaba2017-06-05 17:01:54 -0700802 def test_oob_pmk_any(self):
803 """Data-path: out-of-band, PMK, any peer
804
805 Verifies end-to-end discovery + data-path creation.
806 """
807 self.run_oob_data_path_test(
808 encr_type=self.ENCR_TYPE_PMK,
809 use_peer_id=False)
Etan Cohen6ace4582017-06-05 17:21:55 -0700810
Etan Cohen35653522017-11-09 13:47:20 -0800811 def test_oob_ib_coex_open_specific(self):
812 """Data-path: out-of-band, open encryption, specific peer - in-band coex:
813 set up a concurrent discovery session to verify no impact. The session
814 consists of Publisher on both ends, and a Subscriber on the Responder.
815
816 Verifies end-to-end discovery + data-path creation.
817 """
818 self.run_oob_data_path_test(
819 encr_type=self.ENCR_TYPE_OPEN,
820 use_peer_id=True,
821 setup_discovery_sessions=True)
822
823 def test_oob_ib_coex_open_any(self):
824 """Data-path: out-of-band, open encryption, any peer - in-band coex:
825 set up a concurrent discovery session to verify no impact. The session
826 consists of Publisher on both ends, and a Subscriber on the Responder.
827
828 Verifies end-to-end discovery + data-path creation.
829 """
830 self.run_oob_data_path_test(
831 encr_type=self.ENCR_TYPE_OPEN,
832 use_peer_id=False,
833 setup_discovery_sessions=True)
834
Etan Cohen6ace4582017-06-05 17:21:55 -0700835 ##############################################################
836
Etan Cohen185b3cf2017-08-22 14:10:10 -0700837 @test_tracker_info(uuid="1c2c9805-dc1e-43b5-a1b8-315e8c9a4337")
Etan Cohen6ace4582017-06-05 17:21:55 -0700838 def test_passphrase_min(self):
839 """Data-path: minimum passphrase length
840
841 Use in-band, unsolicited/passive, any peer combination
842 """
843 self.run_ib_data_path_test(ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
844 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
845 encr_type=self.ENCR_TYPE_PASSPHRASE,
846 use_peer_id=False,
847 passphrase_to_use=self.PASSPHRASE_MIN)
848
Etan Cohen185b3cf2017-08-22 14:10:10 -0700849 @test_tracker_info(uuid="e696e2b9-87a9-4521-b337-61b9efaa2057")
Etan Cohen6ace4582017-06-05 17:21:55 -0700850 def test_passphrase_max(self):
851 """Data-path: maximum passphrase length
852
853 Use in-band, unsolicited/passive, any peer combination
854 """
855 self.run_ib_data_path_test(ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
856 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
857 encr_type=self.ENCR_TYPE_PASSPHRASE,
858 use_peer_id=False,
859 passphrase_to_use=self.PASSPHRASE_MAX)
Etan Cohen85adc452017-06-06 08:32:08 -0700860
Etan Cohen185b3cf2017-08-22 14:10:10 -0700861 @test_tracker_info(uuid="533cd44c-ff30-4283-ac28-f71fd7b4f02d")
Etan Cohenbc80da12017-06-06 09:26:02 -0700862 def test_negative_mismatch_publisher_peer_id(self):
863 """Data-path: failure when publisher peer ID is mismatched"""
864 self.run_mismatched_ib_data_path_test(pub_mismatch=True, sub_mismatch=False)
865
Etan Cohen185b3cf2017-08-22 14:10:10 -0700866 @test_tracker_info(uuid="682f275e-722a-4f8b-85e7-0dcea9d25532")
Etan Cohenbc80da12017-06-06 09:26:02 -0700867 def test_negative_mismatch_subscriber_peer_id(self):
868 """Data-path: failure when subscriber peer ID is mismatched"""
869 self.run_mismatched_ib_data_path_test(pub_mismatch=False, sub_mismatch=True)
870
Etan Cohen185b3cf2017-08-22 14:10:10 -0700871 @test_tracker_info(uuid="7fa82796-7fc9-4d9e-bbbb-84b751788943")
Etan Cohen85adc452017-06-06 08:32:08 -0700872 def test_negative_mismatch_init_mac(self):
873 """Data-path: failure when Initiator MAC address mismatch"""
874 self.run_mismatched_oob_data_path_test(
875 init_mismatch_mac=True,
876 resp_mismatch_mac=False)
877
Etan Cohen185b3cf2017-08-22 14:10:10 -0700878 @test_tracker_info(uuid="edeae959-4644-44f9-8d41-bdeb5216954e")
Etan Cohen85adc452017-06-06 08:32:08 -0700879 def test_negative_mismatch_resp_mac(self):
880 """Data-path: failure when Responder MAC address mismatch"""
881 self.run_mismatched_oob_data_path_test(
882 init_mismatch_mac=False,
883 resp_mismatch_mac=True)
884
Etan Cohen185b3cf2017-08-22 14:10:10 -0700885 @test_tracker_info(uuid="91f46949-c47f-49f9-a90f-6fae699613a7")
Etan Cohen85adc452017-06-06 08:32:08 -0700886 def test_negative_mismatch_passphrase(self):
887 """Data-path: failure when passphrases mismatch"""
888 self.run_mismatched_oob_data_path_test(
889 init_encr_type=self.ENCR_TYPE_PASSPHRASE,
890 resp_encr_type=self.ENCR_TYPE_PASSPHRASE)
891
Etan Cohen185b3cf2017-08-22 14:10:10 -0700892 @test_tracker_info(uuid="01c49c2e-dc92-4a27-bb47-c4fc67617c23")
Etan Cohen85adc452017-06-06 08:32:08 -0700893 def test_negative_mismatch_pmk(self):
894 """Data-path: failure when PMK mismatch"""
895 self.run_mismatched_oob_data_path_test(
896 init_encr_type=self.ENCR_TYPE_PMK,
897 resp_encr_type=self.ENCR_TYPE_PMK)
898
Etan Cohen185b3cf2017-08-22 14:10:10 -0700899 @test_tracker_info(uuid="4d651797-5fbb-408e-a4b6-a6e1944136da")
Etan Cohen85adc452017-06-06 08:32:08 -0700900 def test_negative_mismatch_open_passphrase(self):
901 """Data-path: failure when initiator is open, and responder passphrase"""
902 self.run_mismatched_oob_data_path_test(
903 init_encr_type=self.ENCR_TYPE_OPEN,
904 resp_encr_type=self.ENCR_TYPE_PASSPHRASE)
905
Etan Cohen185b3cf2017-08-22 14:10:10 -0700906 @test_tracker_info(uuid="1ae697f4-5987-4187-aeef-1e22d07d4a7c")
Etan Cohen85adc452017-06-06 08:32:08 -0700907 def test_negative_mismatch_open_pmk(self):
908 """Data-path: failure when initiator is open, and responder PMK"""
909 self.run_mismatched_oob_data_path_test(
910 init_encr_type=self.ENCR_TYPE_OPEN,
911 resp_encr_type=self.ENCR_TYPE_PMK)
912
Etan Cohen185b3cf2017-08-22 14:10:10 -0700913 @test_tracker_info(uuid="f027b1cc-0e7a-4075-b880-5e64b288afbd")
Etan Cohen85adc452017-06-06 08:32:08 -0700914 def test_negative_mismatch_pmk_passphrase(self):
915 """Data-path: failure when initiator is pmk, and responder passphrase"""
916 self.run_mismatched_oob_data_path_test(
917 init_encr_type=self.ENCR_TYPE_PMK,
918 resp_encr_type=self.ENCR_TYPE_PASSPHRASE)
919
Etan Cohen185b3cf2017-08-22 14:10:10 -0700920 @test_tracker_info(uuid="0819bbd4-72ae-49c4-bd46-5448db2b0a06")
Etan Cohen85adc452017-06-06 08:32:08 -0700921 def test_negative_mismatch_passphrase_open(self):
922 """Data-path: failure when initiator is passphrase, and responder open"""
923 self.run_mismatched_oob_data_path_test(
924 init_encr_type=self.ENCR_TYPE_PASSPHRASE,
925 resp_encr_type=self.ENCR_TYPE_OPEN)
926
Etan Cohen185b3cf2017-08-22 14:10:10 -0700927 @test_tracker_info(uuid="7ef24f62-8e6b-4732-88a3-80a43584dda4")
Etan Cohen85adc452017-06-06 08:32:08 -0700928 def test_negative_mismatch_pmk_open(self):
929 """Data-path: failure when initiator is PMK, and responder open"""
930 self.run_mismatched_oob_data_path_test(
931 init_encr_type=self.ENCR_TYPE_PMK,
932 resp_encr_type=self.ENCR_TYPE_OPEN)
933
Etan Cohen185b3cf2017-08-22 14:10:10 -0700934 @test_tracker_info(uuid="7b9c9efc-1c06-465e-8a5e-d6a22ac1da97")
Etan Cohen85adc452017-06-06 08:32:08 -0700935 def test_negative_mismatch_passphrase_pmk(self):
936 """Data-path: failure when initiator is passphrase, and responder pmk"""
937 self.run_mismatched_oob_data_path_test(
938 init_encr_type=self.ENCR_TYPE_PASSPHRASE,
939 resp_encr_type=self.ENCR_TYPE_OPEN)
Etan Cohen38c3d5a2017-07-28 10:02:48 -0700940
941
942 ##########################################################################
943
Etan Cohen38c3d5a2017-07-28 10:02:48 -0700944 def wait_for_request_responses(self, dut, req_keys, aware_ifs):
945 """Wait for network request confirmation for all request keys.
946
947 Args:
948 dut: Device under test
949 req_keys: (in) A list of the network requests
950 aware_ifs: (out) A list into which to append the network interface
951 """
952 num_events = 0
953 while num_events != len(req_keys):
954 event = autils.wait_for_event(dut, cconsts.EVENT_NETWORK_CALLBACK)
955 if (event["data"][cconsts.NETWORK_CB_KEY_EVENT] ==
956 cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED):
957 if event["data"][cconsts.NETWORK_CB_KEY_ID] in req_keys:
958 num_events = num_events + 1
959 aware_ifs.append(event["data"][cconsts.NETWORK_CB_KEY_INTERFACE_NAME])
960 else:
961 self.log.info("Received an unexpected connectivity, the revoked "
962 "network request probably went through -- %s", event)
963
Etan Cohenb199cd12017-09-22 10:20:44 -0700964 @test_tracker_info(uuid="2e325e2b-d552-4890-b470-20b40284395d")
Etan Cohen38c3d5a2017-07-28 10:02:48 -0700965 def test_multiple_identical_networks(self):
966 """Validate that creating multiple networks between 2 devices, each network
967 with identical configuration is supported over a single NDP.
968
969 Verify that the interface and IPv6 address is the same for all networks.
970 """
971 init_dut = self.android_devices[0]
972 init_dut.pretty_name = "Initiator"
973 resp_dut = self.android_devices[1]
974 resp_dut.pretty_name = "Responder"
975
976 N = 2 # first iteration (must be 2 to give us a chance to cancel the first)
977 M = 5 # second iteration
978
979 init_ids = []
980 resp_ids = []
981
982 # Initiator+Responder: attach and wait for confirmation & identity
Etan Cohenef38a7f2017-11-09 14:26:43 -0800983 # create N+M sessions to be used in the different (but identical) NDPs
Etan Cohen38c3d5a2017-07-28 10:02:48 -0700984 for i in range(N + M):
Etan Cohena1e8d502017-08-16 09:28:18 -0700985 id, init_mac = autils.attach_with_identity(init_dut)
Etan Cohen38c3d5a2017-07-28 10:02:48 -0700986 init_ids.append(id)
Etan Cohena1e8d502017-08-16 09:28:18 -0700987 id, resp_mac = autils.attach_with_identity(resp_dut)
Etan Cohen38c3d5a2017-07-28 10:02:48 -0700988 resp_ids.append(id)
989
990 # wait for for devices to synchronize with each other - there are no other
991 # mechanisms to make sure this happens for OOB discovery (except retrying
992 # to execute the data-path request)
993 time.sleep(autils.WAIT_FOR_CLUSTER)
994
995 resp_req_keys = []
996 init_req_keys = []
997 resp_aware_ifs = []
998 init_aware_ifs = []
999
1000 # issue N quick requests for identical NDPs - without waiting for result
1001 # tests whether pre-setup multiple NDP procedure
1002 for i in range(N):
1003 # Responder: request network
1004 resp_req_keys.append(autils.request_network(
1005 resp_dut,
1006 resp_dut.droid.wifiAwareCreateNetworkSpecifierOob(
1007 resp_ids[i], aconsts.DATA_PATH_RESPONDER, init_mac, None)))
1008
1009 # Initiator: request network
1010 init_req_keys.append(autils.request_network(
1011 init_dut,
1012 init_dut.droid.wifiAwareCreateNetworkSpecifierOob(
1013 init_ids[i], aconsts.DATA_PATH_INITIATOR, resp_mac, None)))
1014
1015 # remove the first request (hopefully before completed) testing that NDP
1016 # is still created
1017 resp_dut.droid.connectivityUnregisterNetworkCallback(resp_req_keys[0])
1018 resp_req_keys.remove(resp_req_keys[0])
1019 init_dut.droid.connectivityUnregisterNetworkCallback(init_req_keys[0])
1020 init_req_keys.remove(init_req_keys[0])
1021
1022 # wait for network formation for all initial requests
1023 self.wait_for_request_responses(resp_dut, resp_req_keys, resp_aware_ifs)
1024 self.wait_for_request_responses(init_dut, init_req_keys, init_aware_ifs)
1025
Etan Cohenef38a7f2017-11-09 14:26:43 -08001026 # issue M more requests for the same NDPs - tests post-setup multiple NDP
Etan Cohen38c3d5a2017-07-28 10:02:48 -07001027 for i in range(M):
1028 # Responder: request network
1029 resp_req_keys.append(autils.request_network(
1030 resp_dut,
1031 resp_dut.droid.wifiAwareCreateNetworkSpecifierOob(
1032 resp_ids[N + i], aconsts.DATA_PATH_RESPONDER, init_mac, None)))
1033
1034 # Initiator: request network
1035 init_req_keys.append(autils.request_network(
1036 init_dut,
1037 init_dut.droid.wifiAwareCreateNetworkSpecifierOob(
1038 init_ids[N + i], aconsts.DATA_PATH_INITIATOR, resp_mac, None)))
1039
1040 # wait for network formation for all subsequent requests
1041 self.wait_for_request_responses(resp_dut, resp_req_keys[N - 1:],
1042 resp_aware_ifs)
1043 self.wait_for_request_responses(init_dut, init_req_keys[N - 1:],
1044 init_aware_ifs)
1045
1046 # determine whether all interfaces are identical (single NDP) - can't really
1047 # test the IPv6 address since it is not part of the callback event - it is
1048 # simply obtained from the system (so we'll always get the same for the same
1049 # interface)
1050 init_aware_ifs = list(set(init_aware_ifs))
1051 resp_aware_ifs = list(set(resp_aware_ifs))
1052
1053 self.log.info("Interface names: I=%s, R=%s", init_aware_ifs, resp_aware_ifs)
1054 self.log.info("Initiator requests: %s", init_req_keys)
1055 self.log.info("Responder requests: %s", resp_req_keys)
1056
1057 asserts.assert_equal(
1058 len(init_aware_ifs), 1, "Multiple initiator interfaces")
1059 asserts.assert_equal(
1060 len(resp_aware_ifs), 1, "Multiple responder interfaces")
1061
1062 self.log.info("Interface IPv6 (using ifconfig): I=%s, R=%s",
1063 autils.get_ipv6_addr(init_dut, init_aware_ifs[0]),
1064 autils.get_ipv6_addr(resp_dut, resp_aware_ifs[0]))
1065
1066 for i in range(init_dut.aware_capabilities[aconsts.CAP_MAX_NDI_INTERFACES]):
1067 if_name = "%s%d" % (aconsts.AWARE_NDI_PREFIX, i)
1068 init_ipv6 = autils.get_ipv6_addr(init_dut, if_name)
1069 resp_ipv6 = autils.get_ipv6_addr(resp_dut, if_name)
1070
1071 asserts.assert_equal(
1072 init_ipv6 is None, if_name not in init_aware_ifs,
1073 "Initiator interface %s in unexpected state" % if_name)
1074 asserts.assert_equal(
1075 resp_ipv6 is None, if_name not in resp_aware_ifs,
1076 "Responder interface %s in unexpected state" % if_name)
1077
1078 # release requests
1079 for resp_req_key in resp_req_keys:
1080 resp_dut.droid.connectivityUnregisterNetworkCallback(resp_req_key)
1081 for init_req_key in init_req_keys:
1082 init_dut.droid.connectivityUnregisterNetworkCallback(init_req_key)
Etan Cohena1e8d502017-08-16 09:28:18 -07001083
Etan Cohenef38a7f2017-11-09 14:26:43 -08001084 def test_identical_network_from_both_sides(self):
1085 """Validate that requesting two identical NDPs (Open) each being initiated
1086 from a different side, results in the same/single NDP.
1087
1088 Verify that the interface and IPv6 address is the same for all networks.
1089 """
1090 dut1 = self.android_devices[0]
1091 dut2 = self.android_devices[1]
1092
1093 id1, mac1 = autils.attach_with_identity(dut1)
1094 id2, mac2 = autils.attach_with_identity(dut2)
1095
1096 # wait for for devices to synchronize with each other - there are no other
1097 # mechanisms to make sure this happens for OOB discovery (except retrying
1098 # to execute the data-path request)
1099 time.sleep(autils.WAIT_FOR_CLUSTER)
1100
1101 # first NDP: DUT1 (Init) -> DUT2 (Resp)
1102 req_a_resp = autils.request_network(dut2,
1103 dut2.droid.wifiAwareCreateNetworkSpecifierOob(
1104 id2, aconsts.DATA_PATH_RESPONDER,
1105 mac1))
1106
1107 req_a_init = autils.request_network(dut1,
1108 dut1.droid.wifiAwareCreateNetworkSpecifierOob(
1109 id1, aconsts.DATA_PATH_INITIATOR,
1110 mac2))
1111
1112 req_a_resp_event = autils.wait_for_event_with_keys(
1113 dut2, cconsts.EVENT_NETWORK_CALLBACK,
1114 autils.EVENT_NDP_TIMEOUT,
1115 (cconsts.NETWORK_CB_KEY_EVENT,
1116 cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
1117 (cconsts.NETWORK_CB_KEY_ID, req_a_resp))
1118 req_a_init_event = autils.wait_for_event_with_keys(
1119 dut1, cconsts.EVENT_NETWORK_CALLBACK,
1120 autils.EVENT_NDP_TIMEOUT,
1121 (cconsts.NETWORK_CB_KEY_EVENT,
1122 cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
1123 (cconsts.NETWORK_CB_KEY_ID, req_a_init))
1124
1125 req_a_if_resp = req_a_resp_event["data"][
1126 cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
1127 req_a_if_init = req_a_init_event["data"][
1128 cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
1129 self.log.info("Interface names for A: I=%s, R=%s", req_a_if_init,
1130 req_a_if_resp)
1131
1132 req_a_ipv6_resp = \
1133 dut2.droid.connectivityGetLinkLocalIpv6Address(req_a_if_resp).split("%")[0]
1134 req_a_ipv6_init = \
1135 dut1.droid.connectivityGetLinkLocalIpv6Address(req_a_if_init).split("%")[0]
1136 self.log.info("Interface addresses (IPv6) for A: I=%s, R=%s",
1137 req_a_ipv6_init, req_a_ipv6_resp)
1138
1139 # second NDP: DUT2 (Init) -> DUT1 (Resp)
1140 req_b_resp = autils.request_network(dut1,
1141 dut1.droid.wifiAwareCreateNetworkSpecifierOob(
1142 id1, aconsts.DATA_PATH_RESPONDER,
1143 mac2))
1144
1145 req_b_init = autils.request_network(dut2,
1146 dut2.droid.wifiAwareCreateNetworkSpecifierOob(
1147 id2, aconsts.DATA_PATH_INITIATOR,
1148 mac1))
1149
1150 req_b_resp_event = autils.wait_for_event_with_keys(
1151 dut1, cconsts.EVENT_NETWORK_CALLBACK,
1152 autils.EVENT_NDP_TIMEOUT,
1153 (cconsts.NETWORK_CB_KEY_EVENT,
1154 cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
1155 (cconsts.NETWORK_CB_KEY_ID, req_b_resp))
1156 req_b_init_event = autils.wait_for_event_with_keys(
1157 dut2, cconsts.EVENT_NETWORK_CALLBACK,
1158 autils.EVENT_NDP_TIMEOUT,
1159 (cconsts.NETWORK_CB_KEY_EVENT,
1160 cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
1161 (cconsts.NETWORK_CB_KEY_ID, req_b_init))
1162
1163 req_b_if_resp = req_b_resp_event["data"][
1164 cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
1165 req_b_if_init = req_b_init_event["data"][
1166 cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
1167 self.log.info("Interface names for B: I=%s, R=%s", req_b_if_init,
1168 req_b_if_resp)
1169
1170 req_b_ipv6_resp = \
1171 dut1.droid.connectivityGetLinkLocalIpv6Address(req_b_if_resp).split("%")[0]
1172 req_b_ipv6_init = \
1173 dut2.droid.connectivityGetLinkLocalIpv6Address(req_b_if_init).split("%")[0]
1174 self.log.info("Interface addresses (IPv6) for B: I=%s, R=%s",
1175 req_b_ipv6_init, req_b_ipv6_resp)
1176
1177 # validate equality of NDPs (using interface names & ipv6)
1178 asserts.assert_equal(req_a_if_init, req_b_if_resp,
1179 "DUT1 NDPs are on different interfaces")
1180 asserts.assert_equal(req_a_if_resp, req_b_if_init,
1181 "DUT2 NDPs are on different interfaces")
1182 asserts.assert_equal(req_a_ipv6_init, req_b_ipv6_resp,
1183 "DUT1 NDPs are using different IPv6 addresses")
1184 asserts.assert_equal(req_a_ipv6_resp, req_b_ipv6_init,
1185 "DUT2 NDPs are using different IPv6 addresses")
1186
1187 # release requests
1188 dut1.droid.connectivityUnregisterNetworkCallback(req_a_init)
1189 dut1.droid.connectivityUnregisterNetworkCallback(req_b_resp)
1190 dut2.droid.connectivityUnregisterNetworkCallback(req_a_resp)
1191 dut2.droid.connectivityUnregisterNetworkCallback(req_b_init)
1192
Etan Cohena1e8d502017-08-16 09:28:18 -07001193 ########################################################################
1194
Etan Cohend6923f22017-11-09 15:37:16 -08001195 def run_multiple_ndi(self, sec_configs, flip_init_resp=False):
Etan Cohena1e8d502017-08-16 09:28:18 -07001196 """Validate that the device can create and use multiple NDIs.
1197
1198 The security configuration can be:
1199 - None: open
1200 - String: passphrase
1201 - otherwise: PMK (byte array)
1202
1203 Args:
1204 sec_configs: list of security configurations
Etan Cohend6923f22017-11-09 15:37:16 -08001205 flip_init_resp: if True the roles of Initiator and Responder are flipped
1206 between the 2 devices, otherwise same devices are always
1207 configured in the same role.
Etan Cohena1e8d502017-08-16 09:28:18 -07001208 """
Etan Cohen1d2723f2017-11-09 14:59:11 -08001209 dut1 = self.android_devices[0]
1210 dut2 = self.android_devices[1]
Etan Cohena1e8d502017-08-16 09:28:18 -07001211
Etan Cohen1d2723f2017-11-09 14:59:11 -08001212 asserts.skip_if(dut1.aware_capabilities[aconsts.CAP_MAX_NDI_INTERFACES]
Etan Cohena1e8d502017-08-16 09:28:18 -07001213 < len(sec_configs) or
Etan Cohen1d2723f2017-11-09 14:59:11 -08001214 dut2.aware_capabilities[aconsts.CAP_MAX_NDI_INTERFACES]
Etan Cohena1e8d502017-08-16 09:28:18 -07001215 < len(sec_configs),
Etan Cohen1d2723f2017-11-09 14:59:11 -08001216 "DUTs do not support enough NDIs")
Etan Cohena1e8d502017-08-16 09:28:18 -07001217
Etan Cohen1d2723f2017-11-09 14:59:11 -08001218 id1, mac1 = autils.attach_with_identity(dut1)
1219 id2, mac2 = autils.attach_with_identity(dut2)
Etan Cohena1e8d502017-08-16 09:28:18 -07001220
1221 # wait for for devices to synchronize with each other - there are no other
1222 # mechanisms to make sure this happens for OOB discovery (except retrying
1223 # to execute the data-path request)
1224 time.sleep(autils.WAIT_FOR_CLUSTER)
1225
Etan Cohen1d2723f2017-11-09 14:59:11 -08001226 dut2_req_keys = []
1227 dut1_req_keys = []
1228 dut2_aware_ifs = []
1229 dut1_aware_ifs = []
Etan Cohena1e8d502017-08-16 09:28:18 -07001230
Etan Cohend6923f22017-11-09 15:37:16 -08001231 dut2_type = aconsts.DATA_PATH_RESPONDER
1232 dut1_type = aconsts.DATA_PATH_INITIATOR
1233 dut2_is_responder = True
Etan Cohena1e8d502017-08-16 09:28:18 -07001234 for sec in sec_configs:
Etan Cohend6923f22017-11-09 15:37:16 -08001235 if dut2_is_responder:
1236 # DUT2 (Responder): request network
1237 dut2_req_key = autils.request_network(dut2,
1238 autils.get_network_specifier(
1239 dut2, id2,
1240 dut2_type,
1241 mac1, sec))
1242 dut2_req_keys.append(dut2_req_key)
Etan Cohena1e8d502017-08-16 09:28:18 -07001243
Etan Cohend6923f22017-11-09 15:37:16 -08001244 # DUT1 (Initiator): request network
1245 dut1_req_key = autils.request_network(dut1,
1246 autils.get_network_specifier(
1247 dut1, id1,
1248 dut1_type,
1249 mac2, sec))
1250 dut1_req_keys.append(dut1_req_key)
1251 else:
1252 # DUT1 (Responder): request network
1253 dut1_req_key = autils.request_network(dut1,
1254 autils.get_network_specifier(
1255 dut1, id1,
1256 dut1_type,
1257 mac2, sec))
1258 dut1_req_keys.append(dut1_req_key)
1259
1260 # DUT2 (Initiator): request network
1261 dut2_req_key = autils.request_network(dut2,
1262 autils.get_network_specifier(
1263 dut2, id2,
1264 dut2_type,
1265 mac1, sec))
1266 dut2_req_keys.append(dut2_req_key)
Etan Cohena1e8d502017-08-16 09:28:18 -07001267
1268 # Wait for network
Etan Cohen1d2723f2017-11-09 14:59:11 -08001269 dut1_net_event = autils.wait_for_event_with_keys(
1270 dut1, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_TIMEOUT,
Etan Cohena1e8d502017-08-16 09:28:18 -07001271 (cconsts.NETWORK_CB_KEY_EVENT,
1272 cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
Etan Cohen1d2723f2017-11-09 14:59:11 -08001273 (cconsts.NETWORK_CB_KEY_ID, dut1_req_key))
1274 dut2_net_event = autils.wait_for_event_with_keys(
1275 dut2, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_TIMEOUT,
Etan Cohena1e8d502017-08-16 09:28:18 -07001276 (cconsts.NETWORK_CB_KEY_EVENT,
1277 cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
Etan Cohen1d2723f2017-11-09 14:59:11 -08001278 (cconsts.NETWORK_CB_KEY_ID, dut2_req_key))
Etan Cohena1e8d502017-08-16 09:28:18 -07001279
Etan Cohen1d2723f2017-11-09 14:59:11 -08001280 dut2_aware_ifs.append(
1281 dut2_net_event["data"][cconsts.NETWORK_CB_KEY_INTERFACE_NAME])
1282 dut1_aware_ifs.append(
1283 dut1_net_event["data"][cconsts.NETWORK_CB_KEY_INTERFACE_NAME])
Etan Cohena1e8d502017-08-16 09:28:18 -07001284
Etan Cohend6923f22017-11-09 15:37:16 -08001285 if flip_init_resp:
1286 if dut2_is_responder:
1287 dut2_type = aconsts.DATA_PATH_INITIATOR
1288 dut1_type = aconsts.DATA_PATH_RESPONDER
1289 else:
1290 dut2_type = aconsts.DATA_PATH_RESPONDER
1291 dut1_type = aconsts.DATA_PATH_INITIATOR
1292 dut2_is_responder = not dut2_is_responder
1293
Etan Cohena1e8d502017-08-16 09:28:18 -07001294 # check that we are using 2 NDIs
Etan Cohen1d2723f2017-11-09 14:59:11 -08001295 dut1_aware_ifs = list(set(dut1_aware_ifs))
1296 dut2_aware_ifs = list(set(dut2_aware_ifs))
Etan Cohena1e8d502017-08-16 09:28:18 -07001297
Etan Cohen1d2723f2017-11-09 14:59:11 -08001298 self.log.info("Interface names: DUT1=%s, DUT2=%s", dut1_aware_ifs,
1299 dut2_aware_ifs)
1300 self.log.info("DUT1 requests: %s", dut1_req_keys)
1301 self.log.info("DUT2 requests: %s", dut2_req_keys)
Etan Cohena1e8d502017-08-16 09:28:18 -07001302
1303 asserts.assert_equal(
Etan Cohen1d2723f2017-11-09 14:59:11 -08001304 len(dut1_aware_ifs), len(sec_configs), "Multiple DUT1 interfaces")
Etan Cohena1e8d502017-08-16 09:28:18 -07001305 asserts.assert_equal(
Etan Cohen1d2723f2017-11-09 14:59:11 -08001306 len(dut2_aware_ifs), len(sec_configs), "Multiple DUT2 interfaces")
Etan Cohena1e8d502017-08-16 09:28:18 -07001307
1308 for i in range(len(sec_configs)):
1309 if_name = "%s%d" % (aconsts.AWARE_NDI_PREFIX, i)
Etan Cohen1d2723f2017-11-09 14:59:11 -08001310 dut1_ipv6 = autils.get_ipv6_addr(dut1, if_name)
1311 dut2_ipv6 = autils.get_ipv6_addr(dut2, if_name)
Etan Cohena1e8d502017-08-16 09:28:18 -07001312
1313 asserts.assert_equal(
Etan Cohen1d2723f2017-11-09 14:59:11 -08001314 dut1_ipv6 is None, if_name not in dut1_aware_ifs,
1315 "DUT1 interface %s in unexpected state" % if_name)
Etan Cohena1e8d502017-08-16 09:28:18 -07001316 asserts.assert_equal(
Etan Cohen1d2723f2017-11-09 14:59:11 -08001317 dut2_ipv6 is None, if_name not in dut2_aware_ifs,
1318 "DUT2 interface %s in unexpected state" % if_name)
Etan Cohena1e8d502017-08-16 09:28:18 -07001319
1320 # release requests
Etan Cohen1d2723f2017-11-09 14:59:11 -08001321 for dut2_req_key in dut2_req_keys:
1322 dut2.droid.connectivityUnregisterNetworkCallback(dut2_req_key)
1323 for dut1_req_key in dut1_req_keys:
1324 dut1.droid.connectivityUnregisterNetworkCallback(dut1_req_key)
Etan Cohena1e8d502017-08-16 09:28:18 -07001325
Etan Cohenb199cd12017-09-22 10:20:44 -07001326 @test_tracker_info(uuid="2d728163-11cc-46ba-a973-c8e1e71397fc")
Etan Cohena1e8d502017-08-16 09:28:18 -07001327 def test_multiple_ndi_open_passphrase(self):
1328 """Verify that can between 2 DUTs can create 2 NDPs with different security
1329 configuration (one open, one using passphrase). The result should use two
1330 different NDIs"""
1331 self.run_multiple_ndi([None, self.PASSPHRASE])
1332
Etan Cohenb199cd12017-09-22 10:20:44 -07001333 @test_tracker_info(uuid="5f2c32aa-20b2-41f0-8b1e-d0b68df73ada")
Etan Cohena1e8d502017-08-16 09:28:18 -07001334 def test_multiple_ndi_open_pmk(self):
1335 """Verify that can between 2 DUTs can create 2 NDPs with different security
1336 configuration (one open, one using pmk). The result should use two
1337 different NDIs"""
1338 self.run_multiple_ndi([None, self.PMK])
1339
Etan Cohenb199cd12017-09-22 10:20:44 -07001340 @test_tracker_info(uuid="34467659-bcfb-40cd-ba25-7e50560fca63")
Etan Cohena1e8d502017-08-16 09:28:18 -07001341 def test_multiple_ndi_passphrase_pmk(self):
1342 """Verify that can between 2 DUTs can create 2 NDPs with different security
1343 configuration (one using passphrase, one using pmk). The result should use
1344 two different NDIs"""
1345 self.run_multiple_ndi([self.PASSPHRASE, self.PMK])
1346
Etan Cohenb199cd12017-09-22 10:20:44 -07001347 @test_tracker_info(uuid="d9194ce6-45b6-41b1-9cc8-ada79968966d")
Etan Cohena1e8d502017-08-16 09:28:18 -07001348 def test_multiple_ndi_passphrases(self):
1349 """Verify that can between 2 DUTs can create 2 NDPs with different security
1350 configuration (using different passphrases). The result should use two
1351 different NDIs"""
1352 self.run_multiple_ndi([self.PASSPHRASE, self.PASSPHRASE2])
1353
Etan Cohenb199cd12017-09-22 10:20:44 -07001354 @test_tracker_info(uuid="879df795-62d2-40d4-a862-bd46d8f7e67f")
Etan Cohena1e8d502017-08-16 09:28:18 -07001355 def test_multiple_ndi_pmks(self):
1356 """Verify that can between 2 DUTs can create 2 NDPs with different security
1357 configuration (using different PMKS). The result should use two different
1358 NDIs"""
1359 self.run_multiple_ndi([self.PMK, self.PMK2])
Etan Cohend6923f22017-11-09 15:37:16 -08001360
1361 def test_multiple_ndi_open_passphrase_flip(self):
1362 """Verify that can between 2 DUTs can create 2 NDPs with different security
1363 configuration (one open, one using passphrase). The result should use two
1364 different NDIs.
1365
1366 Flip Initiator and Responder roles.
1367 """
1368 self.run_multiple_ndi([None, self.PASSPHRASE], flip_init_resp=True)
1369
1370 def test_multiple_ndi_open_pmk_flip(self):
1371 """Verify that can between 2 DUTs can create 2 NDPs with different security
1372 configuration (one open, one using pmk). The result should use two
1373 different NDIs
1374
1375 Flip Initiator and Responder roles.
1376 """
1377 self.run_multiple_ndi([None, self.PMK], flip_init_resp=True)
1378
1379 def test_multiple_ndi_passphrase_pmk_flip(self):
1380 """Verify that can between 2 DUTs can create 2 NDPs with different security
1381 configuration (one using passphrase, one using pmk). The result should use
1382 two different NDIs
1383
1384 Flip Initiator and Responder roles.
1385 """
1386 self.run_multiple_ndi([self.PASSPHRASE, self.PMK], flip_init_resp=True)
1387
1388 def test_multiple_ndi_passphrases_flip(self):
1389 """Verify that can between 2 DUTs can create 2 NDPs with different security
1390 configuration (using different passphrases). The result should use two
1391 different NDIs
1392
1393 Flip Initiator and Responder roles.
1394 """
1395 self.run_multiple_ndi([self.PASSPHRASE, self.PASSPHRASE2],
1396 flip_init_resp=True)
1397
1398 def test_multiple_ndi_pmks_flip(self):
1399 """Verify that can between 2 DUTs can create 2 NDPs with different security
1400 configuration (using different PMKS). The result should use two different
1401 NDIs
1402
1403 Flip Initiator and Responder roles.
1404 """
1405 self.run_multiple_ndi([self.PMK, self.PMK2], flip_init_resp=True)
Etan Cohen7922a312018-01-23 13:34:55 -08001406
1407 #######################################
1408
1409 def test_ib_responder_any_usage(self):
1410 """Verify that configuring an in-band (Aware discovery) Responder to receive
1411 an NDP request from any peer is not permitted by current API level. Override
1412 API check to validate that possible (i.e. that failure at current API level
1413 is due to an API check and not some underlying failure).
1414 """
1415
1416 # configure all devices to override API check and allow a Responder from ANY
1417 for ad in self.android_devices:
1418 autils.configure_ndp_allow_any_override(ad, True)
1419 self.run_ib_data_path_test(
1420 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
1421 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
1422 encr_type=self.ENCR_TYPE_OPEN,
1423 use_peer_id=False)
1424
1425 # configure all devices to respect API check - i.e. disallow a Responder
1426 # from ANY
1427 for ad in self.android_devices:
1428 autils.configure_ndp_allow_any_override(ad, False)
1429 self.run_ib_data_path_test(
1430 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
1431 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
1432 encr_type=self.ENCR_TYPE_OPEN,
1433 use_peer_id=False,
1434 expect_failure=True)
1435
1436 def test_oob_responder_any_usage(self):
1437 """Verify that configuring an out-of-band (Aware discovery) Responder to
1438 receive an NDP request from any peer is not permitted by current API level.
1439 Override API check to validate that possible (i.e. that failure at current
1440 API level is due to an API check and not some underlying failure).
1441 """
1442
1443 # configure all devices to override API check and allow a Responder from ANY
1444 for ad in self.android_devices:
1445 autils.configure_ndp_allow_any_override(ad, True)
1446 self.run_oob_data_path_test(
1447 encr_type=self.ENCR_TYPE_OPEN,
1448 use_peer_id=False)
1449
1450 # configure all devices to respect API check - i.e. disallow a Responder
1451 # from ANY
1452 for ad in self.android_devices:
1453 autils.configure_ndp_allow_any_override(ad, False)
1454 self.run_oob_data_path_test(
1455 encr_type=self.ENCR_TYPE_OPEN,
1456 use_peer_id=False,
1457 expect_failure=True)