Skip to contentSkip to conversation

gsmdial: adding support for selection of authentication method

PATCH In review [email protected] 2 participants 6 messages Jan 7, 2021 – Jan 8, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 gsmdial: adding support for selection of authentication method

From: Sergei Golubtsov <[email protected]>

Selection capability for authentication method via a command line argument has been added

---
 gatchat/gsmdial.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
gatchat/gsmdial.c +16 -0
index 60e4f245..23f9c2d9 100644
@@ -53,6 +53,7 @@ static gint option_cid = 0;
 static gchar *option_apn = NULL;
 static gint option_offmode = 0;
 static gboolean option_legacy = FALSE;
+static gchar *option_auth_method;
 static gchar *option_username = NULL;
 static gchar *option_password = NULL;
 static gchar *option_pppdump = NULL;
@@ -369,6 +370,17 @@ static void connect_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	}
 	g_at_ppp_set_debug(ppp, gsmdial_debug, "PPP");
 
+	GAtPPPAuthMethod auth_method;
+
+	if (strcmp(option_auth_method, "PAP") == 0)
+		auth_method = G_AT_PPP_AUTH_METHOD_PAP;
+	else if (strcmp(option_auth_method, "NONE") == 0)
+		auth_method = G_AT_PPP_AUTH_METHOD_NONE;
+	else
+		auth_method = G_AT_PPP_AUTH_METHOD_CHAP;
+
+	g_at_ppp_set_auth_method(ppp, auth_method);
+
 	g_at_ppp_set_credentials(ppp, option_username, option_password);
 
 	g_at_ppp_set_acfc_enabled(ppp, option_acfc);
@@ -677,6 +689,10 @@ static GOptionEntry options[] = {
 				"Use ATD*99***<cid>#" },
 	{ "bluetooth", 'b', 0, G_OPTION_ARG_NONE, &option_bluetooth,
 				"Use only ATD*99" },
+	{ "auth", 'A', 0, G_OPTION_ARG_STRING, &option_auth_method,
+				"Specify the authentication method for the PPP"
+				" connection: CHAP, PAP or NONE. CHAP is used"
+				" by default." },
 	{ "username", 'u', 0, G_OPTION_ARG_STRING, &option_username,
 				"Specify PPP username" },
 	{ "password", 'w', 0, G_OPTION_ARG_STRING, &option_password,
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/1 ppp: using RX ACCM = 0 by default

From: Sergei Golubtsov <[email protected]>

Some modems such as Quectel EC200T do not honor the default value for the Async-Control-Character-Map (ACCM) configuration option defined in RFC 1548 6.2 as 0xffffffff. This patch suggests to use RX ACCM = 0 for Ofono by default as pppd does for instance. This will reduce PPP data overhead as well.

---
 gatchat/gatppp.c  |  5 +++++
 gatchat/gatppp.h  |  1 +
 gatchat/ppp.h     |  1 +
 gatchat/ppp_lcp.c | 15 ++++++++++++++-
 4 files changed, 21 insertions(+), 1 deletion(-)
gatchat/gatppp.c +5 -0
index 141e2746..259e6d5c 100644
@@ -806,6 +806,11 @@ void g_at_ppp_set_server_info(GAtPPP *ppp, const char *remote,
 	ipcp_set_server_info(ppp->ipcp, r, d1, d2);
 }
 
+void g_at_ppp_set_accm(GAtPPP *ppp, guint32 accm)
+{
+	lcp_set_accm(ppp->lcp, accm);
+}
+
 void g_at_ppp_set_acfc_enabled(GAtPPP *ppp, gboolean enabled)
 {
 	lcp_set_acfc_enabled(ppp->lcp, enabled);
gatchat/gatppp.h +1 -0
index dd203c28..a12e42e3 100644
@@ -88,6 +88,7 @@ void g_at_ppp_set_recording(GAtPPP *ppp, const char *filename);
 void g_at_ppp_set_server_info(GAtPPP *ppp, const char *remote_ip,
 				const char *dns1, const char *dns2);
 
+void g_at_ppp_set_accm(GAtPPP *ppp, guint32 accm);
 void g_at_ppp_set_acfc_enabled(GAtPPP *ppp, gboolean enabled);
 void g_at_ppp_set_pfc_enabled(GAtPPP *ppp, gboolean enabled);
 
gatchat/ppp.h +1 -0
index ac1a7ef2..6c02b053 100644
@@ -90,6 +90,7 @@ static inline void __put_unaligned_short(void *p, guint16 val)
 struct pppcp_data *lcp_new(GAtPPP *ppp, gboolean dormant);
 void lcp_free(struct pppcp_data *lcp);
 void lcp_protocol_reject(struct pppcp_data *lcp, guint8 *packet, gsize len);
+void lcp_set_accm(struct pppcp_data *pppcp, guint32 accm);
 void lcp_set_acfc_enabled(struct pppcp_data *pppcp, gboolean enabled);
 void lcp_set_pfc_enabled(struct pppcp_data *pppcp, gboolean enabled);
 
gatchat/ppp_lcp.c +14 -1
index 3fe38217..7c45a27f 100644
@@ -121,7 +121,9 @@ static void lcp_generate_config_options(struct lcp_data *lcp)
 
 static void lcp_reset_config_options(struct lcp_data *lcp)
 {
-	/* Using the default ACCM */
+	/* Using RX ACCM = 0 instead of the default ACCM */
+	lcp->accm = 0;
+	lcp->req_options |= REQ_OPTION_ACCM;
 
 	lcp_generate_config_options(lcp);
 }
@@ -398,6 +400,17 @@ struct pppcp_data *lcp_new(GAtPPP *ppp, gboolean is_server)
 	return pppcp;
 }
 
+void lcp_set_accm(struct pppcp_data *pppcp, guint32 accm)
+{
+	struct lcp_data *lcp = pppcp_get_data(pppcp);
+
+	lcp->accm = accm;
+	lcp->req_options |= REQ_OPTION_ACCM;
+
+	lcp_generate_config_options(lcp);
+	pppcp_set_local_options(pppcp, lcp->options, lcp->options_len);
+}
+
 void lcp_set_acfc_enabled(struct pppcp_data *pppcp, gboolean enabled)
 {
 	struct lcp_data *lcp = pppcp_get_data(pppcp);
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH v2] ppp: using RX ACCM = 0 by default

Hi Sergei,

Quoted 7 lines · s.e.golubtsov(a)gmail.com

From: Sergei Golubtsov <[email protected]>

Some modems such as Quectel EC200T do not honor the default value for the Async-Control-Character-Map (ACCM) configuration option defined in RFC 1548 6.2 as 0xffffffff. This patch suggests to use RX ACCM = 0 for Ofono by default as pppd does for instance. This will reduce PPP data overhead as well.

Quoted 7 lines
---
  gatchat/gatppp.c  |  5 +++++
  gatchat/gatppp.h  |  1 +
  gatchat/ppp.h     |  1 +
  gatchat/ppp_lcp.c | 15 ++++++++++++++-
  4 files changed, 21 insertions(+), 1 deletion(-)

Applied, thanks.

Regards,
-Denis

#3 lore raw

PATCH v2 1/1 quectel: adding support for the Quectel EC200 USB modem series

In reply to [email protected]

From: Sergei Golubtsov <[email protected]>

Support for the Quectel EC200 USB modem series has been added. The model identification AT command has been added as the first step in the communication with a Quectel USB modem.

---
 plugins/quectel.c | 128 +++++++++++++++++++++++++++++-----------------
 plugins/udevng.c  |   6 ++-
 2 files changed, 85 insertions(+), 49 deletions(-)
plugins/quectel.c +81 -47
index 82fc688d..950f7ce6 100644
@@ -64,7 +64,7 @@ static const char *cpin_prefix[] = { "+CPIN:", NULL };
 static const char *cbc_prefix[] = { "+CBC:", NULL };
 static const char *qinistat_prefix[] = { "+QINISTAT:", NULL };
 static const char *cgmm_prefix[] = { "UC15", "Quectel_M95", "Quectel_MC60",
-					"EC21", NULL };
+					"EC21", "EC200", NULL };
 static const char *none_prefix[] = { NULL };
 
 static const uint8_t gsm0710_terminate[] = {
@@ -84,6 +84,7 @@ enum quectel_model {
 	QUECTEL_M95,
 	QUECTEL_MC60,
 	QUECTEL_EC21,
+	QUECTEL_EC200,
 };
 
 struct quectel_data {
@@ -127,6 +128,15 @@ enum quectel_power_event {
 
 static const char dbus_hw_interface[] = OFONO_SERVICE ".quectel.Hardware";
 
+static ofono_bool_t has_serial_connection(struct ofono_modem *modem)
+{
+
+	if (ofono_modem_get_string(modem, "Device"))
+		return TRUE;
+
+	return FALSE;
+}
+
 static void quectel_debug(const char *str, void *user_data)
 {
 	const char *prefix = user_data;
@@ -543,6 +553,7 @@ static void dbus_hw_enable(struct ofono_modem *modem)
 	switch (data->model) {
 	case QUECTEL_UC15:
 	case QUECTEL_EC21:
+	case QUECTEL_EC200:
 		g_at_chat_register(data->aux, "+QIND",  qind_notify, FALSE, hw,
 					NULL);
 		break;
@@ -591,6 +602,13 @@ static void qinistat_cb(gboolean ok, GAtResult *result, gpointer user_data)
 		/* UC15 uses a bitmap of 1 + 2 + 4 = 7 */
 		ready = 7;
 		break;
+	case QUECTEL_EC200:
+		/*
+		 * EC200T doesn't indicate that the Phonebook initialization
+		 * is completed (==4) when AT+CFUN=4, that's why 1 + 2 = 3
+		 */
+		ready = 3;
+		break;
 	case QUECTEL_M95:
 	case QUECTEL_MC60:
 		/* M95 and MC60 uses a counter to 3 */
@@ -807,6 +825,9 @@ static void setup_aux(struct ofono_modem *modem)
 				NULL, NULL, NULL);
 		g_at_chat_send(data->aux, "AT+QURCCFG=\"urcport\",\"uart1\"", none_prefix,
 				NULL, NULL, NULL);
+	} else if (data->model == QUECTEL_EC200) {
+		g_at_chat_send(data->aux, "ATE0; &C0; +CMEE=1", none_prefix,
+				NULL, NULL, NULL);
 	} else
 		g_at_chat_send(data->aux, "ATE0; &C0; +CMEE=1; +QIURC=0",
 				none_prefix, NULL, NULL, NULL);
@@ -815,6 +836,59 @@ static void setup_aux(struct ofono_modem *modem)
 			NULL);
 }
 
+static void cgmm_cb(int ok, GAtResult *result, void *user_data)
+{
+	struct ofono_modem *modem = user_data;
+	struct quectel_data *data = ofono_modem_get_data(modem);
+	const char *model;
+
+	DBG("%p ok %d", modem, ok);
+
+	if (!at_util_parse_attr(result, "", &model)) {
+		ofono_error("Failed to query modem model");
+		close_serial(modem);
+		return;
+	}
+
+	if (strcmp(model, "UC15") == 0) {
+		DBG("%p model UC15", modem);
+		data->vendor = OFONO_VENDOR_QUECTEL;
+		data->model = QUECTEL_UC15;
+	} else if (strcmp(model, "Quectel_M95") == 0) {
+		DBG("%p model M95", modem);
+		data->vendor = OFONO_VENDOR_QUECTEL_SERIAL;
+		data->model = QUECTEL_M95;
+	} else if (strcmp(model, "Quectel_MC60") == 0) {
+		DBG("%p model MC60", modem);
+		data->vendor = OFONO_VENDOR_QUECTEL_SERIAL;
+		data->model = QUECTEL_MC60;
+	} else if (strcmp(model, "EC21") == 0) {
+		DBG("%p model EC21", modem);
+		data->vendor = OFONO_VENDOR_QUECTEL_EC2X;
+		data->model = QUECTEL_EC21;
+	} else if (strstr(model, "EC200")) {
+		DBG("%p model %s", modem, model);
+		data->vendor = OFONO_VENDOR_QUECTEL_EC2X;
+		data->model = QUECTEL_EC200;
+	} else {
+		ofono_warn("%p unknown model: '%s'", modem, model);
+		data->vendor = OFONO_VENDOR_QUECTEL;
+		data->model = QUECTEL_UNKNOWN;
+	}
+
+	setup_aux(modem);
+}
+
+static void identify_model(struct ofono_modem *modem)
+{
+	struct quectel_data *data = ofono_modem_get_data(modem);
+
+	DBG("%p", modem);
+
+	g_at_chat_send(data->aux, "AT+CGMM", cgmm_prefix, cgmm_cb, modem,
+			NULL);
+}
+
 static int open_ttys(struct ofono_modem *modem)
 {
 	struct quectel_data *data = ofono_modem_get_data(modem);
@@ -834,7 +908,7 @@ static int open_ttys(struct ofono_modem *modem)
 		return -EIO;
 	}
 
-	setup_aux(modem);
+	identify_model(modem);
 
 	return -EINPROGRESS;
 }
@@ -898,7 +972,7 @@ static void cmux_gatmux(struct ofono_modem *modem)
 		return;
 	}
 
-	setup_aux(modem);
+	identify_model(modem);
 }
 
 static void mux_ready_cb(struct l_timeout *timeout, void *user_data)
@@ -1031,46 +1105,6 @@ static void cmux_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	close_serial(modem);
 }
 
-static void cgmm_cb(int ok, GAtResult *result, void *user_data)
-{
-	struct ofono_modem *modem = user_data;
-	struct quectel_data *data = ofono_modem_get_data(modem);
-	const char *model;
-
-	DBG("%p ok %d", modem, ok);
-
-	if (!at_util_parse_attr(result, "", &model)) {
-		ofono_error("Failed to query modem model");
-		close_serial(modem);
-		return;
-	}
-
-	if (strcmp(model, "UC15") == 0) {
-		DBG("%p model UC15", modem);
-		data->vendor = OFONO_VENDOR_QUECTEL;
-		data->model = QUECTEL_UC15;
-	} else if (strcmp(model, "Quectel_M95") == 0) {
-		DBG("%p model M95", modem);
-		data->vendor = OFONO_VENDOR_QUECTEL_SERIAL;
-		data->model = QUECTEL_M95;
-	} else if (strcmp(model, "Quectel_MC60") == 0) {
-		DBG("%p model MC60", modem);
-		data->vendor = OFONO_VENDOR_QUECTEL_SERIAL;
-		data->model = QUECTEL_MC60;
-	} else if (strcmp(model, "EC21") == 0) {
-		DBG("%p model EC21", modem);
-		data->vendor = OFONO_VENDOR_QUECTEL_EC2X;
-		data->model = QUECTEL_EC21;
-	} else {
-		ofono_warn("%p unknown model: '%s'", modem, model);
-		data->vendor = OFONO_VENDOR_QUECTEL;
-		data->model = QUECTEL_UNKNOWN;
-	}
-
-	g_at_chat_send(data->uart, "AT+CMUX=0,0,5,127,10,3,30,10,2", NULL,
-			cmux_cb, modem, NULL);
-}
-
 static void ate_cb(int ok, GAtResult *result, void *user_data)
 {
 	struct ofono_modem *modem = user_data;
@@ -1078,8 +1112,8 @@ static void ate_cb(int ok, GAtResult *result, void *user_data)
 
 	DBG("%p", modem);
 
-	g_at_chat_send(data->uart, "AT+CGMM", cgmm_prefix, cgmm_cb, modem,
-			NULL);
+	g_at_chat_send(data->uart, "AT+CMUX=0,0,5,127,10,3,30,10,2", NULL,
+		cmux_cb, modem, NULL);
 }
 
 static void init_cmd_cb(gboolean ok, GAtResult *result, void *user_data)
@@ -1211,7 +1245,7 @@ static int quectel_enable(struct ofono_modem *modem)
 {
 	DBG("%p", modem);
 
-	if (ofono_modem_get_string(modem, "Device"))
+	if (has_serial_connection(modem))
 		return open_serial(modem);
 	else
 		return open_ttys(modem);
@@ -1315,7 +1349,7 @@ static void quectel_post_sim(struct ofono_modem *modem)
 	ofono_phonebook_create(modem, data->vendor, "atmodem", data->aux);
 	ofono_call_volume_create(modem, data->vendor, "atmodem", data->aux);
 
-	if (data->model == QUECTEL_EC21) {
+	if (data->model == QUECTEL_EC21 || data->model == QUECTEL_EC200) {
 		ofono_ussd_create(modem, data->vendor, "atmodem", data->aux);
 		ofono_lte_create(modem, data->vendor, "atmodem", data->aux);
 	}
plugins/udevng.c +4 -2
index 3458fe89..34ac1cc0 100644
@@ -941,10 +941,12 @@ static gboolean setup_quectel_serial(struct modem_info *modem)
 
 static gboolean setup_quectel(struct modem_info *modem)
 {
-	if (modem->serial)
+	if (modem->type == MODEM_TYPE_SERIAL)
 		return setup_quectel_serial(modem);
-	else
+	else if (modem->type == MODEM_TYPE_USB)
 		return setup_quectel_usb(modem);
+	else
+		return FALSE;
 }
 
 static gboolean setup_quectelqmi(struct modem_info *modem)
Signature · 1 line
2.17.1
#4 lore raw

Re: [PATCH v2] quectel: adding support for the Quectel EC200 USB modem series

Hi Sergei,

Quoted 10 lines · s.e.golubtsov(a)gmail.com

From: Sergei Golubtsov <[email protected]>

Support for the Quectel EC200 USB modem series has been added. The model identification AT command has been added as the first step in the communication with a Quectel USB modem.

---
  plugins/quectel.c | 128 +++++++++++++++++++++++++++++-----------------
  plugins/udevng.c  |   6 ++-
  2 files changed, 85 insertions(+), 49 deletions(-)

Applied, thanks.

Regards,
-Denis

#5 lore raw
In reply to [email protected]

Hi Sergei,

Quoted 8 lines · s.e.golubtsov(a)gmail.com

From: Sergei Golubtsov <[email protected]>

Selection capability for authentication method via a command line argument has been added

---
  gatchat/gsmdial.c | 16 ++++++++++++++++
  1 file changed, 16 insertions(+)

<snip>

gatchat/gsmdial.c static void connect_cb(gboolean ok, GAtResult *result, gpointer user_data) · line 375

Quoted 7 lines
gatchat/gsmdial.c +3 -0
@@ -369,6 +370,17 @@ static void connect_cb(gboolean ok, GAtResult *result, gpointer user_data)
  	}
  	g_at_ppp_set_debug(ppp, gsmdial_debug, "PPP");
 
+	GAtPPPAuthMethod auth_method;
+
+	if (strcmp(option_auth_method, "PAP") == 0)

note that option_auth_method might be NULL and since you're using strcmp, passing NULL might result in undefined behavior.

gatchat/gsmdial.c static void connect_cb(gboolean ok, GAtResult *result, gpointer user_data) · line 386

Quoted 11 lines
gatchat/gsmdial.c +8 -0
+		auth_method = G_AT_PPP_AUTH_METHOD_PAP;
+	else if (strcmp(option_auth_method, "NONE") == 0)
+		auth_method = G_AT_PPP_AUTH_METHOD_NONE;
+	else
+		auth_method = G_AT_PPP_AUTH_METHOD_CHAP;
+
+	g_at_ppp_set_auth_method(ppp, auth_method);
+
  	g_at_ppp_set_credentials(ppp, option_username, option_password);
 
  	g_at_ppp_set_acfc_enabled(ppp, option_acfc);

Note that I still get the following compiler error:

denkenz(a)localhost ~/ofono-master $ make
make --no-print-directory all-am
CC gatchat/gsmdial.o
gatchat/gsmdial.c: In function ‘connect_cb’:
gatchat/gsmdial.c:373:2: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]

   373 |  GAtPPPAuthMethod auth_method;
       |  ^~~~~~~~~~~~~~~~

oFono code must compile with gnu89 dialect of GCC, so all variable declarations must be in the appropriate block. Please make sure you compile test with optimization enabled in order for gcc to catch any errors/warnings.

I went ahead and modified the patch slightly and applied it to take care of this.

Regards,
-Denis