From patchwork Mon Feb 10 15:59:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13968132 Received: from mail5.g24.pair.com (mail5.g24.pair.com [66.39.139.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4274241CA6 for ; Mon, 10 Feb 2025 15:59:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.39.139.36 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739203201; cv=none; b=kT6LXt1eIqAqosP4vW+VK4Osbv8TaIc1ucy6GYVTKtXwlHszPzz9Rgk5Nv1x+8vP+Cf0h3O+pslOLiTogaDiXtdQCaI9XUGh4t9ILOJrX7Q//HFs0oaxLOAo8EfxM1uEzoOfwbBEa6xpiHzIccOzTTbLSKujqZ87YChNAkxtytE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739203201; c=relaxed/simple; bh=+PsNXIurL4dq55nTDZB+1vkyzD9IQRUEKhBdf1YYQSM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UMU3pIAddhUJH3UusmDBkblZSrwvdVnH5IUarp4TmXaR4MHrOBGIDu+ziaeZHADxYpbG+O2f5xc+F+9BTIhvkkk40vJUm/5bVGxn+a55yKjvzQ+g4iQDjpKb1n178a4qbq/XzOyjSFhkcP/NZIcf0ngPWyDhg/0TQ9KyNP7H+wU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com; spf=pass smtp.mailfrom=nuovations.com; dkim=pass (2048-bit key) header.d=nuovations.com header.i=@nuovations.com header.b=PLtXX75U; arc=none smtp.client-ip=66.39.139.36 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nuovations.com header.i=@nuovations.com header.b="PLtXX75U" Received: from mail5.g24.pair.com (localhost [127.0.0.1]) by mail5.g24.pair.com (Postfix) with ESMTP id DF4341649C6 for ; Mon, 10 Feb 2025 10:59:51 -0500 (EST) Received: from localhost.localdomain (c-24-6-12-99.hsd1.ca.comcast.net [24.6.12.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail5.g24.pair.com (Postfix) with ESMTPSA id 916E7124F64 for ; Mon, 10 Feb 2025 10:59:51 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH v2 1/2] ofono: Correct conditional in 'cm_get_contexts_reply'. Date: Mon, 10 Feb 2025 07:59:48 -0800 Message-ID: <7a05bc1060f2aaba362f8198cdd4f1c7d2ff04e9.1739203086.git.gerickson@nuovations.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuovations.com; h=from:to:subject:date:message-id:in-reply-to:references:mime-version:content-transfer-encoding; s=pair-202401062137; bh=hQWKk/+bUwwnY8jcxecCceqP6ZoQc2qZ7LeXCLJbYFo=; b=PLtXX75UwjvL2+A2djWR5s2Ee61ZbrvPsINNVsRELIkWT6JaRTiwJtHa8+HQtPNuTId9S+VJcKzoM1/mNKSVLEORCWN6N5JP7WEeOmJKfbrORQQgDUzUSkyAls5806UUDHf4ouzpqMNoM2ehCZnIdCNS2+4KVetJ84wfE+r23rpThBwSct8UfZjqy7jB+iGpeOdXcplWdliMszXcF6C1KPcG/m9OJ+xN7M6zJYtqzdu7uUEUDUW60c6zWnqCheNXKhJyjKHAt/s3SDNpQ/SxjwO/eSCMEOR8v/7vXQDUzUq3jeCAk/Zc1Rq0ZyJW+AIp6zo7h2LPk3wOPoN4LjaM8A== X-Scanned-By: mailmunge 3.10 on 66.39.139.36 At the appropriate moment in the oFono plugin lifecycle, it gets and evaluates contexts from a given Cellular modem. Depending on the HNI/MCC+MNC and the network operator, there may be one or more such contexts, each with a different type. Within 'cm_get_contexts_reply', each received context is iterated on, evaluating each for the type 'internet' by calling 'add_cm_context'. If the context is not of type 'internet', 'cm_get_contexts_reply' should continue to iterate until all contexts are exhausted or a matching context is found. The return semantics of 'add_cm_context' are '-ENOMEM' if memory could not be allocated, '-EINVAL' if a context is *not* of the type 'internet'; otherwise zero ('0') if a context of type 'internet' was found. However, the conditional logic of 'cm_get_contexts_reply' prior to this change was: while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) { const char *context_path; dbus_message_iter_recurse(&dict, &entry); dbus_message_iter_get_basic(&entry, &context_path); dbus_message_iter_next(&entry); dbus_message_iter_recurse(&entry, &value); if (add_cm_context(modem, context_path, &value)) break; dbus_message_iter_next(&dict); } So, assuming a set of contexts from, for example Verizon, such as '[ { vzwims, ims }, { vzwinternet, internet }, { vzwapp, wap } ]', then the above logic will encounter '{ vzwims, ims }' on the first iteration, evaluate that it is not of type 'internet', return '-EINVAL' from 'add_cm_context', that will satisfy the conditional and trigger the 'break' from the 'while' loop and context iteration will terminate. This then misses the second, desired '{ vzwinternet, internet }' context and the Cellular interface will never come up. By changing the conditional logic to match the return semantics of 'add_cm_context' the code now works correctly, regardless of the number of contexts iterated on or their order. Fixes: 4b238d8590942 ("ofono: Implementation of simultaneous APNS") --- plugins/ofono.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/ofono.c b/plugins/ofono.c index 062905c8a3a6..6b89df3af0ae 100644 --- a/plugins/ofono.c +++ b/plugins/ofono.c @@ -1415,7 +1415,11 @@ static void cm_get_contexts_reply(DBusPendingCall *call, void *user_data) dbus_message_iter_next(&entry); dbus_message_iter_recurse(&entry, &value); - if (add_cm_context(modem, context_path, &value)) + /* + * If a context of type 'internet' is found, stop iterating; + * we have the desired context. + */ + if (add_cm_context(modem, context_path, &value) == 0) break; dbus_message_iter_next(&dict);