All of lore.kernel.org
 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 v3 3/6] emulator: add +CLIP support for HFP AG
Date: Wed, 13 Apr 2011 18:05:31 +0200	[thread overview]
Message-ID: <1302710734-6103-4-git-send-email-frederic.danis@linux.intel.com> (raw)
In-Reply-To: <1302710734-6103-1-git-send-email-frederic.danis@linux.intel.com>

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

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

diff --git a/src/emulator.c b/src/emulator.c
index 9005c66..8e18785 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -29,6 +29,7 @@
 #include <glib.h>
 
 #include "ofono.h"
+#include "common.h"
 #include "gatserver.h"
 #include "gatppp.h"
 
@@ -52,6 +53,7 @@ struct ofono_emulator {
 	gboolean events_ind;
 	GSList *indicators;
 	guint callsetup_source;
+	gboolean clip;
 };
 
 struct indicator {
@@ -201,6 +203,47 @@ static struct indicator *find_indicator(struct ofono_emulator *em,
 	return NULL;
 }
 
+static struct ofono_call *find_call_with_status(struct ofono_emulator *em,
+								int status)
+{
+	struct ofono_modem *modem = __ofono_atom_get_modem(em->atom);
+	struct ofono_atom *vc_atom;
+	struct ofono_voicecall *vc;
+
+	vc_atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_VOICECALL);
+	if (vc_atom == NULL)
+		return NULL;
+
+	vc = __ofono_atom_get_data(vc_atom);
+
+	return __ofono_voicecall_find_call_with_status(vc, status);
+}
+
+static void notify_ring(struct ofono_emulator *em)
+{
+	struct ofono_call *c;
+	const char *phone;
+	/*
+	 * '+CLIP: "+",' + phone number + phone type on 3 digits max
+	 * + terminating null
+	 */
+	char str[OFONO_MAX_PHONE_NUMBER_LENGTH + 14 + 1];
+
+	g_at_server_send_unsolicited(em->server, "RING");
+
+	if (!em->clip)
+		return;
+
+	c = find_call_with_status(em, CALL_STATUS_INCOMING);
+
+	if (c && c->clip_validity == CLIP_VALIDITY_VALID) {
+		phone = phone_number_to_string(&c->phone_number);
+		sprintf(str, "+CLIP: \"%s\",%d", phone, c->phone_number.type);
+
+		g_at_server_send_unsolicited(em->server, str);
+	}
+}
+
 static gboolean send_callsetup_notification(gpointer user_data)
 {
 	struct ofono_emulator *em = user_data;
@@ -212,7 +255,7 @@ static gboolean send_callsetup_notification(gpointer user_data)
 	call_ind = find_indicator(em, OFONO_EMULATOR_IND_CALL, NULL);
 
 	if (call_ind->value == OFONO_EMULATOR_CALL_INACTIVE)
-		g_at_server_send_unsolicited(em->server, "RING");
+		notify_ring(em);
 
 	return TRUE;
 }
@@ -427,6 +470,42 @@ fail:
 	}
 }
 
+static void clip_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->clip = 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)
 {
@@ -512,6 +591,7 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd)
 		g_at_server_register(em->server, "+BRSF", brsf_cb, em, NULL);
 		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);
 	}
 
 	__ofono_atom_register(em->atom, emulator_unregister);
-- 
1.7.1


  parent reply	other threads:[~2011-04-13 16:05 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-13 16:05 [PATCH v3 0/6] emulator: add simple incoming call support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-13 16:05 ` [PATCH v3 1/6] emulator: add RING for HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-19 18:57   ` Denis Kenzior
2011-04-13 16:05 ` [PATCH v3 2/6] voicecall: add API to find call by status =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-19 18:58   ` Denis Kenzior
2011-04-13 16:05 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis [this message]
2011-04-19 19:00   ` [PATCH v3 3/6] emulator: add +CLIP support for HFP AG Denis Kenzior
2011-04-13 16:05 ` [PATCH v3 4/6] emulator: add +CCWA " =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-19 19:01   ` Denis Kenzior
2011-04-13 16:05 ` [PATCH v3 5/6] voicecall: add ATA support for HFP emulator =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-19 19:01   ` Denis Kenzior
2011-04-13 16:05 ` [PATCH v3 6/6] voicecall: add +CHUP " =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-14 12:27   ` [PATCH v4] " =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-04-21 21:24     ` 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=1302710734-6103-4-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 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.