Open Source Telephony
 help / color / mirror / Atom feed
From: Giacinto Cifelli <gciofono@gmail.com>
To: ofono@ofono.org
Subject: [PATCH v8 4/5] atmodem/atutil: shared functions for cgdcont
Date: Fri, 19 Oct 2018 13:31:40 +0200	[thread overview]
Message-ID: <20181019113141.20734-5-gciofono@gmail.com> (raw)
In-Reply-To: <20181019113141.20734-1-gciofono@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3164 bytes --]

included two new functions:

at_auth_type_from_method: converts the ofono enum ofono_gprs_auth_method
	into the value of the 3GPP 27.007 to pass to the AT command

at_get_cgdcont_command: computes the AT+CGDCONT string, standard version
---
 drivers/atmodem/atutil.c | 49 ++++++++++++++++++++++++++++++++++++++++
 drivers/atmodem/atutil.h |  6 +++++
 2 files changed, 55 insertions(+)

diff --git a/drivers/atmodem/atutil.c b/drivers/atmodem/atutil.c
index 6f4e8a20..ed19e91b 100644
--- a/drivers/atmodem/atutil.c
+++ b/drivers/atmodem/atutil.c
@@ -3,6 +3,7 @@
  *  oFono - Open Source Telephony
  *
  *  Copyright (C) 2008-2011  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2018 Gemalto M2M
  *
  *  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
@@ -27,6 +28,7 @@
 #include <gatchat.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <errno.h>
 
 #define OFONO_API_SUBJECT_TO_CHANGE
@@ -654,3 +656,50 @@ int at_util_get_ipv4_address_and_netmask(const char *addrnetmask,
 
 	return ret;
 }
+
+int at_auth_type_from_method(enum ofono_gprs_auth_method auth_method)
+{
+	switch (auth_method) {
+	case OFONO_GPRS_AUTH_METHOD_PAP:
+		return 1;
+	case OFONO_GPRS_AUTH_METHOD_CHAP:
+		return 2;
+	case OFONO_GPRS_AUTH_METHOD_NONE:
+		return 0;
+	}
+
+	return 0;
+}
+
+char *at_get_cgdcont_command(guint cid, enum ofono_gprs_proto proto,
+							const char *apn)
+{
+	size_t buflen = 32 + OFONO_GPRS_MAX_APN_LENGTH + 1;
+	char *buf = g_new(char, buflen);
+	int len;
+
+	len = snprintf(buf, buflen, "AT+CGDCONT=%u", cid);
+	buflen -= len;
+
+	/*
+	 * if apn is null, it will remove the context.
+	 * but if apn is empty, it will create a context with empty apn
+	 */
+	if (!apn)
+		goto finished;
+
+	switch (proto) {
+	case OFONO_GPRS_PROTO_IPV6:
+		snprintf(buf+len, buflen, ",\"IPV6\",\"%s\"", apn);
+		break;
+	case OFONO_GPRS_PROTO_IPV4V6:
+		snprintf(buf+len, buflen, ",\"IPV4V6\",\"%s\"", apn);
+		break;
+	case OFONO_GPRS_PROTO_IP:
+		snprintf(buf+len, buflen, ",\"IP\",\"%s\"", apn);
+		break;
+	}
+
+finished:
+	return buf;
+}
diff --git a/drivers/atmodem/atutil.h b/drivers/atmodem/atutil.h
index 7113a4cd..447ce56b 100644
--- a/drivers/atmodem/atutil.h
+++ b/drivers/atmodem/atutil.h
@@ -3,6 +3,7 @@
  *  oFono - Open Source Telephony
  *
  *  Copyright (C) 2008-2011  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2018 Gemalto M2M
  *
  *  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
@@ -86,6 +87,11 @@ void at_util_sim_state_query_free(struct at_util_sim_state_query *req);
 int at_util_get_ipv4_address_and_netmask(const char *addrnetmask,
 						char *address, char *netmask);
 
+int at_auth_type_from_method(enum ofono_gprs_auth_method auth_method);
+
+char *at_get_cgdcont_command(guint cid, enum ofono_gprs_proto proto,
+							const char *apn);
+
 struct cb_data {
 	void *cb;
 	void *data;
-- 
2.17.1


  parent reply	other threads:[~2018-10-19 11:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-19 11:31 [PATCH v8 0/5] lte atom auth and IP protocol Giacinto Cifelli
2018-10-19 11:31 ` [PATCH v8 1/5] lte-api: protocol and authentication properties Giacinto Cifelli
2018-10-19 11:31 ` [PATCH v8 2/5] lte.h: added proto and authentication handling Giacinto Cifelli
2018-10-19 11:31 ` [PATCH v8 3/5] lte: protocol and authentication for default ctx Giacinto Cifelli
2018-10-19 11:31 ` Giacinto Cifelli [this message]
2018-10-22 16:56   ` [PATCH v8 4/5] atmodem/atutil: shared functions for cgdcont Denis Kenzior
2018-10-22 17:03     ` Giacinto Cifelli
2018-10-19 11:31 ` [PATCH v8 5/5] atmodem/lte: proto and authentication handling Giacinto Cifelli
2018-10-22 16:48 ` [PATCH v8 0/5] lte atom auth and IP protocol Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181019113141.20734-5-gciofono@gmail.com \
    --to=gciofono@gmail.com \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox