Beispiel #1
0
def hdl_wid_92(params: WIDParams):
    bd_addr = btp.pts_addr_get()
    bd_addr_type = btp.pts_addr_type_get()

    # This pattern is matching Notification handle
    pattern = re.compile(r"(handle)\s?=\s?'([0-9a-fA-F]+)'")
    params = pattern.findall(params.description)
    if not params:
        logging.error("parsing error")
        return False

    params = dict(params)
    handle = int(params.get('handle'), 16)
    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
Beispiel #2
0
def gattc_wid_hdl_multiple_indications(wid, description, test_case_name):
    global indication_subbed_already
    if wid == 99:
        log("%s, %r, %r, %s", gatt_wid_hdl.__name__, wid, description,
            test_case_name)
        pattern = re.compile("'([0-9a-fA-F]+)'")
        params = pattern.findall(description)
        if not params:
            logging.error("parsing error")
            return False

        handle = params[0]

        btp.gattc_cfg_indicate(btp.pts_addr_type_get(), btp.pts_addr_get(), 1,
                               handle)

        if not indication_subbed_already:
            indication_subbed_already = True
        else:
            btp.gattc_notification_ev(btp.pts_addr_get(),
                                      btp.pts_addr_type_get(), 2)
            btp.gattc_notification_ev(btp.pts_addr_get(),
                                      btp.pts_addr_type_get(), 2)
        return True

    module = sys.modules[__name__]

    try:
        handler = getattr(module, "hdl_wid_%d" % wid)
        return handler(WIDParams(wid, description, test_case_name))
    except AttributeError:
        return gatt_wid_hdl(wid, description, test_case_name)
Beispiel #3
0
def l2cap_wid_hdl(wid, description, test_case_name):
    log("%s, %r, %r, %s", l2cap_wid_hdl.__name__, wid, description,
        test_case_name)
    module = sys.modules[__name__]

    try:
        handler = getattr(module, "hdl_wid_%d" % wid)
        return handler(WIDParams(wid, description, test_case_name))
    except AttributeError as e:
        logging.exception(e)
Beispiel #4
0
def hdl_wid_104(params: WIDParams):
    pattern = re.compile(
        r"(ATTRIBUTE\sHANDLE|"
        "VALUE|"
        "FORMAT|"
        "EXPONENT|"
        "UINT|"
        "NAMESPACE|"
        r"DESCRIPTION)\s?=\s?'?([0-9a-fA-F]+)'?", re.IGNORECASE)
    params = pattern.findall(params.description)
    if not params:
        logging.error("parsing error")
        return False

    params = {k.upper(): v for (k, v) in params}
    db = gatt_server_fetch_db()

    attr = db.attr_lookup_handle(int(params.get('ATTRIBUTE HANDLE'), 16))
    if attr is None or not isinstance(attr, GattCharacteristicDescriptor):
        logging.error("included not found")
        return False

    p_format = int(params.get('FORMAT'), 16)
    p_exponent = int(params.get('EXPONENT'), 16)
    p_uint = int(params.get('UINT'), 16)
    p_namespace = int(params.get('NAMESPACE'), 16)
    p_description = int(params.get('DESCRIPTION'), 16)

    i_format, i_exponent, i_uint, i_namespace, i_description = struct.unpack(
        "<BBHBH", attr.value)

    if p_format != i_format \
            or p_exponent != i_exponent \
            or p_uint != i_uint \
            or p_namespace != i_namespace \
            or p_description != i_description:
        return False

    return True
Beispiel #5
0
def hdl_wid_102(params: WIDParams):
    pattern = re.compile(
        r"(ATTRIBUTE\sHANDLE|"
        r"INCLUDED\sSERVICE\sATTRIBUTE\sHANDLE|"
        r"END\sGROUP\sHANDLE|"
        "UUID|"
        "PROPERTIES|"
        "HANDLE|"
        r"SECONDARY\sSERVICE)\s?=\s?'([0-9a-fA-F]+)'", re.IGNORECASE)
    params = pattern.findall(params.description)
    if not params:
        logging.error("parsing error")
        return False

    params = {k.upper(): v for (k, v) in params}
    db = gatt_server_fetch_db()

    if "INCLUDED SERVICE ATTRIBUTE HANDLE" in params:
        incl_handle = int(params.get('INCLUDED SERVICE ATTRIBUTE HANDLE'), 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(params.get('ATTRIBUTE HANDLE'), 16))
        if attr is None or not isinstance(attr, GattServiceIncluded):
            logging.error("included not found")
            return False

        if attr.end_grp_hdl != int(params.get('END GROUP HANDLE'), 16) \
                or incl_uuid != params.get('UUID').upper():
            return False

        return True

    if "PROPERTIES" in params:
        attr_handle = int(params.get('ATTRIBUTE HANDLE'), 16)
        attr = db.attr_lookup_handle(attr_handle)
        if attr is None or not isinstance(attr, GattCharacteristic):
            logging.error("characteristic not found")
            return False

        if attr.prop != int(params.get('PROPERTIES'), 16) \
                or attr.value_handle != int(params.get('HANDLE'), 16) \
                or attr.uuid != params.get('UUID').upper():
            return False

        return True

    if "SECONDARY SERVICE" in params:
        attr_handle = int(params.get('ATTRIBUTE HANDLE'), 16)
        attr = db.attr_lookup_handle(attr_handle)
        if attr is None:
            logging.error("characteristic not found")
            return False

        if not isinstance(attr, GattSecondary) or \
                attr.uuid != params.get('SECONDARY SERVICE').upper():
            return False

        return True

    return False