Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 119830d9 authored by Martin Brabham's avatar Martin Brabham
Browse files

LE Advanced Scanning Test: Add IRK + Random Address scanning Extended PDU +...

LE Advanced Scanning Test: Add IRK + Random Address scanning Extended PDU + PendingIntent; advertising RPA.

Bug: 218710757
Test: gd/cert/run --device --clean --sl4a LeAdvancedScanningTest.test_scan_filter_device_random_address_with_irk_extended_pdu_pending_intent
Tag: #stability
Change-Id: I374fa597ca881f859b9c87d936d90d2c061b7640
parent 048d5ec1
Loading
Loading
Loading
Loading
+83 −0
Original line number Diff line number Diff line
@@ -655,3 +655,86 @@ class LeAdvancedScanningTest(GdSl4aBaseTestClass):
        logging.info("Stopped advertising")

        return True

    def test_scan_filter_device_random_address_with_irk_extended_pdu_pending_intent(self):
        """
        The cert side will advertise an RPA derived from the IRK.

        The DUT (SL4A) side will scan for a RPA with matching IRK.

        The DUT will get results via Pending Intent.
        """
        data = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10]
        byteArrayObject = bytearray(data)
        irk = bytes(byteArrayObject)

        DEVICE_NAME = 'Im_The_CERT!'
        logging.info("Getting public address")
        RANDOM_ADDRESS = self.set_cert_privacy_policy_with_random_address_but_advertise_resolvable(irk)
        logging.info("Done %s" % RANDOM_ADDRESS)

        # Setup cert side to advertise
        gap_name = hci_packets.GapData()
        gap_name.data_type = hci_packets.GapDataType.COMPLETE_LOCAL_NAME
        gap_name.data = list(bytes(DEVICE_NAME, encoding='utf8'))
        gap_data = le_advertising_facade.GapDataMsg(data=bytes(gap_name.Serialize()))
        config = le_advertising_facade.AdvertisingConfig(
            advertisement=[gap_data],
            interval_min=512,
            interval_max=768,
            advertising_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
            own_address_type=common.USE_RANDOM_DEVICE_ADDRESS,
            channel_map=7,
            filter_policy=le_advertising_facade.AdvertisingFilterPolicy.ALL_DEVICES)

        extended_config = le_advertising_facade.ExtendedAdvertisingConfig(
            include_tx_power=True,
            connectable=True,
            legacy_pdus=False,
            advertising_config=config,
            secondary_advertising_phy=ble_scan_settings_phys["1m"])
        request = le_advertising_facade.ExtendedCreateAdvertiserRequest(config=extended_config)
        logging.info("Creating advertiser")
        create_response = self.cert.hci_le_advertising_manager.ExtendedCreateAdvertiser(request)
        logging.info("Created advertiser")

        # Setup SL4A DUT side to scan
        addr_type = ble_address_types["random"]
        logging.info("Start scanning for RANDOM_ADDRESS %s with address type %d and IRK %s" %
                     (RANDOM_ADDRESS, addr_type, irk.decode("utf-8")))
        self.dut.sl4a.bleSetScanSettingsScanMode(ble_scan_settings_modes['low_latency'])
        self.dut.sl4a.bleSetScanSettingsLegacy(False)
        filter_list, scan_settings, scan_callback = generate_ble_scan_objects(self.dut.sl4a)
        # Hard code here since callback index iterates and will cause this to fail if ran
        # Second as the impl in SL4A sends this since its a single callback for broadcast.
        expected_event_name = "BleScan1onScanResults"

        # Setup SL4A DUT filter
        self.dut.sl4a.bleSetScanFilterDeviceAddressTypeAndIrk(RANDOM_ADDRESS, int(addr_type), irk.decode("utf-8"))
        self.dut.sl4a.bleBuildScanFilter(filter_list)

        # Start scanning on SL4A DUT side
        self.dut.sl4a.bleStartBleScanPendingIntent(filter_list, scan_settings)
        logging.info("Started scanning")
        try:
            # Verify if there is scan result
            event_info = self.dut.ed.pop_event(expected_event_name, self.default_timeout)
        except queue.Empty as error:
            logging.error("Could not find initial advertisement.")
            return False
        # Print out scan result
        mac_address = event_info['data']['Result']['deviceInfo']['address']
        logging.info("Filter advertisement with address {}".format(mac_address))

        # Stop scanning
        logging.info("Stop scanning")
        self.dut.sl4a.bleStopBleScan(scan_callback)
        logging.info("Stopped scanning")

        # Stop advertising
        logging.info("Stop advertising")
        remove_request = le_advertising_facade.RemoveAdvertiserRequest(advertiser_id=create_response.advertiser_id)
        self.cert.hci_le_advertising_manager.RemoveAdvertiser(remove_request)
        logging.info("Stopped advertising")

        return True