From patchwork Tue Oct 6 00:48:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao-chen Chou X-Patchwork-Id: 11818009 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D896A6CA for ; Tue, 6 Oct 2020 00:50:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD1EF2076B for ; Tue, 6 Oct 2020 00:50:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="evQrl3fm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726654AbgJFAuP (ORCPT ); Mon, 5 Oct 2020 20:50:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725865AbgJFAuP (ORCPT ); Mon, 5 Oct 2020 20:50:15 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE6F0C0613CE for ; Mon, 5 Oct 2020 17:50:13 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id n14so8026087pff.6 for ; Mon, 05 Oct 2020 17:50:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5Z4qVdzUkHcsZYjnQpCfpE/Vdce9HU4nzwFNBqodzco=; b=evQrl3fmhhMIDab5fPGs3oIKx2u36cTbicMgtWW1AU5dmIAxq68vNxZiRXLLlJ+Ylu O3fesNy9YXosqdKtTCcBKJ2X2rxhcXOxRMFUGyQRfISk0ps9oIHyq/+0OpmTJYSk4GFt e6ZUymidy19xmJoZ7+7koNJQTOPDa36vfciKs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5Z4qVdzUkHcsZYjnQpCfpE/Vdce9HU4nzwFNBqodzco=; b=Ew2FQuQRg2nyQL4pe1GFqyoQBChudsoFkzuJZ34FlSZrtLSBgF4vbjUGawnmto7G8E FhfP9RurDg3nk+qn5VspfGjrx0am49ObOphQH09MfnIDWYwmSkLOJK/IKWdGGS3VjHv6 K+WmhhILxli2txkJ2c8SyKQlCAo1/gACN5xn9wlDjdjAN8JN57k0/C6w4FKbS4YW7jvC z84KnyrtvvKK/vl4XZLScQjES3JAK4Yn0zbVt4eXw7AX2P8U2MFwPxMxwnI0J2RIfUmX xpsXgN1CI2QQgDcjRc8A4Xlt3cHGwt513nXVJ61OnGO7Jf7k0xV/X7OJiD6lxe3avVOX gqyw== X-Gm-Message-State: AOAM531id//lyKKBraKnk4inXs+V3aLoDXdX8m/b0NiwJOvchgBxOgb1 NLY18ta0G/wAuKC5GieDiyuNW01HXU5+eA== X-Google-Smtp-Source: ABdhPJyIOOxRrNe54L7fcMRI7gKVmbQh6Nou2inqMvB7VXMVVvVciOrT1Tkqi0tZ8DJF5nSBQO6MxA== X-Received: by 2002:a63:c00d:: with SMTP id h13mr1847700pgg.358.1601945412939; Mon, 05 Oct 2020 17:50:12 -0700 (PDT) Received: from mcchou0.mtv.corp.google.com ([2620:15c:202:201:de4a:3eff:fe75:1314]) by smtp.gmail.com with ESMTPSA id h2sm776947pjv.4.2020.10.05.17.50.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Oct 2020 17:50:12 -0700 (PDT) From: Miao-chen Chou To: Bluetooth Kernel Mailing List Cc: Manish Mandlik , Alain Michaud , Howard Chung , Luiz Augusto von Dentz , Marcel Holtmann , chromeos-bluetooth-upstreaming@chromium.org, Miao-chen Chou Subject: [BlueZ PATCH v5 4/6] adv_monitor: Implement Add Adv Patterns Monitor cmd handler Date: Mon, 5 Oct 2020 17:48:06 -0700 Message-Id: <20201005174640.BlueZ.v5.4.Ibbcb11712b613ef95c31b41207c3ea945c830018@changeid> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201005174640.BlueZ.v5.1.I2830b9c1212a64b062201ed9f2b71294f50ad22d@changeid> References: <20201005174640.BlueZ.v5.1.I2830b9c1212a64b062201ed9f2b71294f50ad22d@changeid> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Howard Chung - Send the MGMT_OP command to kernel upon registration of a Adv patterns monitor. - Call Activate() or Release() to client depending on the reply from kernel the call through syslog Reviewed-by: Alain Michaud Reviewed-by: Miao-chen Chou Reviewed-by: Manish Mandlik --- (no changes since v1) src/adv_monitor.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/src/adv_monitor.c b/src/adv_monitor.c index 89e20c893..d5caf4dd3 100644 --- a/src/adv_monitor.c +++ b/src/adv_monitor.c @@ -588,11 +588,59 @@ done: return monitor->state != MONITOR_STATE_FAILED; } +/* Handles the callback of Add Adv Patterns Monitor command */ +static void add_adv_patterns_monitor_cb(uint8_t status, uint16_t length, + const void *param, void *user_data) +{ + const struct mgmt_rp_add_adv_patterns_monitor *rp = param; + struct adv_monitor *monitor = user_data; + uint16_t adapter_id = monitor->app->manager->adapter_id; + + if (status != MGMT_STATUS_SUCCESS || !param) { + btd_error(adapter_id, "Failed to Add Adv Patterns Monitor " + "with status 0x%02x", status); + monitor_release(monitor, NULL); + return; + } + + if (length < sizeof(*rp)) { + btd_error(adapter_id, "Wrong size of Add Adv Patterns Monitor " + "response"); + monitor_release(monitor, NULL); + return; + } + + monitor->state = MONITOR_STATE_HONORED; + + DBG("Calling Activate() on Adv Monitor of owner %s at path %s", + monitor->app->owner, monitor->path); + + g_dbus_proxy_method_call(monitor->proxy, "Activate", NULL, NULL, NULL, + NULL); + + DBG("Adv Monitor with handle:0x%04x added", + le16_to_cpu(rp->monitor_handle)); +} + +static void monitor_copy_patterns(void *data, void *user_data) +{ + struct btd_adv_monitor_pattern *pattern = data; + struct mgmt_cp_add_adv_monitor *cp = user_data; + + if (!pattern) + return; + + memcpy(cp->patterns + cp->pattern_count, pattern, sizeof(*pattern)); + cp->pattern_count++; +} + /* Handles an Adv Monitor D-Bus proxy added event */ static void monitor_proxy_added_cb(GDBusProxy *proxy, void *user_data) { struct adv_monitor *monitor; struct adv_monitor_app *app = user_data; + struct mgmt_cp_add_adv_monitor *cp = NULL; + uint8_t pattern_count, cp_len; uint16_t adapter_id = app->manager->adapter_id; const char *path = g_dbus_proxy_get_path(proxy); const char *iface = g_dbus_proxy_get_interface(proxy); @@ -625,7 +673,24 @@ static void monitor_proxy_added_cb(GDBusProxy *proxy, void *user_data) queue_push_tail(app->monitors, monitor); + pattern_count = queue_length(monitor->patterns); + cp_len = sizeof(struct mgmt_cp_add_adv_monitor) + + pattern_count * sizeof(struct mgmt_adv_pattern); + + cp = malloc0(cp_len); + queue_foreach(monitor->patterns, monitor_copy_patterns, cp); + + if (!mgmt_send(app->manager->mgmt, MGMT_OP_ADD_ADV_PATTERNS_MONITOR, + adapter_id, cp_len, cp, add_adv_patterns_monitor_cb, + monitor, NULL)) { + error("Unable to send Add Adv Patterns Monitor command"); + goto done; + } + DBG("Adv Monitor allocated for the object at path %s", path); + +done: + free(cp); } /* Handles the removal of an Adv Monitor D-Bus proxy */ @@ -1039,7 +1104,7 @@ static void adv_match_per_monitor(void *data, void *user_data) struct adv_monitor *monitor = data; struct adv_content_filter_info *info = user_data; - if (!monitor && monitor->state != MONITOR_STATE_HONORED) + if (!monitor || monitor->state != MONITOR_STATE_HONORED) return; /* Reset the intermediate matched status */