예제 #1
0
    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
예제 #2
0
 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
예제 #3
0
    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
예제 #4
0
    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
예제 #5
0
    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
예제 #6
0
def receive(exp_svc_id=None, exp_op=None):
    """The parameters are the values used in the command, so response is
    expected to have the same value

    """
    logging.debug("%s %r %r", receive.__name__, exp_svc_id, exp_op)

    if conn_check() is False:
        return

    try:
        tuple_hdr, tuple_data = BTP_SOCKET.read()
    except KeyboardInterrupt:
        print("\nReceive interrupted!")
        return

    # default __repr__ of namedtuple does not print hex
    print(
        "Received header(svc_id=%d, op=0x%.2x, ctrl_index=%d, data_len=%d)" %
        (tuple_hdr.svc_id, tuple_hdr.op, tuple_hdr.ctrl_index,
         tuple_hdr.data_len))

    hex_str = binascii.hexlify(tuple_data[0])
    hex_str_byte = " ".join(hex_str[i:i + 2]
                            for i in range(0, len(hex_str), 2))
    print("Received data (hex): %s" % hex_str_byte)
    print("Received data (ascii):", tuple_data)

    if exp_svc_id is None and exp_op is None:
        return

    try:
        btp.btp_hdr_check(tuple_hdr, exp_svc_id, exp_op)
    except btp.BTPError as err:
        print(red("%s\nExpected svc_id=%s, op=0x%.2x" %
                  (err, exp_svc_id, exp_op)))
        return

    if tuple_hdr.svc_id == defs.BTP_SERVICE_ID_GAP:
        if tuple_hdr.op == defs.GAP_EV_PASSKEY_DISPLAY:
            passkey = struct.unpack('I', tuple_data[0][7:11])[0]
            print("Passkey:", passkey)
        if tuple_hdr.op == defs.GAP_READ_CONTROLLER_INFO:
            print_controller_info(tuple_data[0])
    print(green("OK"))
예제 #7
0
    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
예제 #8
0
    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