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 3/3] emulator: add +CIND support
Date: Tue, 15 Feb 2011 16:06:33 +0100	[thread overview]
Message-ID: <1297782393-9898-4-git-send-email-frederic.danis@linux.intel.com> (raw)
In-Reply-To: <1297782393-9898-1-git-send-email-frederic.danis@linux.intel.com>

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

currently, only network registration is supported (service, roaming)
---
 src/emulator.c |  118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 118 insertions(+), 0 deletions(-)

diff --git a/src/emulator.c b/src/emulator.c
index 232b314..96c55d4 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -23,15 +23,21 @@
 #include <config.h>
 #endif
 
+#include <stdio.h>
 #include <glib.h>
 
 #include "ofono.h"
+#include "common.h"
 #include "gatserver.h"
 
 struct ofono_emulator {
 	struct ofono_atom *atom;
 	enum ofono_emulator_type type;
 	GAtServer *server;
+	struct ofono_netreg *netreg;
+	unsigned int netreg_watch;
+	unsigned int status_watch;
+	int netreg_status;
 };
 
 static void emulator_debug(const char *str, void *data)
@@ -39,6 +45,98 @@ static void emulator_debug(const char *str, void *data)
 	ofono_info("%s: %s\n", (char *)data, str);
 }
 
+static void cind_update(struct ofono_emulator *em, gboolean final)
+{
+	int status;
+	int roam;
+	char buf[30];
+
+	switch (em->netreg_status) {
+	case NETWORK_REGISTRATION_STATUS_REGISTERED:
+		status = 1;
+		roam = 0;
+		break;
+	case NETWORK_REGISTRATION_STATUS_ROAMING:
+		status = 1;
+		roam = 1;
+		break;
+	default:
+		status = 0;
+		roam = 0;
+		break;
+	}
+
+	call = 0;
+	callsetup = 0;
+	callheld = 0;
+	signal = (em->netreg_signal + 20) / 21;
+	battchg = 0;
+
+	sprintf(buf, "+CIND: %d,0,0,0,0,%d,0", status, roam);
+	g_at_server_send_info(em->server, buf, final);
+}
+
+static void netreg_status_changed(int status, int lac, int ci, int tech,
+					const char *mcc, const char *mnc,
+					void *data)
+{
+	struct ofono_emulator *em = data;
+
+	DBG("%d", status);
+
+	if (em->netreg_status == status)
+		return;
+
+	em->netreg_status = status;
+
+	cind_update(em, TRUE);
+}
+
+static void netreg_watch(struct ofono_atom *atom,
+				enum ofono_atom_watch_condition cond,
+				void *data)
+{
+	struct ofono_emulator *em = data;
+
+	if (cond == OFONO_ATOM_WATCH_CONDITION_UNREGISTERED) {
+		em->status_watch = 0;
+		em->netreg_status = NETWORK_REGISTRATION_STATUS_NOT_REGISTERED;
+		return;
+	}
+
+	em->netreg = __ofono_atom_get_data(atom);
+	em->netreg_status = ofono_netreg_get_status(em->netreg);
+	em->status_watch = __ofono_netreg_add_status_watch(em->netreg,
+					netreg_status_changed, em, NULL);
+
+	cind_update(em, TRUE);
+}
+
+static void at_cind_cb(GAtServerRequestType type, GAtResult *result,
+			gpointer user_data)
+{
+	struct ofono_emulator *em = user_data;
+
+	switch (type) {
+	case G_AT_SERVER_REQUEST_TYPE_QUERY:
+		cind_update(em, FALSE);
+		g_at_server_send_final(em->server, G_AT_SERVER_RESULT_OK);
+		break;
+
+	case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
+		g_at_server_send_info(em->server, "+CIND: (\"service\",(0,1))"
+				",(\"call\",(0,1)),(\"callsetup\",(0-3))"
+				",(\"callheld\",(0-2)),(\"signal\",(0-5))"
+				",(\"roam\",(0,1)),(\"battchg\",(0-5))", FALSE);
+		g_at_server_send_final(em->server, G_AT_SERVER_RESULT_OK);
+		break;
+
+	default:
+		g_at_server_send_final(em->server, G_AT_SERVER_RESULT_ERROR);
+		break;
+	}
+}
+
 static void emulator_disconnect(gpointer user_data)
 {
 	struct ofono_emulator *em = user_data;
@@ -61,6 +159,8 @@ static void emulator_unregister(struct ofono_atom *atom)
 void ofono_emulator_register(struct ofono_emulator *em, int fd)
 {
 	GIOChannel *io;
+	struct ofono_modem *modem;
+	struct ofono_atom *netreg_atom;
 
 	DBG("%p, %d", em, fd);
 
@@ -77,6 +177,24 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd)
 	g_at_server_set_disconnect_function(em->server,
 						emulator_disconnect, em);
 
+	if (em->type == OFONO_EMULATOR_TYPE_HFP) {
+		g_at_server_register(em->server, "+CIND", at_cind_cb, em, NULL);
+
+		modem = __ofono_atom_get_modem(em->atom);
+
+		em->netreg_watch = __ofono_modem_add_atom_watch(modem,
+						OFONO_ATOM_TYPE_NETREG,
+						netreg_watch, em, NULL);
+
+		netreg_atom = __ofono_modem_find_atom(modem,
+							OFONO_ATOM_TYPE_NETREG);
+
+		if (netreg_atom && __ofono_atom_get_registered(netreg_atom))
+			netreg_watch(netreg_atom,
+					OFONO_ATOM_WATCH_CONDITION_REGISTERED,
+					em);
+	}
+
 	__ofono_atom_register(em->atom, emulator_unregister);
 }
 
-- 
1.7.1


  parent reply	other threads:[~2011-02-15 15:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-15 15:06 [PATCH 0/3] bluetooth: add HFP AG plugin =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-15 15:06 ` [PATCH 1/3] " =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-15 17:10   ` Gustavo F. Padovan
2011-02-16  6:24   ` Denis Kenzior
2011-02-15 15:06 ` [PATCH 2/3] emulator: add HFP emulator type =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-16  6:25   ` Denis Kenzior
2011-02-15 15:06 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-02-22 15:40 [PATCH v2 0/3] bluetooth: add CIND and CIEV support in HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-22 15:40 ` [PATCH 3/3] emulator: add CIND support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-22 18:39   ` Denis Kenzior
2011-02-23 15:48 [PATCH v3 0/3] bluetooth: add CIND and CIEV support in HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-23 15:48 ` [PATCH 3/3] emulator: add CIND 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=1297782393-9898-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox