def test_ATT_Client_Discover_Characteristic_Descriptors(self, iut, valid): btp.gap_conn(iut, self.config.tester_addr) btp.gap_wait_for_connection(iut) db = GattDB() btp.gattc_disc_prim_svcs(iut, self.config.tester_addr) btp.gattc_disc_prim_svcs_rsp(iut, db) for svc in db.get_services(): start, end = svc.handle, svc.end_hdl btp.gattc_disc_all_chrc(iut, self.config.tester_addr, start, end) btp.gattc_disc_all_chrc_rsp(iut, db) for char in db.get_characteristics(): start_hdl = char.value_handle + 1 end_hdl = db.find_characteristic_end(char.handle) if not end_hdl: # There are no descriptors there so continue continue # Defensics expects to receive a Request with start handle == end handle if end_hdl == 0xffff: end_hdl = start_hdl btp.gattc_disc_all_desc(iut, self.config.tester_addr, start_hdl, end_hdl) tuple_hdr, tuple_data = iut.btp_worker.read() try: btp.btp_hdr_check(tuple_hdr, defs.BTP_SERVICE_ID_GATT, defs.GATT_DISC_ALL_DESC) except BTPErrorInvalidStatus: pass
def connection_procedure(testcase, central, peripheral): btp.gap_set_conn(peripheral) btp.gap_set_gendiscov(peripheral) uuid = os.urandom(2) btp.gap_adv_ind_on(peripheral, ad=[(AdType.uuid16_some, uuid)]) def verify_f(args): return find_adv_by_uuid(args, btp.btp2uuid(len(uuid), uuid)) btp.gap_start_discov(central) future = btp.gap_device_found_ev(central, verify_f) wait_futures([future], timeout=EV_TIMEOUT) btp.gap_stop_discov(central) found = future.result() testcase.assertIsNotNone(found) peripheral.stack.gap.iut_addr_set(found.addr) def verify_central(args): return verify_address(args, found.addr) future_central = btp.gap_connected_ev(central, verify_central) future_peripheral = btp.gap_connected_ev(peripheral) btp.gap_conn(central, peripheral.stack.gap.iut_addr_get()) wait_futures([future_central, future_peripheral], timeout=EV_TIMEOUT) testcase.assertTrue(central.stack.gap.is_connected()) testcase.assertTrue(peripheral.stack.gap.is_connected()) central_addr, _ = future_peripheral.result() central.stack.gap.iut_addr_set(central_addr)
def hdl_wid_51(_: WIDParams): """ Implements: TSC_MMI_iut_enable_le_connection description: Initiate or create LE ACL connection to the PTS. """ btp.gap_conn() return True
def hdl_wid_51(desc): """ Implements: TSC_MMI_iut_enable_le_connection :param desc: Initiate or create LE ACL connection to the PTS. :return: """ btp.gap_conn() return True
def test_ATT_Client_Exchange_MTU(self, iut, valid): btp.gap_conn(iut, self.config.tester_addr) btp.gap_wait_for_connection(iut) btp.gattc_exchange_mtu(iut, self.config.tester_addr) tuple_hdr, tuple_data = iut.btp_worker.read() try: btp.btp_hdr_check(tuple_hdr, defs.BTP_SERVICE_ID_GATT, defs.GATT_EXCHANGE_MTU) except BTPErrorInvalidStatus: pass
def hdl_wid_402(_: WIDParams): # Please perform the General Connection Establishment Procedure using RPA # then resolve the PTS address and connect with PTS. stack = get_stack() if not stack.gap.iut_has_privacy(): return False btp.gap_conn() return True
def test_ATT_Client_Write_Attribute_Value(self, iut, valid): btp.gap_conn(iut, self.config.tester_addr) btp.gap_wait_for_connection(iut) btp.gattc_write(iut, self.config.tester_addr, self.config.tester_write_hdl, '00') tuple_hdr, tuple_data = iut.btp_worker.read() try: btp.btp_hdr_check(tuple_hdr, defs.BTP_SERVICE_ID_GATT, defs.GATT_WRITE) except BTPErrorInvalidStatus: pass
def test_ATT_Client_Discover_Service_by_uuid(self, iut, valid): btp.gap_conn(iut, self.config.tester_addr) btp.gap_wait_for_connection(iut) btp.gattc_disc_prim_uuid(iut, self.config.tester_addr, self.config.tester_service_uuid) tuple_hdr, tuple_data = iut.btp_worker.read() try: btp.btp_hdr_check(tuple_hdr, defs.BTP_SERVICE_ID_GATT, defs.GATT_DISC_PRIM_UUID) except BTPErrorInvalidStatus: pass
def test_SMP_Client_SC_Passkey_Entry(self, iut, valid): btp.gap_set_io_cap(iut, IOCap.keyboard_display) btp.gap_conn(iut, self.config.tester_addr) btp.gap_wait_for_connection(iut) future = btp.gap_passkey_entry_req_ev(iut) try: wait_futures([future], timeout=EV_TIMEOUT) btp.gap_passkey_entry_rsp(iut, self.config.tester_addr, self.config.tester_passkey) except (TimeoutError, BTPErrorInvalidStatus) as e: if valid: raise e
def test_ATT_Client_Discover_All_Characteristics(self, iut, valid): btp.gap_conn(iut, self.config.tester_addr) btp.gap_wait_for_connection(iut) btp.gattc_disc_all_chrc(iut, self.config.tester_addr, start_hdl=1, stop_hdl=0xffff) tuple_hdr, tuple_data = iut.btp_worker.read() try: btp.btp_hdr_check(tuple_hdr, defs.BTP_SERVICE_ID_GATT, defs.GATT_DISC_ALL_CHRC) except BTPErrorInvalidStatus: pass
def test_SMP_Client_SC_Numeric_Comparison(self, iut, valid): btp.gap_set_io_cap(iut, IOCap.keyboard_display) btp.gap_conn(iut, self.config.tester_addr) btp.gap_wait_for_connection(iut) future = btp.gap_passkey_confirm_req_ev(iut) try: wait_futures([future], timeout=EV_TIMEOUT) results = future.result() pk_iut = results[1] assert (pk_iut is not None) btp.gap_passkey_confirm(iut, self.config.tester_addr, 1) except (TimeoutError, BTPErrorInvalidStatus) as e: if valid: raise e
def hdl_wid_403(_: WIDParams): # Please perform the Directed Connection Establishment Procedure using RPA # then resolve the PTS address and connect with PTS. stack = get_stack() if not stack.gap.iut_has_privacy(): return False if stack.gap.peripheral.data: bd_addr = btp.pts_addr_get() bd_addr_type = btp.pts_addr_type_get() btp.gap_direct_adv_on(bd_addr, bd_addr_type, 0, 1) else: btp.gap_conn() return True
def test_ATT_Client_Discover_Primary_Services(self, iut, valid): btp.gap_conn(iut, self.config.tester_addr) btp.gap_wait_for_connection(iut) btp.gattc_disc_prim_svcs(iut, self.config.tester_addr) tuple_hdr, tuple_data = iut.btp_worker.read() try: btp.btp_hdr_check(tuple_hdr, defs.BTP_SERVICE_ID_GATT, defs.GATT_DISC_PRIM_SVCS) except BTPErrorInvalidStatus: pass try: # In some test cases Defensics won't disconnect # so we have to try to disconnect ourselves btp.gap_disconn(iut, self.config.tester_addr) except BTPErrorInvalidStatus: pass
def test_btp_GAP_CONN_DCON_1(self): """ Verify the IUT1 in the Directed Connectable Mode can connect with another device performing the General Connection Establishment Procedure. The IUT1 is operating in the Peripheral role. """ connection_procedure(self, central=self.iut2, peripheral=self.iut1) iut_addr = self.iut1.stack.gap.iut_addr_get() iut2_addr = self.iut2.stack.gap.iut_addr_get() def verify_iut1(args): return verify_address(args, iut2_addr) def verify_iut2(args): return verify_address(args, iut_addr) future_iut1 = btp.gap_sec_level_changed_ev(self.iut1, verify_iut1) future_iut2 = btp.gap_sec_level_changed_ev(self.iut2, verify_iut2) btp.gap_pair(self.iut1, self.iut2.stack.gap.iut_addr_get()) wait_futures([future_iut1, future_iut2], timeout=EV_TIMEOUT) disconnection_procedure(self, central=self.iut2, peripheral=self.iut1) btp.gap_start_direct_adv(self.iut1, self.iut2.stack.gap.iut_addr_get()) def verify_central(args): return verify_address(args, self.iut1.stack.gap.iut_addr_get()) future_central = btp.gap_connected_ev(self.iut2, verify_central) future_peripheral = btp.gap_connected_ev(self.iut1) btp.gap_conn(self.iut2, self.iut1.stack.gap.iut_addr_get()) wait_futures([future_central, future_peripheral], timeout=EV_TIMEOUT) self.assertTrue(self.iut2.stack.gap.is_connected()) self.assertTrue(self.iut1.stack.gap.is_connected()) disconnection_procedure(self, central=self.iut2, peripheral=self.iut1)
def test_ATT_Client_Read_Long_Attribute_Value(self, iut, valid): btp.gap_conn(iut, self.config.tester_addr) btp.gap_wait_for_connection(iut) btp.gattc_read_long(iut, self.config.tester_addr, self.config.tester_read_hdl, 0) tuple_hdr, tuple_data = iut.btp_worker.read() try: btp.btp_hdr_check(tuple_hdr, defs.BTP_SERVICE_ID_GATT, defs.GATT_READ_LONG) except BTPErrorInvalidStatus: pass try: # In some test cases Defensics won't disconnect # so we have to try to disconnect ourselves btp.gap_disconn(iut, self.config.tester_addr) except BTPErrorInvalidStatus: pass
def hdl_wid_148(_: WIDParams): btp.gap_conn() return not btp.gap_wait_for_connection(10)
def hdl_wid_100(desc): btp.gap_conn() btp.gap_wait_for_connection() btp.gap_pair() return True
def hdl_wid_78(desc): btp.gap_conn() btp.gap_wait_for_connection() return True
def hdl_wid_100(_: WIDParams): btp.gap_conn() return get_stack().gap.wait_for_connection(30)
def hdl_wid_78(desc): btp.gap_conn() return True
def hdl_wid_100(desc): btp.gap_conn() return get_stack().gap.wait_for_connection(30)
def hdl_wid_20100(desc): btp.gap_conn() return True
def hdl_wid_101(_: WIDParams): btp.gap_conn() return True
def hdl_wid_148(desc): btp.gap_conn() return not btp.gap_wait_for_connection(10)
def hdl_wid_20100(_: WIDParams): btp.gap_conn() return True
def hdl_wid_2142(desc): btp.gap_conn() return True
def test_SMP_Client_SC_Just_Works(self, iut, valid): btp.gap_set_io_cap(iut, IOCap.keyboard_display) btp.gap_conn(iut, self.config.tester_addr) btp.gap_wait_for_connection(iut)