Skip to contentSkip to conversation

quectel: add support of Quectel EC200 USB modem

PATCH In review [email protected] 2 participants 2 messages Jan 1, 2021 – Jan 4, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 quectel: add support of Quectel EC200 USB modem

From: Sergei Golubtsov <[email protected]>

Support of 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 modem.

---
 plugins/quectel.c | 49 +++++++++++++++++++++++++++++++++++++++++++----
 plugins/udevng.c  |  6 ++++--
 2 files changed, 49 insertions(+), 6 deletions(-)
plugins/quectel.c +45 -4
index 82fc688d..d77fbe60 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 void cgmm_cb(int ok, GAtResult *result, void *user_data);
+
+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 */
@@ -794,6 +812,18 @@ static void cfun_query(gboolean ok, GAtResult *result, gpointer user_data)
 		cfun_enable(TRUE, NULL, modem);
 }
 
+static void identify_model(struct ofono_modem *modem)
+{
+	struct quectel_data *data = ofono_modem_get_data(modem);
+
+	DBG("%p", modem);
+
+	g_at_chat_set_slave(data->modem, data->aux);
+
+	g_at_chat_send(data->aux, "AT+CGMM", cgmm_prefix, cgmm_cb, modem,
+			NULL);
+}
+
 static void setup_aux(struct ofono_modem *modem)
 {
 	struct quectel_data *data = ofono_modem_get_data(modem);
@@ -807,6 +837,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);
@@ -834,7 +867,7 @@ static int open_ttys(struct ofono_modem *modem)
 		return -EIO;
 	}
 
-	setup_aux(modem);
+	identify_model(modem);
 
 	return -EINPROGRESS;
 }
@@ -1061,14 +1094,22 @@ static void cgmm_cb(int ok, GAtResult *result, void *user_data)
 		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;
 	}
 
-	g_at_chat_send(data->uart, "AT+CMUX=0,0,5,127,10,3,30,10,2", NULL,
+	if (has_serial_connection(modem)) {
+		g_at_chat_send(data->uart, "AT+CMUX=0,0,5,127,10,3,30,10,2", NULL,
 			cmux_cb, modem, NULL);
+	} else {
+		setup_aux(modem);
+	}
 }
 
 static void ate_cb(int ok, GAtResult *result, void *user_data)
@@ -1315,7 +1356,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
#1 lore raw

Hi Sergei,

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

From: Sergei Golubtsov <[email protected]>

Support of 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 modem.

---
  plugins/quectel.c | 49 +++++++++++++++++++++++++++++++++++++++++++----
  plugins/udevng.c  |  6 ++++--
  2 files changed, 49 insertions(+), 6 deletions(-)
plugins/quectel.c +2 -1
index 82fc688d..d77fbe60 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 {

plugins/quectel.c enum quectel_power_event { · line 131

Quoted 4 lines
plugins/quectel.c +1 -0
@@ -127,6 +128,15 @@ enum quectel_power_event {
 
  static const char dbus_hw_interface[] = OFONO_SERVICE ".quectel.Hardware";
 
+static void cgmm_cb(int ok, GAtResult *result, void *user_data);

Please see doc/coding-style.txt item M17

plugins/quectel.c enum quectel_power_event { · line 137

Quoted 6 lines
plugins/quectel.c +6 -0
+
+static ofono_bool_t has_serial_connection(struct ofono_modem *modem)
+{
+	if (ofono_modem_get_string(modem, "Device"))
+		return TRUE;
+	return FALSE;

doc/coding-style.txt item M1

Quoted 28 lines
plugins/quectel.c +10 -0
+}
+
  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 */

plugins/quectel.c static void cfun_query(gboolean ok, GAtResult *result, gpointer user_data) · line 821

Quoted 10 lines
plugins/quectel.c +7 -0
@@ -794,6 +812,18 @@ static void cfun_query(gboolean ok, GAtResult *result, gpointer user_data)
  		cfun_enable(TRUE, NULL, modem);
  }
 
+static void identify_model(struct ofono_modem *modem)
+{
+	struct quectel_data *data = ofono_modem_get_data(modem);
+
+	DBG("%p", modem);
+
+	g_at_chat_set_slave(data->modem, data->aux);

Why do you need this here? This really belongs in open_ttys as opposed to setup_aux or here.

Quoted 19 lines
plugins/quectel.c +8 -0
+
+	g_at_chat_send(data->aux, "AT+CGMM", cgmm_prefix, cgmm_cb, modem,
+			NULL);
+}
+
  static void setup_aux(struct ofono_modem *modem)
  {
  	struct quectel_data *data = ofono_modem_get_data(modem);
@@ -807,6 +837,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);

plugins/quectel.c static int open_ttys(struct ofono_modem *modem) · line 870

Quoted 5 lines
plugins/quectel.c +1 -1
@@ -834,7 +867,7 @@ static int open_ttys(struct ofono_modem *modem)
  		return -EIO;
  	}
 
-	setup_aux(modem);
+	identify_model(modem);

This results in Serial versions of Quectel modems issuing CGMM twice. The logic also becomes very hard to follow.

Perhaps CGMM needs to be issued once after open_ttys (like you're doing for USB variants) for both Serial and USB versions.

Quoted 46 lines
plugins/quectel.c +10 -2
  	return -EINPROGRESS;
  }
@@ -1061,14 +1094,22 @@ static void cgmm_cb(int ok, GAtResult *result, void *user_data)
  		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;
  	}
 
-	g_at_chat_send(data->uart, "AT+CMUX=0,0,5,127,10,3,30,10,2", NULL,
+	if (has_serial_connection(modem)) {
+		g_at_chat_send(data->uart, "AT+CMUX=0,0,5,127,10,3,30,10,2", NULL,
  			cmux_cb, modem, NULL);
+	} else {
+		setup_aux(modem);
+	}
  }
 
  static void ate_cb(int ok, GAtResult *result, void *user_data)
@@ -1315,7 +1356,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 +0 -1
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)

plugins/udevng.c static gboolean setup_quectel_serial(struct modem_info *modem) · line 952

Quoted 10 lines
plugins/udevng.c +4 -1
+	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)

Regards,
-Denis