Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1458197pxb; Thu, 14 Apr 2022 06:43:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpq6aOYZzH4i9DXmULxsekWAvGmhl0HEyYdEyh9BugvcCLQUiJKVJo49+tCqucheEb6VHK X-Received: by 2002:a63:4382:0:b0:383:38ae:bb23 with SMTP id q124-20020a634382000000b0038338aebb23mr2420161pga.148.1649943836423; Thu, 14 Apr 2022 06:43:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649943836; cv=none; d=google.com; s=arc-20160816; b=Py8cOqusvQWUMwYgmZbyPaIibE+jahwLDJxNUPcJsvEG12p0SYq9fsltBKwDXVdPkA alI6T85tGaI2fopSH+BsAn1NHf9KuBnYzQllb+5kEP6KGUlmLgub0b8KTlbG6AYRv/cv A92joIgtUjXMSBnQY5it2xMasMjKN0RSMju/coe264oFLeshlN4F5QGK1DAZbxhQLyAN OZF+4uCjnSbXSHjlsFfEbyfxhOxemMX79g5aGCyIwy4vuRfM7u1aXf+qeDHGmh7VnDS7 rASwD/bz5zuJ2OWYAtquK14AovCjpUcmyNBGxx11syeF6Qq6kxNjbk2aDR1yUOKXaOqn FG4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=uM47SuYuyMQKoe8OoXk2y15wtkbpd13fqQY+8pZiyxM=; b=ZMxdvy45iVXEl46ht7/ctbCNgHGMTiJ2jLrXZSUb7TFEOFpBtE+xYrIflyvDizyZ1f WCPl/v5D7mdKIwHXQsBKpjcJAyu/bMbX25HhqgGA6VlkUQ2KBAUMbv8EC0cbmjl0bhLH KePeR66eZP+BkcO6bF2iOjDL+WwDaLuj6q5PX0Ds/3hWaxwGg+CSlvcRbFr5HrJUJcV7 oG64kwFCWpaIJisg2tA0c4LtXEt03sFK7bq04mMDhbG1oCRkjuLA/3LHMHUdvPrNPBk/ ffVhjWSLSj07AEIBYwL2IXkEQQYyAoIMLw1iAj74to2Ll/vTk+2iFJ6vUfUhXBlbgrQj 4F/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=k7LjQCm0; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z126-20020a626584000000b004fb806fbeb4si16680722pfb.300.2022.04.14.06.43.40; Thu, 14 Apr 2022 06:43:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=k7LjQCm0; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231252AbiDMVjx (ORCPT + 99 others); Wed, 13 Apr 2022 17:39:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231517AbiDMVjv (ORCPT ); Wed, 13 Apr 2022 17:39:51 -0400 Received: from mail-yw1-x112c.google.com (mail-yw1-x112c.google.com [IPv6:2607:f8b0:4864:20::112c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FE425A09C for ; Wed, 13 Apr 2022 14:37:29 -0700 (PDT) Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-2edbd522c21so36557977b3.13 for ; Wed, 13 Apr 2022 14:37:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=uM47SuYuyMQKoe8OoXk2y15wtkbpd13fqQY+8pZiyxM=; b=k7LjQCm05NM+yuG7+7C2YMuuqNeJE70fybVOwWWhAvaHcsU9QpM/WyT9pRrFURd23e vZXSIGo5iyfHVJNeqedOJAT2TFADYTsuPBaO/SM9CPl7hQ6kWTZBLKAnRgB61n/thx1v sdAbrk4V2+P+XJqh6j/OBgHJvXlU4i3TR2Q/d608wgaVai2NQy7k0ONHmyZF6Sw+NpMI 3kfXrXLVwBws/u74rKBXTDu8MB2wu0tcEM1zLL2bAa3tt4pyOeV75kczv7SgXbMnMQBH x8sqPVKyuXOs6BJTHJS50fcTm4B6Eaw/0aO4GXR+nMEK36dl6GLxit1QwZpGTFt96463 f1Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=uM47SuYuyMQKoe8OoXk2y15wtkbpd13fqQY+8pZiyxM=; b=Zz1a1kz+Go47+kpqI1PLJlDM9Xgy0B4BD5RTniGQUza+knAvvg6O9AjDsDtPxmLgQF vEdm1x7VbnU7wKzoyiJVWt6v4UgaVKajj8zk7NXO+oQaPX9sGR2tYeOvAL7hLQNEuPNq 3l6i/3+8dpuTgN2BV6d6bzlG4X4f3x+/ht08ONHowiKXhuZttQz9KqGKXwDiBqJ2xH5T mYSSs7ztSTgUriQvKZzRiPCpWl5HyVrZJwhS9d+fdgKUx+RB6o0nIb0DvvNcDB5l14n0 s+VlTvVJOWlewONXwcm5LlUzN167QrN5uEmFsHmxgcTDGom9aa6PPIP9kpCm3843rLVF eaHg== X-Gm-Message-State: AOAM5323VgIU0nOwMP+ryGs5xm9h2C/y5gu3T0W1+d1arhzemScpj9Ux dqAyG3cW5S4C8dFmthBcqe479dUVLu0WwKtZk98= X-Received: by 2002:a0d:cc83:0:b0:2ec:1f2d:b527 with SMTP id o125-20020a0dcc83000000b002ec1f2db527mr868846ywd.376.1649885848250; Wed, 13 Apr 2022 14:37:28 -0700 (PDT) MIME-Version: 1.0 References: <20220320183445.BlueZ.1.I21d5ed25e9a0a2427bddbd6d4ec04d80d735fc53@changeid> <20220320183445.BlueZ.7.I668ef2477efd8fcdd9c44975c5f7b9f32af966ca@changeid> In-Reply-To: From: Luiz Augusto von Dentz Date: Wed, 13 Apr 2022 14:37:16 -0700 Message-ID: Subject: Re: [BlueZ PATCH 7/9] adv_monitor: Add the monitor Release reason To: Manish Mandlik Cc: Marcel Holtmann , ChromeOS Bluetooth Upstreaming , "linux-bluetooth@vger.kernel.org" , Miao-chen Chou Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Manish, On Wed, Apr 13, 2022 at 1:56 PM Manish Mandlik wrote: > > Hi Luiz, > > On Mon, Mar 21, 2022 at 5:49 PM Luiz Augusto von Dentz wrote: >> >> Hi Manish, >> >> On Sun, Mar 20, 2022 at 6:37 PM Manish Mandlik wro= te: >> > >> > Adv Monitor is released for various reasons. For example, incorrect RS= SI >> > parameters, incorrect monitor type, non-overlapping RSSI thresholds, >> > etc. >> > >> > Return this release reason along with the Release event for the better >> > visibility to clients. >> >> Shouldn't this be sent as a reply to the method registering the monitor? > > Applications can create an Advertisement Monitor D-Bus object any time be= fore or after registering the root path with BlueZ. BlueZ processes monitor= s once it receives ProxyAdded callback from D-Bus once a Monitor is created= on an already registered root path or once the root path is registered for= already created monitors. So, monitor Activate/Release methods are called = later asynchronously to notify applications about acceptance or rejection o= f the monitor. We should probably document this then, so I suppose one can register the root path without having any monitors so they can be added/removed later? >> >> >> > Reviewed-by: Miao-chen Chou >> > --- >> > >> > doc/advertisement-monitor-api.txt | 12 ++++++- >> > src/adv_monitor.c | 56 ++++++++++++++++++++++++++++--= - >> > 2 files changed, 63 insertions(+), 5 deletions(-) >> > >> > diff --git a/doc/advertisement-monitor-api.txt b/doc/advertisement-mon= itor-api.txt >> > index 942d44b2f..fcbd9c5c2 100644 >> > --- a/doc/advertisement-monitor-api.txt >> > +++ b/doc/advertisement-monitor-api.txt >> > @@ -17,12 +17,22 @@ Service org.bluez >> > Interface org.bluez.AdvertisementMonitor1 [experimental] >> > Object path freely definable >> > >> > -Methods void Release() [noreply] >> > +Methods void Release(Int8 reason) [noreply] >> > >> > This gets called as a signal for a client to p= erform >> > clean-up when (1)a monitor cannot be activated= after it >> > was exposed or (2)a monitor has been deactivat= ed. >> > >> > + Possible reasons: 0 Unknown reason >> > + 1 Invalid monitor type >> > + 2 Invalid RSSI parameter(s= ) >> > + 3 Invalid pattern(s) >> > + 4 Monitor already exists >> > + 5 Kernel failed to add mon= itor >> > + 6 Kernel failed to remove = monitor >> > + 7 Monitor removed by kerne= l >> > + 8 App unregistered/destroy= ed >> > + >> > void Activate() [noreply] >> > >> > After a monitor was exposed, this gets called = as a >> > diff --git a/src/adv_monitor.c b/src/adv_monitor.c >> > index 85231557e..6ee3736d2 100644 >> > --- a/src/adv_monitor.c >> > +++ b/src/adv_monitor.c >> > @@ -90,6 +90,18 @@ enum monitor_state { >> > MONITOR_STATE_RELEASED, /* Dbus Object removed by app */ >> > }; >> > >> > +enum monitor_release_reason { >> > + REASON_UNKNOWN, >> > + REASON_INVALID_TYPE, >> > + REASON_INVALID_RSSI_PARAMS, >> > + REASON_INVALID_PATTERNS, >> > + REASON_ALREADY_EXISTS, >> > + REASON_FAILED_TO_ADD, >> > + REASON_FAILED_TO_REMOVE, >> > + REASON_REMOVED_BY_KERNEL, >> > + REASON_APP_DESTROYED, >> > +}; >> > + >> > enum merged_pattern_state { >> > MERGED_PATTERN_STATE_ADDING, /* Adding pattern to kernel */ >> > MERGED_PATTERN_STATE_REMOVING, /* Removing pattern from kerne= l */ >> > @@ -113,6 +125,7 @@ struct adv_monitor { >> > char *path; >> > >> > enum monitor_state state; /* MONITOR_STATE_* */ >> > + enum monitor_release_reason release_reason; >> > >> > struct rssi_parameters rssi; /* RSSI parameter for this mon= itor */ >> > struct adv_monitor_merged_pattern *merged_pattern; >> > @@ -137,6 +150,7 @@ struct adv_monitor_merged_pattern { >> > struct queue *patterns; /* List of bt_ad_pattern objec= ts */ >> > enum merged_pattern_state current_state; /* MERGED_PATTERN_STA= TE_* */ >> > enum merged_pattern_state next_state; /* MERGED_PATTERN_STA= TE_* */ >> > + enum monitor_release_reason release_reason; >> > }; >> > >> > /* Some data like last_seen, timer/timeout values need to be maintain= ed >> > @@ -541,6 +555,18 @@ static void monitor_free(struct adv_monitor *moni= tor) >> > free(monitor); >> > } >> > >> > +/* Includes monitor release reason into the dbus message */ >> > +static void report_release_reason_setup(DBusMessageIter *iter, void *= user_data) >> > +{ >> > + const struct adv_monitor *monitor =3D user_data; >> > + int8_t release_reason =3D REASON_UNKNOWN; >> > + >> > + if (monitor) >> > + release_reason =3D monitor->release_reason; >> > + >> > + dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE, &release_= reason); >> > +} >> > + >> > /* Calls Release() method of the remote Adv Monitor */ >> > static void monitor_release(struct adv_monitor *monitor) >> > { >> > @@ -560,8 +586,9 @@ static void monitor_release(struct adv_monitor *mo= nitor) >> > DBG("Calling Release() on Adv Monitor of owner %s at path %s", >> > monitor->app->owner, monitor->path); >> > >> > - g_dbus_proxy_method_call(monitor->proxy, "Release", NULL, NULL= , NULL, >> > - NULL); >> > + g_dbus_proxy_method_call(monitor->proxy, "Release", >> > + report_release_reason_setup, N= ULL, >> > + monitor, NULL); >> > } >> > >> > /* Removes monitor from the merged_pattern. This would result in remo= ving it >> > @@ -635,13 +662,20 @@ static void monitor_destroy(void *data) >> > static void app_destroy(void *data) >> > { >> > struct adv_monitor_app *app =3D data; >> > + const struct queue_entry *e; >> > >> > if (!app) >> > return; >> > >> > DBG("Destroy Adv Monitor app %s at path %s", app->owner, app->= path); >> > >> > - queue_destroy(app->monitors, monitor_destroy); >> > + for (e =3D queue_get_entries(app->monitors); e; e =3D e->next)= { >> > + struct adv_monitor *m =3D e->data; >> > + >> > + m->release_reason =3D REASON_APP_DESTROYED; >> > + monitor_destroy(m); >> > + } >> > + queue_destroy(app->monitors, NULL); >> > >> > if (app->reg) { >> > app_reply_msg(app, btd_error_failed(app->reg, >> > @@ -793,6 +827,7 @@ static bool parse_monitor_type(struct adv_monitor = *monitor, const char *path) >> > } >> > >> > failed: >> > + monitor->release_reason =3D REASON_INVALID_TYPE; >> > btd_error(adapter_id, >> > "Invalid argument of property Type of the Adv = Monitor " >> > "at path %s", path); >> > @@ -919,6 +954,7 @@ done: >> > return true; >> > >> > failed: >> > + monitor->release_reason =3D REASON_INVALID_RSSI_PARAMS; >> > btd_error(adapter_id, >> > "Invalid argument of RSSI thresholds and timeo= uts " >> > "of the Adv Monitor at path %s", >> > @@ -1005,6 +1041,7 @@ static bool parse_patterns(struct adv_monitor *m= onitor, const char *path) >> > return true; >> > >> > failed: >> > + monitor->release_reason =3D REASON_INVALID_PATTERNS; >> > btd_error(adapter_id, "Invalid argument of property Patterns o= f the " >> > "Adv Monitor at path %s", path); >> > >> > @@ -1053,6 +1090,7 @@ static void merged_pattern_destroy_monitors( >> > struct adv_monitor *monitor =3D e->data; >> > >> > monitor->merged_pattern =3D NULL; >> > + monitor->release_reason =3D merged_pattern->release_re= ason; >> > monitor_destroy(monitor); >> > } >> > } >> > @@ -1086,6 +1124,7 @@ static void remove_adv_monitor_cb(uint8_t status= , uint16_t length, >> > return; >> > >> > fail: >> > + merged_pattern->release_reason =3D REASON_FAILED_TO_REMOVE; >> > merged_pattern_destroy_monitors(merged_pattern); >> > merged_pattern_free(merged_pattern); >> > } >> > @@ -1142,6 +1181,7 @@ static void add_adv_patterns_monitor_cb(uint8_t = status, uint16_t length, >> > return; >> > >> > fail: >> > + merged_pattern->release_reason =3D REASON_FAILED_TO_ADD; >> > merged_pattern_destroy_monitors(merged_pattern); >> > merged_pattern_free(merged_pattern); >> > } >> > @@ -1285,6 +1325,7 @@ static void monitor_proxy_added_cb(GDBusProxy *p= roxy, void *user_data) >> > merged_pattern_add(monitor->merged_pattern); >> > } else { >> > if (!merge_is_possible(existing_pattern, monitor)) { >> > + monitor->release_reason =3D REASON_ALREADY_EXI= STS; >> > monitor_destroy(monitor); >> > DBG("Adv Monitor at path %s released due to ex= isting " >> > "monitor", path); >> > @@ -1551,6 +1592,7 @@ static void remove_merged_pattern(void *data, vo= id *user_data) >> > { >> > struct adv_monitor_merged_pattern *merged_pattern =3D data; >> > uint16_t *handle =3D user_data; >> > + const struct queue_entry *e; >> > >> > if (!handle) >> > return; >> > @@ -1562,8 +1604,14 @@ static void remove_merged_pattern(void *data, v= oid *user_data) >> > DBG("Adv monitor with handle:0x%04x removed by kernel", >> > merged_pattern->monitor_handle); >> > >> > + for (e =3D queue_get_entries(merged_pattern->monitors); e; e = =3D e->next) { >> > + struct adv_monitor *m =3D e->data; >> > + >> > + m->release_reason =3D REASON_REMOVED_BY_KERNEL; >> > + monitor_destroy(m); >> > + } >> > queue_foreach(merged_pattern->monitors, monitor_state_removed,= NULL); >> > - queue_destroy(merged_pattern->monitors, monitor_destroy); >> > + queue_destroy(merged_pattern->monitors, NULL); >> > merged_pattern_free(merged_pattern); >> > } >> > >> > -- >> > 2.35.1.894.gb6a874cedc-goog >> > >> >> >> -- >> Luiz Augusto von Dentz > > > Regards, > Manish. > --=20 Luiz Augusto von Dentz