Open Source Telephony
 help / color / mirror / Atom feed
From: Sergey Matyukevich <geomatsi@gmail.com>
To: ofono@ofono.org
Subject: [PATCH v2 2/2] gemalto: gprs: support authentication settings
Date: Sat, 26 Dec 2020 23:56:42 +0300	[thread overview]
Message-ID: <20201226205642.10332-3-geomatsi@gmail.com> (raw)
In-Reply-To: <20201226205642.10332-1-geomatsi@gmail.com>

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

Add support for gprs contexts with username, password,
and specific authentication type.
---
 drivers/gemaltomodem/gprs-context.c | 53 ++++++++++++++++++++++++++++-
 1 file changed, 52 insertions(+), 1 deletion(-)

diff --git a/drivers/gemaltomodem/gprs-context.c b/drivers/gemaltomodem/gprs-context.c
index 99cb4114..c0837bed 100644
--- a/drivers/gemaltomodem/gprs-context.c
+++ b/drivers/gemaltomodem/gprs-context.c
@@ -46,6 +46,9 @@ static const char *none_prefix[] = { NULL };
 struct gprs_context_data {
 	GAtChat *chat;
 	unsigned int active_context;
+	char username[OFONO_GPRS_MAX_USERNAME_LENGTH + 1];
+	char password[OFONO_GPRS_MAX_PASSWORD_LENGTH + 1];
+	int auth_type;
 	enum ofono_gprs_proto proto;
 	ofono_gprs_context_cb_t cb;
 	void *cb_data;
@@ -82,7 +85,7 @@ static void swwan_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	}
 }
 
-static void cgdcont_enable_cb(gboolean ok, GAtResult *result,
+static void sgauth_enable_cb(gboolean ok, GAtResult *result,
 			gpointer user_data)
 {
 	struct ofono_gprs_context *gc = user_data;
@@ -111,6 +114,38 @@ static void cgdcont_enable_cb(gboolean ok, GAtResult *result,
 	CALLBACK_WITH_FAILURE(gcd->cb, gcd->cb_data);
 }
 
+static void cgdcont_enable_cb(gboolean ok, GAtResult *result,
+				gpointer user_data)
+{
+	struct ofono_gprs_context *gc = user_data;
+	struct gprs_context_data *gcd = ofono_gprs_context_get_data(gc);
+	struct ofono_error error;
+	char buf[384];
+
+	DBG("ok %d", ok);
+
+	if (!ok) {
+		gcd->active_context = 0;
+		decode_at_error(&error, g_at_result_final_response(result));
+		gcd->cb(&error, gcd->cb_data);
+		return;
+	}
+
+	if (gcd->username[0] && gcd->password[0])
+		sprintf(buf, "AT^SGAUTH=%u,%u,\"%s\",\"%s\"",
+			gcd->active_context, gcd->auth_type,
+			gcd->username, gcd->password);
+	else
+		sprintf(buf, "AT^SGAUTH=%u,%u,\"\",\"\"",
+			gcd->active_context, gcd->auth_type);
+
+	if (g_at_chat_send(gcd->chat, buf, none_prefix,
+				sgauth_enable_cb, gc, NULL) > 0)
+		return;
+
+	CALLBACK_WITH_FAILURE(gcd->cb, gcd->cb_data);
+}
+
 static void gemalto_gprs_activate_primary(struct ofono_gprs_context *gc,
 				const struct ofono_gprs_primary_context *ctx,
 				ofono_gprs_context_cb_t cb, void *data)
@@ -125,6 +160,22 @@ static void gemalto_gprs_activate_primary(struct ofono_gprs_context *gc,
 	gcd->cb_data = data;
 	gcd->cb = cb;
 
+	memcpy(gcd->username, ctx->username, sizeof(ctx->username));
+	memcpy(gcd->password, ctx->password, sizeof(ctx->password));
+	gcd->proto = ctx->proto;
+
+	switch (ctx->auth_method) {
+	case OFONO_GPRS_AUTH_METHOD_PAP:
+		gcd->auth_type = 1;
+		break;
+	case OFONO_GPRS_AUTH_METHOD_CHAP:
+		gcd->auth_type = 2;
+		break;
+	case OFONO_GPRS_AUTH_METHOD_NONE:
+	default:
+		gcd->auth_type = 0;
+		break;
+	}
 
 	switch (ctx->proto) {
 	case OFONO_GPRS_PROTO_IP:
-- 
2.29.2

  parent reply	other threads:[~2020-12-26 20:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-26 20:56 [PATCH v2 0/2] gemalto: gprs context driver updates Sergey Matyukevich
2020-12-26 20:56 ` [PATCH v2 1/2] gemalto: gprs: support automatic context activation Sergey Matyukevich
2020-12-26 20:56 ` Sergey Matyukevich [this message]
2020-12-30 16:57 ` [PATCH v2 0/2] gemalto: gprs context driver updates 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=20201226205642.10332-3-geomatsi@gmail.com \
    --to=geomatsi@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