All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Nunes <philippe.nunes@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH v2 6/6] cdmamodem: Add serving system identifier support
Date: Thu, 17 Nov 2011 17:21:04 +0100	[thread overview]
Message-ID: <1321546864-368-7-git-send-email-philippe.nunes@linux.intel.com> (raw)
In-Reply-To: <1321546864-368-1-git-send-email-philippe.nunes@linux.intel.com>

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

---
 drivers/cdmamodem/network-registration.c |   78 ++++++++++++++++++++++++++++++
 include/cdma-netreg.h                    |    7 +++
 2 files changed, 85 insertions(+), 0 deletions(-)

diff --git a/drivers/cdmamodem/network-registration.c b/drivers/cdmamodem/network-registration.c
index a34db91..fe8b4f2 100644
--- a/drivers/cdmamodem/network-registration.c
+++ b/drivers/cdmamodem/network-registration.c
@@ -24,6 +24,7 @@
 #endif
 
 #define _GNU_SOURCE
+#include <string.h>
 #include <glib.h>
 #include <errno.h>
 
@@ -108,6 +109,67 @@ 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') {
+		/* 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 mode_notify(GAtResult *result, gpointer user_data)
 {
 	struct ofono_cdma_netreg *netreg = user_data;
@@ -184,10 +246,26 @@ static void cdma_netreg_remove(struct ofono_cdma_netreg *netreg)
 	g_at_chat_unref(chat);
 }
 
+static void cdma_netreg_serving_system(struct ofono_cdma_netreg *netreg,
+		ofono_cdma_netreg_serving_system_cb_t cb, void *data)
+{
+	GAtChat *chat = ofono_cdma_netreg_get_data(netreg);
+	struct cb_data *cbd = cb_data_new(cb, data);
+
+	if (g_at_chat_send(chat, "AT+CSS=?", NULL, serving_system_cb, cbd,
+				g_free) > 0)
+			return;
+
+	g_free(cbd);
+
+	CALLBACK_WITH_FAILURE(cb, NULL, data);
+}
+
 static struct ofono_cdma_netreg_driver driver = {
 	.name	= "cdmamodem",
 	.probe	= cdma_netreg_probe,
 	.remove	= cdma_netreg_remove,
+	.serving_system = cdma_netreg_serving_system,
 };
 
 void cdma_netreg_init(void)
diff --git a/include/cdma-netreg.h b/include/cdma-netreg.h
index 31ed289..529dab5 100644
--- a/include/cdma-netreg.h
+++ b/include/cdma-netreg.h
@@ -36,12 +36,19 @@ enum cdma_netreg_status {
 
 struct ofono_cdma_netreg;
 
+typedef void (*ofono_cdma_netreg_serving_system_cb_t)(
+				const struct ofono_error *error,
+				const char *sid,
+				void *data);
+
 struct ofono_cdma_netreg_driver {
 	const char *name;
 	int (*probe)(struct ofono_cdma_netreg *cdma_netreg,
 				unsigned int vendor,
 				void *data);
 	void (*remove)(struct ofono_cdma_netreg *cdma_netreg);
+	void (*serving_system)(struct ofono_cdma_netreg *cdma_netreg,
+			ofono_cdma_netreg_serving_system_cb_t cb, void *data);
 };
 
 void ofono_cdma_netreg_status_notify(struct ofono_cdma_netreg *netreg,
-- 
1.7.1


  parent reply	other threads:[~2011-11-17 16:21 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-17 16:20 [PATCH v2 0/6] Add a parser to retrieve the CDMA network name Philippe Nunes
2011-11-17 16:20 ` [PATCH v2 1/6] mbpi: Add mbpi_lookup_cdma_provider_name API Philippe Nunes
2011-11-16 10:28   ` Denis Kenzior
2011-11-17 16:21 ` [PATCH v2 2/6] tools: Add utility for looking CDMA network name from database Philippe Nunes
2011-11-16 10:28   ` Denis Kenzior
2011-11-17 16:21 ` [PATCH v2 3/6] Huaweicdmamodem: remove this specific driver Philippe Nunes
2011-11-17 16:21 ` [PATCH v2 4/6] huaweicdmamodem: Merge this driver with cdmamodem driver Philippe Nunes
2011-11-17 16:21 ` [PATCH v2 5/6] cdmamodem: Add CDMA network-registration support Philippe Nunes
2011-11-17 16:21 ` Philippe Nunes [this message]
2011-11-16 10:26   ` [PATCH v2 6/6] cdmamodem: Add serving system identifier support Denis Kenzior
2011-11-18 13:18     ` Philippe Nunes
2011-11-18 15:18       ` Denis Kenzior
2011-11-24 17:35         ` Philippe Nunes
2011-11-24  7:03           ` Denis Kenzior
2011-11-25 16:31             ` Philippe Nunes
2011-11-24 23:35               ` 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=1321546864-368-7-git-send-email-philippe.nunes@linux.intel.com \
    --to=philippe.nunes@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.