From patchwork Wed Nov 27 21:31:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13887383 Received: from mail-oa1-f51.google.com (mail-oa1-f51.google.com [209.85.160.51]) (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 E5CAF322E for ; Wed, 27 Nov 2024 21:32:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732743126; cv=none; b=coLCp97TY4KHt4+3wmCueb5QCz3MgZITcfF69kBVzQ1fkqVEznJgJSGx4z4Ggs+GrcgUkXr4m9KVZnkYXzdSOCMkue8Rq2Aftn0pE4ujhrILWadmtfVrWnAVhql4Thkp4hr89vM3r7O4Y53wvb8MPlSyZkqeC2W2buDXPEvSoFU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732743126; c=relaxed/simple; bh=ueKfNAB0UPPS79VSnZQMs81BzvVgtXsNHuPCaigc/gY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=uqaU66LdUY10cPASF9/6/Aw1Vz5Y7vyg79GxJ76xDnT74z0bcFm4iJatl0KlUbp4f4BjpZde8JSBBlosDkUK3jeojwupPGkRnWowhQWEwOsIGwEj39G4I/9r6f0dFqYGdDhn4W+ATswec9lF6+EPhxfUPCqZ1fvauhu+Mg0+W3M= 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=C8mE5uu3; arc=none smtp.client-ip=209.85.160.51 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="C8mE5uu3" Received: by mail-oa1-f51.google.com with SMTP id 586e51a60fabf-2973b53ec02so175097fac.1 for ; Wed, 27 Nov 2024 13:32:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732743124; x=1733347924; 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=qjoH1IgYA6E/twIawgveTEBf+PsTyraRvZNOlYoF4S0=; b=C8mE5uu3nfhLbKFvwASp91vXBaHDXWUxbzOXPmmvpx5q1LGcaC28giosyNKKb32EpD CyV3WzSEJnMR6l+ho0ZZ4OIGIFEMUKOo/XmdVdIdNnH3xyD4GPt9dmhiOOkOBPY4PeAN X64W7yW//EKT9qpauFnXruvKG+WH+EVXaeRIskoHxLC90zhQLqwwLWqYVUERgBH5+Eii mP4+rdrdcLU/y8qMGKNxamKU8QzY6NvS3T3IWRcqnUZw8QKMRHDwdIN0vzJbby9KFets l0sagJ2dlF3LRr8XELnbjfvJ9ppsbwlFKYosG31WI+R5q3Vf0dUnUJh/YaBvnP6edjli fcVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732743124; x=1733347924; 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=qjoH1IgYA6E/twIawgveTEBf+PsTyraRvZNOlYoF4S0=; b=QUKsjyVAFbUesk148FSX2Jv7h6DudP8+1ZcAv7P4r40CO2tLCbBpUPyKijq5rc6I2e Yt/dvDZH5ZCyGk4mK1sQ9xO2xL0WRDVWcs3pkygEkQiYG6bfXV6H3Yric/MV7NvZRZ/G UyWAFgaDDhJgctBhH8t8nzisjsW2Qic+cBsPDtoYpI3szbnrdQFYRS08/Im5+AdHamAC BS32nJp/fuuCZPqlYsdmp4OT0id4f3n2/fertEGKdiKxNTp7FO2g9i6jGEvJ2y7jFl1/ 6t3MXOjmh4FycRMHr2Gz/W4AxIqT/uaWxFE+GnfoaVlqKg1RUgxCu17mSY9l7H7D3HP9 b/UQ== X-Gm-Message-State: AOJu0Yy+dErvgQRi9DbyP/wzbaeod8921ozgqVSCMSTPfapS1q4oX3j9 HeoOWCTaQTum3xM7jaYMZzXU/SiN4Ro9cISkp4RoUvaChwY5PfYP3fAsdg== X-Gm-Gg: ASbGncu09nacrnQkTdH+3xGcL9vQan/65ZnIGYM7eGgIzK/mcc29eAN/kMvkt8yQo59 HkEnx4eAfiZwzEXwzb8Pr/EsJ3G8ZSLKoW6buOuAaXqkkddOFIbfVWszA8lHoDhd4bxWiOgEt5f 24CaJYdX+YtND4ZzgWiOJWzGmTVeAuv4i1qy9WSU/Zz682wFua4DHlB7lvOhv3c4zyErT715nwb AF2+JsM1NU1b9Krs6EQ0+nvgQF0455t/iVW7jia2/3Xk7tzLHm6ypgQwtpXv0zjSAfphgvTxw9d 1LgzWcOED5uO+o1mKVo3czQl X-Google-Smtp-Source: AGHT+IED8tA6olW6Ogy2AFMr6QX/nRK4zHPM91B4o7AyuhzplnaELIWD8cXY964SPv7CpGtmXdQIhg== X-Received: by 2002:a05:6870:e86:b0:295:51e0:9241 with SMTP id 586e51a60fabf-29dc4385da4mr4461856fac.37.1732743123751; Wed, 27 Nov 2024 13:32:03 -0800 (PST) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-29de9ba6bbfsm29114fac.48.2024.11.27.13.32.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 13:32:03 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH v2 1/4] provision: Add 311 270 MCC/MNC as Verizon Date: Wed, 27 Nov 2024 15:31:48 -0600 Message-ID: <20241127213200.202536-1-denkenz@gmail.com> X-Mailer: git-send-email 2.47.0 Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- data/provision.json | 1 + 1 file changed, 1 insertion(+) diff --git a/data/provision.json b/data/provision.json index 434bfd8d8f7b..50319cf33a51 100644 --- a/data/provision.json +++ b/data/provision.json @@ -14266,6 +14266,7 @@ "310010", "310011", "310012", + "311270", "311480", "311481", "311482", From patchwork Wed Nov 27 21:31:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13887384 Received: from mail-oa1-f48.google.com (mail-oa1-f48.google.com [209.85.160.48]) (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 A5F238BE5 for ; Wed, 27 Nov 2024 21:32:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732743127; cv=none; b=CDROfgKUd9Ak/rQWWnW3oXMRAaAVCCcmPBgm7GY4l0w830psRDeP+cEWQ3fF4dShKVcWtTPspe+SReusg/7MlgLFV0VEc50sMOSIXW9n0sMMMB1B4TmjdfGvXBLCJYa0eqY6Ikgm+dFiv8b57OQwEoGLultPg0NNJ0vvhMdOOSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732743127; c=relaxed/simple; bh=5TaHO7DrN1vKwslXkZu7hs3eb0pA1dfqLzuVJFX9bcY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oYufi/sbmwDrEoGQEsZZPkPacTukxcYESo1EwloJSwj2q63ghOMSyUh8l9BISobNn83nmPj/LPFctuesedeXF01xQ/SdD/kccqqfSZIqUx5oVwJfG0UhdqocdVdwkmiunqAXeVxPSg5aheZ03q48FKYeU3eSCHlGSMtVamqAEqE= 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=HC/BGq5u; arc=none smtp.client-ip=209.85.160.48 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="HC/BGq5u" Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-296994dd3bfso177369fac.0 for ; Wed, 27 Nov 2024 13:32:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732743124; x=1733347924; 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=4MJpG/OKdJoR9MoyJHu2RKxjCDf02nOlXZGUlqsczIQ=; b=HC/BGq5uLynMA+e9wdjMwED93cXXyUTf66pNQKOB6PeDjCpXMT+CB5n3b3X9N3BBlA oMchEydsBZMplONA/yBHNAI60zbw2I3Y/yV5hyhrNHtehnHT+qTkohrpiBmsqIDOfN0z C3Ye0mmLUrG9QcV9aopOHIvRvvQ62MKjDxA+1Edk7/NSiSMDIm2sfhNSsyctxARdyzrb XaG5dJGz7CpG5cxR0ylWo6Vnd/k49U6reIh2S4qysM5i/2lmAcXPe9EHMJGmjLXRrojv Amj/PRBPZHoUgTfK3VO8ujz05wOQ+eZG/a2e80fytD8pPcdV92r+Hq03lBJAEGnD+gdt EU3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732743124; x=1733347924; 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=4MJpG/OKdJoR9MoyJHu2RKxjCDf02nOlXZGUlqsczIQ=; b=mvtvv/PkkRfSQ680a5cFqgwAjfACmrgLRltRiouDaStMZRS+rH3p9/iXljRhgBu6bP cQOI4G/pfsFortkrhly87a3smyUusZhI/Q5eiYWYfxSI8sXjsQVXLVJwU8HxVKp6P/YT H5PUgh1Pbe6eKSull8Dtym7femFYghistks2AFFoxQ+sxhG7bZkjYOnWCFkiPoDLme6W tJ7nigTNn/0JS4UK1gHrOHqaa5hEzzEOnidFlxxtU2lmshAz0TmTyS9XWD7frXKcUGSn 8OIr1TpGNCL7Mj73nFU3B32aFfeC7ySEtHZXsjeqPvxKVV2OyUNhI21HAtvDGQT+4062 zvJQ== X-Gm-Message-State: AOJu0Yy+7uj3nuQr6rdsNvhHKFRZs6HQKqgLxZqVYxPcJE0l2gHmpkn4 KmsCgus9ccgWM0JpxLCrxpdQD+Oo//xjY9lalXsMboWDIi7W1z1aqdUHPg== X-Gm-Gg: ASbGncv6mp9cRjR6kY+Gl5iGap89FD6u9BGKIDMRClisisv8bQk40FCEHdjlV+W2w9O kq6Xo4V8nyjD6d3O+QVWjxFCiq/nR8F5KCWXyepi/WnWHGLLTqQnNpJvZLtz/2vi+EQHhiBv93X 9fi7IipSZbkhnZAmeOiFN9hljiTmOLu91Z3x13GwjpxoPkqAqgbfCGGRfESb3v5yn5x+yllNs6y +HulwrV9T14IQIfEUWZ2eRltvUIPm8fXLJtE7l/GIfTEYEntVFpSgfUjfgHjNkJSucGupA+cMew 9HjTV9k3lglMWCBw+bBYoCbk X-Google-Smtp-Source: AGHT+IFbxoD/frltrOOgGpOZBf5RopIOZ3oBNT6Q1eyjYE216/jupX0MGG8fiy/vExRgp14Y1MOuvg== X-Received: by 2002:a05:6870:ab0b:b0:288:57fa:961d with SMTP id 586e51a60fabf-29dc438652bmr4139463fac.38.1732743124622; Wed, 27 Nov 2024 13:32:04 -0800 (PST) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-29de9ba6bbfsm29114fac.48.2024.11.27.13.32.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 13:32:04 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH v2 2/4] rmnet: Default created interfaces to MTU of 1400 Date: Wed, 27 Nov 2024 15:31:49 -0600 Message-ID: <20241127213200.202536-2-denkenz@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241127213200.202536-1-denkenz@gmail.com> References: <20241127213200.202536-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 By default the network interface is being created with 16380 byte MTU, which is excessive for cellular links. Typically, cellular links use a maximum MTU of around 1430. Set the MTU to something more reasonable by default. Unfortunately, the kernel does not support setting the MTU value in the original NEWLINK message. It must be set separately in a different transaction. Add support for this and make sure that cancellation logic still works. The logic in update_new_link_ifindex() is updated to make it more defensive. Since two rtnl messages are sent (RTM_NEWLINK to create the device followed by RTM_SETLINK to set the MTU), there are now two RTM_NEWLINK events that are triggered for each item in the rmnet request. Since 'current' is incremented after RTM_NEWLINK request succeeds, there is a possibility of buffer overflow. --- src/rmnet.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 9 deletions(-) diff --git a/src/rmnet.c b/src/rmnet.c index 83110c33a980..42b03249da54 100644 --- a/src/rmnet.c +++ b/src/rmnet.c @@ -25,6 +25,7 @@ #define RMNET_TYPE "rmnet" #define MAX_MUX_IDS 254U +#define DEFAULT_MTU 1400U struct rmnet_request { uint32_t parent_ifindex; @@ -195,19 +196,16 @@ next_request: rmnet_start_next_request(); } -static void rmnet_new_link_cb(int error, uint16_t type, const void *data, +static void rmnet_set_mtu_cb(int error, uint16_t type, const void *data, uint32_t len, void *user_data) { struct rmnet_request *req = l_queue_peek_head(request_q); - DBG("NEWLINK %u (%u/%u) complete, error: %d", - req->netlink_id, req->current + 1, req->n_interfaces, error); + DBG("%u (%u/%u) complete, error: %d", + req->netlink_id, req->current, req->n_interfaces, error); req->netlink_id = 0; - if (!error) - req->current += 1; - if (error || req->canceled) { __rmnet_cancel_request(); req->n_interfaces = 0; @@ -229,6 +227,48 @@ next_request: rmnet_start_next_request(); } +static void rmnet_new_link_cb(int error, uint16_t type, const void *data, + uint32_t len, void *user_data) +{ + struct rmnet_request *req = l_queue_peek_head(request_q); + uint32_t ifindex = req->infos[req->current].ifindex; + + DBG("NEWLINK %u (%u/%u) complete, error: %d", + req->netlink_id, req->current + 1, req->n_interfaces, error); + + req->netlink_id = 0; + + if (!error) + req->current += 1; + + if (error || req->canceled) + goto error; + + /* + * Unfortunately the kernel does not take IFLA_MTU into account + * when creating new RMNet links, so this must be done as a separate + * step. Hopefully this is fixed one day + */ + error = -EIO; + req->netlink_id = l_rtnl_link_set_mtu(rtnl, ifindex, DEFAULT_MTU, + rmnet_set_mtu_cb, NULL, NULL); + if (req->netlink_id) { + DBG("Set MTU: interface: %u/%u, request: %u", + req->current, req->n_interfaces, req->netlink_id); + return; + } +error: + __rmnet_cancel_request(); + req->n_interfaces = 0; + + if (req->new_cb) + req->new_cb(error, req->n_interfaces, + req->n_interfaces ? req->infos : NULL, + req->user_data); + + rmnet_request_free(req); +} + static void rmnet_start_next_request(void) { struct rmnet_request *req = l_queue_peek_head(request_q); @@ -429,6 +469,7 @@ static int rmnet_parse_link(const void *data, uint32_t len, bool have_linkinfo = false; const char *ifname = NULL; uint16_t ifnamelen = 0; + uint32_t mtu = 0; uint16_t rta_type; uint16_t rta_len; const void *rta_data; @@ -450,10 +491,16 @@ static int rmnet_parse_link(const void *data, uint32_t len, have_linkinfo = true; break; + case IFLA_MTU: + if (rta_len != sizeof(uint32_t)) + return -EBADMSG; + + mtu = l_get_u32(rta_data); + break; } } - if (!have_linkinfo || !ifname || !ifnamelen) + if (!have_linkinfo || !ifname || !ifnamelen || !mtu) return -ENOENT; r = rmnet_parse_info_data(&linkinfo, out_mux_id); @@ -530,14 +577,23 @@ static void update_new_link_ifindex(uint16_t mux_id, { struct rmnet_request *req; struct rmnet_ifinfo *info; + unsigned int i; req = l_queue_peek_head(request_q); if (!req || req->request_type != RTM_NEWLINK) return; - info = req->infos + req->current; - if (info->mux_id == mux_id && !strcmp(info->ifname, ifname)) + for (i = 0; i < req->n_interfaces; i++) { + info = req->infos + i; + + if (info->mux_id != mux_id) + continue; + + if (strcmp(info->ifname, ifname)) + continue; + info->ifindex = ifindex; + } } static void rmnet_link_notification(uint16_t type, const void *data, From patchwork Wed Nov 27 21:31:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13887385 Received: from mail-oa1-f42.google.com (mail-oa1-f42.google.com [209.85.160.42]) (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 D9AD38BE5 for ; Wed, 27 Nov 2024 21:32:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732743129; cv=none; b=QXZB/yPQmmW5dPt1g7SdE7nr23nAGrnAXwja58Cdw5QOzMAzWRo/5KIfS4V1ZPioK4OpNsHj1McbaAe78hK48Hvj4mpx1CR+m7RtAZX4uWd6h/tetkqoKez/O7Cl2STSqiSPPyw6kb0ZVBp0uuCWNEU72UUEYM3ZNf5FOf4aFV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732743129; c=relaxed/simple; bh=mI0L8i3m4/EJNGOmVQJYLnp6CCKW3GWaHxlLIaXCzy0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DRJ/Lfkix4+edPnnvFXyxg0g+NwaTRKHo9X0JYX/wwYODUQ21y2pLWrPziE7uxb0yyeeFh6vOB+GjfJiXRZoBwhqA9bnlM4VUWp9B4LclhKasrI7tXExqWySIePdyfnza0KfLO4cz1fVLiwKgX6tgqcC51GbbuONXjOWi5oDhuY= 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=dWLITDT0; arc=none smtp.client-ip=209.85.160.42 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="dWLITDT0" Received: by mail-oa1-f42.google.com with SMTP id 586e51a60fabf-296bff3f5e8so169718fac.2 for ; Wed, 27 Nov 2024 13:32:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732743126; x=1733347926; 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=/bR2AiJV9WCM1g4gkusYNTzn+tVuZD//DSHbotcE1C0=; b=dWLITDT0ZGDnBc47iY+G73zEj8Vao4AuF2hhRe4A3UNgKUfDDFkXxh8dMk/QjjcdV7 d2YBr0fnwgBOhxsmAlhordivf3v10tzDcjDL/c+l9+Hui4R1MyVlCJZLnQfZOLtKLxmd dhCzU7E5GRWraVIwSMtceYSVKG/26JAKDuba053VHbXzwNDX7ys69h9QFhJ5Dx72rYz2 qb40nKIoY82FWzwPNqkiY1rodJ2LVUdDNz/GMlkdhiz4TXpIVjMqJKvFF33ji9kmbEte sFtZp1DRMIEZxUlID+0zJEg/1weoA3ufiZiDvD9QZc0ZRJFD630wxd6FUo/2i7UdBKjY UMoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732743126; x=1733347926; 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=/bR2AiJV9WCM1g4gkusYNTzn+tVuZD//DSHbotcE1C0=; b=TnyERI0CIPwXiU4G6oHmUS/K2/cpzfA3yB8QFZVHWnbPuoEq+NXcCD2HhdfMXo8yvy gKcVsIsAupWfVsSzJgfJwT+LCez9JsPDnAv2iTalkFVDsz8TExDtab+OZihCpctBLN7o rcbJhVvC5PFtuxhyBtShbdZ9tXixZ3Kmh87kYC54t4nKdQdAMDWnYa+yVYT4A9TkBbdt r0OCek6zmxwxuh6GiIFLxPmphVBmBM8gTUtayMGH1FIlu+mmfMIcbPman8nz1uiUVEzq 2taaIPj7LbvgSTyQK8Ufz6tqw7ziLvddE7FQ4vkXuAD/1copdvAPZ6KB+WmejejOlMeb Cz/g== X-Gm-Message-State: AOJu0YxwRDt7Dt8CE05SW0LvurcCUpKzt+IU/1RqVSVnLYpX75s1+/O1 tc0ifEBW8f2Q6fgNsMDAfHe573PP5K/5uA/l93fXoNY0+kVDN4/H3Q1Kbg== X-Gm-Gg: ASbGncvLzLj/p0vbPq6YF2/ylVDuQBjougn4szFWCEB5Xc/4WgA7q+CHKoQwB//q021 uik0cK8Lkk0qBuqkfUQAvkdFMmCUUd3QP/tdl8YfOwRjtautNZ8x16haQdKNrS1uNaNooYt2uwp 024PzyAPBSfMddJxWCFagMgHbMFxK1uzLm+zsTA3SEoX7LhE0O2wYXMRmk6KeC/uPx9bcKylREE 4Sea3ZA+kiiuM7aw6I4sf6JGE3IaAyL6oOniZ63BK/JkB/46KrdLkV/bO/27/h2idPaYAoynNia U9www9ZVM2J4c3bl3KZEnIQE X-Google-Smtp-Source: AGHT+IHNXFnvgGbtBfTGZJOrg8kWrnTp6PS49IZ+w1hK6EnAe4hFuIFP4tjSzQ8GnYST8Bu43HkDTg== X-Received: by 2002:a05:6871:e805:b0:29d:ca30:5c21 with SMTP id 586e51a60fabf-29dca308d5dmr3618437fac.29.1732743125710; Wed, 27 Nov 2024 13:32:05 -0800 (PST) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-29de9ba6bbfsm29114fac.48.2024.11.27.13.32.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 13:32:05 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH v2 3/4] qrtrqmi: Add multiple bearer support on mhi_net Date: Wed, 27 Nov 2024 15:31:50 -0600 Message-ID: <20241127213200.202536-3-denkenz@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241127213200.202536-1-denkenz@gmail.com> References: <20241127213200.202536-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add support for multiple simultaneous active bearers for devices that use the upstream mhi_net driver. Use the newly added rmnet module to request multiple rmnet interfaces that will sit on top of the main mhi_net interface (typically mhi_hwipX). WDA service is also requested, and the data format is setup to perform data aggregation. For drivers that use pre-multiplexed interfaces (i.e. rmnet / IPA), migrate the pre-multiplexing logic to use rmnet_ifinfo structure. --- plugins/qrtrqmi.c | 213 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 191 insertions(+), 22 deletions(-) diff --git a/plugins/qrtrqmi.c b/plugins/qrtrqmi.c index 21103371046a..4a00fa45a110 100644 --- a/plugins/qrtrqmi.c +++ b/plugins/qrtrqmi.c @@ -42,14 +42,27 @@ #include #include +#include #include +#include +#include "src/rmnet.h" + +#define MAX_CONTEXTS 4 +#define DEFAULT_DL_DATAGRAMS 32 +#define DEFAULT_DL_AGGREGATION_SIZE 32768 +#define DEFAULT_UL_AGGREGATION_SIZE 16384 struct qrtrqmi_data { struct qmi_qrtr_node *node; struct qmi_service *dms; + struct qmi_service *wda; int main_net_ifindex; char main_net_name[IFNAMSIZ]; + struct rmnet_ifinfo rmnet_interfaces[MAX_CONTEXTS]; + uint8_t n_premux; + int rmnet_id; bool have_voice : 1; + bool soc_premux : 1; }; static void qrtrqmi_io_debug(const char *str, void *user_data) @@ -66,6 +79,31 @@ static void qrtrqmi_debug(const char *str, void *user_data) ofono_debug("%s%s", prefix, str); } +static int setup_soc_premux_interfaces(struct ofono_modem *modem) +{ + struct qrtrqmi_data *data = ofono_modem_get_data(modem); + const char *interface; + unsigned int i; + char buf[256]; + int mux_id; + + for (i = 0; i < data->n_premux; i++) { + sprintf(buf, "PremuxInterface%dMuxId", i + 1); + mux_id = ofono_modem_get_integer(modem, buf); + + sprintf(buf, "PremuxInterface%d", i + 1); + interface = ofono_modem_get_string(modem, buf); + if (!interface) + return -ENOENT; + + data->rmnet_interfaces[i].mux_id = mux_id; + l_strlcpy(data->rmnet_interfaces[i].ifname, interface, + sizeof(data->rmnet_interfaces[i].ifname)); + } + + return 0; +} + /* * Probe the modem. The following modem properties are expected to be set * in order to initialize the driver properly: @@ -82,6 +120,15 @@ static void qrtrqmi_debug(const char *str, void *user_data) * * Bus * The bus of the modem. Values can be "embedded", or "pci" + * + * PremuxInterface{0..N}MuxId + * The mux identifier of the pre-multiplexed interface (e.g. 1 for rmnet0) + * + * PremuxInterface{0..N} + * The netdev name of the pre-multiplexed interface (e.g. rmnet0) + * + * NumPremuxInterfaces + * The number of pre-multiplexed interfaces */ static int qrtrqmi_probe(struct ofono_modem *modem) { @@ -104,6 +151,9 @@ static int qrtrqmi_probe(struct ofono_modem *modem) if (!if_driver || !ifname || !ifindex || !bus) return -EPROTO; + if (!L_IN_STRSET(bus, "pcie", "embedded")) + return -ENOTSUP; + data = l_new(struct qrtrqmi_data, 1); data->main_net_ifindex = ofono_modem_get_integer(modem, "NetworkInterfaceIndex"); @@ -113,6 +163,22 @@ static int qrtrqmi_probe(struct ofono_modem *modem) ofono_modem_set_data(modem, data); ofono_modem_set_capabilities(modem, OFONO_MODEM_CAPABILITY_LTE); + data->n_premux = ofono_modem_get_integer(modem, "NumPremuxInterfaces"); + if (data->n_premux) { + int err; + + if (data->n_premux > MAX_CONTEXTS) + data->n_premux = MAX_CONTEXTS; + + err = setup_soc_premux_interfaces(modem); + if (err) { + l_free(data); + return err; + } + + data->soc_premux = true; + } + return 0; } @@ -120,6 +186,8 @@ static void qrtrqmi_deinit(struct qrtrqmi_data *data) { qmi_service_free(data->dms); data->dms = NULL; + qmi_service_free(data->wda); + data->wda = NULL; qmi_qrtr_node_free(data->node); data->node = NULL; } @@ -132,13 +200,109 @@ static void qrtrqmi_remove(struct ofono_modem *modem) ofono_modem_set_data(modem, NULL); + if (data->rmnet_id) { + rmnet_cancel(data->rmnet_id); + data->rmnet_id = 0; + } + qrtrqmi_deinit(data); l_free(data); } +static void rmnet_get_interfaces_cb(int error, unsigned int n_interfaces, + const struct rmnet_ifinfo *interfaces, + void *user_data) +{ + struct ofono_modem *modem = user_data; + struct qrtrqmi_data *data = ofono_modem_get_data(modem); + unsigned int i; + + DBG("error: %d, n_interfaces: %u", error, n_interfaces); + data->rmnet_id = 0; + + if (error) + goto error; + + DBG("RMNet interfaces created:"); + for (i = 0; i < n_interfaces; i++) + DBG("\t%s[%d], mux_id: %u", + interfaces[i].ifname, interfaces[i].ifindex, + interfaces[i].mux_id); + + memcpy(data->rmnet_interfaces, interfaces, + sizeof(struct rmnet_ifinfo) * n_interfaces); + data->n_premux = n_interfaces; + ofono_modem_set_powered(modem, TRUE); + return; +error: + qrtrqmi_deinit(data); + ofono_modem_set_powered(modem, FALSE); +} + +static void set_data_format_cb(struct qmi_result *result, void *user_data) +{ + struct ofono_modem *modem = user_data; + struct qrtrqmi_data *data = ofono_modem_get_data(modem); + struct qmi_wda_data_format format; + int r; + + DBG(""); + + if (qmi_result_set_error(result, NULL)) + goto error; + + r = qmi_wda_parse_data_format(result, &format); + if (r < 0) + goto error; + + DBG("DL Aggregation Size: %u", format.dl_max_size); + DBG("DL Max Datagrams: %u", format.dl_max_datagrams); + DBG("DL Aggregation Protocol: %u", format.dl_aggregation_protocol); + DBG("UL Aggregation Protocol: %u", format.ul_aggregation_protocol); + + data->rmnet_id = rmnet_get_interfaces(data->main_net_ifindex, + MAX_CONTEXTS, + rmnet_get_interfaces_cb, + modem, NULL); + if (data->rmnet_id > 0) + return; + + ofono_error("Unable to request RMNet interfaces"); +error: + qrtrqmi_deinit(data); + ofono_modem_set_powered(modem, FALSE); +} + +static void setup_data_format(struct ofono_modem *modem) +{ + struct qrtrqmi_data *data = ofono_modem_get_data(modem); + struct qmi_endpoint_info endpoint_info = { + .endpoint_type = QMI_DATA_ENDPOINT_TYPE_PCIE, + .interface_number = 0x04, + }; + struct qmi_wda_data_format format = { + .ll_protocol = QMI_WDA_DATA_LINK_PROTOCOL_RAW_IP, + .dl_aggregation_protocol = QMI_WDA_AGGREGATION_PROTOCOL_QMAPV5, + .ul_aggregation_protocol = QMI_WDA_AGGREGATION_PROTOCOL_QMAPV5, + .dl_max_datagrams = DEFAULT_DL_DATAGRAMS, + .dl_max_size = DEFAULT_DL_AGGREGATION_SIZE, + }; + + DBG("%p", modem); + + data->wda = qmi_qrtr_node_get_service(data->node, QMI_SERVICE_WDA); + if (qmi_wda_set_data_format(data->wda, &endpoint_info, &format, + set_data_format_cb, modem, NULL) > 0) + return; + + qrtrqmi_deinit(data); + ofono_modem_set_powered(modem, FALSE); +} + static void power_reset_cb(struct qmi_result *result, void *user_data) { struct ofono_modem *modem = user_data; + struct qrtrqmi_data *data = ofono_modem_get_data(modem); DBG(""); @@ -148,6 +312,11 @@ static void power_reset_cb(struct qmi_result *result, void *user_data) return; } + if (!data->soc_premux) { + setup_data_format(modem); + return; + } + ofono_modem_set_powered(modem, TRUE); } @@ -177,7 +346,11 @@ static void get_oper_mode_cb(struct qmi_result *result, void *user_data) break; default: - ofono_modem_set_powered(modem, TRUE); + if (!data->soc_premux) + setup_data_format(modem); + else + ofono_modem_set_powered(modem, TRUE); + return; } @@ -199,6 +372,10 @@ static void lookup_done(void *user_data) !qmi_qrtr_node_has_service(node, QMI_SERVICE_NAS)) goto error; + if (!data->soc_premux && + !qmi_qrtr_node_has_service(node, QMI_SERVICE_WDA)) + goto error; + data->dms = qmi_qrtr_node_get_service(node, QMI_SERVICE_DMS); if (qmi_service_send(data->dms, QMI_DMS_GET_OPER_MODE, NULL, get_oper_mode_cb, modem, NULL) > 0) @@ -236,10 +413,18 @@ static int qrtrqmi_enable(struct ofono_modem *modem) static void power_disable_cb(struct qmi_result *result, void *user_data) { struct ofono_modem *modem = user_data; + struct qrtrqmi_data *data = ofono_modem_get_data(modem); DBG(""); - qrtrqmi_deinit(ofono_modem_get_data(modem)); + if (!data->soc_premux) { + rmnet_del_interfaces(data->n_premux, data->rmnet_interfaces); + data->n_premux = 0; + memset(data->rmnet_interfaces, 0, + sizeof(data->rmnet_interfaces)); + } + + qrtrqmi_deinit(data); ofono_modem_set_powered(modem, FALSE); } @@ -346,11 +531,8 @@ static void setup_gprs(struct ofono_modem *modem) { struct qrtrqmi_data *data = ofono_modem_get_data(modem); struct qmi_qrtr_node *node = data->node; - int n_premux = ofono_modem_get_integer(modem, "NumPremuxInterfaces"); struct ofono_gprs *gprs; - const char *interface; - char buf[256]; - int i; + unsigned int i; gprs = ofono_gprs_create(modem, 0, "qmimodem", qmi_qrtr_node_get_service(node, QMI_SERVICE_WDS), @@ -361,23 +543,10 @@ static void setup_gprs(struct ofono_modem *modem) return; } - /* Upstream driver default, single interface, single context */ - if (!n_premux) { - interface = ofono_modem_get_string(modem, "NetworkInterface"); - setup_gprs_context(0, interface, gprs); - return; - } - - for (i = 0; i < n_premux; i++) { - int mux_id; - - sprintf(buf, "PremuxInterface%dMuxId", i + 1); - mux_id = ofono_modem_get_integer(modem, buf); - - sprintf(buf, "PremuxInterface%d", i + 1); - interface = ofono_modem_get_string(modem, buf); + for (i = 0; i < data->n_premux; i++) { + struct rmnet_ifinfo *ifinfo = data->rmnet_interfaces + i; - setup_gprs_context(mux_id, interface, gprs); + setup_gprs_context(ifinfo->mux_id, ifinfo->ifname, gprs); } } From patchwork Wed Nov 27 21:31:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13887386 Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) (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 27C49190499 for ; Wed, 27 Nov 2024 21:32:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732743129; cv=none; b=bQ9XJjXYRM0XOUVxG2g9eeuSlyIekkPOEkiFu2HCFVvqcaUW0ClG6n6rO9pG+s5H9+bXFtfGLbsrpLFfaypzq9Ey/sJ+eQjohhstGmKsf6LqzQDRdA1+0FdHroMQt3ZVqSR4NGQqJxBS7qhavIYPfDMoDz7xcId5cndQ4Rw3oGU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732743129; c=relaxed/simple; bh=NK0suka3bC9cQrBYmvrmBx8NLKrCUhbAEm5KakH7I+U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EbL+gGc8DhB+jkbCsR5VtyNpJHDsgH7LumMLrEffYMziYX0ax1jL3CH9CgdwHyJgK/RyVfgSb9jIxKYDBdqTetHKa6JGbw8io1BzgqGxSPh+3lpRbnO++1eGMj6ly98BcwfMkjoN5pkqIGUMXh0jDpIq4K9CVygfMiCI3Pt64oE= 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=Ozqms14U; arc=none smtp.client-ip=209.85.161.52 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="Ozqms14U" Received: by mail-oo1-f52.google.com with SMTP id 006d021491bc7-5f1cec20a77so93680eaf.1 for ; Wed, 27 Nov 2024 13:32:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732743127; x=1733347927; 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=LES2CKeCTqrrwjhdcdiTowqliXIiyyUxO8tED5Lh1XU=; b=Ozqms14UfknBafsANFSYTpwsnDOkJeIiPmqz2jSaQ7zrODm5dKHClCVieRvORVcfNv Yn6kc1ccErBtfcCPjOKmeVvn9JuHAiO761tpZQsS/px91k1bHbPreFB5qHRi4xDM+xNm L4NgNu4HKmeGXQLstzyw1wAM13/RPy5lMiw7oWMBOw7vu8RUloxjQzWCQuDagIzU8piI h5E7LcUVtzrxwrbwrLG03G0nk/Q+2k6z/ozifu51HrY8/8940CxCsqkb74taZq1DvstN x6Gkmq9JP8jN4KxrnpuigtUURsBmlWApP06JHrGsHVbYzk/Ov1RBlVc6ppEqmfk7ubxL fF6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732743127; x=1733347927; 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=LES2CKeCTqrrwjhdcdiTowqliXIiyyUxO8tED5Lh1XU=; b=vwsEs43FN6Fkkgs2qGHXDncW3NK7bhK1nWjrRA9UwHsSYuMaFC+PaOWbOZhjsRFWpF 6sdaFUNRFajxMxJIfpFHS+6wfbDM7uUiVE9nfHnfk+l2r/i00woPVOmibG+EiRoTIBUO HS/HGMaQNrGEFqMo7dKqb4ITp6PpgzU2XWxQXkGegVR96SDwPtemHb1HxXqsxgpBdEu1 IGIMtr6u9HTKTRnl6I5Pv2i98UoYH0t9FR8PgEIwgs25UjYVGHIyEkbVfN/+y84c+bUZ 4HZjfOf9KnxPGiynLxLLEZkr9A6UXBZHhoWpgTx3wyv5IDDpgmqTloODHKFnHB1iKNor Sf8Q== X-Gm-Message-State: AOJu0YwHUZezW+D1V0Ot0zTtobBJXLhFAmbYklI41dqH7NUzTWfzXVGH el9p9N5AbetU1bdyNmsMyoiSrlpkPYzrPdNCB1UeLzs6sSTpppTzwasmyg== X-Gm-Gg: ASbGncuLUkIrXiSbQC9ubmORty1Y3b1S1eOKSA/Emr6btr+/w3M3iQmy7qRJDOxgUXX 7Gy5usgkHjl0ykU85ZCCkpA4IlMdZcgR6wa8wWgcxGSFPY4dDD/i50OfKvuAtMbEUuhB7SXCMNp MUDleclHufkOLO9bQjsjJGV7JcQGKqqmPypGRyUEF+wqtPBREZ3GPJNBMjrax1kAm6Z9WjqPCid YY/x7FY4kHIGFy2duUc3xohrSkYydjpNl94VhOMtdnnvbS2Anr/Lu7Gf0UyLlK08ZLnoi/SBwoN ucrWbt/XD5gnnINfc0h2BzgZ X-Google-Smtp-Source: AGHT+IEV383SSJymOun4Nml2A9C0L4VobpZQ8Wvit9y5m9COmjq6Ls0frepDQNTNM2PTYtw9bgiLIw== X-Received: by 2002:a05:6870:1704:b0:29d:c937:8a2a with SMTP id 586e51a60fabf-29dc9378b13mr4169952fac.9.1732743126776; Wed, 27 Nov 2024 13:32:06 -0800 (PST) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-29de9ba6bbfsm29114fac.48.2024.11.27.13.32.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2024 13:32:06 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH v2 4/4] qrtrqmi: Manage main netdev as part of .set_online Date: Wed, 27 Nov 2024 15:31:51 -0600 Message-ID: <20241127213200.202536-4-denkenz@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241127213200.202536-1-denkenz@gmail.com> References: <20241127213200.202536-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The mhi_hwipX interface is created with IFF_UP not set. It must be set IFF_UP when the modem is brought into online state, otherwise packets will not flow properly. Similarly, when bring the modem into offline state, bring down the main network device for consistency. --- plugins/qrtrqmi.c | 73 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 8 deletions(-) diff --git a/plugins/qrtrqmi.c b/plugins/qrtrqmi.c index 4a00fa45a110..27d071aa8284 100644 --- a/plugins/qrtrqmi.c +++ b/plugins/qrtrqmi.c @@ -61,6 +61,7 @@ struct qrtrqmi_data { struct rmnet_ifinfo rmnet_interfaces[MAX_CONTEXTS]; uint8_t n_premux; int rmnet_id; + uint32_t set_powered_id; bool have_voice : 1; bool soc_premux : 1; }; @@ -206,6 +207,12 @@ static void qrtrqmi_remove(struct ofono_modem *modem) } qrtrqmi_deinit(data); + + if (data->set_powered_id) { + l_netlink_cancel(l_rtnl_get(), data->set_powered_id); + data->set_powered_id = 0; + } + l_free(data); } @@ -460,25 +467,75 @@ static void set_online_cb(struct qmi_result *result, void *user_data) CALLBACK_WITH_SUCCESS(cb, cbd->data); } -static void qrtrqmi_set_online(struct ofono_modem *modem, ofono_bool_t online, - ofono_modem_online_cb_t cb, void *user_data) +static void powered_common_cb(int error, bool online, struct cb_data *cbd) { - struct qrtrqmi_data *data = ofono_modem_get_data(modem); - struct cb_data *cbd = cb_data_new(cb, user_data); + struct qrtrqmi_data *data = cbd->user; struct qmi_param *param; + ofono_modem_online_cb_t cb = cbd->cb; - DBG("%p %s", modem, online ? "online" : "offline"); + data->set_powered_id = 0; + + if (error) + goto error; param = qmi_param_new_uint8(QMI_DMS_PARAM_OPER_MODE, online ? QMI_DMS_OPER_MODE_ONLINE : QMI_DMS_OPER_MODE_LOW_POWER); - if (qmi_service_send(data->dms, QMI_DMS_SET_OPER_MODE, param, - set_online_cb, cbd, l_free) > 0) + if (qmi_service_send(data->dms, QMI_DMS_SET_OPER_MODE, + param, set_online_cb, + cb_data_ref(cbd), cb_data_unref) > 0) return; qmi_param_free(param); - l_free(cbd); + cb_data_unref(cbd); +error: + CALLBACK_WITH_FAILURE(cb, cbd->data); +} + +static void powered_up_cb(int error, uint16_t type, const void *msg, + uint32_t len, void *user_data) +{ + struct cb_data *cbd = user_data; + + DBG("error: %d: %s", error, strerror(-error)); + powered_common_cb(error, true, cbd); +} + +static void powered_down_cb(int error, uint16_t type, const void *msg, + uint32_t len, void *user_data) +{ + struct cb_data *cbd = user_data; + + DBG("error: %d: %s", error, strerror(-error)); + powered_common_cb(error, false, cbd); +} + +static void qrtrqmi_set_online(struct ofono_modem *modem, ofono_bool_t online, + ofono_modem_online_cb_t cb, void *user_data) +{ + struct qrtrqmi_data *data = ofono_modem_get_data(modem); + struct l_netlink *rtnl = l_rtnl_get(); + struct cb_data *cbd = cb_data_new(cb, user_data); + l_netlink_command_func_t powered_cb; + + DBG("%p %s", modem, online ? "online" : "offline"); + + cbd->user = data; + + if (online) + powered_cb = powered_up_cb; + else + powered_cb = powered_down_cb; + + data->set_powered_id = l_rtnl_set_powered(rtnl, data->main_net_ifindex, + online, powered_cb, + cbd, cb_data_unref); + if (data->set_powered_id) + return; + + cb_data_unref(cbd); + CALLBACK_WITH_FAILURE(cb, user_data); } static void qrtrqmi_pre_sim(struct ofono_modem *modem)