Open Source Telephony
 help / color / mirror / Atom feed
From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis <frederic.danis@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH v2 8/8] emulator: add +CCWA support for HFP AG
Date: Thu, 07 Apr 2011 18:34:00 +0200	[thread overview]
Message-ID: <1302194040-18811-9-git-send-email-frederic.danis@linux.intel.com> (raw)
In-Reply-To: <1302194040-18811-1-git-send-email-frederic.danis@linux.intel.com>

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

---
 src/emulator.c |   83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 82 insertions(+), 1 deletions(-)

diff --git a/src/emulator.c b/src/emulator.c
index 7559d07..00588b5 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -60,6 +60,7 @@ struct ofono_emulator {
 	 * + phone type on 3 digits max + terminating null
 	 */
 	char incoming_str[OFONO_MAX_PHONE_NUMBER_LENGTH + 14 + 1];
+	gboolean ccwa;
 };
 
 struct indicator {
@@ -208,6 +209,28 @@ static struct indicator *find_indicator(struct ofono_emulator *em,
 	return NULL;
 }
 
+static void notify_ccwa(struct ofono_emulator *em)
+{
+	const char *phone;
+
+	if (em->incoming &&
+			em->incoming->clip_validity == CLIP_VALIDITY_VALID &&
+			em->incoming_str[0] == '\0') {
+		phone = phone_number_to_string(&em->incoming->phone_number);
+		sprintf(em->incoming_str, "+CCWA: \"%s\",%d", phone,
+				em->incoming->phone_number.type);
+	}
+
+	if (em->ccwa) {
+		if (em->incoming_str[0] == '\0')
+			g_at_server_send_unsolicited(em->server,
+							"+CCWA: \"\",128");
+		else
+			g_at_server_send_unsolicited(em->server,
+							em->incoming_str);
+	}
+}
+
 static void notify_ring(struct ofono_emulator *em)
 {
 	const char *phone;
@@ -238,6 +261,8 @@ static gboolean ring_cb(gpointer user_data)
 
 	if (call_ind->value == OFONO_EMULATOR_CALL_INACTIVE)
 		notify_ring(em);
+	else
+		notify_ccwa(em);
 
 	return TRUE;
 }
@@ -488,6 +513,42 @@ fail:
 	};
 }
 
+static void ccwa_cb(GAtServer *server, GAtServerRequestType type,
+			GAtResult *result, gpointer user_data)
+{
+	struct ofono_emulator *em = user_data;
+	GAtResultIter iter;
+	int val;
+
+	if (em->slc == FALSE)
+		goto fail;
+
+	switch (type) {
+	case G_AT_SERVER_REQUEST_TYPE_SET:
+		g_at_result_iter_init(&iter, result);
+		g_at_result_iter_next(&iter, "");
+
+		if (!g_at_result_iter_next_number(&iter, &val))
+			goto fail;
+
+		if (val != 0 && val != 1)
+			goto fail;
+
+		/* check this is last parameter */
+		if (g_at_result_iter_skip_next(&iter))
+			goto fail;
+
+		em->ccwa = val;
+
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
+		break;
+
+	default:
+fail:
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
+	};
+}
+
 static void emulator_add_indicator(struct ofono_emulator *em, const char* name,
 					int min, int max, int dflt)
 {
@@ -574,6 +635,7 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd)
 		g_at_server_register(em->server, "+CIND", cind_cb, em, NULL);
 		g_at_server_register(em->server, "+CMER", cmer_cb, em, NULL);
 		g_at_server_register(em->server, "+CLIP", clip_cb, em, NULL);
+		g_at_server_register(em->server, "+CCWA", ccwa_cb, em, NULL);
 	}
 
 	__ofono_atom_register(em->atom, emulator_unregister);
@@ -793,6 +855,7 @@ void ofono_emulator_set_indicator(struct ofono_emulator *em,
 	char buf[20];
 	struct indicator *ind;
 	struct indicator *call_ind;
+	gboolean callsetup;
 
 	ind = find_indicator(em, name, &i);
 
@@ -802,8 +865,26 @@ void ofono_emulator_set_indicator(struct ofono_emulator *em,
 
 	ind->value = value;
 
+	/*
+	 * When call indicator goes to inactive, force to re-generate
+	 * incoming call (+CLIP or +CCWA) string
+	 */
+	if (g_str_equal(name, OFONO_EMULATOR_IND_CALL) == TRUE &&
+			value == OFONO_EMULATOR_CALL_INACTIVE)
+		em->incoming_str[0] = '\0';
+
 	call_ind = find_indicator(em, OFONO_EMULATOR_IND_CALL, NULL);
 
+	callsetup = g_str_equal(name, OFONO_EMULATOR_IND_CALLSETUP);
+
+	/*
+	 * When callsetup indicator goes to Incoming and there is an active call
+	 * a +CCWA should be sent before +CIEV
+	 */
+	if (callsetup && value == OFONO_EMULATOR_CALLSETUP_INCOMING &&
+			call_ind->value == OFONO_EMULATOR_CALL_ACTIVE)
+		ring_cb(em);
+
 	if (em->events_mode == 3 && em->events_ind && em->slc) {
 		sprintf(buf, "+CIEV: %d,%d", i, ind->value);
 		g_at_server_send_info(em->server, buf, TRUE);
@@ -816,7 +897,7 @@ void ofono_emulator_set_indicator(struct ofono_emulator *em,
 	 *   the +CIEV
 	 * It should be stopped for all other values of callsetup
 	 */
-	if (g_str_equal(name, OFONO_EMULATOR_IND_CALLSETUP) == FALSE)
+	if (!callsetup)
 		return;
 
 	if (value == OFONO_EMULATOR_CALLSETUP_INCOMING && em->ring == 0) {
-- 
1.7.1


  parent reply	other threads:[~2011-04-07 16:34 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-07 16:33 [PATCH v2 0/8] *** SUBJECT HERE *** =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-07 16:33 ` [PATCH v2 1/8] emulator: add defines for call, callsetup and callheld indicators =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-11 15:57   ` Denis Kenzior
2011-04-07 16:33 ` [PATCH v2 2/8] emulator: add " =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-11 15:57   ` Denis Kenzior
2011-04-07 16:33 ` [PATCH v2 3/8] emulator: add RING for HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-11 15:51   ` Denis Kenzior
2011-04-11 16:09     ` Frederic Danis
2011-04-07 16:33 ` [PATCH v2 4/8] emulator: add incoming call API =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-11 15:52   ` Denis Kenzior
2011-04-07 16:33 ` [PATCH v2 5/8] emulator: add +CLIP support for HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-11 15:56   ` Denis Kenzior
2011-04-07 16:33 ` [PATCH v2 6/8] voicecall: add ATA support for HFP emulator =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-11 16:00   ` Denis Kenzior
2011-04-07 16:33 ` [PATCH v2 7/8] voicecall: add +CHUP " =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-11 16:13   ` Denis Kenzior
2011-04-11 16:44     ` Frederic Danis
2011-04-11 16:50       ` Denis Kenzior
2011-04-07 16:34 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis [this message]
2011-04-07 16:39 ` [PATCH v2 0/8] emulator: add simple incoming call support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis

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=1302194040-18811-9-git-send-email-frederic.danis@linux.intel.com \
    --to=frederic.danis@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox