def setup_test(self): super().setup_test() self.dut.address = self.dut.controller_read_only_property.ReadLocalAddress( empty_proto.Empty()).address self.cert.address = self.cert.controller_read_only_property.ReadLocalAddress( empty_proto.Empty()).address self.dut.neighbor.EnablePageScan( neighbor_facade.EnableMsg(enabled=True)) self.cert.neighbor.EnablePageScan( neighbor_facade.EnableMsg(enabled=True)) self.dut_address = common.BluetoothAddress(address=self.dut.address) self.cert_address = common.BluetoothAddress(address=self.cert.address) self.dut_address_with_type = common.BluetoothAddressWithType() self.dut_address_with_type.address.CopyFrom(self.dut_address) self.dut_address_with_type.type = common.BluetoothPeerAddressTypeEnum.PUBLIC_DEVICE_OR_IDENTITY_ADDRESS self.cert_address_with_type = common.BluetoothAddressWithType() self.cert_address_with_type.address.CopyFrom(self.cert_address) self.cert_address_with_type.type = common.BluetoothPeerAddressTypeEnum.PUBLIC_DEVICE_OR_IDENTITY_ADDRESS self.dut.wait_channel_ready() self.cert.wait_channel_ready() self.cert_name = b'ImTheCert' self.cert.hci_controller.WriteLocalName( controller_facade.NameMsg(name=self.cert_name)) self.dut_name = b'ImTheDUT' self.dut.hci_controller.WriteLocalName( controller_facade.NameMsg(name=self.dut_name))
def setup_test(self): super().setup_test() self.dut.neighbor.EnablePageScan( neighbor_facade.EnableMsg(enabled=True)) self.cert.neighbor.EnablePageScan( neighbor_facade.EnableMsg(enabled=True)) self.dut.name = b'DUT Device' self.dut.address = self.dut.hci_controller.GetMacAddress( empty_proto.Empty()).address self.cert.name = b'Cert Device' self.cert.address = self.cert.hci_controller.GetMacAddress( empty_proto.Empty()).address # TODO(optedoblivion): Make this happen in PySecurity or GdDevice self.dut.hci_controller.WriteLocalName( controller_facade.NameMsg(name=self.dut.name)) self.cert.hci_controller.WriteLocalName( controller_facade.NameMsg(name=self.cert.name)) self.dut_security = PySecurity(self.dut) self.cert_security = CertSecurity(self.cert) self.dut_address = common.BluetoothAddressWithType( address=common.BluetoothAddress( address=bytes(b'DD:05:04:03:02:01')), type=common.RANDOM_DEVICE_ADDRESS) privacy_policy = le_initiator_address_facade.PrivacyPolicy( address_policy=le_initiator_address_facade.AddressPolicy. USE_STATIC_ADDRESS, address_with_type=self.dut_address) self.dut.security.SetLeInitiatorAddressPolicy(privacy_policy)
def setup_test(self): self.device_under_test.rootservice.StartStack( facade_rootservice_pb2.StartStackRequest( module_under_test=facade_rootservice_pb2.BluetoothModule.Value( 'SECURITY'), )) self.cert_device.rootservice.StartStack( facade_rootservice_pb2.StartStackRequest( module_under_test=facade_rootservice_pb2.BluetoothModule.Value( 'L2CAP'), )) self.device_under_test.address = self.device_under_test.controller_read_only_property.ReadLocalAddress( empty_proto.Empty()).address self.cert_device.address = self.cert_device.controller_read_only_property.ReadLocalAddress( empty_proto.Empty()).address self.device_under_test.neighbor.EnablePageScan( neighbor_facade.EnableMsg(enabled=True)) self.cert_device.neighbor.EnablePageScan( neighbor_facade.EnableMsg(enabled=True)) self.dut_address = common.BluetoothAddress( address=self.device_under_test.address) self.cert_address = common.BluetoothAddress( address=self.cert_device.address) self.dut_address_with_type = common.BluetoothAddressWithType() self.dut_address_with_type.address.CopyFrom(self.dut_address) self.dut_address_with_type.type = common.BluetoothPeerAddressTypeEnum.PUBLIC_DEVICE_OR_IDENTITY_ADDRESS self.cert_address_with_type = common.BluetoothAddressWithType() self.cert_address_with_type.address.CopyFrom(self.cert_address) self.cert_address_with_type.type = common.BluetoothPeerAddressTypeEnum.PUBLIC_DEVICE_OR_IDENTITY_ADDRESS self.device_under_test.wait_channel_ready() self.cert_device.wait_channel_ready() self.cert_name = b'ImTheCert' self.cert_device.hci_controller.WriteLocalName( controller_facade.NameMsg(name=self.cert_name)) self.dut_name = b'ImTheDUT' self.device_under_test.hci_controller.WriteLocalName( controller_facade.NameMsg(name=self.dut_name))
def setup_test(self): super().setup_test() self.dut.neighbor.EnablePageScan( neighbor_facade.EnableMsg(enabled=True)) self.cert.neighbor.EnablePageScan( neighbor_facade.EnableMsg(enabled=True)) self.dut.name = b'DUT Device' self.dut.address = self.dut.hci_controller.GetMacAddress( empty_proto.Empty()).address self.cert.name = b'Cert Device' self.cert.address = self.cert.hci_controller.GetMacAddress( empty_proto.Empty()).address # TODO(optedoblivion): Make this happen in PySecurity or GdDevice self.dut.hci_controller.WriteLocalName( controller_facade.NameMsg(name=self.dut.name)) self.cert.hci_controller.WriteLocalName( controller_facade.NameMsg(name=self.cert.name)) self.dut_security = PySecurity(self.dut) self.cert_security = CertSecurity(self.cert)
def setup_test(self): self.device_under_test = self.gd_devices[0] self.device_under_test.rootservice.StartStack( facade_rootservice_pb2.StartStackRequest( module_under_test=facade_rootservice_pb2.BluetoothModule.Value('L2CAP'),)) self.device_under_test.wait_channel_ready() dut_address = self.device_under_test.controller_read_only_property.ReadLocalAddress(empty_pb2.Empty()).address pts_address = self.controller_configs.get('pts_address').lower() self.device_under_test.address = dut_address self.dut_address = common_pb2.BluetoothAddress(address=self.device_under_test.address) self.pts_address = common_pb2.BluetoothAddress(address=str.encode(pts_address)) self.device_under_test.neighbor.EnablePageScan(neighbor_facade.EnableMsg(enabled=True))
def test_cert_connects(self): dut_address = self.dut.hci_controller.GetMacAddressSimple() self.dut.neighbor.EnablePageScan( neighbor_facade.EnableMsg(enabled=True)) self.dut_acl_manager.listen_for_an_incoming_connection() self.cert_hci.initiate_connection(dut_address) with self.dut_acl_manager.complete_incoming_connection() as dut_acl: cert_acl = self.cert_hci.complete_connection() dut_acl.send( b'\x29\x00\x07\x00This is just SomeMoreAclData from the DUT') cert_acl.send_first( b'\x26\x00\x07\x00This is just SomeAclData from the Cert') assertThat(cert_acl).emits( lambda packet: b'SomeMoreAclData' in packet.payload) assertThat(dut_acl).emits( lambda packet: b'SomeAclData' in packet.payload)
def test_reject_broadcast(self): dut_address = self.dut.hci_controller.GetMacAddressSimple() self.dut.neighbor.EnablePageScan( neighbor_facade.EnableMsg(enabled=True)) self.dut_acl_manager.listen_for_an_incoming_connection() self.cert_hci.initiate_connection(dut_address) with self.dut_acl_manager.complete_incoming_connection() as dut_acl: cert_acl = self.cert_hci.complete_connection() cert_acl.send( hci_packets.PacketBoundaryFlag.FIRST_AUTOMATICALLY_FLUSHABLE, hci_packets.BroadcastFlag.ACTIVE_PERIPHERAL_BROADCAST, b'\x26\x00\x07\x00This is a Broadcast from the Cert') assertThat(dut_acl).emitsNone() cert_acl.send( hci_packets.PacketBoundaryFlag.FIRST_AUTOMATICALLY_FLUSHABLE, hci_packets.BroadcastFlag.POINT_TO_POINT, b'\x26\x00\x07\x00This is just SomeAclData from the Cert') assertThat(dut_acl).emits( lambda packet: b'SomeAclData' in packet.payload)
def _setup_link_from_cert(self): self.dut.neighbor.EnablePageScan( neighbor_facade.EnableMsg(enabled=True)) self.cert_l2cap.connect_acl(self.dut.address)
def test_cert_connects(self): self.register_for_event(hci_packets.EventCode.CONNECTION_COMPLETE) self.register_for_event(hci_packets.EventCode.ROLE_CHANGE) self.register_for_event( hci_packets.EventCode.CONNECTION_PACKET_TYPE_CHANGED) with EventCallbackStream(self.cert_device.hci.FetchEvents(empty_proto.Empty())) as cert_hci_event_stream, \ EventCallbackStream(self.cert_device.hci.FetchAclPackets(empty_proto.Empty())) as cert_acl_data_stream, \ EventCallbackStream(self.device_under_test.hci_acl_manager.FetchIncomingConnection(empty_proto.Empty())) as incoming_connection_stream, \ EventCallbackStream(self.device_under_test.hci_acl_manager.FetchAclData(empty_proto.Empty())) as acl_data_stream: cert_hci_event_asserts = EventAsserts(cert_hci_event_stream) incoming_connection_asserts = EventAsserts( incoming_connection_stream) cert_acl_data_asserts = EventAsserts(cert_acl_data_stream) acl_data_asserts = EventAsserts(acl_data_stream) # DUT Enables scans and gets its address dut_address = self.device_under_test.hci_controller.GetMacAddress( empty_proto.Empty()).address self.device_under_test.neighbor.EnablePageScan( neighbor_facade.EnableMsg(enabled=True)) # Cert connects self.enqueue_hci_command( hci_packets.CreateConnectionBuilder( dut_address.decode('utf-8'), 0xcc18, # Packet Type hci_packets.PageScanRepetitionMode.R1, 0x0, hci_packets.ClockOffsetValid.INVALID, hci_packets.CreateConnectionRoleSwitch.ALLOW_ROLE_SWITCH), False) conn_handle = 0xfff def get_handle(packet): packet_bytes = packet.event if b'\x03\x0b\x00' in packet_bytes: nonlocal conn_handle cc_view = hci_packets.ConnectionCompleteView( hci_packets.EventPacketView( bt_packets.PacketViewLittleEndian( list(packet_bytes)))) conn_handle = cc_view.GetConnectionHandle() return True return False # DUT gets a connection request incoming_connection_asserts.assert_event_occurs(get_handle) self.device_under_test.hci_acl_manager.SendAclData( acl_manager_facade.AclData( handle=conn_handle, payload=bytes( b'\x29\x00\x07\x00This is just SomeMoreAclData from the DUT' ))) conn_handle = 0xfff cert_hci_event_asserts.assert_event_occurs(get_handle) cert_handle = conn_handle self.enqueue_acl_data( cert_handle, hci_packets.PacketBoundaryFlag.FIRST_AUTOMATICALLY_FLUSHABLE, hci_packets.BroadcastFlag.POINT_TO_POINT, bytes( b'\x26\x00\x07\x00This is just SomeAclData from the Cert')) cert_acl_data_asserts.assert_event_occurs( lambda packet: b'SomeMoreAclData' in packet.data) acl_data_asserts.assert_event_occurs( lambda packet: b'SomeAclData' in packet.payload)