From patchwork Thu Feb 20 00:28:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 11392805 X-Patchwork-Delegate: luiz.dentz@gmail.com 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 2E166109A for ; Thu, 20 Feb 2020 00:28:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 105912465D for ; Thu, 20 Feb 2020 00:28:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TQBY2Ifj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727036AbgBTA2h (ORCPT ); Wed, 19 Feb 2020 19:28:37 -0500 Received: from mail-pl1-f180.google.com ([209.85.214.180]:34018 "EHLO mail-pl1-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726811AbgBTA2h (ORCPT ); Wed, 19 Feb 2020 19:28:37 -0500 Received: by mail-pl1-f180.google.com with SMTP id j7so810904plt.1 for ; Wed, 19 Feb 2020 16:28:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=yIpwUuffQHTqZM/RXQAXvfjnVggdrcZ7xnQhEPrhbJY=; b=TQBY2IfjmL2eKNKb1y4AOrgMHde/ybP0uuwYbnxh0FF3LUNi5bQtR9+ICCbNEqBy9X pZKfHjweg2R2MoFUiD47qLZTGMyfiH0ynQKfEaYdOU3d6XWppTcb5I6xBtqtcmyRNWz7 xt34QmOJ0vPnN4nJr/AixWNdWY9ROJTw44eu6/DXGxTS/5WsOnKPKAB8MSSS3S00usIq UDsxOOwsczm9s3gd8o0qD/BisdDqLKQHhS3+WsIn35UpPsSUxrlNBXEDEh3KliI9Qvwm k2MTG47ymeNR+QPFetw7DkkLd979Lj8jCe6/TJasX4+i7vdHcdmaazoBf1qyWeELB1zM HRiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=yIpwUuffQHTqZM/RXQAXvfjnVggdrcZ7xnQhEPrhbJY=; b=q2TgWZVclAlZDo61EC8cBi+uIWC0QtuX5kgPOs81I4hw5i58r+X1XdZBWj8hCHnjvM YHW+SEpRwHVozaJJ7fBzqEWQAG1+gTwDRqiH+JAm/JQhzZRudIDeCSyvgVM9uKgr6UoT g90VEAaQGvCwBON8DMGX5GWt53mC/Ict3vMaY+Lw4rOYyIZqnNSjSz68zN5OTLWAuL+8 E/29IS+bgQLUIpPJrUqJhYEqtPTsu3G53oQFqJcIeLAeQeHIE5LmpEXaynI/0eDK+9Dm 56+duDlwimeLkJJxz5XHHUcaH5bs+eNXdTpO52Gfv/2Od5UbwVGVoEW6SgGsPLeUg75e hglg== X-Gm-Message-State: APjAAAUqhc3vA35dMLHD5mr0NLw2siVZVP84e/lbGupoplbVh5wuRwaU afWagSuChkKHDn/Nfd3bX5vGICehpEQ= X-Google-Smtp-Source: APXvYqybMSmozGW6xS4KlWX7/fsswUVlstQnWJHEijjIkZJrIqrSg0920/uKPaEyiEB46dKv/6PxLg== X-Received: by 2002:a17:90a:fd85:: with SMTP id cx5mr407344pjb.80.1582158516311; Wed, 19 Feb 2020 16:28:36 -0800 (PST) Received: from vudentzs-t460s.amr.corp.intel.com ([2601:1c0:6800:1640::3287]) by smtp.gmail.com with ESMTPSA id c68sm769213pfc.156.2020.02.19.16.28.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 16:28:35 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/3] doc/adapter-api: Add pattern filter Date: Wed, 19 Feb 2020 16:28:33 -0800 Message-Id: <20200220002835.8929-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.21.1 MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds a pattern filter which can be used to filter devices by address or name prefix which is quite convenient on a crowded environment. --- doc/adapter-api.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/doc/adapter-api.txt b/doc/adapter-api.txt index 2afd61bc3..acae032d9 100644 --- a/doc/adapter-api.txt +++ b/doc/adapter-api.txt @@ -119,6 +119,21 @@ Methods void StartDiscovery() if the adapter is already discoverable setting this filter won't do anything. + string Pattern (Default: none) + + Discover devices where the pattern matches + either the prefix of the address or + device name which is convenient way to limited + the number of device objects created during a + discovery. + + When set disregards device discoverable flags. + + Note: The pattern matching is ignored if there + are other client that don't set any pattern as + it work as a logical OR, also setting empty + string "" pattern will match any device found. + When discovery filter is set, Device objects will be created as new devices with matching criteria are discovered regardless of they are connectable or From patchwork Thu Feb 20 00:28:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 11392809 X-Patchwork-Delegate: luiz.dentz@gmail.com 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 2D7BD138D for ; Thu, 20 Feb 2020 00:28:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 033C42465D for ; Thu, 20 Feb 2020 00:28:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rBYl1C0q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727263AbgBTA2j (ORCPT ); Wed, 19 Feb 2020 19:28:39 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:35292 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727099AbgBTA2j (ORCPT ); Wed, 19 Feb 2020 19:28:39 -0500 Received: by mail-pl1-f196.google.com with SMTP id g6so806697plt.2 for ; Wed, 19 Feb 2020 16:28:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Ns4Fu2uAcE2PjfhDsU29BteUAwP8E8zX8ihqevM9inI=; b=rBYl1C0qWV2WlIEltag+TPkDzK4+fw7XqoGtW+y+N51zXkshhAJDVWrQdLm9cB0PbX pSfsR6mFnYyvJH9401NrUgvIMS0gKl7v/00Yj5fVB8QsTDvriTVSnrD+xfPtPnGbDlsB tK7YLh6LeNTRyIKdDagj8YVbmHSaOjBAqUAv4PBF24CFD/y6DI0YkpfhVFzl2H3Extcl b7eKuRS/PZO6qdpa9LeBKapfjDCfjyS9y7Sw7zHKjmuo75kF8hDnta4tDpY9SVQTUWle 5FVwHhKSvFbfzDPa7yeylhKjXYbrQIjRwlE6NoHM6ueQEagJwF9CWtwP39CDY5XraZPu OZhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ns4Fu2uAcE2PjfhDsU29BteUAwP8E8zX8ihqevM9inI=; b=kzRm3VQncnxmVii9WBl2J/vER4L2FhavJMKQDBf17rJA6JvW1pnl/TR16/cBwR0Ela EvD9cE4GPSnUFmCN9ciVJY94mqbnOVBJFNbht8rLywZvX4yVzIICL/CgUhIvr/6KpsD/ TtvgUGeh91zbIqVeYpqV1k7FElixU1ixOZm3t0kS6/JtU9amyzfZ3ZbUx0SNxAYXInMO tVcr4DYd3iztWrQxBFJrM0E8yNxI9um0Jzp6BjrykcwZFslCslSX4UjKbLKBhd0ndSwn hyFI9WhFsyMpyqsH2TfXjTmDi6W1Pm+RzjUKCksu8x2PKhJsnnwzgRavpNUHUvBEYeKj uWAg== X-Gm-Message-State: APjAAAXc/dN0epfg1Zk+svfBPBeIE5ySJrYX4y325B8liK0w95xlEp5K 3pwq/Wml/+blmeA1W881jRZEwXVVDPs= X-Google-Smtp-Source: APXvYqzty42aysvU0hAp7Oyo+7zwEfIDrAb68YuMCxOyGpeAOT+dnwQjdzXhUII22YFiQKvvgHVWcQ== X-Received: by 2002:a17:90a:db0f:: with SMTP id g15mr400203pjv.40.1582158517096; Wed, 19 Feb 2020 16:28:37 -0800 (PST) Received: from vudentzs-t460s.amr.corp.intel.com ([2601:1c0:6800:1640::3287]) by smtp.gmail.com with ESMTPSA id c68sm769213pfc.156.2020.02.19.16.28.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 16:28:36 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 2/3] adapter: Implement Pattern filter Date: Wed, 19 Feb 2020 16:28:34 -0800 Message-Id: <20200220002835.8929-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200220002835.8929-1-luiz.dentz@gmail.com> References: <20200220002835.8929-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This implements the new Pattern filter as documented in the adapter-api.txt. --- src/adapter.c | 92 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 16 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index 329c3ae0b..972d88772 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -174,6 +174,7 @@ struct conn_param { struct discovery_filter { uint8_t type; + char *pattern; uint16_t pathloss; int16_t rssi; GSList *uuids; @@ -2423,6 +2424,22 @@ static bool parse_discoverable(DBusMessageIter *value, return true; } +static bool parse_pattern(DBusMessageIter *value, + struct discovery_filter *filter) +{ + const char *pattern; + + if (dbus_message_iter_get_arg_type(value) != DBUS_TYPE_STRING) + return false; + + dbus_message_iter_get_basic(value, &pattern); + + free(filter->pattern); + filter->pattern = strdup(pattern); + + return true; +} + struct filter_parser { const char *name; bool (*func)(DBusMessageIter *iter, struct discovery_filter *filter); @@ -2433,6 +2450,7 @@ struct filter_parser { { "Transport", parse_transport }, { "DuplicateData", parse_duplicate_data }, { "Discoverable", parse_discoverable }, + { "Pattern", parse_pattern }, { } }; @@ -2473,6 +2491,7 @@ static bool parse_discovery_filter_dict(struct btd_adapter *adapter, (*filter)->type = get_scan_type(adapter); (*filter)->duplicate = false; (*filter)->discoverable = false; + (*filter)->pattern = NULL; dbus_message_iter_init(msg, &iter); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY || @@ -2518,10 +2537,11 @@ static bool parse_discovery_filter_dict(struct btd_adapter *adapter, goto invalid_args; DBG("filtered discovery params: transport: %d rssi: %d pathloss: %d " - " duplicate data: %s discoverable %s", (*filter)->type, - (*filter)->rssi, (*filter)->pathloss, + " duplicate data: %s discoverable %s pattern %s", + (*filter)->type, (*filter)->rssi, (*filter)->pathloss, (*filter)->duplicate ? "true" : "false", - (*filter)->discoverable ? "true" : "false"); + (*filter)->discoverable ? "true" : "false", + (*filter)->pattern); return true; @@ -6146,6 +6166,52 @@ static void filter_duplicate_data(void *data, void *user_data) *duplicate = client->discovery_filter->duplicate; } +static bool device_is_discoverable(struct btd_adapter *adapter, + struct eir_data *eir, const char *addr, + uint8_t bdaddr_type) +{ + GSList *l; + bool discoverable; + + if (bdaddr_type == BDADDR_BREDR || adapter->filtered_discovery) + discoverable = true; + else + discoverable = eir->flags & (EIR_LIM_DISC | EIR_GEN_DISC); + + /* + * Mark as not discoverable if no client has requested discovery and + * report has not set any discoverable flags. + */ + if (!adapter->discovery_list && !discoverable) + return false; + + /* Do a prefix match for both address and name if pattern is set */ + for (l = adapter->discovery_list; l; l = g_slist_next(l)) { + struct watch_client *client = l->data; + struct discovery_filter *filter = client->discovery_filter; + size_t pattern_len; + + if (!filter || !filter->pattern) + continue; + + /* Reset discoverable if a client has a pattern filter */ + discoverable = false; + + pattern_len = strlen(filter->pattern); + if (!pattern_len) + return true; + + if (!strncmp(filter->pattern, addr, pattern_len)) + return true; + + if (eir->name && !strncmp(filter->pattern, eir->name, + pattern_len)) + return true; + } + + return discoverable; +} + static void update_found_devices(struct btd_adapter *adapter, const bdaddr_t *bdaddr, uint8_t bdaddr_type, int8_t rssi, @@ -6162,21 +6228,14 @@ static void update_found_devices(struct btd_adapter *adapter, memset(&eir_data, 0, sizeof(eir_data)); eir_parse(&eir_data, data, data_len); - if (bdaddr_type == BDADDR_BREDR || adapter->filtered_discovery) - discoverable = true; - else - discoverable = eir_data.flags & (EIR_LIM_DISC | EIR_GEN_DISC); - ba2str(bdaddr, addr); + discoverable = device_is_discoverable(adapter, &eir_data, addr, + bdaddr_type); + dev = btd_adapter_find_device(adapter, bdaddr, bdaddr_type); if (!dev) { - /* - * If no client has requested discovery or the device is - * not marked as discoverable, then do not create new - * device objects. - */ - if (!adapter->discovery_list || !discoverable) { + if (!discoverable) { eir_data_free(&eir_data); return; } @@ -6219,8 +6278,9 @@ static void update_found_devices(struct btd_adapter *adapter, return; } - if (adapter->filtered_discovery && - !is_filter_match(adapter->discovery_list, &eir_data, rssi)) { + /* Don't continue if not discoverable or if filter don't match */ + if (!discoverable || (adapter->filtered_discovery && + !is_filter_match(adapter->discovery_list, &eir_data, rssi))) { eir_data_free(&eir_data); return; } From patchwork Thu Feb 20 00:28:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 11392807 X-Patchwork-Delegate: luiz.dentz@gmail.com 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 9D948109A for ; Thu, 20 Feb 2020 00:28:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7E97C21D56 for ; Thu, 20 Feb 2020 00:28:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SpVCiCH4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727184AbgBTA2j (ORCPT ); Wed, 19 Feb 2020 19:28:39 -0500 Received: from mail-pj1-f68.google.com ([209.85.216.68]:35026 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726811AbgBTA2i (ORCPT ); Wed, 19 Feb 2020 19:28:38 -0500 Received: by mail-pj1-f68.google.com with SMTP id q39so109257pjc.0 for ; Wed, 19 Feb 2020 16:28:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Sgn26Luz9XVSjFD2jqkmBUZAZcGhcXdUtpU3GjpAf84=; b=SpVCiCH4qxnkOHiKeuO2+uerhzIlHICbwjJ4v4yVB5TzupsmElr5hHSOFc9qYizVx/ L235RMj8a1ennulSDnlByKqA6twy/mtHjDkRtonIglFBy6NHgciS6h09ZyyJS/dBNg64 5yBeWuVhP4mqo/T6Ldrgy0qx3utYA0Ba/2PlvR5oDSv0sRmyXUvKgsGKMzhOUzRJUuDg Ulxjk0sJkEiPKN+3GDj6U/rbr4vF8vAdr3vQQVc9zicP3zQUdU/Ws0+yh7NpSP8cjS4t mTWR6XjVqWDqEYZrzMypMe5f/eW8rX4fEtE1FrPdkpDY0Ry+3PQCDM1Kjg3ytEw3YIWM 0qsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Sgn26Luz9XVSjFD2jqkmBUZAZcGhcXdUtpU3GjpAf84=; b=CfYVxaj/MsCqFbMWKdIRs0FzRb73PRkfVLEjNof285v/Pq2JJ66FELV+0RCy5a9FXN E+ZyX2ziaMxNmMdtg2WVPSotAVLx0q4jJeo83YCfiQ2TpjzO+yS/kddqAoSI5OT3/iSt 59ayHSCLog0f3vOf9rl/F1ighah/RVEHqFYlB2CkXzJR6fq9Q2mLBYnbRLrmUt+CcnK+ 2NaW6YlJ/tD3JYkGL8q8w1TaFLdInd0TzTFVO8GFSnxznqE/2jfPqlpW//5JVezqurAJ GDSToHZLbbPp3E7evFhktG2471+vKzxzYhqe1yHi4aBlzSi6p5xyJmJIthVS36RcvotQ USlg== X-Gm-Message-State: APjAAAWUF8B+6uRFzahETzYFXiczSzHKMcW28Ut4Jf13OQ89YqsiwbLr 5Sw2HFw4pnKB3fVxu9E5Y3e6VN6AcXI= X-Google-Smtp-Source: APXvYqzUPotkXLfnKf+pzSvaGdKcPXjZOfD6uAVwJk9uvTMJqBGuvd6kHTOX335lZwibWMG9jWbGYQ== X-Received: by 2002:a17:90a:af81:: with SMTP id w1mr438243pjq.14.1582158517924; Wed, 19 Feb 2020 16:28:37 -0800 (PST) Received: from vudentzs-t460s.amr.corp.intel.com ([2601:1c0:6800:1640::3287]) by smtp.gmail.com with ESMTPSA id c68sm769213pfc.156.2020.02.19.16.28.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 16:28:37 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 3/3] client: Add scan.pattern command Date: Wed, 19 Feb 2020 16:28:35 -0800 Message-Id: <20200220002835.8929-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200220002835.8929-1-luiz.dentz@gmail.com> References: <20200220002835.8929-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This uses the new Pattern filter: [bluetooth]# scan.pattern Living [bluetooth]# scan on SetDiscoveryFilter success Discovery started [CHG] Controller XX:XX:XX:XX:XX:XX Discovering: yes [NEW] Device XX:XX:XX:XX:XX:XX Living Room TV --- client/main.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/client/main.c b/client/main.c index 8bd0bac9e..422da5593 100644 --- a/client/main.c +++ b/client/main.c @@ -1157,6 +1157,7 @@ static void cmd_default_agent(int argc, char *argv[]) static struct set_discovery_filter_args { char *transport; + char *pattern; dbus_uint16_t rssi; dbus_int16_t pathloss; char **uuids; @@ -1241,6 +1242,10 @@ static void set_discovery_filter_setup(DBusMessageIter *iter, void *user_data) DBUS_TYPE_BOOLEAN, &args->discoverable); + if (args->pattern != NULL) + g_dbus_dict_append_entry(&dict, "Pattern", DBUS_TYPE_STRING, + &args->pattern); + dbus_message_iter_close_container(iter, &dict); } @@ -1440,6 +1445,22 @@ static void cmd_scan_filter_discoverable(int argc, char *argv[]) set_discovery_filter(false); } +static void cmd_scan_filter_pattern(int argc, char *argv[]) +{ + if (argc < 2 || !strlen(argv[1])) { + bt_shell_printf("Pattern: %s\n", filter.pattern); + return bt_shell_noninteractive_quit(EXIT_SUCCESS); + } + + free(filter.pattern); + filter.pattern = strdup(argv[1]); + + filter.set = false; + + if (filter.active) + set_discovery_filter(false); +} + static void filter_clear_uuids(void) { g_strfreev(filter.uuids); @@ -1473,6 +1494,12 @@ static void filter_clear_discoverable(void) filter.discoverable = false; } +static void filter_clear_pattern(void) +{ + free(filter.pattern); + filter.pattern = NULL; +} + struct clear_entry { const char *name; void (*clear) (void); @@ -1485,6 +1512,7 @@ static const struct clear_entry filter_clear[] = { { "transport", filter_clear_transport }, { "duplicate-data", filter_clear_duplicate }, { "discoverable", filter_clear_discoverable }, + { "pattern", filter_clear_pattern }, {} }; @@ -2639,8 +2667,11 @@ static const struct bt_shell_menu scan_menu = { { "discoverable", "[on/off]", cmd_scan_filter_discoverable, "Set/Get discoverable filter", NULL }, + { "pattern", "[value]", cmd_scan_filter_pattern, + "Set/Get pattern filter", + NULL }, { "clear", - "[uuids/rssi/pathloss/transport/duplicate-data/discoverable]", + "[uuids/rssi/pathloss/transport/duplicate-data/discoverable/pattern]", cmd_scan_filter_clear, "Clears discovery filter.", filter_clear_generator },