Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3036456ybv; Mon, 24 Feb 2020 16:52:05 -0800 (PST) X-Google-Smtp-Source: APXvYqyt81qlhm3s8VO3ZBNuspZO4TLkkjnwAlRZlZYD6R8iQAJ3xdzI+voAaEXV37w9pmh2y89I X-Received: by 2002:aca:1a06:: with SMTP id a6mr1388837oia.148.1582591924997; Mon, 24 Feb 2020 16:52:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582591924; cv=none; d=google.com; s=arc-20160816; b=AcWaEx6RFnfCyvLqEDC41MONUwIlweikk+OWqqRf8eA2gxB27j3xCHZ4Ugx/Pp8pEm nnw7PSMJumiAxztBNQ/UDN+OcgTmgcmu7pQYHDLwlI4AwKcZh1ETZahy8aK9QXGi6kp8 FWJBRLaaxbt/j7Lyfksynv2tDRcFvMZXhctO3hJGFZpubR/3a+kUn/7bidSJIrsAs36r 4lCee6P9L2zNQvr1N/Y+bD0xGxXKWQTJ7L2nmQXZ2ikkBgDLyKlY56GWb/til5cdYd/2 GoA8b2hCETzA1i20UHZ+p6fOTXWDy4DWGyGV8y3zw0MJ7gpaWqQuYPuN8jvrOGfGSI0t nAGg== 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; bh=jcviaIqd4WAHbtiPfMAj+Fj0/z2oTdpOfyhKhmqacTM=; b=rXM9x0alTU+3OCMIKk5V33o2FGiT9x2xp0vohg/2PZxjDM582Q2mjlNuCCSwIiyZjB coSN/Z72EXxOgXlSglvRsKiFEd+V2+kh22j0AV0fEZThi60/bId7tW3V9kA5uzemyFsl x/Eo/zLV5/x67XfQMZMfxwhpyBJcoQifWt9zgX1zSACGYY5pAL47PRL0weuJqJxH5yil /uYgK/zw0pg/2Lt+y5jUXn0DzNmeKr8/BK+5t5t4qojB+HD8H5QERP7ZBR3rxz/5i+h9 k+PM8E08WRiuICuXquDcLpywEPDxZHei8GlUD62lrPUAmhxe106547Ori+ERmFoICQcy BN9g== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x25si5559253oie.261.2020.02.24.16.51.52; Mon, 24 Feb 2020 16:52:04 -0800 (PST) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728574AbgBYAvr (ORCPT + 99 others); Mon, 24 Feb 2020 19:51:47 -0500 Received: from mga14.intel.com ([192.55.52.115]:60209 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728011AbgBYAvq (ORCPT ); Mon, 24 Feb 2020 19:51:46 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 16:51:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,482,1574150400"; d="scan'208";a="436095386" Received: from ingas-nuc1.sea.intel.com ([10.251.142.189]) by fmsmga005.fm.intel.com with ESMTP; 24 Feb 2020 16:51:46 -0800 From: Inga Stotland To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, Inga Stotland Subject: [PATCH BlueZ 4/5] mesh: Clean up handling config model publication message Date: Mon, 24 Feb 2020 16:51:39 -0800 Message-Id: <20200225005141.9700-5-inga.stotland@intel.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200225005141.9700-1-inga.stotland@intel.com> References: <20200225005141.9700-1-inga.stotland@intel.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 tightens up the Config Server code that handles the processing of Config Model Publication Set and Config Model Publication Get messages. --- mesh/cfgmod-server.c | 131 +++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 87 deletions(-) diff --git a/mesh/cfgmod-server.c b/mesh/cfgmod-server.c index 7111411c7..3eb7316fc 100644 --- a/mesh/cfgmod-server.c +++ b/mesh/cfgmod-server.c @@ -36,8 +36,8 @@ static void send_pub_status(struct mesh_node *node, uint16_t net_idx, uint16_t src, uint16_t dst, - uint8_t status, uint16_t ele_addr, uint16_t pub_addr, - uint32_t mod_id, uint16_t idx, bool cred_flag, + uint8_t status, uint16_t ele_addr, uint32_t mod_id, + uint16_t pub_addr, uint16_t idx, bool cred_flag, uint8_t ttl, uint8_t period, uint8_t retransmit) { uint8_t msg[16]; @@ -56,7 +56,7 @@ static void send_pub_status(struct mesh_node *node, uint16_t net_idx, msg[n++] = period; msg[n++] = retransmit; - if (mod_id < 0x10000 || mod_id > VENDOR_ID_MASK) { + if (mod_id >= VENDOR_ID_MASK) { l_put_le16(mod_id, msg + n); n += 2; } else { @@ -76,8 +76,7 @@ static bool config_pub_get(struct mesh_node *node, uint16_t net_idx, { uint32_t mod_id; uint16_t ele_addr; - int ele_idx; - struct mesh_model_pub *pub = NULL; + struct mesh_model_pub *pub; int status; if (size == 4) { @@ -90,27 +89,22 @@ static bool config_pub_get(struct mesh_node *node, uint16_t net_idx, return false; ele_addr = l_get_le16(pkt); - ele_idx = node_get_element_idx(node, ele_addr); - - if (ele_idx >= 0) - pub = mesh_model_pub_get(node, ele_addr, mod_id, &status); - else - status = MESH_STATUS_INVALID_ADDRESS; + pub = mesh_model_pub_get(node, ele_addr, mod_id, &status); if (pub && status == MESH_STATUS_SUCCESS) send_pub_status(node, net_idx, src, dst, status, ele_addr, - pub->addr, mod_id, pub->idx, pub->credential, + mod_id, pub->addr, pub->idx, pub->credential, pub->ttl, pub->period, pub->retransmit); else - send_pub_status(node, net_idx, src, dst, status, ele_addr, 0, - mod_id, 0, 0, 0, 0, 0); + send_pub_status(node, net_idx, src, dst, status, ele_addr, + mod_id, 0, 0, 0, 0, 0, 0); return true; } -static bool config_pub_set(struct mesh_node *node, uint16_t net_idx, +static void config_pub_set(struct mesh_node *node, uint16_t net_idx, uint16_t src, uint16_t dst, - const uint8_t *pkt, uint16_t size, - bool unreliable) + const uint8_t *pkt, uint8_t virt_offset, + bool vendor, bool unreliable) { uint32_t mod_id; uint16_t ele_addr, idx, ota = 0; @@ -119,93 +113,58 @@ static bool config_pub_set(struct mesh_node *node, uint16_t net_idx, uint8_t ttl, period; uint8_t retransmit; int status; - bool cred_flag, b_virt = false; - bool vendor = false; - - switch (size) { - default: - return false; - - case 11: - idx = l_get_le16(pkt + 4); - ttl = pkt[6]; - period = pkt[7]; - retransmit = pkt[8]; - mod_id = l_get_le16(pkt + 9); - mod_id |= VENDOR_ID_MASK; - break; + bool cred_flag; - case 13: - idx = l_get_le16(pkt + 4); - ttl = pkt[6]; - period = pkt[7]; - retransmit = pkt[8]; - mod_id = l_get_le16(pkt + 9) << 16; - mod_id |= l_get_le16(pkt + 11); - vendor = true; - break; + idx = l_get_le16(pkt + 4 + virt_offset); + ttl = pkt[6 + virt_offset]; + period = pkt[7 + virt_offset]; + retransmit = pkt[8 + virt_offset]; + mod_id = l_get_le16(pkt + 9 + virt_offset); - case 25: - b_virt = true; - idx = l_get_le16(pkt + 18); - ttl = pkt[20]; - period = pkt[21]; - retransmit = pkt[22]; - mod_id = l_get_le16(pkt + 23); + if (!vendor) mod_id |= VENDOR_ID_MASK; - break; - - case 27: - b_virt = true; - idx = l_get_le16(pkt + 18); - ttl = pkt[20]; - period = pkt[21]; - retransmit = pkt[22]; - mod_id = l_get_le16(pkt + 23) << 16; - mod_id |= l_get_le16(pkt + 25); - vendor = true; - break; - } + else + mod_id |= l_get_le16(pkt + 11 + virt_offset); ele_addr = l_get_le16(pkt); pub_addr = pkt + 2; - /* Doesn't accept out-of-range TTLs */ - if (ttl > TTL_MASK && ttl != DEFAULT_TTL) - return false; + /* Doesn't accept virtual seeming addresses */ + test_addr = l_get_le16(pub_addr); + if (!virt_offset && IS_VIRTUAL(test_addr)) + return; /* Get cred_flag */ cred_flag = !!(CREDFLAG_MASK & idx); - /* Ignore non-IDX bits */ + /* Get AppKey index */ idx &= APP_IDX_MASK; - /* Doesn't accept virtual seeming addresses */ - test_addr = l_get_le16(pub_addr); - if (!b_virt && test_addr > 0x7fff && test_addr < 0xc000) - return false; - status = mesh_model_pub_set(node, ele_addr, mod_id, pub_addr, idx, cred_flag, ttl, period, retransmit, - b_virt, &ota); + virt_offset != 0, &ota); l_debug("pub_set: status %d, ea %4.4x, ota: %4.4x, mod: %x, idx: %3.3x", status, ele_addr, ota, mod_id, idx); - if (IS_UNASSIGNED(ota) && !b_virt) { - ttl = period = idx = 0; + if (status != MESH_STATUS_SUCCESS) { + if (!unreliable) + send_pub_status(node, net_idx, src, dst, status, + ele_addr, mod_id, 0, 0, 0, 0, 0, 0); - /* Remove model publication from config file */ - if (status == MESH_STATUS_SUCCESS) - mesh_config_model_pub_del(node_config_get(node), - ele_addr, vendor ? mod_id : mod_id & 0x0000ffff, - vendor); - goto done; + return; } - if (status == MESH_STATUS_SUCCESS) { + if (IS_UNASSIGNED(ota) && !virt_offset) { + ttl = period = idx = 0; + + /* Remove model publication from config file */ + mesh_config_model_pub_del(node_config_get(node), ele_addr, + vendor ? mod_id : mod_id & ~VENDOR_ID_MASK, + vendor); + } else { struct mesh_config_pub db_pub = { - .virt = b_virt, + .virt = (virt_offset != 0), .addr = ota, .idx = idx, .ttl = ttl, @@ -215,21 +174,19 @@ static bool config_pub_set(struct mesh_node *node, uint16_t net_idx, .interval = ((retransmit >> 3) + 1) * 50 }; - if (b_virt) + if (virt_offset) memcpy(db_pub.virt_addr, pub_addr, 16); /* Save model publication to config file */ if (!mesh_config_model_pub_add(node_config_get(node), ele_addr, - vendor ? mod_id : mod_id & 0x0000ffff, + vendor ? mod_id : mod_id & ~VENDOR_ID_MASK, vendor, &db_pub)) status = MESH_STATUS_STORAGE_FAIL; } -done: if (!unreliable) send_pub_status(node, net_idx, src, dst, status, ele_addr, ota, mod_id, idx, cred_flag, ttl, period, retransmit); - return true; } static void send_sub_status(struct mesh_node *node, uint16_t net_idx, @@ -825,7 +782,7 @@ static bool cfg_srv_pkt(uint16_t src, uint32_t dst, uint16_t unicast, if (size != 25 && size != 27) return true; - config_pub_set(node, net_idx, src, unicast, pkt, size, + config_pub_set(node, net_idx, src, unicast, pkt, 14, size == 27, !!(opcode & OP_UNRELIABLE)); break; @@ -833,7 +790,7 @@ static bool cfg_srv_pkt(uint16_t src, uint32_t dst, uint16_t unicast, if (size != 11 && size != 13) return true; - config_pub_set(node, net_idx, src, unicast, pkt, size, + config_pub_set(node, net_idx, src, unicast, pkt, 0, size == 13, !!(opcode & OP_UNRELIABLE)); break; -- 2.21.1