Exemplo n.º 1
0
    def test_le_connect_list_connection_cert_advertises(self):
        self.dut_hci.register_for_le_events(
            hci_packets.SubeventCode.CONNECTION_COMPLETE)
        # DUT Connects
        self.dut_hci.send_command_with_complete(
            hci_packets.LeSetRandomAddressBuilder('0D:05:04:03:02:01'))
        self.dut_hci.send_command_with_complete(
            hci_packets.LeAddDeviceToConnectListBuilder(
                hci_packets.ConnectListAddressType.RANDOM,
                '0C:05:04:03:02:01'))
        phy_scan_params = DirectHciTest._create_phy_scan_params()
        self.dut_hci.send_command_with_status(
            hci_packets.LeExtendedCreateConnectionBuilder(
                hci_packets.InitiatorFilterPolicy.USE_CONNECT_LIST,
                hci_packets.OwnAddressType.RANDOM_DEVICE_ADDRESS,
                hci_packets.AddressType.RANDOM_DEVICE_ADDRESS,
                'BA:D5:A4:A3:A2:A1', 1, [phy_scan_params]))

        # CERT Advertises
        advertising_handle = 1
        self.send_hal_hci_command(
            hci_packets.LeSetExtendedAdvertisingLegacyParametersBuilder(
                advertising_handle,
                hci_packets.LegacyAdvertisingProperties.ADV_IND,
                512,
                768,
                7,
                hci_packets.OwnAddressType.RANDOM_DEVICE_ADDRESS,
                hci_packets.PeerAddressType.PUBLIC_DEVICE_OR_IDENTITY_ADDRESS,
                'A6:A5:A4:A3:A2:A1',
                hci_packets.AdvertisingFilterPolicy.ALL_DEVICES,
                0x7F,
                0,  # SID
                hci_packets.Enable.DISABLED  # Scan request notification
            ))

        self.send_hal_hci_command(
            hci_packets.LeSetExtendedAdvertisingRandomAddressBuilder(
                advertising_handle, '0C:05:04:03:02:01'))

        gap_name = hci_packets.GapData()
        gap_name.data_type = hci_packets.GapDataType.COMPLETE_LOCAL_NAME
        gap_name.data = list(bytes(b'Im_A_Cert'))

        self.send_hal_hci_command(
            hci_packets.LeSetExtendedAdvertisingDataBuilder(
                advertising_handle,
                hci_packets.Operation.COMPLETE_ADVERTISEMENT,
                hci_packets.FragmentPreference.CONTROLLER_SHOULD_NOT,
                [gap_name]))
        enabled_set = hci_packets.EnabledSet()
        enabled_set.advertising_handle = 1
        enabled_set.duration = 0
        enabled_set.max_extended_advertising_events = 0
        self.send_hal_hci_command(
            hci_packets.LeSetExtendedAdvertisingEnableBuilder(
                hci_packets.Enable.ENABLED, [enabled_set]))

        # LeConnectionComplete
        self._verify_le_connection_complete()
Exemplo n.º 2
0
    def test_stream_events(self):
        self.dut_hal.send_hci_command(
            hci_packets.LeAddDeviceToConnectListBuilder(
                hci_packets.ConnectListAddressType.RANDOM,
                '0C:05:04:03:02:01'))

        assertThat(self.dut_hal.get_hci_event_stream()).emits(
            HciMatchers.Exactly(
                hci_packets.LeAddDeviceToConnectListCompleteBuilder(
                    1, hci_packets.ErrorCode.SUCCESS)))
Exemplo n.º 3
0
    def test_loopback_hci_command(self):
        self.dut_hal.send_hci_command(
            hci_packets.WriteLoopbackModeBuilder(
                hci_packets.LoopbackMode.ENABLE_LOCAL))

        command = hci_packets.LeAddDeviceToConnectListBuilder(
            hci_packets.ConnectListAddressType.RANDOM, '0C:05:04:03:02:01')
        self.dut_hal.send_hci_command(command)

        assertThat(self.dut_hal.get_hci_event_stream()).emits(
            HciMatchers.LoopbackOf(command))
Exemplo n.º 4
0
    def test_fetch_hci_event(self):
        with EventStream(self.dut.hal.FetchHciEvent(
                empty_pb2.Empty())) as hci_event_stream:

            self.send_dut_hci_command(
                hci_packets.LeAddDeviceToConnectListBuilder(
                    hci_packets.ConnectListAddressType.RANDOM,
                    '0C:05:04:03:02:01'))
            event = hci_packets.LeAddDeviceToConnectListCompleteBuilder(
                1, hci_packets.ErrorCode.SUCCESS)

            assertThat(hci_event_stream).emits(
                lambda packet: bytes(event.Serialize()) in packet.payload)
Exemplo n.º 5
0
    def test_loopback_hci_command(self):
        with EventStream(self.dut.hal.FetchHciEvent(
                empty_pb2.Empty())) as hci_event_stream:

            self.send_dut_hci_command(
                hci_packets.WriteLoopbackModeBuilder(
                    hci_packets.LoopbackMode.ENABLE_LOCAL))

            command = hci_packets.LeAddDeviceToConnectListBuilder(
                hci_packets.ConnectListAddressType.RANDOM, '0C:05:04:03:02:01')
            self.send_dut_hci_command(command)

            assertThat(hci_event_stream).emits(
                lambda packet: bytes(command.Serialize()) in packet.payload)
Exemplo n.º 6
0
    def test_le_connect_list_connection_cert_advertises(self):
        with EventStream(self.dut.hal.FetchHciEvent(empty_pb2.Empty())) as hci_event_stream, \
            EventStream(self.cert.hal.FetchHciEvent(empty_pb2.Empty())) as cert_hci_event_stream:

            # DUT Connects
            self.send_dut_hci_command(
                hci_packets.LeSetRandomAddressBuilder('0D:05:04:03:02:01'))
            self.send_dut_hci_command(
                hci_packets.LeAddDeviceToConnectListBuilder(
                    hci_packets.ConnectListAddressType.RANDOM,
                    '0C:05:04:03:02:01'))
            phy_scan_params = hci_packets.LeCreateConnPhyScanParameters()
            phy_scan_params.scan_interval = 0x60
            phy_scan_params.scan_window = 0x30
            phy_scan_params.conn_interval_min = 0x18
            phy_scan_params.conn_interval_max = 0x28
            phy_scan_params.conn_latency = 0
            phy_scan_params.supervision_timeout = 0x1f4
            phy_scan_params.min_ce_length = 0
            phy_scan_params.max_ce_length = 0
            self.send_dut_hci_command(
                hci_packets.LeExtendedCreateConnectionBuilder(
                    hci_packets.InitiatorFilterPolicy.USE_CONNECT_LIST,
                    hci_packets.OwnAddressType.RANDOM_DEVICE_ADDRESS,
                    hci_packets.AddressType.RANDOM_DEVICE_ADDRESS,
                    'BA:D5:A4:A3:A2:A1', 1, [phy_scan_params]))

            # CERT Advertises
            advertising_handle = 1
            self.send_cert_hci_command(
                hci_packets.LeSetExtendedAdvertisingLegacyParametersBuilder(
                    advertising_handle,
                    hci_packets.LegacyAdvertisingProperties.ADV_IND,
                    512,
                    768,
                    7,
                    hci_packets.OwnAddressType.RANDOM_DEVICE_ADDRESS,
                    hci_packets.PeerAddressType.
                    PUBLIC_DEVICE_OR_IDENTITY_ADDRESS,
                    'A6:A5:A4:A3:A2:A1',
                    hci_packets.AdvertisingFilterPolicy.ALL_DEVICES,
                    0x7F,
                    0,  # SID
                    hci_packets.Enable.DISABLED  # Scan request notification
                ))

            self.send_cert_hci_command(
                hci_packets.LeSetExtendedAdvertisingRandomAddressBuilder(
                    advertising_handle, '0C:05:04:03:02:01'))

            gap_name = hci_packets.GapData()
            gap_name.data_type = hci_packets.GapDataType.COMPLETE_LOCAL_NAME
            gap_name.data = list(bytes(b'Im_A_Cert'))

            self.send_cert_hci_command(
                hci_packets.LeSetExtendedAdvertisingDataBuilder(
                    advertising_handle,
                    hci_packets.Operation.COMPLETE_ADVERTISEMENT,
                    hci_packets.FragmentPreference.CONTROLLER_SHOULD_NOT,
                    [gap_name]))
            enabled_set = hci_packets.EnabledSet()
            enabled_set.advertising_handle = 1
            enabled_set.duration = 0
            enabled_set.max_extended_advertising_events = 0
            self.send_cert_hci_command(
                hci_packets.LeSetExtendedAdvertisingEnableBuilder(
                    hci_packets.Enable.ENABLED, [enabled_set]))

            # LeConnectionComplete
            cert_hci_event_stream.assert_event_occurs(
                lambda packet: b'\x3e\x13\x01\x00' in packet.payload,
                timeout=timedelta(seconds=20))
            hci_event_stream.assert_event_occurs(
                lambda packet: b'\x3e\x13\x01\x00' in packet.payload,
                timeout=timedelta(seconds=20))
Exemplo n.º 7
0
 def add_to_connect_list(self, remote_addr):
     self.send_hci_command(
         hci_packets.LeAddDeviceToConnectListBuilder(
             hci_packets.ConnectListAddressType.RANDOM, remote_addr))