Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2289250rwi; Tue, 11 Oct 2022 07:09:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4OX9maOzaBaQN6UOsEV5PaPlSChp8WUoGQB/u+u58M38TN0X1BKII2RXJUfnoSkIPJw0VJ X-Received: by 2002:a63:3348:0:b0:439:db24:8b02 with SMTP id z69-20020a633348000000b00439db248b02mr21021022pgz.425.1665497386314; Tue, 11 Oct 2022 07:09:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665497386; cv=none; d=google.com; s=arc-20160816; b=OZqDEmtycjNTxQUdr7G6T3Gz1z6MzIKGDEBMuKNOOIsKFTbTAjxHNdY4T6ytSkVoQM roYtjDhKdnlbwr98xvI2lvkztg5bd7yFaUSHH82+tGk4I+lxHKSc6OV7GA6Md7bzaOqv 6GQ5Ij0HEqeVxdhFQsJVvMQjoMFQ4VPo6CSSArzh+EOK0APNmVtotkg9waXzavj2DhTf GjSCrATYTh3M2dnArl/2Mz0cj4w4JcFI1+ZkeMeHtPNiAtReobf/81uha+zEP5D+GWEZ baMLxv9BQXNMi33gOPhNKhHnH8GvFD8pFW3ukXpWkbMadDd2nerDFrHf7FnPT3BTTsfz HU7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=KjpNczoCHfEiKp0Yh/bv4gNeXmG+DguvVSxK+tk03kE=; b=tUh1mC0y3MbWbncYbJktiCLJCs/dlY9JTBIwpByD6lwGY9yf0Exmnozr8JwZ0oQWSf L78i8wWPTe5O7IHADaP1wAvhLHdJSGu9O49AVyBAeavqgc+RpWKEHQWMTL7cL/3D1Bp7 H8ia4k4gxajQfEcmXswylCiNYZ5btHCikLXcy6K67aR2qXes5yRHWJUE+Vz3pL40K0lE vKPyczWu6makMtj+0kEQ515K/FFjMyPY8Ifd7N8JTORScFmQMZDwP4OKNpiXke9qXS6Q ICJt17Bz2vX9xFPxAOwJTjKMrqKuAF2myIx1zBUPvdxKupm3qZtp9VcOHjbWoydGNHZa eeRg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i5-20020a635845000000b0041dd0c35c54si16855840pgm.47.2022.10.11.07.09.14; Tue, 11 Oct 2022 07:09:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230129AbiJKOHR (ORCPT + 99 others); Tue, 11 Oct 2022 10:07:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230141AbiJKOGl (ORCPT ); Tue, 11 Oct 2022 10:06:41 -0400 Received: from voyager.loytec.com (voyager.loytec.com [88.198.4.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CF7597EED for ; Tue, 11 Oct 2022 07:06:29 -0700 (PDT) Received: from 212-17-98-152.static.upcbusiness.at ([212.17.98.152] helo=lexx.office.loytec.com) by voyager.loytec.com with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oiFto-0002b5-4L for linux-bluetooth@vger.kernel.org; Tue, 11 Oct 2022 16:06:24 +0200 Received: from loytec-dev-vm.delta.corp ([10.101.25.21]) by lexx.office.loytec.com (8.15.2/8.15.2/Some OS 1.2.3-4.5) with ESMTP id 29BE6L6R2091927; Tue, 11 Oct 2022 16:06:21 +0200 From: Isak Westin To: linux-bluetooth@vger.kernel.org Cc: Isak Westin Subject: [PATCH BlueZ v3] mesh: Keep cancelled SAR data for at least 10 sec Date: Tue, 11 Oct 2022 16:06:12 +0200 Message-Id: <20221011140612.2478-1-isak.westin@loytec.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 212.17.98.152 X-SA-Exim-Mail-From: isak.westin@loytec.com X-SA-Exim-Scanned: No (on voyager.loytec.com); SAEximRunCond expanded to false X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org When a SAR transmission has been completed or cancelled, the recipent should store the block authentication values for at least 10 seconds and ignore new segments with the same values during this period. See MshPRFv1.0.1 section 3.5.3.4. --- mesh/net.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/mesh/net.c b/mesh/net.c index 3f42d962c..1d27289bf 100644 --- a/mesh/net.c +++ b/mesh/net.c @@ -46,6 +46,7 @@ #define SEG_TO 2 #define MSG_TO 60 +#define SAR_DEL 10 #define DEFAULT_TRANSMIT_COUNT 1 #define DEFAULT_TRANSMIT_INTERVAL 100 @@ -166,6 +167,7 @@ struct mesh_sar { bool segmented; bool frnd; bool frnd_cred; + bool delete; uint8_t ttl; uint8_t last_seg; uint8_t key_aid; @@ -1492,14 +1494,27 @@ static void inseg_to(struct l_timeout *seg_timeout, void *user_data) static void inmsg_to(struct l_timeout *msg_timeout, void *user_data) { struct mesh_net *net = user_data; - struct mesh_sar *sar = l_queue_remove_if(net->sar_in, + struct mesh_sar *sar = l_queue_find(net->sar_in, match_msg_timeout, msg_timeout); - l_timeout_remove(msg_timeout); - if (!sar) + if (!sar) { + l_timeout_remove(msg_timeout); return; + } - sar->msg_timeout = NULL; + if (!sar->delete) { + /* + * Incomplete timer expired, cancel SAR and start + * delete timer + */ + l_timeout_remove(sar->seg_timeout); + sar->seg_timeout = NULL; + sar->delete = true; + l_timeout_modify(sar->msg_timeout, SAR_DEL); + return; + } + + l_queue_remove(net->sar_in, sar); mesh_sar_free(sar); } @@ -1963,7 +1978,9 @@ static bool seg_rxed(struct mesh_net *net, bool frnd, uint32_t iv_index, /* Re-Send ACK for full msg */ send_net_ack(net, sar_in, expected); return true; - } + } else if (sar_in->delete) + /* Ignore cancelled */ + return false; } else { uint16_t len = MAX_SEG_TO_LEN(segN); @@ -2013,6 +2030,10 @@ static bool seg_rxed(struct mesh_net *net, bool frnd, uint32_t iv_index, /* Kill Inter-Seg timeout */ l_timeout_remove(sar_in->seg_timeout); sar_in->seg_timeout = NULL; + + /* Start delete timer */ + sar_in->delete = true; + l_timeout_modify(sar_in->msg_timeout, SAR_DEL); return true; } -- 2.20.1