From patchwork Wed Jan 24 21:12:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13529685 Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF24D1350D1 for ; Wed, 24 Jan 2024 21:14:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706130849; cv=none; b=tNXFnznHj3/QC/IEkSpahklF+TdykDHVIcNGrlAEy0/oeij5ixm6pV3OINuO63z7rshj5JayjL1Oq8Pd0SASC+drPNmSPVhZ9AlEtm8934OdKdeP09wi+Wk+sgPvTe8VXsjoCuwhNDGBrn64Xk3QH0d54GO86x7orU3vdMoO9nI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706130849; c=relaxed/simple; bh=OTpnF8wBaH461nBqPMFltMg16Hcz9roFOGtNIJhg+Z8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=XNRs17N5TmESyVziInQ9egCu0y9lz+tWHJcKauCbpS7+eFtBf2NUFPRBPeN01wM0lC5HR+hOUsPQ7n69zn3QFnaJSKL8NQXUOBxpSJOAVYkaGvAt5uZD2dluW4EfX8mo4x6cigv0mnYn4X3BnKkYpSM6osZX/FOJcZzbbKV2CFw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VPMqX8lo; arc=none smtp.client-ip=209.85.167.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VPMqX8lo" Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-3bd9030d68fso3585306b6e.3 for ; Wed, 24 Jan 2024 13:14:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706130846; x=1706735646; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=gNhDHln08Azxi2EnQy1WNPfjtieEQtjUVMWvH5VM5GI=; b=VPMqX8loWEm8LtLcmcQhyZjfqujXKNrpWSb58CqPiwT/NFV3bruSDqLlUuAGpq5a+8 SijHYC66EgvuS/F5/sJF7iZ5hy5l02t0oMiTw1QiRaMlhi0goA1On/LYf09PfyzrkASF A0r153l7RnCvT6DaWWzGI3Pwejux2NY0RMwPlYXPMxJk3lXo3hGwnLaUdGiRM4kp3yMz SDLtqGD4gHAqMqG6Rm/4mRzNqrLzKFx+zVuC2+OlaK0Z9luK8m2rmqOMwAZXnX63wtGu s/rWQJLCpMUcg54UKUD8nvwJ0zy6ht5fCVsOX9atU76hBOWjZD0ff28Tbuu7LJJLNLMT AXLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706130846; x=1706735646; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gNhDHln08Azxi2EnQy1WNPfjtieEQtjUVMWvH5VM5GI=; b=UjINtDpxkBEpiVWD59mBc6MdGqN8/lVuqs7qaWpsemRdnZJrm98eLHGQghuvF7eHm5 6MbZSLjJVpy2ri0IsIXBEY4s1DltIypbpspQ5eH1kL0qdYlaq8gu4Ab65O8BXMefqdot /ikXqH/4NS4hpuNVw90hxEN2X7tq65AjTAsQr7fmOL9ZhmNzubx8PFqOZsCWhVob0yuS thJZNWX3NizLc7lrJ0Z9t+UL20h3eTnkWHjgYSNLD40yO833YyGuJ4SpPWaA5AsBkNw0 obtjEwooswav5hkApEK9q80i1meD4hx3a4+cNfJbhx7vRaDSdX0AaB0HKOLxw4H/HXCl ByWA== X-Gm-Message-State: AOJu0YzbkhJZLxE/ap7UDExeNL0bXY8+wuTDfYdhLgoGvgcPSswR++LB yt8ttthuw+oCrIVMRLs8ZTJKcVEJthxWAHrlun5n7vNtC6OmehLy7ISQ2klc X-Google-Smtp-Source: AGHT+IFflII7wAIBRrGq6Mo++ZOle7qr3NJUPpkmx/AKcbv1ArouNPDAC52E4B50JbkOW23wKCF3xQ== X-Received: by 2002:a05:6808:bc7:b0:3bd:cf03:2331 with SMTP id o7-20020a0568080bc700b003bdcf032331mr2035143oik.94.1706130845801; Wed, 24 Jan 2024 13:14:05 -0800 (PST) Received: from localhost.localdomain (070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id t27-20020a0568080b3b00b003bdac23eb89sm2003318oij.34.2024.01.24.13.14.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 13:14:05 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 1/4] core: Remove unused declarations from ofono.h Date: Wed, 24 Jan 2024 15:12:59 -0600 Message-ID: <20240124211317.611706-1-denkenz@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fixes: 36a11599 ("gprs-provision: Remove no longer used atom/driver") --- src/ofono.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/ofono.h b/src/ofono.h index 6a8c53a1..42298e43 100644 --- a/src/ofono.h +++ b/src/ofono.h @@ -587,14 +587,6 @@ bool __ofono_provision_get_settings(const char *mcc, struct ofono_gprs_provision_data **settings, size_t *count); -ofono_bool_t __ofono_gprs_provision_get_settings(const char *mcc, - const char *mnc, const char *spn, - struct ofono_gprs_provision_data **settings, - int *count); -void __ofono_gprs_provision_free_settings( - struct ofono_gprs_provision_data *settings, - int count); - #include enum ofono_emulator_slc_condition { From patchwork Wed Jan 24 21:13:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13529686 Received: from mail-oi1-f172.google.com (mail-oi1-f172.google.com [209.85.167.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A03C9131E54 for ; Wed, 24 Jan 2024 21:14:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706130849; cv=none; b=hoSRkewM2eSkV7HfIl8ACUUxW9m87vVu8DrIVMdJbUqjSZMIb63cJiRQ+pyaH33c8OImXolSzohvNtglmAhy753Hnzey7eZUdh1c/aSWclItrWNLWhHWZJtTuilqmVfGJgARCllLProqngWqQKY4ZxtOmUsm04IPDS9p+9/wsqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706130849; c=relaxed/simple; bh=sgRKj5La7bgo46JyN0H4VYUEBWKsJ69kjflhQUzyT04=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HdMjE9jpLAq/MCnZaEAelF75iiGGeSaruxyD3V+5VsUmy6WyZ0ZKEH1o7hS/wKHEAIngCMidqO6RZxukawyrvBEidx/XCAJpKRKSX8oVjDpW8hoNc1ZhhL/CZcBQKGrxplTA+/PQ7B5yCVN9HonmkE7rhp7ou2E+ZN8hW3lgz7M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HNzvakp1; arc=none smtp.client-ip=209.85.167.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HNzvakp1" Received: by mail-oi1-f172.google.com with SMTP id 5614622812f47-3bdca4f495cso1040944b6e.3 for ; Wed, 24 Jan 2024 13:14:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706130846; x=1706735646; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eRNE+QM5zfRefQAJYk6aR9ObWZSmLdNRqhoSSebGHXs=; b=HNzvakp1ubdV6WKpL7raGeZf2LjH/5g3lLLvk6x8AFSCzQnR33HCIwPxGkZ63Mkn2V uy9bILkC9Oh+N0K7yOSlGMheBrcb5HOMjO1TvdcyfmxnmHVt9ZymfH5XDZsIJZ5Yy20R DV3xY8w59+uNG3GrZTYuUfvZMvJlEJ3T19fwUJxpjgS2pVG42y9xWjMHiUgnCvBLgyqA sspldi1qyiYRUal/IzYLRksUut1JlFjf0PNpXEkrFzBKygB2o9D8MNZyGA9JP89WAgJJ jEi7WouW/1/r0qRdzLCHs7zwMnV6pQt9/5szm6QFMVa0ZBFkyFVNcslbK8l0GPvxffpB XINg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706130846; x=1706735646; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eRNE+QM5zfRefQAJYk6aR9ObWZSmLdNRqhoSSebGHXs=; b=n4PwFLCIbWr/3V7PN3GaMJBWR4uCGLt8Y04+jXalkSSWSTX1DoSxx4xokf467JSLN8 RmH17vABO/qzRmKU6Are2GSChnKENHqvjNK5/HFr/kXqfDoeTocNAKsWnAnd216v/wJb NPyGAHZjnm/dVdfHZN/yNnK71ZZ/iMnAZYAJTX4WX4bOn1bsxm+1YgPwrdj2oa2zWtkl fmSXfvDVCH49ogSgforoatXylN1EShTSBkdh3qsw3pbK5fBYV4KTmPjSfiRoHQ9VeLdI 5lJ+rdvTbwK5QN4I+Mz617kIdNhjUvfU2xUrafMz3KaMnCq1gAw10euohuZWSJSk6j7Q aw5Q== X-Gm-Message-State: AOJu0Yw6kIHnPqtGOfyuHjvmxe0Fuq52lcCHGG1cB4OyMQ4qxgTXm9bR n+jvDn0G5PW90ljuAabdbeCJQV18tHHZ7/M6El94ZHWn8VT1G6fcx4jtTKWV X-Google-Smtp-Source: AGHT+IE9UAXhj2S63vTxiykpZX/TdnlZ/s7sSryUvTQauSj2Vsql+aP2orvFm5Hh9IBZQdz9xLwfAA== X-Received: by 2002:a05:6808:48f:b0:3bd:72dc:65a6 with SMTP id z15-20020a056808048f00b003bd72dc65a6mr1831388oid.58.1706130846543; Wed, 24 Jan 2024 13:14:06 -0800 (PST) Received: from localhost.localdomain (070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id t27-20020a0568080b3b00b003bdac23eb89sm2003318oij.34.2024.01.24.13.14.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 13:14:06 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 2/4] provision: Remove use of ofono_gprs_provision_data Date: Wed, 24 Jan 2024 15:13:00 -0600 Message-ID: <20240124211317.611706-2-denkenz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240124211317.611706-1-denkenz@gmail.com> References: <20240124211317.611706-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Switch to using struct provisiondb_entry instead of struct ofono_gprs_provision_data. For now, mark all string attributes of this structure as const. Strings are currently not allocated and instead point to loations in the provisiondb memory mapped region. Since the provisioning database is only opened at startup and never unmapped during oFono's runtime, returning const pointers to such strings is safe. While here, mark __get_string() as returning a pointer to a const char. --- Makefile.am | 2 +- include/gprs-provision.h | 49 ---------------------------------------- src/gprs.c | 5 ++-- src/ofono.h | 4 ++-- src/provision.c | 10 ++++---- src/provisiondb.c | 16 ++++++------- src/provisiondb.h | 17 ++++++++++++-- tools/lookup-apn.c | 8 +++---- 8 files changed, 38 insertions(+), 73 deletions(-) delete mode 100644 include/gprs-provision.h diff --git a/Makefile.am b/Makefile.am index 15d220f7..280653f3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -144,7 +144,7 @@ pkginclude_HEADERS = include/log.h include/plugin.h include/history.h \ include/audio-settings.h include/nettime.h \ include/ctm.h \ include/sim-auth.h \ - include/gprs-provision.h include/emulator.h \ + include/emulator.h \ include/location-reporting.h \ include/gnss.h \ include/private-network.h \ diff --git a/include/gprs-provision.h b/include/gprs-provision.h deleted file mode 100644 index ac0f5905..00000000 --- a/include/gprs-provision.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * - * oFono - Open Telephony stack for Linux - * - * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef __OFONO_GPRS_PROVISION_H -#define __OFONO_GPRS_PROVISION_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include "gprs-context.h" - -struct ofono_gprs_provision_data { - uint32_t type; /* Multiple types can be set in a bitmap */ - enum ofono_gprs_proto proto; - char *name; - char *apn; - char *username; - char *password; - enum ofono_gprs_auth_method auth_method; - char *message_proxy; - char *message_center; -}; - -#ifdef __cplusplus -} -#endif - -#endif /* __OFONO_GPRS_PROVISION_H */ diff --git a/src/gprs.c b/src/gprs.c index 40642324..f8b6fd3c 100644 --- a/src/gprs.c +++ b/src/gprs.c @@ -43,6 +43,7 @@ #include "ofono.h" #include "common.h" +#include "provisiondb.h" #include "storage.h" #include "simutil.h" #include "util.h" @@ -2371,7 +2372,7 @@ static DBusMessage *gprs_get_contexts(DBusConnection *conn, return reply; } -static void provision_context(const struct ofono_gprs_provision_data *ap, +static void provision_context(const struct provision_db_entry *ap, struct ofono_gprs *gprs) { unsigned int id; @@ -2463,7 +2464,7 @@ static void provision_context(const struct ofono_gprs_provision_data *ap, static void provision_contexts(struct ofono_gprs *gprs, const char *mcc, const char *mnc, const char *spn) { - struct ofono_gprs_provision_data *settings; + struct provision_db_entry *settings; size_t count; size_t i; diff --git a/src/ofono.h b/src/ofono.h index 42298e43..a243d3fb 100644 --- a/src/ofono.h +++ b/src/ofono.h @@ -581,10 +581,10 @@ void __ofono_nettime_info_received(struct ofono_modem *modem, #include -#include +struct provision_db_entry; bool __ofono_provision_get_settings(const char *mcc, const char *mnc, const char *spn, - struct ofono_gprs_provision_data **settings, + struct provision_db_entry **settings, size_t *count); #include diff --git a/src/provision.c b/src/provision.c index cd5cf569..a2dfcf6c 100644 --- a/src/provision.c +++ b/src/provision.c @@ -11,6 +11,8 @@ #include +#include + #include "provisiondb.h" #include "ofono.h" @@ -18,11 +20,11 @@ static struct provision_db *pdb; bool __ofono_provision_get_settings(const char *mcc, const char *mnc, const char *spn, - struct ofono_gprs_provision_data **settings, + struct provision_db_entry **settings, size_t *count) { size_t n_contexts; - struct ofono_gprs_provision_data *contexts; + struct provision_db_entry *contexts; int r; size_t i; uint32_t type; @@ -38,7 +40,7 @@ bool __ofono_provision_get_settings(const char *mcc, n_contexts, mcc, mnc, spn); for (i = 0; i < n_contexts; i++) { - struct ofono_gprs_provision_data *ap = contexts + i; + struct provision_db_entry *ap = contexts + i; DBG("APN: %s, Type: %x, Proto: %x", ap->apn, ap->type, ap->proto); @@ -50,7 +52,7 @@ bool __ofono_provision_get_settings(const char *mcc, /* Make sure there are no duplicates */ for (i = 0, type = 0; i < n_contexts; i++) { - struct ofono_gprs_provision_data *ap = contexts + i; + struct provision_db_entry *ap = contexts + i; if (type & ap->type) { ofono_warn("Duplicate detected for %s%s, spn: %s", diff --git a/src/provisiondb.c b/src/provisiondb.c index 6b864dec..53305eab 100644 --- a/src/provisiondb.c +++ b/src/provisiondb.c @@ -21,8 +21,7 @@ #include #define OFONO_API_SUBJECT_TO_CHANGE -#include -#include +#include #include "provisiondb.h" @@ -205,7 +204,7 @@ static struct provision_data *__get_provision_data(struct node *node) } static int __get_string(struct provision_db *pdb, uint64_t offset, - char **out_str) + const char **out_str) { if (!offset) { *out_str = NULL; @@ -220,13 +219,13 @@ static int __get_string(struct provision_db *pdb, uint64_t offset, } static int __get_contexts(struct provision_db *pdb, uint64_t offset, - struct ofono_gprs_provision_data **contexts, + struct provision_db_entry **contexts, size_t *n_contexts) { void *start = pdb->addr + pdb->contexts_offset; uint64_t num; uint64_t i; - struct ofono_gprs_provision_data *ret; + struct provision_db_entry *ret; int r; if (offset + sizeof(__le64) >= pdb->contexts_size) @@ -238,7 +237,7 @@ static int __get_contexts(struct provision_db *pdb, uint64_t offset, if (offset + num * sizeof(struct context) > pdb->contexts_size) return -EPROTO; - ret = l_new(struct ofono_gprs_provision_data, num); + ret = l_new(struct provision_db_entry, num); for (i = 0; i < num; i++, offset += sizeof(struct context)) { struct context *context = start + offset; @@ -375,8 +374,7 @@ static int key_from_mcc_mnc(const char *mcc, const char *mnc, uint32_t *key) int provision_db_lookup(struct provision_db *pdb, const char *mcc, const char *mnc, const char *match_spn, - struct ofono_gprs_provision_data **items, - size_t *n_items) + struct provision_db_entry **items, size_t *n_items) { int r; uint32_t key; @@ -422,7 +420,7 @@ int provision_db_lookup(struct provision_db *pdb, } for (i = 0; i < count; i++) { - char *spn; + const char *spn; r = __get_string(pdb, L_LE64_TO_CPU(data[i].spn_offset), &spn); if (r < 0) diff --git a/src/provisiondb.h b/src/provisiondb.h index d7381b94..ee203c61 100644 --- a/src/provisiondb.h +++ b/src/provisiondb.h @@ -5,14 +5,27 @@ * SPDX-License-Identifier: LGPL-2.1-or-later */ -struct ofono_gprs_provision_data; +#include + struct provision_db; +struct provision_db_entry { + uint32_t type; /* Multiple types can be set in a bitmap */ + enum ofono_gprs_proto proto; + const char *name; + const char *apn; + const char *username; + const char *password; + enum ofono_gprs_auth_method auth_method; + const char *message_proxy; + const char *message_center; +}; + struct provision_db *provision_db_new(const char *pathname); struct provision_db *provision_db_new_default(void); void provision_db_free(struct provision_db *pdb); int provision_db_lookup(struct provision_db *pdb, const char *mcc, const char *mnc, const char *spn, - struct ofono_gprs_provision_data **items, + struct provision_db_entry **items, size_t *n_items); diff --git a/tools/lookup-apn.c b/tools/lookup-apn.c index ff791993..34d689a4 100644 --- a/tools/lookup-apn.c +++ b/tools/lookup-apn.c @@ -18,8 +18,8 @@ #include #define OFONO_API_SUBJECT_TO_CHANGE -#include -#include +#include +#include #include "provisiondb.h" @@ -29,7 +29,7 @@ static int lookup_apn(const char *match_mcc, const char *match_mnc, const char *match_spn) { struct provision_db *pdb; - struct ofono_gprs_provision_data *contexts; + struct provision_db_entry *contexts; size_t n_contexts; int r; size_t i; @@ -58,7 +58,7 @@ static int lookup_apn(const char *match_mcc, const char *match_mnc, } for (i = 0; i < n_contexts; i++) { - struct ofono_gprs_provision_data *ap = contexts + i; + struct provision_db_entry *ap = contexts + i; fprintf(stdout, "\nName: %s\n", ap->name); fprintf(stdout, "APN: %s\n", ap->apn); From patchwork Wed Jan 24 21:13:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13529687 Received: from mail-oi1-f172.google.com (mail-oi1-f172.google.com [209.85.167.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 668E01350DE for ; Wed, 24 Jan 2024 21:14:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706130849; cv=none; b=mZCMTfNyuGia6N1BBgA+G5ZwbTluOs1HUcjtIPWW0YITEZJk+PCc/fGG6rUbcrXWNZA5zyjnKIsZfXZRJo0BlgR8+DoxV9htunJCDBY0J6b5a9X5X4RhLLtJwz8FBobe+dc1KG0JwbM0O83CQoz+hmouKAECqMysnGll1VNhfUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706130849; c=relaxed/simple; bh=sQ1l2Der8D5kxlRBkfOoOgOyteEr+bW7WySeHdBycZo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ozZ0VwuRAhrvIVD5bjE4en9i3O6MqHewQ6PNm9gyC89h/Ey0+xPuXAtL1V8CNxtl6lpdeClQk6RG/eY0ww/wSbSOX3ywkNj22PmVyHZLAxeG9zZnpWbVS8x5do4+8I+r7EHe2J551Ram+NPjSs8fiGgFjzwjwI8p2wZZcCfZS3w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kWus4FP1; arc=none smtp.client-ip=209.85.167.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kWus4FP1" Received: by mail-oi1-f172.google.com with SMTP id 5614622812f47-3bd67e9d6ceso3741901b6e.3 for ; Wed, 24 Jan 2024 13:14:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706130847; x=1706735647; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gWzySUIZgdMwRyadTX/o9ThHpMkrhHI1ib7TqArzy+A=; b=kWus4FP1L1uyZOtmI8hMqmRl2pcORWj26rJfTkiDkGCzkxTeK26NLQ4uU74ttRKo95 pNa6XbLkr8HBhQMtj0yVyR8vBKfH7IZPCvvzUe2pPHIap9lE4obKiWd2HNBWGm5m++Kw OzpXQYLRaWNe27U4bqdz2WsX0H117/3dzuEHMKw/5BnwOB5v2M3/LsEs/t0z5lg9mw6i 0coatFLuEYHVs4yNqck9/OjsX9EM9xLKE7eFG0qsXqbtL+8Auzzbx7JdrVJpfVnQ+at+ HnHZggCyLu8KefKe7bZh0O6Is41nz01b/AGvSeccoLEa+TBiPMPm9DMMKDHJwFQNa1l4 2jiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706130847; x=1706735647; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gWzySUIZgdMwRyadTX/o9ThHpMkrhHI1ib7TqArzy+A=; b=rOdGllfuw0tO+glS5O4h826qY+8kMKNccT6ex8jxT8NHJaRANHuSfepjcGn2FRKJ7s SUcUqfIJUX/j9LPWqpg9Lp6o8iA5sOhU+qODqo2266i0yfFcYzEDAw9yCEL54/bOjPPO cUxfWF5iZpULOCb3BjjD9zf+QeLHDQ+XzFvvtcPFCsH9mBrdWmeANxQ/G2Vmq2dPyrTe pAPQ3dZ7f7VHE31jR2Y72CleLowDOZP3KsAs+RqWQ1+uYGTOP+tboTC4DkOcjGQkt2WB VL6UwFWwf9CYT7T7P1CoxLGRow7oealF4r0qzlBiEXVBgRxGFPlM7PFbTgXZWE0cX8+c lrnw== X-Gm-Message-State: AOJu0YyFezHJsMcuc+L8zs70dbuLYTXA7GRuXPJKpIVj5WbwUHyMYrNj d5I7IRoGapCLDyCQBj80lrIbZy03d6VD7Qskrt6F+Lj7KNFd8mq0mtvYD9XU X-Google-Smtp-Source: AGHT+IGiyPIu8tIaNI0vqTdDAz9V6DydfZzitJbqdtFuS8YYj8XOCeWrCTiwxNGui3A4OLAD9f7o6g== X-Received: by 2002:a05:6808:f13:b0:3bd:bf47:d635 with SMTP id m19-20020a0568080f1300b003bdbf47d635mr2495611oiw.41.1706130847263; Wed, 24 Jan 2024 13:14:07 -0800 (PST) Received: from localhost.localdomain (070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id t27-20020a0568080b3b00b003bdac23eb89sm2003318oij.34.2024.01.24.13.14.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 13:14:06 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 3/4] gprs: Add some additional context types Date: Wed, 24 Jan 2024 15:13:01 -0600 Message-ID: <20240124211317.611706-3-denkenz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240124211317.611706-1-denkenz@gmail.com> References: <20240124211317.611706-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 These context types are currently unused, but supported by the provisioning database. Add them to the enumeration and update some utility functions to handle them. In the case of SUPL, the context type can now be set via D-Bus API. IA context types will be handled specially by lte atom. --- include/gprs-context.h | 2 ++ src/gprs.c | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/gprs-context.h b/include/gprs-context.h index 81055d89..5d5f0be1 100644 --- a/include/gprs-context.h +++ b/include/gprs-context.h @@ -37,6 +37,8 @@ enum ofono_gprs_context_type { OFONO_GPRS_CONTEXT_TYPE_MMS = 0x0002, OFONO_GPRS_CONTEXT_TYPE_WAP = 0x0004, OFONO_GPRS_CONTEXT_TYPE_IMS = 0x0008, + OFONO_GPRS_CONTEXT_TYPE_SUPL = 0x0010, + OFONO_GPRS_CONTEXT_TYPE_IA = 0x0020, }; struct ofono_gprs_primary_context { diff --git a/src/gprs.c b/src/gprs.c index f8b6fd3c..7b681d85 100644 --- a/src/gprs.c +++ b/src/gprs.c @@ -177,6 +177,10 @@ static const char *gprs_context_default_name(enum ofono_gprs_context_type type) return "WAP"; case OFONO_GPRS_CONTEXT_TYPE_IMS: return "IMS"; + case OFONO_GPRS_CONTEXT_TYPE_SUPL: + return "SUPL"; + case OFONO_GPRS_CONTEXT_TYPE_IA: + return "Initial Attach"; } return NULL; @@ -196,6 +200,10 @@ static const char *gprs_context_type_to_string( return "wap"; case OFONO_GPRS_CONTEXT_TYPE_IMS: return "ims"; + case OFONO_GPRS_CONTEXT_TYPE_SUPL: + return "supl"; + case OFONO_GPRS_CONTEXT_TYPE_IA: + return "ia"; } return NULL; @@ -216,6 +224,9 @@ static gboolean gprs_context_string_to_type(const char *str, } else if (g_str_equal(str, "ims")) { *out = OFONO_GPRS_CONTEXT_TYPE_IMS; return TRUE; + } else if (g_str_equal(str, "supl")) { + *out = OFONO_GPRS_CONTEXT_TYPE_SUPL; + return TRUE; } return FALSE; From patchwork Wed Jan 24 21:13:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13529688 Received: from mail-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1614F1350EF for ; Wed, 24 Jan 2024 21:14:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706130854; cv=none; b=m1MBkFOwg9qBL+Olu4RE+zf3LmQTMW6GX5lozOns8Yh2pI81bHeBsdGVTbhvkZV1ynM4mEB+/c020T/axcGb+T75mfc3hOtgpo7keTNde38esqZBui5u5QeUJcSnMNIvguquFxyT/RvQ2NM2Uj1ot0WZ94iDkzW6/YqwSvIW2lQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706130854; c=relaxed/simple; bh=fXj6TCCcD6KtcYVi9PJWzT0PNGLvwAyTLvdpLiAosnU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DRgQ71+ubr5Q57wQRJl9qKi2k0te39SnzyzuTHQvjW3DZNn83aUHNwkZHEaEZIXk64G1GjPtRnOD3J/eJUFgU6/cuWHTGHtwH3xY9UhM6tzz081eP8idoWQ2pDI5sqQ7rrNsJ5GJM26Q1qHIYHdY5vq45NM3SRPRKd4UEC2Jxog= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QvZQOFyv; arc=none smtp.client-ip=209.85.167.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QvZQOFyv" Received: by mail-oi1-f179.google.com with SMTP id 5614622812f47-3bdca4f495cso1040952b6e.3 for ; Wed, 24 Jan 2024 13:14:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706130848; x=1706735648; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vS6NKrt6pFWwmyHz1EIk1H2Fr7l6F4zHWyQFOQ18vuU=; b=QvZQOFyvkwftuCqneEi0gBxM30J4wpgtBEp8kqZeKYK8WDcWe40fRpoSl+5iCctwTF j3QtIIKPCGI5aITN2zhj3OmZJ12gsVXWSDez88Ska7FrHpY5l96JuHjuyMWe/uHfM8gb qdNPBqKwE6etFapDw+AMxNemUxqKwBMdgs3hp+ZXcU7weaVEYeRR4Q6A+k4szeuv5do+ EJq0UWRXH9uJG5TC7irrSdZ8qghC5ai8HX2GgrdOQLa0PtNKF+I3V0dbL5MFyQxleAv7 Fmn/kyzMSlMVnZxFxvQTvlJlQDaPbB1Kb/MWiPPl7G6t7aGXj1OlNpjJNV6mjTdSFSgv VhHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706130848; x=1706735648; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vS6NKrt6pFWwmyHz1EIk1H2Fr7l6F4zHWyQFOQ18vuU=; b=fH3OyMZZr27YEtoB3F2kup49w6qwqODHHt+2YUI0g0JEmiYv91nrj7wbNOq5Xgc6GF IC3wwfFAlC4wCJOgXAP3fxb9spj74D72omgQflKpnR1oHRnZJT/gdDJQ6n8AN6glIv27 tAVkPi+38o8pGpyaiNIeyDk/RGwo0v8N2C1VvXlj0fo6mD5gl7nDPVQE4pCMMoNmmbSd IRmY+41s0aN8P7gmq7JHgxY2fd/dFkGEZeO2HXOKKMBFwYSd0Upm8/9iHNf7mQ4KqDqA Bw3jzYf8XNJrOhZ4ltYUOaFT3sl5l3mY+qYUAhEduHAMAkSHb4lFtkVYWVNRbMIsjnkF taAg== X-Gm-Message-State: AOJu0YyXwNS1vEgJOlv4hQvMHtyBFJrH/lfO3Ne1DPSxkMC2vuGYQweP 6NgH7REy4/N7uwLJEWn6+Z94FgSQjI71B9RLtqRIpl7e0QxOgV0NW61p7rHa X-Google-Smtp-Source: AGHT+IE0in9En3aK1mW33pYPtnDEVNICDyLPu/djehawmPVWey4dJM7fiGka1W60HaLJMas5pAezBg== X-Received: by 2002:a05:6808:1059:b0:3bd:7e06:5865 with SMTP id c25-20020a056808105900b003bd7e065865mr1529777oih.62.1706130847923; Wed, 24 Jan 2024 13:14:07 -0800 (PST) Received: from localhost.localdomain (070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id t27-20020a0568080b3b00b003bdac23eb89sm2003318oij.34.2024.01.24.13.14.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 13:14:07 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 4/4] unit: Add provisioning database tests Date: Wed, 24 Jan 2024 15:13:02 -0600 Message-ID: <20240124211317.611706-4-denkenz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240124211317.611706-1-denkenz@gmail.com> References: <20240124211317.611706-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- .gitignore | 2 + Makefile.am | 25 +++- unit/test-provision.c | 280 +++++++++++++++++++++++++++++++++++++++ unit/test-provision.json | 92 +++++++++++++ 4 files changed, 395 insertions(+), 4 deletions(-) create mode 100644 unit/test-provision.c create mode 100644 unit/test-provision.json diff --git a/.gitignore b/.gitignore index 87405231..0cfe5283 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,8 @@ unit/test-rilmodem-cs unit/test-rilmodem-gprs unit/test-rilmodem-sms unit/test-mbim +unit/test-provision +unit/test-provision.db unit/test-*.log unit/test-*.trs test-driver diff --git a/Makefile.am b/Makefile.am index 280653f3..79645e76 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,10 +8,12 @@ noinst_LTLIBRARIES = if EXTERNAL_ELL ell_cflags = @ELL_CFLAGS@ ell_ldadd = @ELL_LIBS@ +ell_dependencies = ell_built_sources = ell/shared else ell_cflags = ell_ldadd = ell/libell-internal.la +ell_dependencies = $(ell_ldadd) ell_built_sources = ell/shared ell/internal ell/ell.h noinst_LTLIBRARIES += ell/libell-internal.la @@ -736,7 +738,8 @@ endif AM_CFLAGS = @DBUS_CFLAGS@ @GLIB_CFLAGS@ $(ell_cflags) $(builtin_cflags) \ -DOFONO_PLUGIN_BUILTIN \ - -DPLUGINDIR=\""$(build_plugindir)"\" + -DPLUGINDIR=\""$(build_plugindir)"\" \ + -DUNITDIR=\""$(top_builddir)/unit/"\" AM_CPPFLAGS = -I$(builddir)/include -I$(builddir)/src -I$(srcdir)/src \ -I$(srcdir)/gdbus -I$(srcdir)/gisi -I$(srcdir)/gatchat \ @@ -876,7 +879,9 @@ test_SCRIPTS = $(test_scripts) endif EXTRA_DIST = src/genbuiltin plugins/ofono.rules plugins/ofono-speedup.rules \ - $(doc_files) $(test_scripts) + tools/provisiontool \ + unit/test-provision.json \ + $(doc_files) $(test_scripts) dist_man_MANS = doc/ofonod.8 @@ -890,7 +895,8 @@ unit_tests = unit/test-common unit/test-util \ unit/test-rilmodem-cs \ unit/test-rilmodem-sms \ unit/test-rilmodem-cb \ - unit/test-rilmodem-gprs + unit/test-rilmodem-gprs \ + unit/test-provision noinst_PROGRAMS = $(unit_tests) \ unit/test-sms-root unit/test-mux unit/test-caif @@ -981,6 +987,17 @@ unit_test_mbim_SOURCES = unit/test-mbim.c \ unit_test_mbim_LDADD = $(ell_ldadd) unit_objects += $(unit_test_mbim_OBJECTS) +unit/test-provision.db: unit/test-provision.json + $(AM_V_GEN)$(srcdir)/tools/provisiontool generate \ + --infile $< --outfile $@ + +unit_test_provision_SOURCES = unit/test-provision.c \ + src/provisiondb.h src/provisiondb.c +unit_test_provision_LDADD = $(ell_ldadd) +unit_test_provision_DEPENDENCIES = $(ell_dependencies) \ + unit/test-provision.db +unit_objects += $(unit_test_provision_OBJECTS) + TESTS = $(unit_tests) if TOOLS @@ -1103,4 +1120,4 @@ maintainer-clean-local: -rm -rf build-aux ell clean-local: - @$(RM) -rf include/ofono + @$(RM) -rf include/ofono unit/test-provision.db diff --git a/unit/test-provision.c b/unit/test-provision.c new file mode 100644 index 00000000..9c3dfad4 --- /dev/null +++ b/unit/test-provision.c @@ -0,0 +1,280 @@ +/* + * oFono - Open Source Telephony + * Copyright (C) 2023 Cruise, LLC + * + * SPDX-License-Identifier: GPL-2.0-only + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include + +#include +#include + +#include "provisiondb.h" + +static struct provision_db *pdb; + +static void null_provision_db(const void *data) +{ + struct provision_db_entry *items; + size_t n_items; + int r; + + r = provision_db_lookup(NULL, "123", "345", NULL, &items, &n_items); + assert(r == -EBADF); +} + +static void invalid_mcc_mnc(const void *data) +{ + struct provision_db_entry *items; + size_t n_items; + int r; + + r = provision_db_lookup(pdb, "3444", "33", NULL, &items, &n_items); + assert(r == -EINVAL); + + r = provision_db_lookup(pdb, "3ab", "33", NULL, &items, &n_items); + assert(r == -EINVAL); + + r = provision_db_lookup(pdb, "333", "3", NULL, &items, &n_items); + assert(r == -EINVAL); + + r = provision_db_lookup(pdb, "333", "3334", NULL, &items, &n_items); + assert(r == -EINVAL); +} + +struct provision_test { + const char *mcc; + const char *mnc; + const char *spn; + int result; + size_t n_items; + const struct provision_db_entry *items; +}; + +static const struct provision_db_entry alpha_contexts[] = { + { + .name = "Internet", + .type = OFONO_GPRS_CONTEXT_TYPE_INTERNET, + .proto = OFONO_GPRS_PROTO_IP, + .apn = "internet", + .auth_method = OFONO_GPRS_AUTH_METHOD_NONE, + }, + { + .name = "IMS+MMS", + .type = OFONO_GPRS_CONTEXT_TYPE_IMS | + OFONO_GPRS_CONTEXT_TYPE_MMS | + OFONO_GPRS_CONTEXT_TYPE_IA, + .apn = "imsmms", + .proto = OFONO_GPRS_PROTO_IPV6, + .auth_method = OFONO_GPRS_AUTH_METHOD_PAP, + .message_center = "foobar.mmsc:80", + .message_proxy = "mms.proxy.net", + }, +}; + +static const struct provision_db_entry zyx_contexts[] = { + { + .name = "ZYX", + .apn = "zyx", + .type = OFONO_GPRS_CONTEXT_TYPE_INTERNET | + OFONO_GPRS_CONTEXT_TYPE_IA, + .auth_method = OFONO_GPRS_AUTH_METHOD_NONE, + .proto = OFONO_GPRS_PROTO_IP, + }, +}; + +static const struct provision_db_entry beta_contexts[] = { + { + .type = OFONO_GPRS_CONTEXT_TYPE_INTERNET | + OFONO_GPRS_CONTEXT_TYPE_IA, + .proto = OFONO_GPRS_PROTO_IPV4V6, + .apn = "beta.internet", + .auth_method = OFONO_GPRS_AUTH_METHOD_CHAP, + }, +}; + +static const struct provision_db_entry charlie_contexts[] = { + { + .type = OFONO_GPRS_CONTEXT_TYPE_INTERNET | + OFONO_GPRS_CONTEXT_TYPE_IA, + .proto = OFONO_GPRS_PROTO_IPV4V6, + .apn = "charlie.internet", + .auth_method = OFONO_GPRS_AUTH_METHOD_CHAP, + }, +}; + +static const struct provision_db_entry xyz_contexts[] = { + { + .type = OFONO_GPRS_CONTEXT_TYPE_INTERNET | + OFONO_GPRS_CONTEXT_TYPE_IA, + .proto = OFONO_GPRS_PROTO_IPV4V6, + .apn = "xyz", + .auth_method = OFONO_GPRS_AUTH_METHOD_CHAP, + } +}; + +/* Make sure mccmnc not in the database isn't found */ +static const struct provision_test unknown_mcc_mnc = { + .mcc = "994", + .mnc = "42", + .result = -ENOENT, +}; + +/* Successful lookup of 'Operator Beta' settings */ +static const struct provision_test lookup_beta = { + .mcc = "999", + .mnc = "006", + .result = 0, + .n_items = L_ARRAY_SIZE(beta_contexts), + .items = beta_contexts, +}; + +/* Make sure two digit mnc is treated as != to 3 digit mnc */ +static const struct provision_test two_digit_mnc = { + .mcc = "999", + .mnc = "06", + .result = -ENOENT, +}; + +/* + * Fallback to non-MVNO settings in case SPN doesn't match and an operator with + * no SPN is found. This follows legacy oFono behavior and allows provisioning + * to work on modem drivers that do not support EFspn reading. + */ +static const struct provision_test fallback_no_spn = { + .mcc = "999", + .mnc = "005", + .spn = "Bogus", + .result = 0, + .n_items = L_ARRAY_SIZE(beta_contexts), + .items = beta_contexts, +}; + +/* Same as above, but with an MVNO entry for the same mcc/mnc */ +static const struct provision_test fallback_no_spn_2 = { + .mcc = "999", + .mnc = "002", + .spn = "Bogus", + .result = 0, + .n_items = L_ARRAY_SIZE(alpha_contexts), + .items = alpha_contexts, +}; + +/* Successful lookup of Operator Alpha */ +static const struct provision_test lookup_alpha = { + .mcc = "999", + .mnc = "001", + .result = 0, + .n_items = L_ARRAY_SIZE(alpha_contexts), + .items = alpha_contexts, +}; + +/* Successful lookup of ZYX (MVNO on Alpha) */ +static const struct provision_test lookup_zyx = { + .mcc = "999", + .mnc = "01", + .spn = "ZYX", + .result = 0, + .n_items = L_ARRAY_SIZE(zyx_contexts), + .items = zyx_contexts, +}; + +/* + * Successful lookup of Charlie. This has to be an exact SPN match since + * no wildcard value is available + */ +static const struct provision_test lookup_charlie = { + .mcc = "999", + .mnc = "10", + .spn = "Charlie", + .result = 0, + .n_items = L_ARRAY_SIZE(charlie_contexts), + .items = charlie_contexts, +}; + +/* Successful lookup of XYZ (MVNO on Charlie) */ +static const struct provision_test lookup_xyz = { + .mcc = "999", + .mnc = "11", + .spn = "XYZ", + .result = 0, + .n_items = L_ARRAY_SIZE(xyz_contexts), + .items = xyz_contexts, +}; + +/* No match with for an MCC/MNC present in the DB, but no wildcard entry */ +static const struct provision_test lookup_no_match = { + .mcc = "999", + .mnc = "11", + .result = -ENOENT, +}; + +static void provision_lookup(const void *data) +{ + const struct provision_test *test = data; + struct provision_db_entry *items; + size_t n_items; + size_t i; + int r; + + r = provision_db_lookup(pdb, test->mcc, test->mnc, test->spn, + &items, &n_items); + assert(r == test->result); + + if (r < 0) + return; + + assert(n_items == test->n_items); + for (i = 0; i < n_items; i++) { + const struct provision_db_entry *a = items + i; + const struct provision_db_entry *b = test->items + i; + + assert(b->type == a->type); + assert(b->proto == a->proto); + assert(l_streq0(b->apn, a->apn)); + assert(l_streq0(b->name, a->name)); + assert(l_streq0(b->username, a->username)); + assert(l_streq0(b->password, a->password)); + assert(b->auth_method == a->auth_method); + assert(l_streq0(b->message_proxy, a->message_proxy)); + assert(l_streq0(b->message_center, a->message_center)); + } + + l_free(items); +} + +int main(int argc, char **argv) +{ + int r; + + l_test_init(&argc, &argv); + + l_test_add("Lookup on NULL provision db", null_provision_db, NULL); + l_test_add("MCC/MNC input validation", invalid_mcc_mnc, NULL); + l_test_add("Unknown MCC/MNC", provision_lookup, &unknown_mcc_mnc); + l_test_add("Successful Lookup (Beta)", provision_lookup, &lookup_beta); + l_test_add("Two digit MNC", provision_lookup, &two_digit_mnc); + l_test_add("Fallback no-SPN", provision_lookup, &fallback_no_spn); + l_test_add("Fallback no-SPN#2", provision_lookup, &fallback_no_spn_2); + l_test_add("Successful lookup (Alpha)", provision_lookup, &lookup_alpha); + l_test_add("Successful lookup (ZYX)", provision_lookup, &lookup_zyx); + l_test_add("Exact match (Charlie)", provision_lookup, &lookup_charlie); + l_test_add("Exact match (XYZ)", provision_lookup, &lookup_xyz); + l_test_add("Exact math (no match)", provision_lookup, &lookup_no_match); + + pdb = provision_db_new(UNITDIR "test-provision.db"); + assert(pdb); + + r = l_test_run(); + provision_db_free(pdb); + + return r; +} diff --git a/unit/test-provision.json b/unit/test-provision.json new file mode 100644 index 00000000..61d060ad --- /dev/null +++ b/unit/test-provision.json @@ -0,0 +1,92 @@ +[ + { + "name": "Operator Alpha", + "ids": [ + "99955", "99956", "99901", "99902", "999001", "999002", "999056", "999055" + ], + "apns": [ + { + "name": "Internet", + "apn": "internet", + "type": [ + "internet" + ], + "authentication": "none", + "protocol": "ipv4" + }, + { + "name": "IMS+MMS", + "apn": "imsmms", + "type": [ + "ims", "mms", "ia" + ], + "mmsc": "foobar.mmsc:80", + "mmsproxy": "mms.proxy.net", + "authentication": "pap", + "protocol": "ipv6" + } + ] + }, + { + "name": "ZYX (MVNO on Alpha)", + "ids": [ + "999001", "999002", "99901", "99902" + ], + "spn": "ZYX", + "apns": [ + { + "name": "ZYX", + "apn": "zyx", + "type": [ + "internet", "ia" + ], + "authentication": "none", + "protocol": "ipv4" + } + ] + }, + { + "name": "Operator Beta", + "ids": [ + "999005", "999006" + ], + "apns": [ + { + "apn": "beta.internet", + "type": [ + "internet", "ia" + ] + } + ] + }, + { + "name": "Operator Charlie", + "ids": [ + "99910", "99911" + ], + "spn": "Charlie", + "apns": [ + { + "apn": "charlie.internet", + "type": [ + "internet", "ia" + ] + } + ] + }, + { + "name": "XYZ (MVNO on Charlie)", + "ids": [ + "99911" + ], + "spn": "XYZ", + "apns": [ + { + "apn": "xyz", + "type": [ + "internet", "ia" + ] + } + ] + } +]