Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp1942910rwa; Sun, 21 Aug 2022 21:58:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR6gs4OYXxXLnIPyrUGhq8aU4IivsDsO8Yq47tvprru9wO8paui4iFBylZeMm1Wwpookcsxn X-Received: by 2002:a05:6402:716:b0:446:2a40:9138 with SMTP id w22-20020a056402071600b004462a409138mr11972302edx.82.1661144301647; Sun, 21 Aug 2022 21:58:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661144301; cv=none; d=google.com; s=arc-20160816; b=FVD5Rjx7z3zVTNqIePm3XPOg+Ncjq6r03T0Rsw2itEBAWmnof0SduMwjyaIqjgGub7 Lb8/xzEtQMW8SqZInC9WvcFmJfyIrsh+A58ApBxS9RBGl1hnzzX51rmYKEp4y3nKjrOu vJB8wy8ro5WgUDUe3X+Tw09ZWpbbHCHFbT6f6Nn5TLYtIbUWAn2KEJUMJEaMo98ZIXg1 RXwi5CMAZ+d1TJb5Jrytisut14HVsjxxnqA69Fg2xJgyhPpcM0fciYJRiF+HGKTvvGNN h/FuvMy+2wd3inb4GSBnCESYrYru4rYefjtLS2wspcPIMkBJ6QFn0yyRQmntPqFeoXJ5 IGpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=0UCpCk7kfWDJtYvreVOQFYHPgPiCo5d56aUPAsU2AOE=; b=p/2aKwguo8Iy0jwGYglKZ/qpdq2XAC3elyUTUymndY71f/SRJbrwBa0+7V24tFiz/l VTF5OkdNpbByHC3UIVxt8xVX4QyxEVn5pVu9bh5Up4pkRcHtpKtYl3srTPcOp2Db4p8M cNJ8pRS4oDedj8lSfmNsfbtTfSECZqX64dDFXiesMta8yl+YSnMtk8RwY8QL97GPd11U gt4lbRXANBBCdEb9ieq/uacERStOI+wCsoYYoPzH7u1PQISsoW80MwBxqqUJqf+BfUXE 03IzuCdQI1ToF2d5rmBfdGdnPcPjooI2KGP2DmBlEC32gdcur8gf9erXnib9kGj6QdvX vDsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=QKTG18kO; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id tl24-20020a170907c31800b0073ccfb22163si5851328ejc.497.2022.08.21.21.57.55; Sun, 21 Aug 2022 21:58:21 -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; dkim=pass header.i=@google.com header.s=20210112 header.b=QKTG18kO; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229570AbiHVEyQ (ORCPT + 99 others); Mon, 22 Aug 2022 00:54:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229562AbiHVEyP (ORCPT ); Mon, 22 Aug 2022 00:54:15 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E94701F2E8 for ; Sun, 21 Aug 2022 21:54:13 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-3360c0f0583so169360647b3.2 for ; Sun, 21 Aug 2022 21:54:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc; bh=0UCpCk7kfWDJtYvreVOQFYHPgPiCo5d56aUPAsU2AOE=; b=QKTG18kOD3kbrtrTry+WrK9XQvAtGnK+H9NuW8RffYzvHbZyHcekXZznY+b4dOspI2 AJG8ogpopAVnTYqB/16YhjdloXFLuQbkFj26CakuWmteBiD9r1ZeHHHj4e+UKaKVhC29 wo9g7OiY13Vo6BfnnACmG/sQBy/gTWEarDDtBsn86InOgODJnyRjCbZEMomKczadDo80 URm1inrluGcoLHAbpeQPPFKbH5H5KOHoX62ZWR/cY2RQIfhDchr+jP/z9/pA3f66tFRs GZ5D7LhfsPrRNjmpFWgEp2H+3WmusUCzG8KcWyFtFEwn4XPHNCUJehySrdWgbuCddsPY qC+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc; bh=0UCpCk7kfWDJtYvreVOQFYHPgPiCo5d56aUPAsU2AOE=; b=GKiANR13UsC/MIkB2/d0Xt30snvt4l0Al0lrcTUtqxzOl02Lkid8A0ltEPA23Nv0V6 X6TnVQz+QDte8rYJY8B7Jq6lcp0QFezNz8V0GI9ipebAwuQa8teoHzDFwzpfOGpkehBN zopGN7G2zjy9us1fltEICSHPdiJh4omG3B7HCkKAQMv2K9jJwbmWX8Zlg8If/sUsrwyS Vsq3E9grx3PqZu/Nzs52dNo7vV2te19liNPpICuDLQ88wjzCouPEi/fFHObpyW3M5vX9 RY6XKRBtI0PDrK1G0KlJbWmRw2/oZ3vre4mgcHsNXsyUS0p8QrscIO8vDyhDaeiVa55Z 9KBQ== X-Gm-Message-State: ACgBeo2ETz2NdjFBBkd0ddJrjwYGwf9NG8T3q3ccVJVVo8e8Zeg8GJOZ e3PbMEt4ShYPVqvye6ihEtAWRNR2PWKjVtKuvJa1jRn8DUHYIeX9z+nFHIF1Nn1JluIxA4IPxVW ivIZKJ9P3zXelHzCXvWh4wqlKFNr8RUCTEmpmjL5nQF2bpG3K0Ea+Zw6PF+38cVZuXcz6zO6ILG ad X-Received: from apusaka-p920.tpe.corp.google.com ([2401:fa00:1:17:9732:c819:4bfc:92ae]) (user=apusaka job=sendgmr) by 2002:a0d:edc2:0:b0:338:957:a719 with SMTP id w185-20020a0dedc2000000b003380957a719mr14186205ywe.132.1661144053082; Sun, 21 Aug 2022 21:54:13 -0700 (PDT) Date: Mon, 22 Aug 2022 12:53:53 +0800 Message-Id: <20220822125221.Bluez.1.I541cbea9d6295f531c796bf3bda96b22db76bc19@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog Subject: [Bluez PATCH] adapter: Reset pending settings when receiving MGMT error From: Archie Pusaka To: linux-bluetooth , Luiz Augusto von Dentz , Marcel Holtmann Cc: CrosBT Upstreaming , Archie Pusaka , Sonny Sasaka Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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 From: Archie Pusaka We set the pending settings flag when sending MGMT_SETTING_* commands to the MGMT layer and clear them when receiving success reply, but we don't clear them when receiving error reply. This might cause a setting to be stuck in pending state. Therefore, also clear the pending flag when receiving error. Furthermore, this patch also postpone setting the pending flag until we queue the MGMT command in order to avoid setting it too soon but we return early. Reviewed-by: Sonny Sasaka --- src/adapter.c | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index ec26aab1a7..4da1fcc3e5 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -640,14 +640,21 @@ static void new_settings_callback(uint16_t index, uint16_t length, settings_changed(adapter, settings); } +struct set_mode_data { + struct btd_adapter *adapter; + uint32_t setting; +}; + static void set_mode_complete(uint8_t status, uint16_t length, const void *param, void *user_data) { - struct btd_adapter *adapter = user_data; + struct set_mode_data *data = user_data; + struct btd_adapter *adapter = data->adapter; if (status != MGMT_STATUS_SUCCESS) { btd_error(adapter->dev_id, "Failed to set mode: %s (0x%02x)", mgmt_errstr(status), status); + adapter->pending_settings &= ~data->setting; return; } @@ -677,6 +684,7 @@ static bool set_mode(struct btd_adapter *adapter, uint16_t opcode, { struct mgmt_mode cp; uint32_t setting = 0; + struct set_mode_data *data; memset(&cp, 0, sizeof(cp)); cp.val = mode; @@ -699,15 +707,23 @@ static bool set_mode(struct btd_adapter *adapter, uint16_t opcode, break; } - adapter->pending_settings |= setting; - DBG("sending set mode command for index %u", adapter->dev_id); + data = g_try_new0(struct set_mode_data, 1); + if (!data) + goto failed; + + data->adapter = adapter; + data->setting = setting; + if (mgmt_send(adapter->mgmt, opcode, adapter->dev_id, sizeof(cp), &cp, - set_mode_complete, adapter, NULL) > 0) + set_mode_complete, data, g_free) > 0) { + adapter->pending_settings |= setting; return true; + } +failed: btd_error(adapter->dev_id, "Failed to set mode for index %u", adapter->dev_id); @@ -718,6 +734,7 @@ static bool set_discoverable(struct btd_adapter *adapter, uint8_t mode, uint16_t timeout) { struct mgmt_cp_set_discoverable cp; + struct set_mode_data *data; memset(&cp, 0, sizeof(cp)); cp.val = mode; @@ -734,11 +751,19 @@ static bool set_discoverable(struct btd_adapter *adapter, uint8_t mode, mode); } + data = g_try_new0(struct set_mode_data, 1); + if (!data) + goto failed; + + data->adapter = adapter; + data->setting = 0; + if (mgmt_send(adapter->mgmt, MGMT_OP_SET_DISCOVERABLE, adapter->dev_id, sizeof(cp), &cp, - set_mode_complete, adapter, NULL) > 0) + set_mode_complete, data, g_free) > 0) return true; +failed: btd_error(adapter->dev_id, "Failed to set mode for index %u", adapter->dev_id); @@ -2877,6 +2902,7 @@ static gboolean property_get_mode(struct btd_adapter *adapter, struct property_set_data { struct btd_adapter *adapter; + uint32_t setting; GDBusPendingPropertySet id; }; @@ -2901,6 +2927,8 @@ static void property_set_mode_complete(uint8_t status, uint16_t length, g_dbus_pending_property_error(data->id, dbus_err, mgmt_errstr(status)); + + adapter->pending_settings &= ~data->setting; return; } @@ -2969,8 +2997,6 @@ static void property_set_mode(struct btd_adapter *adapter, uint32_t setting, mode = (enable == TRUE) ? 0x01 : 0x00; - adapter->pending_settings |= setting; - switch (setting) { case MGMT_SETTING_POWERED: opcode = MGMT_OP_SET_POWERED; @@ -3024,11 +3050,14 @@ static void property_set_mode(struct btd_adapter *adapter, uint32_t setting, goto failed; data->adapter = adapter; + data->setting = setting; data->id = id; if (mgmt_send(adapter->mgmt, opcode, adapter->dev_id, len, param, - property_set_mode_complete, data, g_free) > 0) + property_set_mode_complete, data, g_free) > 0) { + adapter->pending_settings |= setting; return; + } g_free(data); -- 2.37.1.595.g718a3a8f04-goog