Open Source Telephony
 help / color / mirror / Atom feed
* [PATCH v4 0/2] bluetooth: add CIND and CIEV support in HFP AG
@ 2011-02-23 17:02 =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
  2011-02-23 17:02 ` [PATCH 1/2] emulator: add support of indicators =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis @ 2011-02-23 17:02 UTC (permalink / raw)
  To: ofono

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

Add CIND and CIEV support for HFP AG

Frédéric Danis (2):
  emulator: add support of indicators
  emulator: add CIND support

 src/emulator.c |  155 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/network.c  |   77 +++++++++++++++++++++++++++-
 2 files changed, 231 insertions(+), 1 deletions(-)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] emulator: add support of indicators
  2011-02-23 17:02 [PATCH v4 0/2] bluetooth: add CIND and CIEV support in HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
@ 2011-02-23 17:02 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
  2011-02-23 17:02 ` [PATCH 2/2] emulator: add CIND support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
  2011-02-23 17:18 ` [PATCH v4 0/2] bluetooth: add CIND and CIEV support in HFP AG Denis Kenzior
  2 siblings, 0 replies; 4+ messages in thread
From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis @ 2011-02-23 17:02 UTC (permalink / raw)
  To: ofono

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

---
 src/emulator.c |   74 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/network.c  |   77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 150 insertions(+), 1 deletions(-)

diff --git a/src/emulator.c b/src/emulator.c
index f0ae84b..53844a7 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -24,6 +24,7 @@
 #endif
 
 #include <stdio.h>
+#include <string.h>
 
 #include <glib.h>
 
@@ -42,6 +43,14 @@ struct ofono_emulator {
 	GAtServer *server;
 	GAtPPP *ppp;
 	guint source;
+	GSList *indicators;
+};
+
+struct indicator {
+	char *name;
+	int value;
+	int min;
+	int max;
 };
 
 static void emulator_debug(const char *str, void *data)
@@ -163,9 +172,30 @@ error:
        g_at_server_send_final(em->server, G_AT_SERVER_RESULT_ERROR);
 }
 
+static void emulator_add_indicator(struct ofono_emulator *em, const char* name,
+					int min, int max, int dflt)
+{
+	struct indicator *ind;
+
+	ind = g_try_new0(struct indicator, 1);
+	if (ind == NULL) {
+		ofono_error("Unable to allocate indicator structure");
+		return;
+	}
+
+	ind->name = g_strdup(name);
+	ind->min = min;
+	ind->max = max;
+	ind->value = dflt;
+
+	em->indicators = g_slist_append(em->indicators, ind);
+}
+
 static void emulator_unregister(struct ofono_atom *atom)
 {
 	struct ofono_emulator *em = __ofono_atom_get_data(atom);
+	struct indicator *ind;
+	GSList *l;
 
 	DBG("%p", em);
 
@@ -174,6 +204,15 @@ static void emulator_unregister(struct ofono_atom *atom)
 		em->source = 0;
 	}
 
+	for (l = em->indicators; l; l = l->next) {
+		ind = l->data;
+
+		g_free(ind->name);
+		g_free(ind);
+	}
+	g_slist_free(em->indicators);
+	em->indicators = NULL;
+
 	g_at_server_unref(em->server);
 	em->server = NULL;
 }
@@ -199,6 +238,13 @@ 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) {
+		emulator_add_indicator(em, OFONO_EMULATOR_IND_SERVICE, 0, 1, 0);
+		emulator_add_indicator(em, OFONO_EMULATOR_IND_SIGNAL, 0, 5, 0);
+		emulator_add_indicator(em, OFONO_EMULATOR_IND_ROAMING, 0, 1, 0);
+		emulator_add_indicator(em, OFONO_EMULATOR_IND_BATTERY, 0, 5, 5);
+	}
+
 	__ofono_atom_register(em->atom, emulator_unregister);
 
 	if (em->type == OFONO_EMULATOR_TYPE_DUN)
@@ -399,3 +445,31 @@ enum ofono_emulator_request_type ofono_emulator_request_get_type(
 {
 	return req->type;
 }
+
+void ofono_emulator_set_indicator(struct ofono_emulator *em,
+					const char *name, int value)
+{
+	GSList *l;
+	int i;
+	char buf[20];
+
+	i = 1;
+	for (l = em->indicators; l; l = l->next) {
+		struct indicator *ind = l->data;
+
+		if (g_str_equal(ind->name, name)) {
+			if (ind->value == value || value < ind->min
+					|| value > ind->max)
+				return;
+
+			ind->value = value;
+
+			sprintf(buf, "+CIEV: %d,%d", i, ind->value);
+			g_at_server_send_info(em->server, buf, TRUE);
+
+			break;
+		}
+
+		i++;
+	}
+}
diff --git a/src/network.c b/src/network.c
index c059906..0cfdddb 100644
--- a/src/network.c
+++ b/src/network.c
@@ -36,6 +36,7 @@
 #include "simutil.h"
 #include "util.h"
 #include "storage.h"
+#include "emulator.h"
 
 #define NETWORK_REGISTRATION_FLAG_HOME_SHOW_PLMN 0x1
 #define NETWORK_REGISTRATION_FLAG_ROAMING_SHOW_SPN 0x2
@@ -82,6 +83,7 @@ struct ofono_netreg {
 	const struct ofono_netreg_driver *driver;
 	void *driver_data;
 	struct ofono_atom *atom;
+	unsigned int hfp_watch;
 };
 
 struct network_operator_data {
@@ -1287,15 +1289,42 @@ static void signal_strength_callback(const struct ofono_error *error,
 	ofono_netreg_strength_notify(netreg, strength);
 }
 
+static void notify_emulator_status(struct ofono_atom *atom, void *data)
+{
+	struct ofono_emulator *em = __ofono_atom_get_data(atom);
+
+	switch (GPOINTER_TO_INT(data)) {
+	case NETWORK_REGISTRATION_STATUS_REGISTERED:
+		ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_SERVICE, 1);
+		ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_ROAMING, 0);
+		break;
+	case NETWORK_REGISTRATION_STATUS_ROAMING:
+		ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_SERVICE, 1);
+		ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_ROAMING, 1);
+		break;
+	default:
+		ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_SERVICE, 0);
+		ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_ROAMING, 0);
+	}
+}
+
 void ofono_netreg_status_notify(struct ofono_netreg *netreg, int status,
 			int lac, int ci, int tech)
 {
 	if (netreg == NULL)
 		return;
 
-	if (netreg->status != status)
+	if (netreg->status != status) {
+		struct ofono_modem *modem;
+
 		set_registration_status(netreg, status);
 
+		modem = __ofono_atom_get_modem(netreg->atom);
+		__ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP,
+					notify_emulator_status,
+					GINT_TO_POINTER(netreg->status));
+	}
+
 	if (netreg->location != lac)
 		set_registration_location(netreg, lac);
 
@@ -1375,9 +1404,21 @@ static void init_registration_status(const struct ofono_error *error,
 	}
 }
 
+static void notify_emulator_strength(struct ofono_atom *atom, void *data)
+{
+	struct ofono_emulator *em = __ofono_atom_get_data(atom);
+	int val = 0;
+
+	if (GPOINTER_TO_INT(data) > 0)
+		val = (GPOINTER_TO_INT(data) - 1) / 20 + 1;
+
+	ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_SIGNAL, val);
+}
+
 void ofono_netreg_strength_notify(struct ofono_netreg *netreg, int strength)
 {
 	DBusConnection *conn = ofono_dbus_get_connection();
+	struct ofono_modem *modem;
 
 	if (netreg->signal_strength == strength)
 		return;
@@ -1401,6 +1442,11 @@ void ofono_netreg_strength_notify(struct ofono_netreg *netreg, int strength)
 					"Strength", DBUS_TYPE_BYTE,
 					&strength);
 	}
+
+	modem = __ofono_atom_get_modem(netreg->atom);
+	__ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP,
+				notify_emulator_strength,
+				GINT_TO_POINTER(netreg->signal_strength));
 }
 
 static void sim_opl_read_cb(int ok, int length, int record,
@@ -1656,6 +1702,14 @@ static void netreg_unregister(struct ofono_atom *atom)
 	const char *path = __ofono_atom_get_path(atom);
 	GSList *l;
 
+	__ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP,
+				notify_emulator_status,
+				GINT_TO_POINTER(0));
+	__ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP,
+				notify_emulator_strength, GINT_TO_POINTER(0));
+
+	__ofono_modem_remove_atom_watch(modem, netreg->hfp_watch);
+
 	__ofono_watchlist_free(netreg->status_watches);
 	netreg->status_watches = NULL;
 
@@ -1837,6 +1891,23 @@ static void sim_spn_spdi_changed(int id, void *userdata)
 			sim_spn_read_cb, netreg);
 }
 
+static void emulator_hfp_watch(struct ofono_atom *atom,
+				enum ofono_atom_watch_condition cond,
+				void *data)
+{
+	struct ofono_netreg *netreg = data;
+	struct ofono_modem *modem = __ofono_atom_get_modem(netreg->atom);
+
+	if (cond == OFONO_ATOM_WATCH_CONDITION_REGISTERED) {
+		__ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP,
+				notify_emulator_status,
+				GINT_TO_POINTER(netreg->status));
+		__ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP,
+				notify_emulator_strength,
+				GINT_TO_POINTER(netreg->signal_strength));
+	}
+}
+
 void ofono_netreg_register(struct ofono_netreg *netreg)
 {
 	DBusConnection *conn = ofono_dbus_get_connection();
@@ -1894,6 +1965,10 @@ void ofono_netreg_register(struct ofono_netreg *netreg)
 	}
 
 	__ofono_atom_register(netreg->atom, netreg_unregister);
+
+	netreg->hfp_watch = __ofono_modem_add_atom_watch(modem,
+					OFONO_ATOM_TYPE_EMULATOR_HFP,
+					emulator_hfp_watch, netreg, NULL);
 }
 
 void ofono_netreg_remove(struct ofono_netreg *netreg)
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] emulator: add CIND support
  2011-02-23 17:02 [PATCH v4 0/2] bluetooth: add CIND and CIEV support in HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
  2011-02-23 17:02 ` [PATCH 1/2] emulator: add support of indicators =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
@ 2011-02-23 17:02 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
  2011-02-23 17:18 ` [PATCH v4 0/2] bluetooth: add CIND and CIEV support in HFP AG Denis Kenzior
  2 siblings, 0 replies; 4+ messages in thread
From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis @ 2011-02-23 17:02 UTC (permalink / raw)
  To: ofono

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

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

diff --git a/src/emulator.c b/src/emulator.c
index 53844a7..e6f503d 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -172,6 +172,85 @@ error:
        g_at_server_send_final(em->server, G_AT_SERVER_RESULT_ERROR);
 }
 
+static void cind_cb(GAtServer *server, GAtServerRequestType type,
+			GAtResult *result, gpointer user_data)
+{
+	struct ofono_emulator *em = user_data;
+	GSList *l;
+	struct indicator *ind;
+	gsize size;
+	int len;
+	char *buf;
+	char *tmp;
+
+	switch (type) {
+	case G_AT_SERVER_REQUEST_TYPE_QUERY:
+		/*
+		 * "+CIND: " + terminating null + number of indicators *
+		 * (max of 3 digits in the value + separator)
+		 */
+		size = 7 + 1 + (g_slist_length(em->indicators) * 4);
+		buf = g_try_malloc0(size);
+		if (buf == NULL)
+			goto fail;
+
+		len = sprintf(buf, "+CIND: ");
+		tmp = buf + len;
+
+		for (l = em->indicators; l; l = l->next) {
+			ind = l->data;
+			len = sprintf(tmp, "%s%d",
+					l == em->indicators ? "" : ",",
+					ind->value);
+			tmp = tmp + len;
+		}
+
+		g_at_server_send_info(em->server, buf, TRUE);
+		g_free(buf);
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
+		break;
+
+	case G_AT_SERVER_REQUEST_TYPE_SUPPORT:
+		/*
+		 * '+CIND: ' + terminating null + number of indicators *
+		 * ( indicator name + '("",(000,000))' + separator)
+		 */
+		size = 8;
+
+		for (l = em->indicators; l; l = l->next) {
+			ind = l->data;
+			size += strlen(ind->name) + 15;
+		}
+
+		buf = g_try_malloc0(size);
+		if (buf == NULL)
+			goto fail;
+
+		len = sprintf(buf, "+CIND: ");
+		tmp = buf + len;
+
+		for (l = em->indicators; l; l = l->next) {
+			ind = l->data;
+			len = sprintf(tmp, "%s(\"%s\",(%d%c%d))",
+					l == em->indicators ? "" : ",",
+					ind->name, ind->min,
+					(ind->max - ind->min) == 1 ? ',' : '-',
+					ind->max);
+			tmp = tmp + len;
+		}
+
+		g_at_server_send_info(server, buf, TRUE);
+		g_free(buf);
+		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);
+		break;
+	}
+}
+
 static void emulator_add_indicator(struct ofono_emulator *em, const char* name,
 					int min, int max, int dflt)
 {
@@ -243,6 +322,8 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd)
 		emulator_add_indicator(em, OFONO_EMULATOR_IND_SIGNAL, 0, 5, 0);
 		emulator_add_indicator(em, OFONO_EMULATOR_IND_ROAMING, 0, 1, 0);
 		emulator_add_indicator(em, OFONO_EMULATOR_IND_BATTERY, 0, 5, 5);
+
+		g_at_server_register(em->server, "+CIND", cind_cb, em, NULL);
 	}
 
 	__ofono_atom_register(em->atom, emulator_unregister);
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v4 0/2] bluetooth: add CIND and CIEV support in HFP AG
  2011-02-23 17:02 [PATCH v4 0/2] bluetooth: add CIND and CIEV support in HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
  2011-02-23 17:02 ` [PATCH 1/2] emulator: add support of indicators =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
  2011-02-23 17:02 ` [PATCH 2/2] emulator: add CIND support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
@ 2011-02-23 17:18 ` Denis Kenzior
  2 siblings, 0 replies; 4+ messages in thread
From: Denis Kenzior @ 2011-02-23 17:18 UTC (permalink / raw)
  To: ofono

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

Hi Frédéric,

On 02/23/2011 11:02 AM, Frédéric Danis wrote:
> Add CIND and CIEV support for HFP AG
> 
> Frédéric Danis (2):
>   emulator: add support of indicators
>   emulator: add CIND support
> 
>  src/emulator.c |  155 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  src/network.c  |   77 +++++++++++++++++++++++++++-
>  2 files changed, 231 insertions(+), 1 deletions(-)

Both patches have been applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-02-23 17:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-23 17:02 [PATCH v4 0/2] bluetooth: add CIND and CIEV support in HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-23 17:02 ` [PATCH 1/2] emulator: add support of indicators =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-23 17:02 ` [PATCH 2/2] emulator: add CIND support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-23 17:18 ` [PATCH v4 0/2] bluetooth: add CIND and CIEV support in HFP AG Denis Kenzior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox