Ejemplo n.º 1
0
    def _set_name(self):
        padded_name = self.cert_name
        while len(padded_name) < 248:
            padded_name = padded_name + b'\0'
        self.cert_hci.send_command(hci_packets.WriteLocalNameBuilder(padded_name))

        assertThat(self.cert_hci.get_event_stream()).emits(HciMatchers.CommandComplete(OpCode.WRITE_LOCAL_NAME))
Ejemplo n.º 2
0
 def start(self):
     enabled_set = EnabledSet()
     enabled_set.advertising_handle = self.handle
     enabled_set.duration = 0
     enabled_set.max_extended_advertising_events = 0
     self.py_hci.send_command(LeSetExtendedAdvertisingEnableBuilder(Enable.ENABLED, [enabled_set]))
     assertThat(self.py_hci.get_event_stream()).emits(
         HciMatchers.CommandComplete(OpCode.LE_SET_EXTENDED_ADVERTISING_ENABLE))
Ejemplo n.º 3
0
 def enable_secure_simple_pairing(self):
     """
         This is called when you want to enable SSP for testing
     """
     logging.info("Cert: Sending WRITE_SIMPLE_PAIRING_MODE [True]")
     self._enqueue_hci_command(
         hci_packets.WriteSimplePairingModeBuilder(
             hci_packets.Enable.ENABLED), True)
     logging.info("Cert: Waiting for controller response")
     assertThat(self._hci_event_stream).emits(
         HciMatchers.CommandComplete(
             hci_packets.OpCode.WRITE_SIMPLE_PAIRING_MODE))
Ejemplo n.º 4
0
 def enable_secure_connections(self):
     """
         This is called when you want to enable secure connections support
     """
     logging.info(
         "Cert: Sending WRITE_SECURE_CONNECTIONS_HOST_SUPPORT [True]")
     self._enqueue_hci_command(
         hci_packets.WriteSecureConnectionsHostSupportBuilder(
             hci_packets.Enable.ENABLED), True)
     logging.info("Cert: Waiting for controller response")
     assertThat(self._hci_event_stream).emits(
         HciMatchers.CommandComplete(
             hci_packets.OpCode.WRITE_SECURE_CONNECTIONS_HOST_SUPPORT))
Ejemplo n.º 5
0
 def ReadBdAddrCompleteCapture():
     return Capture(
         HciMatchers.CommandComplete(hci_packets.OpCode.READ_BD_ADDR),
         lambda packet: hci_packets.ReadBdAddrCompleteView(
             HciMatchers.ExtractMatchingCommandComplete(
                 packet.event, hci_packets.OpCode.READ_BD_ADDR)))
Ejemplo n.º 6
0
 def ReadLocalOobExtendedDataCompleteCapture():
     return Capture(
         HciMatchers.CommandComplete(hci_packets.OpCode.READ_LOCAL_OOB_EXTENDED_DATA),
         lambda packet: HciMatchers.ExtractMatchingCommandComplete(packet.payload, hci_packets.OpCode.READ_LOCAL_OOB_EXTENDED_DATA)
     )
Ejemplo n.º 7
0
 def wait_for_complete(self, opcode):
     assertThat(self.hci_event_stream).emits(
         HciMatchers.CommandComplete(opcode))
Ejemplo n.º 8
0
    def test_le_connection_dut_advertises(self):
        self.dut_hci.register_for_le_events(
            hci_packets.SubeventCode.CONNECTION_COMPLETE)
        # Cert Connects
        self.send_hal_hci_command(
            hci_packets.LeSetRandomAddressBuilder('0C:05:04:03:02:01'))
        phy_scan_params = DirectHciTest._create_phy_scan_params()
        self.send_hal_hci_command(
            hci_packets.LeExtendedCreateConnectionBuilder(
                hci_packets.InitiatorFilterPolicy.USE_PEER_ADDRESS,
                hci_packets.OwnAddressType.RANDOM_DEVICE_ADDRESS,
                hci_packets.AddressType.RANDOM_DEVICE_ADDRESS,
                '0D:05:04:03:02:01', 1, [phy_scan_params]))

        # DUT Advertises
        advertising_handle = 0
        self.dut_hci.send_command_with_complete(
            hci_packets.LeSetExtendedAdvertisingLegacyParametersBuilder(
                advertising_handle,
                hci_packets.LegacyAdvertisingProperties.ADV_IND,
                400,
                450,
                7,
                hci_packets.OwnAddressType.RANDOM_DEVICE_ADDRESS,
                hci_packets.PeerAddressType.PUBLIC_DEVICE_OR_IDENTITY_ADDRESS,
                '00:00:00:00:00:00',
                hci_packets.AdvertisingFilterPolicy.ALL_DEVICES,
                0xF8,
                1,  #SID
                hci_packets.Enable.DISABLED  # Scan request notification
            ))

        self.dut_hci.send_command_with_complete(
            hci_packets.LeSetExtendedAdvertisingRandomAddressBuilder(
                advertising_handle, '0D: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_The_DUT!'))  # TODO: Fix and remove !

        self.dut_hci.send_command_with_complete(
            hci_packets.LeSetExtendedAdvertisingDataBuilder(
                advertising_handle,
                hci_packets.Operation.COMPLETE_ADVERTISEMENT,
                hci_packets.FragmentPreference.CONTROLLER_SHOULD_NOT,
                [gap_name]))

        gap_short_name = hci_packets.GapData()
        gap_short_name.data_type = hci_packets.GapDataType.SHORTENED_LOCAL_NAME
        gap_short_name.data = list(bytes(b'Im_The_D'))

        self.dut_hci.send_command_with_complete(
            hci_packets.LeSetExtendedAdvertisingScanResponseBuilder(
                advertising_handle,
                hci_packets.Operation.COMPLETE_ADVERTISEMENT,
                hci_packets.FragmentPreference.CONTROLLER_SHOULD_NOT,
                [gap_short_name]))

        enabled_set = hci_packets.EnabledSet()
        enabled_set.advertising_handle = advertising_handle
        enabled_set.duration = 0
        enabled_set.max_extended_advertising_events = 0
        self.dut_hci.send_command_with_complete(
            hci_packets.LeSetExtendedAdvertisingEnableBuilder(
                hci_packets.Enable.ENABLED, [enabled_set]))

        # Check for success of Enable
        assertThat(self.dut_hci.get_event_stream()).emits(
            HciMatchers.CommandComplete(
                hci_packets.OpCode.LE_SET_EXTENDED_ADVERTISING_ENABLE))

        (dut_handle, cert_handle) = self._verify_le_connection_complete()

        # Send ACL Data
        self.enqueue_acl_data(
            dut_handle,
            hci_packets.PacketBoundaryFlag.FIRST_NON_AUTOMATICALLY_FLUSHABLE,
            hci_packets.BroadcastFlag.POINT_TO_POINT,
            bytes(b'Just SomeAclData'))
        self.send_hal_acl_data(
            cert_handle,
            hci_packets.PacketBoundaryFlag.FIRST_NON_AUTOMATICALLY_FLUSHABLE,
            hci_packets.BroadcastFlag.POINT_TO_POINT,
            bytes(b'Just SomeMoreAclData'))

        assertThat(
            self.cert_hal.get_acl_stream()).emits(lambda packet: logging.debug(
                packet.payload) or b'SomeAclData' in packet.payload)
        assertThat(self.dut_hci.get_raw_acl_stream()).emits(
            lambda packet: logging.debug(
                packet.data) or b'SomeMoreAclData' in packet.data)