Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2122058ybi; Thu, 4 Jul 2019 05:34:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqydi2631770QX56TGQOeq8YGyPr8nrzis6JlJrl2ObjKrhfWX5bCWLjJzJYMasSmbnNrk+d X-Received: by 2002:a17:902:23:: with SMTP id 32mr49005537pla.34.1562243668025; Thu, 04 Jul 2019 05:34:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562243668; cv=none; d=google.com; s=arc-20160816; b=IiZD7Zr0HECyQl8ig5UDwb9yS5+2k3d0ZuXJykXj/7Z4xJkyY54dk/ZwunpRJzyU+I +7hsmHcYfrd2fGTP+G/opZ43pmYrOuAKc8oXogYxt6WENoqFOrz4yvKuO/CnxZ/04vXd b5Fm+0xOBDCg1Z7a0J2buTftJVwyp3kfm60YRB9ektUPOEA3HjnL3W2TbTRfNhd7SOUC VN0p9BU7l5lQzSO6vWs8rFi/VuQhj8tnFfgDBIM42iJ17BZYnLukJwQ/O4G9qCXbe9td mIYGpb1aiNl9dfxknj//hkrccJ922Kg2BBBxCKUrVpU/+IjNzmDD4+5gj7CzVN/veVWF 2cZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Y0x1q6cQo2g2hFMvC+gSWekWjYxT4SCAgFqeS+gZNTo=; b=GDX1x9wX6yAJ16a5CqNmo/fGYmaEcCuCJ269XWZsyN1UtUrFW4cA4a2CN/a5RZ0XWE 2zDJUWfupck2IsYwffoKXP9XehhPBtmKvcpjpeAqTu0hEKBK+xDFvssoSPADXj6IrD2L 5aYd5q0up7LOkXk2BHIE2LopZVsNsEzQOEpmuqJSlRqMh8NpCiyVO9wNniTHAYgTdV+r xcJgFHwiNBkf7nroaPGxv20ByUKK8pqJMD7O2TYs2zVwJpHBIK8+jR+wdmsKuxjzOGCm 0aEcYVTdD9ewsGxX20VQMs+sXS6J2BbkLVUINoLBAFx2OStjiC/UAF84s0wzPP+IomO0 if4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b=ObmdglxR; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i5si4712363pjk.57.2019.07.04.05.34.13; Thu, 04 Jul 2019 05:34:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b=ObmdglxR; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727726AbfGDMdu (ORCPT + 99 others); Thu, 4 Jul 2019 08:33:50 -0400 Received: from mail-lj1-f170.google.com ([209.85.208.170]:38542 "EHLO mail-lj1-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727768AbfGDMdu (ORCPT ); Thu, 4 Jul 2019 08:33:50 -0400 Received: by mail-lj1-f170.google.com with SMTP id r9so6012139ljg.5 for ; Thu, 04 Jul 2019 05:33:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silvair-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Y0x1q6cQo2g2hFMvC+gSWekWjYxT4SCAgFqeS+gZNTo=; b=ObmdglxRqM5ux/VpucTk4hFa/4m0nk8qXNXcsyB7GOyhpA4jtW3WaNErZ1esV0zFI+ kRhCycqIu+fo9HPAnl7TOH6ssVyJGQQ6eDPybi/PC5zH/aiapr3paDEZ6Sp9nV2d3+OM mQldTMiXcWIDqkAiD2YTqnGqoMwqMzji06lcUlDC8Ql0hSaMEGjJcSvqiShRYb2dwiIN rT1h1upHmp8wsO8DyC4/yMdNxG3+HTdFRJHaL1UInL7FpAhkvAyBwFEo1qIvCzTDNM8f bA5gG8OAi7o3tvcZ7M5k3T6R9Fp+Gva4ufF5aWGjMXU3cx5j6JU87EjTngsjc5oI2lgz ACFA== 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=Y0x1q6cQo2g2hFMvC+gSWekWjYxT4SCAgFqeS+gZNTo=; b=J9CkdE5SS4mifEZMmU1Xf4QOeLXMfWYuW36Fp7XsxhmWKP+aFJnVj/UdP5bndJ6Bn+ +Hn2r5wgNehMumsoWbqyXRsmTRbkK1ilMP8WlJJer+mVvHQS5eKNt7t7/TCoqtv0w1NP Iz6lGq4n0YDEF8esMPQQB4SWOf3icMQDPIKrgziSDwMhEh0la85sH5s+CMe+bv5efMhU xsYN/1DqSvhyBn7XiMdRSd34Ah4NGz0LlbgVOKcadPY/CgmWh59zXBlro4DwPaNgVmbz Bs76s3sVZN/kqKUPj9n/pZ9130W8oPqiBdnaVEaDEwnVy3vUlRTogtFqCN2CS+RMHi+Y YFdg== X-Gm-Message-State: APjAAAWXrm3wNcrIa9iYwOgQAqCPD+0+O1or7wJ6sO77zEViHkPEmfKM L0emsT7V/qGk1Jd/3i0xiWZCy9eYC9M= X-Received: by 2002:a2e:6e0c:: with SMTP id j12mr24438079ljc.123.1562243627276; Thu, 04 Jul 2019 05:33:47 -0700 (PDT) Received: from mlowasrzechonek2133.silvair.lan ([217.153.94.18]) by smtp.gmail.com with ESMTPSA id g68sm1126151ljg.47.2019.07.04.05.33.46 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 04 Jul 2019 05:33:46 -0700 (PDT) From: =?UTF-8?q?Micha=C5=82=20Lowas-Rzechonek?= To: linux-bluetooth@vger.kernel.org Cc: Inga Stotland , Brian Gix Subject: [PATCH BlueZ v5 3/5] mesh: Split APP_IDX_DEV into APP_IDX_DEV_LOCAL and APP_IDX_DEV_REMOTE Date: Thu, 4 Jul 2019 14:33:36 +0200 Message-Id: <20190704123338.5988-4-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190704123338.5988-1-michal.lowas-rzechonek@silvair.com> References: <20190704123338.5988-1-michal.lowas-rzechonek@silvair.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This is needed to distinguish incoming messages encrypted using a device key: if the key is local, the message can be forwarded to internal models. If the key is a known remote one, it will be forwarded to the application via DevKeyMessageReceived() API. --- mesh/cfgmod-server.c | 15 ++++++++------- mesh/model.c | 22 +++++++++++++--------- mesh/net.h | 8 ++++---- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c index 634ac006b..a849b5e99 100644 --- a/mesh/cfgmod-server.c +++ b/mesh/cfgmod-server.c @@ -69,7 +69,8 @@ static void send_pub_status(struct mesh_node *node, uint16_t src, uint16_t dst, n += 2; } - mesh_model_send(node, dst, src, APP_IDX_DEV, DEFAULT_TTL, msg, n); + mesh_model_send(node, dst, src, APP_IDX_DEV_LOCAL, DEFAULT_TTL, + msg, n); } static bool config_pub_get(struct mesh_node *node, uint16_t src, uint16_t dst, @@ -254,7 +255,7 @@ static void send_sub_status(struct mesh_node *node, uint16_t src, uint16_t dst, n += 2; } - mesh_model_send(node, dst, src, APP_IDX_DEV, DEFAULT_TTL, msg, n); + mesh_model_send(node, dst, src, APP_IDX_DEV_LOCAL, DEFAULT_TTL, msg, n); } static bool config_sub_get(struct mesh_node *node, uint16_t src, uint16_t dst, @@ -312,7 +313,7 @@ static bool config_sub_get(struct mesh_node *node, uint16_t src, uint16_t dst, *msg_status = (uint8_t) status; - mesh_model_send(node, dst, src, APP_IDX_DEV, DEFAULT_TTL, msg, n); + mesh_model_send(node, dst, src, APP_IDX_DEV_LOCAL, DEFAULT_TTL, msg, n); return true; } @@ -487,7 +488,7 @@ static void send_model_app_status(struct mesh_node *node, uint16_t src, l_put_le16(id, msg + n); n += 2; - mesh_model_send(node, dst, src, APP_IDX_DEV, DEFAULT_TTL, msg, n); + mesh_model_send(node, dst, src, APP_IDX_DEV_LOCAL, DEFAULT_TTL, msg, n); } static void model_app_list(struct mesh_node *node, uint16_t src, uint16_t dst, @@ -540,7 +541,7 @@ static void model_app_list(struct mesh_node *node, uint16_t src, uint16_t dst, if (result >= 0) { *status = result; - mesh_model_send(node, dst, src, APP_IDX_DEV, DEFAULT_TTL, + mesh_model_send(node, dst, src, APP_IDX_DEV_LOCAL, DEFAULT_TTL, msg, n); } @@ -758,7 +759,7 @@ static bool cfg_srv_pkt(uint16_t src, uint32_t dst, uint16_t interval; uint16_t n; - if (idx != APP_IDX_DEV) + if (idx != APP_IDX_DEV_LOCAL) return false; if (mesh_model_opcode_get(pkt, size, &opcode, &n)) { @@ -1259,7 +1260,7 @@ static bool cfg_srv_pkt(uint16_t src, uint32_t dst, if (n) { /* print_packet("App Tx", long_msg ? long_msg : msg, n); */ mesh_model_send(node, unicast, src, - APP_IDX_DEV, DEFAULT_TTL, + APP_IDX_DEV_LOCAL, DEFAULT_TTL, long_msg ? long_msg : msg, n); } l_free(long_msg); diff --git a/mesh/model.c b/mesh/model.c index 868fe9e52..ee26a8105 100644 --- a/mesh/model.c +++ b/mesh/model.c @@ -306,7 +306,9 @@ static void forward_model(void *a, void *b) bool result; l_debug("model %8.8x with idx %3.3x", mod->id, fwd->idx); - if (fwd->idx != APP_IDX_DEV && !has_binding(mod->bindings, fwd->idx)) + + if (fwd->idx != APP_IDX_DEV_LOCAL && + !has_binding(mod->bindings, fwd->idx)) return; dst = fwd->dst; @@ -356,15 +358,15 @@ static int dev_packet_decrypt(struct mesh_node *node, const uint8_t *data, uint16_t dst, uint8_t key_id, uint32_t seq, uint32_t iv_idx, uint8_t *out) { - const uint8_t *dev_key; + const uint8_t *key; - dev_key = node_get_device_key(node); - if (!dev_key) + key = node_get_device_key(node); + if (!key) return false; if (mesh_crypto_payload_decrypt(NULL, 0, data, size, szmict, src, - dst, key_id, seq, iv_idx, out, dev_key)) - return APP_IDX_DEV; + dst, key_id, seq, iv_idx, out, key)) + return APP_IDX_DEV_LOCAL; return -1; } @@ -942,7 +944,7 @@ bool mesh_model_send(struct mesh_node *node, uint16_t src, uint16_t target, if (IS_UNASSIGNED(target)) return false; - if (app_idx == APP_IDX_DEV) { + if (app_idx == APP_IDX_DEV_LOCAL) { key = node_get_device_key(node); if (!key) return false; @@ -1371,12 +1373,14 @@ struct mesh_model *mesh_model_setup(struct mesh_node *node, uint8_t ele_idx, if (ele_idx != PRIMARY_ELE_IDX) return NULL; - l_queue_push_head(mod->bindings, L_UINT_TO_PTR(APP_IDX_DEV)); + l_queue_push_head(mod->bindings, + L_UINT_TO_PTR(APP_IDX_DEV_LOCAL)); return mod; } if (db_mod->id == CONFIG_CLI_MODEL) { - l_queue_push_head(mod->bindings, L_UINT_TO_PTR(APP_IDX_DEV)); + l_queue_push_head(mod->bindings, + L_UINT_TO_PTR(APP_IDX_DEV_LOCAL)); return mod; } diff --git a/mesh/net.h b/mesh/net.h index f19024766..8848e6df0 100644 --- a/mesh/net.h +++ b/mesh/net.h @@ -37,10 +37,10 @@ struct mesh_node; #define SEQ_MASK 0xffffff #define CREDFLAG_MASK 0x1000 -#define APP_IDX_MASK 0x0fff -#define APP_IDX_DEV 0x7fff -#define APP_IDX_ANY 0x8000 -#define APP_IDX_NET 0xffff + +#define APP_IDX_MASK 0x0fff +#define APP_IDX_DEV_REMOTE 0x6fff +#define APP_IDX_DEV_LOCAL 0x7fff #define NET_IDX_INVALID 0xffff #define NET_NID_INVALID 0xff -- 2.19.1