• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3.4
2#
3#   Copyright 2018 - 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 binascii
18import queue
19import time
20
21from acts import asserts
22from acts import base_test
23from acts import utils
24from acts.test_decorators import test_tracker_info
25from acts.test_utils.wifi import wifi_constants
26from acts.test_utils.wifi import wifi_test_utils as wutils
27from acts.test_utils.wifi.aware import aware_test_utils as autils
28
29class WifiDppTest(base_test.BaseTestClass):
30  """This class tests the DPP API surface.
31
32     Attributes: The tests in this class require one DUT and one helper phone
33     device.
34     The tests in this class do not require a SIM.
35  """
36
37  DPP_TEST_TIMEOUT = 60
38  DPP_TEST_SSID_PREFIX = "dpp_test_ssid_"
39  DPP_TEST_SECURITY_SAE = "SAE"
40  DPP_TEST_SECURITY_PSK_PASSPHRASE = "PSK_PASSPHRASE"
41  DPP_TEST_SECURITY_PSK = "PSK"
42
43  DPP_TEST_EVENT_DPP_CALLBACK = "onDppCallback"
44  DPP_TEST_EVENT_DATA = "data"
45  DPP_TEST_EVENT_ENROLLEE_SUCCESS = "onEnrolleeSuccess"
46  DPP_TEST_EVENT_CONFIGURATOR_SUCCESS = "onConfiguratorSuccess"
47  DPP_TEST_EVENT_PROGRESS = "onProgress"
48  DPP_TEST_EVENT_FAILURE = "onFailure"
49  DPP_TEST_MESSAGE_TYPE = "Type"
50  DPP_TEST_MESSAGE_STATUS = "Status"
51  DPP_TEST_MESSAGE_NETWORK_ID = "NetworkId"
52
53  DPP_TEST_NETWORK_ROLE_STA = "sta"
54  DPP_TEST_NETWORK_ROLE_AP = "ap"
55
56  WPA_SUPPLICANT_SECURITY_SAE = "sae"
57  WPA_SUPPLICANT_SECURITY_PSK = "psk"
58
59  def setup_class(self):
60    """ Sets up the required dependencies from the config file and configures the device for
61        WifiService API tests.
62
63        Returns:
64          True is successfully configured the requirements for testig.
65    """
66
67    # Device 0 is under test. Device 1 performs the responder role
68    self.dut = self.android_devices[0]
69    self.helper_dev = self.android_devices[1]
70
71    # Do a simple version of init - mainly just sync the time and enable
72    # verbose logging.  We would also like to test with phones in less
73    # constrained states (or add variations where we specifically
74    # constrain).
75    utils.require_sl4a((self.dut,))
76    utils.sync_device_time(self.dut)
77
78    # Enable verbose logging on the dut
79    self.dut.droid.wifiEnableVerboseLogging(1)
80    asserts.assert_true(self.dut.droid.wifiGetVerboseLoggingLevel() == 1,
81                        "Failed to enable WiFi verbose logging on the dut.")
82
83  def teardown_class(self):
84    wutils.reset_wifi(self.dut)
85
86  def on_fail(self, test_name, begin_time):
87        self.dut.take_bug_report(test_name, begin_time)
88        self.dut.cat_adb_log(test_name, begin_time)
89
90  def create_and_save_wifi_network_config(self, security):
91    """ Create a config with random SSID and password.
92
93            Args:
94               security: Security type: PSK or SAE
95
96            Returns:
97               A tuple with the config and networkId for the newly created and
98               saved network.
99    """
100    config_ssid = self.DPP_TEST_SSID_PREFIX + utils.rand_ascii_str(8)
101    config_password = utils.rand_ascii_str(8)
102    self.dut.log.info(
103        "creating config: %s %s %s" % (config_ssid, config_password, security))
104    config = {
105        wutils.WifiEnums.SSID_KEY: config_ssid,
106        wutils.WifiEnums.PWD_KEY: config_password,
107        wutils.WifiEnums.SECURITY: security
108    }
109
110    # Now save the config.
111    network_id = self.dut.droid.wifiAddNetwork(config)
112    self.dut.log.info("saved config: network_id = %d" % network_id)
113    return network_id
114
115  def check_network_config_saved(self, expected_ssid, security, network_id):
116    """ Get the configured networks and check if the provided network ID is present.
117
118            Args:
119             expected_ssid: Expected SSID to match with received configuration.
120             security: Security type to match, PSK or SAE
121
122            Returns:
123                True if the WifiConfig is present.
124    """
125    networks = self.dut.droid.wifiGetConfiguredNetworks()
126    if not networks:
127      return False
128
129    # Normalize PSK and PSK Passphrase to PSK
130    if security == self.DPP_TEST_SECURITY_PSK_PASSPHRASE:
131      security = self.DPP_TEST_SECURITY_PSK
132
133    # If the device doesn't support SAE, then the test fallbacks to PSK
134    if not self.dut.droid.wifiIsWpa3SaeSupported() and \
135              security == self.DPP_TEST_SECURITY_SAE:
136      security = self.DPP_TEST_SECURITY_PSK
137
138    for network in networks:
139      if network_id == network['networkId'] and \
140              security == network[wutils.WifiEnums.SECURITY] and \
141              expected_ssid == network[wutils.WifiEnums.SSID_KEY]:
142        self.log.info("Found SSID %s" % network[wutils.WifiEnums.SSID_KEY])
143        return True
144    return False
145
146  def forget_network(self, network_id):
147    """ Simple method to call wifiForgetNetwork and wait for confirmation callback.
148
149            Returns:
150                True if network was successfully deleted.
151        """
152    self.dut.log.info("Deleting config: networkId = %s" % network_id)
153    self.dut.droid.wifiForgetNetwork(network_id)
154    try:
155      event = self.dut.ed.pop_event(wifi_constants.WIFI_FORGET_NW_SUCCESS, 10)
156      return True
157    except queue.Empty:
158      self.dut.log.error("Failed to forget network")
159      return False
160
161  def gen_uri(self, device, info="DPP_TESTER", chan="81/1", mac=None):
162    """Generate a URI on a device
163
164            Args:
165                device: Device object
166                mac: MAC address to use
167                info: Optional info to be embedded in URI
168                chan: Optional channel info
169
170            Returns:
171             URI ID to be used later
172    """
173
174    # Clean up any previous URIs
175    self.del_uri(device, "'*'")
176
177    self.log.info("Generating a URI for the Responder")
178    cmd = "wpa_cli DPP_BOOTSTRAP_GEN type=qrcode info=%s" % info
179
180    if mac:
181      cmd += " mac=%s" % mac
182
183    if chan:
184      cmd += " chan=%s" % chan
185
186    result = device.adb.shell(cmd)
187
188    if "FAIL" in result:
189      asserts.fail("gen_uri: Failed to generate a URI. Command used: %s" % cmd)
190
191    if not result.index("\n"):
192      asserts.fail("gen_uri: Helper device not responding correctly, may need to restart it."
193                   " Command used: %s" % cmd)
194
195    result = result[result.index("\n") + 1:]
196    device.log.info("Generated URI, id = %s" % result)
197
198    return result
199
200  def get_uri(self, device, uri_id):
201    """Get a previously generated URI from a device
202
203            Args:
204                device: Device object
205                uri_id: URI ID returned by gen_uri method
206
207            Returns:
208                URI string
209
210        """
211    self.log.info("Reading the contents of the URI of the Responder")
212    cmd = "wpa_cli DPP_BOOTSTRAP_GET_URI %s" % uri_id
213    result = device.adb.shell(cmd)
214
215    if "FAIL" in result:
216      asserts.fail("get_uri: Failed to read URI. Command used: %s" % cmd)
217
218    result = result[result.index("\n") + 1:]
219    device.log.info("URI contents = %s" % result)
220
221    return result
222
223  def del_uri(self, device, uri_id):
224    """Delete a previously generated URI
225
226          Args:
227          device: Device object
228          uri_id: URI ID returned by gen_uri method
229    """
230    self.log.info("Deleting the Responder URI")
231    cmd = "wpa_cli DPP_BOOTSTRAP_REMOVE %s" % uri_id
232    result = device.adb.shell(cmd)
233
234    if "FAIL" in result:
235      asserts.fail("del_uri: Failed to delete URI. Command used: %s" % cmd)
236    device.log.info("Deleted URI, id = %s" % uri_id)
237
238  def start_responder_configurator(self,
239                                   device,
240                                   freq=2412,
241                                   net_role=DPP_TEST_NETWORK_ROLE_STA,
242                                   security=DPP_TEST_SECURITY_SAE,
243                                   invalid_config=False):
244    """Start a responder on helper device
245
246           Args:
247               device: Device object
248               freq: Frequency to listen on
249               net_role: Network role to configure
250               security: Security type: SAE or PSK
251               invalid_config: Send invalid configuration (negative test)
252
253            Returns:
254                ssid: SSID name of the network to be configured
255
256        """
257    if not net_role or (net_role != self.DPP_TEST_NETWORK_ROLE_STA and
258                        net_role != self.DPP_TEST_NETWORK_ROLE_AP):
259      asserts.fail("start_responder: Must specify net_role sta or ap")
260
261    self.log.info("Starting Responder in Configurator mode, frequency %sMHz" % freq)
262
263    conf = "conf=%s-" % net_role
264
265    use_psk = False
266
267    if security == self.DPP_TEST_SECURITY_SAE:
268      if not self.dut.droid.wifiIsWpa3SaeSupported():
269        self.log.warning("SAE not supported on device! reverting to PSK")
270        security = self.DPP_TEST_SECURITY_PSK_PASSPHRASE
271
272    if security == self.DPP_TEST_SECURITY_SAE:
273      conf += self.WPA_SUPPLICANT_SECURITY_SAE
274    elif security == self.DPP_TEST_SECURITY_PSK_PASSPHRASE:
275      conf += self.WPA_SUPPLICANT_SECURITY_PSK
276    else:
277      conf += self.WPA_SUPPLICANT_SECURITY_PSK
278      use_psk = True
279
280    ssid = self.DPP_TEST_SSID_PREFIX + utils.rand_ascii_str(8)
281    self.log.debug("SSID = %s" % ssid)
282
283    ssid_encoded = binascii.hexlify(ssid.encode()).decode()
284
285    if use_psk:
286      psk = utils.rand_ascii_str(16)
287      if not invalid_config:
288        psk_encoded = binascii.b2a_hex(psk.encode()).decode()
289      else:
290        # Use the psk as is without hex encoding, will make it invalid
291        psk_encoded = psk
292      self.log.debug("PSK = %s" % psk)
293    else:
294      password = utils.rand_ascii_str(8)
295      if not invalid_config:
296        password_encoded = binascii.b2a_hex(password.encode()).decode()
297      else:
298        # Use the password as is without hex encoding, will make it invalid
299        password_encoded = password
300      self.log.debug("Password = %s" % password)
301
302    conf += " ssid=%s" % ssid_encoded
303
304    if password:  # SAE password or PSK passphrase
305      conf += " pass=%s" % password_encoded
306    else:  # PSK
307      conf += " psk=%s" % psk_encoded
308
309    # Stop responder first
310    self.stop_responder(device)
311
312    cmd = "wpa_cli set dpp_configurator_params guard=1 %s" % conf
313    device.log.debug("Command used: %s" % cmd)
314    result = self.helper_dev.adb.shell(cmd)
315    if "FAIL" in result:
316      asserts.fail(
317          "start_responder_configurator: Failure. Command used: %s" % cmd)
318
319    cmd = "wpa_cli DPP_LISTEN %d role=configurator netrole=%s" % (freq,
320                                                                  net_role)
321    device.log.debug("Command used: %s" % cmd)
322    result = self.helper_dev.adb.shell(cmd)
323    if "FAIL" in result:
324      asserts.fail(
325          "start_responder_configurator: Failure. Command used: %s" % cmd)
326
327    device.log.info("Started responder in configurator mode")
328    return ssid
329
330  def start_responder_enrollee(self,
331                               device,
332                               freq=2412,
333                               net_role=DPP_TEST_NETWORK_ROLE_STA):
334    """Start a responder-enrollee on helper device
335
336           Args:
337               device: Device object
338               freq: Frequency to listen on
339               net_role: Network role to request
340
341            Returns:
342                ssid: SSID name of the network to be configured
343
344        """
345    if not net_role or (net_role != self.DPP_TEST_NETWORK_ROLE_STA and
346                        net_role != self.DPP_TEST_NETWORK_ROLE_AP):
347      asserts.fail("start_responder: Must specify net_role sta or ap")
348
349    # Stop responder first
350    self.stop_responder(device)
351    self.log.info("Starting Responder in Enrollee mode, frequency %sMHz" % freq)
352
353    cmd = "wpa_cli DPP_LISTEN %d role=enrollee netrole=%s" % (freq, net_role)
354    result = device.adb.shell(cmd)
355
356    if "FAIL" in result:
357      asserts.fail("start_responder_enrollee: Failure. Command used: %s" % cmd)
358
359    device.log.info("Started responder in enrollee mode")
360
361  def stop_responder(self, device):
362    """Stop responder on helper device
363
364       Args:
365           device: Device object
366    """
367    result = device.adb.shell("wpa_cli DPP_STOP_LISTEN")
368    if "FAIL" in result:
369      asserts.fail("stop_responder: Failed to stop responder")
370    device.adb.shell("wpa_cli set dpp_configurator_params")
371
372    device.log.info("Stopped responder")
373
374  def start_dpp_as_initiator_configurator(self,
375                                          security,
376                                          use_mac,
377                                          responder_chan="81/1",
378                                          responder_freq=2412,
379                                          net_role=DPP_TEST_NETWORK_ROLE_STA,
380                                          cause_timeout=False,
381                                          fail_authentication=False,
382                                          invalid_uri=False):
383    """ Test Easy Connect (DPP) as initiator configurator.
384
385                1. Enable wifi, if needed
386                2. Create and save a random config.
387                3. Generate a URI using the helper device
388                4. Start DPP as responder-enrollee on helper device
389                5. Start DPP as initiator configurator on dut
390                6. Check if configurator sent successfully
391                7. Delete the URI from helper device
392                8. Remove the config.
393
394        Args:
395            security: Security type, a string "SAE" or "PSK"
396            use_mac: A boolean indicating whether to use the device's MAC
397              address (if True) or use a Broadcast (if False).
398            responder_chan: Responder channel to specify in the URI
399            responder_freq: Frequency that the Responder would actually listen on.
400              Note: To succeed, there must be a correlation between responder_chan, which is what
401              the URI advertises, and responder_freq which is the actual frequency. See:
402              https://en.wikipedia.org/wiki/List_of_WLAN_channels
403            net_role: Network role, a string "sta" or "ap"
404            cause_timeout: Intentionally don't start the responder to cause a
405              timeout
406            fail_authentication: Fail authentication by corrupting the
407              responder's key
408            invalid_uri: Use garbage string instead of a URI
409    """
410    if not self.dut.droid.wifiIsEasyConnectSupported():
411      self.log.warning("Easy Connect is not supported on device!")
412      return
413
414    wutils.wifi_toggle_state(self.dut, True)
415    test_network_id = self.create_and_save_wifi_network_config(security)
416
417    if use_mac:
418      mac = autils.get_mac_addr(self.helper_dev, "wlan0")
419    else:
420      mac = None
421
422    if invalid_uri:
423      enrollee_uri = "dskjgnkdjfgnkdsjfgnsDFGDIFGKDSJFGFDbgjdsnbkjdfnkbgsdfgFDSGSDfgesouhgureho" \
424                     "iu3ht98368903434089ut4958763094u0934ujg094j5oifegjfds"
425    else:
426      # Generate a URI with default info and channel
427      uri_id = self.gen_uri(self.helper_dev, chan=responder_chan, mac=mac)
428
429      # Get the URI. This is equal to scanning a QR code
430      enrollee_uri = self.get_uri(self.helper_dev, uri_id)
431
432      # Corrupt the responder key if required
433      if fail_authentication:
434        enrollee_uri = enrollee_uri[:80] + "DeAdBeeF" + enrollee_uri[88:]
435        self.log.info("Corrupted enrollee URI: %s" % enrollee_uri)
436
437    if not cause_timeout:
438      # Start DPP as an enrolle-responder for STA on helper device
439      self.start_responder_enrollee(self.helper_dev, freq=responder_freq, net_role=net_role)
440    else:
441      self.log.info("Not starting DPP responder on purpose")
442
443    self.log.info("Starting DPP in Configurator-Initiator mode")
444
445    # Start DPP as configurator-initiator on dut
446    self.dut.droid.startEasyConnectAsConfiguratorInitiator(enrollee_uri,
447                                                   test_network_id, net_role)
448
449    start_time = time.time()
450    while time.time() < start_time + self.DPP_TEST_TIMEOUT:
451      dut_event = self.dut.ed.pop_event(self.DPP_TEST_EVENT_DPP_CALLBACK,
452                                        self.DPP_TEST_TIMEOUT)
453      if dut_event[self.DPP_TEST_EVENT_DATA][self.DPP_TEST_MESSAGE_TYPE] \
454              == self.DPP_TEST_EVENT_ENROLLEE_SUCCESS:
455        asserts.fail("DPP failure, unexpected result!")
456        break
457      if dut_event[self.DPP_TEST_EVENT_DATA][
458          self
459          .DPP_TEST_MESSAGE_TYPE] == self.DPP_TEST_EVENT_CONFIGURATOR_SUCCESS:
460        if cause_timeout or fail_authentication or invalid_uri:
461          asserts.fail(
462              "Unexpected DPP success, status code: %s" %
463              dut_event[self.DPP_TEST_EVENT_DATA][self.DPP_TEST_MESSAGE_STATUS])
464        else:
465          val = dut_event[self.DPP_TEST_EVENT_DATA][
466              self.DPP_TEST_MESSAGE_STATUS]
467          if val == 0:
468            self.dut.log.info("DPP Configuration sent success")
469        break
470      if dut_event[self.DPP_TEST_EVENT_DATA][
471          self.DPP_TEST_MESSAGE_TYPE] == self.DPP_TEST_EVENT_PROGRESS:
472        self.dut.log.info("DPP progress event")
473        val = dut_event[self.DPP_TEST_EVENT_DATA][self.DPP_TEST_MESSAGE_STATUS]
474        if val == 0:
475          self.dut.log.info("DPP Authentication success")
476        elif val == 1:
477          self.dut.log.info("DPP Response pending")
478        continue
479      if dut_event[self.DPP_TEST_EVENT_DATA][
480          self.DPP_TEST_MESSAGE_TYPE] == self.DPP_TEST_EVENT_FAILURE:
481        if cause_timeout or fail_authentication or invalid_uri:
482          self.dut.log.info(
483              "Error %s occurred, as expected" %
484              dut_event[self.DPP_TEST_EVENT_DATA][self.DPP_TEST_MESSAGE_STATUS])
485        else:
486          asserts.fail(
487              "DPP failure, status code: %s" %
488              dut_event[self.DPP_TEST_EVENT_DATA][self.DPP_TEST_MESSAGE_STATUS])
489        break
490
491    # Clear all pending events.
492    self.dut.ed.clear_all_events()
493
494    # Stop responder
495    self.stop_responder(self.helper_dev)
496
497    if not invalid_uri:
498      # Delete URI
499      self.del_uri(self.helper_dev, uri_id)
500
501    asserts.assert_true(
502        self.forget_network(test_network_id),
503        "Test network not deleted from configured networks.")
504
505  def start_dpp_as_initiator_enrollee(self,
506                                      security,
507                                      use_mac,
508                                      cause_timeout=False,
509                                      invalid_config=False):
510    """ Test Easy Connect (DPP) as initiator enrollee.
511
512                1. Enable wifi, if needed
513                2. Start DPP as responder-configurator on helper device
514                3. Start DPP as initiator enrollee on dut
515                4. Check if configuration received successfully
516                5. Delete the URI from helper device
517                6. Remove the config.
518
519        Args:
520            security: Security type, a string "SAE" or "PSK"
521            use_mac: A boolean indicating whether to use the device's MAC
522              address (if True) or use a Broadcast (if False).
523            cause_timeout: Intentionally don't start the responder to cause a
524              timeout
525            invalid_config: Responder to intentionally send malformed
526              configuration
527    """
528    if not self.dut.droid.wifiIsEasyConnectSupported():
529      self.log.warning("Easy Connect is not supported on device!")
530      return
531
532    wutils.wifi_toggle_state(self.dut, True)
533
534    if use_mac:
535      mac = autils.get_mac_addr(self.helper_dev, "wlan0")
536    else:
537      mac = None
538
539    # Generate a URI with default info and channel
540    uri_id = self.gen_uri(self.helper_dev, mac=mac)
541
542    # Get the URI. This is equal to scanning a QR code
543    configurator_uri = self.get_uri(self.helper_dev, uri_id)
544
545    if not cause_timeout:
546      # Start DPP as an configurator-responder for STA on helper device
547      ssid = self.start_responder_configurator(
548          self.helper_dev, security=security, invalid_config=invalid_config)
549    else:
550      self.log.info(
551          "Not starting a responder configurator on helper device, on purpose")
552      ssid = self.DPP_TEST_SSID_PREFIX + utils.rand_ascii_str(8)
553
554    self.log.info("Starting DPP in Enrollee-Initiator mode")
555
556    # Start DPP as enrollee-initiator on dut
557    self.dut.droid.startEasyConnectAsEnrolleeInitiator(configurator_uri)
558
559    network_id = 0
560
561    start_time = time.time()
562    while time.time() < start_time + self.DPP_TEST_TIMEOUT:
563      dut_event = self.dut.ed.pop_event(self.DPP_TEST_EVENT_DPP_CALLBACK,
564                                        self.DPP_TEST_TIMEOUT)
565      if dut_event[self.DPP_TEST_EVENT_DATA][
566          self.DPP_TEST_MESSAGE_TYPE] == self.DPP_TEST_EVENT_ENROLLEE_SUCCESS:
567        if cause_timeout or invalid_config:
568          asserts.fail(
569              "Unexpected DPP success, status code: %s" %
570              dut_event[self.DPP_TEST_EVENT_DATA][self.DPP_TEST_MESSAGE_STATUS])
571        else:
572          self.dut.log.info("DPP Configuration received success")
573          network_id = dut_event[self.DPP_TEST_EVENT_DATA][
574              self.DPP_TEST_MESSAGE_NETWORK_ID]
575          self.dut.log.info("NetworkID: %d" % network_id)
576        break
577      if dut_event[self.DPP_TEST_EVENT_DATA][
578          self
579          .DPP_TEST_MESSAGE_TYPE] == self.DPP_TEST_EVENT_CONFIGURATOR_SUCCESS:
580        asserts.fail(
581            "DPP failure, unexpected result: %s" %
582            dut_event[self.DPP_TEST_EVENT_DATA][self.DPP_TEST_MESSAGE_STATUS])
583        break
584      if dut_event[self.DPP_TEST_EVENT_DATA][
585          self.DPP_TEST_MESSAGE_TYPE] == self.DPP_TEST_EVENT_PROGRESS:
586        self.dut.log.info("DPP progress event")
587        val = dut_event[self.DPP_TEST_EVENT_DATA][self.DPP_TEST_MESSAGE_STATUS]
588        if val == 0:
589          self.dut.log.info("DPP Authentication success")
590        elif val == 1:
591          self.dut.log.info("DPP Response pending")
592        continue
593      if dut_event[self.DPP_TEST_EVENT_DATA][
594          self.DPP_TEST_MESSAGE_TYPE] == self.DPP_TEST_EVENT_FAILURE:
595        if cause_timeout or invalid_config:
596          self.dut.log.info(
597              "Error %s occurred, as expected" %
598              dut_event[self.DPP_TEST_EVENT_DATA][self.DPP_TEST_MESSAGE_STATUS])
599        else:
600          asserts.fail(
601              "DPP failure, status code: %s" %
602              dut_event[self.DPP_TEST_EVENT_DATA][self.DPP_TEST_MESSAGE_STATUS])
603        break
604      asserts.fail("Unknown message received")
605
606    # Clear all pending events.
607    self.dut.ed.clear_all_events()
608
609    # Stop responder
610    self.stop_responder(self.helper_dev)
611
612    # Delete URI
613    self.del_uri(self.helper_dev, uri_id)
614
615    if not (invalid_config or cause_timeout):
616      # Check that the saved network is what we expect
617      asserts.assert_true(
618          self.check_network_config_saved(ssid, security, network_id),
619          "Could not find the expected network: %s" % ssid)
620
621      asserts.assert_true(
622          self.forget_network(network_id),
623          "Test network not deleted from configured networks.")
624
625  """ Tests Begin """
626
627  @test_tracker_info(uuid="30893d51-2069-4e1c-8917-c8a840f91b59")
628  def test_dpp_as_initiator_configurator_with_psk_5G(self):
629    asserts.skip_if(not self.dut.droid.wifiIs5GHzBandSupported() or
630            not self.helper_dev.droid.wifiIs5GHzBandSupported(),
631            "5G not supported on at least on test device")
632    self.start_dpp_as_initiator_configurator(
633      security=self.DPP_TEST_SECURITY_PSK, responder_chan="126/149", responder_freq=5745,
634      use_mac=True)
635
636  @test_tracker_info(uuid="54d1d19a-aece-459c-b819-9d4b1ae63f77")
637  def test_dpp_as_initiator_configurator_with_psk_5G_broadcast(self):
638    asserts.skip_if(not self.dut.droid.wifiIs5GHzBandSupported() or
639                    not self.helper_dev.droid.wifiIs5GHzBandSupported(),
640                    "5G not supported on at least on test device")
641    self.start_dpp_as_initiator_configurator(
642      security=self.DPP_TEST_SECURITY_PSK, responder_chan="126/149", responder_freq=5745,
643      use_mac=False)
644
645  @test_tracker_info(uuid="18270a69-300c-4f54-87fd-c19073a2854e ")
646  def test_dpp_as_initiator_configurator_with_psk_no_chan_in_uri_listen_on_5745_broadcast(self):
647    asserts.skip_if(not self.dut.droid.wifiIs5GHzBandSupported() or
648                    not self.helper_dev.droid.wifiIs5GHzBandSupported(),
649                    "5G not supported on at least on test device")
650    self.start_dpp_as_initiator_configurator(
651      security=self.DPP_TEST_SECURITY_PSK, responder_chan=None, responder_freq=5745, use_mac=False)
652
653  @test_tracker_info(uuid="fbdd687c-954a-400b-9da3-2d17e28b0798")
654  def test_dpp_as_initiator_configurator_with_psk_no_chan_in_uri_listen_on_5745(self):
655    asserts.skip_if(not self.dut.droid.wifiIs5GHzBandSupported() or
656                    not self.helper_dev.droid.wifiIs5GHzBandSupported(),
657                    "5G not supported on at least on test device")
658    self.start_dpp_as_initiator_configurator(
659      security=self.DPP_TEST_SECURITY_PSK, responder_chan=None, responder_freq=5745, use_mac=True)
660
661  @test_tracker_info(uuid="570f499f-ab12-4405-af14-c9ed36da2e01 ")
662  def test_dpp_as_initiator_configurator_with_psk_no_chan_in_uri_listen_on_2462_broadcast(self):
663    self.start_dpp_as_initiator_configurator(
664      security=self.DPP_TEST_SECURITY_PSK, responder_chan=None, responder_freq=2462, use_mac=False)
665
666  @test_tracker_info(uuid="e1f083e0-0878-4c49-8ac5-d7c6bba24625")
667  def test_dpp_as_initiator_configurator_with_psk_no_chan_in_uri_listen_on_2462(self):
668    self.start_dpp_as_initiator_configurator(
669      security=self.DPP_TEST_SECURITY_PSK, responder_chan=None, responder_freq=2462, use_mac=True)
670
671  @test_tracker_info(uuid="d2a526f5-4269-493d-bd79-4e6d1b7b00f0")
672  def test_dpp_as_initiator_configurator_with_psk(self):
673    self.start_dpp_as_initiator_configurator(
674        security=self.DPP_TEST_SECURITY_PSK, use_mac=True)
675
676  @test_tracker_info(uuid="6ead218c-222b-45b8-8aad-fe7d883ed631")
677  def test_dpp_as_initiator_configurator_with_sae(self):
678    self.start_dpp_as_initiator_configurator(
679        security=self.DPP_TEST_SECURITY_SAE, use_mac=True)
680
681  @test_tracker_info(uuid="1686adb5-1b3c-4e6d-a969-6b007bdd990d")
682  def test_dpp_as_initiator_configurator_with_psk_passphrase(self):
683    self.start_dpp_as_initiator_configurator(
684        security=self.DPP_TEST_SECURITY_PSK_PASSPHRASE, use_mac=True)
685
686  @test_tracker_info(uuid="3958feb5-1a0c-4487-9741-ac06f04c55a2")
687  def test_dpp_as_initiator_configurator_with_sae_broadcast(self):
688    self.start_dpp_as_initiator_configurator(
689        security=self.DPP_TEST_SECURITY_SAE, use_mac=False)
690
691  @test_tracker_info(uuid="fe6d66f5-73a1-46e9-8f49-73b8f332cc8c")
692  def test_dpp_as_initiator_configurator_with_psk_passphrase_broadcast(self):
693    self.start_dpp_as_initiator_configurator(
694        security=self.DPP_TEST_SECURITY_PSK_PASSPHRASE, use_mac=False)
695
696  @test_tracker_info(uuid="9edd372d-e2f1-4545-8d04-6a1636fcbc4b")
697  def test_dpp_as_initiator_configurator_with_sae_for_ap(self):
698    self.start_dpp_as_initiator_configurator(
699        security=self.DPP_TEST_SECURITY_SAE,
700        use_mac=True,
701        net_role=self.DPP_TEST_NETWORK_ROLE_AP)
702
703  @test_tracker_info(uuid="e9eec912-d665-4926-beac-859cb13dc17b")
704  def test_dpp_as_initiator_configurator_with_psk_passphrase_for_ap(self):
705    self.start_dpp_as_initiator_configurator(
706        security=self.DPP_TEST_SECURITY_PSK_PASSPHRASE,
707        use_mac=True,
708        net_role=self.DPP_TEST_NETWORK_ROLE_AP)
709
710  @test_tracker_info(uuid="8055694f-606f-41dd-9826-3ea1e9b007f8")
711  def test_dpp_as_initiator_enrollee_with_sae(self):
712    self.start_dpp_as_initiator_enrollee(
713        security=self.DPP_TEST_SECURITY_SAE, use_mac=True)
714
715  @test_tracker_info(uuid="c1e9f605-b5c0-4e53-8a08-1b0087a667fa")
716  def test_dpp_as_initiator_enrollee_with_psk_passphrase(self):
717    self.start_dpp_as_initiator_enrollee(
718        security=self.DPP_TEST_SECURITY_PSK_PASSPHRASE, use_mac=True)
719
720  @test_tracker_info(uuid="1d7f30ad-2f9a-427a-8059-651dc8827ae2")
721  def test_dpp_as_initiator_enrollee_with_sae_broadcast(self):
722    self.start_dpp_as_initiator_enrollee(
723        security=self.DPP_TEST_SECURITY_SAE, use_mac=False)
724
725  @test_tracker_info(uuid="0cfc2645-600e-4f2b-ab5c-fcee6d363a9a")
726  def test_dpp_as_initiator_enrollee_with_psk_passphrase_broadcast(self):
727    self.start_dpp_as_initiator_enrollee(
728        security=self.DPP_TEST_SECURITY_PSK_PASSPHRASE, use_mac=False)
729
730  @test_tracker_info(uuid="2e26b248-65dd-41f6-977b-e223d72b2de9")
731  def test_start_dpp_as_initiator_enrollee_receive_invalid_config(self):
732    self.start_dpp_as_initiator_enrollee(
733        security=self.DPP_TEST_SECURITY_PSK_PASSPHRASE,
734        use_mac=True,
735        invalid_config=True)
736
737  @test_tracker_info(uuid="ed189661-d1c1-4626-9f01-3b7bb8a417fe")
738  def test_dpp_as_initiator_configurator_fail_authentication(self):
739    self.start_dpp_as_initiator_configurator(
740        security=self.DPP_TEST_SECURITY_PSK_PASSPHRASE,
741        use_mac=True,
742        fail_authentication=True)
743
744  @test_tracker_info(uuid="5a8c6587-fbb4-4a27-9cba-af6f8935833a")
745  def test_dpp_as_initiator_configurator_fail_unicast_timeout(self):
746    self.start_dpp_as_initiator_configurator(
747        security=self.DPP_TEST_SECURITY_PSK_PASSPHRASE,
748        use_mac=True,
749        cause_timeout=True)
750
751  @test_tracker_info(uuid="b12353ac-1a04-4036-81a4-2d2d0c653dbb")
752  def test_dpp_as_initiator_configurator_fail_broadcast_timeout(self):
753    self.start_dpp_as_initiator_configurator(
754        security=self.DPP_TEST_SECURITY_PSK_PASSPHRASE,
755        use_mac=False,
756        cause_timeout=True)
757
758  @test_tracker_info(uuid="eeff91be-09ce-4a33-8b4f-ece40eb51c76")
759  def test_dpp_as_initiator_configurator_invalid_uri(self):
760    self.start_dpp_as_initiator_configurator(
761        security=self.DPP_TEST_SECURITY_PSK_PASSPHRASE,
762        use_mac=True,
763        invalid_uri=True)
764
765  @test_tracker_info(uuid="1fa25f58-0d0e-40bd-8714-ab78957514d9")
766  def test_start_dpp_as_initiator_enrollee_fail_timeout(self):
767    self.start_dpp_as_initiator_enrollee(
768        security=self.DPP_TEST_SECURITY_PSK_PASSPHRASE,
769        use_mac=True,
770        cause_timeout=True)
771
772  """ Tests End """
773