diff mbox series

[v2,6/8] qmi: gprs-context: Split out IPv4 setting processing

Message ID 20240506215804.57124-6-denkenz@gmail.com (mailing list archive)
State Accepted
Commit cfd311c6e5845b7b16facb2cb18f69d97033f313
Headers show
Series [v2,1/8] qmi: wds: Fix up enum naming | expand

Commit Message

Denis Kenzior May 6, 2024, 9:58 p.m. UTC
Prepare to support IPv6 bearers by moving IPv4 bearer context processing
into its own function.  get_settings_ipv4() will be called if the
reported IP Family TLV reports ipv4.
---
 drivers/qmimodem/gprs-context.c | 69 ++++++++++++++++++++-------------
 1 file changed, 43 insertions(+), 26 deletions(-)
diff mbox series

Patch

diff --git a/drivers/qmimodem/gprs-context.c b/drivers/qmimodem/gprs-context.c
index 9ac57c893725..99d42e7b5e1f 100644
--- a/drivers/qmimodem/gprs-context.c
+++ b/drivers/qmimodem/gprs-context.c
@@ -78,44 +78,20 @@  static void pkt_status_notify(struct qmi_result *result, void *user_data)
 	}
 }
 
-static void get_settings_cb(struct qmi_result *result, void *user_data)
+static void get_settings_ipv4(struct ofono_gprs_context *gc,
+					struct qmi_result *result)
 {
-	static const uint8_t RESULT_PDP_TYPE = 0x11;	/* uint8 */
-	static const uint8_t RESULT_APN = 0x14;		/* string */
 	static const uint8_t RESULT_PRIMARY_DNS = 0x15;
 	static const uint8_t RESULT_SECONDARY_DNS = 0x16;
 	static const uint8_t RESULT_IP_ADDRESS = 0x1e;
 	static const uint8_t RESULT_GATEWAY = 0x20;
 	static const uint8_t RESULT_GATEWAY_NETMASK = 0x21;
-	static const uint8_t RESULT_IP_FAMILY = 0x2b;	/* uint8 */
-	struct cb_data *cbd = user_data;
-	ofono_gprs_context_cb_t cb = cbd->cb;
-	struct ofono_gprs_context *gc = cbd->user;
-	uint8_t pdp_type, ip_family;
 	uint32_t ip_addr;
 	struct in_addr addr;
 	char* straddr;
-	char* apn;
 	const char *dns[3] = { NULL, NULL, NULL };
 	char dns_buf[2][INET_ADDRSTRLEN];
 
-	DBG("");
-
-	if (qmi_result_set_error(result, NULL))
-		goto done;
-
-	apn = qmi_result_get_string(result, RESULT_APN);
-	if (apn) {
-		DBG("APN: %s", apn);
-		l_free(apn);
-	}
-
-	if (qmi_result_get_uint8(result, RESULT_PDP_TYPE, &pdp_type))
-		DBG("PDP type %d", pdp_type);
-
-	if (qmi_result_get_uint8(result, RESULT_IP_FAMILY, &ip_family))
-		DBG("IP family %d", ip_family);
-
 	if (qmi_result_get_uint32(result, RESULT_IP_ADDRESS, &ip_addr)) {
 		addr.s_addr = htonl(ip_addr);
 		straddr = inet_ntoa(addr);
@@ -151,6 +127,47 @@  static void get_settings_cb(struct qmi_result *result, void *user_data)
 
 	if (dns[0])
 		ofono_gprs_context_set_ipv4_dns_servers(gc, dns);
+}
+
+static void get_settings_cb(struct qmi_result *result, void *user_data)
+{
+	static const uint8_t RESULT_PDP_TYPE = 0x11;	/* uint8 */
+	static const uint8_t RESULT_APN = 0x14;		/* string */
+	static const uint8_t RESULT_IP_FAMILY = 0x2b;	/* uint8 */
+	struct cb_data *cbd = user_data;
+	ofono_gprs_context_cb_t cb = cbd->cb;
+	struct ofono_gprs_context *gc = cbd->user;
+	uint8_t pdp_type, ip_family;
+	char* apn;
+
+	DBG("");
+
+	if (qmi_result_set_error(result, NULL))
+		goto done;
+
+	apn = qmi_result_get_string(result, RESULT_APN);
+	if (apn) {
+		DBG("APN: %s", apn);
+		l_free(apn);
+	}
+
+	if (qmi_result_get_uint8(result, RESULT_PDP_TYPE, &pdp_type))
+		DBG("PDP type %d", pdp_type);
+
+	if (!qmi_result_get_uint8(result, RESULT_IP_FAMILY, &ip_family)) {
+		ofono_error("No IP family in results");
+		goto done;
+	}
+
+	switch (ip_family) {
+	case QMI_WDS_IP_FAMILY_IPV4:
+		get_settings_ipv4(gc, result);
+		break;
+	case QMI_WDS_IP_FAMILY_IPV6:
+		break;
+	default:
+		break;
+	}
 
 done:
 	CALLBACK_WITH_SUCCESS(cb, cbd->data);