From patchwork Tue Mar 31 08:28:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Lowas-Rzechonek?= X-Patchwork-Id: 197197 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS,UNWANTED_LANGUAGE_BODY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4FE87C2D0F3 for ; Tue, 31 Mar 2020 08:28:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2713120787 for ; Tue, 31 Mar 2020 08:28:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=silvair-com.20150623.gappssmtp.com header.i=@silvair-com.20150623.gappssmtp.com header.b="fGCFxjcg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729624AbgCaI2G (ORCPT ); Tue, 31 Mar 2020 04:28:06 -0400 Received: from mail-wr1-f47.google.com ([209.85.221.47]:46141 "EHLO mail-wr1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726299AbgCaI2G (ORCPT ); Tue, 31 Mar 2020 04:28:06 -0400 Received: by mail-wr1-f47.google.com with SMTP id j17so24685359wru.13 for ; Tue, 31 Mar 2020 01:28:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silvair-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=b63k3DErR/1nXLYBaG+6sS5inCIckcEURx2bMOJ8U6k=; b=fGCFxjcgVMEbT3rbb4TM2F6RFSgO5ejvLyPieOe2uuIgTGAnqJr9+xOpB1ea9rT+nV MPwAhMd+CUrB6aEg0JKMNoq2MMo4/mvPx2We1HjxZgQHnlkh2dVEr6CyGqjMZO1tx4qH bndpf9elwKEPdtIHquF4F0qbK2lqDb/nhKrViamF7XL7owAEJnQAMOedUZTkylaDdW1P 9+Pvv9KsYvbbKE0iw7RGcN0IsR95zjl7lxufU4lWfyY88tH0yQU3spqvDQr34uDzIzDv sIQcfnin7YpRITywx08An8QHRIs4gYyZ72i5DoOo8IVEw70ZrlvMw5AfSenCK5Ds3q/d YvZg== 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=b63k3DErR/1nXLYBaG+6sS5inCIckcEURx2bMOJ8U6k=; b=cUKgtYWctUuaj0TB23SqZ6DMImhAddRpZUi1qm+2BAUBMuf5b7BSop9XkcAvEDU93Z kozhDK3v7bjE6Sbp1pMZMxajOYcnHonQ5LM1XaiKlVWcLLUI6IBXFxaIqemZAUx2ytfW joSncWGlJmzSfqlezYy+g3OopGkl7tPHP7o2HEN+vY8/yOenZGEbaz/uXqRSszYz0Woy 2bM2avIgZRMKbZs8L03z8Z45d23SC2N6AV51SJXCPOJg3y2FbnYTEjO4JTA8UfpYvD8z 6puIgD4Mql9wuDF3x0MwAI96OAkw41Yu1CzpuNYpxeljPGLxiASD7wfA4n1B6oOHa/7A O+0w== X-Gm-Message-State: ANhLgQ2XFkEUfyP0IcreF4ACcVgyO18LirGVj6m+Z8c730epzK5plshk nZW47DMTpajDNxkY2ofvBdR72YCxBF2p8w== X-Google-Smtp-Source: ADFU+vuGNlBGE6B6wp8zQ6h2h9OP4b0tTk1GgEJwDUijUbP4YQyO9n2N1BtDG/8GsNdNFK27CWb3eg== X-Received: by 2002:adf:e744:: with SMTP id c4mr18354949wrn.133.1585643284274; Tue, 31 Mar 2020 01:28:04 -0700 (PDT) Received: from mlowasrzechonek2133.silvair.lan ([217.153.94.18]) by smtp.gmail.com with ESMTPSA id x16sm6172296wrn.71.2020.03.31.01.28.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 01:28:03 -0700 (PDT) From: =?utf-8?q?Micha=C5=82_Lowas-Rzechonek?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 2/6] mesh: Remove unused 'server' argument Date: Tue, 31 Mar 2020 10:28:06 +0200 Message-Id: <20200331082810.10856-3-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200331082810.10856-1-michal.lowas-rzechonek@silvair.com> References: <20200331082810.10856-1-michal.lowas-rzechonek@silvair.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org --- mesh/manager.c | 2 +- mesh/prov-initiator.c | 1 - mesh/provision.h | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/mesh/manager.c b/mesh/manager.c index 0909c7e16..a4c2f2d41 100644 --- a/mesh/manager.c +++ b/mesh/manager.c @@ -256,7 +256,7 @@ static struct l_dbus_message *add_node_call(struct l_dbus *dbus, } - if (!initiator_start(PB_ADV, uuid, 99, 0, 60, add_pending->agent, + if (!initiator_start(PB_ADV, uuid, 99, 60, add_pending->agent, add_data_get, add_cmplt, node, add_pending)) { reply = dbus_error(msg, MESH_ERROR_FAILED, "Failed to start provisioning initiator"); diff --git a/mesh/prov-initiator.c b/mesh/prov-initiator.c index 7a767cfb3..d5bae114a 100644 --- a/mesh/prov-initiator.c +++ b/mesh/prov-initiator.c @@ -817,7 +817,6 @@ static void int_prov_ack(void *user_data, uint8_t msg_num) bool initiator_start(enum trans_type transport, uint8_t uuid[16], uint16_t max_ele, - uint16_t server, /* Only valid for PB-Remote */ uint32_t timeout, /* in seconds from mesh.conf */ struct mesh_agent *agent, mesh_prov_initiator_data_req_func_t get_prov_data, diff --git a/mesh/provision.h b/mesh/provision.h index 755d848a0..d6f6e0ab0 100644 --- a/mesh/provision.h +++ b/mesh/provision.h @@ -118,7 +118,6 @@ void acceptor_cancel(void *user_data); bool initiator_start(enum trans_type transport, uint8_t uuid[16], uint16_t max_ele, - uint16_t server, /* Only valid for PB-Remote */ uint32_t timeout, /* in seconds from mesh.conf */ struct mesh_agent *agent, mesh_prov_initiator_data_req_func_t get_prov_data, From patchwork Tue Mar 31 08:28:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Lowas-Rzechonek?= X-Patchwork-Id: 197195 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E553C2D0E8 for ; Tue, 31 Mar 2020 08:28:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CF0A220B80 for ; Tue, 31 Mar 2020 08:28:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=silvair-com.20150623.gappssmtp.com header.i=@silvair-com.20150623.gappssmtp.com header.b="dX/7dX2+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730140AbgCaI2N (ORCPT ); Tue, 31 Mar 2020 04:28:13 -0400 Received: from mail-wr1-f46.google.com ([209.85.221.46]:46150 "EHLO mail-wr1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729819AbgCaI2M (ORCPT ); Tue, 31 Mar 2020 04:28:12 -0400 Received: by mail-wr1-f46.google.com with SMTP id j17so24685589wru.13 for ; Tue, 31 Mar 2020 01:28:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silvair-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=IecFyvJoyjkzMoYy3KC7YwYN0zPf+QMyEtAzUmAo0zQ=; b=dX/7dX2+iz+boUt2hKzW5zckkvj8MK2rOSOBJqvmxvpXPnwHAMBZjRpDmYfqJoRmyK lJBRNqVuPwE8EzChB9/eC3qe2yVBXCPLtMSMQBb+tV2xkohuNTdvXvfwcTwI4LQPSVlS /aYpVm6BwtGcQDbnCt8JWyDW7RS9ZdDCAfn9LvJ9wwF1qVdmdSCJLhfK4gUgsyQ/BknH m7EdugTLHTYPilqgNRRyBMJGKLf1L4YEd9mlWNw+UUAV2oTrNGX82zMlT4rhQhX9v5F0 F8dDuoyuUg0dF3FsLLQYo1bMs3GitW59DNpiDsI10598pmtS0q90aASmcgmgb+ufGy30 yp3w== 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=IecFyvJoyjkzMoYy3KC7YwYN0zPf+QMyEtAzUmAo0zQ=; b=JZp9NA1A4hq1+nk2w+GEeo1e2NBI00msNKbhJd6uN0HU+RXcLVOGS4clS/GDYoNE2v 0T7vgMYo3d+jHu2Wemp2MuseZtwEabUvlUGrkMKnEBISjFy2Fkq+G8sQLFotzJ255KKQ JIJMT7hih2gB3AxdM5hid67LuIcypwce0VLCmTPVAkCX0sqNWEXMx2AKpPcvknsxC9oF Xqg0yGRTjhVAwsBxqpo3ZWyfs/oVNkPUYvc0jaD5LHa3GBiOecckLPZMTlOJBfFCpmG4 fOX+3sZgbcBGLbfQWu9PlTq3ouVLgL76nkMW8BM7hdWL1p66ofv3TYHnpOxGr2e6OTTP QDHQ== X-Gm-Message-State: ANhLgQ1y7OzHWVZXtgwvjFrZWabuvmgJa05Au+1wSetox6IPFrGt9npP Q50gfdDS4pAtlsPSq/tBsYefbA0HQydEqQ== X-Google-Smtp-Source: ADFU+vt8qBrzmCfrf/xqFAQh4ipllxRLNw1omtYgzfwJq9nIzIH9BTuyLbHjxS2gcIX/svhDkk7gWw== X-Received: by 2002:a5d:4f86:: with SMTP id d6mr18706644wru.315.1585643288105; Tue, 31 Mar 2020 01:28:08 -0700 (PDT) Received: from mlowasrzechonek2133.silvair.lan ([217.153.94.18]) by smtp.gmail.com with ESMTPSA id x16sm6172296wrn.71.2020.03.31.01.28.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 01:28:05 -0700 (PDT) From: =?utf-8?q?Micha=C5=82_Lowas-Rzechonek?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 4/6] mesh: Refresh provisioner's capabilities Date: Tue, 31 Mar 2020 10:28:08 +0200 Message-Id: <20200331082810.10856-5-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200331082810.10856-1-michal.lowas-rzechonek@silvair.com> References: <20200331082810.10856-1-michal.lowas-rzechonek@silvair.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org As provisioner's capabilities might change during application lifetime (e.g. no network link to download OOB key), let's query the agent again after application calls AddNode(). --- mesh/agent.c | 105 +++++++++++++++++++++++++++++++++++------- mesh/agent.h | 2 + mesh/manager.c | 33 +++++++++---- mesh/prov-initiator.c | 47 +++++++++++++++---- mesh/provision.h | 3 ++ 5 files changed, 154 insertions(+), 36 deletions(-) diff --git a/mesh/agent.c b/mesh/agent.c index 3ab3893a1..02993738c 100644 --- a/mesh/agent.c +++ b/mesh/agent.c @@ -40,7 +40,8 @@ typedef enum { MESH_AGENT_REQUEST_IN_ALPHA, MESH_AGENT_REQUEST_STATIC_OOB, MESH_AGENT_REQUEST_PRIVATE_KEY, - MESH_AGENT_REQUEST_PUBLIC_KEY + MESH_AGENT_REQUEST_PUBLIC_KEY, + MESH_AGENT_REQUEST_CAPABILITIES, } agent_request_type_t; struct agent_request { @@ -158,6 +159,25 @@ static void parse_oob_info(struct mesh_agent_prov_caps *caps, } } +static void parse_properties(struct mesh_agent *agent, + struct l_dbus_message_iter *properties) +{ + const char *key, *uri_string; + struct l_dbus_message_iter variant; + + while (l_dbus_message_iter_next_entry(properties, &key, &variant)) { + if (!strcmp(key, "Capabilities")) { + parse_prov_caps(&agent->caps, &variant); + } else if (!strcmp(key, "URI")) { + l_dbus_message_iter_get_variant(&variant, "s", + &uri_string); + /* TODO: compute hash */ + } else if (!strcmp(key, "OutOfBandInfo")) { + parse_oob_info(&agent->caps, &variant); + } + } +} + static void agent_free(void *agent_data) { struct mesh_agent *agent = agent_data; @@ -193,6 +213,7 @@ static void agent_free(void *agent_data) case MESH_AGENT_REQUEST_VIBRATE: case MESH_AGENT_REQUEST_OUT_NUMERIC: case MESH_AGENT_REQUEST_OUT_ALPHA: + case MESH_AGENT_REQUEST_CAPABILITIES: simple_cb = agent->req->cb; simple_cb(req->user_data, err); default: @@ -235,26 +256,13 @@ struct mesh_agent *mesh_agent_create(const char *path, const char *owner, struct l_dbus_message_iter *properties) { struct mesh_agent *agent; - const char *key, *uri_string; - struct l_dbus_message_iter variant; agent = l_new(struct mesh_agent, 1); - - while (l_dbus_message_iter_next_entry(properties, &key, &variant)) { - if (!strcmp(key, "Capabilities")) { - parse_prov_caps(&agent->caps, &variant); - } else if (!strcmp(key, "URI")) { - l_dbus_message_iter_get_variant(&variant, "s", - &uri_string); - /* TODO: compute hash */ - } else if (!strcmp(key, "OutOfBandInfo")) { - parse_oob_info(&agent->caps, &variant); - } - } - agent->owner = l_strdup(owner); agent->path = l_strdup(path); + parse_properties(agent, properties); + l_queue_push_tail(agents, agent); return agent; @@ -289,13 +297,76 @@ static int get_reply_error(struct l_dbus_message *reply) if (l_dbus_message_is_error(reply)) { l_dbus_message_get_error(reply, &name, &desc); - l_error("Agent failed output action (%s), %s", name, desc); + l_error("Agent failed (%s), %s", name, desc); return MESH_ERROR_FAILED; } return MESH_ERROR_NONE; } +static void properties_reply(struct l_dbus_message *reply, void *user_data) +{ + struct mesh_agent *agent = user_data; + struct agent_request *req; + mesh_agent_cb_t cb; + struct l_dbus_message_iter properties; + int err; + + if (!l_queue_find(agents, simple_match, agent) || !agent->req) + return; + + req = agent->req; + + err = get_reply_error(reply); + + if (err != MESH_ERROR_NONE) + goto fail; + + if (!l_dbus_message_get_arguments(reply, "a{sv}", &properties)) { + err = MESH_ERROR_FAILED; + goto fail; + } + + parse_properties(agent, &properties); +fail: + if (req->cb) + { + cb = req->cb; + cb(req->user_data, err); + } + + l_dbus_message_unref(req->msg); + l_free(req); + agent->req = NULL; +} + +void mesh_agent_refresh(struct mesh_agent *agent, mesh_agent_cb_t cb, + void *user_data) +{ + struct l_dbus *dbus = dbus_get_bus(); + struct l_dbus_message *msg; + struct l_dbus_message_builder *builder; + + agent->req = create_request(MESH_AGENT_REQUEST_CAPABILITIES, (void *)cb, + user_data); + + msg = l_dbus_message_new_method_call(dbus, agent->owner, agent->path, + L_DBUS_INTERFACE_PROPERTIES, + "GetAll"); + + builder = l_dbus_message_builder_new(msg); + l_dbus_message_builder_append_basic(builder, 's', + MESH_PROVISION_AGENT_INTERFACE); + l_dbus_message_builder_finalize(builder); + l_dbus_message_builder_destroy(builder); + + l_dbus_send_with_reply(dbus_get_bus(), msg, properties_reply, agent, + NULL); + + agent->req->msg = l_dbus_message_ref(msg); +} + + static void simple_reply(struct l_dbus_message *reply, void *user_data) { struct mesh_agent *agent = user_data; diff --git a/mesh/agent.h b/mesh/agent.h index 80333acd5..6cc3d0f71 100644 --- a/mesh/agent.h +++ b/mesh/agent.h @@ -42,6 +42,8 @@ void mesh_agent_init(void); void mesh_agent_cleanup(void); struct mesh_agent *mesh_agent_create(const char *path, const char *owner, struct l_dbus_message_iter *properties); +void mesh_agent_refresh(struct mesh_agent *agent, mesh_agent_cb_t cb, + void *user_data); void mesh_agent_remove(struct mesh_agent *agent); void mesh_agent_cancel(struct mesh_agent *agent); diff --git a/mesh/manager.c b/mesh/manager.c index a4c2f2d41..9ec4a1468 100644 --- a/mesh/manager.c +++ b/mesh/manager.c @@ -81,6 +81,9 @@ static void free_pending_add_call() l_dbus_remove_watch(dbus_get_bus(), add_pending->disc_watch); + if (add_pending->msg) + l_dbus_message_unref(add_pending->msg); + l_free(add_pending); add_pending = NULL; } @@ -212,6 +215,23 @@ static bool add_data_get(void *user_data, uint8_t num_ele) return true; } +static void add_start(void *user_data, int err) +{ + struct l_dbus_message *reply; + + l_info("Start callback"); + + if (err == MESH_ERROR_NONE) + reply = l_dbus_message_new_method_return(add_pending->msg); + else + reply = dbus_error(add_pending->msg, MESH_ERROR_FAILED, + "Failed to start provisioning initiator"); + + l_dbus_send(dbus_get_bus(), reply); + + add_pending->msg = NULL; +} + static struct l_dbus_message *add_node_call(struct l_dbus *dbus, struct l_dbus_message *msg, void *user_data) @@ -243,6 +263,7 @@ static struct l_dbus_message *add_node_call(struct l_dbus *dbus, /* Invoke Prov Initiator */ add_pending = l_new(struct add_data, 1); + add_pending->msg = l_dbus_message_ref(msg); memcpy(add_pending->uuid, uuid, 16); add_pending->node = node; add_pending->agent = node_get_agent(node); @@ -255,20 +276,14 @@ static struct l_dbus_message *add_node_call(struct l_dbus *dbus, goto fail; } - - if (!initiator_start(PB_ADV, uuid, 99, 60, add_pending->agent, - add_data_get, add_cmplt, node, add_pending)) { - reply = dbus_error(msg, MESH_ERROR_FAILED, - "Failed to start provisioning initiator"); - goto fail; - } + initiator_start(PB_ADV, uuid, 99, 60, add_pending->agent, add_start, + add_data_get, add_cmplt, node, add_pending); add_pending->disc_watch = l_dbus_add_disconnect_watch(dbus, node_get_owner(node), prov_disc_cb, NULL, NULL); - return l_dbus_message_new_method_return(msg); - + return NULL; fail: l_free(add_pending); add_pending = NULL; diff --git a/mesh/prov-initiator.c b/mesh/prov-initiator.c index f2ebff69e..17bda6521 100644 --- a/mesh/prov-initiator.c +++ b/mesh/prov-initiator.c @@ -36,6 +36,7 @@ #include "mesh/pb-adv.h" #include "mesh/mesh.h" #include "mesh/agent.h" +#include "mesh/error.h" /* Quick size sanity check */ static const uint16_t expected_pdu_size[] = { @@ -77,6 +78,7 @@ enum int_state { #define MAT_SECRET (MAT_REMOTE_PUBLIC | MAT_LOCAL_PRIVATE) struct mesh_prov_initiator { + mesh_prov_initiator_start_func_t start_cb; mesh_prov_initiator_complete_func_t complete_cb; mesh_prov_initiator_data_req_func_t data_req_cb; prov_trans_tx_t trans_tx; @@ -102,6 +104,7 @@ struct mesh_prov_initiator { uint8_t private_key[32]; uint8_t secret[32]; uint8_t rand_auth_workspace[48]; + uint8_t uuid[16]; }; static struct mesh_prov_initiator *prov = NULL; @@ -814,17 +817,45 @@ static void int_prov_ack(void *user_data, uint8_t msg_num) } } +static void initiator_open_cb(void *user_data, int err) +{ + bool result; + + if (!prov) + return; + + if (err != MESH_ERROR_NONE) + goto fail; + + /* Always register for PB-ADV */ + result = pb_adv_reg(true, int_prov_open, int_prov_close, int_prov_rx, + int_prov_ack, prov->uuid, prov); + + if (!result) { + err = MESH_ERROR_FAILED; + goto fail; + } + + if (!prov) + return; + + prov->start_cb(prov->caller_data, MESH_ERROR_NONE); + return; +fail: + prov->start_cb(prov->caller_data, err); + initiator_free(); +} + bool initiator_start(enum trans_type transport, uint8_t uuid[16], uint16_t max_ele, uint32_t timeout, /* in seconds from mesh.conf */ struct mesh_agent *agent, + mesh_prov_initiator_start_func_t start_cb, mesh_prov_initiator_data_req_func_t data_req_cb, mesh_prov_initiator_complete_func_t complete_cb, void *node, void *caller_data) { - bool result; - /* Invoked from Add() method in mesh-api.txt, to add a * remote unprovisioned device network. */ @@ -837,19 +868,15 @@ bool initiator_start(enum trans_type transport, prov->node = node; prov->agent = agent; prov->complete_cb = complete_cb; + prov->start_cb = start_cb; prov->data_req_cb = data_req_cb; prov->caller_data = caller_data; prov->previous = -1; + memcpy(prov->uuid, uuid, 16); - /* Always register for PB-ADV */ - result = pb_adv_reg(true, int_prov_open, int_prov_close, int_prov_rx, - int_prov_ack, uuid, prov); - - if (result) - return true; + mesh_agent_refresh(prov->agent, initiator_open_cb, prov); - initiator_free(); - return false; + return true; } void initiator_cancel(void *user_data) diff --git a/mesh/provision.h b/mesh/provision.h index 43f53f935..1d78ed8e2 100644 --- a/mesh/provision.h +++ b/mesh/provision.h @@ -100,6 +100,8 @@ typedef bool (*mesh_prov_acceptor_complete_func_t)(void *user_data, uint8_t status, struct mesh_prov_node_info *info); +typedef void (*mesh_prov_initiator_start_func_t)(void *user_data, int err); + typedef bool (*mesh_prov_initiator_data_req_func_t)(void *user_data, uint8_t num_elem); @@ -120,6 +122,7 @@ bool initiator_start(enum trans_type transport, uint16_t max_ele, uint32_t timeout, /* in seconds from mesh.conf */ struct mesh_agent *agent, + mesh_prov_initiator_start_func_t start_cb, mesh_prov_initiator_data_req_func_t data_req_cb, mesh_prov_initiator_complete_func_t complete_cb, void *node, void *caller_data); From patchwork Tue Mar 31 08:28:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Lowas-Rzechonek?= X-Patchwork-Id: 197196 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8E06C43331 for ; Tue, 31 Mar 2020 08:28:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8E34B20B80 for ; Tue, 31 Mar 2020 08:28:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=silvair-com.20150623.gappssmtp.com header.i=@silvair-com.20150623.gappssmtp.com header.b="ciCE58r7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730139AbgCaI2M (ORCPT ); Tue, 31 Mar 2020 04:28:12 -0400 Received: from mail-wm1-f50.google.com ([209.85.128.50]:33670 "EHLO mail-wm1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730099AbgCaI2L (ORCPT ); Tue, 31 Mar 2020 04:28:11 -0400 Received: by mail-wm1-f50.google.com with SMTP id z14so1450377wmf.0 for ; Tue, 31 Mar 2020 01:28:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silvair-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=lhpsPY4jlAN7Ykwz9dJPh8jnrQJzpF+87K6jrmmQP9I=; b=ciCE58r7hn/nTcSA/xIX322uSzAEmd4QmW1ybXkoYbCRwgrZ7O4YdpSV1HccMQ+RXX aNLt8lYn3uC7QhCAkPqcCx8Vw3kGYg14AaCy00+Rtt5+FgkVjJ76otLttJ8s2igl5Dgd MAdV+pCIHGLAQ8n4OXnvFh7LrIqhjpQlDEG9Fr101xX5nh1wLlBPnGfuefUNdWHuH1Kt a+1X06tE22NZHp/Yzbao99gSSqchWeGaBb9m8YlsNimMnOP1z+lHrdQ1D+0nfpsWOX81 qsOyeCy4KQlVnh6tum4hjqzFfUXxk05r1WOkR/lhdF6NPW7t7VLzhbBrVCCKWRRbWGxS yy0A== 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=lhpsPY4jlAN7Ykwz9dJPh8jnrQJzpF+87K6jrmmQP9I=; b=gTSGKm2kdn79qq4QHE5ZbnHlXSvI8ZQlWWPgXrS4wbuirz7bLGgMpjD5EK+sDT0Pk8 T/BBkuaCbn06Iebu+AfglIihKO0IhAHhQmkr3vGPrQL275etrXu/3jCQjvNxTADyjfvk hLm2ikNV1wt92sN7cWLXMw+DguyX5dS+wy9yu08XbLoM459RhASycrILmgIcA2dmP2t+ 1VShiWkjnbyXxXGyY21sgB/AeZ78cj/jLfzhXhJBczDVmVEeZEQEklQZRgGpvHJmofyl jvG7EJrXpRbznB4/GQmUaZ8W7VkCCblzLIVYRLUMhTZqZQYVeJWE8Le6zdF8wNih4b9I zRJg== X-Gm-Message-State: ANhLgQ1JGlr5JfXhhSxRMQqa3t4eRcH3XmE2jv4gRY8XeDYSLiNfLbsN npQ2US5+CdRQEo6QrmNCvLrBUw1c1duBDA== X-Google-Smtp-Source: ADFU+vsu8q3LnJDjMC9nvyI2lwrBnA+cK6rLxL6tt/tp/blHLWuh14ZHBaUa2BuZxu5PSNnEOvFByw== X-Received: by 2002:a1c:2e04:: with SMTP id u4mr2352140wmu.185.1585643288992; Tue, 31 Mar 2020 01:28:08 -0700 (PDT) Received: from mlowasrzechonek2133.silvair.lan ([217.153.94.18]) by smtp.gmail.com with ESMTPSA id x16sm6172296wrn.71.2020.03.31.01.28.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 01:28:08 -0700 (PDT) From: =?utf-8?q?Micha=C5=82_Lowas-Rzechonek?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 5/6] mesh: Honor provisioner's capabilities Date: Tue, 31 Mar 2020 10:28:09 +0200 Message-Id: <20200331082810.10856-6-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200331082810.10856-1-michal.lowas-rzechonek@silvair.com> References: <20200331082810.10856-1-michal.lowas-rzechonek@silvair.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch makes the daemon select authentication method based from capabilities supported by both provisioned node and provisioner application. --- mesh/prov-initiator.c | 82 ++++++++++++++++++++++++++---------------- tools/mesh-cfgclient.c | 7 ++++ 2 files changed, 58 insertions(+), 31 deletions(-) diff --git a/mesh/prov-initiator.c b/mesh/prov-initiator.c index 17bda6521..a36d090f3 100644 --- a/mesh/prov-initiator.c +++ b/mesh/prov-initiator.c @@ -38,6 +38,8 @@ #include "mesh/agent.h" #include "mesh/error.h" +#define MIN(x, y) ((x) < (y) ? (x) : (y)) + /* Quick size sanity check */ static const uint16_t expected_pdu_size[] = { 2, /* PROV_INVITE */ @@ -587,6 +589,44 @@ failure: int_prov_close(prov, fail_code[1]); } +static void int_prov_start_auth(const struct mesh_agent_prov_caps *prov_caps, + const struct mesh_net_prov_caps *dev_caps, + struct prov_start *start) +{ + uint8_t pub_type = prov_caps->pub_type & dev_caps->pub_type; + uint8_t static_type = prov_caps->static_type & dev_caps->static_type; + uint16_t output_action = prov_caps->output_action & + dev_caps->output_action; + uint8_t output_size = MIN(prov_caps->output_size, + dev_caps->output_size); + uint16_t input_action = prov_caps->input_action & + dev_caps->input_action; + uint8_t input_size = MIN(prov_caps->input_size, dev_caps->input_size); + + if (pub_type) + start->pub_key = 0x01; + + /* Parse OOB Options, prefer static, then out, then in */ + if (static_type) { + start->auth_method = 0x01; + return; + } + + if(output_size && output_action) { + start->auth_method = 0x02; + start->auth_action = u16_high_bit(L_BE16_TO_CPU(output_action)); + start->auth_size = MIN(output_size, 8); + return; + } + + if (input_size && input_action) { + start->auth_method = 0x03; + start->auth_action = u16_high_bit(L_BE16_TO_CPU(input_action)); + start->auth_size = MIN(input_size, 8); + return; + } +} + static void int_prov_rx(void *user_data, const uint8_t *data, uint16_t len) { struct mesh_prov_initiator *rx_prov = user_data; @@ -638,43 +678,23 @@ static void int_prov_rx(void *user_data, const uint8_t *data, uint16_t len) goto failure; } - /* If Public Key available Out of Band, use it */ - if (prov->conf_inputs.caps.pub_type) { - prov->conf_inputs.start.pub_key = 0x01; + /* + * Select auth mechanism from methods supported by both + * parties. + */ + int_prov_start_auth(mesh_agent_get_caps(prov->agent), + &prov->conf_inputs.caps, + &prov->conf_inputs.start); + + if (prov->conf_inputs.start.pub_key == 0x01) { prov->expected = PROV_CONFIRM; /* Prompt Agent for remote Public Key */ mesh_agent_request_public_key(prov->agent, pub_key_cb, prov); - /* Nothing else for us to do now */ } else prov->expected = PROV_PUB_KEY; - /* Parse OOB Options, prefer static, then out, then in */ - if (prov->conf_inputs.caps.static_type) { - - prov->conf_inputs.start.auth_method = 0x01; - - } else if (prov->conf_inputs.caps.output_size && - prov->conf_inputs.caps.output_action) { - - prov->conf_inputs.start.auth_method = 0x02; - prov->conf_inputs.start.auth_action = - u16_high_bit(l_get_be16(data + 6)); - prov->conf_inputs.start.auth_size = - (data[5] > 8 ? 8 : data[5]); - - } else if (prov->conf_inputs.caps.input_size && - prov->conf_inputs.caps.input_action) { - - prov->conf_inputs.start.auth_method = 0x03; - prov->conf_inputs.start.auth_action = - u16_high_bit(l_get_be16(data + 9)); - prov->conf_inputs.start.auth_size = - (data[8] > 8 ? 8 : data[8]); - - } - out = l_malloc(1 + sizeof(prov->conf_inputs.start)); out[0] = PROV_START; memcpy(out + 1, &prov->conf_inputs.start, @@ -789,7 +809,7 @@ static void int_prov_ack(void *user_data, uint8_t msg_num) switch (prov->state) { case INT_PROV_START_SENT: prov->state = INT_PROV_START_ACKED; - if (prov->conf_inputs.caps.pub_type == 0) + if (!prov->conf_inputs.start.pub_key) send_pub_key(prov); break; @@ -798,7 +818,7 @@ static void int_prov_ack(void *user_data, uint8_t msg_num) break; case INT_PROV_KEY_SENT: - if (prov->conf_inputs.caps.pub_type == 1) + if (prov->conf_inputs.start.pub_key) int_prov_auth(); break; diff --git a/tools/mesh-cfgclient.c b/tools/mesh-cfgclient.c index eafabf825..08cae899f 100644 --- a/tools/mesh-cfgclient.c +++ b/tools/mesh-cfgclient.c @@ -617,6 +617,13 @@ static bool register_agent(void) return false; } + if (!l_dbus_object_add_interface(dbus, app.agent_path, + L_DBUS_INTERFACE_PROPERTIES, NULL)) { + l_error("Failed to add interface %s", + L_DBUS_INTERFACE_PROPERTIES); + return false; + } + return true; }