From 0d9a380ea0b0911dc85488a11cd895ad29f7f809 Mon Sep 17 00:00:00 2001 From: Giacinto Cifelli Date: Mon, 22 Oct 2018 20:56:08 +0200 Subject: [PATCH] atmodem: Add at_util_get_cgdcont_command The function at_util_get_cgdcont_command computes the AT+CGDCONT string, as per 3GPP 27.007. It uses a second function, at_util_gprs_proto_to_pdp_type, that returns the pdp_type string for the command --- drivers/atmodem/atutil.c | 27 +++++++++++++++++++++++++++ drivers/atmodem/atutil.h | 13 +++++++++++++ 2 files changed, 40 insertions(+) diff --git a/drivers/atmodem/atutil.c b/drivers/atmodem/atutil.c index 661ba205..98e3a2f8 100644 --- a/drivers/atmodem/atutil.c +++ b/drivers/atmodem/atutil.c @@ -670,3 +670,30 @@ int at_util_gprs_auth_method_to_auth_prot( return 0; } + +const char *at_util_gprs_proto_to_pdp_type(enum ofono_gprs_proto proto) +{ + switch (proto) { + case OFONO_GPRS_PROTO_IPV6: + return "IPV6"; + case OFONO_GPRS_PROTO_IPV4V6: + return "IPV4V6"; + break; + case OFONO_GPRS_PROTO_IP: + return "IP"; + } + + return NULL; +} + +char *at_util_get_cgdcont_command(guint cid, enum ofono_gprs_proto proto, + const char *apn) +{ + const char *pdp_type = at_util_gprs_proto_to_pdp_type(proto); + + if (!apn) + return g_strdup_printf("AT+CGDCONT=%u", cid); + + return g_strdup_printf("AT+CGDCONT=%u,\"%s\",\"%s\"", cid, pdp_type, + apn); +} diff --git a/drivers/atmodem/atutil.h b/drivers/atmodem/atutil.h index aa6b8d4d..f1389a94 100644 --- a/drivers/atmodem/atutil.h +++ b/drivers/atmodem/atutil.h @@ -90,6 +90,19 @@ int at_util_get_ipv4_address_and_netmask(const char *addrnetmask, int at_util_gprs_auth_method_to_auth_prot( enum ofono_gprs_auth_method auth_method); +const char *at_util_gprs_proto_to_pdp_type(enum ofono_gprs_proto proto); + +/* + * at_util_get_cgdcont_command + * if the apn pointer is NULL, the context will be removed: the resulting + * string will be like: AT+CGDCONT=7 + * but if apn pointer is not NULL and the string is empty, then + * this function will create a normal context with empty apn, like: + * AT+CGDCONT=4,"IPV6","" + */ +char *at_util_get_cgdcont_command(guint cid, enum ofono_gprs_proto proto, + const char *apn); + struct cb_data { void *cb; void *data;