Пример #1
0
    def test_le_ad_scan_dut_scans(self):
        privacy_policy = le_initiator_address_facade.PrivacyPolicy(
            address_policy=le_initiator_address_facade.AddressPolicy.
            USE_STATIC_ADDRESS,
            address_with_type=common.BluetoothAddressWithType(
                address=common.BluetoothAddress(
                    address=bytes(b'D0:05:04:03:02:01')),
                type=common.RANDOM_DEVICE_ADDRESS),
            rotation_irk=
            b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
            minimum_rotation_time=0,
            maximum_rotation_time=0)
        self.dut.hci_le_initiator_address.SetPrivacyPolicyForInitiatorAddress(
            privacy_policy)
        cert_privacy_policy = le_initiator_address_facade.PrivacyPolicy(
            address_policy=le_initiator_address_facade.AddressPolicy.
            USE_STATIC_ADDRESS,
            address_with_type=common.BluetoothAddressWithType(
                address=common.BluetoothAddress(
                    address=bytes(b'C0:05:04:03:02:01')),
                type=common.RANDOM_DEVICE_ADDRESS),
            rotation_irk=
            b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
            minimum_rotation_time=0,
            maximum_rotation_time=0)
        self.cert.hci_le_initiator_address.SetPrivacyPolicyForInitiatorAddress(
            cert_privacy_policy)
        with EventStream(
                # DUT Scans
                self.dut.hci_le_scanning_manager.StartScan(
                    empty_proto.Empty())) as advertising_event_stream:

            # CERT Advertises
            gap_name = hci_packets.GapData()
            gap_name.data_type = hci_packets.GapDataType.COMPLETE_LOCAL_NAME
            gap_name.data = list(bytes(b'Im_The_CERT!'))
            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,
                event_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
                address_type=common.RANDOM_DEVICE_ADDRESS,
                channel_map=7,
                filter_policy=le_advertising_facade.AdvertisingFilterPolicy.
                ALL_DEVICES)
            request = le_advertising_facade.CreateAdvertiserRequest(
                config=config)

            create_response = self.cert.hci_le_advertising_manager.CreateAdvertiser(
                request)

            advertising_event_stream.assert_event_occurs(
                lambda packet: b'Im_The_CERT' in packet.event)

            remove_request = le_advertising_facade.RemoveAdvertiserRequest(
                advertiser_id=create_response.advertiser_id)
            self.cert.hci_le_advertising_manager.RemoveAdvertiser(
                remove_request)
Пример #2
0
    def test_le_ad_scan_dut_advertises(self):
        self.register_for_le_event(hci_packets.SubeventCode.ADVERTISING_REPORT)
        self.register_for_le_event(
            hci_packets.SubeventCode.EXTENDED_ADVERTISING_REPORT)
        with EventStream(self.cert.hci.FetchLeSubevents(
                empty_proto.Empty())) as hci_le_event_stream:

            # CERT Scans
            self.enqueue_hci_command(
                hci_packets.LeSetRandomAddressBuilder('0C:05:04:03:02:01'),
                True)
            scan_parameters = hci_packets.PhyScanParameters()
            scan_parameters.le_scan_type = hci_packets.LeScanType.ACTIVE
            scan_parameters.le_scan_interval = 40
            scan_parameters.le_scan_window = 20
            self.enqueue_hci_command(
                hci_packets.LeSetExtendedScanParametersBuilder(
                    hci_packets.OwnAddressType.RANDOM_DEVICE_ADDRESS,
                    hci_packets.LeScanningFilterPolicy.ACCEPT_ALL, 1,
                    [scan_parameters]), True)
            self.enqueue_hci_command(
                hci_packets.LeSetExtendedScanEnableBuilder(
                    hci_packets.Enable.ENABLED,
                    hci_packets.FilterDuplicates.DISABLED, 0, 0), True)

            # DUT Advertises
            gap_name = hci_packets.GapData()
            gap_name.data_type = hci_packets.GapDataType.COMPLETE_LOCAL_NAME
            gap_name.data = list(bytes(b'Im_The_DUT'))
            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,
                event_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
                address_type=common.RANDOM_DEVICE_ADDRESS,
                channel_map=7,
                filter_policy=le_advertising_facade.AdvertisingFilterPolicy.
                ALL_DEVICES)
            request = le_advertising_facade.CreateAdvertiserRequest(
                config=config)

            create_response = self.dut.hci_le_advertising_manager.CreateAdvertiser(
                request)

            hci_le_event_stream.assert_event_occurs(
                lambda packet: b'Im_The_DUT' in packet.event)

            remove_request = le_advertising_facade.RemoveAdvertiserRequest(
                advertiser_id=create_response.advertiser_id)
            self.dut.hci_le_advertising_manager.RemoveAdvertiser(
                remove_request)
            self.enqueue_hci_command(
                hci_packets.LeSetScanEnableBuilder(
                    hci_packets.Enable.DISABLED, hci_packets.Enable.DISABLED),
                True)
Пример #3
0
    def test_le_ad_scan_dut_scans(self):
        with EventCallbackStream(
                # DUT Scans
                self.device_under_test.hci_le_scanning_manager.StartScan(
                    empty_proto.Empty())) as advertising_event_stream:

            hci_event_asserts = EventAsserts(advertising_event_stream)

            # CERT Advertises
            gap_name = hci_packets.GapData()
            gap_name.data_type = hci_packets.GapDataType.COMPLETE_LOCAL_NAME
            gap_name.data = list(bytes(b'Im_The_CERT!'))
            gap_data = le_advertising_facade.GapDataMsg(
                data=bytes(gap_name.Serialize()))
            config = le_advertising_facade.AdvertisingConfig(
                advertisement=[gap_data],
                random_address=common.BluetoothAddress(
                    address=bytes(b'A6:A5:A4:A3:A2:A1')),
                interval_min=512,
                interval_max=768,
                event_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
                address_type=common.RANDOM_DEVICE_ADDRESS,
                peer_address_type=common.PUBLIC_DEVICE_OR_IDENTITY_ADDRESS,
                peer_address=common.BluetoothAddress(
                    address=bytes(b'0C:05:04:03:02:01')),
                channel_map=7,
                filter_policy=le_advertising_facade.AdvertisingFilterPolicy.
                ALL_DEVICES)
            request = le_advertising_facade.CreateAdvertiserRequest(
                config=config)

            create_response = self.cert_device.hci_le_advertising_manager.CreateAdvertiser(
                request)

            hci_event_asserts.assert_event_occurs(
                lambda packet: b'Im_The_CERT' in packet.event)

            remove_request = le_advertising_facade.RemoveAdvertiserRequest(
                advertiser_id=create_response.advertiser_id)
            self.cert_device.hci_le_advertising_manager.RemoveAdvertiser(
                remove_request)
    def test_scan_filter_device_name_legacy_pdu(self):
        # Use public address on cert side
        logging.info("Setting public address")
        DEVICE_NAME = 'Im_The_CERT!'
        public_address = self.set_cert_privacy_policy_with_public_address()
        logging.info("Set public 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_PUBLIC_DEVICE_ADDRESS,
            channel_map=7,
            filter_policy=le_advertising_facade.AdvertisingFilterPolicy.
            ALL_DEVICES,
            tx_power=20)
        request = le_advertising_facade.CreateAdvertiserRequest(config=config)
        logging.info("Creating advertiser")
        create_response = self.cert.hci_le_advertising_manager.CreateAdvertiser(
            request)
        logging.info("Created advertiser")

        # Setup SL4A DUT side to scan
        logging.info("Start scanning with public address %s" % public_address)
        self.dut.droid.bleSetScanSettingsScanMode(
            ble_scan_settings_modes['low_latency'])
        filter_list, scan_settings, scan_callback = generate_ble_scan_objects(
            self.dut.droid)
        expected_event_name = scan_result.format(scan_callback)

        # Setup SL4A DUT filter
        self.dut.droid.bleSetScanFilterDeviceName(DEVICE_NAME)
        self.dut.droid.bleBuildScanFilter(filter_list)

        # Start scanning on SL4A DUT side
        self.dut.droid.bleStartBleScan(filter_list, scan_settings,
                                       scan_callback)
        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:
            self.log.error("Could not find initial advertisement.")
            return False
        # Print out scan result
        mac_address = event_info['data']['Result']['deviceInfo']['address']
        self.log.info(
            "Filter advertisement with address {}".format(mac_address))

        # Stop scanning
        logging.info("Stop scanning")
        self.dut.droid.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