Open Source Telephony
 help / color / mirror / Atom feed
From: Yang Gu <yang.gu@intel.com>
To: ofono@ofono.org
Subject: [PATCH 1/3] Make fetch command function as external
Date: Tue, 13 Jul 2010 18:29:59 +0800	[thread overview]
Message-ID: <1279017001-23915-1-git-send-email-yang.gu@intel.com> (raw)

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

---
 Makefile.am                |    1 +
 drivers/atmodem/sim-poll.c |   55 +------------------------------------------
 drivers/atmodem/stk.c      |   51 ++++++++++++++++++++++++++++++++++++++++
 drivers/atmodem/stk.h      |   22 +++++++++++++++++
 4 files changed, 76 insertions(+), 53 deletions(-)
 create mode 100644 drivers/atmodem/stk.h

diff --git a/Makefile.am b/Makefile.am
index 24aa886..e256841 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -143,6 +143,7 @@ builtin_sources += $(gatchat_sources) \
 				drivers/atmodem/network-registration.c \
 				drivers/atmodem/sim.c \
 				drivers/atmodem/stk.c \
+				drivers/atmodem/stk.h \
 				drivers/atmodem/sim-poll.c \
 				drivers/atmodem/sim-poll.h \
 				drivers/atmodem/ussd.c \
diff --git a/drivers/atmodem/sim-poll.c b/drivers/atmodem/sim-poll.c
index f1a83e3..3f1a355 100644
--- a/drivers/atmodem/sim-poll.c
+++ b/drivers/atmodem/sim-poll.c
@@ -39,6 +39,7 @@
 
 #include "atmodem.h"
 #include "sim-poll.h"
+#include "stk.h"
 
 struct sim_poll_data {
 	GAtChat *chat;
@@ -58,58 +59,6 @@ struct sim_poll_data {
 static const char *csim_prefix[] = { "+CSIM:", NULL };
 
 static gboolean sim_status_poll(gpointer user_data);
-static void sim_fetch_command(struct sim_poll_data *spd, int length);
-
-static void at_csim_fetch_cb(gboolean ok, GAtResult *result,
-		gpointer user_data)
-{
-	struct sim_poll_data *spd = user_data;
-	GAtResultIter iter;
-	const guint8 *response;
-	gint rlen, len;
-
-	if (!ok)
-		return;
-
-	g_at_result_iter_init(&iter, result);
-
-	if (!g_at_result_iter_next(&iter, "+CSIM:"))
-		return;
-
-	if (!g_at_result_iter_next_number(&iter, &rlen))
-		return;
-
-	if (!g_at_result_iter_next_hexstring(&iter, &response, &len))
-		return;
-
-	if (rlen != len * 2 || len < 2)
-		return;
-
-	/* Check that SW1 indicates success */
-	if (response[len - 2] != 0x90 && response[len - 2] != 0x91)
-		return;
-
-	if (response[len - 2] == 0x90 && response[len - 1] != 0)
-		return;
-
-	DBG("csim_fetch_cb: %i", len);
-
-	ofono_stk_proactive_command_notify(spd->stk, len - 2, response);
-
-	/* Can this happen? */
-	if (response[len - 2] == 0x91)
-		sim_fetch_command(spd, response[len - 1]);
-}
-
-static void sim_fetch_command(struct sim_poll_data *spd, int length)
-{
-	char buf[64];
-
-	snprintf(buf, sizeof(buf), "AT+CSIM=10,A0120000%02hhX", length);
-
-	g_at_chat_send(spd->chat, buf, csim_prefix,
-			at_csim_fetch_cb, spd, NULL);
-}
 
 static void sim_status_poll_schedule(struct sim_poll_data *spd)
 {
@@ -196,7 +145,7 @@ static void at_csim_status_cb(gboolean ok, GAtResult *result,
 		return;
 
 	/* We have a proactive command pending, FETCH it */
-	sim_fetch_command(spd, response[len - 1]);
+	at_sim_fetch_command(spd->stk, response[len - 1]);
 }
 
 static gboolean sim_status_poll(gpointer user_data)
diff --git a/drivers/atmodem/stk.c b/drivers/atmodem/stk.c
index aede668..1283cca 100644
--- a/drivers/atmodem/stk.c
+++ b/drivers/atmodem/stk.c
@@ -38,6 +38,7 @@
 #include "gatresult.h"
 
 #include "atmodem.h"
+#include "stk.h"
 
 struct stk_data {
 	GAtChat *chat;
@@ -45,6 +46,56 @@ struct stk_data {
 
 static const char *csim_prefix[] = { "+CSIM:", NULL };
 
+static void csim_fetch_cb(gboolean ok, GAtResult *result,
+		gpointer user_data)
+{
+	struct ofono_stk *stk = user_data;
+	GAtResultIter iter;
+	const guint8 *response;
+	gint rlen, len;
+
+	if (!ok)
+		return;
+
+	g_at_result_iter_init(&iter, result);
+
+	if (!g_at_result_iter_next(&iter, "+CSIM:"))
+		return;
+
+	if (!g_at_result_iter_next_number(&iter, &rlen))
+		return;
+
+	if (!g_at_result_iter_next_hexstring(&iter, &response, &len))
+		return;
+
+	if (rlen != len * 2 || len < 2)
+		return;
+
+	/* Check that SW1 indicates success */
+	if (response[len - 2] != 0x90 && response[len - 2] != 0x91)
+		return;
+
+	if (response[len - 2] == 0x90 && response[len - 1] != 0)
+		return;
+
+	DBG("csim_fetch_cb: %i", len);
+
+	ofono_stk_proactive_command_notify(stk, len - 2, response);
+
+	/* Can this happen? */
+	if (response[len - 2] == 0x91)
+		at_sim_fetch_command(stk, response[len - 1]);
+}
+
+void at_sim_fetch_command(struct ofono_stk *stk, int length)
+{
+	char buf[64];
+	struct stk_data *sd = ofono_stk_get_data(stk);
+
+	snprintf(buf, sizeof(buf), "AT+CSIM=10,A0120000%02hhX", length);
+	g_at_chat_send(sd->chat, buf, csim_prefix, csim_fetch_cb, stk, NULL);
+}
+
 static void at_csim_envelope_cb(gboolean ok, GAtResult *result,
 				gpointer user_data)
 {
diff --git a/drivers/atmodem/stk.h b/drivers/atmodem/stk.h
new file mode 100644
index 0000000..265ac2e
--- /dev/null
+++ b/drivers/atmodem/stk.h
@@ -0,0 +1,22 @@
+/*
+ *
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2008-2010  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+void at_sim_fetch_command(struct ofono_stk *stk, int length);
-- 
1.7.0.4


             reply	other threads:[~2010-07-13 10:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-13 10:29 Yang Gu [this message]
2010-07-13 10:30 ` [PATCH 2/3] Support phonesim proactive command notification Yang Gu
2010-07-13 14:56   ` Denis Kenzior
2010-07-13 10:30 ` [PATCH 3/3] Use specific vendor for phonesim stk Yang Gu
2010-07-13 14:56   ` Denis Kenzior
2010-07-13 14:55 ` [PATCH 1/3] Make fetch command function as external Denis Kenzior
  -- strict thread matches above, loose matches on Subject: below --
2010-07-09 14:52 Yang Gu
2010-07-09 15:09 ` Gu, Yang
2010-07-09 17:17 ` 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=1279017001-23915-1-git-send-email-yang.gu@intel.com \
    --to=yang.gu@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox