diff mbox series

[10/13] gobi: Bring down the main interface at startup

Message ID 20241031220638.1582166-10-denkenz@gmail.com (mailing list archive)
State Accepted
Commit 147de7a149f9e8fe488eb6a6a3f042dd87e76bc7
Headers show
Series [01/13] qmi: validate TLV length | expand

Commit Message

Denis Kenzior Oct. 31, 2024, 10:06 p.m. UTC
The current gobi logic tried to set the qmi_wwan 'raw_ip' state based on
the results of wda_get_data_format.  If link_layer protocol was
'raw_ip', then 'raw_ip' setting on qmi_wwan was set to 'Y'.  For 802.3,
'raw_ip' setting was set to 'N'.

Unfortunately this was broken at some point and the setting could not be
toggled when the main network device was IFF_UP (default when USB device
is detected by the kernel).

Fix this by having .enable callback bring the device down at
initialization time.  oFono core will set the device IFF_UP once the
context is activated, and bring it down when the context is deactivated.
---
 plugins/gobi.c | 46 ++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 38 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/plugins/gobi.c b/plugins/gobi.c
index 5c3ae0737a15..e75a0312f6d0 100644
--- a/plugins/gobi.c
+++ b/plugins/gobi.c
@@ -230,13 +230,10 @@  static void add_service_request(struct gobi_data *data,
 	data->service_requests[data->num_service_requests++] = req;
 }
 
-static void shutdown_cb(void *user_data)
+static void __shutdown_device(struct ofono_modem *modem)
 {
-	struct ofono_modem *modem = user_data;
 	struct gobi_data *data = ofono_modem_get_data(modem);
 
-	DBG("");
-
 	data->discover_attempts = 0;
 	memset(&data->service_requests, 0, sizeof(data->service_requests));
 	data->cur_service_request = 0;
@@ -245,7 +242,15 @@  static void shutdown_cb(void *user_data)
 
 	qmi_qmux_device_free(data->device);
 	data->device = NULL;
+}
+
+static void shutdown_cb(void *user_data)
+{
+	struct ofono_modem *modem = user_data;
 
+	DBG("");
+
+	__shutdown_device(modem);
 	ofono_modem_set_powered(modem, FALSE);
 }
 
@@ -552,11 +557,32 @@  error:
 	shutdown_device(modem);
 }
 
+static void init_powered_down_cb(int error, uint16_t type,
+					const void *msg, uint32_t len,
+					void *user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct gobi_data *data = ofono_modem_get_data(modem);
+	int r;
+
+	DBG("error: %d", error);
+
+	data->set_powered_id = 0;
+
+	if (error)
+		goto error;
+
+	r = qmi_qmux_device_discover(data->device, discover_cb, modem, NULL);
+	if (!r)
+		return;
+error:
+	__shutdown_device(modem);
+}
+
 static int gobi_enable(struct ofono_modem *modem)
 {
 	struct gobi_data *data = ofono_modem_get_data(modem);
 	const char *device;
-	int r;
 
 	DBG("%p", modem);
 
@@ -575,11 +601,15 @@  static int gobi_enable(struct ofono_modem *modem)
 		qmi_qmux_device_set_io_debug(data->device,
 						gobi_io_debug, "QMI: ");
 
-	r = qmi_qmux_device_discover(data->device, discover_cb, modem, NULL);
-	if (!r)
+	data->set_powered_id =
+		l_rtnl_set_powered(l_rtnl_get(), data->main_net_ifindex,
+					false, init_powered_down_cb,
+					modem, NULL);
+	if (data->set_powered_id)
 		return -EINPROGRESS;
 
-	return r;
+	__shutdown_device(modem);
+	return -EIO;
 }
 
 static void power_disable_cb(struct qmi_result *result, void *user_data)