Beispiel #1
0
def hdl_wid_24(desc):
    MMI.reset()
    MMI.parse_description(desc)

    db = gatt_server_fetch_db()

    if MMI.args:
        incl_handle = int(MMI.args[1], 16)
        attr = db.attr_lookup_handle(incl_handle)
        if attr is None or not isinstance(attr, GattService):
            logging.error("service not found")
            return False

        incl_uuid = attr.uuid
        attr = db.attr_lookup_handle(int(MMI.args[0], 16))
        if attr is None or not isinstance(attr, GattServiceIncluded):
            logging.error("included not found")
            return False

        if attr.end_grp_hdl != int(MMI.args[2], 16) \
                or incl_uuid != MMI.args[3]:
            logging.error("end group handle not found")
            return False

        return True
Beispiel #2
0
def hdl_wid_52(params: WIDParams):
    if params.test_case_name.startswith('GATT/CL'):
        return btp.verify_description(params.description)

    MMI.reset()
    MMI.parse_description(params.description)

    handle = int(MMI.args[0], 16)
    value = MMI.args[1]

    db = gatt_server_fetch_db()
    attr = db.attr_lookup_handle(handle)
    if attr is None:
        return False

    if not isinstance(attr, GattCharacteristicDescriptor):
        return False

    if attr.uuid == UUID.CEP:
        (value_read, ) = struct.unpack("<H", attr.value)
        value_read = '{0:04x}'.format(value_read)
    else:
        value_read = hexlify(attr.value).upper()

    value_read = value_read.decode('utf-8')
    if value_read != value:
        return False

    return True
Beispiel #3
0
def hdl_wid_56(desc):
    MMI.reset()
    MMI.parse_description(desc)

    if not MMI.args or len(MMI.args) != 3:
        logging.error("parsing error")

    handle1 = MMI.args[0]
    handle2 = MMI.args[1]
    values = MMI.args[2]

    values_read = ""

    att_rsp, value_len, value = btp.gatts_get_attr_val(btp.pts_addr_type_get(),
                                                       btp.pts_addr_get(),
                                                       handle1)
    values_read += hexlify(value).decode('utf-8')

    att_rsp, value_len, value = btp.gatts_get_attr_val(btp.pts_addr_type_get(),
                                                       btp.pts_addr_get(),
                                                       handle2)
    values_read += hexlify(value).decode('utf-8')

    if values_read.upper() != values.upper():
        return False

    return True
Beispiel #4
0
def hdl_wid_52(desc):
    MMI.reset()
    MMI.parse_description(desc)

    handle = int(MMI.args[0], 16)
    value = MMI.args[1]

    db = gatt_server_fetch_db()
    attr = db.attr_lookup_handle(handle)
    if attr is None:
        return False

    if not isinstance(attr, GattCharacteristicDescriptor):
        return False

    if attr.uuid == UUID.CEP:
        (value_read, ) = struct.unpack("<H", attr.value)
        value_read = '{0:04x}'.format(value_read, 'x')
    else:
        value_read = hexlify(attr.value).upper()

    value_read = value_read.decode('utf-8')
    if value_read != value:
        return False

    return True
Beispiel #5
0
def hdl_wid_24(params: WIDParams):
    if params.test_case_name.startswith('GATT/CL'):
        return btp.verify_description(params.description)

    MMI.reset()
    MMI.parse_description(params.description)

    db = gatt_server_fetch_db()

    if not MMI.args:
        return False

    incl_handle = int(MMI.args[1], 16)
    attr = db.attr_lookup_handle(incl_handle)
    if attr is None or not isinstance(attr, GattService):
        logging.error("service not found")
        return False

    incl_uuid = attr.uuid
    attr = db.attr_lookup_handle(int(MMI.args[0], 16))
    if attr is None or not isinstance(attr, GattServiceIncluded):
        logging.error("included not found")
        return False

    if attr.end_grp_hdl != int(MMI.args[2], 16) \
            or incl_uuid != MMI.args[3]:
        logging.error("end group handle not found")
        return False

    return True
Beispiel #6
0
def hdl_wid_56(desc):
    MMI.reset()
    MMI.parse_description(desc)

    if not MMI.args or len(MMI.args) != 3:
        logging.error("parsing error")

    handle1 = MMI.args[0]
    handle2 = MMI.args[1]
    values = MMI.args[2]

    values_read = ""

    bd_addr = btp.pts_addr_get()
    bd_addr_type = btp.pts_addr_type_get()

    att_rsp, value_len, value = btp.gatts_get_attr_val(bd_addr_type, bd_addr,
                                                       handle1)
    values_read += value.hex()

    att_rsp, value_len, value = btp.gatts_get_attr_val(bd_addr_type, bd_addr,
                                                       handle2)
    values_read += value.hex()

    if values_read.upper() != values.upper():
        return False

    return True
Beispiel #7
0
def hdl_wid_17(desc):
    MMI.reset()
    MMI.parse_description(desc)
    pts_services = MMI.args
    if not pts_services:
        logging.error("%s parsing error", hdl_wid_17.__name__)
        return False

    iut_services = []

    # Get all primary services
    attrs = btp.gatts_get_attrs(type_uuid='2800')
    for attr in attrs:
        handle, perm, type_uuid = attr
        (_, uuid_len, uuid) = btp.gatts_get_attr_val(btp.pts_addr_type_get(),
                                                     btp.pts_addr_get(),
                                                     handle)
        uuid = btp.btp2uuid(uuid_len, uuid)
        iut_services.append(uuid)

    # Verification
    for service in pts_services:
        if service in iut_services:
            iut_services.remove(service)
            logging.debug("Service %s found", service)
            continue
        else:
            logging.error("Service %s not found", service)
            return False
    return True
Beispiel #8
0
def hdl_wid_141(desc):
    MMI.reset()
    MMI.parse_description(desc)

    hdl1 = MMI.args[0]
    hdl2 = MMI.args[1]
    btp.gattc_read_multiple(btp.pts_addr_type_get(), btp.pts_addr_get(), hdl1, hdl2)
    return '0000'
Beispiel #9
0
def hdl_wid_141(params: WIDParams):
    MMI.reset()
    MMI.parse_description(params.description)

    hdl1 = MMI.args[0]
    hdl2 = MMI.args[1]
    btp.gattc_read_multiple_var(btp.pts_addr_type_get(), btp.pts_addr_get(),
                                hdl1, hdl2)
    return '0000'
Beispiel #10
0
def hdl_wid_304(desc):
    MMI.reset()
    MMI.parse_description(desc)

    hdl = MMI.args[0]
    val = MMI.args[1]
    _, _, data = btp.gatts_get_attr_val(btp.pts_addr_type_get(), btp.pts_addr_get(), hdl)
    data = hexlify(data).decode().upper()
    return bool(data in val)
Beispiel #11
0
def hdl_wid_22(desc):
    MMI.reset()
    MMI.parse_description(desc)

    parsed_args = []

    for arg in MMI.args:
        parsed_args.append([char for char in arg if char != "-"])

    handles = []
    uuids = []

    # Extract UUID's from parsed arguments
    uuids_from_parse = parsed_args[::3]

    # Delete unwanted UUID values
    del parsed_args[0::3]
    parsed_handles = parsed_args

    # Convert remaining arguments to integers
    parsed_handles = [int("".join(arg), 16) for arg in parsed_handles]

    # Increment every 2th handle
    parsed_handles[1::2] = [arg + 1 for arg in parsed_handles[1::2]]

    # Get all primary services
    attrs = btp.gatts_get_attrs(type_uuid='2800')
    for attr in attrs:
        start_handle, perm, type_uuid = attr

        val = btp.gatts_get_attr_val(btp.pts_addr_type_get(),
                                     btp.pts_addr_get(), start_handle)
        if not val:
            continue

        (_, uuid_len, uuid) = val

        uuids.append(str(btp.btp2uuid(uuid_len, uuid)))
        handles.append(start_handle)

    for uuid in uuids_from_parse:
        if uuid in uuids_from_parse:
            logging.debug("UUUID %r present", uuid)
            continue
        else:
            logging.debug("UUID %r not present", uuid)
            return False
    for handle in parsed_handles:
        if handle in parsed_handles:
            logging.debug("Handle %r present", handle)
            continue
        else:
            logging.debug("Handle $r not present", handle)
            return False

    return True
def hdl_wid_76(desc):
    MMI.reset()
    MMI.parse_description(desc)

    btp.gattc_write_reliable(btp.pts_addr_type_get(), btp.pts_addr_get(),
                             MMI.args[0], 0, '12', MMI.args[1])

    btp.gattc_write_reliable_rsp(True)

    return True
def hdl_wid_51(desc):
    MMI.reset()
    MMI.parse_description(desc)

    btp.gattc_read_uuid(btp.pts_addr_type_get(), btp.pts_addr_get(),
                        MMI.args[1], MMI.args[2], MMI.args[0])

    btp.gattc_read_uuid_rsp(True)

    return True
def hdl_wid_108(desc):
    MMI.reset()
    MMI.parse_description(desc)

    btp.gattc_read_uuid(btp.pts_addr_type_get(), btp.pts_addr_get(), 0x0001,
                        0xffff, MMI.args[0])

    btp.gattc_read_uuid_rsp(True, True)

    return True
Beispiel #15
0
def hdl_wid_25(desc):
    MMI.reset()
    MMI.parse_description(desc)

    pts_chrc_uuid = MMI.args[0]
    pts_chrc_handles = [
        int(MMI.args[1], 16),
        int(MMI.args[2], 16),
        int(MMI.args[3], 16),
        int(MMI.args[4], 16)
    ]

    iut_start_handle = None
    iut_end_handle = None

    bd_addr = btp.pts_addr_get()
    bd_addr_type = btp.pts_addr_type_get()

    # Find pts_chrc_uuid service and it's handle range
    svcs = btp.gatts_get_attrs(type_uuid='2800')
    for svc in svcs:
        handle, perm, type_uuid = svc

        if iut_start_handle:
            iut_end_handle = handle - 1
            break

        svc_val = btp.gatts_get_attr_val(bd_addr_type, bd_addr, handle)
        if not svc_val:
            continue

        att_rsp, uuid_len, uuid = svc_val
        if btp.btp2uuid(uuid_len, uuid) == pts_chrc_uuid:
            iut_start_handle = handle

    if iut_start_handle is None or iut_end_handle is None:
        logging.error("service %s not found", pts_chrc_uuid)
        return False

    iut_chrc_handles = []

    # Lookup all services within service range
    chrcs = btp.gatts_get_attrs(type_uuid='2803',
                                start_handle=iut_start_handle,
                                end_handle=iut_end_handle)
    for chrc in chrcs:
        handle, perm, type_uuid = chrc
        iut_chrc_handles.append(handle)

    if iut_chrc_handles != pts_chrc_handles:
        return False

    return True
Beispiel #16
0
def hdl_wid_52(desc):
    MMI.reset()
    MMI.parse_description(desc)

    handle = int(MMI.args[0], 16)

    _, _, value = btp.gatts_get_attr_val(btp.pts_addr_type_get(),
                                         btp.pts_addr_get(), handle)

    value_read = hexlify(value).decode('utf-8')

    return bool(value_read == MMI.args[1])
Beispiel #17
0
def hdl_wid_139(desc):
    MMI.reset()
    MMI.parse_description(desc)

    hdl = MMI.args[0]

    if not hdl:
        logging.error("parsing error")
        return False

    read_val = btp.gatts_get_attr_val(btp.pts_addr_type_get(), btp.pts_addr_get(), hdl)
    return bool(read_val == COMPARED_VALUE[0])
Beispiel #18
0
def hdl_wid_135(params: WIDParams):
    MMI.reset()
    MMI.parse_description(params.description)

    hdl = MMI.args[0]

    if not hdl:
        logging.error("parsing error")
        return False

    btp.gattc_write(btp.pts_addr_type_get(None), btp.pts_addr_get(None), hdl,
                    '01', 1)
    return True
Beispiel #19
0
def hdl_wid_142(desc):
    MMI.reset()
    MMI.parse_description(desc)

    hdl = MMI.args[0]

    if not hdl:
        logging.error("parsing error")
        return False

    btp.gattc_write(btp.pts_addr_type_get(None), btp.pts_addr_get(None), hdl,
                    '02', 1)
    return True
Beispiel #20
0
def hdl_wid_24(desc):
    MMI.reset()
    MMI.parse_description(desc)

    # Include service in description should have 3 parameters:
    # Attribute Handle, Included Service Attribute Handle and End Group Handle
    num_includes = len(MMI.args) / 3

    pts_services = []

    for i in range(num_includes):
        pts_services.append([
            int(MMI.args[i + 0], 16),
            int(MMI.args[i + 1], 16),
            int(MMI.args[i + 2], 16)
        ])

    iut_services = []

    # Get all Included services
    attrs = btp.gatts_get_attrs(type_uuid='2802')
    for attr in attrs:
        handle, perm, type_uuid = attr

        val = btp.gatts_get_attr_val(btp.pts_addr_type_get(),
                                     btp.pts_addr_get(), handle)
        if not val:
            continue

        (_, val_len, attr_value) = val

        hdr = '<HH'
        hdr_len = struct.calcsize(hdr)
        data_len = val_len - hdr_len
        incl_hdl, end_hdl, _ = struct.unpack(hdr + '%ds' % data_len,
                                             attr_value)
        iut_services.append([handle, incl_hdl, end_hdl])

    # Verification
    for service in pts_services:
        if service in iut_services:
            iut_services.remove(service)
            logging.debug("Service %r found", service)
            continue
        else:
            logging.error("Service %r not found", service)
            return False

    return True
Beispiel #21
0
def hdl_wid_138(params: WIDParams):
    MMI.reset()
    MMI.parse_description(params.description)

    hdl = MMI.args[0]

    if not hdl:
        logging.error("parsing error")
        return False

    read_val = btp.gatts_get_attr_val(btp.pts_addr_type_get(),
                                      btp.pts_addr_get(), hdl)
    COMPARED_VALUE.append(read_val)

    return True
Beispiel #22
0
def hdl_wid_20(desc):
    MMI.reset()
    MMI.parse_description(desc)

    uuid = MMI.args[0]

    if not uuid:
        logging.error("%s parsing error", hdl_wid_20.__name__)
        return False

    btp.gattc_disc_prim_uuid(btp.pts_addr_type_get(), btp.pts_addr_get(), uuid)

    btp.gattc_disc_prim_uuid_rsp(True)

    return True
def hdl_wid_52(desc):
    MMI.reset()
    MMI.parse_description(desc)

    handle = int(MMI.args[0], 16)

    _, _, value = btp.gatts_get_attr_val(btp.pts_addr_type_get(),
                                         btp.pts_addr_get(), handle)

    value_read = hexlify(value)

    if value_read == MMI.args[1]:
        return True
    else:
        return False
Beispiel #24
0
def hdl_wid_58(desc):
    MMI.reset()
    MMI.parse_description(desc)

    hdl = MMI.args[0]

    if not hdl:
        logging.error("parsing error")
        return False

    btp.gattc_read(btp.pts_addr_type_get(), btp.pts_addr_get(), hdl)

    btp.gattc_read_rsp(True, True)

    return True
Beispiel #25
0
def hdl_wid_23(desc):
    MMI.reset()
    MMI.parse_description(desc)

    pts_services = [[int(MMI.args[1], 16), int(MMI.args[2], 16), MMI.args[0]]]

    if not pts_services:
        logging.debug("parsing error")
        return False

    bd_addr = btp.pts_addr_get()
    bd_addr_type = btp.pts_addr_type_get()

    iut_services = []

    # [start_hdl, end_hdl, uuid]
    iut_service = None

    # Get all primary services
    attrs = btp.gatts_get_attrs(type_uuid='2800')
    for attr in attrs:
        start_handle, perm, type_uuid = attr

        if iut_service is not None:
            iut_service[1] = start_handle - 1
            iut_services.append(iut_service)
            iut_service = None

        val = btp.gatts_get_attr_val(bd_addr_type, bd_addr, start_handle)
        if not val:
            continue

        (_, uuid_len, uuid) = val
        iut_service = [start_handle, "unknown", btp.btp2uuid(uuid_len, uuid)]

    iut_services.append(iut_service)

    # Verification
    for service in pts_services:
        if service in iut_services:
            iut_services.remove(service)
            logging.debug("Service %r found", service)
            continue
        else:
            logging.error("Service %r not found", service)
            return False

    return True
Beispiel #26
0
def hdl_wid_69(desc):
    MMI.reset()
    MMI.parse_description(desc)

    if not MMI.args:
        logging.error("parsing error")
        return False

    handle = int(MMI.args[0], 16)
    size = int(MMI.args[1], 16)

    btp.gattc_write_long(btp.pts_addr_type_get(None), btp.pts_addr_get(None),
                         handle, 0, '12', size)
    btp.gattc_write_long_rsp()

    return True
Beispiel #27
0
def hdl_wid_17(desc):
    MMI.reset()
    MMI.parse_description(desc)

    iut_services = []

    attrs = btp.gatts_get_attrs(type_uuid='2800')
    for attr in attrs:
        handle, _, _ = attr
        (_, uuid_len, uuid) = btp.gatts_get_attr_val(
            btp.pts_addr_type_get(),
            btp.pts_addr_get(), handle)
        uuid = btp.btp2uuid(uuid_len, uuid)
        iut_services.append(uuid)

    return bool(iut_services == MMI.args)
Beispiel #28
0
def hdl_wid_77(desc):
    MMI.reset()
    MMI.parse_description(desc)

    hdl = MMI.args[0]
    offset = int(MMI.args[1])

    if not hdl or not offset:
        logging.error("parsing error")
        return False

    btp.gattc_write_long(btp.pts_addr_type_get(), btp.pts_addr_get(), hdl,
                         offset, '12', None)

    btp.gattc_write_long_rsp(True)

    return True
Beispiel #29
0
def hdl_wid_81(desc):
    MMI.reset()
    MMI.parse_description(desc)

    hdl = MMI.args[0]
    val_mtp = MMI.args[1]

    if not hdl or not val_mtp:
        logging.error("parsing error")
        return False

    btp.gattc_write_long(btp.pts_addr_type_get(), btp.pts_addr_get(), hdl, 0,
                         '1234', val_mtp)

    btp.gattc_write_long_rsp(True)

    return True
Beispiel #30
0
def hdl_wid_57(desc):
    MMI.reset()
    MMI.parse_description(desc)

    hdl1 = MMI.args[0]
    hdl2 = MMI.args[1]

    if not hdl1 or not hdl2:
        logging.error("parsing error")
        return False

    btp.gattc_read_multiple(btp.pts_addr_type_get(), btp.pts_addr_get(), hdl1,
                            hdl2)

    btp.gattc_read_multiple_rsp(True, True)

    return True