Skip to contentSkip to conversation

Provider name and SID

PATCH In review Philippe Nunes 2 participants 8 messages Jan 18, 2012 Kbuild

lore
Share & tools
lore
#0 lore raw

v4 cover Provider name and SID

This version introduces a QCDM helper library.
Also, to simplify the QCDM handling, a dedicated callback is set for each command sent.
Currently, we are not considering that a new command can be issued before the answer from the previous command is handled. If this case occurs, then we would need to introduce a command queue in the GAtHDLC structure to be able to invoke properly the callbacks.

Philippe.

Philippe Nunes (6):
gatchat: Add g_at_chat_set_slave_qcdm / g_at_chat_get_slave_qcdm
huawei: Open qcdm port to fetch network status & SID
gatqcdm: Add helper functions for QCDM handling
huaweimodem: Probe the QCDM port with the version info request
huaweimodem: Add 'serving_system' entry point to get SID
udevng: Add a default assignment for Huawei QCDM port

 Makefile.am                       |    1 +
 drivers/huaweimodem/cdma-netreg.c |  174 ++++++++++++++++++++++++++++++++++---
 gatchat/gatchat.c                 |   26 ++++++
 gatchat/gatchat.h                 |    4 +
 gatchat/gatqcdm.c                 |   84 ++++++++++++++++++
 gatchat/gatqcdm.h                 |   57 ++++++++++++
 plugins/huawei.c                  |   44 +++++++++
 plugins/udevng.c                  |   30 +++++--
 8 files changed, 400 insertions(+), 20 deletions(-)
 create mode 100644 gatchat/gatqcdm.c
 create mode 100644 gatchat/gatqcdm.h
#1 lore raw

PATCH v4 1/6 gatchat: Add g_at_chat_set_slave_qcdm / g_at_chat_get_slave_qcdm

---
 gatchat/gatchat.c |   26 ++++++++++++++++++++++++++
 gatchat/gatchat.h |    4 ++++
 2 files changed, 30 insertions(+), 0 deletions(-)
gatchat/gatchat.c +26 -0
index 7a0ef35..2fde572 100644
@@ -35,6 +35,7 @@
 #include "ringbuffer.h"
 #include "gatchat.h"
 #include "gatio.h"
+#include "gathdlc.h"
 
 /* #define WRITE_SCHEDULER_DEBUG 1 */
 
@@ -110,6 +111,7 @@ struct _GAtChat {
 	struct at_chat *parent;
 	guint group;
 	GAtChat *slave;
+	GAtHDLC	*qcdm;
 };
 
 struct terminator_info {
@@ -1354,6 +1356,30 @@ GAtChat *g_at_chat_get_slave(GAtChat *chat)
 	return chat->slave;
 }
 
+GAtHDLC *g_at_chat_set_slave_qcdm(GAtChat *chat, GAtHDLC *diag)
+{
+	if (chat == NULL)
+		return NULL;
+
+	if (chat->qcdm != NULL)
+		g_at_hdlc_unref(chat->qcdm);
+
+	if (diag != NULL)
+		chat->qcdm = g_at_hdlc_ref(diag);
+	else
+		chat->qcdm = NULL;
+
+	return chat->qcdm;
+}
+
+GAtHDLC *g_at_chat_get_slave_qcdm(GAtChat *chat)
+{
+	if (chat == NULL)
+		return NULL;
+
+	return chat->qcdm;
+}
+
 GIOChannel *g_at_chat_get_channel(GAtChat *chat)
 {
 	if (chat == NULL || chat->parent->io == NULL)
gatchat/gatchat.h +4 -0
index 367581e..496b3dc 100644
@@ -30,6 +30,7 @@ extern "C" {
 #include "gatsyntax.h"
 #include "gatutil.h"
 #include "gatio.h"
+#include "gathdlc.h"
 
 struct _GAtChat;
 
@@ -68,6 +69,9 @@ GAtChat *g_at_chat_clone(GAtChat *chat);
 GAtChat *g_at_chat_set_slave(GAtChat *chat, GAtChat *slave);
 GAtChat *g_at_chat_get_slave(GAtChat *chat);
 
+GAtHDLC *g_at_chat_set_slave_qcdm(GAtChat *chat, GAtHDLC *diag);
+GAtHDLC *g_at_chat_get_slave_qcdm(GAtChat *chat);
+
 void g_at_chat_suspend(GAtChat *chat);
 void g_at_chat_resume(GAtChat *chat);
 
Signature · 1 line
1.7.1
#2 lore raw

PATCH v4 2/6 huawei: Open qcdm port to fetch network status & SID

In reply to Philippe Nunes
---
 plugins/huawei.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)
plugins/huawei.c +44 -0
index 5d8875a..58f8832 100644
@@ -78,6 +78,7 @@ enum {
 struct huawei_data {
 	GAtChat *modem;
 	GAtChat *pcui;
+	GAtHDLC *diag;
 	gboolean have_sim;
 	int sim_state;
 	guint sysinfo_poll_source;
@@ -120,6 +121,7 @@ static void huawei_remove(struct ofono_modem *modem)
 
 	/* Cleanup after hot-unplug */
 	g_at_chat_unref(data->pcui);
+	g_at_hdlc_unref(data->diag);
 
 	g_free(data);
 }
@@ -357,6 +359,9 @@ static void shutdown_device(struct huawei_data *data)
 	g_at_chat_unref(data->modem);
 	data->modem = NULL;
 
+	g_at_hdlc_unref(data->diag);
+	data->diag = NULL;
+
 	g_at_chat_cancel_all(data->pcui);
 	g_at_chat_unregister_all(data->pcui);
 
@@ -577,6 +582,38 @@ static GAtChat *open_device(struct ofono_modem *modem,
 	return chat;
 }
 
+static GAtHDLC *open_qcdm(struct ofono_modem *modem)
+{
+	const char *device;
+	GIOChannel *channel;
+	GAtHDLC *hdlc;
+
+	device = ofono_modem_get_string(modem, "Diag");
+	if (device == NULL)
+		return NULL;
+
+	DBG("Diagnostic Monitor %s", device);
+
+	channel = g_at_tty_open_qcdm(device);
+	if (channel == NULL)
+		return NULL;
+
+	hdlc = g_at_hdlc_new(channel);
+
+	g_io_channel_unref(channel);
+
+	if (hdlc == NULL)
+		return NULL;
+
+	if (getenv("OFONO_AT_DEBUG"))
+		g_at_hdlc_set_debug(hdlc, huawei_debug, "DIAG: ");
+
+	g_at_hdlc_set_xmit_accm(hdlc, 0);
+	g_at_hdlc_set_recv_accm(hdlc, 0);
+
+	return hdlc;
+}
+
 static int huawei_enable(struct ofono_modem *modem)
 {
 	struct huawei_data *data = ofono_modem_get_data(modem);
@@ -594,6 +631,10 @@ static int huawei_enable(struct ofono_modem *modem)
 		return -EIO;
 	}
 
+	data->diag = open_qcdm(modem);
+	if (data->diag != NULL)
+		g_at_chat_set_slave_qcdm(data->pcui, data->diag);
+
 	g_at_chat_set_slave(data->modem, data->pcui);
 
 	g_at_chat_send(data->modem, "ATE0 +CMEE=1", NULL, NULL, NULL, NULL);
@@ -634,6 +675,9 @@ static int huawei_disable(struct ofono_modem *modem)
 	g_at_chat_unref(data->modem);
 	data->modem = NULL;
 
+	g_at_hdlc_unref(data->diag);
+	data->diag = NULL;
+
 	g_at_chat_cancel_all(data->pcui);
 	g_at_chat_unregister_all(data->pcui);
 
Signature · 1 line
1.7.1
#3 lore raw

PATCH v4 3/6 gatqcdm: Add helper functions for QCDM handling

In reply to Philippe Nunes
---
 Makefile.am       |    1 +
 gatchat/gatqcdm.c |   84 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 gatchat/gatqcdm.h |   57 ++++++++++++++++++++++++++++++++++++
 3 files changed, 142 insertions(+), 0 deletions(-)
 create mode 100644 gatchat/gatqcdm.c
 create mode 100644 gatchat/gatqcdm.h
Makefile.am +1 -0
index 0472dfa..fc8bc42 100644
@@ -72,6 +72,7 @@ gatchat_sources = gatchat/gatchat.h gatchat/gatchat.c \
 				gatchat/gatserver.h gatchat/gatserver.c \
 				gatchat/gatrawip.h gatchat/gatrawip.c \
 				gatchat/gathdlc.c gatchat/gathdlc.h \
+				gatchat/gatqcdm.c gatchat/gatqcdm.h \
 				gatchat/gatppp.c gatchat/gatppp.h \
 				gatchat/ppp.h gatchat/ppp_cp.h \
 				gatchat/ppp_cp.c gatchat/ppp_lcp.c \
gatchat/gatqcdm.c new file +84 -0

84 lines not on this page · raw message

gatchat/gatqcdm.h new file +57 -0

57 lines not on this page · raw message

Signature · 1 line
1.7.1
#4 lore raw

PATCH v4 4/6 huaweimodem: Probe the QCDM port with the version info request

In reply to Philippe Nunes
---
 drivers/huaweimodem/cdma-netreg.c |   66 ++++++++++++++++++++++++++++++------
 1 files changed, 55 insertions(+), 11 deletions(-)
drivers/huaweimodem/cdma-netreg.c +55 -11
index 2ae66e1..bf48b53 100644
@@ -24,6 +24,8 @@
 #endif
 
 #define _GNU_SOURCE
+#include <string.h>
+#include <stdio.h>
 #include <glib.h>
 #include <errno.h>
 
@@ -32,11 +34,19 @@
 #include <ofono/cdma-netreg.h>
 
 #include "gatchat.h"
+#include "gatqcdm.h"
 
 #include "huaweimodem.h"
 
 static const char *sysinfo_prefix[] = { "^SYSINFO:", NULL };
 
+struct netreg_data {
+	GAtChat *chat;
+	GAtHDLC *diag;
+	void *cb;
+	void *cb_data;
+};
+
 static gboolean parse_sysinfo(GAtResult *result, gint *status)
 {
 	GAtResultIter iter;
@@ -107,12 +117,34 @@ static void sysinfo_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	ofono_cdma_netreg_status_notify(netreg, status);
 }
 
+static void version_info_cb(const unsigned char *buf, gsize len,
+							gpointer user_data)
+{
+	struct ofono_cdma_netreg *netreg = user_data;
+	struct netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
+	struct version_info verinfo;
+
+	if (!g_at_qcdm_result_get_version_info(buf, len, &verinfo)) {
+		/* This is probably not a QCDM port */
+		g_at_hdlc_unref(nd->diag);
+		nd->diag = NULL;
+		return;
+	}
+
+	DBG("Version information\n");
+	DBG("Compiled Date: %s\n", verinfo.comp_date);
+	DBG("Compiled Time: %s\n", verinfo.comp_time);
+	DBG("Release Date: %s\n", verinfo.rel_date);
+	DBG("Release Time: %s\n", verinfo.rel_time);
+	DBG("Model: %s\n", verinfo.model);
+	DBG("MSM version: %d\n", verinfo.msm_ver);
+}
 static void mode_notify(GAtResult *result, gpointer user_data)
 {
 	struct ofono_cdma_netreg *netreg = user_data;
-	GAtChat *chat = ofono_cdma_netreg_get_data(netreg);
+	struct netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
 
-	g_at_chat_send(chat, "AT^SYSINFO", sysinfo_prefix,
+	g_at_chat_send(nd->chat, "AT^SYSINFO", sysinfo_prefix,
 				sysinfo_cb, netreg, NULL);
 }
 
@@ -169,20 +201,20 @@ error:
 static void probe_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
 	struct ofono_cdma_netreg *netreg = user_data;
-	GAtChat *chat = ofono_cdma_netreg_get_data(netreg);
+	struct netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
 
 	if (!ok) {
 		ofono_cdma_netreg_remove(netreg);
 		return;
 	}
 
-	g_at_chat_register(chat, "^MODE:",
+	g_at_chat_register(nd->chat, "^MODE:",
 				mode_notify, FALSE, netreg, NULL);
 
-	g_at_chat_register(chat, "^RSSILVL:",
+	g_at_chat_register(nd->chat, "^RSSILVL:",
 				rssilvl_notify, FALSE, netreg, NULL);
 
-	g_at_chat_register(chat, "^HRSSILVL:",
+	g_at_chat_register(nd->chat, "^HRSSILVL:",
 				hrssilvl_notify, FALSE, netreg, NULL);
 
 	ofono_cdma_netreg_register(netreg);
@@ -191,23 +223,35 @@ static void probe_cb(gboolean ok, GAtResult *result, gpointer user_data)
 static int huawei_cdma_netreg_probe(struct ofono_cdma_netreg *netreg,
 				unsigned int vendor, void *data)
 {
-	GAtChat *chat = g_at_chat_clone(data);
+	struct netreg_data *nd;
 
-	ofono_cdma_netreg_set_data(netreg, chat);
+	nd = g_new0(struct netreg_data, 1);
 
-	g_at_chat_send(chat, "AT^SYSINFO", sysinfo_prefix,
+	nd->chat = g_at_chat_clone(data);
+	nd->diag = g_at_chat_get_slave_qcdm(data);
+
+	ofono_cdma_netreg_set_data(netreg, nd);
+
+	g_at_chat_send(nd->chat, "AT^SYSINFO", sysinfo_prefix,
 				probe_cb, netreg, NULL);
 
+	if (nd->diag)
+		/* Request version info to probe the QCDM port */
+		g_at_qcdm_send(nd->diag, G_AT_QCDM_CMD_VERSION_INFO,
+					version_info_cb, netreg);
+
 	return 0;
 }
 
 static void huawei_cdma_netreg_remove(struct ofono_cdma_netreg *netreg)
 {
-	GAtChat *chat = ofono_cdma_netreg_get_data(netreg);
+	struct netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
 
 	ofono_cdma_netreg_set_data(netreg, NULL);
 
-	g_at_chat_unref(chat);
+	g_at_chat_unref(nd->chat);
+	g_at_hdlc_unref(nd->diag);
+	g_free(nd);
 }
 
 static struct ofono_cdma_netreg_driver driver = {
Signature · 1 line
1.7.1
#5 lore raw

PATCH v4 5/6 huaweimodem: Add 'serving_system' entry point to get SID

In reply to Philippe Nunes
---
 drivers/huaweimodem/cdma-netreg.c |  108 +++++++++++++++++++++++++++++++++++++
 1 files changed, 108 insertions(+), 0 deletions(-)
drivers/huaweimodem/cdma-netreg.c +108 -0
index bf48b53..e9dd3e2 100644
@@ -117,6 +117,66 @@ static void sysinfo_cb(gboolean ok, GAtResult *result, gpointer user_data)
 	ofono_cdma_netreg_status_notify(netreg, status);
 }
 
+static gboolean parse_css(GAtResult *result, const char **sid)
+{
+	GAtResultIter iter;
+	/*
+	* According TIA/EIA/IS-707, CSS query returns <AB>,<SID> but
+	* according TIA/EIA/IS-707-A , it returns <Band_Class>,<Band>,<SID>.
+	* PREV field which has been added afterward is ignored
+	*/
+
+	g_at_result_iter_init(&iter, result);
+
+	g_at_result_iter_next(&iter, NULL);
+
+	/* Skip first field since we are not interested in this */
+	if (!g_at_result_iter_skip_next(&iter))
+		return FALSE;
+
+	if (!g_at_result_iter_next_unquoted_string(&iter, sid))
+		return FALSE;
+	/*
+	* As CSS answer may differ according which revision of TIA/EIA/IS-707
+	* the modem is compliant, we need to check if this field is Band or SID
+	*/
+	if ((*sid[0] >= 'A' && *sid[0] <= 'F') || (*sid[0] == 'Z'))
+		/* This is the band field, the next field is the SID*/
+		if (!g_at_result_iter_next_unquoted_string(&iter, sid))
+			return FALSE;
+
+	if (!strcmp(*sid, "99999"))
+		/* The mobile station is not registered.*/
+		return FALSE;
+
+	return TRUE;
+}
+
+static void serving_system_cb(gboolean ok, GAtResult *result,
+				gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	ofono_cdma_netreg_serving_system_cb_t cb = cbd->cb;
+	struct ofono_error error;
+	const char *sid;
+
+	decode_at_error(&error, g_at_result_final_response(result));
+
+	if (!ok) {
+		cb(&error, NULL, cbd->data);
+		return;
+	}
+
+	if (parse_css(result, &sid) == FALSE) {
+		CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
+		return;
+	}
+
+	DBG("serving system: SID %s", sid);
+
+	cb(&error, sid, cbd->data);
+}
+
 static void version_info_cb(const unsigned char *buf, gsize len,
 							gpointer user_data)
 {
@@ -139,6 +199,32 @@ static void version_info_cb(const unsigned char *buf, gsize len,
 	DBG("Model: %s\n", verinfo.model);
 	DBG("MSM version: %d\n", verinfo.msm_ver);
 }
+
+static void status_cb(const unsigned char *buf, gsize len, gpointer user_data)
+{
+	struct ofono_cdma_netreg *netreg = user_data;
+	struct netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
+	ofono_cdma_netreg_serving_system_cb_t cb = nd->cb;
+	char str[6];
+	guint16 sid;
+
+	if (!g_at_qcdm_result_parse_status(buf, len, &sid)) {
+		/* fall back to use +CSS */
+		if (g_at_chat_send(nd->chat, "AT+CSS=?", NULL,
+				serving_system_cb, netreg, NULL) > 0)
+			return;
+
+		CALLBACK_WITH_FAILURE(cb, NULL, nd->cb_data);
+		return;
+	}
+
+	snprintf(str, 6, "%d", sid);
+	DBG("Status command response\n");
+	DBG("Serving Identification number: SID %s", str);
+
+	CALLBACK_WITH_SUCCESS(cb, str, nd->cb_data);
+}
+
 static void mode_notify(GAtResult *result, gpointer user_data)
 {
 	struct ofono_cdma_netreg *netreg = user_data;
@@ -254,10 +340,32 @@ static void huawei_cdma_netreg_remove(struct ofono_cdma_netreg *netreg)
 	g_free(nd);
 }
 
+static void huaweicdma_netreg_serving_system(struct ofono_cdma_netreg *netreg,
+		ofono_cdma_netreg_serving_system_cb_t cb, void *data)
+{
+	struct netreg_data *nd = ofono_cdma_netreg_get_data(netreg);
+
+	nd->cb = cb;
+	nd->cb_data = data;
+
+	/* First use QCDM port if any */
+	if (nd->diag) {
+		/* Request Station status */
+		if (g_at_qcdm_send(nd->diag, G_AT_QCDM_CMD_STATUS,
+				status_cb, netreg) > 0)
+			return;
+	} else if (g_at_chat_send(nd->chat, "AT+CSS=?", NULL,
+					serving_system_cb, netreg, NULL) > 0)
+		return;
+
+	CALLBACK_WITH_FAILURE(cb, NULL, data);
+}
+
 static struct ofono_cdma_netreg_driver driver = {
 	.name	= "huaweimodem",
 	.probe	= huawei_cdma_netreg_probe,
 	.remove	= huawei_cdma_netreg_remove,
+	.serving_system = huaweicdma_netreg_serving_system,
 };
 
 void huawei_cdma_netreg_init(void)
Signature · 1 line
1.7.1
#6 lore raw

PATCH v4 6/6 udevng: Add a default assignment for Huawei QCDM port

In reply to Philippe Nunes
---
 plugins/udevng.c |   30 +++++++++++++++++++++---------
 1 files changed, 21 insertions(+), 9 deletions(-)
plugins/udevng.c +21 -9
index 2a9200d..7b0d60f 100644
@@ -237,6 +237,7 @@ static gboolean setup_sierra(struct modem_info *modem)
 static gboolean setup_huawei(struct modem_info *modem)
 {
 	const char *mdm = NULL, *pcui = NULL, *diag = NULL;
+	const char *default_pcui = NULL;
 	GSList *list;
 
 	DBG("%s", modem->syspath);
@@ -266,22 +267,33 @@ static gboolean setup_huawei(struct modem_info *modem)
 			if (mdm != NULL && pcui != NULL)
 				break;
 		} else if (g_strcmp0(info->interface, "255/255/255") == 0) {
-			if (g_strcmp0(info->number, "00") == 0)
+			if (mdm == NULL && g_strcmp0(info->number, "00") == 0)
 				mdm = info->devnode;
-			else if (g_strcmp0(info->number, "01") == 0)
-				pcui = info->devnode;
-			else if (g_strcmp0(info->number, "02") == 0)
-				pcui = info->devnode;
-			else if (g_strcmp0(info->number, "03") == 0)
-				pcui = info->devnode;
-			else if (g_strcmp0(info->number, "04") == 0)
-				pcui = info->devnode;
+			else if (diag == NULL) {
+				if (g_strcmp0(info->number, "01") == 0)
+					diag = info->devnode;
+			} else if (pcui == NULL) {
+				if (g_strcmp0(info->number, "01") == 0)
+					default_pcui = info->devnode;
+				else if (g_strcmp0(info->number, "02") == 0)
+					default_pcui = info->devnode;
+				else if (g_strcmp0(info->number, "03") == 0)
+					default_pcui = info->devnode;
+				else if (g_strcmp0(info->number, "04") == 0)
+					default_pcui = info->devnode;
+			}
 		}
 	}
 
+	if (pcui == NULL && default_pcui != NULL)
+		pcui = default_pcui;
+
 	if (mdm == NULL || pcui == NULL)
 		return FALSE;
 
+	if (diag != NULL && g_strcmp0(diag, pcui) == 0)
+		diag = NULL;
+
 	DBG("modem=%s pcui=%s diag=%s", mdm, pcui, diag);
 
 	ofono_modem_set_string(modem->modem, "Modem", mdm);
Signature · 1 line
1.7.1
#7 lore raw
In reply to Philippe Nunes

Hi Philippe,

Quoted 7 lines

This version introduces a QCDM helper library.
Also, to simplify the QCDM handling, a dedicated callback is set for each command sent.
Currently, we are not considering that a new command can be issued before the answer from the previous command is handled. If this case occurs, then we would need to introduce a command queue in the GAtHDLC structure to be able to invoke properly the callbacks.

I would actually prefer if you create a clean GAtQCDM with proper queue handling and a clean API. Command queue inside GAtHDLC is wrong since that is not what HDLC actually is about.

Regards

Marcel