Example #1
0
def hdl_wid_109(desc):
    MMI.reset()
    MMI.parse_description(desc)

    uuid = MMI.args[0]

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

    btp.gattc_read_uuid(btp.pts_addr_type_get(None), btp.pts_addr_get(None),
                        "0001", "FFFF", uuid)

    try:
        btp.gattc_read_uuid_rsp(False, True)
    except socket.timeout:
        return False

    return True
Example #2
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, 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)

    if iut_services == MMI.args:
        return True
    else:
        return False
Example #3
0
def hdl_wid_48(desc):
    MMI.reset()
    MMI.parse_description(desc)

    hdl = MMI.args[0]

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

    btp.gattc_read_long(btp.pts_addr_type_get(None), btp.pts_addr_get(None),
                        hdl, 0, 1)

    try:
        btp.gattc_read_long_rsp(True, True)
    except socket.timeout:
        pass

    return True
Example #4
0
def gap_wid_hdl_failed_read(wid, description, test_case_name):
    log("%s, %r, %r, %s", gap_wid_hdl.__name__, wid, description,
        test_case_name)

    if wid == 112:
        bd_addr = btp.pts_addr_get()
        bd_addr_type = btp.pts_addr_type_get()

        handle = btp.parse_handle_description(description)
        if not handle:
            return False

        try:
            btp.gattc_read(bd_addr_type, bd_addr, handle)
            btp.gattc_read_rsp()
        except socket.timeout:
            pass
        return True
    return gap_wid_hdl(wid, description, test_case_name)
Example #5
0
def hdl_wid_76(params: WIDParams):
    pattern = re.compile("'([0-9a-fA-F]+)'")
    command_params = pattern.findall(params.description)
    if not command_params:
        logging.error("parsing error")
        return False

    handle = command_params[0]
    off = int(command_params[1])

    btp.gattc_write_long(btp.pts_addr_type_get(), btp.pts_addr_get(), handle,
                         off, '12', None)
    no_rsp_check_tests = ["GATT/CL/GAW/BV-10-C", "GATT/CL/GAW/BI-37-C"]

    if params.test_case_name in no_rsp_check_tests:
        return True

    btp.gattc_write_long_rsp(True)
    return True
Example #6
0
def hdl_wid_75(desc):
    MMI.reset()
    MMI.parse_description(desc)
    if not MMI.args:
        logging.debug("parsing error")

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

    time.sleep(5)

    attr = btp.gatts_get_attr_val(btp.pts_addr_type_get(), btp.pts_addr_get(),
                                  handle)

    _, _, val = attr

    parsed_val = hexlify(val).decode('utf-8').upper()

    return bool(value == parsed_val)
Example #7
0
def hdl_wid_29(desc):
    MMI.reset()
    MMI.parse_description(desc)

    start_hdl = MMI.args[0]
    end_hdl = MMI.args[1]
    uuid = MMI.args[2]

    if not start_hdl or not end_hdl or not uuid:
        logging.error("parsing error")
        return False

    btp.gattc_disc_chrc_uuid(btp.pts_addr_type_get(),
                             btp.pts_addr_get(),
                             start_hdl, end_hdl, uuid)

    btp.gattc_disc_chrc_uuid_rsp(True)

    return True
Example #8
0
def hdl_wid_46(desc):
    """
    :param desc: Please send an L2CAP Connection Parameter Update request using valid parameters.
    :return:
    """
    btp.gap_wait_for_connection()

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

    new_params = copy.deepcopy(stack.gap.conn_params.data)

    new_params.conn_latency += 1

    btp.gap_conn_param_update(bd_addr, bd_addr_type, new_params.conn_itvl,
                              new_params.conn_itvl, new_params.conn_latency,
                              new_params.supervision_timeout)

    return True
Example #9
0
def hdl_wid_74(desc):
    MMI.reset()
    MMI.parse_description(desc)

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

    if not hdl or size == 0:
        logging.error("parsing error")
        return False

    btp.gattc_write(btp.pts_addr_type_get(), btp.pts_addr_get(), hdl, '12',
                    size)

    try:
        btp.gattc_write_rsp(True, 40)
    except socket.timeout:
        pass

    return True
Example #10
0
def hdl_wid_51(desc):
    MMI.reset()
    MMI.parse_description(desc)

    uuid = MMI.args[0]
    start_hdl = MMI.args[1]
    end_hdl = MMI.args[2]

    if not uuid or not start_hdl or not end_hdl:
        logging.debug("parsing error")
        return False

    btp.gattc_read_uuid(btp.pts_addr_type_get(), btp.pts_addr_get(), start_hdl,
                        end_hdl, uuid)

    try:
        btp.gattc_read_uuid_rsp(True, True)
    except socket.timeout:
        pass

    return True
Example #11
0
def hdl_wid_122(desc):
    bd_addr = btp.pts_addr_get()
    bd_addr_type = btp.pts_addr_type_get()

    # Lookup characteristic UUID that returns Insufficient Encryption Key Size
    chrcs = btp.gatts_get_attrs(type_uuid='2803')
    for chrc in chrcs:
        handle, perm, type_uuid = chrc

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

        att_rsp, val_len, val = chrc_data

        hdr = '<BH'
        hdr_len = struct.calcsize(hdr)
        uuid_len = val_len - hdr_len

        prop, handle, chrc_uuid = struct.unpack("<BH%ds" % uuid_len, val)
        chrc_value_attr = btp.gatts_get_attrs(start_handle=handle,
                                              end_handle=handle)
        if not chrc_value_attr:
            continue

        handle, perm, type_uuid = chrc_value_attr[0]
        chrc_value_data = btp.gatts_get_attr_val(bd_addr_type, bd_addr, handle)
        if not chrc_value_data:
            continue

        att_rsp, val_len, val = chrc_value_data

        # Check if returned ATT Insufficient Authorization error
        if att_rsp != 0x0c:
            continue

        return btp.btp2uuid(uuid_len, chrc_uuid)

    return '0000'
Example #12
0
def hdl_wid_119(desc):
    bd_addr = btp.pts_addr_get()
    bd_addr_type = btp.pts_addr_type_get()

    # Lookup UUID that is not present on IUT GATT Server
    uuid_list = []

    chrcs = btp.gatts_get_attrs(type_uuid='2803')
    for chrc in chrcs:
        handle, perm, type_uuid = chrc

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

        att_rsp, val_len, val = chrc_val

        hdr = '<BH'
        hdr_len = struct.calcsize(hdr)
        uuid_len = val_len - hdr_len

        prop, handle, uuid = struct.unpack("<BH%ds" % uuid_len, val)
        uuid_list.append(btp.btp2uuid(uuid_len, uuid))

    if len(uuid_list) == 0:
        logging.error("No attribute found!")
        return "0000"

    uuid_invalid = 1

    while True:
        if format(uuid_invalid, 'x').zfill(4) in uuid_list:
            uuid_invalid += 1
        else:
            uuid_invalid = format(uuid_invalid, 'x').zfill(4)
            break

    return uuid_invalid
Example #13
0
def hdl_wid_112(desc):
    bd_addr = btp.pts_addr_get()
    bd_addr_type = btp.pts_addr_type_get()

    # Lookup characteristic handle that requires read authorization
    chrcs = btp.gatts_get_attrs(type_uuid='2803')
    for chrc in chrcs:
        handle, perm, type_uuid = chrc

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

        (att_rsp, val_len, val) = chrc_val

        hdr = '<BH'
        hdr_len = struct.calcsize(hdr)
        uuid_len = val_len - hdr_len

        prop, handle, chrc_uuid = struct.unpack("<BH%ds" % uuid_len, val)
        chrc_value_attr = btp.gatts_get_attrs(start_handle=handle,
                                              end_handle=handle)
        if not chrc_value_attr:
            continue

        handle, perm, type_uuid = chrc_value_attr[0]
        chrc_value_data = btp.gatts_get_attr_val(bd_addr_type, bd_addr, handle)
        if not chrc_value_data:
            continue

        # Check if returned ATT Insufficient Authorization error
        att_rsp, val_len, val = chrc_value_data
        if att_rsp != 8:
            continue

        return '{0:04x}'.format(handle, 'x')

    return '0000'
Example #14
0
def hdl_wid_161(desc):
    match = re.findall(r'(0[xX])?([0-9a-fA-F]{4})', desc)
    handle = int(match[0][1], 16)

    attr = btp.gatts_get_attrs(handle, handle)
    if not attr:
        return

    (handle, permission, type_uuid) = attr.pop()

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

    # Check if characteristic has signed write property
    value = btp.gatts_get_attr_val(bd_addr_type, bd_addr, handle - 1)
    if not value:
        return

    (att_rsp, val_len, val) = value

    hdr = '<BH'
    hdr_len = struct.calcsize(hdr)
    uuid_len = val_len - hdr_len

    (properties, value_handle,
     chrc_uuid) = struct.unpack("<BH%ds" % uuid_len, val)

    if properties & Prop.auth_swrite == 0:
        return

    chrc_uuid = btp.btp2uuid(uuid_len, chrc_uuid)

    value = btp.gatts_get_attr_val(bd_addr_type, bd_addr, handle)
    if not value:
        return

    (att_rsp, val_len, val) = value
    return val_len
Example #15
0
def hdl_wid_98(desc):
    MMI.reset()
    MMI.parse_description(desc)
    if not MMI.args:
        logging.error("parsing error")
        return False

    handle = int(MMI.args[0], 16)
    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, handle)

    if att_rsp:
        logging.debug("cannot read chrc value")
        return False

    # delay to let the PTS subscribe for notifications
    sleep(2)

    btp.gatts_set_val(handle, hexlify(value))

    return True
Example #16
0
def hdl_wid_12(_: WIDParams):
    btp.gattc_exchange_mtu(btp.pts_addr_type_get(), btp.pts_addr_get())
    return True
Example #17
0
def hdl_wid_15(desc):
    btp.gattc_find_included(btp.pts_addr_type_get(), btp.pts_addr_get(),
                            '0001', 'FFFF')

    btp.gattc_find_included_rsp(True)
    return True
Example #18
0
def hdl_wid_12(desc):
    btp.gattc_exchange_mtu(btp.pts_addr_type_get(), btp.pts_addr_get())
    return True
Example #19
0
def hdl_wid_10(desc):
    btp.gattc_disc_all_prim(btp.pts_addr_type_get(), btp.pts_addr_get())
    btp.gattc_disc_all_prim_rsp()
    return True
Example #20
0
def hdl_wid_3(desc):
    btp.gap_disconn(btp.pts_addr_get(), btp.pts_addr_type_get())
    return True
Example #21
0
def hdl_wid_46(desc):
    btp.gap_wait_for_connection()
    bd_addr = btp.pts_addr_get()
    bd_addr_type = btp.pts_addr_type_get()
    btp.gap_conn_param_update(bd_addr, bd_addr_type, 200, 300, 0, 200)
    return True
Example #22
0
def hdl_wid_127(desc):
    btp.gap_conn_param_update(btp.pts_addr_get(), btp.pts_addr_type_get(), 720,
                              864, 0, 400)
    return True
Example #23
0
def hdl_wid_73(desc):
    btp.gattc_read_uuid(btp.pts_addr_type_get(None), btp.pts_addr_get(None),
                        '0001', 'FFFF', UUID.device_name)
    return True
Example #24
0
def hdl_wid_110(desc):
    pts_bd_addr = btp.pts_addr_get()
    pts_bd_addr_type = btp.pts_addr_type_get()
    btp.gattc_signed_write(pts_bd_addr_type, pts_bd_addr, "0001", "01")
    return True
Example #25
0
def hdl_wid_59(_: WIDParams):
    btp.gap_conn_param_update(btp.pts_addr_get(), btp.pts_addr_type_get(), 720,
                              864, 0, 400)
    return True
Example #26
0
def hdl_wid_10(_: WIDParams):
    btp.gattc_disc_all_prim(btp.pts_addr_type_get(), btp.pts_addr_get())
    btp.gattc_disc_all_prim_rsp(store_rsp=True)
    return True
Example #27
0
def hdl_wid_90(desc):
    btp.gattc_notification_ev(btp.pts_addr_get(), btp.pts_addr_type_get(), 1)
    return True
def hdl_wid_3(desc):
    time.sleep(2)
    btp.gap_disconn(btp.pts_addr_get(), btp.pts_addr_type_get())
    return True
def hdl_wid_15(desc):
    btp.gattc_find_included(btp.pts_addr_type_get(), btp.pts_addr_get(), None,
                            None)
    return True
Example #30
0
def hdl_wid_82(desc):
    btp.gattc_write(btp.pts_addr_type_get(None), btp.pts_addr_get(None),
                    '0100', '12', 1)
    btp.gattc_write_rsp()

    return True