From patchwork Wed May 19 19:09:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Gix X-Patchwork-Id: 442610 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=-11.8 required=3.0 tests=BAYES_00, 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 E1940C43461 for ; Wed, 19 May 2021 19:09:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CB30961355 for ; Wed, 19 May 2021 19:09:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231915AbhESTK7 (ORCPT ); Wed, 19 May 2021 15:10:59 -0400 Received: from mga06.intel.com ([134.134.136.31]:6662 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231899AbhESTK6 (ORCPT ); Wed, 19 May 2021 15:10:58 -0400 IronPort-SDR: bawwuEJVITwEx6g1XEN/kmEf3FtmmOy4fS2hBtFJzhaDhdS2rNBqp/PijiAhVW9yRjY0N5Qhe9 WCgDKkOSuPiQ== X-IronPort-AV: E=McAfee;i="6200,9189,9989"; a="262284397" X-IronPort-AV: E=Sophos;i="5.82,313,1613462400"; d="scan'208";a="262284397" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2021 12:09:36 -0700 IronPort-SDR: 3bEVjwGlCb3D6tqnc1iV6yUCBek6tsCzu8Eh5F8W/E8Ir/yyCsfYPJBHXo+gzu2bQmMUTC0tI8 kZo25q7bg7BQ== X-IronPort-AV: E=Sophos;i="5.82,313,1613462400"; d="scan'208";a="439855259" Received: from bgi1-mobl2.amr.corp.intel.com ([10.212.229.7]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2021 12:09:36 -0700 From: Brian Gix To: linux-bluetooth@vger.kernel.org Cc: inga.stotland@intel.com, brian.gix@intel.com Subject: [PATCH BlueZ v3 1/6] mesh: Fix delivery of PB-ACK to acceptors Date: Wed, 19 May 2021 12:09:20 -0700 Message-Id: <20210519190925.1723012-2-brian.gix@intel.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210519190925.1723012-1-brian.gix@intel.com> References: <20210519190925.1723012-1-brian.gix@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Remove unneeded initialization that prevented the Acceptor roll of ever recognizing a valid PB-ACK. --- mesh/pb-adv.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mesh/pb-adv.c b/mesh/pb-adv.c index c74dae79f..83f922aa8 100644 --- a/mesh/pb-adv.c +++ b/mesh/pb-adv.c @@ -358,7 +358,6 @@ static void pb_adv_packet(void *user_data, const uint8_t *pkt, uint16_t len) first = !session->link_id; session->link_id = link_id; session->last_peer_trans_num = 0xFF; - session->local_acked = 0xFF; session->peer_trans_num = 0x00; session->local_trans_num = 0x7F; session->opened = true; From patchwork Wed May 19 19:09:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Gix X-Patchwork-Id: 442609 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=-11.8 required=3.0 tests=BAYES_00, 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 DDB8CC433ED for ; Wed, 19 May 2021 19:09:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C1EFA61355 for ; Wed, 19 May 2021 19:09:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231935AbhESTLB (ORCPT ); Wed, 19 May 2021 15:11:01 -0400 Received: from mga06.intel.com ([134.134.136.31]:6666 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231902AbhESTK7 (ORCPT ); Wed, 19 May 2021 15:10:59 -0400 IronPort-SDR: 7hEubBTU9f9JRmc9RhoUIjvJKIOBNxlIK3ORjWtXVuyWjb/SAmqnLniPfw2buPdQWHDkoM+nCj bvJPOoixvJmw== X-IronPort-AV: E=McAfee;i="6200,9189,9989"; a="262284398" X-IronPort-AV: E=Sophos;i="5.82,313,1613462400"; d="scan'208";a="262284398" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2021 12:09:37 -0700 IronPort-SDR: 4v5apE+ntVv2GQvSfUnYjLgKQLVoHqW+DjpjTatrP/ozpLeNy1+X5CeVgKT3qQXSXbgaBxSRwU o/u13JUq/Lxg== X-IronPort-AV: E=Sophos;i="5.82,313,1613462400"; d="scan'208";a="439855263" Received: from bgi1-mobl2.amr.corp.intel.com ([10.212.229.7]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2021 12:09:36 -0700 From: Brian Gix To: linux-bluetooth@vger.kernel.org Cc: inga.stotland@intel.com, brian.gix@intel.com Subject: [PATCH BlueZ v3 2/6] mesh: Normalize endian of public/private ECC keys Date: Wed, 19 May 2021 12:09:21 -0700 Message-Id: <20210519190925.1723012-3-brian.gix@intel.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210519190925.1723012-1-brian.gix@intel.com> References: <20210519190925.1723012-1-brian.gix@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org The Mesh profile specification defines a Mesh byte order of Big Endian for Public keys used to calculate shared secrets. Further the specification sample data also show this same byte order for Private keys. However, our internal ECDH shared secret calculation requires Little Endian byte ordering. This fixes our DBus interface, and debugging output to use Mesh Byte Ordering (Big Endian) for all human readable input/output. --- mesh/prov-acceptor.c | 8 +++++++- mesh/prov-initiator.c | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/mesh/prov-acceptor.c b/mesh/prov-acceptor.c index e806b12ef..0dbb84f50 100644 --- a/mesh/prov-acceptor.c +++ b/mesh/prov-acceptor.c @@ -223,7 +223,11 @@ static bool acp_credentials(struct mesh_prov_acceptor *prov) print_packet("PublicKeyProv", prov->conf_inputs.prv_pub_key, 64); print_packet("PublicKeyDev", prov->conf_inputs.dev_pub_key, 64); + + /* Normalize for debug out -- No longer needed for calculations */ + swap_u256_bytes(prov->private_key); print_packet("PrivateKeyLocal", prov->private_key, 32); + print_packet("ConfirmationInputs", &prov->conf_inputs, sizeof(prov->conf_inputs)); print_packet("ECDHSecret", prov->secret, 32); @@ -307,11 +311,13 @@ static void priv_key_cb(void *user_data, int err, uint8_t *key, uint32_t len) return; } + /* API delivers Mesh byte order, switch to little endian */ + swap_u256_bytes(key); memcpy(prov->private_key, key, 32); ecc_make_public_key(prov->private_key, prov->conf_inputs.dev_pub_key); - /* Convert to Mesh byte order */ + /* Convert Public key to Mesh byte order */ swap_u256_bytes(prov->conf_inputs.dev_pub_key); swap_u256_bytes(prov->conf_inputs.dev_pub_key + 32); diff --git a/mesh/prov-initiator.c b/mesh/prov-initiator.c index ae9c646de..c62577523 100644 --- a/mesh/prov-initiator.c +++ b/mesh/prov-initiator.c @@ -222,6 +222,9 @@ static bool int_credentials(struct mesh_prov_initiator *prov) print_packet("PublicKeyProv", prov->conf_inputs.prv_pub_key, 64); print_packet("PublicKeyDev", prov->conf_inputs.dev_pub_key, 64); + + /* Print DBG out in Mesh order */ + swap_u256_bytes(prov->private_key); print_packet("PrivateKeyLocal", prov->private_key, 32); print_packet("ConfirmationInputs", &prov->conf_inputs, sizeof(prov->conf_inputs)); From patchwork Wed May 19 19:09:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Gix X-Patchwork-Id: 442608 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=-11.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 0A7A7C43462 for ; Wed, 19 May 2021 19:09:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E3504613AD for ; Wed, 19 May 2021 19:09:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231939AbhESTLD (ORCPT ); Wed, 19 May 2021 15:11:03 -0400 Received: from mga06.intel.com ([134.134.136.31]:6666 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231916AbhESTLA (ORCPT ); Wed, 19 May 2021 15:11:00 -0400 IronPort-SDR: +3rjVoc2yAoKRWGPVVz0IxD5loLKGbGITM7YLkqHp4Ck3bgy+f+hUgwSRAxsl+787oIC+HqNTm 8sm0lRij6HZQ== X-IronPort-AV: E=McAfee;i="6200,9189,9989"; a="262284401" X-IronPort-AV: E=Sophos;i="5.82,313,1613462400"; d="scan'208";a="262284401" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2021 12:09:37 -0700 IronPort-SDR: wkYeBk1EtFJHN0eFblwU2Jn6CCBA20ct5H52GUK/54WjjmGBpb5IYOX1ZoktVNXbwo3GKS3aQq AGkq+q9BbsPQ== X-IronPort-AV: E=Sophos;i="5.82,313,1613462400"; d="scan'208";a="439855270" Received: from bgi1-mobl2.amr.corp.intel.com ([10.212.229.7]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2021 12:09:37 -0700 From: Brian Gix To: linux-bluetooth@vger.kernel.org Cc: inga.stotland@intel.com, brian.gix@intel.com Subject: [PATCH BlueZ v3 4/6] test/mesh: Add support for testing more OOB auth Date: Wed, 19 May 2021 12:09:23 -0700 Message-Id: <20210519190925.1723012-5-brian.gix@intel.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210519190925.1723012-1-brian.gix@intel.com> References: <20210519190925.1723012-1-brian.gix@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org To pass IOP testing, we need to be able to support Input OOB and Out of band Public Key exchange, This patch adds agent methods to support those capabilities, but are turned off because the test code uses insecure fixed values instead of randomized values. --- test/agent.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/agent.py b/test/agent.py index b46cd95f4..57a74183d 100755 --- a/test/agent.py +++ b/test/agent.py @@ -35,7 +35,9 @@ class Agent(dbus.service.Object): caps = [] oob = [] caps.append('out-numeric') + #caps.append('in-numeric') -- Do not use well known in-oob caps.append('static-oob') + #caps.append('public-oob') -- Do not use well known key pairs oob.append('other') return { AGENT_IFACE: { @@ -56,6 +58,27 @@ class Agent(dbus.service.Object): print(set_cyan('DisplayNumeric ('), type, set_cyan(') number ='), set_green(value)) + @dbus.service.method(AGENT_IFACE, in_signature="s", out_signature="u") + def PromptNumeric(self, type): + # Sample in-oob -- DO-NOT-USE + value = 12345 + print(set_cyan('PromptNumeric ('), type, + set_cyan(') number ='), set_green(value)) + return dbus.UInt32(value) + + @dbus.service.method(AGENT_IFACE, in_signature="", out_signature="ay") + def PrivateKey(self): + # Sample Public/Private pair from Mesh Profile Spec DO-NOT-USE + private_key_str = '6872b109ea0574adcf88bf6da64996a4624fe018191d9322a4958837341284bc' + public_key_str = 'ce9027b5375fe5d3ed3ac89cef6a8370f699a2d3130db02b87e7a632f15b0002e5b72c775127dc0ce686002ecbe057e3d6a8000d4fbf2cdfffe0d38a1c55a043' + print(set_cyan('PrivateKey ()')) + print(set_cyan('Enter Public key on remote device: '), + set_green(public_key_str)); + private_key = bytearray.fromhex(private_key_str) + + return dbus.Array(private_key, signature='y') + + @dbus.service.method(AGENT_IFACE, in_signature="s", out_signature="ay") def PromptStatic(self, type): static_key = numpy.random.randint(0, 255, 16) From patchwork Wed May 19 19:09:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Gix X-Patchwork-Id: 442607 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=-8.9 required=3.0 tests=BAYES_00, 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 69A4DC43470 for ; Wed, 19 May 2021 19:09:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E1526135A for ; Wed, 19 May 2021 19:09:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231862AbhESTLD (ORCPT ); Wed, 19 May 2021 15:11:03 -0400 Received: from mga06.intel.com ([134.134.136.31]:6662 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231922AbhESTLA (ORCPT ); Wed, 19 May 2021 15:11:00 -0400 IronPort-SDR: /34KjFQleJtFssMp9+ocihzYasDtI4AwN9A/NSyKazDIUudAW6ZwBjs1+TbCoul9aaQCkhAAaq Zdj5JEcCVyAg== X-IronPort-AV: E=McAfee;i="6200,9189,9989"; a="262284403" X-IronPort-AV: E=Sophos;i="5.82,313,1613462400"; d="scan'208";a="262284403" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2021 12:09:37 -0700 IronPort-SDR: MSNpX5ZCEK2rDdaim0oDdQ1Q80XIQUWkoijhPUfTRBqvMAEL60rfQ9efwpeJTv/fy2d6IXZx85 qw+/qFiFFeQA== X-IronPort-AV: E=Sophos;i="5.82,313,1613462400"; d="scan'208";a="439855273" Received: from bgi1-mobl2.amr.corp.intel.com ([10.212.229.7]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2021 12:09:37 -0700 From: Brian Gix To: linux-bluetooth@vger.kernel.org Cc: inga.stotland@intel.com, brian.gix@intel.com Subject: [PATCH BlueZ v3 5/6] mesh: Add single threading to prov-acp ob messaging Date: Wed, 19 May 2021 12:09:24 -0700 Message-Id: <20210519190925.1723012-6-brian.gix@intel.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210519190925.1723012-1-brian.gix@intel.com> References: <20210519190925.1723012-1-brian.gix@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Certain IOP and stress testing scenarios can cause additional outbound messages to be attempted before the prior outbound message completes. This patch adds queuing if outbpund messages are attempted too quickly so that the additional message is not sent until the prior message is ACKed. --- mesh/prov-acceptor.c | 88 +++++++++++++++++++++++++++----------------- mesh/provision.h | 1 + 2 files changed, 56 insertions(+), 33 deletions(-) diff --git a/mesh/prov-acceptor.c b/mesh/prov-acceptor.c index 0dbb84f50..f579a143b 100644 --- a/mesh/prov-acceptor.c +++ b/mesh/prov-acceptor.c @@ -42,26 +42,15 @@ static const uint16_t expected_pdu_size[] = { #define BEACON_TYPE_UNPROVISIONED 0x00 +struct deferred_cmd { + uint16_t len; + uint8_t cmd[]; +}; + static const uint8_t pkt_filter = MESH_AD_TYPE_PROVISION; static const uint8_t bec_filter[] = {MESH_AD_TYPE_BEACON, BEACON_TYPE_UNPROVISIONED}; -enum acp_state { - ACP_PROV_IDLE = 0, - ACP_PROV_CAPS_SENT, - ACP_PROV_CAPS_ACKED, - ACP_PROV_KEY_SENT, - ACP_PROV_KEY_ACKED, - ACP_PROV_INP_CMPLT_SENT, - ACP_PROV_INP_CMPLT_ACKED, - ACP_PROV_CONF_SENT, - ACP_PROV_CONF_ACKED, - ACP_PROV_RAND_SENT, - ACP_PROV_RAND_ACKED, - ACP_PROV_CMPLT_SENT, - ACP_PROV_FAIL_SENT, -}; - #define MAT_REMOTE_PUBLIC 0x01 #define MAT_LOCAL_PRIVATE 0x02 #define MAT_RAND_AUTH 0x04 @@ -70,12 +59,13 @@ enum acp_state { struct mesh_prov_acceptor { mesh_prov_acceptor_complete_func_t cmplt; prov_trans_tx_t trans_tx; + struct l_queue *ob; void *agent; void *caller_data; void *trans_data; struct l_timeout *timeout; uint32_t to_secs; - enum acp_state state; + uint8_t out_opcode; uint8_t transport; uint8_t material; uint8_t expected; @@ -99,6 +89,7 @@ static void acceptor_free(void) return; l_timeout_remove(prov->timeout); + l_queue_destroy(prov->ob, l_free); mesh_send_cancel(bec_filter, sizeof(bec_filter)); mesh_send_cancel(&pkt_filter, sizeof(pkt_filter)); @@ -126,6 +117,21 @@ static void acp_prov_close(void *user_data, uint8_t reason) acceptor_free(); } +static void prov_send(struct mesh_prov_acceptor *prov, void *cmd, uint16_t len) +{ + struct deferred_cmd *defer; + + if (prov->out_opcode == PROV_NONE) { + prov->out_opcode = *(uint8_t *) cmd; + prov->trans_tx(prov->trans_data, cmd, len); + } else { + defer = l_malloc(len + sizeof(struct deferred_cmd)); + defer->len = len; + memcpy(defer->cmd, cmd, len); + l_queue_push_tail(prov->ob, defer); + } +} + static void prov_to(struct l_timeout *timeout, void *user_data) { struct mesh_prov_acceptor *rx_prov = user_data; @@ -140,7 +146,7 @@ static void prov_to(struct l_timeout *timeout, void *user_data) if (prov->cmplt && prov->trans_tx) { prov->cmplt(prov->caller_data, PROV_ERR_TIMEOUT, NULL); prov->cmplt = NULL; - prov->trans_tx(prov->trans_data, fail_code, 2); + prov_send(prov, fail_code, 2); prov->timeout = l_timeout_create(1, prov_to, prov, NULL); return; } @@ -258,7 +264,7 @@ static void number_cb(void *user_data, int err, uint32_t number) if (err) { msg.opcode = PROV_FAILED; msg.reason = PROV_ERR_UNEXPECTED_ERR; - prov->trans_tx(prov->trans_data, &msg, sizeof(msg)); + prov_send(prov, &msg, sizeof(msg)); return; } @@ -267,7 +273,7 @@ static void number_cb(void *user_data, int err, uint32_t number) l_put_be32(number, prov->rand_auth_workspace + 44); prov->material |= MAT_RAND_AUTH; msg.opcode = PROV_INP_CMPLT; - prov->trans_tx(prov->trans_data, &msg.opcode, 1); + prov_send(prov, &msg.opcode, 1); } static void static_cb(void *user_data, int err, uint8_t *key, uint32_t len) @@ -281,7 +287,7 @@ static void static_cb(void *user_data, int err, uint8_t *key, uint32_t len) if (err || !key || len != 16) { msg.opcode = PROV_FAILED; msg.reason = PROV_ERR_UNEXPECTED_ERR; - prov->trans_tx(prov->trans_data, &msg, sizeof(msg)); + prov_send(prov, &msg, sizeof(msg)); return; } @@ -292,7 +298,7 @@ static void static_cb(void *user_data, int err, uint8_t *key, uint32_t len) if (prov->conf_inputs.start.auth_action == PROV_ACTION_IN_ALPHA) { msg.opcode = PROV_INP_CMPLT; - prov->trans_tx(prov->trans_data, &msg.opcode, 1); + prov_send(prov, &msg.opcode, 1); } } @@ -307,7 +313,7 @@ static void priv_key_cb(void *user_data, int err, uint8_t *key, uint32_t len) if (err || !key || len != 32) { msg.opcode = PROV_FAILED; msg.reason = PROV_ERR_UNEXPECTED_ERR; - prov->trans_tx(prov->trans_data, &msg, sizeof(msg)); + prov_send(prov, &msg, sizeof(msg)); return; } @@ -326,7 +332,7 @@ static void priv_key_cb(void *user_data, int err, uint8_t *key, uint32_t len) if (!acp_credentials(prov)) { msg.opcode = PROV_FAILED; msg.reason = PROV_ERR_UNEXPECTED_ERR; - prov->trans_tx(prov->trans_data, &msg, sizeof(msg)); + prov_send(prov, &msg, sizeof(msg)); } } } @@ -339,9 +345,8 @@ static void send_caps(struct mesh_prov_acceptor *prov) memcpy(&msg.caps, &prov->conf_inputs.caps, sizeof(prov->conf_inputs.caps)); - prov->state = ACP_PROV_CAPS_SENT; prov->expected = PROV_START; - prov->trans_tx(prov->trans_data, &msg, sizeof(msg)); + prov_send(prov, &msg, sizeof(msg)); } static void send_pub_key(struct mesh_prov_acceptor *prov) @@ -350,7 +355,7 @@ static void send_pub_key(struct mesh_prov_acceptor *prov) msg.opcode = PROV_PUB_KEY; memcpy(msg.pub_key, prov->conf_inputs.dev_pub_key, sizeof(msg.pub_key)); - prov->trans_tx(prov->trans_data, &msg, sizeof(msg)); + prov_send(prov, &msg, sizeof(msg)); } static bool send_conf(struct mesh_prov_acceptor *prov) @@ -365,7 +370,7 @@ static bool send_conf(struct mesh_prov_acceptor *prov) if (!memcmp(msg.conf, prov->confirm, sizeof(msg.conf))) return false; - prov->trans_tx(prov->trans_data, &msg, sizeof(msg)); + prov_send(prov, &msg, sizeof(msg)); return true; } @@ -375,7 +380,7 @@ static void send_rand(struct mesh_prov_acceptor *prov) msg.opcode = PROV_RANDOM; memcpy(msg.rand, prov->rand_auth_workspace, sizeof(msg.rand)); - prov->trans_tx(prov->trans_data, &msg, sizeof(msg)); + prov_send(prov, &msg, sizeof(msg)); } static void acp_prov_rx(void *user_data, const uint8_t *data, uint16_t len) @@ -614,8 +619,7 @@ static void acp_prov_rx(void *user_data, const uint8_t *data, uint16_t len) if (result) { prov->rand_auth_workspace[0] = PROV_COMPLETE; - prov->trans_tx(prov->trans_data, - prov->rand_auth_workspace, 1); + prov_send(prov, prov->rand_auth_workspace, 1); goto cleanup; } else { fail.reason = PROV_ERR_UNEXPECTED_ERR; @@ -638,7 +642,7 @@ static void acp_prov_rx(void *user_data, const uint8_t *data, uint16_t len) failure: fail.opcode = PROV_FAILED; - prov->trans_tx(prov->trans_data, &fail, sizeof(fail)); + prov_send(prov, &fail, sizeof(fail)); if (prov->cmplt) prov->cmplt(prov->caller_data, fail.reason, NULL); prov->cmplt = NULL; @@ -652,7 +656,23 @@ cleanup: static void acp_prov_ack(void *user_data, uint8_t msg_num) { - /* TODO: Handle PB-ADV Ack */ + struct mesh_prov_acceptor *rx_prov = user_data; + struct deferred_cmd *deferred; + + if (rx_prov != prov) + return; + + if (prov->out_opcode == PROV_NONE) + return; + + prov->out_opcode = PROV_NONE; + + deferred = l_queue_pop_head(prov->ob); + if (!deferred) + return; + + prov_send(prov, deferred->cmd, deferred->len); + l_free(deferred); } @@ -680,7 +700,9 @@ bool acceptor_start(uint8_t num_ele, uint8_t uuid[16], prov->to_secs = timeout; prov->agent = agent; prov->cmplt = complete_cb; + prov->ob = l_queue_new(); prov->previous = -1; + prov->out_opcode = PROV_NONE; prov->caller_data = caller_data; caps = mesh_agent_get_caps(agent); diff --git a/mesh/provision.h b/mesh/provision.h index 1a11b691b..1634c4d40 100644 --- a/mesh/provision.h +++ b/mesh/provision.h @@ -38,6 +38,7 @@ struct mesh_agent; #define PROV_DATA 0x07 #define PROV_COMPLETE 0x08 #define PROV_FAILED 0x09 +#define PROV_NONE 0xFF /* Spec defined Error Codes */ #define PROV_ERR_SUCCESS 0x00